Let specify GUID value for GUID-defined FV region, and remove potential dead loop...
[mirror_edk2.git] / Tools / CCode / Source / FlashMap / FlashDefFile.c
index 0bfdad2..5a9205a 100644 (file)
@@ -76,6 +76,8 @@ typedef struct _FLASH_BLOCK_DESCRIPTION {
   unsigned int                    Alignment;                  // power of 2 alignment\r
   WCHAR_T                         Attributes[MAX_ATTR_LEN];   // only used for Region definitions\r
   WCHAR_T                         AreaType[MAX_AREATYPE_LEN]; // only used for Region definitions\r
+  EFI_GUID                        AreaTypeGuid;\r
+  WCHAR_T                         AreaTypeGuidString[MAX_NAME_LEN];\r
   FLASH_SUBREGION_DESCRIPTION     *Subregions;\r
   FLASH_SUBREGION_DESCRIPTION     *LastSubregion;\r
 } FLASH_BLOCK_DESCRIPTION;\r
@@ -795,6 +797,41 @@ Returns:
       }\r
 \r
       PreviousComma = SFPIsToken (",");\r
+      //\r
+      // Parse optional attribute "AreaTypeGuid"\r
+      //\r
+      if (SFPIsKeyword ("AreaTypeGuid")) {\r
+        //\r
+        // Check for preceeding comma now\r
+        //\r
+        if (!PreviousComma) {\r
+          Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected ',' before 'AreaTypeGuid'", NULL);\r
+          WarningCount++;\r
+        }\r
+        \r
+        if (!SFPIsToken ("=")) {\r
+          Warning (SFPGetFileName (), SFPGetLineNumber (), 0, "expected '='", NULL);\r
+          WarningCount++;\r
+        }\r
+        \r
+        if (SFPGetQuotedString (FBlockDesc->AreaTypeGuidString, sizeof (FBlockDesc->AreaTypeGuidString))) {\r
+          //\r
+          // Nothing else to do\r
+          //\r
+        } else if (!SFPGetGuid (PARSE_GUID_STYLE_5_FIELDS, &FBlockDesc->AreaTypeGuid)) {\r
+          Error (\r
+            SFPGetFileName (),\r
+            SFPGetLineNumber (),\r
+            0,\r
+            "expected AreaTypeGuid quoted string or GUID of form 12345678-1234-1234-1234-123456789ABC",\r
+            NULL\r
+            );\r
+          ErrorCount++;\r
+          goto Done;\r
+        }\r
+        PreviousComma = SFPIsToken (",");\r
+      }\r
+\r
       //\r
       // Parse optional Subregion definitions\r
       //\r
@@ -1781,7 +1818,32 @@ Returns:
     fprintf (OutFptr, "    FLASH_REGION_%s_BASE,\\\n", FBlock->Name);\r
     fprintf (OutFptr, "    FLASH_REGION_%s_SIZE,\\\n", FBlock->Name);\r
     fprintf (OutFptr, "    %s,\\\n", FBlock->Attributes);\r
-    fprintf (OutFptr, "    %s,\\\n  },\\\n", FBlock->AreaType);\r
+    fprintf (OutFptr, "    %s,\\\n", FBlock->AreaType);\r
+    fprintf (OutFptr, "    0, 0, 0,\\\n");\r
+    //\r
+    // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or\r
+    // as a quoted string. Do the right one.\r
+    //\r
+    if (FBlock->AreaTypeGuidString[0] != 0) {\r
+      fprintf (OutFptr, "    %s, \\\n", FBlock->AreaTypeGuidString);\r
+    } else {\r
+      fprintf (\r
+        OutFptr,\r
+        "    { 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },\\\n",\r
+        FBlock->AreaTypeGuid.Data1,\r
+        (unsigned int) FBlock->AreaTypeGuid.Data2,\r
+        (unsigned int) FBlock->AreaTypeGuid.Data3,\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[0],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[1],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[2],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[3],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[4],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[5],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[6],\r
+        (unsigned int) FBlock->AreaTypeGuid.Data4[7]\r
+        );\r
+    }\r
+    fprintf (OutFptr, "  },\\\n");\r
   }\r
 \r
   fprintf (OutFptr, "\n\n");\r