]> Git Repo - J-u-boot.git/blame - cmd/spl.c
abootimg: Add init_boot image support
[J-u-boot.git] / cmd / spl.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
1648a375
SS
2/*
3 * Copyright (C) 2011
4 * Corscience GmbH & Co. KG - Simon Schwarz <[email protected]>
1648a375
SS
5 */
6
1648a375
SS
7#include <command.h>
8#include <cmd_spl.h>
c7694dd4 9#include <env.h>
4d72caa5 10#include <image.h>
f7ae49fc 11#include <log.h>
401d1c4f 12#include <asm/global_data.h>
b08c8c48 13#include <linux/libfdt.h>
1648a375
SS
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static const char **subcmd_list[] = {
18
19 [SPL_EXPORT_FDT] = (const char * []) {
20#ifdef CONFIG_OF_LIBFDT
21 "start",
22 "loados",
23 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
24 "ramdisk",
25 #endif
26 "fdt",
27 "cmdline",
28 "bdt",
29 "prep",
30#endif
31 NULL,
32 },
33 [SPL_EXPORT_ATAGS] = (const char * []) {
6493fa4c 34#ifdef CONFIG_SUPPORT_PASSING_ATAGS
1648a375
SS
35 "start",
36 "loados",
37#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
38 "ramdisk",
39#endif
40 "cmdline",
41 "bdt",
42 "prep",
43#endif
44 NULL,
45 },
46 NULL
47};
48
49/* Calls bootm with the parameters given */
09140113 50static int call_bootm(int argc, char *const argv[], const char *subcommand[])
1648a375
SS
51{
52 char *bootm_argv[5];
53
54 int i = 0;
55 int ret = 0;
56 int j;
57
58 /* create paramter array */
59 bootm_argv[0] = "do_bootm";
60 switch (argc) {
61 case 3:
62 bootm_argv[4] = argv[2]; /* fdt addr */
63 case 2:
64 bootm_argv[3] = argv[1]; /* initrd addr */
65 case 1:
66 bootm_argv[2] = argv[0]; /* kernel addr */
67 }
68
69
70 /*
71 * - do the work -
72 * exec subcommands of do_bootm to init the images
73 * data structure
74 */
75 while (subcommand[i] != NULL) {
76 bootm_argv[1] = (char *)subcommand[i];
77 debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
78 for (j = 0; j < argc; j++)
79 debug("%s ", bootm_argv[j + 2]);
80 debug("\n");
81
82 ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
83 bootm_argv);
84 debug("Subcommand retcode: %d\n", ret);
85 i++;
86 }
87
88 if (ret) {
89 printf("ERROR prep subcommand failed!\n");
90 return -1;
91 }
92
93 return 0;
94}
95
09140113 96static struct cmd_tbl cmd_spl_export_sub[] = {
1648a375
SS
97 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
98 U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
99};
100
09140113
SG
101static int spl_export(struct cmd_tbl *cmdtp, int flag, int argc,
102 char *const argv[])
1648a375 103{
09140113 104 const struct cmd_tbl *c;
1648a375
SS
105
106 if (argc < 2) /* no subcommand */
107 return cmd_usage(cmdtp);
108
109 c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
110 ARRAY_SIZE(cmd_spl_export_sub));
d1f2ee70 111 if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
1648a375
SS
112 argc -= 2;
113 argv += 2;
d1f2ee70 114 if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
1648a375 115 return -1;
d1f2ee70 116 switch ((long)c->cmd) {
bf3d58bb 117#ifdef CONFIG_OF_LIBFDT
1648a375
SS
118 case SPL_EXPORT_FDT:
119 printf("Argument image is now in RAM: 0x%p\n",
120 (void *)images.ft_addr);
767cb74a
AG
121 env_set_addr("fdtargsaddr", images.ft_addr);
122 env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
b65ac633 123#ifdef CONFIG_CMD_SPL_WRITE_SIZE
767cb74a
AG
124 if (fdt_totalsize(images.ft_addr) >
125 CONFIG_CMD_SPL_WRITE_SIZE)
126 puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n");
b65ac633 127#endif
1648a375 128 break;
bf3d58bb 129#endif
1648a375
SS
130 case SPL_EXPORT_ATAGS:
131 printf("Argument image is now in RAM at: 0x%p\n",
132 (void *)gd->bd->bi_boot_params);
133 break;
134 }
135 } else {
136 /* Unrecognized command */
137 return cmd_usage(cmdtp);
138 }
139
140 return 0;
141}
142
09140113 143static struct cmd_tbl cmd_spl_sub[] = {
1648a375
SS
144 U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
145};
146
09140113 147static int do_spl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
1648a375 148{
09140113 149 const struct cmd_tbl *c;
1648a375
SS
150 int cmd;
151
152 if (argc < 2) /* no subcommand */
153 return cmd_usage(cmdtp);
154
155 c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
156 if (c) {
d1f2ee70 157 cmd = (long)c->cmd;
1648a375
SS
158 switch (cmd) {
159 case SPL_EXPORT:
160 argc--;
161 argv++;
162 if (spl_export(cmdtp, flag, argc, argv))
163 printf("Subcommand failed\n");
164 break;
165 default:
166 /* unrecognized command */
167 return cmd_usage(cmdtp);
168 }
169 } else {
170 /* Unrecognized command */
171 return cmd_usage(cmdtp);
172 }
173 return 0;
174}
175
176U_BOOT_CMD(
177 spl, 6 , 1, do_spl, "SPL configuration",
28786eb9
SB
178 "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
179 "\timg\t\t\"atags\" or \"fdt\"\n"
180 "\tkernel_addr\taddress where a kernel image is stored.\n"
181 "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
182 "\tinitrd_addr\taddress of initial ramdisk\n"
183 "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
184 "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
185 );
This page took 0.454529 seconds and 4 git commands to generate.