cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a binary file length multiple of 16byte

asala.19
Associate III

Hi,

I am working on p-nucleo-wb55 and run SBSFU example successfully. now i want replace default user application with my application as a secure application (.sfb). I refer AN5056(Integration guide for the X-CUBE-SBSFU) section 8.1 How to make an application SBSFU compatible. but i am woking on AC6 IDE and example steps are for the IAR IDE.

So can you please tell me what linker script (.ld) changes require to make application SBSFU compatible and as specially how to make bin file length multiple of 16 byte which required during aes encryption.

Thanks,

Arjun

3 REPLIES 3
berendi
Principal

Replace every occurence of ALIGN(4) or ALIGN(8) with ALIGN(16) in the linker script.

Not all of them would be strictly necessary, but it won't waste more than a handful of bytes, and I can't exactly tell which one is necessary in a file that I can't see.

Anyway if you want to find out, the workaround at the bottom of this thread might give you a hint.

Arno1
Senior

Normally the solution is to add a small part to the binary at the end to align the entire binary file to 16B.

Here is an example from a UserApp linker script:

  /* Extra ROM section (last one) to make sure the binary size is a multiple of the AES block size (16 bytes) and F7 flash writing unit (4 bytes)*/
  .align16 :
  {
    . = . + 1;         /* _edata=. is aligned on 8 bytes so could be aligned on 16 bytes: add 1 byte gap */
    . = ALIGN(16) - 1; /* increment the location counter until next 16 bytes aligned address (-1 byte)   */
    BYTE(0);           /* allocate 1 byte (value is 0) to be a multiple of 16 bytes                      */
  } > APPLI_region_ROM

If you would align each section to 16B you would lose some bytes to each section instead of just a few at the end. Either way we're talking peanuts here.

Hi,

Thanks for your support i resolve issue with ALIGN(16).

Regards,

Arjun