int main(void) { __stack_chk_guard = random32(); setup(); memory_protect(); oledInit(); // at least one button is unpressed uint16_t state = gpio_port_read(BTN_PORT); if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) { check_firmware_sanity(); oledClear(); oledDrawBitmap(40, 0, &bmp_logo64_empty); oledRefresh(); uint8_t hash[32]; if (!signatures_ok(hash)) { show_unofficial_warning(hash); } load_app(); } bootloader_loop(); return 0; }
/* * 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 */ }
int main(void) { #ifndef APPVER setup(); #endif __stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks #ifndef APPVER memory_protect(); oledInit(); #endif #ifndef APPVER // at least one button is unpressed uint16_t state = gpio_port_read(BTN_PORT); int unpressed = ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO); if (firmware_present() && unpressed) { oledClear(); oledDrawBitmap(40, 0, &bmp_logo64_empty); oledRefresh(); uint8_t hash[32]; int signed_firmware = signatures_ok(hash); if (SIG_OK != signed_firmware) { show_unofficial_warning(hash); timer_init(); } load_app(signed_firmware); } #endif bootloader_loop(); return 0; }
/** * Initialize PXE. */ void pxe_init(void) { bootp_packet_t *bootp; pxe_device_t *pxe; /* Boot device is set to 0x7f by the PXE boot sector. */ if (bios_boot_device != 0x7f) { return; } if (!get_entry_point()) return; dprintf( "pxe: booting via PXE, entry point at %04x:%04x (%p)\n", pxe_entry_point >> 16, pxe_entry_point & 0xffff, segoff_to_linear(pxe_entry_point)); // When using PXE, 0x8d000 onwards is reserved for use by the PXE stack so // we need to mark it as internal to ensure we don't load anything there. // Also reserve a bit more because the PXE ROM on some machines appears to // take a dump over memory below there as well. memory_protect(0x80000, 0x1f000); // Obtain the BOOTP reply packet. bootp = get_bootp_packet(); // Create a device. pxe = malloc(sizeof(*pxe)); memset(pxe, 0, sizeof(*pxe)); pxe->net.ops = &pxe_net_ops; pxe->net.server_port = PXENV_TFTP_PORT; pxe->mount.device = &pxe->net.device; pxe->mount.ops = &pxe_fs_ops; net_device_register_with_bootp(&pxe->net, bootp, true); pxe->net.device.mount = &pxe->mount; // register a pre-boot hook to shut down the PXE stack loader_register_preboot_hook(shutdown_pxe); }