From patchwork Tue Nov 10 20:26:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1397797 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; dmarc=pass (p=reject dis=none) header.from=prevas.dk 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=Mj8ozgQ7; 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 4CVztH32L9z9sRR for ; Wed, 11 Nov 2020 07:27:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BEDC82522; Tue, 10 Nov 2020 21:26:27 +0100 (CET) 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="Mj8ozgQ7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 587FC82385; Tue, 10 Nov 2020 21:26:21 +0100 (CET) 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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0726.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe02::726]) (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 765528234E for ; Tue, 10 Nov 2020 21:26:15 +0100 (CET) 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=Et4CZGYYdglENW/qlsxpP1WDGKkq0rlI9gftYjkWNcj0p0LGLlt+znAOVqQBL+r8BKZsfpfvebAS4chMoOLY69pj9iFibzjNc0vU+Zbr8MS5ks0y4FfpUKDIaI33RirwLmhtET7W0kI8JlwsZ280MZnGW5sW8F/a/eGxlA33pKl4i8yMKjx/r5wnAoGk5a+A+XpxI/c2leFWRToCz+FVextiSPSeww/sU86vidApbdyQkJ39s2jsFnufNXw6ehEB30AUXHaFvRWdrdXz66O9mLU4I9T/Cixe/8N53KdwEXnB3extUTY+Rhl3LUrP/Ma6hyK4lm4LREuSYtUZUDEDTQ== 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=7U96L6mnfOyk0KG6MdihElswiGvGM2enKfRqv7iWN+o=; b=Udnk+gKMTCD0Wah0vMGwRNAohWOvV3pNAL7PR2JH/hpiyRiof/kpxOFM6OImqxfni4/5Qnquk3OjECPvtFJeTGlDPQU4PBrsZesT3yf0Au0UvcOcQG8gLsb5HQpYDXCy58kJwZxTJXzYV/QjC+8PajOUBut19Xj9CQgtKiBM5lPhEfxuslqGEUr6mEOMiP1q4YsqNevnrwRSiyppZ7Y4QDiqqtrLw1ZO54wPQ/BmEErfDcRjK4dVtVWUSKtT/UXyXg25PI3dxLmqe7PLc6QyVR2gNVY39VYOQLHaTt8NYp6suR0ZQH9qAK/Qr+dqxc0nRf891HgybFeOJ6jvC5Ntzg== 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=7U96L6mnfOyk0KG6MdihElswiGvGM2enKfRqv7iWN+o=; b=Mj8ozgQ77l1TpjU7043y7VxcBqR+ODaj+WqjZJe8N0euPPreg+3S5+uaz9ZfAYqOQzgRMGkCU4IyhVy8UEjjuedwFBKDAASuEpKj4Td6VzFrdEuHz2Q8G13AnckJCbbhv8Q0YkVKrtvZCRReKa9B9dUlN1yetP3cHTYpdaSXpCk= 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 AM0PR10MB3299.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:188::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.30; Tue, 10 Nov 2020 20:26:13 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::9dc3:9785:dc4e:ad62]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::9dc3:9785:dc4e:ad62%6]) with mapi id 15.20.3499.032; Tue, 10 Nov 2020 20:26:13 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Joe Hershberger , Wolfgang Denk , Patrick Delaunay , Tom Rini , Rasmus Villemoes Subject: [PATCH 4/5] env: allow default environment to be amended from control dtb Date: Tue, 10 Nov 2020 21:26:02 +0100 Message-Id: <20201110202603.20944-5-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201110202603.20944-1-rasmus.villemoes@prevas.dk> References: <20201110202603.20944-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [5.186.115.188] X-ClientProxiedBy: AM6PR0202CA0067.eurprd02.prod.outlook.com (2603:10a6:20b:3a::44) 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 (5.186.115.188) by AM6PR0202CA0067.eurprd02.prod.outlook.com (2603:10a6:20b:3a::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21 via Frontend Transport; Tue, 10 Nov 2020 20:26:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cbb16e15-f0f9-4e04-6be6-08d885b6de67 X-MS-TrafficTypeDiagnostic: AM0PR10MB3299: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:267; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J7WZpPA6l6p4XfAZYIB6c0xalQ9+j1jbQn/+57+8QVtiC9oHsvN5/JPmDU4c9zUeKIiMe4e0viO0yHQZez2bIiH+MaRWP4YtqArAjCgeCIV95znIQiaBpnByhqdHoTRaZCeUKNJdOkGS+tXamxYpkte8q/mwQRCIXGFSjlIzR6aa7yVZ+SjE4xR9VXnDhvrUfklWbjB1IEStH21EJyCBe5ZXwcu7ajt6G7mJRD5h1YcqkNTyYFR5i9oFW436VwadTK53QvxdPILwY3q06ru3WSLkq+75nfcgrKlSOhcMiR1x3GKVkKdp1IrvizcqztAe5mqpHZ/MeIAYTo0n+Y63/g== 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:(396003)(39830400003)(136003)(376002)(366004)(346002)(6486002)(5660300002)(52116002)(2906002)(316002)(107886003)(8936002)(6506007)(8676002)(66556008)(66476007)(66946007)(956004)(86362001)(8976002)(6916009)(44832011)(478600001)(16526019)(6512007)(186003)(54906003)(4326008)(1076003)(6666004)(36756003)(2616005)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: qp95sHnTDppU3mTJTmDxV/z4BzSbFI+VDppXisIDlNsWtAM5llzmW67DIaktrMhlTOc2SOgtL3VmIhsyBpOSYLGqmZMlsDuhpDIL9ZIDVPZPZf0iOi0LJ/zUlsxEw+H72PHAvY0O4PpgQ1rlosYu53iMzMAFPgp417aThfoMFinMlnPzrpQ7X14A5u3hxf48BxiobRzOFABPzXytgOlHOj2a+rk63LPjU6pMpCwCABsZBErw6U/ZC+u9j5iWhVYsd11gYbHyrdtUp7DuRda05EKEepXVLTtH5ujECjcGRwatYfo+z/ASolZC530YBRTZk7xonFVKcTivV4/XqX8qpSeNobPkYN4kHcYJcuvx6yjHQTos8+ApDdvwry6nnislPd5PHD9byOXXk851NOfbnjGLhn7XpL/V3Ux2pGsnK5i0oaaUnMcJhfJR9V8Eh0eWsDia0Ws+vs13KkKtO3gOsF/WmbAdODdliidec9paoSiiSEn4GWCyWvk2kSK08rvtiv/SweujKNfQ++AWYH0UGgzztNhX4Mjior3wi3F28dC4h83RhhlCA6tBHx8KLw07w6XDutfDiu490DA38c1SdkSt1AfzFxH4yKeC+mTnOq2kCxUM4b0yKKi4ySOrEdklXpEolHgXI8CNGaoQzYc01w== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: cbb16e15-f0f9-4e04-6be6-08d885b6de67 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2020 20:26:13.5836 (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: QMxy7omwNwP2ucoHJbN/Ir6xN0UnhwVYMXvJd6EpH4elFPgWjcSoMLnD+xmv/ixT77Zzu1pNPdRGulzDhCgxPJzpVABCj/X6Zf7tIg474EU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB3299 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.3 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. To that end, allow the control dtb to contain a /config/default-enviroment property, whose value will be used to amend the default environment baked into the U-Boot binary itself. Signed-off-by: Rasmus Villemoes --- cmd/nvedit.c | 37 +++++++++++++++++++++++++++++++++++++ env/Kconfig | 21 +++++++++++++++++++++ env/common.c | 19 +++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 7fce723800..eda8b3b9d2 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -703,6 +703,39 @@ char *from_env(const char *envvar) return ret; } +static int env_get_f_fdt(const char *name, char *buf, unsigned len) +{ + const char *env; + int plen, nlen, n; + + if (!IS_ENABLED(CONFIG_ENV_AMEND_DEFAULT_FROM_FDT)) + return 0; + + env = fdtdec_get_config_property(gd->fdt_blob, "default-environment", + &plen); + if (!env) + return 0; + + nlen = strlen(name); + while (plen > nlen) { + if (memcmp(name, env, nlen) == 0 && env[nlen] == '=') { + /* Found. Copy value. */ + n = strlcpy(buf, &env[nlen + 1], len); + if (n < len) + return n; + + printf("env_buf [%u bytes] too small for value of \"%s\"\n", + len, name); + return len; + } + /* Skip this key=val pair. */ + n = strlen(env) + 1; + plen -= n; + env += n; + } + return 0; +} + /* * Look up variable from environment for restricted C runtime env. */ @@ -710,6 +743,10 @@ int env_get_f(const char *name, char *buf, unsigned len) { int i, nxt, c; + i = env_get_f_fdt(name, buf, len); + if (i) + return i; + for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { int val, n; diff --git a/env/Kconfig b/env/Kconfig index 67ce93061b..66bbac42c7 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -646,6 +646,27 @@ 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_AMEND_DEFAULT_FROM_FDT + bool "Amend default environment by /config/default-environment property" + depends on OF_CONTROL + help + The default environment built into the U-Boot binary is a + static array defined from various CONFIG_ options, or via + CONFIG_DEFAULT_ENV_FILE. Selecting this option means that + whenever that default environment is used (either for + populating the initial environment, or for resetting + specific variables to their default value), the device tree + property /config/default-environment is also consulted, and + values found there have precedence over those in the static + array. That property should be a series of "key=value" + pairs, e.g. + + /config { + default-environment = "ipaddr=1.2.3.4", + "bootcmd=tftp $loadaddr foo.itb; bootm $loadaddr", + "bootdelay=5"; + } + config ENV_APPEND bool "Always append the environment with new data" default n diff --git a/env/common.c b/env/common.c index 7363da849b..8d0e45fde6 100644 --- a/env/common.c +++ b/env/common.c @@ -63,6 +63,22 @@ char *env_get_default(const char *name) return ret_val; } +static void env_amend_default_from_fdt(int flags, int nvars, char *const vars[]) +{ + const void *val; + int len; + + if (!IS_ENABLED(CONFIG_ENV_AMEND_DEFAULT_FROM_FDT)) + return; + + val = fdtdec_get_config_property(gd->fdt_blob, "default-environment", + &len); + if (!val) + return; + + himport_r(&env_htab, val, len, '\0', flags, 0, nvars, vars); +} + void env_set_default(const char *s, int flags) { if (sizeof(default_environment) > ENV_SIZE) { @@ -88,6 +104,8 @@ void env_set_default(const char *s, int flags) pr_err("## Error: Environment import failed: errno = %d\n", errno); + env_amend_default_from_fdt(flags | H_NOCLEAR, 0, NULL); + gd->flags |= GD_FLG_ENV_READY; gd->flags |= GD_FLG_ENV_DEFAULT; } @@ -104,6 +122,7 @@ void env_set_default_vars(int nvars, char * const vars[], int flags) himport_r(&env_htab, (const char *)default_environment, sizeof(default_environment), '\0', flags, 0, nvars, vars); + env_amend_default_from_fdt(flags, nvars, vars); } /*