blob: 56051b8a4be926c8882b7a7e4909816375bf84b0 [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>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Simon Schwarz1648a372012-03-15 04:01:34 +000012
13DECLARE_GLOBAL_DATA_PTR;
14
15static const char **subcmd_list[] = {
16
17 [SPL_EXPORT_FDT] = (const char * []) {
18#ifdef CONFIG_OF_LIBFDT
19 "start",
20 "loados",
21 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
22 "ramdisk",
23 #endif
24 "fdt",
25 "cmdline",
26 "bdt",
27 "prep",
28#endif
29 NULL,
30 },
31 [SPL_EXPORT_ATAGS] = (const char * []) {
32#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
33 defined(CONFIG_CMDLINE_TAG) || \
34 defined(CONFIG_INITRD_TAG) || \
35 defined(CONFIG_SERIAL_TAG) || \
36 defined(CONFIG_REVISION_TAG)
37 "start",
38 "loados",
39#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
40 "ramdisk",
41#endif
42 "cmdline",
43 "bdt",
44 "prep",
45#endif
46 NULL,
47 },
48 NULL
49};
50
51/* Calls bootm with the parameters given */
52static int call_bootm(int argc, char * const argv[], const char *subcommand[])
53{
54 char *bootm_argv[5];
55
56 int i = 0;
57 int ret = 0;
58 int j;
59
60 /* create paramter array */
61 bootm_argv[0] = "do_bootm";
62 switch (argc) {
63 case 3:
64 bootm_argv[4] = argv[2]; /* fdt addr */
65 case 2:
66 bootm_argv[3] = argv[1]; /* initrd addr */
67 case 1:
68 bootm_argv[2] = argv[0]; /* kernel addr */
69 }
70
71
72 /*
73 * - do the work -
74 * exec subcommands of do_bootm to init the images
75 * data structure
76 */
77 while (subcommand[i] != NULL) {
78 bootm_argv[1] = (char *)subcommand[i];
79 debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
80 for (j = 0; j < argc; j++)
81 debug("%s ", bootm_argv[j + 2]);
82 debug("\n");
83
84 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
85 bootm_argv);
86 debug("Subcommand retcode: %d\n", ret);
87 i++;
88 }
89
90 if (ret) {
91 printf("ERROR prep subcommand failed!\n");
92 return -1;
93 }
94
95 return 0;
96}
97
98static cmd_tbl_t cmd_spl_export_sub[] = {
99 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
100 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
101};
102
103static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
104{
105 const cmd_tbl_t *c;
106
107 if (argc < 2) /* no subcommand */
108 return cmd_usage(cmdtp);
109
110 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
111 ARRAY_SIZE(cmd_spl_export_sub));
York Sund1f2ee72017-08-15 11:14:42 -0700112 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
Simon Schwarz1648a372012-03-15 04:01:34 +0000113 argc -= 2;
114 argv += 2;
York Sund1f2ee72017-08-15 11:14:42 -0700115 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
Simon Schwarz1648a372012-03-15 04:01:34 +0000116 return -1;
York Sund1f2ee72017-08-15 11:14:42 -0700117 switch ((long)c->cmd) {
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000118#ifdef CONFIG_OF_LIBFDT
Simon Schwarz1648a372012-03-15 04:01:34 +0000119 case SPL_EXPORT_FDT:
120 printf("Argument image is now in RAM: 0x%p\n",
121 (void *)images.ft_addr);
Anatolij Gustschin767cb742017-08-17 21:01:48 +0200122 env_set_addr("fdtargsaddr", images.ft_addr);
123 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
York Sunb65ac632017-09-28 08:42:11 -0700124#ifdef CONFIG_CMD_SPL_WRITE_SIZE
Anatolij Gustschin767cb742017-08-17 21:01:48 +0200125 if (fdt_totalsize(images.ft_addr) >
126 CONFIG_CMD_SPL_WRITE_SIZE)
127 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
York Sunb65ac632017-09-28 08:42:11 -0700128#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000129 break;
Łukasz Majewskibf3d58b2012-12-06 05:23:38 +0000130#endif
Simon Schwarz1648a372012-03-15 04:01:34 +0000131 case SPL_EXPORT_ATAGS:
132 printf("Argument image is now in RAM at: 0x%p\n",
133 (void *)gd->bd->bi_boot_params);
134 break;
135 }
136 } else {
137 /* Unrecognized command */
138 return cmd_usage(cmdtp);
139 }
140
141 return 0;
142}
143
144static cmd_tbl_t cmd_spl_sub[] = {
145 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
146};
147
148static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
149{
150 const cmd_tbl_t *c;
151 int cmd;
152
153 if (argc < 2) /* no subcommand */
154 return cmd_usage(cmdtp);
155
156 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
157 if (c) {
York Sund1f2ee72017-08-15 11:14:42 -0700158 cmd = (long)c->cmd;
Simon Schwarz1648a372012-03-15 04:01:34 +0000159 switch (cmd) {
160 case SPL_EXPORT:
161 argc--;
162 argv++;
163 if (spl_export(cmdtp, flag, argc, argv))
164 printf("Subcommand failed\n");
165 break;
166 default:
167 /* unrecognized command */
168 return cmd_usage(cmdtp);
169 }
170 } else {
171 /* Unrecognized command */
172 return cmd_usage(cmdtp);
173 }
174 return 0;
175}
176
177U_BOOT_CMD(
178 spl, 6 , 1, do_spl, "SPL configuration",
Stefano Babic28786eb2013-02-23 00:53:27 +0000179 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
180 "\timg\t\t\"atags\" or \"fdt\"\n"
181 "\tkernel_addr\taddress where a kernel image is stored.\n"
182 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
183 "\tinitrd_addr\taddress of initial ramdisk\n"
184 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
185 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
186 );