From 428ce212a582522a6e844c8920c0d5b2f28e79c9 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Thu, 27 Jul 2017 12:46:50 +0200 Subject: [PATCH] shell: add boot commands --- Makefile | 1 + include/shell/boot.h | 6 +++++ source/shell/boot.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 include/shell/boot.h create mode 100644 source/shell/boot.c diff --git a/Makefile b/Makefile index d407d0f..cf32451 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ obj-y += source/ftl/gc.o obj-y += source/ftl/map.o obj-y += source/shell/args.o +obj-y += source/shell/boot.o obj-y += source/shell/cmd.o obj-y += source/shell/echo.o obj-y += source/shell/flash.o diff --git a/include/shell/boot.h b/include/shell/boot.h new file mode 100644 index 0000000..a1cf6dd --- /dev/null +++ b/include/shell/boot.h @@ -0,0 +1,6 @@ +#pragma once + +struct console; + +int shell_prepare(struct console *con, size_t argc, const char **argv); +int shell_boot(struct console *con, size_t argc, const char **argv); diff --git a/source/shell/boot.c b/source/shell/boot.c new file mode 100644 index 0000000..fe9464b --- /dev/null +++ b/source/shell/boot.c @@ -0,0 +1,65 @@ +#include +#include +#include + +#include +#include + +#include + +#include + +extern struct mufs *mufs; + +int shell_prepare(struct console *con, size_t argc, const char **argv) +{ + char buf[256]; + struct mufs_file *file; + size_t size, n; + + if (argc < 1) { + fprintf(con->fp, "usage: booting \n"); + return -1; + } + + if (!mufs) { + fprintf(con->fp, "error: no file system mounted.\n"); + return -1; + } + + if (!(file = mufs_open(mufs, "logs/boot.log", MUFS_WRITE | MUFS_APPEND))) { + fprintf(con->fp, "error: unable to open the file\n"); + return -1; + } + + n = min(strlen(argv[0]), sizeof(buf) - 2); + + memcpy(buf, argv[0], n); + buf[n++] = '\n'; + buf[n] = '\0'; + + size = mufs_write(file, buf, n); + mufs_close(file); + + if (size < n) { + fprintf(con->fp, "error: unable to log the version to boot\n"); + return -1; + } + + return 0; +} + +int shell_boot(struct console *con, size_t argc, const char **argv) +{ + (void)con; + + if (argc < 1) { + fprintf(con->fp, "usage: booting ok\n"); + return -1; + } + + if (strcmp(argv[0], "ok") != 0) + return -1; + + return 0; +}