2023-09-13 07:40 PM
Hi Guys,
Ported SBSFU 2.6.2 to STM32G0B1CEU6 (512K FLASH and 64K RAM) based on Nucleo-G071RB example.
Modified mapping_fwimg.ld as below:
/* Slots must be aligned on 2048 bytes (0x800) */
/* swap (4 kbytes) */
__ICFEDIT_SWAP_start__ = 0x08042000;
__ICFEDIT_SWAP_end__ = 0x08042FFF;
/* Active slot #1 (200 kbytes) */
__ICFEDIT_SLOT_Active_1_start__ = 0x08010000;
__ICFEDIT_SLOT_Active_1_end__ = 0x08041FFF;
__ICFEDIT_SLOT_Active_1_header__ = __ICFEDIT_SLOT_Active_1_start__;
/* Dwl slot #1 (200 kbytes) */
__ICFEDIT_SLOT_Dwl_1_start__ = 0x08043000;
__ICFEDIT_SLOT_Dwl_1_end__ = 0x08074FFF;
/* Slots not configured */
__ICFEDIT_SLOT_Active_2_header__ = 0x00000000;
__ICFEDIT_SLOT_Active_2_start__ = 0x00000000;
__ICFEDIT_SLOT_Active_2_end__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_header__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_start__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_end__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_2_start__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_2_end__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_3_start__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_3_end__ = 0x00000000;
Following the step-by-step guide in UM2262.
All security features are turned off. Secure bootloader boots up fine, the first firmware uploads ok and ran. See log below:
= [SBOOT] RuntimeProtections: 0
= [SBOOT] System Security Check successfully passed. Starting...
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= Secure Boot and Secure Firmware Update =
======================================================================
= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
INFO: A Reboot has been triggered by a Hardware reset!
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK USER FW STATUS
No valid FW found in the active slots nor new FW to be installed
Waiting for the local download to start...
= [SBOOT] STATE: DOWNLOAD NEW USER FIRMWARE
File> Transfer> YMODEM> Send ...
FwSize=-16843010 | PartialFwSize=-16843010 | PartialFwOffset=-16843010 | 23088 bytes received
= [SBOOT] STATE: REBOOT STATE MACHINE
========= End of Execution ==========
= [SBOOT] RuntimeProtections: 0
= [SBOOT] System Security Check successfully passed. Starting...
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= Secure Boot and Secure Firmware Update =
======================================================================
= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
INFO: A Reboot has been triggered by a Software reset!
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK USER FW STATUS
New Fw to be installed from slot SLOT_DWL_1
= [SBOOT] STATE: INSTALL NEW USER FIRMWARE
= [SBOOT] RuntimeProtections: 0
21040 bytes of ciphertext decrypted.
Image preparation done.
Swapping the firmware images..................................................
Installation procedure completed.
FW installation succeeded.
========= End of Execution ==========
= [SBOOT] RuntimeProtections: 0
= [SBOOT] System Security Check successfully passed. Starting...
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= Secure Boot and Secure Firmware Update =
======================================================================
= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
INFO: A Reboot has been triggered by a Software reset!
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK USER FW STATUS
A FW is detected in the slot SLOT_ACTIVE_1
= [SBOOT] STATE: VERIFY USER FW SIGNATURE
= [SBOOT] RuntimeProtections: 0
= [SBOOT] STATE: EXECUTE USER FIRMWARE
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= User App #A =
======================================================================
=================== Main Menu ============================
Download a new Fw Image ------------------------------- 1
Test Protections -------------------------------------- 2
Test SE User Code ------------------------------------- 3
Multiple download ------------------------------------- 4
Validate a FW Image------------------------------------ 5
Selection :
However, got an error when I try to upload a different version from the userApp:
================ New Fw Download =========================
-- Send Firmware
-- -- Erasing download area ...
-- -- File> Transfer> YMODEM> Send ..........................................C
-- -- Programming Completed Successfully!
-- -- Bytes: 23088
-- Image correctly downloaded - reboot
= [SBOOT] RuntimeProtections: 0
= [SBOOT] System Security Check successfully passed. Starting...
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= Secure Boot and Secure Firmware Update =
======================================================================
= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
INFO: A Reboot has been triggered by a Software reset!
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK USER FW STATUS
New Fw to be installed from slot SLOT_DWL_1
= [SBOOT] STATE: INSTALL NEW USER FIRMWARE
= [SBOOT] RuntimeProtections: 0
21040 bytes of ciphertext decrypted.
Image preparation done.
Swapping the firmware images.............................................
Abnormal error 2 at line 958 in ../../../Projects/NUCLEO-G071RB/Applications/2_Images/2_Images_SBSFU/SBSFU/App/sfu_fwimg_swap.c - BLOCK
It failed in line:
/* don't copy header in active slot
this will be done at the end during validation step */
if ((index_active_slot == 0) && (chunk == 0))
{
write_len = write_len - SFU_IMG_IMAGE_OFFSET;
}
e_ret_status = SFU_LL_FLASH_Write(&flash_if_status, CHUNK_0_ADDR_MODIFIED(ActiveSlot, index_active_slot, chunk),
buffer, write_len);
STATUS_FWIMG(e_ret_status == SFU_ERROR, SFU_IMG_FLASH_WRITE_FAILED);
if (e_ret_status != SFU_SUCCESS)
{
return SFU_ERROR;
}
}
Any idea why this issue is happening? Thanks.
Solved! Go to Solution.
2023-09-20 12:22 AM
Finally figured it out. My issue was SBSFU low level flash function is not checking the bank number when erasing pages. The example project I used in based on single bank flash and there is no implementation to deal with dual bank flash memory. Firmware swapping issue went away as soon as I implemented the bank check. Hopefully this is helpful for all the others who encounters similar issues.
2023-09-13 08:44 PM
Did a bit of debugging, seems write flash operation failed at function
2023-09-14 11:32 PM
It seems the flash write error will happen once I start swapping the actual code section of the userApp. It is fine if the active slot is empty, any idea why is this happening? I am pretty sure there is no security mechanism that been enabled will prevent the swapping process. Any help would be appreciated.
2023-09-18 05:54 AM
Looks like I've encountered similar issue.
The difference is that when there is no active image installed, and I want to upload one via YMODEM, it also fails.
On the other hand, if I install SBSFU + UserApp as a single package, everything works fine.
2023-09-18 06:54 PM
Thanks for the reply, Jakub. I tried install SBSFU + UserApp as a single package but still get the same flash error (complaining about the destination is not empty). I can make it work if I fit everything in one flash bank. Could you share your firmware linker script? Anything else you changed for STM32G0B1CEU6? It seems to me it might have something to do with the dual bank flash setup of STM32G0B1CEU6. Also tried to use the whole flash as a single bank but it didn't work either.
2023-09-19 05:09 AM
First I should clarify. I am using STM32F756ZGTx so I have only single bank configuration available. I don't think that my linker scripts will be helpful in any way for you.
I would like to help, but I'm struggling with our setup too :\
I've noticed that everything works fine as long as changes are minimized to what ST did for their sample projects. The less changes, the better it works.
2023-09-20 12:22 AM
Finally figured it out. My issue was SBSFU low level flash function is not checking the bank number when erasing pages. The example project I used in based on single bank flash and there is no implementation to deal with dual bank flash memory. Firmware swapping issue went away as soon as I implemented the bank check. Hopefully this is helpful for all the others who encounters similar issues.