• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 
24 
25 Module Name:
26 
27   FlashMap.c
28 
29 Abstract:
30 
31   Build GUIDed HOBs for platform specific flash map.
32 
33 --*/
34 
35 #include "Efi.h"
36 #include "Pei.h"
37 #include "PeiLib.h"
38 #include "PeiLib.h"
39 #include "EfiFlashMap.h"
40 #include EFI_PROTOCOL_CONSUMER (FirmwareVolumeBlock)
41 #include EFI_GUID_DEFINITION (FlashMapHob)
42 #include EFI_GUID_DEFINITION (SystemNvDataGuid)
43 #include EFI_GUID_DEFINITION (FirmwareFileSystem)
44 
45 EFI_GUID                            mFvBlockGuid      = EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID;
46 EFI_GUID                            mFfsGuid          = EFI_FIRMWARE_FILE_SYSTEM_GUID;
47 EFI_GUID                            mSystemDataGuid   = EFI_SYSTEM_NV_DATA_HOB_GUID;
48 
49 static EFI_FLASH_AREA_DATA          mFlashAreaData[]  = {
50 	//
51   // Variable area
52   //
53   { FixedPcdGet32 (PcdFlashNvStorageVariableBase),
54     FixedPcdGet32 (PcdFlashNvStorageVariableSize),
55     EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,
56     EFI_FLASH_AREA_EFI_VARIABLES },
57 
58   //
59   // Boot block 2nd part
60   //
61   { FixedPcdGet32 (PcdFlashFvRecovery2Base),
62     FixedPcdGet32 (PcdFlashFvRecovery2Size),
63     EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,
64     EFI_FLASH_AREA_FTW_BACKUP },
65 
66   //
67   // Recovery FV
68   //
69   { FixedPcdGet32 (PcdFlashFvRecoveryBase),
70     FixedPcdGet32 (PcdFlashFvRecoverySize),
71     EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,
72     EFI_FLASH_AREA_RECOVERY_BIOS },
73 
74   //
75   // Main FV
76   //
77   { FixedPcdGet32 (PcdFlashFvMainBase),
78     FixedPcdGet32 (PcdFlashFvMainSize),
79     EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,
80     EFI_FLASH_AREA_MAIN_BIOS }
81 
82 };
83 
84 #define NUM_FLASH_AREA_DATA (ARRAY_SIZE (mFlashAreaData))
85 
86 /**
87   Build GUID HOBs for platform specific flash map.
PeimInitializeFlashMap(IN EFI_FFS_FILE_HEADER * FfsHeader,IN EFI_PEI_SERVICES ** PeiServices)88 
89   @param FfsHeader     Pointer this FFS file header.
90   @param PeiServices   General purpose services available to every PEIM.
91 
92   @retval EFI_SUCCESS   Guid HOBs for platform flash map is built.
93   @retval Otherwise     Failed to build the Guid HOB data.
94 
95 **/
96 EFI_STATUS
97 PeimInitializeFlashMap (
98   IN EFI_FFS_FILE_HEADER       *FfsHeader,
99   IN EFI_PEI_SERVICES          **PeiServices
100   )
101 {
102   UINTN                         Index;
103   EFI_FLASH_AREA_HOB_DATA       FlashHobData;
104 
105   //
106   // Build flash area entries as GUIDed HOBs.
107   //
108   for (Index = 0; Index < NUM_FLASH_AREA_DATA; Index++) {
109     ZeroMem(&FlashHobData, sizeof (EFI_FLASH_AREA_HOB_DATA));
110 
111     FlashHobData.AreaType               = mFlashAreaData[Index].AreaType;
112     FlashHobData.NumberOfEntries        = 1;
113     FlashHobData.SubAreaData.Attributes = mFlashAreaData[Index].Attributes;
114     FlashHobData.SubAreaData.Base       = (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Base;
115     FlashHobData.SubAreaData.Length     = (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Length;
116 
117     switch (FlashHobData.AreaType) {
118     case EFI_FLASH_AREA_RECOVERY_BIOS:
119     case EFI_FLASH_AREA_MAIN_BIOS:
120       CopyMem (
121         &FlashHobData.AreaTypeGuid,
122         &mFfsGuid,
123         sizeof (EFI_GUID)
124         );
125       CopyMem (
126         &FlashHobData.SubAreaData.FileSystem,
127         &mFvBlockGuid,
128         sizeof (EFI_GUID)
129         );
130       break;
131 
132     case EFI_FLASH_AREA_GUID_DEFINED:
133       CopyMem (
134         &FlashHobData.AreaTypeGuid,
135         &mSystemDataGuid,
136         sizeof (EFI_GUID)
137         );
138       CopyMem (
139         &FlashHobData.SubAreaData.FileSystem,
140         &mFvBlockGuid,
141         sizeof (EFI_GUID)
142         );
143       break;
144 
145     default:
146       break;
147     }
148 
149     PeiBuildHobGuidData(PeiServices,
150                         &gEfiFlashMapHobGuid,
151                         &FlashHobData,
152                         sizeof (EFI_FLASH_AREA_HOB_DATA)
153                         );
154   }
155   return EFI_SUCCESS;
156 }
157 
158