tbm-mcu/source/shell/ftl.c

55 lines
988 B
C
Raw Normal View History

2017-05-19 19:02:03 +02:00
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
2017-07-24 17:57:13 +02:00
#include <console.h>
2017-05-19 19:02:03 +02:00
#include <flash.h>
#include <ftl.h>
#include <macros.h>
#include <shell.h>
extern struct flash_dev *flash;
2017-07-27 11:54:31 +02:00
static int do_ftl_probe(struct console *con, size_t argc, const char **argv)
2017-05-19 19:02:03 +02:00
{
(void)argv;
(void)argc;
2017-05-19 19:02:03 +02:00
if (flash) {
flash_release(flash);
flash = NULL;
}
if (!(flash = flash_probe())) {
2017-07-24 17:57:13 +02:00
fprintf(con->fp, "error: unable to probe the flash device.\n");
2017-07-27 11:54:31 +02:00
return -1;
2017-05-19 19:02:03 +02:00
}
if (!(flash = ftl_mount(flash))) {
2017-07-24 17:57:13 +02:00
fprintf(con->fp, "error: unable to mount the flash translation layer.\n");
2017-07-27 11:54:31 +02:00
return -1;
2017-05-19 19:02:03 +02:00
}
2017-07-27 11:54:31 +02:00
return 0;
2017-05-19 19:02:03 +02:00
}
static struct cmd ftl_cmds[] = {
{ "probe", NULL, do_ftl_probe },
{ NULL, NULL, NULL },
};
2017-07-27 11:54:31 +02:00
int do_ftl_cmd(struct console *con, size_t argc, const char **argv)
2017-05-19 19:02:03 +02:00
{
if (argc < 1) {
2017-07-24 17:57:13 +02:00
fprintf(con->fp, "usage: flash <command>\n");
2017-07-27 11:54:31 +02:00
return -1;
}
2017-07-27 11:54:31 +02:00
return cmd_exec(ftl_cmds, con, argc, argv);
2017-05-19 19:02:03 +02:00
}