1 // SPDX-License-Identifier: GPL-2.0+
3 * Bootmethod for distro boot (syslinux boot from a block device)
5 * Copyright 2021 Google LLC
9 #define LOG_CATEGORY UCLASS_BOOTSTD
23 #include <pxe_utils.h>
25 static int disto_getfile(struct pxe_context *ctx, const char *file_path,
26 char *file_addr, ulong *sizep)
28 struct distro_info *info = ctx->userdata;
32 addr = simple_strtoul(file_addr, NULL, 16);
36 ret = bootmeth_read_file(info->dev, info->bflow, file_path, addr,
39 return log_msg_ret("read", ret);
44 static int distro_check(struct udevice *dev, struct bootflow_iter *iter)
48 /* This only works on block devices */
49 ret = bootflow_iter_uses_blk_dev(iter);
51 return log_msg_ret("blk", ret);
56 static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow)
58 struct blk_desc *desc;
59 const char *const *prefixes;
60 struct udevice *bootstd;
65 ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd);
67 return log_msg_ret("std", ret);
69 /* If a block device, we require a partition table */
70 if (bflow->blk && !bflow->part)
73 prefixes = bootstd_get_prefixes(bootstd);
75 desc = bflow->blk ? dev_get_uclass_plat(bflow->blk) : NULL;
77 prefix = prefixes ? prefixes[i] : NULL;
79 ret = bootmeth_try_file(bflow, desc, prefix, DISTRO_FNAME);
80 } while (ret && prefixes && prefixes[++i]);
82 return log_msg_ret("try", ret);
85 ret = bootmeth_alloc_file(bflow, 0x10000, 1);
87 return log_msg_ret("read", ret);
92 static int distro_boot(struct udevice *dev, struct bootflow *bflow)
94 struct cmd_tbl cmdtp = {}; /* dummy */
95 struct pxe_context ctx;
96 struct distro_info info;
100 addr = map_to_sysmem(bflow->buf);
103 ret = pxe_setup_ctx(&ctx, &cmdtp, disto_getfile, &info, true,
106 return log_msg_ret("ctx", -EINVAL);
108 ret = pxe_process(&ctx, addr, false);
110 return log_msg_ret("bread", -EINVAL);
115 static int distro_bootmeth_bind(struct udevice *dev)
117 struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
119 plat->desc = IS_ENABLED(CONFIG_BOOTSTD_FULL) ?
120 "Syslinux boot from a block device" : "syslinux";
125 static struct bootmeth_ops distro_bootmeth_ops = {
126 .check = distro_check,
127 .read_bootflow = distro_read_bootflow,
128 .read_file = bootmeth_common_read_file,
132 static const struct udevice_id distro_bootmeth_ids[] = {
133 { .compatible = "u-boot,distro-syslinux" },
137 U_BOOT_DRIVER(bootmeth_distro) = {
138 .name = "bootmeth_distro",
139 .id = UCLASS_BOOTMETH,
140 .of_match = distro_bootmeth_ids,
141 .ops = &distro_bootmeth_ops,
142 .bind = distro_bootmeth_bind,