2017-09-05 271 views
0

我想使用gdb將二進制文件閃存到我的ARM MCU閃存中。使用gdb將二進制文件加載到閃存中

目前我能夠加載ELF這樣的:

# arm-none-eabi-gdb --command=flash.gdb "myfirmware.elf" 

# cat flash.gdb 
set confirm off 
target remote 127.0.0.1:7224 
monitor reset 
load 
detach 
quit 

基本上load命令善於加載ELF節到正確的地址。

但是爲了在MCU閃存中放入多個固件,我想發送一個完整的二進制圖像。 爲了測試它,我做(含什麼,但0)一zero.bin圖像:

# hexdump zero.bin 
0000000 0000 0000 0000 0000 0000 0000 0000 0000 
* 
0020000 


# arm-none-eabi-gdb 
(gdb) target remote 127.0.0.1:7224 
(gdb) mon reset halt 
(gdb) mon reset init 
(gdb) set arm fallback-mode auto 
(gdb) set debug arm 
(gdb) restore zero.bin binary 0x0 
Restoring binary file zero.bin into memory (0x0 to 0x20000) 
Writing to flash memory forbidden in this context 
(gdb) info mem                           
Using memory regions provided by the target.                
Num Enb Low Addr High Addr Attrs                  
0 y 0x00000000 0x00020000 flash blocksize 0x800 nocache            
1 y 0x00020000 0x100000000 rw nocache   
(gdb) delete mem 1 
warning: Switching to manual control of memory regions; use "mem auto" to fetch regions from the target again. 
(gdb) delete mem 0 
(gdb) mem 0 0x100000000 rw nocache 
(gdb) info mem 
Using user-defined memory regions. 
Num Enb Low Addr High Addr Attrs 
1 y 0x00000000 0x100000000 rw nocache 
(gdb) restore zero.bin binary 0x0 
Restoring binary file zero.bin into memory (0x0 to 0x20000) 
(gdb) x/10 0x0 
0x0: 0x20003000  0x00003c5d  0x00003c7d  0x00003c7d 
0x10: 0x00000000  0x00000000  0x00000000  0x00000000 
0x20: 0x00000000  0x00000000 

因此,這似乎並沒有工作,因爲你可以看到爲0x0它應該是充滿了「0 '但它仍然包含我以前的固件(實際上是向量表)

我想錯過什麼?或者也許有另一種方法來使用gdb加載二進制文件?

+0

恢復命令失敗,寫入禁止在此上下文中閃存。我試圖找出爲什麼這也發生在我身上 – Jon

+0

實際上,在我的情況下,這是因爲這個區域映射到閃存,而gdb需要一種方法來弄清楚如何編程閃存它不可能是某種東西像'addr [i] = data [i]'。我不知道如何設置gdb來做到這一點。無論如何,希望它有幫助! – Ervadac

回答

0

如果您正在使用OpenOCD的

mon flash write_bank <num> <file_name> <offset> 

應該幫助你。

例如,如果你的閃光燈開始於0x400000

mon flash write_bank 0 zero.bin 0x100000

將寫入zero.bin文件在0x500000,假設地址是可寫的。

相關問題