# Adding support for the Rockpi-S



## mapaul (Jun 19, 2021)

I recently procured some of the excellent Rockpi-S boards, which come with full size usb and ethernet, onboard audio out, optional nand flash, optional wifi / BT (over SDIO), as well as optional POE all in a small relatively inexpensive package running on the RK3308.

My personal use-case is to build a device that can do shairport-sync (airplay) to some speakers, and probably a print server, but I can imagine a lot of other uses for them as well.

This thread is to document my attempts to get the board working, but also as I am somewhat new to Freebsd, to ask for help along the way.

My plan of action is as follows:

- Build u-boot for this board
- Bring up the board using the process in /usr/src/release/release.sh process, and ideally upstream that change.
- Document what works and what doesn't
- Investigate using nanobsd for this type of board.

If anyone has already done any of these steps (especially the u-boot work), I would love to collaborate. Also if there is a better place to communicate this please let me know.

I would like any advice on whether I should persue crochet over the /usr/src/release/release.sh process. I don't currently fully understand how I would choose between them. Also the release.sh processes seem to take an unreasonably large amount of time in order to build. Is there anything that I can do to have repeat builds at least be faster?


----------



## T-Daemon (Jun 21, 2021)

mapaul said:


> Also if there is a better place to communicate this please let me know.


A better place would be freebsd-arm@ mailing list. All the ARM developers are there to find.



			FreeBSD Mailing lists: subscription for freebsd-arm
		




mapaul said:


> Also the release.sh processes seem to take an unreasonably large amount of time in order to build. Is there anything that I can do to have repeat builds at least be faster?


Try



			MetaMode - FreeBSD Wiki
		


To make kernel module filemon persist reboots, set in /etc/rc.conf `kld_list="filemon"` .


----------



## mapaul (Jul 9, 2021)

Thanks for the suggestions!

Progress so far is slim. I have been working on getting u-boot up and running, and mostly just learning about what exactly it does, how it's installed, and how it differs between linux and FreeBSD. I'm probably missing some information on these things, but so far here is what I understand.

u-boot is roughly equivalent to the bios or EFI on an x86 device. It is responsible for bringing up DRAM and possibly other necessary aspects of the system that need to be working before a kernel can be run. It is also responsible for finding and booting into a kernel. To accomplish this job, has drivers for lots of things like disk drives, keyboards, serial ports, ethernet, among others. These allow logging, user-interaction, and ultimately finding a kernel image to boot from.

Also unlike a bios or efi, where the image is burned onto the board, u-boot is typically installed on the same sd-card or nand-flash that the device will eventually boot from. This means we have to provide a u-boot that works with both our kernel and our board and install it to the correct location of the SD card where it will be loaded.

This high level understanding of u-boot applies for both Linux and FreeBSD. I am still trying to understand the specific things FreeBSD needs from u-boot in order to boot on it.

So far I have started with the bsp provided by the manufacturer to try to build u-boot (following this guide). I did investigate creating a port of u-boot for the rock pi s under freebsd, but so far the specific chipset RK3308 does not seem to be supported in freebsd's u-boot or the upstream repo, and I don't really know all what has been customized to get it to work. So instead I am hoping to try to patch whatever FreeBSD needs into the manufacturer supplied u-boot source code in order to get it running, but the first step is just to get a working u-boot shell for the rock-pi-s so I can at least poke around.

Following the guide above, I have built idbloader.img, uboot.img and trust.img and coppied them to the correct offsets on the sd card. That does show text on the uart, but it crashloops. one cycle of the text is below:

```
INFO:    Preloader serial: 0
NOTICE:  BL31: v1.3(release):3a579d3
NOTICE:  BL31: Built : 09:09:17, Jan 29 2019
INFO:    Lastlog: last=0x100000, realtime=0x102000, size=0x2000
INFO:    ARM GICv2 driver initialized
INFO:    Using opteed sec cpu_context!
INFO:    boot cpu mask: 1
INFO:    plat_rockchip_pmu_init: pd status 0xe
INFO:    BL31: Initializing runtime services
WARNING: No OPTEE provided by BL2 boot loader, Booting device without OPTEE initialization. SMC`s destined for OPTEE will return SMC_UNK
ERROR:   Error initializing runtime service opteed_fast
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0x600000
INFO:    SPSR = 0x3c9
No serial driver found
WARN: PSCI sysreset is disabled

DDR Version V1.26
REGFB: 0x00000032, 0x00000032
In
589MHz
DDR3
 Col=10 Bank=8 Row=15 Size=512MB
msch:1
Returning to boot ROM...
```

I think I need to understand why this fails, and maybe try to boot a custom build linux kernel before I will be able to get FreeBSD running.


----------



## mapaul (Jul 10, 2021)

Had a small breakthrough today. I got lucky and discovered a working prebuilt u-boot intended for use with openBSD (gist). Importantly this copy of uboot has the bootefi command, which appears to be required for FreeBSD. Using these files, and the latest mini-memstick image for aarch64, I was able to put together a bootable sd card for the rock pi s. The image booted into the u-boot shell, and I was able to load the device tree and Freebsd kernel.


```
fatload mmc 0:1 ${fdt_addr_r} rk3308-rock-pi-s.dtb
fatload mmc 0:1 ${kernel_addr_r} efi/boot/bootaa64.efi
bootefi ${kernel_addr_r} ${fdt_addr_r}
```

This did boot the freebsd kernel, but resulted in a boot loop. I am including one cycle of the logs form that bootloop here.


```
INFO:    PSCI Power Domain Map:
INFO:      Domain Node : Level 2, parent_node -1, State ON (0x0)
INFO:      Domain Node : Level 1, parent_node 0, State ON (0x0)
INFO:      Domain Node : Level 0, parent_node 0, State ON (0x0)
INFO:      Domain Node : Level 0, parent_node 0, State ON (0x0)
INFO:      CPU Node : MPID 0x0, parent_node 1, State ON (0x0)
INFO:      CPU Node : MPID 0xffffffffffffffff, parent_node 1, State OFF (0x2)
INFO:      CPU Node : MPID 0xffffffffffffffff, parent_node 1, State OFF (0x2)
INFO:      CPU Node : MPID 0xffffffffffffffff, parent_node 1, State OFF (0x2)

DDR Version V1.26
REGFB: 0x00000032, 0x00000031
In
589MHz
DDR3
 Col=10 Bank=8 Row=15 Size=512MB
msch:1
Returning to boot ROM...
INFO:    Preloader serial: 0
NOTICE:  BL31: v1.3(release):3a579d3
NOTICE:  BL31: Built : 09:09:17, Jan 29 2019
INFO:    Lastlog: last=0x100000, realtime=0x102000, size=0x2000
INFO:    ARM GICv2 driver initialized
INFO:    Using opteed sec cpu_context!
INFO:    boot cpu mask: 1
INFO:    plat_rockchip_pmu_init: pd status 0xe
INFO:    BL31: Initializing runtime services
WARNING: No OPTEE provided by BL2 boot loader, Booting device without OPTEE initialization. SMC`s destined for OPTEE will return SMC_UNK
ERROR:   Error initializing runtime service opteed_fast
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0x600000
INFO:    SPSR = 0x3c9


U-Boot 2017.09-02378-g2dce0717fc-dirty (Nov 26 2019 - 21:44:56 +1000)

Model: Radxa ROCK Pi S
PreSerial: 0
DRAM:  510 MiB
Relocation Offset is: 1f916000
vdd_core 1044000 uV
vdd-core init 1044000 uV
MMC:   dwmmc@ff480000: 0, dwmmc@ff490000: 1
Using default environment

In:    serial@ff0c0000
Consoles: EFI console
    Reading loader env vars from /efi/freebsd/loader.env
FreeBSD/arm64 EFI loader, Revision 1.1
(Thu Jul  1 05:57:02 UTC 2021 root@releng1.nyi.freebsd.org)
PartType: EFI
   Command line arguments: loader.efi
   Image base: 0x280000ial#" variable, errno=1
   EFI version: 2.051
   EFI Firmware: Das U-boot (rev 0.00)
   Console: comconsole (0)
   Load Path: \efi\boot\bootaa64.efi
   Load Device: dwmmc@ff480000.blk
"Synchronous Abort" handler, esr 0x96000010
* Relocate offset = 000000001f916000
* ELR(PC)    =   fffffffffeb12654
* LR         =   fffffffffeafbd3c
* SP         =   000000001e4f5610
aclk_peri 185714 KHz
* ESR_EL2    =   0000000096000010
pclk_perEC[31:26] == 100101, Exception from a Data abort, from current exception level
hclk_audIL[25] == 1, 32-bit instruction trapped
pclk_audio 98303 KHz
* DAIF       =   00000000000003c0
Hit key D[9] == 1, DBG maskedL+C'):  0
android_A[8] == 1, ABORT maskeduld not find misc partition
ANDROID:I[7] == 1, IRQ maskede)"
android_F[6] == 1, FIQ maskedCould not found bootable partition boot
Android boot failed, error -1.
* SPSR_EL2   =hi 0000000020000349
boot_rocD[9] == 1, DBG masked boot part info error
Card didA[8] == 1, ABORT masked select!
mmc_initI[7] == 0, IRQ not masked
switch tF[6] == 1, FIQ masked
mmc0 is M[4] == 0, Exception taken from AArch64
ScanningM[3:0] == 1001, EL2h
Found EFI removable media binary efi/boot/bootaa64.efi
* SCTLR_EL2  =ot 0000000030c51835
1266140 I[12] == 1, Icaches enablediB/s)
## StartC[2] == 1, Dcache enabled280000 ...
Adding bM[0] == 1, MMU enabled000000 (size: 0x1fe00000)
Scanning disk dwmmc@ff480000.blk...
* HCR_EL2    =   000000000800003aelect!
* VBAR_EL2   =   000000001ff16800
* TTBR0_EL2  =   000000001fff0000..
Scanning disk nandc@ff4b0000.blk...
x0 : 0000000000000000 x1 : 0000000000000000
x2 : 0000000000000000 x3 : 000000001e4d4749
x4 : 0000000000000073 x5 : 0000000000000050
x6 : 000000001e42625c x7 : 000000001e4d43c2
x8 : 0000000000000000 x9 : 0000000000000000
x10: fefefefefefefeff x11: 0000000000000006
x12: 0000000000000000 x13: 0000000000000000
x14: 0000000000000000 x15: 0000000000000000
x16: 0000000000000000 x17: 0000000000000000
x18: 000000001f50ddb8 x19: 000000001e4f5878
x20: 000000001e4d2d64 x21: 0000000000000000
x22: 0000000000000000 x23: 0000000000000000
x24: 000000001e4f7a88 x25: 000000001e4e0000
x26: 0000000000000000 x27: 000000001e4f77d8
x28: 000000001e4e6000 x29: 000000001e4f5800

SP:
1e4f5610:  00000000 00000000 00000000 00000000
1e4f5620:  00000000 00000000 1ff942ca 00000000
1e4f5630:  00000000 00000000 00000000 00000000
1e4f5640:  1ff94311 00000000 1ff94337 00000000
1e4f5650:  1ff94384 00000000 1ff943d1 00000000
1e4f5660:  1ff94411 00000000 1ff94451 00000000
1e4f5670:  1ff9448e 00000000 00000000 00000000
1e4f5680:  00000000 00000000 1ff944cb 00000000
1e4f5690:  1e4f5800 00000000 1ff16a0c 00000000
1e4f56a0:  1e4f5878 00000000 1e4d2d64 00000000
1e4f56b0:  1fff0000 00000000 0800003a 00000000
1e4f56c0:  30c51835 00000000 1e4f5610 00000000
1e4f56d0:  20000349 00000000 1ff16800 00000000
1e4f56e0:  000003c0 00000000 96000010 00000000
1e4f56f0:  1e428654 00000000 00000000 00000000
1e4f5700:  00000000 00000000 00000000 00000000

Resetting CPU ...
```

I don't really know how to figure out what went wrong in this log. but it looks like the following lines are important:

`"Synchronous Abort" handler, esr 0x96000010`
and
`android_A[8] == 1, ABORT maskeduld not find misc partition
ANDROID:I[7] == 1, IRQ maskede)"
android_F[6] == 1, FIQ maskedCould not found bootable partition boot`

Which seems to have multiple strings on top of one another. I can't really tell if it's 
`Could not find misc partition
Found bootable partition boot`

or 
`Could not find misc partition
Could not found bootable partition`


----------



## T-Daemon (Jul 10, 2021)

mapaul said:


> I don't really know how to figure out what went wrong in this log.


If you are asking for help you really should subscribe to the freebsd-arm@ mailing list. All the ARM developers are active there. It's more likely to find on that list a helping hand than here in Forums. FreeBSD developers are rarely on Forums, if at all.

It could take longer to figure out a solution alone here than to collaborate with members of the freebsd-arm@ list. You can expect there members with substantial understanding of the problem and the one or other might pointing in the right direction or maybe there is already a same/similar work in progress.


----------



## mapaul (Jul 10, 2021)

Thanks T-Daemon, I have already done so and have gotten some response there. I was planning to still log my progress here, since it's easier to format code and text on this forum than in an email.


----------

