# Using/Booting FreeBSD on the Firefly RK-3399 SoC



## sylvainsab (Mar 5, 2021)

Hello,

I have acquired a Firefly RK-3399 SoC ARM board.

I see there is an official u-boot in the ports for this board, however I am unable to build the dtb from /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts (using the dtc utility)
(I'm using another machine right now, I'll edit in a moment to show the error messages - Three error messages around lines 22-25 it seems.)

I have also tried to use the dtb provided by openbsd, putting it in /boot/dtb/rk3399-firefly.dtb on the sd card, although yet another trouble is that FreeBSD doesn't seem to recognize my sd card reader, so I have to edit the img by tweaking around with mdconfig(8)... 

Here is the output I get on the console from openbsd :


```
$cu -s 1500000 -l /dev/cuaU0

U-Boot TPL 2020.10 (Feb 28 2021 - 14:33:08)
Channel 0: DDR3, 800MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
Channel 1: DDR3, 800MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
256B stride
Trying to boot from BOOTROM
Returning to boot ROM...

U-Boot SPL 2020.10 (Feb 28 2021 - 14:33:08 +0000)
Trying to boot from MMC1


U-Boot 2020.10 (Feb 28 2021 - 14:33:08 +0000)

SoC: Rockchip rk3399
Reset cause: POR
Model: Firefly-RK3399 Board
DRAM:  3.9 GiB
PMIC:  RK808
Cannot find regulator pwm init_voltage
MMC:   mmc@fe310000: 2, mmc@fe320000: 1, sdhci@fe330000: 0
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial@ff1a0000
Out:   serial@ff1a0000
Err:   serial@ff1a0000
Model: Firefly-RK3399 Board
Net:   eth0: ethernet@fe300000
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0(part 0) is current device
Scanning mmc 0:1...
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
Found EFI removable media binary efi/boot/bootaa64.efi
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
Card did not respond to voltage select!
Scanning disk mmc@fe310000.blk...
Disk mmc@fe310000.blk not ready
Scanning disk mmc@fe320000.blk...
** Unrecognized filesystem type **
Scanning disk sdhci@fe330000.blk...
** Unrecognized filesystem type **
Found 6 disks
** Unable to read file ubootefi.var **
Failed to load EFI variables
BootOrder not defined
EFI boot manager: Cannot load any image
393216 bytes read in 21 ms (17.9 MiB/s)
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
```

So, a complex endeavor but hopefully I will manage to boot/install FreeBSD on this device.

Thanks to anyone who would help


----------



## sylvainsab (Mar 5, 2021)

Here are the errors I get when trying to generate the dtb :

```
# dtc /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts
Error at /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts:22:25: Expected numbers in array of cells
                enable-dpios = <&gpio1 RK_PB5 GPIO_ACTIVE_HIGH>;
                                       ^
Error at /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts:22:25: Expected ; at end of property
                enable-dpios = <&gpio1 RK_PB5 GPIO_ACTIVE_HIGH>;
                                       ^
Error at /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts:22:25: Failed to find root node /.
                enable-dpios = <&gpio1 RK_PB5 GPIO_ACTIVE_HIGH>;
                                       ^
```

PS to the moderators this thread should be in "Embedded" I'm sorry, can you move it ? thx


----------



## JohnnySorocil (Mar 15, 2021)

Try with:

```
cpp -nostdinc -I /usr/src/sys/gnu/dts/include -undef -x assembler-with-cpp /usr/src/sys/gnu/dts/arm64/rockchip/rk3399-firefly.dts > tmp.dts && dtc -@ -H epapr -i . -I dts -O dtb -o rk3399-firefly.dtb tmp.dts
```
Works on my workbench™
Method above also works on dts downloaded (and patched) from Linux kernel from Github


----------

