From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30B05C4332F for ; Mon, 28 Nov 2022 08:41:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AE370851C2; Mon, 28 Nov 2022 09:41:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QxNwcdCt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8357F8519D; Mon, 28 Nov 2022 09:41:45 +0100 (CET) Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 CB03D851FC for ; Mon, 28 Nov 2022 09:41:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=max.oss.09@gmail.com Received: by mail-ej1-x62d.google.com with SMTP id bj12so23850168ejb.13 for ; Mon, 28 Nov 2022 00:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=95Ccw1OHIlU8aJ0+cVh3HT3PGgcJW2huX+adMniGKtQ=; b=QxNwcdCtoIMztmMRfNS4JetfxNQ9Zkb8wKm+tDtFG7K77CTjwR5Fs/Vr9wUgzcl+Wp 4ueMGwaZbUCW866/GI3zKLaKyAVA21jhuBX2F2YbCb0A1nYUVmi/ffpjUGcOU+5NvAgp 7qYh7utRR1l4QjwJEkL1JZx+acovM1d9TqzPQbiY5R/5txeHrRwNZJPOIqnXlGEe0Pnq RLEkUpnclQS8GW04ve/Elia/ZH2fq2BI4k1m+P2hq3JB+fjgTAMuM9ERglpjVwOo4xcS S7zb3OYBw4xiIB6cd/bBoQzbLA1ycgfvDsj04Yo0FiCnq9Jx5uVoIdUdbqAKcpuMl9lL 2GTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=95Ccw1OHIlU8aJ0+cVh3HT3PGgcJW2huX+adMniGKtQ=; b=HkLjeeSHCjBowbsN10VN1uLvY6y4gINk7knQFFglgGTITH8dNPVrDdsEW9pdlZ8R2S ANTgr39gWJ8x72YngmSMKlXfsIYW1UlBiKZuQxEFlxK4bZfRta0Wk1cxKeP9lNoAFREO cztiZ+72k0xGl3LguhIKBFvUXXQd34lVBJLVd4RrGmT42DGXgUH9yY0lJxFsvTQDZQJ5 wxm/ffcpeB2eVRAdHjpZb8TlcaPZ8IcqZ5VNTYFHT1kOZ13ke1NRUcDNeXhc5bnlzl1U sK1Un62A+mO9UV5rDPMhJ9HGYUlDFba2gDW0kRPji1EfgCtlEKqWofqzZW9iz87vtCdy 6zTA== X-Gm-Message-State: ANoB5pmM9qPAEcZoQEdp/GQpXE03Eve7qI6o87jGxRWtUlytTyRBYOX/ jlv0XtylCGzBOVeuIBUAQ9jra7jhH9E= X-Google-Smtp-Source: AA0mqf5Gr99PAOPol5nQs17zc5lIumOtYlB0/1tVLwSBroN9GsKfU+F0ncK65PUTpYoI5F84YFuwrA== X-Received: by 2002:a17:906:c303:b0:7ad:95d2:9df2 with SMTP id s3-20020a170906c30300b007ad95d29df2mr41236252ejz.607.1669624901110; Mon, 28 Nov 2022 00:41:41 -0800 (PST) Received: from linuxdev2.toradex.int (31-10-206-125.static.upc.ch. [31.10.206.125]) by smtp.gmail.com with ESMTPSA id cd10-20020a170906b34a00b007aa239cf4d9sm4671961ejb.89.2022.11.28.00.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 00:41:40 -0800 (PST) From: Max Krummenacher To: u-boot@lists.denx.de Cc: Adam Ford , =?UTF-8?q?Pali=20Roh=C3=A1r?= , U-Boot STM32 , Patrick DELAUNAY , Tom Rini , Patrice CHOTARD , Max Krummenacher , AKASHI Takahiro , Du Huanpeng , Heiko Thiery , Heinrich Schuchardt , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Quentin Schulz , Samuel Holland , Simon Glass , Stefan Roese Subject: [PATCH v5 1/1] u-boot-initial-env: rework make target Date: Mon, 28 Nov 2022 09:41:22 +0100 Message-Id: <20221128084122.3456680-2-max.oss.09@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221128084122.3456680-1-max.oss.09@gmail.com> References: <20221128084122.3456680-1-max.oss.09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean From: Max Krummenacher With LTO enabled the U-Boot initial environment is no longer stored in an easy accessible section in env/common.o. I.e. the section name changes from build to build, its content maybe compressed and it is annotated with additional data. Drop trying to read the initial env with elf tools from the compiler specific object file in favour of adding and using a host tool with the only functionality of printing the initial env to stdout. See also: https://lore.kernel.org/all/927b122e-1f62-e790-f5ca-30bae4332c77@foss.st.com/ Signed-off-by: Max Krummenacher Acked-by: Pali Rohár --- Changes in v5: - don't build the printinitialenv tool unconditionally but build it only as part of the u-boot-initial-env target. This no longer fails the 'make tools-only_defconfig tools-only' use-case which is reported by Tom Rini. Adding the $(env_h) dependencies to the tools target might give circular dependencies issues with some future tool. - add Acked-by: Pali Rohár Changes in v4: - add '(objtree)/' when calling the tool. Suggested by Pali Rohár. - renamed patch, as more than just the Makefile has changes Changes in v3: - moved the tool from scripts/ to tools/. Suggested by Tom Rini - changed the dependencies to '$(env_h)' and 'tools'. Suggested by Tom Rini and Pali Rohár. - removed the sed rule which replaces \x00 with \x0A as this is already done by the tool. Suggested by Pali Rohár. Changes in v2: - reworked to build a host tool which prints the configured environment as proposed by Pali Rohár https://lore.kernel.org/u-boot/20221018174827.1393211-1-max.oss.09@gmail.com/ - renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled" Makefile | 10 ++++++---- tools/.gitignore | 1 + tools/Makefile | 4 ++++ tools/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tools/printinitialenv.c diff --git a/Makefile b/Makefile index 2d24ac3959f..32e4bef10f5 100644 --- a/Makefile +++ b/Makefile @@ -2439,11 +2439,13 @@ endif $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost quiet_cmd_genenv = GENENV $@ -cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \ - sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \ - sort --field-separator== -k1,1 --stable $@ -o $@ +cmd_genenv = \ + $(objtree)/tools/printinitialenv | \ + sed -e '/^\s*$$/d' | \ + sort --field-separator== -k1,1 --stable -o $@ -u-boot-initial-env: u-boot.bin +u-boot-initial-env: $(env_h) FORCE + $(Q)$(MAKE) $(build)=tools $(objtree)/tools/printinitialenv $(call if_changed,genenv) # Consistency checks diff --git a/tools/.gitignore b/tools/.gitignore index d3a93ff294a..28e8ce2a07a 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -28,6 +28,7 @@ /mxsboot /ncb /prelink-riscv +/printinitialenv /proftool /relocate-rela /spl_size_limit diff --git a/tools/Makefile b/tools/Makefile index 26be0a7ba2e..80bc62befcb 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -275,6 +275,10 @@ clean-dirs := lib common always := $(hostprogs-y) +# Host tool to dump the currently configured default environment, +# build it on demand, i.e. not add it to 'always'. +hostprogs-y += printinitialenv + # Generated LCD/video logo LOGO_H = $(objtree)/include/bmp_logo.h LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h diff --git a/tools/printinitialenv.c b/tools/printinitialenv.c new file mode 100644 index 00000000000..c58b234d679 --- /dev/null +++ b/tools/printinitialenv.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2022 + * Max Krummenacher, Toradex + * + * Snippets taken from tools/env/fw_env.c + * + * This prints the list of default environment variables as currently + * configured. + * + */ + +#include + +/* Pull in the current config to define the default environment */ +#include + +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ /* get only #defines from config.h */ +#include +#undef __ASSEMBLY__ +#else +#include +#endif + +#define DEFAULT_ENV_INSTANCE_STATIC +#include +#include + +int main(void) +{ + char *env, *nxt; + + for (env = default_environment; *env; env = nxt + 1) { + for (nxt = env; *nxt; ++nxt) { + if (nxt >= &default_environment[sizeof(default_environment)]) { + fprintf(stderr, "## Error: environment not terminated\n"); + return -1; + } + } + printf("%s\n", env); + } + return 0; +} -- 2.35.3