/* * 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 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef USE_BACKUP_RAM #include #endif #ifdef USE_OPTIGA #include #endif #ifdef USE_TAMPER #include #endif #ifdef USE_TROPIC #include #endif static void drivers_init(void) { flash_init(); parse_boardloader_capabilities(); unit_properties_init(); #ifdef USE_STORAGE_HWKEY secure_aes_init(); #endif entropy_init(); #ifdef USE_TAMPER tamper_init(); #endif random_delays_init(); #ifdef RDI random_delays_start_rdi(); #endif #ifdef USE_OEM_KEYS_CHECK check_oem_keys(); #endif #if PRODUCTION || BOOTLOADER_QA check_and_replace_bootloader(); #endif #ifdef USE_OPTIGA optiga_init_and_configure(); #endif #ifdef USE_TROPIC tropic_init(); #endif #ifdef USE_BACKUP_RAM backup_ram_init(); #endif } // Secure monitor panic handler // (may be called from interrupt context) static void secmon_panic(const systask_postmortem_t *pminfo) { // Since the system state is unreliable, enter emergency mode, // store the postmortem info into bootargs and reboot. system_emergency_rescue(NULL, pminfo); } // defined in linker script extern uint32_t _codelen; #define SECMON_SIZE ((uint32_t) & _codelen) #define KERNEL_START (FIRMWARE_START + SECMON_SIZE) int main(void) { // Initialize system's core services system_init(secmon_panic); tz_init(); // Initialize secure monitor drivers drivers_init(); // Jump to the kernel (non-secure world) jump_to_vectbl_ns(KERNEL_START); }