Blame view

cmd/spl.c 4.09 KB
1648a3750   Simon Schwarz   Add cmd_spl command
1
2
3
4
  /*
   * Copyright (C) 2011
   * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
1648a3750   Simon Schwarz   Add cmd_spl command
6
7
8
9
10
   */
  
  #include <common.h>
  #include <command.h>
  #include <cmd_spl.h>
b08c8c487   Masahiro Yamada   libfdt: move head...
11
  #include <linux/libfdt.h>
1648a3750   Simon Schwarz   Add cmd_spl command
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  
  DECLARE_GLOBAL_DATA_PTR;
  
  static const char **subcmd_list[] = {
  
  	[SPL_EXPORT_FDT] = (const char * []) {
  #ifdef CONFIG_OF_LIBFDT
  		"start",
  		"loados",
  	#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  		"ramdisk",
  	#endif
  		"fdt",
  		"cmdline",
  		"bdt",
  		"prep",
  #endif
  		NULL,
  	},
  	[SPL_EXPORT_ATAGS] = (const char * []) {
  #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  	defined(CONFIG_CMDLINE_TAG) || \
  	defined(CONFIG_INITRD_TAG) || \
  	defined(CONFIG_SERIAL_TAG) || \
  	defined(CONFIG_REVISION_TAG)
  		"start",
  		"loados",
  #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  		"ramdisk",
  #endif
  		"cmdline",
  		"bdt",
  		"prep",
  #endif
  		NULL,
  	},
  	NULL
  };
  
  /* Calls bootm with the parameters given */
  static int call_bootm(int argc, char * const argv[], const char *subcommand[])
  {
  	char *bootm_argv[5];
  
  	int i = 0;
  	int ret = 0;
  	int j;
  
  	/* create paramter array */
  	bootm_argv[0] = "do_bootm";
  	switch (argc) {
  	case 3:
  		bootm_argv[4] = argv[2]; /* fdt addr */
  	case 2:
  		bootm_argv[3] = argv[1]; /* initrd addr */
  	case 1:
  		bootm_argv[2] = argv[0]; /* kernel addr */
  	}
  
  
  	/*
  	 * - do the work -
  	 * exec subcommands of do_bootm to init the images
  	 * data structure
  	 */
  	while (subcommand[i] != NULL) {
  		bootm_argv[1] = (char *)subcommand[i];
  		debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
  		for (j = 0; j < argc; j++)
  			debug("%s ", bootm_argv[j + 2]);
  		debug("
  ");
  
  		ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
  			bootm_argv);
  		debug("Subcommand retcode: %d
  ", ret);
  		i++;
  	}
  
  	if (ret) {
  		printf("ERROR prep subcommand failed!
  ");
  		return -1;
  	}
  
  	return 0;
  }
  
  static cmd_tbl_t cmd_spl_export_sub[] = {
  	U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
  	U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
  };
  
  static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	const cmd_tbl_t *c;
  
  	if (argc < 2) /* no subcommand */
  		return cmd_usage(cmdtp);
  
  	c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
  		ARRAY_SIZE(cmd_spl_export_sub));
d1f2ee702   York Sun   cmd: spl: Fix com...
115
  	if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) {
1648a3750   Simon Schwarz   Add cmd_spl command
116
117
  		argc -= 2;
  		argv += 2;
d1f2ee702   York Sun   cmd: spl: Fix com...
118
  		if (call_bootm(argc, argv, subcmd_list[(long)c->cmd]))
1648a3750   Simon Schwarz   Add cmd_spl command
119
  			return -1;
d1f2ee702   York Sun   cmd: spl: Fix com...
120
  		switch ((long)c->cmd) {
bf3d58bb7   Łukasz Majewski   cmd:spl:fix: Prev...
121
  #ifdef CONFIG_OF_LIBFDT
1648a3750   Simon Schwarz   Add cmd_spl command
122
123
124
125
  		case SPL_EXPORT_FDT:
  			printf("Argument image is now in RAM: 0x%p
  ",
  				(void *)images.ft_addr);
767cb74a0   Anatolij Gustschin   cmd: spl: provide...
126
127
  			env_set_addr("fdtargsaddr", images.ft_addr);
  			env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr));
b65ac633f   York Sun   cmd: spl: fix com...
128
  #ifdef CONFIG_CMD_SPL_WRITE_SIZE
767cb74a0   Anatolij Gustschin   cmd: spl: provide...
129
130
131
132
  			if (fdt_totalsize(images.ft_addr) >
  			    CONFIG_CMD_SPL_WRITE_SIZE)
  				puts("WARN: FDT size > CMD_SPL_WRITE_SIZE
  ");
b65ac633f   York Sun   cmd: spl: fix com...
133
  #endif
1648a3750   Simon Schwarz   Add cmd_spl command
134
  			break;
bf3d58bb7   Łukasz Majewski   cmd:spl:fix: Prev...
135
  #endif
1648a3750   Simon Schwarz   Add cmd_spl command
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  		case SPL_EXPORT_ATAGS:
  			printf("Argument image is now in RAM at: 0x%p
  ",
  				(void *)gd->bd->bi_boot_params);
  			break;
  		}
  	} else {
  		/* Unrecognized command */
  		return cmd_usage(cmdtp);
  	}
  
  	return 0;
  }
  
  static cmd_tbl_t cmd_spl_sub[] = {
  	U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  };
  
  static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	const cmd_tbl_t *c;
  	int cmd;
  
  	if (argc < 2) /* no subcommand */
  		return cmd_usage(cmdtp);
  
  	c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
  	if (c) {
d1f2ee702   York Sun   cmd: spl: Fix com...
164
  		cmd = (long)c->cmd;
1648a3750   Simon Schwarz   Add cmd_spl command
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  		switch (cmd) {
  		case SPL_EXPORT:
  			argc--;
  			argv++;
  			if (spl_export(cmdtp, flag, argc, argv))
  				printf("Subcommand failed
  ");
  			break;
  		default:
  			/* unrecognized command */
  			return cmd_usage(cmdtp);
  		}
  	} else {
  		/* Unrecognized command */
  		return cmd_usage(cmdtp);
  	}
  	return 0;
  }
  
  U_BOOT_CMD(
  	spl, 6 , 1, do_spl, "SPL configuration",
28786eb96   Stefano Babic   SPL: Change descr...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  	"export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]
  "
  	"\timg\t\t\"atags\" or \"fdt\"
  "
  	"\tkernel_addr\taddress where a kernel image is stored.
  "
  	"\t\t\tkernel is loaded as part of the boot process, but it is not started.
  "
  	"\tinitrd_addr\taddress of initial ramdisk
  "
  	"\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.
  "
  	"\tfdt_addr\tin case of fdt, the address of the device tree.
  "
  	);