1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 01:48:17 +00:00

embed: rename trassert to ensure

This commit is contained in:
Pavol Rusnak 2017-10-12 16:06:53 +02:00
parent 8cc8272fb3
commit 2fc69bed61
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
8 changed files with 26 additions and 26 deletions

View File

@ -151,13 +151,13 @@ int main(void)
clear_otg_hs_memory(); clear_otg_hs_memory();
periph_init(); periph_init();
trassert(0 == display_init(), NULL); ensure(0 == display_init(), NULL);
trassert(0 == flash_init(), NULL); ensure(0 == flash_init(), NULL);
trassert(0 == sdcard_init(), NULL); ensure(0 == sdcard_init(), NULL);
if (check_sdcard()) { if (check_sdcard()) {
if (!copy_sdcard()) { if (!copy_sdcard()) {
trassert(true == copy_sdcard(), NULL); ensure(true == copy_sdcard(), NULL);
} else { } else {
for (;;); for (;;);
} }
@ -165,7 +165,7 @@ int main(void)
check_and_jump(); check_and_jump();
trassert(0, "halt"); ensure(0, "halt");
return 0; return 0;
} }

View File

@ -128,17 +128,17 @@ int usb_init_all(void) {
.report_desc = hid_report_desc, .report_desc = hid_report_desc,
}; };
trassert(0 == usb_init(&dev_info), NULL); ensure(0 == usb_init(&dev_info), NULL);
trassert(0 == usb_hid_add(&hid_info), NULL); ensure(0 == usb_hid_add(&hid_info), NULL);
trassert(0 == usb_start(), NULL); ensure(0 == usb_start(), NULL);
return 0; return 0;
} }
void mainloop(void) void mainloop(void)
{ {
trassert(0 == flash_init(), NULL); ensure(0 == flash_init(), NULL);
trassert(0 == usb_init_all(), NULL); ensure(0 == usb_init_all(), NULL);
display_clear(); display_clear();
@ -149,7 +149,7 @@ void mainloop(void)
if (r != USB_PACKET_SIZE) { if (r != USB_PACKET_SIZE) {
continue; continue;
} }
trassert(r == USB_PACKET_SIZE, NULL); ensure(r == USB_PACKET_SIZE, NULL);
uint16_t msg_id; uint16_t msg_id;
uint32_t msg_size; uint32_t msg_size;
if (!msg_parse_header(buf, &msg_id, &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))); 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]; 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) int main(void)
@ -212,7 +212,7 @@ int main(void)
display_orientation(0); display_orientation(0);
display_backlight(255); display_backlight(255);
trassert(0 == touch_init(), NULL); ensure(0 == touch_init(), NULL);
uint32_t touched = 0; uint32_t touched = 0;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -225,7 +225,7 @@ int main(void)
check_and_jump(); check_and_jump();
} }
trassert(0, "halt"); ensure(0, "halt");
return 0; return 0;
} }

View File

@ -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) { STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t msg; mp_buffer_info_t msg;
if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) { if (n_args > 0 && mp_get_buffer(args[0], &msg, MP_BUFFER_READ)) {
trassert(0, msg.buf); ensure(0, msg.buf);
} else { } else {
trassert(0, "halt"); ensure(0, "halt");
} }
return mp_const_none; return mp_const_none;
} }

View File

@ -33,9 +33,9 @@ int main(void)
display_orientation(0); display_orientation(0);
display_backlight(255); display_backlight(255);
trassert(0 == flash_init(), NULL); ensure(0 == flash_init(), NULL);
trassert(0 == sdcard_init(), NULL); ensure(0 == sdcard_init(), NULL);
trassert(0 == touch_init(), NULL); ensure(0 == touch_init(), NULL);
for (;;) { for (;;) {
printf("CORE: Starting main loop\n"); printf("CORE: Starting main loop\n");
@ -75,7 +75,7 @@ int main(void)
// MicroPython default exception handler // MicroPython default exception handler
void __attribute__((noreturn)) nlr_jump_fail(void *val) { void __attribute__((noreturn)) nlr_jump_fail(void *val) {
trassert(0, "uncaught exception"); ensure(0, "uncaught exception");
} }
void PendSV_Handler(void) { void PendSV_Handler(void) {

View File

@ -6,7 +6,7 @@ static int vcp_iface_num = -1;
int mp_hal_stdin_rx_chr(void) { 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 #define VCP_READ_TIMEOUT 25
uint8_t c = 0; uint8_t c = 0;

View File

@ -34,7 +34,7 @@ uint32_t __stack_chk_guard;
void __attribute__((noreturn)) __stack_chk_fail(void) void __attribute__((noreturn)) __stack_chk_fail(void)
{ {
trassert(0, "Stack smashing detected"); ensure(0, "Stack smashing detected");
} }
#ifndef NDEBUG #ifndef NDEBUG

View File

@ -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); 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); void jump_to(uint32_t address);

View File

@ -3,6 +3,6 @@
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func); 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 #endif