// 1NNN: Jumps to address NNN static int op_1XXX(word_t op) { int nnn = (op >> 0) & 0xFFF; if (chip8.PC == nnn) system_halt(); // infinite loop detected chip8.PC = nnn; // to avoid later increment system_decPC(); return SUCCESS; }
void show_unofficial_warning(void) { layoutDialog(DIALOG_ICON_WARNING, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL); do { delay(100000); buttonUpdate(); } while (!button.YesUp && !button.NoUp); if (button.YesUp) { return; // yes button was pressed -> return } layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); }
void check_firmware_sanity(void) { int broken = 0; if (memcmp((void *)FLASH_META_MAGIC, "TRZR", 4)) { // magic does not match broken++; } if (*((uint32_t *)FLASH_META_CODELEN) < 4096) { // firmware reports smaller size than 4kB broken++; } if (*((uint32_t *)FLASH_META_CODELEN) > FLASH_TOTAL_SIZE - (FLASH_APP_START - FLASH_ORIGIN)) { // firmware reports bigger size than flash size broken++; } if (broken) { layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Firmware appears", "to be broken.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); } }
/* * main - Bootloader main entry function * * INPUT * - argc: (not used) * - argv: (not used) * OUTPUT * 0 when complete */ int main(int argc, char *argv[]) { (void)argc; (void)argv; clock_init(); bootloader_init(); #if !defined(DEBUG_ON) && (MEMORY_PROTECT == 0) #error "To compile release version, please set MEMORY_PROTECT flag" #elif !defined(DEBUG_ON) /* Checks and sets memory protection */ memory_protect(); #elif (MEMORY_PROTECT == 1) #error "Can only compile release versions with MEMORY_PROTECT flag" #endif /* Initialize stack guard with random value (-fstack_protector_all) */ __stack_chk_guard = random32(); led_func(SET_GREEN_LED); led_func(SET_RED_LED); dbg_print("\n\rKeepKey LLC, Copyright (C) 2015\n\r"); dbg_print("BootLoader Version %d.%d.%d\n\r", BOOTLOADER_MAJOR_VERSION, BOOTLOADER_MINOR_VERSION, BOOTLOADER_PATCH_VERSION); if(is_fw_update_mode()) { update_fw(); } else { boot(); } #if DEBUG_LINK board_reset(); #else system_halt(); /* Loops forever */ #endif return(0); /* Should never get here */ }
void show_halt(void) { layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); }
void show_halt(void) { layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); }
/* * storage_commit() - Write content of configuration in shadow memory to * storage partion in flash * * INPUT * none * OUTPUT * none */ void storage_commit(void) { uint32_t shadow_ram_crc32, shadow_flash_crc32, retries; memcpy((void *)&shadow_config, STORAGE_MAGIC_STR, STORAGE_MAGIC_LEN); for(retries = 0; retries < STORAGE_RETRIES; retries++) { /* Capture CRC for verification at restore */ shadow_ram_crc32 = calc_crc32((uint32_t *)&shadow_config, sizeof(shadow_config) / sizeof(uint32_t)); if(shadow_ram_crc32 == 0) { continue; /* Retry */ } /* Make sure flash is in good state before proceeding */ if(!flash_chk_status()) { flash_clear_status_flags(); continue; /* Retry */ } /* Make sure storage sector is valid before proceeding */ if(storage_location < FLASH_STORAGE1 && storage_location > FLASH_STORAGE3) { /* Let it exhaust the retries and error out */ continue; } flash_unlock(); flash_erase_word(storage_location); wear_leveling_shift(); flash_erase_word(storage_location); /* Load storage data first before loading storage magic */ if(flash_write_word(storage_location, STORAGE_MAGIC_LEN, sizeof(shadow_config) - STORAGE_MAGIC_LEN, (uint8_t *)&shadow_config + STORAGE_MAGIC_LEN)) { if(!flash_write_word(storage_location, 0, STORAGE_MAGIC_LEN, (uint8_t *)&shadow_config)) { continue; /* Retry */ } } else { continue; /* Retry */ } /* Flash write completed successfully. Verify CRC */ shadow_flash_crc32 = calc_crc32((uint32_t *)flash_write_helper( storage_location), sizeof(shadow_config) / sizeof(uint32_t)); if(shadow_flash_crc32 == shadow_ram_crc32) { /* Commit successful, break to exit */ break; } else { continue; /* Retry */ } } flash_lock(); if(retries >= STORAGE_RETRIES) { layout_warning_static("Error Detected. Reboot Device!"); system_halt(); } }
int command_sys_halt(struct cli *c, int argc, char **argv) { system_halt(); return 0; }