|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <console.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <mufs.h>
|
|
|
|
#include <shell.h>
|
|
|
|
|
|
|
|
#include <shell/boot.h>
|
|
|
|
|
|
|
|
extern struct mufs *mufs;
|
|
|
|
extern struct shell user_shell;
|
|
|
|
|
|
|
|
struct cmd safe_cmds[] = {
|
|
|
|
{ "booting", "", shell_boot },
|
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_shell.cmds = safe_cmds;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|