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