<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Another attempt at blogging</title>
    <link>http://longhouse.vikings.scot/uefi/qemu-arm-uefi.html</link>
    <description>ARM, open source and stuff...</description>
    <language>en</language>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <generator>blosxom/2.1.2</generator>

  <item>
    <title>UEFI for ARM/ARM64 on QEMU</title>
    <pubDate>Fri, 26 Sep 2014 23:38:00 +0100</pubDate>
    <link>http://longhouse.vikings.scot/2014/09/26#qemu-arm-uefi</link>
    <category>/uefi</category>
    <guid isPermaLink="false">http://longhouse.vikings.scot/uefi/qemu-arm-uefi</guid>
    <description>
&lt;p/&gt;One really useful thing that happened at &lt;a href=&quot;http://www.linaro.org/connect/lcu/lcu14/&quot;&gt;Linaro Connect&lt;/a&gt; last week was that Ard Biesheuvel managed to complete the port of UEFI to arm and aarch64 QEMU. This has been a component missing for us to enable what is really the standard development environment for most Linux devs.
&lt;p/&gt;Ard has documented this on &lt;a href=&quot;https://wiki.linaro.org/LEG/UEFIforQEMU&quot;&gt;the Linaro wiki&lt;/a&gt;, but I wanted to &lt;b&gt;(a)&lt;/b&gt; put this into an rss feed and &lt;b&gt;(b)&lt;/b&gt; have a static set of instructions. Also, I&apos;ve added the platforms to the &lt;a href=&quot;http://git.linaro.org/uefi/uefi-tools.git&quot;&gt;uefi-tools&lt;/a&gt; platform configuration to make building a bit less tedious.

&lt;h3&gt;QEMU&lt;/h3&gt;
&lt;p/&gt;Earlier this year, without the noisy announcement it deserved, we finally got AArch64 system support in QEMU. User mode emulation had been available for quite some time at that point, and had been really useful for the Linux distributions&apos; bootstrapping efforts, but did not help the kernel and firmware developers.

&lt;p/&gt;Anyway, the UEFI port depends on some changes that only went in last week, so for now we still need to build a fresh upstream:
&lt;p/&gt;&lt;pre&gt;$ git clone git://git.qemu.org/qemu.git
$ cd qemu
$ ./configure --prefix=/usr/local --target-list=arm-softmmu,aarch64-softmmu
$ make -j9
$ sudo make install&lt;/pre&gt;

&lt;h3&gt;UEFI&lt;/h3&gt;
&lt;p/&gt;The required patches to EDK2 are already upstream, so the only requirement is that you have a working cross compiler. I am using a Linaro 4.8 gcc prebuilt one.

&lt;p/&gt;&lt;pre&gt;$ git clone git://git.linaro.org/uefi/uefi-tools.git
$ git clone https://github.com/tianocore/edk2.git
$ cd edk2
$ ../uefi-tools/uefi-build.sh -b DEBUG -b RELEASE qemu64&lt;/pre&gt;

&lt;p/&gt;The generated firmware image will be found as &lt;pre&gt;Build/ArmVirtualizationQemu-AARCH64/{DEBUG,RELEASE}_GCC48/FV/QEMU_EFI.fd&lt;/pre&gt;

&lt;p/&gt;To build the 32-bit variant:
&lt;pre&gt;$ ../uefi-tools/uefi-build.sh -b DEBUG -b RELEASE qemu&lt;/pre&gt;

&lt;p/&gt;The generated firmware image will be found as &lt;pre&gt;Build/ArmVirtualizationQemu-ARM/{DEBUG,RELEASE}_GCC48/FV/QEMU_EFI.fd&lt;/pre&gt;

&lt;h3&gt;Prebuilt binaries&lt;/h3&gt;
&lt;p/&gt;So, due to yours truly messing up, this support was not included in Linaro&apos;s &lt;a href=&quot;http://releases.linaro.org/14.09/components/kernel/uefi-linaro&quot;&gt;2014.09 release&lt;/a&gt; (the source code contains the support, but the pre-built images are missing). However. I kicked off a build just after and produced &lt;a href=&quot;http://snapshots.linaro.org/components/kernel/linaro-edk2/27/debug/qemu64&quot;&gt;a debug&lt;/a&gt; and &lt;a href=&quot;http://snapshots.linaro.org/components/kernel/linaro-edk2/27/release/qemu64&quot;&gt;a release&lt;/a&gt; version.

&lt;h3&gt;Setting up and running a system&lt;/h3&gt;
&lt;p/&gt;You will want to generate data files to hold the emulated flash images for the UEFI firmware and UEFI&apos;s persistent environment variables:
&lt;pre&gt;$ dd if=/dev/zero bs=1M count=64 of=flash0.img
$ dd if=/dev/zero bs=1M count=64 of=flash1.img
$ dd if=Build/ArmVirtualizationQemu-AARCH64/DEBUG_GCC48/FV/QEMU_EFI.fd \
	bs=1M of=flash0.img conv=notrunc&lt;/pre&gt;

&lt;p/&gt;And then launch the 64-bit model using:

&lt;p/&gt;&lt;pre&gt;$ qemu-system-aarch64 \
	-m 1024 \
	-cpu cortex-a57 \
	-M virt \
	-pflash flash0.img \
	-pflash flash1.img \
	-serial stdio&lt;/pre&gt;

&lt;p/&gt;Or for the aarch32 variant:
&lt;pre&gt;$ qemu-system-arm \
	-m 1024 \
	-cpu cortex-a15 \
	-M virt \
	-pflash flash0.img \
	-pflash flash1.img \
	-serial stdio&lt;/pre&gt;
</description>
  </item>
  </channel>
</rss>
