使用gdb将二进制文件加载到闪存中

时间:2017-09-05 10:09:21

标签: arm gdb

我想使用gdb将二进制文件刷入我的ARM MCU闪存。

目前我可以像这样加载一个精灵:

# 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闪存,我想发送一个完整的二进制映像。 为了测试它,我制作了一个zero.bin图像(只包含0):

# 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加载二进制文件?

2 个答案:

答案 0 :(得分:0)

如果您使用 OpenOCD

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

应该帮助你。

例如,如果您的Flash以0x400000开始,

mon flash write_bank 0 zero.bin 0x100000

将在0x500000处写入zero.bin文件,假设该地址是可写的。

答案 1 :(得分:0)

您无法删除内存区域。因为GDB使用vFlashWrite数据包写入闪存,使用M or X数据包写入RAM。

我只知道使用gdb将二进制数据写入闪存的一种方法。 您需要使用一个.data部分将二进制图像转换为elf文件。

powerpc-objcopy -I binary -O elf32-powerpc -B PowerPC -S zero.bin zero.elf

要检查新的精灵文件,请使用readelf

powerpc-readelf -h -t zero.elf

最后只使用load命令和flash基地址,因为这个elf文件没有任何地址信息。 (或者你可以使用--change-addresses 0x0选项和objcopy)

load zero.elf 0x0

我在PowerPC上检查过这个。 GDB版本是8.1。

This GDB was configured as "--host=x86_64-pc-linux-gnu --target=powerpc-eabi".