blob: b8e0aa4253984fa5ee7f76f3ac86954cb2542ca6 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Schwarz1648a372012-03-15 04:01:34 +00002/*
3 * Copyright (C) 2011
4 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
Simon Schwarz1648a372012-03-15 04:01:34 +00005 */
6
7#include <common.h>
8#include <command.h>
9#include <cmd_spl.h>
Simon Glassc7694dd2019-08-01 09:46:46 -060010#include <env.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060011#include <image.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090012#include <linux/libfdt.h>
Simon Schwarz1648a372012-03-15 04:01:34 +000013
14DECLARE_GLOBAL_DATA_PTR;
15
16static const char **subcmd_list[] = {
17
18 [SPL_EXPORT_FDT] = (const char * []) {
19#ifdef CONFIG_OF_LIBFDT
20 "start",
21 "loados",
22 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
23 "ramdisk",
24 #endif
25 "fdt",
26 "cmdline",
27 "bdt",
28 "prep",
29#endif
30 NULL,
31 },
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)
38 "start",
39 "loados",
40#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
41 "ramdisk",
42#endif
43 "cmdline",
44 "bdt",
45 "prep",
46#endif
47 NULL,
48 },
49 NULL
50};
51
52/* Calls bootm with the parameters given */
Simon Glass09140112020-05-10 11:40:03 -060053static int call_bootm(int argc, char *const argv[], const char *subcommand[])
Simon Schwarz1648a372012-03-15 04:01:34 +000054{
55 char *bootm_argv[5];
56
57 int i = 0;
58 int ret = 0;
59 int j;
60
61 /* create paramter array */
62 bootm_argv[0] = "do_bootm";
63 switch (argc) {
64 case 3:
65 bootm_argv[4] = argv[2]; /* fdt addr */
66 case 2:
67 bootm_argv[3] = argv[1]; /* initrd addr */
68 case 1:
69 bootm_argv[2] = argv[0]; /* kernel addr */
70 }
71
72
73 /*
74 * - do the work -
75 * exec subcommands of do_bootm to init the images
76 * data structure
77 */
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]);
83 debug("\n");
84
85 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
86 bootm_argv);
87 debug("Subcommand retcode: %d\n", ret);
88 i++;
89 }
90
91 if (ret) {
92 printf("ERROR prep subcommand failed!\n");
93 return -1;
94 }
95
96 return 0;
97}
98
Simon Glass09140112020-05-10 11:40:03 -060099static struct cmd_tbl cmd_spl_export_sub[] = {
Simon Schwarz1648a372012-03-15 04:01:34 +0000100 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
101 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
102};
103
Simon Glass09140112020-05-10 11:40:03 -0600104static int spl_export(struct cmd_tbl *cmdtp, int flag, int argc,
105 char *const argv[])
Simon Schwarz1648a372012-03-15 04:01:34 +0000106{
Simon Glass09140112020-05-10 11:40:03 -0600107 const struct cmd_tbl *c;
Simon Schwarz1648a372012-03-15 04:01:34 +0000108
109 if (argc < 2) /* no subcommand */
110 return cmd_usage(cmdtp);
111
112 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
113 ARRAY_SIZE(cmd_spl_export_sub));
York Sund1f2ee72017-08-15 11:14:42 -0700114 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
Simon Schwarz1648a372012-03-15 04:01:34 +0000115 argc -= 2;
116 argv += 2;
York Sund1f2ee72017-08-15 11:14:42 -0700117 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
Simon Schwarz1648a372012-03-15 04:01:34 +0000118 return -1;
York Sund1f2ee72017-08-15 11:14:42 -0700119 switch ((long)c->cmd) {
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000120#ifdef CONFIG_OF_LIBFDT
Simon Schwarz1648a372012-03-15 04:01:34 +0000121 case SPL_EXPORT_FDT:
122 printf("Argument image is now in RAM: 0x%p\n",
123 (void *)images.ft_addr);
Anatolij Gustschin767cb74a2017-08-17 21:01:48 +0200124 env_set_addr("fdtargsaddr", images.ft_addr);
125 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
York Sunb65ac632017-09-28 08:42:11 -0700126#ifdef CONFIG_CMD_SPL_WRITE_SIZE
Anatolij Gustschin767cb74a2017-08-17 21:01:48 +0200127 if (fdt_totalsize(images.ft_addr) >
128 CONFIG_CMD_SPL_WRITE_SIZE)
129 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
York Sunb65ac632017-09-28 08:42:11 -0700130#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000131 break;
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000132#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000133 case SPL_EXPORT_ATAGS:
134 printf("Argument image is now in RAM at: 0x%p\n",
135 (void *)gd->bd->bi_boot_params);
136 break;
137 }
138 } else {
139 /* Unrecognized command */
140 return cmd_usage(cmdtp);
141 }
142
143 return 0;
144}
145
Simon Glass09140112020-05-10 11:40:03 -0600146static struct cmd_tbl cmd_spl_sub[] = {
Simon Schwarz1648a372012-03-15 04:01:34 +0000147 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
148};
149
Simon Glass09140112020-05-10 11:40:03 -0600150static int do_spl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Schwarz1648a372012-03-15 04:01:34 +0000151{
Simon Glass09140112020-05-10 11:40:03 -0600152 const struct cmd_tbl *c;
Simon Schwarz1648a372012-03-15 04:01:34 +0000153 int cmd;
154
155 if (argc < 2) /* no subcommand */
156 return cmd_usage(cmdtp);
157
158 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
159 if (c) {
York Sund1f2ee72017-08-15 11:14:42 -0700160 cmd = (long)c->cmd;
Simon Schwarz1648a372012-03-15 04:01:34 +0000161 switch (cmd) {
162 case SPL_EXPORT:
163 argc--;
164 argv++;
165 if (spl_export(cmdtp, flag, argc, argv))
166 printf("Subcommand failed\n");
167 break;
168 default:
169 /* unrecognized command */
170 return cmd_usage(cmdtp);
171 }
172 } else {
173 /* Unrecognized command */
174 return cmd_usage(cmdtp);
175 }
176 return 0;
177}
178
179U_BOOT_CMD(
180 spl, 6 , 1, do_spl, "SPL configuration",
Stefano Babic28786eb2013-02-23 00:53:27 +0000181 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
182 "\timg\t\t\"atags\" or \"fdt\"\n"
183 "\tkernel_addr\taddress where a kernel image is stored.\n"
184 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
185 "\tinitrd_addr\taddress of initial ramdisk\n"
186 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
187 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
188 );