]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/FwImage/fwimage.c
The alignment of data section also meet with the requirement of section itself.
[mirror_edk2.git] / Tools / CCode / Source / FwImage / fwimage.c
index fb3f1a7ecdb593d12f3a54282ad665336d46b2c1..11090952cd61d27162bc8b75ffee933ffdea8d12 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2004, Intel Corporation                                                         \r
+Copyright (c) 2004 - 2007, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -240,7 +240,7 @@ INTN
 CheckElfHeader(
   VOID
   )
-{
+{\r
   //
   // Note: Magic has already been tested.
   //
@@ -254,11 +254,15 @@ CheckElfHeader(
     return 0;
   if (Ehdr->e_version != EV_CURRENT)
     return 0;
-  
+\r
+  //\r
+  // Find the section header table\r
+  // 
   ShdrBase = (Elf_Shdr *)((UINT8 *)Ehdr + Ehdr->e_shoff);
 
-  CoffSectionsOffset = (UINT32 *)malloc(Ehdr->e_shnum * sizeof (UINT32));
-  memset(CoffSectionsOffset, 0, Ehdr->e_shnum * sizeof(UINT32));
+  CoffSectionsOffset = (UINT32 *)malloc(Ehdr->e_shnum * sizeof (UINT32));\r
+
+  memset(CoffSectionsOffset, 0, Ehdr->e_shnum * sizeof(UINT32));\r
   return 1;
 }
 
@@ -269,7 +273,7 @@ IsTextShdr(
 {
   return (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC;
 }
-
+\r
 int
 IsDataShdr(
   Elf_Shdr *Shdr
@@ -331,25 +335,37 @@ ScanSections(
   TextOffset = CoffOffset;
   for (i = 0; i < Ehdr->e_shnum; i++) {
     Elf_Shdr *shdr = GetShdrByIndex(i);
-    if (IsTextShdr(shdr)) {
+    if (IsTextShdr(shdr)) {\r
+      //\r
+      // Align the coff offset to meet with the alignment requirement of section\r
+      // itself.\r
+      // \r
+      CoffOffset = (CoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1);\r
+\r
       /* Relocate entry.  */
-      if (Ehdr->e_entry >= shdr->sh_addr
-         && Ehdr->e_entry < shdr->sh_addr + shdr->sh_size) {
-       CoffEntry = CoffOffset + Ehdr->e_entry - shdr->sh_addr;
+      if ((Ehdr->e_entry >= shdr->sh_addr) && \r
+          (Ehdr->e_entry < shdr->sh_addr + shdr->sh_size)) {
+        CoffEntry = CoffOffset + Ehdr->e_entry - shdr->sh_addr;
       }
-      CoffSectionsOffset[i] = CoffOffset;
+      CoffSectionsOffset[i] = CoffOffset;\r
       CoffOffset += shdr->sh_size;
-    }
-  }
+    }\r
+  }\r
   CoffOffset = CoffAlign(CoffOffset);
-                      
+\r
   //
   //  Then data sections.
   //
   DataOffset = CoffOffset;
   for (i = 0; i < Ehdr->e_shnum; i++) {
     Elf_Shdr *shdr = GetShdrByIndex(i);
-    if (IsDataShdr(shdr)) {
+    if (IsDataShdr(shdr)) {\r
+      //\r
+      // Align the coff offset to meet with the alignment requirement of section\r
+      // itself.\r
+      // \r
+      CoffOffset = (CoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1);\r
+
       CoffSectionsOffset[i] = CoffOffset;
       CoffOffset += shdr->sh_size;
     }
@@ -762,7 +778,7 @@ Returns:
   TimeStamp         = 0;\r
   TimeStampPresent  = FALSE;\r
 \r
-  if (argc < 1) {\r
+  if (argc == 1) {\r
     Usage();\r
     return STATUS_ERROR;\r
   }\r