]> Git Repo - u-boot.git/blob - cmd/qfw.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / cmd / qfw.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2015 Miao Yan <[email protected]>
4  */
5
6 #include <command.h>
7 #include <env.h>
8 #include <errno.h>
9 #include <qfw.h>
10 #include <dm.h>
11
12 static struct udevice *qfw_dev;
13
14 static int qemu_fwcfg_cmd_list_firmware(void)
15 {
16         int ret;
17         struct fw_cfg_file_iter iter;
18         struct fw_file *file;
19
20         /* make sure fw_list is loaded */
21         ret = qfw_read_firmware_list(qfw_dev);
22         if (ret)
23                 return ret;
24
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);
29         }
30
31         return 0;
32 }
33
34 static int qemu_fwcfg_do_list(struct cmd_tbl *cmdtp, int flag,
35                               int argc, char *const argv[])
36 {
37         if (qemu_fwcfg_cmd_list_firmware() < 0)
38                 return CMD_RET_FAILURE;
39
40         return 0;
41 }
42
43 static int qemu_fwcfg_do_cpus(struct cmd_tbl *cmdtp, int flag,
44                               int argc, char *const argv[])
45 {
46         printf("%d cpu(s) online\n", qfw_online_cpus(qfw_dev));
47         return 0;
48 }
49
50 static int qemu_fwcfg_do_load(struct cmd_tbl *cmdtp, int flag,
51                               int argc, char *const argv[])
52 {
53         char *env;
54         ulong load_addr;
55         ulong initrd_addr;
56
57         env = env_get("loadaddr");
58         load_addr = env ?
59                 hextoul(env, NULL) :
60                 CONFIG_SYS_LOAD_ADDR;
61
62         env = env_get("ramdiskaddr");
63         initrd_addr = env ?
64                 hextoul(env, NULL) :
65 #ifdef CFG_RAMDISK_ADDR
66                 CFG_RAMDISK_ADDR;
67 #else
68                 0;
69 #endif
70
71         if (argc == 2) {
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);
76         }
77
78         if (!load_addr || !initrd_addr) {
79                 printf("missing load or initrd address\n");
80                 return CMD_RET_FAILURE;
81         }
82
83         return qemu_fwcfg_setup_kernel(qfw_dev, load_addr, initrd_addr);
84 }
85
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, "", ""),
90 };
91
92 static int do_qemu_fw(struct cmd_tbl *cmdtp, int flag, int argc,
93                       char *const argv[])
94 {
95         int ret;
96         struct cmd_tbl *fwcfg_cmd;
97
98         ret = qfw_get_dev(&qfw_dev);
99         if (ret) {
100                 printf("QEMU fw_cfg interface not found\n");
101                 return CMD_RET_USAGE;
102         }
103
104         fwcfg_cmd = find_cmd_tbl(argv[1], fwcfg_commands,
105                                  ARRAY_SIZE(fwcfg_commands));
106         argc -= 2;
107         argv += 2;
108         if (!fwcfg_cmd || argc > fwcfg_cmd->maxargs)
109                 return CMD_RET_USAGE;
110
111         ret = fwcfg_cmd->cmd(fwcfg_cmd, flag, argc, argv);
112
113         return cmd_process_error(fwcfg_cmd, ret);
114 }
115
116 U_BOOT_CMD(
117         qfw,    4,      1,      do_qemu_fw,
118         "QEMU firmware interface",
119         "<command>\n"
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"
123 );
This page took 0.033004 seconds and 4 git commands to generate.