I want to use dfu_target lib to implement dfu.
I refer to fota_download.c and test\subsys\dfu. But when I use dfu_target_init() I get an error return value.
I did it based on the hello_world demo. The development board used is nrf9160_nrf52840. My ncs version is 1.8.0.
My prj.conf file:
CONFIG_BOOTLOADER_MCUBOOT=y CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="D:\\Code\\ncs\\bootloader\\mcuboot\\enc-rsa2048-priv.pem" CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE="D:\\Code\\ncs\\bootloader\\mcuboot\\enc-rsa2048-pub.pem" CONFIG_DFU_TARGET=y CONFIG_DFU_TARGET_MCUBOOT=y CONFIG_FLASH=y CONFIG_IMG_ERASE_PROGRESSIVELY=y CONFIG_IMG_MANAGER=y CONFIG_MCUBOOT_IMG_MANAGER=y
My code:
void dfu_target_test()
{
char bin_header[512] = {0x3D, 0xB8, 0xF3, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ret = 0;
int img_type = dfu_target_img_type(bin_header, sizeof(bin_header));
printk("image type: 0x%x\n", img_type);
ret = dfu_target_init(img_type, 0x1000, NULL);
if (ret) {
printk("error: 0x%x\n", ret);
}
size_t offset = 0;
ret = dfu_target_offset_get(&offset);
if (ret != 0) {
printk("error: target offset isn't zero\n");
}
ret = dfu_target_write(bin_header, sizeof(bin_header));
if (ret) {
printk("write flash error: 0x%x\n", ret);
}
}
The bin_header comes from app_update.bin header.
output:
I: vcom0_pins_routing is ENABLED I: vcom2_pins_routing is ENABLED I: led1_pin_routing is ENABLED I: led2_pin_routing is ENABLED I: led3_pin_routing is ENABLED I: led4_pin_routing is ENABLED I: switch1_pin_routing is ENABLED I: switch2_pin_routing is ENABLED I: button1_pin_routing is ENABLED I: button2_pin_routing is ENABLED I: nrf_interface_pins_0_2_routing is disabled I: nrf_interface_pins_3_5_routing is disabled I: nrf_interface_pins_6_8_routing is disabled I: Board configured. *** Booting Zephyr OS build v2.7.0-ncs1 *** I: Starting bootloader I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: none I: Bootloader chainload address offset: 0xc000 I: Jumping to the first image slot *** Booting Zephyr OS build v2.7.0-ncs1 *** Hello World! nrf9160dk_nrf52840 app version: 2.0 image type: 0x1 error: 0xffffffed write flash error: 0xfffffff4
I need to write the firmware myself to complete the upgrade project. The code here just does a test to write the firmware, but it fails on initialization. And looking at address 0x83000 through J-Flash, nothing is written. I think maybe my configuration is incorrect.
Please help me to see if my prj.conf is configured correctly. Or is this due to other issues?
Thanks.