2 * Copyright (c) 2011-2012 The Chromium OS Authors.
3 * SPDX-License-Identifier: GPL-2.0+
7 #include <asm/getopt.h>
8 #include <asm/sections.h>
13 int sandbox_early_getopt_check(void)
15 struct sandbox_state *state = state_get_current();
16 struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
17 size_t num_options = __u_boot_sandbox_option_count();
19 int max_arg_len, max_noarg_len;
21 /* parse_err will be a string of the faulting option */
22 if (!state->parse_err)
25 if (strcmp(state->parse_err, "help")) {
26 printf("u-boot: error: failed while parsing option: %s\n"
27 "\ttry running with --help for more information.\n",
33 "u-boot, a command line test interface to U-Boot\n\n"
34 "Usage: u-boot [options]\n"
38 for (i = 0; i < num_options; ++i)
39 max_arg_len = max(strlen(sb_opt[i]->flag), max_arg_len);
40 max_noarg_len = max_arg_len + 7;
42 for (i = 0; i < num_options; ++i) {
43 struct sandbox_cmdline_option *opt = sb_opt[i];
45 /* first output the short flag if it has one */
46 if (opt->flag_short >= 0x100)
49 printf(" -%c, ", opt->flag_short);
51 /* then the long flag */
53 printf("--%-*s", max_noarg_len, opt->flag);
55 printf("--%-*s <arg> ", max_arg_len, opt->flag);
57 /* finally the help text */
58 printf(" %s\n", opt->help);
64 static int sandbox_cmdline_cb_help(struct sandbox_state *state, const char *arg)
66 /* just flag to sandbox_early_getopt_check to show usage */
69 SANDBOX_CMDLINE_OPT_SHORT(help, 'h', 0, "Display help");
71 int sandbox_main_loop_init(void)
73 struct sandbox_state *state = state_get_current();
75 /* Execute command if required */
77 run_command_list(state->cmd, -1, 0);
78 os_exit(state->exit_type);
84 static int sandbox_cmdline_cb_command(struct sandbox_state *state,
90 SANDBOX_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command");
92 static int sandbox_cmdline_cb_fdt(struct sandbox_state *state, const char *arg)
94 state->fdt_fname = arg;
97 SANDBOX_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT");
99 int main(int argc, char *argv[])
101 struct sandbox_state *state;
108 state = state_get_current();
109 if (os_parse_args(state, argc, argv))
113 * Do pre- and post-relocation init, then start up U-Boot. This will
118 /* NOTREACHED - board_init_f() does not return */