]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkPlatformPkg/Library/PlatformHelperLib/PlatformHelperPei.c
MdeModulePkg: Add the missing Library uni files of ImageDecode instances
[mirror_edk2.git] / QuarkPlatformPkg / Library / PlatformHelperLib / PlatformHelperPei.c
CommitLineData
b303605e
MK
1/** @file\r
2Implementation of Helper routines for PEI enviroment.\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <PiPei.h>\r
17\r
18#include <Library/PeiServicesTablePointerLib.h>\r
19#include <Library/PeiServicesLib.h>\r
20#include <Library/I2cLib.h>\r
21\r
22#include "CommonHeader.h"\r
23\r
24//\r
25// Routines defined in other source modules of this component.\r
26//\r
27\r
28//\r
29// Routines local to this source module.\r
30//\r
31\r
32//\r
33// Routines exported by this source module.\r
34//\r
35\r
36/**\r
37 Find pointer to RAW data in Firmware volume file.\r
38\r
39 @param FvNameGuid Firmware volume to search. If == NULL search all.\r
40 @param FileNameGuid Firmware volume file to search for.\r
41 @param SectionData Pointer to RAW data section of found file.\r
42 @param SectionDataSize Pointer to UNITN to get size of RAW data.\r
43\r
44 @retval EFI_SUCCESS Raw Data found.\r
45 @retval EFI_INVALID_PARAMETER FileNameGuid == NULL.\r
46 @retval EFI_NOT_FOUND Firmware volume file not found.\r
47 @retval EFI_UNSUPPORTED Unsupported in current enviroment (PEI or DXE).\r
48\r
49**/\r
50EFI_STATUS\r
51EFIAPI\r
52PlatformFindFvFileRawDataSection (\r
53 IN CONST EFI_GUID *FvNameGuid OPTIONAL,\r
54 IN CONST EFI_GUID *FileNameGuid,\r
55 OUT VOID **SectionData,\r
56 OUT UINTN *SectionDataSize\r
57 )\r
58{\r
59 EFI_STATUS Status;\r
60 UINTN Instance;\r
61 EFI_PEI_FV_HANDLE VolumeHandle;\r
62 EFI_PEI_FILE_HANDLE FileHandle;\r
63 EFI_SECTION_TYPE SearchType;\r
64 EFI_FV_INFO VolumeInfo;\r
65 EFI_FV_FILE_INFO FileInfo;\r
66 CONST EFI_PEI_SERVICES **PeiServices;\r
67\r
68 if (FileNameGuid == NULL || SectionData == NULL || SectionDataSize == NULL) {\r
69 return EFI_INVALID_PARAMETER;\r
70 }\r
71 *SectionData = NULL;\r
72 *SectionDataSize = 0;\r
73\r
74 PeiServices = GetPeiServicesTablePointer ();\r
75 SearchType = EFI_SECTION_RAW;\r
76 for (Instance = 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance, &VolumeHandle))); Instance++) {\r
77 if (FvNameGuid != NULL) {\r
78 Status = PeiServicesFfsGetVolumeInfo (VolumeHandle, &VolumeInfo);\r
79 if (EFI_ERROR (Status)) {\r
80 continue;\r
81 }\r
82 if (!CompareGuid (FvNameGuid, &VolumeInfo.FvName)) {\r
83 continue;\r
84 }\r
85 }\r
86 Status = PeiServicesFfsFindFileByName (FileNameGuid, VolumeHandle, &FileHandle);\r
87 if (!EFI_ERROR (Status)) {\r
88 Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);\r
89 if (EFI_ERROR (Status)) {\r
90 continue;\r
91 }\r
92 if (IS_SECTION2(FileInfo.Buffer)) {\r
93 *SectionDataSize = SECTION2_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER2);\r
94 } else {\r
95 *SectionDataSize = SECTION_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER);\r
96 }\r
97 Status = PeiServicesFfsFindSectionData (SearchType, FileHandle, SectionData);\r
98 if (!EFI_ERROR (Status)) {\r
99 return Status;\r
100 }\r
101 }\r
102 }\r
103 return EFI_NOT_FOUND;\r
104}\r
105\r
106/**\r
107 Find free spi protect register and write to it to protect a flash region.\r
108\r
109 @param DirectValue Value to directly write to register.\r
110 if DirectValue == 0 the use Base & Length below.\r
111 @param BaseAddress Base address of region in Flash Memory Map.\r
112 @param Length Length of region to protect.\r
113\r
114 @retval EFI_SUCCESS Free spi protect register found & written.\r
115 @retval EFI_NOT_FOUND Free Spi protect register not found.\r
116 @retval EFI_DEVICE_ERROR Unable to write to spi protect register.\r
117**/\r
118EFI_STATUS\r
119EFIAPI\r
120PlatformWriteFirstFreeSpiProtect (\r
121 IN CONST UINT32 DirectValue,\r
122 IN CONST UINT32 BaseAddress,\r
123 IN CONST UINT32 Length\r
124 )\r
125{\r
126 return WriteFirstFreeSpiProtect (\r
127 QNC_RCRB_BASE,\r
128 DirectValue,\r
129 BaseAddress,\r
130 Length,\r
131 NULL\r
132 );\r
133}\r
134\r
135/** Check if System booted with recovery Boot Stage1 image.\r
136\r
137 @retval TRUE If system booted with recovery Boot Stage1 image.\r
138 @retval FALSE If system booted with normal stage1 image.\r
139\r
140**/\r
141BOOLEAN\r
142EFIAPI\r
143PlatformIsBootWithRecoveryStage1 (\r
144 VOID\r
145 )\r
146{\r
147 BOOLEAN IsRecoveryBoot;\r
148 QUARK_EDKII_STAGE1_HEADER *Edk2ImageHeader;\r
149\r
150 Edk2ImageHeader = (QUARK_EDKII_STAGE1_HEADER *) PcdGet32 (PcdEsramStage1Base);\r
151 switch ((UINT8)Edk2ImageHeader->ImageIndex & QUARK_STAGE1_IMAGE_TYPE_MASK) {\r
152 case QUARK_STAGE1_RECOVERY_IMAGE_TYPE:\r
153 //\r
154 // Recovery Boot\r
155 //\r
156 IsRecoveryBoot = TRUE;\r
157 break;\r
158 default:\r
159 //\r
160 // Normal Boot\r
161 //\r
162 IsRecoveryBoot = FALSE;\r
163 break;\r
164 }\r
165\r
166 return IsRecoveryBoot;\r
167}\r