Hacking u-boot for Pinebook. Part #1 - using FEL

It's been a while since I posted to my blog. A lot of things happened since then, I guess the most important is -- I moved to Canada. I've been living in Vancouver (OK, Greater Vancouver) with my wife and cat for more than 2 years now. But enough about me, let's get back to the topic.

Recently I've got a Pinebook, mostly for hacking purposes. It's pretty nice device - quad-core Allwinner A64 CPU, 2GB LPDDR3 RAM, eMMC storage, etc, etc. See pine64.org for full specs. But unfortunately it comes with BSP kernel from Allwinner which is pretty ancient - 3.10 (released in 2013, more than 4 years ago!)

Hopefully, mainline support for A64 is in pretty decent shape, see http://linux-sunxi.org/Linux_mainlining_effort. Sure some things are missing - LCD, sound, power management, and that's not all. But it's good - there's something to hack on, right?

So I decided to start with u-boot. Hopefully, Allwinner SoCs support boot over USB - it's called FEL, see http://linux-sunxi.org/FEL for details. So basically it's possible to load and execute SPL to configure DRAM, and then load and start u-boot. That's very convenient for development - you don't have to do SD-card juggling, just connect your laptop to the board using USB cable (USB-A to USB-A in my case), load your card with special image and you're good to go.

Unfortunately, 64-bit SPL doesn't support jumping back into FEL which is 32-bit code. To overcome this issue, it's possible to build SPL in 32-bit mode. It's not supported in mainline u-boot at the moment, but there're patches on the list, see https://lists.denx.de/pipermail/u-boot/2016-November/271732.html
So it works like this:

  • Load and executre 32-bit SPL using FEL, which jumps back to FEL code after it's done
    • sunxi-fel spl sunxi-spl.bin
  • Load ATF (ARM trust firmware)
    • sunxi-fel write 0x44000 bl31.bin
  • Load u-boot
    • sunxi-fel write 0x4a000000
  • Jump into 64-bit ATF, which jumps to u-boot after it's done:
    • sunxi-fel reset64 0x44000
Don't try to flash your card with 32-bit SPL and 64-bit u-boot - that won't work. 32-bit SPL doesn't know how to switch to 64-bit mode, use it only with FEL.

That's it for today. In part #2 I'll be talking about PMIC and LCD on Pinebook.

Comments

Nico said…
Hello Anarsoul,

A quick thank you for your Alarm image. I use it since 2019 on my Pine A64 LTS. I finally removed your custom repo and switched to plain Archlinux Arm ones, but it still works well, although I lost my BT/Wifi add-on card on the manufacturer slot over time. Not that much a problem, I use Ethernet.

This box hosts my screen'ed irssi which I can use through a SSH session. More important, it has some nifty services for the Cjdns-propelled Hyperboria trusted overlay network :

-It's the home of the Dir, the human-curated directory of websites that are reported automatically as currently reachable on Hyperboria (Hyped websites as we say). Thanx to your effort. Human part is just people categorizing them by tags.
-It is also the host of the initial tracker peer of the Hyperboria "Cjdradio" P2P audio streaming infrastructure, and also hosts one radio "station" (not real webradio, indeed, each stream being user specific).

I chose your image at the time, because Armbian just had no X. It gave me the opportunity to discover Arch Linux, I'm very happy since.

Many thanks
anarsoul said…
Hey Nico,

Happy to hear that it's still useful for someone! :)

However as you already discovered, you shouldn't really need my custom repo anymore, since most of my changes are upstream now.

To get BT working you just need a device tree that enables BT node (or an overlay) and firmware from https://github.com/anarsoul/rtl8723bt-firmware in your /lib/firmware

For WiFi you also need a device tree that enables WiFi node (or an overlay) and 8723cs driver.

I'm using Archlinux ARM on most of my ARM devices, and for a new device I just bootstrap it on another working ARM device with arch-install-scripts.

Regards,
Vasily

Popular posts from this blog

Access point with Raspberry Pi and rtl8192cu dongle

Migration to xubuntu

Wayland and software rendering