Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 May 2012 17:40:34 +0000 (10:40 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 May 2012 17:40:34 +0000 (10:40 -0700)
Pull x86 EFI updates from Ingo Molnar:
 "This patchset makes changes to the bzImage EFI header, so that it can
  be signed with a secure boot signature tool.  It should not affect
  anyone who is not using the EFI self-boot feature in any way."

* 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86, efi: Fix NumberOfRvaAndSizes field in PE32 header for EFI_STUB
  x86, efi: Fix .text section overlapping image header for EFI_STUB
  x86, efi: Fix issue of overlapping .reloc section for EFI_STUB

1  2 
arch/x86/boot/compressed/eboot.c
arch/x86/boot/tools/build.c

@@@ -539,7 -539,7 +539,7 @@@ static efi_status_t handle_ramdisks(efi
                struct initrd *initrd;
                efi_file_handle_t *h;
                efi_file_info_t *info;
 -              efi_char16_t filename[256];
 +              efi_char16_t filename_16[256];
                unsigned long info_sz;
                efi_guid_t info_guid = EFI_FILE_INFO_ID;
                efi_char16_t *p;
                str += 7;
  
                initrd = &initrds[i];
 -              p = filename;
 +              p = filename_16;
  
                /* Skip any leading slashes */
                while (*str == '/' || *str == '\\')
                        str++;
  
                while (*str && *str != ' ' && *str != '\n') {
 -                      if (p >= filename + sizeof(filename))
 +                      if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16))
                                break;
  
                        *p++ = *str++;
                                goto free_initrds;
                }
  
 -              status = efi_call_phys5(fh->open, fh, &h, filename,
 +              status = efi_call_phys5(fh->open, fh, &h, filename_16,
                                        EFI_FILE_MODE_READ, (u64)0);
                if (status != EFI_SUCCESS)
                        goto close_handles;
@@@ -904,11 -904,19 +904,19 @@@ struct boot_params *efi_main(void *hand
  
        memset(boot_params, 0x0, 0x4000);
  
-       /* Copy first two sectors to boot_params */
-       memcpy(boot_params, image->image_base, 1024);
        hdr = &boot_params->hdr;
  
+       /* Copy the second sector to boot_params */
+       memcpy(&hdr->jump, image->image_base + 512, 512);
+       /*
+        * Fill out some of the header fields ourselves because the
+        * EFI firmware loader doesn't load the first sector.
+        */
+       hdr->root_flags = 1;
+       hdr->vid_mode = 0xffff;
+       hdr->boot_flag = 0xAA55;
        /*
         * The EFI firmware loader could have placed the kernel image
         * anywhere in memory, but the kernel has various restrictions
@@@ -198,42 -198,53 +198,60 @@@ int main(int argc, char ** argv
  
        pe_header = get_unaligned_le32(&buf[0x3c]);
  
-       /* Size of code */
-       put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
        /* Size of image */
        put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
  
+       /*
+        * Subtract the size of the first section (512 bytes) which
+        * includes the header and .reloc section. The remaining size
+        * is that of the .text section.
+        */
+       file_sz -= 512;
+       /* Size of code */
+       put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
  #ifdef CONFIG_X86_32
 -      /* Address of entry point */
 -      put_unaligned_le32(i, &buf[pe_header + 0x28]);
 +      /*
 +       * Address of entry point.
 +       *
 +       * The EFI stub entry point is +16 bytes from the start of
 +       * the .text section.
 +       */
 +      put_unaligned_le32(i + 16, &buf[pe_header + 0x28]);
  
        /* .text size */
        put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
  
+       /* .text vma */
+       put_unaligned_le32(0x200, &buf[pe_header + 0xb4]);
        /* .text size of initialised data */
        put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
+       /* .text file offset */
+       put_unaligned_le32(0x200, &buf[pe_header + 0xbc]);
  #else
        /*
         * Address of entry point. startup_32 is at the beginning and
         * the 64-bit entry point (startup_64) is always 512 bytes
 -       * after.
 +       * after. The EFI stub entry point is 16 bytes after that, as
 +       * the first instruction allows legacy loaders to jump over
 +       * the EFI stub initialisation
         */
 -      put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
 +      put_unaligned_le32(i + 528, &buf[pe_header + 0x28]);
  
        /* .text size */
        put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
  
+       /* .text vma */
+       put_unaligned_le32(0x200, &buf[pe_header + 0xc4]);
        /* .text size of initialised data */
        put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
  
+       /* .text file offset */
+       put_unaligned_le32(0x200, &buf[pe_header + 0xcc]);
  #endif /* CONFIG_X86_32 */
  #endif /* CONFIG_EFI_STUB */