Commit 87e321d9 authored by Adam Wujek's avatar Adam Wujek

Revert "shell: add shell commands at compile time"

This reverts commit shell: add shell commands at compile time
Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent 0636d290
......@@ -45,12 +45,6 @@ SECTIONS
.text : { *(.text .text.*) } > ram =0
.cmd : {
__cmd_begin = .;
KEEP(*(.cmd))
__cmd_end = .;
} > ram
.rodata : { *(.rodata .rodata.*) } > ram
.data : {
......
......@@ -125,10 +125,9 @@ static int cmd_temp(const char *args[])
return 0;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(temp) = {
.name = "temp",
.exec = cmd_temp,
};
*/
......@@ -27,13 +27,10 @@ static int cmd_w1_w(const char *args[])
return i == blen ? 0 : -1;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(w1w) = {
.name = "w1w",
.exec = cmd_w1_w,
};
*/
/* A shell command, for testing read: "w1r <offset> <len> */
static int cmd_w1_r(const char *args[])
......@@ -57,13 +54,10 @@ static int cmd_w1_r(const char *args[])
return i == blen ? 0 : -1;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(w1r) = {
.name = "w1r",
.exec = cmd_w1_r,
};
*/
/* A shell command, for checking */
static int cmd_w1(const char *args[])
......@@ -86,10 +80,8 @@ static int cmd_w1(const char *args[])
return 0;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(w1) = {
.name = "w1",
.exec = cmd_w1,
};
*/
......@@ -25,12 +25,9 @@ struct wrc_shell_cmd {
int (*exec) (const char *args[]);
};
extern struct wrc_shell_cmd __cmd_begin[], __cmd_end[];
/* Put the structures in their own section */
#define DEFINE_WRC_COMMAND(_name) \
static struct wrc_shell_cmd __wrc_cmd_ ## _name \
__attribute__((section(".cmd"), __used__))
struct wrc_shell_cmd __wrc_cmd_ ## _name
char *env_get(const char *var);
int env_set(const char *var, const char *value);
......@@ -42,7 +39,9 @@ extern int shell_is_interacting;
void shell_boot_script(void);
void shell_show_build_init(void);
void shell_register_command( struct wrc_shell_cmd* cmd );
void shell_list_cmds(void);
void shell_register_commands(void);
void shell_activate_ui_command( int (*callback)(void) );
#endif
......@@ -31,10 +31,7 @@ static int cmd_refresh(const char *args[])
return 0;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(refresh) = {
.name = "refresh",
.exec = cmd_refresh,
};
*/
......@@ -9,10 +9,7 @@ static int cmd_uptime(const char *args[])
return 0;
}
/* This command was not registered before */
/*
DEFINE_WRC_COMMAND(uptime) = {
.name = "uptime",
.exec = cmd_uptime,
};
*/
......@@ -65,6 +65,9 @@ static int cmd_pos = 0, cmd_len = 0;
static int state = SH_PROMPT;
static int current_key = 0;
static struct wrc_shell_cmd *cmds[ SHELL_MAX_COMMANDS ];
static int n_cmds = 0;
int shell_is_interacting;
int (*shell_ui_callback)(void);
......@@ -127,8 +130,9 @@ static int _shell_exec(void)
if (*tokptr[0] == '#')
return 0;
for (p = __cmd_begin; p < __cmd_end; p++)
for (i = 0; i < n_cmds; i++)
{
p = cmds[i];
if (!strcasecmp(p->name, tokptr[0])) {
rv = p->exec((const char **)(tokptr + 1));
if (rv < 0)
......@@ -338,6 +342,18 @@ void shell_show_build_init(void)
pp_printf("(empty)\n");
}
void shell_register_command( struct wrc_shell_cmd* cmd )
{
if( n_cmds >= SHELL_MAX_COMMANDS )
{
pp_printf("can't register shell command '%s', increase SHELL_MAX_COMMANDS\n", cmd->name );
return;
}
cmds[ n_cmds ] = cmd;
n_cmds++;
}
void shell_activate_ui_command( int (*callback)(void) )
{
shell_ui_callback = callback;
......@@ -349,11 +365,11 @@ void shell_activate_ui_command( int (*callback)(void) )
static int cmd_help(const char *args[])
{
struct wrc_shell_cmd *p;
int i;
pp_printf("Available commands:\n");
for (p = __cmd_begin; p < __cmd_end; p++) {
pp_printf(" %s\n", p->name);
for(i = 0; i < n_cmds; i++) {
pp_printf(" %s\n", cmds[i]->name);
}
return 0;
......@@ -363,3 +379,38 @@ DEFINE_WRC_COMMAND(help) = {
.name = "help",
.exec = cmd_help,
};
#define REGISTER_WRC_COMMAND(_name) \
{ extern struct wrc_shell_cmd __wrc_cmd_ ## _name; shell_register_command( &__wrc_cmd_ ## _name ); }
void shell_register_commands(void)
{
REGISTER_WRC_COMMAND(gui);
REGISTER_WRC_COMMAND(ps);
REGISTER_WRC_COMMAND(pll);
REGISTER_WRC_COMMAND(ptp);
REGISTER_WRC_COMMAND(verbose);
REGISTER_WRC_COMMAND(mode);
REGISTER_WRC_COMMAND(mac);
REGISTER_WRC_COMMAND(sdb);
REGISTER_WRC_COMMAND(calibration);
REGISTER_WRC_COMMAND(help);
REGISTER_WRC_COMMAND(diag);
REGISTER_WRC_COMMAND(init);
REGISTER_WRC_COMMAND(sfp);
REGISTER_WRC_COMMAND(stat);
REGISTER_WRC_COMMAND(ver);
REGISTER_WRC_COMMAND(ptrack);
REGISTER_WRC_COMMAND(time);
if (HAS_IP)
REGISTER_WRC_COMMAND(ip);
if (HAS_VLANS)
REGISTER_WRC_COMMAND(vlan);
if (HAS_CMD_PPS)
REGISTER_WRC_COMMAND(pps);
if (HAS_CMD_LEAPSEC)
REGISTER_WRC_COMMAND(leapsec);
if (HAS_CMD_NETCONSOLE)
REGISTER_WRC_COMMAND(netconsole);
}
......@@ -102,6 +102,7 @@ static void wrc_initialize(void)
/* try reading t24 phase transition from EEPROM */
calib_t24p(WRC_MODE_MASTER, &cal_phase_transition);
shell_init();
shell_register_commands();
_endram = ENDRAM_MAGIC;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment