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 39198C38A02 for ; Fri, 28 Oct 2022 16:20:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3ADBB850BB; Fri, 28 Oct 2022 18:20:30 +0200 (CEST) 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="Cd8OO6V8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 61BC1850BA; Fri, 28 Oct 2022 18:20:26 +0200 (CEST) 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 9442484F17 for ; Fri, 28 Oct 2022 18:20:23 +0200 (CEST) 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 k2so14144640ejr.2 for ; Fri, 28 Oct 2022 09:20:23 -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=9jQov0U3K0h5xYE0c6Q7wOYslz3K5OHQFZ2gqKyHUJI=; b=Cd8OO6V8bJ6ScLZ7GZl5LH9E+A/EGnxaTrewOKaxAhbH1gK/HuI6Ot+/StqjAlUWYD WFL64lau5OtwdkXnfmU53jPEH6sWFJ/6sYNf9OOTj5xXAB5e/O1vM1t1EsHWhfyChWVR HRTA5w3DR2LU/iNZ90DUCM5ChmrkJ3NTiNztR1yXrZ/fXanM8QJOYuIePOGpn7MA1WiX 7hzU8vImohE2i6GWtJvolUzY7w+lgCctcsbT6juz7kWfViv9R+4oyTg85Eu4F9RPw7S+ 0TST5dtc4ueQpxrWyij+G3sSN4//TScT1sKeHxttGrC3tBYYsXaRryF6NwwfZ5VHESxo FS4Q== 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=9jQov0U3K0h5xYE0c6Q7wOYslz3K5OHQFZ2gqKyHUJI=; b=IKkS7PEmmbevNCEDwzxruGn54CY+NDA6i+rT97w2wIIsGBPsW3/JT4AX6+qWMBuXUv 8CA0zXFxLk7WHwIZvICB7MXU5x5xe2siusIq6Ks+BFbAkMMNGX6jxAim8JxuZGNmyAVh iJIuVzF+ZnB6bHdnZqSbLLbIcpwJgTkrf2MfzYJy3RyVrvb4zZ5FpM7ePmcrLOQJHzc4 rzObKEM7v+/2OUcQXjgxBj9pb/m3mMrmbU9XYl0R537gtPjf6MXjg0ORE3IFtOcObyht LObpbsOWR7oZAcJeqmpKbLLSgEU+ExY6oS69UJ+eV9YQ8bVCboiHSGEWkKZrzjPtQmOK gHAw== X-Gm-Message-State: ACrzQf1f13kfZkZbxIUNA+2N3xj3k8Fhy6/jWM/jXTJHC58UoMg8/spd t1UxnppKm2Pgu4oC/h9wUQXXAYJ1Hy4= X-Google-Smtp-Source: AMsMyM5FMSRkNVquwkqRQGPIGA0Z2gX5qkhxJu6ffUG5yqhs3dVLUJsuwXN5x1PURHTjQOMp6mZrgQ== X-Received: by 2002:a17:907:9807:b0:797:a5ba:1327 with SMTP id ji7-20020a170907980700b00797a5ba1327mr145848ejc.274.1666974022717; Fri, 28 Oct 2022 09:20:22 -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 le5-20020a170907170500b00781e7d364ebsm2458478ejc.144.2022.10.28.09.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 09:20:22 -0700 (PDT) From: Max Krummenacher To: u-boot@lists.denx.de Cc: Tom Rini , U-Boot STM32 , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Adam Ford , Patrick DELAUNAY , Patrice CHOTARD , Max Krummenacher , Heinrich Schuchardt , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Philippe Reynes , Quentin Schulz , Simon Glass Subject: [PATCH v2 1/1] Makefile: rework u-boot-initial-env target Date: Fri, 28 Oct 2022 18:18:49 +0200 Message-Id: <20221028161850.565610-2-max.oss.09@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221028161850.565610-1-max.oss.09@gmail.com> References: <20221028161850.565610-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 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 | 7 ++++--- scripts/.gitignore | 1 + scripts/Makefile | 5 +++++ scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 scripts/printinitialenv.c diff --git a/Makefile b/Makefile index 0f1174718f7..2f97d63c398 100644 --- a/Makefile +++ b/Makefile @@ -2442,9 +2442,10 @@ 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 = \ + scripts/printinitialenv | \ + sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \ + sort --field-separator== -k1,1 --stable -o $@ u-boot-initial-env: u-boot.bin $(call if_changed,genenv) diff --git a/scripts/.gitignore b/scripts/.gitignore index 08cc824bac3..6068724a0d4 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -2,3 +2,4 @@ # Generated files # bin2c +printinitialenv diff --git a/scripts/Makefile b/scripts/Makefile index 8731e6cecd7..ba993820571 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -5,8 +5,13 @@ # --------------------------------------------------------------------------- hostprogs-$(CONFIG_BUILD_BIN2C) += bin2c +hostprogs-y += printinitialenv always := $(hostprogs-y) +HOSTCFLAGS_printinitialenv.o += \ + $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \ + -DUSE_HOSTCC + # Let clean descend into subdirs subdir- += basic kconfig dtc diff --git a/scripts/printinitialenv.c b/scripts/printinitialenv.c new file mode 100644 index 00000000000..c58b234d679 --- /dev/null +++ b/scripts/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