| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #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;
- }
|