2018-02-26 13:06:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
|
|
|
*
|
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-02-24 12:19:00 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "py/nlr.h"
|
|
|
|
#include "py/compile.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "py/stackctrl.h"
|
|
|
|
#include "py/repl.h"
|
|
|
|
#include "py/gc.h"
|
2017-03-26 21:11:57 +00:00
|
|
|
#include "py/mperrno.h"
|
2017-02-24 12:19:00 +00:00
|
|
|
#include "lib/utils/pyexec.h"
|
|
|
|
|
2017-03-07 13:50:09 +00:00
|
|
|
#include "gccollect.h"
|
2017-02-24 12:19:00 +00:00
|
|
|
#include "pendsv.h"
|
|
|
|
|
2017-03-21 00:41:49 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "display.h"
|
2017-03-07 14:52:19 +00:00
|
|
|
#include "flash.h"
|
2018-02-23 18:08:34 +00:00
|
|
|
#include "mpu.h"
|
2017-03-07 14:52:19 +00:00
|
|
|
#include "rng.h"
|
|
|
|
#include "sdcard.h"
|
|
|
|
#include "touch.h"
|
2017-03-24 15:38:46 +00:00
|
|
|
|
2017-10-11 19:15:22 +00:00
|
|
|
int main(void)
|
2017-09-28 12:08:08 +00:00
|
|
|
{
|
2018-02-23 18:08:34 +00:00
|
|
|
// Enable MPU
|
|
|
|
mpu_config();
|
|
|
|
|
2017-11-21 13:33:36 +00:00
|
|
|
// Init peripherals
|
2017-02-24 12:19:00 +00:00
|
|
|
pendsv_init();
|
2017-10-20 13:25:24 +00:00
|
|
|
sdcard_init();
|
2017-10-20 15:18:55 +00:00
|
|
|
touch_init();
|
2017-03-07 14:52:19 +00:00
|
|
|
|
2018-02-22 19:40:04 +00:00
|
|
|
display_clear();
|
|
|
|
|
2017-11-21 13:33:36 +00:00
|
|
|
printf("CORE: Preparing stack\n");
|
|
|
|
// Stack limit should be less than real stack size, so we have a chance
|
|
|
|
// to recover from limit hit.
|
|
|
|
mp_stack_set_top(&_estack);
|
|
|
|
mp_stack_set_limit((char*)&_estack - (char*)&_heap_end - 1024);
|
|
|
|
|
|
|
|
// GC init
|
|
|
|
printf("CORE: Starting GC\n");
|
|
|
|
gc_init(&_heap_start, &_heap_end);
|
|
|
|
|
|
|
|
// Interpreter init
|
|
|
|
printf("CORE: Starting interpreter\n");
|
|
|
|
mp_init();
|
|
|
|
mp_obj_list_init(mp_sys_argv, 0);
|
|
|
|
mp_obj_list_init(mp_sys_path, 0);
|
|
|
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
|
|
|
|
|
2018-02-08 17:04:10 +00:00
|
|
|
// Set optimization level
|
|
|
|
MP_STATE_VM(mp_optimise_value) = PYOPT;
|
|
|
|
|
2017-11-21 13:33:36 +00:00
|
|
|
// Execute the main script
|
|
|
|
printf("CORE: Executing main script\n");
|
|
|
|
pyexec_frozen_module("main.py");
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
printf("CORE: Main script finished, cleaning up\n");
|
|
|
|
mp_deinit();
|
2017-02-24 12:19:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-11 18:01:22 +00:00
|
|
|
// MicroPython default exception handler
|
|
|
|
|
|
|
|
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
|
2017-10-26 21:51:39 +00:00
|
|
|
ensure(secfalse, "uncaught exception");
|
2017-10-11 18:01:22 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 21:11:59 +00:00
|
|
|
void PendSV_Handler(void) {
|
|
|
|
pendsv_isr_handler();
|
|
|
|
}
|
|
|
|
|
2017-11-21 13:33:36 +00:00
|
|
|
// MicroPython builtin stubs
|
2017-02-24 12:19:00 +00:00
|
|
|
|
|
|
|
mp_import_stat_t mp_import_stat(const char *path) {
|
|
|
|
return MP_IMPORT_STAT_NO_EXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|