]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix EdkII tracker 223 to enhance genfvimage tool to support TE image format. If so...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 Sep 2006 12:30:25 +0000 (12:30 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 Sep 2006 12:30:25 +0000 (12:30 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1431 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/TianoTools/GenFvImage/GenFvImageLib.c

index 379818b7edfab3052ea7fb41ecf13a6cd5e2205e..888656ad5c9f586aa814dfac6b17d7542b41c77a 100644 (file)
@@ -1354,9 +1354,7 @@ Returns:
   UINT32                    EntryPoint;\r
   UINT32                    BaseOfCode;\r
   UINT16                    MachineType;\r
   UINT32                    EntryPoint;\r
   UINT32                    BaseOfCode;\r
   UINT16                    MachineType;\r
-  EFI_TE_IMAGE_HEADER       *TeHdr;\r
 \r
 \r
-  TeHdr = NULL;\r
   //\r
   // Verify input parameters.\r
   //\r
   //\r
   // Verify input parameters.\r
   //\r
@@ -1431,27 +1429,31 @@ Returns:
   //\r
   if (Status == EFI_NOT_FOUND) {\r
     Status = GetSectionByType (FfsFile, EFI_SECTION_TE, 1, &Pe32Section);\r
   //\r
   if (Status == EFI_NOT_FOUND) {\r
     Status = GetSectionByType (FfsFile, EFI_SECTION_TE, 1, &Pe32Section);\r
-    if (Status == EFI_NOT_FOUND) {\r
-      BaseOfCode = 0x60;\r
-    } else {\r
-      TeHdr       = (EFI_TE_IMAGE_HEADER *) ((UINTN) Pe32Section.Pe32Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
-      BaseOfCode  = TeHdr->BaseOfCode - TeHdr->StrippedSize;\r
-    }\r
-  } else if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0, "could not parse a PE32 section from the PEI file", NULL);\r
-    return Status;\r
-  } else {\r
+  }\r
+\r
+  if (Status == EFI_SUCCESS) {\r
     Status = GetPe32Info (\r
               (VOID *) ((UINTN) Pe32Section.Pe32Section + sizeof (EFI_SECTION_PE32)),\r
               &EntryPoint,\r
               &BaseOfCode,\r
               &MachineType\r
               );\r
     Status = GetPe32Info (\r
               (VOID *) ((UINTN) Pe32Section.Pe32Section + sizeof (EFI_SECTION_PE32)),\r
               &EntryPoint,\r
               &BaseOfCode,\r
               &MachineType\r
               );\r
-    if (EFI_ERROR (Status)) {\r
-      Error (NULL, 0, 0, "GetPe32Info() could not get PE32 entry point for PEI file", NULL);\r
-      return Status;\r
-    }\r
+  } else if (Status == EFI_NOT_FOUND) {\r
+    //\r
+    // For PIC, hardcode.\r
+    //\r
+    BaseOfCode = 0x60;\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    Error (NULL, 0, 0, "could not parse a PE32 section from the PEI file", NULL);\r
+    return Status;\r
   }\r
   }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    Error (NULL, 0, 0, "GetPe32Info() could not get PE32 entry point for PEI file", NULL);\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Open the source file\r
   //\r
   //\r
   // Open the source file\r
   //\r
@@ -1508,9 +1510,9 @@ Returns:
       TokenAddress += BaseAddress;\r
 \r
       //\r
       TokenAddress += BaseAddress;\r
 \r
       //\r
-      // If PE32 then find the start of code.  For PIC it is hardcoded.\r
+      // If PE32 or TE section then find the start of code.  For PIC it is hardcoded.\r
       //\r
       //\r
-      if (TeHdr == NULL && Pe32Section.Pe32Section) {\r
+      if (Pe32Section.Pe32Section) {\r
         //\r
         // Add the offset of the PE32 section\r
         //\r
         //\r
         // Add the offset of the PE32 section\r
         //\r
@@ -1520,20 +1522,13 @@ Returns:
         // Add the size of the PE32 section header\r
         //\r
         TokenAddress += sizeof (EFI_PE32_SECTION);\r
         // Add the size of the PE32 section header\r
         //\r
         TokenAddress += sizeof (EFI_PE32_SECTION);\r
-      } else if (TeHdr != NULL) {\r
-        //\r
-        // Add the Te section and FfsHeader\r
-        //\r
-        //\r
-        //  BUGBUG: Don't know why this is 0x28 bytes.\r
-        //\r
-        TokenAddress += (UINTN) TeHdr - (UINTN) FfsFile + 0x28;\r
       } else {\r
         //\r
       } else {\r
         //\r
-        // BUGBUG: Don't know why this is 0x28 bytes.\r
+        // For PIC hardcoded.\r
         //\r
         TokenAddress += 0x28;\r
       }\r
         //\r
         TokenAddress += 0x28;\r
       }\r
+\r
       //\r
       // Add the beginning of the code\r
       //\r
       //\r
       // Add the beginning of the code\r
       //\r
@@ -2114,12 +2109,17 @@ Returns:
     Error (NULL, 0, 0, "could not find the PEI core in the FV", NULL);\r
     return EFI_ABORTED;\r
   }\r
     Error (NULL, 0, 0, "could not find the PEI core in the FV", NULL);\r
     return EFI_ABORTED;\r
   }\r
+\r
   //\r
   //\r
-  // PEI Core found, now find PE32 section\r
+  // PEI Core found, now find PE32 or TE section\r
   //\r
   Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);\r
   //\r
   Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);\r
+  if (Status == EFI_NOT_FOUND) {\r
+    Status = GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, &Pe32Section);\r
+  }\r
+\r
   if (EFI_ERROR (Status)) {\r
   if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0, "could not find PE32 section in PEI core file", NULL);\r
+    Error (NULL, 0, 0, "could not find PE32 or TE section in PEI core file", NULL);\r
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
@@ -2129,6 +2129,7 @@ Returns:
             &BaseOfCode,\r
             &MachineType\r
             );\r
             &BaseOfCode,\r
             &MachineType\r
             );\r
+\r
   if (EFI_ERROR (Status)) {\r
     Error (NULL, 0, 0, "could not get PE32 entry point for PEI core", NULL);\r
     return EFI_ABORTED;\r
   if (EFI_ERROR (Status)) {\r
     Error (NULL, 0, 0, "could not get PE32 entry point for PEI core", NULL);\r
     return EFI_ABORTED;\r
@@ -2322,9 +2323,9 @@ GetPe32Info (
 \r
 Routine Description:\r
 \r
 \r
 Routine Description:\r
 \r
-  Retrieves the PE32 entry point offset and machine type.  See EfiImage.h for\r
-  machine types.  The entry point offset is from the beginning of the PE32\r
-  buffer passed in.\r
+  Retrieves the PE32 entry point offset and machine type from PE image or TeImage.  \r
+  See EfiImage.h for machine types.  The entry point offset is from the beginning \r
+  of the PE32 buffer passed in.\r
 \r
 Arguments:\r
 \r
 \r
 Arguments:\r
 \r
@@ -2344,6 +2345,7 @@ Returns:
 {\r
   EFI_IMAGE_DOS_HEADER  *DosHeader;\r
   EFI_IMAGE_NT_HEADERS  *NtHeader;\r
 {\r
   EFI_IMAGE_DOS_HEADER  *DosHeader;\r
   EFI_IMAGE_NT_HEADERS  *NtHeader;\r
+  EFI_TE_IMAGE_HEADER   *TeHeader;\r
 \r
   //\r
   // Verify input parameters\r
 \r
   //\r
   // Verify input parameters\r
@@ -2351,36 +2353,52 @@ Returns:
   if (Pe32 == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (Pe32 == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  //\r
-  // First is the DOS header\r
-  //\r
-  DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;\r
-\r
-  //\r
-  // Verify DOS header is expected\r
-  //\r
-  if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
-    printf ("ERROR: Unknown magic number in the DOS header, 0x%04X.\n", DosHeader->e_magic);\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-  //\r
-  // Immediately following is the NT header.\r
-  //\r
-  NtHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32 + DosHeader->e_lfanew);\r
 \r
   //\r
 \r
   //\r
-  // Verify NT header is expected\r
+  // First check whether it is one TE Image.\r
   //\r
   //\r
-  if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
-    printf ("ERROR: Unrecognized image signature 0x%08X.\n", NtHeader->Signature);\r
-    return EFI_UNSUPPORTED;\r
+  TeHeader = (EFI_TE_IMAGE_HEADER *) Pe32;\r
+  if (TeHeader->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    //\r
+    // By TeImage Header to get output\r
+    //\r
+    *EntryPoint   = TeHeader->AddressOfEntryPoint + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;\r
+    *BaseOfCode   = TeHeader->BaseOfCode + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;\r
+    *MachineType  = TeHeader->Machine;\r
+  } else {\r
+  \r
+    //\r
+    // Then check whether \r
+    // First is the DOS header\r
+    //\r
+    DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;\r
+  \r
+    //\r
+    // Verify DOS header is expected\r
+    //\r
+    if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
+      printf ("ERROR: Unknown magic number in the DOS header, 0x%04X.\n", DosHeader->e_magic);\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    //\r
+    // Immediately following is the NT header.\r
+    //\r
+    NtHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32 + DosHeader->e_lfanew);\r
+  \r
+    //\r
+    // Verify NT header is expected\r
+    //\r
+    if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
+      printf ("ERROR: Unrecognized image signature 0x%08X.\n", NtHeader->Signature);\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    //\r
+    // Get output\r
+    //\r
+    *EntryPoint   = NtHeader->OptionalHeader.AddressOfEntryPoint;\r
+    *BaseOfCode   = NtHeader->OptionalHeader.BaseOfCode;\r
+    *MachineType  = NtHeader->FileHeader.Machine;\r
   }\r
   }\r
-  //\r
-  // Get output\r
-  //\r
-  *EntryPoint   = NtHeader->OptionalHeader.AddressOfEntryPoint;\r
-  *BaseOfCode   = NtHeader->OptionalHeader.BaseOfCode;\r
-  *MachineType  = NtHeader->FileHeader.Machine;\r
 \r
   //\r
   // Verify machine type is supported\r
 \r
   //\r
   // Verify machine type is supported\r