Hi
We want to add one flash partition to use to store external host files by http downloading, so we changed the dts to below:
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x10000>;
};
slot0_partition: partition@10000 {
label = "image-0";
};
slot0_ns_partition: partition@20000 {
label = "image-0-nonsecure";
};
slot1_partition: partition@50000 {
label = "image-1";
};
slot1_ns_partition: partition@60000 {
label = "image-1-nonsecure";
};
host_partition: partition@90000 {
label = "image-host";
reg = <0x00090000 0x60000>;
};
scratch_partition: partition@f0000 {
label = "image-scratch";
reg = <0x000f0000 0xa000>;
};
storage_partition: partition@fa000 {
label = "storage";
reg = <0x000fa000 0x00006000>;
};
};
};
/* Flash partition at /soc/peripheral@40000000/flash-controller@39000/flash@0/partitions/partition@90000 */ #define DT_FLASH_AREA_IMAGE_HOST_ID 5 #define DT_FLASH_AREA_IMAGE_HOST_READ_ONLY 0 #define DT_FLASH_AREA_IMAGE_HOST_OFFSET_0 589824 #define DT_FLASH_AREA_IMAGE_HOST_OFFSET DT_FLASH_AREA_IMAGE_HOST_OFFSET_0 #define DT_FLASH_AREA_IMAGE_HOST_SIZE_0 393216 #define DT_FLASH_AREA_IMAGE_HOST_SIZE DT_FLASH_AREA_IMAGE_HOST_SIZE_0 #define DT_FLASH_AREA_IMAGE_HOST_DEV "NRF_FLASH_DRV_NAME" #define DT_FLASH_AREA_5_ID 5 #define DT_FLASH_AREA_5_READ_ONLY 0 #define DT_FLASH_AREA_5_OFFSET_0 589824 #define DT_FLASH_AREA_5_OFFSET DT_FLASH_AREA_5_OFFSET_0 #define DT_FLASH_AREA_5_SIZE_0 393216 #define DT_FLASH_AREA_5_SIZE DT_FLASH_AREA_5_SIZE_0 #define DT_FLASH_AREA_5_DEV "NRF_FLASH_DRV_NAME"
then we duplicated the dfu_target_mcuboot to dfu_target_host and flash_img to flash_host for this host file's OTA download, but the flash erase error occurred in dfu_target_host_write() of first fragment, here is the error log:
[00:00:52.731,262] <inf> download_client: Downloaded 4096/142248 bytes (2%)
[00:00:52.731,292] <inf> dfu_target: Image type: DFU_TARGET_IMAGE_TYPE_HOST
[00:00:52.731,292] <inf> dfu_target_host: Falsh_host_init: dev_id 0, id 5, offset 0x00018200, size 0x0006de00
[00:00:52.731,323] <inf> flash_host: Erasing sector at offset 0x00018000
[00:00:52.731,323] <err> flash_host: Error -22 while erasing sector
[00:00:52.731,353] <err> flash_host: flash_name(NRF_FLASH_DRV_NAME) id(5) offset(0xfffffe00) size(0x1000)
[00:00:52.731,353] <err> flash_host: flash_progressive_erase error -22 offset=0x00000000
[00:00:52.731,384] <err> dfu_target_host: flash_host_buffered_write error -22
[00:00:52.731,384] <err> fota_download: dfu_target_write error -22
[00:00:52.834,716] <inf> download_client: Fragment refused, download stopped.
It seems the offset(0x00018200) of host flash partition was wrong, and if I correct it in dfu_target_host_init() as below, the firmware will crash and reboot. How to fix this issue?
int dfu_target_host_init(size_t file_size, dfu_target_callback_t cb)
{
ARG_UNUSED(cb);
int err = flash_host_init(&flash_host);
//customer added:
//flash_host.flash_area->fa_off = DT_FLASH_AREA_IMAGE_HOST_OFFSET;
//flash_host.flash_area->fa_size = DT_FLASH_AREA_IMAGE_HOST_SIZE;
LOG_INF("Falsh_host_init: dev_id %d, id %d, offset 0x%08x, size 0x%08x", flash_host.flash_area->fa_device_id,
flash_host.flash_area->fa_id, flash_host.flash_area->fa_off, flash_host.flash_area->fa_size);
//customer added end
if (err != 0) {
LOG_ERR("flash_host_init error %d", err);
return err;
}
if (file_size > DT_FLASH_AREA_IMAGE_HOST_SIZE) {
LOG_ERR("Requested file too big to fit in flash %d > %d",
file_size, DT_FLASH_AREA_IMAGE_HOST_SIZE);
return -EFBIG;
}
if (IS_ENABLED(CONFIG_DFU_TARGET_HOST_SAVE_PROGRESS)) {
static struct settings_handler sh = {
.name = MODULE,
.h_set = settings_set,
};
/* settings_subsys_init is idempotent so this is safe to do. */
err = settings_subsys_init();
if (err) {
LOG_ERR("settings_subsys_init failed (err %d)", err);
return err;
}
err = settings_register(&sh);
if (err) {
LOG_ERR("Cannot register settings (err %d)", err);
return err;
}
err = settings_load();
if (err) {
LOG_ERR("Cannot load settings (err %d)", err);
return err;
}
}
return 0;
}