2 * Copyright (c) 2011-2012 The Chromium OS Authors.
3 * See file CREDITS for list of people who contributed to this
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include <asm/getopt.h>
24 #include <asm/sections.h>
25 #include <asm/state.h>
29 int sandbox_early_getopt_check(void)
31 struct sandbox_state *state = state_get_current();
32 struct sb_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
33 size_t num_options = __u_boot_sandbox_option_count();
35 int max_arg_len, max_noarg_len;
37 /* parse_err will be a string of the faulting option */
38 if (!state->parse_err)
41 if (strcmp(state->parse_err, "help")) {
42 printf("u-boot: error: failed while parsing option: %s\n"
43 "\ttry running with --help for more information.\n",
49 "u-boot, a command line test interface to U-Boot\n\n"
50 "Usage: u-boot [options]\n"
54 for (i = 0; i < num_options; ++i)
55 max_arg_len = max(strlen(sb_opt[i]->flag), max_arg_len);
56 max_noarg_len = max_arg_len + 7;
58 for (i = 0; i < num_options; ++i) {
59 struct sb_cmdline_option *opt = sb_opt[i];
61 /* first output the short flag if it has one */
62 if (opt->flag_short >= 0x100)
65 printf(" -%c, ", opt->flag_short);
67 /* then the long flag */
69 printf("--%-*s", max_noarg_len, opt->flag);
71 printf("--%-*s <arg> ", max_arg_len, opt->flag);
73 /* finally the help text */
74 printf(" %s\n", opt->help);
80 static int sb_cmdline_cb_help(struct sandbox_state *state, const char *arg)
82 /* just flag to sandbox_early_getopt_check to show usage */
85 SB_CMDLINE_OPT_SHORT(help, 'h', 0, "Display help");
87 int sandbox_main_loop_init(void)
89 struct sandbox_state *state = state_get_current();
91 /* Execute command if required */
93 run_command(state->cmd, 0);
94 os_exit(state->exit_type);
100 static int sb_cmdline_cb_command(struct sandbox_state *state, const char *arg)
105 SB_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command");
107 int main(int argc, char *argv[])
109 struct sandbox_state *state;
116 state = state_get_current();
117 if (os_parse_args(state, argc, argv))
121 * Do pre- and post-relocation init, then start up U-Boot. This will