1 // SPDX-License-Identifier: GPL-2.0+
3 * Bootmethod for QEMU qfw
5 * Copyright 2023 Google LLC
9 #define LOG_CATEGORY UCLASS_BOOTSTD
19 static int qfw_check(struct udevice *dev, struct bootflow_iter *iter)
21 const struct udevice *media = dev_get_parent(iter->dev);
22 enum uclass_id id = device_get_uclass_id(media);
24 log_debug("media=%s\n", media->name);
31 static int qfw_read_bootflow(struct udevice *dev, struct bootflow *bflow)
33 struct udevice *qfw_dev = dev_get_parent(bflow->dev);
37 load = env_get_hex("kernel_addr_r", 0);
38 initrd = env_get_hex("ramdisk_addr_r", 0);
39 log_debug("setup kernel %s %lx %lx\n", qfw_dev->name, load, initrd);
40 bflow->name = strdup("qfw");
42 return log_msg_ret("name", -ENOMEM);
44 ret = qemu_fwcfg_setup_kernel(qfw_dev, load, initrd);
45 log_debug("setup kernel result %d\n", ret);
47 return log_msg_ret("cmd", -EIO);
49 bflow->state = BOOTFLOWST_READY;
54 static int qfw_read_file(struct udevice *dev, struct bootflow *bflow,
55 const char *file_path, ulong addr, ulong *sizep)
60 static int qfw_boot(struct udevice *dev, struct bootflow *bflow)
64 ret = run_command("booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdtcontroladdr}",
67 ret = run_command("bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} "
68 "${fdtcontroladdr}", 0);
71 return ret ? -EIO : 0;
74 static int qfw_bootmeth_bind(struct udevice *dev)
76 struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
78 plat->desc = "QEMU boot using firmware interface";
83 static struct bootmeth_ops qfw_bootmeth_ops = {
85 .read_bootflow = qfw_read_bootflow,
86 .read_file = qfw_read_file,
90 static const struct udevice_id qfw_bootmeth_ids[] = {
91 { .compatible = "u-boot,qfw-extlinux" },
95 U_BOOT_DRIVER(bootmeth_qfw) = {
96 .name = "bootmeth_qfw",
97 .id = UCLASS_BOOTMETH,
98 .of_match = qfw_bootmeth_ids,
99 .ops = &qfw_bootmeth_ops,
100 .bind = qfw_bootmeth_bind,