1 // SPDX-License-Identifier: GPL-2.0+
12 #include <asm/global_data.h>
13 #include <linux/libfdt.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 static const char **subcmd_list[] = {
19 [SPL_EXPORT_FDT] = (const char * []) {
20 #ifdef CONFIG_OF_LIBFDT
23 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
33 [SPL_EXPORT_ATAGS] = (const char * []) {
34 #ifdef CONFIG_SUPPORT_PASSING_ATAGS
37 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
49 /* Calls bootm with the parameters given */
50 static int call_bootm(int argc, char *const argv[], const char *subcommand[])
58 /* create paramter array */
59 bootm_argv[0] = "do_bootm";
62 bootm_argv[4] = argv[2]; /* fdt addr */
64 bootm_argv[3] = argv[1]; /* initrd addr */
66 bootm_argv[2] = argv[0]; /* kernel addr */
71 * exec subcommands of do_bootm to init the images
74 while (subcommand[i] != NULL) {
75 bootm_argv[1] = (char *)subcommand[i];
76 debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
77 for (j = 0; j < argc; j++)
78 debug("%s ", bootm_argv[j + 2]);
81 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
83 debug("Subcommand retcode: %d\n", ret);
88 printf("ERROR prep subcommand failed!\n");
95 static struct cmd_tbl cmd_spl_export_sub[] = {
96 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
97 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
100 static int spl_export(struct cmd_tbl *cmdtp, int flag, int argc,
103 const struct cmd_tbl *c;
105 if (argc < 2) /* no subcommand */
106 return cmd_usage(cmdtp);
108 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
109 ARRAY_SIZE(cmd_spl_export_sub));
110 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
113 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
115 switch ((long)c->cmd) {
116 #ifdef CONFIG_OF_LIBFDT
118 printf("Argument image is now in RAM: 0x%p\n",
119 (void *)images.ft_addr);
120 env_set_addr("fdtargsaddr", images.ft_addr);
121 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
122 #ifdef CONFIG_CMD_SPL_WRITE_SIZE
123 if (fdt_totalsize(images.ft_addr) >
124 CONFIG_CMD_SPL_WRITE_SIZE)
125 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
129 case SPL_EXPORT_ATAGS:
130 printf("Argument image is now in RAM at: 0x%p\n",
131 (void *)gd->bd->bi_boot_params);
135 /* Unrecognized command */
136 return cmd_usage(cmdtp);
142 static struct cmd_tbl cmd_spl_sub[] = {
143 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
146 static int do_spl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
148 const struct cmd_tbl *c;
151 if (argc < 2) /* no subcommand */
152 return cmd_usage(cmdtp);
154 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
161 if (spl_export(cmdtp, flag, argc, argv))
162 printf("Subcommand failed\n");
165 /* unrecognized command */
166 return cmd_usage(cmdtp);
169 /* Unrecognized command */
170 return cmd_usage(cmdtp);
176 spl, 6 , 1, do_spl, "SPL configuration",
177 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
178 "\timg\t\t\"atags\" or \"fdt\"\n"
179 "\tkernel_addr\taddress where a kernel image is stored.\n"
180 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
181 "\tinitrd_addr\taddress of initial ramdisk\n"
182 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
183 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"