【问题标题】:Load a binary into flash memory using gdb使用 gdb 将二进制文件加载到闪存中
【发布时间】:2017-09-05 10:09:20
【问题描述】:

我想使用 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 命令擅长将精灵段加载到正确的地址。

但是要在 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 加载二进制文件的方法?

【问题讨论】:

  • 恢复命令失败,Writing to flash memory forbidden in this context。我正在试图弄清楚为什么这也会发生在我身上
  • 实际上在我的情况下,这是因为这个区域被映射到闪存,而 gdb 需要一种方法来确定如何对闪存进行编程,它不可能像 addr[i] = data[i] 这样的东西。我不知道如何设置 gdb 来做到这一点。无论如何,希望它有所帮助!

标签: arm gdb


【解决方案1】:

如果您使用的是OpenOCD

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

应该能帮到你。

例如,如果您的闪存从0x400000 开始,

mon flash write_bank 0 zero.bin 0x100000

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

【讨论】:

    【解决方案2】:

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

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

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

    要检查您的新 elf 文件,请使用 readelf

    powerpc-readelf -h -t zero.elf

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

    load zero.elf 0x0

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多