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 BBCF9C19F28 for ; Sat, 30 Jul 2022 21:57:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1917C84516; Sat, 30 Jul 2022 23:54:01 +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="Xv/ucZpG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E5FEB8412C; Sat, 30 Jul 2022 23:53:41 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 CF10D844AC for ; Sat, 30 Jul 2022 23:53:38 +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-ot1-x332.google.com with SMTP id g19-20020a9d1293000000b0061c7bfda5dfso5678985otg.1 for ; Sat, 30 Jul 2022 14:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0iJ29r8+zqkTqTeoH0XShAvzU/J4S/rjlSde8ktAn4s=; b=Xv/ucZpGQ4mx3ivDQSXW+u6Ro/qlsqQNJfOhptX25MbUJNkgrd7d1qQR2CDou4rHzv Hcb1adyptUVpLmgCIEQjg6pTrUDmnZE8oeNNk8SusTkWDsAcW0zBH6HjBbv0RfAlTqNP wKbYC4rnx3gTvV3jNn/rzwfB/D/Tv9LyWgUag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0iJ29r8+zqkTqTeoH0XShAvzU/J4S/rjlSde8ktAn4s=; b=QRD8Pv3htD1eSQqRbibF5Fmk8BjuhoFfdpI1/5hqB3zcQFl6lqZ9/cZhTPvTZ/GBmB 3vXtlkKYK+Sfq/s+FgU5DPV7s+OMIXIrqETxfFZ95cmfsp3dFZet3UIrFUCwBIlwkXFA f0sTBJD1mUxPxJ2SHAxBVBfDea9uuwb18AyOPqUo4ZPMnznSqznZ8xWOLn6cFHhyAPWj sQqpaYpaNZHsAtdNQhLAHjrsV0sZITxLOXgzhZF9Z39fPUKR4poqI+Us4iTFp+m+BF16 ceJhcIoFeZ8AA77/sZA/9DAsy6a9ehJBIlN7hFpTvbck+7ySyy8G/rGE3zeTJLikOB/3 2AuA== X-Gm-Message-State: AJIora+BK/9aLNMTHT7ByvAdmNMQmL8MHr5RTMBPcsdLgTFZ4PfEn/xy 0YS31tuwG7xIh3U8EKu7IpPbonWGYHw59hDk X-Google-Smtp-Source: AGRyM1ud6ja6iblzlkOGK8PtzhJlbWGFtu5Y4YsMKWX37FxzWeaqFx8O8bPHDnC1IIDkXetUwljPBA== X-Received: by 2002:a9d:6847:0:b0:61c:96ce:8a4e with SMTP id c7-20020a9d6847000000b0061c96ce8a4emr3616253oto.261.1659218018261; Sat, 30 Jul 2022 14:53:38 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id 19-20020a544193000000b0032f75714af1sm1699656oiy.18.2022.07.30.14.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 14:53:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Bin Meng , Simon Glass Subject: [PATCH v2 30/35] vbe: Add initial support for VBE Date: Sat, 30 Jul 2022 15:52:32 -0600 Message-Id: <20220730215237.818368-26-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog In-Reply-To: <20220730215237.818368-1-sjg@chromium.org> References: <20220730215237.818368-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.6 at phobos.denx.de X-Virus-Status: Clean Create a new bootmeth for VBE along with a library to handle finding the VBE methods. Signed-off-by: Simon Glass --- (no changes since v1) boot/Kconfig | 10 ++++ boot/Makefile | 2 + boot/vbe.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++ include/bootstd.h | 2 + include/vbe.h | 48 +++++++++++++++++++ 5 files changed, 181 insertions(+) create mode 100644 boot/vbe.c create mode 100644 include/vbe.h diff --git a/boot/Kconfig b/boot/Kconfig index b8adc64b9a7..094a790f3e8 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -392,6 +392,16 @@ config BOOTMETH_EFILOADER This provides a way to try out standard boot on an existing boot flow. +config BOOTMETH_VBE + bool "Bootdev support for Verified Boot for Embedded" + depends on FIT + default y + select BOOTMETH_GLOBAL + help + Enables support for VBE boot. This is a standard boot method which + supports selection of various firmware components, seleciton of an OS to + boot as well as updating these using fwupd. + config BOOTMETH_SANDBOX def_bool y depends on SANDBOX diff --git a/boot/Makefile b/boot/Makefile index bab02be53fa..0378a9db27f 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -47,3 +47,5 @@ obj-$(CONFIG_CMD_ADTIMG) += image-android-dt.o ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o endif + +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o diff --git a/boot/vbe.c b/boot/vbe.c new file mode 100644 index 00000000000..e6ee087dc24 --- /dev/null +++ b/boot/vbe.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Verified Boot for Embedded (VBE) access functions + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include + +/** + * is_vbe() - Check if a device is a VBE method + * + * @dev: Device to check + * @return true if this is a VBE bootmth device, else false + */ +static bool is_vbe(struct udevice *dev) +{ + return !strncmp("vbe", dev->driver->name, 3); +} + +int vbe_find_next_device(struct udevice **devp) +{ + for (uclass_find_next_device(devp); + *devp; + uclass_find_next_device(devp)) { + if (is_vbe(*devp)) + return 0; + } + + return 0; +} + +int vbe_find_first_device(struct udevice **devp) +{ + uclass_find_first_device(UCLASS_BOOTMETH, devp); + if (*devp && is_vbe(*devp)) + return 0; + + return vbe_find_next_device(devp); +} + +int vbe_list(void) +{ + struct bootstd_priv *std; + struct udevice *dev; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return ret; + + printf("%3s %-3s %-15s %-15s %s\n", "#", "Sel", "Device", "Driver", + "Description"); + printf("%3s %-3s %-15s %-15s %s\n", "---", "---", "--------------", + "--------------", "-----------"); + for (ret = vbe_find_first_device(&dev); dev; + ret = vbe_find_next_device(&dev)) { + const struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev); + + printf("%3d %-3s %-15s %-15s %s\n", dev_seq(dev), + std->vbe_bootmeth == dev ? "*" : "", dev->name, + dev->driver->name, plat->desc); + } + printf("%3s %-3s %-15s %-15s %s\n", "---", "---", "--------------", + "--------------", "-----------"); + + return 0; +} + +int vbe_select(struct udevice *dev) +{ + struct bootstd_priv *std; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return ret; + std->vbe_bootmeth = dev; + + return 0; +} + +int vbe_find_by_any(const char *name, struct udevice **devp) +{ + struct udevice *dev; + int ret, seq; + char *endp; + + seq = simple_strtol(name, &endp, 16); + + /* Select by name */ + if (*endp) { + ret = uclass_get_device_by_name(UCLASS_BOOTMETH, name, &dev); + if (ret) { + printf("Cannot probe VBE bootmeth '%s' (err=%d)\n", name, + ret); + return ret; + } + + /* select by number */ + } else { + ret = uclass_get_device_by_seq(UCLASS_BOOTMETH, seq, &dev); + if (ret) { + printf("Cannot find '%s' (err=%d)\n", name, ret); + return ret; + } + } + + *devp = dev; + + return 0; +} diff --git a/include/bootstd.h b/include/bootstd.h index b002365f4f0..01be249d16e 100644 --- a/include/bootstd.h +++ b/include/bootstd.h @@ -26,6 +26,7 @@ struct udevice; * @glob_head: Head for the global list of all bootflows across all bootdevs * @bootmeth_count: Number of bootmeth devices in @bootmeth_order * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated + * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none */ struct bootstd_priv { const char **prefixes; @@ -35,6 +36,7 @@ struct bootstd_priv { struct list_head glob_head; int bootmeth_count; struct udevice **bootmeth_order; + struct udevice *vbe_bootmeth; }; /** diff --git a/include/vbe.h b/include/vbe.h new file mode 100644 index 00000000000..b83f6f0c519 --- /dev/null +++ b/include/vbe.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Verified Boot for Embedded (VBE) support + * See doc/develop/vbe.rst + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#ifndef __VBE_H +#define __VBE_H + +/** + * vbe_list() - List the VBE bootmeths + * + * This shows a list of the VBE bootmeth devices + * + * @return 0 (always) + */ +int vbe_list(void); + +/** + * vbe_find_by_any() - Find a VBE bootmeth by name or sequence + * + * @name: name (e.g. "vbe-simple"), or sequence ("2") to find + * @devp: returns the device found, on success + * Return: 0 if OK, -ve on error + */ +int vbe_find_by_any(const char *name, struct udevice **devp); + +/** + * vbe_find_first_device() - Find the first VBE bootmeth + * + * @devp: Returns first available VBE bootmeth, or NULL if none + * Returns: 0 (always) + */ +int vbe_find_first_device(struct udevice **devp); + +/** + * vbe_find_next_device() - Find the next available VBE bootmeth + * + * @devp: Previous device to start from. Returns next available VBE bootmeth, + * or NULL if none + * Returns: 0 (always) + */ +int vbe_find_next_device(struct udevice **devp); + +#endif -- 2.37.1.455.g008518b4e5-goog