Skip to contentSkip to conversation

sandbox: allow cross-compiling sandbox

PATCH New Heinrich Schuchardt 3 participants 6 messages Feb 10, 2021 – Mar 16, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE is set, use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

make sandbox_defconfig NO_SDL=1 CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1 MK_ARCH=aarch64 make

---
v2:
use $CROSS_COMPILE instead of an extra environment variable

---
 Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Makefile +7 -3
index ebbedb1fb1..6c256a23b6 100644
@@ -17,9 +17,13 @@ NAME =
 # o Look for make include files relative to root of kernel src
 MAKEFLAGS += -rR --include-dir=$(CURDIR)
 
-# Determine host architecture
+# Determine target architecture for the sandbox
 include include/host_arch.h
-MK_ARCH="${shell uname -m}"
+ifeq ("", "$(CROSS_COMPILE)")
+  MK_ARCH="${shell uname -m}"
+else
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\s*\([^\/]*\/\)*\([^-]*\)-\S*/\2/p'}"
+endif
 unexport HOST_ARCH
 ifeq ("x86_64", $(MK_ARCH))
   export HOST_ARCH=$(HOST_ARCH_X86_64)
@@ -27,7 +31,7 @@ else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" "i586" "i686"))
   export HOST_ARCH=$(HOST_ARCH_X86)
 else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
   export HOST_ARCH=$(HOST_ARCH_AARCH64)
-else ifeq ("armv7l", $(MK_ARCH))
+else ifneq (,$(findstring $(MK_ARCH), "arm" "armv7" "armv7l"))
   export HOST_ARCH=$(HOST_ARCH_ARM)
 else ifeq ("riscv32", $(MK_ARCH))
   export HOST_ARCH=$(HOST_ARCH_RISCV32)

--
2.30.0

#1 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

Quoted 4 lines · Heinrich Schuchardt

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE

is set,

Quoted 7 lines

use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

make sandbox_defconfig NO_SDL=1 CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1

MK_ARCH=aarch64 make

Quoted 15 lines

---
v2:
use $CROSS_COMPILE instead of an extra environment variable

---
  Makefile | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
Makefile +0 -0
index ebbedb1fb1..6c256a23b6 100644
@@ -17,9 +17,13 @@ NAME =
  # o Look for make include files relative to root of kernel src

Makefile NAME = · line 25

Quoted 10 lines
Makefile +5 -2
  MAKEFLAGS += -rR --include-dir=$(CURDIR)
 
-# Determine host architecture
+# Determine target architecture for the sandbox
  include include/host_arch.h
-MK_ARCH="${shell uname -m}"
+ifeq ("", "$(CROSS_COMPILE)")
+  MK_ARCH="${shell uname -m}"
+else
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 

's/^\s*\([^\/]*\/\)*\([^-]*\)-\S*/\2/p'}"

Makefile NAME = · line 26

Quoted 1 line
Makefile +1 -0
+endif

Won't this break cross-compiling? E.g. if on my x86_64 machine I run "CROSS_COMPILE=arm-linux-gnueabihf- make" my HOST_ARCH will be HOST_ARCH_ARM, even though it should be HOST_ARCH_X86_64.

I think you need a separate variable for a "canadian cross." gcc uses "build," "host," and "target," but as-is U-Boot's HOST_ARCH is gcc's "build" arch.

--Sean

Makefile else ifneq (,$(findstring $(MK_ARCH), "i386" "i486"

Quoted 4 lines
Makefile +0 -0
  unexport HOST_ARCH
  ifeq ("x86_64", $(MK_ARCH))
    export HOST_ARCH=$(HOST_ARCH_X86_64)
@@ -27,7 +31,7 @@ else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" 

"i586" "i686"))

Quoted 11 lines
Makefile +1 -2
    export HOST_ARCH=$(HOST_ARCH_X86)
  else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
    export HOST_ARCH=$(HOST_ARCH_AARCH64)
-else ifeq ("armv7l", $(MK_ARCH))
+else ifneq (,$(findstring $(MK_ARCH), "arm" "armv7" "armv7l"))
    export HOST_ARCH=$(HOST_ARCH_ARM)
  else ifeq ("riscv32", $(MK_ARCH))
    export HOST_ARCH=$(HOST_ARCH_RISCV32)
--

2.30.0

#2 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

Quoted 42 lines · Sean Anderson
Quoted 4 lines · Heinrich Schuchardt

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE

is set,

Quoted 7 lines

use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

????? make sandbox_defconfig NO_SDL=1
????? CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1

MK_ARCH=aarch64 make

Quoted 20 lines

---
v2:
???? use $CROSS_COMPILE instead of an extra environment variable
---
?? Makefile | 10 +++++++---
?? 1 file changed, 7 insertions(+), 3 deletions(-)

Makefile +0 -0
index ebbedb1fb1..6c256a23b6 100644
@@ -17,9 +17,13 @@ NAME =

?? # o Look for make include files relative to root of kernel src ?? MAKEFLAGS += -rR --include-dir=$(CURDIR)

Makefile +1 -1
-# Determine host architecture
+# Determine target architecture for the sandbox

?? include include/host_arch.h

Makefile NAME =

Quoted 5 lines
Makefile +4 -1
-MK_ARCH="${shell uname -m}"
+ifeq ("", "$(CROSS_COMPILE)")
+? MK_ARCH="${shell uname -m}"
+else
+? MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 

's/^\s*\([^\/]*\/\)*\([^-]*\)-\S*/\2/p'}"

Quoted 5 lines
Quoted 1 line

+endif

Won't this break cross-compiling? E.g. if on my x86_64 machine I run "CROSS_COMPILE=arm-linux-gnueabihf- make" my HOST_ARCH will be HOST_ARCH_ARM, even though it should be HOST_ARCH_X86_64.

And it seems I've confused HOSTARCH with HOST_ARCH...

(probably a good candidate for a rename)

--Sean

Quoted 23 lines

I think you need a separate variable for a "canadian cross." gcc uses "build," "host," and "target," but as-is U-Boot's HOST_ARCH is gcc's "build" arch.

--Sean

Makefile else ifneq (,$(findstring $(MK_ARCH), "i386" "i486"

Quoted 4 lines

?? unexport HOST_ARCH
?? ifeq ("x86_64", $(MK_ARCH))
???? export HOST_ARCH=$(HOST_ARCH_X86_64)

Makefile +0 -0
@@ -27,7 +31,7 @@ else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" 

"i586" "i686"))

Quoted 11 lines
Makefile +1 -2
 ???? export HOST_ARCH=$(HOST_ARCH_X86)
 ?? else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
 ???? export HOST_ARCH=$(HOST_ARCH_AARCH64)
-else ifeq ("armv7l", $(MK_ARCH))
+else ifneq (,$(findstring $(MK_ARCH), "arm" "armv7" "armv7l"))
 ???? export HOST_ARCH=$(HOST_ARCH_ARM)
 ?? else ifeq ("riscv32", $(MK_ARCH))
 ???? export HOST_ARCH=$(HOST_ARCH_RISCV32)
--

2.30.0

#3 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

In reply to Heinrich Schuchardt
Quoted 13 lines · Heinrich Schuchardt

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE is set, use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

make sandbox_defconfig NO_SDL=1 CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1 MK_ARCH=aarch64 make

Quoted 7 lines

---
v2:
use $CROSS_COMPILE instead of an extra environment variable

---
 Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
#4 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

HI Heinrich,

Quoted 15 lines · Simon Glass
Quoted 13 lines · Heinrich Schuchardt

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE is set, use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

make sandbox_defconfig NO_SDL=1 CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1 MK_ARCH=aarch64 make

Quoted 8 lines
Quoted 7 lines

---
v2:
use $CROSS_COMPILE instead of an extra environment variable

---
 Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

With this patch if I try to build sandbox with CROSS_COMPILE=/bin/ it fails.

In fact 'buildman -A sandbox' will return '/bin/' so I'd like your thoughts on what to do about this. Should we modify your patch or perhaps make buildman return something else with -A sandbox?

Regards,
Simon

Quoted 1 line
#5 lore raw

PATCH v2 1/1 sandbox: allow cross-compiling sandbox

HI Heinrich,

Quoted 15 lines · Simon Glass
Quoted 13 lines · Heinrich Schuchardt

UEFI test files like helloworld.efi require an architecture specific PE-COFF header.

Currently this does not work for cross compiling. If $CROSS_COMPILE is set, use the first part of the architecture triplet from the variable to choose the PE-COFF header.

Now we can cross-compile the sandbox, e.g.

make sandbox_defconfig NO_SDL=1 CROSS_COMPILE=/opt/bin/aarch64-linux-gnu- NO_SDL=1 MK_ARCH=aarch64 make

Quoted 8 lines
Quoted 7 lines

---
v2:
use $CROSS_COMPILE instead of an extra environment variable

---
 Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

With this patch if I try to build sandbox with CROSS_COMPILE=/bin/ it fails.

In fact 'buildman -A sandbox' will return '/bin/' so I'd like your thoughts on what to do about this. Should we modify your patch or perhaps make buildman return something else with -A sandbox?

Regards,
Simon

Quoted 1 line

Applied to u-boot-dm/next, thanks!