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 0BB34C43217 for ; Tue, 8 Nov 2022 17:09:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31D6C84FE7; Tue, 8 Nov 2022 18:09:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="AT4k93WQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 13F1784FF4; Tue, 8 Nov 2022 18:09:29 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6B1F784FFA for ; Tue, 8 Nov 2022 18:09:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39CA2616CD; Tue, 8 Nov 2022 17:09:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49160C433C1; Tue, 8 Nov 2022 17:09:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667927354; bh=qb2E8c3LXFpsV/FY9Mb/LhswJtXBtLS9h2UYdhOBoMc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AT4k93WQUOX0HmGZT8G5G9CHbNwRbifsoCOxjcEMS4m0zgR/DtH4dL3wZejRSysNP nB89q2uQ6jhI2QDcPjGrmRCBeIugomX44JGZNw1FJrLXXDyEPXg8p5YTjJf6TNocY8 ppTEFikq6bmM0oQdhSpkio8VykxHHfhQFbHi7+rOqQpQVkaZ/Coi9dge74eAtyTgr8 1DmpjplmjlZzDsSUUuaMZlR4eW4x5tWe3k+pilpK0JUb4kirnuh2yUTUxHA55+livw C7MxTHtZ4/qMM3UgcOVxdm/Ur8i9DJlUkX5Uo3L9CyfT6cR0tTpl3jlcbAfWA56/4s OCtuKJGbWuzXA== Received: by pali.im (Postfix) id 7FA91818; Tue, 8 Nov 2022 18:09:11 +0100 (CET) Date: Tue, 8 Nov 2022 18:09:11 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Max Krummenacher Cc: u-boot@lists.denx.de, Patrick DELAUNAY , Patrice CHOTARD , Tom Rini , U-Boot STM32 , Adam Ford , Max Krummenacher , AKASHI Takahiro , Du Huanpeng , Heiko Thiery , Heinrich Schuchardt , Marek =?utf-8?B?QmVow7pu?= , Quentin Schulz , Samuel Holland , Simon Glass , Stefan Roese Subject: Re: [PATCH v4 1/1] u-boot-initial-env: rework make target Message-ID: <20221108170911.klluse5h7km36vru@pali> References: <20221108085222.1378781-1-max.oss.09@gmail.com> <20221108085222.1378781-2-max.oss.09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221108085222.1378781-2-max.oss.09@gmail.com> User-Agent: NeoMutt/20180716 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 On Tuesday 08 November 2022 09:52:22 Max Krummenacher wrote: > 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 Looks good, 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 | 9 +++++---- > tools/.gitignore | 1 + > tools/Makefile | 3 +++ > tools/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 53 insertions(+), 4 deletions(-) > create mode 100644 tools/printinitialenv.c > > diff --git a/Makefile b/Makefile > index 0f1174718f7..c0669840dc7 100644 > --- a/Makefile > +++ b/Makefile > @@ -2442,11 +2442,12 @@ 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) tools FORCE > $(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 34a1aa7a8b7..a3afdee7813 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -245,6 +245,9 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs > hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler > HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include > > +# host tool to dump the currently configured default environment > +hostprogs-y += printinitialenv > + > HOSTCFLAGS_mkeficapsule.o += \ > $(shell pkg-config --cflags gnutls 2> /dev/null || echo "") > HOSTCFLAGS_mkeficapsule.o += \ > 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 >