From patchwork Sat Oct 26 05:01:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 286252 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B39382C00BB for ; Sat, 26 Oct 2013 16:03:13 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ADE634A25E; Sat, 26 Oct 2013 07:03:05 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yM7Q3Q2CrNrQ; Sat, 26 Oct 2013 07:03:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1B4F94A25F; Sat, 26 Oct 2013 07:02:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3484F4A20D for ; Sat, 26 Oct 2013 07:02:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ruep1FFw28Vc for ; Sat, 26 Oct 2013 07:02:42 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from mail-ie0-f201.google.com (mail-ie0-f201.google.com [209.85.223.201]) by theia.denx.de (Postfix) with ESMTPS id 7FC1A4A21A for ; Sat, 26 Oct 2013 07:02:28 +0200 (CEST) Received: by mail-ie0-f201.google.com with SMTP id u16so913569iet.2 for ; Fri, 25 Oct 2013 22:02:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X5sq2Q9FTllNRKY21eZVArRYsWQRdRUfsHzIuJH2g/M=; b=JK3Pk52N86hrj1iH520VTlm32BmakEwSuzlRf7HcczAT6oK8mx2KDnVrERZEHHr4wu ue10cy0MIi357zvyPygyJeN4IgzdNi7D8PlwujcyVQhsXpWa1NVRlP7cT+bcouI4K+nB taumfDs0LteOM+2WFM4KfqmVJjgMY7wKb20gUZmHw2YqQuuknb1obBZTkPKHDj5oYAMT 4GdqiuSCcdq6PNHOvv1jc9z7AHcUjn/yfSb5hyHycacRz6U5FPrVP7Thl41NI8Sz9wkv ZPh7Z0fxtxvt88QMdoC+yPTmMpy5Aps9qWuGnyI62DqvvM58w+COGesz+J/O0m4yBIS6 ng0w== X-Gm-Message-State: ALoCoQkBQFjkPfKfy4RFWJIRAMAL0DqPErKF0fSgSt7qaoo6RUvbPN/frBOUZhDsLve2tJaKeY+Gm706EEolH09KGVVleH5NM+uLePV75K40GLL0hvO8CZna4929D2NLjyFc1uz8mC1otG6Ym93oHa612+oLZXflMYflV30gY9a32DSBsbDdq/NLmroGSnvW6HW4rOByYGww X-Received: by 10.50.106.116 with SMTP id gt20mr774671igb.0.1382763747424; Fri, 25 Oct 2013 22:02:27 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id k47si575892yha.2.2013.10.25.22.02.27 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Oct 2013 22:02:27 -0700 (PDT) Received: from kaki.bld.corp.google.com (kaki.bld.corp.google.com [172.29.216.32]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 22B835A4191; Fri, 25 Oct 2013 22:02:27 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id D8DE42211B7; Fri, 25 Oct 2013 23:01:42 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Fri, 25 Oct 2013 23:01:33 -0600 Message-Id: <1382763695-2849-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.4.1 In-Reply-To: <1382763695-2849-2-git-send-email-sjg@chromium.org> References: <1382763695-2849-2-git-send-email-sjg@chromium.org> Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v3 3/5] Allow U-Boot scripts to be placed in a .env file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de At present U-Boot environment variables, and thus scripts, are defined by CONFIG_EXTRA_ENV_SETTINGS. It is painful to add large amounts of text to this file and dealing with quoting and newlines is harder than it should be. It would be better if we could just type the script into a text file and have it included by U-Boot. Add a feature that brings in a .env file associated with the board config, if present. To use it, create a file in a board//env directory called .env (or common.env if you want the same environment for all boards). The environment variables should be of the form "var=value". Values can extend to multiple lines. See the README under 'Environment Variables:' for more information and an example. Comments are not permitted in the environment with this commit. Signed-off-by: Simon Glass --- Changes in v3: - Add more detail in the README about the format of .env files - Adjust Makefile to generate the .inc and .h files in separate fules - Correctly terminate environment files with \n - Improve the comment about " in the awk script Changes in v2: - Add dependency rule so that the environment is rebuilt when it changes - Add information and updated example script to README - Move .env file from include/configs to board/ - Use awk script to process environment since it is much easier on the brain Makefile | 35 +++++++++++++++++++++++++++++++- README | 38 +++++++++++++++++++++++++++++++++++ common/env_embedded.c | 1 + config.mk | 2 ++ include/env_default.h | 2 ++ mkconfig | 7 +++++++ tools/scripts/env2string.awk | 48 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tools/scripts/env2string.awk diff --git a/Makefile b/Makefile index 2d18d27..a9b4b9e 100644 --- a/Makefile +++ b/Makefile @@ -708,7 +708,7 @@ $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h $(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS) \ -MQ $(obj)include/autoconf.mk include/common.h > $@ -$(obj)include/autoconf.mk: $(obj)include/config.h +$(obj)include/generated/autoconf.mk.base: $(obj)include/config.h @$(XECHO) Generating $@ ; \ set -e ; \ : Extract the config macros ; \ @@ -734,6 +734,39 @@ $(obj)include/spl-autoconf.mk: $(obj)include/config.h sed -n -f tools/scripts/define2mk.sed > $@.tmp && \ mv $@.tmp $@ +# We expect '.env' but failing that will use 'common.env' +ENV_HEADER := $(obj)include/generated/environment.h +ENV_DIR := $(if $(VENDOR),$(VENDOR)/env,$(BOARD)/env) +ENV_FILE_BOARD := $(src)board/${ENV_DIR}/$(BOARD).env +ENV_FILE_COMMON := $(src)board/${ENV_DIR}/common.env +ENV_FILE := $(if $(wildcard $(ENV_FILE_BOARD)),$(ENV_FILE_BOARD),$(ENV_FILE_COMMON)) + +# Regenerate the environment if it changes +$(obj)include/generated/environment.in: $(obj)include/generated/autoconf.mk.base \ + $(wildcard $(ENV_FILE)) + if [ -f "$(ENV_FILE)" ]; then \ + cat $(ENV_FILE) >$@ ; \ + else \ + echo -n >$@ ; \ + fi + +$(obj)include/generated/environment.inc: $(obj)include/generated/environment.in + @$(XECHO) Generating $@ ; \ + set -e ; \ + : Process the environment file ; \ + echo -n "CONFIG_EXTRA_ENV_TEXT=" >$@ ; \ + awk -f tools/scripts/env2string.awk $< >>$@ + +$(ENV_HEADER): $(obj)include/generated/environment.in + @$(XECHO) Generating $@ ; \ + set -e ; \ + : Process the environment file ; \ + echo -n "#define CONFIG_EXTRA_ENV_TEXT " >$@ ; \ + awk -f tools/scripts/env2string.awk $< >>$@ + +$(obj)include/autoconf.mk: $(obj)include/generated/environment.inc $(ENV_HEADER) + cat $(obj)include/generated/autoconf.mk.base $< >$@ + $(obj)include/generated/generic-asm-offsets.h: $(obj)include/autoconf.mk.dep \ $(obj)include/spl-autoconf.mk \ $(obj)include/tpl-autoconf.mk \ diff --git a/README b/README index f0eedbb..3146a2d 100644 --- a/README +++ b/README @@ -4556,6 +4556,44 @@ environment. As long as you don't save the environment you are working with an in-memory copy. In case the Flash area containing the environment is erased by accident, a default environment is provided. +The default environment is created in include/env_default.h, and can be +augmented by various CONFIG defines. See that file for details. In +particular you can define CONFIG_EXTRA_ENV_SETTINGS in your board file +to add environment variables (see 'CONFIG_EXTRA_ENV_SETTINGS' above +for details). + +It is also possible to create an environment file with the name +board//env/.env for your board. If that file is not present +then U-Boot will look for board//env/common.env so that you can +have a common environment for all vendor boards. + +This is a plain text file where you can type your environment variables in +the form 'var=value'. Blank lines and multi-line variables are supported. +The conversion script looks for a line that starts with a letter or number +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. + +For example, for snapper9260 you would create a text file called +board/bluewater/env/snapper9260.env containing the environment text. + +>>> +bootcmd= + if [ -z ${tftpserverip} ]; then + echo "Use 'setenv tftpserverip a.b.c.d' to set IP address." + fi + + usb start; setenv autoload n; bootp; + tftpboot ${tftpserverip}: + bootm +failed= + echo boot failed - please check your image +<<< + +The resulting environment can be exported and importing using the +'env export/import -t' commands. + + Some configuration options can be set using Environment Variables. List of environment variables (most likely not complete): diff --git a/common/env_embedded.c b/common/env_embedded.c index 1c4f915..1d7fe2a 100644 --- a/common/env_embedded.c +++ b/common/env_embedded.c @@ -74,6 +74,7 @@ #endif #define DEFAULT_ENV_INSTANCE_EMBEDDED +#include #include #ifdef CONFIG_ENV_ADDR_REDUND diff --git a/config.mk b/config.mk index 91a8f24..a9f3317 100644 --- a/config.mk +++ b/config.mk @@ -190,8 +190,10 @@ sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules endif ifdef VENDOR BOARDDIR = $(VENDOR)/$(BOARD) +ENVDIR=${vendor}/env else BOARDDIR = $(BOARD) +ENVDIR=${board}/env endif ifdef BOARD sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules diff --git a/include/env_default.h b/include/env_default.h index 90431be..b88b1e4 100644 --- a/include/env_default.h +++ b/include/env_default.h @@ -121,6 +121,8 @@ const uchar default_environment[] = { #ifdef CONFIG_EXTRA_ENV_SETTINGS CONFIG_EXTRA_ENV_SETTINGS #endif + /* This is created in the Makefile */ + CONFIG_EXTRA_ENV_TEXT "\0" #ifdef DEFAULT_ENV_INSTANCE_EMBEDDED } diff --git a/mkconfig b/mkconfig index 1d06c8e..8240431 100755 --- a/mkconfig +++ b/mkconfig @@ -144,8 +144,10 @@ fi # Assign board directory to BOARDIR variable if [ -z "${vendor}" ] ; then BOARDDIR=${board} + ENVDIR=${board}/env else BOARDDIR=${vendor}/${board} + ENVDIR=${vendor}/env fi # @@ -174,10 +176,15 @@ echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h cat << EOF >> config.h #define CONFIG_BOARDDIR board/$BOARDDIR +#define CONFIG_ENVDIR board/$ENVDIR #include #include #include #include +#if !defined(DO_DEPS_ONLY) && !defined(D__UBOOT_CONFIG__) && \ + !defined(__ASSEMBLY__) +#include +#endif #include #include EOF diff --git a/tools/scripts/env2string.awk b/tools/scripts/env2string.awk new file mode 100644 index 0000000..2a86494 --- /dev/null +++ b/tools/scripts/env2string.awk @@ -0,0 +1,48 @@ +# +# (C) Copyright 2013 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Sed script to parse a text file containing an environment and convert it +# to a C string which can be compiled into U-Boot. +# + +# We output a double quote before starting, and again when we finish so that +# all output is quoted. +BEGIN { + # env holds the env variable we are currently processing + env = ""; + ORS = "" + print "\"" +} + +{ + # Quote quotes + gsub("\"", "\\\"") + + # Is this the start of a new environment variable? + if (match($0, "^([^ =][^ =]*)=(.*)", arr)) { + if (length(env) != 0) { + # Record the value of the variable now completed + vars[var] = env + } + var = arr[1] + env = arr[2] + } else { + # Change newline to \n + env = env "\\n" $0; + } +} + +END { + # Record the value of the variable now completed + if (length(env) != 0) { + vars[var] = env + } + + # Print out all the variables + for (var in vars) { + print var "=" vars[var] "\\0"; + } + print "\"\n" +}