]>
Commit | Line | Data |
---|---|---|
35edb766 | 1 | /* |
04b3ea0e | 2 | * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de> |
35edb766 L |
3 | * |
4 | * (C) Copyright 2000-2009 | |
5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
6 | * | |
04b3ea0e | 7 | * SPDX-License-Identifier: GPL-2.0 |
35edb766 | 8 | */ |
d684c216 L |
9 | |
10 | /* | |
11 | * Definitions for Command Processor | |
12 | */ | |
13 | #ifndef __COMMAND_H | |
14 | #define __COMMAND_H | |
15 | ||
16 | #include "common.h" | |
17 | #include "config.h" | |
fcd2239e | 18 | #include <setjmp.h> |
d684c216 L |
19 | |
20 | #ifndef NULL | |
21 | #define NULL 0 | |
22 | #endif | |
23 | ||
24 | /* Default to a width of 8 characters for help message command width */ | |
25 | #ifndef CONFIG_SYS_HELP_CMD_WIDTH | |
26 | #define CONFIG_SYS_HELP_CMD_WIDTH 8 | |
27 | #endif | |
28 | ||
d0581f88 L |
29 | /* |
30 | * Error codes that commands return to cmd_process(). We use the standard 0 | |
31 | * and 1 for success and failure, but add one more case - failure with a | |
32 | * request to call cmd_usage(). But the cmd_process() function handles | |
33 | * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1. | |
34 | * This is just a convenience for commands to avoid them having to call | |
35 | * cmd_usage() all over the place. | |
36 | */ | |
37 | typedef enum { | |
889202c4 L |
38 | CMD_RET_SUCCESS = 0, /* Success */ |
39 | CMD_RET_FAILURE = 1, /* Failure */ | |
d0581f88 L |
40 | CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */ |
41 | } command_ret_t; | |
42 | ||
d684c216 L |
43 | /* |
44 | * Monitor Command Table | |
45 | */ | |
46 | ||
8da60ec5 | 47 | typedef const FLASH struct cmd_tbl_s cmd_tbl_t; |
d684c216 L |
48 | struct cmd_tbl_s { |
49 | const FLASH char *name; /* Command Name */ | |
fcf1d5b3 L |
50 | uint8_t maxargs; /* maximum number of arguments */ |
51 | uint8_t flags; /* autorepeat allowed? */ | |
35edb766 | 52 | /* Implementation function */ |
fcf1d5b3 | 53 | command_ret_t (*cmd)(const FLASH struct cmd_tbl_s *, uint_fast8_t, int, char * const []); |
35edb766 | 54 | const FLASH char *usage; /* Usage message (short) */ |
d684c216 L |
55 | #ifdef CONFIG_SYS_LONGHELP |
56 | const FLASH char *help; /* Help message (long) */ | |
57 | #endif | |
8da60ec5 L |
58 | cmd_tbl_t *subcmd; |
59 | // const FLASH struct cmd_tbl_s *subcommands; | |
d684c216 L |
60 | #ifdef CONFIG_AUTO_COMPLETE |
61 | /* do auto completion on the arguments */ | |
62 | int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); | |
63 | #endif | |
64 | }; | |
65 | ||
d0581f88 L |
66 | /** |
67 | * Process a command with arguments. We look up the command and execute it | |
68 | * if valid. Otherwise we print a usage message. | |
69 | * | |
70 | * @param flag Some flags normally 0 (see CMD_FLAG_.. above) | |
71 | * @param argc Number of arguments (arg 0 must be the command text) | |
72 | * @param argv Arguments | |
73 | * @param repeatable This function sets this to 0 if the command is not | |
74 | * repeatable. If the command is repeatable, the value | |
75 | * is left unchanged. | |
76 | * @return 0 if the command succeeded, 1 if it failed | |
77 | */ | |
78 | command_ret_t | |
fcf1d5b3 | 79 | cmd_process(uint_fast8_t flag, int argc, char * const argv[], uint_fast8_t *repeatable); |
d0581f88 | 80 | |
d684c216 L |
81 | |
82 | /* command.c */ | |
5caa8c2b | 83 | command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]); |
d684c216 | 84 | |
8da60ec5 | 85 | int cmd_tbl_item_count(cmd_tbl_t *p); |
d0581f88 | 86 | command_ret_t cmd_usage(cmd_tbl_t *cmdtp); |
d684c216 L |
87 | |
88 | #ifdef CONFIG_AUTO_COMPLETE | |
89 | extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); | |
dea9a315 | 90 | extern int cmd_auto_complete(const FLASH char *const prompt, char *buf, int *np, int *colp); |
d684c216 L |
91 | #endif |
92 | ||
93 | /** | |
94 | * cmd_process_error() - report and process a possible error | |
95 | * | |
96 | * @cmdtp: Command which caused the error | |
97 | * @err: Error code (0 if none, -ve for error, like -EIO) | |
98 | * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found | |
99 | */ | |
100 | int cmd_process_error(cmd_tbl_t *cmdtp, int err); | |
101 | ||
102 | /* | |
103 | * Monitor Command | |
104 | * | |
105 | * All commands use a common argument format: | |
106 | * | |
fcf1d5b3 | 107 | * void function (cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]); |
d684c216 L |
108 | */ |
109 | ||
110 | ||
111 | #ifdef CONFIG_CMD_BOOTD | |
fcf1d5b3 | 112 | extern command_ret_t do_bootd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]); |
d684c216 L |
113 | #endif |
114 | #ifdef CONFIG_CMD_BOOTM | |
fcf1d5b3 | 115 | extern command_ret_t do_bootm(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]); |
d684c216 L |
116 | extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd); |
117 | #else | |
fcf1d5b3 | 118 | static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp UNUSED, const char *cmd UNUSED) |
d684c216 | 119 | { |
d684c216 L |
120 | return 0; |
121 | } | |
122 | #endif | |
123 | ||
124 | extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, | |
125 | char *const argv[]); | |
126 | ||
d684c216 L |
127 | /* |
128 | * Command Flags: | |
129 | */ | |
fcf1d5b3 L |
130 | #define CMD_FLAG_REPEAT 0x01 /* repeat last command */ |
131 | #define CMD_FLAG_BOOTD 0x02 /* command is from bootd */ | |
132 | ||
133 | /* | |
134 | * Flags for command table: | |
135 | */ | |
7a1ed620 | 136 | #define CTBL_RPT 0x01 /* command is repeatable */ |
fcf1d5b3 | 137 | #define CTBL_SUBCMD 0x02 /* command has subcommands */ |
7a1ed620 L |
138 | #define CTBL_SUBCMDAUTO 0x04 /* execute subcommands whithout prefix */ |
139 | #define CTBL_DBG 0x08 /* command is only for debugging */ | |
d684c216 L |
140 | |
141 | #ifdef CONFIG_AUTO_COMPLETE | |
142 | # define _CMD_COMPLETE(x) x, | |
143 | #else | |
144 | # define _CMD_COMPLETE(x) | |
145 | #endif | |
146 | #ifdef CONFIG_SYS_LONGHELP | |
147 | # define _CMD_HELP(x) x, | |
148 | #else | |
149 | # define _CMD_HELP(x) | |
150 | #endif | |
151 | ||
152 | ||
8da60ec5 L |
153 | #define CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd, \ |
154 | _usage, _help, _subtbl, _comp) \ | |
155 | { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \ | |
156 | _CMD_HELP(FSTR(_help)) _subtbl, _CMD_COMPLETE(_comp) } | |
157 | ||
158 | #define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \ | |
159 | _usage, _help, _comp) \ | |
160 | { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \ | |
161 | _CMD_HELP(FSTR(_help)) NULL, _CMD_COMPLETE(_comp) } | |
162 | ||
163 | #define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help) \ | |
164 | CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd, \ | |
165 | _usage, _help, NULL, NULL) | |
d684c216 | 166 | |
8da60ec5 L |
167 | #define CMD_TBL_ITEM_TOP(_name, _maxargs, _rep, _cmd, _usage, _help, _subtbl) \ |
168 | CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd, \ | |
169 | _usage, _help, _subtbl, NULL) | |
d684c216 | 170 | |
5caa8c2b L |
171 | #define CMD_TBL_END(_table_start) { .subcmd = _table_start } |
172 | ||
fcf1d5b3 | 173 | typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, uint_fast8_t, int, char * const []); |
d684c216 L |
174 | |
175 | extern cmd_tbl_t cmd_tbl[]; | |
176 | ||
fcd2239e L |
177 | extern jmp_buf cmd_jbuf; |
178 | ||
d684c216 L |
179 | |
180 | #endif /* __COMMAND_H */ |