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