X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FCCode%2FSource%2FFwImage%2Ffwimage.c;fp=Tools%2FCCode%2FSource%2FFwImage%2Ffwimage.c;h=a4ae10c4c26dcbd23a4008fd12433dd652301aec;hp=beddd8ee08557b47d415dc2500159dbc9506ecb8;hb=189985640da8be75d1c4ca46690e8e2b8f38f7b1;hpb=265bfe7cd4afbaae1f5af255daedf8b1c77d6a78 diff --git a/Tools/CCode/Source/FwImage/fwimage.c b/Tools/CCode/Source/FwImage/fwimage.c index beddd8ee08..a4ae10c4c2 100644 --- a/Tools/CCode/Source/FwImage/fwimage.c +++ b/Tools/CCode/Source/FwImage/fwimage.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2004, Intel Corporation +Copyright (c) 2004 - 2007, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -240,7 +240,7 @@ INTN CheckElfHeader( VOID ) -{ +{ // // Note: Magic has already been tested. // @@ -254,11 +254,15 @@ CheckElfHeader( return 0; if (Ehdr->e_version != EV_CURRENT) return 0; - + + // + // Find the section header table + // 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)); + + memset(CoffSectionsOffset, 0, Ehdr->e_shnum * sizeof(UINT32)); return 1; } @@ -269,7 +273,7 @@ IsTextShdr( { return (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC; } - + int IsDataShdr( Elf_Shdr *Shdr @@ -331,18 +335,22 @@ ScanSections( TextOffset = CoffOffset; for (i = 0; i < Ehdr->e_shnum; i++) { Elf_Shdr *shdr = GetShdrByIndex(i); - if (IsTextShdr(shdr)) { + if (IsTextShdr(shdr)) { + // + // Align the coff offset + // + CoffOffset = (CoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1); /* 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) && + (Ehdr->e_entry < shdr->sh_addr + shdr->sh_size)) { + CoffEntry = CoffOffset + Ehdr->e_entry - shdr->sh_addr; } - CoffSectionsOffset[i] = CoffOffset; + CoffSectionsOffset[i] = CoffOffset; CoffOffset += shdr->sh_size; - } - } + } + } CoffOffset = CoffAlign(CoffOffset); - + // // Then data sections. //