From mboxrd@z Thu Jan 1 00:00:00 1970 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 EFF05C433F5 for ; Sun, 6 Mar 2022 12:53:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7624A83D64; Sun, 6 Mar 2022 13:52:22 +0100 (CET) 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="ldjKCPPR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2CCF83BDF; Sun, 6 Mar 2022 13:51:54 +0100 (CET) Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (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 9F34B83CAF for ; Sun, 6 Mar 2022 13:51:16 +0100 (CET) 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-x12b.google.com with SMTP id h7so1569427ile.1 for ; Sun, 06 Mar 2022 04:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J2HavqJqntrwlCUwIMgbDPJyWIurTQ6/To5YD3SsfVw=; b=ldjKCPPRV15dtnddwOPHIKA82/1icORULUGQCHZiizSZWie90sf0UnxA9Bpw32O4FD NpYxkh8psFZ89UBR3EUb+HM47QbHJVYYgEcM6VLAyZFXA4IxGww559P9xbWtJQB1Q9Xr 24J8ZGa66c7J0k3zseLN/muco0p4f2Ay6KxgM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J2HavqJqntrwlCUwIMgbDPJyWIurTQ6/To5YD3SsfVw=; b=TxpcTFOO2wI5dOE1BsJfsbx9idfmHPkFfSb+2fBGVZVhhNjhLLtFbfibvqHLbde61q 7Nll41DvRQG7yj0/8JRAztVSsNWUqZ1X9kHg2njbIuEvUoArFsCHuVu5OXja12aiyaiA 3WbPSAbC6kvXMEdlWuGKsN+aJ4sg+CpmW7+1FxsDR+JCDyfNWuIGx3uMTB3em3OfjL8k mrGPNkQMz1fNEadjTrFOUbZo8inB2hO9e4KI9S1+KpPqzmTssGYmtKLrCHsiDkFQpUWy wbkvT9cugUXZxMRtYBGbfTmWhpbz7sg/zwlL69T8wVdcTPLJj2dI3Smhw+4DzpPGNwcm qzAw== X-Gm-Message-State: AOAM530U/bPWqdJg/jOSK0sb9eLCGinwKhJ9Un9wdNIH5od0MVeKPg3T rH+fNFgX09TyNd9pp5C8Q+aMUp2NnR5MXQ== X-Google-Smtp-Source: ABdhPJydo6kWkcJ/s9Yixa7RlvXHy1Vc4MceYJ091cT6ErLxsnoqgWJxaVRsTLs9j1c4ElH597yS8g== X-Received: by 2002:a05:6e02:1585:b0:2c2:5b2c:e3e5 with SMTP id m5-20020a056e02158500b002c25b2ce3e5mr7818952ilu.76.1646571074890; Sun, 06 Mar 2022 04:51:14 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id p22-20020a5d8d16000000b006115627b87csm7653533ioj.55.2022.03.06.04.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 04:51:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Dennis Gilmore , Ilias Apalodimas , Lukas Auer , Tom Rini , Heinrich Schuchardt , Michal Simek , Daniel Schwierzeck , Steffen Jaeckel , Simon Glass Subject: [PATCH v4 17/33] bootstd: Add a bootdev command Date: Sun, 6 Mar 2022 05:50:00 -0700 Message-Id: <20220306054946.v4.17.Ic1c0b48869db2404f5d8c89518eb88156b8bc46a@changeid> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220306125016.3133737-1-sjg@chromium.org> References: <20220306125016.3133737-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.5 at phobos.denx.de X-Virus-Status: Clean Add a 'bootdev' command to handle listing and selection of bootdevs. Disable standard boot for a few boards which otherwise run out of space. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Use separate Kconfig options for each command MAINTAINERS | 1 + cmd/Kconfig | 10 +++ cmd/Makefile | 1 + cmd/bootdev.c | 120 +++++++++++++++++++++++++++++ configs/amcore_defconfig | 1 + configs/rcar3_salvator-x_defconfig | 1 + configs/tbs2910_defconfig | 1 + 7 files changed, 135 insertions(+) create mode 100644 cmd/bootdev.c diff --git a/MAINTAINERS b/MAINTAINERS index c47a8143b2..873e8f6352 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -689,6 +689,7 @@ F: boot/bootdev*.c F: boot/bootflow.c F: boot/bootmeth*.c F: boot/bootstd.c +F: cmd/bootdev.c F: include/bootdev*.h F: include/bootflow.h F: include/bootmeth.h diff --git a/cmd/Kconfig b/cmd/Kconfig index d10deed244..2a54d45be3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,16 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTDEV + bool "bootdev" + depends on BOOTSTD + default y if BOOTSTD_FULL + help + Support listing available bootdevs (boot devices) which can provide an + OS to boot, as well as showing information about a particular one. + + This command is not necessary for bootstd to work. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..18be0a3ae8 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o obj-$(CONFIG_CMD_ARMFLASH) += armflash.o obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o +obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o obj-$(CONFIG_CMD_SOURCE) += source.o obj-$(CONFIG_CMD_BCB) += bcb.o obj-$(CONFIG_CMD_BDI) += bdinfo.o diff --git a/cmd/bootdev.c b/cmd/bootdev.c new file mode 100644 index 0000000000..ecd797c050 --- /dev/null +++ b/cmd/bootdev.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 'bootdev' command + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int bootdev_check_state(struct bootstd_priv **stdp) +{ + struct bootstd_priv *std; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return ret; + if (!std->cur_bootdev) { + printf("Please use 'bootdev select' first\n"); + return -ENOENT; + } + *stdp = std; + + return 0; +} + +static int do_bootdev_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool probe; + + probe = argc >= 2 && !strcmp(argv[1], "-p"); + bootdev_list(probe); + + return 0; +} + +static int do_bootdev_select(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootstd_priv *std; + struct udevice *dev; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return CMD_RET_FAILURE; + if (argc < 2) { + std->cur_bootdev = NULL; + return 0; + } + if (bootdev_find_by_any(argv[1], &dev)) + return CMD_RET_FAILURE; + + std->cur_bootdev = dev; + + return 0; +} + +static int do_bootdev_info(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootstd_priv *priv; + struct bootflow *bflow; + int ret, i, num_valid; + struct udevice *dev; + bool probe; + + probe = argc >= 2 && !strcmp(argv[1], "-p"); + + ret = bootdev_check_state(&priv); + if (ret) + return CMD_RET_FAILURE; + + dev = priv->cur_bootdev; + + /* Count the number of bootflows, including how many are valid*/ + num_valid = 0; + for (ret = bootdev_first_bootflow(dev, &bflow), i = 0; + !ret; + ret = bootdev_next_bootflow(&bflow), i++) + num_valid += bflow->state == BOOTFLOWST_READY; + + /* + * Prove the device, if requested, otherwise assume that there is no + * error + */ + ret = 0; + if (probe) + ret = device_probe(dev); + + printf("Name: %s\n", dev->name); + printf("Sequence: %d\n", dev_seq(dev)); + printf("Status: %s\n", ret ? simple_itoa(ret) : device_active(dev) ? + "Probed" : "OK"); + printf("Uclass: %s\n", dev_get_uclass_name(dev_get_parent(dev))); + printf("Bootflows: %d (%d valid)\n", i, num_valid); + + return 0; +} + +#ifdef CONFIG_SYS_LONGHELP +static char bootdev_help_text[] = + "list [-p] - list all available bootdevs (-p to probe)\n" + "bootdev select - select a bootdev by name | label | seq\n" + "bootdev info [-p] - show information about a bootdev (-p to probe)"; +#endif + +U_BOOT_CMD_WITH_SUBCMDS(bootdev, "Boot devices", bootdev_help_text, + U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootdev_list), + U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootdev_select), + U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootdev_info)); diff --git a/configs/amcore_defconfig b/configs/amcore_defconfig index afb3a7707f..9906d736bd 100644 --- a/configs/amcore_defconfig +++ b/configs/amcore_defconfig @@ -7,6 +7,7 @@ CONFIG_ENV_SECT_SIZE=0x1000 CONFIG_DEFAULT_DEVICE_TREE="amcore" CONFIG_TARGET_AMCORE=y CONFIG_SYS_LOAD_ADDR=0x20000 +# CONFIG_BOOTSTD is not set CONFIG_BOOTDELAY=1 CONFIG_USE_BOOTCOMMAND=y CONFIG_BOOTCOMMAND="bootm ffc20000" diff --git a/configs/rcar3_salvator-x_defconfig b/configs/rcar3_salvator-x_defconfig index 5fb27d257a..2db915f887 100644 --- a/configs/rcar3_salvator-x_defconfig +++ b/configs/rcar3_salvator-x_defconfig @@ -12,6 +12,7 @@ CONFIG_TARGET_SALVATOR_X=y CONFIG_REMAKE_ELF=y CONFIG_SYS_LOAD_ADDR=0x58000000 CONFIG_FIT=y +# CONFIG_BOOTSTD is not set CONFIG_SUPPORT_RAW_INITRD=y CONFIG_USE_BOOTARGS=y CONFIG_USE_BOOTCOMMAND=y diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig index e1278f2e70..353c61fe7b 100644 --- a/configs/tbs2910_defconfig +++ b/configs/tbs2910_defconfig @@ -14,6 +14,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx6q-tbs2910" CONFIG_PRE_CON_BUF_ADDR=0x7c000000 CONFIG_CMD_HDMIDETECT=y CONFIG_AHCI=y +# CONFIG_BOOTSTD is not set CONFIG_SUPPORT_RAW_INITRD=y CONFIG_BOOTDELAY=3 CONFIG_USE_BOOTCOMMAND=y -- 2.35.1.616.g0bdcbb4464-goog