How to run FreeBSD on new boards built on Rockchip 35XX..

To me Petiteboot was more of an hassle than a help. I have a handle on u-boot.
PetiteBoot on SPI needs to be shutoff or erased.
sf erase 0 100000
I guess I should have mentioned this is forever gone???? You can restore I would think.

One option for dual boot is wipe out petiteboot and make seperate microSD for each OS. Armbian and FreeBSD.
Then you could put u-boot on microSD or SPI flash.
 
Well There is no official EDK2 image for the ODroid M1 but given I can find a proper DTS file for it I can most likely build one for you :)
You just need to follow the steps in the README.txt file.
The images for StationP2 og NanopiR5S might work for you, but most likely some features are not working correctly
However if you just can get it to boot, getting the right support into a kernel will be the first step.
 
There is [a DTS file in the Linux Kernel Repo](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/rockchip/rk3568-odroid-m1.dts) if that holds any value - not sure what else is needed to build the img/idt pair, but I'd be more than happy to look into getting it to work and giving it a spin (assuming I can get it to boot - time has not been on my side). Build instructions would be enough for me to go a long way
 
But u-boot doesn't support HDMI or has that been added ?

Anyhow I'll check the linux dts file and see if it "fits" into what we have I FreeBSD.
I would assume that you can use EDK2 from one of the other rk3568 boards and have that boot a kernel with a build in m1 DTB and have it working.
I can try to build an image for you to test out...
Anyhow I'll happily share my EDK2-rk356x tree (based on Jared's excellent work) where I have added several boards and adding the m1 should be easy to add with a little work.
 
I've got a NanoPi R5C which I would like to set up as an internet router. Ideally, I would like to run OPNsense on it, but FreeBSD would be great for a start (maybe I'll learn pf instead!).

I would really like to run the bootloader from the eMMC or SD card, and boot FreeBSD from an external USB 3 SSD.

I went to https://personalbsd.org/download/UEFI-RK356x/ and downloaded the following files:

NANOPI-R5C_EFI.img
NANOPI-R5C_EFI.itb
idblock.bin

Unfortunately, I'm not sure exactly what to do with them! ;)

I started by writing the img file to an SD card, but unfortunately gpart shows the partition table as corrupt:

Code:
=>   34  67517  mmcsd0  GPT  (7.2G) [CORRUPT]
     34     30          - free -  (15K)
     64  16320       1  linux-data  (8.0M)
  16384  16384       2  linux-data  (8.0M)
  32768  32768       3  linux-data  (16M)
  65536   2015          - free -  (1.0M)

=>   34  67517  diskid/DISK-13A380FE  GPT  (7.2G) [CORRUPT]
     34     30                        - free -  (15K)
     64  16320                     1  linux-data  (8.0M)
  16384  16384                     2  linux-data  (8.0M)
  32768  32768                     3  linux-data  (16M)
  65536   2015                        - free -  (1.0M)


If I put the SD card into my NanoPi, the SYS light is solid, but there is no HDMI output, and the CAPS or NUM lock keys don't do anything


Looking at the crochet-setup.sh I also downloaded, it creates a partition layout on the disk and then writes the itb and bin files to it.

So I did the following:

Code:
gpart create -s gpt /dev/mmcsd0
gpart add -t linux-data -l loader -b 32k -s 16320 /dev/mmcsd0
gpart add -t linux-data -l uboot -s 8m /dev/mmcsd0
gpart add -t linux-data -l env -s 16m /dev/mmcsd0
gpart add -t linux-data -l resource -s 16m /dev/mmcsd0
dd if=idblock.bin of=/dev/mmcsd0 conv=notrunc bs=512 seek=64
dd if=NANOPI-R5C_EFI.itb  of=/dev/mmcsd0 conv=notrunc bs=512 seek=20480

Unfortunately, I get exactly the same behaviour when I put the card into the NanoPi (although the partition table is not corrupt).

Please could someone give me some steps to get this working, or point me towards a guide?
 
but unfortunately gpart shows the partition table as corrupt:
This is because GPT is not at end of disk. Simply do gpart recover any time you are flashing images. The image is smaller than disk size and shows as corrupt because secondary GPT partition table is not where it should be. At end of disk. gpart recover handles that.

HDMI is only available via EDK2 booting on RK356x and greater. I have to guide no offer. I only use serial and ssh connections.
 
This was all I had to get bootsectors right. A file from Sleepwalkers site.

#!/bin/sh

# In FreeBSD

DISK_MD="md0"

UBOOT_DIR="roc-rk3566-pc"
UBOOT_BIN="idblock.bin"
UBOOT_PATH="/usr/local/share/edk2/${UBOOT_DIR}"

set -x

#
# Station-P2 uses EFI
#
station_partition_image ( ) {
gpart destroy -F ${DISK_MD}
gpart create -s GPT ${DISK_MD}
gpart add -t linux-data -l loader -b 32k -s 16320 ${DISK_MD}
gpart add -t linux-data -l uboot -s 8m ${DISK_MD}
gpart add -t linux-data -l env -s 16m ${DISK_MD}
gpart add -t efi -l efi -a 512k -b 16m -s 50m ${DISK_MD}
gpart add -t freebsd-swap -l swapfs -a 64k -s 1G ${DISK_MD}
gpart add -t freebsd-ufs -l rootfs -a 64k -s 1G ${DISK_MD}
}

station_uefi_write () {
echo "Installing EDK2 on ${DISK_MD}"
if [ -f ${UBOOT_PATH}/idblock.bin ] ; then
dd if=${UBOOT_PATH}/idblock.bin of=/dev/${DISK_MD} bs=512 seek=64 conv=notrunc
dd if=${UBOOT_PATH}/u-boot.itb of=/dev/${DISK_MD} bs=512 seek=20480 conv=notrunc
fi
}

# Insert SD card reader in to USB,
# uncomment next line an run
# station_partition_image
station_uefi_write
 
Just in case you have issues I will spell this out.
Most of his work had both an image file and the two individual files for flashing.
You only need one or the other.
For example:
ROCK-3A_EFI.img
ROCK-3A_EFI.itb
idblock.bin

So either flash the image file (no offset needed) or the two individual bootfiles with offsets.
dd if=${UBOOT_PATH}/idblock.bin of=/dev/${DISK_MD} bs=512 seek=64 conv=notrunc
dd if=${UBOOT_PATH}/u-boot.itb of=/dev/${DISK_MD} bs=512 seek=20480 conv=notrunc
 
When I was first using Sleepwalkers work I was leary. Seeing Linux partitions freaked me out. When I asked what they were about the response I got was it was built on Linux.
That really did not ease my feelings much. A weird unmountable partion on my setup.
Then I checked out the disks with gparted and noticed the disk labels. Ahhha. Its not malicious but just the way EDK2 builds things.
One partition is EDK2 environment settings and I can't remember the others. All valid partitions I believed. Similar to u-boot but partitions.
 
Phishfry thank you very much for all of the advice. I will need HDMI out because the Nano Pi is in a metal case, and there is no other computer close to where it will live, so serial is not an option. If I need to access the console, I can just take a portable HDMI display and a USB keyboard.

I downloaded the latest Tianocore EDK II release, but it doesn't seem to contain any binaries I can write to the SD card. Do you know if there are any pre-built binaries anywhere that I can use?
 
I have ported rk356x vop2 (frame bufferr) driver into evadot's drm subtree. its not yet finished (sometimes it [dead]locks but i get a videoconsole. ill post the source and building instructions later in the week.
in theory it should work on 35[78]x too but those may use an unsupported version of hdmi chipset.
if i find out wtf is the problem with panfrost (i suspect something with atf or rk tpl) then we we'll have 3d tioo
 
I'm a little confused, because if the U-Boot version used by the Linux distros works with HDMI, then why can't we just use that to boot FreeBSD? It worked fine for my Orange Pi R1 Plus a few years ago using these instructions (although not all of the hardware was supported), although I can't get it to work with the NanoPi R5C, possibly because the latest Armbian .deb file does not contain trust.bin.

covacat that would be great - thanks very much! :)
 
Phishfry I thought I would make a start using your instructions, as I can always replace the boot loader later. I wrote the NANOPI-R5C_EFI.img to the SD card, and did a gpart repair as you advised.

I then set up my USB to TTL adapter, and inserted the card and the USB stick with FreeBSD-14.3-RELEASE-arm64-aarch64-memstick.img into the NanoPi. Finally, I ran minicom, and powered up the NanoPi.

Unfortunately, however, I just see gibberish in minicom. Which settings do you use for it?

Also, should U-Boot see the USB stick, and boot? Or are there some extra steps?
 
Phishfry thank you, 1500000 works fine!

Unfortunately, I don't get a U-Boot command prompt, and it seems to freeze after this:

Code:
I/TC: Primary CPU initializing
I/TC: Primary CPU switching to normal world boot
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0xa00000
INFO:    SPSR = 0x3c9

I've attached the full output in case it helps.
 

Attachments

Phishfry or anybody with a serial console
can you test this at the u-boot prompt on a rk356x board ?
md 0xfde60000 1 (this is panfrost mmio base address)
tell me if it panics or hangs and if it not the board model and ROCKCHIP_TPL and BL31 versions
 
pollito_cpc

If you can use U-Boot instead of EDK2 I suggest you create your own port. A slave port for u-boot.

You see there is NanoPi-5S in ports tree but you have NanoPi-5C.

But you can morph that into your own port. Use it as a guide. I am sure the nanopi5c has a "defconfig" file in u-boot.

That is all it takes to make a slave port. Two files. A makefile and a file for the package system.


mkdir /usr/ports/sysutils/u-boot-nanopi-5c
cd /usr/ports/sysutils/u-boot-nanopi-5c

Use a text editor and create: /usr/ports/sysutils/u-boot-nanopi-5c/Makefile
ee Makefile
Code:
MASTERDIR=      ${.CURDIR}/../u-boot-master

MODEL=          nanopi-r5c
BOARD_CONFIG=   nanopi-r5c-rk3568_defconfig
FAMILY=         rk356X

.include "${MASTERDIR}/Makefile"

Here is your package description file. Created in the same directory.

ee pkg-descr
Code:
U-Boot loader and related files for the FriendlyARM NanoPi-R5C

To install this bootloader on an sdcard just do:

dd if=/usr/local/share/u-boot/u-boot-nanopi-r5s/idbloader.img of=/path/to/sdcarddevice seek=64 bs=512 conv=sync
dd if=/usr/local/share/u-boot/u-boot-nanopi-r5s/u-boot.itb of=/path/to/sdcarddevice seek=16384 bs=512 conv=sync

So that is all it takes to build your slave port for NanoPi-5C

Now you can build it with:

make install

You can use packages for the build to save time and remain on a package based system.

make build-depends-list | cut -c 12- | xargs pkg install -A -y


Give it a few minutes and you will have a custom u-boot port.

The finish package gets installed in /usr/local/share/u-boot/u-boot-nanopi-5c/

You should notice the instructions inside pkg-descr which you created.
 
covacat No crash see below for response.

RK3566 Zero3E

Code:
=> md 0xfde60000 1
00000000: 14000001                             ....

From packages:
Code:
=> version
U-Boot 2025.04 (Apr 27 2025 - 23:50:27 +0000)

aarch64-none-elf-gcc (FreeBSD Ports Collection for aarch64noneelf) 11.3.0
GNU ld (GNU Binutils) 2.44

Code:
NOTICE:  BL31: v2.3():v2.3-645-g8cea6ab0b:cl, fwver: v1.44
NOTICE:  BL31: Built : 16:36:43, Sep 19 2023

I can't seem to find a TPL version or ATF..

Code:
U-Boot SPL 2025.04 (Apr 27 2025 - 23:50:27 +0000)
Trying to boot from MMC2
## Checking hash(es) for config config-2 ... OK
## Checking hash(es) for Image atf-1 ... sha256+ OK
## Checking hash(es) for Image u-boot ... sha256+ OK
## Checking hash(es) for Image fdt-2 ... sha256+ OK
## Checking hash(es) for Image atf-2 ... sha256+ OK
## Checking hash(es) for Image atf-3 ... sha256+ OK
## Checking hash(es) for Image atf-4 ... sha256+ OK
## Checking hash(es) for Image atf-5 ... sha256+ OK
## Checking hash(es) for Image atf-6 ... sha256+ OK
INFO:    Preloader serial: 2
NOTICE:  BL31: v2.3():v2.3-645-g8cea6ab0b:cl, fwver: v1.44
NOTICE:  BL31: Built : 16:36:43, Sep 19 2023
INFO:    GICv3 without legacy support detected.
INFO:    ARM GICv3 driver initialized in EL3
INFO:    pmu v1 is valid 220114
INFO:    l3 cache partition cfg-0
INFO:    dfs DDR fsp_param[0].freq_mhz= 1056MHz
INFO:    dfs DDR fsp_param[1].freq_mhz= 324MHz
INFO:    dfs DDR fsp_param[2].freq_mhz= 528MHz
INFO:    dfs DDR fsp_param[3].freq_mhz= 780MHz
INFO:    Using opteed sec cpu_context!
INFO:    boot cpu mask: 0
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 = 0xa00000
INFO:    SPSR = 0x3c9


U-Boot 2025.04 (Apr 27 2025 - 23:50:27 +0000)

Model: Radxa ZERO 3E
SoC:   RK3566T
DRAM:  1 GiB (effective 1022 MiB)
PMIC:  RK817 (on=0x40, off=0x00)
Core:  285 devices, 29 uclasses, devicetree: separate
MMC:   mmc@fe2b0000: 1
Loading Environment from nowhere... OK
In:    serial@fe660000
Out:   serial@fe660000
Err:   serial@fe660000
Model: Radxa ZERO 3E
SoC:   RK3566T
Net:   eth0: ethernet@fe010000
Hit any key to stop autoboot:  0
 
pollito_cpc

Once you have a solid u-boot to work from you must decide which FreeBSD version to use.

For RK3568 there is a PCIe bus issue and there is a patch for -CURRENT contained in a PR.
It could be committed by now I have not looked.

But some of the Ethernet interfaces hang off PCIe bus so you may need to patch.
The issue is there are two PCIe buses used on some RK3568 and depending on devices you need them both.

So my best guess you have Realtek-Kmod interfaces and EQOS interface(s). Realtek-Kmod will hang off PCIe bus. EQOS off system bus and OK.
You may be fine with the ethernet interfaces but find the M.2 slot does not work or vice-versa. You need to test.

So you have SOS's image from above in this thread. 14-STABLE to test with.

You may need a patched -CURRENT for all interfaces.

Build u-boot and test from there.

Note:Realtek-Kmod is my slang for a driver in ports for Realtek Interfaces. These are not built into the OS so you need to install it and load the Kernel Module.
net/realtek-re-kmod
net/realtek-re-kmod198
 
i fixed a dwhdmi driver bug so now the dead[lock] seems to be gone

it seems that panfrost requires rockchip power domains implemented :( to work on rk35xx
otherwise the kernel bombs when accessing gpu's register space
yet another 1.5k lines of linux driver to port :(
fortunately there is a power-domains generic implementation framework on https://reviews.freebsd.org/ which will make stuff somewhat easier
id fscking drove me nuts to find this out (and still not 100% sure this is the solution but looks like it)
 
pollito_cpc

I was looking at the NanoPi-5C and it appears the two ethenet interfaces do hang off the PCIe Bus.
As noted earlier RK3568 has two PCIe buses and without the noted patch for -CURRENT only one PCIe bus works. Which PCIe bus it is I dunno.
You could find both interfaces work but M.2 slot does not recognize devices or vice-versa. M.2 slot recognizes device but ethernet does not work.

I would like to hear your results and offer any help needed.
 
bragging time
Code:
root@:/ # dmesg|egrep "vop|panfros|drm"
rk_drm0: <Rockchip Display Subsystem> on ofwbus0
rk_vop20: <Rockchip RK35xx Visual Output Processor> mem 0xfe040000-0xfe042fff,0xfe044000-0xfe044fff irq 29 on ofwbus0
rk_vop20: VOP2 version: 40158023
panfrost0: <Mali Midgard/Bifrost GPU> mem 0xfde60000-0xfde63fff irq 19,20,21 on ofwbus0
panfrost0: Mali GPU clock rate 594000000 Hz
panfrost0: Mali GPU bus clock rate 500000000 Hz
rk_drm0: port found
rk_vop20: Selected port 48
rk_vop20: vop2_create_crtcs: No remote for vp1
rk_vop20: vop2_create_crtcs: No remote for vp2
[drm] Connector HDMI-A-1: get mode from tunables:
[drm]   - kern.vt.fb.modes.HDMI-A-1
[drm]   - kern.vt.fb.default_mode
[drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[drm] Initialized rockchip 1.0.0 20201113 for rk_drm on minor 0
panfrost0: GPU revision 1000, id 7402
panfrost0: Mali 7402, major 1, minor 0, status 0
panfrost0: Features: L2 7110206, Shader 2, Tiler 209, Mem 1, MMU 2823, AS ff, JS 7
panfrost0: panfrost_gpu_intr: pending 600
panfrost0: panfrost_gpu_intr: pending 600
panfrost0: panfrost_gpu_intr: pending 600
panfrost0: GPU is powered on
panfrost0: panfrost_gpu_intr: pending 20000
[drm] Initialized panfrost 1.2.0 20201124 for panfrost on minor 1
rk_vop20: Update mode to 1920x1080p60, type: 0 for vp0 0xffffa000023f0c60
 
1751027306029.png
 
Back
Top