Hello NXP community ,
I am working with Yocto BSP 43 and have a requirement to read a custom user defined version input of BL2 from the bootloader.
The idea is to store this version information at a predefined offset in SRAM, so that we can later access it using that fixed address.
To achieve this, we tried the following:
Added a new section in bl2.ld for the version info.
Defined the variable in bl2main.c and linked it to that section.
However, the variable is not appearing in the bl2.map file.
I’ve attached the updated files [bl2_main.c , bl2.ld.S] along with screenshot [bl2_main_chang.png , bl2.ld.change.png] respectively showing where exactly the changes were made.
Question:
How can we properly place this version variable at a fixed SRAM offset so that it is accessible by the bootloader ?
Hello @ashwini2024,
Thanks for contacting us again and thanks for the detailed description of your problem.
Using a simple blink example for the S32G3 I added the following:
To main.c
__attribute__((section(".my_seccion")))
volatile const char my_array[20];
To linker_ram.ld
. = ALIGN(4);
KEEP(*(.my_mem))
That, inside and at the end fo the following section:
.non_cacheable :
{
...
...
...
. = ALIGN(4);
KEEP(*(.my_mem))
} > int_sram_no_cacheable
With those two changes I was able to see the following in the .map file:
*(.my_mem)
.my_mem 0x34540000 0x14 ./src/main.o
0x34540000 my_array
The main difference I see with your changes is that I did not create a section, I used an already existing section and put a custom range on it. Also please use volatile to prevent te compiler from optimizing the variable in case it is not called in your code.
Let me know if the behavior changes
Hello
Thank you for the information.
I have gone through the information that you have provided but my intention is to statically assign particular address location to the variable so even in future builds address wont be changed. Therefore we would like to create a custom section with the particular address and we would like to redirect that variable to the custom section. I hope you understood my concern.
Thanks in advance.
Hello @ashwini2024,
I tried in ATF and it seems that even if volatile is used, the variable gets optimized, I had to do a workaround, using the variable in the code so that it does get a space in memory, furthermore I also changed the linker descriptor to ensure the section is in a fixed address, here is my patch:
diff --git a/bl2/bl2.ld.S b/bl2/bl2.ld.S
index db83a0c50..1784a6ac4 100644
--- a/bl2/bl2.ld.S
+++ b/bl2/bl2.ld.S
@@ -12,7 +12,8 @@ OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
ENTRY(bl2_entrypoint)
MEMORY {
- RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
+ RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE - 0x200
+ MY_RAM (rwx): ORIGIN = BL2_BASE + BL2_LIMIT - BL2_BASE - 0x200 + 1, LENGTH = 0x00000200
}
SECTIONS {
@@ -86,6 +87,15 @@ SECTIONS {
__RO_END__ = .;
} >RAM
+
+ /* Custom RAM section for user-defined variables */
+ .my_section : ALIGN(8) {
+ __MY_SECTION_START__ = .;
+ KEEP(*(.my_seccion))
+ __MY_SECTION_RAM_END__ = .;
+ } >MY_RAM
+
+
#endif /* SEPARATE_CODE_AND_RODATA */
__RW_START__ = .;
diff --git a/bl2/bl2_main.c b/bl2/bl2_main.c
index 923a554fb..4d4b1c758 100644
--- a/bl2/bl2_main.c
+++ b/bl2/bl2_main.c
@@ -84,6 +84,13 @@ void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
* next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
* runs entirely in S-EL1.
******************************************************************************/
+#define DATE_LENGTH 11 // date + NULL terminator
+#define DATE_SIZE DATE_LENGTH + 1// DATE_LENGTH + 1 to add a dummy byte
+#define DATE_LAST_INDEX DATE_SIZE - 1
+
+__attribute__((section(".my_seccion"))) char bl2_ver[DATE_SIZE] = "2025-08-21";
+
+
void bl2_main(void)
{
entry_point_info_t *next_bl_ep_info;
@@ -95,6 +102,11 @@ void bl2_main(void)
NOTICE("BL2: %s\n", version_string);
NOTICE("BL2: %s\n", build_message);
+ /* ensure bl2_ver is not optimized */
+ /* just modify the dummy byte */
+ bl2_ver[DATE_LAST_INDEX] = 0xAA;
+
+
/* Perform remaining generic architectural setup in S-EL1 */
bl2_arch_setup();
In essence what I did is:
- removed 0x200 bytes from the RAM section and created MY_RAM section, of length 0x200;
- Added the region
- created the bl2_ver variable in "my_section"
- added a dummy use in bl2_main to ensure the variable is not optmized
With all of this I was able to see the variable in the map file. you should be able to add the changes of bl2_main.c in any file you prefer.
Let me know if it works for you.
Hello
Thank you for the information.
I have followed your steps.
I have opened a support ticket and have attached my map file .Please have a look.
https://support.nxp.com/s/case/500Tg00000OR5ijIAD/bl-versioning?language=en_US
Hello @ashwini2024,
Please check the answer I published in the private ticket, as you will see the variable and section are present in the map file you sent, however I did not use the same names you proposed, please modify the patch yo your needs.
Thanks.