blob: 61256f4830f7ddd7e07297e0cb503eee2575f681 [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 */
53static int call_bootm(int argc, char * const argv[], const char *subcommand[])
54{
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
99static 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, "", ""),
102};
103
104static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
105{
106 const cmd_tbl_t *c;
107
108 if (argc < 2) /* no subcommand */
109 return cmd_usage(cmdtp);
110
111 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
112 ARRAY_SIZE(cmd_spl_export_sub));
York Sund1f2ee72017-08-15 11:14:42 -0700113 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
Simon Schwarz1648a372012-03-15 04:01:34 +0000114 argc -= 2;
115 argv += 2;
York Sund1f2ee72017-08-15 11:14:42 -0700116 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
Simon Schwarz1648a372012-03-15 04:01:34 +0000117 return -1;
York Sund1f2ee72017-08-15 11:14:42 -0700118 switch ((long)c->cmd) {
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000119#ifdef CONFIG_OF_LIBFDT
Simon Schwarz1648a372012-03-15 04:01:34 +0000120 case SPL_EXPORT_FDT:
121 printf("Argument image is now in RAM: 0x%p\n",
122 (void *)images.ft_addr);
Anatolij Gustschin767cb742017-08-17 21:01:48 +0200123 env_set_addr("fdtargsaddr", images.ft_addr);
124 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
York Sunb65ac632017-09-28 08:42:11 -0700125#ifdef CONFIG_CMD_SPL_WRITE_SIZE
Anatolij Gustschin767cb742017-08-17 21:01:48 +0200126 if (fdt_totalsize(images.ft_addr) >
127 CONFIG_CMD_SPL_WRITE_SIZE)
128 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
York Sunb65ac632017-09-28 08:42:11 -0700129#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000130 break;
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000131#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000132 case SPL_EXPORT_ATAGS:
133 printf("Argument image is now in RAM at: 0x%p\n",
134 (void *)gd->bd->bi_boot_params);
135 break;
136 }
137 } else {
138 /* Unrecognized command */
139 return cmd_usage(cmdtp);
140 }
141
142 return 0;
143}
144
145static cmd_tbl_t cmd_spl_sub[] = {
146 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
147};
148
149static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
150{
151 const cmd_tbl_t *c;
152 int cmd;
153
154 if (argc < 2) /* no subcommand */
155 return cmd_usage(cmdtp);
156
157 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
158 if (c) {
York Sund1f2ee72017-08-15 11:14:42 -0700159 cmd = (long)c->cmd;
Simon Schwarz1648a372012-03-15 04:01:34 +0000160 switch (cmd) {
161 case SPL_EXPORT:
162 argc--;
163 argv++;
164 if (spl_export(cmdtp, flag, argc, argv))
165 printf("Subcommand failed\n");
166 break;
167 default:
168 /* unrecognized command */
169 return cmd_usage(cmdtp);
170 }
171 } else {
172 /* Unrecognized command */
173 return cmd_usage(cmdtp);
174 }
175 return 0;
176}
177
178U_BOOT_CMD(
179 spl, 6 , 1, do_spl, "SPL configuration",
Stefano Babic28786eb2013-02-23 00:53:27 +0000180 "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"
187 );