2 Implementation of Helper routines for PEI enviroment.
4 Copyright (c) 2013-2016 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/PeiServicesTablePointerLib.h>
13 #include <Library/PeiServicesLib.h>
14 #include <Library/I2cLib.h>
16 #include "CommonHeader.h"
19 // Routines defined in other source modules of this component.
23 // Routines local to this source module.
27 // Routines exported by this source module.
31 Find pointer to RAW data in Firmware volume file.
33 @param FvNameGuid Firmware volume to search. If == NULL search all.
34 @param FileNameGuid Firmware volume file to search for.
35 @param SectionData Pointer to RAW data section of found file.
36 @param SectionDataSize Pointer to UNITN to get size of RAW data.
38 @retval EFI_SUCCESS Raw Data found.
39 @retval EFI_INVALID_PARAMETER FileNameGuid == NULL.
40 @retval EFI_NOT_FOUND Firmware volume file not found.
41 @retval EFI_UNSUPPORTED Unsupported in current enviroment (PEI or DXE).
46 PlatformFindFvFileRawDataSection (
47 IN CONST EFI_GUID
*FvNameGuid OPTIONAL
,
48 IN CONST EFI_GUID
*FileNameGuid
,
49 OUT VOID
**SectionData
,
50 OUT UINTN
*SectionDataSize
55 EFI_PEI_FV_HANDLE VolumeHandle
;
56 EFI_PEI_FILE_HANDLE FileHandle
;
57 EFI_SECTION_TYPE SearchType
;
58 EFI_FV_INFO VolumeInfo
;
59 EFI_FV_FILE_INFO FileInfo
;
61 if (FileNameGuid
== NULL
|| SectionData
== NULL
|| SectionDataSize
== NULL
) {
62 return EFI_INVALID_PARAMETER
;
67 SearchType
= EFI_SECTION_RAW
;
68 for (Instance
= 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance
, &VolumeHandle
))); Instance
++) {
69 if (FvNameGuid
!= NULL
) {
70 Status
= PeiServicesFfsGetVolumeInfo (VolumeHandle
, &VolumeInfo
);
71 if (EFI_ERROR (Status
)) {
74 if (!CompareGuid (FvNameGuid
, &VolumeInfo
.FvName
)) {
78 Status
= PeiServicesFfsFindFileByName (FileNameGuid
, VolumeHandle
, &FileHandle
);
79 if (!EFI_ERROR (Status
)) {
80 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &FileInfo
);
81 if (EFI_ERROR (Status
)) {
84 if (IS_SECTION2(FileInfo
.Buffer
)) {
85 *SectionDataSize
= SECTION2_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER2
);
87 *SectionDataSize
= SECTION_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER
);
89 Status
= PeiServicesFfsFindSectionData (SearchType
, FileHandle
, SectionData
);
90 if (!EFI_ERROR (Status
)) {
99 Find free spi protect register and write to it to protect a flash region.
101 @param DirectValue Value to directly write to register.
102 if DirectValue == 0 the use Base & Length below.
103 @param BaseAddress Base address of region in Flash Memory Map.
104 @param Length Length of region to protect.
106 @retval EFI_SUCCESS Free spi protect register found & written.
107 @retval EFI_NOT_FOUND Free Spi protect register not found.
108 @retval EFI_DEVICE_ERROR Unable to write to spi protect register.
112 PlatformWriteFirstFreeSpiProtect (
113 IN CONST UINT32 DirectValue
,
114 IN CONST UINT32 BaseAddress
,
115 IN CONST UINT32 Length
118 return WriteFirstFreeSpiProtect (
127 /** Check if System booted with recovery Boot Stage1 image.
129 @retval TRUE If system booted with recovery Boot Stage1 image.
130 @retval FALSE If system booted with normal stage1 image.
135 PlatformIsBootWithRecoveryStage1 (
139 BOOLEAN IsRecoveryBoot
;
140 QUARK_EDKII_STAGE1_HEADER
*Edk2ImageHeader
;
142 Edk2ImageHeader
= (QUARK_EDKII_STAGE1_HEADER
*) PcdGet32 (PcdEsramStage1Base
);
143 switch ((UINT8
)Edk2ImageHeader
->ImageIndex
& QUARK_STAGE1_IMAGE_TYPE_MASK
) {
144 case QUARK_STAGE1_RECOVERY_IMAGE_TYPE
:
148 IsRecoveryBoot
= TRUE
;
154 IsRecoveryBoot
= FALSE
;
158 return IsRecoveryBoot
;