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
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue