2 Implementation of Helper routines for PEI enviroment.
4 Copyright (c) 2013-2015 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
;
66 CONST EFI_PEI_SERVICES
**PeiServices
;
68 if (FileNameGuid
== NULL
|| SectionData
== NULL
|| SectionDataSize
== NULL
) {
69 return EFI_INVALID_PARAMETER
;
74 PeiServices
= GetPeiServicesTablePointer ();
75 SearchType
= EFI_SECTION_RAW
;
76 for (Instance
= 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance
, &VolumeHandle
))); Instance
++) {
77 if (FvNameGuid
!= NULL
) {
78 Status
= PeiServicesFfsGetVolumeInfo (VolumeHandle
, &VolumeInfo
);
79 if (EFI_ERROR (Status
)) {
82 if (!CompareGuid (FvNameGuid
, &VolumeInfo
.FvName
)) {
86 Status
= PeiServicesFfsFindFileByName (FileNameGuid
, VolumeHandle
, &FileHandle
);
87 if (!EFI_ERROR (Status
)) {
88 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &FileInfo
);
89 if (EFI_ERROR (Status
)) {
92 if (IS_SECTION2(FileInfo
.Buffer
)) {
93 *SectionDataSize
= SECTION2_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER2
);
95 *SectionDataSize
= SECTION_SIZE(FileInfo
.Buffer
) - sizeof(EFI_COMMON_SECTION_HEADER
);
97 Status
= PeiServicesFfsFindSectionData (SearchType
, FileHandle
, SectionData
);
98 if (!EFI_ERROR (Status
)) {
103 return EFI_NOT_FOUND
;
107 Find free spi protect register and write to it to protect a flash region.
109 @param DirectValue Value to directly write to register.
110 if DirectValue == 0 the use Base & Length below.
111 @param BaseAddress Base address of region in Flash Memory Map.
112 @param Length Length of region to protect.
114 @retval EFI_SUCCESS Free spi protect register found & written.
115 @retval EFI_NOT_FOUND Free Spi protect register not found.
116 @retval EFI_DEVICE_ERROR Unable to write to spi protect register.
120 PlatformWriteFirstFreeSpiProtect (
121 IN CONST UINT32 DirectValue
,
122 IN CONST UINT32 BaseAddress
,
123 IN CONST UINT32 Length
126 return WriteFirstFreeSpiProtect (
135 /** Check if System booted with recovery Boot Stage1 image.
137 @retval TRUE If system booted with recovery Boot Stage1 image.
138 @retval FALSE If system booted with normal stage1 image.
143 PlatformIsBootWithRecoveryStage1 (
147 BOOLEAN IsRecoveryBoot
;
148 QUARK_EDKII_STAGE1_HEADER
*Edk2ImageHeader
;
150 Edk2ImageHeader
= (QUARK_EDKII_STAGE1_HEADER
*) PcdGet32 (PcdEsramStage1Base
);
151 switch ((UINT8
)Edk2ImageHeader
->ImageIndex
& QUARK_STAGE1_IMAGE_TYPE_MASK
) {
152 case QUARK_STAGE1_RECOVERY_IMAGE_TYPE
:
156 IsRecoveryBoot
= TRUE
;
162 IsRecoveryBoot
= FALSE
;
166 return IsRecoveryBoot
;