The "read only" part is more about field-programmability than writability in general. Broadly speaking there are three types of ROM:
- The kind that is programmed as part of the manufacturing process and whose content cannot be changed, such as mask ROM;
- the kind that can be erased with special equiment, such as EPROM that can be erased with UV light;
- and the kind that can be erased electrically (usually in circuit), such as EEPROM;
- also, see the helpful comment left by @Olaf below about the differences between Flash and EEPROM (which admittedly are greater than I thought!)
Many microcontrollers these days – such as Atmel's popular ATmega series – contain some on-chip flash memory for program storage, and may also contain EEPROM for nonvolatile data storage. These memories are written by hardware-specific device programmers.
It is the joint responsibility of the compiler, the linker and the device programmer to make sure that the right data or code is placed in the right type of memory. For example, the compiler likely emits assembly directives that place executable code in the .text
section. The linker combines the .text
sections of the object files that constitute the program. Finally, the combined .text
is written to the device's flash memory.
The device programmer obviously needs some understanding of the executable file format, and a mapping of section names to memory types. Alternatively, an intermediate tool could translate the executable into an input file for the programmer.