2023-08-02 02:41 AM - edited 2023-08-02 02:59 AM
Hello board,
I seek to implement a position independent firmware to achieve a dual slot fota strategy:
I followed the steps described by the UM2609 guide for stm32CubeIDE chapter 2.8 which covers this exact requirement https://www.st.com/resource/en/user_manual/um2609-stm32cubeide-user-guide-stmicroelectronics.pdf .
At this point:
At this point I think I am maybe missing something regarding global variables relocation, or am I doing something else wrong?
I hope any of you can shed light on this mistery as online information regarding this subject is very scarce!
Regards, Matteo
2023-08-21 04:45 AM
I updated my previous post, variables loaded at the wrong address are local static zero-initialized (or uninitialized) variables, which are not included in the .got, all other global and global static variables are instead correctly listed in the got.
So the question on how to force .got to consider local static variables living in the .bss space remains...
2023-08-21 09:43 AM
See the 2nd answer here:
Talks about adding -mpic-data-is-text-relative
2023-08-23 06:23 AM - edited 2023-08-23 06:27 AM
Update:
It turns out the solution is to DISABLE the pic-data-is-text-relative option adding -mno-pic-data-is-text-relative,
source gcc board
Now the local static variables are addressed (and added) to the global offset table just like global and global static variables!
I don't know why the other stack overflow answers suggested the exact opposite...either a mistake or just different use case, anyway do not use -mpic-data-is-text-relative ! Disable it with -mno-pic-data-is-text-relative.
However, the war is not over!
The next obstacles turns out to be libc ( newlib-nano) functions, such as printf, sprintf etc, which by disassembly I see that they are definitiviely not position independent..the code jumps and fetches data not relative to program counter causing again hardfault.
So I guess, is there an easy way with Stm32CubeIde to recompile newlib-nano in a position independent fashion? Or import any other libc variant suitable for this purpose?