mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
bootstd: Add an implementation of distro boot
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 <sjg@chromium.org>
This commit is contained in:
parent
7fca71d0d6
commit
31aefaf89a
5 changed files with 186 additions and 1 deletions
|
@ -701,7 +701,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
|
||||
|
|
15
boot/Kconfig
15
boot/Kconfig
|
@ -326,6 +326,21 @@ config BOOTSTD_FULL
|
|||
- support for selecting the ordering of bootdevs using the devicetree
|
||||
as well as the "boot_targets" environment variable
|
||||
|
||||
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
|
||||
|
|
|
@ -24,6 +24,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
|
||||
|
|
143
boot/bootmeth_distro.c
Normal file
143
boot/bootmeth_distro.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Bootmethod for distro boot (syslinux boot from a block device)
|
||||
*
|
||||
* Copyright 2021 Google LLC
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*/
|
||||
|
||||
#define LOG_CATEGORY UCLASS_BOOTSTD
|
||||
|
||||
#include <common.h>
|
||||
#include <bootdev.h>
|
||||
#include <bootflow.h>
|
||||
#include <bootmeth.h>
|
||||
#include <bootstd.h>
|
||||
#include <command.h>
|
||||
#include <distro.h>
|
||||
#include <dm.h>
|
||||
#include <fs.h>
|
||||
#include <malloc.h>
|
||||
#include <mapmem.h>
|
||||
#include <mmc.h>
|
||||
#include <pxe_utils.h>
|
||||
|
||||
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;
|
||||
const char *const *prefixes;
|
||||
struct udevice *bootstd;
|
||||
const char *prefix;
|
||||
loff_t size;
|
||||
int ret, i;
|
||||
|
||||
ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd);
|
||||
if (ret)
|
||||
return log_msg_ret("std", ret);
|
||||
|
||||
/* If a block device, we require a partition table */
|
||||
if (bflow->blk && !bflow->part)
|
||||
return -ENOENT;
|
||||
|
||||
prefixes = bootstd_get_prefixes(bootstd);
|
||||
i = 0;
|
||||
desc = bflow->blk ? dev_get_uclass_plat(bflow->blk) : NULL;
|
||||
do {
|
||||
prefix = prefixes ? prefixes[i] : NULL;
|
||||
|
||||
ret = bootmeth_try_file(bflow, desc, prefix, DISTRO_FNAME);
|
||||
} while (ret && prefixes && prefixes[++i]);
|
||||
if (ret)
|
||||
return log_msg_ret("try", ret);
|
||||
size = bflow->size;
|
||||
|
||||
ret = bootmeth_alloc_file(bflow, 0x10000, 1);
|
||||
if (ret)
|
||||
return log_msg_ret("read", ret);
|
||||
|
||||
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 = IS_ENABLED(CONFIG_BOOTSTD_FULL) ?
|
||||
"Syslinux boot from a block device" : "syslinux";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct bootmeth_ops distro_bootmeth_ops = {
|
||||
.check = distro_check,
|
||||
.read_bootflow = distro_read_bootflow,
|
||||
.read_file = bootmeth_common_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,
|
||||
};
|
24
include/distro.h
Normal file
24
include/distro.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*/
|
||||
|
||||
#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
|
Loading…
Reference in a new issue