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 10FFDC4332F for ; Tue, 8 Nov 2022 08:54:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E58DF84E3C; Tue, 8 Nov 2022 09:53:54 +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="RHfx3tNA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D020584DEB; Tue, 8 Nov 2022 09:53:46 +0100 (CET) Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 7C49684F34 for ; Tue, 8 Nov 2022 09:53:29 +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-x630.google.com with SMTP id ft34so396130ejc.12 for ; Tue, 08 Nov 2022 00:53:29 -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=ZhSt0IM4DKvGxdjJPXT3qNiT0HPqjT7VAxKRE5pTW2Y=; b=RHfx3tNAH5Sh7HUMeIVt/A7OEGGZUyCE5EGdlZgtA78AlLkzeGYfqc54Bn0i+1G97g +HpgaTHXugblQsu07PdldhL1iQ3abSeoPnmPtkJ0IMWde4W3JdEmAlaseYMb89DlOPH6 5VZ8GbywMlhIjKNkEg1BeZE/1/LtBC9xTGpSEMwgSSVKV4nrAYYuWzNxx2OeH17F5g3h BCLdzleKA8zzy1Ef9UvrKowZI+A4JMrS2Vqgqdby5ZSlK98lK2k7RkRoRM0l6E854F4U 7kc/G5AD/j6XKNSz74FH4w0ED0F4HnfB4DygrSoE/ZqsHM97+Q9xnTf6cfz1+55MD6/d 66sg== 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=ZhSt0IM4DKvGxdjJPXT3qNiT0HPqjT7VAxKRE5pTW2Y=; b=J+PYGSBdARDNHIuOpOcG18WiKmNbwl+qBK5M/I22oFZOvv3GyiDtOs4BoH3SfAb/I1 De5r5M0QqjMWf7qBRoByLZBIZ6KukIHJJIhdamLOhP/PuS5aMIm/fdTtEwfUnwM4zMZD ueEbfUSsLIImgiK3IsZ1IlKfV3+tC5gXQ/mTygRViPiPGVDmhimPsH8U1fcAhBzZsUg0 JkFII7PORSCnPo0HMZq6sa5LkG3BPErZ/wTFdyWL7fVBi3k4eOApKZ+kJtLC7RnMchHY 88WF8n0I1hVYiLzVUMzWeFZ1xiTqqzybYy3y+I6bdB80WHsRhJeQbHY5EvO/BencWjDH Vi1A== X-Gm-Message-State: ANoB5pm8tP1ZK6IueVbBaty4QZVmcxu7HORp4F0iv9UDkNp4LRtuAfGI DqdjgVZoroH25vAwY7gcKjQyI6/SoOk= X-Google-Smtp-Source: AA0mqf6fvUzEePo2i9Ks0WP9tZsKpjYxHnpT4BXhtwtioYVjKTh3T2O6Z0d9yXn8bQY8JQACaNODeg== X-Received: by 2002:a17:907:c208:b0:7ad:a0df:d4c7 with SMTP id ti8-20020a170907c20800b007ada0dfd4c7mr9273446ejc.312.1667897589838; Tue, 08 Nov 2022 00:53:09 -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 s18-20020aa7c552000000b00461c1804cdasm5303628edr.3.2022.11.08.00.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:53:09 -0800 (PST) From: Max Krummenacher To: u-boot@lists.denx.de Cc: Patrick DELAUNAY , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Patrice CHOTARD , Tom Rini , U-Boot STM32 , Adam Ford , 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 v4 1/1] u-boot-initial-env: rework make target Date: Tue, 8 Nov 2022 09:52:22 +0100 Message-Id: <20221108085222.1378781-2-max.oss.09@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221108085222.1378781-1-max.oss.09@gmail.com> References: <20221108085222.1378781-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 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