int main(void) { _buttonusr_isr = (void *)&buttonisr_usr; _timerusr_isr = (void *)&timerisr_usr; _mmhusr_isr = (void *)&mmhisr; /* Drop privileges */ drop_privs(); /* Init board */ kk_board_init(); /* Program the model into OTP, if we're not in screen-test mode, and it's * not already there */ (void)flash_programModel(); /* Init for safeguard against stack overflow (-fstack-protector-all) */ __stack_chk_guard = (uintptr_t)random32(); /* Bootloader Verification */ check_bootloader(); led_func(SET_RED_LED); dbg_print("Application Version %d.%d.%d\n\r", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION); /* Init storage */ storage_init(); /* Init protcol buffer message map and usb msg callback */ fsm_init(); led_func(SET_GREEN_LED); usbInit(); u2fInit(); led_func(CLR_RED_LED); reset_idle_time(); if (is_mfg_mode()) layout_screen_test(); else if (!storage_isInitialized()) layout_standard_notification("Welcome", "keepkey.com/get-started", NOTIFICATION_LOGO); else layoutHomeForced(); while (1) { delay_ms_with_callback(ONE_SEC, &exec, 1); increment_idle_time(ONE_SEC); toggle_screensaver(); } return 0; }
/* * keepkey_leds_init() - Initialize gpios for LEDs * * INPUT * none * OUTPUT * none */ void keepkey_leds_init(void) { #ifndef EMULATOR pin_init_output(&GREEN_LED, PUSH_PULL_MODE, NO_PULL_MODE); pin_init_output(&RED_LED, PUSH_PULL_MODE, NO_PULL_MODE); led_func(CLR_GREEN_LED); led_func(CLR_RED_LED); #endif }
/* * dbg_trigger() - Scope trigger pulse for debugging * * INPUT * - color: color of led to trigger * OUTPUT * none */ void dbg_trigger(uint32_t color) { switch(color) { case 1: led_func(CLR_RED_LED); led_func(SET_RED_LED); break; case 2: led_func(CLR_GREEN_LED); led_func(SET_GREEN_LED); } }
/* * kk_board_init() - Initialize board * * INPUT * none * OUTPUT * none */ void kk_board_init(void) { kk_timer_init(); // keepkey_leds_init(); led_func(CLR_GREEN_LED); led_func(CLR_RED_LED); kk_keepkey_button_init(); #ifndef EMULATOR svc_enable_interrupts(); // This enables the timer and button interrupts #endif layout_init(display_canvas_init()); }
/* * boot() - Runs through application firmware checking, and then boots * * INPUT * none * OUTPUT * true/false whether boot was successful * */ static bool boot(void) { if(magic_ok()) { layout_home(); if(signatures_ok() == 0) /* Signature check failed */ { delay_ms(500); if(!confirm_without_button_request("Unofficial Firmware", "Do you want to continue booting?")) { layout_simple_message("Boot Aborted"); goto cancel_boot; } layout_home(); } led_func(CLR_RED_LED); cm_disable_interrupts(); set_vector_table_application(); application_jump(); } else { layout_simple_message("Please Reinstall Firmware"); goto cancel_boot; } cancel_boot: return(false); }
/* * 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 */ }
/* * main() - Application main entry * * INPUT * none * OUTPUT * 0 when complete */ int main(void) { /* Init for safeguard against stack overflow (-fstack-protector-all) */ __stack_chk_guard = (uintptr_t)random32(); /* Init board */ board_init(); led_func(SET_RED_LED); dbg_print("Application Version %d.%d.%d\n\r", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION); /* Init storage */ storage_init(); /* Init protcol buffer message map and usb msg callback */ fsm_init(); led_func(SET_GREEN_LED); screen_test(); /* Enable interrupt for timer */ cm_enable_interrupts(); usb_init(); led_func(CLR_RED_LED); reset_idle_time(); while(1) { delay_ms_with_callback(ONE_SEC, &exec, 1); increment_idle_time(ONE_SEC); toggle_screensaver(); } return(0); }
/* * update_fw() - Firmware update mode * * INPUT * none * OUTPUT * none * */ static void update_fw(void) { led_func(CLR_GREEN_LED); if(usb_flash_firmware()) { layout_standard_notification("Firmware Update Complete", "Please disconnect and reconnect.", NOTIFICATION_UNPLUG); display_refresh(); } else { layout_simple_message("Firmware Update Failure, Try Again"); } }
static int led_avila_attach(device_t dev) { struct led_avila_softc *sc = device_get_softc(dev); struct ixp425_softc *sa = device_get_softc(device_get_parent(dev)); sc->sc_dev = dev; sc->sc_iot = sa->sc_iot; sc->sc_gpio_ioh = sa->sc_gpio_ioh; /* Configure LED GPIO pin as output */ GPIO_CONF_WRITE_4(sc, IXP425_GPIO_GPOER, GPIO_CONF_READ_4(sc, IXP425_GPIO_GPOER) &~ GPIO_LED_STATUS_BIT); sc->sc_led = led_create(led_func, sc, "gpioled"); led_func(sc, 1); /* Turn on LED */ return (0); }