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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A8BDC433EF for ; Sat, 23 Oct 2021 23:31:49 +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 9D5B860C4D for ; Sat, 23 Oct 2021 23:31:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9D5B860C4D 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 4AAB0835AE; Sun, 24 Oct 2021 01:30:50 +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="cm2AjJvp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 910F48331C; Sun, 24 Oct 2021 01:27:57 +0200 (CEST) Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 236698355F for ; Sun, 24 Oct 2021 01:27:16 +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-x229.google.com with SMTP id t4so10032823oie.5 for ; Sat, 23 Oct 2021 16:27:16 -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=K9q2JM17yaPatbu7C9mcpAdmRaaIsx+Ns/XAbydlXXE=; b=cm2AjJvp4GJfibqqJJqG9pUPgxSX4z+HJM8lwaCrIhH9Cw0b0nHEzkIgB+cR35DKkV puhTkITgWHV7fQ71RKnwbIPR5XGr56rBHUisUlhhxTjkwT0DAfjFUYbqNR3ejlJAbUDh U/quDZkvEMwutDWSjAaCCFxVOy3+DsNOnNxIk= 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=K9q2JM17yaPatbu7C9mcpAdmRaaIsx+Ns/XAbydlXXE=; b=BwAtqM571ZBppVEiS/QNDBpoJNq//2giWqEab25c6FGzTG2ImdMBXmvEuSt3OB0hgF BmnCxlwgkVwecA6Y4qWpmpHK+6XYOCexdxj6OXv+xMGy6cvlzSHItvVIaayd9uHofTkD 9rEuzfx3oO/kV4iXu7wKIL6HrcFslpgpLG3pQI5Hcn9/vzMLbDm3ypm4NyYuD3NC+TWI aIKXKlvLqM8plhBF7QSFkAdscY2rZmKP296NKC6hYOCdr1a7XX+C7U2p2tPGcW8iVuAr t+W+nX0ZaT27IbTNL0OtgzAoY6pnu3NIf6kDFvOaIYKPkP2ta6LK84WIk62TjsYN0UeQ MtNw== X-Gm-Message-State: AOAM533McY4Fbpvg4hJ0oHgbkyphib01E2MAUV2RXJNgJ0sq/gmOpBNo wmNWTe5Dz8jMRtVMae0qV2WnpzES+dp3sA== X-Google-Smtp-Source: ABdhPJwN4WO+e8esTdUsjPja3xA+KEwXNw+1jeSVDvxDG/dHzMkZnDgRN4Wjh5B7z/E1R6ruBGCXig== X-Received: by 2002:aca:300e:: with SMTP id w14mr6204834oiw.178.1635031634565; Sat, 23 Oct 2021 16:27:14 -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 l24sm2253885oop.4.2021.10.23.16.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:14 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass Subject: [PATCH v2 27/41] bootstd: Add an implementation of distro boot Date: Sat, 23 Oct 2021 17:26:21 -0600 Message-Id: <20211023172618.v2.27.Iafd004865970e7357960cacc4981e212e4cf3d16@changeid> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-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 bootmeth driver which handles distro boot from a disk, so we can boot a bootflow using this commonly used mechanism. In effect, this provides the same functionality as the 'sysboot' command and shares the same code. But the interface into it is via a bootmeth. For now this requires the 'pxe' command be enabled. Future work may tidy this up so that it can be used without CONFIG_CMDLINE being enabled. Signed-off-by: Simon Glass --- (no changes since v1) MAINTAINERS | 3 +- boot/Kconfig | 15 +++ boot/Makefile | 2 + boot/bootmeth_distro.c | 217 +++++++++++++++++++++++++++++++++++++++++ include/distro.h | 24 +++++ 5 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 boot/bootmeth_distro.c create mode 100644 include/distro.h diff --git a/MAINTAINERS b/MAINTAINERS index a95329286da..fc05570f11d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -641,7 +641,8 @@ F: boot/bootflow.c F: boot/bootmeth*.c F: boot/bootstd.c F: cmd/bootdev.c -F: include/bootdev*.h +F: cmd/bootflow.c +F: include/bootdev.h F: include/bootflow.h F: include/bootmeth.h F: include/bootstd.h diff --git a/boot/Kconfig b/boot/Kconfig index 58c495bb347..c5c8be70da9 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -295,6 +295,21 @@ config BOOTSTD U-Boot) - bootflow - a description of how to boot (owned by the distro) +if BOOTSTD + +config BOOTMETH_DISTRO + bool "Bootdev support for distro boot" + depends on CMD_PXE + default y + help + Enables support for distro boot using bootdevs. This makes the + bootdevs look for a 'extlinux/extlinux.conf' on each filesystem + they scan. + + This provides a way to try out standard boot on an existing boot flow. + +endif + config LEGACY_IMAGE_FORMAT bool "Enable support for the legacy image format" default y if !FIT_SIGNATURE diff --git a/boot/Makefile b/boot/Makefile index f58c192ae07..d8f5c340b85 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -28,6 +28,8 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow.o obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o + obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o diff --git a/boot/bootmeth_distro.c b/boot/bootmeth_distro.c new file mode 100644 index 00000000000..551159abff3 --- /dev/null +++ b/boot/bootmeth_distro.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Bootmethod for distro boot (syslinux boot from a block device) + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int disto_getfile(struct pxe_context *ctx, const char *file_path, + char *file_addr, ulong *sizep) +{ + struct distro_info *info = ctx->userdata; + ulong addr; + int ret; + + addr = simple_strtoul(file_addr, NULL, 16); + + /* Allow up to 1GB */ + *sizep = 1 << 30; + ret = bootmeth_read_file(info->dev, info->bflow, file_path, addr, + sizep); + if (ret) + return log_msg_ret("read", ret); + + return 0; +} + +static int distro_check(struct udevice *dev, struct bootflow_iter *iter) +{ + int ret; + + /* This only works on block devices */ + ret = bootflow_iter_uses_blk_dev(iter); + if (ret) + return log_msg_ret("blk", ret); + + return 0; +} + +static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow) +{ + struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); + const char *const *prefixes; + struct udevice *bootstd; + loff_t size, bytes_read; + char fname[200]; + ulong addr; + int ret, i; + char *buf; + + ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd); + if (ret) + return log_msg_ret("std", ret); + + /* We require a partition table */ + if (!bflow->part) + return -ENOENT; + + bflow->fname = strdup(DISTRO_FNAME); + if (!bflow->fname) + return log_msg_ret("name", -ENOMEM); + + prefixes = bootstd_get_prefixes(bootstd); + if (prefixes) { + log_debug("Trying prefixes:\n"); + for (i = 0; prefixes[i]; i++) { + snprintf(fname, sizeof(fname), "%s%s", prefixes[i], + DISTRO_FNAME); + ret = fs_size(fname, &size); + log_debug(" %s - err=%d\n", fname, ret); + if (!ret) + break; + + /* + * Sadly FS closes the file after fs_size() so we must + * redo this + */ + ret = fs_set_blk_dev_with_part(desc, bflow->part); + if (ret) + return log_msg_ret("set", ret); + } + log_debug(" done\n"); + } else { + strcpy(fname, DISTRO_FNAME); + ret = fs_size(bflow->fname, &size); + log_debug("No prefixes: %s - err=%d", fname, ret); + } + if (ret) + return log_msg_ret("size", ret); + + bflow->fname = strdup(fname); + if (!bflow->fname) + return log_msg_ret("name", -ENOMEM); + + bflow->state = BOOTFLOWST_FILE; + bflow->size = size; + log_debug(" - distro file size %x\n", (uint)size); + if (size > 0x10000) + return log_msg_ret("chk", -E2BIG); + + /* Sadly FS closes the file after fs_size() so we must redo this */ + ret = fs_set_blk_dev_with_part(desc, bflow->part); + if (ret) + return log_msg_ret("set", ret); + + buf = malloc(size + 1); + if (!buf) + return log_msg_ret("buf", -ENOMEM); + addr = map_to_sysmem(buf); + + ret = fs_read(bflow->fname, addr, 0, 0, &bytes_read); + if (ret) { + free(buf); + return log_msg_ret("read", ret); + } + if (size != bytes_read) + return log_msg_ret("bread", -EINVAL); + buf[size] = '\0'; + bflow->state = BOOTFLOWST_READY; + bflow->buf = buf; + + return 0; +} + +static int distro_read_file(struct udevice *dev, struct bootflow *bflow, + const char *file_path, ulong addr, ulong *sizep) +{ + struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); + loff_t len_read; + loff_t size; + int ret; + + ret = fs_set_blk_dev_with_part(desc, bflow->part); + if (ret) + return log_msg_ret("set1", ret); + ret = fs_size(file_path, &size); + if (ret) + return log_msg_ret("size", ret); + if (size > *sizep) + return log_msg_ret("spc", -ENOSPC); + + ret = fs_set_blk_dev_with_part(desc, bflow->part); + if (ret) + return log_msg_ret("set2", ret); + ret = fs_read(file_path, addr, 0, 0, &len_read); + if (ret) + return ret; + *sizep = len_read; + + return 0; +} + +static int distro_boot(struct udevice *dev, struct bootflow *bflow) +{ + struct cmd_tbl cmdtp = {}; /* dummy */ + struct pxe_context ctx; + struct distro_info info; + ulong addr; + int ret; + + addr = map_to_sysmem(bflow->buf); + info.dev = dev; + info.bflow = bflow; + ret = pxe_setup_ctx(&ctx, &cmdtp, disto_getfile, &info, true, + bflow->subdir); + if (ret) + return log_msg_ret("ctx", -EINVAL); + + ret = pxe_process(&ctx, addr, false); + if (ret) + return log_msg_ret("bread", -EINVAL); + + return 0; +} + +static int distro_bootmeth_bind(struct udevice *dev) +{ + struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev); + + plat->desc = "Syslinux boot from a block device"; + + return 0; +} + +static struct bootmeth_ops distro_bootmeth_ops = { + .check = distro_check, + .read_bootflow = distro_read_bootflow, + .read_file = distro_read_file, + .boot = distro_boot, +}; + +static const struct udevice_id distro_bootmeth_ids[] = { + { .compatible = "u-boot,distro-syslinux" }, + { } +}; + +U_BOOT_DRIVER(bootmeth_distro) = { + .name = "bootmeth_distro", + .id = UCLASS_BOOTMETH, + .of_match = distro_bootmeth_ids, + .ops = &distro_bootmeth_ops, + .bind = distro_bootmeth_bind, +}; diff --git a/include/distro.h b/include/distro.h new file mode 100644 index 00000000000..2ee145871b2 --- /dev/null +++ b/include/distro.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#ifndef __distro_h +#define __distro_h + +#define DISTRO_FNAME "extlinux/extlinux.conf" + +/** + * struct distro_info - useful information for distro_getfile() + * + * @dev: bootmethod device being used to boot + * @bflow: bootflow being booted + */ +struct distro_info { + struct udevice *dev; + struct bootflow *bflow; + struct cmd_tbl *cmdtp; +}; + +#endif -- 2.33.0.1079.g6e70778dc9-goog