3 Copyright (c) 2004-2005 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
19 Utility for flash management in the Intel Platform Innovation Framework
20 for EFI build environment.
27 #include <UefiBaseTypes.h>
30 #include "EfiUtilityMsgs.h"
31 #include "FlashDefFile.h"
32 #include "SimpleFileParsing.h"
34 // #include "EfiFirmwareVolumeHeader.h"
35 #include "MultiPhase.h"
36 #include "FirmwareVolumeHeader.h"
39 // #include "TrackMallocFree.h"
42 #define MAX_STRING_LEN 256
43 #define MAX_NAME_LEN 128
44 #define BUFFER_SIZE 1024
45 #define MAX_ATTR_LEN 128
46 #define MAX_AREATYPE_LEN 128
47 #define COLUMN2_START 60
48 #define COLUMN3_START 70
50 // Information for each subregions defined in the fdf file will be saved in these
52 typedef struct _FLASH_SUBREGION_DESCRIPTION
{
53 struct _FLASH_SUBREGION_DESCRIPTION
*Next
;
54 int CreateHob
; // to add to the auto-created HOB array
55 WCHAR_T Name
[MAX_NAME_LEN
]; // each subregion within a region must have a unique name
56 unsigned int Size
; // size, in bytes, of this subregion
57 unsigned int SizeLeft
; // used when creating the image
58 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // subregion attributes used in the output HOB
59 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // subregion area type used in the output HOB
60 EFI_GUID NameGuid
; // used in the output HOB
61 WCHAR_T NameGuidString
[MAX_NAME_LEN
];
62 EFI_GUID AreaTypeGuid
; // used in the output HOB
63 WCHAR_T AreaTypeGuidString
[MAX_NAME_LEN
];
64 EFI_GUID FileSystemGuid
; // used in the output HOB
65 WCHAR_T FileSystemGuidString
[MAX_NAME_LEN
];
66 } FLASH_SUBREGION_DESCRIPTION
;
69 // Information for each block in a flash device will be saved in one of these.
70 // We'll also use it for region definitions.
72 typedef struct _FLASH_BLOCK_DESCRIPTION
{
73 struct _FLASH_BLOCK_DESCRIPTION
*Next
; // next block in the linked list
74 WCHAR_T Name
[MAX_NAME_LEN
]; // each block must have a unique name
75 unsigned int Size
; // size, in bytes, of this block
76 unsigned int SizeLeft
; // for use when creating image
77 unsigned int Flags
; // user-defined flags for the block
78 unsigned int Alignment
; // power of 2 alignment
79 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // only used for Region definitions
80 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // only used for Region definitions
81 FLASH_SUBREGION_DESCRIPTION
*Subregions
;
82 FLASH_SUBREGION_DESCRIPTION
*LastSubregion
;
83 } FLASH_BLOCK_DESCRIPTION
;
86 // Information for each flash device will be saved in one of these
88 typedef struct _FLASH_DEVICE_DESCRIPTION
{
89 struct _FLASH_DEVICE_DESCRIPTION
*Next
; // next flash device in our linked list
90 int ErasePolarity
; // erase polarity of the flash device
91 unsigned int BaseAddress
; // base address of the flash device
92 unsigned int Size
; // total size, in bytes, of the flash device
93 WCHAR_T Name
[MAX_NAME_LEN
]; // name of the flash device
94 FLASH_BLOCK_DESCRIPTION
*PBlocks
; // linked list of physical block descriptors
95 FLASH_BLOCK_DESCRIPTION
*LastPBlock
; // last block in the linked list
96 FLASH_BLOCK_DESCRIPTION
*Regions
; // linked list of flash region descriptors
97 FLASH_BLOCK_DESCRIPTION
*LastRegion
; // last region in the linked list
98 } FLASH_DEVICE_DESCRIPTION
;
101 // For image definitions, they can specify a file name or raw data bytes. Keep a linked list.
103 typedef struct _IMAGE_DEFINITION_ENTRY
{
104 struct _IMAGE_DEFINITION_ENTRY
*Next
;
105 WCHAR_T RegionName
[MAX_NAME_LEN
];
106 WCHAR_T SubregionName
[MAX_NAME_LEN
];
107 WCHAR_T Name
[MAX_NAME_LEN
]; // file or data name
108 int IsRawData
; // non-zero if raw data bytes
109 unsigned int RawDataSize
;
111 int Optional
; // optional file (don't include if it doesn't exist)
112 } IMAGE_DEFINITION_ENTRY
;
115 // When we parse an image definition, save all the data for each in one of these
117 typedef struct _IMAGE_DEFINITION
{
118 struct _IMAGE_DEFINITION
*Next
;
119 WCHAR_T Name
[MAX_NAME_LEN
];
120 IMAGE_DEFINITION_ENTRY
*Entries
;
121 IMAGE_DEFINITION_ENTRY
*LastEntry
;
130 static const char *CIncludeHeader
= "/*++\n\n"
131 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n""#ifndef _FLASH_MAP_H_\n"
132 "#define _FLASH_MAP_H_\n\n";
134 // "#include \"EfiFlashMap.h\"\n\n";
136 static const char *CIncludeFooter
= "#endif // #ifndef _FLASH_MAP_H_\n\n";
138 static const char *CFlashMapDataFileHeader
= "/*++\n\n"
139 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n";
141 static FLASH_DEVICE_DESCRIPTION
*mFlashDevices
= NULL
;
142 static IMAGE_DEFINITION
*mImageDefinitions
= NULL
;
145 // Local function prototypes
175 FLASH_SUBREGION_DESCRIPTION
*
176 ParseSubregionDefinition (
177 unsigned int SizeLeft
187 Initialization routine for the services that operate on a flash
198 mFlashDevices
= NULL
;
199 mImageDefinitions
= NULL
;
209 Finalization/cleanup routine for the services that operate on a flash
220 FLASH_BLOCK_DESCRIPTION
*FBNext
;
221 FLASH_DEVICE_DESCRIPTION
*FDNext
;
222 IMAGE_DEFINITION
*IDNext
;
223 IMAGE_DEFINITION_ENTRY
*IDENext
;
224 FLASH_SUBREGION_DESCRIPTION
*SubNext
;
226 // Go through all our flash devices and free the memory
228 while (mFlashDevices
!= NULL
) {
230 // Free the physical block definitions
232 while (mFlashDevices
->PBlocks
!= NULL
) {
233 FBNext
= mFlashDevices
->PBlocks
->Next
;
234 _free (mFlashDevices
->PBlocks
);
235 mFlashDevices
->PBlocks
= FBNext
;
238 // Free the region definitions
240 while (mFlashDevices
->Regions
!= NULL
) {
241 FBNext
= mFlashDevices
->Regions
->Next
;
243 // First free the subregion definitions
245 while (mFlashDevices
->Regions
->Subregions
!= NULL
) {
246 SubNext
= mFlashDevices
->Regions
->Subregions
->Next
;
247 _free (mFlashDevices
->Regions
->Subregions
);
248 mFlashDevices
->Regions
->Subregions
= SubNext
;
251 _free (mFlashDevices
->Regions
);
252 mFlashDevices
->Regions
= FBNext
;
255 FDNext
= mFlashDevices
->Next
;
256 _free (mFlashDevices
);
257 mFlashDevices
= FDNext
;
260 // Free up the image definitions, and the data
262 while (mImageDefinitions
!= NULL
) {
266 while (mImageDefinitions
->Entries
!= NULL
) {
267 IDENext
= mImageDefinitions
->Entries
->Next
;
268 if (mImageDefinitions
->Entries
->RawData
!= NULL
) {
269 _free (mImageDefinitions
->Entries
->RawData
);
272 _free (mImageDefinitions
->Entries
);
273 mImageDefinitions
->Entries
= IDENext
;
276 IDNext
= mImageDefinitions
->Next
;
277 _free (mImageDefinitions
);
278 mImageDefinitions
= IDNext
;
289 Parse the specified flash definition file, saving the definitions in
290 file-static variables for use by other functions.
293 FileName - name of the input flash definition text file.
296 STATUS_SUCCESS - file parsed with no errors or warnings
297 STATUS_WARNING - warnings, but no errors, were encountered while parsing
298 STATUS_ERROR - errors were encountered while parsing
305 FLASH_DEVICE_DESCRIPTION
*FDDesc
;
306 FLASH_BLOCK_DESCRIPTION
*FBlockDesc
;
307 FLASH_BLOCK_DESCRIPTION
*TempBlockDesc
;
308 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
309 FLASH_SUBREGION_DESCRIPTION
*TempSubregion
;
310 unsigned int BlockSizeLeft
;
311 unsigned int RegionSizeLeft
;
312 unsigned int SubregionSizeLeft
;
315 IMAGE_DEFINITION
*ImageDef
;
316 IMAGE_DEFINITION_ENTRY
*ImageDefEntry
;
317 IMAGE_DEFINITION_ENTRY
*TempImageDefEntry
;
318 BUFFER_DATA
*BufferData
;
320 BOOLEAN PreviousComma
;
322 if ((Fptr
= fopen (FileName
, "r")) == NULL
) {
323 Error (NULL
, 0, 0, FileName
, "failed to open input flash definition file for reading");
328 Status
= STATUS_SUCCESS
;
332 // Initialize the simple-file-parsing routines
338 if ((Status
= SFPOpenFile (FileName
)) != STATUS_SUCCESS
) {
342 // Parse the file. Should start with a series of these:
344 // Name = "FLASH_1234", Size = 0x2004, BaseAddress = 0xFFF0000, ErasePolarity = 1,
345 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
346 // Block { Name = "BLOCK2", Size = 0x1004, Flags = 0x0002 }
347 // Region { Name = "REGION_NAME", Size = 0x2004, Align= 4 }
350 while (SFPIsKeyword ("FlashDevice")) {
352 // Allocate memory for new flash device description block
354 FDDesc
= (FLASH_DEVICE_DESCRIPTION
*) _malloc (sizeof (FLASH_DEVICE_DESCRIPTION
));
355 if (FDDesc
== NULL
) {
356 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
361 memset (FDDesc
, 0, sizeof (FLASH_DEVICE_DESCRIPTION
));
363 // Open brace -- warning if not there
365 if (!SFPIsToken ("{")) {
366 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
370 // Parse: Name = "DeviceName",
372 if (!SFPIsKeyword ("Name")) {
373 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
378 if (!SFPIsToken ("=")) {
379 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
383 if (!SFPGetQuotedString (FDDesc
->Name
, sizeof (FDDesc
->Name
))) {
384 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of flash device", NULL
);
389 if (!SFPIsToken (",")) {
390 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following flash device name", NULL
);
394 // Parse: Size = 0x20000,
396 if (!SFPIsKeyword ("Size")) {
397 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
402 if (!SFPIsToken ("=")) {
403 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
407 if (!SFPGetNumber (&FDDesc
->Size
)) {
408 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
415 if (FDDesc
->Size
== 0) {
416 Error (SFPGetFileName (), SFPGetLineNumber (), 0, FDDesc
->Name
, "Size field cannot be 0", NULL
);
423 // Parse: BaseAddress = 0xFFF0000,
425 if (!SFPIsKeyword ("BaseAddress")) {
426 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'BaseAddress'", NULL
);
431 if (!SFPIsToken ("=")) {
432 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
436 if (!SFPGetNumber (&FDDesc
->BaseAddress
)) {
437 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for BaseAddress", NULL
);
442 if (!SFPIsToken (",")) {
443 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following BaseAddress value", NULL
);
447 // Parse: ErasePolarity = 1,
449 if (!SFPIsKeyword ("ErasePolarity")) {
450 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'ErasePolarity'", NULL
);
455 if (!SFPIsToken ("=")) {
456 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
460 if (!SFPGetNumber (&Num
) || ((Num
!= 0) && (Num
!= 1))) {
461 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric erase polarity value 1 or 0", NULL
);
466 FDDesc
->ErasePolarity
= Num
;
467 if (!SFPIsToken (",")) {
468 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following erase polarity value", NULL
);
473 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
475 // Keep track of size to make sure the sum of the physical blocks and region sizes do not
476 // exceed the size of the flash device.
478 BlockSizeLeft
= FDDesc
->Size
;
479 RegionSizeLeft
= FDDesc
->Size
;
480 while (SFPIsKeyword ("Block")) {
482 // Allocate memory for a new physical block descriptor
484 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
485 if (FBlockDesc
== NULL
) {
486 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
491 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
493 // Open brace -- warning if not there
495 if (!SFPIsToken ("{")) {
496 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
500 // Parse: Name = "BlockName",
502 if (!SFPIsKeyword ("Name")) {
503 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
508 if (!SFPIsToken ("=")) {
509 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
513 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
514 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of physical block", NULL
);
519 // Make sure there are no other physical block names with this same name
521 for (TempBlockDesc
= FDDesc
->PBlocks
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
522 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
528 "physical block with this name already defined"
534 if (!SFPIsToken (",")) {
535 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following physical block name", NULL
);
539 // Parse: Size = 0x2000,
541 if (!SFPIsKeyword ("Size")) {
542 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
547 if (!SFPIsToken ("=")) {
548 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
552 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
553 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
558 // Make sure the sum of physical blocks so far does not exceed flash device size
560 if (BlockSizeLeft
< FBlockDesc
->Size
) {
565 "sum of physical block sizes exceeds flash device size",
571 BlockSizeLeft
-= FBlockDesc
->Size
;
574 // Optional parse: Flags = 0xFFF0000,
576 if (SFPIsKeyword ("Flags")) {
577 if (!SFPIsToken ("=")) {
578 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
582 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
583 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
589 if (!SFPIsToken ("}")) {
590 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected PhysicalBlock closing brace '}'", NULL
);
594 // Add the physical block descriptor to the end of the linked list
596 if (FDDesc
->LastPBlock
!= NULL
) {
597 FDDesc
->LastPBlock
->Next
= FBlockDesc
;
599 FDDesc
->PBlocks
= FBlockDesc
;
602 FDDesc
->LastPBlock
= FBlockDesc
;
605 // Make sure sum of sizes of physical blocks added up to size of flash device
607 if (BlockSizeLeft
!= 0) {
613 "sum of sizes of physical blocks (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
614 FDDesc
->Size
- BlockSizeLeft
,
622 // Region { Name = "REGION_1", Size = 0x2000, Flags = 0x1234, Alignment = 4, Attributes = "str", AreaType = "str" }
624 while (SFPIsKeyword ("Region")) {
626 // Allocate memory for a new physical block descriptor
628 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
629 if (FBlockDesc
== NULL
) {
630 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
635 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
637 // Open brace -- warning if not there
639 if (!SFPIsToken ("{")) {
640 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
644 // Parse: Name = "BlockName",
646 if (!SFPIsKeyword ("Name")) {
647 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
652 if (!SFPIsToken ("=")) {
653 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
657 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
658 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
663 // Make sure there are no other region names with this same name
665 for (TempBlockDesc
= FDDesc
->Regions
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
666 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
672 "Region with this name already defined"
678 if (!SFPIsToken (",")) {
679 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
683 // Parse: Size = 0x2000,
685 if (!SFPIsKeyword ("Size")) {
686 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
691 if (!SFPIsToken ("=")) {
692 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
696 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
697 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
702 if (!SFPIsToken (",")) {
703 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
706 // Make sure the sum of regions so far does not exceed flash device size
708 if (RegionSizeLeft
< FBlockDesc
->Size
) {
709 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Region sizes exceeds flash device size", NULL
);
713 RegionSizeLeft
-= FBlockDesc
->Size
;
715 // Optional parse: Flags = 0xFFF0000,
717 if (SFPIsKeyword ("Flags")) {
718 if (!SFPIsToken ("=")) {
719 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
723 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
724 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
731 if (!SFPIsToken (",")) {
732 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
736 // Optional parse: Alignment = 4
738 if (SFPIsKeyword ("Alignment")) {
739 if (!SFPIsToken ("=")) {
740 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
744 if (!SFPGetNumber (&FBlockDesc
->Alignment
)) {
745 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Alignment value", NULL
);
752 if (!SFPIsToken (",")) {
753 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
757 // Parse: Attributes = "String",
759 if (!SFPIsKeyword ("Attributes")) {
760 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
765 if (!SFPIsToken ("=")) {
766 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
770 if (!SFPGetQuotedString (FBlockDesc
->Attributes
, sizeof (FBlockDesc
->Attributes
))) {
771 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
776 if (!SFPIsToken (",")) {
777 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
780 // Parse: AreaType = "String",
782 if (!SFPIsKeyword ("AreaType")) {
783 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
788 if (!SFPIsToken ("=")) {
789 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
793 if (!SFPGetQuotedString (FBlockDesc
->AreaType
, sizeof (FBlockDesc
->AreaType
))) {
794 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
799 PreviousComma
= SFPIsToken (",");
801 // Parse optional Subregion definitions
803 SubregionSizeLeft
= FBlockDesc
->Size
;
804 while (SFPIsToken ("Subregion")) {
805 if (!PreviousComma
) {
806 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'Subregion'", NULL
);
808 PreviousComma
= TRUE
;
811 Subregion
= ParseSubregionDefinition (SubregionSizeLeft
);
812 if (Subregion
== NULL
) {
817 SubregionSizeLeft
-= Subregion
->Size
;
819 // Add it to the end of our list
821 if (FBlockDesc
->Subregions
== NULL
) {
822 FBlockDesc
->Subregions
= Subregion
;
824 FBlockDesc
->LastSubregion
->Next
= Subregion
;
827 FBlockDesc
->LastSubregion
= Subregion
;
829 // Make sure all subregion names are unique. We do this each time
830 // through so that we catch the error immediately after it happens, in
831 // which case the reported line number is at least close to where the
832 // problem lies. We don't exit on the error because we can continue parsing
833 // the script to perhaps catch other errors or warnings.
835 for (Subregion
= FBlockDesc
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
836 for (TempSubregion
= Subregion
->Next
; TempSubregion
!= NULL
; TempSubregion
= TempSubregion
->Next
) {
837 if (strcmp (Subregion
->Name
, TempSubregion
->Name
) == 0) {
838 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Subregion
->Name
, "duplicate Subregion name");
845 if (!SFPIsToken ("}")) {
846 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Region closing brace '}'", NULL
);
850 // Add the region descriptor to the end of the linked list
852 if (FDDesc
->LastRegion
!= NULL
) {
853 FDDesc
->LastRegion
->Next
= FBlockDesc
;
855 FDDesc
->Regions
= FBlockDesc
;
858 FDDesc
->LastRegion
= FBlockDesc
;
861 // Make sure sum of sizes of regions adds up to size of flash device
863 if (RegionSizeLeft
!= 0) {
869 "sum of sizes of Regions (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
870 FDDesc
->Size
- RegionSizeLeft
,
877 // Look for closing brace
879 if (!SFPIsToken ("}")) {
880 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected FlashDevice closing brace '}'", NULL
);
884 // Add this flash description to the list
886 FDDesc
->Next
= mFlashDevices
;
887 mFlashDevices
= FDDesc
;
890 while (SFPIsKeyword ("FlashDeviceImage")) {
892 // Allocate memory for a new FD image definition
894 ImageDef
= (IMAGE_DEFINITION
*) _malloc (sizeof (IMAGE_DEFINITION
));
895 if (ImageDef
== NULL
) {
896 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
901 memset (ImageDef
, 0, sizeof (IMAGE_DEFINITION
));
903 // Open brace -- warning if not there
905 if (!SFPIsToken ("{")) {
906 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
910 // Parse: Name = "ImageName",
912 if (!SFPIsKeyword ("Name")) {
913 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
918 if (!SFPIsToken ("=")) {
919 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
923 if (!SFPGetQuotedString (ImageDef
->Name
, sizeof (ImageDef
->Name
))) {
924 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of image", NULL
);
929 if (!SFPIsToken (",")) {
930 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following image name", NULL
);
936 // Parse: File { Name = "FV\FvOem.fv", Region = "REGION_OEM", Optional = TRUE }
938 if (SFPIsKeyword ("File")) {
939 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
940 if (ImageDefEntry
== NULL
) {
941 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
946 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
948 // Open brace -- warning if not there
950 if (!SFPIsToken ("{")) {
951 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
955 // Parse: Name = "FileName.txt"
957 if (!SFPIsKeyword ("Name")) {
958 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
963 if (!SFPIsToken ("=")) {
964 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
968 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
969 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of file", NULL
);
974 if (!SFPIsToken (",")) {
975 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following file name", NULL
);
979 // Parse: Region = "REGION_NAME"
981 if (!SFPIsKeyword ("Region")) {
982 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
987 if (!SFPIsToken ("=")) {
988 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
992 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
993 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
998 if (!SFPIsToken (",")) {
999 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1003 // Parse optional: Subregion = "SUBREGION_NAME"
1005 if (SFPIsKeyword ("Subregion")) {
1006 if (!SFPIsToken ("=")) {
1007 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1011 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1012 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1017 if (!SFPIsToken (",")) {
1018 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1022 // For a given region, you can only place data using the region name, or the subregion names.
1023 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1024 // here by checking that any previous entries with the same Region name had a Subregion specified
1027 for (TempImageDefEntry
= ImageDef
->Entries
;
1028 TempImageDefEntry
!= NULL
;
1029 TempImageDefEntry
= TempImageDefEntry
->Next
1031 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1032 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1035 SFPGetLineNumber (),
1037 TempImageDefEntry
->RegionName
,
1038 "data already placed on a region-basis in the region, can't place data using subregions"
1046 // Optional parse: Optional = TRUE | FALSE
1048 if (SFPIsKeyword ("Optional")) {
1049 if (!SFPIsToken ("=")) {
1050 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1054 if (!SFPIsKeyword ("TRUE")) {
1055 ImageDefEntry
->Optional
= 1;
1056 } else if (SFPIsKeyword ("FALSE")) {
1061 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1071 if (!SFPIsToken ("}")) {
1072 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace to File entry", NULL
);
1077 // Add the entry to the end of the list
1079 if (ImageDef
->LastEntry
!= NULL
) {
1080 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1082 ImageDef
->Entries
= ImageDefEntry
;
1085 ImageDef
->LastEntry
= ImageDefEntry
;
1086 } else if (SFPIsKeyword ("RawData")) {
1088 // Parse: RawData { Name = "PadBytes", Region = "REGION_1", Data = { 0x78, 0x56, 0x34, 0x12 }}
1090 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
1091 if (ImageDefEntry
== NULL
) {
1092 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1097 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
1098 ImageDefEntry
->IsRawData
= 1;
1100 // Open brace -- warning if not there
1102 if (!SFPIsToken ("{")) {
1105 SFPGetLineNumber (),
1107 "expected '{' opening brace for RawData definition",
1113 // Parse: Name = "PadBytes"
1115 if (!SFPIsKeyword ("Name")) {
1116 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1121 if (!SFPIsToken ("=")) {
1122 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1126 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
1127 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of raw data", NULL
);
1132 if (!SFPIsToken (",")) {
1133 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following raw data name", NULL
);
1137 // Parse: Region = "REGION_NAME"
1139 if (!SFPIsKeyword ("Region")) {
1140 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
1145 if (!SFPIsToken ("=")) {
1146 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1150 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
1151 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
1156 if (!SFPIsToken (",")) {
1157 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1161 // Parse optional: Subregion = "SUBREGION_NAME"
1163 if (SFPIsKeyword ("Subregion")) {
1164 if (!SFPIsToken ("=")) {
1165 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1169 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1170 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1175 if (!SFPIsToken (",")) {
1176 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1180 // For a given region, you can only place data using the region name, or the subregion names.
1181 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1182 // here by checking that any previous entries with the same Region name had a Subregion specified
1185 for (TempImageDefEntry
= ImageDef
->Entries
;
1186 TempImageDefEntry
!= NULL
;
1187 TempImageDefEntry
= TempImageDefEntry
->Next
1189 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1190 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1193 SFPGetLineNumber (),
1195 TempImageDefEntry
->RegionName
,
1196 "data already placed on a region-basis in the region, can't place data using subregions"
1204 // Parse: Data = { 0x78, 0x56, 0x34, 0x12 }
1206 if (!SFPIsKeyword ("Data")) {
1207 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Data'", NULL
);
1212 if (!SFPIsToken ("=")) {
1213 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1217 if (!SFPIsToken ("{")) {
1218 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '{' preceeding data list", NULL
);
1222 if ((BufferData
= CreateBufferData ()) == NULL
) {
1227 // Read bytes from input file until closing brace
1229 while (!SFPIsToken ("}")) {
1230 if (!SFPGetNumber (&Num
)) {
1231 SFPGetNextToken (Str
, sizeof (Str
));
1232 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected data value", Str
);
1234 FreeBufferData (BufferData
, TRUE
);
1241 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "only values 0-255 (0x00-0xFF) allowed", NULL
);
1243 FreeBufferData (BufferData
, TRUE
);
1247 AddBufferDataByte (BufferData
, (char) Num
);
1252 // Now get the data and save it in our image entry
1254 ImageDefEntry
->RawData
= GetBufferData (BufferData
, &ImageDefEntry
->RawDataSize
);
1255 FreeBufferData (BufferData
, 0);
1257 // Closing brace for RawData {}
1259 if (!SFPIsToken ("}")) {
1260 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace for RawData", NULL
);
1265 // Add the entry to the end of the list
1267 if (ImageDef
->LastEntry
!= NULL
) {
1268 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1270 ImageDef
->Entries
= ImageDefEntry
;
1273 ImageDef
->LastEntry
= ImageDefEntry
;
1274 } else if (SFPIsToken ("}")) {
1276 // Closing brace for FDImage {}
1280 SFPGetNextToken (Str
, sizeof (Str
));
1281 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "unrecognized token", Str
);
1287 // Add this image definition to our global list
1289 ImageDef
->Next
= mImageDefinitions
;
1290 mImageDefinitions
= ImageDef
;
1293 // Check for end-of-file
1296 SFPGetNextToken (Str
, sizeof (Str
));
1297 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected end-of-file", Str
);
1303 if (ErrorCount
!= 0) {
1304 return STATUS_ERROR
;
1305 } else if (WarningCount
!= 0) {
1306 return STATUS_WARNING
;
1309 return STATUS_SUCCESS
;
1313 FLASH_SUBREGION_DESCRIPTION
*
1314 ParseSubregionDefinition (
1315 unsigned int SizeLeft
1319 Routine Description:
1321 Parse Subregion definitions from the input flash definition file. Format:
1327 Attributes = "EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV",
1328 AreaType = "EFI_FLASH_AREA_EFI_VARIABLES",
1329 NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD (or "EFI_SOME_GUID"),
1330 AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1331 FileSystemGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1334 NOTE: The caller has already parsed the "Subregion" token, so start with the opening brace.
1338 SizeLeft - in the flash definition file, a Region can be broken up into
1339 one or more subregions. As we parse the subregion definitions,
1340 the caller keeps track of how much space is left in the region
1341 that we're parsing subregions for. SizeLeft is that size, and
1342 so the size of the subregion we're now parsing better not
1343 exceed the size left.
1346 NULL - unrecoverable errors detected while parsing the subregion definition
1348 pointer to a subregion definition created from the parsed subregion
1352 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1355 unsigned int Number
;
1356 BOOLEAN PreviousComma
;
1358 // Allocate memory for the new subregion descriptor
1362 Subregion
= (FLASH_SUBREGION_DESCRIPTION
*) _malloc (sizeof (FLASH_SUBREGION_DESCRIPTION
));
1363 if (Subregion
== NULL
) {
1364 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1369 memset (Subregion
, 0, sizeof (FLASH_SUBREGION_DESCRIPTION
));
1371 // Open brace -- warning if not there
1373 if (!SFPIsToken ("{")) {
1374 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
1378 // Parse: CreateHob = TRUE | FALSE,
1380 if (!SFPIsKeyword ("CreateHob")) {
1381 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'CreateHob'", NULL
);
1386 if (!SFPIsToken ("=")) {
1387 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1391 if (SFPIsToken ("TRUE")) {
1392 Subregion
->CreateHob
= 1;
1393 } else if (SFPIsToken ("FALSE")) {
1395 // Subregion->CreateHob = 0; -- not required since we did a memset earlier
1398 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1403 if (!SFPIsToken (",")) {
1404 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following CreateHob value", NULL
);
1408 // Parse: Name = "Name",
1410 if (!SFPIsKeyword ("Name")) {
1411 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1416 if (!SFPIsToken ("=")) {
1417 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1421 if (!SFPGetQuotedString (Subregion
->Name
, sizeof (Subregion
->Name
))) {
1422 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion name", NULL
);
1427 if (!SFPIsToken (",")) {
1428 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1432 // Parse: Size = 0x2000,
1434 if (!SFPIsKeyword ("Size")) {
1435 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
1440 if (!SFPIsToken ("=")) {
1441 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1445 if (!SFPGetNumber (&Subregion
->Size
)) {
1446 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
1452 // Check that the size does not exceed the size left passed in
1454 if (Subregion
->Size
> SizeLeft
) {
1455 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Subregion sizes exceeds Region size", NULL
);
1460 if (!SFPIsToken (",")) {
1461 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following Size value", NULL
);
1464 // Parse: Attributes = Number | "String",
1466 if (!SFPIsKeyword ("Attributes")) {
1467 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
1472 if (!SFPIsToken ("=")) {
1473 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1477 if (SFPGetNumber (&Number
)) {
1478 sprintf (Subregion
->Attributes
, "0x%X", Number
);
1479 } else if (!SFPGetQuotedString (Subregion
->Attributes
, sizeof (Subregion
->Attributes
))) {
1480 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
1485 if (!SFPIsToken (",")) {
1486 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
1489 // Parse: AreaType = Number | "String",
1490 // AreaType is a UINT8, so error if it exceeds the size
1492 if (!SFPIsKeyword ("AreaType")) {
1493 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
1498 if (!SFPIsToken ("=")) {
1499 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1503 if (SFPGetNumber (&Number
)) {
1504 if (Number
> 0xFF) {
1505 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "AreaType value exceeds 255", NULL
);
1509 sprintf (Subregion
->AreaType
, "0x%X", Number
& 0x00FF);
1510 } else if (!SFPGetQuotedString (Subregion
->AreaType
, sizeof (Subregion
->AreaType
))) {
1511 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
1516 if (!SFPIsToken (",")) {
1517 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following AreaType value", NULL
);
1520 // Parse the three GUIDs (last two are optional)
1522 // NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD, (or "EFI_SOME_GUID")
1523 // AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1524 // FileSysteGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1526 if (!SFPIsKeyword ("NameGuid")) {
1527 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'NameGuid'", NULL
);
1532 if (!SFPIsToken ("=")) {
1533 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1537 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1539 if (SFPGetQuotedString (Subregion
->NameGuidString
, sizeof (Subregion
->NameGuidString
))) {
1541 // Nothing else to do
1543 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->NameGuid
)) {
1546 SFPGetLineNumber (),
1548 "expected NameGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1555 // Comma following NameGuid is optional if they don't specify AreaTypeGuid or FileSystemGuid
1557 PreviousComma
= SFPIsToken (",");
1558 if (SFPIsKeyword ("AreaTypeGuid")) {
1560 // Check for preceeding comma now
1562 if (!PreviousComma
) {
1563 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'AreaTypeGuid'", NULL
);
1567 if (!SFPIsToken ("=")) {
1568 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1572 if (SFPGetQuotedString (Subregion
->AreaTypeGuidString
, sizeof (Subregion
->AreaTypeGuidString
))) {
1574 // Nothing else to do
1576 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->AreaTypeGuid
)) {
1579 SFPGetLineNumber (),
1581 "expected AreaTypeGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1588 PreviousComma
= SFPIsToken (",");
1591 if (SFPIsKeyword ("FileSystemGuid")) {
1593 // Check for preceeding comma now
1595 if (!PreviousComma
) {
1596 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'FileSystemGuid'", NULL
);
1600 if (!SFPIsToken ("=")) {
1601 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1605 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1607 if (SFPGetQuotedString (Subregion
->FileSystemGuidString
, sizeof (Subregion
->FileSystemGuidString
))) {
1609 // Nothing else to do
1611 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->FileSystemGuid
)) {
1614 SFPGetLineNumber (),
1616 "expected FileSystemGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1626 // Look for subregion closing brace
1628 if (!SFPIsToken ("}")) {
1629 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion closing brace '}'", NULL
);
1635 // If any errors were encountered, then delete the subregion definition
1637 if (ErrorCount
!= 0) {
1646 FDFCreateCIncludeFile (
1647 char *FlashDeviceName
,
1652 Routine Description:
1653 Create a header file with #define definitions per an already-parsed
1654 flash definition file.
1657 FlashDeviceName - name of flash device (from the flash definition file)
1659 FileName - name of output file to create
1662 STATUS_SUCCESS - no errors or warnings
1663 STATUS_WARNING - warnings, but no errors, were encountered
1664 STATUS_ERROR - errors were encountered
1669 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1670 FLASH_DEVICE_DESCRIPTION
*FDev
;
1671 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1672 unsigned int Offset
;
1673 unsigned int SubregionOffset
;
1676 // Find the definition we're supposed to use
1678 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1679 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1685 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1686 return STATUS_ERROR
;
1689 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1690 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1691 return STATUS_ERROR
;
1696 fprintf (OutFptr
, CIncludeHeader
);
1698 // Write flash block base and size defines
1700 fprintf (OutFptr
, "#define FLASH_BASE 0x%08X\n", FDev
->BaseAddress
);
1701 fprintf (OutFptr
, "#define FLASH_SIZE 0x%08X\n\n", FDev
->Size
);
1703 // Write flash regions base, size and offset defines
1707 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1710 "#define FLASH_REGION_%s_BASE %*c0x%08X\n",
1712 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1714 Offset
+ FDev
->BaseAddress
1718 "#define FLASH_REGION_%s_SIZE %*c0x%08X\n",
1720 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1726 "#define FLASH_REGION_%s_OFFSET %*c0x%08X\n",
1728 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1733 // Create defines for any subregions
1735 SubregionOffset
= 0;
1736 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1739 "#define FLASH_REGION_%s_SUBREGION_%s_BASE %*c0x%08X\n",
1742 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1744 FDev
->BaseAddress
+ Offset
+ SubregionOffset
1748 "#define FLASH_REGION_%s_SUBREGION_%s_SIZE %*c0x%08X\n",
1751 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1757 "#define FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c0x%08X\n",
1760 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1762 Offset
+ SubregionOffset
1764 SubregionOffset
+= Subregion
->Size
;
1765 if (Subregion
->CreateHob
!= 0) {
1770 Offset
+= FBlock
->Size
;
1773 // Now create a #define for the flash map data definition
1775 fprintf (OutFptr
, "\n\n#define EFI_FLASH_AREA_DATA_DEFINITION \\\n");
1777 // Emit entry for each region
1780 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1781 fprintf (OutFptr
, " /* %s region */\\\n", FBlock
->Name
);
1782 fprintf (OutFptr
, " {\\\n");
1783 fprintf (OutFptr
, " FLASH_REGION_%s_BASE,\\\n", FBlock
->Name
);
1784 fprintf (OutFptr
, " FLASH_REGION_%s_SIZE,\\\n", FBlock
->Name
);
1785 fprintf (OutFptr
, " %s,\\\n", FBlock
->Attributes
);
1786 fprintf (OutFptr
, " %s,\\\n },\\\n", FBlock
->AreaType
);
1789 fprintf (OutFptr
, "\n\n");
1791 // Now walk the list again to create the EFI_HOB_FLASH_MAP_ENTRY_TYPE definition
1793 if (CreateHobs
!= 0) {
1794 fprintf (OutFptr
, "//\n// EFI_HOB_FLASH_MAP_ENTRY_TYPE definition\n//\n");
1795 fprintf (OutFptr
, "#define EFI_HOB_FLASH_MAP_ENTRY_TYPE_DATA_DEFINITION");
1796 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1798 // See if the block has subregions, and that the CreateHobs flag is set
1802 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1803 if (Subregion
->CreateHob
!= 0) {
1809 // If any of the subregions had the CreateHobs flag set, then create the entries in the
1812 if (CreateHobs
!= 0) {
1813 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1814 if (Subregion
->CreateHob
!= 0) {
1815 fprintf (OutFptr
, " \\\n");
1816 fprintf (OutFptr
, " /* %s.%s Subregion */\\\n", FBlock
->Name
, Subregion
->Name
);
1817 fprintf (OutFptr
, " {\\\n");
1818 fprintf (OutFptr
, " EFI_HOB_TYPE_GUID_EXTENSION,\\\n");
1819 fprintf (OutFptr
, " sizeof (EFI_HOB_FLASH_MAP_ENTRY_TYPE ),\\\n");
1820 fprintf (OutFptr
, " 0,\\\n");
1822 // The NameGuid may have been specified in the input flash definition file as a GUID, or
1823 // as a quoted string. Do the right one.
1825 if (Subregion
->NameGuidString
[0] != 0) {
1826 fprintf (OutFptr
, " %s, \\\n", Subregion
->NameGuidString
);
1830 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1831 Subregion
->NameGuid
.Data1
,
1832 (unsigned int) Subregion
->NameGuid
.Data2
,
1833 (unsigned int) Subregion
->NameGuid
.Data3
,
1834 (unsigned int) Subregion
->NameGuid
.Data4
[0],
1835 (unsigned int) Subregion
->NameGuid
.Data4
[1],
1836 (unsigned int) Subregion
->NameGuid
.Data4
[2],
1837 (unsigned int) Subregion
->NameGuid
.Data4
[3],
1838 (unsigned int) Subregion
->NameGuid
.Data4
[4],
1839 (unsigned int) Subregion
->NameGuid
.Data4
[5],
1840 (unsigned int) Subregion
->NameGuid
.Data4
[6],
1841 (unsigned int) Subregion
->NameGuid
.Data4
[7]
1845 fprintf (OutFptr
, " 0, 0, 0,\\\n");
1846 fprintf (OutFptr
, " %s,\\\n", Subregion
->AreaType
);
1848 // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or
1849 // as a quoted string. Do the right one.
1851 if (Subregion
->AreaTypeGuidString
[0] != 0) {
1852 fprintf (OutFptr
, " %s, \\\n", Subregion
->AreaTypeGuidString
);
1856 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1857 Subregion
->AreaTypeGuid
.Data1
,
1858 (unsigned int) Subregion
->AreaTypeGuid
.Data2
,
1859 (unsigned int) Subregion
->AreaTypeGuid
.Data3
,
1860 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[0],
1861 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[1],
1862 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[2],
1863 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[3],
1864 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[4],
1865 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[5],
1866 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[6],
1867 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[7]
1871 fprintf (OutFptr
, " 1,\\\n");
1872 fprintf (OutFptr
, " {\\\n");
1873 fprintf (OutFptr
, " %s,\\\n", Subregion
->Attributes
);
1874 fprintf (OutFptr
, " 0,\\\n");
1875 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_BASE,\\\n", FBlock
->Name
, Subregion
->Name
);
1876 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_SIZE,\\\n", FBlock
->Name
, Subregion
->Name
);
1878 // The FileSystemGuid may have been specified in the input flash definition file as a GUID, or
1879 // as a quoted string. Do the right one.
1881 if (Subregion
->FileSystemGuidString
[0] != 0) {
1882 fprintf (OutFptr
, " %s, \\\n", Subregion
->FileSystemGuidString
);
1886 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1887 Subregion
->FileSystemGuid
.Data1
,
1888 (unsigned int) Subregion
->FileSystemGuid
.Data2
,
1889 (unsigned int) Subregion
->FileSystemGuid
.Data3
,
1890 (unsigned int) Subregion
->FileSystemGuid
.Data4
[0],
1891 (unsigned int) Subregion
->FileSystemGuid
.Data4
[1],
1892 (unsigned int) Subregion
->FileSystemGuid
.Data4
[2],
1893 (unsigned int) Subregion
->FileSystemGuid
.Data4
[3],
1894 (unsigned int) Subregion
->FileSystemGuid
.Data4
[4],
1895 (unsigned int) Subregion
->FileSystemGuid
.Data4
[5],
1896 (unsigned int) Subregion
->FileSystemGuid
.Data4
[6],
1897 (unsigned int) Subregion
->FileSystemGuid
.Data4
[7]
1901 fprintf (OutFptr
, " },\\\n");
1902 fprintf (OutFptr
, " },");
1908 fprintf (OutFptr
, "\n\n");
1912 // Write the file's closing #endif
1914 fprintf (OutFptr
, CIncludeFooter
);
1916 return STATUS_SUCCESS
;
1920 FDFCreateAsmIncludeFile (
1921 char *FlashDeviceName
,
1926 Routine Description:
1927 Create an assembly header file with equate definitions per an already-parsed
1928 flash definition file.
1931 FlashDeviceName - name of flash device (from the flash definition file)
1933 FileName - name of output file to create
1936 STATUS_SUCCESS - no errors or warnings
1937 STATUS_WARNING - warnings, but no errors, were encountered
1938 STATUS_ERROR - errors were encountered
1943 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1944 FLASH_DEVICE_DESCRIPTION
*FDev
;
1945 unsigned int Offset
;
1946 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1947 unsigned int SubregionOffset
;
1949 // Find the definition we're supposed to use
1951 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1952 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1958 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1959 return STATUS_ERROR
;
1962 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1963 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1964 return STATUS_ERROR
;
1969 fprintf (OutFptr
, "\n\n");
1971 // Write flash block size and offset defines
1975 "FLASH_BASE %*cequ 0%08Xh\n",
1980 fprintf (OutFptr
, "FLASH_SIZE %*cequ 0%08Xh\n", COLUMN2_START
- 40, ' ', FDev
->Size
);
1982 // Write flash region size and offset defines
1984 fprintf (OutFptr
, "\n");
1986 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1989 "FLASH_REGION_%s_BASE %*cequ 0%08Xh\n",
1991 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
1993 FDev
->BaseAddress
+ Offset
1997 "FLASH_REGION_%s_SIZE %*cequ 0%08Xh\n",
1999 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2005 "FLASH_REGION_%s_OFFSET %*cequ 0%08Xh\n",
2007 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2012 // Create defines for any subregions
2014 SubregionOffset
= 0;
2015 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2018 "FLASH_REGION_%s_SUBREGION_%s_BASE %*cequ 0%08Xh\n",
2021 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2023 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2027 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*cequ 0%08Xh\n",
2030 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2036 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*cequ 0%08Xh\n",
2039 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2041 Offset
+ SubregionOffset
2043 SubregionOffset
+= Subregion
->Size
;
2046 Offset
+= FBlock
->Size
;
2052 fprintf (OutFptr
, "\n\n");
2054 return STATUS_SUCCESS
;
2059 char *FlashDeviceName
2063 Routine Description:
2064 Using the given flash device name, add symbols to the global symbol table. This
2065 allows other functions to use the symbol definitions for other purposes.
2068 FlashDeviceName - name of flash device (from the flash definition file)
2072 STATUS_SUCCESS - no errors or warnings
2073 STATUS_WARNING - warnings, but no errors, were encountered
2074 STATUS_ERROR - errors were encountered
2078 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2079 FLASH_DEVICE_DESCRIPTION
*FDev
;
2080 unsigned int Offset
;
2083 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2084 unsigned int SubregionOffset
;
2086 // Find the definition we're supposed to use
2088 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2089 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2095 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
2096 return STATUS_ERROR
;
2099 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
);
2100 SymbolAdd ("FLASH_BASE", SymValue
, 0);
2101 sprintf (SymValue
, "0x%08X", FDev
->Size
);
2102 SymbolAdd ("FLASH_SIZE", SymValue
, 0);
2104 // Add flash block size and offset defines
2107 // for (FBlock = FDev->PBlocks; FBlock != NULL; FBlock = FBlock->Next) {
2108 // sprintf (SymName, "FLASH_BLOCK_%s_BASE", FBlock->Name);
2109 // sprintf (SymValue, "0x%08X", FDev->BaseAddress + Offset);
2110 // SymbolAdd (SymName, SymValue, 0);
2111 // sprintf (SymName, "FLASH_BLOCK_%s_SIZE", FBlock->Name);
2112 // sprintf (SymValue, "0x%08X", FBlock->Size);
2113 // SymbolAdd (SymName, SymValue, 0);
2114 // sprintf (SymName, "FLASH_BLOCK_%s_OFFSET", FBlock->Name);
2115 // sprintf (SymValue, "0x%08X", Offset);
2116 // SymbolAdd (SymName, SymValue, 0);
2117 // Offset += FBlock->Size;
2120 // Add flash region block base, size, and offset defines
2123 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2124 sprintf (SymName
, "FLASH_REGION_%s_BASE", FBlock
->Name
);
2125 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
);
2126 SymbolAdd (SymName
, SymValue
, 0);
2127 sprintf (SymName
, "FLASH_REGION_%s_SIZE", FBlock
->Name
);
2128 sprintf (SymValue
, "0x%08X", FBlock
->Size
);
2129 SymbolAdd (SymName
, SymValue
, 0);
2130 sprintf (SymName
, "FLASH_REGION_%s_OFFSET", FBlock
->Name
);
2131 sprintf (SymValue
, "0x%08X", Offset
);
2132 SymbolAdd (SymName
, SymValue
, 0);
2134 // Add subregion symbols
2136 if (FBlock
->Subregions
!= NULL
) {
2137 SubregionOffset
= 0;
2138 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2139 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_BASE", FBlock
->Name
, Subregion
->Name
);
2140 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
+ SubregionOffset
);
2141 SymbolAdd (SymName
, SymValue
, 0);
2142 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_SIZE", FBlock
->Name
, Subregion
->Name
);
2143 sprintf (SymValue
, "0x%08X", Subregion
->Size
);
2144 SymbolAdd (SymName
, SymValue
, 0);
2145 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_OFFSET", FBlock
->Name
, Subregion
->Name
);
2146 sprintf (SymValue
, "0x%08X", Offset
+ SubregionOffset
);
2147 SymbolAdd (SymName
, SymValue
, 0);
2148 SubregionOffset
+= Subregion
->Size
;
2152 Offset
+= FBlock
->Size
;
2155 return STATUS_SUCCESS
;
2160 char *FlashDeviceName
,
2166 Routine Description:
2167 Create a flash image using the given device and image names.
2170 FlashDeviceName - name of flash device (from the flash definition file)
2172 ImageName - name of image (from the flash definition file) to create
2173 FileName - name of output file to create
2176 STATUS_SUCCESS - no errors or warnings
2177 STATUS_WARNING - warnings, but no errors, were encountered
2178 STATUS_ERROR - errors were encountered
2184 FLASH_BLOCK_DESCRIPTION
*RegionDef
;
2185 FLASH_DEVICE_DESCRIPTION
*FDev
;
2186 IMAGE_DEFINITION
*ImageDef
;
2187 unsigned int Offset
;
2191 IMAGE_DEFINITION_ENTRY
*IDefEntry
;
2192 FLASH_SUBREGION_DESCRIPTION
*SubregionDef
;
2194 // Find the flash definition we're supposed to use
2197 Status
= STATUS_ERROR
;
2198 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2199 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2205 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2206 return STATUS_ERROR
;
2209 // Find the image name we're supposed to create
2211 for (ImageDef
= mImageDefinitions
; ImageDef
!= NULL
; ImageDef
= ImageDef
->Next
) {
2212 if (strcmp (ImageDef
->Name
, ImageName
) == 0) {
2217 if (ImageDef
== NULL
) {
2218 Error (NULL
, 0, 0, ImageName
, "image definition not found in image definitions");
2219 return STATUS_ERROR
;
2222 // Open the output file
2224 if ((OutFptr
= fopen (FileName
, "wb")) == NULL
) {
2225 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2226 return STATUS_ERROR
;
2229 // Allocate a buffer to copy the input data to
2231 Buffer
= (char *) _malloc (FDev
->Size
);
2232 if (Buffer
== NULL
) {
2233 Error (NULL
, 0, 0, (INT8
*) "failed to allocate memory", NULL
);
2237 // Set contents of buffer to the erased value
2239 if (FDev
->ErasePolarity
) {
2240 memset (Buffer
, 0xFF, FDev
->Size
);
2242 memset (Buffer
, 0, FDev
->Size
);
2245 // Set all region and subregion size-left fields to the size of the region/subregion
2247 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2248 RegionDef
->SizeLeft
= RegionDef
->Size
;
2249 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2250 SubregionDef
->SizeLeft
= SubregionDef
->Size
;
2254 // Now go through the image list, read files into the buffer.
2256 for (IDefEntry
= ImageDef
->Entries
; IDefEntry
!= NULL
; IDefEntry
= IDefEntry
->Next
) {
2258 // If it's a file name, open the file, get the size, find the corresponding
2259 // flash region it's in, and copy the data.
2261 if (IDefEntry
->IsRawData
== 0) {
2262 if ((InFptr
= fopen (IDefEntry
->Name
, "rb")) == NULL
) {
2263 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to open input file for reading");
2267 fseek (InFptr
, 0, SEEK_END
);
2268 FileSize
= ftell (InFptr
);
2269 fseek (InFptr
, 0, SEEK_SET
);
2271 FileSize
= IDefEntry
->RawDataSize
;
2274 // Find the region/subregion it's in, see if we have space left
2277 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2278 if (strcmp (RegionDef
->Name
, IDefEntry
->RegionName
) == 0) {
2282 Offset
+= RegionDef
->Size
;
2285 if (RegionDef
== NULL
) {
2286 Error (NULL
, 0, 0, IDefEntry
->RegionName
, "Region name not found in FlashDevice %s definition", FDev
->Name
);
2291 // Check for subregion
2293 if (IDefEntry
->SubregionName
[0] != 0) {
2294 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2295 if (strcmp (SubregionDef
->Name
, IDefEntry
->SubregionName
) == 0) {
2299 Offset
+= SubregionDef
->Size
;
2302 if (SubregionDef
== NULL
) {
2307 IDefEntry
->SubregionName
,
2308 "Subregion name not found in FlashDevice %s.%s Region definition",
2315 // Enough space in the subregion?
2317 if (SubregionDef
->SizeLeft
< (unsigned int) FileSize
) {
2323 "insufficient space in Subregion (at least 0x%X additional bytes required)",
2324 FileSize
- SubregionDef
->SizeLeft
2330 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2332 if (IDefEntry
->IsRawData
== 0) {
2333 if (fread (Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2334 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2342 Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
),
2344 IDefEntry
->RawDataSize
2348 SubregionDef
->SizeLeft
-= FileSize
;
2350 // Align based on the Region alignment requirements.
2352 if (RegionDef
->Alignment
!= 0) {
2353 while (((unsigned int) (SubregionDef
->Size
- SubregionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2354 if (SubregionDef
->SizeLeft
== 0) {
2358 SubregionDef
->SizeLeft
--;
2363 // Placing data in a region. Check for enough space in the region left.
2365 if (RegionDef
->SizeLeft
< (unsigned int) FileSize
) {
2371 "insufficient space in Region (at least 0x%X additional bytes required)",
2372 FileSize
- RegionDef
->SizeLeft
2378 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2380 if (IDefEntry
->IsRawData
== 0) {
2381 if (fread (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2382 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2389 memcpy (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), IDefEntry
->RawData
, IDefEntry
->RawDataSize
);
2392 RegionDef
->SizeLeft
-= FileSize
;
2396 if (RegionDef
->Alignment
!= 0) {
2397 while (((unsigned int) (RegionDef
->Size
- RegionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2398 if (RegionDef
->SizeLeft
== 0) {
2402 RegionDef
->SizeLeft
--;
2408 if (fwrite (Buffer
, FDev
->Size
, 1, OutFptr
) != 1) {
2409 Error (NULL
, 0, 0, "failed to write buffer contents to output file", NULL
);
2413 Status
= STATUS_SUCCESS
;
2415 if (InFptr
!= NULL
) {
2419 if (Buffer
!= NULL
) {
2423 if (OutFptr
!= NULL
) {
2425 if (Status
== STATUS_ERROR
) {
2435 char *FlashDeviceName
,
2440 Routine Description:
2441 Create a DSC-style output file with equates for flash management.
2444 FlashDeviceName - name of flash device (from the flash definition file)
2446 FileName - name of output file to create
2449 STATUS_SUCCESS - no errors or warnings
2450 STATUS_WARNING - warnings, but no errors, were encountered
2451 STATUS_ERROR - errors were encountered
2456 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2457 FLASH_DEVICE_DESCRIPTION
*FDev
;
2458 unsigned int Offset
;
2459 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2460 unsigned int SubregionOffset
;
2462 // Find the definition we're supposed to use
2464 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2465 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2471 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2472 return STATUS_ERROR
;
2475 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
2476 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2477 return STATUS_ERROR
;
2480 // Write the flash base address and size
2482 fprintf (OutFptr
, "\n");
2483 fprintf (OutFptr
, "FLASH_BASE = 0x%08X\n", FDev
->BaseAddress
);
2484 fprintf (OutFptr
, "FLASH_SIZE = 0x%08X\n\n", FDev
->Size
);
2486 // Write flash block size and offset defines
2489 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2492 "FLASH_REGION_%s_BASE %*c= 0x%08X\n",
2494 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2496 Offset
+ FDev
->BaseAddress
2500 "FLASH_REGION_%s_SIZE %*c= 0x%08X\n",
2502 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2508 "FLASH_REGION_%s_SIZE_BLOCKS %*c= 0x%x\n",
2510 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2512 (FBlock
->Size
)/(FDev
->PBlocks
->Size
)
2515 // Create defines for any subregions
2517 SubregionOffset
= 0;
2518 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2521 "FLASH_REGION_%s_SUBREGION_%s_BASE %*c= 0x%08X\n",
2524 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2526 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2530 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*c= 0x%08X\n",
2533 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2539 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c= 0x%08X\n",
2542 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2544 Offset
+ SubregionOffset
2547 SubregionOffset
+= Subregion
->Size
;
2550 Offset
+= FBlock
->Size
;
2555 fprintf (OutFptr
, "\n");
2557 return STATUS_SUCCESS
;
2563 Routine Description:
2564 The following buffer management routines are used to encapsulate functionality
2565 for managing a growable data buffer.
2568 BUFFER_DATA - structure that is used to maintain a data buffer
2581 Routine Description:
2583 Create a growable data buffer with default buffer length.
2591 NULL - error occured during data buffer creation
2592 Not NULL - the pointer to the newly created data buffer
2597 BD
= (BUFFER_DATA
*) _malloc (sizeof (BUFFER_DATA
));
2599 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2603 memset (BD
, 0, sizeof (BUFFER_DATA
));
2604 BD
->BufferStart
= (char *) _malloc (BUFFER_SIZE
);
2605 if (BD
->BufferStart
== NULL
) {
2607 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2611 BD
->BufferEnd
= BD
->BufferStart
+ BUFFER_SIZE
;
2612 BD
->BufferPos
= BD
->BufferStart
;
2619 BUFFER_DATA
*Buffer
,
2624 Routine Description:
2626 Add a single byte to a growable data buffer, growing the buffer if required.
2630 Buffer - pointer to the growable data buffer to add a single byte to
2631 Data - value of the single byte data to be added
2635 TRUE - the single byte data was successfully added
2636 FALSE - error occurred, the single byte data was not added
2643 // See if we have to grow the buffer
2645 if (Buffer
->BufferPos
>= Buffer
->BufferEnd
) {
2646 Size
= (int) Buffer
->BufferEnd
- (int) Buffer
->BufferStart
;
2647 NewBuffer
= (char *) _malloc (Size
+ BUFFER_SIZE
);
2648 if (NewBuffer
== NULL
) {
2649 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2653 memcpy (NewBuffer
, Buffer
->BufferStart
, Size
);
2654 _free (Buffer
->BufferStart
);
2655 Buffer
->BufferStart
= NewBuffer
;
2656 Buffer
->BufferPos
= Buffer
->BufferStart
+ Size
;
2657 Buffer
->BufferEnd
= Buffer
->BufferStart
+ Size
+ BUFFER_SIZE
;
2660 *Buffer
->BufferPos
= Data
;
2661 Buffer
->BufferPos
++;
2668 BUFFER_DATA
*Buffer
,
2673 Routine Description:
2675 Free memory used to manage a growable data buffer.
2679 Buffer - pointer to the growable data buffer to be destructed
2680 FreeData - TRUE, free memory containing the buffered data
2681 FALSE, do not free the buffered data memory
2689 if (Buffer
!= NULL
) {
2690 if (FreeData
&& (Buffer
->BufferStart
!= NULL
)) {
2691 _free (Buffer
->BufferStart
);
2701 BUFFER_DATA
*Buffer
,
2706 Routine Description:
2708 Return a pointer and size of the data in a growable data buffer.
2712 Buffer - pointer to the growable data buffer
2713 BufferSize - size of the data in the growable data buffer
2717 pointer of the data in the growable data buffer
2721 *BufferSize
= (int) Buffer
->BufferPos
- (int) Buffer
->BufferStart
;
2722 return Buffer
->BufferStart
;
2728 unsigned int BaseAddr
2732 Routine Description:
2733 Walk a binary image and see if you find anything that looks like a
2737 FDFileName - name of input FD image to parse
2738 BaseAddr - base address of input FD image
2741 STATUS_SUCCESS - no errors or warnings
2742 STATUS_WARNING - warnings, but no errors, were encountered
2743 STATUS_ERROR - errors were encountered
2746 This routine is used for debug purposes only.
2753 EFI_FIRMWARE_VOLUME_HEADER FVHeader
;
2755 FileSystemGuid
= { 0x7A9354D9, 0x0468, 0x444a, 0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF };
2757 if ((InFptr
= fopen (FDFileName
, "rb")) == NULL
) {
2758 Error (NULL
, 0, 0, FDFileName
, "failed to open file for reading");
2759 return STATUS_ERROR
;
2762 fseek (InFptr
, 0, SEEK_END
);
2763 FileSize
= ftell (InFptr
);
2764 fseek (InFptr
, 0, SEEK_SET
);
2766 while (Offset
< FileSize
) {
2767 fseek (InFptr
, Offset
, SEEK_SET
);
2769 // Read the contents of the file, see if it's an FV header
2771 if (fread (&FVHeader
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
), 1, InFptr
) == 1) {
2773 // Check version and GUID
2775 if ((FVHeader
.Revision
== EFI_FVH_REVISION
) && (FVHeader
.Signature
== EFI_FVH_SIGNATURE
)) {
2776 fprintf (stdout
, "FV header at 0x%08X FVSize=0x%08X ", Offset
+ BaseAddr
, (UINT32
) FVHeader
.FvLength
);
2777 if (memcmp (&FVHeader
.FileSystemGuid
, &FileSystemGuid
, sizeof (EFI_GUID
)) == 0) {
2778 fprintf (stdout
, "standard FFS file system\n");
2780 fprintf (stdout
, "non-standard FFS file system\n");
2785 Offset
+= 16 * 1024;
2789 return STATUS_SUCCESS
;