Re: Would FreeBSD run on an Orange Pi Zero 2 (Allwinner H616)

From: Dr. Rolf Jansen <freebsd-rj_at_cyclaero.com>
Date: Mon, 10 Apr 2023 00:27:46 UTC
> Am 23.03.2023 um 11:06 schrieb Dr. Rolf Jansen <freebsd-rj@cyclaero.com>:
> 
> Hello,
> 
> For a new project I bought an Orange Pi Zero 2, is it worth trying FreeBSD with it. I don’t need graphics and wireless, only ethernet.
> 
> http://www.orangepi.org/orangepiwiki/index.php/Orange_Pi_Zero_2
> 
> Any insights would be appreciated.
> 
> 
>> Anfang der weitergeleiteten Nachricht:
>> 
>> Von: Daniel Engberg <daniel.engberg.lists@pyret.net>
>> Betreff: Would FreeBSD run on an Orange Pi Zero 2 (Allwinner H616)
>> Datum: 25. März 2023 um 16:48:38 GMT-3
>> An: rj@obsigna.com
>> 
>> Hi,
>> 
>> Not subscribed but probably not as only some parts of H6 are supported and H616 is the next revsion (https://wiki.freebsd.org/arm/Allwinner#arm.2FAllwinner.2FH6.H6_Supported_Boards).
>> According to https://linux-sunxi.org/Xunlong_Orange_Pi_Zero2 there's a build target for your board and you also need to attach the correct dts file to the kernel and see how far it boots.
>> 
>> You need to create a port for u-boot and modify the Makefile in src so the kernel includes device tree for your SBC.
>> 
>> https://cgit.freebsd.org/src/tree/sys/modules/dtb/allwinner/Makefile
>> https://cgit.freebsd.org/ports/tree/sysutils/u-boot-orangepi-pc2/Makefile (you can use that as a template)
>> 
>> https://cgit.freebsd.org/src/tree/sys/contrib/device-tree/src/arm64/allwinner/sun50i-h616-orangepi-zero2.dts

My Orange Pi Zero 2 arrived, and I built an u-boot port for it following Daniels’s suggestions, however, quite possible I missed the one or the other point.

I built it on a RPi4B running FreeBSD 14-CURRENT (2023-03-30).

I added to /usr/src/sys/modules/dtb/allwinner/Makefile a line for the DTS file of the Orange Pi Zero 2 (before I checked that it exists - it does):

   DTS=    \
           allwinner/sun50i-a64-nanopi-a64.dts \
   ...
   ...
           allwinner/sun50i-h6-pine-h64-model-b.dts \
           allwinner/sun50i-h616-orangepi-zero2.dts
   ...

Then I started make in that directory and copied the generated sun50i-h616-orangepi-zero2.dtb to /boot/dtb/allwinner - perhaps this is not necessary, but it shouldn’t harm either.

I created a ports directory systutils/u-boot-orangepi-zero2 and I modified the Makefile to:

   MASTERDIR=	${.CURDIR}/../u-boot-master

   MODEL=		orangepi-zero2
   BOARD_CONFIG=	orangepi_zero2_defconfig
   FAMILY=		allwinner64
   SUBFAMILY=		h616

   .include "${MASTERDIR}/Makefile“

In that directory, I executed make install clean, and it went through without hickup.

Now my Orange Pi Zero 2 boots well from a SD card with Debian 3.0.6 Bullseye with Linux 5.16.17-sun50iw9. That SD card is a MBR one, and therefore I created a new one by which I replaced the linux-data partition by a freebsd one having one freebsd-ufs slice.

The partition scheme of the Linux uSD card:

   =>      63  31116225  da2  MBR  (15G)
           63      8129       - free -  (4.0M)
         8192  30793728    1  linux-data  (15G)
     30801920    314368       - free -  (154M)

The partition scheme of the FreeBSD uSD card:

   =>      63  15523777  da1  MBR  (7.4G)
           63      8066       - free -  (3.9M)
         8129  15515711    1  freebsd  (7.4G)

   =>       0  15515711  da1s1  BSD  (7.4G)
            0  15515711      1  freebsd-ufs  (7.4G)

/dev/da1s1s contains a complete FreeBSD 14-CURRENT-aarch64 installation which I cloned from the respective root slice of my running RPi4B. Then I put sun50i-h616-orangepi-zero2.dtb into /boot/dtb/allwinner, and I dd’ed my new u-boot port to the SD card:

   dd if=/usr/local/share/u-boot/u-boot-orangepi-zero2/u-boot-sunxi-with-spl.bin of=/dev/da1 bs=128k seek=1 conv=sync

I started the Orange Pi Zero 2 from the newly created uSD card and the serial console shows me:

   U-Boot SPL 2021.10-orangepi (Aug 09 2022 - 21:00:00 +0800)
   DRAM: 1024 MiB
   Trying to boot from MMC1
   mmc_load_image_raw_sector: mmc block read error
   SPL: failed to boot from all boot devices
   ### ERROR ### Please RESET the board ###

U-Boot SPL 2021.10-orangepi is not the one which I built (2023.01). May it be that the Orange Pi comes with an U-Boot somewhere on-board?

Does anybody have ideas any ideas on how to proceed?

Best regards

Rolf