/* NOTE: Do not autostart burried devices without hardware override! E.g. use RS485 break condition to stay in bootloader, or make sure JTAG pins are accessible to restore to a working state. */ int main(void) { hyministm32v_init(); bootloader_init(); if (!flash_null(_config.start)) _config.start(); bootloader_blink_loop(LED); // bootloader_loop(); return 0; }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); bootloader_init(); // Check if we reset in the middle of a firmware update if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); softdevice_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. softdevice_init(!app_reset); scheduler_init(); } // Check if the Bootloader Control pin is low. If so, enter the bootloader // mode. dfu_start = (nrf_gpio_pin_read(BOOTLOADER_CTRL_PIN) == 0); // If the Bootloader Control pin is low or the application in the flash // is not valid, enter the bootloader mode. if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); } // If the application was or now is valid, run it if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
//! @brief Entry point for the bootloader. int main(void) { bootloader_init(); bootloader_run(); // Should never end up here. debug_printf("Warning: reached end of main()\r\n"); return 0; }
void call_start_cpu(void) { // 1. Hardware initialization if(bootloader_init() != ESP_OK){ return; } // 2. Select image to boot esp_image_metadata_t image_data; if(select_image(&image_data) != ESP_OK){ return; } // 3. Loading the selected image bootloader_utility_load_image(&image_data); }
/* * 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) { init_clock(); NVIC_SetPriority(SWI2_IRQn, 2); NVIC_EnableIRQ(SWI2_IRQn); __enable_irq(); #ifdef RTT_LOG SEGGER_RTT_Init(); __LOG("= START | %s | ===========================================================\n", __TIME__); #endif init_leds(); bootloader_init(); /* Wait for any ongoing bank transfers to finish. */ while (dfu_bank_transfer_in_progress()) { /* may safely while-loop here, as the bank-transfer finishes in an IRQ. */ __WFE(); } /* check whether we should go to application */ if (NRF_POWER->GPREGRET == RBC_MESH_GPREGRET_CODE_GO_TO_APP) { bootloader_abort(DFU_END_SUCCESS); } NRF_POWER->GPREGRET = RBC_MESH_GPREGRET_CODE_GO_TO_APP; bootloader_enable(); while (1) { __WFE(); } }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0) ? true: false); if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(LED_0); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_clear(LED_0); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { leds_off(); // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } nrf_gpio_pin_clear(LED_0); nrf_gpio_pin_clear(LED_1); NVIC_SystemReset(); }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); } dfu_start = app_reset; dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE) ? true: false); // If button is held down for 3 seconds, don't start bootloader. // This means that we go straight to Espruino, where the button is still // pressed and can be used to stop execution of the sent code. if (dfu_start) { nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); int count = 3000; while (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE && count) { nrf_delay_us(999); count--; } if (!count) dfu_start = false; nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, !BOOTLOADER_BUTTON_PRESS_LED_ONSTATE); } if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
int main(int argc, char **argv) { bool do_verify = false; bool do_reset = false; char **itr; const char *opt; const char *filename = NULL; uint16_t vid = 0, pid = 0; bool vidpid_valid; struct bootloader *bl; int res; if (argc < 2) { print_usage(argv[0]); return 1; } /* Parse the command line. */ itr = argv+1; opt = *itr; while (opt) { if (opt[0] == '-') { /* Option parameter */ if (opt[1] == '-') { /* Long option, two dashes. */ if (!strcmp(opt, "--help")) { print_usage(argv[0]); return 1; } else if (!strcmp(opt, "--reset")) do_reset = true; else if (!strcmp(opt, "--verify")) do_verify = true; else if (!strncmp(opt, "--dev", 5)) { if (opt[5] != '=') { fprintf(stderr, "--dev requires vid/pid pair\n\n"); return 1; } vidpid_valid = parse_vid_pid(opt+6, &vid, &pid); if (!vidpid_valid) { fprintf(stderr, "Invalid VID/PID pair\n\n"); return 1; } } else { fprintf(stderr, "Invalid Parameter %s\n\n", opt); return 1; } } else { const char *c = opt + 1; if (!*c) { /* This is a parameter of a single hyphen, which means read from stdin. */ filename = opt; } while (*c) { /* Short option, only one dash */ switch (*c) { case 'v': do_verify = true; break; case 'r': do_reset = true; break; case 'd': itr++; opt = *itr; if (!opt) { fprintf(stderr, "Must specify vid:pid after -d\n\n"); return 1; } vidpid_valid = parse_vid_pid(opt, &vid, &pid); if (!vidpid_valid) { fprintf(stderr, "Invalid VID/PID pair\n\n"); return 1; } break; default: fprintf(stderr, "Invalid parameter '%c'\n\n", *c); return 1; } c++; } } } else { /* Doesn't start with a dash. Must be the filename */ if (filename) { fprintf(stderr, "Multiple filenames listed. This is not supported\n\n"); return 1; } filename = opt; } itr++; opt = *itr; } vid = vidpid_valid? vid: DEFAULT_VID; pid = vidpid_valid? pid: DEFAULT_PID; if (!filename) { fprintf(stderr, "No Filename specified. Specify a filename of use \"-\" to read from stdin.\n"); return 1; } /* Command line parsing is done. Do the programming of the device. */ /* Open the device */ res = bootloader_init(&bl, filename, vid, pid); if (res == BOOTLOADER_CANT_OPEN_FILE) { fprintf(stderr, "Unable to open file %s\n", filename); return 1; } else if (res == BOOTLOADER_CANT_OPEN_DEVICE) { fprintf(stderr, "\nUnable to open device %04hx:%04hx " "for programming.\n" "Make sure that the device is connected " "and that you have proper permissions\nto " "open it.\n", vid, pid); return 1; } else if (res == BOOTLOADER_CANT_QUERY_DEVICE) { fprintf(stderr, "Unable to query device parameters\n"); return 1; } else if (res == BOOTLOADER_MULTIPLE_CONNECTED) { fprintf(stderr, "Multiple devices are connected. Remove all but one.\n"); } else if (res < 0) { fprintf(stderr, "Unspecified error initializing bootloader %d\n", res); return 1; } /* Erase */ res = bootloader_erase(bl); if (res < 0) { fprintf(stderr, "Erasing of device failed\n"); return 1; } /* Program */ res = bootloader_program(bl); if (res < 0) { fprintf(stderr, "Programming of device failed\n"); return 1; } /* Verify */ if (do_verify) { res = bootloader_verify(bl); if (res < 0) { fprintf(stderr, "Verification of programmed memory failed\n"); return 1; } } /* Reset */ if (do_reset) { res = bootloader_reset(bl); if (res < 0) { fprintf(stderr, "Device Reset failed\n"); return 1; } } /* Close */ bootloader_free(bl); return 0; }
/* * Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); if (app_reset) { NRF_POWER->GPREGRET = 0; } leds_init(); #if defined(DBGLOG_SUPPORT) uart_init(); #endif PUTS("\nBootloader *** " __DATE__ " " __TIME__ " ***"); // This check ensures that the defined fields in the bootloader // corresponds with actual setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); #if defined(BUTTON_SUPPORT) buttons_init(); #endif (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!app_reset); scheduler_init(); dis_init(); } dfu_start = app_reset; #if defined(BUTTON_SUPPORT) dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); #endif if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); PUTS("Start DFU"); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { PUTS("Start App"); // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); bool power_on = (NRF_POWER->GPREGRET == 0x000000); if (dfu_start || power_on) { NRF_POWER->GPREGRET = BOOTLOADER_APP_START; } // leds_init(); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); // buttons_init(); (void)bootloader_init(); if (bootloader_dfu_sd_in_progress()) { // nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); ble_stack_init(!dfu_start); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); // nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else { // If stack is present then continue initialization of bootloader. ble_stack_init(!dfu_start); scheduler_init(); } // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); if (power_on || dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { // nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED); // Initiate an update of the firmware. err_code = bootloader_dfu_start(power_on); APP_ERROR_CHECK(err_code); // nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED); } else if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) { // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }