From patchwork Wed Jan 19 01:43:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1581606 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=FqBqYNbP; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JdpQK053Zz9sPC for ; Wed, 19 Jan 2022 12:46:16 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0F2F383838; Wed, 19 Jan 2022 02:44:54 +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="FqBqYNbP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 88BBB83214; Wed, 19 Jan 2022 02:44:17 +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=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) (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 50162836E6 for ; Wed, 19 Jan 2022 02:43:57 +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-io1-xd29.google.com with SMTP id i82so954087ioa.8 for ; Tue, 18 Jan 2022 17:43:57 -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=JTrnrCRELLabOPSlldUgcpz5YVbOczNco74h7S4bhvo=; b=FqBqYNbPSZXlIn0M3Za0eq5DI8Fl2fH3phHeadEJ+T7depOkLnbOz6ET24fciciJB/ YMBYAU5PcuFYmddlhf53o2bwFvlr49G51Z1oseqMksY9U1pOBz57yXvQzS7b+S2WBV8p 8mQ3ImuUD4YTpp7Yk+Pf2bAX3rCdHpn9z3DSw= 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=JTrnrCRELLabOPSlldUgcpz5YVbOczNco74h7S4bhvo=; b=7RTAObnvrS4KdqZbTnR3+2Cay7pyfhDG3N398xOPwvBKKvoXp07xM77AVLlthA8Ksd srrxU3A+GDwOweg4baXqlHhr6gXOMqwKOa0n9j5Hxlu6thZgAL+ulkg2IcQxXIM9n+SN p07/c2J92SwMaDTEIm2QbfUZmPOL8RYVaF7gapQcU6iWbCSc8z09jm1ETy33/jf0K1qY wOxOjpzIRG2AoPl+hcg/Zof9BBNC+6kpAHnUF5cIIiAgfys11KAdDK+BuC7iv90LcZH8 TVnhLRribcJ/wN+zc8gE+YozIdsCHgN0GiyBwZcU0aKae6swiWo/e8SiG7oamcv8VfnJ 96GA== X-Gm-Message-State: AOAM530CFJR/bPeT9wHOvb0VMF4pklvMAkanQpryqwP50c4CbJ50h6El v5QrptPXXlw/ZdLDcLvCQGk6Oq/kwDnokg== X-Google-Smtp-Source: ABdhPJxh8Lmpq1LIXIRYy1gyPdEx1t+XXzSsnBiqY3NTmDAesAfCT5WLkg/6vSwzt/cGlG3YIbI+FQ== X-Received: by 2002:a02:a403:: with SMTP id c3mr13683626jal.318.1642556635894; Tue, 18 Jan 2022 17:43:55 -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 j18sm10546314ila.86.2022.01.18.17.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 17:43:55 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Daniel Schwierzeck , Dennis Gilmore , Steffen Jaeckel , Lukas Auer , Michal Simek , Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 17/31] bootstd: Add a bootmeth command Date: Tue, 18 Jan 2022 18:43:01 -0700 Message-Id: <20220118184259.v3.17.I6f3d772aa3671d526b66580c7989ae6c27c8538a@changeid> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog In-Reply-To: <20220119014315.1938157-1-sjg@chromium.org> References: <20220119014315.1938157-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.2 at phobos.denx.de X-Virus-Status: Clean Add a 'bootmeth' command to handle listing and ordering of boot methods. Signed-off-by: Simon Glass --- Changes in v3: - Move bootmeth ordering into the uclass cmd/Kconfig | 11 +++++ cmd/Makefile | 1 + cmd/bootmeth.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 cmd/bootmeth.c diff --git a/cmd/Kconfig b/cmd/Kconfig index d1c04f0446f..c87dbe16b8d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -222,6 +222,17 @@ config CMD_BOOTFLOW_FULL This command is not necessary for bootstd to work. +config CMD_BOOTMETH + bool "bootmeth" + depends on BOOTSTD + default y if BOOTSTD_FULL + help + Support listing available bootmethds (methods used to boot an + Operating System), as well as selecting the order that the bootmeths + are used. + + 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 2923bd98860..e7c36e1023e 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_CMD_ARMFLASH) += armflash.o obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o obj-$(CONFIG_CMD_BOOTFLOW) += bootflow.o +obj-$(CONFIG_CMD_BOOTMETH) += bootmeth.o obj-$(CONFIG_CMD_SOURCE) += source.o obj-$(CONFIG_CMD_BCB) += bcb.o obj-$(CONFIG_CMD_BDI) += bdinfo.o diff --git a/cmd/bootmeth.c b/cmd/bootmeth.c new file mode 100644 index 00000000000..c9a27fe8ac6 --- /dev/null +++ b/cmd/bootmeth.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 'bootmeth' command + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int do_bootmeth_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootstd_priv *std; + struct udevice *dev; + bool use_order; + bool all = false; + int ret; + int i; + + if (argc > 1 && *argv[1] == '-') { + all = strchr(argv[1], 'a'); + argc--; + argv++; + } + + ret = bootstd_get_priv(&std); + if (ret) { + printf("Cannot get bootstd (err=%d)\n", ret); + return CMD_RET_FAILURE; + } + + printf("Order Seq Name Description\n"); + printf("----- --- ------------------ ------------------\n"); + + /* + * Use the ordering if we have one, so long as we are not trying to list + * all bootmethds + */ + use_order = std->bootmeth_count && !all; + if (use_order) + dev = std->bootmeth_order[0]; + else + ret = uclass_find_first_device(UCLASS_BOOTMETH, &dev); + + for (i = 0; dev;) { + struct bootmeth_uc_plat *ucp = dev_get_uclass_plat(dev); + int order = i; + + /* + * With the -a flag we may list bootdevs that are not in the + * ordering. Find their place in the order + */ + if (all && std->bootmeth_count) { + int j; + + /* Find the position of this bootmeth in the order */ + order = -1; + for (j = 0; j < std->bootmeth_count; j++) { + if (std->bootmeth_order[j] == dev) + order = j; + } + } + + if (order == -1) + printf("%5s", "-"); + else + printf("%5x", order); + printf(" %3x %-19.19s %s\n", dev_seq(dev), dev->name, + ucp->desc); + i++; + if (use_order) + dev = std->bootmeth_order[i]; + else + uclass_find_next_device(&dev); + } + printf("----- --- ------------------ ------------------\n"); + printf("(%d bootmeth%s)\n", i, i != 1 ? "s" : ""); + + return 0; +} + +static int do_bootmeth_order(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + + ret = bootmeth_set_order(argv[1]); + if (ret) { + printf("Failed (err=%d)\n", ret); + return CMD_RET_FAILURE; + } + env_set("bootmeths", argv[1]); + + return 0; +} + +#ifdef CONFIG_SYS_LONGHELP +static char bootmeth_help_text[] = + "list [-a] - list available bootmeths (-a all)\n" + "bootmeth order [ ...] - select bootmeth order / subset to use"; +#endif + +U_BOOT_CMD_WITH_SUBCMDS(bootmeth, "Boot methods", bootmeth_help_text, + U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootmeth_list), + U_BOOT_SUBCMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_bootmeth_order));