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 79671EB64D7 for ; Tue, 20 Jun 2023 08:24:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B372D86330; Tue, 20 Jun 2023 10:23:47 +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="Gs3aJQ4Y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E663286330; Tue, 20 Jun 2023 10:23:31 +0200 (CEST) Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (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 9B3F486341 for ; Tue, 20 Jun 2023 10:23:28 +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-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-51a20c744ebso5152085a12.1 for ; Tue, 20 Jun 2023 01:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687249408; x=1689841408; 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=3cwzUsNKv2xXIB5bvzmVg007j5k/cm0/SWQrOTwTQkk=; b=Gs3aJQ4YeGm03DDMNQb9kUVEl6lg+pCExJcIU60I0aPREuZurBxZremZUND41We++1 T2t8spYd6X99ib+koAupsNZabYradJO35bDO0a0T7SierKOAIUaYBuw77BeNMo6bPtA5 d9F3BRfK3q4vUJ6ZMEvf1YSmfxLN1HakeRQNs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687249408; x=1689841408; 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=3cwzUsNKv2xXIB5bvzmVg007j5k/cm0/SWQrOTwTQkk=; b=GdOO1OU12SQV+1xV6cE7rF09cLdEZnDHaQFjiq43EPZj74WC+0qx/h44u2ISPpH4Lw hWKA6vGyTU+PdEQbGneSGmIx6sLrs5LjqYRO+lbWnqdDRq6htsvEDAg8pU7UH2LYOCkE q9jncwG6a7BtiZSyqfUVZikuiO/tA+oyHPuSj9Dk63pRflhbImL6yvbAdSMxGMJMXEDg 6XQ57EnzzLNsJthCPf4cdkDDtMCgC42yn0ViJ/ZbkePUvKmmEaoda8Q3Seodxf1tjl7o 9uprj5CTrtZtyl/rP7jT4kpAuFxpCzRlg5RITAX25mOezip5pSaLld8OgIHGY227xE+D aRgQ== X-Gm-Message-State: AC+VfDzCgDYJW7zZqm3aFXC2uTmluVo2UM0UPrdMB23JJwejqhEWZ57n 3Q8N/NafUU/ocEiX3iYl7836+tFZVZzon0ujHQo= X-Google-Smtp-Source: ACHHUZ7lCgLewfOhiCPQnpsa/qsr1DXrebkpQnhnbZEZEyeXE60ZtZzdY7rTqv6xSDX4I3oEcTrLmw== X-Received: by 2002:aa7:ce19:0:b0:51a:598d:552a with SMTP id d25-20020aa7ce19000000b0051a598d552amr3895241edv.36.1687249407980; Tue, 20 Jun 2023 01:23:27 -0700 (PDT) Received: from sjg1.roam.corp.google.com (79-67-123-132.dynamic.dsl.as9105.com. [79.67.123.132]) by smtp.gmail.com with ESMTPSA id y19-20020aa7c253000000b005148e981bd3sm768360edo.12.2023.06.20.01.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 01:23:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH v2 07/19] bootstd: Use the bootargs env var for changing the cmdline Date: Tue, 20 Jun 2023 09:22:38 +0100 Message-ID: <20230620082257.1678140-7-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230620082257.1678140-1-sjg@chromium.org> References: <20230620082257.1678140-1-sjg@chromium.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean The "bootargs" environment variable is used to set the command-line arguments to pass to the OS. Use this same mechanism with bootstd as well. When the variable is updated, it is written to the current bootflow. When the current bootflow is updated, the environment variable is updated too. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootflow.c | 59 ++++++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 6 +++++ include/env_callback.h | 6 +++-- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index 487552fa28c0..62b7f45ab278 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -552,3 +553,61 @@ int bootflow_iter_check_system(const struct bootflow_iter *iter) return -ENOTSUPP; } + +/** + * bootflow_cmdline_set() - Set the command line for a bootflow + * + * @value: New command-line string + * Returns 0 if OK, -ENOENT if no current bootflow, -ENOMEM if out of memory + */ +int bootflow_cmdline_set(struct bootflow *bflow, const char *value) +{ + char *cmdline = NULL; + + if (value) { + cmdline = strdup(value); + if (!cmdline) + return -ENOMEM; + } + + free(bflow->cmdline); + bflow->cmdline = cmdline; + + return 0; +} + +#ifdef CONFIG_BOOTSTD_FULL +/** + * on_bootargs() - Update the cmdline of a bootflow + */ +static int on_bootargs(const char *name, const char *value, enum env_op op, + int flags) +{ + struct bootstd_priv *std; + struct bootflow *bflow; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return 0; + bflow = std->cur_bootflow; + if (!bflow) + return 0; + + switch (op) { + case env_op_create: + case env_op_overwrite: + ret = bootflow_cmdline_set(bflow, value); + if (ret && ret != ENOENT) + return 1; + return 0; + case env_op_delete: + bootflow_cmdline_set(bflow, NULL); + fallthrough; + default: + return 0; + } +} +U_BOOT_ENV_CALLBACK(bootargs, on_bootargs); +#endif + diff --git a/cmd/bootflow.c b/cmd/bootflow.c index ddb168c70390..f33db7be5f2e 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -288,6 +288,12 @@ static int do_bootflow_select(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } std->cur_bootflow = found; + if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) { + if (env_set("bootargs", found->cmdline)) { + printf("Cannot set bootargs\n"); + return CMD_RET_FAILURE; + } + } return 0; } diff --git a/include/env_callback.h b/include/env_callback.h index a9a14f2a84a5..23bc650c162d 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -60,8 +60,10 @@ #define NET6_CALLBACKS #endif -#ifdef CONFIG_BOOTSTD -#define BOOTSTD_CALLBACK "bootmeths:bootmeths," +#ifdef CONFIG_BOOTSTD_FULL +#define BOOTSTD_CALLBACK \ + "bootmeths:bootmeths," \ + "bootargs:bootargs," #else #define BOOTSTD_CALLBACK #endif -- 2.41.0.162.gfafddb0af9-goog