1 // SPDX-License-Identifier: GPL-2.0+
12 static struct udevice *qfw_dev;
14 static int qemu_fwcfg_cmd_list_firmware(void)
17 struct fw_cfg_file_iter iter;
20 /* make sure fw_list is loaded */
21 ret = qfw_read_firmware_list(qfw_dev);
25 for (file = qfw_file_iter_init(qfw_dev, &iter);
26 !qfw_file_iter_end(&iter);
27 file = qfw_file_iter_next(&iter)) {
28 printf("%08lx %-56s\n", file->addr, file->cfg.name);
34 static int qemu_fwcfg_do_list(struct cmd_tbl *cmdtp, int flag,
35 int argc, char *const argv[])
37 if (qemu_fwcfg_cmd_list_firmware() < 0)
38 return CMD_RET_FAILURE;
43 static int qemu_fwcfg_do_cpus(struct cmd_tbl *cmdtp, int flag,
44 int argc, char *const argv[])
46 printf("%d cpu(s) online\n", qfw_online_cpus(qfw_dev));
50 static int qemu_fwcfg_do_load(struct cmd_tbl *cmdtp, int flag,
51 int argc, char *const argv[])
57 env = env_get("loadaddr");
62 env = env_get("ramdiskaddr");
65 #ifdef CFG_RAMDISK_ADDR
72 load_addr = hextoul(argv[0], NULL);
73 initrd_addr = hextoul(argv[1], NULL);
74 } else if (argc == 1) {
75 load_addr = hextoul(argv[0], NULL);
78 if (!load_addr || !initrd_addr) {
79 printf("missing load or initrd address\n");
80 return CMD_RET_FAILURE;
83 return qemu_fwcfg_setup_kernel(qfw_dev, load_addr, initrd_addr);
86 static struct cmd_tbl fwcfg_commands[] = {
87 U_BOOT_CMD_MKENT(list, 0, 1, qemu_fwcfg_do_list, "", ""),
88 U_BOOT_CMD_MKENT(cpus, 0, 1, qemu_fwcfg_do_cpus, "", ""),
89 U_BOOT_CMD_MKENT(load, 2, 1, qemu_fwcfg_do_load, "", ""),
92 static int do_qemu_fw(struct cmd_tbl *cmdtp, int flag, int argc,
96 struct cmd_tbl *fwcfg_cmd;
98 ret = qfw_get_dev(&qfw_dev);
100 printf("QEMU fw_cfg interface not found\n");
101 return CMD_RET_USAGE;
104 fwcfg_cmd = find_cmd_tbl(argv[1], fwcfg_commands,
105 ARRAY_SIZE(fwcfg_commands));
108 if (!fwcfg_cmd || argc > fwcfg_cmd->maxargs)
109 return CMD_RET_USAGE;
111 ret = fwcfg_cmd->cmd(fwcfg_cmd, flag, argc, argv);
113 return cmd_process_error(fwcfg_cmd, ret);
117 qfw, 4, 1, do_qemu_fw,
118 "QEMU firmware interface",
120 " - list : print firmware(s) currently loaded\n"
121 " - cpus : print online cpu number\n"
122 " - load <kernel addr> <initrd addr> : load kernel and initrd (if any), and setup for zboot\n"