cancel
Showing results for 
Search instead for 
Did you mean: 

Add a binary header and a sbsfu segment to an elf file

MButk.1
Associate

I have a problem with merge SBSFU .elf file and application .elf.

I prepared:

  1. SBSFU.elf - addresses in linker script: 0x08000000 - 0x08020000
  2. application.elf - 0x08020400 - 0x081FFFFF
  3. header.bin - size: 1024B

So I suppose, that like in SBSFU example header.bin will jump into space between SBSFU and application (0x08020000 - 0x08020400), but in my case result .elf file is corrupted. After merge application begin from 0x08020034 and header is placed at the end of application.

I use command:

STM32_Programmer_CLI -ms application.elf header.bin SBSFU.elf

8 REPLIES 8
Jocelyn RICARD
ST Employee

Hello,

the SBSFU is provided with tools written in python. Entry point is prepareimage.py (in Middlewares\ST\STM32_Secure_Engine\Utilities\KeysAndImages\

I would suggest starting from the postbuild script provided in SECoreBin to do what you want.

Best regards

Jocelyn

NTrin.1
Associate II

You probably have moved on, but I'll write anyway for people who need it.

I faced the same problem with the example from "NUCLEO-H753ZI\Applications\2_Images\2_Images_UserApp".

@Jocelyn RICARD​ The merging of header is done by STM32_Programmer_CLI.exe, not by perpareimage.

At the end, I use objcopy.exe (you can use the one from STM32CubeIDE), to add header data to the elf file.

Alternatively, you can define the header in your source and initialize it with known pattern. Then in post-build you search for the pattern in the elf file and replace it with the real header data.

Jocelyn RICARD
ST Employee

Hi @NTrin.1​ 

Thank you for the information.

I actually didn't understand correctly the OP.

I made a quick test and the merge command of STM32CubeProgrammer seems to be working fine at least on H753 2 images project.

This can be easily activated in the default configuration by adding a dummy parameter in the postbuild command after the version.

Only "issue" I found in version 2.5.0 (not present in 2.4.0) is that postbuild tries to access STM32CubeProgrammer_Cli in Program File (x86) instead of Program Files but I don't think this is what you experienced.

So to be able to report a possible error on the elf merging feature of the STM32CubeProgrammer I would need some way to reproduce the issue.

Best regards

Jocelyn

NTrin.1
Associate II

@Jocelyn RICARD​  The merge by STM32_Programmer_CLI.exe goes without errors. That's not the issue. The issue is the resulting elf file is bad. The address of the header is wrong. You can use an elf tool to view the resulting elf file and check the address of the header. It's wrong.


Hello,

I have the same problem as the questioner.
I will briefly describe my situation, perhaps the error can be reproduced at ST. Or someone can give me a hint where the error lies.

I have the following:
1. sbsfu.elf - the address range in the linker script: 0x0800000 - 0x0801FFFF
2. userApp.elf - app 0x08020200 - 0x080FFFFF
3.header.bin - size: 512B

After executing the postbuild.sh script, the global BIN file (SBSFU + UserApp) is created correctly and the application can also be executed on the NUCLEO-F429ZI board.

The script also offers the option of creating a global ELF file. To do this, the following command is executed:
STM32_Programmer_CLI -ms UserApp.elf header.bin sbsfu.elf

The command can be executed without error and the new UserApp.elf file is also created.

Unfortunately, the header is appended at the end (after the user application), starting with the address 0x20001EDC.

I expected the header to be inserted before the user application, in the address range 0x08020000 - 0x08020200.

I am using STM32_Programmer_CLI in the 2.8.0. version.

Hopefully someone can help me and point out where the error is.

Or someone writes me how the call of objcopy.exe looks like to connect the haeder (bin-file) with the UserApp.elf file.

Best regards
JP

Pavel A.
Evangelist III

STM32_Programmer_CLI -ms UserApp.elf header.bin sbsfu.elf

A .bin file does not contain address information. STM32_Programmer_CLI has no idea where to place it. Try to convert your .bin into .hex and provide the address. If you don't have a tool, here's a script.

 

Hello Pavel A.

Thank you for your quick response.
I understand what you mean.
But how should STM32_Programmer_CLI be called so that it knows where to put the header? The call of STM32_Programmer_CLI takes place in a script provided by ST itself. Is the call in ST's script wrong?
In other words, must the header not be a binary file?

Greetings
JP2

Pavel A.
Evangelist III

Hm, you're right. STM32_Programmer_CLI can program binary files, so it has a way to specify address for it. Or may  be the ST script does something for proper combining.