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.