title: Load a binary into flash memory using gdb
body: <p>I'd like to flash a binary file into my ARM MCU flash memory using gdb.</p>
  
  <p>Currently I'm able to load an elf like this:</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>Basically the <code>load</code> command is good at loading elf sections to the right addresses.</p>
  
  <p>However to put multiple firmware in the MCU flash memory, I'd like to send a complete binary image.
  In order to test it, I made a zero.bin image (containing nothing but 0):</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>So this doesn't seem to work, as you can see in 0x0 it should be full of '0' but it still contains my previous firmware (the vector table actually)</p>
  
  <p>What do I miss? Or maybe there is another way to load a binary using gdb?</p>