Re: [PATCH 1/3] sandbox: Move HOST_ARCH detection to Kconfig

2024-05-18 Thread Jiaxun Yang



在2024年5月17日五月 下午11:09,Jiaxun Yang写道:
[...]
> diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c 
> b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> index f668cdac4ab2..2dfbb7c74075 100644
> --- a/lib/efi_selftest/efi_selftest_miniapp_exception.c
> +++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c

Seeme like I forgot to move host_arch.h from this file, I don't understand why
does it only cause problem non-sandbox build.

Will resend if no further review comments.

Thanks
- Jiaxun

> @@ -36,11 +36,11 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
>  #elif defined(CONFIG_X86)
>   asm volatile (".word 0x\n");
>  #elif defined(CONFIG_SANDBOX)
> -#if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
> +#if (CONFIG_IS_ENABLED(HOST_ARCH_ARM) || 
> CONFIG_IS_ENABLED(HOST_ARCH_AARCH64))
>   asm volatile (".word 0xe7f7defb\n");
> -#elif (HOST_ARCH == HOST_ARCH_RISCV32 || HOST_ARCH == 
> HOST_ARCH_RISCV64)
> +#elif (CONFIG_IS_ENABLED(HOST_ARCH_RISCV32) || 
> CONFIG_IS_ENABLED(HOST_ARCH_RISCV64))
>   asm volatile (".word 0x\n");
> -#elif (HOST_ARCH == HOST_ARCH_X86 || HOST_ARCH == HOST_ARCH_X86_64)
> +#elif (CONFIG_IS_ENABLED(HOST_ARCH_X86) || 
> CONFIG_IS_ENABLED(HOST_ARCH_X86_64))
>   asm volatile (".word 0x\n");
>  #endif
>  #endif
>
> -- 
> 2.34.1

-- 
- Jiaxun


[PATCH 1/3] sandbox: Move HOST_ARCH detection to Kconfig

2024-05-17 Thread Jiaxun Yang
Move host arch detection to Kconfig so we can make some
options depend on HOST_ARCH.

Also now we are using compiler macros to detect target
arch, which is more robust than looking at uname -a.

Signed-off-by: Jiaxun Yang 
---
 Makefile  | 24 -
 arch/sandbox/Kconfig  | 23 
 arch/sandbox/config.mk| 12 +--
 arch/sandbox/lib/crt0_sandbox_efi.S   | 14 ++--
 arch/sandbox/lib/reloc_sandbox_efi.c  | 14 ++--
 include/efi_default_filename.h| 14 ++--
 include/host_arch.h   | 26 ---
 lib/efi_selftest/efi_selftest_miniapp_exception.c |  6 +++---
 8 files changed, 53 insertions(+), 80 deletions(-)

diff --git a/Makefile b/Makefile
index 44deb339af19..596f6458e6b2 100644
--- a/Makefile
+++ b/Makefile
@@ -16,29 +16,6 @@ NAME =
 # (this increases performance and avoids hard-to-debug behaviour)
 MAKEFLAGS += -rR
 
-# Determine target architecture for the sandbox
-include include/host_arch.h
-ifeq ("", "$(CROSS_COMPILE)")
-  MK_ARCH="${shell uname -m}"
-else
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 
's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
-endif
-unexport HOST_ARCH
-ifeq ("x86_64", $(MK_ARCH))
-  export HOST_ARCH=$(HOST_ARCH_X86_64)
-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 ifneq (,$(findstring $(MK_ARCH), "arm" "armv7" "armv7a" "armv7l"))
-  export HOST_ARCH=$(HOST_ARCH_ARM)
-else ifeq ("riscv32", $(MK_ARCH))
-  export HOST_ARCH=$(HOST_ARCH_RISCV32)
-else ifeq ("riscv64", $(MK_ARCH))
-  export HOST_ARCH=$(HOST_ARCH_RISCV64)
-endif
-undefine MK_ARCH
-
 # Avoid funny character set dependencies
 unexport LC_ALL
 LC_COLLATE=C
@@ -1963,7 +1940,6 @@ define filechk_version.h
echo \#define U_BOOT_VERSION_NUM $(VERSION); \
echo \#define U_BOOT_VERSION_NUM_PATCH $$(echo $(PATCHLEVEL) | \
sed -e "s/^0*//"); \
-   echo \#define HOST_ARCH $(HOST_ARCH); \
echo \#define CC_VERSION_STRING \"$$(LC_ALL=C $(CC) --version | head -n 
1)\"; \
echo \#define LD_VERSION_STRING \"$$(LC_ALL=C $(LD) --version | head -n 
1)\"; )
 endef
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 1c8353d6156d..c3954e33aceb 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -47,6 +47,29 @@ config HOST_32BIT
 config HOST_64BIT
def_bool $(cc-define,_LP64)
 
+config HOST_ARCH_X86
+   def_bool $(cc-define,__i386__)
+
+config HOST_ARCH_X86_64
+   def_bool $(cc-define,__x86_64__)
+
+config HOST_ARCH_ARM
+   def_bool $(cc-define,__arm__)
+
+config HOST_ARCH_AARCH64
+   def_bool $(cc-define,__aarch64__)
+
+config HOST_ARCH_RISCV32
+   def_bool $(cc-define,__riscv_xlen 32)
+
+config HOST_ARCH_RISCV64
+   def_bool $(cc-define,__riscv_xlen 64)
+
+config HOST_ARCH_UNKNOWN
+   def_bool !HOST_ARCH_X86 && !HOST_ARCH_X86_64 && \
+!HOST_ARCH_ARM && !HOST_ARCH_AARCH64 && \
+!HOST_ARCH_RISCV32 && !HOST_ARCH_RISCV64
+
 config HOST_HAS_SDL
def_bool $(success,sdl2-config --version)
 
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 405843800e9e..6b1da993ba4e 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -44,27 +44,27 @@ cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T 
u-boot-spl.lds \
-Wl,--no-whole-archive \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
 
-ifeq ($(HOST_ARCH),$(HOST_ARCH_X86_64))
+ifeq ($(CONFIG_HOST_ARCH_X86_64),y)
 EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_x86_64_efi.lds
 EFI_TARGET := --target=efi-app-x86_64
-else ifeq ($(HOST_ARCH),$(HOST_ARCH_X86))
+else ifeq ($(CONFIG_HOST_ARCH_X86),y)
 EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_ia32_efi.lds
 EFI_TARGET := --target=efi-app-ia32
-else ifeq ($(HOST_ARCH),$(HOST_ARCH_AARCH64))
+else ifeq ($(CONFIG_HOST_ARCH_AARCH64),y)
 EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_aarch64_efi.lds
 OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
-j __u_boot_list -j .rela.dyn -j .got -j .got.plt \
-j .binman_sym_table -j .text_rest \
-j .efi_runtime -j .efi_runtime_rel
-else ifeq ($(HOST_ARCH),$(HOST_ARCH_ARM))
+else ifeq ($(CONFIG_HOST_ARCH_ARM),y)
 EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_arm_efi.lds
 OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
-j .data -j .got -j .got.plt -j __u_boot_list -j .rel.dyn \
-j .binman_sym_table -j .text_rest \
-j .efi_runtime -j .efi_runtime_rel
-else ifeq ($(HOST_ARCH),$(HOST_ARCH_RISCV32))
+else ifeq ($(CONFIG_HOST_ARCH_RISCV32),y)