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 X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2A69C4338F for ; Thu, 19 Aug 2021 03:50:54 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3BA0B6109E for ; Thu, 19 Aug 2021 03:50:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3BA0B6109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 744A483248; Thu, 19 Aug 2021 05:47:46 +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="MEXEj8gW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 59C23831EB; Thu, 19 Aug 2021 05:46:50 +0200 (CEST) Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (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 A9C5F83168 for ; Thu, 19 Aug 2021 05:46:36 +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-oi1-x22a.google.com with SMTP id bj40so6660731oib.6 for ; Wed, 18 Aug 2021 20:46:36 -0700 (PDT) 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=6rRea0ztKuTg439vq07PJnT8w6qlcIbJBsoPxRrRMAQ=; b=MEXEj8gWJbSrx1Fpa3uNvEs20UQE1gJY3MmbPTWZ3nBN8c/8BNolnPdDcZ3JcRhmQQ qdIrDzDc2DwLs59YCIz9FFbZaXFo3Mc10nu+lpiqVF8gJQYaZlqnUuhxSbmIZXLFE0X9 nXriAGYeK5PQPxOGrDdIagKa0vikOCCp4nrxU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6rRea0ztKuTg439vq07PJnT8w6qlcIbJBsoPxRrRMAQ=; b=VPjfjhLmmZulGv5Wag8AVkvA4OxyHLoSJI1qI5Q4GANGafOzp/6JxG9DZEkapmmR6D 62S8318oalvld23G0QSmtNL7tQbjxkSU2XMlnIvXyAJGhcnFXTQWlz3W/WodOH72/jDy pAgy1oSVTgB0jZlEQyC2OI683T8CVAf6hdUH5RaB3lwUKYeAYLADAE17zswFZIPgh93y JpoNgwOSJc5XVITxvoZcS1G735qNfzrLDS63e2CoE1vM3HyuzZrvwX+x3xJ4gfAliXYy h2bgK7G8O7ZXCMcmxFbrA32UTSVWLAE3KxBMbPuVAFWl+cWN9JnlehP8QHAtdEJc+rNq Qhzg== X-Gm-Message-State: AOAM530YVWPRfVSL6zclS6iaMk/SKqISgk2kGmT1y5gXowW/LwnbDjdP A7oRplEHKu9/zHai58Xo5ya8pMkNMRoqXw== X-Google-Smtp-Source: ABdhPJwMuT4ZbenLQYCKgMbmzDayaHBVKSWMJz2dWXIkWpABtZxd6MscjX1K5RgvzUYr54Mc5ySV5Q== X-Received: by 2002:a05:6808:1389:: with SMTP id c9mr1114643oiw.89.1629344795046; Wed, 18 Aug 2021 20:46:35 -0700 (PDT) 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 q3sm370025ooa.13.2021.08.18.20.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:46:34 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Steffen Jaeckel , Michal Simek , Tom Rini , Dennis Gilmore , Daniel Schwierzeck , Lukas Auer , Simon Glass Subject: [PATCH 21/28] bootmethod: Add a command Date: Wed, 18 Aug 2021 21:45:54 -0600 Message-Id: <20210818214547.21.Ic1c0b48869db2404f5d8c89518eb88156b8bc46a@changeid> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210819034601.1618773-1-sjg@chromium.org> References: <20210819034601.1618773-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 'bootmethod' command to handle listing and selection of bootmethods. Signed-off-by: Simon Glass --- MAINTAINERS | 1 + cmd/Kconfig | 8 +++ cmd/bootmethod.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 cmd/bootmethod.c diff --git a/MAINTAINERS b/MAINTAINERS index f78141c138b..655746265f8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -635,6 +635,7 @@ M: Simon Glass S: Maintained F: boot/bootmethod.c F: boot/distro.c +F: cmd/bootmethod.c F: include/bootmethod.h F: include/distro.h diff --git a/cmd/Kconfig b/cmd/Kconfig index ffef3cc76ca..eec0dee8773 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,14 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTMETHOD + bool "bootmethod" + default y if BOOTMETHOD + help + Support working with bootmethods, including listing available ones + and showing information about a particular one. It also allows + looking at bootflows available with the bootmethod. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/bootmethod.c b/cmd/bootmethod.c new file mode 100644 index 00000000000..2620ff61eb2 --- /dev/null +++ b/cmd/bootmethod.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 'bootmethod' command + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +static int bootmethod_check_state(struct bootflow_state **statep) +{ + struct bootflow_state *state; + int ret; + + ret = bootmethod_get_state(&state); + if (ret) + return ret; + if (!state->cur_bootmethod) { + printf("Please use 'bootmethod select' first\n"); + return -ENOENT; + } + *statep = state; + + return 0; +} + +static int do_bootmethod_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool probe; + + probe = argc >= 2 && !strcmp(argv[1], "-p"); + bootmethod_list(probe); + + return 0; +} + +static int do_bootmethod_select(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootflow_state *state; + struct udevice *dev; + const char *name; + char *endp; + int seq; + int ret; + + ret = bootmethod_get_state(&state); + if (ret) + return CMD_RET_FAILURE; + if (argc < 2) { + state->cur_bootmethod = NULL; + return 0; + } + name = argv[1]; + seq = simple_strtol(name, &endp, 16); + + /* Select by name or number */ + if (*endp) + ret = uclass_get_device_by_name(UCLASS_BOOTMETHOD, name, &dev); + else + ret = uclass_get_device_by_seq(UCLASS_BOOTMETHOD, seq, &dev); + if (ret) { + printf("Cannot find '%s' (err=%d)\n", name, ret); + return CMD_RET_FAILURE; + } + state->cur_bootmethod = dev; + + return 0; +} + +static int do_bootmethod_info(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootflow_state *state; + struct bootflow *bflow; + int ret, i, num_valid; + struct udevice *dev; + bool probe; + + probe = argc >= 2 && !strcmp(argv[1], "-p"); + + ret = bootmethod_check_state(&state); + if (ret) + return CMD_RET_FAILURE; + + dev = state->cur_bootmethod; + + /* Count the number of bootflows, including how many are valid*/ + num_valid = 0; + for (ret = bootmethod_first_bootflow(dev, &bflow), i = 0; + !ret; + ret = bootmethod_next_bootflow(&bflow), i++) + num_valid += bflow->state == BOOTFLOWST_LOADED; + + /* + * 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 bootmethod_help_text[] = + "list [-p] - list all available bootmethods (-p to probe)\n" + "bootmethod select - select a bootmethod by name\n" + "bootmethod info [-p] - show information about a bootmethod (-p to probe)"; +#endif + +U_BOOT_CMD_WITH_SUBCMDS(bootmethod, "Bootmethods", bootmethod_help_text, + U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootmethod_list), + U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootmethod_select), + U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootmethod_info)); -- 2.33.0.rc1.237.g0d66db33f3-goog