August 24, 2018

Nanopi Fire3 and USB booting.

The Samsung S5P6818 chip has an on-chip bootrom that can boot via several different methods. The bootrom code tries first to load an image from the SD card. If that fails, it falls back to USB.

To check this out, remove the SD card from the unit, connect a USB cable (in my case this is how I power the board at this time, so I get this "for free"). When I power it up, I see the following in the logs on my linux machine:

Aug 24 09:35:45 trona kernel: usb 2-1.8: new high-speed USB device number 4 using ehci-pci
Aug 24 09:35:45 trona kernel: usb 2-1.8: New USB device found, idVendor=04e8, idProduct=1234, bcdDevice= 0.00
Aug 24 09:35:45 trona kernel: usb 2-1.8: New USB device strings: Mfr=0, Product=0, SerialNumber=0
I do not get this when I have a proper SD card plugged in, so this is all working just as the documentation says.

Try the s5p6818_spl project from metro94

I found this while searching online, and it works great. This makes a tiny program which will blink the LED (connected to B12) on my Fire3 board. Note that his program was written for the NanoPi M3 boards, which also uses the s5p6818 SoC and apparently (and conveniently) must have an onboard LED connected to GPIO B12. To build this I cloned the project, then added the line CROSS_COMPILE = aarch64-linux-gnu- to the Makefile. After this, typing "make" did a clean compile (nice!) and then typing this downloaded the code to my board:
su
make install
He provides two important pieces of software in the "tools" directory. The first is "build", which puts a proper header into the download image. The second is "load", which runs on my linux system and talks to the board via USB. I find that I must run the "load" program as root for it to have proper permissions to access the device files for USB, otherwise I get the message:
libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/002/004: Permission denied
libusb: error [_get_usbfs_fd] libusb requires write access to USB device nodes.
Failed when starting 2ndboot
make: *** [Makefile:103: install] Error 255
Once I am running as root, I get the following messages. Most importantly the LED begins to blink!
make install
Start transfer, size = 5280
Finish transfer, actual size = 5280
Second Boot Successed

Source code for the tools

I am unable to find source code for the "build" or "load" programs. Metro94 has another project called s5pxx18_load which is a linux program using libusb that is closely related to the "load" program, but not identical. This fellow did not return emails, so I spent some time reverse engineering his binary blobs and this led to several projects of my own.

My own standalone projects and usb_loader

Beginning with the code in s5pxx18_load, I worked up my own USB loader that replaces both "build" and "load". This includes a disassembly of the on-chip bootrom, my USB_loader, and several standalone or "SPL" projects.

Lessons Learned

The on-chip boot loader can be used to download programs via the USB cable and this works very well. The linux side program is available and easy to understand (especially once I finished modifying it!). The on-chip loader runs in A32 mode and transfers control in A32 mode. A header with a fairly short sequence of instructions can switch to A64 mode -- or the downloaded program can continue to run in A32 mode. It is your choice.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org