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 X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE44EC433EF for ; Sun, 19 Sep 2021 19:00:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E627A61050 for ; Sun, 19 Sep 2021 19:00:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E627A61050 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EAA0B83230; Sun, 19 Sep 2021 21:00:42 +0200 (CEST) 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="cKLinD3t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FE4B82DA1; Sun, 19 Sep 2021 21:00:20 +0200 (CEST) Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (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 9B7158324A for ; Sun, 19 Sep 2021 21:00:02 +0200 (CEST) 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@chromium.org Received: by mail-oi1-x230.google.com with SMTP id w206so10108211oiw.4 for ; Sun, 19 Sep 2021 12:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JsE9tjgpCTE7JOd6skkc0UdWo+B9g/C+Q7Mra0bUjSc=; b=cKLinD3tJ/GZqj3g5l5Liw0/Ip5fenE38Iob91726ayQ550sCRovxmLhteoggYMaPy kt2aTJiPiJMcVYjkPMourYEYO8DXnZMuSLhn0Ql0G6jOrzjaLbdO0KA2P6+gS0SLZxOr rLtCiSSGNlSh4QyPJvLCJaNTXJwiwzHUMQyYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JsE9tjgpCTE7JOd6skkc0UdWo+B9g/C+Q7Mra0bUjSc=; b=a9p53Y5CRy6DM6pAU9lvbz6TCRJrk9bSmpGg9SdO6ab4sRUrmMgbG5BBGzDrEdP+3e qmLaXaGZHStY9a8DWGuCaZ/5JNidhTdI8dK7rHJpfFqy4VlAmHHHIft9pmkNE/neFXOA a9WhQ2tNMrl+iO5lZRCTZBZjEPlFlHrylDwsEEyuEnfNzMQFcG/bqi72NA2mdk5TltOq qSmUfm7I2IyNGegno5GCgFUVso8/dwJtMm3NNmTQxrtnG687LuY30UdMzZ9TIusDjmaJ XnfpOgq2lqHq5lKR5nHSPIk9ecLNkZ4ePOB6NUvFUc9vwQ8//RpvwSyi/iYzDomQDTve uqVg== X-Gm-Message-State: AOAM531et6v5/fN12EiM30U8CaljzVN4h3TR0fzKDD75iTT43Ye0+TCg D8/VK7A32vg/elInyEmnr1xuACrGrGKaAQ== X-Google-Smtp-Source: ABdhPJyPxNnoBv63r9/ozb0k6+N6o/JgwktAn5ZUVCQ7KpBmkJ03S3Bh2YaCwwR387Bk2zum9EM6wQ== X-Received: by 2002:a05:6808:1141:: with SMTP id u1mr16440397oiu.79.1632078001019; Sun, 19 Sep 2021 12:00:01 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id bj27sm2634540oib.58.2021.09.19.12.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 12:00:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Bin Meng , Joe Hershberger , =?UTF-8?q?Marek=20Beh=C3=BAn?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH v4 4/5] env: Allow environment files to use the C preprocessor Date: Sun, 19 Sep 2021 12:59:49 -0600 Message-Id: <20210919125937.v4.4.Ie78bfbfca0d01d9cba501e127f446ec48e1f7afe@changeid> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919185950.3813952-1-sjg@chromium.org> References: <20210919185950.3813952-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean In many cases environment variables need access to the U-Boot CONFIG variables to select different options. Enable this so that the environment scripts can be as useful as the ones currently in the board config files. Also support += to allow variables to be appended to. This is needed when using the preprocessor. Signed-off-by: Simon Glass --- Changes in v4: - Add documentation in rST format instead of README Changes in v3: - Define __UBOOT_CONFIG__ when collecting environment files Changes in v2: - Add separate patch to enable C preprocessor for environment files - Enable var+=value form to simplify composing variables in multiple steps Makefile | 7 ++++++- doc/usage/environment.rst | 8 ++++++++ scripts/env2string.awk | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9e44af2ccb1..6315de93506 100644 --- a/Makefile +++ b/Makefile @@ -1813,7 +1813,12 @@ ENV_FILE := $(if $(wildcard $(ENV_FILE_BOARD)),$(ENV_FILE_BOARD),$(ENV_FILE_COMM quiet_cmd_gen_envp = ENVP $@ cmd_gen_envp = \ if [ -f "$(ENV_FILE)" ]; then \ - cat $(ENV_FILE) >$@; \ + $(CPP) -P $(CFLAGS) -x assembler-with-cpp -D__ASSEMBLY__ \ + -D__UBOOT_CONFIG__ \ + -I . -I include \ + -I $(srctree)/include -include include/config.h \ + -I$(srctree)/arch/$(ARCH)/include \ + $(ENV_FILE) -o $@; \ else \ echo -n >$@ ; \ fi diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst index 81130d17f85..5df55cdfa8f 100644 --- a/doc/usage/environment.rst +++ b/doc/usage/environment.rst @@ -31,6 +31,14 @@ and has an equals sign immediately afterwards. Spaces before the = are not permitted. It is a good idea to indent your scripts so that only the 'var=' appears at the start of a line. +To add additional text to a variable you can use var+=value. This text is +merged into the variable during the make process and made available as a +single value to U-Boot. + +This file can include C-style comments. Blank lines and multi-line +variables are supported, and you can use normal C preprocessor directives +and CONFIG defines from your board config also. + For example, for snapper9260 you would create a text file called `board/bluewater/env/snapper9260.env` containing the environment text. diff --git a/scripts/env2string.awk b/scripts/env2string.awk index f442d3b7c44..9851925d877 100644 --- a/scripts/env2string.awk +++ b/scripts/env2string.awk @@ -29,6 +29,12 @@ NF { } var = arr[1] env = arr[2] + + # Deal with += + if (match(var, "(.*)[+]$", var_arr)) { + var = var_arr[1] + env = vars[var] env + } } else { # Change newline to \n env = env "\\n" $0; -- 2.33.0.464.g1972c5931b-goog