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.
28 #include <Common/UefiBaseTypes.h>
29 #include <Common/FirmwareVolumeHeader.h>
30 #include <Common/MultiPhase.h>
32 #include "EfiUtilityMsgs.h"
33 #include "FlashDefFile.h"
34 #include "SimpleFileParsing.h"
38 // #include "TrackMallocFree.h"
41 #define MAX_STRING_LEN 256
42 #define MAX_NAME_LEN 128
43 #define BUFFER_SIZE 1024
44 #define MAX_ATTR_LEN 128
45 #define MAX_AREATYPE_LEN 128
46 #define COLUMN2_START 60
47 #define COLUMN3_START 70
49 // Information for each subregions defined in the fdf file will be saved in these
51 typedef struct _FLASH_SUBREGION_DESCRIPTION
{
52 struct _FLASH_SUBREGION_DESCRIPTION
*Next
;
53 int CreateHob
; // to add to the auto-created HOB array
54 WCHAR_T Name
[MAX_NAME_LEN
]; // each subregion within a region must have a unique name
55 unsigned int Size
; // size, in bytes, of this subregion
56 unsigned int SizeLeft
; // used when creating the image
57 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // subregion attributes used in the output HOB
58 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // subregion area type used in the output HOB
59 EFI_GUID NameGuid
; // used in the output HOB
60 WCHAR_T NameGuidString
[MAX_NAME_LEN
];
61 EFI_GUID AreaTypeGuid
; // used in the output HOB
62 WCHAR_T AreaTypeGuidString
[MAX_NAME_LEN
];
63 EFI_GUID FileSystemGuid
; // used in the output HOB
64 WCHAR_T FileSystemGuidString
[MAX_NAME_LEN
];
65 } FLASH_SUBREGION_DESCRIPTION
;
68 // Information for each block in a flash device will be saved in one of these.
69 // We'll also use it for region definitions.
71 typedef struct _FLASH_BLOCK_DESCRIPTION
{
72 struct _FLASH_BLOCK_DESCRIPTION
*Next
; // next block in the linked list
73 WCHAR_T Name
[MAX_NAME_LEN
]; // each block must have a unique name
74 unsigned int Size
; // size, in bytes, of this block
75 unsigned int SizeLeft
; // for use when creating image
76 unsigned int Flags
; // user-defined flags for the block
77 unsigned int Alignment
; // power of 2 alignment
78 WCHAR_T Attributes
[MAX_ATTR_LEN
]; // only used for Region definitions
79 WCHAR_T AreaType
[MAX_AREATYPE_LEN
]; // only used for Region definitions
80 FLASH_SUBREGION_DESCRIPTION
*Subregions
;
81 FLASH_SUBREGION_DESCRIPTION
*LastSubregion
;
82 } FLASH_BLOCK_DESCRIPTION
;
85 // Information for each flash device will be saved in one of these
87 typedef struct _FLASH_DEVICE_DESCRIPTION
{
88 struct _FLASH_DEVICE_DESCRIPTION
*Next
; // next flash device in our linked list
89 int ErasePolarity
; // erase polarity of the flash device
90 unsigned int BaseAddress
; // base address of the flash device
91 unsigned int Size
; // total size, in bytes, of the flash device
92 WCHAR_T Name
[MAX_NAME_LEN
]; // name of the flash device
93 FLASH_BLOCK_DESCRIPTION
*PBlocks
; // linked list of physical block descriptors
94 FLASH_BLOCK_DESCRIPTION
*LastPBlock
; // last block in the linked list
95 FLASH_BLOCK_DESCRIPTION
*Regions
; // linked list of flash region descriptors
96 FLASH_BLOCK_DESCRIPTION
*LastRegion
; // last region in the linked list
97 } FLASH_DEVICE_DESCRIPTION
;
100 // For image definitions, they can specify a file name or raw data bytes. Keep a linked list.
102 typedef struct _IMAGE_DEFINITION_ENTRY
{
103 struct _IMAGE_DEFINITION_ENTRY
*Next
;
104 WCHAR_T RegionName
[MAX_NAME_LEN
];
105 WCHAR_T SubregionName
[MAX_NAME_LEN
];
106 WCHAR_T Name
[MAX_NAME_LEN
]; // file or data name
107 int IsRawData
; // non-zero if raw data bytes
108 unsigned int RawDataSize
;
110 int Optional
; // optional file (don't include if it doesn't exist)
111 } IMAGE_DEFINITION_ENTRY
;
114 // When we parse an image definition, save all the data for each in one of these
116 typedef struct _IMAGE_DEFINITION
{
117 struct _IMAGE_DEFINITION
*Next
;
118 WCHAR_T Name
[MAX_NAME_LEN
];
119 IMAGE_DEFINITION_ENTRY
*Entries
;
120 IMAGE_DEFINITION_ENTRY
*LastEntry
;
129 static const char *CIncludeHeader
= "/*++\n\n"
130 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n""#ifndef _FLASH_MAP_H_\n"
131 "#define _FLASH_MAP_H_\n\n";
133 // "#include \"EfiFlashMap.h\"\n\n";
135 static const char *CIncludeFooter
= "#endif // #ifndef _FLASH_MAP_H_\n\n";
137 static const char *CFlashMapDataFileHeader
= "/*++\n\n"
138 " DO NOT EDIT -- file auto-generated by FlashMap utility\n\n""--*/\n""\n";
140 static FLASH_DEVICE_DESCRIPTION
*mFlashDevices
= NULL
;
141 static IMAGE_DEFINITION
*mImageDefinitions
= NULL
;
144 // Local function prototypes
174 FLASH_SUBREGION_DESCRIPTION
*
175 ParseSubregionDefinition (
176 unsigned int SizeLeft
186 Initialization routine for the services that operate on a flash
197 mFlashDevices
= NULL
;
198 mImageDefinitions
= NULL
;
208 Finalization/cleanup routine for the services that operate on a flash
219 FLASH_BLOCK_DESCRIPTION
*FBNext
;
220 FLASH_DEVICE_DESCRIPTION
*FDNext
;
221 IMAGE_DEFINITION
*IDNext
;
222 IMAGE_DEFINITION_ENTRY
*IDENext
;
223 FLASH_SUBREGION_DESCRIPTION
*SubNext
;
225 // Go through all our flash devices and free the memory
227 while (mFlashDevices
!= NULL
) {
229 // Free the physical block definitions
231 while (mFlashDevices
->PBlocks
!= NULL
) {
232 FBNext
= mFlashDevices
->PBlocks
->Next
;
233 _free (mFlashDevices
->PBlocks
);
234 mFlashDevices
->PBlocks
= FBNext
;
237 // Free the region definitions
239 while (mFlashDevices
->Regions
!= NULL
) {
240 FBNext
= mFlashDevices
->Regions
->Next
;
242 // First free the subregion definitions
244 while (mFlashDevices
->Regions
->Subregions
!= NULL
) {
245 SubNext
= mFlashDevices
->Regions
->Subregions
->Next
;
246 _free (mFlashDevices
->Regions
->Subregions
);
247 mFlashDevices
->Regions
->Subregions
= SubNext
;
250 _free (mFlashDevices
->Regions
);
251 mFlashDevices
->Regions
= FBNext
;
254 FDNext
= mFlashDevices
->Next
;
255 _free (mFlashDevices
);
256 mFlashDevices
= FDNext
;
259 // Free up the image definitions, and the data
261 while (mImageDefinitions
!= NULL
) {
265 while (mImageDefinitions
->Entries
!= NULL
) {
266 IDENext
= mImageDefinitions
->Entries
->Next
;
267 if (mImageDefinitions
->Entries
->RawData
!= NULL
) {
268 _free (mImageDefinitions
->Entries
->RawData
);
271 _free (mImageDefinitions
->Entries
);
272 mImageDefinitions
->Entries
= IDENext
;
275 IDNext
= mImageDefinitions
->Next
;
276 _free (mImageDefinitions
);
277 mImageDefinitions
= IDNext
;
288 Parse the specified flash definition file, saving the definitions in
289 file-static variables for use by other functions.
292 FileName - name of the input flash definition text file.
295 STATUS_SUCCESS - file parsed with no errors or warnings
296 STATUS_WARNING - warnings, but no errors, were encountered while parsing
297 STATUS_ERROR - errors were encountered while parsing
304 FLASH_DEVICE_DESCRIPTION
*FDDesc
;
305 FLASH_BLOCK_DESCRIPTION
*FBlockDesc
;
306 FLASH_BLOCK_DESCRIPTION
*TempBlockDesc
;
307 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
308 FLASH_SUBREGION_DESCRIPTION
*TempSubregion
;
309 unsigned int BlockSizeLeft
;
310 unsigned int RegionSizeLeft
;
311 unsigned int SubregionSizeLeft
;
314 IMAGE_DEFINITION
*ImageDef
;
315 IMAGE_DEFINITION_ENTRY
*ImageDefEntry
;
316 IMAGE_DEFINITION_ENTRY
*TempImageDefEntry
;
317 BUFFER_DATA
*BufferData
;
319 BOOLEAN PreviousComma
;
321 if ((Fptr
= fopen (FileName
, "r")) == NULL
) {
322 Error (NULL
, 0, 0, FileName
, "failed to open input flash definition file for reading");
327 Status
= STATUS_SUCCESS
;
331 // Initialize the simple-file-parsing routines
337 if ((Status
= SFPOpenFile (FileName
)) != STATUS_SUCCESS
) {
341 // Parse the file. Should start with a series of these:
343 // Name = "FLASH_1234", Size = 0x2004, BaseAddress = 0xFFF0000, ErasePolarity = 1,
344 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
345 // Block { Name = "BLOCK2", Size = 0x1004, Flags = 0x0002 }
346 // Region { Name = "REGION_NAME", Size = 0x2004, Align= 4 }
349 while (SFPIsKeyword ("FlashDevice")) {
351 // Allocate memory for new flash device description block
353 FDDesc
= (FLASH_DEVICE_DESCRIPTION
*) _malloc (sizeof (FLASH_DEVICE_DESCRIPTION
));
354 if (FDDesc
== NULL
) {
355 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
360 memset (FDDesc
, 0, sizeof (FLASH_DEVICE_DESCRIPTION
));
362 // Open brace -- warning if not there
364 if (!SFPIsToken ("{")) {
365 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
369 // Parse: Name = "DeviceName",
371 if (!SFPIsKeyword ("Name")) {
372 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
377 if (!SFPIsToken ("=")) {
378 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
382 if (!SFPGetQuotedString (FDDesc
->Name
, sizeof (FDDesc
->Name
))) {
383 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of flash device", NULL
);
388 if (!SFPIsToken (",")) {
389 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following flash device name", NULL
);
393 // Parse: Size = 0x20000,
395 if (!SFPIsKeyword ("Size")) {
396 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
401 if (!SFPIsToken ("=")) {
402 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
406 if (!SFPGetNumber (&FDDesc
->Size
)) {
407 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
414 if (FDDesc
->Size
== 0) {
415 Error (SFPGetFileName (), SFPGetLineNumber (), 0, FDDesc
->Name
, "Size field cannot be 0", NULL
);
422 // Parse: BaseAddress = 0xFFF0000,
424 if (!SFPIsKeyword ("BaseAddress")) {
425 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'BaseAddress'", NULL
);
430 if (!SFPIsToken ("=")) {
431 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
435 if (!SFPGetNumber (&FDDesc
->BaseAddress
)) {
436 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for BaseAddress", NULL
);
441 if (!SFPIsToken (",")) {
442 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following BaseAddress value", NULL
);
446 // Parse: ErasePolarity = 1,
448 if (!SFPIsKeyword ("ErasePolarity")) {
449 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'ErasePolarity'", NULL
);
454 if (!SFPIsToken ("=")) {
455 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
459 if (!SFPGetNumber (&Num
) || ((Num
!= 0) && (Num
!= 1))) {
460 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric erase polarity value 1 or 0", NULL
);
465 FDDesc
->ErasePolarity
= Num
;
466 if (!SFPIsToken (",")) {
467 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following erase polarity value", NULL
);
472 // Block { Name = "BLOCK1", Size = 0x1000, Flags = 0x0001 }
474 // Keep track of size to make sure the sum of the physical blocks and region sizes do not
475 // exceed the size of the flash device.
477 BlockSizeLeft
= FDDesc
->Size
;
478 RegionSizeLeft
= FDDesc
->Size
;
479 while (SFPIsKeyword ("Block")) {
481 // Allocate memory for a new physical block descriptor
483 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
484 if (FBlockDesc
== NULL
) {
485 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
490 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
492 // Open brace -- warning if not there
494 if (!SFPIsToken ("{")) {
495 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
499 // Parse: Name = "BlockName",
501 if (!SFPIsKeyword ("Name")) {
502 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
507 if (!SFPIsToken ("=")) {
508 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
512 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
513 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of physical block", NULL
);
518 // Make sure there are no other physical block names with this same name
520 for (TempBlockDesc
= FDDesc
->PBlocks
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
521 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
527 "physical block with this name already defined"
533 if (!SFPIsToken (",")) {
534 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following physical block name", NULL
);
538 // Parse: Size = 0x2000,
540 if (!SFPIsKeyword ("Size")) {
541 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
546 if (!SFPIsToken ("=")) {
547 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
551 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
552 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
557 // Make sure the sum of physical blocks so far does not exceed flash device size
559 if (BlockSizeLeft
< FBlockDesc
->Size
) {
564 "sum of physical block sizes exceeds flash device size",
570 BlockSizeLeft
-= FBlockDesc
->Size
;
573 // Optional parse: Flags = 0xFFF0000,
575 if (SFPIsKeyword ("Flags")) {
576 if (!SFPIsToken ("=")) {
577 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
581 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
582 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
588 if (!SFPIsToken ("}")) {
589 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected PhysicalBlock closing brace '}'", NULL
);
593 // Add the physical block descriptor to the end of the linked list
595 if (FDDesc
->LastPBlock
!= NULL
) {
596 FDDesc
->LastPBlock
->Next
= FBlockDesc
;
598 FDDesc
->PBlocks
= FBlockDesc
;
601 FDDesc
->LastPBlock
= FBlockDesc
;
604 // Make sure sum of sizes of physical blocks added up to size of flash device
606 if (BlockSizeLeft
!= 0) {
612 "sum of sizes of physical blocks (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
613 FDDesc
->Size
- BlockSizeLeft
,
621 // Region { Name = "REGION_1", Size = 0x2000, Flags = 0x1234, Alignment = 4, Attributes = "str", AreaType = "str" }
623 while (SFPIsKeyword ("Region")) {
625 // Allocate memory for a new physical block descriptor
627 FBlockDesc
= (FLASH_BLOCK_DESCRIPTION
*) _malloc (sizeof (FLASH_BLOCK_DESCRIPTION
));
628 if (FBlockDesc
== NULL
) {
629 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
634 memset (FBlockDesc
, 0, sizeof (FLASH_BLOCK_DESCRIPTION
));
636 // Open brace -- warning if not there
638 if (!SFPIsToken ("{")) {
639 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
643 // Parse: Name = "BlockName",
645 if (!SFPIsKeyword ("Name")) {
646 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
651 if (!SFPIsToken ("=")) {
652 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
656 if (!SFPGetQuotedString (FBlockDesc
->Name
, sizeof (FBlockDesc
->Name
))) {
657 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
662 // Make sure there are no other region names with this same name
664 for (TempBlockDesc
= FDDesc
->Regions
; TempBlockDesc
!= NULL
; TempBlockDesc
= TempBlockDesc
->Next
) {
665 if (strcmp (TempBlockDesc
->Name
, FBlockDesc
->Name
) == 0) {
671 "Region with this name already defined"
677 if (!SFPIsToken (",")) {
678 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
682 // Parse: Size = 0x2000,
684 if (!SFPIsKeyword ("Size")) {
685 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
690 if (!SFPIsToken ("=")) {
691 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
695 if (!SFPGetNumber (&FBlockDesc
->Size
)) {
696 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
701 if (!SFPIsToken (",")) {
702 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
705 // Make sure the sum of regions so far does not exceed flash device size
707 if (RegionSizeLeft
< FBlockDesc
->Size
) {
708 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Region sizes exceeds flash device size", NULL
);
712 RegionSizeLeft
-= FBlockDesc
->Size
;
714 // Optional parse: Flags = 0xFFF0000,
716 if (SFPIsKeyword ("Flags")) {
717 if (!SFPIsToken ("=")) {
718 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
722 if (!SFPGetNumber (&FBlockDesc
->Flags
)) {
723 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric value for Flags", NULL
);
730 if (!SFPIsToken (",")) {
731 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
735 // Optional parse: Alignment = 4
737 if (SFPIsKeyword ("Alignment")) {
738 if (!SFPIsToken ("=")) {
739 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
743 if (!SFPGetNumber (&FBlockDesc
->Alignment
)) {
744 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Alignment value", NULL
);
751 if (!SFPIsToken (",")) {
752 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
756 // Parse: Attributes = "String",
758 if (!SFPIsKeyword ("Attributes")) {
759 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
764 if (!SFPIsToken ("=")) {
765 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
769 if (!SFPGetQuotedString (FBlockDesc
->Attributes
, sizeof (FBlockDesc
->Attributes
))) {
770 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
775 if (!SFPIsToken (",")) {
776 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
779 // Parse: AreaType = "String",
781 if (!SFPIsKeyword ("AreaType")) {
782 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
787 if (!SFPIsToken ("=")) {
788 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
792 if (!SFPGetQuotedString (FBlockDesc
->AreaType
, sizeof (FBlockDesc
->AreaType
))) {
793 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
798 PreviousComma
= SFPIsToken (",");
800 // Parse optional Subregion definitions
802 SubregionSizeLeft
= FBlockDesc
->Size
;
803 while (SFPIsToken ("Subregion")) {
804 if (!PreviousComma
) {
805 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'Subregion'", NULL
);
807 PreviousComma
= TRUE
;
810 Subregion
= ParseSubregionDefinition (SubregionSizeLeft
);
811 if (Subregion
== NULL
) {
816 SubregionSizeLeft
-= Subregion
->Size
;
818 // Add it to the end of our list
820 if (FBlockDesc
->Subregions
== NULL
) {
821 FBlockDesc
->Subregions
= Subregion
;
823 FBlockDesc
->LastSubregion
->Next
= Subregion
;
826 FBlockDesc
->LastSubregion
= Subregion
;
828 // Make sure all subregion names are unique. We do this each time
829 // through so that we catch the error immediately after it happens, in
830 // which case the reported line number is at least close to where the
831 // problem lies. We don't exit on the error because we can continue parsing
832 // the script to perhaps catch other errors or warnings.
834 for (Subregion
= FBlockDesc
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
835 for (TempSubregion
= Subregion
->Next
; TempSubregion
!= NULL
; TempSubregion
= TempSubregion
->Next
) {
836 if (strcmp (Subregion
->Name
, TempSubregion
->Name
) == 0) {
837 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Subregion
->Name
, "duplicate Subregion name");
844 if (!SFPIsToken ("}")) {
845 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Region closing brace '}'", NULL
);
849 // Add the region descriptor to the end of the linked list
851 if (FDDesc
->LastRegion
!= NULL
) {
852 FDDesc
->LastRegion
->Next
= FBlockDesc
;
854 FDDesc
->Regions
= FBlockDesc
;
857 FDDesc
->LastRegion
= FBlockDesc
;
860 // Make sure sum of sizes of regions adds up to size of flash device
862 if (RegionSizeLeft
!= 0) {
868 "sum of sizes of Regions (0x%08X) != flash device size (0x%08X) : delta = 0x%08X",
869 FDDesc
->Size
- RegionSizeLeft
,
876 // Look for closing brace
878 if (!SFPIsToken ("}")) {
879 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected FlashDevice closing brace '}'", NULL
);
883 // Add this flash description to the list
885 FDDesc
->Next
= mFlashDevices
;
886 mFlashDevices
= FDDesc
;
889 while (SFPIsKeyword ("FlashDeviceImage")) {
891 // Allocate memory for a new FD image definition
893 ImageDef
= (IMAGE_DEFINITION
*) _malloc (sizeof (IMAGE_DEFINITION
));
894 if (ImageDef
== NULL
) {
895 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
900 memset (ImageDef
, 0, sizeof (IMAGE_DEFINITION
));
902 // Open brace -- warning if not there
904 if (!SFPIsToken ("{")) {
905 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
909 // Parse: Name = "ImageName",
911 if (!SFPIsKeyword ("Name")) {
912 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
917 if (!SFPIsToken ("=")) {
918 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
922 if (!SFPGetQuotedString (ImageDef
->Name
, sizeof (ImageDef
->Name
))) {
923 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of image", NULL
);
928 if (!SFPIsToken (",")) {
929 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following image name", NULL
);
935 // Parse: File { Name = "FV\FvOem.fv", Region = "REGION_OEM", Optional = TRUE }
937 if (SFPIsKeyword ("File")) {
938 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
939 if (ImageDefEntry
== NULL
) {
940 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
945 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
947 // Open brace -- warning if not there
949 if (!SFPIsToken ("{")) {
950 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
954 // Parse: Name = "FileName.txt"
956 if (!SFPIsKeyword ("Name")) {
957 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
962 if (!SFPIsToken ("=")) {
963 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
967 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
968 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of file", NULL
);
973 if (!SFPIsToken (",")) {
974 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following file name", NULL
);
978 // Parse: Region = "REGION_NAME"
980 if (!SFPIsKeyword ("Region")) {
981 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
986 if (!SFPIsToken ("=")) {
987 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
991 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
992 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
997 if (!SFPIsToken (",")) {
998 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1002 // Parse optional: Subregion = "SUBREGION_NAME"
1004 if (SFPIsKeyword ("Subregion")) {
1005 if (!SFPIsToken ("=")) {
1006 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1010 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1011 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1016 if (!SFPIsToken (",")) {
1017 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1021 // For a given region, you can only place data using the region name, or the subregion names.
1022 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1023 // here by checking that any previous entries with the same Region name had a Subregion specified
1026 for (TempImageDefEntry
= ImageDef
->Entries
;
1027 TempImageDefEntry
!= NULL
;
1028 TempImageDefEntry
= TempImageDefEntry
->Next
1030 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1031 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1034 SFPGetLineNumber (),
1036 TempImageDefEntry
->RegionName
,
1037 "data already placed on a region-basis in the region, can't place data using subregions"
1045 // Optional parse: Optional = TRUE | FALSE
1047 if (SFPIsKeyword ("Optional")) {
1048 if (!SFPIsToken ("=")) {
1049 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1053 if (!SFPIsKeyword ("TRUE")) {
1054 ImageDefEntry
->Optional
= 1;
1055 } else if (SFPIsKeyword ("FALSE")) {
1060 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1070 if (!SFPIsToken ("}")) {
1071 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace to File entry", NULL
);
1076 // Add the entry to the end of the list
1078 if (ImageDef
->LastEntry
!= NULL
) {
1079 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1081 ImageDef
->Entries
= ImageDefEntry
;
1084 ImageDef
->LastEntry
= ImageDefEntry
;
1085 } else if (SFPIsKeyword ("RawData")) {
1087 // Parse: RawData { Name = "PadBytes", Region = "REGION_1", Data = { 0x78, 0x56, 0x34, 0x12 }}
1089 ImageDefEntry
= (IMAGE_DEFINITION_ENTRY
*) _malloc (sizeof (IMAGE_DEFINITION_ENTRY
));
1090 if (ImageDefEntry
== NULL
) {
1091 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1096 memset (ImageDefEntry
, 0, sizeof (IMAGE_DEFINITION_ENTRY
));
1097 ImageDefEntry
->IsRawData
= 1;
1099 // Open brace -- warning if not there
1101 if (!SFPIsToken ("{")) {
1104 SFPGetLineNumber (),
1106 "expected '{' opening brace for RawData definition",
1112 // Parse: Name = "PadBytes"
1114 if (!SFPIsKeyword ("Name")) {
1115 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1120 if (!SFPIsToken ("=")) {
1121 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1125 if (!SFPGetQuotedString (ImageDefEntry
->Name
, sizeof (ImageDefEntry
->Name
))) {
1126 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted name of raw data", NULL
);
1131 if (!SFPIsToken (",")) {
1132 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following raw data name", NULL
);
1136 // Parse: Region = "REGION_NAME"
1138 if (!SFPIsKeyword ("Region")) {
1139 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Region'", NULL
);
1144 if (!SFPIsToken ("=")) {
1145 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1149 if (!SFPGetQuotedString (ImageDefEntry
->RegionName
, sizeof (ImageDefEntry
->RegionName
))) {
1150 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Region name", NULL
);
1155 if (!SFPIsToken (",")) {
1156 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1160 // Parse optional: Subregion = "SUBREGION_NAME"
1162 if (SFPIsKeyword ("Subregion")) {
1163 if (!SFPIsToken ("=")) {
1164 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1168 if (!SFPGetQuotedString (ImageDefEntry
->SubregionName
, sizeof (ImageDefEntry
->SubregionName
))) {
1169 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Subegion name", NULL
);
1174 if (!SFPIsToken (",")) {
1175 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Subregion name", NULL
);
1179 // For a given region, you can only place data using the region name, or the subregion names.
1180 // In other words, you can't say File1->Region1 and File2->Region1.Subregion1. Enforce that
1181 // here by checking that any previous entries with the same Region name had a Subregion specified
1184 for (TempImageDefEntry
= ImageDef
->Entries
;
1185 TempImageDefEntry
!= NULL
;
1186 TempImageDefEntry
= TempImageDefEntry
->Next
1188 if (strcmp (TempImageDefEntry
->Name
, ImageDefEntry
->Name
) == 0) {
1189 if (TempImageDefEntry
->SubregionName
[0] == 0) {
1192 SFPGetLineNumber (),
1194 TempImageDefEntry
->RegionName
,
1195 "data already placed on a region-basis in the region, can't place data using subregions"
1203 // Parse: Data = { 0x78, 0x56, 0x34, 0x12 }
1205 if (!SFPIsKeyword ("Data")) {
1206 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Data'", NULL
);
1211 if (!SFPIsToken ("=")) {
1212 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1216 if (!SFPIsToken ("{")) {
1217 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '{' preceeding data list", NULL
);
1221 if ((BufferData
= CreateBufferData ()) == NULL
) {
1226 // Read bytes from input file until closing brace
1228 while (!SFPIsToken ("}")) {
1229 if (!SFPGetNumber (&Num
)) {
1230 SFPGetNextToken (Str
, sizeof (Str
));
1231 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected data value", Str
);
1233 FreeBufferData (BufferData
, TRUE
);
1240 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "only values 0-255 (0x00-0xFF) allowed", NULL
);
1242 FreeBufferData (BufferData
, TRUE
);
1246 AddBufferDataByte (BufferData
, (char) Num
);
1251 // Now get the data and save it in our image entry
1253 ImageDefEntry
->RawData
= GetBufferData (BufferData
, &ImageDefEntry
->RawDataSize
);
1254 FreeBufferData (BufferData
, 0);
1256 // Closing brace for RawData {}
1258 if (!SFPIsToken ("}")) {
1259 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '}' closing brace for RawData", NULL
);
1264 // Add the entry to the end of the list
1266 if (ImageDef
->LastEntry
!= NULL
) {
1267 ImageDef
->LastEntry
->Next
= ImageDefEntry
;
1269 ImageDef
->Entries
= ImageDefEntry
;
1272 ImageDef
->LastEntry
= ImageDefEntry
;
1273 } else if (SFPIsToken ("}")) {
1275 // Closing brace for FDImage {}
1279 SFPGetNextToken (Str
, sizeof (Str
));
1280 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "unrecognized token", Str
);
1286 // Add this image definition to our global list
1288 ImageDef
->Next
= mImageDefinitions
;
1289 mImageDefinitions
= ImageDef
;
1292 // Check for end-of-file
1295 SFPGetNextToken (Str
, sizeof (Str
));
1296 Error (SFPGetFileName (), SFPGetLineNumber (), 0, Str
, "expected end-of-file", Str
);
1302 if (ErrorCount
!= 0) {
1303 return STATUS_ERROR
;
1304 } else if (WarningCount
!= 0) {
1305 return STATUS_WARNING
;
1308 return STATUS_SUCCESS
;
1312 FLASH_SUBREGION_DESCRIPTION
*
1313 ParseSubregionDefinition (
1314 unsigned int SizeLeft
1318 Routine Description:
1320 Parse Subregion definitions from the input flash definition file. Format:
1326 Attributes = "EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV",
1327 AreaType = "EFI_FLASH_AREA_EFI_VARIABLES",
1328 NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD (or "EFI_SOME_GUID"),
1329 AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1330 FileSystemGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID") (optional)
1333 NOTE: The caller has already parsed the "Subregion" token, so start with the opening brace.
1337 SizeLeft - in the flash definition file, a Region can be broken up into
1338 one or more subregions. As we parse the subregion definitions,
1339 the caller keeps track of how much space is left in the region
1340 that we're parsing subregions for. SizeLeft is that size, and
1341 so the size of the subregion we're now parsing better not
1342 exceed the size left.
1345 NULL - unrecoverable errors detected while parsing the subregion definition
1347 pointer to a subregion definition created from the parsed subregion
1351 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1354 unsigned int Number
;
1355 BOOLEAN PreviousComma
;
1357 // Allocate memory for the new subregion descriptor
1361 Subregion
= (FLASH_SUBREGION_DESCRIPTION
*) _malloc (sizeof (FLASH_SUBREGION_DESCRIPTION
));
1362 if (Subregion
== NULL
) {
1363 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
1368 memset (Subregion
, 0, sizeof (FLASH_SUBREGION_DESCRIPTION
));
1370 // Open brace -- warning if not there
1372 if (!SFPIsToken ("{")) {
1373 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected {", NULL
);
1377 // Parse: CreateHob = TRUE | FALSE,
1379 if (!SFPIsKeyword ("CreateHob")) {
1380 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'CreateHob'", NULL
);
1385 if (!SFPIsToken ("=")) {
1386 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1390 if (SFPIsToken ("TRUE")) {
1391 Subregion
->CreateHob
= 1;
1392 } else if (SFPIsToken ("FALSE")) {
1394 // Subregion->CreateHob = 0; -- not required since we did a memset earlier
1397 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'TRUE' or 'FALSE'", NULL
);
1402 if (!SFPIsToken (",")) {
1403 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following CreateHob value", NULL
);
1407 // Parse: Name = "Name",
1409 if (!SFPIsKeyword ("Name")) {
1410 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Name'", NULL
);
1415 if (!SFPIsToken ("=")) {
1416 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1420 if (!SFPGetQuotedString (Subregion
->Name
, sizeof (Subregion
->Name
))) {
1421 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion name", NULL
);
1426 if (!SFPIsToken (",")) {
1427 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected comma following Region name", NULL
);
1431 // Parse: Size = 0x2000,
1433 if (!SFPIsKeyword ("Size")) {
1434 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Size'", NULL
);
1439 if (!SFPIsToken ("=")) {
1440 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1444 if (!SFPGetNumber (&Subregion
->Size
)) {
1445 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected numeric Size value", NULL
);
1451 // Check that the size does not exceed the size left passed in
1453 if (Subregion
->Size
> SizeLeft
) {
1454 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "sum of Subregion sizes exceeds Region size", NULL
);
1459 if (!SFPIsToken (",")) {
1460 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following Size value", NULL
);
1463 // Parse: Attributes = Number | "String",
1465 if (!SFPIsKeyword ("Attributes")) {
1466 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'Attributes'", NULL
);
1471 if (!SFPIsToken ("=")) {
1472 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1476 if (SFPGetNumber (&Number
)) {
1477 sprintf (Subregion
->Attributes
, "0x%X", Number
);
1478 } else if (!SFPGetQuotedString (Subregion
->Attributes
, sizeof (Subregion
->Attributes
))) {
1479 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted Attributes string", NULL
);
1484 if (!SFPIsToken (",")) {
1485 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ','", NULL
);
1488 // Parse: AreaType = Number | "String",
1489 // AreaType is a UINT8, so error if it exceeds the size
1491 if (!SFPIsKeyword ("AreaType")) {
1492 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'AreaType'", NULL
);
1497 if (!SFPIsToken ("=")) {
1498 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1502 if (SFPGetNumber (&Number
)) {
1503 if (Number
> 0xFF) {
1504 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "AreaType value exceeds 255", NULL
);
1508 sprintf (Subregion
->AreaType
, "0x%X", Number
& 0x00FF);
1509 } else if (!SFPGetQuotedString (Subregion
->AreaType
, sizeof (Subregion
->AreaType
))) {
1510 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected quoted AreaType string", NULL
);
1515 if (!SFPIsToken (",")) {
1516 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' following AreaType value", NULL
);
1519 // Parse the three GUIDs (last two are optional)
1521 // NameGuid = 12345678-1234-5678-AAAA-BBBBCCCCDDDD, (or "EFI_SOME_GUID")
1522 // AreaTypeGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1523 // FileSysteGuid = 11111111-2222-3333-4444-1, (or "EFI_SOME_GUID")
1525 if (!SFPIsKeyword ("NameGuid")) {
1526 Error (SFPGetFileName (), SFPGetLineNumber (), 0, "expected 'NameGuid'", NULL
);
1531 if (!SFPIsToken ("=")) {
1532 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1536 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1538 if (SFPGetQuotedString (Subregion
->NameGuidString
, sizeof (Subregion
->NameGuidString
))) {
1540 // Nothing else to do
1542 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->NameGuid
)) {
1545 SFPGetLineNumber (),
1547 "expected NameGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1554 // Comma following NameGuid is optional if they don't specify AreaTypeGuid or FileSystemGuid
1556 PreviousComma
= SFPIsToken (",");
1557 if (SFPIsKeyword ("AreaTypeGuid")) {
1559 // Check for preceeding comma now
1561 if (!PreviousComma
) {
1562 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'AreaTypeGuid'", NULL
);
1566 if (!SFPIsToken ("=")) {
1567 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1571 if (SFPGetQuotedString (Subregion
->AreaTypeGuidString
, sizeof (Subregion
->AreaTypeGuidString
))) {
1573 // Nothing else to do
1575 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->AreaTypeGuid
)) {
1578 SFPGetLineNumber (),
1580 "expected AreaTypeGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1587 PreviousComma
= SFPIsToken (",");
1590 if (SFPIsKeyword ("FileSystemGuid")) {
1592 // Check for preceeding comma now
1594 if (!PreviousComma
) {
1595 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'FileSystemGuid'", NULL
);
1599 if (!SFPIsToken ("=")) {
1600 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL
);
1604 // Allow a GUID or a quoted string identifier, which we'll just copy as a string
1606 if (SFPGetQuotedString (Subregion
->FileSystemGuidString
, sizeof (Subregion
->FileSystemGuidString
))) {
1608 // Nothing else to do
1610 } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS
, &Subregion
->FileSystemGuid
)) {
1613 SFPGetLineNumber (),
1615 "expected FileSystemGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",
1625 // Look for subregion closing brace
1627 if (!SFPIsToken ("}")) {
1628 Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected Subregion closing brace '}'", NULL
);
1634 // If any errors were encountered, then delete the subregion definition
1636 if (ErrorCount
!= 0) {
1645 FDFCreateCIncludeFile (
1646 char *FlashDeviceName
,
1651 Routine Description:
1652 Create a header file with #define definitions per an already-parsed
1653 flash definition file.
1656 FlashDeviceName - name of flash device (from the flash definition file)
1658 FileName - name of output file to create
1661 STATUS_SUCCESS - no errors or warnings
1662 STATUS_WARNING - warnings, but no errors, were encountered
1663 STATUS_ERROR - errors were encountered
1668 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1669 FLASH_DEVICE_DESCRIPTION
*FDev
;
1670 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1671 unsigned int Offset
;
1672 unsigned int SubregionOffset
;
1675 // Find the definition we're supposed to use
1677 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1678 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1684 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1685 return STATUS_ERROR
;
1688 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1689 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1690 return STATUS_ERROR
;
1695 fprintf (OutFptr
, CIncludeHeader
);
1697 // Write flash block base and size defines
1699 fprintf (OutFptr
, "#define FLASH_BASE 0x%08X\n", FDev
->BaseAddress
);
1700 fprintf (OutFptr
, "#define FLASH_SIZE 0x%08X\n\n", FDev
->Size
);
1702 // Write flash regions base, size and offset defines
1706 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1709 "#define FLASH_REGION_%s_BASE %*c0x%08X\n",
1711 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1713 Offset
+ FDev
->BaseAddress
1717 "#define FLASH_REGION_%s_SIZE %*c0x%08X\n",
1719 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1725 "#define FLASH_REGION_%s_OFFSET %*c0x%08X\n",
1727 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
1732 // Create defines for any subregions
1734 SubregionOffset
= 0;
1735 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1738 "#define FLASH_REGION_%s_SUBREGION_%s_BASE %*c0x%08X\n",
1741 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1743 FDev
->BaseAddress
+ Offset
+ SubregionOffset
1747 "#define FLASH_REGION_%s_SUBREGION_%s_SIZE %*c0x%08X\n",
1750 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1756 "#define FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c0x%08X\n",
1759 COLUMN3_START
- 43 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
1761 Offset
+ SubregionOffset
1763 SubregionOffset
+= Subregion
->Size
;
1764 if (Subregion
->CreateHob
!= 0) {
1769 Offset
+= FBlock
->Size
;
1772 // Now create a #define for the flash map data definition
1774 fprintf (OutFptr
, "\n\n#define EFI_FLASH_AREA_DATA_DEFINITION \\\n");
1776 // Emit entry for each region
1779 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1780 fprintf (OutFptr
, " /* %s region */\\\n", FBlock
->Name
);
1781 fprintf (OutFptr
, " {\\\n");
1782 fprintf (OutFptr
, " FLASH_REGION_%s_BASE,\\\n", FBlock
->Name
);
1783 fprintf (OutFptr
, " FLASH_REGION_%s_SIZE,\\\n", FBlock
->Name
);
1784 fprintf (OutFptr
, " %s,\\\n", FBlock
->Attributes
);
1785 fprintf (OutFptr
, " %s,\\\n },\\\n", FBlock
->AreaType
);
1788 fprintf (OutFptr
, "\n\n");
1790 // Now walk the list again to create the EFI_HOB_FLASH_MAP_ENTRY_TYPE definition
1792 if (CreateHobs
!= 0) {
1793 fprintf (OutFptr
, "//\n// EFI_HOB_FLASH_MAP_ENTRY_TYPE definition\n//\n");
1794 fprintf (OutFptr
, "#define EFI_HOB_FLASH_MAP_ENTRY_TYPE_DATA_DEFINITION");
1795 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1797 // See if the block has subregions, and that the CreateHobs flag is set
1801 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1802 if (Subregion
->CreateHob
!= 0) {
1808 // If any of the subregions had the CreateHobs flag set, then create the entries in the
1811 if (CreateHobs
!= 0) {
1812 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
1813 if (Subregion
->CreateHob
!= 0) {
1814 fprintf (OutFptr
, " \\\n");
1815 fprintf (OutFptr
, " /* %s.%s Subregion */\\\n", FBlock
->Name
, Subregion
->Name
);
1816 fprintf (OutFptr
, " {\\\n");
1817 fprintf (OutFptr
, " EFI_HOB_TYPE_GUID_EXTENSION,\\\n");
1818 fprintf (OutFptr
, " sizeof (EFI_HOB_FLASH_MAP_ENTRY_TYPE ),\\\n");
1819 fprintf (OutFptr
, " 0,\\\n");
1821 // The NameGuid may have been specified in the input flash definition file as a GUID, or
1822 // as a quoted string. Do the right one.
1824 if (Subregion
->NameGuidString
[0] != 0) {
1825 fprintf (OutFptr
, " %s, \\\n", Subregion
->NameGuidString
);
1829 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1830 Subregion
->NameGuid
.Data1
,
1831 (unsigned int) Subregion
->NameGuid
.Data2
,
1832 (unsigned int) Subregion
->NameGuid
.Data3
,
1833 (unsigned int) Subregion
->NameGuid
.Data4
[0],
1834 (unsigned int) Subregion
->NameGuid
.Data4
[1],
1835 (unsigned int) Subregion
->NameGuid
.Data4
[2],
1836 (unsigned int) Subregion
->NameGuid
.Data4
[3],
1837 (unsigned int) Subregion
->NameGuid
.Data4
[4],
1838 (unsigned int) Subregion
->NameGuid
.Data4
[5],
1839 (unsigned int) Subregion
->NameGuid
.Data4
[6],
1840 (unsigned int) Subregion
->NameGuid
.Data4
[7]
1844 fprintf (OutFptr
, " 0, 0, 0,\\\n");
1845 fprintf (OutFptr
, " %s,\\\n", Subregion
->AreaType
);
1847 // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or
1848 // as a quoted string. Do the right one.
1850 if (Subregion
->AreaTypeGuidString
[0] != 0) {
1851 fprintf (OutFptr
, " %s, \\\n", Subregion
->AreaTypeGuidString
);
1855 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1856 Subregion
->AreaTypeGuid
.Data1
,
1857 (unsigned int) Subregion
->AreaTypeGuid
.Data2
,
1858 (unsigned int) Subregion
->AreaTypeGuid
.Data3
,
1859 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[0],
1860 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[1],
1861 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[2],
1862 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[3],
1863 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[4],
1864 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[5],
1865 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[6],
1866 (unsigned int) Subregion
->AreaTypeGuid
.Data4
[7]
1870 fprintf (OutFptr
, " 1,\\\n");
1871 fprintf (OutFptr
, " {\\\n");
1872 fprintf (OutFptr
, " %s,\\\n", Subregion
->Attributes
);
1873 fprintf (OutFptr
, " 0,\\\n");
1874 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_BASE,\\\n", FBlock
->Name
, Subregion
->Name
);
1875 fprintf (OutFptr
, " FLASH_REGION_%s_SUBREGION_%s_SIZE,\\\n", FBlock
->Name
, Subregion
->Name
);
1877 // The FileSystemGuid may have been specified in the input flash definition file as a GUID, or
1878 // as a quoted string. Do the right one.
1880 if (Subregion
->FileSystemGuidString
[0] != 0) {
1881 fprintf (OutFptr
, " %s, \\\n", Subregion
->FileSystemGuidString
);
1885 " { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",
1886 Subregion
->FileSystemGuid
.Data1
,
1887 (unsigned int) Subregion
->FileSystemGuid
.Data2
,
1888 (unsigned int) Subregion
->FileSystemGuid
.Data3
,
1889 (unsigned int) Subregion
->FileSystemGuid
.Data4
[0],
1890 (unsigned int) Subregion
->FileSystemGuid
.Data4
[1],
1891 (unsigned int) Subregion
->FileSystemGuid
.Data4
[2],
1892 (unsigned int) Subregion
->FileSystemGuid
.Data4
[3],
1893 (unsigned int) Subregion
->FileSystemGuid
.Data4
[4],
1894 (unsigned int) Subregion
->FileSystemGuid
.Data4
[5],
1895 (unsigned int) Subregion
->FileSystemGuid
.Data4
[6],
1896 (unsigned int) Subregion
->FileSystemGuid
.Data4
[7]
1900 fprintf (OutFptr
, " },\\\n");
1901 fprintf (OutFptr
, " },");
1907 fprintf (OutFptr
, "\n\n");
1911 // Write the file's closing #endif
1913 fprintf (OutFptr
, CIncludeFooter
);
1915 return STATUS_SUCCESS
;
1919 FDFCreateAsmIncludeFile (
1920 char *FlashDeviceName
,
1925 Routine Description:
1926 Create an assembly header file with equate definitions per an already-parsed
1927 flash definition file.
1930 FlashDeviceName - name of flash device (from the flash definition file)
1932 FileName - name of output file to create
1935 STATUS_SUCCESS - no errors or warnings
1936 STATUS_WARNING - warnings, but no errors, were encountered
1937 STATUS_ERROR - errors were encountered
1942 FLASH_BLOCK_DESCRIPTION
*FBlock
;
1943 FLASH_DEVICE_DESCRIPTION
*FDev
;
1944 unsigned int Offset
;
1945 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
1946 unsigned int SubregionOffset
;
1948 // Find the definition we're supposed to use
1950 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
1951 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
1957 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
1958 return STATUS_ERROR
;
1961 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
1962 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
1963 return STATUS_ERROR
;
1968 fprintf (OutFptr
, "\n\n");
1970 // Write flash block size and offset defines
1974 "FLASH_BASE %*cequ 0%08Xh\n",
1979 fprintf (OutFptr
, "FLASH_SIZE %*cequ 0%08Xh\n", COLUMN2_START
- 40, ' ', FDev
->Size
);
1981 // Write flash region size and offset defines
1983 fprintf (OutFptr
, "\n");
1985 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
1988 "FLASH_REGION_%s_BASE %*cequ 0%08Xh\n",
1990 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
1992 FDev
->BaseAddress
+ Offset
1996 "FLASH_REGION_%s_SIZE %*cequ 0%08Xh\n",
1998 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2004 "FLASH_REGION_%s_OFFSET %*cequ 0%08Xh\n",
2006 COLUMN2_START
- 20 - strlen (FBlock
->Name
),
2011 // Create defines for any subregions
2013 SubregionOffset
= 0;
2014 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2017 "FLASH_REGION_%s_SUBREGION_%s_BASE %*cequ 0%08Xh\n",
2020 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2022 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2026 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*cequ 0%08Xh\n",
2029 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2035 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*cequ 0%08Xh\n",
2038 COLUMN3_START
- 39 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2040 Offset
+ SubregionOffset
2042 SubregionOffset
+= Subregion
->Size
;
2045 Offset
+= FBlock
->Size
;
2051 fprintf (OutFptr
, "\n\n");
2053 return STATUS_SUCCESS
;
2058 char *FlashDeviceName
2062 Routine Description:
2063 Using the given flash device name, add symbols to the global symbol table. This
2064 allows other functions to use the symbol definitions for other purposes.
2067 FlashDeviceName - name of flash device (from the flash definition file)
2071 STATUS_SUCCESS - no errors or warnings
2072 STATUS_WARNING - warnings, but no errors, were encountered
2073 STATUS_ERROR - errors were encountered
2077 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2078 FLASH_DEVICE_DESCRIPTION
*FDev
;
2079 unsigned int Offset
;
2082 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2083 unsigned int SubregionOffset
;
2085 // Find the definition we're supposed to use
2087 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2088 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2094 Error (NULL
, 0, 0, NULL
, FlashDeviceName
, "flash device not found in flash definitions");
2095 return STATUS_ERROR
;
2098 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
);
2099 SymbolAdd ("FLASH_BASE", SymValue
, 0);
2100 sprintf (SymValue
, "0x%08X", FDev
->Size
);
2101 SymbolAdd ("FLASH_SIZE", SymValue
, 0);
2103 // Add flash block size and offset defines
2106 // for (FBlock = FDev->PBlocks; FBlock != NULL; FBlock = FBlock->Next) {
2107 // sprintf (SymName, "FLASH_BLOCK_%s_BASE", FBlock->Name);
2108 // sprintf (SymValue, "0x%08X", FDev->BaseAddress + Offset);
2109 // SymbolAdd (SymName, SymValue, 0);
2110 // sprintf (SymName, "FLASH_BLOCK_%s_SIZE", FBlock->Name);
2111 // sprintf (SymValue, "0x%08X", FBlock->Size);
2112 // SymbolAdd (SymName, SymValue, 0);
2113 // sprintf (SymName, "FLASH_BLOCK_%s_OFFSET", FBlock->Name);
2114 // sprintf (SymValue, "0x%08X", Offset);
2115 // SymbolAdd (SymName, SymValue, 0);
2116 // Offset += FBlock->Size;
2119 // Add flash region block base, size, and offset defines
2122 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2123 sprintf (SymName
, "FLASH_REGION_%s_BASE", FBlock
->Name
);
2124 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
);
2125 SymbolAdd (SymName
, SymValue
, 0);
2126 sprintf (SymName
, "FLASH_REGION_%s_SIZE", FBlock
->Name
);
2127 sprintf (SymValue
, "0x%08X", FBlock
->Size
);
2128 SymbolAdd (SymName
, SymValue
, 0);
2129 sprintf (SymName
, "FLASH_REGION_%s_OFFSET", FBlock
->Name
);
2130 sprintf (SymValue
, "0x%08X", Offset
);
2131 SymbolAdd (SymName
, SymValue
, 0);
2133 // Add subregion symbols
2135 if (FBlock
->Subregions
!= NULL
) {
2136 SubregionOffset
= 0;
2137 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2138 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_BASE", FBlock
->Name
, Subregion
->Name
);
2139 sprintf (SymValue
, "0x%08X", FDev
->BaseAddress
+ Offset
+ SubregionOffset
);
2140 SymbolAdd (SymName
, SymValue
, 0);
2141 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_SIZE", FBlock
->Name
, Subregion
->Name
);
2142 sprintf (SymValue
, "0x%08X", Subregion
->Size
);
2143 SymbolAdd (SymName
, SymValue
, 0);
2144 sprintf (SymName
, "FLASH_REGION_%s_SUBREGION_%s_OFFSET", FBlock
->Name
, Subregion
->Name
);
2145 sprintf (SymValue
, "0x%08X", Offset
+ SubregionOffset
);
2146 SymbolAdd (SymName
, SymValue
, 0);
2147 SubregionOffset
+= Subregion
->Size
;
2151 Offset
+= FBlock
->Size
;
2154 return STATUS_SUCCESS
;
2159 char *FlashDeviceName
,
2165 Routine Description:
2166 Create a flash image using the given device and image names.
2169 FlashDeviceName - name of flash device (from the flash definition file)
2171 ImageName - name of image (from the flash definition file) to create
2172 FileName - name of output file to create
2175 STATUS_SUCCESS - no errors or warnings
2176 STATUS_WARNING - warnings, but no errors, were encountered
2177 STATUS_ERROR - errors were encountered
2183 FLASH_BLOCK_DESCRIPTION
*RegionDef
;
2184 FLASH_DEVICE_DESCRIPTION
*FDev
;
2185 IMAGE_DEFINITION
*ImageDef
;
2186 unsigned int Offset
;
2190 IMAGE_DEFINITION_ENTRY
*IDefEntry
;
2191 FLASH_SUBREGION_DESCRIPTION
*SubregionDef
;
2193 // Find the flash definition we're supposed to use
2196 Status
= STATUS_ERROR
;
2197 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2198 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2204 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2205 return STATUS_ERROR
;
2208 // Find the image name we're supposed to create
2210 for (ImageDef
= mImageDefinitions
; ImageDef
!= NULL
; ImageDef
= ImageDef
->Next
) {
2211 if (strcmp (ImageDef
->Name
, ImageName
) == 0) {
2216 if (ImageDef
== NULL
) {
2217 Error (NULL
, 0, 0, ImageName
, "image definition not found in image definitions");
2218 return STATUS_ERROR
;
2221 // Open the output file
2223 if ((OutFptr
= fopen (FileName
, "wb")) == NULL
) {
2224 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2225 return STATUS_ERROR
;
2228 // Allocate a buffer to copy the input data to
2230 Buffer
= (char *) _malloc (FDev
->Size
);
2231 if (Buffer
== NULL
) {
2232 Error (NULL
, 0, 0, (INT8
*) "failed to allocate memory", NULL
);
2236 // Set contents of buffer to the erased value
2238 if (FDev
->ErasePolarity
) {
2239 memset (Buffer
, 0xFF, FDev
->Size
);
2241 memset (Buffer
, 0, FDev
->Size
);
2244 // Set all region and subregion size-left fields to the size of the region/subregion
2246 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2247 RegionDef
->SizeLeft
= RegionDef
->Size
;
2248 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2249 SubregionDef
->SizeLeft
= SubregionDef
->Size
;
2253 // Now go through the image list, read files into the buffer.
2255 for (IDefEntry
= ImageDef
->Entries
; IDefEntry
!= NULL
; IDefEntry
= IDefEntry
->Next
) {
2257 // If it's a file name, open the file, get the size, find the corresponding
2258 // flash region it's in, and copy the data.
2260 if (IDefEntry
->IsRawData
== 0) {
2261 if ((InFptr
= fopen (IDefEntry
->Name
, "rb")) == NULL
) {
2262 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to open input file for reading");
2266 fseek (InFptr
, 0, SEEK_END
);
2267 FileSize
= ftell (InFptr
);
2268 fseek (InFptr
, 0, SEEK_SET
);
2270 FileSize
= IDefEntry
->RawDataSize
;
2273 // Find the region/subregion it's in, see if we have space left
2276 for (RegionDef
= FDev
->Regions
; RegionDef
!= NULL
; RegionDef
= RegionDef
->Next
) {
2277 if (strcmp (RegionDef
->Name
, IDefEntry
->RegionName
) == 0) {
2281 Offset
+= RegionDef
->Size
;
2284 if (RegionDef
== NULL
) {
2285 Error (NULL
, 0, 0, IDefEntry
->RegionName
, "Region name not found in FlashDevice %s definition", FDev
->Name
);
2290 // Check for subregion
2292 if (IDefEntry
->SubregionName
[0] != 0) {
2293 for (SubregionDef
= RegionDef
->Subregions
; SubregionDef
!= NULL
; SubregionDef
= SubregionDef
->Next
) {
2294 if (strcmp (SubregionDef
->Name
, IDefEntry
->SubregionName
) == 0) {
2298 Offset
+= SubregionDef
->Size
;
2301 if (SubregionDef
== NULL
) {
2306 IDefEntry
->SubregionName
,
2307 "Subregion name not found in FlashDevice %s.%s Region definition",
2314 // Enough space in the subregion?
2316 if (SubregionDef
->SizeLeft
< (unsigned int) FileSize
) {
2322 "insufficient space in Subregion (at least 0x%X additional bytes required)",
2323 FileSize
- SubregionDef
->SizeLeft
2329 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2331 if (IDefEntry
->IsRawData
== 0) {
2332 if (fread (Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2333 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2341 Buffer
+ Offset
+ (SubregionDef
->Size
- SubregionDef
->SizeLeft
),
2343 IDefEntry
->RawDataSize
2347 SubregionDef
->SizeLeft
-= FileSize
;
2349 // Align based on the Region alignment requirements.
2351 if (RegionDef
->Alignment
!= 0) {
2352 while (((unsigned int) (SubregionDef
->Size
- SubregionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2353 if (SubregionDef
->SizeLeft
== 0) {
2357 SubregionDef
->SizeLeft
--;
2362 // Placing data in a region. Check for enough space in the region left.
2364 if (RegionDef
->SizeLeft
< (unsigned int) FileSize
) {
2370 "insufficient space in Region (at least 0x%X additional bytes required)",
2371 FileSize
- RegionDef
->SizeLeft
2377 // Read the file into the buffer if it's a file. Otherwise copy the raw data
2379 if (IDefEntry
->IsRawData
== 0) {
2380 if (fread (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), FileSize
, 1, InFptr
) != 1) {
2381 Error (NULL
, 0, 0, IDefEntry
->Name
, "failed to read file contents");
2388 memcpy (Buffer
+ Offset
+ (RegionDef
->Size
- RegionDef
->SizeLeft
), IDefEntry
->RawData
, IDefEntry
->RawDataSize
);
2391 RegionDef
->SizeLeft
-= FileSize
;
2395 if (RegionDef
->Alignment
!= 0) {
2396 while (((unsigned int) (RegionDef
->Size
- RegionDef
->SizeLeft
) &~RegionDef
->Alignment
) != 0) {
2397 if (RegionDef
->SizeLeft
== 0) {
2401 RegionDef
->SizeLeft
--;
2407 if (fwrite (Buffer
, FDev
->Size
, 1, OutFptr
) != 1) {
2408 Error (NULL
, 0, 0, "failed to write buffer contents to output file", NULL
);
2412 Status
= STATUS_SUCCESS
;
2414 if (InFptr
!= NULL
) {
2418 if (Buffer
!= NULL
) {
2422 if (OutFptr
!= NULL
) {
2424 if (Status
== STATUS_ERROR
) {
2434 char *FlashDeviceName
,
2439 Routine Description:
2440 Create a DSC-style output file with equates for flash management.
2443 FlashDeviceName - name of flash device (from the flash definition file)
2445 FileName - name of output file to create
2448 STATUS_SUCCESS - no errors or warnings
2449 STATUS_WARNING - warnings, but no errors, were encountered
2450 STATUS_ERROR - errors were encountered
2455 FLASH_BLOCK_DESCRIPTION
*FBlock
;
2456 FLASH_DEVICE_DESCRIPTION
*FDev
;
2457 unsigned int Offset
;
2458 FLASH_SUBREGION_DESCRIPTION
*Subregion
;
2459 unsigned int SubregionOffset
;
2461 // Find the definition we're supposed to use
2463 for (FDev
= mFlashDevices
; FDev
!= NULL
; FDev
= FDev
->Next
) {
2464 if (strcmp (FDev
->Name
, FlashDeviceName
) == 0) {
2470 Error (NULL
, 0, 0, FlashDeviceName
, "flash device not found in flash definitions");
2471 return STATUS_ERROR
;
2474 if ((OutFptr
= fopen (FileName
, "w")) == NULL
) {
2475 Error (NULL
, 0, 0, FileName
, "failed to open output file for writing");
2476 return STATUS_ERROR
;
2479 // Write the flash base address and size
2481 fprintf (OutFptr
, "\n");
2482 fprintf (OutFptr
, "FLASH_BASE = 0x%08X\n", FDev
->BaseAddress
);
2483 fprintf (OutFptr
, "FLASH_SIZE = 0x%08X\n\n", FDev
->Size
);
2485 // Write flash block size and offset defines
2488 for (FBlock
= FDev
->Regions
; FBlock
!= NULL
; FBlock
= FBlock
->Next
) {
2491 "FLASH_REGION_%s_BASE %*c= 0x%08X\n",
2493 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2495 Offset
+ FDev
->BaseAddress
2499 "FLASH_REGION_%s_SIZE %*c= 0x%08X\n",
2501 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2507 "FLASH_REGION_%s_SIZE_BLOCKS %*c= 0x%x\n",
2509 COLUMN2_START
- 40 - strlen (FBlock
->Name
),
2511 (FBlock
->Size
)/(FDev
->PBlocks
->Size
)
2514 // Create defines for any subregions
2516 SubregionOffset
= 0;
2517 for (Subregion
= FBlock
->Subregions
; Subregion
!= NULL
; Subregion
= Subregion
->Next
) {
2520 "FLASH_REGION_%s_SUBREGION_%s_BASE %*c= 0x%08X\n",
2523 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2525 FDev
->BaseAddress
+ Offset
+ SubregionOffset
2529 "FLASH_REGION_%s_SUBREGION_%s_SIZE %*c= 0x%08X\n",
2532 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2538 "FLASH_REGION_%s_SUBREGION_%s_OFFSET %*c= 0x%08X\n",
2541 COLUMN3_START
- 48 - strlen (FBlock
->Name
) - strlen (Subregion
->Name
),
2543 Offset
+ SubregionOffset
2546 SubregionOffset
+= Subregion
->Size
;
2549 Offset
+= FBlock
->Size
;
2554 fprintf (OutFptr
, "\n");
2556 return STATUS_SUCCESS
;
2562 Routine Description:
2563 The following buffer management routines are used to encapsulate functionality
2564 for managing a growable data buffer.
2567 BUFFER_DATA - structure that is used to maintain a data buffer
2580 Routine Description:
2582 Create a growable data buffer with default buffer length.
2590 NULL - error occured during data buffer creation
2591 Not NULL - the pointer to the newly created data buffer
2596 BD
= (BUFFER_DATA
*) _malloc (sizeof (BUFFER_DATA
));
2598 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2602 memset (BD
, 0, sizeof (BUFFER_DATA
));
2603 BD
->BufferStart
= (char *) _malloc (BUFFER_SIZE
);
2604 if (BD
->BufferStart
== NULL
) {
2606 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2610 BD
->BufferEnd
= BD
->BufferStart
+ BUFFER_SIZE
;
2611 BD
->BufferPos
= BD
->BufferStart
;
2618 BUFFER_DATA
*Buffer
,
2623 Routine Description:
2625 Add a single byte to a growable data buffer, growing the buffer if required.
2629 Buffer - pointer to the growable data buffer to add a single byte to
2630 Data - value of the single byte data to be added
2634 TRUE - the single byte data was successfully added
2635 FALSE - error occurred, the single byte data was not added
2642 // See if we have to grow the buffer
2644 if (Buffer
->BufferPos
>= Buffer
->BufferEnd
) {
2645 Size
= (int) Buffer
->BufferEnd
- (int) Buffer
->BufferStart
;
2646 NewBuffer
= (char *) _malloc (Size
+ BUFFER_SIZE
);
2647 if (NewBuffer
== NULL
) {
2648 Error (__FILE__
, __LINE__
, 0, "memory allocation failure", NULL
);
2652 memcpy (NewBuffer
, Buffer
->BufferStart
, Size
);
2653 _free (Buffer
->BufferStart
);
2654 Buffer
->BufferStart
= NewBuffer
;
2655 Buffer
->BufferPos
= Buffer
->BufferStart
+ Size
;
2656 Buffer
->BufferEnd
= Buffer
->BufferStart
+ Size
+ BUFFER_SIZE
;
2659 *Buffer
->BufferPos
= Data
;
2660 Buffer
->BufferPos
++;
2667 BUFFER_DATA
*Buffer
,
2672 Routine Description:
2674 Free memory used to manage a growable data buffer.
2678 Buffer - pointer to the growable data buffer to be destructed
2679 FreeData - TRUE, free memory containing the buffered data
2680 FALSE, do not free the buffered data memory
2688 if (Buffer
!= NULL
) {
2689 if (FreeData
&& (Buffer
->BufferStart
!= NULL
)) {
2690 _free (Buffer
->BufferStart
);
2700 BUFFER_DATA
*Buffer
,
2705 Routine Description:
2707 Return a pointer and size of the data in a growable data buffer.
2711 Buffer - pointer to the growable data buffer
2712 BufferSize - size of the data in the growable data buffer
2716 pointer of the data in the growable data buffer
2720 *BufferSize
= (int) Buffer
->BufferPos
- (int) Buffer
->BufferStart
;
2721 return Buffer
->BufferStart
;
2727 unsigned int BaseAddr
2731 Routine Description:
2732 Walk a binary image and see if you find anything that looks like a
2736 FDFileName - name of input FD image to parse
2737 BaseAddr - base address of input FD image
2740 STATUS_SUCCESS - no errors or warnings
2741 STATUS_WARNING - warnings, but no errors, were encountered
2742 STATUS_ERROR - errors were encountered
2745 This routine is used for debug purposes only.
2752 EFI_FIRMWARE_VOLUME_HEADER FVHeader
;
2754 FileSystemGuid
= { 0x7A9354D9, 0x0468, 0x444a, 0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF };
2756 if ((InFptr
= fopen (FDFileName
, "rb")) == NULL
) {
2757 Error (NULL
, 0, 0, FDFileName
, "failed to open file for reading");
2758 return STATUS_ERROR
;
2761 fseek (InFptr
, 0, SEEK_END
);
2762 FileSize
= ftell (InFptr
);
2763 fseek (InFptr
, 0, SEEK_SET
);
2765 while (Offset
< FileSize
) {
2766 fseek (InFptr
, Offset
, SEEK_SET
);
2768 // Read the contents of the file, see if it's an FV header
2770 if (fread (&FVHeader
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
), 1, InFptr
) == 1) {
2772 // Check version and GUID
2774 if ((FVHeader
.Revision
== EFI_FVH_REVISION
) && (FVHeader
.Signature
== EFI_FVH_SIGNATURE
)) {
2775 fprintf (stdout
, "FV header at 0x%08X FVSize=0x%08X ", Offset
+ BaseAddr
, (UINT32
) FVHeader
.FvLength
);
2776 if (memcmp (&FVHeader
.FileSystemGuid
, &FileSystemGuid
, sizeof (EFI_GUID
)) == 0) {
2777 fprintf (stdout
, "standard FFS file system\n");
2779 fprintf (stdout
, "non-standard FFS file system\n");
2784 Offset
+= 16 * 1024;
2788 return STATUS_SUCCESS
;