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 A5E81EB64D9 for ; Wed, 12 Jul 2023 15:06:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 01DF586B27; Wed, 12 Jul 2023 17:05:16 +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="JyTKdKQK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EC06886B27; Wed, 12 Jul 2023 17:05:10 +0200 (CEST) Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) (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 1F0A386ADB for ; Wed, 12 Jul 2023 17:05:08 +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-il1-x12c.google.com with SMTP id e9e14a558f8ab-345a8a78bcfso26689605ab.2 for ; Wed, 12 Jul 2023 08:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689174306; x=1691766306; 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=7ILkXB6jW9Hyah0Yw5jnEPl5pBAIB6p6/JeOt2YS+Oo=; b=JyTKdKQK0RphYO/edzPDF9NX4DqYS3luWsrKgc7to5SoW9R5swQNWxytvZYKfliCJK YtUGd62d+auyUk3fkZJiF2RwPz7dqmGj9ieZIq+VehmJsJGg9CFR9yG7oFFYOY0ZyAIn +JqOzn2nIdpC2KSvplEZizs6z4jZ7sBqJHh8c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689174306; x=1691766306; 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=7ILkXB6jW9Hyah0Yw5jnEPl5pBAIB6p6/JeOt2YS+Oo=; b=LPyMxstxd527HhRKKSotD1dfXl9EivVnUz4U7Av3XtYH8gmeRnpJdjrzdJlNSDFbu2 nWmnma4lHjNhfjSY0RivfHhxfSlFgVzs06fuysGZPmRCUJR0kqV3D71h7eR925nZiuoS Q8V2cqkmSq3SBhx2Qejvd+m62skxcWaKDjsUk3PWEJhz6rTyK0GpQ6axezh7wsh34+yU HLPA01IjaQdySHxxMFblyFK3vy2Uhz18AvI6US2Q7g+E4mm9h6tLRj1D0jQheel8xdfq moB9Ro6s7275nJuRZ/gSHFD9B25dqwybJFQpuUv4vcB0g1h62fg5Z9D/Kk8EdZfm/VHv nWhA== X-Gm-Message-State: ABy/qLZMu1GYuZhuDz6wODu0G3KP+zKSr879q3I93hVnkYtlNS1mHBel psN3pwMIRkUq3rwPnHOR+jd0z044b4aJeJwxA4k= X-Google-Smtp-Source: APBJJlH24kcUmUUcSkAsfjLbjzzsZ0u08+u7rrTUqtSV5eJtmy+C8fLDMHRQePGJTzwk5UhI8s3Y6Q== X-Received: by 2002:a05:6e02:8a2:b0:346:63f1:a979 with SMTP id a2-20020a056e0208a200b0034663f1a979mr7543931ilt.30.1689174306564; Wed, 12 Jul 2023 08:05:06 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id h16-20020a0566380f1000b0042b08954dc3sm1202958jas.33.2023.07.12.08.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 08:05:06 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Bin Meng , Simon Glass Subject: [PATCH v3 06/18] bootstd: Use the bootargs env var for changing the cmdline Date: Wed, 12 Jul 2023 09:04:35 -0600 Message-ID: <20230712150453.2407923-7-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog In-Reply-To: <20230712150453.2407923-1-sjg@chromium.org> References: <20230712150453.2407923-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 Reviewed-by: Bin Meng --- (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.390.g38632f3daf-goog