Skip to contentSkip to conversation

x86: Specify -march=core2 to build 64-bit U-Boot proper

PATCH New Bin Meng 3 participants 17 messages Oct 11, 2018 – Oct 13, 2018 x86

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/4 x86: Specify -march=core2 to build 64-bit U-Boot proper

With newer kernel.org GCC (7.3.0 or 8.1.0), the u-boot.rom image built for qemu-x86_64 target does not boot. It keeps resetting soon after the 32-bit SPL jumps to 64-bit proper. Debugging shows that the reset happens inside env_callback_init().

000000000113dd85 <env_callback_init>:

 113dd85:       41 54                   push   %r12
 113dd87:       55                      push   %rbp
 113dd88:       31 c0                   xor    %eax,%eax
 113dd8a:       53                      push   %rbx
 113dd8b:       0f 57 c0                xorps  %xmm0,%xmm0

Executing "xorps %xmm0,%xmm0" causes CPU to immediately reset. However older GCC like 5.4.0 (the one shipped by Ubuntu 16.04) does not generate such instructions that utilizes SSE for this function - env_callback_init() and U-Boot boots without any issue. Explicitly specifying -march=core2 for newer GCC allows U-Boot proper to boot again. Examine assembly codes of env_callback_init and there is no SSE instruction in that function hence U-Boot continues to boot.

core2 seems to be the oldest arch in GCC that supports 64-bit. Like 32-bit U-Boot build we use -march=i386 which is the most conservative cpu type so that the image can run on any x86 processor, let's do the same for the 64-bit U-Boot build.

---

 arch/x86/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/config.mk +1 -1
index cc94071..576501e 100644
@@ -23,7 +23,7 @@ endif
 ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
 else
-PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64
+PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
 endif
 
 PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/4 x86: Ensure no instruction sets of MMX/SSE are generated in 64-bit build

With the '-march=core2' fix, it seems that we have some luck that the 64-bit U-Boot boots again. However if we examine the disassembly codes there are still SSE instructions elsewhere which means passing cpu type to GCC is not enough to prevent it from generating these instructions. A simple test case is doing a 'bootefi selftest' from the U-Boot shell and it leads to a reset too.

The 'bootefi selftest' reset is even seen with the image created by the relative older GCC 5.4.0, the one shipped by Ubuntu 16.04.

To make sure no MMX/SSE instruction sets are generated, tell GCC not to do this. Note AVX is out of the question as CORE2 is old enough to support AVX yet.

---

 arch/x86/config.mk | 1 +
 1 file changed, 1 insertion(+)
arch/x86/config.mk +1 -0
index 576501e..8151e47 100644
@@ -24,6 +24,7 @@ ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
 else
 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
+PLATFORM_CPPFLAGS += -mno-mmx -mno-sse
 endif
 
 PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 x86: Ensure no instruction sets of MMX/SSE are generated in 64-bit build

Quoted 6 lines · Bin Meng

With the '-march=core2' fix, it seems that we have some luck that the 64-bit U-Boot boots again. However if we examine the disassembly codes there are still SSE instructions elsewhere which means passing cpu type to GCC is not enough to prevent it from generating these instructions. A simple test case is doing a 'bootefi selftest' from the U-Boot shell and it leads to a reset too.

I can confirm that an unexpected reset patch occurs without the patch.

Quoted 19 lines

The 'bootefi selftest' reset is even seen with the image created by the relative older GCC 5.4.0, the one shipped by Ubuntu 16.04.

To make sure no MMX/SSE instruction sets are generated, tell GCC not to do this. Note AVX is out of the question as CORE2 is old enough to support AVX yet.

---

 arch/x86/config.mk | 1 +
 1 file changed, 1 insertion(+)
arch/x86/config.mk +0 -0
index 576501e..8151e47 100644

arch/x86/config.mk ifeq ($(IS_32BIT),y) · line 27

Quoted 4 lines
arch/x86/config.mk +1 -0
@@ -24,6 +24,7 @@ ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
 else
 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
+PLATFORM_CPPFLAGS += -mno-mmx -mno-sse

According to https://wiki.osdev.org/SSE SSE has to be initialized. Otherwise SSE instructions lead to an undefined instruction exception. Is it this initialization that we lack? If this is your motivation please, state it in the commit message.

I think this patch could be squashed with the prior one.

Heinrich

Quoted 4 lines
arch/x86/config.mk +0 -0
 endif
 
 PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
author
#3 lore raw

PATCH 2/4 x86: Ensure no instruction sets of MMX/SSE are generated in 64-bit build

Hi Heinrich,

Quoted 11 lines · Heinrich Schuchardt
Quoted 6 lines · Bin Meng

With the '-march=core2' fix, it seems that we have some luck that the 64-bit U-Boot boots again. However if we examine the disassembly codes there are still SSE instructions elsewhere which means passing cpu type to GCC is not enough to prevent it from generating these instructions. A simple test case is doing a 'bootefi selftest' from the U-Boot shell and it leads to a reset too.

I can confirm that an unexpected reset patch occurs without the patch.

I think you mean "bootefi selftest" reset, right?

Quoted 14 lines
Quoted 14 lines

The 'bootefi selftest' reset is even seen with the image created by the relative older GCC 5.4.0, the one shipped by Ubuntu 16.04.

To make sure no MMX/SSE instruction sets are generated, tell GCC not to do this. Note AVX is out of the question as CORE2 is old enough to support AVX yet.

---

 arch/x86/config.mk | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

arch/x86/config.mk ifeq ($(IS_32BIT),y) · line 27

Quoted 9 lines
arch/x86/config.mk +1 -0
index 576501e..8151e47 100644
@@ -24,6 +24,7 @@ ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
 else
 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
+PLATFORM_CPPFLAGS += -mno-mmx -mno-sse

According to https://wiki.osdev.org/SSE SSE has to be initialized. Otherwise SSE instructions lead to an undefined instruction exception. Is it this initialization that we lack? If this is your motivation please, state it in the commit message.

Yes, it's intentional. U-Boot as a bootloader does not want to handle these advanced SIMD stuff.

Quoted 1 line

I think this patch could be squashed with the prior one.

They are different thing, although they solved similar reset. The first patch is adding the -march=core2 which is the counterpart of -march=i386 for 32-bit U-Boot. This patch is to disable MMX/SSE completely which I think deserve a separate patch.

Regards,
Bin

author
#4 lore raw

PATCH 3/4 x86: doc: Mention qemu-x86_64 support

In reply to Bin Meng

Currently only 32-bit U-Boot for QEMU x86 is documented. Mention the 64-bit support.

---

 doc/README.x86 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
doc/README.x86 +6 -2
index 8cc4672..ab48466 100644
@@ -32,7 +32,7 @@ are supported:
    - Link (Chromebook Pixel)
    - Minnowboard MAX
    - Samus (Chromebook Pixel 2015)
-   - QEMU x86
+   - QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.
@@ -376,7 +376,9 @@ QEMU x86 target instructions for bare mode:
 
 To build u-boot.rom for QEMU x86 targets, just simply run
 
-$ make qemu-x86_defconfig
+$ make qemu-x86_defconfig (for 32-bit)
+or
+$ make qemu-x86_64_defconfig (for 64-bit)
 $ make all
 
 Note this default configuration will build a U-Boot for the QEMU x86 i440FX
@@ -387,6 +389,8 @@ Device Tree Control  --->
 	...
 	(qemu-x86_q35) Default Device Tree for DT control
 
+To run 64-bit U-Boot, qemu-system-x86_64 should be used instead.
+
 Test with coreboot
 ------------------
 For testing U-Boot as the coreboot payload, there are things that need be paid
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/4 x86: doc: Mention qemu-x86_64 support

Quoted 23 lines · Bin Meng

Currently only 32-bit U-Boot for QEMU x86 is documented. Mention the 64-bit support.

---

 doc/README.x86 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
doc/README.x86 +1 -1
index 8cc4672..ab48466 100644
@@ -32,7 +32,7 @@ are supported:
    - Link (Chromebook Pixel)
    - Minnowboard MAX
    - Samus (Chromebook Pixel 2015)
-   - QEMU x86
+   - QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.

doc/README.x86 QEMU x86 target instructions for bare mode: · line 382

Quoted 8 lines
doc/README.x86 +3 -1
@@ -376,7 +376,9 @@ QEMU x86 target instructions for bare mode:
 
 To build u-boot.rom for QEMU x86 targets, just simply run
 
-$ make qemu-x86_defconfig
+$ make qemu-x86_defconfig (for 32-bit)
+or
+$ make qemu-x86_64_defconfig (for 64-bit)
 $ make all

If your patch series creates a U-Boot usable with QEMU depends on the chosen CPU:

This one seems to work:
qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

This one fails (as expected):
qemu-system-x86_64 -bios u-boot.rom --nographic -cpu pentium

I could not get the emulation running without -nographic. Do you know why?

The documentation above is insufficient. Please, provide a minimum QEMU command line which includes a CPU specification.

I would prefer if you could specify two lines per bitness - one with kvm and one without, e.g.

qemu-system-x86_64 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

qemu-system-i386 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-i386 -bios u-boot.rom -nographic -cpu core2duo

Best regards

Heinrich

Quoted 12 lines
doc/README.x86 +2 -0
 Note this default configuration will build a U-Boot for the QEMU x86 i440FX
@@ -387,6 +389,8 @@ Device Tree Control  --->
...
 	(qemu-x86_q35) Default Device Tree for DT control
 
+To run 64-bit U-Boot, qemu-system-x86_64 should be used instead.
+
 Test with coreboot
 ------------------
 For testing U-Boot as the coreboot payload, there are things that need be paid
author
#6 lore raw

PATCH 3/4 x86: doc: Mention qemu-x86_64 support

Hi Heinrich,

Quoted 37 lines · Heinrich Schuchardt
Quoted 23 lines · Bin Meng

Currently only 32-bit U-Boot for QEMU x86 is documented. Mention the 64-bit support.

---

 doc/README.x86 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
doc/README.x86 +1 -1
index 8cc4672..ab48466 100644
@@ -32,7 +32,7 @@ are supported:
    - Link (Chromebook Pixel)
    - Minnowboard MAX
    - Samus (Chromebook Pixel 2015)
-   - QEMU x86
+   - QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.

doc/README.x86 QEMU x86 target instructions for bare mode: · line 382

Quoted 8 lines
doc/README.x86 +3 -1
@@ -376,7 +376,9 @@ QEMU x86 target instructions for bare mode:
 
 To build u-boot.rom for QEMU x86 targets, just simply run
 
-$ make qemu-x86_defconfig
+$ make qemu-x86_defconfig (for 32-bit)
+or
+$ make qemu-x86_64_defconfig (for 64-bit)
 $ make all

If your patch series creates a U-Boot usable with QEMU depends on the chosen CPU:

Quoted 5 lines

This one seems to work:
qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

This one fails (as expected):
qemu-system-x86_64 -bios u-boot.rom --nographic -cpu pentium

Pentium does not support 64-bit, so it is expected. In my testing I always omit the '-cpu' so this is not a problem. But I can document this.

Quoted 3 lines

I could not get the emulation running without -nographic. Do you know why?

This is due to currently the VGA support is missing in the 64-bit U-Boot.

Quoted 5 lines

The documentation above is insufficient. Please, provide a minimum QEMU command line which includes a CPU specification.

I would prefer if you could specify two lines per bitness - one with kvm and one without, e.g.

I doubt -enable-kvm works with U-Boot.

Quoted 7 lines

qemu-system-x86_64 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

qemu-system-i386 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-i386 -bios u-boot.rom -nographic -cpu core2duo

Will add more info in v2.

Regards,
Bin

#7 lore raw

PATCH 3/4 x86: doc: Mention qemu-x86_64 support

Quoted 56 lines · Bin Meng

Hi Heinrich,

Quoted 37 lines · Heinrich Schuchardt
Quoted 23 lines · Bin Meng

Currently only 32-bit U-Boot for QEMU x86 is documented. Mention the 64-bit support.

---

 doc/README.x86 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
doc/README.x86 +1 -1
index 8cc4672..ab48466 100644
@@ -32,7 +32,7 @@ are supported:
    - Link (Chromebook Pixel)
    - Minnowboard MAX
    - Samus (Chromebook Pixel 2015)
-   - QEMU x86
+   - QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.

doc/README.x86 QEMU x86 target instructions for bare mode: · line 382

Quoted 8 lines
doc/README.x86 +3 -1
@@ -376,7 +376,9 @@ QEMU x86 target instructions for bare mode:
 
 To build u-boot.rom for QEMU x86 targets, just simply run
 
-$ make qemu-x86_defconfig
+$ make qemu-x86_defconfig (for 32-bit)
+or
+$ make qemu-x86_64_defconfig (for 64-bit)
 $ make all

If your patch series creates a U-Boot usable with QEMU depends on the chosen CPU:

Quoted 5 lines

This one seems to work:
qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

This one fails (as expected):
qemu-system-x86_64 -bios u-boot.rom --nographic -cpu pentium

Pentium does not support 64-bit, so it is expected. In my testing I always omit the '-cpu' so this is not a problem. But I can document this.

Quoted 3 lines

I could not get the emulation running without -nographic. Do you know why?

This is due to currently the VGA support is missing in the 64-bit U-Boot.

Quoted 7 lines
Quoted 5 lines

The documentation above is insufficient. Please, provide a minimum QEMU command line which includes a CPU specification.

I would prefer if you could specify two lines per bitness - one with kvm and one without, e.g.

I doubt -enable-kvm works with U-Boot.

Why? It is just an instruction how QEMU should emulate the CPU. KVM does not require anything on the target software side.

I have had no problem with KVM on the i386 target.

Regards

Heinrich

Quoted 14 lines
Quoted 8 lines

qemu-system-x86_64 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

qemu-system-i386 -bios u-boot.rom -nographic -enable-kvm -cpu host qemu-system-i386 -bios u-boot.rom -nographic -cpu core2duo

Will add more info in v2.

Regards,
Bin

author
#8 lore raw

PATCH 3/4 x86: doc: Mention qemu-x86_64 support

Hi Heinrich,

Quoted 64 lines · Heinrich Schuchardt
Quoted 62 lines · Bin Meng

Hi Heinrich,

Quoted 37 lines · Heinrich Schuchardt
Quoted 23 lines · Bin Meng

Currently only 32-bit U-Boot for QEMU x86 is documented. Mention the 64-bit support.

---

 doc/README.x86 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
doc/README.x86 +1 -1
index 8cc4672..ab48466 100644
@@ -32,7 +32,7 @@ are supported:
    - Link (Chromebook Pixel)
    - Minnowboard MAX
    - Samus (Chromebook Pixel 2015)
-   - QEMU x86
+   - QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.

doc/README.x86 QEMU x86 target instructions for bare mode: · line 382

Quoted 8 lines
doc/README.x86 +3 -1
@@ -376,7 +376,9 @@ QEMU x86 target instructions for bare mode:
 
 To build u-boot.rom for QEMU x86 targets, just simply run
 
-$ make qemu-x86_defconfig
+$ make qemu-x86_defconfig (for 32-bit)
+or
+$ make qemu-x86_64_defconfig (for 64-bit)
 $ make all

If your patch series creates a U-Boot usable with QEMU depends on the chosen CPU:

Quoted 5 lines

This one seems to work:
qemu-system-x86_64 -bios u-boot.rom -nographic -cpu core2duo

This one fails (as expected):
qemu-system-x86_64 -bios u-boot.rom --nographic -cpu pentium

Pentium does not support 64-bit, so it is expected. In my testing I always omit the '-cpu' so this is not a problem. But I can document this.

Quoted 3 lines

I could not get the emulation running without -nographic. Do you know why?

This is due to currently the VGA support is missing in the 64-bit U-Boot.

Quoted 5 lines

The documentation above is insufficient. Please, provide a minimum QEMU command line which includes a CPU specification.

I would prefer if you could specify two lines per bitness - one with kvm and one without, e.g.

Quoted 6 lines
Quoted 1 line

I doubt -enable-kvm works with U-Boot.

Why? It is just an instruction how QEMU should emulate the CPU. KVM does not require anything on the target software side.

I have had no problem with KVM on the i386 target.

I suspect some drivers may have issues when working with KVM, eg: some memory barriers might be needed due to guest (U-Boot) and host (x86 machine) are speaking the same language. But I have never fully test this configuration.

Regards,
Bin

author
#9 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

In reply to Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

---
testp.py testing is currently failing at 'bootefi selftest'.

 .travis.yml | 8 ++++++++
 1 file changed, 8 insertions(+)
.travis.yml +8 -0
index 2b759c9..9d0531f 100644
@@ -408,6 +408,14 @@ matrix:
           BUILDMAN="^qemu-x86$"
           TOOLCHAIN="x86_64"
           BUILD_ROM="yes"
+    - name: "test/py qemu-x86_64"
+      env:
+        - TEST_PY_BD="qemu-x86_64"
+          TEST_PY_TEST_SPEC="not sleep"
+          QEMU_TARGET="x86_64-softmmu"
+          BUILDMAN="^qemu-x86_64$"
+          TOOLCHAIN="x86_64"
+          BUILD_ROM="yes"
     - name: "test/py zynq_zc702"
       env:
         - TEST_PY_BD="zynq_zc702"
Signature · 1 line
2.7.4
author
#10 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

Hi Heinrich,

Quoted 8 lines · Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

---
testp.py testing is currently failing at 'bootefi selftest'.

Can you try this series for the 'bootefi selftest' testing?

BTW: do you know how to call test.py on the local machine to do testing on QEMU? The doc does not provide enough information ..

Quoted 13 lines
 .travis.yml | 8 ++++++++
 1 file changed, 8 insertions(+)
.travis.yml +2 -0
index 2b759c9..9d0531f 100644
@@ -408,6 +408,14 @@ matrix:
           BUILDMAN="^qemu-x86$"
           TOOLCHAIN="x86_64"
           BUILD_ROM="yes"
+    - name: "test/py qemu-x86_64"
+      env:

.travis.yml matrix:

Quoted 10 lines
.travis.yml +6 -1
+        - TEST_PY_BD="qemu-x86_64"
+          TEST_PY_TEST_SPEC="not sleep"
+          QEMU_TARGET="x86_64-softmmu"
+          BUILDMAN="^qemu-x86_64$"
+          TOOLCHAIN="x86_64"
+          BUILD_ROM="yes"
     - name: "test/py zynq_zc702"
       env:
         - TEST_PY_BD="zynq_zc702"
--

Regards,
Bin

#11 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

Quoted 6 lines · Bin Meng

Hi Heinrich,

Quoted 3 lines · Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

Quoted 7 lines
Quoted 5 lines

---
testp.py testing is currently failing at 'bootefi selftest'.

Can you try this series for the 'bootefi selftest' testing?

I am clueless why the EFI subsystems is failing completely on qemu-x86_64_defconfig.

Any printf() or puts() statement I put into lib/efi_loader/efi_boottime.c leads to no output at all.

I connected gdb with

gdb u-boot -ex 'target remote localhost:1234'
add-symbol-file u-boot <relocaddr>

But the debugger did not stop at breakpoints.

Regards

Heinrich

Quoted 31 lines

BTW: do you know how to call test.py on the local machine to do testing on QEMU? The doc does not provide enough information ..

Quoted 13 lines
 .travis.yml | 8 ++++++++
 1 file changed, 8 insertions(+)
.travis.yml +2 -0
index 2b759c9..9d0531f 100644
@@ -408,6 +408,14 @@ matrix:
           BUILDMAN="^qemu-x86$"
           TOOLCHAIN="x86_64"
           BUILD_ROM="yes"
+    - name: "test/py qemu-x86_64"
+      env:

.travis.yml matrix:

Quoted 10 lines
.travis.yml +6 -1
+        - TEST_PY_BD="qemu-x86_64"
+          TEST_PY_TEST_SPEC="not sleep"
+          QEMU_TARGET="x86_64-softmmu"
+          BUILDMAN="^qemu-x86_64$"
+          TOOLCHAIN="x86_64"
+          BUILD_ROM="yes"
     - name: "test/py zynq_zc702"
       env:
         - TEST_PY_BD="zynq_zc702"
--

Regards,
Bin

author
#12 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 6 lines · Bin Meng

Hi Heinrich,

Quoted 3 lines · Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

Quoted 7 lines
Quoted 5 lines

---
testp.py testing is currently failing at 'bootefi selftest'.

Can you try this series for the 'bootefi selftest' testing?

I am clueless why the EFI subsystems is failing completely on qemu-x86_64_defconfig.

Any printf() or puts() statement I put into lib/efi_loader/efi_boottime.c leads to no output at all.

Quoted 6 lines

I connected gdb with

gdb u-boot -ex 'target remote localhost:1234'
add-symbol-file u-boot <relocaddr>

But the debugger did not stop at breakpoints.

I encountered exactly the same issue that breakpoint is not hit when debugging this endless loop issue. And I finally figured it out:

The symbol table should not be loaded to <relocaddr>, instead it needs to be loaded to <relocaddr + .text - .text.start>.

The .text.start was introduced in commit 7e21fbca26d18327cf7cabaad08df276a06a07d8 "efi_loader: Rename sections to allow for implicit data", and its commit message mentioned: [agraf:
Fix x86_64 breakage], although I was not sure what x86_64 breakage was fixed.

Please have a try.

Regards,
Bin

#13 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

Quoted 44 lines · Bin Meng

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 6 lines · Bin Meng

Hi Heinrich,

Quoted 3 lines · Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

Quoted 7 lines
Quoted 5 lines

---
testp.py testing is currently failing at 'bootefi selftest'.

Can you try this series for the 'bootefi selftest' testing?

I am clueless why the EFI subsystems is failing completely on qemu-x86_64_defconfig.

Any printf() or puts() statement I put into lib/efi_loader/efi_boottime.c leads to no output at all.

Quoted 6 lines

I connected gdb with

gdb u-boot -ex 'target remote localhost:1234'
add-symbol-file u-boot <relocaddr>

But the debugger did not stop at breakpoints.

I encountered exactly the same issue that breakpoint is not hit when debugging this endless loop issue. And I finally figured it out:

The symbol table should not be loaded to <relocaddr>, instead it needs to be loaded to <relocaddr + .text - .text.start>.

The .text.start was introduced in commit 7e21fbca26d18327cf7cabaad08df276a06a07d8 "efi_loader: Rename sections to allow for implicit data", and its commit message mentioned: [agraf:
Fix x86_64 breakage], although I was not sure what x86_64 breakage was fixed.

Quoted 5 lines

Please have a try.

Regards,
Bin

Hello Bin,

thanks for your hint. Now I was able to debug the problem.

The code is not correctly relocated.

Function do_elf_reloc_fixups64() only analyzes re_src->r_offset but not the relocation type.

I put a print statement into the relocation loop and found the relocation type of the first relocation to be reported as having an illegal value of 0x10ff70. All other relocation types were reported as 0x8 as expected.

arch/x86/lib/relocate.c +0 -0
index ed10755d9c..095374830f 100644
@@ -55,6 +55,7 @@ static void do_elf_reloc_fixups64(unsigned int

text_base, uintptr_t size,
do {

.   /* Get the location from the relocation entry */
.   offset_ptr_rom = (Elf64_Addr *)(uintptr_t)re_src->r_offset;
+   printf("Reloc type %llx\n", ELF64_R_TYPE(re_src->r_info));

.
. /* Check that the location of the relocation is in .text */
. if (offset_ptr_rom >= (Elf64_Addr *)(uintptr_t)text_base &&

Reloc type 10ff70
Reloc type 8
Reloc type 8
Reloc type 8
..

The relocation types in efi_runtime_relocate() are complete garbage:

efi_runtime_relocate: 8
efi_runtime_relocate: 30
efi_runtime_relocate: b0
efi_runtime_relocate: 8
efi_runtime_relocate: 50
efi_runtime_relocate: 20
efi_runtime_relocate: 8
efi_runtime_relocate: 60
efi_runtime_relocate: 20
efi_runtime_relocate: 8
efi_runtime_relocate: a0
efi_runtime_relocate: b5
efi_runtime_relocate: 8
efi_runtime_relocate: b0
efi_runtime_relocate: aa
efi_runtime_relocate: 8
efi_runtime_relocate: c0
efi_runtime_relocate: c0
efi_runtime_relocate: 8
efi_runtime_relocate: d0
efi_runtime_relocate: 68
efi_runtime_relocate: 8
efi_runtime_relocate: e0
efi_runtime_relocate: b5
efi_runtime_relocate: 8
efi_runtime_relocate: f0
efi_runtime_relocate: cb
efi_runtime_relocate: 8
efi_runtime_relocate: 0
efi_runtime_relocate: e1

I will send a patch for efi_runtime_relocate().

Bin, can you please, have a look at the first problem.

Best regards

Heinrich

#14 lore raw

PATCH 4/4 WIP: travis: Add qemu-x86_64 target for test.py testing

Quoted 120 lines · Heinrich Schuchardt
Quoted 44 lines · Bin Meng

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 6 lines · Bin Meng

Hi Heinrich,

Quoted 3 lines · Bin Meng

Add qemu-x86_64 to the list of targets we use for test.py runs.

Quoted 7 lines
Quoted 5 lines

---
testp.py testing is currently failing at 'bootefi selftest'.

Can you try this series for the 'bootefi selftest' testing?

I am clueless why the EFI subsystems is failing completely on qemu-x86_64_defconfig.

Any printf() or puts() statement I put into lib/efi_loader/efi_boottime.c leads to no output at all.

Quoted 6 lines

I connected gdb with

gdb u-boot -ex 'target remote localhost:1234'
add-symbol-file u-boot <relocaddr>

But the debugger did not stop at breakpoints.

I encountered exactly the same issue that breakpoint is not hit when debugging this endless loop issue. And I finally figured it out:

The symbol table should not be loaded to <relocaddr>, instead it needs to be loaded to <relocaddr + .text - .text.start>.

The .text.start was introduced in commit 7e21fbca26d18327cf7cabaad08df276a06a07d8 "efi_loader: Rename sections to allow for implicit data", and its commit message mentioned: [agraf:
Fix x86_64 breakage], although I was not sure what x86_64 breakage was fixed.

Quoted 5 lines

Please have a try.

Regards,
Bin

Hello Bin,

thanks for your hint. Now I was able to debug the problem.

The code is not correctly relocated.

Function do_elf_reloc_fixups64() only analyzes re_src->r_offset but not the relocation type.

I put a print statement into the relocation loop and found the relocation type of the first relocation to be reported as having an illegal value of 0x10ff70. All other relocation types were reported as 0x8 as expected.

arch/x86/lib/relocate.c +0 -0
index ed10755d9c..095374830f 100644
@@ -55,6 +55,7 @@ static void do_elf_reloc_fixups64(unsigned int
 text_base, uintptr_t size,
 do {
.   /* Get the location from the relocation entry */
.   offset_ptr_rom = (Elf64_Addr *)(uintptr_t)re_src->r_offset;
+   printf("Reloc type %llx\n", ELF64_R_TYPE(re_src->r_info));

.
. /* Check that the location of the relocation is in .text */
. if (offset_ptr_rom >= (Elf64_Addr *)(uintptr_t)text_base &&

Reloc type 10ff70
Reloc type 8
Reloc type 8
Reloc type 8
..

The relocation types in efi_runtime_relocate() are complete garbage:

efi_runtime_relocate: 8
efi_runtime_relocate: 30
efi_runtime_relocate: b0
efi_runtime_relocate: 8
efi_runtime_relocate: 50
efi_runtime_relocate: 20
efi_runtime_relocate: 8
efi_runtime_relocate: 60
efi_runtime_relocate: 20
efi_runtime_relocate: 8
efi_runtime_relocate: a0
efi_runtime_relocate: b5
efi_runtime_relocate: 8
efi_runtime_relocate: b0
efi_runtime_relocate: aa
efi_runtime_relocate: 8
efi_runtime_relocate: c0
efi_runtime_relocate: c0
efi_runtime_relocate: 8
efi_runtime_relocate: d0
efi_runtime_relocate: 68
efi_runtime_relocate: 8
efi_runtime_relocate: e0
efi_runtime_relocate: b5
efi_runtime_relocate: 8
efi_runtime_relocate: f0
efi_runtime_relocate: cb
efi_runtime_relocate: 8
efi_runtime_relocate: 0
efi_runtime_relocate: e1

Quoted 10 lines

I will send a patch for efi_runtime_relocate().

Bin, can you please, have a look at the first problem.

Best regards

Heinrich

Using a memory watchpoint pinpoints the culprit overwriting the relocation table with an illegal relocation type:

Hardware access (read/write) watchpoint 1: *0x118b188

Old value = 8
New value = 1113968
arch_setup_gd (new_gd=0x10ff70) at arch/x86/cpu/x86_64/cpu.c:32 (gdb)

0x111173e <arch_setup_gd> mov %rdi,0x79a43(%rip)
# 0x118b188

0x1111745 <arch_setup_gd+7> mov $0x20,%edi

0x111174a <arch_setup_gd+12> jmpq 0x11399fb <printch>

0x111174f <cpu_has_64bit> mov $0x1,%eax

The global_data_ptr and the relocation table occupy the same memory location:

.bss.global_data_ptr

                0x000000000118b188        0x8 arch/x86/cpu/built-in.o
                0x000000000118b188                global_data_ptr

.rela.got 0x000000000118b180 0x90 arch/x86/cpu/start64.o
.rela.bss 0x000000000118b210 0x0 arch/x86/cpu/start64.o

Essentially we have to relocate before accessing any global symbols in the data section. I have sent a patch moving global_data_ptr to the .text section.

Best regards

Heinrich

#15 lore raw

PATCH 1/4 x86: Specify -march=core2 to build 64-bit U-Boot proper

In reply to Bin Meng
Quoted 21 lines · Bin Meng

With newer kernel.org GCC (7.3.0 or 8.1.0), the u-boot.rom image built for qemu-x86_64 target does not boot. It keeps resetting soon after the 32-bit SPL jumps to 64-bit proper. Debugging shows that the reset happens inside env_callback_init().

000000000113dd85 <env_callback_init>:

 113dd85:       41 54                   push   %r12
 113dd87:       55                      push   %rbp
 113dd88:       31 c0                   xor    %eax,%eax
 113dd8a:       53                      push   %rbx
 113dd8b:       0f 57 c0                xorps  %xmm0,%xmm0

Executing "xorps %xmm0,%xmm0" causes CPU to immediately reset. However older GCC like 5.4.0 (the one shipped by Ubuntu 16.04) does not generate such instructions that utilizes SSE for this function - env_callback_init() and U-Boot boots without any issue. Explicitly specifying -march=core2 for newer GCC allows U-Boot proper to boot again. Examine assembly codes of env_callback_init and there is no SSE instruction in that function hence U-Boot continues to boot.

Quoted 6 lines

core2 seems to be the oldest arch in GCC that supports 64-bit. Like 32-bit U-Boot build we use -march=i386 which is the most conservative cpu type so that the image can run on any x86 processor, let's do the same for the 64-bit U-Boot build.

Quoted 19 lines

---

 arch/x86/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/config.mk +1 -1
index cc94071..576501e 100644
@@ -23,7 +23,7 @@ endif
 ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
 else
-PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64
+PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
 endif
 
 PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
#16 lore raw

PATCH 1/4 x86: Specify -march=core2 to build 64-bit U-Boot proper

In reply to Bin Meng
Quoted 26 lines · Bin Meng

With newer kernel.org GCC (7.3.0 or 8.1.0), the u-boot.rom image built for qemu-x86_64 target does not boot. It keeps resetting soon after the 32-bit SPL jumps to 64-bit proper. Debugging shows that the reset happens inside env_callback_init().

000000000113dd85 <env_callback_init>:

 113dd85:       41 54                   push   %r12
 113dd87:       55                      push   %rbp
 113dd88:       31 c0                   xor    %eax,%eax
 113dd8a:       53                      push   %rbx
 113dd8b:       0f 57 c0                xorps  %xmm0,%xmm0

Executing "xorps %xmm0,%xmm0" causes CPU to immediately reset. However older GCC like 5.4.0 (the one shipped by Ubuntu 16.04) does not generate such instructions that utilizes SSE for this function - env_callback_init() and U-Boot boots without any issue. Explicitly specifying -march=core2 for newer GCC allows U-Boot proper to boot again. Examine assembly codes of env_callback_init and there is no SSE instruction in that function hence U-Boot continues to boot.

core2 seems to be the oldest arch in GCC that supports 64-bit. Like 32-bit U-Boot build we use -march=i386 which is the most conservative cpu type so that the image can run on any x86 processor, let's do the same for the 64-bit U-Boot build.

Quoted 5 lines

---

 arch/x86/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)