3 Copyright (c) 2004-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Utility for flash management in the Intel Platform Innovation Framework
19 for EFI build environment.
27 #include <Common/UefiBaseTypes.h>
28 #include <Common/FirmwareVolumeHeader.h>
29 #include <Common/MultiPhase.h>
31 #include "EfiUtilityMsgs.h"
32 #include "FlashDefFile.h"
33 #include "SimpleFileParsing.h"
37 // #include "TrackMallocFree.h"
40 #define MAX_STRING_LEN 256
41 #define MAX_NAME_LEN 128
42 #define BUFFER_SIZE 1024
43 #define MAX_ATTR_LEN 128
44 #define MAX_AREATYPE_LEN 128
45 #define COLUMN2_START 60
46 #define COLUMN3_START 70
48 // Information for each subregions defined in the fdf file will be saved in these
50 typedef struct _FLASH_SUBREGION_DESCRIPTION
{
51 struct _FLASH_SUBREGION_DESCRIPTION
*Next
;
52 int CreateHob
; // to add to the auto-created HOB array
53 WCHAR_T Name
[MAX_NAME_LEN
]; // each subregion within a region must have a unique name
54 unsigned int Size
; // size, in bytes, of this subregion
55 unsigned int SizeLeft
; // used when creating the image
56 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // subregion attributes used in the output HOB
57 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // subregion area type used in the output HOB
58 EFI_GUID NameGuid
; // used in the output HOB
59 WCHAR_T NameGuidString
[MAX_NAME_LEN
];
60 EFI_GUID AreaTypeGuid
; // used in the output HOB
61 WCHAR_T AreaTypeGuidString
[MAX_NAME_LEN
];
62 EFI_GUID FileSystemGuid
; // used in the output HOB
63 WCHAR_T FileSystemGuidString
[MAX_NAME_LEN
];
64 } FLASH_SUBREGION_DESCRIPTION
;
67 // Information for each block in a flash device will be saved in one of these.
68 // We'll also use it for region definitions.
70 typedef struct _FLASH_BLOCK_DESCRIPTION
{
71 struct _FLASH_BLOCK_DESCRIPTION
*Next
; // next block in the linked list
72 WCHAR_T Name
[MAX_NAME_LEN
]; // each block must have a unique name
73 unsigned int Size
; // size, in bytes, of this block
74 unsigned int SizeLeft
; // for use when creating image
75 unsigned int Flags
; // user-defined flags for the block
76 unsigned int Alignment
; // power of 2 alignment
77 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // only used for Region definitions
78 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // only used for Region definitions
79 FLASH_SUBREGION_DESCRIPTION
*Subregions
;
80 FLASH_SUBREGION_DESCRIPTION
*LastSubregion
;
81 } FLASH_BLOCK_DESCRIPTION
;
84 // Information for each flash device will be saved in one of these
86 typedef struct _FLASH_DEVICE_DESCRIPTION
{
87 struct _FLASH_DEVICE_DESCRIPTION
*Next
; // next flash device in our linked list
88 int ErasePolarity
; // erase polarity of the flash device
89 unsigned int BaseAddress
; // base address of the flash device
90 unsigned int Size
; // total size, in bytes, of the flash device
91 WCHAR_T Name
[MAX_NAME_LEN
]; // name of the flash device
92 FLASH_BLOCK_DESCRIPTION
*PBlocks
; // linked list of physical block descriptors
93 FLASH_BLOCK_DESCRIPTION
*LastPBlock
; // last block in the linked list
94 FLASH_BLOCK_DESCRIPTION
*Regions
; // linked list of flash region descriptors
95 FLASH_BLOCK_DESCRIPTION
*LastRegion
; // last region in the linked list
96 } FLASH_DEVICE_DESCRIPTION
;
99 // For image definitions, they can specify a file name or raw data bytes. Keep a linked list.
101 typedef struct _IMAGE_DEFINITION_ENTRY
{
102 struct _IMAGE_DEFINITION_ENTRY
*Next
;
103 WCHAR_T RegionName
[MAX_NAME_LEN
];
104 WCHAR_T SubregionName
[MAX_NAME_LEN
];
105 WCHAR_T Name
[MAX_NAME_LEN
]; // file or data name
106 int IsRawData
; // non-zero if raw data bytes
107 unsigned int RawDataSize
;
109 int Optional
; // optional file (don't include if it doesn't exist)
110 } IMAGE_DEFINITION_ENTRY
;
113 // When we parse an image definition, save all the data for each in one of these
115 typedef struct _IMAGE_DEFINITION
{
116 struct _IMAGE_DEFINITION
*Next
;
117 WCHAR_T Name
[MAX_NAME_LEN
];
118 IMAGE_DEFINITION_ENTRY
*Entries
;
119 IMAGE_DEFINITION_ENTRY
*LastEntry
;
128 static const char *CIncludeHeader
= "/*++\n\n"
129 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n""#ifndef _FLASH_MAP_H_\n"
130 "#define _FLASH_MAP_H_\n\n";
132 // "#include \"EfiFlashMap.h\"\n\n";
134 static const char *CIncludeFooter
= "#endif // #ifndef _FLASH_MAP_H_\n\n";
136 static const char *CFlashMapDataFileHeader
= "/*++\n\n"
137 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n";
139 static FLASH_DEVICE_DESCRIPTION
*mFlashDevices
= NULL
;
140 static IMAGE_DEFINITION
*mImageDefinitions
= NULL
;
143 // Local function prototypes
173 FLASH_SUBREGION_DESCRIPTION
*
174 ParseSubregionDefinition (
175 unsigned int SizeLeft
185 Initialization routine for the services that operate on a flash
196 mFlashDevices
= NULL
;
197 mImageDefinitions
= NULL
;
207 Finalization/cleanup routine for the services that operate on a flash
218 FLASH_BLOCK_DESCRIPTION
*FBNext
;
219 FLASH_DEVICE_DESCRIPTION
*FDNext
;
220 IMAGE_DEFINITION
*IDNext
;
221 IMAGE_DEFINITION_ENTRY
*IDENext
;
222 FLASH_SUBREGION_DESCRIPTION
*SubNext
;
224 // Go through all our flash devices and free the memory
226 while (mFlashDevices
!= NULL
) {
228 // Free the physical block definitions
230 while (mFlashDevices
->PBlocks
!= NULL
) {
231 FBNext
= mFlashDevices
->PBlocks
->Next
;
232 _free (mFlashDevices
->PBlocks
);
233 mFlashDevices
->PBlocks
= FBNext
;
236 // Free the region definitions
238 while (mFlashDevices
->Regions
!= NULL
) {
239 FBNext
= mFlashDevices
->Regions
->Next
;
241 // First free the subregion definitions
243 while (mFlashDevices
->Regions
->Subregions
!= NULL
) {
244 SubNext
= mFlashDevices
->Regions
->Subregions
->Next
;
245 _free (mFlashDevices
->Regions
->Subregions
);
246 mFlashDevices
->Regions
->Subregions
= SubNext
;
249 _free (mFlashDevices
->Regions
);
250 mFlashDevices
->Regions
= FBNext
;
253 FDNext
= mFlashDevices
->Next
;
254 _free (mFlashDevices
);
255 mFlashDevices
= FDNext
;
258 // Free up the image definitions, and the data
260 while (mImageDefinitions
!= NULL
) {
264 while (mImageDefinitions
->Entries
!= NULL
) {
265 IDENext
= mImageDefinitions
->Entries
->Next
;
266 if (mImageDefinitions
->Entries
->RawData
!= NULL
) {
267 _free (mImageDefinitions
->Entries
->RawData
);
270 _free (mImageDefinitions
->Entries
);
271 mImageDefinitions
->Entries
= IDENext
;
274 IDNext
= mImageDefinitions
->Next
;
275 _free (mImageDefinitions
);
276 mImageDefinitions
= IDNext
;
287 Parse the specified flash definition file, saving the definitions in
288 file-static variables for use by other functions.
291 FileName - name of the input flash definition text file.
294 STATUS_SUCCESS - file parsed with no errors or warnings
295 STATUS_WARNING - warnings, but no errors, were encountered while parsing
296 STATUS_ERROR - errors were encountered while parsing
303 FLASH_DEVICE_DESCRIPTION
*FDDesc
;
304 FLASH_BLOCK_DESCRIPTION
*FBlockDesc
;
305 FLASH_BLOCK_DESCRIPTION
*TempBlockDesc
;
306 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
307 FLASH_SUBREGION_DESCRIPTION
*TempSubregion
;
308 unsigned int BlockSizeLeft
;
309 unsigned int RegionSizeLeft
;
310 unsigned int SubregionSizeLeft
;
313 IMAGE_DEFINITION
*ImageDef
;
314 IMAGE_DEFINITION_ENTRY
*ImageDefEntry
;
315 IMAGE_DEFINITION_ENTRY
*TempImageDefEntry
;
316 BUFFER_DATA
*BufferData
;
318 BOOLEAN PreviousComma
;
320 if ((Fptr
= fopen (FileName
, "r")) == NULL
) {
321 Error (NULL
, 0, 0, FileName
, "failed to open input flash definition file for reading");
326 Status
= STATUS_SUCCESS
;
330 // Initialize the simple-file-parsing routines
336 if ((Status
= SFPOpenFile (FileName
)) != STATUS_SUCCESS
) {
340 // Parse the file. Should start with a series of these:
342 // Name = "FLASH_1234", Size = 0x2004, BaseAddress = 0xFFF0000, ErasePolarity = 1,
343 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
344 // Block { Name = "BLOCK2", Size = 0x1004, Flags = 0x0002 }
345 // Region { Name = "REGION_NAME", Size = 0x2004, Align= 4 }
348 while (SFPIsKeyword ("FlashDevice")) {
350 // Allocate memory for new flash device description block
352 FDDesc
= (FLASH_DEVICE_DESCRIPTION
*) _malloc (sizeof (FLASH_DEVICE_DESCRIPTION
));
353 if (FDDesc
== NULL
) {
354 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
359 memset (FDDesc
, 0, sizeof (FLASH_DEVICE_DESCRIPTION
));
361 // Open brace -- warning if not there
363 if (!SFPIsToken ("{")) {
364 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
368 // Parse: Name = "DeviceName",
370 if (!SFPIsKeyword ("Name")) {
371 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
376 if (!SFPIsToken ("=")) {
377 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
381 if (!SFPGetQuotedString (FDDesc
->Name
, sizeof (FDDesc
->Name
))) {
382 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of flash device", NULL
);
387 if (!SFPIsToken (",")) {
388 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following flash device name", NULL
);
392 // Parse: Size = 0x20000,
394 if (!SFPIsKeyword ("Size")) {
395 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
400 if (!SFPIsToken ("=")) {
401 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
405 if (!SFPGetNumber (&FDDesc
->Size
)) {
406 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
413 if (FDDesc
->Size
== 0) {
414 Error (SFPGetFileName (), SFPGetLineNumber (), 0, FDDesc
->Name
, "Size field cannot be 0", NULL
);
421 // Parse: BaseAddress = 0xFFF0000,
423 if (!SFPIsKeyword ("BaseAddress")) {
424 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'BaseAddress'", NULL
);
429 if (!SFPIsToken ("=")) {
430 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
434 if (!SFPGetNumber (&FDDesc
->BaseAddress
)) {
435 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for BaseAddress", NULL
);
440 if (!SFPIsToken (",")) {
441 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following BaseAddress value", NULL
);
445 // Parse: ErasePolarity = 1,
447 if (!SFPIsKeyword ("ErasePolarity")) {
448 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'ErasePolarity'", NULL
);
453 if (!SFPIsToken ("=")) {
454 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
458 if (!SFPGetNumber (&Num
) || ((Num
!= 0) && (Num
!= 1))) {
459 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric erase polarity value 1 or 0", NULL
);
464 FDDesc
->ErasePolarity
= Num
;
465 if (!SFPIsToken (",")) {
466 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following erase polarity value", NULL
);
471 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
473 // Keep track of size to make sure the sum of the physical blocks and region sizes do not
474 // exceed the size of the flash device.
476 BlockSizeLeft
= FDDesc
->Size
;
477 RegionSizeLeft
= FDDesc
->Size
;
478 while (SFPIsKeyword ("Block")) {
480 // Allocate memory for a new physical block descriptor
482 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
483 if (FBlockDesc
== NULL
) {
484 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
489 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
491 // Open brace -- warning if not there
493 if (!SFPIsToken ("{")) {
494 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
498 // Parse: Name = "BlockName",
500 if (!SFPIsKeyword ("Name")) {
501 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
506 if (!SFPIsToken ("=")) {
507 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
511 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
512 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of physical block", NULL
);
517 // Make sure there are no other physical block names with this same name
519 for (TempBlockDesc
= FDDesc
->PBlocks
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
520 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
526 "physical block with this name already defined"
532 if (!SFPIsToken (",")) {
533 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following physical block name", NULL
);
537 // Parse: Size = 0x2000,
539 if (!SFPIsKeyword ("Size")) {
540 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
545 if (!SFPIsToken ("=")) {
546 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
550 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
551 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
556 // Make sure the sum of physical blocks so far does not exceed flash device size
558 if (BlockSizeLeft
< FBlockDesc
->Size
) {
563 "sum of physical block sizes exceeds flash device size",
569 BlockSizeLeft
-= FBlockDesc
->Size
;
572 // Optional parse: Flags = 0xFFF0000,
574 if (SFPIsKeyword ("Flags")) {
575 if (!SFPIsToken ("=")) {
576 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
580 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
581 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
587 if (!SFPIsToken ("}")) {
588 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected PhysicalBlock closing brace '}'", NULL
);
592 // Add the physical block descriptor to the end of the linked list
594 if (FDDesc
->LastPBlock
!= NULL
) {
595 FDDesc
->LastPBlock
->Next
= FBlockDesc
;
597 FDDesc
->PBlocks
= FBlockDesc
;
600 FDDesc
->LastPBlock
= FBlockDesc
;
603 // Make sure sum of sizes of physical blocks added up to size of flash device
605 if (BlockSizeLeft
!= 0) {
611 "sum of sizes of physical blocks (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
612 FDDesc
->Size
- BlockSizeLeft
,
620 // Region { Name = "REGION_1", Size = 0x2000, Flags = 0x1234, Alignment = 4, Attributes = "str", AreaType = "str" }
622 while (SFPIsKeyword ("Region")) {
624 // Allocate memory for a new physical block descriptor
626 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
627 if (FBlockDesc
== NULL
) {
628 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
633 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
635 // Open brace -- warning if not there
637 if (!SFPIsToken ("{")) {
638 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
642 // Parse: Name = "BlockName",
644 if (!SFPIsKeyword ("Name")) {
645 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
650 if (!SFPIsToken ("=")) {
651 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
655 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
656 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
661 // Make sure there are no other region names with this same name
663 for (TempBlockDesc
= FDDesc
->Regions
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
664 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
670 "Region with this name already defined"
676 if (!SFPIsToken (",")) {
677 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
681 // Parse: Size = 0x2000,
683 if (!SFPIsKeyword ("Size")) {
684 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
689 if (!SFPIsToken ("=")) {
690 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
694 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
695 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
700 if (!SFPIsToken (",")) {
701 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
704 // Make sure the sum of regions so far does not exceed flash device size
706 if (RegionSizeLeft
< FBlockDesc
->Size
) {
707 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Region sizes exceeds flash device size", NULL
);
711 RegionSizeLeft
-= FBlockDesc
->Size
;
713 // Optional parse: Flags = 0xFFF0000,
715 if (SFPIsKeyword ("Flags")) {
716 if (!SFPIsToken ("=")) {
717 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
721 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
722 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
729 if (!SFPIsToken (",")) {
730 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
734 // Optional parse: Alignment = 4
736 if (SFPIsKeyword ("Alignment")) {
737 if (!SFPIsToken ("=")) {
738 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
742 if (!SFPGetNumber (&FBlockDesc
->Alignment
)) {
743 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Alignment value", NULL
);
750 if (!SFPIsToken (",")) {
751 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
755 // Parse: Attributes = "String",
757 if (!SFPIsKeyword ("Attributes")) {
758 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
763 if (!SFPIsToken ("=")) {
764 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
768 if (!SFPGetQuotedString (FBlockDesc
->Attributes
, sizeof (FBlockDesc
->Attributes
))) {
769 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
774 if (!SFPIsToken (",")) {
775 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
778 // Parse: AreaType = "String",
780 if (!SFPIsKeyword ("AreaType")) {
781 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
786 if (!SFPIsToken ("=")) {
787 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
791 if (!SFPGetQuotedString (FBlockDesc
->AreaType
, sizeof (FBlockDesc
->AreaType
))) {
792 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
797 PreviousComma
= SFPIsToken (",");
799 // Parse optional Subregion definitions
801 SubregionSizeLeft
= FBlockDesc
->Size
;
802 while (SFPIsToken ("Subregion")) {
803 if (!PreviousComma
) {
804 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'Subregion'", NULL
);
806 PreviousComma
= TRUE
;
809 Subregion
= ParseSubregionDefinition (SubregionSizeLeft
);
810 if (Subregion
== NULL
) {
815 SubregionSizeLeft
-= Subregion
->Size
;
817 // Add it to the end of our list
819 if (FBlockDesc
->Subregions
== NULL
) {
820 FBlockDesc
->Subregions
= Subregion
;
822 FBlockDesc
->LastSubregion
->Next
= Subregion
;
825 FBlockDesc
->LastSubregion
= Subregion
;
827 // Make sure all subregion names are unique. We do this each time
828 // through so that we catch the error immediately after it happens, in
829 // which case the reported line number is at least close to where the
830 // problem lies. We don't exit on the error because we can continue parsing
831 // the script to perhaps catch other errors or warnings.
833 for (Subregion
= FBlockDesc
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
834 for (TempSubregion
= Subregion
->Next
; TempSubregion
!= NULL
; TempSubregion
= TempSubregion
->Next
) {
835 if (strcmp (Subregion
->Name
, TempSubregion
->Name
) == 0) {
836 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Subregion
->Name
, "duplicate Subregion name");
843 if (!SFPIsToken ("}")) {
844 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Region closing brace '}'", NULL
);
848 // Add the region descriptor to the end of the linked list
850 if (FDDesc
->LastRegion
!= NULL
) {
851 FDDesc
->LastRegion
->Next
= FBlockDesc
;
853 FDDesc
->Regions
= FBlockDesc
;
856 FDDesc
->LastRegion
= FBlockDesc
;
859 // Make sure sum of sizes of regions adds up to size of flash device
861 if (RegionSizeLeft
!= 0) {
867 "sum of sizes of Regions (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
868 FDDesc
->Size
- RegionSizeLeft
,
875 // Look for closing brace
877 if (!SFPIsToken ("}")) {
878 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected FlashDevice closing brace '}'", NULL
);
882 // Add this flash description to the list
884 FDDesc
->Next
= mFlashDevices
;
885 mFlashDevices
= FDDesc
;
888 while (SFPIsKeyword ("FlashDeviceImage")) {
890 // Allocate memory for a new FD image definition
892 ImageDef
= (IMAGE_DEFINITION
*) _malloc (sizeof (IMAGE_DEFINITION
));
893 if (ImageDef
== NULL
) {
894 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
899 memset (ImageDef
, 0, sizeof (IMAGE_DEFINITION
));
901 // Open brace -- warning if not there
903 if (!SFPIsToken ("{")) {
904 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
908 // Parse: Name = "ImageName",
910 if (!SFPIsKeyword ("Name")) {
911 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
916 if (!SFPIsToken ("=")) {
917 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
921 if (!SFPGetQuotedString (ImageDef
->Name
, sizeof (ImageDef
->Name
))) {
922 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of image", NULL
);
927 if (!SFPIsToken (",")) {
928 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following image name", NULL
);
934 // Parse: File { Name = "FV\FvOem.fv", Region = "REGION_OEM", Optional = TRUE }
936 if (SFPIsKeyword ("File")) {
937 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
938 if (ImageDefEntry
== NULL
) {
939 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
944 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
946 // Open brace -- warning if not there
948 if (!SFPIsToken ("{")) {
949 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
953 // Parse: Name = "FileName.txt"
955 if (!SFPIsKeyword ("Name")) {
956 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
961 if (!SFPIsToken ("=")) {
962 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
966 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
967 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of file", NULL
);
972 if (!SFPIsToken (",")) {
973 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following file name", NULL
);
977 // Parse: Region = "REGION_NAME"
979 if (!SFPIsKeyword ("Region")) {
980 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
985 if (!SFPIsToken ("=")) {
986 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
990 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
991 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
996 if (!SFPIsToken (",")) {
997 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1001 // Parse optional: Subregion = "SUBREGION_NAME"
1003 if (SFPIsKeyword ("Subregion")) {
1004 if (!SFPIsToken ("=")) {
1005 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1009 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1010 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1015 if (!SFPIsToken (",")) {
1016 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1020 // For a given region, you can only place data using the region name, or the subregion names.
1021 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1022 // here by checking that any previous entries with the same Region name had a Subregion specified
1025 for (TempImageDefEntry
= ImageDef
->Entries
;
1026 TempImageDefEntry
!= NULL
;
1027 TempImageDefEntry
= TempImageDefEntry
->Next
1029 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1030 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1033 SFPGetLineNumber (),
1035 TempImageDefEntry
->RegionName
,
1036 "data already placed on a region-basis in the region, can't place data using subregions"
1044 // Optional parse: Optional = TRUE | FALSE
1046 if (SFPIsKeyword ("Optional")) {
1047 if (!SFPIsToken ("=")) {
1048 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1052 if (!SFPIsKeyword ("TRUE")) {
1053 ImageDefEntry
->Optional
= 1;
1054 } else if (SFPIsKeyword ("FALSE")) {
1059 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1069 if (!SFPIsToken ("}")) {
1070 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace to File entry", NULL
);
1075 // Add the entry to the end of the list
1077 if (ImageDef
->LastEntry
!= NULL
) {
1078 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1080 ImageDef
->Entries
= ImageDefEntry
;
1083 ImageDef
->LastEntry
= ImageDefEntry
;
1084 } else if (SFPIsKeyword ("RawData")) {
1086 // Parse: RawData { Name = "PadBytes", Region = "REGION_1", Data = { 0x78, 0x56, 0x34, 0x12 }}
1088 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
1089 if (ImageDefEntry
== NULL
) {
1090 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1095 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
1096 ImageDefEntry
->IsRawData
= 1;
1098 // Open brace -- warning if not there
1100 if (!SFPIsToken ("{")) {
1103 SFPGetLineNumber (),
1105 "expected '{' opening brace for RawData definition",
1111 // Parse: Name = "PadBytes"
1113 if (!SFPIsKeyword ("Name")) {
1114 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1119 if (!SFPIsToken ("=")) {
1120 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1124 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
1125 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of raw data", NULL
);
1130 if (!SFPIsToken (",")) {
1131 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following raw data name", NULL
);
1135 // Parse: Region = "REGION_NAME"
1137 if (!SFPIsKeyword ("Region")) {
1138 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
1143 if (!SFPIsToken ("=")) {
1144 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1148 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
1149 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
1154 if (!SFPIsToken (",")) {
1155 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1159 // Parse optional: Subregion = "SUBREGION_NAME"
1161 if (SFPIsKeyword ("Subregion")) {
1162 if (!SFPIsToken ("=")) {
1163 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1167 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1168 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1173 if (!SFPIsToken (",")) {
1174 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1178 // For a given region, you can only place data using the region name, or the subregion names.
1179 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1180 // here by checking that any previous entries with the same Region name had a Subregion specified
1183 for (TempImageDefEntry
= ImageDef
->Entries
;
1184 TempImageDefEntry
!= NULL
;
1185 TempImageDefEntry
= TempImageDefEntry
->Next
1187 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1188 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1191 SFPGetLineNumber (),
1193 TempImageDefEntry
->RegionName
,
1194 "data already placed on a region-basis in the region, can't place data using subregions"
1202 // Parse: Data = { 0x78, 0x56, 0x34, 0x12 }
1204 if (!SFPIsKeyword ("Data")) {
1205 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Data'", NULL
);
1210 if (!SFPIsToken ("=")) {
1211 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1215 if (!SFPIsToken ("{")) {
1216 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '{' preceeding data list", NULL
);
1220 if ((BufferData
= CreateBufferData ()) == NULL
) {
1225 // Read bytes from input file until closing brace
1227 while (!SFPIsToken ("}")) {
1228 if (!SFPGetNumber (&Num
)) {
1229 SFPGetNextToken (Str
, sizeof (Str
));
1230 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected data value", Str
);
1232 FreeBufferData (BufferData
, TRUE
);
1239 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "only values 0-255 (0x00-0xFF) allowed", NULL
);
1241 FreeBufferData (BufferData
, TRUE
);
1245 AddBufferDataByte (BufferData
, (char) Num
);
1250 // Now get the data and save it in our image entry
1252 ImageDefEntry
->RawData
= GetBufferData (BufferData
, &ImageDefEntry
->RawDataSize
);
1253 FreeBufferData (BufferData
, 0);
1255 // Closing brace for RawData {}
1257 if (!SFPIsToken ("}")) {
1258 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace for RawData", NULL
);
1263 // Add the entry to the end of the list
1265 if (ImageDef
->LastEntry
!= NULL
) {
1266 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1268 ImageDef
->Entries
= ImageDefEntry
;
1271 ImageDef
->LastEntry
= ImageDefEntry
;
1272 } else if (SFPIsToken ("}")) {
1274 // Closing brace for FDImage {}
1278 SFPGetNextToken (Str
, sizeof (Str
));
1279 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "unrecognized token", Str
);
1285 // Add this image definition to our global list
1287 ImageDef
->Next
= mImageDefinitions
;
1288 mImageDefinitions
= ImageDef
;
1291 // Check for end-of-file
1294 SFPGetNextToken (Str
, sizeof (Str
));
1295 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected end-of-file", Str
);
1301 if (ErrorCount
!= 0) {
1302 return STATUS_ERROR
;
1303 } else if (WarningCount
!= 0) {
1304 return STATUS_WARNING
;
1307 return STATUS_SUCCESS
;
1311 FLASH_SUBREGION_DESCRIPTION
*
1312 ParseSubregionDefinition (
1313 unsigned int SizeLeft
1317 Routine Description:
1319 Parse Subregion definitions from the input flash definition file. Format:
1325 Attributes = "EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV",
1326 AreaType = "EFI_FLASH_AREA_EFI_VARIABLES",
1327 NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD (or "EFI_SOME_GUID"),
1328 AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1329 FileSystemGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1332 NOTE: The caller has already parsed the "Subregion" token, so start with the opening brace.
1336 SizeLeft - in the flash definition file, a Region can be broken up into
1337 one or more subregions. As we parse the subregion definitions,
1338 the caller keeps track of how much space is left in the region
1339 that we're parsing subregions for. SizeLeft is that size, and
1340 so the size of the subregion we're now parsing better not
1341 exceed the size left.
1344 NULL - unrecoverable errors detected while parsing the subregion definition
1346 pointer to a subregion definition created from the parsed subregion
1350 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1353 unsigned int Number
;
1354 BOOLEAN PreviousComma
;
1356 // Allocate memory for the new subregion descriptor
1360 Subregion
= (FLASH_SUBREGION_DESCRIPTION
*) _malloc (sizeof (FLASH_SUBREGION_DESCRIPTION
));
1361 if (Subregion
== NULL
) {
1362 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1367 memset (Subregion
, 0, sizeof (FLASH_SUBREGION_DESCRIPTION
));
1369 // Open brace -- warning if not there
1371 if (!SFPIsToken ("{")) {
1372 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
1376 // Parse: CreateHob = TRUE | FALSE,
1378 if (!SFPIsKeyword ("CreateHob")) {
1379 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'CreateHob'", NULL
);
1384 if (!SFPIsToken ("=")) {
1385 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1389 if (SFPIsToken ("TRUE")) {
1390 Subregion
->CreateHob
= 1;
1391 } else if (SFPIsToken ("FALSE")) {
1393 // Subregion->CreateHob = 0; -- not required since we did a memset earlier
1396 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1401 if (!SFPIsToken (",")) {
1402 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following CreateHob value", NULL
);
1406 // Parse: Name = "Name",
1408 if (!SFPIsKeyword ("Name")) {
1409 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1414 if (!SFPIsToken ("=")) {
1415 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1419 if (!SFPGetQuotedString (Subregion
->Name
, sizeof (Subregion
->Name
))) {
1420 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion name", NULL
);
1425 if (!SFPIsToken (",")) {
1426 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1430 // Parse: Size = 0x2000,
1432 if (!SFPIsKeyword ("Size")) {
1433 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
1438 if (!SFPIsToken ("=")) {
1439 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1443 if (!SFPGetNumber (&Subregion
->Size
)) {
1444 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
1450 // Check that the size does not exceed the size left passed in
1452 if (Subregion
->Size
> SizeLeft
) {
1453 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Subregion sizes exceeds Region size", NULL
);
1458 if (!SFPIsToken (",")) {
1459 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following Size value", NULL
);
1462 // Parse: Attributes = Number | "String",
1464 if (!SFPIsKeyword ("Attributes")) {
1465 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
1470 if (!SFPIsToken ("=")) {
1471 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1475 if (SFPGetNumber (&Number
)) {
1476 sprintf (Subregion
->Attributes
, "0x%X", Number
);
1477 } else if (!SFPGetQuotedString (Subregion
->Attributes
, sizeof (Subregion
->Attributes
))) {
1478 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
1483 if (!SFPIsToken (",")) {
1484 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
1487 // Parse: AreaType = Number | "String",
1488 // AreaType is a UINT8, so error if it exceeds the size
1490 if (!SFPIsKeyword ("AreaType")) {
1491 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
1496 if (!SFPIsToken ("=")) {
1497 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1501 if (SFPGetNumber (&Number
)) {
1502 if (Number
> 0xFF) {
1503 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "AreaType value exceeds 255", NULL
);
1507 sprintf (Subregion
->AreaType
, "0x%X", Number
& 0x00FF);
1508 } else if (!SFPGetQuotedString (Subregion
->AreaType
, sizeof (Subregion
->AreaType
))) {
1509 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
1514 if (!SFPIsToken (",")) {
1515 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following AreaType value", NULL
);
1518 // Parse the three GUIDs (last two are optional)
1520 // NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD, (or "EFI_SOME_GUID")
1521 // AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1522 // FileSysteGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1524 if (!SFPIsKeyword ("NameGuid")) {
1525 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'NameGuid'", NULL
);
1530 if (!SFPIsToken ("=")) {
1531 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1535 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1537 if (SFPGetQuotedString (Subregion
->NameGuidString
, sizeof (Subregion
->NameGuidString
))) {
1539 // Nothing else to do
1541 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->NameGuid
)) {
1544 SFPGetLineNumber (),
1546 "expected NameGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1553 // Comma following NameGuid is optional if they don't specify AreaTypeGuid or FileSystemGuid
1555 PreviousComma
= SFPIsToken (",");
1556 if (SFPIsKeyword ("AreaTypeGuid")) {
1558 // Check for preceeding comma now
1560 if (!PreviousComma
) {
1561 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'AreaTypeGuid'", NULL
);
1565 if (!SFPIsToken ("=")) {
1566 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1570 if (SFPGetQuotedString (Subregion
->AreaTypeGuidString
, sizeof (Subregion
->AreaTypeGuidString
))) {
1572 // Nothing else to do
1574 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->AreaTypeGuid
)) {
1577 SFPGetLineNumber (),
1579 "expected AreaTypeGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1586 PreviousComma
= SFPIsToken (",");
1589 if (SFPIsKeyword ("FileSystemGuid")) {
1591 // Check for preceeding comma now
1593 if (!PreviousComma
) {
1594 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'FileSystemGuid'", NULL
);
1598 if (!SFPIsToken ("=")) {
1599 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1603 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1605 if (SFPGetQuotedString (Subregion
->FileSystemGuidString
, sizeof (Subregion
->FileSystemGuidString
))) {
1607 // Nothing else to do
1609 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->FileSystemGuid
)) {
1612 SFPGetLineNumber (),
1614 "expected FileSystemGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1624 // Look for subregion closing brace
1626 if (!SFPIsToken ("}")) {
1627 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion closing brace '}'", NULL
);
1633 // If any errors were encountered, then delete the subregion definition
1635 if (ErrorCount
!= 0) {
1644 FDFCreateCIncludeFile (
1645 char *FlashDeviceName
,
1650 Routine Description:
1651 Create a header file with #define definitions per an already-parsed
1652 flash definition file.
1655 FlashDeviceName - name of flash device (from the flash definition file)
1657 FileName - name of output file to create
1660 STATUS_SUCCESS - no errors or warnings
1661 STATUS_WARNING - warnings, but no errors, were encountered
1662 STATUS_ERROR - errors were encountered
1667 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1668 FLASH_DEVICE_DESCRIPTION
*FDev
;
1669 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1670 unsigned int Offset
;
1671 unsigned int SubregionOffset
;
1674 // Find the definition we're supposed to use
1676 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1677 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1683 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1684 return STATUS_ERROR
;
1687 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1688 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1689 return STATUS_ERROR
;
1694 fprintf (OutFptr
, CIncludeHeader
);
1696 // Write flash block base and size defines
1698 fprintf (OutFptr
, "#define FLASH_BASE 0x%08X\n", FDev
->BaseAddress
);
1699 fprintf (OutFptr
, "#define FLASH_SIZE 0x%08X\n\n", FDev
->Size
);
1701 // Write flash regions base, size and offset defines
1705 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1708 "#define FLASH_REGION_%s_BASE %*c0x%08X\n",
1710 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1712 Offset
+ FDev
->BaseAddress
1716 "#define FLASH_REGION_%s_SIZE %*c0x%08X\n",
1718 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1724 "#define FLASH_REGION_%s_OFFSET %*c0x%08X\n",
1726 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1731 // Create defines for any subregions
1733 SubregionOffset
= 0;
1734 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1737 "#define FLASH_REGION_%s_SUBREGION_%s_BASE %*c0x%08X\n",
1740 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1742 FDev
->BaseAddress
+ Offset
+ SubregionOffset
1746 "#define FLASH_REGION_%s_SUBREGION_%s_SIZE %*c0x%08X\n",
1749 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1755 "#define FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c0x%08X\n",
1758 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1760 Offset
+ SubregionOffset
1762 SubregionOffset
+= Subregion
->Size
;
1763 if (Subregion
->CreateHob
!= 0) {
1768 Offset
+= FBlock
->Size
;
1771 // Now create a #define for the flash map data definition
1773 fprintf (OutFptr
, "\n\n#define EFI_FLASH_AREA_DATA_DEFINITION \\\n");
1775 // Emit entry for each region
1778 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1779 fprintf (OutFptr
, " /* %s region */\\\n", FBlock
->Name
);
1780 fprintf (OutFptr
, " {\\\n");
1781 fprintf (OutFptr
, " FLASH_REGION_%s_BASE,\\\n", FBlock
->Name
);
1782 fprintf (OutFptr
, " FLASH_REGION_%s_SIZE,\\\n", FBlock
->Name
);
1783 fprintf (OutFptr
, " %s,\\\n", FBlock
->Attributes
);
1784 fprintf (OutFptr
, " %s,\\\n },\\\n", FBlock
->AreaType
);
1787 fprintf (OutFptr
, "\n\n");
1789 // Now walk the list again to create the EFI_HOB_FLASH_MAP_ENTRY_TYPE definition
1791 if (CreateHobs
!= 0) {
1792 fprintf (OutFptr
, "//\n// EFI_HOB_FLASH_MAP_ENTRY_TYPE definition\n//\n");
1793 fprintf (OutFptr
, "#define EFI_HOB_FLASH_MAP_ENTRY_TYPE_DATA_DEFINITION");
1794 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1796 // See if the block has subregions, and that the CreateHobs flag is set
1800 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1801 if (Subregion
->CreateHob
!= 0) {
1807 // If any of the subregions had the CreateHobs flag set, then create the entries in the
1810 if (CreateHobs
!= 0) {
1811 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1812 if (Subregion
->CreateHob
!= 0) {
1813 fprintf (OutFptr
, " \\\n");
1814 fprintf (OutFptr
, " /* %s.%s Subregion */\\\n", FBlock
->Name
, Subregion
->Name
);
1815 fprintf (OutFptr
, " {\\\n");
1816 fprintf (OutFptr
, " EFI_HOB_TYPE_GUID_EXTENSION,\\\n");
1817 fprintf (OutFptr
, " sizeof (EFI_HOB_FLASH_MAP_ENTRY_TYPE ),\\\n");
1818 fprintf (OutFptr
, " 0,\\\n");
1820 // The NameGuid may have been specified in the input flash definition file as a GUID, or
1821 // as a quoted string. Do the right one.
1823 if (Subregion
->NameGuidString
[0] != 0) {
1824 fprintf (OutFptr
, " %s, \\\n", Subregion
->NameGuidString
);
1828 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1829 Subregion
->NameGuid
.Data1
,
1830 (unsigned int) Subregion
->NameGuid
.Data2
,
1831 (unsigned int) Subregion
->NameGuid
.Data3
,
1832 (unsigned int) Subregion
->NameGuid
.Data4
[0],
1833 (unsigned int) Subregion
->NameGuid
.Data4
[1],
1834 (unsigned int) Subregion
->NameGuid
.Data4
[2],
1835 (unsigned int) Subregion
->NameGuid
.Data4
[3],
1836 (unsigned int) Subregion
->NameGuid
.Data4
[4],
1837 (unsigned int) Subregion
->NameGuid
.Data4
[5],
1838 (unsigned int) Subregion
->NameGuid
.Data4
[6],
1839 (unsigned int) Subregion
->NameGuid
.Data4
[7]
1843 fprintf (OutFptr
, " 0, 0, 0,\\\n");
1844 fprintf (OutFptr
, " %s,\\\n", Subregion
->AreaType
);
1846 // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or
1847 // as a quoted string. Do the right one.
1849 if (Subregion
->AreaTypeGuidString
[0] != 0) {
1850 fprintf (OutFptr
, " %s, \\\n", Subregion
->AreaTypeGuidString
);
1854 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1855 Subregion
->AreaTypeGuid
.Data1
,
1856 (unsigned int) Subregion
->AreaTypeGuid
.Data2
,
1857 (unsigned int) Subregion
->AreaTypeGuid
.Data3
,
1858 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[0],
1859 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[1],
1860 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[2],
1861 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[3],
1862 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[4],
1863 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[5],
1864 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[6],
1865 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[7]
1869 fprintf (OutFptr
, " 1,\\\n");
1870 fprintf (OutFptr
, " {\\\n");
1871 fprintf (OutFptr
, " %s,\\\n", Subregion
->Attributes
);
1872 fprintf (OutFptr
, " 0,\\\n");
1873 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_BASE,\\\n", FBlock
->Name
, Subregion
->Name
);
1874 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_SIZE,\\\n", FBlock
->Name
, Subregion
->Name
);
1876 // The FileSystemGuid may have been specified in the input flash definition file as a GUID, or
1877 // as a quoted string. Do the right one.
1879 if (Subregion
->FileSystemGuidString
[0] != 0) {
1880 fprintf (OutFptr
, " %s, \\\n", Subregion
->FileSystemGuidString
);
1884 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1885 Subregion
->FileSystemGuid
.Data1
,
1886 (unsigned int) Subregion
->FileSystemGuid
.Data2
,
1887 (unsigned int) Subregion
->FileSystemGuid
.Data3
,
1888 (unsigned int) Subregion
->FileSystemGuid
.Data4
[0],
1889 (unsigned int) Subregion
->FileSystemGuid
.Data4
[1],
1890 (unsigned int) Subregion
->FileSystemGuid
.Data4
[2],
1891 (unsigned int) Subregion
->FileSystemGuid
.Data4
[3],
1892 (unsigned int) Subregion
->FileSystemGuid
.Data4
[4],
1893 (unsigned int) Subregion
->FileSystemGuid
.Data4
[5],
1894 (unsigned int) Subregion
->FileSystemGuid
.Data4
[6],
1895 (unsigned int) Subregion
->FileSystemGuid
.Data4
[7]
1899 fprintf (OutFptr
, " },\\\n");
1900 fprintf (OutFptr
, " },");
1906 fprintf (OutFptr
, "\n\n");
1910 // Write the file's closing #endif
1912 fprintf (OutFptr
, CIncludeFooter
);
1914 return STATUS_SUCCESS
;
1918 FDFCreateAsmIncludeFile (
1919 char *FlashDeviceName
,
1924 Routine Description:
1925 Create an assembly header file with equate definitions per an already-parsed
1926 flash definition file.
1929 FlashDeviceName - name of flash device (from the flash definition file)
1931 FileName - name of output file to create
1934 STATUS_SUCCESS - no errors or warnings
1935 STATUS_WARNING - warnings, but no errors, were encountered
1936 STATUS_ERROR - errors were encountered
1941 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1942 FLASH_DEVICE_DESCRIPTION
*FDev
;
1943 unsigned int Offset
;
1944 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1945 unsigned int SubregionOffset
;
1947 // Find the definition we're supposed to use
1949 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1950 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1956 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1957 return STATUS_ERROR
;
1960 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1961 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1962 return STATUS_ERROR
;
1967 fprintf (OutFptr
, "\n\n");
1969 // Write flash block size and offset defines
1973 "FLASH_BASE %*cequ 0%08Xh\n",
1978 fprintf (OutFptr
, "FLASH_SIZE %*cequ 0%08Xh\n", COLUMN2_START
- 40, ' ', FDev
->Size
);
1980 // Write flash region size and offset defines
1982 fprintf (OutFptr
, "\n");
1984 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1987 "FLASH_REGION_%s_BASE %*cequ 0%08Xh\n",
1989 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
1991 FDev
->BaseAddress
+ Offset
1995 "FLASH_REGION_%s_SIZE %*cequ 0%08Xh\n",
1997 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2003 "FLASH_REGION_%s_OFFSET %*cequ 0%08Xh\n",
2005 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2010 // Create defines for any subregions
2012 SubregionOffset
= 0;
2013 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2016 "FLASH_REGION_%s_SUBREGION_%s_BASE %*cequ 0%08Xh\n",
2019 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2021 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2025 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*cequ 0%08Xh\n",
2028 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2034 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*cequ 0%08Xh\n",
2037 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2039 Offset
+ SubregionOffset
2041 SubregionOffset
+= Subregion
->Size
;
2044 Offset
+= FBlock
->Size
;
2050 fprintf (OutFptr
, "\n\n");
2052 return STATUS_SUCCESS
;
2057 char *FlashDeviceName
2061 Routine Description:
2062 Using the given flash device name, add symbols to the global symbol table. This
2063 allows other functions to use the symbol definitions for other purposes.
2066 FlashDeviceName - name of flash device (from the flash definition file)
2070 STATUS_SUCCESS - no errors or warnings
2071 STATUS_WARNING - warnings, but no errors, were encountered
2072 STATUS_ERROR - errors were encountered
2076 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2077 FLASH_DEVICE_DESCRIPTION
*FDev
;
2078 unsigned int Offset
;
2081 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2082 unsigned int SubregionOffset
;
2084 // Find the definition we're supposed to use
2086 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2087 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2093 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
2094 return STATUS_ERROR
;
2097 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
);
2098 SymbolAdd ("FLASH_BASE", SymValue
, 0);
2099 sprintf (SymValue
, "0x%08X", FDev
->Size
);
2100 SymbolAdd ("FLASH_SIZE", SymValue
, 0);
2102 // Add flash block size and offset defines
2105 // for (FBlock = FDev->PBlocks; FBlock != NULL; FBlock = FBlock->Next) {
2106 // sprintf (SymName, "FLASH_BLOCK_%s_BASE", FBlock->Name);
2107 // sprintf (SymValue, "0x%08X", FDev->BaseAddress + Offset);
2108 // SymbolAdd (SymName, SymValue, 0);
2109 // sprintf (SymName, "FLASH_BLOCK_%s_SIZE", FBlock->Name);
2110 // sprintf (SymValue, "0x%08X", FBlock->Size);
2111 // SymbolAdd (SymName, SymValue, 0);
2112 // sprintf (SymName, "FLASH_BLOCK_%s_OFFSET", FBlock->Name);
2113 // sprintf (SymValue, "0x%08X", Offset);
2114 // SymbolAdd (SymName, SymValue, 0);
2115 // Offset += FBlock->Size;
2118 // Add flash region block base, size, and offset defines
2121 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2122 sprintf (SymName
, "FLASH_REGION_%s_BASE", FBlock
->Name
);
2123 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
);
2124 SymbolAdd (SymName
, SymValue
, 0);
2125 sprintf (SymName
, "FLASH_REGION_%s_SIZE", FBlock
->Name
);
2126 sprintf (SymValue
, "0x%08X", FBlock
->Size
);
2127 SymbolAdd (SymName
, SymValue
, 0);
2128 sprintf (SymName
, "FLASH_REGION_%s_OFFSET", FBlock
->Name
);
2129 sprintf (SymValue
, "0x%08X", Offset
);
2130 SymbolAdd (SymName
, SymValue
, 0);
2132 // Add subregion symbols
2134 if (FBlock
->Subregions
!= NULL
) {
2135 SubregionOffset
= 0;
2136 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2137 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_BASE", FBlock
->Name
, Subregion
->Name
);
2138 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
+ SubregionOffset
);
2139 SymbolAdd (SymName
, SymValue
, 0);
2140 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_SIZE", FBlock
->Name
, Subregion
->Name
);
2141 sprintf (SymValue
, "0x%08X", Subregion
->Size
);
2142 SymbolAdd (SymName
, SymValue
, 0);
2143 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_OFFSET", FBlock
->Name
, Subregion
->Name
);
2144 sprintf (SymValue
, "0x%08X", Offset
+ SubregionOffset
);
2145 SymbolAdd (SymName
, SymValue
, 0);
2146 SubregionOffset
+= Subregion
->Size
;
2150 Offset
+= FBlock
->Size
;
2153 return STATUS_SUCCESS
;
2158 char *FlashDeviceName
,
2164 Routine Description:
2165 Create a flash image using the given device and image names.
2168 FlashDeviceName - name of flash device (from the flash definition file)
2170 ImageName - name of image (from the flash definition file) to create
2171 FileName - name of output file to create
2174 STATUS_SUCCESS - no errors or warnings
2175 STATUS_WARNING - warnings, but no errors, were encountered
2176 STATUS_ERROR - errors were encountered
2182 FLASH_BLOCK_DESCRIPTION
*RegionDef
;
2183 FLASH_DEVICE_DESCRIPTION
*FDev
;
2184 IMAGE_DEFINITION
*ImageDef
;
2185 unsigned int Offset
;
2189 IMAGE_DEFINITION_ENTRY
*IDefEntry
;
2190 FLASH_SUBREGION_DESCRIPTION
*SubregionDef
;
2192 // Find the flash definition we're supposed to use
2195 Status
= STATUS_ERROR
;
2196 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2197 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2203 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2204 return STATUS_ERROR
;
2207 // Find the image name we're supposed to create
2209 for (ImageDef
= mImageDefinitions
; ImageDef
!= NULL
; ImageDef
= ImageDef
->Next
) {
2210 if (strcmp (ImageDef
->Name
, ImageName
) == 0) {
2215 if (ImageDef
== NULL
) {
2216 Error (NULL
, 0, 0, ImageName
, "image definition not found in image definitions");
2217 return STATUS_ERROR
;
2220 // Open the output file
2222 if ((OutFptr
= fopen (FileName
, "wb")) == NULL
) {
2223 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2224 return STATUS_ERROR
;
2227 // Allocate a buffer to copy the input data to
2229 Buffer
= (char *) _malloc (FDev
->Size
);
2230 if (Buffer
== NULL
) {
2231 Error (NULL
, 0, 0, (INT8
*) "failed to allocate memory", NULL
);
2235 // Set contents of buffer to the erased value
2237 if (FDev
->ErasePolarity
) {
2238 memset (Buffer
, 0xFF, FDev
->Size
);
2240 memset (Buffer
, 0, FDev
->Size
);
2243 // Set all region and subregion size-left fields to the size of the region/subregion
2245 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2246 RegionDef
->SizeLeft
= RegionDef
->Size
;
2247 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2248 SubregionDef
->SizeLeft
= SubregionDef
->Size
;
2252 // Now go through the image list, read files into the buffer.
2254 for (IDefEntry
= ImageDef
->Entries
; IDefEntry
!= NULL
; IDefEntry
= IDefEntry
->Next
) {
2256 // If it's a file name, open the file, get the size, find the corresponding
2257 // flash region it's in, and copy the data.
2259 if (IDefEntry
->IsRawData
== 0) {
2260 if ((InFptr
= fopen (IDefEntry
->Name
, "rb")) == NULL
) {
2261 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to open input file for reading");
2265 fseek (InFptr
, 0, SEEK_END
);
2266 FileSize
= ftell (InFptr
);
2267 fseek (InFptr
, 0, SEEK_SET
);
2269 FileSize
= IDefEntry
->RawDataSize
;
2272 // Find the region/subregion it's in, see if we have space left
2275 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2276 if (strcmp (RegionDef
->Name
, IDefEntry
->RegionName
) == 0) {
2280 Offset
+= RegionDef
->Size
;
2283 if (RegionDef
== NULL
) {
2284 Error (NULL
, 0, 0, IDefEntry
->RegionName
, "Region name not found in FlashDevice %s definition", FDev
->Name
);
2289 // Check for subregion
2291 if (IDefEntry
->SubregionName
[0] != 0) {
2292 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2293 if (strcmp (SubregionDef
->Name
, IDefEntry
->SubregionName
) == 0) {
2297 Offset
+= SubregionDef
->Size
;
2300 if (SubregionDef
== NULL
) {
2305 IDefEntry
->SubregionName
,
2306 "Subregion name not found in FlashDevice %s.%s Region definition",
2313 // Enough space in the subregion?
2315 if (SubregionDef
->SizeLeft
< (unsigned int) FileSize
) {
2321 "insufficient space in Subregion (at least 0x%X additional bytes required)",
2322 FileSize
- SubregionDef
->SizeLeft
2328 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2330 if (IDefEntry
->IsRawData
== 0) {
2331 if (fread (Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2332 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2340 Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
),
2342 IDefEntry
->RawDataSize
2346 SubregionDef
->SizeLeft
-= FileSize
;
2348 // Align based on the Region alignment requirements.
2350 if (RegionDef
->Alignment
!= 0) {
2351 while (((unsigned int) (SubregionDef
->Size
- SubregionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2352 if (SubregionDef
->SizeLeft
== 0) {
2356 SubregionDef
->SizeLeft
--;
2361 // Placing data in a region. Check for enough space in the region left.
2363 if (RegionDef
->SizeLeft
< (unsigned int) FileSize
) {
2369 "insufficient space in Region (at least 0x%X additional bytes required)",
2370 FileSize
- RegionDef
->SizeLeft
2376 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2378 if (IDefEntry
->IsRawData
== 0) {
2379 if (fread (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2380 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2387 memcpy (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), IDefEntry
->RawData
, IDefEntry
->RawDataSize
);
2390 RegionDef
->SizeLeft
-= FileSize
;
2394 if (RegionDef
->Alignment
!= 0) {
2395 while (((unsigned int) (RegionDef
->Size
- RegionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2396 if (RegionDef
->SizeLeft
== 0) {
2400 RegionDef
->SizeLeft
--;
2406 if (fwrite (Buffer
, FDev
->Size
, 1, OutFptr
) != 1) {
2407 Error (NULL
, 0, 0, "failed to write buffer contents to output file", NULL
);
2411 Status
= STATUS_SUCCESS
;
2413 if (InFptr
!= NULL
) {
2417 if (Buffer
!= NULL
) {
2421 if (OutFptr
!= NULL
) {
2423 if (Status
== STATUS_ERROR
) {
2433 char *FlashDeviceName
,
2438 Routine Description:
2439 Create a DSC-style output file with equates for flash management.
2442 FlashDeviceName - name of flash device (from the flash definition file)
2444 FileName - name of output file to create
2447 STATUS_SUCCESS - no errors or warnings
2448 STATUS_WARNING - warnings, but no errors, were encountered
2449 STATUS_ERROR - errors were encountered
2454 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2455 FLASH_DEVICE_DESCRIPTION
*FDev
;
2456 unsigned int Offset
;
2457 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2458 unsigned int SubregionOffset
;
2460 // Find the definition we're supposed to use
2462 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2463 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2469 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2470 return STATUS_ERROR
;
2473 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
2474 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2475 return STATUS_ERROR
;
2478 // Write the flash base address and size
2480 fprintf (OutFptr
, "\n");
2481 fprintf (OutFptr
, "FLASH_BASE = 0x%08X\n", FDev
->BaseAddress
);
2482 fprintf (OutFptr
, "FLASH_SIZE = 0x%08X\n\n", FDev
->Size
);
2484 // Write flash block size and offset defines
2487 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2490 "FLASH_REGION_%s_BASE %*c= 0x%08X\n",
2492 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2494 Offset
+ FDev
->BaseAddress
2498 "FLASH_REGION_%s_SIZE %*c= 0x%08X\n",
2500 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2506 "FLASH_REGION_%s_SIZE_BLOCKS %*c= 0x%x\n",
2508 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2510 (FBlock
->Size
)/(FDev
->PBlocks
->Size
)
2513 // Create defines for any subregions
2515 SubregionOffset
= 0;
2516 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2519 "FLASH_REGION_%s_SUBREGION_%s_BASE %*c= 0x%08X\n",
2522 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2524 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2528 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*c= 0x%08X\n",
2531 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2537 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c= 0x%08X\n",
2540 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2542 Offset
+ SubregionOffset
2545 SubregionOffset
+= Subregion
->Size
;
2548 Offset
+= FBlock
->Size
;
2553 fprintf (OutFptr
, "\n");
2555 return STATUS_SUCCESS
;
2561 Routine Description:
2562 The following buffer management routines are used to encapsulate functionality
2563 for managing a growable data buffer.
2566 BUFFER_DATA - structure that is used to maintain a data buffer
2579 Routine Description:
2581 Create a growable data buffer with default buffer length.
2589 NULL - error occured during data buffer creation
2590 Not NULL - the pointer to the newly created data buffer
2595 BD
= (BUFFER_DATA
*) _malloc (sizeof (BUFFER_DATA
));
2597 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2601 memset (BD
, 0, sizeof (BUFFER_DATA
));
2602 BD
->BufferStart
= (char *) _malloc (BUFFER_SIZE
);
2603 if (BD
->BufferStart
== NULL
) {
2605 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2609 BD
->BufferEnd
= BD
->BufferStart
+ BUFFER_SIZE
;
2610 BD
->BufferPos
= BD
->BufferStart
;
2617 BUFFER_DATA
*Buffer
,
2622 Routine Description:
2624 Add a single byte to a growable data buffer, growing the buffer if required.
2628 Buffer - pointer to the growable data buffer to add a single byte to
2629 Data - value of the single byte data to be added
2633 TRUE - the single byte data was successfully added
2634 FALSE - error occurred, the single byte data was not added
2641 // See if we have to grow the buffer
2643 if (Buffer
->BufferPos
>= Buffer
->BufferEnd
) {
2644 Size
= (int) Buffer
->BufferEnd
- (int) Buffer
->BufferStart
;
2645 NewBuffer
= (char *) _malloc (Size
+ BUFFER_SIZE
);
2646 if (NewBuffer
== NULL
) {
2647 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2651 memcpy (NewBuffer
, Buffer
->BufferStart
, Size
);
2652 _free (Buffer
->BufferStart
);
2653 Buffer
->BufferStart
= NewBuffer
;
2654 Buffer
->BufferPos
= Buffer
->BufferStart
+ Size
;
2655 Buffer
->BufferEnd
= Buffer
->BufferStart
+ Size
+ BUFFER_SIZE
;
2658 *Buffer
->BufferPos
= Data
;
2659 Buffer
->BufferPos
++;
2666 BUFFER_DATA
*Buffer
,
2671 Routine Description:
2673 Free memory used to manage a growable data buffer.
2677 Buffer - pointer to the growable data buffer to be destructed
2678 FreeData - TRUE, free memory containing the buffered data
2679 FALSE, do not free the buffered data memory
2687 if (Buffer
!= NULL
) {
2688 if (FreeData
&& (Buffer
->BufferStart
!= NULL
)) {
2689 _free (Buffer
->BufferStart
);
2699 BUFFER_DATA
*Buffer
,
2704 Routine Description:
2706 Return a pointer and size of the data in a growable data buffer.
2710 Buffer - pointer to the growable data buffer
2711 BufferSize - size of the data in the growable data buffer
2715 pointer of the data in the growable data buffer
2719 *BufferSize
= (int) Buffer
->BufferPos
- (int) Buffer
->BufferStart
;
2720 return Buffer
->BufferStart
;
2726 unsigned int BaseAddr
2730 Routine Description:
2731 Walk a binary image and see if you find anything that looks like a
2735 FDFileName - name of input FD image to parse
2736 BaseAddr - base address of input FD image
2739 STATUS_SUCCESS - no errors or warnings
2740 STATUS_WARNING - warnings, but no errors, were encountered
2741 STATUS_ERROR - errors were encountered
2744 This routine is used for debug purposes only.
2751 EFI_FIRMWARE_VOLUME_HEADER FVHeader
;
2753 FileSystemGuid
= { 0x7A9354D9, 0x0468, 0x444a, 0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF };
2755 if ((InFptr
= fopen (FDFileName
, "rb")) == NULL
) {
2756 Error (NULL
, 0, 0, FDFileName
, "failed to open file for reading");
2757 return STATUS_ERROR
;
2760 fseek (InFptr
, 0, SEEK_END
);
2761 FileSize
= ftell (InFptr
);
2762 fseek (InFptr
, 0, SEEK_SET
);
2764 while (Offset
< FileSize
) {
2765 fseek (InFptr
, Offset
, SEEK_SET
);
2767 // Read the contents of the file, see if it's an FV header
2769 if (fread (&FVHeader
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
), 1, InFptr
) == 1) {
2771 // Check version and GUID
2773 if ((FVHeader
.Revision
== EFI_FVH_REVISION
) && (FVHeader
.Signature
== EFI_FVH_SIGNATURE
)) {
2774 fprintf (stdout
, "FV header at 0x%08X FVSize=0x%08X ", Offset
+ BaseAddr
, (UINT32
) FVHeader
.FvLength
);
2775 if (memcmp (&FVHeader
.FileSystemGuid
, &FileSystemGuid
, sizeof (EFI_GUID
)) == 0) {
2776 fprintf (stdout
, "standard FFS file system\n");
2778 fprintf (stdout
, "non-standard FFS file system\n");
2783 Offset
+= 16 * 1024;
2787 return STATUS_SUCCESS
;