3 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
5 * SPDX-License-Identifier: GPL-2.0+
12 DECLARE_GLOBAL_DATA_PTR;
14 static const char **subcmd_list[] = {
16 [SPL_EXPORT_FDT] = (const char * []) {
17 #ifdef CONFIG_OF_LIBFDT
20 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
30 [SPL_EXPORT_ATAGS] = (const char * []) {
31 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
32 defined(CONFIG_CMDLINE_TAG) || \
33 defined(CONFIG_INITRD_TAG) || \
34 defined(CONFIG_SERIAL_TAG) || \
35 defined(CONFIG_REVISION_TAG)
38 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
50 /* Calls bootm with the parameters given */
51 static int call_bootm(int argc, char * const argv[], const char *subcommand[])
59 /* create paramter array */
60 bootm_argv[0] = "do_bootm";
63 bootm_argv[4] = argv[2]; /* fdt addr */
65 bootm_argv[3] = argv[1]; /* initrd addr */
67 bootm_argv[2] = argv[0]; /* kernel addr */
73 * exec subcommands of do_bootm to init the images
76 while (subcommand[i] != NULL) {
77 bootm_argv[1] = (char *)subcommand[i];
78 debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
79 for (j = 0; j < argc; j++)
80 debug("%s ", bootm_argv[j + 2]);
83 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
85 debug("Subcommand retcode: %d\n", ret);
90 printf("ERROR prep subcommand failed!\n");
97 static cmd_tbl_t cmd_spl_export_sub[] = {
98 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
99 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
102 static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
106 if (argc < 2) /* no subcommand */
107 return cmd_usage(cmdtp);
109 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
110 ARRAY_SIZE(cmd_spl_export_sub));
111 if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
114 if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
116 switch ((int)c->cmd) {
117 #ifdef CONFIG_OF_LIBFDT
119 printf("Argument image is now in RAM: 0x%p\n",
120 (void *)images.ft_addr);
121 env_set_addr("fdtargsaddr", images.ft_addr);
122 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
123 if (fdt_totalsize(images.ft_addr) >
124 CONFIG_CMD_SPL_WRITE_SIZE)
125 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
128 case SPL_EXPORT_ATAGS:
129 printf("Argument image is now in RAM at: 0x%p\n",
130 (void *)gd->bd->bi_boot_params);
134 /* Unrecognized command */
135 return cmd_usage(cmdtp);
141 static cmd_tbl_t cmd_spl_sub[] = {
142 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
145 static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
150 if (argc < 2) /* no subcommand */
151 return cmd_usage(cmdtp);
153 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
160 if (spl_export(cmdtp, flag, argc, argv))
161 printf("Subcommand failed\n");
164 /* unrecognized command */
165 return cmd_usage(cmdtp);
168 /* Unrecognized command */
169 return cmd_usage(cmdtp);
175 spl, 6 , 1, do_spl, "SPL configuration",
176 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
177 "\timg\t\t\"atags\" or \"fdt\"\n"
178 "\tkernel_addr\taddress where a kernel image is stored.\n"
179 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
180 "\tinitrd_addr\taddress of initial ramdisk\n"
181 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
182 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"