about mcuboot flash dfu image invaild

Hello Sir,

I am currently working with the boards:52840dk and ncs:2.9.1

Regarding the issue of failed mcuboot upgrade after writing the upgrade firmware using flash APIs, where the “zephyr.signed.bin” file is the one written to flash.

(The code in this routine has been modified.)

I first transferred the upgraded firmware to the memory via the serial port or other way.

Then, this is the process of writing to the flash using the flash API

while (offset < length)
{
	size_t write_len = MIN(length - offset, CONFIG_IMG_BLOCK_BUF_SIZE);  //Each time, write in blocks of size blocksize.
	if (write_len < CONFIG_IMG_BLOCK_BUF_SIZE)
		break;
	ret = flash_img_buffered_write(&flash_ctx, &uart_rx_buf[offset],
								   write_len, false);  //During the write process, the data in the last write buffer is less than the block size
	if (ret != 0)
	{
		printk("Flash write failed at offset %zu: %d\n", offset, ret);
		return ret;
	}
	offset += write_len;
}
ret = flash_img_buffered_write(&flash_ctx, NULL, 0, true);	//flush The last written buffer
/*ret = flash_img_buffered_write(&flash_ctx, &uart_rx_buf[offset],
							   (length % 512), true);*/  
if (ret != 0)
{
	printk("Final flush failed: %d\n", ret);
	return ret;
}
bytes_written = flash_img_bytes_written(&flash_ctx); //Buffer for the total number of bytes read and written
printk("Total bytes written: %zu\n", bytes_written);
if (bytes_written % UART_RX_MTU != 0)  //Check if it has been fully written in
{
	ret = boot_request_upgrade(BOOT_UPGRADE_PERMANENT); //If fully written, it will enter the DFU mode and start the update process
	if (ret != 0)
	{
		printk("Failed to request upgrade: %d\n", ret);
		return ret;
	}
	printk("Firmware update completed successfully!\n");
}

However, the update failed continuously. This is the error log reported by mcuboot.

its display secondary slot is not vaild,then I dump flash data

In Flash, the corresponding address contains the content I wrote, and the size and other details are also correct. Then, the part circled in red at the top should be the check bit of the swap_type located at the end of the secondary slot sector.

The specific content and the address where it is located have also been confirmed to be correct.

However, it was never able to be upgraded. Later, after debugging, it was found that the program failed during the hash verification process. it should be the verification of the TLV field. It is located at the end of the image, which is the part circled in the above picture.

Here's the problem: even though the contents in the flash are identical to the zephyr.signed.bin file, the upgrade still fails. Later, I dumped a Zephyr routine that can be upgraded successfully and checked the flash status before upgrading. I found that the TLV fields at the end of this routine's flash are different from the last 69 bytes of the zephyr.signed.bin in this routine.

I have found in many official and unofficial documents that this zephyr.signed.bin is used for DFU/OTA upgrades, and apart from this file, I haven't found any other new files that seem suitable for upgrading.

Then the remaining possibility is that since Zephyr uses west flash for burning, could it be that west flash modifies the signature? Or there might be other issues? What should I do next?

Please forgive my not-so-fluent English

Djangyond Kang,

Embedded Developer

Shenzhen Best of Best Holdings Co.,Ltd

Parents
  • Hi,

    west flash does not modify the signature, or do anythign like that. The image is written as is.

    There are two potential problems that come to mind: 1: did you wrtite the image at an incorrect addres or with an offset, so that validation failes because of that? In wchich address does slot 1 start, and can you doubel check that this is exactly where you copy the newimage (without any offset)? Also, make sure you sign with a valid key?

    Also, testing with CONFIG_MCUBOOT_LOG_LEVEL_DBG=y in the MCUboot configuration may give some more information about that is happening.

  • thanks for your reply,I've double-checked the address offset I set for Slot 1, and it exactly matches the flash addresses I dumped earlier.

    after my verification, in my code, both the size and offset in the flash are correct. On the contrary, in the successfully upgradeable routine, the TLV fields at the end of the image cannot match those of the zephyr.signed.bin. I am very curious about this issue,and it maybe the key of the question?

  • Hi,

    If the partition manager is used (which is the default for nRF Connect SDK), the partition in the devicetree is not used. So it would be good to check the partition manager report. Can you generate the partition report as described here and share it?

    What is the difference between the two image trailers you list? Are they from the exact same image, or is there a difference (could be just a different build time, if the time is included in the imsage as is the case with the SMP server sample, or any other change that would cause it to difer). 

Reply
  • Hi,

    If the partition manager is used (which is the default for nRF Connect SDK), the partition in the devicetree is not used. So it would be good to check the partition manager report. Can you generate the partition report as described here and share it?

    What is the difference between the two image trailers you list? Are they from the exact same image, or is there a difference (could be just a different build time, if the time is included in the imsage as is the case with the SMP server sample, or any other change that would cause it to difer). 

Children
No Data
Related