Update the Linux boot protocol
PATCH v3 1/3 Update the Linux boot protocol
The Linux boot header includes information on the kernel's desired load address and alignment. Add support for that.
--- ChangeLog | 6 ++++++ include/grub/i386/linux.h | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-)
ChangeLog +6 -0
@@ -1,3 +1,9 @@ +2012-02-08 Matthew Garrett <[email protected]> + + * include/grub/i386/linux.h (linux_kernel_header): Update to + boot protocol 2.10. + (linux_kernel_params): Likewise + 2012-02-07 Vladimir Serbinenko <[email protected]> * grub-core/lib/i386/relocator16.S: Revert moving A20 code into PM
include/grub/i386/linux.h +23 -5
@@ -86,7 +86,7 @@ enumGRUB_VIDEO_LINUX_TYPE_SIMPLE =0x70 /* Linear framebuffer without any additional functions. */ }; -/* For the Linux/i386 boot protocol version 2.03. */ +/* For the Linux/i386 boot protocol version 2.10. */ struct linux_kernel_header {grub_uint8_t code1[0x0020 ];
@@ -131,8 +131,16 @@ struct linux_kernel_headergrub_uint32_t initrd_addr_max;/* Highest address for initrd */ grub_uint32_t kernel_alignment;grub_uint8_t relocatable; -grub_uint8_t pad[3 ]; +grub_uint8_t min_alignment; +grub_uint8_t pad[2 ];grub_uint32_t cmdline_size; +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint64_t pref_address; +grub_uint64_t init_size; } __attribute__ ((packed));/* Boot parameters for Linux based on 2.6.12. This is used by the setup
@@ -276,10 +284,20 @@ struct linux_kernel_paramsgrub_uint32_t ramdisk_size;/* initrd size */ grub_uint32_t bootsect_kludge;/* obsolete */ grub_uint16_t heap_end_ptr;/* Free memory after setup end */ -grub_uint16_t pad1;/* Unused */ +grub_uint8_t ext_loader_ver;/* Extended loader version */ +grub_uint8_t ext_loader_type;/* Extended loader type */ grub_uint32_t cmd_line_ptr;/* Points to the kernel command line */ - -grub_uint8_t pad2[164 ];/* 22c */ +grub_uint32_t initrd_addr_max;/* Maximum initrd address */ +grub_uint32_t kernel_alignment;/* Alignment of the kernel */ +grub_uint8_t relocatable_kernel;/* Is the kernel relocatable */ +grub_uint8_t pad1[3 ]; +grub_uint32_t cmdline_size;/* Size of the kernel command line */ +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint8_t pad2[120 ];/* 258 */ struct grub_e820_mmap e820_map[GRUB_E820_MAX_ENTRY ];/* 2d0 */ } __attribute__ ((packed));
Signature · 1 line
1.7.7.6
PATCH v3 2/3 Add support for avoiding firmware in relocations
EFI and OF both support firmware regions which may be in use during loading. Add support for avoiding these.
--- ChangeLog | 10 +++++ grub-core/lib/efi/relocator.c | 51 ++++++++++++++++++++++++++ grub-core/lib/ieee1275/relocator.c | 27 ++++++++++++++ grub-core/lib/relocator.c | 12 ++++++- grub-core/loader/i386/bsd.c | 19 ++++++---- grub-core/loader/i386/bsdXX.c | 8 ++-- grub-core/loader/i386/coreboot/chainloader.c | 2 +- grub-core/loader/i386/linux.c | 4 +- grub-core/loader/i386/multiboot_mbi.c | 2 +- grub-core/loader/i386/pc/chainloader.c | 4 +- grub-core/loader/i386/pc/freedos.c | 2 +- grub-core/loader/i386/pc/linux.c | 4 +- grub-core/loader/i386/pc/ntldr.c | 4 +- grub-core/loader/i386/pc/plan9.c | 4 +- grub-core/loader/i386/pc/pxechainloader.c | 2 +- grub-core/loader/mips/linux.c | 6 ++-- grub-core/loader/multiboot_elfxx.c | 2 +- grub-core/loader/multiboot_mbi2.c | 2 +- grub-core/loader/xnu.c | 2 +- grub-core/loader/xnu_resume.c | 2 +- include/grub/relocator.h | 3 +- include/grub/relocator_private.h | 2 + 22 files changed, 139 insertions(+), 35 deletions(-)
ChangeLog +10 -0
@@ -1,5 +1,15 @@ 2012-02-08 Matthew Garrett <[email protected]> + * grub-core/lib/efi/relocator.c (grub_relocator_alloc_chunk_addr): + Add argument to fail allocation when target address overlaps + firmware regions. All users updated. + * grub-core/lib/efi/relocator.c (grub_relocator_firmware_overlaps): + New function + * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_overlaps): + Likewise + +2012-02-08 Matthew Garrett <[email protected]> + * include/grub/i386/linux.h (linux_kernel_header): Update to boot protocol 2.10. (linux_kernel_params): Likewise
grub-core/lib/efi/relocator.c +51 -0
57 lines not on this page · raw message
grub-core/lib/ieee1275/relocator.c +27 -0
@@ -42,6 +42,33 @@ grub_relocator_firmware_get_max_events (void)return 2 * counter; } +unsigned +grub_relocator_firmware_overlaps (grub_phys_addr_t target,grub_size_t size) +{ +int overlap =0 ; + auto int NESTED_FUNC_ATTR check (grub_uint64_t addr, grub_uint64_t len, +grub_memory_type_t type); + int NESTED_FUNC_ATTR check (grub_uint64_t addr, grub_uint64_t len, +grub_memory_type_t type) + { +grub_uint64_t end = addr + len; + +if (type ==GRUB_MEMORY_AVAILABLE ) +return 0 ; + +if (target >= addr && target <= end) + overlap =1 ; + +if (target + size >= addr && target + size <= end) + overlap =1 ; + +return 0 ; + } + +grub_machine_mmap_iterate (check); +return overlap; +} +unsigned grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events) {
grub-core/lib/relocator.c +11 -1
@@ -1203,7 +1203,8 @@ adjust_limits (struct grub_relocator *rel,grub_err_t grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,grub_relocator_chunk_t *out, -grub_phys_addr_t target,grub_size_t size) +grub_phys_addr_t target,grub_size_t size, +int avoid_firmware) {struct grub_relocator_chunk *chunk;grub_phys_addr_t min_addr =0 , max_addr;
@@ -1213,6 +1214,15 @@ grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,adjust_limits (rel, &min_addr, &max_addr, target, target); +if (avoid_firmware) + { +#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS +if (grub_relocator_firmware_overlaps (target, size)) + +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"target overlaps with firmware" ); +#endif + } +for (chunk = rel->chunks; chunk; chunk = chunk->next)if ((chunk->target <= target && target < chunk->target + chunk->size) || (target <= chunk->target && chunk->target < target + size))
grub-core/loader/i386/bsd.c +11 -8
@@ -606,7 +606,7 @@ grub_freebsd_boot (void) {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - kern_end, p_size); + kern_end, p_size,0 );if (err)return err; p =get_virtual_current_address (ch);
@@ -788,7 +788,7 @@ grub_openbsd_boot (void) err =grub_relocator_alloc_chunk_addr (relocator, &ch, buf_target, tag_buf_len +sizeof (struct grub_openbsd_bootargs ) - +9 *sizeof (grub_uint32_t)); + +9 *sizeof (grub_uint32_t),0 );if (err)return err; buf0 =get_virtual_current_address (ch);
@@ -1079,7 +1079,8 @@ grub_netbsd_boot (void) err =grub_relocator_alloc_chunk_addr (relocator, &ch, arg_target, tag_buf_len +sizeof (struct grub_netbsd_bootinfo ) - + tag_count *sizeof (grub_uint32_t)); + + tag_count *sizeof (grub_uint32_t), +0 );if (err)return err; curarg =get_virtual_current_address (ch);
@@ -1219,7 +1220,8 @@ grub_bsd_load_aout (grub_file_t file, const char *filename)grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - kern_start, kern_end - kern_start); + kern_start, kern_end - kern_start, +0 );if (err)return err; kern_chunk_src =get_virtual_current_address (ch);
@@ -1330,7 +1332,8 @@ grub_bsd_load_elf (grub_elf_t elf)if (err)return err; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - kern_start, kern_end - kern_start); + kern_start, kern_end - kern_start, +0 );if (err)return err;
@@ -1373,7 +1376,7 @@ grub_bsd_load_elf (grub_elf_t elf)grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, - kern_end - kern_start); + kern_end - kern_start,0 );if (err)return err; kern_chunk_src =get_virtual_current_address (ch);
@@ -1837,7 +1840,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)), {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, kern_end, - file->size); + file->size,0 );if (err) goto fail; src =get_virtual_current_address (ch);
@@ -1888,7 +1891,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type) {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, kern_end, - file->size); + file->size,0 );if (err) goto fail;
grub-core/loader/i386/bsdXX.c +4 -4
@@ -106,7 +106,7 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator, {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - module, chunk_size); + module, chunk_size,0 );if (err)return err; chunk_src =get_virtual_current_address (ch);
@@ -204,7 +204,7 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator,grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - module, chunk_size); + module, chunk_size,0 );if (err)return err;
@@ -319,7 +319,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - symtarget, chunk_size); + symtarget, chunk_size,0 );if (err)return err; sym_chunk =get_virtual_current_address (ch);
@@ -434,7 +434,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - symtarget, chunk_size); + symtarget, chunk_size,0 );if (err)return err; sym_chunk =get_virtual_current_address (ch);
grub-core/loader/i386/coreboot/chainloader.c +1 -1
@@ -69,7 +69,7 @@ grub_chain_elf32_hook (Elf32_Phdr * phdr, grub_addr_t * addr, int *do_load) *do_load =1 ; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - phdr->p_paddr, phdr->p_memsz); + phdr->p_paddr, phdr->p_memsz,0 );if (err)return err;
grub-core/loader/i386/linux.c +2 -2
@@ -266,7 +266,7 @@ allocate_pages (grub_size_t prot_size) err =grub_relocator_alloc_chunk_addr (relocator, &ch, real_mode_target, (real_size + mmap_size - + efi_mmap_size)); + + efi_mmap_size),0 );if (err) goto fail; real_mode_mem =get_virtual_current_address (ch);
@@ -278,7 +278,7 @@ allocate_pages (grub_size_t prot_size) {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, - prot_mode_target, prot_size); + prot_mode_target, prot_size,0 );if (err) goto fail; prot_mode_mem =get_virtual_current_address (ch);
grub-core/loader/i386/multiboot_mbi.c +1 -1
@@ -119,7 +119,7 @@ grub_multiboot_load (grub_file_t file) err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, &ch, header->load_addr, - code_size); + code_size,0 );if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );
grub-core/loader/i386/pc/chainloader.c +2 -2
@@ -166,13 +166,13 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)grub_err_t err; err =grub_relocator_alloc_chunk_addr (rel, &ch,0x7C00 , -GRUB_DISK_SECTOR_SIZE ); +GRUB_DISK_SECTOR_SIZE ,0 );if (err) goto fail; bs =get_virtual_current_address (ch); err =grub_relocator_alloc_chunk_addr (rel, &ch,GRUB_MEMORY_MACHINE_PART_TABLE_ADDR , -64 ); +64 ,0 );if (err) goto fail; ptable =get_virtual_current_address (ch);
grub-core/loader/i386/pc/freedos.c +1 -1
@@ -101,7 +101,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (rel, &ch,GRUB_FREEDOS_SEGMENT <<4 , - kernelsyssize); + kernelsyssize,0 );if (err) goto fail; kernelsys =get_virtual_current_address (ch);
grub-core/loader/i386/pc/linux.c +2 -2
@@ -273,7 +273,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), err =grub_relocator_alloc_chunk_addr (relocator, &ch, grub_linux_real_target,GRUB_LINUX_CL_OFFSET - + maximal_cmdline_size); + + maximal_cmdline_size,0 );if (err)return err; grub_linux_real_chunk =get_virtual_current_address (ch);
@@ -317,7 +317,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, grub_linux_prot_target, - grub_linux16_prot_size); + grub_linux16_prot_size,0 );if (err)return err; grub_linux_prot_chunk =get_virtual_current_address (ch);
grub-core/loader/i386/pc/ntldr.c +2 -2
@@ -97,7 +97,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)), {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (rel, &ch,0x7C00 , -GRUB_DISK_SECTOR_SIZE ); +GRUB_DISK_SECTOR_SIZE ,0 );if (err) goto fail; bs =get_virtual_current_address (ch);
@@ -124,7 +124,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)), {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (rel, &ch,GRUB_NTLDR_SEGMENT <<4 , - ntldrsize); + ntldrsize,0 );if (err) goto fail; ntldr =get_virtual_current_address (ch);
grub-core/loader/i386/pc/plan9.c +2 -2
@@ -417,7 +417,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])grub_relocator_chunk_t ch;grub_err_t err; err =grub_relocator_alloc_chunk_addr (rel, &ch,GRUB_PLAN9_CONFIG_ADDR , - configsize); + configsize,0 );if (err) goto fail; config =get_virtual_current_address (ch);
@@ -448,7 +448,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])grub_err_t err; err =grub_relocator_alloc_chunk_addr (rel, &ch,GRUB_PLAN9_TARGET , - memsize); + memsize,0 );if (err) goto fail; mem =get_virtual_current_address (ch);
grub-core/loader/i386/pc/pxechainloader.c +1 -1
@@ -130,7 +130,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)), imagesize =grub_file_size (file); {grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (rel, &ch,0x7c00 , imagesize); + err =grub_relocator_alloc_chunk_addr (rel, &ch,0x7c00 , imagesize,0 );if (err) goto fail; image =get_virtual_current_address (ch);
grub-core/loader/mips/linux.c +3 -3
@@ -87,7 +87,7 @@ grub_linux_boot (void) err =grub_relocator_alloc_chunk_addr (relocator, &ch, ((16 <<20 ) -264 ), -grub_strlen (params) +1 +8 ); +grub_strlen (params) +1 +8 ,0 );if (err)return err; memsize =get_virtual_current_address (ch);
@@ -159,7 +159,7 @@ grub_linux_load32 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, target_addr &0x1fffffff , - linux_size); + linux_size,0 );if (err)return err; playground =get_virtual_current_address (ch);
@@ -214,7 +214,7 @@ grub_linux_load64 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator, &ch, target_addr &0x1fffffff , - linux_size); + linux_size,0 );if (err)return err; playground =get_virtual_current_address (ch);
grub-core/loader/multiboot_elfxx.c +1 -1
@@ -102,7 +102,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); +phdr (i)->p_memsz,0 );if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);
grub-core/loader/multiboot_mbi2.c +1 -1
@@ -227,7 +227,7 @@ grub_multiboot_load (grub_file_t file) err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, &ch, addr_tag->load_addr, - code_size); + code_size,0 );if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );
grub-core/loader/xnu.c +1 -1
@@ -60,7 +60,7 @@ grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target) err =grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, grub_xnu_heap_target_start - + grub_xnu_heap_size, size); + + grub_xnu_heap_size, size,0 );if (err)return err;
grub-core/loader/xnu_resume.c +1 -1
@@ -110,7 +110,7 @@ grub_xnu_resume (char *imagename) {grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, codedest, - codesize +GRUB_XNU_PAGESIZE ); + codesize +GRUB_XNU_PAGESIZE ,0 );if (err) {grub_file_close (file);
include/grub/relocator.h +2 -1
@@ -33,7 +33,8 @@ struct grub_relocator *grub_relocator_new (void);grub_err_t grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,grub_relocator_chunk_t *out, -grub_phys_addr_t target,grub_size_t size); +grub_phys_addr_t target,grub_size_t size, +int avoid_firmware);void *get_virtual_current_address (grub_relocator_chunk_t in);
include/grub/relocator_private.h +2 -0
@@ -104,6 +104,8 @@ struct grub_relocator_mmap_event#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS int grub_relocator_firmware_alloc_region (grub_phys_addr_t start,grub_size_t size); +unsigned grub_relocator_firmware_overlaps (grub_phys_addr_t start, +grub_size_t size);unsigned grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events);unsigned grub_relocator_firmware_get_max_events (void ); void grub_relocator_firmware_free_region (grub_phys_addr_t start,
Signature · 1 line
1.7.7.6
Re: [PATCH V3 2/3] Add support for avoiding firmware in relocations
Quoted 4 lines · Matthew Garrett
EFI and OF both support firmware regions which may be in use during loading.
grub-core/lib/efi/relocator.c +2
-0+unsigned +grub_relocator_firmware_overlaps (grub_phys_addr_t target,grub_size_t size)
grub-core/lib/efi/relocator.c grub_relocator_firmware_get_max_events (void) · line 53
Quoted 10 lines
grub-core/lib/efi/relocator.c +10
-0+{ +grub_efi_uintn_t mmapsize =0 , desc_size =0 ; +grub_efi_uint32_t descriptor_version =0 ; +grub_efi_memory_descriptor_t *descs =NULL ; +grub_efi_uintn_t key; +int overlap =0 ; +grub_efi_memory_descriptor_t *desc; + +grub_efi_get_memory_map (&mmapsize,NULL ,&key,&desc_size, + &descriptor_version);
You need to check return value.
You don't use key. You can just make it NULL (grub_efi_get_memory_map handles it).
grub-core/lib/efi/relocator.c grub_relocator_firmware_get_max_events (void) · line 57
Quoted 4 lines
grub-core/lib/efi/relocator.c +4
-0+ descs =grub_malloc (mmapsize); +if (!descs) +return 0 ; +
You seem to lack error handling as whole. I'd suggest make this function return grub_err_t and generate a grub_error itself if overlap is detected. You current code would happily allocate anywhere if grub_malloc fails.
Quoted 5 lines
grub-core/lib/relocator.c +4
-0+grub_efi_get_memory_map (&mmapsize, descs,&key,&desc_size, + &descriptor_version); + +adjust_limits (rel,&min_addr,&max_addr, target, target);
grub-core/lib/relocator.c grub_relocator_alloc_chunk_addr (struct grub_relocator *rel, · line 1225
Quoted 10 lines
grub-core/lib/relocator.c +9
-0+if (avoid_firmware) + { +#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS +if (grub_relocator_firmware_overlaps (target, size)) + +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"target overlaps with firmware" ); +#endif + } +
Ditto. Also here you have indentation problem
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Re: [PATCH V3 2/3] Add support for avoiding firmware in relocations
In reply to Matthew Garrettgrub-core/lib/ieee1275/relocator.c grub_relocator_firmware_get_max_events (void) · line 63
Quoted 8 lines · Matthew Garrett
grub-core/lib/ieee1275/relocator.c +8
-0+if (type ==GRUB_MEMORY_AVAILABLE ) +return 0 ; + +if (target>= addr&& target<= end) + overlap =1 ; + +if (target + size>= addr&& target + size<= end) + overlap =1 ;
This won't work. IEEE1275 declares only one type of memory range: available. Other ranges aren't declared at all. Also it would make sense to expand this implementation to other non-efi platforms (pc, coreboot, ...).
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Re: [PATCH V3 2/3] Add support for avoiding firmware in relocations
In reply to Matthew GarrettQuoted 2 lines · Matthew Garrett
EFI and OF both support firmware regions which may be in use during loading. Add support for avoiding these.
Also Seth Goldberg noticed that using chunk_align with start=end=target does exactly what we want (as if avoid=1). You may need to modify efi/relocator.c though as to which regions it considers available.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
PATCH v3 3/3 Update Linux loader to follow the kernel's preferences
In reply to Matthew GarrettWe should attempt to load the kernel at its preferred address, and if we can't do that then we should at lesat align it correctly. When doing so we should also make sure to avoid putting the kernel on top of any regions being used by the firmware.
--- ChangeLog | 8 +++++ grub-core/loader/i386/linux.c | 67 ++++++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 10 deletions(-)
ChangeLog +8 -0
@@ -1,5 +1,13 @@ 2012-02-08 Matthew Garrett <[email protected]> + * grub-core/loader/i386/linux.c (allocate_pages): Attempt to obtain + appropriately aligned memory if the desired target is unavailable + (grub_cmd_linux): Update to match newer Linux boot protocols, and + attempt to load the kernel at its preferred address rather than + hardcoding. + +2012-02-08 Matthew Garrett <[email protected]> + * grub-core/lib/efi/relocator.c (grub_relocator_alloc_chunk_addr): Add argument to fail allocation when target address overlaps firmware regions. All users updated.
grub-core/loader/i386/linux.c +57 -10
125 lines not on this page · raw message
Signature · 1 line
1.7.7.6
Re: [PATCH V3 3/3] Update Linux loader to follow the kernel's preferences
Quoted 32 lines · Matthew Garrett
We should attempt to load the kernel at its preferred address, and if we can't do that then we should at lesat align it correctly. When doing so we should also make sure to avoid putting the kernel on top of any regions being used by the firmware.
--- ChangeLog | 8 +++++ grub-core/loader/i386/linux.c | 67 ++++++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 10 deletions(-)ChangeLog +8
-0@@ -1,5 +1,13 @@ 2012-02-08 Matthew Garrett<[email protected]> + * grub-core/loader/i386/linux.c (allocate_pages): Attempt to obtain + appropriately aligned memory if the desired target is unavailable + (grub_cmd_linux): Update to match newer Linux boot protocols, and + attempt to load the kernel at its preferred address rather than + hardcoding. + +2012-02-08 Matthew Garrett<[email protected]> + * grub-core/lib/efi/relocator.c (grub_relocator_alloc_chunk_addr): Add argument to fail allocation when target address overlaps firmware regions. All users updated.grub-core/loader/i386/linux.c +0
-0
grub-core/loader/i386/linux.c free_pages (void) · line 186
Quoted 5 lines
grub-core/loader/i386/linux.c +1
-1@@ -183,13 +183,14 @@ free_pages (void)grub_relocator_unload (relocator); relocator =NULL ; real_mode_mem = prot_mode_mem = initrd_mem =0 ; - real_mode_target = prot_mode_target = initrd_mem_target =0 ; + real_mode_target = initrd_mem_target =0 ;
Any reason not to clean prot_mode_target? Looks like you wanted to remove its use. If so, can you remove declaration as well?
grub-core/loader/i386/linux.c allocate_pages (grub_size_t prot_size) · line 274
Quoted 6 lines
grub-core/loader/i386/linux.c +2
-0@@ -269,18 +270,38 @@ allocate_pages (grub_size_t prot_size) + efi_mmap_size), 0);if (err) goto fail; + + grub_errno =GRUB_ERR_NONE ;
Why do you reset error here?
Quoted 7 lines
grub-core/loader/i386/linux.c +0
-2real_mode_mem =get_virtual_current_address (ch); } efi_mmap_buf = (grub_uint8_t *) real_mode_mem + real_size + mmap_size; - prot_mode_target =GRUB_LINUX_BZIMAGE_ADDR ; - {
grub-core/loader/i386/linux.c allocate_pages (grub_size_t prot_size) · line 288
Quoted 10 lines
grub-core/loader/i386/linux.c +7
-1grub_relocator_chunk_t ch; err =grub_relocator_alloc_chunk_addr (relocator,&ch, - prot_mode_target, prot_size,0 ); + prot_mode_target, prot_size, + relocatable); +if (err) + { +unsigned int i; +for (i = *align; i>= min_align; i--) + {
I see here no check that kernel is relocatable.
grub-core/loader/i386/linux.c allocate_pages (grub_size_t prot_size) · line 298
Quoted 10 lines
grub-core/loader/i386/linux.c +10
-0+ err =grub_relocator_alloc_chunk_align (relocator,&ch, +0x1000000 ,0xffffffff , + prot_size,1 << i, +GRUB_RELOCATOR_PREFERENCE_LOW ); +if (!err) + { + *align = i; + prot_mode_target =get_physical_target_address (ch); +break ; + }
Here you need to clean grub_errno since you ignore error
grub-core/loader/i386/linux.c allocate_pages (grub_size_t prot_size) · line 301
Quoted 3 lines
grub-core/loader/i386/linux.c +3
-0+ } + } +
You need to restore grub_errno here (you can use grub_error_save and grub_error_load).
Quoted 71 lines
grub-core/loader/i386/linux.c +31
-4if (err) goto fail; + prot_mode_mem =get_virtual_current_address (ch); }@@ -631,8 +652,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),struct linux_kernel_header lh;struct linux_kernel_params *params;grub_uint8_t setup_sects; -grub_size_t real_size, prot_size; +grub_size_t real_size, prot_size, prot_file_size, align =0 , min_align =0 ;grub_ssize_t len; +int relocatable =0 ;int i;grub_dl_ref (my_mod);@@ -705,9 +727,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), setup_sects =GRUB_LINUX_DEFAULT_SETUP_SECTS ; real_size = setup_sects<<GRUB_DISK_SECTOR_BITS ; - prot_size =grub_file_size (file) - real_size -GRUB_DISK_SECTOR_SIZE ; -if (allocate_pages (prot_size)) +if (grub_le_to_cpu16 (lh.version)>=0x205 ) + { +for (align =0 ; align<32 ; align++) + { +if (grub_le_to_cpu32 (lh.kernel_alignment)& (1 << align)) +break ; + } + relocatable =grub_le_to_cpu32 (lh.relocatable); + } + +if (grub_le_to_cpu16 (lh.version)>=0x020a ) + { + min_align = lh.min_alignment; + prot_size =grub_le_to_cpu32 (lh.init_size); + prot_mode_target =grub_le_to_cpu64 (lh.pref_address); + } +else + { + min_align =0 ; + prot_size =grub_file_size (file) - real_size -GRUB_DISK_SECTOR_SIZE ; + prot_mode_target =grub_le_to_cpu32 (lh.code32_start); + } + + prot_file_size =grub_file_size (file) - real_size -GRUB_DISK_SECTOR_SIZE ; +if (allocate_pages (prot_size,&align, min_align, relocatable)) goto fail; params = (struct linux_kernel_params *) real_mode_mem;@@ -715,6 +760,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),grub_memcpy (¶ms->setup_sects,&lh.setup_sects,sizeof (lh) -0x1F1 ); params->ps_mouse = params->padding10 =0 ; + params->code32_start = prot_mode_target; + params->kernel_alignment = (1 << align); len =0x400 -sizeof (lh);if (grub_file_read (file, (char *) real_mode_mem +sizeof (lh), len) != len)@@ -774,7 +821,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),grub_file_seek (file, real_size +GRUB_DISK_SECTOR_SIZE );grub_dprintf ("linux" ,"bzImage, setup=0x%x, size=0x%x\n" , - (unsigned ) real_size, (unsigned ) prot_size); + (unsigned ) real_size, (unsigned ) prot_file_size);/* Look for memory size and video mode specified on the command line. */ linux_mem_size =0 ;
grub-core/loader/i386/linux.c grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), · line 961
Quoted 5 lines
grub-core/loader/i386/linux.c +1
-1@@ -911,7 +958,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), maximal_cmdline_size - (sizeof (LINUX_IMAGE) - 1)); - len = prot_size; + len = prot_file_size;
Any reason for rename?
Quoted 5 lines
grub-core/loader/i386/linux.c +0
-1if (grub_file_read (file, prot_mode_mem, len) != len&& !grub_errno)grub_error (GRUB_ERR_FILE_READ_ERROR ,N_ ("premature end of file %s" ), argv[0 ]); -- 1.7.7.6 _______________________________________________ Grub-develmailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Go ahead.
Quoted 76 lines · Matthew Garrett
The Linux boot header includes information on the kernel's desired load address and alignment. Add support for that.
--- ChangeLog | 6 ++++++ include/grub/i386/linux.h | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-)ChangeLog +6
-0@@ -1,3 +1,9 @@ +2012-02-08 Matthew Garrett<[email protected]> + + * include/grub/i386/linux.h (linux_kernel_header): Update to + boot protocol 2.10. + (linux_kernel_params): Likewise + 2012-02-07 Vladimir Serbinenko<[email protected]> * grub-core/lib/i386/relocator16.S: Revert moving A20 code into PMinclude/grub/i386/linux.h +23
-5@@ -86,7 +86,7 @@ enumGRUB_VIDEO_LINUX_TYPE_SIMPLE =0x70 /* Linear framebuffer without any additional functions. */ }; -/* For the Linux/i386 boot protocol version 2.03. */ +/* For the Linux/i386 boot protocol version 2.10. */ struct linux_kernel_header {grub_uint8_t code1[0x0020 ];@@ -131,8 +131,16 @@ struct linux_kernel_headergrub_uint32_t initrd_addr_max;/* Highest address for initrd */ grub_uint32_t kernel_alignment;grub_uint8_t relocatable; -grub_uint8_t pad[3 ]; +grub_uint8_t min_alignment; +grub_uint8_t pad[2 ];grub_uint32_t cmdline_size; +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint64_t pref_address; +grub_uint64_t init_size; } __attribute__ ((packed));/* Boot parameters for Linux based on 2.6.12. This is used by the setup @@ -276,10 +284,20 @@ struct linux_kernel_paramsgrub_uint32_t ramdisk_size;/* initrd size */ grub_uint32_t bootsect_kludge;/* obsolete */ grub_uint16_t heap_end_ptr;/* Free memory after setup end */ -grub_uint16_t pad1;/* Unused */ +grub_uint8_t ext_loader_ver;/* Extended loader version */ +grub_uint8_t ext_loader_type;/* Extended loader type */ grub_uint32_t cmd_line_ptr;/* Points to the kernel command line */ - -grub_uint8_t pad2[164 ];/* 22c */ +grub_uint32_t initrd_addr_max;/* Maximum initrd address */ +grub_uint32_t kernel_alignment;/* Alignment of the kernel */ +grub_uint8_t relocatable_kernel;/* Is the kernel relocatable */ +grub_uint8_t pad1[3 ]; +grub_uint32_t cmdline_size;/* Size of the kernel command line */ +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint8_t pad2[120 ];/* 258 */ struct grub_e820_mmap e820_map[GRUB_E820_MAX_ENTRY ];/* 2d0 */ } __attribute__ ((packed));
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Status of this patch in grub2 v2.00 code freeze?
- Keshav
Quoted 91 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Go ahead.
Quoted 67 lines · Matthew Garrett
The Linux boot header includes information on the kernel's desired load address and alignment. Add support for that.
--- ChangeLog | 6 ++++++ include/grub/i386/linux.h | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-)ChangeLog +6
-0@@ -1,3 +1,9 @@ +2012-02-08 Matthew Garrett<[email protected]> + + * include/grub/i386/linux.h (linux_kernel_header): Update to + boot protocol 2.10. + (linux_kernel_params): Likewise + 2012-02-07 Vladimir Serbinenko<[email protected]> * grub-core/lib/i386/relocator16.S: Revert moving A20 code into PMinclude/grub/i386/linux.h +0
-0@@ -86,7 +86,7 @@ enumGRUB_VIDEO_LINUX_TYPE_SIMPLE =0x70 /* Linear framebuffer without any additional functions. */
};include/grub/i386/linux.h +16
-5-/* For the Linux/i386 boot protocol version 2.03. */ +/* For the Linux/i386 boot protocol version 2.10. */ struct linux_kernel_header {grub_uint8_t code1[0x0020 ];@@ -131,8 +131,16 @@ struct linux_kernel_headergrub_uint32_t initrd_addr_max;/* Highest address for initrd */ grub_uint32_t kernel_alignment;grub_uint8_t relocatable; -grub_uint8_t pad[3 ]; +grub_uint8_t min_alignment; +grub_uint8_t pad[2 ];grub_uint32_t cmdline_size; +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint64_t pref_address; +grub_uint64_t init_size; } __attribute__ ((packed));/* Boot parameters for Linux based on 2.6.12. This is used by the setup @@ -276,10 +284,20 @@ struct linux_kernel_paramsgrub_uint32_t ramdisk_size;/* initrd size */ grub_uint32_t bootsect_kludge;/* obsolete */ grub_uint16_t heap_end_ptr;/* Free memory after setup end */ -grub_uint16_t pad1;/* Unused */ +grub_uint8_t ext_loader_ver;/* Extended loader version */ +grub_uint8_t ext_loader_type;/* Extended loader type */ grub_uint32_t cmd_line_ptr;/* Points to the kernel command line */ - -grub_uint8_t pad2[164 ];/* 22c */ +grub_uint32_t initrd_addr_max;/* Maximum initrd address */ +grub_uint32_t kernel_alignment;/* Alignment of the kernel */ +grub_uint8_t relocatable_kernel;/* Is the kernel relocatable */ +grub_uint8_t pad1[3 ];include/grub/i386/linux.h struct linux_kernel_params · line 303
Quoted 10 lines
include/grub/i386/linux.h +7
-0+grub_uint32_t cmdline_size;/* Size of the kernel command line */ +grub_uint32_t hardware_subarch; +grub_uint64_t hardware_subarch_data; +grub_uint32_t payload_offset; +grub_uint32_t payload_length; +grub_uint64_t setup_data; +grub_uint8_t pad2[120 ];/* 258 */ struct grub_e820_mmap e820_map[GRUB_E820_MAX_ENTRY ];/* 2d0 */ } __attribute__ ((packed));--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 1 line · Keshav P R
Status of this patch in grub2 v2.00 code freeze?
I have written what have to be fixed first.
And one thing: your idea to put into distro a patch which has known serious issues that have to be resolved was a very bad one.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
I am asking about 'this' patch (patch 1/3) alone. Not the other two ones. And the distro package was never updated, it was just a test build with a bzr snapshot and these patches, given to users willing to test the code.
- Keshav
Quoted 16 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Keshav P R
Status of this patch in grub2 v2.00 code freeze?
I have written what have to be fixed first.
And one thing: your idea to put into distro a patch which has known serious issues that have to be resolved was a very bad one.--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Coming to the issue of distro package, has the uefi relocator hang (seen in many asus laptops) been fixed in bzr mainline?
Quoted 26 lines · Keshav P R
I am asking about 'this' patch (patch 1/3) alone. Not the other two ones. And the distro package was never updated, it was just a test build with a bzr snapshot and these patches, given to users willing to test the code.
- Keshav
Quoted 16 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Keshav P R
Status of this patch in grub2 v2.00 code freeze?
I have written what have to be fixed first.
And one thing: your idea to put into distro a patch which has known serious issues that have to be resolved was a very bad one.--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 2 lines · Keshav P R
Coming to the issue of distro package, has the uefi relocator hang (seen in many asus laptops) been fixed in bzr mainline?
The reports feature one bug that debug=all caused relocator to hang. I don't know what happens in case when no "debug" is set and whether it's relocator's (or GRUB's at all for that matter) fault.
Quoted 30 lines · Keshav P R
Quoted 5 lines
I am asking about 'this' patch (patch 1/3) alone. Not the other two ones. And the distro package was never updated, it was just a test build with a bzr snapshot and these patches, given to users willing to test the code.
Quoted 20 lines
- Keshav
Quoted 16 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Keshav P R
Status of this patch in grub2 v2.00 code freeze?
I have written what have to be fixed first.
And one thing: your idea to put into distro a patch which has known serious issues that have to be resolved was a very bad one.--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Keshav P R
I am asking about 'this' patch (patch 1/3) alone.
'This' patch by itself has no effect.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko