From patchwork Sat Jan 22 01:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1582908 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Sfp6c52q; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jgdt14rZlz9t25 for ; Sat, 22 Jan 2022 12:28:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF962838C1; Sat, 22 Jan 2022 02:27:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Sfp6c52q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E397183852; Sat, 22 Jan 2022 02:27:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A4EEB83041 for ; Sat, 22 Jan 2022 02:27:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x132.google.com with SMTP id r15so9054233ilj.7 for ; Fri, 21 Jan 2022 17:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3eq6Q4BXj1iDWHaYkwyivLCf8Q/1PT10InT38Gc8P/k=; b=Sfp6c52qkXknlETigPtO6jHj/U7vHUl8V7Pwh0GyiNps3F/SmNKbdXtR4n98+0GyJf F5/uZHmKvV/wd8Va36CbNJEmFw8evMC1Oaf6po5gq28kvMPIwu0rhhk99fut7Xzn3Il1 CO0d4Wp1JPDqXH2pcURENHEwZP8RNXDVyOnn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3eq6Q4BXj1iDWHaYkwyivLCf8Q/1PT10InT38Gc8P/k=; b=YRK7SJM2xdz/PKgK2yOY81pmhKRSU5rJlclCmf9faAV9pp+XZ4IqNamqYC10uEShYR nB2vpo2f1cfx01atFwRJEZvU7bbEnVdKZjkbaSs1s4lAF0+MGoMpRGUlMvxsSRbmHQwo S7emnOfkcrD7keGHV5I2RAGSEFSTPsTtd3lUMoWjnavOSQ/0fvTwcYJxg9DkKR+2c53l iJGnsz1fBzduZd7jGMUnr8jTKGsoriSAGQ9Zy/fU7dtripiKKI3osYj3MvNy4IC7Xvzc VVN4kWmeLzxhkU72Dp2iPuANvFdQbbwDiT8rU5q86tfwPcYwGnx8cR9x/nq03g0T/nRW CEzw== X-Gm-Message-State: AOAM530groInKN6GVa+0Pz65oIw0y500Tynro+9gk9ihdMOq9deNtGdt NxM5fcji2cdvhHIsP+3Veh6oI0wgfSE5Wg== X-Google-Smtp-Source: ABdhPJyz4Ffzk1sFbvwu3HL1luahNGg+Fyw/dRsQa88BkKKhfaeoQG8gorCmg6VQAGTlgd1Vb7GIwA== X-Received: by 2002:a05:6e02:1707:: with SMTP id u7mr3806176ill.92.1642814864141; Fri, 21 Jan 2022 17:27:44 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id k17sm2153586ioj.1.2022.01.21.17.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 17:27:43 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v4 3/4] sandbox: Detect the host bit size automatically Date: Fri, 21 Jan 2022 18:27:35 -0700 Message-Id: <20220122012736.2725994-4-sjg@chromium.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220122012736.2725994-1-sjg@chromium.org> References: <20220122012736.2725994-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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. Tidy up the Kconfig help for the above two options while we are here. Signed-off-by: Simon Glass --- Changes in v4: - Use $(HOSTCC) instead of gcc - Add proper Kconfig help Changes in v3: - Use 'bitness' instead of 'bit' Changes in v2: - Drop patches previously applied - Put all the packages in gcc.rst Makefile | 11 ++++++++++- arch/sandbox/Kconfig | 33 ++++++++++++++++++++++++++++----- scripts/kconfig/Makefile | 14 +++++++++++++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b08bad48738..da9b5e494f8 100644 --- a/Makefile +++ b/Makefile @@ -570,8 +570,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 \nint main(void) { printf("CONFIG_HOST_%dBIT=y\\n", __WORDSIZE); return 0; }' \ + | $(HOSTCC) -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 477c51960da..08d7f3bded6 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -35,19 +35,42 @@ config SYS_CONFIG_NAME choice prompt "Run sandbox on 32/64-bit host" - default HOST_64BIT + default HOST_DETECT_BITNESS 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" depends on !PHYS_64BIT + help + Select this if the host is a 32-bit machine. This adjusts various + tests and other features to work correctly in this environment. If + this option is enabled on 64-bit machines you may get build warnings + and/or errors. config HOST_64BIT bool "64-bit host" + help + Select this if the host is a 64-bit machine. This adjusts various + tests and other features to work correctly in this environment. If + this option is enabled on 32-bit machines you may get build warnings + and/or errors. + +config HOST_DETECT_BITNESS + bool "Auto-detect host bitness" + help + Select this if you want the build system to determine the bitness + automatically. This compiles a small program during the build, then + runs it to determine the bitness using __WORDSIZE (32 or 64 bits). + Then it adds one of the above options (CONFIG_HOST_32 or + CONFIG_HOST_64) to the configuration when creating it. + + In rare situations this may fail, e.g. on an unsupported Operating + System or toolchain, in which case you will likely get build warnings + and errors. endchoice diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 12e525ee31f..4e28a7e5973 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