ieee1275: Include a.out header in assembly of sparc64 boot loader
PATCH 1/1 ieee1275: Include a.out header in assembly of sparc64 boot loader
Recent versions of binutils dropped support for the a.out and COFF formats on sparc64 targets. Since the boot loader on sparc64 is supposed to be an a.out binary and the a.out header entries are rather simple to calculate in our case, we just write the header ourselves instead of relying on external tools to do that.
---
v2:
- fix grammar in long description
v3:
- fix formatting in assembly code
- update comment in boot loader for consistency
v4:
- add comments to explain offset adjustments and a.out header fields
grub-core/Makefile.core.def | 19 ++++++++++++++---- grub-core/boot/sparc64/ieee1275/boot.S | 27 +++++++++++++++++++++++--- include/grub/sparc64/ieee1275/boot.h | 3 +-- 3 files changed, 40 insertions(+), 9 deletions(-)
grub-core/Makefile.core.def +15 -4
@@ -425,8 +425,13 @@ image = { i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; - sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; + /* The entry point for a.out binaries on sparc64 starts + at 0x4000. Since we are writing the 32 bytes long a.out + header in the assembly code ourselves, we need to tell + the linker to adjust the start of the text segment to + 0x4000 - 0x20 = 0x3fe0. + */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; objcopyflags = '-O binary'; enable = i386_pc;
@@ -455,8 +460,14 @@ image = { i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; - sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; + + /* The entry point for a.out binaries on sparc64 starts + at 0x4000. Since we are writing the 32 bytes long a.out + header in the assembly code ourselves, we need to tell + the linker to adjust the start of the text segment to + 0x4000 - 0x20 = 0x3fe0. + */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; sparc64_ieee1275_cppflags = '-DCDBOOT=1'; objcopyflags = '-O binary';
grub-core/boot/sparc64/ieee1275/boot.S +24 -3
@@ -21,6 +21,23 @@ .text .align 4 + /* We're writing the a.out header ourselves as newer + * upstream versions of binutils no longer support + * the a.out format on sparc64. + * + * The boot loader fits into 512 bytes with 32 bytes + * used for the a.out header, hence the text segment + * size is 512 - 32. There is no data segment and no + * code relocation, thus those fields remain zero. + */ + .word 0x1030107 /* magic number */ + .word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* size of text segment */ + .word 0 /* size of initialized data */ + .word 0 /* size of uninitialized data */ + .word 0 /* size of symbol table || checksum */ + .word _start /* entry point */ + .word 0 /* size of text relocation */ + .word 0 /* size of data relocation */ .globl _start _start: /* OF CIF entry point arrives in %o4 */
@@ -40,10 +57,14 @@ pic_base: * * After loading in that block we will execute it by jumping to the * load address plus the size of the prepended A.OUT header (32 bytes). + * + * Since this assembly code includes the 32 bytes long a.out header, + * we need to move the actual code entry point forward by the size + * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE. */ - .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE boot_path: - .org GRUB_BOOT_MACHINE_KERNEL_BYTE + .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE boot_path_end: kernel_byte: .xword (2 << 9) kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR
@@ -52,7 +73,7 @@ kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR #define boot_path_end (_start + 1024) #include <grub/offsets.h> - .org 8 + .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE kernel_byte: .xword (2 << 9) kernel_size: .word 512 kernel_address: .word GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS
include/grub/sparc64/ieee1275/boot.h +1 -2
@@ -46,8 +46,7 @@#define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80 -#define GRUB_BOOT_MACHINE_CODE_END \ - (0x1fc - GRUB_BOOT_AOUT_HEADER_SIZE) +#define GRUB_BOOT_MACHINE_CODE_END 0x1fc#define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200
Signature · 1 line
2.20.1
Quoted 7 lines · John Paul Adrian Glaubitz
Recent versions of binutils dropped support for the a.out and COFF formats on sparc64 targets. Since the boot loader on sparc64 is supposed to be an a.out binary and the a.out header entries are rather simple to calculate in our case, we just write the header ourselves instead of relying on external tools to do that.
Signed-off-by John Paul Adrian Glaubitz <[email protected]>
LGTM, Reviewed-by: Daniel Kiper <[email protected]>
Eric, are you OK with this patch?
Daniel
Quoted 10 lines · Daniel Kiper
Quoted 6 lines · John Paul Adrian Glaubitz
Recent versions of binutils dropped support for the a.out and COFF formats on sparc64 targets. Since the boot loader on sparc64 is supposed to be an a.out binary and the a.out header entries are rather simple to calculate in our case, we just write the header ourselves instead of relying on external tools to do that.
Quoted 6 lines
Quoted 1 line
Signed-off-by John Paul Adrian Glaubitz <[email protected]>LGTM, Reviewed-by: Daniel Kiper <[email protected]>
Eric, are you OK with this patch?
I tried it out, but on my system it doesn’t fit in the 512 byte block? Am I missing something?
Before the patch:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: warning: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.. grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.. Installation finished. No error reported.
$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 512 Mar 25 12:13 /boot/grub/sparc64-ieee1275/boot.img
After:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: error: the size of `/boot/grub/sparc64-ieee1275/boot.img' is not 512.
$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 544 Mar 25 12:10 /boot/grub/sparc64-ieee1275/boot.img
Quoted 13 lines · Eric Snowberg
I tried it out, but on my system it doesn’t fit in the 512 byte block? Am I missing something?
Before the patch:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: warning: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.. grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.. Installation finished. No error reported.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 512 Mar 25 12:13 /boot/grub/sparc64-ieee1275/boot.img
Quoted 8 lines
After:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: error: the size of `/boot/grub/sparc64-ieee1275/boot.img' is not 512.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 544 Mar 25 12:10 /boot/grub/sparc64-ieee1275/boot.img
Hmm, let me have another look. Thanks for testing.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 8 lines · John Paul Adrian Glaubitz
Quoted 6 lines
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: error: the size of `/boot/grub/sparc64-ieee1275/boot.img' is not 512.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 544 Mar 25 12:10 /boot/grub/sparc64-ieee1275/boot.imgHmm, let me have another look. Thanks for testing.
I am not done testing yet but I just realized, 544 = 512 + 32, so it looks like the a.out header is appended twice. Does an older binutils maybe default to a.out when just passing binary as the output format?
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 3 lines · John Paul Adrian Glaubitz
I am not done testing yet but I just realized, 544 = 512 + 32, so it looks like the a.out header is appended twice. Does an older binutils maybe default to a.out when just passing binary as the output format?
Just did another test build, the sizes are correct for me:
glaubitz@kyoto:~/grub/grub-core$ ls -l *img -rwxr-xr-x 1 glaubitz glaubitz 512 Mar 25 19:02 boot.img -rwxr-xr-x 1 glaubitz glaubitz 512 Mar 25 19:02 cdboot.img -rwxr-xr-x 1 glaubitz glaubitz 512 Mar 25 19:02 diskboot.img -rwxr-xr-x 1 glaubitz glaubitz 85888 Mar 25 19:02 kernel.img glaubitz@kyoto:~/grub/grub-core$
I will try it with an older version of binutils then and see what happens.
Will take a little longer as I also need to downgrade gcc and related libraries as gcc-8 pulls in the newer binutils.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 13 lines · Eric Snowberg
I tried it out, but on my system it doesn’t fit in the 512 byte block? Am I missing something?
Before the patch:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: warning: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.. grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.. Installation finished. No error reported.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 512 Mar 25 12:13 /boot/grub/sparc64-ieee1275/boot.img
Quoted 8 lines
After:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: error: the size of `/boot/grub/sparc64-ieee1275/boot.img' is not 512.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 544 Mar 25 12:10 /boot/grub/sparc64-ieee1275/boot.img
Could you tell me what build environment this is?
Is this on Solaris? I want to try reproducing it, so I can figure what happened.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 23 lines · John Paul Adrian Glaubitz
Quoted 19 lines · Eric Snowberg
I tried it out, but on my system it doesn’t fit in the 512 byte block? Am I missing something?
Before the patch:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: warning: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.. grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.. Installation finished. No error reported.$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 512 Mar 25 12:13 /boot/grub/sparc64-ieee1275/boot.imgAfter:
$ grub-install --force --skip-fs-probe /dev/sdb1 Installing for sparc64-ieee1275 platform. grub-install: error: the size of `/boot/grub/sparc64-ieee1275/boot.img' is not 512.
Quoted 6 lines
Quoted 2 lines
$ ls -al /boot/grub/sparc64-ieee1275/boot.img -rw-r--r--. 1 root root 544 Mar 25 12:10 /boot/grub/sparc64-ieee1275/boot.imgCould you tell me what build environment this is?
Is this on Solaris? I want to try reproducing it, so I can figure what happened.
I’m using Oracle Linux for SPARC (6.9).
Quoted 4 lines · Eric Snowberg
Quoted 2 lines
Is this on Solaris? I want to try reproducing it, so I can figure what happened.
I’m using Oracle Linux for SPARC (6.9).
Ok, so it can only be a matter of the older binutils version implicitly assuming the output format to be a.out.
Could you try the modified patch? I'm explicitly passing "-O binary" now for the sparc64_ieee1275_objcopyflags.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
grub-core/Makefile.core.def +17 -4
@@ -425,8 +425,14 @@ image = { i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; - sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; + sparc64_ieee1275_objcopyflags = '-O binary'; + /* The entry point for a.out binaries on sparc64 starts + at 0x4000. Since we are writing the 32 bytes long a.out + header in the assembly code ourselves, we need to tell + the linker to adjust the start of the text segment to + 0x4000 - 0x20 = 0x3fe0. + */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; objcopyflags = '-O binary'; enable = i386_pc;
@@ -455,8 +461,15 @@ image = { i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; - sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; + + sparc64_ieee1275_objcopyflags = '-O binary'; + /* The entry point for a.out binaries on sparc64 starts + at 0x4000. Since we are writing the 32 bytes long a.out + header in the assembly code ourselves, we need to tell + the linker to adjust the start of the text segment to + 0x4000 - 0x20 = 0x3fe0. + */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; sparc64_ieee1275_cppflags = '-DCDBOOT=1'; objcopyflags = '-O binary';
grub-core/boot/sparc64/ieee1275/boot.S +24 -3
@@ -21,6 +21,23 @@ .text .align 4 + /* We're writing the a.out header ourselves as newer + * upstream versions of binutils no longer support + * the a.out format on sparc64. + * + * The boot loader fits into 512 bytes with 32 bytes + * used for the a.out header, hence the text segment + * size is 512 - 32. There is no data segment and no + * code relocation, thus those fields remain zero. + */ + .word 0x1030107 /* magic number */ + .word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* size of text segment */ + .word 0 /* size of initialized data */ + .word 0 /* size of uninitialized data */ + .word 0 /* size of symbol table || checksum */ + .word _start /* entry point */ + .word 0 /* size of text relocation */ + .word 0 /* size of data relocation */ .globl _start _start: /* OF CIF entry point arrives in %o4 */
@@ -40,10 +57,14 @@ pic_base: * * After loading in that block we will execute it by jumping to the * load address plus the size of the prepended A.OUT header (32 bytes). + * + * Since this assembly code includes the 32 bytes long a.out header, + * we need to move the actual code entry point forward by the size + * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE. */ - .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE boot_path: - .org GRUB_BOOT_MACHINE_KERNEL_BYTE + .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE boot_path_end: kernel_byte: .xword (2 << 9) kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR
@@ -52,7 +73,7 @@ kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR #define boot_path_end (_start + 1024) #include <grub/offsets.h> - .org 8 + .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE kernel_byte: .xword (2 << 9) kernel_size: .word 512 kernel_address: .word GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS
include/grub/sparc64/ieee1275/boot.h +1 -2
@@ -46,8 +46,7 @@#define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80 -#define GRUB_BOOT_MACHINE_CODE_END \ - (0x1fc - GRUB_BOOT_AOUT_HEADER_SIZE) +#define GRUB_BOOT_MACHINE_CODE_END 0x1fc#define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200
Quoted 7 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Eric Snowberg
Quoted 2 lines
Is this on Solaris? I want to try reproducing it, so I can figure what happened.
Quoted 8 lines
Quoted 1 line
I’m using Oracle Linux for SPARC (6.9).
Ok, so it can only be a matter of the older binutils version implicitly assuming the output format to be a.out.
Could you try the modified patch? I'm explicitly passing "-O binary" now for the
sparc64_ieee1275_objcopyflags.
Yes, that fixes the problem.