August 30, 2018

Nanopi Fire3 -- My U-boot setup

I have spent a bunch of time, too much time, trying to figure out the setup to launch U-Boot as it is done with the Linux distribution provided by Friendly Arm. I have learned enough to set up something much simpler myself. A big advantage of what I am doing is that there are no mysterious binary "things" that run before U-Boot gets started.

bl1-mmcboot-m3

Source for this is available, making this easy to build. I make one change. An embedded constant at offset 0x40 in startup_aarch64.S needs to be changed so it will look for U-boot at sector 129 rather than 64. Here is my comment from that file:
/* Note by tjt about location 0x40.
 * The value here was originally 0x8000 (which is a 64 sector offset, i.e. 32K)
 * I changed this to 0x10200, which is a 129 sector offset.
 * This is 1 sector for the partition table or whatever,
 * Then allows 128 sectors for this thing (bl1), i.e. 64K
 * This must fit into the 64K SRAM, so surely nothing bigger is needed.
 * At this time, the size of bl1 is about 35K,
 *  so the old 32K allotment is suspect anyway.
 */
Once this change is done, I recompile and then install this on my SD card via:
dd if=out/bl1-nanopi.bin of=/dev/sdf bs=512 seek=1 conv=fdatasync

Changes to U-Boot itself

The U-Boot binary needs a NSIH style header with some proper values plugged in. To do this, I edit arch/arm/cpu/armv8/start.S and add this code:
#define TJT_NSIH
.globl  _start
_start:
        b       reset
#ifdef  TJT_NSIH
        .skip   60
        .word 0x00000000    // 0x040 : Device Read Address for next boot
        .word 0x000A0000    // 0x044 : Load Size for Uboot (640K)
        .word 0x43c00000    // 0x048 : Load Address for Uboot.
        .word 0x43c00000    // 0x04C : Launch Address for Uboot.

        .skip 428
        .word 0x4849534E    // 0x1FC        "NSIH"
#endif
The bl1-mmcboot loader will find this, load 640K to address 0x43c00000, and branch to 0x43c00000 to start U-boot running. The current size of uboot.bin is just over 500K, so this will do fine. After adding this bit of code, I recompile U-Boot and install it on my SD card via:
dd if=u-boot.bin of=/dev/sdf bs=512 seek=129 conv=fdatasync
I ignore fip-nonsecure.img entirely.

Try it out

After putting these two things onto the flash card, I put the card into my Fire3 board and hit the reset button. It works just fine! No need for all the mysterious FIP and secure mode jive that the linux setup uses.

Lessons Learned

Simple is good and seems to work fine. This gives me known source code all the way to and through U-Boot.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org