Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/source/main.c

97 lines
2.0 KiB

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <buzzer.h>
#include <console.h>
#include <gpio.h>
#include <flash.h>
#include <ftl.h>
#include <mufs.h>
#include <rcc.h>
#include <rtc.h>
#include <shell.h>
#include <shell/alarm.h>
#include <shell/boot.h>
#include <shell/buzzer.h>
#include <shell/echo.h>
#include <shell/led.h>
#include <shell/mufs.h>
#include <shell/rtc.h>
#include <shell/version.h>
struct console *user_con, *admin_con;
struct shell user_shell, admin_shell;
extern struct flash_dev *flash;
extern struct mufs *mufs;
extern struct buzzer buzzers[];
extern size_t nbuzzers;
struct cmd user_cmds[] = {
{ "hi", "", shell_version },
{ "buzzer", "", shell_buzzer },
{ "led", "", shell_led },
{ "reset", "", shell_alarm },
{ "cat", "", shell_cat },
{ "ls", "", shell_ls },
{ "date", "", shell_date },
{ "time", "", shell_time },
{ "booting", "", shell_prepare },
{ NULL, NULL, NULL },
};
struct cmd admin_cmds[] = {
{ "echo", "", shell_echo },
{ "buzzer", "", shell_buzzer },
{ "led", "", shell_led },
{ "reset", "", shell_alarm },
{ "flash", "", do_flash_cmd },
{ "ftl", "", do_ftl_cmd },
{ "mufs", "", do_mufs_cmd },
{ "date", "", shell_date },
{ "time", "", shell_time },
{ "set-date", "", shell_set_date },
{ "set-time", "", shell_set_time },
{ NULL, NULL, NULL },
};
int main(void)
{
size_t i;
rcc_init();
gpio_init();
rtc_init(NULL);
for (i = 0; i < nbuzzers; ++i) {
buzzer_init(buzzers + i);
}
user_con = console_init(1);
admin_con = console_init(0);
if ((flash = flash_probe())) {
flash = ftl_mount(flash);
mufs = mufs_mount(flash);
} else {
fprintf(admin_con->fp, "error: unable to probe flash chip.\n");
}
fprintf(user_con->fp, "TBM-dev (built on " __DATE__ ")\n");
fprintf(admin_con->fp, "TBM-dev (built on " __DATE__ ")\n");
shell_init(&user_shell, user_cmds, user_con, "tbm $",
SHELL_SHOW_EXIT_CODE);
shell_init(&admin_shell, admin_cmds, admin_con, "tbm #",
SHELL_SHOW_EXIT_CODE);
while (1) {
shell_parse(&user_shell);
shell_parse(&admin_shell);
}
return 0;
}