shell: add commands for ftl and mufs
This commit is contained in:
parent
8714c04f2e
commit
ff0b94789e
5 changed files with 155 additions and 8 deletions
16
Makefile
16
Makefile
|
@ -19,18 +19,22 @@ CFLAGS += -Os
|
||||||
LDFLAGS += -Os
|
LDFLAGS += -Os
|
||||||
|
|
||||||
obj-y += source/bitops.o
|
obj-y += source/bitops.o
|
||||||
obj-y += source/bitset.o
|
|
||||||
obj-y += source/main.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/core/flash.o
|
||||||
|
|
||||||
obj-y += source/fs/block.o
|
obj-y += source/fs/mufs/super.o
|
||||||
obj-y += source/fs/part.o
|
|
||||||
|
|
||||||
|
obj-y += source/ftl/dev.o
|
||||||
obj-y += source/ftl/ftl.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))
|
obj = $(addprefix $(BUILD)/, $(obj-y))
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ struct cmd {
|
||||||
};
|
};
|
||||||
|
|
||||||
void do_flash_cmd(const char *line);
|
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_exec(struct cmd *cmds, const char *line);
|
||||||
void cmd_loop(const char *s);
|
void cmd_loop(const char *s);
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
struct cmd main_cmds[] = {
|
struct cmd main_cmds[] = {
|
||||||
{ "flash", do_flash_cmd },
|
{ "flash", do_flash_cmd },
|
||||||
{ "part", do_part_cmd },
|
{ "ftl", do_ftl_cmd },
|
||||||
|
{ "mufs", do_mufs_cmd },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
79
source/shell/ftl.c
Normal file
79
source/shell/ftl.c
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <flash.h>
|
||||||
|
#include <ftl.h>
|
||||||
|
#include <macros.h>
|
||||||
|
#include <shell.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
62
source/shell/mufs.c
Normal file
62
source/shell/mufs.c
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <flash.h>
|
||||||
|
#include <ftl.h>
|
||||||
|
#include <macros.h>
|
||||||
|
#include <shell.h>
|
||||||
|
|
||||||
|
#include <fs/mufs.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue