mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 07:58:09 +00:00
embed: rename trassert to ensure
This commit is contained in:
parent
8cc8272fb3
commit
2fc69bed61
@ -151,13 +151,13 @@ int main(void)
|
||||
clear_otg_hs_memory();
|
||||
periph_init();
|
||||
|
||||
trassert(0 == display_init(), NULL);
|
||||
trassert(0 == flash_init(), NULL);
|
||||
trassert(0 == sdcard_init(), NULL);
|
||||
ensure(0 == display_init(), NULL);
|
||||
ensure(0 == flash_init(), NULL);
|
||||
ensure(0 == sdcard_init(), NULL);
|
||||
|
||||
if (check_sdcard()) {
|
||||
if (!copy_sdcard()) {
|
||||
trassert(true == copy_sdcard(), NULL);
|
||||
ensure(true == copy_sdcard(), NULL);
|
||||
} else {
|
||||
for (;;);
|
||||
}
|
||||
@ -165,7 +165,7 @@ int main(void)
|
||||
|
||||
check_and_jump();
|
||||
|
||||
trassert(0, "halt");
|
||||
ensure(0, "halt");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -128,17 +128,17 @@ int usb_init_all(void) {
|
||||
.report_desc = hid_report_desc,
|
||||
};
|
||||
|
||||
trassert(0 == usb_init(&dev_info), NULL);
|
||||
trassert(0 == usb_hid_add(&hid_info), NULL);
|
||||
trassert(0 == usb_start(), NULL);
|
||||
ensure(0 == usb_init(&dev_info), NULL);
|
||||
ensure(0 == usb_hid_add(&hid_info), NULL);
|
||||
ensure(0 == usb_start(), NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mainloop(void)
|
||||
{
|
||||
trassert(0 == flash_init(), NULL);
|
||||
trassert(0 == usb_init_all(), NULL);
|
||||
ensure(0 == flash_init(), NULL);
|
||||
ensure(0 == usb_init_all(), NULL);
|
||||
|
||||
display_clear();
|
||||
|
||||
@ -149,7 +149,7 @@ void mainloop(void)
|
||||
if (r != USB_PACKET_SIZE) {
|
||||
continue;
|
||||
}
|
||||
trassert(r == USB_PACKET_SIZE, NULL);
|
||||
ensure(r == USB_PACKET_SIZE, NULL);
|
||||
uint16_t msg_id;
|
||||
uint32_t msg_size;
|
||||
if (!msg_parse_header(buf, &msg_id, &msg_size)) {
|
||||
@ -190,12 +190,12 @@ void check_bootloader_version(void)
|
||||
bits[i / 8] |= (1 << (7 - (i % 8)));
|
||||
}
|
||||
}
|
||||
trassert(true == flash_otp_write(BOOTLOADER_VERSION_OTP_BLOCK, 0, bits, FLASH_OTP_BLOCK_SIZE), NULL);
|
||||
ensure(true == flash_otp_write(BOOTLOADER_VERSION_OTP_BLOCK, 0, bits, FLASH_OTP_BLOCK_SIZE), NULL);
|
||||
|
||||
uint8_t bits2[FLASH_OTP_BLOCK_SIZE];
|
||||
trassert(true == flash_otp_read(BOOTLOADER_VERSION_OTP_BLOCK, 0, bits2, FLASH_OTP_BLOCK_SIZE), NULL);
|
||||
ensure(true == flash_otp_read(BOOTLOADER_VERSION_OTP_BLOCK, 0, bits2, FLASH_OTP_BLOCK_SIZE), NULL);
|
||||
|
||||
trassert(0 == memcmp(bits, bits2, FLASH_OTP_BLOCK_SIZE), "Bootloader downgraded");
|
||||
ensure(0 == memcmp(bits, bits2, FLASH_OTP_BLOCK_SIZE), "Bootloader downgraded");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -212,7 +212,7 @@ int main(void)
|
||||
display_orientation(0);
|
||||
display_backlight(255);
|
||||
|
||||
trassert(0 == touch_init(), NULL);
|
||||
ensure(0 == touch_init(), NULL);
|
||||
|
||||
uint32_t touched = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@ -225,7 +225,7 @@ int main(void)
|
||||
check_and_jump();
|
||||
}
|
||||
|
||||
trassert(0, "halt");
|
||||
ensure(0, "halt");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -86,9 +86,9 @@ 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)) {
|
||||
trassert(0, msg.buf);
|
||||
ensure(0, msg.buf);
|
||||
} else {
|
||||
trassert(0, "halt");
|
||||
ensure(0, "halt");
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ int main(void)
|
||||
display_orientation(0);
|
||||
display_backlight(255);
|
||||
|
||||
trassert(0 == flash_init(), NULL);
|
||||
trassert(0 == sdcard_init(), NULL);
|
||||
trassert(0 == touch_init(), NULL);
|
||||
ensure(0 == flash_init(), NULL);
|
||||
ensure(0 == sdcard_init(), NULL);
|
||||
ensure(0 == touch_init(), NULL);
|
||||
|
||||
for (;;) {
|
||||
printf("CORE: Starting main loop\n");
|
||||
@ -75,7 +75,7 @@ int main(void)
|
||||
// MicroPython default exception handler
|
||||
|
||||
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
|
||||
trassert(0, "uncaught exception");
|
||||
ensure(0, "uncaught exception");
|
||||
}
|
||||
|
||||
void PendSV_Handler(void) {
|
||||
|
@ -6,7 +6,7 @@ static int vcp_iface_num = -1;
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
|
||||
trassert(vcp_iface_num >= 0, "vcp stdio is not configured");
|
||||
ensure(vcp_iface_num >= 0, "vcp stdio is not configured");
|
||||
|
||||
#define VCP_READ_TIMEOUT 25
|
||||
uint8_t c = 0;
|
||||
|
@ -34,7 +34,7 @@ uint32_t __stack_chk_guard;
|
||||
|
||||
void __attribute__((noreturn)) __stack_chk_fail(void)
|
||||
{
|
||||
trassert(0, "Stack smashing detected");
|
||||
ensure(0, "Stack smashing detected");
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -14,7 +14,7 @@ void periph_init(void);
|
||||
|
||||
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);
|
||||
|
||||
#define trassert(expr, msg) ((expr) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||
#define ensure(expr, msg) ((expr) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||
|
||||
void jump_to(uint32_t address);
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);
|
||||
|
||||
#define trassert(expr, msg) ((expr) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||
#define ensure(expr, msg) ((expr) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user