shell: add boot commands

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent db0a62fc9f
commit 428ce212a5
  1. 1
      Makefile
  2. 6
      include/shell/boot.h
  3. 65
      source/shell/boot.c

@ -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

@ -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);

@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <console.h>
#include <macros.h>
#include <fs/mufs.h>
#include <shell/boot.h>
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 <version>\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;
}
Loading…
Cancel
Save