Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 2 | /* |
Simon Glass | 20bf89a | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012 The Chromium OS Authors. |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 07a3b23 | 2015-05-04 11:31:08 -0600 | [diff] [blame] | 8 | #include <errno.h> |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 9 | #include <os.h> |
Rabin Vincent | 7e0194a | 2014-10-29 23:21:38 +0100 | [diff] [blame] | 10 | #include <cli.h> |
Simon Glass | 8e17078 | 2015-01-19 20:21:34 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 12 | #include <asm/getopt.h> |
Simon Glass | c395fdf | 2014-07-10 22:23:27 -0600 | [diff] [blame] | 13 | #include <asm/io.h> |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 14 | #include <asm/sections.h> |
Simon Glass | 20bf89a | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 15 | #include <asm/state.h> |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 16 | |
Simon Glass | 2fd34e6 | 2013-11-10 10:26:59 -0700 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 19 | int sandbox_early_getopt_check(void) |
| 20 | { |
| 21 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 22 | struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start; |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 23 | size_t num_options = __u_boot_sandbox_option_count(); |
| 24 | size_t i; |
| 25 | int max_arg_len, max_noarg_len; |
| 26 | |
| 27 | /* parse_err will be a string of the faulting option */ |
| 28 | if (!state->parse_err) |
| 29 | return 0; |
| 30 | |
| 31 | if (strcmp(state->parse_err, "help")) { |
| 32 | printf("u-boot: error: failed while parsing option: %s\n" |
| 33 | "\ttry running with --help for more information.\n", |
| 34 | state->parse_err); |
| 35 | os_exit(1); |
| 36 | } |
| 37 | |
| 38 | printf( |
| 39 | "u-boot, a command line test interface to U-Boot\n\n" |
| 40 | "Usage: u-boot [options]\n" |
| 41 | "Options:\n"); |
| 42 | |
| 43 | max_arg_len = 0; |
| 44 | for (i = 0; i < num_options; ++i) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 45 | max_arg_len = max((int)strlen(sb_opt[i]->flag), max_arg_len); |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 46 | max_noarg_len = max_arg_len + 7; |
| 47 | |
| 48 | for (i = 0; i < num_options; ++i) { |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 49 | struct sandbox_cmdline_option *opt = sb_opt[i]; |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 50 | |
| 51 | /* first output the short flag if it has one */ |
| 52 | if (opt->flag_short >= 0x100) |
| 53 | printf(" "); |
| 54 | else |
| 55 | printf(" -%c, ", opt->flag_short); |
| 56 | |
| 57 | /* then the long flag */ |
| 58 | if (opt->has_arg) |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 59 | printf("--%-*s <arg> ", max_arg_len, opt->flag); |
Simon Glass | 5f679f0 | 2013-11-10 10:26:58 -0700 | [diff] [blame] | 60 | else |
| 61 | printf("--%-*s", max_noarg_len, opt->flag); |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 62 | |
| 63 | /* finally the help text */ |
| 64 | printf(" %s\n", opt->help); |
| 65 | } |
| 66 | |
| 67 | os_exit(0); |
| 68 | } |
| 69 | |
Simon Glass | b419dbb | 2017-03-28 10:27:28 -0600 | [diff] [blame] | 70 | int misc_init_f(void) |
| 71 | { |
| 72 | return sandbox_early_getopt_check(); |
| 73 | } |
| 74 | |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 75 | static int sandbox_cmdline_cb_help(struct sandbox_state *state, const char *arg) |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 76 | { |
| 77 | /* just flag to sandbox_early_getopt_check to show usage */ |
| 78 | return 1; |
| 79 | } |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 80 | SANDBOX_CMDLINE_OPT_SHORT(help, 'h', 0, "Display help"); |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 81 | |
Simon Glass | 5cf1663 | 2016-07-04 11:57:50 -0600 | [diff] [blame] | 82 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 0fc3c22 | 2012-02-26 17:38:50 -0500 | [diff] [blame] | 83 | int sandbox_main_loop_init(void) |
| 84 | { |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 85 | struct sandbox_state *state = state_get_current(); |
| 86 | |
| 87 | /* Execute command if required */ |
Sjoerd Simons | 335f470 | 2015-04-30 22:16:09 +0200 | [diff] [blame] | 88 | if (state->cmd || state->run_distro_boot) { |
| 89 | int retval = 0; |
Joe Hershberger | 744d788 | 2015-02-06 15:37:31 -0600 | [diff] [blame] | 90 | |
Rabin Vincent | 7e0194a | 2014-10-29 23:21:38 +0100 | [diff] [blame] | 91 | cli_init(); |
| 92 | |
Simon Glass | e0f1280 | 2016-03-13 19:07:30 -0600 | [diff] [blame] | 93 | #ifdef CONFIG_CMDLINE |
Sjoerd Simons | 335f470 | 2015-04-30 22:16:09 +0200 | [diff] [blame] | 94 | if (state->cmd) |
| 95 | retval = run_command_list(state->cmd, -1, 0); |
| 96 | |
| 97 | if (state->run_distro_boot) |
| 98 | retval = cli_simple_run_command("run distro_bootcmd", |
| 99 | 0); |
Simon Glass | e0f1280 | 2016-03-13 19:07:30 -0600 | [diff] [blame] | 100 | #endif |
Simon Glass | f498e43 | 2013-11-10 10:27:02 -0700 | [diff] [blame] | 101 | if (!state->interactive) |
Joe Hershberger | 744d788 | 2015-02-06 15:37:31 -0600 | [diff] [blame] | 102 | os_exit(retval); |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Sjoerd Simons | 335f470 | 2015-04-30 22:16:09 +0200 | [diff] [blame] | 105 | return 0; |
| 106 | } |
Simon Glass | 5cf1663 | 2016-07-04 11:57:50 -0600 | [diff] [blame] | 107 | #endif |
Sjoerd Simons | 335f470 | 2015-04-30 22:16:09 +0200 | [diff] [blame] | 108 | |
| 109 | static int sandbox_cmdline_cb_boot(struct sandbox_state *state, |
| 110 | const char *arg) |
| 111 | { |
| 112 | state->run_distro_boot = true; |
Simon Glass | 0fc3c22 | 2012-02-26 17:38:50 -0500 | [diff] [blame] | 113 | return 0; |
| 114 | } |
Sjoerd Simons | 335f470 | 2015-04-30 22:16:09 +0200 | [diff] [blame] | 115 | SANDBOX_CMDLINE_OPT_SHORT(boot, 'b', 0, "Run distro boot commands"); |
Simon Glass | 0fc3c22 | 2012-02-26 17:38:50 -0500 | [diff] [blame] | 116 | |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 117 | static int sandbox_cmdline_cb_command(struct sandbox_state *state, |
| 118 | const char *arg) |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 119 | { |
| 120 | state->cmd = arg; |
| 121 | return 0; |
| 122 | } |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 123 | SANDBOX_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command"); |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 124 | |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 125 | static int sandbox_cmdline_cb_fdt(struct sandbox_state *state, const char *arg) |
Simon Glass | 1539343 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 126 | { |
| 127 | state->fdt_fname = arg; |
| 128 | return 0; |
| 129 | } |
Simon Glass | 64367c8 | 2013-12-03 16:43:23 -0700 | [diff] [blame] | 130 | SANDBOX_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT"); |
Simon Glass | 1539343 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 131 | |
Simon Glass | 8e17078 | 2015-01-19 20:21:34 -0700 | [diff] [blame] | 132 | static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state, |
| 133 | const char *arg) |
| 134 | { |
| 135 | const char *fmt = "%s.dtb"; |
| 136 | char *fname; |
| 137 | int len; |
| 138 | |
| 139 | len = strlen(state->argv[0]) + strlen(fmt) + 1; |
| 140 | fname = os_malloc(len); |
| 141 | if (!fname) |
| 142 | return -ENOMEM; |
| 143 | snprintf(fname, len, fmt, state->argv[0]); |
| 144 | state->fdt_fname = fname; |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | SANDBOX_CMDLINE_OPT_SHORT(default_fdt, 'D', 0, |
| 149 | "Use the default u-boot.dtb control FDT in U-Boot directory"); |
| 150 | |
Simon Glass | 3c3968f | 2019-09-25 08:56:07 -0600 | [diff] [blame] | 151 | static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state, |
| 152 | const char *arg) |
| 153 | { |
| 154 | const char *fmt = "/arch/sandbox/dts/test.dtb"; |
| 155 | char *p; |
| 156 | char *fname; |
| 157 | int len; |
| 158 | |
| 159 | len = strlen(state->argv[0]) + strlen(fmt) + 1; |
| 160 | fname = os_malloc(len); |
| 161 | if (!fname) |
| 162 | return -ENOMEM; |
| 163 | strcpy(fname, state->argv[0]); |
| 164 | p = strrchr(fname, '/'); |
| 165 | if (!p) |
| 166 | p = fname + strlen(fname); |
| 167 | len -= p - fname; |
| 168 | snprintf(p, len, fmt, p); |
| 169 | state->fdt_fname = fname; |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | SANDBOX_CMDLINE_OPT_SHORT(test_fdt, 'T', 0, |
| 174 | "Use the test.dtb control FDT in U-Boot directory"); |
| 175 | |
Simon Glass | f498e43 | 2013-11-10 10:27:02 -0700 | [diff] [blame] | 176 | static int sandbox_cmdline_cb_interactive(struct sandbox_state *state, |
| 177 | const char *arg) |
| 178 | { |
| 179 | state->interactive = true; |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | SANDBOX_CMDLINE_OPT_SHORT(interactive, 'i', 0, "Enter interactive mode"); |
| 184 | |
Simon Glass | e990653 | 2014-02-27 13:26:16 -0700 | [diff] [blame] | 185 | static int sandbox_cmdline_cb_jump(struct sandbox_state *state, |
| 186 | const char *arg) |
| 187 | { |
Simon Glass | 47acfc6 | 2014-02-27 13:26:23 -0700 | [diff] [blame] | 188 | /* Remember to delete this U-Boot image later */ |
| 189 | state->jumped_fname = arg; |
Simon Glass | e990653 | 2014-02-27 13:26:16 -0700 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | SANDBOX_CMDLINE_OPT_SHORT(jump, 'j', 1, "Jumped from previous U-Boot"); |
| 194 | |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 195 | static int sandbox_cmdline_cb_memory(struct sandbox_state *state, |
| 196 | const char *arg) |
| 197 | { |
| 198 | int err; |
| 199 | |
| 200 | /* For now assume we always want to write it */ |
| 201 | state->write_ram_buf = true; |
| 202 | state->ram_buf_fname = arg; |
| 203 | |
Simon Glass | c043e03 | 2014-11-11 12:47:08 -0700 | [diff] [blame] | 204 | err = os_read_ram_buf(arg); |
| 205 | if (err) { |
Simon Glass | 332894d | 2018-10-01 11:55:12 -0600 | [diff] [blame] | 206 | printf("Failed to read RAM buffer '%s': %d\n", arg, err); |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 207 | return err; |
| 208 | } |
Simon Glass | 24a284a | 2018-11-23 21:29:29 -0700 | [diff] [blame] | 209 | state->ram_buf_read = true; |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1, |
| 214 | "Read/write ram_buf memory contents from file"); |
| 215 | |
Simon Glass | 47acfc6 | 2014-02-27 13:26:23 -0700 | [diff] [blame] | 216 | static int sandbox_cmdline_cb_rm_memory(struct sandbox_state *state, |
| 217 | const char *arg) |
| 218 | { |
| 219 | state->ram_buf_rm = true; |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | SANDBOX_CMDLINE_OPT(rm_memory, 0, "Remove memory file after reading"); |
| 224 | |
Simon Glass | d7c8d8d | 2013-11-10 10:27:04 -0700 | [diff] [blame] | 225 | static int sandbox_cmdline_cb_state(struct sandbox_state *state, |
| 226 | const char *arg) |
| 227 | { |
| 228 | state->state_fname = arg; |
| 229 | return 0; |
| 230 | } |
| 231 | SANDBOX_CMDLINE_OPT_SHORT(state, 's', 1, "Specify the sandbox state FDT"); |
| 232 | |
| 233 | static int sandbox_cmdline_cb_read(struct sandbox_state *state, |
| 234 | const char *arg) |
| 235 | { |
| 236 | state->read_state = true; |
| 237 | return 0; |
| 238 | } |
| 239 | SANDBOX_CMDLINE_OPT_SHORT(read, 'r', 0, "Read the state FDT on startup"); |
| 240 | |
| 241 | static int sandbox_cmdline_cb_write(struct sandbox_state *state, |
| 242 | const char *arg) |
| 243 | { |
| 244 | state->write_state = true; |
| 245 | return 0; |
| 246 | } |
| 247 | SANDBOX_CMDLINE_OPT_SHORT(write, 'w', 0, "Write state FDT on exit"); |
| 248 | |
| 249 | static int sandbox_cmdline_cb_ignore_missing(struct sandbox_state *state, |
| 250 | const char *arg) |
| 251 | { |
| 252 | state->ignore_missing_state_on_read = true; |
| 253 | return 0; |
| 254 | } |
| 255 | SANDBOX_CMDLINE_OPT_SHORT(ignore_missing, 'n', 0, |
| 256 | "Ignore missing state on read"); |
| 257 | |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 258 | static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state, |
| 259 | const char *arg) |
| 260 | { |
| 261 | state->show_lcd = true; |
| 262 | return 0; |
| 263 | } |
| 264 | SANDBOX_CMDLINE_OPT_SHORT(show_lcd, 'l', 0, |
| 265 | "Show the sandbox LCD display"); |
| 266 | |
Simon Glass | 678ef47 | 2014-02-27 13:26:22 -0700 | [diff] [blame] | 267 | static const char *term_args[STATE_TERM_COUNT] = { |
| 268 | "raw-with-sigs", |
| 269 | "raw", |
| 270 | "cooked", |
| 271 | }; |
| 272 | |
| 273 | static int sandbox_cmdline_cb_terminal(struct sandbox_state *state, |
| 274 | const char *arg) |
| 275 | { |
| 276 | int i; |
| 277 | |
| 278 | for (i = 0; i < STATE_TERM_COUNT; i++) { |
| 279 | if (!strcmp(arg, term_args[i])) { |
| 280 | state->term_raw = i; |
| 281 | return 0; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | printf("Unknown terminal setting '%s' (", arg); |
| 286 | for (i = 0; i < STATE_TERM_COUNT; i++) |
| 287 | printf("%s%s", i ? ", " : "", term_args[i]); |
| 288 | puts(")\n"); |
| 289 | |
| 290 | return 1; |
| 291 | } |
| 292 | SANDBOX_CMDLINE_OPT_SHORT(terminal, 't', 1, |
| 293 | "Set terminal to raw/cooked mode"); |
| 294 | |
Simon Glass | fe6d12a | 2015-11-08 23:47:50 -0700 | [diff] [blame] | 295 | static int sandbox_cmdline_cb_verbose(struct sandbox_state *state, |
| 296 | const char *arg) |
| 297 | { |
| 298 | state->show_test_output = true; |
| 299 | return 0; |
| 300 | } |
| 301 | SANDBOX_CMDLINE_OPT_SHORT(verbose, 'v', 0, "Show test output"); |
| 302 | |
Simon Glass | 4e9a64d | 2018-10-01 11:55:11 -0600 | [diff] [blame] | 303 | static int sandbox_cmdline_cb_log_level(struct sandbox_state *state, |
| 304 | const char *arg) |
| 305 | { |
| 306 | state->default_log_level = simple_strtol(arg, NULL, 10); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | SANDBOX_CMDLINE_OPT_SHORT(log_level, 'L', 1, |
| 311 | "Set log level (0=panic, 7=debug)"); |
| 312 | |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 313 | static int sandbox_cmdline_cb_show_of_platdata(struct sandbox_state *state, |
| 314 | const char *arg) |
| 315 | { |
| 316 | state->show_of_platdata = true; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | SANDBOX_CMDLINE_OPT(show_of_platdata, 0, "Show of-platdata in SPL"); |
| 321 | |
Simon Glass | e0f1280 | 2016-03-13 19:07:30 -0600 | [diff] [blame] | 322 | int board_run_command(const char *cmdline) |
| 323 | { |
| 324 | printf("## Commands are disabled. Please enable CONFIG_CMDLINE.\n"); |
| 325 | |
| 326 | return 1; |
| 327 | } |
| 328 | |
Simon Glass | b94eed5 | 2017-03-28 10:27:16 -0600 | [diff] [blame] | 329 | static void setup_ram_buf(struct sandbox_state *state) |
| 330 | { |
Simon Glass | 24a284a | 2018-11-23 21:29:29 -0700 | [diff] [blame] | 331 | /* Zero the RAM buffer if we didn't read it, to keep valgrind happy */ |
Simon Glass | cd3705e | 2019-04-08 13:20:43 -0600 | [diff] [blame] | 332 | if (!state->ram_buf_read) |
Simon Glass | 24a284a | 2018-11-23 21:29:29 -0700 | [diff] [blame] | 333 | memset(state->ram_buf, '\0', state->ram_size); |
Simon Glass | 24a284a | 2018-11-23 21:29:29 -0700 | [diff] [blame] | 334 | |
Simon Glass | b94eed5 | 2017-03-28 10:27:16 -0600 | [diff] [blame] | 335 | gd->arch.ram_buf = state->ram_buf; |
| 336 | gd->ram_size = state->ram_size; |
| 337 | } |
| 338 | |
Simon Glass | 46508c9 | 2018-11-15 18:44:03 -0700 | [diff] [blame] | 339 | void state_show(struct sandbox_state *state) |
| 340 | { |
| 341 | char **p; |
| 342 | |
| 343 | printf("Arguments:\n"); |
| 344 | for (p = state->argv; *p; p++) |
| 345 | printf("%s ", *p); |
| 346 | printf("\n"); |
| 347 | } |
| 348 | |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 349 | int main(int argc, char *argv[]) |
| 350 | { |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 351 | struct sandbox_state *state; |
Simon Glass | c395fdf | 2014-07-10 22:23:27 -0600 | [diff] [blame] | 352 | gd_t data; |
Simon Glass | d7c8d8d | 2013-11-10 10:27:04 -0700 | [diff] [blame] | 353 | int ret; |
Simon Glass | 20bf89a | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 354 | |
Simon Glass | 752707a | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 355 | memset(&data, '\0', sizeof(data)); |
| 356 | gd = &data; |
| 357 | gd->arch.text_base = os_find_text_base(); |
| 358 | |
Simon Glass | d7c8d8d | 2013-11-10 10:27:04 -0700 | [diff] [blame] | 359 | ret = state_init(); |
| 360 | if (ret) |
| 361 | goto err; |
Simon Glass | 20bf89a | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 362 | |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 363 | state = state_get_current(); |
| 364 | if (os_parse_args(state, argc, argv)) |
| 365 | return 1; |
| 366 | |
Simon Glass | d7c8d8d | 2013-11-10 10:27:04 -0700 | [diff] [blame] | 367 | ret = sandbox_read_state(state, state->state_fname); |
| 368 | if (ret) |
| 369 | goto err; |
| 370 | |
Andy Yan | 25428c4 | 2017-07-24 17:49:59 +0800 | [diff] [blame] | 371 | #if CONFIG_VAL(SYS_MALLOC_F_LEN) |
Simon Glass | 0cc6f5c | 2014-07-10 22:23:31 -0600 | [diff] [blame] | 372 | gd->malloc_base = CONFIG_MALLOC_F_ADDR; |
| 373 | #endif |
Simon Glass | 4e9a64d | 2018-10-01 11:55:11 -0600 | [diff] [blame] | 374 | #if CONFIG_IS_ENABLED(LOG) |
| 375 | gd->default_log_level = state->default_log_level; |
| 376 | #endif |
Simon Glass | b94eed5 | 2017-03-28 10:27:16 -0600 | [diff] [blame] | 377 | setup_ram_buf(state); |
Simon Glass | c395fdf | 2014-07-10 22:23:27 -0600 | [diff] [blame] | 378 | |
Simon Glass | 752707a | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 379 | /* |
| 380 | * Set up the relocation offset here, since sandbox symbols are always |
| 381 | * relocated by the OS before sandbox is entered. |
| 382 | */ |
| 383 | gd->reloc_off = (ulong)gd->arch.text_base; |
| 384 | |
Simon Glass | 2fd34e6 | 2013-11-10 10:26:59 -0700 | [diff] [blame] | 385 | /* Do pre- and post-relocation init */ |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 386 | board_init_f(0); |
Allen Martin | 074b455 | 2013-01-22 13:11:21 +0000 | [diff] [blame] | 387 | |
Simon Glass | 2fd34e6 | 2013-11-10 10:26:59 -0700 | [diff] [blame] | 388 | board_init_r(gd->new_gd, 0); |
| 389 | |
| 390 | /* NOTREACHED - board_init_r() does not return */ |
Allen Martin | 074b455 | 2013-01-22 13:11:21 +0000 | [diff] [blame] | 391 | return 0; |
Simon Glass | d7c8d8d | 2013-11-10 10:27:04 -0700 | [diff] [blame] | 392 | |
| 393 | err: |
| 394 | printf("Error %d\n", ret); |
| 395 | return 1; |
Simon Glass | 5ba8ef6 | 2011-10-03 19:26:45 +0000 | [diff] [blame] | 396 | } |