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.
29 #include "EfiUtilityMsgs.h"
30 #include "FlashDefFile.h"
31 #include "SimpleFileParsing.h"
33 #include "EfiFirmwareVolumeHeader.h"
36 // #include "TrackMallocFree.h"
39 #define MAX_STRING_LEN 256
40 #define MAX_NAME_LEN 128
41 #define BUFFER_SIZE 1024
42 #define MAX_ATTR_LEN 128
43 #define MAX_AREATYPE_LEN 128
44 #define COLUMN2_START 60
45 #define COLUMN3_START 70
47 // Information for each subregions defined in the fdf file will be saved in these
49 typedef struct _FLASH_SUBREGION_DESCRIPTION
{
50 struct _FLASH_SUBREGION_DESCRIPTION
*Next
;
51 int CreateHob
; // to add to the auto-created HOB array
52 WCHAR_T Name
[MAX_NAME_LEN
]; // each subregion within a region must have a unique name
53 unsigned int Size
; // size, in bytes, of this subregion
54 unsigned int SizeLeft
; // used when creating the image
55 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // subregion attributes used in the output HOB
56 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // subregion area type used in the output HOB
57 EFI_GUID NameGuid
; // used in the output HOB
58 WCHAR_T NameGuidString
[MAX_NAME_LEN
];
59 EFI_GUID AreaTypeGuid
; // used in the output HOB
60 WCHAR_T AreaTypeGuidString
[MAX_NAME_LEN
];
61 EFI_GUID FileSystemGuid
; // used in the output HOB
62 WCHAR_T FileSystemGuidString
[MAX_NAME_LEN
];
63 } FLASH_SUBREGION_DESCRIPTION
;
66 // Information for each block in a flash device will be saved in one of these.
67 // We'll also use it for region definitions.
69 typedef struct _FLASH_BLOCK_DESCRIPTION
{
70 struct _FLASH_BLOCK_DESCRIPTION
*Next
; // next block in the linked list
71 WCHAR_T Name
[MAX_NAME_LEN
]; // each block must have a unique name
72 unsigned int Size
; // size, in bytes, of this block
73 unsigned int SizeLeft
; // for use when creating image
74 unsigned int Flags
; // user-defined flags for the block
75 unsigned int Alignment
; // power of 2 alignment
76 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // only used for Region definitions
77 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // only used for Region definitions
78 FLASH_SUBREGION_DESCRIPTION
*Subregions
;
79 FLASH_SUBREGION_DESCRIPTION
*LastSubregion
;
80 } FLASH_BLOCK_DESCRIPTION
;
83 // Information for each flash device will be saved in one of these
85 typedef struct _FLASH_DEVICE_DESCRIPTION
{
86 struct _FLASH_DEVICE_DESCRIPTION
*Next
; // next flash device in our linked list
87 int ErasePolarity
; // erase polarity of the flash device
88 unsigned int BaseAddress
; // base address of the flash device
89 unsigned int Size
; // total size, in bytes, of the flash device
90 WCHAR_T Name
[MAX_NAME_LEN
]; // name of the flash device
91 FLASH_BLOCK_DESCRIPTION
*PBlocks
; // linked list of physical block descriptors
92 FLASH_BLOCK_DESCRIPTION
*LastPBlock
; // last block in the linked list
93 FLASH_BLOCK_DESCRIPTION
*Regions
; // linked list of flash region descriptors
94 FLASH_BLOCK_DESCRIPTION
*LastRegion
; // last region in the linked list
95 } FLASH_DEVICE_DESCRIPTION
;
98 // For image definitions, they can specify a file name or raw data bytes. Keep a linked list.
100 typedef struct _IMAGE_DEFINITION_ENTRY
{
101 struct _IMAGE_DEFINITION_ENTRY
*Next
;
102 WCHAR_T RegionName
[MAX_NAME_LEN
];
103 WCHAR_T SubregionName
[MAX_NAME_LEN
];
104 WCHAR_T Name
[MAX_NAME_LEN
]; // file or data name
105 int IsRawData
; // non-zero if raw data bytes
106 unsigned int RawDataSize
;
108 int Optional
; // optional file (don't include if it doesn't exist)
109 } IMAGE_DEFINITION_ENTRY
;
112 // When we parse an image definition, save all the data for each in one of these
114 typedef struct _IMAGE_DEFINITION
{
115 struct _IMAGE_DEFINITION
*Next
;
116 WCHAR_T Name
[MAX_NAME_LEN
];
117 IMAGE_DEFINITION_ENTRY
*Entries
;
118 IMAGE_DEFINITION_ENTRY
*LastEntry
;
127 static const char *CIncludeHeader
= "/*++\n\n"
128 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n""#ifndef _FLASH_MAP_H_\n"
129 "#define _FLASH_MAP_H_\n\n";
131 // "#include \"EfiFlashMap.h\"\n\n";
133 static const char *CIncludeFooter
= "#endif // #ifndef _FLASH_MAP_H_\n\n";
135 static const char *CFlashMapDataFileHeader
= "/*++\n\n"
136 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n";
138 static FLASH_DEVICE_DESCRIPTION
*mFlashDevices
= NULL
;
139 static IMAGE_DEFINITION
*mImageDefinitions
= NULL
;
142 // Local function prototypes
172 FLASH_SUBREGION_DESCRIPTION
*
173 ParseSubregionDefinition (
174 unsigned int SizeLeft
184 Initialization routine for the services that operate on a flash
195 mFlashDevices
= NULL
;
196 mImageDefinitions
= NULL
;
206 Finalization/cleanup routine for the services that operate on a flash
217 FLASH_BLOCK_DESCRIPTION
*FBNext
;
218 FLASH_DEVICE_DESCRIPTION
*FDNext
;
219 IMAGE_DEFINITION
*IDNext
;
220 IMAGE_DEFINITION_ENTRY
*IDENext
;
221 FLASH_SUBREGION_DESCRIPTION
*SubNext
;
223 // Go through all our flash devices and free the memory
225 while (mFlashDevices
!= NULL
) {
227 // Free the physical block definitions
229 while (mFlashDevices
->PBlocks
!= NULL
) {
230 FBNext
= mFlashDevices
->PBlocks
->Next
;
231 _free (mFlashDevices
->PBlocks
);
232 mFlashDevices
->PBlocks
= FBNext
;
235 // Free the region definitions
237 while (mFlashDevices
->Regions
!= NULL
) {
238 FBNext
= mFlashDevices
->Regions
->Next
;
240 // First free the subregion definitions
242 while (mFlashDevices
->Regions
->Subregions
!= NULL
) {
243 SubNext
= mFlashDevices
->Regions
->Subregions
->Next
;
244 _free (mFlashDevices
->Regions
->Subregions
);
245 mFlashDevices
->Regions
->Subregions
= SubNext
;
248 _free (mFlashDevices
->Regions
);
249 mFlashDevices
->Regions
= FBNext
;
252 FDNext
= mFlashDevices
->Next
;
253 _free (mFlashDevices
);
254 mFlashDevices
= FDNext
;
257 // Free up the image definitions, and the data
259 while (mImageDefinitions
!= NULL
) {
263 while (mImageDefinitions
->Entries
!= NULL
) {
264 IDENext
= mImageDefinitions
->Entries
->Next
;
265 if (mImageDefinitions
->Entries
->RawData
!= NULL
) {
266 _free (mImageDefinitions
->Entries
->RawData
);
269 _free (mImageDefinitions
->Entries
);
270 mImageDefinitions
->Entries
= IDENext
;
273 IDNext
= mImageDefinitions
->Next
;
274 _free (mImageDefinitions
);
275 mImageDefinitions
= IDNext
;
286 Parse the specified flash definition file, saving the definitions in
287 file-static variables for use by other functions.
290 FileName - name of the input flash definition text file.
293 STATUS_SUCCESS - file parsed with no errors or warnings
294 STATUS_WARNING - warnings, but no errors, were encountered while parsing
295 STATUS_ERROR - errors were encountered while parsing
302 FLASH_DEVICE_DESCRIPTION
*FDDesc
;
303 FLASH_BLOCK_DESCRIPTION
*FBlockDesc
;
304 FLASH_BLOCK_DESCRIPTION
*TempBlockDesc
;
305 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
306 FLASH_SUBREGION_DESCRIPTION
*TempSubregion
;
307 unsigned int BlockSizeLeft
;
308 unsigned int RegionSizeLeft
;
309 unsigned int SubregionSizeLeft
;
312 IMAGE_DEFINITION
*ImageDef
;
313 IMAGE_DEFINITION_ENTRY
*ImageDefEntry
;
314 IMAGE_DEFINITION_ENTRY
*TempImageDefEntry
;
315 BUFFER_DATA
*BufferData
;
317 BOOLEAN PreviousComma
;
319 if ((Fptr
= fopen (FileName
, "r")) == NULL
) {
320 Error (NULL
, 0, 0, FileName
, "failed to open input flash definition file for reading");
325 Status
= STATUS_SUCCESS
;
329 // Initialize the simple-file-parsing routines
335 if ((Status
= SFPOpenFile (FileName
)) != STATUS_SUCCESS
) {
339 // Parse the file. Should start with a series of these:
341 // Name = "FLASH_1234", Size = 0x2004, BaseAddress = 0xFFF0000, ErasePolarity = 1,
342 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
343 // Block { Name = "BLOCK2", Size = 0x1004, Flags = 0x0002 }
344 // Region { Name = "REGION_NAME", Size = 0x2004, Align= 4 }
347 while (SFPIsKeyword ("FlashDevice")) {
349 // Allocate memory for new flash device description block
351 FDDesc
= (FLASH_DEVICE_DESCRIPTION
*) _malloc (sizeof (FLASH_DEVICE_DESCRIPTION
));
352 if (FDDesc
== NULL
) {
353 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
358 memset (FDDesc
, 0, sizeof (FLASH_DEVICE_DESCRIPTION
));
360 // Open brace -- warning if not there
362 if (!SFPIsToken ("{")) {
363 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
367 // Parse: Name = "DeviceName",
369 if (!SFPIsKeyword ("Name")) {
370 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
375 if (!SFPIsToken ("=")) {
376 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
380 if (!SFPGetQuotedString (FDDesc
->Name
, sizeof (FDDesc
->Name
))) {
381 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of flash device", NULL
);
386 if (!SFPIsToken (",")) {
387 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following flash device name", NULL
);
391 // Parse: Size = 0x20000,
393 if (!SFPIsKeyword ("Size")) {
394 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
399 if (!SFPIsToken ("=")) {
400 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
404 if (!SFPGetNumber (&FDDesc
->Size
)) {
405 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
412 if (FDDesc
->Size
== 0) {
413 Error (SFPGetFileName (), SFPGetLineNumber (), 0, FDDesc
->Name
, "Size field cannot be 0", NULL
);
420 // Parse: BaseAddress = 0xFFF0000,
422 if (!SFPIsKeyword ("BaseAddress")) {
423 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'BaseAddress'", NULL
);
428 if (!SFPIsToken ("=")) {
429 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
433 if (!SFPGetNumber (&FDDesc
->BaseAddress
)) {
434 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for BaseAddress", NULL
);
439 if (!SFPIsToken (",")) {
440 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following BaseAddress value", NULL
);
444 // Parse: ErasePolarity = 1,
446 if (!SFPIsKeyword ("ErasePolarity")) {
447 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'ErasePolarity'", NULL
);
452 if (!SFPIsToken ("=")) {
453 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
457 if (!SFPGetNumber (&Num
) || ((Num
!= 0) && (Num
!= 1))) {
458 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric erase polarity value 1 or 0", NULL
);
463 FDDesc
->ErasePolarity
= Num
;
464 if (!SFPIsToken (",")) {
465 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following erase polarity value", NULL
);
470 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
472 // Keep track of size to make sure the sum of the physical blocks and region sizes do not
473 // exceed the size of the flash device.
475 BlockSizeLeft
= FDDesc
->Size
;
476 RegionSizeLeft
= FDDesc
->Size
;
477 while (SFPIsKeyword ("Block")) {
479 // Allocate memory for a new physical block descriptor
481 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
482 if (FBlockDesc
== NULL
) {
483 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
488 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
490 // Open brace -- warning if not there
492 if (!SFPIsToken ("{")) {
493 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
497 // Parse: Name = "BlockName",
499 if (!SFPIsKeyword ("Name")) {
500 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
505 if (!SFPIsToken ("=")) {
506 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
510 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
511 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of physical block", NULL
);
516 // Make sure there are no other physical block names with this same name
518 for (TempBlockDesc
= FDDesc
->PBlocks
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
519 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
525 "physical block with this name already defined"
531 if (!SFPIsToken (",")) {
532 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following physical block name", NULL
);
536 // Parse: Size = 0x2000,
538 if (!SFPIsKeyword ("Size")) {
539 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
544 if (!SFPIsToken ("=")) {
545 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
549 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
550 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
555 // Make sure the sum of physical blocks so far does not exceed flash device size
557 if (BlockSizeLeft
< FBlockDesc
->Size
) {
562 "sum of physical block sizes exceeds flash device size",
568 BlockSizeLeft
-= FBlockDesc
->Size
;
571 // Optional parse: Flags = 0xFFF0000,
573 if (SFPIsKeyword ("Flags")) {
574 if (!SFPIsToken ("=")) {
575 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
579 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
580 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
586 if (!SFPIsToken ("}")) {
587 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected PhysicalBlock closing brace '}'", NULL
);
591 // Add the physical block descriptor to the end of the linked list
593 if (FDDesc
->LastPBlock
!= NULL
) {
594 FDDesc
->LastPBlock
->Next
= FBlockDesc
;
596 FDDesc
->PBlocks
= FBlockDesc
;
599 FDDesc
->LastPBlock
= FBlockDesc
;
602 // Make sure sum of sizes of physical blocks added up to size of flash device
604 if (BlockSizeLeft
!= 0) {
610 "sum of sizes of physical blocks (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
611 FDDesc
->Size
- BlockSizeLeft
,
619 // Region { Name = "REGION_1", Size = 0x2000, Flags = 0x1234, Alignment = 4, Attributes = "str", AreaType = "str" }
621 while (SFPIsKeyword ("Region")) {
623 // Allocate memory for a new physical block descriptor
625 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
626 if (FBlockDesc
== NULL
) {
627 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
632 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
634 // Open brace -- warning if not there
636 if (!SFPIsToken ("{")) {
637 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
641 // Parse: Name = "BlockName",
643 if (!SFPIsKeyword ("Name")) {
644 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
649 if (!SFPIsToken ("=")) {
650 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
654 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
655 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
660 // Make sure there are no other region names with this same name
662 for (TempBlockDesc
= FDDesc
->Regions
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
663 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
669 "Region with this name already defined"
675 if (!SFPIsToken (",")) {
676 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
680 // Parse: Size = 0x2000,
682 if (!SFPIsKeyword ("Size")) {
683 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
688 if (!SFPIsToken ("=")) {
689 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
693 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
694 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
699 if (!SFPIsToken (",")) {
700 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
703 // Make sure the sum of regions so far does not exceed flash device size
705 if (RegionSizeLeft
< FBlockDesc
->Size
) {
706 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Region sizes exceeds flash device size", NULL
);
710 RegionSizeLeft
-= FBlockDesc
->Size
;
712 // Optional parse: Flags = 0xFFF0000,
714 if (SFPIsKeyword ("Flags")) {
715 if (!SFPIsToken ("=")) {
716 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
720 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
721 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
728 if (!SFPIsToken (",")) {
729 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
733 // Optional parse: Alignment = 4
735 if (SFPIsKeyword ("Alignment")) {
736 if (!SFPIsToken ("=")) {
737 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
741 if (!SFPGetNumber (&FBlockDesc
->Alignment
)) {
742 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Alignment value", NULL
);
749 if (!SFPIsToken (",")) {
750 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
754 // Parse: Attributes = "String",
756 if (!SFPIsKeyword ("Attributes")) {
757 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
762 if (!SFPIsToken ("=")) {
763 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
767 if (!SFPGetQuotedString (FBlockDesc
->Attributes
, sizeof (FBlockDesc
->Attributes
))) {
768 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
773 if (!SFPIsToken (",")) {
774 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
777 // Parse: AreaType = "String",
779 if (!SFPIsKeyword ("AreaType")) {
780 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
785 if (!SFPIsToken ("=")) {
786 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
790 if (!SFPGetQuotedString (FBlockDesc
->AreaType
, sizeof (FBlockDesc
->AreaType
))) {
791 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
796 PreviousComma
= SFPIsToken (",");
798 // Parse optional Subregion definitions
800 SubregionSizeLeft
= FBlockDesc
->Size
;
801 while (SFPIsToken ("Subregion")) {
802 if (!PreviousComma
) {
803 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'Subregion'", NULL
);
805 PreviousComma
= TRUE
;
808 Subregion
= ParseSubregionDefinition (SubregionSizeLeft
);
809 if (Subregion
== NULL
) {
814 SubregionSizeLeft
-= Subregion
->Size
;
816 // Add it to the end of our list
818 if (FBlockDesc
->Subregions
== NULL
) {
819 FBlockDesc
->Subregions
= Subregion
;
821 FBlockDesc
->LastSubregion
->Next
= Subregion
;
824 FBlockDesc
->LastSubregion
= Subregion
;
826 // Make sure all subregion names are unique. We do this each time
827 // through so that we catch the error immediately after it happens, in
828 // which case the reported line number is at least close to where the
829 // problem lies. We don't exit on the error because we can continue parsing
830 // the script to perhaps catch other errors or warnings.
832 for (Subregion
= FBlockDesc
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
833 for (TempSubregion
= Subregion
->Next
; TempSubregion
!= NULL
; TempSubregion
= TempSubregion
->Next
) {
834 if (strcmp (Subregion
->Name
, TempSubregion
->Name
) == 0) {
835 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Subregion
->Name
, "duplicate Subregion name");
842 if (!SFPIsToken ("}")) {
843 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Region closing brace '}'", NULL
);
847 // Add the region descriptor to the end of the linked list
849 if (FDDesc
->LastRegion
!= NULL
) {
850 FDDesc
->LastRegion
->Next
= FBlockDesc
;
852 FDDesc
->Regions
= FBlockDesc
;
855 FDDesc
->LastRegion
= FBlockDesc
;
858 // Make sure sum of sizes of regions adds up to size of flash device
860 if (RegionSizeLeft
!= 0) {
866 "sum of sizes of Regions (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
867 FDDesc
->Size
- RegionSizeLeft
,
874 // Look for closing brace
876 if (!SFPIsToken ("}")) {
877 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected FlashDevice closing brace '}'", NULL
);
881 // Add this flash description to the list
883 FDDesc
->Next
= mFlashDevices
;
884 mFlashDevices
= FDDesc
;
887 while (SFPIsKeyword ("FlashDeviceImage")) {
889 // Allocate memory for a new FD image definition
891 ImageDef
= (IMAGE_DEFINITION
*) _malloc (sizeof (IMAGE_DEFINITION
));
892 if (ImageDef
== NULL
) {
893 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
898 memset (ImageDef
, 0, sizeof (IMAGE_DEFINITION
));
900 // Open brace -- warning if not there
902 if (!SFPIsToken ("{")) {
903 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
907 // Parse: Name = "ImageName",
909 if (!SFPIsKeyword ("Name")) {
910 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
915 if (!SFPIsToken ("=")) {
916 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
920 if (!SFPGetQuotedString (ImageDef
->Name
, sizeof (ImageDef
->Name
))) {
921 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of image", NULL
);
926 if (!SFPIsToken (",")) {
927 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following image name", NULL
);
933 // Parse: File { Name = "FV\FvOem.fv", Region = "REGION_OEM", Optional = TRUE }
935 if (SFPIsKeyword ("File")) {
936 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
937 if (ImageDefEntry
== NULL
) {
938 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
943 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
945 // Open brace -- warning if not there
947 if (!SFPIsToken ("{")) {
948 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
952 // Parse: Name = "FileName.txt"
954 if (!SFPIsKeyword ("Name")) {
955 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
960 if (!SFPIsToken ("=")) {
961 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
965 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
966 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of file", NULL
);
971 if (!SFPIsToken (",")) {
972 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following file name", NULL
);
976 // Parse: Region = "REGION_NAME"
978 if (!SFPIsKeyword ("Region")) {
979 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
984 if (!SFPIsToken ("=")) {
985 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
989 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
990 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
995 if (!SFPIsToken (",")) {
996 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1000 // Parse optional: Subregion = "SUBREGION_NAME"
1002 if (SFPIsKeyword ("Subregion")) {
1003 if (!SFPIsToken ("=")) {
1004 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1008 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1009 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1014 if (!SFPIsToken (",")) {
1015 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1019 // For a given region, you can only place data using the region name, or the subregion names.
1020 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1021 // here by checking that any previous entries with the same Region name had a Subregion specified
1024 for (TempImageDefEntry
= ImageDef
->Entries
;
1025 TempImageDefEntry
!= NULL
;
1026 TempImageDefEntry
= TempImageDefEntry
->Next
1028 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1029 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1032 SFPGetLineNumber (),
1034 TempImageDefEntry
->RegionName
,
1035 "data already placed on a region-basis in the region, can't place data using subregions"
1043 // Optional parse: Optional = TRUE | FALSE
1045 if (SFPIsKeyword ("Optional")) {
1046 if (!SFPIsToken ("=")) {
1047 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1051 if (!SFPIsKeyword ("TRUE")) {
1052 ImageDefEntry
->Optional
= 1;
1053 } else if (SFPIsKeyword ("FALSE")) {
1058 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1068 if (!SFPIsToken ("}")) {
1069 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace to File entry", NULL
);
1074 // Add the entry to the end of the list
1076 if (ImageDef
->LastEntry
!= NULL
) {
1077 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1079 ImageDef
->Entries
= ImageDefEntry
;
1082 ImageDef
->LastEntry
= ImageDefEntry
;
1083 } else if (SFPIsKeyword ("RawData")) {
1085 // Parse: RawData { Name = "PadBytes", Region = "REGION_1", Data = { 0x78, 0x56, 0x34, 0x12 }}
1087 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
1088 if (ImageDefEntry
== NULL
) {
1089 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1094 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
1095 ImageDefEntry
->IsRawData
= 1;
1097 // Open brace -- warning if not there
1099 if (!SFPIsToken ("{")) {
1102 SFPGetLineNumber (),
1104 "expected '{' opening brace for RawData definition",
1110 // Parse: Name = "PadBytes"
1112 if (!SFPIsKeyword ("Name")) {
1113 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1118 if (!SFPIsToken ("=")) {
1119 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1123 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
1124 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of raw data", NULL
);
1129 if (!SFPIsToken (",")) {
1130 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following raw data name", NULL
);
1134 // Parse: Region = "REGION_NAME"
1136 if (!SFPIsKeyword ("Region")) {
1137 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
1142 if (!SFPIsToken ("=")) {
1143 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1147 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
1148 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
1153 if (!SFPIsToken (",")) {
1154 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1158 // Parse optional: Subregion = "SUBREGION_NAME"
1160 if (SFPIsKeyword ("Subregion")) {
1161 if (!SFPIsToken ("=")) {
1162 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1166 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1167 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1172 if (!SFPIsToken (",")) {
1173 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1177 // For a given region, you can only place data using the region name, or the subregion names.
1178 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1179 // here by checking that any previous entries with the same Region name had a Subregion specified
1182 for (TempImageDefEntry
= ImageDef
->Entries
;
1183 TempImageDefEntry
!= NULL
;
1184 TempImageDefEntry
= TempImageDefEntry
->Next
1186 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1187 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1190 SFPGetLineNumber (),
1192 TempImageDefEntry
->RegionName
,
1193 "data already placed on a region-basis in the region, can't place data using subregions"
1201 // Parse: Data = { 0x78, 0x56, 0x34, 0x12 }
1203 if (!SFPIsKeyword ("Data")) {
1204 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Data'", NULL
);
1209 if (!SFPIsToken ("=")) {
1210 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1214 if (!SFPIsToken ("{")) {
1215 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '{' preceeding data list", NULL
);
1219 if ((BufferData
= CreateBufferData ()) == NULL
) {
1224 // Read bytes from input file until closing brace
1226 while (!SFPIsToken ("}")) {
1227 if (!SFPGetNumber (&Num
)) {
1228 SFPGetNextToken (Str
, sizeof (Str
));
1229 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected data value", Str
);
1231 FreeBufferData (BufferData
, TRUE
);
1238 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "only values 0-255 (0x00-0xFF) allowed", NULL
);
1240 FreeBufferData (BufferData
, TRUE
);
1244 AddBufferDataByte (BufferData
, (char) Num
);
1249 // Now get the data and save it in our image entry
1251 ImageDefEntry
->RawData
= GetBufferData (BufferData
, &ImageDefEntry
->RawDataSize
);
1252 FreeBufferData (BufferData
, 0);
1254 // Closing brace for RawData {}
1256 if (!SFPIsToken ("}")) {
1257 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace for RawData", NULL
);
1262 // Add the entry to the end of the list
1264 if (ImageDef
->LastEntry
!= NULL
) {
1265 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1267 ImageDef
->Entries
= ImageDefEntry
;
1270 ImageDef
->LastEntry
= ImageDefEntry
;
1271 } else if (SFPIsToken ("}")) {
1273 // Closing brace for FDImage {}
1277 SFPGetNextToken (Str
, sizeof (Str
));
1278 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "unrecognized token", Str
);
1284 // Add this image definition to our global list
1286 ImageDef
->Next
= mImageDefinitions
;
1287 mImageDefinitions
= ImageDef
;
1290 // Check for end-of-file
1293 SFPGetNextToken (Str
, sizeof (Str
));
1294 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected end-of-file", Str
);
1300 if (ErrorCount
!= 0) {
1301 return STATUS_ERROR
;
1302 } else if (WarningCount
!= 0) {
1303 return STATUS_WARNING
;
1306 return STATUS_SUCCESS
;
1310 FLASH_SUBREGION_DESCRIPTION
*
1311 ParseSubregionDefinition (
1312 unsigned int SizeLeft
1316 Routine Description:
1318 Parse Subregion definitions from the input flash definition file. Format:
1324 Attributes = "EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV",
1325 AreaType = "EFI_FLASH_AREA_EFI_VARIABLES",
1326 NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD (or "EFI_SOME_GUID"),
1327 AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1328 FileSystemGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1331 NOTE: The caller has already parsed the "Subregion" token, so start with the opening brace.
1335 SizeLeft - in the flash definition file, a Region can be broken up into
1336 one or more subregions. As we parse the subregion definitions,
1337 the caller keeps track of how much space is left in the region
1338 that we're parsing subregions for. SizeLeft is that size, and
1339 so the size of the subregion we're now parsing better not
1340 exceed the size left.
1343 NULL - unrecoverable errors detected while parsing the subregion definition
1345 pointer to a subregion definition created from the parsed subregion
1349 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1352 unsigned int Number
;
1353 BOOLEAN PreviousComma
;
1355 // Allocate memory for the new subregion descriptor
1359 Subregion
= (FLASH_SUBREGION_DESCRIPTION
*) _malloc (sizeof (FLASH_SUBREGION_DESCRIPTION
));
1360 if (Subregion
== NULL
) {
1361 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1366 memset (Subregion
, 0, sizeof (FLASH_SUBREGION_DESCRIPTION
));
1368 // Open brace -- warning if not there
1370 if (!SFPIsToken ("{")) {
1371 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
1375 // Parse: CreateHob = TRUE | FALSE,
1377 if (!SFPIsKeyword ("CreateHob")) {
1378 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'CreateHob'", NULL
);
1383 if (!SFPIsToken ("=")) {
1384 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1388 if (SFPIsToken ("TRUE")) {
1389 Subregion
->CreateHob
= 1;
1390 } else if (SFPIsToken ("FALSE")) {
1392 // Subregion->CreateHob = 0; -- not required since we did a memset earlier
1395 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1400 if (!SFPIsToken (",")) {
1401 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following CreateHob value", NULL
);
1405 // Parse: Name = "Name",
1407 if (!SFPIsKeyword ("Name")) {
1408 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1413 if (!SFPIsToken ("=")) {
1414 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1418 if (!SFPGetQuotedString (Subregion
->Name
, sizeof (Subregion
->Name
))) {
1419 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion name", NULL
);
1424 if (!SFPIsToken (",")) {
1425 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1429 // Parse: Size = 0x2000,
1431 if (!SFPIsKeyword ("Size")) {
1432 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
1437 if (!SFPIsToken ("=")) {
1438 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1442 if (!SFPGetNumber (&Subregion
->Size
)) {
1443 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
1449 // Check that the size does not exceed the size left passed in
1451 if (Subregion
->Size
> SizeLeft
) {
1452 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Subregion sizes exceeds Region size", NULL
);
1457 if (!SFPIsToken (",")) {
1458 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following Size value", NULL
);
1461 // Parse: Attributes = Number | "String",
1463 if (!SFPIsKeyword ("Attributes")) {
1464 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
1469 if (!SFPIsToken ("=")) {
1470 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1474 if (SFPGetNumber (&Number
)) {
1475 sprintf (Subregion
->Attributes
, "0x%X", Number
);
1476 } else if (!SFPGetQuotedString (Subregion
->Attributes
, sizeof (Subregion
->Attributes
))) {
1477 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
1482 if (!SFPIsToken (",")) {
1483 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
1486 // Parse: AreaType = Number | "String",
1487 // AreaType is a UINT8, so error if it exceeds the size
1489 if (!SFPIsKeyword ("AreaType")) {
1490 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
1495 if (!SFPIsToken ("=")) {
1496 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1500 if (SFPGetNumber (&Number
)) {
1501 if (Number
> 0xFF) {
1502 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "AreaType value exceeds 255", NULL
);
1506 sprintf (Subregion
->AreaType
, "0x%X", Number
& 0x00FF);
1507 } else if (!SFPGetQuotedString (Subregion
->AreaType
, sizeof (Subregion
->AreaType
))) {
1508 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
1513 if (!SFPIsToken (",")) {
1514 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following AreaType value", NULL
);
1517 // Parse the three GUIDs (last two are optional)
1519 // NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD, (or "EFI_SOME_GUID")
1520 // AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1521 // FileSysteGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1523 if (!SFPIsKeyword ("NameGuid")) {
1524 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'NameGuid'", NULL
);
1529 if (!SFPIsToken ("=")) {
1530 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1534 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1536 if (SFPGetQuotedString (Subregion
->NameGuidString
, sizeof (Subregion
->NameGuidString
))) {
1538 // Nothing else to do
1540 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->NameGuid
)) {
1543 SFPGetLineNumber (),
1545 "expected NameGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1552 // Comma following NameGuid is optional if they don't specify AreaTypeGuid or FileSystemGuid
1554 PreviousComma
= SFPIsToken (",");
1555 if (SFPIsKeyword ("AreaTypeGuid")) {
1557 // Check for preceeding comma now
1559 if (!PreviousComma
) {
1560 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'AreaTypeGuid'", NULL
);
1564 if (!SFPIsToken ("=")) {
1565 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1569 if (SFPGetQuotedString (Subregion
->AreaTypeGuidString
, sizeof (Subregion
->AreaTypeGuidString
))) {
1571 // Nothing else to do
1573 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->AreaTypeGuid
)) {
1576 SFPGetLineNumber (),
1578 "expected AreaTypeGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1585 PreviousComma
= SFPIsToken (",");
1588 if (SFPIsKeyword ("FileSystemGuid")) {
1590 // Check for preceeding comma now
1592 if (!PreviousComma
) {
1593 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'FileSystemGuid'", NULL
);
1597 if (!SFPIsToken ("=")) {
1598 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1602 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1604 if (SFPGetQuotedString (Subregion
->FileSystemGuidString
, sizeof (Subregion
->FileSystemGuidString
))) {
1606 // Nothing else to do
1608 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->FileSystemGuid
)) {
1611 SFPGetLineNumber (),
1613 "expected FileSystemGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1623 // Look for subregion closing brace
1625 if (!SFPIsToken ("}")) {
1626 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion closing brace '}'", NULL
);
1632 // If any errors were encountered, then delete the subregion definition
1634 if (ErrorCount
!= 0) {
1643 FDFCreateCIncludeFile (
1644 char *FlashDeviceName
,
1649 Routine Description:
1650 Create a header file with #define definitions per an already-parsed
1651 flash definition file.
1654 FlashDeviceName - name of flash device (from the flash definition file)
1656 FileName - name of output file to create
1659 STATUS_SUCCESS - no errors or warnings
1660 STATUS_WARNING - warnings, but no errors, were encountered
1661 STATUS_ERROR - errors were encountered
1666 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1667 FLASH_DEVICE_DESCRIPTION
*FDev
;
1668 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1669 unsigned int Offset
;
1670 unsigned int SubregionOffset
;
1673 // Find the definition we're supposed to use
1675 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1676 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1682 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1683 return STATUS_ERROR
;
1686 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1687 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1688 return STATUS_ERROR
;
1693 fprintf (OutFptr
, CIncludeHeader
);
1695 // Write flash block base and size defines
1697 fprintf (OutFptr
, "#define FLASH_BASE 0x%08X\n", FDev
->BaseAddress
);
1698 fprintf (OutFptr
, "#define FLASH_SIZE 0x%08X\n\n", FDev
->Size
);
1700 // Write flash regions base, size and offset defines
1704 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1707 "#define FLASH_REGION_%s_BASE %*c0x%08X\n",
1709 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1711 Offset
+ FDev
->BaseAddress
1715 "#define FLASH_REGION_%s_SIZE %*c0x%08X\n",
1717 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1723 "#define FLASH_REGION_%s_OFFSET %*c0x%08X\n",
1725 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1730 // Create defines for any subregions
1732 SubregionOffset
= 0;
1733 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1736 "#define FLASH_REGION_%s_SUBREGION_%s_BASE %*c0x%08X\n",
1739 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1741 FDev
->BaseAddress
+ Offset
+ SubregionOffset
1745 "#define FLASH_REGION_%s_SUBREGION_%s_SIZE %*c0x%08X\n",
1748 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1754 "#define FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c0x%08X\n",
1757 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1759 Offset
+ SubregionOffset
1761 SubregionOffset
+= Subregion
->Size
;
1762 if (Subregion
->CreateHob
!= 0) {
1767 Offset
+= FBlock
->Size
;
1770 // Now create a #define for the flash map data definition
1772 fprintf (OutFptr
, "\n\n#define EFI_FLASH_AREA_DATA_DEFINITION \\\n");
1774 // Emit entry for each region
1777 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1778 fprintf (OutFptr
, " /* %s region */\\\n", FBlock
->Name
);
1779 fprintf (OutFptr
, " {\\\n");
1780 fprintf (OutFptr
, " FLASH_REGION_%s_BASE,\\\n", FBlock
->Name
);
1781 fprintf (OutFptr
, " FLASH_REGION_%s_SIZE,\\\n", FBlock
->Name
);
1782 fprintf (OutFptr
, " %s,\\\n", FBlock
->Attributes
);
1783 fprintf (OutFptr
, " %s,\\\n },\\\n", FBlock
->AreaType
);
1786 fprintf (OutFptr
, "\n\n");
1788 // Now walk the list again to create the EFI_HOB_FLASH_MAP_ENTRY_TYPE definition
1790 if (CreateHobs
!= 0) {
1791 fprintf (OutFptr
, "//\n// EFI_HOB_FLASH_MAP_ENTRY_TYPE definition\n//\n");
1792 fprintf (OutFptr
, "#define EFI_HOB_FLASH_MAP_ENTRY_TYPE_DATA_DEFINITION");
1793 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1795 // See if the block has subregions, and that the CreateHobs flag is set
1799 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1800 if (Subregion
->CreateHob
!= 0) {
1806 // If any of the subregions had the CreateHobs flag set, then create the entries in the
1809 if (CreateHobs
!= 0) {
1810 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1811 if (Subregion
->CreateHob
!= 0) {
1812 fprintf (OutFptr
, " \\\n");
1813 fprintf (OutFptr
, " /* %s.%s Subregion */\\\n", FBlock
->Name
, Subregion
->Name
);
1814 fprintf (OutFptr
, " {\\\n");
1815 fprintf (OutFptr
, " EFI_HOB_TYPE_GUID_EXTENSION,\\\n");
1816 fprintf (OutFptr
, " sizeof (EFI_HOB_FLASH_MAP_ENTRY_TYPE ),\\\n");
1817 fprintf (OutFptr
, " 0,\\\n");
1819 // The NameGuid may have been specified in the input flash definition file as a GUID, or
1820 // as a quoted string. Do the right one.
1822 if (Subregion
->NameGuidString
[0] != 0) {
1823 fprintf (OutFptr
, " %s, \\\n", Subregion
->NameGuidString
);
1827 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1828 Subregion
->NameGuid
.Data1
,
1829 (unsigned int) Subregion
->NameGuid
.Data2
,
1830 (unsigned int) Subregion
->NameGuid
.Data3
,
1831 (unsigned int) Subregion
->NameGuid
.Data4
[0],
1832 (unsigned int) Subregion
->NameGuid
.Data4
[1],
1833 (unsigned int) Subregion
->NameGuid
.Data4
[2],
1834 (unsigned int) Subregion
->NameGuid
.Data4
[3],
1835 (unsigned int) Subregion
->NameGuid
.Data4
[4],
1836 (unsigned int) Subregion
->NameGuid
.Data4
[5],
1837 (unsigned int) Subregion
->NameGuid
.Data4
[6],
1838 (unsigned int) Subregion
->NameGuid
.Data4
[7]
1842 fprintf (OutFptr
, " 0, 0, 0,\\\n");
1843 fprintf (OutFptr
, " %s,\\\n", Subregion
->AreaType
);
1845 // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or
1846 // as a quoted string. Do the right one.
1848 if (Subregion
->AreaTypeGuidString
[0] != 0) {
1849 fprintf (OutFptr
, " %s, \\\n", Subregion
->AreaTypeGuidString
);
1853 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1854 Subregion
->AreaTypeGuid
.Data1
,
1855 (unsigned int) Subregion
->AreaTypeGuid
.Data2
,
1856 (unsigned int) Subregion
->AreaTypeGuid
.Data3
,
1857 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[0],
1858 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[1],
1859 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[2],
1860 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[3],
1861 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[4],
1862 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[5],
1863 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[6],
1864 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[7]
1868 fprintf (OutFptr
, " 1,\\\n");
1869 fprintf (OutFptr
, " {\\\n");
1870 fprintf (OutFptr
, " %s,\\\n", Subregion
->Attributes
);
1871 fprintf (OutFptr
, " 0,\\\n");
1872 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_BASE,\\\n", FBlock
->Name
, Subregion
->Name
);
1873 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_SIZE,\\\n", FBlock
->Name
, Subregion
->Name
);
1875 // The FileSystemGuid may have been specified in the input flash definition file as a GUID, or
1876 // as a quoted string. Do the right one.
1878 if (Subregion
->FileSystemGuidString
[0] != 0) {
1879 fprintf (OutFptr
, " %s, \\\n", Subregion
->FileSystemGuidString
);
1883 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1884 Subregion
->FileSystemGuid
.Data1
,
1885 (unsigned int) Subregion
->FileSystemGuid
.Data2
,
1886 (unsigned int) Subregion
->FileSystemGuid
.Data3
,
1887 (unsigned int) Subregion
->FileSystemGuid
.Data4
[0],
1888 (unsigned int) Subregion
->FileSystemGuid
.Data4
[1],
1889 (unsigned int) Subregion
->FileSystemGuid
.Data4
[2],
1890 (unsigned int) Subregion
->FileSystemGuid
.Data4
[3],
1891 (unsigned int) Subregion
->FileSystemGuid
.Data4
[4],
1892 (unsigned int) Subregion
->FileSystemGuid
.Data4
[5],
1893 (unsigned int) Subregion
->FileSystemGuid
.Data4
[6],
1894 (unsigned int) Subregion
->FileSystemGuid
.Data4
[7]
1898 fprintf (OutFptr
, " },\\\n");
1899 fprintf (OutFptr
, " },");
1905 fprintf (OutFptr
, "\n\n");
1909 // Write the file's closing #endif
1911 fprintf (OutFptr
, CIncludeFooter
);
1913 return STATUS_SUCCESS
;
1917 FDFCreateAsmIncludeFile (
1918 char *FlashDeviceName
,
1923 Routine Description:
1924 Create an assembly header file with equate definitions per an already-parsed
1925 flash definition file.
1928 FlashDeviceName - name of flash device (from the flash definition file)
1930 FileName - name of output file to create
1933 STATUS_SUCCESS - no errors or warnings
1934 STATUS_WARNING - warnings, but no errors, were encountered
1935 STATUS_ERROR - errors were encountered
1940 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1941 FLASH_DEVICE_DESCRIPTION
*FDev
;
1942 unsigned int Offset
;
1943 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1944 unsigned int SubregionOffset
;
1946 // Find the definition we're supposed to use
1948 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1949 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1955 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1956 return STATUS_ERROR
;
1959 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1960 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1961 return STATUS_ERROR
;
1966 fprintf (OutFptr
, "\n\n");
1968 // Write flash block size and offset defines
1972 "FLASH_BASE %*cequ 0%08Xh\n",
1977 fprintf (OutFptr
, "FLASH_SIZE %*cequ 0%08Xh\n", COLUMN2_START
- 40, ' ', FDev
->Size
);
1979 // Write flash region size and offset defines
1981 fprintf (OutFptr
, "\n");
1983 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1986 "FLASH_REGION_%s_BASE %*cequ 0%08Xh\n",
1988 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
1990 FDev
->BaseAddress
+ Offset
1994 "FLASH_REGION_%s_SIZE %*cequ 0%08Xh\n",
1996 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2002 "FLASH_REGION_%s_OFFSET %*cequ 0%08Xh\n",
2004 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2009 // Create defines for any subregions
2011 SubregionOffset
= 0;
2012 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2015 "FLASH_REGION_%s_SUBREGION_%s_BASE %*cequ 0%08Xh\n",
2018 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2020 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2024 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*cequ 0%08Xh\n",
2027 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2033 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*cequ 0%08Xh\n",
2036 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2038 Offset
+ SubregionOffset
2040 SubregionOffset
+= Subregion
->Size
;
2043 Offset
+= FBlock
->Size
;
2049 fprintf (OutFptr
, "\n\n");
2051 return STATUS_SUCCESS
;
2056 char *FlashDeviceName
2060 Routine Description:
2061 Using the given flash device name, add symbols to the global symbol table. This
2062 allows other functions to use the symbol definitions for other purposes.
2065 FlashDeviceName - name of flash device (from the flash definition file)
2069 STATUS_SUCCESS - no errors or warnings
2070 STATUS_WARNING - warnings, but no errors, were encountered
2071 STATUS_ERROR - errors were encountered
2075 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2076 FLASH_DEVICE_DESCRIPTION
*FDev
;
2077 unsigned int Offset
;
2080 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2081 unsigned int SubregionOffset
;
2083 // Find the definition we're supposed to use
2085 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2086 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2092 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
2093 return STATUS_ERROR
;
2096 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
);
2097 SymbolAdd ("FLASH_BASE", SymValue
, 0);
2098 sprintf (SymValue
, "0x%08X", FDev
->Size
);
2099 SymbolAdd ("FLASH_SIZE", SymValue
, 0);
2101 // Add flash block size and offset defines
2104 // for (FBlock = FDev->PBlocks; FBlock != NULL; FBlock = FBlock->Next) {
2105 // sprintf (SymName, "FLASH_BLOCK_%s_BASE", FBlock->Name);
2106 // sprintf (SymValue, "0x%08X", FDev->BaseAddress + Offset);
2107 // SymbolAdd (SymName, SymValue, 0);
2108 // sprintf (SymName, "FLASH_BLOCK_%s_SIZE", FBlock->Name);
2109 // sprintf (SymValue, "0x%08X", FBlock->Size);
2110 // SymbolAdd (SymName, SymValue, 0);
2111 // sprintf (SymName, "FLASH_BLOCK_%s_OFFSET", FBlock->Name);
2112 // sprintf (SymValue, "0x%08X", Offset);
2113 // SymbolAdd (SymName, SymValue, 0);
2114 // Offset += FBlock->Size;
2117 // Add flash region block base, size, and offset defines
2120 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2121 sprintf (SymName
, "FLASH_REGION_%s_BASE", FBlock
->Name
);
2122 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
);
2123 SymbolAdd (SymName
, SymValue
, 0);
2124 sprintf (SymName
, "FLASH_REGION_%s_SIZE", FBlock
->Name
);
2125 sprintf (SymValue
, "0x%08X", FBlock
->Size
);
2126 SymbolAdd (SymName
, SymValue
, 0);
2127 sprintf (SymName
, "FLASH_REGION_%s_OFFSET", FBlock
->Name
);
2128 sprintf (SymValue
, "0x%08X", Offset
);
2129 SymbolAdd (SymName
, SymValue
, 0);
2131 // Add subregion symbols
2133 if (FBlock
->Subregions
!= NULL
) {
2134 SubregionOffset
= 0;
2135 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2136 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_BASE", FBlock
->Name
, Subregion
->Name
);
2137 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
+ SubregionOffset
);
2138 SymbolAdd (SymName
, SymValue
, 0);
2139 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_SIZE", FBlock
->Name
, Subregion
->Name
);
2140 sprintf (SymValue
, "0x%08X", Subregion
->Size
);
2141 SymbolAdd (SymName
, SymValue
, 0);
2142 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_OFFSET", FBlock
->Name
, Subregion
->Name
);
2143 sprintf (SymValue
, "0x%08X", Offset
+ SubregionOffset
);
2144 SymbolAdd (SymName
, SymValue
, 0);
2145 SubregionOffset
+= Subregion
->Size
;
2149 Offset
+= FBlock
->Size
;
2152 return STATUS_SUCCESS
;
2157 char *FlashDeviceName
,
2163 Routine Description:
2164 Create a flash image using the given device and image names.
2167 FlashDeviceName - name of flash device (from the flash definition file)
2169 ImageName - name of image (from the flash definition file) to create
2170 FileName - name of output file to create
2173 STATUS_SUCCESS - no errors or warnings
2174 STATUS_WARNING - warnings, but no errors, were encountered
2175 STATUS_ERROR - errors were encountered
2181 FLASH_BLOCK_DESCRIPTION
*RegionDef
;
2182 FLASH_DEVICE_DESCRIPTION
*FDev
;
2183 IMAGE_DEFINITION
*ImageDef
;
2184 unsigned int Offset
;
2188 IMAGE_DEFINITION_ENTRY
*IDefEntry
;
2189 FLASH_SUBREGION_DESCRIPTION
*SubregionDef
;
2191 // Find the flash definition we're supposed to use
2194 Status
= STATUS_ERROR
;
2195 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2196 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2202 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2203 return STATUS_ERROR
;
2206 // Find the image name we're supposed to create
2208 for (ImageDef
= mImageDefinitions
; ImageDef
!= NULL
; ImageDef
= ImageDef
->Next
) {
2209 if (strcmp (ImageDef
->Name
, ImageName
) == 0) {
2214 if (ImageDef
== NULL
) {
2215 Error (NULL
, 0, 0, ImageName
, "image definition not found in image definitions");
2216 return STATUS_ERROR
;
2219 // Open the output file
2221 if ((OutFptr
= fopen (FileName
, "wb")) == NULL
) {
2222 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2223 return STATUS_ERROR
;
2226 // Allocate a buffer to copy the input data to
2228 Buffer
= (char *) _malloc (FDev
->Size
);
2229 if (Buffer
== NULL
) {
2230 Error (NULL
, 0, 0, (INT8
*) "failed to allocate memory", NULL
);
2234 // Set contents of buffer to the erased value
2236 if (FDev
->ErasePolarity
) {
2237 memset (Buffer
, 0xFF, FDev
->Size
);
2239 memset (Buffer
, 0, FDev
->Size
);
2242 // Set all region and subregion size-left fields to the size of the region/subregion
2244 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2245 RegionDef
->SizeLeft
= RegionDef
->Size
;
2246 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2247 SubregionDef
->SizeLeft
= SubregionDef
->Size
;
2251 // Now go through the image list, read files into the buffer.
2253 for (IDefEntry
= ImageDef
->Entries
; IDefEntry
!= NULL
; IDefEntry
= IDefEntry
->Next
) {
2255 // If it's a file name, open the file, get the size, find the corresponding
2256 // flash region it's in, and copy the data.
2258 if (IDefEntry
->IsRawData
== 0) {
2259 if ((InFptr
= fopen (IDefEntry
->Name
, "rb")) == NULL
) {
2260 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to open input file for reading");
2264 fseek (InFptr
, 0, SEEK_END
);
2265 FileSize
= ftell (InFptr
);
2266 fseek (InFptr
, 0, SEEK_SET
);
2268 FileSize
= IDefEntry
->RawDataSize
;
2271 // Find the region/subregion it's in, see if we have space left
2274 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2275 if (strcmp (RegionDef
->Name
, IDefEntry
->RegionName
) == 0) {
2279 Offset
+= RegionDef
->Size
;
2282 if (RegionDef
== NULL
) {
2283 Error (NULL
, 0, 0, IDefEntry
->RegionName
, "Region name not found in FlashDevice %s definition", FDev
->Name
);
2288 // Check for subregion
2290 if (IDefEntry
->SubregionName
[0] != 0) {
2291 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2292 if (strcmp (SubregionDef
->Name
, IDefEntry
->SubregionName
) == 0) {
2296 Offset
+= SubregionDef
->Size
;
2299 if (SubregionDef
== NULL
) {
2304 IDefEntry
->SubregionName
,
2305 "Subregion name not found in FlashDevice %s.%s Region definition",
2312 // Enough space in the subregion?
2314 if (SubregionDef
->SizeLeft
< (unsigned int) FileSize
) {
2320 "insufficient space in Subregion (at least 0x%X additional bytes required)",
2321 FileSize
- SubregionDef
->SizeLeft
2327 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2329 if (IDefEntry
->IsRawData
== 0) {
2330 if (fread (Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2331 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2339 Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
),
2341 IDefEntry
->RawDataSize
2345 SubregionDef
->SizeLeft
-= FileSize
;
2347 // Align based on the Region alignment requirements.
2349 if (RegionDef
->Alignment
!= 0) {
2350 while (((unsigned int) (SubregionDef
->Size
- SubregionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2351 if (SubregionDef
->SizeLeft
== 0) {
2355 SubregionDef
->SizeLeft
--;
2360 // Placing data in a region. Check for enough space in the region left.
2362 if (RegionDef
->SizeLeft
< (unsigned int) FileSize
) {
2368 "insufficient space in Region (at least 0x%X additional bytes required)",
2369 FileSize
- RegionDef
->SizeLeft
2375 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2377 if (IDefEntry
->IsRawData
== 0) {
2378 if (fread (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2379 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2386 memcpy (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), IDefEntry
->RawData
, IDefEntry
->RawDataSize
);
2389 RegionDef
->SizeLeft
-= FileSize
;
2393 if (RegionDef
->Alignment
!= 0) {
2394 while (((unsigned int) (RegionDef
->Size
- RegionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2395 if (RegionDef
->SizeLeft
== 0) {
2399 RegionDef
->SizeLeft
--;
2405 if (fwrite (Buffer
, FDev
->Size
, 1, OutFptr
) != 1) {
2406 Error (NULL
, 0, 0, "failed to write buffer contents to output file", NULL
);
2410 Status
= STATUS_SUCCESS
;
2412 if (InFptr
!= NULL
) {
2416 if (Buffer
!= NULL
) {
2420 if (OutFptr
!= NULL
) {
2422 if (Status
== STATUS_ERROR
) {
2432 char *FlashDeviceName
,
2437 Routine Description:
2438 Create a DSC-style output file with equates for flash management.
2441 FlashDeviceName - name of flash device (from the flash definition file)
2443 FileName - name of output file to create
2446 STATUS_SUCCESS - no errors or warnings
2447 STATUS_WARNING - warnings, but no errors, were encountered
2448 STATUS_ERROR - errors were encountered
2453 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2454 FLASH_DEVICE_DESCRIPTION
*FDev
;
2455 unsigned int Offset
;
2456 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2457 unsigned int SubregionOffset
;
2459 // Find the definition we're supposed to use
2461 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2462 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2468 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2469 return STATUS_ERROR
;
2472 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
2473 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2474 return STATUS_ERROR
;
2477 // Write the flash base address and size
2479 fprintf (OutFptr
, "\n");
2480 fprintf (OutFptr
, "FLASH_BASE = 0x%08X\n", FDev
->BaseAddress
);
2481 fprintf (OutFptr
, "FLASH_SIZE = 0x%08X\n\n", FDev
->Size
);
2483 // Write flash block size and offset defines
2486 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2489 "FLASH_REGION_%s_BASE %*c= 0x%08X\n",
2491 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2493 Offset
+ FDev
->BaseAddress
2497 "FLASH_REGION_%s_SIZE %*c= 0x%08X\n",
2499 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2505 "FLASH_REGION_%s_SIZE_BLOCKS %*c= 0x%x\n",
2507 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2509 (FBlock
->Size
)/(FDev
->PBlocks
->Size
)
2512 // Create defines for any subregions
2514 SubregionOffset
= 0;
2515 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2518 "FLASH_REGION_%s_SUBREGION_%s_BASE %*c= 0x%08X\n",
2521 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2523 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2527 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*c= 0x%08X\n",
2530 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2536 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c= 0x%08X\n",
2539 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2541 Offset
+ SubregionOffset
2544 SubregionOffset
+= Subregion
->Size
;
2547 Offset
+= FBlock
->Size
;
2552 fprintf (OutFptr
, "\n");
2554 return STATUS_SUCCESS
;
2560 Routine Description:
2561 The following buffer management routines are used to encapsulate functionality
2562 for managing a growable data buffer.
2565 BUFFER_DATA - structure that is used to maintain a data buffer
2578 Routine Description:
2580 Create a growable data buffer with default buffer length.
2588 NULL - error occured during data buffer creation
2589 Not NULL - the pointer to the newly created data buffer
2594 BD
= (BUFFER_DATA
*) _malloc (sizeof (BUFFER_DATA
));
2596 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2600 memset (BD
, 0, sizeof (BUFFER_DATA
));
2601 BD
->BufferStart
= (char *) _malloc (BUFFER_SIZE
);
2602 if (BD
->BufferStart
== NULL
) {
2604 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2608 BD
->BufferEnd
= BD
->BufferStart
+ BUFFER_SIZE
;
2609 BD
->BufferPos
= BD
->BufferStart
;
2616 BUFFER_DATA
*Buffer
,
2621 Routine Description:
2623 Add a single byte to a growable data buffer, growing the buffer if required.
2627 Buffer - pointer to the growable data buffer to add a single byte to
2628 Data - value of the single byte data to be added
2632 TRUE - the single byte data was successfully added
2633 FALSE - error occurred, the single byte data was not added
2640 // See if we have to grow the buffer
2642 if (Buffer
->BufferPos
>= Buffer
->BufferEnd
) {
2643 Size
= (int) Buffer
->BufferEnd
- (int) Buffer
->BufferStart
;
2644 NewBuffer
= (char *) _malloc (Size
+ BUFFER_SIZE
);
2645 if (NewBuffer
== NULL
) {
2646 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2650 memcpy (NewBuffer
, Buffer
->BufferStart
, Size
);
2651 _free (Buffer
->BufferStart
);
2652 Buffer
->BufferStart
= NewBuffer
;
2653 Buffer
->BufferPos
= Buffer
->BufferStart
+ Size
;
2654 Buffer
->BufferEnd
= Buffer
->BufferStart
+ Size
+ BUFFER_SIZE
;
2657 *Buffer
->BufferPos
= Data
;
2658 Buffer
->BufferPos
++;
2665 BUFFER_DATA
*Buffer
,
2670 Routine Description:
2672 Free memory used to manage a growable data buffer.
2676 Buffer - pointer to the growable data buffer to be destructed
2677 FreeData - TRUE, free memory containing the buffered data
2678 FALSE, do not free the buffered data memory
2686 if (Buffer
!= NULL
) {
2687 if (FreeData
&& (Buffer
->BufferStart
!= NULL
)) {
2688 _free (Buffer
->BufferStart
);
2698 BUFFER_DATA
*Buffer
,
2703 Routine Description:
2705 Return a pointer and size of the data in a growable data buffer.
2709 Buffer - pointer to the growable data buffer
2710 BufferSize - size of the data in the growable data buffer
2714 pointer of the data in the growable data buffer
2718 *BufferSize
= (int) Buffer
->BufferPos
- (int) Buffer
->BufferStart
;
2719 return Buffer
->BufferStart
;
2725 unsigned int BaseAddr
2729 Routine Description:
2730 Walk a binary image and see if you find anything that looks like a
2734 FDFileName - name of input FD image to parse
2735 BaseAddr - base address of input FD image
2738 STATUS_SUCCESS - no errors or warnings
2739 STATUS_WARNING - warnings, but no errors, were encountered
2740 STATUS_ERROR - errors were encountered
2743 This routine is used for debug purposes only.
2750 EFI_FIRMWARE_VOLUME_HEADER FVHeader
;
2752 FileSystemGuid
= { 0x7A9354D9, 0x0468, 0x444a, 0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF };
2754 if ((InFptr
= fopen (FDFileName
, "rb")) == NULL
) {
2755 Error (NULL
, 0, 0, FDFileName
, "failed to open file for reading");
2756 return STATUS_ERROR
;
2759 fseek (InFptr
, 0, SEEK_END
);
2760 FileSize
= ftell (InFptr
);
2761 fseek (InFptr
, 0, SEEK_SET
);
2763 while (Offset
< FileSize
) {
2764 fseek (InFptr
, Offset
, SEEK_SET
);
2766 // Read the contents of the file, see if it's an FV header
2768 if (fread (&FVHeader
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
), 1, InFptr
) == 1) {
2770 // Check version and GUID
2772 if ((FVHeader
.Revision
== EFI_FVH_REVISION
) && (FVHeader
.Signature
== EFI_FVH_SIGNATURE
)) {
2773 fprintf (stdout
, "FV header at 0x%08X FVSize=0x%08X ", Offset
+ BaseAddr
, (UINT32
) FVHeader
.FvLength
);
2774 if (memcmp (&FVHeader
.FileSystemGuid
, &FileSystemGuid
, sizeof (EFI_GUID
)) == 0) {
2775 fprintf (stdout
, "standard FFS file system\n");
2777 fprintf (stdout
, "non-standard FFS file system\n");
2782 Offset
+= 16 * 1024;
2786 return STATUS_SUCCESS
;