1 // SPDX-License-Identifier: GPL-2.0+
4 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
12 #include <linux/libfdt.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 static const char **subcmd_list[] = {
18 [SPL_EXPORT_FDT] = (const char * []) {
19 #ifdef CONFIG_OF_LIBFDT
22 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
32 [SPL_EXPORT_ATAGS] = (const char * []) {
33 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
34 defined(CONFIG_CMDLINE_TAG) || \
35 defined(CONFIG_INITRD_TAG) || \
36 defined(CONFIG_SERIAL_TAG) || \
37 defined(CONFIG_REVISION_TAG)
40 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
52 /* Calls bootm with the parameters given */
53 static int call_bootm(int argc, char * const argv[], const char *subcommand[])
61 /* create paramter array */
62 bootm_argv[0] = "do_bootm";
65 bootm_argv[4] = argv[2]; /* fdt addr */
67 bootm_argv[3] = argv[1]; /* initrd addr */
69 bootm_argv[2] = argv[0]; /* kernel addr */
75 * exec subcommands of do_bootm to init the images
78 while (subcommand[i] != NULL) {
79 bootm_argv[1] = (char *)subcommand[i];
80 debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
81 for (j = 0; j < argc; j++)
82 debug("%s ", bootm_argv[j + 2]);
85 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
87 debug("Subcommand retcode: %d\n", ret);
92 printf("ERROR prep subcommand failed!\n");
99 static cmd_tbl_t cmd_spl_export_sub[] = {
100 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
101 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
104 static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
108 if (argc < 2) /* no subcommand */
109 return cmd_usage(cmdtp);
111 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
112 ARRAY_SIZE(cmd_spl_export_sub));
113 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
116 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
118 switch ((long)c->cmd) {
119 #ifdef CONFIG_OF_LIBFDT
121 printf("Argument image is now in RAM: 0x%p\n",
122 (void *)images.ft_addr);
123 env_set_addr("fdtargsaddr", images.ft_addr);
124 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
125 #ifdef CONFIG_CMD_SPL_WRITE_SIZE
126 if (fdt_totalsize(images.ft_addr) >
127 CONFIG_CMD_SPL_WRITE_SIZE)
128 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
132 case SPL_EXPORT_ATAGS:
133 printf("Argument image is now in RAM at: 0x%p\n",
134 (void *)gd->bd->bi_boot_params);
138 /* Unrecognized command */
139 return cmd_usage(cmdtp);
145 static cmd_tbl_t cmd_spl_sub[] = {
146 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
149 static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
154 if (argc < 2) /* no subcommand */
155 return cmd_usage(cmdtp);
157 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
164 if (spl_export(cmdtp, flag, argc, argv))
165 printf("Subcommand failed\n");
168 /* unrecognized command */
169 return cmd_usage(cmdtp);
172 /* Unrecognized command */
173 return cmd_usage(cmdtp);
179 spl, 6 , 1, do_spl, "SPL configuration",
180 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
181 "\timg\t\t\"atags\" or \"fdt\"\n"
182 "\tkernel_addr\taddress where a kernel image is stored.\n"
183 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
184 "\tinitrd_addr\taddress of initial ramdisk\n"
185 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
186 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"