Hope all is well.
Lately I've been studying linker scripts and I believe I got a gist of it enough to hold a conversation, however I can't find the answers I am looking for to some of the questions I had and was hoping if someone can educate me on this.
Case Scenario 1.
In a material I was watching he put an array called "buf_flash" into a section called ".myBufSectionFLASH" which is then loaded into flash at the address of 0x8001000. This array is simply populated with the values '0, 1, .. 9'. He verifies the contents within the address of 0x8001000 and the values are there.
Question 1.
I am confused as to how does the linker know how to interface with the internal flash? AFAIK If I were to write to flash there must be some procedures such as unlocking flash, erasing the page, keeping track of pages and so on and so forth.
Case Scenario 2.
In this article in the ".data section" he loads the .data section from flash into ram, then proceeds to explain "RAM isn’t persisted while power is off, those sections need to be loaded from flash. At boot, the Reset_Handler copies the data from flash to RAM before the main function is called."
Question 2.
Why is the .data section loaded from flash then into ram. Is this not inefficient? As you have to occupy space in both memory spaces? Can one just load the .data section into ram initially?
Every article I read kept mentioning about persistent storage. What I am confused about is that if I have a global variable called int foo = 3; Wouldn't my program initialize this variable to 3 every time, why does it matter if it powers off and the value is wiped, it will just get initalize to three again on boot up? If non-volatile is needed just write to flash in application code?
Thank you for reading, learning forward to any feedback.