title: Compiling and running ARM assembly binary on Cortex-M4 (simulated in QEMU)
body: <p>I successfully compiled and executed ARM binary file on a virtual QEMU embedded system <code>connex</code> using this procedure: </p>
  
  <pre><code>arm-none-eabi-as -o program.o program.s
  arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o  
  arm-none-eabi-objcopy -O binary program.elf program.bin
  dd if=/dev/zero of=flash.bin bs=4096 count=4096
  dd if=program.bin of=flash.bin bs=4096 conv=notrunc
  qemu-system-arm -M connex -pflash flash.bin -nographic -serial /dev/null
  </code></pre>
  
  <p>In line four I created a zeroed out empty disk which represents flash and in line five I copied my binary into flash.</p>
  
  <p>So this works like a charm, but it simulates an entire embedded system while I only want to simulate ARM core, for example Cortex-M4. This is why I am trying to just use <code>qemu-arm</code> instead of <code>qemu-system-arm</code>. </p>
  
  <p>So I 1st tried to compile and run my program like this (lines 1-3 are same as above): </p>
  
  <pre><code>arm-none-eabi-as -o program.o program.s
  arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o  
  arm-none-eabi-objcopy -O binary program.elf program.bin
  qemu-arm -cpu cortex-m4 program.bin
  </code></pre>
  
  <p>And this doesn't work - it says: </p>
  
  <pre><code>Error while loading program.bin: Exec format error
  </code></pre>
  
  <p>So I tried to create flash image like before (because it worked):</p>
  
  <pre><code>arm-none-eabi-as -o program.o program.s
  arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o  
  arm-none-eabi-objcopy -O binary program.elf program.bin
  dd if=/dev/zero of=flash.bin bs=4096 count=4096
  dd if=program.bin of=flash.bin bs=4096 conv=notrunc
  qemu-arm -cpu cortex-m4 flash.bin
  </code></pre>
  
  <p>And I get this: </p>
  
  <pre><code>Error while loading flash.bin: Permission denied
  </code></pre>
  
  <p>Can anyone help me a bit? Using <code>sudo</code> doesn't help.</p>