2022-05-17 11:20 AM
I would like to place some of the functions of ST Crypto library (cmox_crypto) into the ITCM to increase the performance on STM32H750x MCU. I would also like to place some of the associated data (tables) into ITCM or DTCM. However, the functions are provided in the precompiled library (*.a), and code is in .text section. I can place the entire .text into ITCM through linker script, but I'd like to do it selectively and only for some functions.
Will attaching the __attribute__((section(".itcm_text"))) to the functions prototypes in *.h files work?
Even if it does, there are many nested calls there and modifying all references is difficult. Does anyone know a better way of assigning sections to symbols through some linker directives or a script file?
What is the best way to do the same for data?
2022-05-17 11:37 AM
> Will attaching the __attribute__((section(".itcm_text"))) to the functions prototypes in *.h files work?
No
If the .a library is not built with per-function text sections, there is no good way to extract a single function. The linker can report dependencies of functions (what is called by your function).
2022-05-17 12:29 PM
Pavel, I already checked that attributes on prototypes do not work.
What other options may be available? For instance, un-archiving the library and then specifying explicitly the files that should go to each section in the linker scripts? Will it override the default section in the *.o files which are extracted from library?
2022-05-17 01:03 PM
For those interested: here is how I managed to partially solve the problem:
.itcm_text :
{
. = ALIGN(4);
itcm_text_start = .;
*(.itcm_text) /* Fast-executing code */
*(.itcm_text*) /* Fast-executing code */
cmox_aesfast_decrypt.c.o
cmox_aesfast_encrypt.c.o
cmox_aessmall_decrypt.c.o
cmox_aessmall_encrypt.c.o
cmox_aes_common.c.o
cmox_bn.c.o
....
. = ALIGN(4);
itcm_text_end = .;
} >ITCMRAM /* AT >FLASH*/
The AT>FLASH will be needed only if the program is designed for flash storage.
This is a brute force method, but the linker will only pick the modules which are called from the user program, and eliminates the unused modules.
Interestingly, the trick moved not only the code, but also the constant tables for the cryptographic functions into ITCM. It might be good to place them in the DTCM for faster access, but I did not yet learn how to do it.
2022-05-17 01:11 PM
One more hint: the sections are defined as following; that allows to aggregate and remap them:
2022-05-17 07:47 PM
You don't have to unpack the library. LD can specify members of archive in place of object files, see here.
the syntax is ‘archive:file’