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