From patchwork Fri Apr 28 19:18:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1775138 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=YaVr2+hH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7N0Q50hXz23tl for ; Sat, 29 Apr 2023 05:27:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DBBCB85E03; Fri, 28 Apr 2023 21:26:45 +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="YaVr2+hH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 850C885EE7; Fri, 28 Apr 2023 21:26:41 +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=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 E026485D94 for ; Fri, 28 Apr 2023 21:18:39 +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-x132.google.com with SMTP id e9e14a558f8ab-32f397b44dcso20672495ab.1 for ; Fri, 28 Apr 2023 12:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682709518; x=1685301518; 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=UqtAZ61ymNRtPnUnElL7AJll6LciW3C0tz6jbL1RUBk=; b=YaVr2+hHZppwloCd2l3ukyeXHF9cabeSRZXaVNGZYRQJGoc/L6QDJPXcuXpg8eBWjY x8XSgBZDNGZFNZXXyQ9olJ0gswkgf2QM44F1h0voae1s/SVwM1DD7nOY6fwM6bBsbbsN A+Hhte6n8xF1ubidHWwRoY3Kddp6mBak/QnM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682709518; x=1685301518; 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=UqtAZ61ymNRtPnUnElL7AJll6LciW3C0tz6jbL1RUBk=; b=jlbHbPZ2gZeaU8cb7oZEwkmoqkQIIpP4OMsuytAb79asSUgtsOnOe2G141G/uyvyjh suc06mVzmS3+SfQUStQJJ8GoS1SOHAuwV5TQ9xEsK6G9vo7ZXkXnSAbK+uBBZLySqwLY U0zCZ2bN2INda2+MCMJBo+9DCn+eKaSscK/AEAWptDDBOzqfuxjTVH0Qy14FLHIy1LmG SDeCp8CEiUiCifthShjBLQ1NcrsC/ftuYJPBOtmj8On5MWSK0JDnQ71v4wcIDi0Pm6/l Nolx76l3Gd5rzw07zCjaCtpGOQQkpU5R4x668Tt7JzqbOpttg77U+NOgU3FZXT9/0gxM kxug== X-Gm-Message-State: AC+VfDyHWvZ2lx41ZWyyr4W/TQtIoFRuseZ3pTvWveYn0fNQ64KO67Jf L3NaSnwos+w4MZQ6QRGOZcEa6CePzMDSZCeKrbM= X-Google-Smtp-Source: ACHHUZ7uu4sP8U4fBRKO0Cru9sw/iXFhIMbtY5nAYI8lPLnZVAHoIIbLOP9AHA911G/kY6LewN08qw== X-Received: by 2002:a05:6e02:c6a:b0:32f:828f:54a7 with SMTP id f10-20020a056e020c6a00b0032f828f54a7mr260292ilj.12.1682709518499; Fri, 28 Apr 2023 12:18:38 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:9261:21dc:edb:e426]) by smtp.gmail.com with ESMTPSA id l12-20020a0566380d8c00b0041407c67451sm1698811jaj.165.2023.04.28.12.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 12:18:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Joe Hershberger , Wolfgang Denk Subject: [PATCH 07/18] bootstd: Use the bootargs env var for changing the cmdline Date: Fri, 28 Apr 2023 13:18:07 -0600 Message-ID: <20230428191819.3070393-7-sjg@chromium.org> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog In-Reply-To: <20230428191819.3070393-1-sjg@chromium.org> References: <20230428191819.3070393-1-sjg@chromium.org> MIME-Version: 1.0 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 --- 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 487552fa28c..62b7f45ab27 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 59d1bdc25b7..b20d5893632 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 a9a14f2a84a..23bc650c162 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