[PATCH v2 5/5] sandbox: Detect the host bit size automatically

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Jul 19 02:54:44 CEST 2021


On 7/18/21 10:14 PM, Simon Glass wrote:
> At present if you build sandbox on a 32-bit host a lot of errors are
> produced. This is because CONFIG_HOST_64BIT is enabled by default.
>
> It is quite annoying to have to change that manually before building
> sandbox. It is also quite confusing for new users.
>
> Add a way to detect the setting and add the appropriate
> CONFIG_HOST_64BIT=y or CONFIG_HOST_32BIT=y to the defconfig, to avoid
> this issue.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v2:
> - Drop patches previously applied
> - Put all the packages in gcc.rst
>
>   Makefile                 | 11 ++++++++++-
>   arch/sandbox/Kconfig     | 13 ++++++++-----
>   scripts/kconfig/Makefile | 14 +++++++++++++-
>   3 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index bc404c8f989..0257d202597 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -565,8 +565,17 @@ export KBUILD_DEFCONFIG KBUILD_KCONFIG
>   config: scripts_basic outputmakefile FORCE
>   	$(Q)$(MAKE) $(build)=scripts/kconfig $@
>
> +# If nothing is specified explicitly, detect the bit size for sandbox,
> +# referred to from arch/sandbox/Kconfig
> +# Add it to the end of the defconfig file
>   %config: scripts_basic outputmakefile FORCE
> -	$(Q)$(MAKE) $(build)=scripts/kconfig $@
> +	$(Q)if test -f $(srctree)/configs/$@ && \
> +		! grep -Eq "CONFIG_HOST_(32|64)BIT=y" $(srctree)/configs/$@; then \
> +		echo '#include <stdio.h>\nint main(void) { printf("CONFIG_HOST_%dBIT=y\\n", __WORDSIZE); return 0; }' \
> +			 | gcc -x c - -o get_word_size; \
> +		extra=$$(./get_word_size); \
> +	fi; \
> +	$(MAKE) $(build)=scripts/kconfig EXTRA_DEFCONFIG=$$extra $@
>
>   else
>   # ===========================================================================
> diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
> index f83282d9d56..01b2a3fcad1 100644
> --- a/arch/sandbox/Kconfig
> +++ b/arch/sandbox/Kconfig
> @@ -35,12 +35,12 @@ config SYS_CONFIG_NAME
>
>   choice
>   	prompt "Run sandbox on 32/64-bit host"
> -	default HOST_64BIT
> +	default HOST_DETECT_BIT
>   	help
> -	  Sandbox can be built on 32-bit and 64-bit hosts.
> -	  The default is to build on a 64-bit host and run
> -	  on a 64-bit host. If you want to run sandbox on
> -	  a 32-bit host, change it here.
> +	  Sandbox can be built on 32-bit and 64-bit hosts. This is generally
> +	  auto-detected but you can force a particular word size here. If you
> +	  see strange warnings about SANDBOX_BITS_PER_LONG then you may have
> +	  selected the wrong value.
>
>   config HOST_32BIT
>   	bool "32-bit host"
> @@ -49,6 +49,9 @@ config HOST_32BIT
>   config HOST_64BIT
>   	bool "64-bit host"
>
> +config HOST_DETECT_BIT

%s/BIT/BITNESS/

HOST_DETECT_BITNESS would better express the meaning of the flag.
Cf. https://en.wiktionary.org/wiki/bitness

> +	bool "Auto-detect bit size"

The flag does not enable detecting the size of a bit.

boot "Auto-detect bitness."

Best regards

Heinrich

> +
>   endchoice
>
>   config SANDBOX_CRASH_RESET
> diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
> index d52128425ce..8e14db7ade3 100644
> --- a/scripts/kconfig/Makefile
> +++ b/scripts/kconfig/Makefile
> @@ -12,6 +12,9 @@ PHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig \
>   #  Set SRCARCH to .. fake this Makefile.
>   SRCARCH := ..
>
> +# For U-Boot, EXTRA_DEFCONFIG contains a line to be added to the defconfig
> +# before processing. If empty, no line is added.
> +
>   ifdef KBUILD_KCONFIG
>   Kconfig := $(KBUILD_KCONFIG)
>   else
> @@ -92,8 +95,17 @@ else
>   endif
>   endif
>
> +# If EXTRA_DEFCONFIG is defined, add it to the end of the defconfig, before
> +# processing. This allows the caller to change a setting on the fly
>   %_defconfig: $(obj)/conf
> -	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
> +	$(Q)defconfig="$(srctree)/arch/$(SRCARCH)/configs/$@"; \
> +	if [ -n "$(EXTRA_DEFCONFIG)" ]; then \
> +		cat $$defconfig >defconfig_tmp; \
> +		echo $(EXTRA_DEFCONFIG) >>defconfig_tmp; \
> +		$< $(silent) --defconfig=defconfig_tmp $(Kconfig); \
> +	else \
> +		$< $(silent) --defconfig=$$defconfig $(Kconfig); \
> +	fi
>
>   # Added for U-Boot (backward compatibility)
>   %_config: %_defconfig
>



More information about the U-Boot mailing list