diff --git a/Makefile b/Makefile index b4b8e0e..16e42d7 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ all: $(BUILD)/tbm -include scripts/Makefile.${TARGET} -CFLAGS += -DTBM_VERSION=\"2017-07-27-dev\" +CFLAGS += -DTBM_VERSION=\"2017-10-31\" CFLAGS += -Iinclude CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration CFLAGS += -Wredundant-decls -pedantic diff --git a/include/shell.h b/include/shell.h index 7499d28..b9018d6 100644 --- a/include/shell.h +++ b/include/shell.h @@ -6,7 +6,6 @@ struct console; struct cmd { const char *cmd; - const char *desc; int (* exec)(struct console *con, size_t argc, const char **argv); }; @@ -31,6 +30,11 @@ int shell_init(struct shell *shell, struct cmd *cmds, struct console *con, const char *prompt, unsigned flags); int shell_parse(struct shell *shell); -int do_flash_cmd(struct console *con, size_t argc, const char **argv); -int do_ftl_cmd(struct console *con, size_t argc, const char **argv); -int do_mufs_cmd(struct console *con, size_t argc, const char **argv); +int shell_flash_probe(struct console *con, size_t argc, const char **argv); +int shell_flash_release(struct console *con, size_t argc, const char **argv); +int shell_flash_info(struct console *con, size_t argc, const char **argv); +int shell_flash_read(struct console *con, size_t argc, const char **argv); +int shell_flash_write(struct console *con, size_t argc, const char **argv); +int shell_flash_erase(struct console *con, size_t argc, const char **argv); + +int shell_ftl_probe(struct console *con, size_t argc, const char **argv); diff --git a/include/shell/mufs.h b/include/shell/mufs.h index 1ff3572..6ff49e0 100644 --- a/include/shell/mufs.h +++ b/include/shell/mufs.h @@ -10,5 +10,6 @@ int shell_cat(struct console *con, size_t argc, const char **argv); int shell_write(struct console *con, size_t argc, const char **argv); int shell_append(struct console *con, size_t argc, const char **argv); int shell_mv(struct console *con, size_t argc, const char **argv); +int shell_cp(struct console *con, size_t argc, const char **argv); int shell_rm(struct console *con, size_t argc, const char **argv); int shell_ls(struct console *con, size_t argc, const char **argv); diff --git a/source/main.c b/source/main.c index 82352fe..7d7de53 100644 --- a/source/main.c +++ b/source/main.c @@ -31,31 +31,48 @@ extern struct buzzer buzzers[]; extern size_t nbuzzers; struct cmd user_cmds[] = { - { "hi", "", shell_version }, - { "buzzer", "", shell_buzzer }, - { "led", "", shell_led }, - { "reset", "", shell_alarm }, - { "cat", "", shell_cat }, - { "ls", "", shell_ls }, - { "date", "", shell_date }, - { "time", "", shell_time }, - { "booting", "", shell_prepare }, - { NULL, NULL, NULL }, + { "hi", shell_version }, + { "buzzer", shell_buzzer }, + { "led", shell_led }, + { "reset", shell_alarm }, + { "cat", shell_cat }, + { "ls", shell_ls }, + { "date", shell_date }, + { "time", shell_time }, + { "booting", shell_prepare }, + { NULL, NULL }, }; struct cmd admin_cmds[] = { - { "echo", "", shell_echo }, - { "buzzer", "", shell_buzzer }, - { "led", "", shell_led }, - { "reset", "", shell_alarm }, - { "flash", "", do_flash_cmd }, - { "ftl", "", do_ftl_cmd }, - { "mufs", "", do_mufs_cmd }, - { "date", "", shell_date }, - { "time", "", shell_time }, - { "set-date", "", shell_set_date }, - { "set-time", "", shell_set_time }, - { NULL, NULL, NULL }, + { "echo", shell_echo }, + { "buzzer", shell_buzzer }, + { "led", shell_led }, + { "reset", shell_alarm }, + { "flash_probe", shell_flash_probe }, + { "flash_release", shell_flash_release }, + { "flash_info", shell_flash_info }, + { "flash_read", shell_flash_read }, + { "flash_write", shell_flash_write }, + { "flash_erase", shell_flash_erase }, + { "ftl_probe", shell_ftl_probe }, + { "date", shell_date }, + { "time", shell_time }, + { "set_date", shell_set_date }, + { "set_time", shell_set_time }, + { "mount", shell_mount }, + { "umount", shell_unmount }, + { "format", shell_format }, + { "mkdir", shell_mkdir }, + { "rmdir", shell_rmdir }, + { "ls", shell_ls }, + { "stat", shell_stat }, + { "cat", shell_cat }, + { "write", shell_write }, + { "append", shell_append }, + { "mv", shell_mv, }, + { "cp", shell_cp, }, + { "rm", shell_rm, }, + { NULL, NULL }, }; int main(void) diff --git a/source/platform/stm32f0/alarm.c b/source/platform/stm32f0/alarm.c index 8ef09d4..c65f061 100644 --- a/source/platform/stm32f0/alarm.c +++ b/source/platform/stm32f0/alarm.c @@ -128,8 +128,6 @@ int alarm_enable(uint32_t timeout) int alarm_disable(void) { - uint32_t alarm_sec; - gpio_set(GPIOC, GPIO8); pwr_disable_backup_domain_write_protect(); diff --git a/source/shell/alarm.c b/source/shell/alarm.c index f4b88d3..6c4467e 100644 --- a/source/shell/alarm.c +++ b/source/shell/alarm.c @@ -12,6 +12,8 @@ int shell_alarm(struct console *con, size_t argc, const char **argv) int state = 0; uint32_t timeout = 10; + (void)con; + if (argc >= 2) timeout = strtoul(argv[0], NULL, 0); diff --git a/source/shell/boot.c b/source/shell/boot.c index 8a514b4..eef3669 100644 --- a/source/shell/boot.c +++ b/source/shell/boot.c @@ -7,14 +7,25 @@ #include #include +#include #include +#include +#include +#include +#include extern struct mufs *mufs; extern struct shell user_shell; struct cmd safe_cmds[] = { - { "booting", "", shell_boot }, - { NULL, NULL, NULL }, + { "hi", shell_version }, + { "buzzer", shell_buzzer }, + { "led", shell_led }, + { "reset", shell_alarm }, + { "date", shell_date }, + { "time", shell_time }, + { "booting", shell_boot }, + { NULL, NULL }, }; int shell_prepare(struct console *con, size_t argc, const char **argv) diff --git a/source/shell/echo.c b/source/shell/echo.c index 103e5ba..fd610b4 100644 --- a/source/shell/echo.c +++ b/source/shell/echo.c @@ -9,9 +9,7 @@ int shell_echo(struct console *con, size_t argc, const char **argv) if (argc < 1) return -1; - fprintf(con->fp, "%s\n", argv[0]); + fputs(argv[0], con->fp); return 0; } - - diff --git a/source/shell/flash.c b/source/shell/flash.c index 5e14809..bd8751c 100644 --- a/source/shell/flash.c +++ b/source/shell/flash.c @@ -57,7 +57,7 @@ static void print_hex_ascii(FILE *fp, uint32_t offset, const char *buf, size_t l } } -static int do_flash_probe(struct console *con, size_t argc, const char **argv) +int shell_flash_probe(struct console *con, size_t argc, const char **argv) { (void)argv; (void)argc; @@ -75,7 +75,7 @@ static int do_flash_probe(struct console *con, size_t argc, const char **argv) return 0; } -static int do_flash_release(struct console *con, size_t argc, const char **argv) +int shell_flash_release(struct console *con, size_t argc, const char **argv) { (void)argv; (void)argc; @@ -91,7 +91,7 @@ static int do_flash_release(struct console *con, size_t argc, const char **argv) return 0; } -static int do_flash_info(struct console *con, size_t argc, const char **argv) +int shell_flash_info(struct console *con, size_t argc, const char **argv) { char jedec_id[3] = { 0, 0, 0 }; size_t size, capacity; @@ -118,7 +118,7 @@ static int do_flash_info(struct console *con, size_t argc, const char **argv) return 0; } -static int do_flash_read(struct console *con, size_t argc, const char **argv) +int shell_flash_read(struct console *con, size_t argc, const char **argv) { char buf[256]; size_t addr, len, nbytes; @@ -162,7 +162,7 @@ static int do_flash_read(struct console *con, size_t argc, const char **argv) return 0; } -static int do_flash_write(struct console *con, size_t argc, const char **argv) +int shell_flash_write(struct console *con, size_t argc, const char **argv) { char buf[256]; size_t addr, len, nbytes; @@ -211,7 +211,7 @@ static int do_flash_write(struct console *con, size_t argc, const char **argv) return 0; } -static int do_flash_erase(struct console *con, size_t argc, const char **argv) +int shell_flash_erase(struct console *con, size_t argc, const char **argv) { size_t addr, len; @@ -246,23 +246,3 @@ static int do_flash_erase(struct console *con, size_t argc, const char **argv) return 0; } - -static struct cmd flash_cmds[] = { - { "probe", NULL, do_flash_probe }, - { "release", NULL, do_flash_release }, - { "info", NULL, do_flash_info }, - { "read", NULL, do_flash_read }, - { "write", NULL, do_flash_write }, - { "erase", NULL, do_flash_erase }, - { NULL, NULL, NULL }, -}; - -int do_flash_cmd(struct console *con, size_t argc, const char **argv) -{ - if (argc < 1) { - fprintf(con->fp, "usage: flash \n"); - return -1; - } - - return cmd_exec(flash_cmds, con, argc, argv); -} diff --git a/source/shell/ftl.c b/source/shell/ftl.c index 110eb65..d7e84f2 100644 --- a/source/shell/ftl.c +++ b/source/shell/ftl.c @@ -15,7 +15,7 @@ extern struct flash_dev *flash; -static int do_ftl_probe(struct console *con, size_t argc, const char **argv) +int shell_ftl_probe(struct console *con, size_t argc, const char **argv) { (void)argv; (void)argc; @@ -37,18 +37,3 @@ static int do_ftl_probe(struct console *con, size_t argc, const char **argv) return 0; } - -static struct cmd ftl_cmds[] = { - { "probe", NULL, do_ftl_probe }, - { NULL, NULL, NULL }, -}; - -int do_ftl_cmd(struct console *con, size_t argc, const char **argv) -{ - if (argc < 1) { - fprintf(con->fp, "usage: flash \n"); - return -1; - } - - return cmd_exec(ftl_cmds, con, argc, argv); -} diff --git a/source/shell/mufs.c b/source/shell/mufs.c index e1d472c..ba8b76b 100644 --- a/source/shell/mufs.c +++ b/source/shell/mufs.c @@ -380,25 +380,3 @@ int shell_ls(struct console *con, size_t argc, const char **argv) mufs_closedir(dir); return 0; } - -static struct cmd mufs_cmds[] = { - { "mount", NULL, shell_mount }, - { "umount", NULL, shell_unmount }, - { "format", NULL, shell_format }, - { "mkdir", NULL, shell_mkdir }, - { "rmdir", NULL, shell_rmdir }, - { "ls", NULL, shell_ls }, - { "stat", NULL, shell_stat }, - { "cat", NULL, shell_cat }, - { "write", NULL, shell_write }, - { "append", NULL, shell_append }, - { "mv", NULL, shell_mv, }, - { "cp", NULL, shell_cp, }, - { "rm", NULL, shell_rm, }, - { NULL, NULL, NULL }, -}; - -int do_mufs_cmd(struct console *con, size_t argc, const char **argv) -{ - return cmd_exec(mufs_cmds, con, argc, argv); -} diff --git a/source/shell/version.c b/source/shell/version.c index 0c607ae..0e3c03f 100644 --- a/source/shell/version.c +++ b/source/shell/version.c @@ -11,7 +11,7 @@ int shell_version(struct console *con, size_t argc, const char **argv) if (argc < 1) return -1; - fprintf(con->fp, "hello %s\n", TBM_VERSION); + fputs(TBM_VERSION, con->fp); return 0; }