diff --git a/Makefile b/Makefile index f63e21e..0cea796 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ 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 diff --git a/include/shell.h b/include/shell.h index 7953af5..90899df 100644 --- a/include/shell.h +++ b/include/shell.h @@ -6,5 +6,7 @@ struct cmd { }; void do_flash_cmd(const char *line); +void do_part_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 5aa1342..1cac743 100644 --- a/source/shell/cmd.c +++ b/source/shell/cmd.c @@ -6,6 +6,7 @@ struct cmd main_cmds[] = { { "flash", do_flash_cmd }, + { "part", do_part_cmd }, { NULL, NULL }, }; diff --git a/source/shell/part.c b/source/shell/part.c new file mode 100644 index 0000000..f0ca218 --- /dev/null +++ b/source/shell/part.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +static void do_part_create(const char *s); + +static struct cmd part_cmds[] = { + { "create", do_part_create }, + { NULL, NULL }, +}; + +extern struct flash_dev *flash; + +static void do_part_create(const char *s) +{ + (void)s; + + if (!flash) { + fprintf(stderr, "error: no flash device probed.\n"); + return; + } + + if (part_create(flash) != 0) { + fprintf(stderr, "error: unable to create partition table.\n"); + return; + } +} + +void do_part_cmd(const char *line) +{ + cmd_exec(part_cmds, line); +}