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 5261AC4332F for ; Sun, 4 Dec 2022 21:20:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0CAAD8566D; Sun, 4 Dec 2022 22:18:16 +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="ZCEWD7QC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B64485663; Sun, 4 Dec 2022 22:18:14 +0100 (CET) Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) (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 0B9A785660 for ; Sun, 4 Dec 2022 22:18:09 +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@google.com Received: by mail-yb1-xb29.google.com with SMTP id o127so12270533yba.5 for ; Sun, 04 Dec 2022 13:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KHlFDVDxKt/jZX62ZdFaeqZU27WhxrRHtrnRnXUt2AA=; b=ZCEWD7QCufGZRYiP9+PqzCo9MRFG9kC82+9BlXN2srGdrL8jK1JS/gm4IVY47e2AeT AI4UFx48xVYsTUcZIfqGo+2sGYmVj1iTtijgHh0Xs9LK2VUYbVjpwSLtRrucvfZO/gac jqZQAcIiwwteQgTOGtP1FtYxqRujx9zpITfEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KHlFDVDxKt/jZX62ZdFaeqZU27WhxrRHtrnRnXUt2AA=; b=tmKPVK+JsIkLLVc2KqADjzLt7e6TghpwovfR1epBS173ui+zLhekdaiwi8kLyZHVy3 D6Er1pzfE3WGXxgST2RApPCQJmxoE5IRyr4V9TQs/FIV5MJBO5hb2quHKWocuMufakWY 2jAUpYGigdHVORZIffUigpGgg91N8vcD3FVuun2SA3ZRykZX9TitIdAZ4vrKRtrHYiSJ awsTJRg1MTJZ0r3RlUq7EC2g60nfQ1e4NKSEw8YAzIZ4GBEjfBXmKalMBqiPXjplaFq/ JmH4vYxepHZNqkRNNCn4ewQWHJf/230yMxrW2hmoXgZYClVtGjrKoBmKdmz9spcis0zb VOzg== X-Gm-Message-State: ANoB5pmwyOLw3y5pzxvG9CTiA9Owg98BDryEx0shRIVljgDYUp8vt/gQ t0T0L+ZgHU+hP/7Nq5Nr6XD5TyCaSBcVhcBiaZ1PvQ== X-Google-Smtp-Source: AA0mqf6/IRDZFaIrQyhBCie2ViV+TMmt6ob0jlNJVPokSXjiAW1obW1sDE6KtmrxoJ1uR7EKlBmBzlSLWyV6RK2C7G0= X-Received: by 2002:a25:d215:0:b0:6f1:dc5b:b188 with SMTP id j21-20020a25d215000000b006f1dc5bb188mr46978457ybg.176.1670188687410; Sun, 04 Dec 2022 13:18:07 -0800 (PST) MIME-Version: 1.0 References: <20221128084122.3456680-1-max.oss.09@gmail.com> <20221128084122.3456680-2-max.oss.09@gmail.com> In-Reply-To: <20221128084122.3456680-2-max.oss.09@gmail.com> From: Simon Glass Date: Mon, 5 Dec 2022 10:16:59 +1300 Message-ID: Subject: Re: [PATCH v5 1/1] u-boot-initial-env: rework make target To: Max Krummenacher Cc: u-boot@lists.denx.de, Adam Ford , =?UTF-8?Q?Pali_Roh=C3=A1r?= , U-Boot STM32 , Patrick DELAUNAY , Tom Rini , Patrice CHOTARD , Max Krummenacher , AKASHI Takahiro , Du Huanpeng , Heiko Thiery , Heinrich Schuchardt , =?UTF-8?B?TWFyZWsgQmVow7pu?= , Quentin Schulz , Samuel Holland , Stefan Roese Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi Max, On Mon, 28 Nov 2022 at 21:41, 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 > Acked-by: Pali Roh=C3=A1r > > --- > > 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=C3=A1r > > Changes in v4: > - add '(objtree)/' when calling the tool. Suggested by Pali Roh=C3=A1r. > - 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=C3=A1r. > - removed the sed rule which replaces \x00 with \x0A as this is already > done by the tool. Suggested by Pali Roh=C3=A1r. > > Changes in v2: > - reworked to build a host tool which prints the configured > environment as proposed by Pali Roh=C3=A1r > https://lore.kernel.org/u-boot/20221018174827.1393211-1-max.oss.09@gmai= l.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 Reviewed-by: Simon Glass It would be nice to have a test for this. It could go in test_env.py and you can use test_event.py as an example. - Simon > > 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 =3D GENENV $@ > -cmd_genenv =3D $(OBJCOPY) --dump-section .rodata.default_environment=3D$= @ env/common.o; \ > - sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/= d' $@; \ > - sort --field-separator=3D=3D -k1,1 --stable $@ -o $@ > +cmd_genenv =3D \ > + $(objtree)/tools/printinitialenv | \ > + sed -e '/^\s*$$/d' | \ > + sort --field-separator=3D=3D -k1,1 --stable -o $@ > > -u-boot-initial-env: u-boot.bin > +u-boot-initial-env: $(env_h) FORCE > + $(Q)$(MAKE) $(build)=3Dtools $(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 :=3D lib common > > always :=3D $(hostprogs-y) > > +# Host tool to dump the currently configured default environment, > +# build it on demand, i.e. not add it to 'always'. > +hostprogs-y +=3D printinitialenv > + > # Generated LCD/video logo > LOGO_H =3D $(objtree)/include/bmp_logo.h > LOGO_DATA_H =3D $(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 =3D default_environment; *env; env =3D nxt + 1) { > + for (nxt =3D env; *nxt; ++nxt) { > + if (nxt >=3D &default_environment[sizeof(default_= environment)]) { > + fprintf(stderr, "## Error: environment no= t terminated\n"); > + return -1; > + } > + } > + printf("%s\n", env); > + } > + return 0; > +} > -- > 2.35.3 >