PlatformHelperPei.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /** @file
  2. Implementation of Helper routines for PEI enviroment.
  3. Copyright (c) 2013-2016 Intel Corporation.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/PeiServicesTablePointerLib.h>
  8. #include <Library/PeiServicesLib.h>
  9. #include <Library/I2cLib.h>
  10. #include "CommonHeader.h"
  11. //
  12. // Routines defined in other source modules of this component.
  13. //
  14. //
  15. // Routines local to this source module.
  16. //
  17. //
  18. // Routines exported by this source module.
  19. //
  20. /**
  21. Find pointer to RAW data in Firmware volume file.
  22. @param FvNameGuid Firmware volume to search. If == NULL search all.
  23. @param FileNameGuid Firmware volume file to search for.
  24. @param SectionData Pointer to RAW data section of found file.
  25. @param SectionDataSize Pointer to UNITN to get size of RAW data.
  26. @retval EFI_SUCCESS Raw Data found.
  27. @retval EFI_INVALID_PARAMETER FileNameGuid == NULL.
  28. @retval EFI_NOT_FOUND Firmware volume file not found.
  29. @retval EFI_UNSUPPORTED Unsupported in current enviroment (PEI or DXE).
  30. **/
  31. EFI_STATUS
  32. EFIAPI
  33. PlatformFindFvFileRawDataSection (
  34. IN CONST EFI_GUID *FvNameGuid OPTIONAL,
  35. IN CONST EFI_GUID *FileNameGuid,
  36. OUT VOID **SectionData,
  37. OUT UINTN *SectionDataSize
  38. )
  39. {
  40. EFI_STATUS Status;
  41. UINTN Instance;
  42. EFI_PEI_FV_HANDLE VolumeHandle;
  43. EFI_PEI_FILE_HANDLE FileHandle;
  44. EFI_SECTION_TYPE SearchType;
  45. EFI_FV_INFO VolumeInfo;
  46. EFI_FV_FILE_INFO FileInfo;
  47. if (FileNameGuid == NULL || SectionData == NULL || SectionDataSize == NULL) {
  48. return EFI_INVALID_PARAMETER;
  49. }
  50. *SectionData = NULL;
  51. *SectionDataSize = 0;
  52. SearchType = EFI_SECTION_RAW;
  53. for (Instance = 0; !EFI_ERROR((PeiServicesFfsFindNextVolume (Instance, &VolumeHandle))); Instance++) {
  54. if (FvNameGuid != NULL) {
  55. Status = PeiServicesFfsGetVolumeInfo (VolumeHandle, &VolumeInfo);
  56. if (EFI_ERROR (Status)) {
  57. continue;
  58. }
  59. if (!CompareGuid (FvNameGuid, &VolumeInfo.FvName)) {
  60. continue;
  61. }
  62. }
  63. Status = PeiServicesFfsFindFileByName (FileNameGuid, VolumeHandle, &FileHandle);
  64. if (!EFI_ERROR (Status)) {
  65. Status = PeiServicesFfsGetFileInfo (FileHandle, &FileInfo);
  66. if (EFI_ERROR (Status)) {
  67. continue;
  68. }
  69. if (IS_SECTION2(FileInfo.Buffer)) {
  70. *SectionDataSize = SECTION2_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER2);
  71. } else {
  72. *SectionDataSize = SECTION_SIZE(FileInfo.Buffer) - sizeof(EFI_COMMON_SECTION_HEADER);
  73. }
  74. Status = PeiServicesFfsFindSectionData (SearchType, FileHandle, SectionData);
  75. if (!EFI_ERROR (Status)) {
  76. return Status;
  77. }
  78. }
  79. }
  80. return EFI_NOT_FOUND;
  81. }
  82. /**
  83. Find free spi protect register and write to it to protect a flash region.
  84. @param DirectValue Value to directly write to register.
  85. if DirectValue == 0 the use Base & Length below.
  86. @param BaseAddress Base address of region in Flash Memory Map.
  87. @param Length Length of region to protect.
  88. @retval EFI_SUCCESS Free spi protect register found & written.
  89. @retval EFI_NOT_FOUND Free Spi protect register not found.
  90. @retval EFI_DEVICE_ERROR Unable to write to spi protect register.
  91. **/
  92. EFI_STATUS
  93. EFIAPI
  94. PlatformWriteFirstFreeSpiProtect (
  95. IN CONST UINT32 DirectValue,
  96. IN CONST UINT32 BaseAddress,
  97. IN CONST UINT32 Length
  98. )
  99. {
  100. return WriteFirstFreeSpiProtect (
  101. QNC_RCRB_BASE,
  102. DirectValue,
  103. BaseAddress,
  104. Length,
  105. NULL
  106. );
  107. }
  108. /** Check if System booted with recovery Boot Stage1 image.
  109. @retval TRUE If system booted with recovery Boot Stage1 image.
  110. @retval FALSE If system booted with normal stage1 image.
  111. **/
  112. BOOLEAN
  113. EFIAPI
  114. PlatformIsBootWithRecoveryStage1 (
  115. VOID
  116. )
  117. {
  118. BOOLEAN IsRecoveryBoot;
  119. QUARK_EDKII_STAGE1_HEADER *Edk2ImageHeader;
  120. Edk2ImageHeader = (QUARK_EDKII_STAGE1_HEADER *) PcdGet32 (PcdEsramStage1Base);
  121. switch ((UINT8)Edk2ImageHeader->ImageIndex & QUARK_STAGE1_IMAGE_TYPE_MASK) {
  122. case QUARK_STAGE1_RECOVERY_IMAGE_TYPE:
  123. //
  124. // Recovery Boot
  125. //
  126. IsRecoveryBoot = TRUE;
  127. break;
  128. default:
  129. //
  130. // Normal Boot
  131. //
  132. IsRecoveryBoot = FALSE;
  133. break;
  134. }
  135. return IsRecoveryBoot;
  136. }