1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

make __fatal_error more useful, add make sizecheck target

This commit is contained in:
Pavol Rusnak 2017-04-28 15:39:22 +02:00
parent 44b32aa4a6
commit 8b0336862f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
12 changed files with 79 additions and 70 deletions

View File

@ -28,11 +28,12 @@ install:
- pip2 install ecdsa mnemonic protobuf requests
script:
- test "$GOAL" != "stm32" || test "$CC" != "gcc" || make vendorheader
- test "$GOAL" != "stm32" || test "$CC" != "gcc" || make build_cross
- test "$GOAL" != "stm32" || test "$CC" != "gcc" || make build_boardloader
- test "$GOAL" != "stm32" || test "$CC" != "gcc" || make build_bootloader
- test "$GOAL" != "stm32" || test "$CC" != "gcc" || make build_firmware
- test "$GOAL" != "stm32" || make vendorheader
- test "$GOAL" != "stm32" || make build_cross
- test "$GOAL" != "stm32" || make build_boardloader
- test "$GOAL" != "stm32" || make build_bootloader
- test "$GOAL" != "stm32" || make build_firmware
- test "$GOAL" != "stm32" || make sizecheck
- test "$GOAL" != "unix" || make build_unix TREZOR_NOUI=1
- test "$GOAL" != "unix" || make test

View File

@ -56,11 +56,11 @@ build_boardloader: ## build boardloader
build_bootloader: ## build bootloader
$(MAKE) -f Makefile.bootloader $(TREZORHAL_PORT_OPTS)
./tools/binctl micropython/bootloader/build/bootloader.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
./tools/binctl $(BOOTLOADER_BUILD_DIR)/bootloader.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
build_firmware: res build_cross ## build firmware with frozen modules
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS)
./tools/binctl micropython/firmware/build/firmware.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
./tools/binctl $(FIRMWARE_BUILD_DIR)/firmware.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
build_unix: ## build unix port
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS)
@ -117,10 +117,15 @@ vendorheader: ## construct default vendor header
./tools/binctl micropython/firmware/vendorheader.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
binctl: ## print info about binary files
./tools/binctl micropython/bootloader/build/bootloader.bin
./tools/binctl $(BOOTLOADER_BUILD_DIR)/bootloader.bin
./tools/binctl micropython/firmware/vendorheader.bin
./tools/binctl micropython/firmware/build/firmware.bin
./tools/binctl $(FIRMWARE_BUILD_DIR)/firmware.bin
bloaty: ## run bloaty size profiler
bloaty -d symbols -n 0 -s file micropython/firmware/build/firmware.elf | less
bloaty -d compileunits -n 0 -s file micropython/firmware/build/firmware.elf | less
bloaty -d symbols -n 0 -s file $(FIRMWARE_BUILD_DIR)/firmware.elf | less
bloaty -d compileunits -n 0 -s file $(FIRMWARE_BUILD_DIR)/firmware.elf | less
sizecheck: ## check sizes of binary files
test 32768 -ge $(shell stat -c%s $(BOARDLOADER_BUILD_DIR)/boardloader.bin)
test 65536 -ge $(shell stat -c%s $(BOOTLOADER_BUILD_DIR)/bootloader.bin)
test 917504 -ge $(shell stat -c%s $(FIRMWARE_BUILD_DIR)/firmware.bin)

View File

@ -13,7 +13,7 @@
#define IMAGE_MAXSIZE (1 * 64 * 1024 + 7 * 128 * 1024)
void pendsv_isr_handler(void) {
__fatal_error("pendsv");
__fatal_error("pendsv", __FILE__, __LINE__, __FUNCTION__);
}
bool check_sdcard(void)
@ -146,15 +146,15 @@ int main(void)
periph_init();
if (0 != display_init()) {
__fatal_error("display_init failed");
__fatal_error("display_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != flash_init()) {
__fatal_error("flash_init failed");
__fatal_error("flash_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != sdcard_init()) {
__fatal_error("sdcard_init failed");
__fatal_error("sdcard_init", __FILE__, __LINE__, __FUNCTION__);
}
display_clear();
@ -166,13 +166,13 @@ int main(void)
if (check_sdcard()) {
if (!copy_sdcard()) {
__fatal_error("halt");
__fatal_error("HALT", __FILE__, __LINE__, __FUNCTION__);
}
}
check_and_jump();
__fatal_error("halt");
__fatal_error("HALT", __FILE__, __LINE__, __FUNCTION__);
return 0;
}

View File

@ -19,7 +19,7 @@
#define IMAGE_MAXSIZE (7 * 128 * 1024)
void pendsv_isr_handler(void) {
__fatal_error("pendsv");
__fatal_error("pendsv", __FILE__, __LINE__, __FUNCTION__);
}
void display_vendor(const uint8_t *vimg, const char *vstr, uint32_t vstr_len, uint32_t fw_version)
@ -132,13 +132,13 @@ int usb_init_all(void) {
};
if (0 != usb_init(&dev_info)) {
__fatal_error("usb_init failed");
__fatal_error("usb_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != usb_hid_add(&hid_info)) {
__fatal_error("usb_hid_add failed");
__fatal_error("usb_hid_add", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != usb_start()) {
__fatal_error("usb_start failed");
__fatal_error("usb_start", __FILE__, __LINE__, __FUNCTION__);
}
return 0;
@ -182,11 +182,11 @@ uint32_t process_upload_message(uint32_t msg_size, const uint8_t *initbuf, uint3
void mainloop(void)
{
if (0 != flash_init()) {
__fatal_error("flash_init failed");
__fatal_error("flash_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != usb_init_all()) {
__fatal_error("usb_init_all failed");
__fatal_error("usb_init_all", __FILE__, __LINE__, __FUNCTION__);
}
uint8_t buf[USB_PACKET_SIZE];
@ -238,11 +238,11 @@ int main(void)
periph_init();
if (0 != display_init()) {
__fatal_error("display_init failed");
__fatal_error("display_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != touch_init()) {
__fatal_error("touch_init failed");
__fatal_error("touch_init", __FILE__, __LINE__, __FUNCTION__);
}
display_clear();
@ -258,14 +258,7 @@ int main(void)
check_and_jump();
}
__fatal_error("halt");
__fatal_error("HALT", __FILE__, __LINE__, __FUNCTION__);
return 0;
}
#ifndef NDEBUG
void __assert_func(const char *file, int line, const char *func, const char *expr) {
// printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
__fatal_error("Assertion failed");
}
#endif

View File

@ -60,12 +60,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_memcpy_obj, 5, 5, mod
STATIC mp_obj_t mod_TrezorUtils_halt(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t msg;
if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) {
printf("HALT! %s\n", (const char *)msg.buf);
__fatal_error(msg.buf, __FILE__, __LINE__, __FUNCTION__);
} else {
printf("HALT!\n");
__fatal_error("HALT", __FILE__, __LINE__, __FUNCTION__);
}
// TODO: is this the best we can do?
__fatal_error("HALT");
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_halt_obj, 0, 1, mod_TrezorUtils_halt);

View File

@ -28,23 +28,23 @@ int main(void) {
pendsv_init();
if (0 != display_init()) {
__fatal_error("display_init failed");
__fatal_error("display_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != flash_init()) {
__fatal_error("flash_init failed");
__fatal_error("flash_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != rng_init()) {
__fatal_error("rng_init failed");
__fatal_error("rng_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != sdcard_init()) {
__fatal_error("sdcard_init failed");
__fatal_error("sdcard_init", __FILE__, __LINE__, __FUNCTION__);
}
if (0 != touch_init()) {
__fatal_error("touch_init failed");
__fatal_error("touch_init", __FILE__, __LINE__, __FUNCTION__);
}
for (;;) {
@ -72,13 +72,6 @@ int main(void) {
return 0;
}
#ifndef NDEBUG
void __assert_func(const char *file, int line, const char *func, const char *expr) {
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
__fatal_error("Assertion failed");
}
#endif
// Micropython file I/O stubs
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {

View File

@ -6,12 +6,18 @@
#define FATAL_FGCOLOR 0xFFFF
#define FATAL_BGCOLOR 0x7800
void __attribute__((noreturn)) __fatal_error(const char *msg) {
void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func) {
for (volatile uint32_t delay = 0; delay < 10000000; delay++) {
}
display_print("FATAL ERROR:\n", -1);
display_print("\nFATAL ERROR:\n", -1);
display_print(msg, -1);
display_print("\n", -1);
if (file) {
display_print("\nFile: ", -1); display_print(file, -1); (void)line;
}
if (func) {
display_print("\nFunc: ", -1); display_print(func, -1);
}
display_print("\n", 1);
display_print_out(FATAL_FGCOLOR, FATAL_BGCOLOR);
for (;;) {
display_backlight(255);
@ -21,8 +27,17 @@ void __attribute__((noreturn)) __fatal_error(const char *msg) {
}
}
#ifndef NDEBUG
void __assert_func(const char *file, int line, const char *func, const char *expr) {
display_print("\nassert(", -1);
display_print(expr, -1);
display_print(")\n", 2);
__fatal_error("Assertion failed", file, line, func);
}
#endif
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
__fatal_error("uncaught exception");
__fatal_error("uncaught exception", __FILE__, __LINE__, __FUNCTION__);
}
extern void SystemClock_Config(void);

View File

@ -10,9 +10,9 @@
void periph_init(void);
void __attribute__((noreturn)) nlr_jump_fail(void *val);
void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func);
void __attribute__((noreturn)) __fatal_error(const char *msg);
void __attribute__((noreturn)) nlr_jump_fail(void *val);
void jump_to(uint32_t address);

View File

@ -71,12 +71,11 @@
#include "gccollect.h"
#include "display.h"
#include "common.h"
#define IRQ_ENTER(irq)
#define IRQ_EXIT(irq)
extern void __fatal_error(const char*);
/******************************************************************************/
/* Cortex-M4 Processor Exceptions Handlers */
/******************************************************************************/
@ -174,7 +173,7 @@ void HardFault_C_Handler(ExceptionRegisters_t *regs) {
/* Go to infinite loop when Hard Fault exception occurs */
while (1) {
__fatal_error("HardFault");
__fatal_error("HardFault", __FILE__, __LINE__, __FUNCTION__);
}
}
@ -216,7 +215,7 @@ void NMI_Handler(void) {
void MemManage_Handler(void) {
/* Go to infinite loop when Memory Manage exception occurs */
while (1) {
__fatal_error("MemManage");
__fatal_error("MemManage", __FILE__, __LINE__, __FUNCTION__);
}
}
@ -228,7 +227,7 @@ void MemManage_Handler(void) {
void BusFault_Handler(void) {
/* Go to infinite loop when Bus Fault exception occurs */
while (1) {
__fatal_error("BusFault");
__fatal_error("BusFault", __FILE__, __LINE__, __FUNCTION__);
}
}
@ -240,7 +239,7 @@ void BusFault_Handler(void) {
void UsageFault_Handler(void) {
/* Go to infinite loop when Usage Fault exception occurs */
while (1) {
__fatal_error("UsageFault");
__fatal_error("UsageFault", __FILE__, __LINE__, __FUNCTION__);
}
}

View File

@ -95,7 +95,7 @@
#define MICROPY_HW_CLK_PLLQ (7)
#define MICROPY_HW_CLK_LAST_FREQ (1)
void __fatal_error(const char *msg);
#include "common.h"
/**
* @}
@ -324,7 +324,7 @@ void SystemClock_Config(void)
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
__fatal_error("HAL_RCC_OscConfig");
__fatal_error("HAL_RCC_OscConfig", __FILE__, __LINE__, __FUNCTION__);
}
#endif
@ -409,14 +409,14 @@ void SystemClock_Config(void)
#endif
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
__fatal_error("HAL_RCC_OscConfig");
__fatal_error("HAL_RCC_OscConfig", __FILE__, __LINE__, __FUNCTION__);
}
#if defined(MCU_SERIES_F7)
/* Activate the OverDrive to reach the 200 MHz Frequency */
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
{
__fatal_error("HAL_PWREx_EnableOverDrive");
__fatal_error("HAL_PWREx_EnableOverDrive", __FILE__, __LINE__, __FUNCTION__);
}
#endif
@ -426,7 +426,7 @@ void SystemClock_Config(void)
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, MICROPY_HW_FLASH_LATENCY) != HAL_OK)
{
__fatal_error("HAL_RCC_ClockConfig");
__fatal_error("HAL_RCC_ClockConfig", __FILE__, __LINE__, __FUNCTION__);
}
#if defined(MCU_SERIES_F7)

View File

@ -3,8 +3,13 @@
#include "common.h"
void __attribute__((noreturn)) __fatal_error(const char *msg) {
printf("FATAL ERROR:\n");
printf("%s\n", msg);
void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func) {
printf("\nFATAL ERROR:\n%s\n", msg);
if (file) {
printf("File: %s:%d\n", file, line);
}
if (func) {
printf("Func: %s\n", func);
}
exit(1);
}

View File

@ -1,6 +1,6 @@
#ifndef __TREZORUNIX_COMMON_H__
#define __TREZORUNIX_COMMON_H__
void __attribute__((noreturn)) __fatal_error(const char *msg);
void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func);
#endif