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 075D5C433FE for ; Fri, 4 Nov 2022 12:46:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B7E585103; Fri, 4 Nov 2022 13:46:12 +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="Zp3JPkAt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D265F85202; Fri, 4 Nov 2022 13:46:04 +0100 (CET) Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 137A7851F6 for ; Fri, 4 Nov 2022 13:45:59 +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-ed1-x52f.google.com with SMTP id r14so7432920edc.7 for ; Fri, 04 Nov 2022 05:45:59 -0700 (PDT) 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=7ZxRixcDXoK+ZZjQFG0LKgdMO+0+q28kq8UXiJY4cHk=; b=Zp3JPkAt+LtlpxLygyvKVxnqllgLkmbSYjBdbANte+cgkgpQkVajoQRXH7wsdIHdYW WSTI7Vd36SIxJBGx6RN7CW3RnWdjV0ol8iibFJBhLzm8BuWiSSLVPVAv1wZaroNzvKVR pMcH3OR/5YKlrUT5P4t2+qPTj9y8WSMuhXRUXdkAAKxonb2J+JOJQoIrBGehi5fdw0qo MtHfFagJS5UMo+nLhUsY577ZSEbAm9MKRzqJ2b87OMoV39pWI54dps2Tgj/a+dCQtvQi yqIHE22HC+TXXmrWVx5Oef9d6uz/bkYrk5tU+InC365QatPBt26YhCHN2KZAPpyvS4l8 JFsg== 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=7ZxRixcDXoK+ZZjQFG0LKgdMO+0+q28kq8UXiJY4cHk=; b=5HPNhzgl7T9RPe+9KcsQ7ciJG/FqkuGGTs9818ZJpUX72xCdmWHNw2zH8HSpFNblFs lxivTreZFwwUHk7aubke01+m8VkMGPh1DlF+d5XiVPgD9UYowUBgY6gDDqU6CTIwrbGK blkOSws6FNhsf27ADtK/uI7dwN0bWhfy1zbAdQyaNTC1Sz9wLL4qR/Tu8834zfN28m5c 4Nwtr3IRtZWTrlyu1H9xnMddd3lfwcatATVQXFpPHAPXxI7KqbkEAskLs8/Tfg+LqWO4 g9D0SMfxvHea4kNmQ50Pd9Lhbfu/qal6NItQBnMUNIEv+IR2f9RnRa5mpgyIPpvesKFn +lLA== X-Gm-Message-State: ACrzQf01gOlirTE0fBsUUqrUi1yLk4a+piW7eb701GOhioqTEjAzU/B/ lRzYyVp9tUkRyUKB4vzShtEF8uBDbDu0BQ== X-Google-Smtp-Source: AMsMyM7M53o0kPzpdOuFxs2TkO2+gRP/joGd/45YfRTlivii7Nkt2nkQEi8asM4KA3PJrZn3HemtLg== X-Received: by 2002:a05:6402:1cc5:b0:453:ed3f:6a38 with SMTP id ds5-20020a0564021cc500b00453ed3f6a38mr35847735edb.346.1667565958147; Fri, 04 Nov 2022 05:45:58 -0700 (PDT) Received: from linuxdev2.toradex.int (31-10-206-125.static.upc.ch. [31.10.206.125]) by smtp.gmail.com with ESMTPSA id t26-20020aa7db1a000000b0045ce419ecffsm1898105eds.58.2022.11.04.05.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 05:45:57 -0700 (PDT) From: Max Krummenacher To: u-boot@lists.denx.de Cc: Adam Ford , U-Boot STM32 , =?UTF-8?q?Pali=20Roh=C3=A1r?= , 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 , Weijie Gao Subject: [PATCH v3 1/1] Makefile: rework u-boot-initial-env target Date: Fri, 4 Nov 2022 13:44:57 +0100 Message-Id: <20221104124458.890133-2-max.oss.09@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221104124458.890133-1-max.oss.09@gmail.com> References: <20221104124458.890133-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 --- 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..b8ee2deb3ec 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 = \ + 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