<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Another attempt at blogging</title>
    <link>http://longhouse.vikings.scot/uefi</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>QEMU USB host device pass-through</title>
    <pubDate>Tue, 13 Dec 2016 18:09:00 +0000</pubDate>
    <link>http://longhouse.vikings.scot/2016/12/13#qemu-usb-passthrough</link>
    <category>/uefi</category>
    <guid isPermaLink="false">http://longhouse.vikings.scot/uefi/qemu-usb-passthrough</guid>
    <description>
&lt;h2&gt;Speeding up UEFI driver development&lt;/h2&gt;
&lt;p/&gt;While working on the ChaosKey UEFI driver, I once again found myself in a situation of tedium: how to simplify driver development when the target for my device driver is firmware. Moving around a USB key with a FAT filesystem may be a completely valid thing to do in order to install a pre-existing driver. But when you are trying to learn how to write drivers for a new platform (and write &lt;a href=&quot;http://blog.eciton.net/uefi/uefi-driver-part1.html&quot;&gt;blog posts about it&lt;/a&gt;), the &lt;i&gt;modify -&gt; compile -&gt; copy -&gt; reboot -&gt; load -&gt; fail -&gt; try again&lt;/i&gt; cycle gets quite tedious. As usual, QEMU has/is the answer, letting you pass a USB device controlled by the host over to the guest.

&lt;h3&gt;Make sure your QEMU is built with libusb support&lt;/h3&gt;
&lt;p/&gt;Unsurprisingly, in order to support passing through USB device access to guests, QEMU needs to know how to deal with USB - and it does this using libusb. Most Linux distributions package a version of QEMU with libusb support enabled, but if you are building your own version from source, make sure the output from configure contains &lt;pre&gt;libusb            yes&lt;/pre&gt; If it does not, under Debian, &lt;code&gt;$ sudo apt-get build-dep qemu&lt;/code&gt; should do the trick - anywhere else make sure you manually install libusb v1.0 or later (Debian&apos;s &lt;code&gt;libusb-dev&lt;/code&gt; package is v0.1, which will not work), with development headers.
Without libusb support, you&apos;ll get the error message &lt;code&gt;&apos;usb-host&apos; is not a valid device model name&lt;/code&gt; when following the below instructions.

&lt;h3&gt;Identifying your device&lt;/h3&gt;
&lt;p/&gt;Once your QEMU is ready, in order to pass a device through to a guest, you must first locate it on the host.
&lt;pre&gt;$ lsusb
...
Bus 008 Device 002: ID 1d50:60c6 OpenMoko, Inc
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
....&lt;/pre&gt;
The vendor ID (1d50) of ChaosKey is taken from the &lt;a href=&quot;http://wiki.openmoko.org/wiki/USB_Product_IDs&quot;&gt;OpenMoko project&lt;/a&gt;, which has repurposed their otherwise unused device registry space for various community/homebrew devices.

&lt;p/&gt;If you want to be able to access the device as non-root, ensure the device node under &lt;pre&gt;/dev/bus/usb/&amp;lt;bus&amp;gt;/&amp;lt;device&amp;gt;&lt;/pre&gt; (in this case &lt;code&gt;/dev/bus/usb/008/002&lt;/code&gt;) has suitable read-write access for your user.

&lt;h3&gt;Launching QEMU&lt;/h3&gt;
&lt;p/&gt;Unlike the x86 default &quot;pc&quot; machine, QEMU has no default machine type for ARM. The &quot;generic virtualized platform&quot; type &lt;i&gt;virt&lt;/i&gt; has no USB attached by default, so we need to manually add one. &lt;code&gt;ich-usb-uhci1&lt;/code&gt; supports high-speed, and so is needed for some devices to work under emulation. Using the &quot;virtual FAT&quot; support in QEMU is the easiest way to get a driver into UEFI without recompiling. The example below uses a subdirectory called &lt;code&gt;fatdir&lt;/code&gt; which QEMU generates an emulated FAT filesystem from.

&lt;p/&gt;
&lt;pre&gt;
USB_HOST_BUS=8
USB_HOST_PORT=2
AARCH64_OPTS=&quot;-pflash QEMU_EFI.fd -cpu cortex-a57 -M virt -usb -device ich9-usb-uhci1&quot;
X86_OPTS=&quot;-pflash OVMF.fd -usb&quot;
COMMON_OPTS=&quot;-device usb-host,bus=usb-bus.0,hostbus=$USB_HOST_BUS,hostport=$USB_HOST_PORT -nographic -net none -hda fat:fatdir/&quot;
&lt;/pre&gt;

&lt;p/&gt;
This can then be executed as&lt;br/&gt;
&lt;code&gt;$ qemu-system-x86_64 $X86_OPTS $COMMON_OPTS&lt;/code&gt;&lt;br/&gt;
or&lt;br/&gt;
&lt;code&gt;$ qemu-system-aarch64 $AARCH64_OPTS $COMMON_OPTS&lt;/code&gt;&lt;br/&gt;
respectively.&lt;br/&gt;

&lt;p/&gt;
&lt;b&gt;Note:&lt;/b&gt; Ordering of some of the above options is important.&lt;br/&gt;
&lt;b&gt;Note2:&lt;/b&gt; That AARCH64 &lt;code&gt;QEMU_EFI.fd&lt;/code&gt; needs to be extended to 64MB in order for QEMU to be happy with it. &lt;a href=&quot;http://blog.eciton.net/uefi/qemu-arm-uefi.html&quot;&gt;See this older post for an example.&lt;/a&gt;

&lt;p/&gt;
My usage then looks like the following, after having been dropped into the UEFI shell, with a bunch of overly verbose debug messages in my last compiled version of the driver:
&lt;pre&gt;
Shell&gt; load fs0:\ChaosKeyDxe.efi
*** Installed ChaosKey driver! ***
Image &apos;FS0:\ChaosKeyDxe.efi&apos; loaded at 47539000 - Success
Shell&gt; y (0x1D50:0x60C6) is my homeboy!
1 supported languages
0: 0409
Manufacturer: altusmetrum.org
Product: ChaosKey-hw-1.0-sw-1.6.6
Serial: 001c00325346430b20333632
&lt;/pre&gt;

&lt;p/&gt;
And, yes, those last three lines are actually read from the USB device connected to host QEMU is running on.

&lt;h3&gt;Final comments&lt;/h3&gt;
&lt;p/&gt;
One thing that is unsurprising, but very cool and useful, is that this works well cross-architecture. So you can test that your drivers are truly portable by building (and testing) them for AARCH64, EBC and X64 without having to move around between physical machines.

&lt;p/&gt;
Oh, and another useful command in this cycle is &lt;code&gt;reset -s&lt;/code&gt; in the UEFI shell, which &quot;powers down&quot; the machine and exits QEMU.</description>
  </item>
  <item>
    <title>UEFI Driver Development - Part 1</title>
    <pubDate>Tue, 13 Sep 2016 22:02:00 +0100</pubDate>
    <link>http://longhouse.vikings.scot/2016/09/13#uefi-driver-part1</link>
    <category>/uefi</category>
    <guid isPermaLink="false">http://longhouse.vikings.scot/uefi/uefi-driver-part1</guid>
    <description>
&lt;p/&gt;One of the key features of UEFI is that the specification and the APIs/ABIs it guarantees provides the ability to produce portable applications, drivers and libraries (in the form of protocols). On the simpler side, by letting you compile the driver once for each architecture - and on the more space age side by letting you build a single driver that works across all architectures (using &lt;a href=&quot;http://vzimmer.blogspot.co.uk/2015/08/efi-byte-code.html&quot;&gt;EFI Byte Code&lt;/a&gt;). The extra magic comes in the form of Option ROM support, which lets plug-in PCI cards keep a driver onboard, informing UEFI to load it on boot. (Any jokes about Forth drivers for Open Firmware go here.)

&lt;p/&gt;So, having never actually written a UEFI driver from scratch, and most of the drivers I have come across having really been platform drivers, I figured that would be a good start to write a standalone driver from scratch. And the outcome is this slightly hands-on blog post series. This part covers:
&lt;ul&gt;
  &lt;li&gt;creating a new driver from scratch&lt;/li&gt;
  &lt;li&gt;building it as a standalone driver&lt;/li&gt;
  &lt;li&gt;loading it from the UEFI Shell&lt;/li&gt;
  &lt;li&gt;having it detect the presence of a device it recognizes&lt;/li&gt;
  &lt;li&gt;unloading it from the UEFI Shell&lt;/li&gt;
&lt;/ul&gt;

&lt;p/&gt;Having just come across a hardware random number generator called &lt;a href=&quot;http://altusmetrum.org/ChaosKey/&quot;&gt;ChaosKey&lt;/a&gt;, I figured this would make an excellent candidate.

&lt;h2&gt;Creating a standalone UEFI driver from scratch&lt;/h2&gt;
&lt;p/&gt;Since UEFI drivers are meant to be standalone buildable, they tend to be kept in separate directories. Since this driver is intended to run during/after DXE phase, let&apos;s put everything in a directory called &lt;a href=&quot;https://git.linaro.org/people/leif.lindholm/OpenPlatformPkg.git/tree/b1f241e7e2cc0e241d737d1533f0a95008520637:/Drivers/Usb/Misc/ChaosKeyDxe&quot;&gt;ChaosKeyDxe&lt;/a&gt; (CamelCase mandatory - link takes you to the directory in git, where you can view the files directly).

&lt;h3&gt;Create a build information file&lt;/h3&gt;
&lt;p/&gt;First of all, we need a build information file (&lt;b&gt;.inf&lt;/b&gt;). The format of the build information file is described in the &lt;i&gt;EDK II INF File Spec&lt;/i&gt;, which can be found in the &lt;a href=&quot;https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Specifications&quot;&gt;EDK2 github pages&lt;/a&gt;.

&lt;p/&gt;Start with a [Defines] section
&lt;pre&gt;
[Defines]
  INF_VERSION                    = 0x00010019
  BASE_NAME                      = ChaosKeyDxe
  FILE_GUID                      = 9A54122B-F5E4-40D8-AE61-A71E406ED449
  MODULE_TYPE                    = UEFI_DRIVER
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = ChaosKeyEntryPoint
  UNLOAD_IMAGE                   = ChaosKeyUnload
&lt;/pre&gt;

&lt;p/&gt;The &lt;b&gt;INF_VERSION&lt;/b&gt; reflects which version of the INF file format is being followed, in this case 1.25 (&lt;code&gt;0x0001.0x0019&lt;/code&gt;). Interestingly, nearly all build information files I have come across before specify 0x00010005 ... cargo culting from earlier examples.&lt;br/&gt;&lt;br/&gt;
Followed by &lt;b&gt;BASE_NAME&lt;/b&gt;, the single word identifier used for this component. To keep things simple, I&apos;m reusing the directory name, for the same reasons.&lt;br/&gt;&lt;br/&gt;
And then a &lt;b&gt;FILE_GUID&lt;/b&gt;, generated uniquely for this file - for example through &lt;a href=&quot;https://www.guidgenerator.com/online-guid-generator.aspx&quot;&gt;this online generator&lt;/a&gt;, ensuring &lt;i&gt;Uppcase&lt;/i&gt; and &lt;i&gt;Hyphens&lt;/i&gt; are both ticked. If this string is copied from an existing template rather than uniquely generated, &lt;i&gt;really&lt;/i&gt; bad stuff will happen.&lt;br/&gt;&lt;br/&gt;
And then &lt;b&gt;MODULE_TYPE&lt;/b&gt; to tell the build system we are producing a UEFI_DRIVER.&lt;br/&gt;&lt;br/&gt;
A &lt;b&gt;VERSION_STRING&lt;/b&gt; is also required - this is simply a UCS2 string indicating the version of the driver.&lt;br/&gt;&lt;br/&gt;
The &lt;b&gt;ENTRY_POINT&lt;/b&gt; function is automatically called at driver load time, and needs to contain code that registers the driver with the system, and do any other global setup needed to make the driver ready to set up individual devices.&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;UNLOAD_IMAGE&lt;/b&gt; points to the function cleaning up after the driver when it is to be unloaded. This is not really mandatory for a driver expected to be used for booting the system (it will be discarded by the operating system anyway, unless it takes specific actions to keep bits resident), but it comes in very handy for development.

&lt;p/&gt;The build information file usually includes a (commentary only) stanza stating which architectures the executable is expected to work on.
&lt;pre&gt;#
#  VALID_ARCHITECTURES           = AARCH64 ARM EBC IA32 IPF X64
#&lt;/pre&gt;
The remainder of the file simply specifies which source files are used to build the driver, which declaration files it uses (&lt;code&gt;MdePkg/MdePkg.dec&lt;/code&gt;), which library classes it needs (resolved into specific libraries by the build description file) and which protocols it consumes.
&lt;pre&gt;[Sources]
  ChaosKeyDriver.h
  DriverBinding.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiBootServicesTableLib
  UefiDriverEntryPoint
  UefiLib

[Protocols]
  gEfiUsbIoProtocolGuid
&lt;/pre&gt;

&lt;h3&gt;Adding some actual code&lt;/h3&gt;
&lt;p/&gt;Since we are not yet implementing any actual functionality beyond discovery, the only C source file added at this point is &lt;code&gt;DriverBinding.c&lt;/code&gt;. This all comes down to implementing an instance of &lt;code&gt;EFI_DRIVER_BINDING_PROTOCOL&lt;/code&gt;. Let us go through that, function by function.

&lt;h4&gt;EntryPoint&lt;/h4&gt;
&lt;p/&gt;All the &lt;a href=&quot;https://git.linaro.org/people/leif.lindholm/OpenPlatformPkg.git/blob/b1f241e7e2cc0e241d737d1533f0a95008520637:/Drivers/Usb/Misc/ChaosKeyDxe/DriverBinding.c#l180&quot;&gt;entry point function&lt;/a&gt; does is register the protocol instance, as defined in the &lt;code&gt;gUsbDriverBinding&lt;/code&gt; struct, with the system - and return &lt;code&gt;EFI_SUCCESS&lt;/code&gt;, printing an informational message as it does so. The &lt;code&gt;gUsbDriverBinding&lt;/code&gt; struct contains pointers to the &lt;code&gt;Supported()&lt;/code&gt;, &lt;code&gt;Start()&lt;/code&gt; and &lt;code&gt;Stop()&lt;/code&gt; functions defined by the protocol, as well as a &lt;code&gt;Version&lt;/code&gt; number which lets UEFI pick the most up to date driver if multiple are available.

&lt;h4&gt;Supported&lt;/h4&gt;
&lt;p/&gt;When a new device is detected in the system, UEFI will ask all of the plausible drivers whether they know how to deal with it, by calling their &lt;a href=&quot;https://git.linaro.org/people/leif.lindholm/OpenPlatformPkg.git/blob/b1f241e7e2cc0e241d737d1533f0a95008520637:/Drivers/Usb/Misc/ChaosKeyDxe/DriverBinding.c#l29&quot;&gt;&lt;code&gt;Supported()&lt;/code&gt;&lt;/a&gt; function. This implementation is probably one of the few bits of this driver that is pretty much feature complete - all it really needs to do is to find the USB manufacturer/device IDs and see if they are ones the driver knows how to handle. It then returns &lt;code&gt;EFI_UNSUPPORTED&lt;/code&gt; if this is a device it does not support, or &lt;code&gt;EFI_SUCCESS&lt;/code&gt; if it is a device it supports.

&lt;h4&gt;Start/Stop&lt;/h4&gt;
&lt;p/&gt;&lt;code&gt;Start()&lt;/code&gt; and &lt;code&gt;Stop()&lt;/code&gt; are left empty for now, returning &lt;code&gt;EFI_UNSUPPORTED&lt;/code&gt; whenever they are called. This is something that will be filled in in part 2 of this series.

&lt;h4&gt;UnloadImage&lt;/h4&gt;
&lt;p/&gt;Finally, when (if!) we unload the driver, &lt;a href=&quot;https://git.linaro.org/people/leif.lindholm/OpenPlatformPkg.git/blob/b1f241e7e2cc0e241d737d1533f0a95008520637:/Drivers/Usb/Misc/ChaosKeyDxe/DriverBinding.c#l219&quot;&gt;&lt;code&gt;UnloadImage()&lt;/code&gt;&lt;/a&gt; ensures that the bits that were registered by &lt;code&gt;EntryPoint()&lt;/code&gt; are unregistered again.

&lt;h2&gt;Building and using the driver&lt;/h2&gt;
&lt;h3&gt;Building the standalone driver&lt;/h3&gt;
&lt;p/&gt;In order to build a standalone driver, you need a platform description (&lt;code&gt;.dsc&lt;/code&gt;) file, mapping your library dependencies to actually available libraries. One way of doing this is to implement your own complete &lt;code&gt;.dsc&lt;/code&gt;. However, this is exactly what EDK2&apos;s &lt;code&gt;OptionRomPkg/OptionRomPkg.dsc&lt;/code&gt; provides. So a simpler way can be to simply add the &lt;code&gt;.inf&lt;/code&gt; to the &lt;code&gt;[Components]&lt;/code&gt; section of &lt;code&gt;OptionRomPkg.dsc&lt;/code&gt;. After that, the build should be as easy as:
&lt;p/&gt;&lt;pre&gt;GCC5_AARCH64_PREFIX=aarch64-linux-gnu- build -a AARCH64 -t GCC5 -p OptionRomPkg/OptionRomPkg.dsc -m OpenPlatformPkg/Drivers/Usb/Misc/ChaosKeyDxe/ChaosKeyDxe.inf&lt;/pre&gt;


&lt;h3&gt;Loading the driver&lt;/h3&gt;
&lt;p/&gt;For this example (and because Juno&apos;s built-in magical program-over-USB filesystem is insane), let&apos;s load the driver from a USB key. For simplicity&apos;s sake, have it plugged in when powering on and drop into the UEFI Shell. In my case, the USB key ended up as filesystem &lt;code&gt;FS2:&lt;/code&gt;.
&lt;pre&gt;Shell&gt; FS2:
FS2:\&gt; load ChaosKeyDxe.efi
add-symbol-file /home/leif/work/git/edk2/Build/OptionRomPkg/DEBUG_GCC5/AARCH64/OpenPlatformPkg/Drivers/Usb/Misc/ChaosKeyDxe/ChaosKeyDxe/DEBUG/ChaosKeyDxe.dll 0xF85E4000
Loading driver at 0x000F85E3000 EntryPoint=0x000F85E4044 ChaosKeyDxe.efi
*** Installed ChaosKey driver! ***
Image &apos;FS2:\ChaosKeyDxe.efi&apos; loaded at F85E3000 - Success
FS2:\&gt; 
&lt;/pre&gt;

&lt;p/&gt;At this point, you can verify that the driver has loaded by invoking the &lt;code&gt;drivers&lt;/code&gt; command:
&lt;pre&gt;FS2:\&gt; drivers
             T   D
             Y C I
             P F A
DRV VERSION  E G G #D  #C  DRIVER NAME                         IMAGE PATH
=== ======== = = = === === =================================== ==========
 23 00000030 D N N   1   0 &lt;null string&gt;                       Fv(B73FE497-B92E-416E-8326-45AD0D270092)/FvFile(1DF18DA0-A18B-11DF-8C3A-0002A5D5C51B)
...
 6F 0000000A D N N   1   0 &lt;null string&gt;                       Fv(B73FE497-B92E-416E-8326-45AD0D270092)/FvFile(4579B72D-7EC4-4DD4-8486-083C86B182A7)
 9E 0000000A ? N N   0   0 &lt;null string&gt;                       FS2:\ChaosKeyDxe.efi
&lt;/pre&gt;
You can see how the driver is loaded, and has the driver handle number &lt;code&gt;9E&lt;/code&gt;.

&lt;p/&gt;Now, plug in the ChaosKey:
&lt;pre&gt;FS2:\&gt; ChaosKey (0x1D50:0x60C6) is my homeboy!
UsbSelectConfig: failed to connect driver Not Found, ignored
&lt;/pre&gt;
We can see how the &lt;code&gt;Supported()&lt;/code&gt; function is invoked, and we then see an error message. The error is triggered by our empty &lt;code&gt;Start()&lt;/code&gt; function returning EFI_UNSUPPORTED when UEFI attempts to bring the device online. We&apos;ll fix that bit in part 2 of the series.

&lt;h3&gt;Unloading the driver&lt;/h3&gt;
&lt;p/&gt;During development, it can be handy to be able to load/unload without a full reboot. To do so, just call &lt;code&gt;unload&lt;/code&gt; with the driver handle you got from the &lt;code&gt;drivers&lt;/code&gt; command. Add the &lt;code&gt;-v&lt;/code&gt; option to get some extra output.
&lt;pre&gt;FS2:\&gt; unload -v 9E
     Revision......: 0x00001000
     ParentHandle..: FD317918
     SystemTable...: FDF30018
     DeviceHandle..: FD243918
     FilePath......: FC98FF98
     OptionsSize...: 0
     LoadOptions...: &lt;null string&gt;
     ImageBase.....: F85E3000
     ImageSize.....: 8000
     CodeType......: EfiBootServicesCode
     DataType......: EfiBootServicesData
     Unload........: F85E4000
Unload - Handle [FC990598].  [y/n]?
y
remove-symbol-file /home/leif/work/git/edk2/Build/OptionRomPkg/DEBUG_GCC5/AARCH64/OpenPlatformPkg/Drivers/Usb/Misc/ChaosKeyDxe/ChaosKeyDxe/DEBUG/ChaosKeyDxe.dll 0xF85E4000
Unload - Handle [FC990598] Result Success.
FS2:\&gt;
&lt;/pre&gt;
You can also verify the unload was successful by running &lt;code&gt;drivers&lt;/code&gt; again, and seeing this driver no longer listed.</description>
  </item>
  <item>
    <title>Opening up UEFI platform support</title>
    <pubDate>Wed, 22 Jun 2016 16:54:00 +0100</pubDate>
    <link>http://longhouse.vikings.scot/2016/06/22#opening_uefi_platform_support</link>
    <category>/uefi</category>
    <guid isPermaLink="false">http://longhouse.vikings.scot/uefi/opening_uefi_platform_support</guid>
    <description>
&lt;p/&gt;As some of you may know, one of the main points I have been pushing for over the past couple of years has been the availability of reference code for real platforms. Given that historically, firmware source code has simply not been available for UEFI-based computers, resolving this has been no trivial exercise.

&lt;p/&gt;I gave &lt;a href=&quot;https://youtu.be/m7vkCQzf56w&quot;&gt;an outline presentation about this&lt;/a&gt; at the UEFI spring plugfest in Seattle last year, announcing that I was starting a work-in-progress tree called &lt;a href=&quot;https://git.linaro.org/uefi/OpenPlatformPkg.git&quot;&gt;OpenPlatformPkg&lt;/a&gt; (due to lack of imagination) where I was going to start staging support for multiple platforms/devices. I created this as a separate tree holding only the platform code. As a way to keep things clean, and if I am to be honest also because this enforces deeper consideration of changes to core code. (I&apos;m not suggesting this is the way it should be done when moving platform support into Tianocore, just that it removed several potential conflict points when interacting with organisations not used to working against a single source tree for multiple platforms.)

&lt;/p&gt;Since then, the most visible impact of this in the EDK2 source tree has been the &lt;i&gt;removal&lt;/i&gt; of platform code from EDK2, as I moved it into OpenPlatformPkg. I finally started to see contributions outside of the ARM ltd. platforms a couple of months ago, and have since struggled to keep up with reviewing the patches contributed:

&lt;/p&gt;Over the past few weeks, I have merged support for:
&lt;ul&gt;
&lt;li/&gt;Hisilicon D02 and D03 platforms
&lt;li/&gt;AMD Overdrive (Seattle development platform)
&lt;li/&gt;LeMaker Cello (Seattle-based 96boards EE)
&lt;/ul&gt;
I am also currently working with Semihalf to get support for Marvell Armada 7040 in.

&lt;p/&gt;A warning for the purists - I have not been mandating that the entirety of the platform support is provided in source form. But we do now have a tree which can be used to rebuild against newer versions of upstream EDK2, and I do mandate that each platform adds &lt;i&gt;some&lt;/i&gt; open source bits.


&lt;h3&gt;AMD&lt;/h3&gt;
&lt;p/&gt;We have been working with AMD over the past few months to provide a port based on the official Seattle Firmware Development Kit (FDK) - the same that is used for the commercial firmware shipped on AMD Overdrive and Softiron 3000 platforms. Since this was never originally designed to be used in an open source context, it has included the relicensing of header files and some restructuring to permit simple rebuilding of the binary modules for new FDK releases.

&lt;p/&gt;So this new port comes with some blobs - BUT it does bring source code for ACPI, SMBIOS, (non-PCIe) SATA controller, Hardware RNG and overall platform initialization. And of course it reuses some existing open source drivers available in EDK2. From a personal perspective, this means I can now with a quick turnaround test new EDK2 core changes on my Overdrive.

&lt;p/&gt;This being a platform with all of its RAM &gt; 4GB, it has also helped flush out some incorrect assumptions in core EDK2 code (and a Linux driver or two).


&lt;h3&gt;Hisilicon&lt;/h3&gt;
&lt;p/&gt;We actually got most of the way towards a port for the D02 platform back in December - enough for me to agree to post it as a public branch on the main OpenPlatformPkg repository. But I still had a fair amount of things I wanted improved style wise, and the Hisilicon engineers were under pressure to provide a port for the newer D03 platform as well, so spent a few months getting this up and running.

&lt;p/&gt;But contrary to the story we have seen many times (with many different vendors) in the mobile space, once they completed this they came back.  and put a big effort responding to review feedback to ensure both platforms could be merged simultaneously during our reference platform sprint in Cambridge (UK) last week.


&lt;h3&gt;Future&lt;/h3&gt;
&lt;p/&gt;Well, Tianocore has now obtained a more standardised (and public) change process, and there is currently a proposal underway for how to support platforms in official repositories:
http://thread.gmane.org/gmane.comp.bios.edk2.devel/11624
With a bit of luck and some hard work OpenPlatformPkg can become redundant the year after it was introduced!

&lt;p/&gt;I have also had a few more contacts from people looking to provide ports for upcoming (and existing) platforms, so there should be some more to show later in the year.</description>
  </item>
  <item>
    <title>Installing Debian Jessie on QEMU AArch64</title>
    <pubDate>Tue, 27 Jan 2015 13:06:00 +0000</pubDate>
    <link>http://longhouse.vikings.scot/2015/01/27#qemu-aarch64-jessie</link>
    <category>/uefi</category>
    <guid isPermaLink="false">http://longhouse.vikings.scot/uefi/qemu-aarch64-jessie</guid>
    <description>
&lt;p/&gt;I previously wrote about how to &lt;a href=&quot;http://blog.eciton.net/uefi/qemu-arm-uefi.html&quot;&gt;run AArch64 UEFI on QEMU&lt;/a&gt;, but it did not really cover how to do anything useful with it. So here is a follow-up, showing how you can install and run a full &lt;a href=&quot;http://www.debian.org/&quot;&gt;Debian&lt;/a&gt; installation. The steps below &lt;i&gt;require&lt;/i&gt; at least version 2015.01 of linaro-edk2.

&lt;h3&gt;Building QEMU&lt;/h3&gt;
&lt;p/&gt;Full support for AArch64 (the 64-bit ARM architecture) was only added into QEMU version 2.2.0, so will probably not yet be in any distribution-provided QEMU. So for now, let&apos;s build our own:

&lt;p/&gt;&lt;pre&gt;$ git clone git://git.qemu-project.org/qemu.git
$ cd qemu
$ git checkout -b 2.2.0-stable v2.2.0
$ ./configure --prefix=/usr/local --target-list=aarch64-softmmu
$ make -j`getconf _NPROCESSORS_ONLN`
$ sudo make install&lt;/pre&gt;

&lt;h3&gt;Create ROM Images&lt;/h3&gt;
&lt;p/&gt;The aarch64 &lt;i&gt;virt&lt;/i&gt; machine sports two emulated 64MB NOR flash devices, holding the platform firmware and its persistent environment. We use the IntelBds flavour of the UEFI images, which is what the x86 Ovmf QEMU port does.

&lt;p/&gt;&lt;pre&gt;$ mkdir ~/arm64-qemu &amp;&amp; cd ~/arm64-qemu
$ dd if=/dev/zero of=flash0.img bs=1M count=64
$ LINARO_EDK2_URL=http://releases.linaro.org/15.01/components/kernel/uefi-linaro/
$ wget $LINARO_EDK2_URL/release/qemu64-intelbds/QEMU_EFI.fd
$ dd if=QEMU_EFI.fd of=flash0.img conv=notrunc
$ dd if=/dev/zero of=flash1.img bs=1M count=64
&lt;/pre&gt;

&lt;h3&gt;Block devices&lt;/h3&gt;
&lt;p/&gt;We need to prepare image files for the emulated HDD as well as the installation CDROM. The CDROM image, we just download - until Debian Jessie has actually been released, from &lt;a href=&quot;http://cdimage.debian.org/cdimage/weekly-builds/arm64/&quot;&gt;the weekly snapshots&lt;/a&gt;. I would recommend the &lt;a href=&quot;http://cdimage.debian.org/cdimage/weekly-builds/arm64/iso-cd/debian-testing-arm64-netinst.iso&quot;&gt;netinst iso&lt;/a&gt;, which is 150MB in size and grabs all packages from the network. If you need to do an installation somewhere with no networking, go for the 4.4GB &lt;a href=&quot;http://cdimage.debian.org/cdimage/weekly-builds/arm64/iso-dvd/debian-testing-arm64-DVD-1.iso&quot;&gt;single DVD image&lt;/a&gt; instead.

&lt;p/&gt;For the HDD image, we just need to create an empty file of sufficient size to hold our system - I would say 8GB, but if you&apos;re doing something very limited you could get away with less.
&lt;p/&gt;&lt;pre&gt;$ dd if=/dev/zero of=hda.img bs=1M count=8192&lt;/pre&gt;

&lt;h3&gt;Creating a launch script&lt;/h3&gt;
&lt;p/&gt;Since we do not yet have PCI emulation on AArch64 in QEMU (underway) or EDK2 (to be commenced in the next month or so), we cannot simply use -hda and -cdrom so find ourselves in &quot;magic rune&quot; territory. For now, the below script is a simple enough way to launch the emulator.

&lt;pre&gt;#!/bin/sh

CDROM_IMG=debian-testing-arm64-netinst.iso
HDA_IMG=hda.img

make_cdrom_arg()
{
        echo &quot;-drive file=$1,id=cdrom,if=none,media=cdrom&quot; \
             &quot;-device virtio-scsi-device -device scsi-cd,drive=cdrom&quot;
}

make_hda_arg()
{
        echo &quot;-drive if=none,file=$1,id=hd0&quot; \
             &quot;-device virtio-blk-device,drive=hd0&quot;
}

HDA_ARGS=`make_hda_arg $HDA_IMG`
if [ $# -eq 1 ]; then
        case $1 in
            install)
                CDROM_ARGS=`make_cdrom_arg $CDROM_IMG`
            ;;
            *)
                CDROM_ARGS=&quot;&quot;
            ;;
        esac
fi

qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic \
                    -pflash flash0.img -pflash flash1.img \
                    $CDROM_ARGS $HDA_ARGS -netdev user,id=eth0 \
                    -device virtio-net-device,netdev=eth0 &lt;/pre&gt;

&lt;h3&gt;Launching the model&lt;/h3&gt;
&lt;p/&gt;Save the above script as &lt;code&gt;launch.sh&lt;/code&gt;, make it executable with &lt;code&gt;chmod +x launch.sh&lt;/code&gt; and launch the emulator with &lt;code&gt;./launch.sh install&lt;/code&gt;. You should end up with something looking a bit like this in your terminal:
&lt;img src=&quot;/static/img/jessie-arm64-qemu.png&quot;/&gt;
&lt;p/&gt;From here on, you have a standard Debian installer, which I&apos;m not going to help you with, since there are many other resources available (and the installer is generally quite straightforward).</description>
  </item>
  <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>
