From patchwork Wed Apr 21 09:06:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1468645 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=clD0N9Kt; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQF7c4GN9z9t5G for ; Wed, 21 Apr 2021 19:07:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C996982B4E; Wed, 21 Apr 2021 11:07:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk 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=prevas.dk header.i=@prevas.dk header.b="clD0N9Kt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F2BB982B3A; Wed, 21 Apr 2021 11:07:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0720.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::720]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E993882B47 for ; Wed, 21 Apr 2021 11:07:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqZVccBgFVNl+VuhzsuQ8XX6W3ysSXp7Uy73k1LxYh7Iamz2bPIf73DZdXViL1EzPFE00MpHE4LaXArUlkBYiHlUmLsKzu4PTdpNsKjV9Gy7HMUufQA18UkYwaw1xXmq6iyOwLfhQGqTiNk8ugfoEKgivMKT/pMh4NgQ2UPyoxnk+ECH+iULXKCd1a3hXI/kp0qa2L4WfGN72l5U3zdXsZrmF0Rg4UVCeH+TJ4QKtE9P/+HGBcMxg6pJo7Y1/RTWBQW+/ozRgEYhmIS91Ne5BOWXPr3svLAUb0TLfYudKB+d0EwncLNRkNp/1KJxCjgRvXZugpDugnjsYToo2XJoVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0UeggTjW0wrkRHLeCJhm6SG8QL/udANuTWK/+C7Lou8=; b=n+0om6t1zg6YCmnekDfkS2RR6z7+J7Zh/oTrjslYrrVl9R0zXpyAxMD0Cx3wZyW92svXGgkzv3rN9RWR0U9sp2R4a8K99Sxv+w+v/1ov2KKk3X7UqIuEKHL+f2RdUqWzUOliMsTYtgBipnu1HYlKXqLLT4vsPjytm6OYwfEyJXdCongzGLf5a3xx50KMEn9TiWw0kYWB2l0IrDCF0VtlZUe0byMGwxzr8yA5O6RahnHsIEUCBHDs7HXS/tg6jgQyK/Z9Y5bMKoDzM+bk+gFBKaRxOouydI0qSqvDnHwa2OrFmGixBViiXEy4W6SyXk4kSW6Iq++4XOcwX5gR+5pMdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0UeggTjW0wrkRHLeCJhm6SG8QL/udANuTWK/+C7Lou8=; b=clD0N9KtY8HKR3h0v1r3SCM8+53spdLMevpSpBgKqbtUObBxJaBK2sfIAq6b7OUlwk9q1ZUgEMYmk3x7q7i13cPzl2WKGqwtORsUjYnV4RDvmEsFZZ/O5l2tgMH3y3u9yz7hOqdZdORudEGlJJzRPxxl03rXQhoUhKIYhA8SwSE= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM9PR10MB4562.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:26c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20; Wed, 21 Apr 2021 09:07:04 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::888d:190b:b3b5:1ad2]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::888d:190b:b3b5:1ad2%3]) with mapi id 15.20.4065.021; Wed, 21 Apr 2021 09:07:04 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Wolfgang Denk , Simon Glass , Tom Rini , Joe Hershberger , Patrick Delaunay , Rasmus Villemoes Subject: [PATCH v2 1/2] env: allow environment to be amended from control dtb Date: Wed, 21 Apr 2021 11:06:54 +0200 Message-Id: <20210421090655.1458746-2-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210421090655.1458746-1-rasmus.villemoes@prevas.dk> References: <20210413224345.2692591-1-rasmus.villemoes@prevas.dk> <20210421090655.1458746-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [80.208.71.248] X-ClientProxiedBy: AM0PR03CA0028.eurprd03.prod.outlook.com (2603:10a6:208:14::41) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (80.208.71.248) by AM0PR03CA0028.eurprd03.prod.outlook.com (2603:10a6:208:14::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Wed, 21 Apr 2021 09:07:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e21d0f0b-e2f2-43dc-0dbc-08d904a4d4a0 X-MS-TrafficTypeDiagnostic: AM9PR10MB4562: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bt3D9X1G3heE8jFSESswnKHh7SpORl24RzPK8nal4F/DsN3kv2uQyKPnacwdn4MTSmGL+UtojR3+XISl3njcGcy/dmnCx3GbktA/f6FcxltjXwfyQlfZljOi7XC0Nd0FbZ7UJQPg5omTCnPR8ELiDVJBYpstTSxcHAOq4hy1EAqQ1fKOhiFIV0ozUT1rpjJDy4lWot4nGISenOWrzA35pXl9htx+rOjAyVp0xp2fOsdePBGVu9M+jyQonEB78lYV4Tsufg9u+mWuw+mDqh5tlb6nJy462pOBoB++o9EK/XrhVMQ86XEZt6q6D6yx7QRwtdLU5na2bnnklP3GEOd+iumsMwNUJeE+UbqRn1pynGc/iMS8fTnRYae+jg55ttRisY0myEQb0RFaM5VSHQMXZtezI7sg7wqjZcnw6sP+0jRbiqfkDa9AOmhQ/lSh1gfwOX6nK8V2GAgajdo4ZnuvOwAsSvzigk30X7yWg5DsRbRwhxjjxmlQStG9/fso8CXS087aLAmJE28JKoBGofGRE4XCpHGUb2qZbYtb9lG9ez0en7dibBD3Bf9cTFovhDbag1XeiDjqEXpUUgNtRkR1CQ4FgL1xOIEtuICzoi7Wc0IVe14TSIDHBMPcGOUAz7sa1DifnjO5TWlqeqlVCYYHtlR5jrG501JMxwwaJcAToHM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(376002)(39850400004)(136003)(346002)(396003)(366004)(52116002)(6486002)(8976002)(2906002)(5660300002)(6506007)(16526019)(66476007)(66946007)(36756003)(107886003)(86362001)(8676002)(478600001)(38350700002)(6512007)(6916009)(38100700002)(26005)(8936002)(186003)(316002)(54906003)(83380400001)(1076003)(44832011)(2616005)(956004)(6666004)(66556008)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: VLXuEU6j+/M2DcGcSZLMnd1fAeXgN+Tvz3RgM4OMX1BnAGr2Q2WMZ5IVxdpBbQkhcGfrVbw3xB6rdN9RtOFeZWsmvWcyejJb1Lg+QV+3Ja2lwrNLLJQHYbkt7QOOk67Et4oS0RajmD/o1oSYARBO6Eg2g2LIwDqQt8CqcQD/qDQ7c9nZeDnfTxg5hT8MoD7QBhRg+yiizU5DpVSgArpKD695JVdVzhToEB0U39LW/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WYMNS5otI6i/nAvDNkopVsWkcv/fM X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: e21d0f0b-e2f2-43dc-0dbc-08d904a4d4a0 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 09:07:03.9831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: L6LwvNmwaDPUjmM4Nck/5vZjmdReg9U7ds8YffIyfKUf3p88sVOAzKQLlB431R5d9o3W4R3YcZp6gMTjqrrxBFfd2KagRhfOHP9YSC6Mbto= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR10MB4562 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.102.4 at phobos.denx.de X-Virus-Status: Clean It can be useful to use the same U-Boot binary for multiple purposes, say the normal one, one for developers that allow breaking into the U-Boot shell, and one for use during bootstrapping which runs a special-purpose bootcmd. Or one can have several board variants that can share almost all boot logic, but just needs a few tweaks in the variables used by the boot script. To that end, allow the control dtb to contain a /config/enviroment node (or whatever one puts in fdt_env_path variable), whose property/value pairs are used to update the run-time environment after it has been loaded from its persistent location. The indirection via fdt_env_path is for maximum flexibility - for example, should the user wish (or board logic dictate) that the values in the DTB should no longer be applied, one simply needs to delete the fdt_env_path variable; that can even be done automatically by including a fdt_env_path = ""; property in the DTB node. Reviewed-by: Simon Glass Signed-off-by: Rasmus Villemoes Acked-by: Joe Hershberger --- common/board_r.c | 2 ++ env/Kconfig | 18 ++++++++++++++++++ env/common.c | 30 ++++++++++++++++++++++++++++++ include/env.h | 15 +++++++++++++++ include/env_default.h | 3 +++ 5 files changed, 68 insertions(+) diff --git a/common/board_r.c b/common/board_r.c index c835ff8e26..3f82404772 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -459,6 +459,8 @@ static int initr_env(void) else env_set_default(NULL, 0); + env_import_fdt(); + if (IS_ENABLED(CONFIG_OF_CONTROL)) env_set_hex("fdtcontroladdr", (unsigned long)map_to_sysmem(gd->fdt_blob)); diff --git a/env/Kconfig b/env/Kconfig index 08e49c2a47..78c534344f 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -669,6 +669,24 @@ config DELAY_ENVIRONMENT later by U-Boot code. With CONFIG_OF_CONTROL this is instead controlled by the value of /config/load-environment. +config ENV_IMPORT_FDT + bool "Amend environment by FDT properties" + depends on OF_CONTROL + help + If selected, after the environment has been loaded from its + persistent location, the "env_fdt_path" variable is looked + up and used as a path to a node in the control DTB. The + property/value pairs in that node is then used to update the + run-time environment. This can be useful to use the same + U-Boot binary with different board variants. + +config ENV_FDT_PATH + string "Default value for env_fdt_path variable" + depends on ENV_IMPORT_FDT + default "/config/environment" + help + The initial value of the env_fdt_path variable. + config ENV_APPEND bool "Always append the environment with new data" default n diff --git a/env/common.c b/env/common.c index 49bbb05eec..81e9e0b2aa 100644 --- a/env/common.c +++ b/env/common.c @@ -20,6 +20,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -334,3 +335,32 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf, return found; } #endif + +#ifdef CONFIG_ENV_IMPORT_FDT +void env_import_fdt(void) +{ + const char *path; + struct ofprop prop; + ofnode node; + int res; + + path = env_get("env_fdt_path"); + if (!path || !path[0]) + return; + + node = ofnode_path(path); + if (!ofnode_valid(node)) { + printf("Warning: device tree node '%s' not found\n", path); + return; + } + + for (res = ofnode_get_first_property(node, &prop); + !res; + res = ofnode_get_next_property(&prop)) { + const char *name, *val; + + val = ofnode_get_property_by_prop(&prop, &name, NULL); + env_set(name, val); + } +} +#endif diff --git a/include/env.h b/include/env.h index b5731e4b9a..d5e2bcb530 100644 --- a/include/env.h +++ b/include/env.h @@ -375,4 +375,19 @@ int env_get_char(int index); * This is used for those unfortunate archs with crappy toolchains */ void env_reloc(void); + + +/** + * env_import_fdt() - Import environment values from device tree blob + * + * This uses the value of the environment variable "env_fdt_path" as a + * path to an fdt node, whose property/value pairs are added to the + * environment. + */ +#ifdef CONFIG_ENV_IMPORT_FDT +void env_import_fdt(void); +#else +static inline void env_import_fdt(void) {} +#endif + #endif diff --git a/include/env_default.h b/include/env_default.h index ea31a8eddf..1ddd64ba8f 100644 --- a/include/env_default.h +++ b/include/env_default.h @@ -103,6 +103,9 @@ const uchar default_environment[] = { #ifdef CONFIG_SYS_SOC "soc=" CONFIG_SYS_SOC "\0" #endif +#ifdef CONFIG_ENV_IMPORT_FDT + "env_fdt_path=" CONFIG_ENV_FDT_PATH "\0" +#endif #endif #if defined(CONFIG_BOOTCOUNT_BOOTLIMIT) && (CONFIG_BOOTCOUNT_BOOTLIMIT > 0) "bootlimit=" __stringify(CONFIG_BOOTCOUNT_BOOTLIMIT)"\0"