From ff0b94789e8cb22b10771512139fbde7401862df Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Fri, 19 May 2017 19:02:03 +0200 Subject: [PATCH] shell: add commands for ftl and mufs --- Makefile | 16 +++++++---- include/shell.h | 3 +- source/shell/cmd.c | 3 +- source/shell/ftl.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ source/shell/mufs.c | 62 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 source/shell/ftl.c create mode 100644 source/shell/mufs.c diff --git a/Makefile b/Makefile index 53cc0f8..75a4a0a 100644 --- a/Makefile +++ b/Makefile @@ -19,18 +19,22 @@ CFLAGS += -Os LDFLAGS += -Os obj-y += source/bitops.o -obj-y += source/bitset.o obj-y += source/main.o -obj-y += source/shell/cmd.o -obj-y += source/shell/flash.o -obj-y += source/shell/part.o obj-y += source/core/flash.o -obj-y += source/fs/block.o -obj-y += source/fs/part.o +obj-y += source/fs/mufs/super.o +obj-y += source/ftl/dev.o obj-y += source/ftl/ftl.o +obj-y += source/ftl/gc.o +obj-y += source/ftl/map.o + +obj-y += source/shell/cmd.o +obj-y += source/shell/flash.o +obj-y += source/shell/ftl.o +obj-y += source/shell/mufs.o +obj-y += source/shell/part.o obj = $(addprefix $(BUILD)/, $(obj-y)) diff --git a/include/shell.h b/include/shell.h index 90899df..ba12b24 100644 --- a/include/shell.h +++ b/include/shell.h @@ -6,7 +6,8 @@ struct cmd { }; void do_flash_cmd(const char *line); -void do_part_cmd(const char *line); +void do_ftl_cmd(const char *line); +void do_mufs_cmd(const char *line); void cmd_exec(struct cmd *cmds, const char *line); void cmd_loop(const char *s); diff --git a/source/shell/cmd.c b/source/shell/cmd.c index 77803c6..65c66fd 100644 --- a/source/shell/cmd.c +++ b/source/shell/cmd.c @@ -6,7 +6,8 @@ struct cmd main_cmds[] = { { "flash", do_flash_cmd }, - { "part", do_part_cmd }, + { "ftl", do_ftl_cmd }, + { "mufs", do_mufs_cmd }, { NULL, NULL }, }; diff --git a/source/shell/ftl.c b/source/shell/ftl.c new file mode 100644 index 0000000..de4bb64 --- /dev/null +++ b/source/shell/ftl.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +static void do_ftl_mount(const char *s); +static void do_ftl_test(const char *s); + +static struct cmd ftl_cmds[] = { + { "mount", do_ftl_mount }, + { "test", do_ftl_test }, + { NULL, NULL }, +}; + +extern struct flash_dev *flash; + +static void do_ftl_mount(const char *s) +{ + (void)s; + + if (!flash) { + fprintf(stderr, "error: no flash device probed.\n"); + return; + } + + if (!(flash = ftl_mount(flash))) { + fprintf(stderr, "error: unable to mount the device.\n"); + return; + } +} + +static void do_ftl_test(const char *s) +{ + uint8_t page[4096]; + uint32_t n; + + (void)s; + + if (!flash) { + fprintf(stderr, "error: no flash device probed.\n"); + return; + } + + memset(page, 0xff, 4096); + memcpy(page, "test", 4); + + /*for (n = 0; n < 64; ++n) { + if (flash_write(dev, n << 12, page, sizeof page) == 0) + printf("unable to write the upage\n"); + } + + ftl_trim(dev->priv, 0x29);*/ + + for (n = 0; n < 64; ++n) { + if (ftl_is_mapped(flash->priv, n)) + printf("%x [OK]\n", n); + else + printf("%x [FAIL]\n", n); + } + + printf("Capacity: %u/%u bytes (%u%% used)\n", + flash_get_size(flash), + flash_get_capacity(flash), + 100 * flash_get_size(flash) / flash_get_capacity(flash)); +} + +void do_ftl_cmd(const char *line) +{ + cmd_exec(ftl_cmds, line); +} diff --git a/source/shell/mufs.c b/source/shell/mufs.c new file mode 100644 index 0000000..5dac496 --- /dev/null +++ b/source/shell/mufs.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +static void do_mufs_mount(const char *s); +static void do_mufs_format(const char *s); + +static struct cmd mufs_cmds[] = { + { "mount", do_mufs_mount }, + { "format", do_mufs_format }, + { NULL, NULL }, +}; + +extern struct flash_dev *flash; +struct mufs mufs; + +static void do_mufs_mount(const char *s) +{ + (void)s; + + if (!flash) { + fprintf(stderr, "error: no flash device probed.\n"); + return; + } + + if (mufs_mount(&mufs, flash) < 0) { + fprintf(stderr, "error: unable to mount the filesystem.\n"); + return; + } +} + +static void do_mufs_format(const char *s) +{ + (void)s; + + if (!flash) { + fprintf(stderr, "error: no flash device probed.\n"); + return; + } + + if (mufs_format(flash) < 0) { + fprintf(stderr, "error: unable to format the flash device.\n"); + return; + } +} + +void do_mufs_cmd(const char *line) +{ + cmd_exec(mufs_cmds, line); +}