#include "flash.h" #include "nrf_delay.h" #include "uart.h" #include "bootloader.h" //#define NUM_FILE 15984 //static bool store_flag=false; //static bool update_flag=false; //static bool load_flag=false; //static bool clear_flag=false; //static pstorage_handle_t m_storage_handle_app1; //static pstorage_handle_t m_storage_handle_app2; ////static pstorage_handle_t block_hander; //static void upgrade_pstorage_cb_handler(pstorage_handle_t * p_handle, // uint8_t op_code, // uint32_t result, // uint8_t * p_data, // uint32_t data_len) //{ // switch(op_code) // { // case PSTORAGE_LOAD_OP_CODE: // if (result == NRF_SUCCESS) // { // load_flag=true; // printf("BOOTLOADER PSTORAGE_LOAD_OP_CODE success \r\n"); // } // else // { // printf("BOOTLOADER PSTORAGE_LOAD_OP_CODE fail \r\n"); // } // break; // case PSTORAGE_STORE_OP_CODE: // if (result == NRF_SUCCESS) // { // store_flag=true; // printf("BOOTLOADER PSTORAGE_STORE_OP_CODE success \r\n"); // } // else // { // printf("BOOTLOADER PSTORAGE_STORE_OP_CODE fail \r\n"); // } // break; // case PSTORAGE_CLEAR_OP_CODE: // if (result == NRF_SUCCESS) // { // clear_flag=true; // printf("BOOTLOADER PSTORAGE_CLEAR_OP_CODE success \r\n"); // } // else // { // printf("BOOTLOADER PSTORAGE_CLEAR_OP_CODE fail \r\n"); // } // break; // case PSTORAGE_UPDATE_OP_CODE: // if (result == NRF_SUCCESS) // { // update_flag=true; // printf("BOOTLOADER PSTORAGE_UPDATE_OP_CODE success \r\n"); // } // else // { // printf("BOOTLOADER PSTORAGE_UPDATE_OP_CODE fail \r\n"); // } // break; // default:break; // } //} //uint32_t flash_upgrade_op(void) //{ // pstorage_module_param_t param; // uint32_t err_code; // //uint32_t i; // // param.cb = upgrade_pstorage_cb_handler; //// m_storage_handle_app1.block_id = DFU_BANK_0_REGION_START; // // //// err_code = pstorage_init(); //// if(err_code == NRF_SUCCESS) //// { //// printf("BOOTLOADER flash pstorage init success!\r\n"); //// } //// else //// { //// printf("BOOTLOADER flash pstorage init fail!\r\n"); //// return err_code; //// } // err_code = pstorage_register(¶m,&m_storage_handle_app1); // if(err_code == NRF_SUCCESS) // { // printf("BOOTLOADER flash pstorage register success!\r\n"); // } // else // { // printf("BOOTLOADER flash pstorage register fail!\r\n"); // return err_code; // } // // m_storage_handle_app1.block_id = DFU_BANK_0_REGION_START; // m_storage_handle_app2 = m_storage_handle_app1; // m_storage_handle_app2.block_id = DFU_BANK_1_REGION_START; // // clear_flag = false; // err_code = pstorage_clear(&m_storage_handle_app1,DFU_IMAGE_MAX_SIZE_BANKED); // if(err_code == NRF_SUCCESS) // { // printf("BOOTLOADER flash pstorage clear success!\r\n"); // } // else // { // printf("BOOTLOADER flash pstorage clear fail!\r\n"); // } // while(!clear_flag) // { // printf("BOOTLOADER flash clear wating...\r\n"); // nrf_delay_ms(200); // } // store_flag = false; // err_code = pstorage_store(&m_storage_handle_app1,(uint8_t *)m_storage_handle_app2.block_id,NUM_FILE,0); // if(err_code == NRF_SUCCESS) // { // printf("BOOTLOADER flash pstorage store success!\r\n"); // } // else // { // printf("BOOTLOADER flash pstorage store fail!\r\n"); // } // while(!store_flag) // { // printf("BOOTLOADER flash store wating...\r\n"); // nrf_delay_ms(200); // } // printf("BOOTLOADER flash pstorage store all success,start app now!\r\n"); // //nrf_delay_ms(50); // //bootloader_app_start(DFU_BANK_0_REGION_START); // // return err_code; //} uint32_t dfu_app_image_swap(void) { sd_mbr_command_t sd_mbr_cmd; //uint32_t len; uint32_t err_code; sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_SD; sd_mbr_cmd.params.copy_sd.src = (uint32_t *) 0x2AC00; sd_mbr_cmd.params.copy_sd.dst = (uint32_t *) 0x1B000; //sd_mbr_cmd.params.copy_sd.len = 4987; sd_mbr_cmd.params.copy_sd.len = (*((uint32_t *)DFU_APP_DATA_USER_START))/4; err_code = sd_mbr_command(&sd_mbr_cmd); if (err_code != NRF_SUCCESS) { // printf("BOOTLOADER swap app image fail!err_code is %d\r\n",err_code); return err_code; } sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; return sd_mbr_command(&sd_mbr_cmd); } uint16_t reset_data_flash_update(uint8_t *src,uint16_t size,uint16_t offset) { return 0; }