Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap scratch not updating version number #2156

Open
lefebvresam opened this issue Dec 20, 2024 · 0 comments
Open

swap scratch not updating version number #2156

lefebvresam opened this issue Dec 20, 2024 · 0 comments

Comments

@lefebvresam
Copy link

lefebvresam commented Dec 20, 2024

I sign a primary image with version 1.1.3+4, then I create a test update signed-update.bin with version 1.2.4+6. I can clearly see those version numbers in the application headers of both images. I combine the primary image with the boatloader and flash with st-flash. It starts and the first time, the version cannot be read out and the boot cannot be confirmed. After the copy from the file signed-update.bin on SD card to SPI flash (Secondary slot) I reboot, magic is still bad, the swap is done, the new image starts and still the old version number is read out. After a second reboot, the swapped image starts again, magic is good but version number is still the old one.

[INFO][BL]: Starting MCUboot
[INFO][MCUb]: Primary image: magic=bad, swap_type=0x0, copy_done=0x2, image_ok=0x2
[INFO][MCUb]: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[INFO][MCUb]: Boot source: none
[INFO][MCUb]: Image index: 0, Swap type: none
[INFO][BL]: Booting firmware image at 0x8021000
[INFO][HMC20]: Starting main thread
[ERROR   DISPLAY     1149] cannot read version number: error_nr 1
[WARN][HMC20]: The boot could not been confirmed
[INFO][HMC20]: Secondary block device initialized
[INFO][HMC20]: Secondary block device erased
[INFO][HMC20]: copy chunk 0 at 0x00000
[INFO][HMC20]: copy chunk 1 at 0x04000
[INFO][HMC20]: copy chunk 2 at 0x08000
[INFO][HMC20]: copy chunk 3 at 0x0C000
[INFO][HMC20]: copy chunk 4 at 0x10000
[INFO][HMC20]: Copy done
[INFO][HMC20]: Reset MCU to update
[INFO][BL]: Starting MCUboot
[INFO][MCUb]: Primary image: magic=bad, swap_type=0x0, copy_done=0x2, image_ok=0x2
[INFO][MCUb]: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[INFO][MCUb]: Boot source: none
[INFO][MCUb]: Image index: 0, Swap type: test
[INFO][MCUb]: Starting swap using scratch algorithm.
[INFO][BL]: Booting firmware image at 0x8021000
[INFO][main]: Boot confirmed
[INFO][main]: Hello version 1.1.3+4
I am new
[INFO][BL]: Starting MCUboot
[INFO][MCUb]: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1
[INFO][MCUb]: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[INFO][MCUb]: Boot source: none
[INFO][MCUb]: Image index: 0, Swap type: none
[INFO][BL]: Booting firmware image at 0x8021000
[INFO][main]: Boot confirmed
[INFO][main]: Hello version 1.1.3+4
I am new

If you call boot_get_current_version(&version);, you call boot_read_image_header(&state, 0, &hdr, &status); where '0' is int slot, in swap_scratch.c. To read the version in the primary slot (0), you need the id of the secundary slot (1) because of the line:

boot_read_image_header() in swap_scratch.c:

#define BOOT_PRIMARY_SLOT               0
#define BOOT_SECONDARY_SLOT             1
...
/* If all segments have been swapped, the header is located in the other slot */
hdr_slot = (slot == BOOT_PRIMARY_SLOT) ? BOOT_SECONDARY_SLOT : BOOT_PRIMARY_SLOT;

This seems not to be logical. If I change to 1 I have the right version number:

swap_count 1
bs->idx 134399953
BOOT_STATUS_IDX_0 1
If all segments have been swapped, the header is located in the other slot
hdr_slot 0
area_id 0
[INFO][main]: Hello version 1.2.4+6
I am new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant