Let specify GUID value for GUID-defined FV region, and remove potential dead loop...
[mirror_edk2.git] / Tools / CCode / Source / FlashMap / FlashDefFile.c
index cdbf7886ece5d34e145a9fb78486c41f67017e12..5a9205ab36c1fa5d54e0d5ac7b162b8a5b0c0f11 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
@@ -1813,9 +1875,9 @@ Returns:
             fprintf (OutFptr, " \\\n");\r
             fprintf (OutFptr, "  /* %s.%s Subregion */\\\n", FBlock->Name, Subregion->Name);\r
             fprintf (OutFptr, "  {\\\n");\r
-            fprintf (OutFptr, "    EFI_HOB_TYPE_GUID_EXTENSION,\\\n");\r
+            fprintf (OutFptr, "    {EFI_HOB_TYPE_GUID_EXTENSION,\\\n");\r
             fprintf (OutFptr, "    sizeof (EFI_HOB_FLASH_MAP_ENTRY_TYPE ),\\\n");\r
-            fprintf (OutFptr, "    0,\\\n");\r
+            fprintf (OutFptr, "    0},\\\n");\r
             //\r
             // The NameGuid may have been specified in the input flash definition file as a GUID, or\r
             // as a quoted string. Do the right one.\r
@@ -1825,7 +1887,7 @@ Returns:
             } 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
+                "    { 0x%08X, 0x%04X, 0x%04X, {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}},\\\n",\r
                 Subregion->NameGuid.Data1,\r
                 (unsigned int) Subregion->NameGuid.Data2,\r
                 (unsigned int) Subregion->NameGuid.Data3,\r
@@ -1840,7 +1902,7 @@ Returns:
                 );\r
             }\r
 \r
-            fprintf (OutFptr, "    0, 0, 0,\\\n");\r
+            fprintf (OutFptr, "    {0, 0, 0},\\\n");\r
             fprintf (OutFptr, "    %s,\\\n", Subregion->AreaType);\r
             //\r
             // The AreaTypeGuid may have been specified in the input flash definition file as a GUID, or\r
@@ -1851,7 +1913,7 @@ Returns:
             } 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
+                "    { 0x%08X, 0x%04X, 0x%04X, {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}},\\\n",\r
                 Subregion->AreaTypeGuid.Data1,\r
                 (unsigned int) Subregion->AreaTypeGuid.Data2,\r
                 (unsigned int) Subregion->AreaTypeGuid.Data3,\r
@@ -1867,7 +1929,7 @@ Returns:
             }\r
 \r
             fprintf (OutFptr, "    1,\\\n");\r
-            fprintf (OutFptr, "    {\\\n");\r
+            fprintf (OutFptr, "    {{\\\n");\r
             fprintf (OutFptr, "      %s,\\\n", Subregion->Attributes);\r
             fprintf (OutFptr, "      0,\\\n");\r
             fprintf (OutFptr, "      FLASH_REGION_%s_SUBREGION_%s_BASE,\\\n", FBlock->Name, Subregion->Name);\r
@@ -1881,7 +1943,7 @@ Returns:
             } 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
+                "      { 0x%08X, 0x%04X, 0x%04X, {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}},\\\n",\r
                 Subregion->FileSystemGuid.Data1,\r
                 (unsigned int) Subregion->FileSystemGuid.Data2,\r
                 (unsigned int) Subregion->FileSystemGuid.Data3,\r
@@ -1896,7 +1958,7 @@ Returns:
                 );\r
             }\r
 \r
-            fprintf (OutFptr, "    },\\\n");\r
+            fprintf (OutFptr, "    }},\\\n");\r
             fprintf (OutFptr, "  },");\r
           }\r
         }\r