Commit ce0af021 authored by Alessandro Rubini's avatar Alessandro Rubini

shell: optionally define a build-time init command

This commit adds the possibility to build an init command in the
binary.  It can be useful to install a number of nodes with a special
configuration, without the need to reach the shell and/or eeprom of
each one.

This is useful, for example, to pass syslog configuration
or the (yet to be implemented) definition of multiple vlans for
etherbone and the wr fabric (frame classes 7 and 6 f the packet
filter). Moreover, I personally love to load a master or slave node
for testing without interacting with the node (or changing the flash
over and over).

This commit also makes reading of commands from storage an optional
feature, but only in the advanced/developer options. Thus, you can
build a wrpc that uses the build-time init commands, or the
flash-stored init commands, both or none of them.

Size effects:
     * no effect if you keep the defaults (no build-time init, flash init)
     * +248 bytes (+ the command itself) if you enable build-time init
     * -1696 bytes if you remove flash-based init (discouraged)
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 4cfc5987
......@@ -91,6 +91,36 @@ config SYSLOG
The user (or init script) must use "syslog <ipaddr> <macaddr>"
to enable it. The special "off" ipaddr disables syslog.
config BUILD_INIT
depends on WR_NODE
default n
boolean "Include an init command in the binary (build-time)"
config INIT_COMMAND
depends on BUILD_INIT
string "Enter the init command, use ';' as command separator"
default ""
config INIT_COMMAND
string
default ""
# The following two integer values are derived, and used in if() (shell.c)
config HAS_BUILD_INIT
int
default 1 if BUILD_INIT
default 0
config HAS_FLASH_INIT
int
default 1 if FLASH_INIT
default 0
config FLASH_INIT
boolean
default y if EMBEDDED_NODE
default n
#
# This is a set of configuration options that should not be changed by
# normal users. If the "developer" menu is used, the binary is tainted.
......@@ -142,6 +172,11 @@ config CMD_LL
on the master, because they are just sent to the slave
during the initial handshake
config FLASH_INIT
depends on WR_NODE && DEVELOPER
default y
boolean "Read init commands from flash storage"
# CHECK_RESET for switch and node
config CHECK_RESET
depends on DEVELOPER
......
......@@ -16,12 +16,17 @@ CONFIG_W1=y
CONFIG_IP=y
CONFIG_CMD_CONFIG=y
CONFIG_SYSLOG=y
CONFIG_BUILD_INIT=y
CONFIG_INIT_COMMAND="help"
CONFIG_HAS_BUILD_INIT=1
CONFIG_HAS_FLASH_INIT=1
#
# wrpc-sw is tainted if you change the following options
#
CONFIG_DEVELOPER=y
CONFIG_CMD_LL=y
CONFIG_FLASH_INIT=y
CONFIG_CHECK_RESET=y
CONFIG_SPLL_FIFO_LOG=y
CONFIG_PRINTF_FULL=y
......
......@@ -248,6 +248,23 @@ const char *fromdec(const char *dec, int *v)
return dec;
}
static char shell_init_cmd[] = CONFIG_INIT_COMMAND;
static int build_init_readcmd(uint8_t *cmd, int maxlen)
{
static char *p = shell_init_cmd;
int i;
/* use semicolon as separator */
for (i = 0; i < maxlen && p[i] && p[i] != ';'; i++)
cmd[i] = p[i];
cmd[i] = '\0';
p += i;
if (*p == ';')
p++;
return i;
}
void shell_boot_script(void)
{
uint8_t next = 0;
......@@ -255,7 +272,16 @@ void shell_boot_script(void)
if (!has_eeprom)
return;
while (1) {
while (CONFIG_HAS_BUILD_INIT) {
cmd_len = build_init_readcmd((uint8_t *)cmd_buf,
SH_MAX_LINE_LEN);
if (!cmd_len)
break;
pp_printf("executing: %s\n", cmd_buf);
_shell_exec();
}
while (CONFIG_HAS_FLASH_INIT) {
cmd_len = storage_init_readcmd((uint8_t *)cmd_buf,
SH_MAX_LINE_LEN, next);
if (cmd_len <= 0) {
......
......@@ -11,7 +11,6 @@ obj-$(CONFIG_WR_NODE) += \
shell/cmd_gui.o \
shell/cmd_sdb.o \
shell/cmd_mac.o \
shell/cmd_init.o \
shell/cmd_ptrack.o \
shell/cmd_help.o \
shell/cmd_ps.o \
......@@ -22,3 +21,4 @@ obj-$(CONFIG_PPSI) += shell/cmd_verbose.o
obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o
obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o
obj-$(CONFIG_CMD_LL) += shell/cmd_ll.o
obj-$(CONFIG_FLASH_INIT) += shell/cmd_init.o
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