title: How to build and boot Linux aarch64 with U-Boot with Buildroot on QEMU?
body: <p>I tried:</p>
  
  <pre><code>git clone git://git.buildroot.net/buildroot
  cd buildroot
  git checkout 2019.08
  make qemu_aarch64_virt_defconfig
  make menuconfig
  </code></pre>
  
  <p>In <code>menuconfig</code>, I set:</p>
  
  <ul>
  <li>Bootloaders
  
  <ul>
  <li>U-Boot configuration (Using an in-tree board defconfig file)
  
  <ul>
  <li><code>qemu_arm64</code></li>
  </ul></li>
  </ul></li>
  <li>Kernel
  
  <ul>
  <li>Install kernel image to /boot in target</li>
  </ul></li>
  </ul>
  
  <p>and finally:</p>
  
  <pre><code>make BR2_JLEVEL="$nproc"
  </code></pre>
  
  <p>Now, I can boot fine without U-Boot with the command line mentioned at: <a href="https://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it-wi/49349237#49349237">How to download the Torvalds Linux Kernel master, (re)compile it, and boot it with QEMU?</a></p>
  
  <pre><code>./output/host/usr/bin/qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -kernel output/images/Image -append "root=/dev/vda console=ttyAMA0" -netdev user,id=eth0 -device virtio-net-device,netdev=eth0 -drive file=output/images/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
  </code></pre>
  
  <p>but that is not using U-Boot.</p>
  
  <p>When I do:</p>
  
  <pre><code>ls -l output/images/
  </code></pre>
  
  <p>it contains:</p>
  
  <pre><code>-rw-r--r-- 1 ciro ciro 6.5M 2019-09-20_13:36:23 Image
  -rw-r--r-- 1 ciro ciro  60M 2019-09-20_13:39:02 rootfs.ext2
  lrwxrwxrwx 1 ciro ciro   11 2019-09-20_13:36:25 rootfs.ext4 -&gt; rootfs.ext2
  -rw-r--r-- 1 ciro ciro 583K 2019-09-20_13:34:15 u-boot.bin
  </code></pre>
  
  <p>so there is a U-Boot binary there: <code>u-boot.bin</code>, but how do I use that with QEMU?</p>
  
  <p>I tried as mentioned at: <a href="https://stackoverflow.com/questions/43066645/can-arm-qemu-system-emulator-boot-from-card-image-without-kernel-param">Can ARM qemu system emulator boot from card image without kernel param?</a> to remove <code>-kernel</code> and <code>-append</code> and add <code>-bios u-boot.bin</code>:</p>
  
  <pre><code>./output/host/usr/bin/qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -bios output/images/u-boot.bin -netdev user,id=eth0 -device virtio-net-device,netdev=eth0 -drive file=output/images/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
  </code></pre>
  
  <p>Now I do get the U-Boot shell, but boot fails and leaves me no the U-Boot prompt:</p>
  
  <pre><code>U-Boot 2019.07 (Sep 20 2019 - 13:34:10 +0100)
  
  DRAM:  128 MiB
  Flash: 128 MiB
  *** Warning - bad CRC, using default environment
  
  In:    pl011@9000000
  Out:   pl011@9000000
  Err:   pl011@9000000
  Net:   
  Warning: virtio-net#31 using MAC address from ROM
  eth0: virtio-net#31
  Hit any key to stop autoboot:  0 
  starting USB...
  No working controllers found
  USB is stopped. Please issue 'usb start' first.
  scanning bus for devices...
  
  Device 0: unknown device
  
  Device 0: QEMU VirtIO Block Device
              Type: Hard Disk
              Capacity: 60.0 MB = 0.0 GB (122880 x 512)
  ... is now current device
  ** No partition table - virtio 0 **
  starting USB...
  No working controllers found
  BOOTP broadcast 1
  DHCP client bound to address 10.0.2.15 (2 ms)
  Using virtio-net#31 device
  TFTP from server 10.0.2.2; our IP address is 10.0.2.15
  Filename 'boot.scr.uimg'.
  Load address: 0x40200000
  Loading: *
  TFTP error: 'Access violation' (2)
  Not retrying...
  BOOTP broadcast 1
  DHCP client bound to address 10.0.2.15 (0 ms)
  Using virtio-net#31 device
  TFTP from server 10.0.2.2; our IP address is 10.0.2.15
  Filename 'boot.scr.uimg'.
  Load address: 0x40400000
  Loading: *
  TFTP error: 'Access violation' (2)
  Not retrying...
  =&gt; 
  </code></pre>
  
  <p>so it appears that U-Boot cannot handle the VirtIO device? Or according to Peter, I have to create a partition table. I couldn't find that automatically in Buildroot, but I could do it manually, here is one approach: <a href="https://unix.stackexchange.com/questions/209566/how-to-format-a-partition-inside-of-an-img-file/527132#527132">https://unix.stackexchange.com/questions/209566/how-to-format-a-partition-inside-of-an-img-file/527132#527132</a></p>
  
  <p>Another approach would be to keep <code>-kernel -append</code> and let QEMU put the kernel into memory as done without U-Boot, and then use the <code>booti</code> U-Boot command I've found on <code>help</code>:</p>
  
  <pre><code>booti     - boot Linux kernel 'Image' format from memory
  </code></pre>
  
  <p>so I just need to find out its address. But that is kind of cheating since I want U-boot to do the hard work rather than cheat with QEMU.</p>
  
  <p>My goal is to reach a good setup to develop U-Boot and QEMU's early boot stuff.</p>