Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 2 | /* |
Detlev Zundel | 5e6c06b | 2009-03-25 17:27:52 +0100 | [diff] [blame] | 3 | * (C) Copyright 2000-2009 |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Definitions for Command Processor |
| 9 | */ |
| 10 | #ifndef __COMMAND_H |
| 11 | #define __COMMAND_H |
| 12 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 13 | #include <linker_lists.h> |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 14 | |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 15 | #ifndef NULL |
| 16 | #define NULL 0 |
| 17 | #endif |
| 18 | |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 19 | /* Default to a width of 8 characters for help message command width */ |
| 20 | #ifndef CONFIG_SYS_HELP_CMD_WIDTH |
Heinrich Schuchardt | 8c55cc0 | 2019-02-28 06:17:56 +0100 | [diff] [blame] | 21 | #define CONFIG_SYS_HELP_CMD_WIDTH 10 |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 22 | #endif |
| 23 | |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 24 | #ifndef __ASSEMBLY__ |
| 25 | /* |
| 26 | * Monitor Command Table |
| 27 | */ |
| 28 | |
| 29 | struct cmd_tbl_s { |
| 30 | char *name; /* Command Name */ |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 31 | int maxargs; /* maximum number of arguments */ |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 32 | /* |
| 33 | * Same as ->cmd() except the command |
| 34 | * tells us if it can be repeated. |
| 35 | * Replaces the old ->repeatable field |
| 36 | * which was not able to make |
| 37 | * repeatable property different for |
| 38 | * the main command and sub-commands. |
| 39 | */ |
| 40 | int (*cmd_rep)(struct cmd_tbl_s *cmd, int flags, int argc, |
| 41 | char * const argv[], int *repeatable); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 42 | /* Implementation function */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 43 | int (*cmd)(struct cmd_tbl_s *, int, int, char * const []); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 44 | char *usage; /* Usage message (short) */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | #ifdef CONFIG_SYS_LONGHELP |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 46 | char *help; /* Help message (long) */ |
| 47 | #endif |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_AUTO_COMPLETE |
| 49 | /* do auto completion on the arguments */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 50 | int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 51 | #endif |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | typedef struct cmd_tbl_s cmd_tbl_t; |
| 55 | |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 56 | |
Igor Grinberg | de83256 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 57 | #if defined(CONFIG_CMD_RUN) |
| 58 | extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 59 | #endif |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 60 | |
| 61 | /* common/command.c */ |
Detlev Zundel | 5e6c06b | 2009-03-25 17:27:52 +0100 | [diff] [blame] | 62 | int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 63 | flag, int argc, char * const argv[]); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 64 | cmd_tbl_t *find_cmd(const char *cmd); |
Kumar Gala | ac2dad6 | 2008-09-23 10:05:02 -0500 | [diff] [blame] | 65 | cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len); |
Boris Brezillon | ae73c33 | 2018-12-03 22:54:19 +0100 | [diff] [blame] | 66 | int complete_subcmdv(cmd_tbl_t *cmdtp, int count, int argc, |
| 67 | char * const argv[], char last_char, int maxv, |
| 68 | char *cmdv[]); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 69 | |
Mike Frysinger | 33e84d1 | 2011-04-23 23:43:24 +0000 | [diff] [blame] | 70 | extern int cmd_usage(const cmd_tbl_t *cmdtp); |
Peter Tyser | ddb3af9 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 71 | |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 72 | /* Dummy ->cmd and ->cmd_rep wrappers. */ |
| 73 | int cmd_always_repeatable(cmd_tbl_t *cmdtp, int flag, int argc, |
| 74 | char * const argv[], int *repeatable); |
| 75 | int cmd_never_repeatable(cmd_tbl_t *cmdtp, int flag, int argc, |
| 76 | char * const argv[], int *repeatable); |
| 77 | int cmd_discard_repeatable(cmd_tbl_t *cmdtp, int flag, int argc, |
| 78 | char * const argv[]); |
| 79 | |
| 80 | static inline bool cmd_is_repeatable(cmd_tbl_t *cmdtp) |
| 81 | { |
| 82 | return cmdtp->cmd_rep == cmd_always_repeatable; |
| 83 | } |
| 84 | |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 85 | #ifdef CONFIG_AUTO_COMPLETE |
Mike Frysinger | b5bc05e | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 86 | extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 87 | extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp); |
| 88 | #endif |
| 89 | |
Simon Glass | d738553 | 2014-02-26 15:59:15 -0700 | [diff] [blame] | 90 | /** |
| 91 | * cmd_process_error() - report and process a possible error |
| 92 | * |
| 93 | * @cmdtp: Command which caused the error |
| 94 | * @err: Error code (0 if none, -ve for error, like -EIO) |
Heinrich Schuchardt | 1b128c3 | 2018-10-12 11:23:04 +0200 | [diff] [blame] | 95 | * @return 0 (CMD_RET_SUCCESS) if there is not error, |
Michal Simek | 2e1b90b | 2018-06-21 14:49:26 +0200 | [diff] [blame] | 96 | * 1 (CMD_RET_FAILURE) if an error is found |
| 97 | * -1 (CMD_RET_USAGE) if 'usage' error is found |
Simon Glass | d738553 | 2014-02-26 15:59:15 -0700 | [diff] [blame] | 98 | */ |
| 99 | int cmd_process_error(cmd_tbl_t *cmdtp, int err); |
| 100 | |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 101 | /* |
| 102 | * Monitor Command |
| 103 | * |
| 104 | * All commands use a common argument format: |
| 105 | * |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 106 | * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 107 | */ |
| 108 | |
Simon Glass | 0ae023d | 2017-08-04 16:34:38 -0600 | [diff] [blame] | 109 | #if defined(CONFIG_CMD_MEMORY) || \ |
| 110 | defined(CONFIG_CMD_I2C) || \ |
| 111 | defined(CONFIG_CMD_ITEST) || \ |
Bartosz Golaszewski | 7dd2386 | 2019-05-20 10:22:14 +0200 | [diff] [blame] | 112 | defined(CONFIG_CMD_PCI) || \ |
| 113 | defined(CONFIG_CMD_SETEXPR) |
Jean-Christophe PLAGNIOL-VILLARD | 82290f2 | 2008-09-10 22:48:05 +0200 | [diff] [blame] | 114 | #define CMD_DATA_SIZE |
| 115 | extern int cmd_get_data_size(char* arg, int default_size); |
| 116 | #endif |
| 117 | |
Mike Frysinger | 2e50fa3 | 2010-10-20 03:36:26 -0400 | [diff] [blame] | 118 | #ifdef CONFIG_CMD_BOOTD |
| 119 | extern int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 120 | #endif |
Mike Frysinger | 194c2e8 | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 121 | #ifdef CONFIG_CMD_BOOTM |
Mike Frysinger | 2a5ba45 | 2010-10-20 03:35:39 -0400 | [diff] [blame] | 122 | extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Mike Frysinger | 194c2e8 | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 123 | extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd); |
| 124 | #else |
| 125 | static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) |
| 126 | { |
| 127 | return 0; |
| 128 | } |
| 129 | #endif |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 130 | |
Rob Herring | c88e1bf | 2012-12-02 21:00:23 -0600 | [diff] [blame] | 131 | extern int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 132 | |
Stephen Warren | 9c3c931 | 2015-07-21 17:49:41 -0600 | [diff] [blame] | 133 | extern int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 134 | |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 135 | extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, |
| 136 | char *const argv[]); |
| 137 | |
Mike Frysinger | 6d1f698 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 138 | extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Michael van Slingerland | 2451dec | 2016-01-13 19:31:17 +0100 | [diff] [blame] | 139 | extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Mike Frysinger | 2a5ba45 | 2010-10-20 03:35:39 -0400 | [diff] [blame] | 140 | |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 141 | extern unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
| 142 | char * const argv[]); |
AKASHI Takahiro | 117e68a | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 143 | |
| 144 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
| 145 | extern int do_env_print_efi(cmd_tbl_t *cmdtp, int flag, int argc, |
| 146 | char * const argv[]); |
| 147 | extern int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, |
| 148 | char * const argv[]); |
| 149 | #endif |
| 150 | |
Simon Glass | 1727b94 | 2012-02-14 19:59:25 +0000 | [diff] [blame] | 151 | /* |
| 152 | * Error codes that commands return to cmd_process(). We use the standard 0 |
| 153 | * and 1 for success and failure, but add one more case - failure with a |
| 154 | * request to call cmd_usage(). But the cmd_process() function handles |
| 155 | * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1. |
| 156 | * This is just a convenience for commands to avoid them having to call |
| 157 | * cmd_usage() all over the place. |
| 158 | */ |
| 159 | enum command_ret_t { |
| 160 | CMD_RET_SUCCESS, /* 0 = Success */ |
| 161 | CMD_RET_FAILURE, /* 1 = Failure */ |
| 162 | CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */ |
| 163 | }; |
| 164 | |
| 165 | /** |
| 166 | * Process a command with arguments. We look up the command and execute it |
| 167 | * if valid. Otherwise we print a usage message. |
| 168 | * |
| 169 | * @param flag Some flags normally 0 (see CMD_FLAG_.. above) |
| 170 | * @param argc Number of arguments (arg 0 must be the command text) |
| 171 | * @param argv Arguments |
| 172 | * @param repeatable This function sets this to 0 if the command is not |
| 173 | * repeatable. If the command is repeatable, the value |
| 174 | * is left unchanged. |
Richard Genoud | 94ff067 | 2012-12-03 06:28:28 +0000 | [diff] [blame] | 175 | * @param ticks If ticks is not null, this function set it to the |
| 176 | * number of ticks the command took to complete. |
Simon Glass | 1727b94 | 2012-02-14 19:59:25 +0000 | [diff] [blame] | 177 | * @return 0 if the command succeeded, 1 if it failed |
| 178 | */ |
| 179 | int cmd_process(int flag, int argc, char * const argv[], |
Richard Genoud | 94ff067 | 2012-12-03 06:28:28 +0000 | [diff] [blame] | 180 | int *repeatable, unsigned long *ticks); |
Simon Glass | 2176d60 | 2012-02-14 19:59:23 +0000 | [diff] [blame] | 181 | |
Tom Rini | 23415e5 | 2015-12-07 08:23:29 -0500 | [diff] [blame] | 182 | void fixup_cmdtable(cmd_tbl_t *cmdtp, int size); |
Simon Glass | 4ef90b7 | 2016-03-19 02:18:38 -0600 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * board_run_command() - Fallback function to execute a command |
| 186 | * |
| 187 | * When no command line features are enabled in U-Boot, this function is |
| 188 | * called to execute a command. Typically the function can look at the |
| 189 | * command and perform a few very specific tasks, such as booting the |
| 190 | * system in a particular way. |
| 191 | * |
| 192 | * This function is only used when CONFIG_CMDLINE is not enabled. |
| 193 | * |
| 194 | * In normal situations this function should not return, since U-Boot will |
| 195 | * simply hang. |
| 196 | * |
| 197 | * @cmdline: Command line string to execute |
| 198 | * @return 0 if OK, 1 for error |
| 199 | */ |
| 200 | int board_run_command(const char *cmdline); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 201 | #endif /* __ASSEMBLY__ */ |
| 202 | |
| 203 | /* |
| 204 | * Command Flags: |
| 205 | */ |
| 206 | #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */ |
| 207 | #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */ |
Simon Glass | 94cb9c2 | 2014-10-07 13:59:43 -0600 | [diff] [blame] | 208 | #define CMD_FLAG_ENV 0x0004 /* command is from the environment */ |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 209 | |
Mike Frysinger | b5bc05e | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 210 | #ifdef CONFIG_AUTO_COMPLETE |
| 211 | # define _CMD_COMPLETE(x) x, |
| 212 | #else |
| 213 | # define _CMD_COMPLETE(x) |
| 214 | #endif |
| 215 | #ifdef CONFIG_SYS_LONGHELP |
| 216 | # define _CMD_HELP(x) x, |
| 217 | #else |
| 218 | # define _CMD_HELP(x) |
| 219 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 220 | |
Boris Brezillon | 20052d4 | 2018-12-03 22:54:21 +0100 | [diff] [blame] | 221 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 222 | #define U_BOOT_SUBCMDS_RELOC(_cmdname) \ |
| 223 | static void _cmdname##_subcmds_reloc(void) \ |
| 224 | { \ |
| 225 | static int relocated; \ |
| 226 | \ |
| 227 | if (relocated) \ |
| 228 | return; \ |
| 229 | \ |
| 230 | fixup_cmdtable(_cmdname##_subcmds, \ |
| 231 | ARRAY_SIZE(_cmdname##_subcmds)); \ |
| 232 | relocated = 1; \ |
| 233 | } |
| 234 | #else |
| 235 | #define U_BOOT_SUBCMDS_RELOC(_cmdname) \ |
| 236 | static void _cmdname##_subcmds_reloc(void) { } |
| 237 | #endif |
| 238 | |
| 239 | #define U_BOOT_SUBCMDS_DO_CMD(_cmdname) \ |
| 240 | static int do_##_cmdname(cmd_tbl_t *cmdtp, int flag, int argc, \ |
| 241 | char * const argv[], int *repeatable) \ |
| 242 | { \ |
| 243 | cmd_tbl_t *subcmd; \ |
| 244 | \ |
| 245 | _cmdname##_subcmds_reloc(); \ |
| 246 | \ |
| 247 | /* We need at least the cmd and subcmd names. */ \ |
| 248 | if (argc < 2 || argc > CONFIG_SYS_MAXARGS) \ |
| 249 | return CMD_RET_USAGE; \ |
| 250 | \ |
| 251 | subcmd = find_cmd_tbl(argv[1], _cmdname##_subcmds, \ |
| 252 | ARRAY_SIZE(_cmdname##_subcmds)); \ |
| 253 | if (!subcmd || argc - 1 > subcmd->maxargs) \ |
| 254 | return CMD_RET_USAGE; \ |
| 255 | \ |
| 256 | if (flag == CMD_FLAG_REPEAT && \ |
| 257 | !cmd_is_repeatable(subcmd)) \ |
| 258 | return CMD_RET_SUCCESS; \ |
| 259 | \ |
| 260 | return subcmd->cmd_rep(subcmd, flag, argc - 1, \ |
| 261 | argv + 1, repeatable); \ |
| 262 | } |
| 263 | |
| 264 | #ifdef CONFIG_AUTO_COMPLETE |
| 265 | #define U_BOOT_SUBCMDS_COMPLETE(_cmdname) \ |
| 266 | static int complete_##_cmdname(int argc, char * const argv[], \ |
| 267 | char last_char, int maxv, \ |
| 268 | char *cmdv[]) \ |
| 269 | { \ |
| 270 | return complete_subcmdv(_cmdname##_subcmds, \ |
| 271 | ARRAY_SIZE(_cmdname##_subcmds), \ |
| 272 | argc - 1, argv + 1, last_char, \ |
| 273 | maxv, cmdv); \ |
| 274 | } |
| 275 | #else |
| 276 | #define U_BOOT_SUBCMDS_COMPLETE(_cmdname) |
| 277 | #endif |
| 278 | |
| 279 | #define U_BOOT_SUBCMDS(_cmdname, ...) \ |
| 280 | static cmd_tbl_t _cmdname##_subcmds[] = { __VA_ARGS__ }; \ |
| 281 | U_BOOT_SUBCMDS_RELOC(_cmdname) \ |
| 282 | U_BOOT_SUBCMDS_DO_CMD(_cmdname) \ |
| 283 | U_BOOT_SUBCMDS_COMPLETE(_cmdname) |
| 284 | |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 285 | #ifdef CONFIG_CMDLINE |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 286 | #define U_BOOT_CMDREP_MKENT_COMPLETE(_name, _maxargs, _cmd_rep, \ |
| 287 | _usage, _help, _comp) \ |
| 288 | { #_name, _maxargs, _cmd_rep, cmd_discard_repeatable, \ |
| 289 | _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) } |
| 290 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 291 | #define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \ |
| 292 | _usage, _help, _comp) \ |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 293 | { #_name, _maxargs, \ |
| 294 | _rep ? cmd_always_repeatable : cmd_never_repeatable, \ |
| 295 | _cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 296 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 297 | #define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \ |
Albert ARIBAUD | c24895e | 2013-02-25 00:59:00 +0000 | [diff] [blame] | 298 | ll_entry_declare(cmd_tbl_t, _name, cmd) = \ |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 299 | U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \ |
| 300 | _usage, _help, _comp); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 301 | |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 302 | #define U_BOOT_CMDREP_COMPLETE(_name, _maxargs, _cmd_rep, _usage, \ |
| 303 | _help, _comp) \ |
| 304 | ll_entry_declare(cmd_tbl_t, _name, cmd) = \ |
| 305 | U_BOOT_CMDREP_MKENT_COMPLETE(_name, _maxargs, _cmd_rep, \ |
| 306 | _usage, _help, _comp) |
| 307 | |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 308 | #else |
| 309 | #define U_BOOT_SUBCMD_START(name) static cmd_tbl_t name[] = {}; |
| 310 | #define U_BOOT_SUBCMD_END |
| 311 | |
| 312 | #define _CMD_REMOVE(_name, _cmd) \ |
| 313 | int __remove_ ## _name(void) \ |
| 314 | { \ |
| 315 | if (0) \ |
| 316 | _cmd(NULL, 0, 0, NULL); \ |
| 317 | return 0; \ |
| 318 | } |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 319 | |
| 320 | #define U_BOOT_CMDREP_MKENT_COMPLETE(_name, _maxargs, _cmd_rep, \ |
| 321 | _usage, _help, _comp) \ |
| 322 | { #_name, _maxargs, 0 ? _cmd_rep : NULL, NULL, _usage, \ |
| 323 | _CMD_HELP(_help) _CMD_COMPLETE(_comp) } |
| 324 | |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 325 | #define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, \ |
| 326 | _help, _comp) \ |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 327 | { #_name, _maxargs, NULL, 0 ? _cmd : NULL, _usage, \ |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 328 | _CMD_HELP(_help) _CMD_COMPLETE(_comp) } |
| 329 | |
| 330 | #define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, \ |
| 331 | _comp) \ |
| 332 | _CMD_REMOVE(sub_ ## _name, _cmd) |
| 333 | |
Boris Brezillon | c71dfd1 | 2018-12-03 22:54:20 +0100 | [diff] [blame] | 334 | #define U_BOOT_CMDREP_COMPLETE(_name, _maxargs, _cmd_rep, _usage, \ |
| 335 | _help, _comp) \ |
| 336 | _CMD_REMOVE(sub_ ## _name, _cmd_rep) |
| 337 | |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 338 | #endif /* CONFIG_CMDLINE */ |
| 339 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 340 | #define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \ |
| 341 | U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 342 | |
Simon Glass | 9a48bc3 | 2016-03-13 19:07:33 -0600 | [diff] [blame] | 343 | #define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \ |
| 344 | U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \ |
| 345 | _usage, _help, NULL) |
| 346 | |
Boris Brezillon | 20052d4 | 2018-12-03 22:54:21 +0100 | [diff] [blame] | 347 | #define U_BOOT_SUBCMD_MKENT_COMPLETE(_name, _maxargs, _rep, _do_cmd, \ |
| 348 | _comp) \ |
| 349 | U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _do_cmd, \ |
| 350 | "", "", _comp) |
| 351 | |
| 352 | #define U_BOOT_SUBCMD_MKENT(_name, _maxargs, _rep, _do_cmd) \ |
| 353 | U_BOOT_SUBCMD_MKENT_COMPLETE(_name, _maxargs, _rep, _do_cmd, \ |
| 354 | NULL) |
| 355 | |
| 356 | #define U_BOOT_CMD_WITH_SUBCMDS(_name, _usage, _help, ...) \ |
| 357 | U_BOOT_SUBCMDS(_name, __VA_ARGS__) \ |
| 358 | U_BOOT_CMDREP_COMPLETE(_name, CONFIG_SYS_MAXARGS, do_##_name, \ |
| 359 | _usage, _help, complete_##_name) |
| 360 | |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 361 | #endif /* __COMMAND_H */ |