blob: 89efcecfa92626f06a3c253d55eca6411ee3d5e8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk78f66222002-08-27 10:27:51 +00002/*
Detlev Zundel2dce5512009-03-25 17:27:52 +01003 * (C) Copyright 2000-2009
wdenk78f66222002-08-27 10:27:51 +00004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk78f66222002-08-27 10:27:51 +00005 */
6
7/*
8 * Definitions for Command Processor
9 */
10#ifndef __COMMAND_H
11#define __COMMAND_H
12
Marek Vasut6c7c9462012-10-12 10:27:04 +000013#include <linker_lists.h>
Stefan Roesef2302d42008-08-06 14:05:38 +020014
wdenk78f66222002-08-27 10:27:51 +000015#ifndef NULL
16#define NULL 0
17#endif
18
Peter Tyser2fb26042009-01-27 18:03:12 -060019/* Default to a width of 8 characters for help message command width */
20#ifndef CONFIG_SYS_HELP_CMD_WIDTH
21#define CONFIG_SYS_HELP_CMD_WIDTH 8
22#endif
23
wdenk78f66222002-08-27 10:27:51 +000024#ifndef __ASSEMBLY__
25/*
26 * Monitor Command Table
27 */
28
29struct cmd_tbl_s {
30 char *name; /* Command Name */
wdenk78f66222002-08-27 10:27:51 +000031 int maxargs; /* maximum number of arguments */
32 int repeatable; /* autorepeat allowed? */
33 /* Implementation function */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020034 int (*cmd)(struct cmd_tbl_s *, int, int, char * const []);
wdenk78f66222002-08-27 10:27:51 +000035 char *usage; /* Usage message (short) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020036#ifdef CONFIG_SYS_LONGHELP
wdenk78f66222002-08-27 10:27:51 +000037 char *help; /* Help message (long) */
38#endif
wdenk04a85b32004-04-15 18:22:41 +000039#ifdef CONFIG_AUTO_COMPLETE
40 /* do auto completion on the arguments */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020041 int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
wdenk04a85b32004-04-15 18:22:41 +000042#endif
wdenk78f66222002-08-27 10:27:51 +000043};
44
45typedef struct cmd_tbl_s cmd_tbl_t;
46
wdenk78f66222002-08-27 10:27:51 +000047
Igor Grinbergd09b1782011-11-07 01:13:59 +000048#if defined(CONFIG_CMD_RUN)
49extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
50#endif
wdenk78f66222002-08-27 10:27:51 +000051
52/* common/command.c */
Detlev Zundel2dce5512009-03-25 17:27:52 +010053int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
Wolfgang Denk54841ab2010-06-28 22:00:46 +020054 flag, int argc, char * const argv[]);
wdenk78f66222002-08-27 10:27:51 +000055cmd_tbl_t *find_cmd(const char *cmd);
Kumar Galab799cb42008-09-23 10:05:02 -050056cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
Boris Brezillon6fb61442018-12-03 22:54:19 +010057int complete_subcmdv(cmd_tbl_t *cmdtp, int count, int argc,
58 char * const argv[], char last_char, int maxv,
59 char *cmdv[]);
wdenk78f66222002-08-27 10:27:51 +000060
Mike Frysingere84ffdd2011-04-23 23:43:24 +000061extern int cmd_usage(const cmd_tbl_t *cmdtp);
Peter Tyser62c3ae72009-01-27 18:03:10 -060062
wdenk04a85b32004-04-15 18:22:41 +000063#ifdef CONFIG_AUTO_COMPLETE
Mike Frysinger722b0612010-10-20 03:52:39 -040064extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
wdenk04a85b32004-04-15 18:22:41 +000065extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp);
66#endif
67
Simon Glass16ff9902014-02-26 15:59:15 -070068/**
69 * cmd_process_error() - report and process a possible error
70 *
71 * @cmdtp: Command which caused the error
72 * @err: Error code (0 if none, -ve for error, like -EIO)
Heinrich Schuchardt8a3d7342018-10-12 11:23:04 +020073 * @return 0 (CMD_RET_SUCCESS) if there is not error,
Michal Simek27eb7bc2018-06-21 14:49:26 +020074 * 1 (CMD_RET_FAILURE) if an error is found
75 * -1 (CMD_RET_USAGE) if 'usage' error is found
Simon Glass16ff9902014-02-26 15:59:15 -070076 */
77int cmd_process_error(cmd_tbl_t *cmdtp, int err);
78
wdenk78f66222002-08-27 10:27:51 +000079/*
80 * Monitor Command
81 *
82 * All commands use a common argument format:
83 *
Wolfgang Denk54841ab2010-06-28 22:00:46 +020084 * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk78f66222002-08-27 10:27:51 +000085 */
86
Simon Glass6f62d7c2017-08-04 16:34:38 -060087#if defined(CONFIG_CMD_MEMORY) || \
88 defined(CONFIG_CMD_I2C) || \
89 defined(CONFIG_CMD_ITEST) || \
90 defined(CONFIG_CMD_PCI)
Jean-Christophe PLAGNIOL-VILLARD8a40fb12008-09-10 22:48:05 +020091#define CMD_DATA_SIZE
92extern int cmd_get_data_size(char* arg, int default_size);
93#endif
94
Mike Frysinger7842fb72010-10-20 03:36:26 -040095#ifdef CONFIG_CMD_BOOTD
96extern int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
97#endif
Mike Frysinger67d668b2011-06-05 13:43:02 +000098#ifdef CONFIG_CMD_BOOTM
Mike Frysinger36ebb782010-10-20 03:35:39 -040099extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Mike Frysinger67d668b2011-06-05 13:43:02 +0000100extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd);
101#else
102static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
103{
104 return 0;
105}
106#endif
Rob Herring7405a132012-09-21 04:02:30 +0000107
Rob Herringda620222012-12-02 21:00:23 -0600108extern int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
109
Stephen Warren8b5c7382015-07-21 17:49:41 -0600110extern int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
111
Rob Herring7405a132012-09-21 04:02:30 +0000112extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
113 char *const argv[]);
114
Mike Frysinger882b7d72010-10-20 03:41:17 -0400115extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Michael van Slingerland4e42e292016-01-13 19:31:17 +0100116extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Mike Frysinger36ebb782010-10-20 03:35:39 -0400117
Nitin Jain51916862018-02-16 12:56:17 +0530118extern unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
119 char * const argv[]);
Simon Glass9d12d5d2012-02-14 19:59:25 +0000120/*
121 * Error codes that commands return to cmd_process(). We use the standard 0
122 * and 1 for success and failure, but add one more case - failure with a
123 * request to call cmd_usage(). But the cmd_process() function handles
124 * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
125 * This is just a convenience for commands to avoid them having to call
126 * cmd_usage() all over the place.
127 */
128enum command_ret_t {
129 CMD_RET_SUCCESS, /* 0 = Success */
130 CMD_RET_FAILURE, /* 1 = Failure */
131 CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */
132};
133
134/**
135 * Process a command with arguments. We look up the command and execute it
136 * if valid. Otherwise we print a usage message.
137 *
138 * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
139 * @param argc Number of arguments (arg 0 must be the command text)
140 * @param argv Arguments
141 * @param repeatable This function sets this to 0 if the command is not
142 * repeatable. If the command is repeatable, the value
143 * is left unchanged.
Richard Genoud34765e82012-12-03 06:28:28 +0000144 * @param ticks If ticks is not null, this function set it to the
145 * number of ticks the command took to complete.
Simon Glass9d12d5d2012-02-14 19:59:25 +0000146 * @return 0 if the command succeeded, 1 if it failed
147 */
148int cmd_process(int flag, int argc, char * const argv[],
Richard Genoud34765e82012-12-03 06:28:28 +0000149 int *repeatable, unsigned long *ticks);
Simon Glassbdf8e342012-02-14 19:59:23 +0000150
Tom Rinicbb2df22015-12-07 08:23:29 -0500151void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);
Simon Glassf8bb6962016-03-19 02:18:38 -0600152
153/**
154 * board_run_command() - Fallback function to execute a command
155 *
156 * When no command line features are enabled in U-Boot, this function is
157 * called to execute a command. Typically the function can look at the
158 * command and perform a few very specific tasks, such as booting the
159 * system in a particular way.
160 *
161 * This function is only used when CONFIG_CMDLINE is not enabled.
162 *
163 * In normal situations this function should not return, since U-Boot will
164 * simply hang.
165 *
166 * @cmdline: Command line string to execute
167 * @return 0 if OK, 1 for error
168 */
169int board_run_command(const char *cmdline);
wdenk78f66222002-08-27 10:27:51 +0000170#endif /* __ASSEMBLY__ */
171
172/*
173 * Command Flags:
174 */
175#define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
176#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
Simon Glass87b63982014-10-07 13:59:43 -0600177#define CMD_FLAG_ENV 0x0004 /* command is from the environment */
wdenk78f66222002-08-27 10:27:51 +0000178
Mike Frysinger722b0612010-10-20 03:52:39 -0400179#ifdef CONFIG_AUTO_COMPLETE
180# define _CMD_COMPLETE(x) x,
181#else
182# define _CMD_COMPLETE(x)
183#endif
184#ifdef CONFIG_SYS_LONGHELP
185# define _CMD_HELP(x) x,
186#else
187# define _CMD_HELP(x)
188#endif
wdenk8bde7f72003-06-27 21:31:46 +0000189
Simon Glassfb241122016-03-13 19:07:33 -0600190#ifdef CONFIG_CMDLINE
Marek Vasut6c7c9462012-10-12 10:27:04 +0000191#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
192 _usage, _help, _comp) \
193 { #_name, _maxargs, _rep, _cmd, _usage, \
194 _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
wdenk8bde7f72003-06-27 21:31:46 +0000195
Marek Vasut6c7c9462012-10-12 10:27:04 +0000196#define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \
Albert ARIBAUDef123c52013-02-25 00:59:00 +0000197 ll_entry_declare(cmd_tbl_t, _name, cmd) = \
Marek Vasut6c7c9462012-10-12 10:27:04 +0000198 U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
199 _usage, _help, _comp);
wdenk8bde7f72003-06-27 21:31:46 +0000200
Simon Glassfb241122016-03-13 19:07:33 -0600201#else
202#define U_BOOT_SUBCMD_START(name) static cmd_tbl_t name[] = {};
203#define U_BOOT_SUBCMD_END
204
205#define _CMD_REMOVE(_name, _cmd) \
206 int __remove_ ## _name(void) \
207 { \
208 if (0) \
209 _cmd(NULL, 0, 0, NULL); \
210 return 0; \
211 }
212#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, \
213 _help, _comp) \
214 { #_name, _maxargs, _rep, 0 ? _cmd : NULL, _usage, \
215 _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
216
217#define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, \
218 _comp) \
219 _CMD_REMOVE(sub_ ## _name, _cmd)
220
221#endif /* CONFIG_CMDLINE */
222
Marek Vasut6c7c9462012-10-12 10:27:04 +0000223#define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \
224 U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
wdenk8bde7f72003-06-27 21:31:46 +0000225
Simon Glassfb241122016-03-13 19:07:33 -0600226#define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \
227 U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
228 _usage, _help, NULL)
229
wdenk78f66222002-08-27 10:27:51 +0000230#endif /* __COMMAND_H */