Search code examples
embeddedromeeprom

How can compiler place data on ROM in embedded system?


As I know, the constant value, initialized data of variable will be placed in ROM (Read Only Momory) by compiler in embedded system. But, ROM is Read-only, means that can't write so how can compiler can write these data when programming?

I think ROM in this embedded system case mostly means about EEPROM or flash memory meaning for writing permission.

Is my understanding correct in both embedded system with OS and without OS?


Solution

  • But, ROM is Read-only, means that can't write so how can compiler can write these data when programming?

    To answer the question, the compiler merely creates object files.

    These are passed to the linker, which decides at what physical address the variables will end up, typically by reading a linker script of some kind. The linker script might say something like: "program code goes into flash section 1, string literals go into flash section 2, const variables go into flash section 3". The linker creates some binary file format.

    The binary is in turn passed to a chip programmer tool or in-circuit debugger, which contains the actual routines for programming the flash.