]>
Commit | Line | Data |
---|---|---|
b303605e MK |
1 | /** @file\r |
2 | Implementation of Helper routines for PEI enviroment.\r | |
3 | \r | |
0c5d4079 | 4 | Copyright (c) 2013-2016 Intel Corporation.\r |
b303605e MK |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT 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 | |
50 | EFI_STATUS\r | |
51 | EFIAPI\r | |
52 | PlatformFindFvFileRawDataSection (\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 | |
b303605e MK |
66 | \r |
67 | if (FileNameGuid == NULL || SectionData == NULL || SectionDataSize == NULL) {\r | |
68 | return EFI_INVALID_PARAMETER;\r | |
69 | }\r | |
70 | *SectionData = NULL;\r | |
71 | *SectionDataSize = 0;\r | |
72 | \r | |
b303605e MK |
73 | SearchType = EFI_SECTION_RAW;\r |
74 | for (Instance = 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance, &VolumeHandle))); Instance++) {\r | |
75 | if (FvNameGuid != NULL) {\r | |
76 | Status = PeiServicesFfsGetVolumeInfo (VolumeHandle, &VolumeInfo);\r | |
77 | if (EFI_ERROR (Status)) {\r | |
78 | continue;\r | |
79 | }\r | |
80 | if (!CompareGuid (FvNameGuid, &VolumeInfo.FvName)) {\r | |
81 | continue;\r | |
82 | }\r | |
83 | }\r | |
84 | Status = PeiServicesFfsFindFileByName (FileNameGuid, VolumeHandle, &FileHandle);\r | |
85 | if (!EFI_ERROR (Status)) {\r | |
86 | Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);\r | |
87 | if (EFI_ERROR (Status)) {\r | |
88 | continue;\r | |
89 | }\r | |
90 | if (IS_SECTION2(FileInfo.Buffer)) {\r | |
91 | *SectionDataSize = SECTION2_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER2);\r | |
92 | } else {\r | |
93 | *SectionDataSize = SECTION_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER);\r | |
94 | }\r | |
95 | Status = PeiServicesFfsFindSectionData (SearchType, FileHandle, SectionData);\r | |
96 | if (!EFI_ERROR (Status)) {\r | |
97 | return Status;\r | |
98 | }\r | |
99 | }\r | |
100 | }\r | |
101 | return EFI_NOT_FOUND;\r | |
102 | }\r | |
103 | \r | |
104 | /**\r | |
105 | Find free spi protect register and write to it to protect a flash region.\r | |
106 | \r | |
107 | @param DirectValue Value to directly write to register.\r | |
108 | if DirectValue == 0 the use Base & Length below.\r | |
109 | @param BaseAddress Base address of region in Flash Memory Map.\r | |
110 | @param Length Length of region to protect.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS Free spi protect register found & written.\r | |
113 | @retval EFI_NOT_FOUND Free Spi protect register not found.\r | |
114 | @retval EFI_DEVICE_ERROR Unable to write to spi protect register.\r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | PlatformWriteFirstFreeSpiProtect (\r | |
119 | IN CONST UINT32 DirectValue,\r | |
120 | IN CONST UINT32 BaseAddress,\r | |
121 | IN CONST UINT32 Length\r | |
122 | )\r | |
123 | {\r | |
124 | return WriteFirstFreeSpiProtect (\r | |
125 | QNC_RCRB_BASE,\r | |
126 | DirectValue,\r | |
127 | BaseAddress,\r | |
128 | Length,\r | |
129 | NULL\r | |
130 | );\r | |
131 | }\r | |
132 | \r | |
133 | /** Check if System booted with recovery Boot Stage1 image.\r | |
134 | \r | |
135 | @retval TRUE If system booted with recovery Boot Stage1 image.\r | |
136 | @retval FALSE If system booted with normal stage1 image.\r | |
137 | \r | |
138 | **/\r | |
139 | BOOLEAN\r | |
140 | EFIAPI\r | |
141 | PlatformIsBootWithRecoveryStage1 (\r | |
142 | VOID\r | |
143 | )\r | |
144 | {\r | |
145 | BOOLEAN IsRecoveryBoot;\r | |
146 | QUARK_EDKII_STAGE1_HEADER *Edk2ImageHeader;\r | |
147 | \r | |
148 | Edk2ImageHeader = (QUARK_EDKII_STAGE1_HEADER *) PcdGet32 (PcdEsramStage1Base);\r | |
149 | switch ((UINT8)Edk2ImageHeader->ImageIndex & QUARK_STAGE1_IMAGE_TYPE_MASK) {\r | |
150 | case QUARK_STAGE1_RECOVERY_IMAGE_TYPE:\r | |
151 | //\r | |
152 | // Recovery Boot\r | |
153 | //\r | |
154 | IsRecoveryBoot = TRUE;\r | |
155 | break;\r | |
156 | default:\r | |
157 | //\r | |
158 | // Normal Boot\r | |
159 | //\r | |
160 | IsRecoveryBoot = FALSE;\r | |
161 | break;\r | |
162 | }\r | |
163 | \r | |
164 | return IsRecoveryBoot;\r | |
165 | }\r |