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.
123 lines
2.9 KiB
123 lines
2.9 KiB
![]()
7 years ago
|
/*
|
||
|
* 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/>.
|
||
|
*/
|
||
|
|
||
![]()
8 years ago
|
#include <stdint.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
![]()
6 years ago
|
#include "lib/utils/pyexec.h"
|
||
![]()
8 years ago
|
#include "py/compile.h"
|
||
|
#include "py/gc.h"
|
||
![]()
8 years ago
|
#include "py/mperrno.h"
|
||
![]()
6 years ago
|
#include "py/nlr.h"
|
||
|
#include "py/repl.h"
|
||
|
#include "py/runtime.h"
|
||
|
#include "py/stackctrl.h"
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
#include "ports/stm32/gccollect.h"
|
||
|
#include "ports/stm32/pendsv.h"
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
#include "bl_check.h"
|
||
![]()
8 years ago
|
#include "common.h"
|
||
|
#include "display.h"
|
||
![]()
8 years ago
|
#include "flash.h"
|
||
![]()
7 years ago
|
#include "mpu.h"
|
||
![]()
8 years ago
|
#include "rng.h"
|
||
|
#include "sdcard.h"
|
||
|
#include "touch.h"
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
int main(void) {
|
||
|
// reinitialize HAL for Trezor One
|
||
![]()
6 years ago
|
#if TREZOR_MODEL == 1
|
||
![]()
6 years ago
|
HAL_Init();
|
||
![]()
6 years ago
|
#endif
|
||
|
|
||
![]()
6 years ago
|
collect_hw_entropy();
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
#if TREZOR_MODEL == T
|
||
![]()
6 years ago
|
check_and_replace_bootloader();
|
||
|
// Enable MPU
|
||
|
mpu_config_firmware();
|
||
![]()
6 years ago
|
#endif
|
||
![]()
7 years ago
|
|
||
![]()
6 years ago
|
// Init peripherals
|
||
|
pendsv_init();
|
||
![]()
6 years ago
|
|
||
|
#if TREZOR_MODEL == 1
|
||
![]()
6 years ago
|
display_init();
|
||
|
touch_init();
|
||
![]()
6 years ago
|
#endif
|
||
|
|
||
|
#if TREZOR_MODEL == T
|
||
![]()
6 years ago
|
sdcard_init();
|
||
|
touch_init();
|
||
|
touch_power_on();
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
display_clear();
|
||
![]()
6 years ago
|
#endif
|
||
![]()
7 years ago
|
|
||
![]()
6 years ago
|
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)
|
||
|
|
||
|
// 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();
|
||
|
|
||
|
return 0;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
// MicroPython default exception handler
|
||
|
|
||
|
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
|
||
![]()
6 years ago
|
ensure(secfalse, "uncaught exception");
|
||
![]()
7 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
void PendSV_Handler(void) { pendsv_isr_handler(); }
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
// MicroPython builtin stubs
|
||
![]()
8 years ago
|
|
||
|
mp_import_stat_t mp_import_stat(const char *path) {
|
||
![]()
6 years ago
|
return MP_IMPORT_STAT_NO_EXIST;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
|
mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||
![]()
6 years ago
|
return mp_const_none;
|
||
![]()
8 years ago
|
}
|
||
|
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|