]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFv/GenFvInternalLib.c
add missing <BR>
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFvInternalLib.c
index 189dc431ebda71baf86514f0b87541003f00822b..45a2c8022d77db0b1c362990209a5425019bd647 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -209,6 +209,7 @@ Returns:
       DebugMsg (NULL, 0, 9, "rebase address", "%s = %s", EFI_FV_BASE_ADDRESS_STRING, Value);\r
 \r
       FvInfo->BaseAddress = Value64;\r
+      FvInfo->BaseAddressSet = TRUE;\r
     }\r
   }\r
 \r
@@ -1085,7 +1086,11 @@ Returns:
       // Rebase the PE or TE image in FileBuffer of FFS file for XIP \r
       // Rebase for the debug genfvmap tool\r
       //\r
-      FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile);\r
+      Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile);\r
+      if (EFI_ERROR (Status)) {\r
+        Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]);\r
+        return Status;\r
+      }          \r
       //\r
       // copy VTF File\r
       //\r
@@ -1124,7 +1129,11 @@ Returns:
     // Rebase the PE or TE image in FileBuffer of FFS file for XIP. \r
     // Rebase Bs and Rt drivers for the debug genfvmap tool.\r
     //\r
-    FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile);\r
+    Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile);\r
+       if (EFI_ERROR (Status)) {\r
+         Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]);\r
+         return Status;\r
+       }               \r
     //\r
     // Copy the file\r
     //\r
@@ -2792,7 +2801,6 @@ Returns:
   PE_COFF_LOADER_IMAGE_CONTEXT          OrigImageContext;  \r
   EFI_PHYSICAL_ADDRESS                  XipBase;\r
   EFI_PHYSICAL_ADDRESS                  NewPe32BaseAddress;\r
-  EFI_PHYSICAL_ADDRESS                  *BaseToUpdate;\r
   UINTN                                 Index;\r
   EFI_FILE_SECTION_POINTER              CurrentPe32Section;\r
   EFI_FFS_FILE_STATE                    SavedState;\r
@@ -2809,7 +2817,6 @@ Returns:
 \r
   Index              = 0;  \r
   MemoryImagePointer = NULL;\r
-  BaseToUpdate       = NULL;\r
   TEImageHeader      = NULL;\r
   ImgHdr             = NULL;\r
   SectionHeader      = NULL;\r
@@ -2818,11 +2825,20 @@ Returns:
   PeFileBuffer       = NULL;\r
 \r
   //\r
-  // Don't need to relocate image when BaseAddress is not set.\r
+  // Don't need to relocate image when BaseAddress is zero and no ForceRebase Flag specified.\r
+  //\r
+  if ((FvInfo->BaseAddress == 0) && (FvInfo->ForceRebase == -1)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  //\r
+  // If ForceRebase Flag specified to FALSE, will always not take rebase action.\r
   //\r
-  if (FvInfo->BaseAddress == 0) {\r
+  if (FvInfo->ForceRebase == 0) {\r
     return EFI_SUCCESS;\r
   }\r
+\r
+\r
   XipBase = FvInfo->BaseAddress + XipOffset;\r
 \r
   //\r
@@ -2974,7 +2990,6 @@ Returns:
         }\r
 \r
         NewPe32BaseAddress = XipBase + (UINTN) CurrentPe32Section.Pe32Section + sizeof (EFI_PE32_SECTION) - (UINTN)FfsFile;\r
-        BaseToUpdate = &XipBase;\r
         break;\r
 \r
       case EFI_FV_FILETYPE_DRIVER:\r
@@ -2990,7 +3005,6 @@ Returns:
           return EFI_ABORTED;\r
         }\r
         NewPe32BaseAddress = XipBase + (UINTN) CurrentPe32Section.Pe32Section + sizeof (EFI_PE32_SECTION) - (UINTN)FfsFile;\r
-        BaseToUpdate = &XipBase;                       \r
         break;\r
 \r
       default:\r
@@ -3020,7 +3034,7 @@ Returns:
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
-    ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~((INT64)ImageContext.SectionAlignment - 1));\r
+    ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~((UINTN) ImageContext.SectionAlignment - 1));\r
     \r
     Status =  PeCoffLoaderLoadImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
@@ -3247,7 +3261,7 @@ Returns:
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
-    ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~(ImageContext.SectionAlignment - 1));\r
+    ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~((UINTN) ImageContext.SectionAlignment - 1));\r
 \r
     Status =  PeCoffLoaderLoadImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r