]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
Enhance peirebase tool to get base address from the corresponding fv.inf file, which...
[mirror_edk2.git] / Tools / CCode / Source / PeiRebase / PeiRebaseExe.c
index 27c646e486fab1b86699270498f41ec2e0fe001b..d27083aceb5acbc0072705cc79539f82bb5f959c 100644 (file)
@@ -100,6 +100,10 @@ Returns:
   EFI_FFS_FILE_HEADER         *CurrentFile;\r
   BOOLEAN                     ErasePolarity;\r
   EFI_PHYSICAL_ADDRESS        CurrentFileBaseAddress;\r
+  CHAR8                       InfFileName[_MAX_PATH];\r
+  CHAR8                       *InfFileImage;\r
+  UINTN                       InfFileSize;\r
+  MEMORY_FILE                 InfMemoryFile;\r
 \r
   ErasePolarity = FALSE;\r
   //\r
@@ -129,6 +133,9 @@ Returns:
   OutputFile        = NULL;\r
   MapFile           = NULL;\r
   FvImage           = NULL;\r
+  InfFileImage      = NULL;\r
+  InfFileSize       = 0;\r
+  strcpy (InfFileName, "");\r
 \r
   //\r
   // Parse the command line arguments\r
@@ -194,6 +201,52 @@ Returns:
       }\r
       break;\r
 \r
+    case 'F':\r
+    case 'f':\r
+      if (!BaseAddressSet) {\r
+        strcpy (InfFileName, argv[Index + 1]);\r
+        //\r
+        // Read the INF file image\r
+        //\r
+        Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r
+        if (EFI_ERROR (Status)) {\r
+          PrintUsage ();\r
+          Error (NULL, 0, 0, argv[Index + 1], "-f FvInfFile can't be opened.");\r
+          return STATUS_ERROR;\r
+        }\r
+        //\r
+        // Initialize file structures\r
+        //\r
+        InfMemoryFile.FileImage           = InfFileImage;\r
+        InfMemoryFile.CurrentFilePointer  = InfFileImage;\r
+        InfMemoryFile.Eof                 = InfFileImage + InfFileSize;\r
+        //\r
+        // Read BaseAddress from fv.inf file.\r
+        //\r
+        FindToken (&InfMemoryFile, "[options]", "EFI_BASE_ADDRESS", 0, InfFileName);\r
+        //\r
+        // free Inf File Image\r
+        //\r
+        free (InfFileImage);\r
+        \r
+        //\r
+        // Convert string to UINT64 base address.\r
+        //\r
+        Status = AsciiStringToUint64 (InfFileName, FALSE, &BaseAddress);\r
+        if (EFI_ERROR (Status)) {\r
+          PrintUsage ();\r
+          Error (NULL, 0, 0, argv[Index + 1], "can't find the base address in the specified fv.inf file.");\r
+          return STATUS_ERROR;\r
+        }\r
+\r
+        BaseAddressSet = TRUE;\r
+      } else {\r
+        PrintUsage ();\r
+        Error (NULL, 0, 0, argv[Index + 1], "BaseAddress has been got once from fv.inf or the specified base address.");\r
+        return STATUS_ERROR;\r
+      }\r
+      break;\r
+\r
     case 'M':\r
     case 'm':\r
       if (strlen (MapFileName) == 0) {\r
@@ -212,7 +265,7 @@ Returns:
       break;\r
     }\r
   }\r
-\r
+  \r
   //\r
   // Create the Map file if we need it\r
   //\r
@@ -486,15 +539,18 @@ Returns:
 --*/\r
 {\r
   printf (\r
-    "Usage: %s -I InputFileName -O OutputFileName -B BaseAddress [-M MapFile]\n",\r
+    "Usage: %s -I InputFileName -O OutputFileName [-B BaseAddress] -F FvInfFileName -M MapFile\n",\r
     UTILITY_NAME\r
     );\r
   printf ("  Where:\n");\r
-  printf ("    InputFileName is the name of the EFI FV file to rebase.\n");\r
+  printf ("    InputFileName  is the name of the EFI FV file to rebase.\n");\r
   printf ("    OutputFileName is the desired output file name.\n");\r
-  printf ("    BaseAddress is the FV base address to rebase agains.\n");\r
-  printf ("    MapFileName is an optional map file of the relocations\n");\r
-  printf ("  Argument pair may be in any order.\n\n");\r
+  printf ("    BaseAddress    is the FV base address to rebase agains.\n");\r
+  printf ("    FvInfFileName  is the fv.inf to be used to generate this fv image.\n");\r
+  printf ("                   BaseAddress can also be got from the fv.inf file.\n");\r
+  printf ("                   Choose only one method to input BaseAddress.\n");\r
+  printf ("    MapFileName    is an optional map file of the relocations\n");\r
+  printf ("    Argument pair may be in any order.\n\n");\r
 }\r
 \r
 EFI_STATUS\r