]>
Commit | Line | Data |
---|---|---|
35edb766 L |
1 | /* |
2 | * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> | |
3 | * | |
4 | * (C) Copyright 2000-2009 | |
5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
6 | * | |
7 | * SPDX-License-Identifier: GPL-2.0+ | |
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" | |
18 | ||
19 | #ifndef NULL | |
20 | #define NULL 0 | |
21 | #endif | |
22 | ||
23 | /* Default to a width of 8 characters for help message command width */ | |
24 | #ifndef CONFIG_SYS_HELP_CMD_WIDTH | |
25 | #define CONFIG_SYS_HELP_CMD_WIDTH 8 | |
26 | #endif | |
27 | ||
d0581f88 L |
28 | /* |
29 | * Error codes that commands return to cmd_process(). We use the standard 0 | |
30 | * and 1 for success and failure, but add one more case - failure with a | |
31 | * request to call cmd_usage(). But the cmd_process() function handles | |
32 | * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1. | |
33 | * This is just a convenience for commands to avoid them having to call | |
34 | * cmd_usage() all over the place. | |
35 | */ | |
36 | typedef enum { | |
889202c4 L |
37 | CMD_RET_SUCCESS = 0, /* Success */ |
38 | CMD_RET_FAILURE = 1, /* Failure */ | |
d0581f88 L |
39 | CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */ |
40 | } command_ret_t; | |
41 | ||
d684c216 L |
42 | /* |
43 | * Monitor Command Table | |
44 | */ | |
45 | ||
46 | struct cmd_tbl_s { | |
47 | const FLASH char *name; /* Command Name */ | |
35edb766 L |
48 | int maxargs; /* maximum number of arguments */ |
49 | int repeatable; /* autorepeat allowed? */ | |
50 | /* Implementation function */ | |
d0581f88 | 51 | command_ret_t (*cmd)(const FLASH struct cmd_tbl_s *, int, int, char * const []); |
35edb766 | 52 | const FLASH char *usage; /* Usage message (short) */ |
d684c216 L |
53 | #ifdef CONFIG_SYS_LONGHELP |
54 | const FLASH char *help; /* Help message (long) */ | |
55 | #endif | |
56 | #ifdef CONFIG_AUTO_COMPLETE | |
57 | /* do auto completion on the arguments */ | |
58 | int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); | |
59 | #endif | |
60 | }; | |
61 | ||
62 | typedef const FLASH struct cmd_tbl_s cmd_tbl_t; | |
63 | ||
d0581f88 L |
64 | extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
65 | ||
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 | |
79 | cmd_process(int flag, int argc, char * const argv[], uint_fast8_t *repeatable); | |
80 | ||
d684c216 L |
81 | |
82 | /* command.c */ | |
d0581f88 | 83 | command_ret_t _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int |
d684c216 L |
84 | flag, int argc, char * const argv[]); |
85 | cmd_tbl_t *find_cmd(const char *cmd); | |
86 | cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len); | |
87 | ||
88 | int cmd_tbl_item_count(void); | |
d0581f88 | 89 | command_ret_t cmd_usage(cmd_tbl_t *cmdtp); |
d684c216 L |
90 | |
91 | #ifdef CONFIG_AUTO_COMPLETE | |
92 | extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); | |
dea9a315 | 93 | extern int cmd_auto_complete(const FLASH char *const prompt, char *buf, int *np, int *colp); |
d684c216 L |
94 | #endif |
95 | ||
96 | /** | |
97 | * cmd_process_error() - report and process a possible error | |
98 | * | |
99 | * @cmdtp: Command which caused the error | |
100 | * @err: Error code (0 if none, -ve for error, like -EIO) | |
101 | * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found | |
102 | */ | |
103 | int cmd_process_error(cmd_tbl_t *cmdtp, int err); | |
104 | ||
105 | /* | |
106 | * Monitor Command | |
107 | * | |
108 | * All commands use a common argument format: | |
109 | * | |
110 | * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); | |
111 | */ | |
112 | ||
113 | ||
114 | #ifdef CONFIG_CMD_BOOTD | |
d0581f88 | 115 | extern command_ret_t do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
d684c216 L |
116 | #endif |
117 | #ifdef CONFIG_CMD_BOOTM | |
d0581f88 | 118 | extern command_ret_t do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
d684c216 L |
119 | extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd); |
120 | #else | |
121 | static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) | |
122 | { | |
123 | (void) cmdtp; (void) cmd; | |
124 | ||
125 | return 0; | |
126 | } | |
127 | #endif | |
128 | ||
129 | extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, | |
130 | char *const argv[]); | |
131 | ||
d0581f88 | 132 | extern command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
d684c216 L |
133 | |
134 | /* | |
135 | * Command Flags: | |
136 | */ | |
137 | #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */ | |
138 | #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */ | |
139 | ||
140 | #ifdef CONFIG_AUTO_COMPLETE | |
141 | # define _CMD_COMPLETE(x) x, | |
142 | #else | |
143 | # define _CMD_COMPLETE(x) | |
144 | #endif | |
145 | #ifdef CONFIG_SYS_LONGHELP | |
146 | # define _CMD_HELP(x) x, | |
147 | #else | |
148 | # define _CMD_HELP(x) | |
149 | #endif | |
150 | ||
151 | ||
152 | #define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \ | |
153 | _usage, _help, _comp) \ | |
154 | { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \ | |
155 | _CMD_HELP(FSTR(_help)) _CMD_COMPLETE(_comp) } | |
156 | ||
157 | #define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help) \ | |
158 | CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \ | |
159 | _usage, _help, NULL) | |
160 | ||
d0581f88 | 161 | typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, int, int, char * const []); |
d684c216 L |
162 | |
163 | extern cmd_tbl_t cmd_tbl[]; | |
164 | ||
165 | ||
166 | #endif /* __COMMAND_H */ |