clean up and size optimisations

master
S.J.R. van Schaik 7 years ago
parent b5cdc92ba8
commit 1c0a6907df
  1. 2
      Makefile
  2. 12
      include/shell.h
  3. 1
      include/shell/mufs.h
  4. 61
      source/main.c
  5. 2
      source/platform/stm32f0/alarm.c
  6. 2
      source/shell/alarm.c
  7. 15
      source/shell/boot.c
  8. 4
      source/shell/echo.c
  9. 32
      source/shell/flash.c
  10. 17
      source/shell/ftl.c
  11. 22
      source/shell/mufs.c
  12. 2
      source/shell/version.c

@ -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

@ -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);

@ -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);

@ -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)

@ -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();

@ -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);

@ -7,14 +7,25 @@
#include <mufs.h>
#include <shell.h>
#include <shell/alarm.h>
#include <shell/boot.h>
#include <shell/buzzer.h>
#include <shell/led.h>
#include <shell/rtc.h>
#include <shell/version.h>
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)

@ -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;
}

@ -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 <command>\n");
return -1;
}
return cmd_exec(flash_cmds, con, argc, argv);
}

@ -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 <command>\n");
return -1;
}
return cmd_exec(ftl_cmds, con, argc, argv);
}

@ -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);
}

@ -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;
}

Loading…
Cancel
Save