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

I'm also trying to get FreeBSD working on a RK35xx board, the Orange Pi 3B. Which uses RK3566, I pretty new to this, so I must confess I'm a little bit lost. I'd like to build an image that wouldn't require users to flash a new bootloader, so I'm trying to get this working with the onboard U-Boot bootloader. I've chose this board because it's a very cheap one and I could by from local resellers, I can in fact easily afford more expensive boards, but I wanted to have more people involved on this without the price barrier.

I'll try to register my progress on this thread. My goal is to have pfSense + WiFi working on this board, so this will probably be very difficult, but it should be very fun as well.
https://forums.freebsd.org/threads/raspberry-pi-5-status.91406/post-645892
renatoalencar, do you use JTAG and GDB to debug your Orange Pi 3B RK3566 board bring up? Flirc Jeff probe is a $16 USD or 15 EU$ 2 serial channel that provides a console port and a JTAG OpenOCD interface. What do you use? What JAG probes are you interested in? Can you share your thoughts?

I really want to see this inexpensive Arm64 Quad Core A55 running desktop FreeBSD or GhostBSD so that others have a chance for a first computer running FreeBSD / GhostBSD, like the old Commodore C64 was 40 years ago. Connected to a family TV for a Display Monitor and Sound , have a keyboard and mouse to allow for creativity and building. ( Tablets and Cellphones are for consuming media , not creating digital assets ie, spread sheets, CAD Computer Aided Design Files, Editing Video, Inkspace creating digital pictures). So, I applaud your efforts and encourage you to continue.

https://ghostbsd-arm64.blogspot.com/2023/12/how-to-install-ghostbsd-arm64-into-usb.html#more How to install GhostBSD-Arm64 into a USB SSD drive.
https://ghostbsd-arm64.blogspot.com/2024/01/january-19-2024-howto-download.html
Download FreeBSD 14.0-RELEASE image to write into a USB Flash drive stick or
Download GhostBSD-Arm64 image to write into a USB Flash drive stick.
 
i used u-boot from https://github.com/Kwiboo/u-boot-rockchip
just add CONFIG_EFI_LOADER=y to configs/orangepi-3b-rk3566_defconfig and it worked
i have a lot of hacks for this board most of the stuff is posted in the
https://forums.freebsd.org/threads/running-freebsd-on-radxa-rock-3c-rk3566-board.89389 thread
I've made this changes to the Orange Pi's U-Boot tree and could get it to work:

Code:
diff --git a/Makefile b/Makefile
index 590fd4c1f..f7f1309d2 100644
--- a/Makefile
+++ b/Makefile
@@ -360,7 +360,7 @@ KBUILD_CPPFLAGS := -D__KERNEL__ -D__UBOOT__
 KBUILD_CFLAGS   := -Wall -Wstrict-prototypes \
            -Wno-format-security \
            -fno-builtin -ffreestanding
-KBUILD_CFLAGS    += -fshort-wchar -Werror
+KBUILD_CFLAGS    += -fshort-wchar
 KBUILD_AFLAGS   := -D__ASSEMBLY__

 # Read UBOOTRELEASE from include/config/uboot.release (if it exists)
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index 7d0a9aa2f..91b2f7060 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -1040,7 +1040,7 @@ void board_quiesce_devices(void *images)

     /* relocate kernel after decompress cleanup */
     kernel_addr = env_get_ulong("kernel_addr_r", 16, 0);
-    if (kernel_addr != bootm_images->ep) {
+    if (bootm_images != NULL && kernel_addr != bootm_images->ep) {
         memmove((char *)bootm_images->ep, (const char *)kernel_addr,
             bootm_images->os.image_len);
         printf("== DO RELOCATE == Kernel from 0x%08lx to 0x%08lx\n",
diff --git a/common/main.c b/common/main.c
index 6a1159879..b14cc903e 100644
--- a/common/main.c
+++ b/common/main.c
@@ -63,6 +63,7 @@ void main_loop(void)
     if (cli_process_fdt(&s))
         cli_secure_boot_cmd(s);

+    run_command("fdt chosen; fdt set /aliases mmc0 \"/sdhci@fe310000\";", 0);
     autoboot_command(s);

     cli_loop();
diff --git a/configs/orangepi-3b-rk3566_defconfig b/configs/orangepi-3b-rk3566_defconfig
index 4b5eed949..9eece0bbd 100644
--- a/configs/orangepi-3b-rk3566_defconfig
+++ b/configs/orangepi-3b-rk3566_defconfig
@@ -211,7 +211,7 @@ CONFIG_LZ4=y
 CONFIG_LZMA=y
 CONFIG_SPL_GZIP=y
 CONFIG_ERRNO_STR=y
-# CONFIG_EFI_LOADER is not set
+CONFIG_EFI_LOADER=y
 CONFIG_AVB_LIBAVB=y
 CONFIG_AVB_LIBAVB_AB=y
 CONFIG_AVB_LIBAVB_ATX=y
diff --git a/make.sh b/make.sh
index 233bc9aa3..9978a2d7a 100755
--- a/make.sh
+++ b/make.sh
@@ -13,7 +13,8 @@ CMD_ARGS=$1
 ########################################### User can modify #############################################
 RKBIN_TOOLS=../rkbin/tools
 CROSS_COMPILE_ARM32=../prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
-CROSS_COMPILE_ARM64=../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
+#CROSS_COMPILE_ARM64=../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
+CROSS_COMPILE_ARM64=/sbin/aarch64-linux-gnu-
 ########################################### User not touch #############################################
 # Declare global INI file searching index name for every chip, update in select_chip_info()
 RKCHIP=

Only setting CONFIG_EFI_LOADER and making a small tweak for it to work.

I've also used the Quartz64 Model A device tree and changed the clocks and reset settings for the GMAC interface and got Ethernet working. I've been trying to fix some issues with the eqos driver (proper initialization and auto negotiation issues), got some progress, although at a slow pace.

I'm using the -CURRENT image, and I just need to load the
/boot/dtb/rockchip/rk3566-quartz64-a.dtb
device tree at first boot to get serial working. It's actually being easier than I thought initially, besides the networking stuff.

GMAC Device Tree:

Code:
&gmac1 {
        assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;
        assigned-clock-parents = <&cru SCLK_GMAC1_RGMII_SPEED>, <&cru CLK_MAC1_2TOP>;
        assigned-clock-rates = <0>, <125000000>;
        clock_in_out = "input";
        phy-supply = <&vcc_3v3>;
        phy-mode = "rgmii";
        pinctrl-names = "default";
        pinctrl-0 = <&gmac1m0_miim
                     &gmac1m0_tx_bus2
                     &gmac1m0_rx_bus2
                     &gmac1m0_rgmii_clk
                     &gmac1m0_clkinout
                     &gmac1m0_rgmii_bus>;
        snps,reset-gpio = <&gpio3 RK_PC2 GPIO_ACTIVE_LOW>;
        snps,reset-active-low;
        /* Reset time is 20ms, 100ms for rtl8211f */
        snps,reset-delays-us = <0 50000 200000>;
        tx_delay = <0x30>;
        rx_delay = <0x10>;
        phy-handle = <&rgmii_phy1>;
        status = "okay";
};
 
https://forums.freebsd.org/threads/raspberry-pi-5-status.91406/post-645892
renatoalencar, do you use JTAG and GDB to debug your Orange Pi 3B RK3566 board bring up? Flirc Jeff probe is a $16 USD or 15 EU$ 2 serial channel that provides a console port and a JTAG OpenOCD interface. What do you use? What JAG probes are you interested in? Can you share your thoughts?

I really want to see this inexpensive Arm64 Quad Core A55 running desktop FreeBSD or GhostBSD so that others have a chance for a first computer running FreeBSD / GhostBSD, like the old Commodore C64 was 40 years ago. Connected to a family TV for a Display Monitor and Sound , have a keyboard and mouse to allow for creativity and building. ( Tablets and Cellphones are for consuming media , not creating digital assets ie, spread sheets, CAD Computer Aided Design Files, Editing Video, Inkspace creating digital pictures). So, I applaud your efforts and encourage you to continue.

https://ghostbsd-arm64.blogspot.com/2023/12/how-to-install-ghostbsd-arm64-into-usb.html#more How to install GhostBSD-Arm64 into a USB SSD drive.
https://ghostbsd-arm64.blogspot.com/2024/01/january-19-2024-howto-download.html
Download FreeBSD 14.0-RELEASE image to write into a USB Flash drive stick or
Download GhostBSD-Arm64 image to write into a USB Flash drive stick.
I didn't try to use JTAG on this one, I need to find one and see it works with this board, looks like the SD card connection shares some pin with the JTAG interface, which may interfere with each other.

Looks like I need USB and HDMI working for this, so I'll try to do that later. I believe things should be partially in place for this.
 
Managed to get my Rock5B booting 14.1-RELEASE (from the aarch64 memstick image) thanks to EDK2-rk3588.

Things that are working:
  • onboard ethernet works great after installing net/realtek-re-kmod from ports and then adding
    Code:
    if_re_load="YES"
    if_re_name="/boot/modules/if_re.ko"
    to /boot/loader.conf.
  • onboard USB has worked with every device I've tried so far (some keyboards and USB3 disks), on both the USB2 and USB3 ports
  • my ASM1166-based M.2-to-SATA3 6-port adapter on the backside of the board is detected and seems to be stable so far
  • HDMI output at 1080p60 seems fairly stable

Performance seems… not great? powerd errors out on startup with
Code:
powerd: no cpufreq(4) support -- aborting: No such file or directory
so it looks like there's no support for dynamically adjusting CPU frequency/voltage.

And I think EDK2 is defaulting me to the slowest speeds on all cores.
Updated CPU speeds in UEFI settings, and now everything feels much snappier.

I tried to build a DTB for the Rock 5B from /usr/src/sys/contrib/device-tree/src/arm64/rockchip/rk3588-rock-5b.dts, but sudo dtc -o rock5b.dtb rk3588-rock-5b.dts errors out with
Code:
Error at rk3588-rock-5b.dts:35:24: Expected numbers in array of cells
    hp-det-gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
                          ^
Error at rk3588-rock-5b.dts:35:24: Expected ; at end of property
    hp-det-gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
                          ^
Error at rk3588-rock-5b.dts:35:24: Failed to find root node /.
    hp-det-gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
                          ^
Failed to parse tree.
Before I start hacking it up, does anybody here already have a working .dts file for the Rock 5B they can share?


Never mind, see followup below :)
 

SleepWalker has an image you can try the DTS from.
Thanks for the hint! Since my forum account is new I've got to wait for moderator approval on my messages for a bit yet, but I figured out that I was doing it wrong last night and managed to generate a DTB file myself between when I posted and now. The DTB I built seems to be working (serial console works properly now!)

I would attach it here but apparently that's not gonna work, so instead I'll just copy/paste from my terminal session. Thanks again Phishfry, your post over in another thread got me most of the way there.

Code:
> cd /usr/src/sys/contrib/device-tree

> export MACHINE=arm64

> export DTC=/usr/bin/dtc

> /usr/src/sys/tools/fdt/make_dtb.sh \
    /usr/src/sys \
    src/arm64/rockchip/rk3588-rock-5b.dts \
    /tmp

> sudo cp /tmp/rk3588-rock-5b.dtb /boot/dtb/rockchip

> cat >>/boot/loader.conf<<END
dtbfile_load="YES"
dtbfile_type="dtb"
dtbfile_name="/boot/dtb/rockchip/rk3588-rock-5b.dtb"
END

And now that I've got that working, I've generated DTBs for a whole bunch of other SBCs I have here (Rock64, RockPro64, Rock Pi 4A, Quartz64B…). Wonder why FreeBSD didn't ship most of these DTBs in the 14.1 release.
 
Wonder why FreeBSD didn't ship most of these DTBs in the 14.1 release.
Build u-boot from ports and it builds DTB for you for the whole class CPU..
For example build port for sysutils/u-boot-rockpro64 and it will build all RK3399 from uboots gnu dts tree.
Code:
  find /usr/ports/sysutils/u-boot-rock-pi-4c/work/ -name "*.dtb"
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-evb.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-eaidk-610.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-ficus.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-firefly.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-gru-bob.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-orangepi.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-gru-kevin.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-khadas-edge.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-khadas-edge-captain.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-khadas-edge-v.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-leez-p710.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopi-m4.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopc-t4.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopi-m4-2gb.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopi-m4b.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopi-r4s.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-nanopi-neo4.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-pinebook-pro.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-pinephone-pro.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-puma-haikou.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-roc-pc.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-roc-pc-mezzanine.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-rock-4c-plus.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-rock-pi-4a.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-rock-pi-4c.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-rock960.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399-rockpro64.dtb
/usr/ports/sysutils/u-boot-rock-pi-4c/work/u-boot-2023.07/arch/arm/dts/rk3399pro-rock-pi-n10.dtb

FreeBSD uses a master/slave port arrangement for u-boot and you can make your own board ports easily that way.
The above is my clone from uboot-rock -pi-4
 
Once you guys have this hashed out, may I request a simple howto? I'd like to get the 16GB RK3588S over the 8GB PI 5, but I'd like to confirm that it's straightforward to install and get running. My use-case would be headless.
 
Once you guys have this hashed out, may I request a simple howto?
Me too..

just kidding. What you need to do is watch u-boot releases and when it supports RK3588 you can try.

In my case I have been waiting for Rock3A && Rock3C support in our ports tree for u-boot..

As you can see above I was using a July 2023 branch.
I updated my ports tree to see what new has come and I see a NanoPi-R4S and NanoPi-R5S port.
That has the RK3568 support I needed. sysutils/u-boot-nanopi-r4s

So now I can clone that port into a customized Rock3A port that builds I hope. Change defconfig to Rock3A.
Last year I tried to force it when it first hit u-boot tree and there were errors. A little too new.
Now that we have a RK3568 port I should have better luck.
Now in saying that I am unsure the RK3568 PCIe bus is supported in FreeBSD. I hope to get some other RK3568 boards up now.
With MerryIOT miner I got stuck because of u-boot.
 
Is FreeBSD 13 or 14 likely to boot on a Radxa E20C (RK3328)? I can't tell if the dual ethernet E20C is an older and obscure board that never really took off, or it's brand new.

Also, can the kernel be built and installed on-device, or does it need to be cross-compiled?

The planned use - basic NAT - can probably be done easily with whatever Linux Radxa supplies, but I'd rather use FreeBSD.

Thanks!
 
Is FreeBSD 13 or 14 likely to boot on a Radxa E20C (RK3328)?
This is the same CPU that Rock64 uses so you start with that FreeBSD image and change the dtb to suit your board.

Now that I look at the question I see you might be incorrect about Rockchip CPU used.

RK3528A

That might be a problem.
You would need to build a FreeBSD u-boot for it. I would start with something RK356x based and see what dtb's it builds.
Raxda seems slow to support official u-boot and they use real old branches.
 
Now that I look at the question I see you might be incorrect about Rockchip CPU used.
Thanks for catching my error with the SoC identifier.

Would a Nanopi R2S (RK3328 - double checked that!) be a better option?


I note there's a file rk3328-nanopi-r2s.dts present in the 14.x sources.
 
Thanks for catching my error with the SoC identifier.

Would a Nanopi R2S (RK3328 - double checked that!) be a better option?


I note there's a file rk3328-nanopi-r2s.dts present in the 14.x sources.
After finding a page dedicted to FreeBSD on R2S, I decided to buy one, but perhaps I should have checked further first... today I find the file (FreeBSD-aarch64-13.0-RELEASE-p8-NanoPi-R2S-20220316.img.xz) no longer exists on personalbsd.org, or another mirror.

Is that image still available somewhere? Or does rk3328-nanopi-r2s.dts in the 14.x sources mean that FreeBSD directly supports it?

Edit: I just realised I'm repeating my previous error. This thread is for a 35xx SoC, whilst I have 33xx. Sorry peeps.
 
Has anyone gotten the atheros wifi adapter to work with the rk3568? BPI-R2-PRO is a mini pcie slot. At the moment I have a RTL8188CE wifi card working there, but it's 2.4GHz and 802.11n works with minor problems. Speed is about 15 - 30 Mbit/s. I have an I210 Gigabit Fiber card in the M2 slot. I can't use the wifi card there. The option is to use a USB wifi adapter, but I don't like it at the moment. AR928X card test speed was about 100Mbit/s and it is good enough for me. I would like to get this card working on the BPI-R2-PRO router. If anyone has experience getting an atheros wifi card with rk3568 to work, please share your experience.

I got the other cards to work when I removed the current rk3568.dtsi and rk356x.dtsi from the pcie section in strict last line.

Code:
diff --git a/sys/contrib/device-tree/src/arm64/rockchip/rk3568.dtsi b/sys/contrib/device-tree/src/arm64/rockchip/rk3568.dtsi
index f1be76a54ceb..da7b5eb74182 100644
--- a/sys/contrib/device-tree/src/arm64/rockchip/rk3568.dtsi
+++ b/sys/contrib/device-tree/src/arm64/rockchip/rk3568.dtsi
@@ -96,8 +96,8 @@
                      <0x0 0xfe270000 0x0 0x00010000>,
                      <0x0 0xf2000000 0x0 0x00100000>;
                ranges = <0x01000000 0x0 0xf2100000 0x0 0xf2100000 0x0 0x00100000>,
-                        <0x02000000 0x0 0xf2200000 0x0 0xf2200000 0x0 0x01e00000>,
-                        <0x03000000 0x0 0x40000000 0x3 0x40000000 0x0 0x40000000>;
+                        <0x02000000 0x0 0xf2200000 0x0 0xf2200000 0x0 0x01e00000>;
+               //       <0x03000000 0x0 0x40000000 0x3 0x40000000 0x0 0x40000000>;
                reg-names = "dbi", "apb", "config";
                resets = <&cru SRST_PCIE30X1_POWERUP>;
                reset-names = "pipe";
@@ -149,8 +149,8 @@
                      <0x0 0xfe280000 0x0 0x00010000>,
                      <0x0 0xf0000000 0x0 0x00100000>;
                ranges = <0x01000000 0x0 0xf0100000 0x0 0xf0100000 0x0 0x00100000>,
-                        <0x02000000 0x0 0xf0200000 0x0 0xf0200000 0x0 0x01e00000>,
-                        <0x03000000 0x0 0x40000000 0x3 0x80000000 0x0 0x40000000>;
+                        <0x02000000 0x0 0xf0200000 0x0 0xf0200000 0x0 0x01e00000>;
+               //       <0x03000000 0x0 0x40000000 0x3 0x80000000 0x0 0x40000000>;
                reg-names = "dbi", "apb", "config";
                resets = <&cru SRST_PCIE30X2_POWERUP>;
                reset-names = "pipe";
diff --git a/sys/contrib/device-tree/src/arm64/rockchip/rk356x.dtsi b/sys/contrib/device-tree/src/arm64/rockchip/rk356x.dtsi
index 61680c7ac489..7a3c97145dc9 100644
--- a/sys/contrib/device-tree/src/arm64/rockchip/rk356x.dtsi
+++ b/sys/contrib/device-tree/src/arm64/rockchip/rk356x.dtsi
@@ -983,8 +983,8 @@
                phy-names = "pcie-phy";
                power-domains = <&power RK3568_PD_PIPE>;
                ranges = <0x01000000 0x0 0xf4100000 0x0 0xf4100000 0x0 0x00100000>,
-                        <0x02000000 0x0 0xf4200000 0x0 0xf4200000 0x0 0x01e00000>,
-                        <0x03000000 0x0 0x40000000 0x3 0x00000000 0x0 0x40000000>;
+                        <0x02000000 0x0 0xf4200000 0x0 0xf4200000 0x0 0x01e00000>;
+               //       <0x03000000 0x0 0x40000000 0x3 0x00000000 0x0 0x40000000>;
                resets = <&cru SRST_PCIE20_POWERUP>;
                reset-names = "pipe";
                #address-cells = <3>;

But when loading the atheros card I get an error message.

Code:
 [ath_hal] loaded
[ar5210] loaded
[ar5211] loaded
[ar5212] loaded
[ar5416] loaded
[ar9300] loaded
[ath_rate] loaded
[ath_dfs] loaded
pci0: driver added
pci1: driver added
pci2: driver added
pci3: driver added
found->    vendor=0x168c, dev=0x002a, revid=0x01
    domain=2, bus=1, slot=0, func=0
    class=02-80-00, hdrtype=0x00, mfdev=0
    cmdreg=0x0000, statreg=0x0010, cachelnsz=0 (dwords)
    lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
    intpin=a, irq=255
    powerspec 2  supports D0 D1 D3  current D0
    MSI supports 1 metssage
    MSI-X supports 1 message in map 0x10
pci2:1:0:0: reprobing on driver added
ath0: <Atheros 9280> at device 0.0 on pci3
pcib3: allocated initial memory window of 0xf0200000-0xf02fffff
pcib3: allocated memory range (0xf0200000-0xf020ffff) for rid 10 of ath0
ath0: Lazy allocation of 0x10000 bytes rid 0x10 type 3 at 0xf0200000
ofw_pci mapdev: start f0200000, len 65536
pcib3: slot 0 INTA is routed to irq 102
ath0: could not map interrupt
device_attach: ath0 attach returned 6
[ath] loaded
 
I haven't had time to mess with my Rock3A RK3568 boards lately.

One thing I would check is different sources for your dtsi.

I see your patch is based on FreeBSD source and I dunno if I would use that.
/sys/contrib/device-tree/src/arm64/rockchip/rk356x.dtsi

I would compile a u-boot from ports tree for any RK3568 board.
(for example /usr/ports/sysutils/u-boot-nanopi-r5s/)
Then study the dtsi from u-boot source files and compare to FreeBSD source version.
 
OK Here is my Rock 3a slave u-boot port. It finally builds.

Create new directory:
mkdir /usr/ports/sysutils/u-boot-rock-3a
cd /usr/ports/sysutils/u-boot-rock-3a

Create the ports Makefile file under this new directory
Code:
MASTERDIR=    ${.CURDIR}/../u-boot-master

MODEL=        rock-3a
BOARD_CONFIG=    rock-3a-rk3568_defconfig
FAMILY=        rk356X

.include "${MASTERDIR}/Makefile"

Now create another file for the port. The package description file - pkg-desc
Code:
U-Boot loader and related files for the rock-3a.

To install this bootloader on an sdcard just do:
dd if=/usr/local/share/u-boot/u-boot-rock-3a/idbloader.img of=/path/to/sdcarddevice seek=64 bs=512 conv=sync
dd if=/usr/local/share/u-boot/u-boot-rock-3a/u-boot.itb of=/path/to/sdcarddevice seek=16384 bs=512 conv=sync

Now build it with make and let it eat.

The final output:

Code:
===>  Staging for u-boot-rock-3a-2024.04
===>   Generating temporary packing list
/bin/mkdir -p /usr/ports/sysutils/u-boot-rock-3a/work/stage//usr/local/share/u-boot/u-boot-rock-3a
install  -m 0644 /usr/ports/sysutils/u-boot-rock-3a/work/u-boot-2024.04/idbloader.img /usr/ports/sysutils/u-boot-rock-3a/work/stage//usr/local/share/u-boot/u-boot-rock-3a
install  -m 0644 /usr/ports/sysutils/u-boot-rock-3a/work/u-boot-2024.04/u-boot.itb /usr/ports/sysutils/u-boot-rock-3a/work/stage//usr/local/share/u-boot/u-boot-rock-3aarnge trip its be
install  -m 0644 /usr/ports/sysutils/u-boot-rock-3a/pkg-descr /usr/ports/sysutils/u-boot-rock-3a/work/stage//usr/local/share/u-boot/u-boot-rock-3a/README
====> Compressing man pages (compress-man)

Yipee. Now on to testing.

Scrape out the files needed for testing.

Here is the DTB from the u-boot ports build.
/usr/ports/sysutils/u-boot-rock-3a/work/u-boot-2024.04/arch/arm/dts/rk3568-rock-3a.dtb

Now notice all the other goodies it built. DTB's for other RK3568 too.

Raxda E25
Odroid M1
NanoPi 5S
NanoPi 5R
BPI-R2-PRO
SoQuartz
Quartz64

EVB and RK3568-Generic

So all these should at least boot on FreeBSD when you build a slave RK356X u-boot port. All you need is a defconfig file in u-boot.
 
Last edited:
Phishfry thanks a lot for the great example. I hope this helps many others. I found this solution a few weeks ago.

When I use u-boot for bpi-r2-pro, I have to manually enable vcc3v3_pcie every time.
Code:
BPI-R2PRO> regulator status
Name                 Enabled            uV         mA Mode       Status
vdd_logic            enabled        900000          - -          0
vdd_gpu              enabled        900000          - -          0
vcc_ddr              enabled        500000          - -          0
vdd_npu              disabled       900000          - -          0
vcc_1v8              enabled       1800000          - -          0
vdda0v9_image        enabled        900000          - -          0
vdda_0v9             enabled        900000          - -          0
vdda0v9_pmu          enabled        900000          - -          0
vccio_acodec         enabled       3300000          - -          0
vccio_sd             enabled       3300000          - -          0
vcc3v3_pmu           enabled       3300000          - -          0
vcca_1v8             enabled       1800000          - -          0
vcca1v8_pmu          enabled       1800000          - -          0
vcca1v8_image        enabled       1800000          - -          0
vcc_3v3              enabled       3300000          - -          0
vcc3v3_sd            enabled       3300000          - -          0
dc_12v               enabled      12000000          - -          0
vcc3v3_sys           enabled       3300000          - -          0
vcc5v0_sys           enabled       5000000          - -          0
pcie30_avdd0v9       enabled        900000          - -          0
pcie30_avdd1v8       enabled       1800000          - -          0
vcc3v3_pcie          disabled      3300000          - -          0
vcc3v3_minipcie      disabled      3300000          - -          0
vcc3v3_ngff          disabled      3300000          - -          0
vcc5v0_usb           enabled       5000000          - -          0
vcc5v0_usb_host      disabled      5000000          - -          0
vcc5v0_usb_otg       disabled      5000000          - -          0
BPI-R2PRO>
BPI-R2PRO> regulator dev vcc3v3_pcie
dev: vcc3v3_pcie @ vcc3v3-pi6c-05-regulator
BPI-R2PRO> regulator enable
BPI-R2PRO> regulator status
Regulator vcc3v3_pcie status:
 * enable:         1 (true)
 * value uV:       3300000
 * current uA:     No data available (err: -61)
 * mode id:        Function not implemented (err: -38)
BPI-R2PRO>
Code:
        /* pi6c pcie clock generator feeds both ports */
        vcc3v3_pi6c_05: vcc3v3-pi6c-05-regulator {
                compatible = "regulator-fixed";
                regulator-name = "vcc3v3_pcie";
                regulator-min-microvolt = <3300000>;
                regulator-max-microvolt = <3300000>;
                enable-active-high;
                gpios = <&gpio0 RK_PD4 GPIO_ACTIVE_HIGH>;
                startup-delay-us = <200000>;
                vin-supply = <&vcc5v0_sys>;
        };

&pcie30phy {
        data-lanes = <1 2>;
        phy-supply = <&vcc3v3_pi6c_05>;
        status = "okay";
};

In the freebsd code rk3568_pciephy.c today there is no handling of regulators and the system freezes during pcie initialization.
Maybe it is possible to save vcc3v3_pcie activation in u-boot conf file. Another option is to change the u-boot bpi-r2-pro.dts file and recompile it.

Today freebsd freezes when initializing I210 card with u-boot bpi-r2-pro.dtb.
If I remove this card, I get RX CRC errors on the CPU port of the mediatek switch.
That's why today I use UEFI-RK356x with fdt mode to boot the my device. I don't know what the UEFI loader eqos/mtswitch changes so that crcerrs don't occur with it.

I look forward to your results with the Rock 3A and the atheros card.
 
Well I got somewhere today on ROCK 3A. I had to switch to -CURRENT and that solved many problems.
Used -CURRENT image for rockpro64 and added my dtbs from u-boot to EFI partition and /boot/dtb/. Flashed u-boot to microSD.
I have an Atheros QNF222 M.2 module mounted on top.
It is found on bootup but no driver is loaded automatically because aarch64. So pciconf shows none0@.
To auto load the driver in /boot/loader.conf or load at command pronmpt with kldload if_ath.
Code:
if_ath_load="YES"
Then it shows up on boot ready to work.

I do have problems with it hanging on boot at PCI Express Bus.
When I go into u-boot command prompt and I do pci enum then boot it boots OK.

Code:
# pciconf -lv
pcib1@pci0:0:0:0:    class=0x060400 rev=0x01 hdr=0x01 vendor=0x1d87 device=0x3566 subvendor=0x0000 subdevice=0x0000
    vendor     = 'Rockchip Electronics Co., Ltd'
    device     = 'RK3568 Remote Signal Processor'
    class      = bridge
    subclass   = PCI-PCI
none0@pci0:1:0:0:    class=0x028000 rev=0x01 hdr=0x00 vendor=0x168c device=0x0034 subvendor=0x1028 subdevice=0x0300
    vendor     = 'Qualcomm Atheros'
    device     = 'AR9462 Wireless Network Adapter'
    class      = network
pcib3@pci2:0:0:0:    class=0x060400 rev=0x01 hdr=0x01 vendor=0x1d87 device=0x3566 subvendor=0x0000 subdevice=0x0000
    vendor     = 'Rockchip Electronics Co., Ltd'
    device     = 'RK3568 Remote Signal Processor'
    class      = bridge
    subclass   = PCI-PCI
 
I never did get the if_ath driver to attach.

I went into u-boot and enabled the regulator as well.

Code:
=> regulator dev vcc3v3_pcie
dev: vcc3v3_pcie @ vcc3v3-pcie-regulator
=> regulator enable
=> regulator status
Regulator vcc3v3_pcie status:
 * enable:         1 (true)
 * value uV:       3300000
 * current uA:     No data available (err: -61)
 * mode id:        Function not implemented (err: -38)
=> pci
=> pci enum
pcie_dw_rockchip pcie@fe280000: PCIe-2 Link Fail
 
Maybe it is possible to save vcc3v3_pcie activation in u-boot conf file. Another option is to change the u-boot bpi-r2-pro.dts file and recompile it.
Both of those sound possible.
A simple u-boot boot script can enable the 3v3 regulator. The commands from above will do what you need.

JohnnySorocil gave a good writeup here:

boot.cmd on your EFI/ESP partition.
Code:
regulator dev vcc3v3_pcie
regulator enable
pci
pci enum

mkimage -C none -A arm -T script -d /boot/efi/boot.cmd /boot/efi/boot.scr from sysutils/u-boot-tools.
You probably don't need the pci commands but they should not hurt. Maybe even add regulator status for onscreen confirmation.
 
Phishfry, you have done a great job. :)
Have you seen it attach driver with resistor setting?
Sorry, I don't understand the meaning of your question. Can you explain it in more detail.

This weekend I played a bit with my atheros and other cards. Sorry, maybe I've misunderstood the interrupt in the PCI standards. But it seems to me that Atheros driver only supports INTx interrupt. It seems that the RK3568 driver does not support INTx emulation. All my other cards I've tried have been msi/msi-x supported.

I got the idea to try adding a simple MSI support hack to the atheros driver. Now the driverses are attaced. I can scan very close channels. When I set up hostap mode, I can't see ssid on other devices. Apparently the radio is not working properly. I didn't try the client mode.
Git:
diff --git a/sys/dev/ath/if_ath_pci.c b/sys/dev/ath/if_ath_pci.c
index 72f0a802aa5f..1add5eda4314 100644
--- a/sys/dev/ath/if_ath_pci.c
+++ b/sys/dev/ath/if_ath_pci.c
@@ -212,12 +212,23 @@ ath_pci_attach(device_t dev)
        ATH_TX_LOCK_INIT(sc);
        ATH_TXSTATUS_LOCK_INIT(sc);

+       if (bootverbose) {
+               device_printf(dev, "MSI count : %d\n",  pci_msi_count(dev));
+               device_printf(dev, "MSI-X count : %d\n", pci_msix_count(dev));
+       }
+
        /*
         * Arrange interrupt line.
         */
-       rid = 0;
-       psc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
-                                            RF_SHAREABLE|RF_ACTIVE);
+       rid = 1;
+       if (pci_alloc_msi(dev, &rid) == 0)
+               rid = 1;
+       else
+               rid = 0;
+
+       psc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE |
+           (rid != 0 ? 0 : RF_SHAREABLE));
+
        if (psc->sc_irq == NULL) {
                device_printf(dev, "could not map interrupt\n");
                goto bad1;
@@ -323,6 +334,7 @@ ath_pci_detach(device_t dev)
        bus_generic_detach(dev);
        bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
        bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
+       pci_release_msi(dev);

        bus_dma_tag_destroy(sc->sc_dmat);
        bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);

Code:
ath0@pci2:1:0:0:        class=0x028000 rev=0x01 hdr=0x00 vendor=0x168c device=0x002a subvendor=0x168c subdevi0
    vendor     = 'Qualcomm Atheros'
    device     = 'AR928X Wireless Network Adapter (PCI-Express)'
    class      = network
 
Back
Top