2 Implementation of Helper routines for PEI enviroment.
4 Copyright (c) 2013-2016 Intel Corporation.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/PeiServicesTablePointerLib.h>
19 #include <Library/PeiServicesLib.h>
20 #include <Library/I2cLib.h>
22 #include "CommonHeader.h"
25 // Routines defined in other source modules of this component.
29 // Routines local to this source module.
33 // Routines exported by this source module.
37 Find pointer to RAW data in Firmware volume file.
39 @param FvNameGuid Firmware volume to search. If == NULL search all.
40 @param FileNameGuid Firmware volume file to search for.
41 @param SectionData Pointer to RAW data section of found file.
42 @param SectionDataSize Pointer to UNITN to get size of RAW data.
44 @retval EFI_SUCCESS Raw Data found.
45 @retval EFI_INVALID_PARAMETER FileNameGuid == NULL.
46 @retval EFI_NOT_FOUND Firmware volume file not found.
47 @retval EFI_UNSUPPORTED Unsupported in current enviroment (PEI or DXE).
52 PlatformFindFvFileRawDataSection (
53 IN CONST EFI_GUID
*FvNameGuid OPTIONAL
,
54 IN CONST EFI_GUID
*FileNameGuid
,
55 OUT VOID
**SectionData
,
56 OUT UINTN
*SectionDataSize
61 EFI_PEI_FV_HANDLE VolumeHandle
;
62 EFI_PEI_FILE_HANDLE FileHandle
;
63 EFI_SECTION_TYPE SearchType
;
64 EFI_FV_INFO VolumeInfo
;
65 EFI_FV_FILE_INFO FileInfo
;
67 if (FileNameGuid
== NULL
|| SectionData
== NULL
|| SectionDataSize
== NULL
) {
68 return EFI_INVALID_PARAMETER
;
73 SearchType
= EFI_SECTION_RAW
;
74 for (Instance
= 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance
, &VolumeHandle
))); Instance
++) {
75 if (FvNameGuid
!= NULL
) {
76 Status
= PeiServicesFfsGetVolumeInfo (VolumeHandle
, &VolumeInfo
);
77 if (EFI_ERROR (Status
)) {
80 if (!CompareGuid (FvNameGuid
, &VolumeInfo
.FvName
)) {
84 Status
= PeiServicesFfsFindFileByName (FileNameGuid
, VolumeHandle
, &FileHandle
);
85 if (!EFI_ERROR (Status
)) {
86 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &FileInfo
);
87 if (EFI_ERROR (Status
)) {
90 if (IS_SECTION2(FileInfo
.Buffer
)) {
91 *SectionDataSize
= SECTION2_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER2
);
93 *SectionDataSize
= SECTION_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER
);
95 Status
= PeiServicesFfsFindSectionData (SearchType
, FileHandle
, SectionData
);
96 if (!EFI_ERROR (Status
)) {
101 return EFI_NOT_FOUND
;
105 Find free spi protect register and write to it to protect a flash region.
107 @param DirectValue Value to directly write to register.
108 if DirectValue == 0 the use Base & Length below.
109 @param BaseAddress Base address of region in Flash Memory Map.
110 @param Length Length of region to protect.
112 @retval EFI_SUCCESS Free spi protect register found & written.
113 @retval EFI_NOT_FOUND Free Spi protect register not found.
114 @retval EFI_DEVICE_ERROR Unable to write to spi protect register.
118 PlatformWriteFirstFreeSpiProtect (
119 IN CONST UINT32 DirectValue
,
120 IN CONST UINT32 BaseAddress
,
121 IN CONST UINT32 Length
124 return WriteFirstFreeSpiProtect (
133 /** Check if System booted with recovery Boot Stage1 image.
135 @retval TRUE If system booted with recovery Boot Stage1 image.
136 @retval FALSE If system booted with normal stage1 image.
141 PlatformIsBootWithRecoveryStage1 (
145 BOOLEAN IsRecoveryBoot
;
146 QUARK_EDKII_STAGE1_HEADER
*Edk2ImageHeader
;
148 Edk2ImageHeader
= (QUARK_EDKII_STAGE1_HEADER
*) PcdGet32 (PcdEsramStage1Base
);
149 switch ((UINT8
)Edk2ImageHeader
->ImageIndex
& QUARK_STAGE1_IMAGE_TYPE_MASK
) {
150 case QUARK_STAGE1_RECOVERY_IMAGE_TYPE
:
154 IsRecoveryBoot
= TRUE
;
160 IsRecoveryBoot
= FALSE
;
164 return IsRecoveryBoot
;