]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Library/PlatformHelperLib/PlatformHelperPei.c
9de3f613e0cbf74bbb33ca5def1a07a10a9f377e
[mirror_edk2.git] / QuarkPlatformPkg / Library / PlatformHelperLib / PlatformHelperPei.c
1 /** @file
2 Implementation of Helper routines for PEI enviroment.
3
4 Copyright (c) 2013-2016 Intel Corporation.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiPei.h>
11
12 #include <Library/PeiServicesTablePointerLib.h>
13 #include <Library/PeiServicesLib.h>
14 #include <Library/I2cLib.h>
15
16 #include "CommonHeader.h"
17
18 //
19 // Routines defined in other source modules of this component.
20 //
21
22 //
23 // Routines local to this source module.
24 //
25
26 //
27 // Routines exported by this source module.
28 //
29
30 /**
31 Find pointer to RAW data in Firmware volume file.
32
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.
37
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).
42
43 **/
44 EFI_STATUS
45 EFIAPI
46 PlatformFindFvFileRawDataSection (
47 IN CONST EFI_GUID *FvNameGuid OPTIONAL,
48 IN CONST EFI_GUID *FileNameGuid,
49 OUT VOID **SectionData,
50 OUT UINTN *SectionDataSize
51 )
52 {
53 EFI_STATUS Status;
54 UINTN Instance;
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;
60
61 if (FileNameGuid == NULL || SectionData == NULL || SectionDataSize == NULL) {
62 return EFI_INVALID_PARAMETER;
63 }
64 *SectionData = NULL;
65 *SectionDataSize = 0;
66
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)) {
72 continue;
73 }
74 if (!CompareGuid (FvNameGuid, &VolumeInfo.FvName)) {
75 continue;
76 }
77 }
78 Status = PeiServicesFfsFindFileByName (FileNameGuid, VolumeHandle, &FileHandle);
79 if (!EFI_ERROR (Status)) {
80 Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);
81 if (EFI_ERROR (Status)) {
82 continue;
83 }
84 if (IS_SECTION2(FileInfo.Buffer)) {
85 *SectionDataSize = SECTION2_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER2);
86 } else {
87 *SectionDataSize = SECTION_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER);
88 }
89 Status = PeiServicesFfsFindSectionData (SearchType, FileHandle, SectionData);
90 if (!EFI_ERROR (Status)) {
91 return Status;
92 }
93 }
94 }
95 return EFI_NOT_FOUND;
96 }
97
98 /**
99 Find free spi protect register and write to it to protect a flash region.
100
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.
105
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.
109 **/
110 EFI_STATUS
111 EFIAPI
112 PlatformWriteFirstFreeSpiProtect (
113 IN CONST UINT32 DirectValue,
114 IN CONST UINT32 BaseAddress,
115 IN CONST UINT32 Length
116 )
117 {
118 return WriteFirstFreeSpiProtect (
119 QNC_RCRB_BASE,
120 DirectValue,
121 BaseAddress,
122 Length,
123 NULL
124 );
125 }
126
127 /** Check if System booted with recovery Boot Stage1 image.
128
129 @retval TRUE If system booted with recovery Boot Stage1 image.
130 @retval FALSE If system booted with normal stage1 image.
131
132 **/
133 BOOLEAN
134 EFIAPI
135 PlatformIsBootWithRecoveryStage1 (
136 VOID
137 )
138 {
139 BOOLEAN IsRecoveryBoot;
140 QUARK_EDKII_STAGE1_HEADER *Edk2ImageHeader;
141
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:
145 //
146 // Recovery Boot
147 //
148 IsRecoveryBoot = TRUE;
149 break;
150 default:
151 //
152 // Normal Boot
153 //
154 IsRecoveryBoot = FALSE;
155 break;
156 }
157
158 return IsRecoveryBoot;
159 }