blob: 0f5a87309d2a2e42cfd60d40183bf6662dbaf172 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassbace3d02011-10-03 19:26:45 +00002/*
Simon Glass6fb62072012-02-15 15:51:15 -08003 * Copyright (c) 2011-2012 The Chromium OS Authors.
Simon Glassbace3d02011-10-03 19:26:45 +00004 */
5
6#include <common.h>
Simon Glassd41b7032022-03-04 08:42:58 -07007#include <cli.h>
Simon Glass288b29e2019-11-14 12:57:43 -07008#include <command.h>
Heinrich Schuchardt9c547292020-12-02 16:22:11 +01009#include <efi_loader.h>
Simon Glass38068822015-05-04 11:31:08 -060010#include <errno.h>
Simon Glass42fdceb2022-03-04 08:43:04 -070011#include <event.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Patrick Delaunaya4918b22020-11-27 11:20:55 +010013#include <log.h>
Simon Glass5c2859c2013-11-10 10:27:03 -070014#include <os.h>
Simon Glass4209be32020-02-03 07:35:47 -070015#include <sort.h>
Simon Glass70db4212012-02-15 15:51:16 -080016#include <asm/getopt.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glass4d94dfa2014-07-10 22:23:27 -060018#include <asm/io.h>
Simon Glass3ff6fe52020-02-03 07:36:05 -070019#include <asm/malloc.h>
Simon Glass70db4212012-02-15 15:51:16 -080020#include <asm/sections.h>
Simon Glass6fb62072012-02-15 15:51:15 -080021#include <asm/state.h>
Simon Glassd41b7032022-03-04 08:42:58 -070022#include <dm/root.h>
Simon Glass4209be32020-02-03 07:35:47 -070023#include <linux/ctype.h>
Simon Glassbace3d02011-10-03 19:26:45 +000024
Simon Glass808434c2013-11-10 10:26:59 -070025DECLARE_GLOBAL_DATA_PTR;
26
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +010027static char **os_argv;
28
Simon Glass4209be32020-02-03 07:35:47 -070029/* Compare two options so that they can be sorted into alphabetical order */
30static int h_compare_opt(const void *p1, const void *p2)
31{
32 const struct sandbox_cmdline_option *opt1 = p1;
33 const struct sandbox_cmdline_option *opt2 = p2;
34 const char *str1, *str2;
35 char flag1[2], flag2[2];
36
37 opt1 = *(struct sandbox_cmdline_option **)p1;
38 opt2 = *(struct sandbox_cmdline_option **)p2;
39 flag1[1] = '\0';
40 flag2[1] = '\0';
41
42 *flag1 = opt1->flag_short < 0x100 ? opt1->flag_short : '\0';
43 *flag2 = opt2->flag_short < 0x100 ? opt2->flag_short : '\0';
44
45 str1 = *flag1 ? flag1 : opt1->flag;
46 str2 = *flag2 ? flag2 : opt2->flag;
47
48 /*
49 * Force lower-case flags to come before upper-case ones. We only
50 * support upper-case for short flags.
51 */
52 if (isalpha(*str1) && isalpha(*str2) &&
53 tolower(*str1) == tolower(*str2))
54 return isupper(*str1) - isupper(*str2);
55
56 return strcasecmp(str1, str2);
57}
58
Simon Glass70db4212012-02-15 15:51:16 -080059int sandbox_early_getopt_check(void)
60{
61 struct sandbox_state *state = state_get_current();
Marek BehĂșnd1f81fd2021-05-20 13:24:06 +020062 struct sandbox_cmdline_option **sb_opt =
63 __u_boot_sandbox_option_start();
Simon Glass70db4212012-02-15 15:51:16 -080064 size_t num_options = __u_boot_sandbox_option_count();
65 size_t i;
66 int max_arg_len, max_noarg_len;
Simon Glass4209be32020-02-03 07:35:47 -070067 struct sandbox_cmdline_option **sorted_opt;
68 int size;
Simon Glass70db4212012-02-15 15:51:16 -080069
70 /* parse_err will be a string of the faulting option */
71 if (!state->parse_err)
72 return 0;
73
74 if (strcmp(state->parse_err, "help")) {
75 printf("u-boot: error: failed while parsing option: %s\n"
76 "\ttry running with --help for more information.\n",
77 state->parse_err);
78 os_exit(1);
79 }
80
81 printf(
82 "u-boot, a command line test interface to U-Boot\n\n"
83 "Usage: u-boot [options]\n"
84 "Options:\n");
85
86 max_arg_len = 0;
87 for (i = 0; i < num_options; ++i)
Masahiro Yamadab4141192014-11-07 03:03:31 +090088 max_arg_len = max((int)strlen(sb_opt[i]->flag), max_arg_len);
Simon Glass70db4212012-02-15 15:51:16 -080089 max_noarg_len = max_arg_len + 7;
90
Simon Glass4209be32020-02-03 07:35:47 -070091 /* Sort the options */
92 size = sizeof(*sorted_opt) * num_options;
Simon Glassb308d9f2021-02-06 09:57:33 -070093 sorted_opt = os_malloc(size);
Simon Glass4209be32020-02-03 07:35:47 -070094 if (!sorted_opt) {
95 printf("No memory to sort options\n");
96 os_exit(1);
97 }
98 memcpy(sorted_opt, sb_opt, size);
99 qsort(sorted_opt, num_options, sizeof(*sorted_opt), h_compare_opt);
100
Simon Glass70db4212012-02-15 15:51:16 -0800101 for (i = 0; i < num_options; ++i) {
Simon Glass4209be32020-02-03 07:35:47 -0700102 struct sandbox_cmdline_option *opt = sorted_opt[i];
Simon Glass70db4212012-02-15 15:51:16 -0800103
104 /* first output the short flag if it has one */
105 if (opt->flag_short >= 0x100)
106 printf(" ");
107 else
108 printf(" -%c, ", opt->flag_short);
109
110 /* then the long flag */
111 if (opt->has_arg)
Simon Glass70db4212012-02-15 15:51:16 -0800112 printf("--%-*s <arg> ", max_arg_len, opt->flag);
Simon Glass6ebcab82013-11-10 10:26:58 -0700113 else
114 printf("--%-*s", max_noarg_len, opt->flag);
Simon Glass70db4212012-02-15 15:51:16 -0800115
116 /* finally the help text */
117 printf(" %s\n", opt->help);
118 }
119
120 os_exit(0);
121}
122
Simon Glass42fdceb2022-03-04 08:43:04 -0700123static int sandbox_misc_init_f(void *ctx, struct event *event)
Simon Glass68969772017-03-28 10:27:28 -0600124{
125 return sandbox_early_getopt_check();
126}
Simon Glass42fdceb2022-03-04 08:43:04 -0700127EVENT_SPY(EVT_MISC_INIT_F, sandbox_misc_init_f);
Simon Glass68969772017-03-28 10:27:28 -0600128
Simon Glass7b3efc62013-12-03 16:43:23 -0700129static int sandbox_cmdline_cb_help(struct sandbox_state *state, const char *arg)
Simon Glass70db4212012-02-15 15:51:16 -0800130{
131 /* just flag to sandbox_early_getopt_check to show usage */
132 return 1;
133}
Simon Glass7b3efc62013-12-03 16:43:23 -0700134SANDBOX_CMDLINE_OPT_SHORT(help, 'h', 0, "Display help");
Simon Glass70db4212012-02-15 15:51:16 -0800135
Simon Glassd0d07462016-07-04 11:57:50 -0600136#ifndef CONFIG_SPL_BUILD
Simon Glassab4e07e2012-02-26 17:38:50 -0500137int sandbox_main_loop_init(void)
138{
Simon Glass70db4212012-02-15 15:51:16 -0800139 struct sandbox_state *state = state_get_current();
140
141 /* Execute command if required */
Sjoerd Simonsebaa8322015-04-30 22:16:09 +0200142 if (state->cmd || state->run_distro_boot) {
143 int retval = 0;
Joe Hershberger88539e42015-02-06 15:37:31 -0600144
Rabin Vincent7dbcb762014-10-29 23:21:38 +0100145 cli_init();
146
Simon Glass2b6793d2016-03-13 19:07:30 -0600147#ifdef CONFIG_CMDLINE
Sjoerd Simonsebaa8322015-04-30 22:16:09 +0200148 if (state->cmd)
149 retval = run_command_list(state->cmd, -1, 0);
150
151 if (state->run_distro_boot)
152 retval = cli_simple_run_command("run distro_bootcmd",
153 0);
Simon Glass2b6793d2016-03-13 19:07:30 -0600154#endif
Simon Glassc5a62d42013-11-10 10:27:02 -0700155 if (!state->interactive)
Joe Hershberger88539e42015-02-06 15:37:31 -0600156 os_exit(retval);
Simon Glass70db4212012-02-15 15:51:16 -0800157 }
158
Simon Glassab4e07e2012-02-26 17:38:50 -0500159 return 0;
160}
Simon Glassd0d07462016-07-04 11:57:50 -0600161#endif
Simon Glassab4e07e2012-02-26 17:38:50 -0500162
Sjoerd Simonsebaa8322015-04-30 22:16:09 +0200163static int sandbox_cmdline_cb_boot(struct sandbox_state *state,
164 const char *arg)
165{
166 state->run_distro_boot = true;
167 return 0;
168}
169SANDBOX_CMDLINE_OPT_SHORT(boot, 'b', 0, "Run distro boot commands");
170
Simon Glass7b3efc62013-12-03 16:43:23 -0700171static int sandbox_cmdline_cb_command(struct sandbox_state *state,
172 const char *arg)
Simon Glass70db4212012-02-15 15:51:16 -0800173{
174 state->cmd = arg;
175 return 0;
176}
Simon Glass7b3efc62013-12-03 16:43:23 -0700177SANDBOX_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command");
Simon Glass70db4212012-02-15 15:51:16 -0800178
Simon Glass7b3efc62013-12-03 16:43:23 -0700179static int sandbox_cmdline_cb_fdt(struct sandbox_state *state, const char *arg)
Simon Glassf828bf22013-04-20 08:42:41 +0000180{
181 state->fdt_fname = arg;
182 return 0;
183}
Simon Glass7b3efc62013-12-03 16:43:23 -0700184SANDBOX_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT");
Simon Glassf828bf22013-04-20 08:42:41 +0000185
Simon Glass1f32ae92015-01-19 20:21:34 -0700186static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state,
187 const char *arg)
188{
189 const char *fmt = "%s.dtb";
190 char *fname;
191 int len;
192
193 len = strlen(state->argv[0]) + strlen(fmt) + 1;
Simon Glassb308d9f2021-02-06 09:57:33 -0700194 fname = os_malloc(len);
Simon Glass1f32ae92015-01-19 20:21:34 -0700195 if (!fname)
196 return -ENOMEM;
197 snprintf(fname, len, fmt, state->argv[0]);
198 state->fdt_fname = fname;
199
200 return 0;
201}
202SANDBOX_CMDLINE_OPT_SHORT(default_fdt, 'D', 0,
203 "Use the default u-boot.dtb control FDT in U-Boot directory");
204
Simon Glass189882c2019-09-25 08:56:07 -0600205static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,
206 const char *arg)
207{
208 const char *fmt = "/arch/sandbox/dts/test.dtb";
209 char *p;
210 char *fname;
211 int len;
212
213 len = strlen(state->argv[0]) + strlen(fmt) + 1;
Simon Glassb308d9f2021-02-06 09:57:33 -0700214 fname = os_malloc(len);
Simon Glass189882c2019-09-25 08:56:07 -0600215 if (!fname)
216 return -ENOMEM;
217 strcpy(fname, state->argv[0]);
218 p = strrchr(fname, '/');
219 if (!p)
220 p = fname + strlen(fname);
221 len -= p - fname;
Heinrich Schuchardtb680c5532020-12-25 16:04:26 +0100222 snprintf(p, len, fmt);
Simon Glass189882c2019-09-25 08:56:07 -0600223 state->fdt_fname = fname;
224
225 return 0;
226}
227SANDBOX_CMDLINE_OPT_SHORT(test_fdt, 'T', 0,
228 "Use the test.dtb control FDT in U-Boot directory");
229
Simon Glassc5a62d42013-11-10 10:27:02 -0700230static int sandbox_cmdline_cb_interactive(struct sandbox_state *state,
231 const char *arg)
232{
233 state->interactive = true;
234 return 0;
235}
236
237SANDBOX_CMDLINE_OPT_SHORT(interactive, 'i', 0, "Enter interactive mode");
238
Simon Glassbda77732014-02-27 13:26:16 -0700239static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
240 const char *arg)
241{
Simon Glassab839dc2014-02-27 13:26:23 -0700242 /* Remember to delete this U-Boot image later */
243 state->jumped_fname = arg;
Simon Glassbda77732014-02-27 13:26:16 -0700244
245 return 0;
246}
247SANDBOX_CMDLINE_OPT_SHORT(jump, 'j', 1, "Jumped from previous U-Boot");
248
Simon Glass5c2859c2013-11-10 10:27:03 -0700249static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
250 const char *arg)
251{
252 int err;
253
254 /* For now assume we always want to write it */
255 state->write_ram_buf = true;
256 state->ram_buf_fname = arg;
257
Simon Glassf80a8bb2014-11-11 12:47:08 -0700258 err = os_read_ram_buf(arg);
259 if (err) {
Simon Glass1c5a81d2018-10-01 11:55:12 -0600260 printf("Failed to read RAM buffer '%s': %d\n", arg, err);
Simon Glass5c2859c2013-11-10 10:27:03 -0700261 return err;
262 }
Simon Glassa65d1a02018-11-23 21:29:29 -0700263 state->ram_buf_read = true;
Simon Glass5c2859c2013-11-10 10:27:03 -0700264
265 return 0;
266}
267SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1,
268 "Read/write ram_buf memory contents from file");
269
Simon Glassab839dc2014-02-27 13:26:23 -0700270static int sandbox_cmdline_cb_rm_memory(struct sandbox_state *state,
271 const char *arg)
272{
273 state->ram_buf_rm = true;
274
275 return 0;
276}
277SANDBOX_CMDLINE_OPT(rm_memory, 0, "Remove memory file after reading");
278
Simon Glass1209e272013-11-10 10:27:04 -0700279static int sandbox_cmdline_cb_state(struct sandbox_state *state,
280 const char *arg)
281{
282 state->state_fname = arg;
283 return 0;
284}
285SANDBOX_CMDLINE_OPT_SHORT(state, 's', 1, "Specify the sandbox state FDT");
286
287static int sandbox_cmdline_cb_read(struct sandbox_state *state,
288 const char *arg)
289{
290 state->read_state = true;
291 return 0;
292}
293SANDBOX_CMDLINE_OPT_SHORT(read, 'r', 0, "Read the state FDT on startup");
294
295static int sandbox_cmdline_cb_write(struct sandbox_state *state,
296 const char *arg)
297{
298 state->write_state = true;
299 return 0;
300}
301SANDBOX_CMDLINE_OPT_SHORT(write, 'w', 0, "Write state FDT on exit");
302
303static int sandbox_cmdline_cb_ignore_missing(struct sandbox_state *state,
304 const char *arg)
305{
306 state->ignore_missing_state_on_read = true;
307 return 0;
308}
309SANDBOX_CMDLINE_OPT_SHORT(ignore_missing, 'n', 0,
310 "Ignore missing state on read");
311
Simon Glass7d95f2a2014-02-27 13:26:19 -0700312static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state,
313 const char *arg)
314{
315 state->show_lcd = true;
316 return 0;
317}
318SANDBOX_CMDLINE_OPT_SHORT(show_lcd, 'l', 0,
319 "Show the sandbox LCD display");
320
Simon Glass6be88c72020-02-03 07:36:13 -0700321static int sandbox_cmdline_cb_double_lcd(struct sandbox_state *state,
322 const char *arg)
323{
324 state->double_lcd = true;
325
326 return 0;
327}
328SANDBOX_CMDLINE_OPT_SHORT(double_lcd, 'K', 0,
329 "Double the LCD display size in each direction");
330
Simon Glassffb87902014-02-27 13:26:22 -0700331static const char *term_args[STATE_TERM_COUNT] = {
332 "raw-with-sigs",
333 "raw",
334 "cooked",
335};
336
337static int sandbox_cmdline_cb_terminal(struct sandbox_state *state,
338 const char *arg)
339{
340 int i;
341
342 for (i = 0; i < STATE_TERM_COUNT; i++) {
343 if (!strcmp(arg, term_args[i])) {
344 state->term_raw = i;
345 return 0;
346 }
347 }
348
349 printf("Unknown terminal setting '%s' (", arg);
350 for (i = 0; i < STATE_TERM_COUNT; i++)
351 printf("%s%s", i ? ", " : "", term_args[i]);
352 puts(")\n");
353
354 return 1;
355}
356SANDBOX_CMDLINE_OPT_SHORT(terminal, 't', 1,
357 "Set terminal to raw/cooked mode");
358
Simon Glass9ce8b402015-11-08 23:47:50 -0700359static int sandbox_cmdline_cb_verbose(struct sandbox_state *state,
360 const char *arg)
361{
362 state->show_test_output = true;
363 return 0;
364}
365SANDBOX_CMDLINE_OPT_SHORT(verbose, 'v', 0, "Show test output");
366
Simon Glass2b1dc292018-10-01 11:55:11 -0600367static int sandbox_cmdline_cb_log_level(struct sandbox_state *state,
368 const char *arg)
369{
370 state->default_log_level = simple_strtol(arg, NULL, 10);
371
372 return 0;
373}
374SANDBOX_CMDLINE_OPT_SHORT(log_level, 'L', 1,
375 "Set log level (0=panic, 7=debug)");
376
Simon Glassb25ff5c2020-10-25 20:38:28 -0600377static int sandbox_cmdline_cb_unittests(struct sandbox_state *state,
378 const char *arg)
379{
380 state->run_unittests = true;
381
382 return 0;
383}
384SANDBOX_CMDLINE_OPT_SHORT(unittests, 'u', 0, "Run unit tests");
385
Simon Glass22b29cc2020-10-25 20:38:33 -0600386static int sandbox_cmdline_cb_select_unittests(struct sandbox_state *state,
387 const char *arg)
388{
389 state->select_unittests = arg;
390
391 return 0;
392}
393SANDBOX_CMDLINE_OPT_SHORT(select_unittests, 'k', 1, "Select unit tests to run");
394
Simon Glass85f718f2021-03-22 18:21:01 +1300395static int sandbox_cmdline_cb_signals(struct sandbox_state *state,
396 const char *arg)
397{
398 state->handle_signals = true;
399
400 return 0;
401}
402SANDBOX_CMDLINE_OPT_SHORT(signals, 'S', 0,
403 "Handle signals (such as SIGSEGV) in sandbox");
404
Simon Glasscb897002021-07-24 15:14:39 -0600405static int sandbox_cmdline_cb_autoboot_keyed(struct sandbox_state *state,
406 const char *arg)
407{
408 state->autoboot_keyed = true;
409
410 return 0;
411}
412SANDBOX_CMDLINE_OPT(autoboot_keyed, 0, "Allow keyed autoboot");
413
Simon Glassbb967242017-03-28 10:27:16 -0600414static void setup_ram_buf(struct sandbox_state *state)
415{
Simon Glassa65d1a02018-11-23 21:29:29 -0700416 /* Zero the RAM buffer if we didn't read it, to keep valgrind happy */
Simon Glass5dbe7942019-04-08 13:20:43 -0600417 if (!state->ram_buf_read)
Simon Glassa65d1a02018-11-23 21:29:29 -0700418 memset(state->ram_buf, '\0', state->ram_size);
Simon Glassa65d1a02018-11-23 21:29:29 -0700419
Simon Glassbb967242017-03-28 10:27:16 -0600420 gd->arch.ram_buf = state->ram_buf;
421 gd->ram_size = state->ram_size;
422}
423
Simon Glassd66ddaf2018-11-15 18:44:03 -0700424void state_show(struct sandbox_state *state)
425{
426 char **p;
427
428 printf("Arguments:\n");
429 for (p = state->argv; *p; p++)
430 printf("%s ", *p);
431 printf("\n");
432}
433
Heinrich Schuchardt9c547292020-12-02 16:22:11 +0100434void __efi_runtime EFIAPI efi_reset_system(
435 enum efi_reset_type reset_type,
436 efi_status_t reset_status,
437 unsigned long data_size, void *reset_data)
438{
Heinrich Schuchardt7a001e02021-11-20 14:49:18 +0100439 if (reset_type == EFI_RESET_SHUTDOWN)
440 sandbox_exit();
441 else
442 sandbox_reset();
Heinrich Schuchardt9c547292020-12-02 16:22:11 +0100443}
444
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100445void sandbox_reset(void)
446{
447 /* Do this here while it still has an effect */
448 os_fd_restore();
449 if (state_uninit())
450 os_exit(2);
451
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100452 /* Restart U-Boot */
453 os_relaunch(os_argv);
454}
455
Simon Glassbace3d02011-10-03 19:26:45 +0000456int main(int argc, char *argv[])
457{
Simon Glass70db4212012-02-15 15:51:16 -0800458 struct sandbox_state *state;
Heinrich Schuchardt205b9f52021-05-15 19:29:13 +0200459 void * text_base;
Simon Glass4d94dfa2014-07-10 22:23:27 -0600460 gd_t data;
Simon Glassb308d9f2021-02-06 09:57:33 -0700461 int size;
Simon Glass1209e272013-11-10 10:27:04 -0700462 int ret;
Simon Glass6fb62072012-02-15 15:51:15 -0800463
Heinrich Schuchardt205b9f52021-05-15 19:29:13 +0200464 text_base = os_find_text_base();
465
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100466 /*
Heinrich Schuchardt3beba4a2021-05-11 21:03:16 +0200467 * This must be the first invocation of os_malloc() to have
468 * state->ram_buf in the low 4 GiB.
469 */
470 ret = state_init();
471 if (ret)
472 goto err;
473
474 /*
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100475 * Copy argv[] so that we can pass the arguments in the original
476 * sequence when resetting the sandbox.
477 */
Simon Glassb308d9f2021-02-06 09:57:33 -0700478 size = sizeof(char *) * (argc + 1);
479 os_argv = os_malloc(size);
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100480 if (!os_argv)
481 os_exit(1);
Simon Glassb308d9f2021-02-06 09:57:33 -0700482 memcpy(os_argv, argv, size);
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100483
Simon Glass001d1882019-04-08 13:20:41 -0600484 memset(&data, '\0', sizeof(data));
485 gd = &data;
Heinrich Schuchardt205b9f52021-05-15 19:29:13 +0200486 gd->arch.text_base = text_base;
Simon Glass001d1882019-04-08 13:20:41 -0600487
Simon Glass70db4212012-02-15 15:51:16 -0800488 state = state_get_current();
489 if (os_parse_args(state, argc, argv))
490 return 1;
491
Patrick Delaunay10bb90f2020-11-20 09:48:33 +0100492 /* Remove old memory file if required */
493 if (state->ram_buf_rm && state->ram_buf_fname) {
494 os_unlink(state->ram_buf_fname);
495 state->write_ram_buf = false;
496 state->ram_buf_fname = NULL;
497 }
498
Simon Glass1209e272013-11-10 10:27:04 -0700499 ret = sandbox_read_state(state, state->state_fname);
500 if (ret)
501 goto err;
502
Simon Glass85f718f2021-03-22 18:21:01 +1300503 if (state->handle_signals) {
504 ret = os_setup_signal_handlers();
505 if (ret)
506 goto err;
507 }
Heinrich Schuchardtb46f30a2020-11-12 00:29:56 +0100508
Andy Yan1fc50d72017-07-24 17:49:59 +0800509#if CONFIG_VAL(SYS_MALLOC_F_LEN)
Simon Glass29afe9e2014-07-10 22:23:31 -0600510 gd->malloc_base = CONFIG_MALLOC_F_ADDR;
511#endif
Simon Glass2b1dc292018-10-01 11:55:11 -0600512#if CONFIG_IS_ENABLED(LOG)
513 gd->default_log_level = state->default_log_level;
514#endif
Simon Glassbb967242017-03-28 10:27:16 -0600515 setup_ram_buf(state);
Simon Glass4d94dfa2014-07-10 22:23:27 -0600516
Simon Glass001d1882019-04-08 13:20:41 -0600517 /*
518 * Set up the relocation offset here, since sandbox symbols are always
519 * relocated by the OS before sandbox is entered.
520 */
521 gd->reloc_off = (ulong)gd->arch.text_base;
522
Patrick Delaunaya4918b22020-11-27 11:20:55 +0100523 /* sandbox test: log functions called before log_init in board_init_f */
Patrick Delaunaya4918b22020-11-27 11:20:55 +0100524 log_debug("debug: %s\n", __func__);
525
Simon Glass808434c2013-11-10 10:26:59 -0700526 /* Do pre- and post-relocation init */
Simon Glassbace3d02011-10-03 19:26:45 +0000527 board_init_f(0);
Allen Martin8ec21bb2013-01-22 13:11:21 +0000528
Simon Glass808434c2013-11-10 10:26:59 -0700529 board_init_r(gd->new_gd, 0);
530
531 /* NOTREACHED - board_init_r() does not return */
Allen Martin8ec21bb2013-01-22 13:11:21 +0000532 return 0;
Simon Glass1209e272013-11-10 10:27:04 -0700533
534err:
535 printf("Error %d\n", ret);
536 return 1;
Simon Glassbace3d02011-10-03 19:26:45 +0000537}