1. 程式人生 > >RO,RW,ZI概念

RO,RW,ZI概念

RO:
RO=read-only
RW:
RW=read-write
ZI:
ZI=zero-initialized

各部分在空間上的分配結構如下圖:
在這裡插入圖片描述
When you compile a standalone firmware for a microcontroller (as opposed to a user-mode program to be run in an OS), in the end you usually get a single monolithic image that will be flashed into the flash ROM and executed in-place. This is fine for code which usually is not modified, or read-only (const) data, but not so great for writable data. That’s where RW and ZI regions come in. The compiler inserts a small bootstrap code which takes a chunk with initial values of initialized data from the ROM image and copies it into RAM (this is the RW region). It then zeroes out the rest of the used RAM (ZI region). Then the control is transferred to the actual code written by the programmer.
當你編譯一個獨立的應用程式時,編譯完後生成一個整體的image,然後燒錄到flash並且執行,對於程式碼(code)和只讀常數(read-only const data)是可行的,但對要求讀寫的資料(writable data)就不太好了.所以才需要RW和ZI區的加入.編譯器插入一段程式碼用於從ROM複製一大塊初始資料到RAM(RW區),然後清零剩下的RAM(ZI區).

Thus, to calculate the used ROM (flash) space, you need to add up code, RO-data and RW-data. Used RAM will be the sum of RW-data and ZI-data. So, for your case, it’s 1264+16+0=1280 bytes of flash and 0+1384=1384 bytes of RAM.
因此,ROM空間你需要把code,RO-data和RW-data區加起來,RAM空間要把RW-data和ZI-data區加起來.即
Total RO Size (Code + RO Data)
Total RW Size (RW Data + ZI Data)
Total ROM Size (Code + RO Data + RW Data)

參考連結ROM and RAM in ARM