Move ELF program header
PATCH 1/1 Move ELF program header
Hi,
This patch move the elf program header to the beginning, it should solve the problem with coreboot.
Signature · 1 line
Bean
util/elf/grub-mkimage.c +23 -11
@@ -166,8 +166,8 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])FILE *in;char *kernel_path;grub_addr_t grub_end =0 ; -off_t phdroff; -int i; +off_t offset; +int i, phdr_size;/* Read ELF header. */ kernel_path =grub_util_get_path (dir,"kernel.elf" );
@@ -177,8 +177,21 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])grub_util_read_at (&ehdr,sizeof (ehdr),0 , in); - phdrs =xmalloc (grub_target_to_host16 (ehdr.e_phentsize) - * (grub_target_to_host16 (ehdr.e_phnum) +2 )); + offset =ALIGN_UP (sizeof (ehdr),sizeof (long )); + ehdr.e_phoff =grub_host_to_target32 (offset); + + phdr_size = (grub_target_to_host16 (ehdr.e_phentsize) * +grub_target_to_host16 (ehdr.e_phnum)); + +if (mods[0 ] !=NULL ) + phdr_size +=grub_target_to_host16 (ehdr.e_phentsize); + +if (chrp) + phdr_size +=grub_target_to_host16 (ehdr.e_phentsize); + + phdrs =xmalloc (phdr_size); + offset +=ALIGN_UP (phdr_size,sizeof (long )); +/* Copy all existing segments. */ for (i =0 ; i <grub_target_to_host16 (ehdr.e_phnum); i++) {
@@ -207,8 +220,11 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])grub_util_read_at (segment_img,grub_target_to_host32 (phdr->p_filesz),grub_target_to_host32 (phdr->p_offset), in); + + phdr->p_offset =grub_host_to_target32 (offset);grub_util_write_image_at (segment_img,grub_target_to_host32 (phdr->p_filesz), -grub_target_to_host32 (phdr->p_offset), out); + offset, out); + offset +=ALIGN_UP (grub_target_to_host32 (phdr->p_filesz),sizeof (long ));free (segment_img); }
@@ -249,14 +265,10 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[]) ehdr.e_shnum =0 ; ehdr.e_shstrndx =0 ; -/* Append entire segment table to the file. */ - phdroff =ALIGN_UP (grub_util_get_fp_size (out),sizeof (long )); -grub_util_write_image_at (phdrs,grub_target_to_host16 (ehdr.e_phentsize) - *grub_target_to_host16 (ehdr.e_phnum), phdroff, - out); +/* Write entire segment table to the file. */ +grub_util_write_image_at (phdrs, phdr_size,grub_target_to_host32 (ehdr.e_phoff), out);/* Write ELF header. */ - ehdr.e_phoff =grub_host_to_target32 (phdroff);grub_util_write_image_at (&ehdr,sizeof (ehdr),0 , out);free (phdrs);
Quoted 8 lines · Bean
Hi,
This patch move the elf program header to the beginning, it should solve the problem with coreboot.
--
Bean
Any comment ?
Signature · 1 line
Bean
Quoted 11 lines · Bean
Quoted 8 lines · Bean
Hi,
This patch move the elf program header to the beginning, it should solve the problem with coreboot.
--
BeanAny comment ?
I don't have time to check atm, but please make sure it doesn't break ieee1275 support.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 7 lines · Robert Millan
Quoted 6 lines · Bean
Quoted 5 lines · Bean
Hi,
This patch move the elf program header to the beginning, it should solve the problem with coreboot.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
--
BeanAny comment ?
I don't have time to check atm, but please make sure it doesn't break ieee1275 support.
Hi,
I test it with olpc and it works. I don't have ppc, would someone check it ?
Signature · 1 line
Bean
Quoted 1 line · Bean
I test it with olpc and it works. I don't have ppc, would someone check it ?
I could make CVS GRUB compile on PowerPC after removing floating point code, but I could not get the rescue image to boot in qemu, with or without the patch. I know that it worked before (it would show "out of memory" due to Open Hack'Ware limitations, but at least the GRUB code was loaded and running).
I'm afraid I won't be able to spend any more time on the PowerPC port. If anyone cares, they would need to fix a lot of stuff.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 4 lines · Pavel Roskin
Quoted 1 line · Bean
I test it with olpc and it works. I don't have ppc, would someone check it ?
Quoted 8 lines
I could make CVS GRUB compile on PowerPC after removing floating point code, but I could not get the rescue image to boot in qemu, with or without the patch. I know that it worked before (it would show "out of memory" due to Open Hack'Ware limitations, but at least the GRUB code was loaded and running).
I'm afraid I won't be able to spend any more time on the PowerPC port. If anyone cares, they would need to fix a lot of stuff.
Hi,
I see, you're using qemu to test ppc, maybe I can try it some time. Is the emulation good, how close to the real hardware ?
btw, do you remember which version works ? We can track down the problem from there.
Signature · 1 line
Bean
Quoting Bean <[email protected]>:
Quoted 2 lines
I see, you're using qemu to test ppc, maybe I can try it some time. Is the emulation good, how close to the real hardware ?
qemu uses so called Open Hack'Ware, which doesn't have proper terminal support for the menu and doesn't report available memory in the way GRUB expects. The later causes "out of memory" messages, but it can be worked around in GRUB by hardcoding memory size.
Quoted 2 lines
btw, do you remember which version works ? We can track down the problem from there.
It was working when grub-mkrescue was added for PowerPC. According to the logs, that's January 31, 2008.
It looks like my G3 PowerMac died yesterday and won't turn on anymore.
The same thing happened to my G4 PowerMac several months ago. So, I
guess qemu remains the only option for me.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 13 lines · Pavel Roskin
Quoting Bean <[email protected]>:
Quoted 2 lines
I see, you're using qemu to test ppc, maybe I can try it some time. Is the emulation good, how close to the real hardware ?
qemu uses so called Open Hack'Ware, which doesn't have proper terminal support for the menu and doesn't report available memory in the way GRUB expects. The later causes "out of memory" messages, but it can be worked around in GRUB by hardcoding memory size.
Quoted 2 lines
btw, do you remember which version works ? We can track down the problem from there.
Quoted 6 lines
It was working when grub-mkrescue was added for PowerPC. According to the logs, that's January 31, 2008.
It looks like my G3 PowerMac died yesterday and won't turn on anymore. The same thing happened to my G4 PowerMac several months ago. So, I guess qemu remains the only option for me.
Hi,
Oh, this problem is caused by grub_ofconsole_setcursor. Open Hackware doesn't like the cursor-on call, if I comment it out, it will continue to run until the "out of memory" error.
Signature · 1 line
Bean
Quoted 6 lines · Bean
Hi,
Oh, this problem is caused by
grub_ofconsole_setcursor. Open Hackware doesn't like the cursor-on call, if I comment it out, it will continue to run until the "out of memory" error.
We could have a flag in kern/ieee1275/cmain.c for this. There's a stanza for Open Hackware already.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 10 lines · Robert Millan
Quoted 6 lines · Bean
Hi,
Oh, this problem is caused by
grub_ofconsole_setcursor. Open Hackware doesn't like the cursor-on call, if I comment it out, it will continue to run until the "out of memory" error.We could have a flag in
kern/ieee1275/cmain.cfor this. There's a stanza for Open Hackware already.
Hi,
That flag is not enough, actually, Open Hackware don't support interpret command at all, perhaps we need to a new flag GRUB_IEEE1275_FLAG_CANNOT_INTERPRET.
Signature · 1 line
Bean
Quoted 10 lines · Robert Millan
Quoted 6 lines · Bean
Hi,
Oh, this problem is caused by
grub_ofconsole_setcursor. Open Hackware doesn't like the cursor-on call, if I comment it out, it will continue to run until the "out of memory" error.We could have a flag in
kern/ieee1275/cmain.cfor this. There's a stanza for Open Hackware already.
Actually, the real OpenFirmware on PowerMac G3 is also complaining about "cursor on", but it's not fatal. Open Hackware doesn't have Forth interpreter, so it recognizes Forth commands by checksums and panics for unknown checksums.
I could resurrect my Mac by replugging everything on the motherboard.
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 4 lines · Pavel Roskin
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
That's strange, it does work on i386 with the "real" OpenFirmware (I think you're referring to the same implementation)
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 8 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
That's strange, it does work on i386 with the "real" OpenFirmware (I think you're referring to the same implementation)
I don't know if it's the same implementation. It's whatever Apple put on their G3 machines.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 3 lines · Pavel Roskin
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
Hi,
Are you using the native compiler, or cross compile from i386 ? It could have some effect.
Signature · 1 line
Bean
Quoted 9 lines · Bean
Quoted 3 lines · Pavel Roskin
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
Hi,
Are you using the native compiler, or cross compile from i386 ? It could have some effect.
I'm compiling natively on PowerPC.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 6 lines · Pavel Roskin
Quoted 5 lines · Bean
Quoted 3 lines · Pavel Roskin
The real OpenFirmware fails to recognize modules embedded into the image by grub-mkimage. I remember I spent some time fixing it, but it's broken again.
Quoted 6 lines
Quoted 4 lines
Hi,
Are you using the native compiler, or cross compile from i386 ? It could have some effect.
I'm compiling natively on PowerPC.
It could be an endian problem. Check the elf header, see if the fields are ok.
Signature · 1 line
Bean
Quoted 6 lines · Bean
Quoted 4 lines
Quoted 2 lines
Are you using the native compiler, or cross compile from i386 ? It could have some effect.
I'm compiling natively on PowerPC.
It could be an endian problem. Check the elf header, see if the fields are ok.
That's the headers, I don't see anything wrong. The sections are missing, but it has always been like that. The version is current from CVS.
$ ./grub-mkimage -o grub.img -d . *.mod $ objdump -x grub.img
grub.img: file format elf32-powerpc
grub.img
architecture: powerpc:common, flags 0x00000102:EXEC_P, D_PAGED
start address 0x00010000
Program Header:
LOAD off 0x000000c0 vaddr 0x00010000 paddr 0x00010000 align 2**4
filesz 0x0000bf04 memsz 0x000133a8 flags rwx
LOAD off 0x0000bfc4 vaddr 0x100000b4 paddr 0x100000b4 align 2**2
filesz 0x00000024 memsz 0x00000024 flags r--
NOTE off 0x0000bfc4 vaddr 0x100000b4 paddr 0x100000b4 align 2**2
filesz 0x00000024 memsz 0x00000024 flags r--
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
filesz 0x00000000 memsz 0x00000000 flags rwx
LOAD off 0x0000bfe8 vaddr 0x10009000 paddr 0x10009000 align 2**2
filesz 0x00052104 memsz 0x00052104 flags rwxSections:
Idx Name Size VMA LMA File off Algn
SYMBOL TABLE:
no symbols
The image loads, complains about "cursor-on", shows "Welcome to GRUB" and the prompt. "lsmod" shows an empty list.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 33 lines · Pavel Roskin
Quoted 6 lines · Bean
Quoted 4 lines
Quoted 2 lines
Are you using the native compiler, or cross compile from i386 ? It could have some effect.
I'm compiling natively on PowerPC.
It could be an endian problem. Check the elf header, see if the fields are ok.
That's the headers, I don't see anything wrong. The sections are missing, but it has always been like that. The version is current from CVS.
$ ./grub-mkimage -o grub.img -d . *.mod $ objdump -x grub.imggrub.img: file format elf32-powerpc
grub.img
architecture: powerpc:common, flags0x00000102:EXEC_P,D_PAGED
start address0x00010000Program Header:
LOAD off 0x000000c0 vaddr 0x00010000 paddr 0x00010000 align 2**4 filesz 0x0000bf04 memsz 0x000133a8 flags rwx LOAD off 0x0000bfc4 vaddr 0x100000b4 paddr 0x100000b4 align 2**2 filesz 0x00000024 memsz 0x00000024 flags r-- NOTE off 0x0000bfc4 vaddr 0x100000b4 paddr 0x100000b4 align 2**2 filesz 0x00000024 memsz 0x00000024 flags r-- STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2 filesz 0x00000000 memsz 0x00000000 flags rwx LOAD off 0x0000bfe8 vaddr 0x10009000 paddr 0x10009000 align 2**2 filesz 0x00052104 memsz 0x00052104 flags rwx
Quoted 8 lines
Sections:
Idx Name Size VMA LMA File off Algn
SYMBOL TABLE:
no symbolsThe image loads, complains about "cursor-on", shows "Welcome to GRUB" and the prompt. "lsmod" shows an empty list.
Hi,
You can also add some printf in kern/elf.c to see if grub can parse it properly, for example, grub_elf_check_header is a common place where problem occurs.
Signature · 1 line
Bean