Contents
- FreeBSD/ARM on the Bananapi family (R64/R2/R2-PRO/R3/R4)
FreeBSD/ARM on the Bananapi family (R64/R2/R2-PRO/R3/R4)
What is Bananapi-R64 Pi?
SoC: MediaTek MT7622 (Dual-core ARM Cortex-A53)
- RAM: 1GB DDR3
- Storage: microSD, eMMC
Network: 5x Gigabit Ethernet, onboard WiFi (MT7615), miniPCIe slot
- USB: 1x USB 3.0
- UART: 3x serial ports
- GPIO, I2C, SPI, PWM support
How to build the experimental code
Code is in here:
1. https://github.com/Martinfx/freebsd-src/tree/max-support-mediatek-7622-bananapir64
Build kernel from source and copy kernel.bin to tftpboot:
2. sudo git pull; sudo make buildkernel buildworld TARGET_ARCH=aarch64 TARGET=arm64 KERNCONF=MEDIATEK -j12 ;sudo cp -vR /usr/obj/usr/src/arm64.aarch64/sys/MEDIATEK/kernel.bin /tftpboot
or install the kernel to mount the folder:
3. sudo make installkernel installworld distrib-dirs distribution TARGET_ARCH=aarch64 TARGET=arm64 KERNCONF=MEDIATEK -j12 DESTDIR=/mnt/freebsd/
root@bpi-r64 ~# less /etc/rc.conf
hostname="bpi-r64"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
dnsmasq_enable="YES"
sshd_enable="YES"
pf_enable="YES"
gateway_enable="YES" # net.inet.ip.forwarding=1
defaultrouter="192.168.10.1"
defaultroute_delay="0"
ifconfig_mtge1="DHCP" # WAN – od domácího routeru
ifconfig_mtge0="inet 192.168.20.1/24" # LAN – tvoje síť za routerem
ext_if = "mtge1"
int_if = "mtge0"
set skip on { lo0 $int_if }
nat on $ext_if inet from $int_if:network to any -> ($ext_if)
pass all
Connecting to host 192.168.10.94, port 5201
[ 5] local 192.168.10.99 port 42733 connected to 192.168.10.94 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.01 sec 113 MBytes 938 Mbits/sec 0 728 KBytes
[ 5] 1.01-2.00 sec 111 MBytes 939 Mbits/sec 0 728 KBytes
[ 5] 2.00-3.00 sec 112 MBytes 934 Mbits/sec 0 728 KBytes
[ 5] 3.00-4.01 sec 113 MBytes 940 Mbits/sec 0 728 KBytes
[ 5] 4.01-5.00 sec 110 MBytes 935 Mbits/sec 0 728 KBytes
[ 5] 5.00-6.01 sec 113 MBytes 938 Mbits/sec 0 728 KBytes
[ 5] 6.01-7.00 sec 110 MBytes 932 Mbits/sec 0 728 KBytes
[ 5] 7.00-8.00 sec 112 MBytes 937 Mbits/sec 0 728 KBytes
[ 5] 8.00-9.00 sec 111 MBytes 933 Mbits/sec 0 728 KBytes
[ 5] 9.00-10.00 sec 112 MBytes 938 Mbits/sec 0 728 KBytes
[ 5] 10.00-11.00 sec 112 MBytes 935 Mbits/sec 0 728 KBytes
^C[ 5] 11.00-11.92 sec 102 MBytes 939 Mbits/sec 0 728 KBytesYou can also boot from tftpboot...
Peripherals Support Table
Peripheral |
Status |
Notes |
SD Card (mmc0) |
Working |
|
eMMC |
Not supported |
|
Ethernet (LAN) |
experimental |
speed 940 Mbits/sec |
Ethernet (WAN) |
experimental |
speed 940 Mbits/sec |
Ethernet switch 7531 |
experimental |
Driver WIP, needs more testing |
WiFi (MT7615) |
experimental |
needs more testing mt7615 speed 100/100 |
USB 3.0 |
Working |
|
USB 2.0 |
Working |
|
UART0 (console) |
Working |
Default console |
UART1/2 |
Disabled |
|
GPIO |
Partial |
Basic gpio WIP, need test |
Pinctrl |
Working |
Basic pinctrl |
SPI |
Not supported |
|
I2C |
Not supported |
|
PWM |
Not supported |
|
SATA |
Not supported |
|
miniPCIe |
experimental |
Use for extra WiFi cards mt7615 |
RTC |
Partial |
Internal RTC supported |
Watchdog |
Working |
Driver WIP, needs more testing |
Xhci |
Working |
Driver WIP, needs more testing |
Clocks + clocks pll |
Working |
Driver WIP, needs more testing |
What is Bananapi-R2 Pro?
Peripherals Support Table
Peripheral |
Status |
Notes |
SD Card (mmc0) |
Working |
|
eMMC |
Not supported |
|
Ethernet (LAN) |
Working |
only ChaosBSD |
Ethernet (WAN) |
Working |
only ChaosBSD |
WiFi (MT7615) |
Not supported |
No driver in FreeBSD yet (mt76 missing) |
USB 3.0 |
Broken |
not working |
UART0 (console) |
Working |
Default console |
UART1/2 |
Disabled |
|
GPIO |
Working |
Basic gpio WIP, need test |
Pinctrl |
Working |
Basic pinctrl |
SPI |
Not supported |
|
I2C |
Working |
|
PWM |
Not supported |
|
Sata |
Developing |
not tested |
miniPCIe |
Working |
Use for extra WiFi cards, not tested |
RTC |
Working |
Internal RTC supported |
Watchdog |
Working |
|
Clocks |
Working |
|
- For bananapi-r2-pro, there is a bug in AHCI
- For bananapi-r2-pro, there is a bug in PCIE (freeze, but wait for .dts patch)
Support for the Ethernet MT7531 switch has been merged into ChaosBSD
What is Banana Pi BPI-R2 (MediaTek MT7623N)
Peripherals Support Table
Peripheral |
Status |
Notes |
SD Card (mmc0) |
Not supported |
|
eMMC |
Not supported |
|
Ethernet (LAN) |
Not supported |
|
Ethernet (WAN) |
Not supported |
|
WiFi (MT7615) |
Not supported |
|
USB 3.0 |
Not supported |
not working |
UART0 (console) |
|
Default console |
UART1/2 |
Disabled |
|
GPIO |
Not supported |
|
Pinctrl |
Not supported |
|
SPI |
Not supported |
|
I2C |
Not supported |
|
PWM |
Not supported |
|
Sata |
Not supported |
|
miniPCIe |
Not supported |
|
RTC |
Not supported |
|
Watchdog |
Not supported |
|
Clocks |
working on |
|
Switch 7530 |
Not supported |
|
Contents
- FreeBSD/ARM on the Bananapi family (R64/R2/R2-PRO/R3/R4)
Overview
This page tracks the work-in-progress FreeBSD port to the MediaTek MT7623 SoC, using the Banana Pi BPI-R2 as the reference board.
The MT7623 is a quad-core ARM Cortex-A7 (armv7) SoC and is register-level very close to the MediaTek MT2701; all clock drivers written so far probe on both, so MT2701 gets partial support for free.
The port lives in a new SoC directory, sys/arm/mediatek/, and is built as part of the armv7 GENERIC kernel.
Status: work in progress, not yet merged into FreeBSD main.
Hardware
Item |
Detail |
SoC |
MediaTek MT7623N |
CPU |
4x ARM Cortex-A7, up to 1.3 GHz (OPP table 98 MHz - 1300 MHz) |
Architecture |
armv7 |
RAM |
2 GB DDR3 at 0x80000000 |
Interrupt controller |
ARM GIC (Cortex-A7 GIC) |
Timer |
ARM generic timer, plus MediaTek APXGPT block at 0x10008000 |
Console |
uart2 at 0x11004000, 115200n8 |
Ethernet |
2x GMAC plus MT7530 switch (1x WAN, 4x LAN) |
Storage |
eMMC, microSD, SPI-NOR, NAND |
PMIC |
MediaTek MT6323 |
Other |
HDMI, PCIe, USB (xHCI plus MUSB), SATA, I2C, SPI, PWM, Mali-450 GPU |
The device tree already present in the FreeBSD tree is sys/contrib/device-tree/src/arm/mediatek/mt7623n-bananapi-bpi-r2.dts (compatible = "bananapi,bpi-r2", "mediatek,mt7623"), so no out-of-tree DTS is required.
Current status
The board brings up the platform layer, all four cores, the serial console, the clock tree, reset controllers, pin muxing and GPIO. Peripheral drivers (networking, storage, USB, PCIe) are not written yet.
Implemented
Component |
Source file |
Notes |
Platform / machdep |
mt7623_machdep.c |
FDT platform for mediatek,mt7623, devmap, DELAY, generic timer bring-up |
SMP |
mt7623_mp.c |
Starts the secondary Cortex-A7 cores |
UART |
mt7623_uart.c |
ns8250 derivative, console and EARLY_PRINTF |
Clock framework |
mdtk_clk.c, mdtk_clk.h |
Registration layer over the FreeBSD clk framework |
PLL |
mt_clk_pll.c, mt_clk_pll.h |
MediaTek PLL clknode |
topckgen |
mt7623_topgen.c |
Top clock generator: muxes, gates, dividers |
apmixedsys |
mt7623_apmixedsys.c |
PLL block |
infracfg |
mt7623_infracfg.c |
Clocks plus reset controller |
pericfg |
mt7623_pericfg.c |
Clocks plus reset controller |
hifsys |
mt7623_hifsys.c |
Clocks plus reset controller |
imgsys |
mt7623_imgsys.c |
Clock gates |
bdpsys |
mt7623_bdpsys.c |
Clock gates |
audsys |
mt7623_audsys.c |
Clock gates |
vdecsys |
mt7623_vdecsys.c |
Clock gates |
syscon |
mt7623_syscfg.c |
mediatek,mt7623-pctl-a-syscfg via simple_mfd |
pinctrl |
mt7623_pinctrl.c |
Pin muxing via GPIO_MODE registers |
GPIO |
mt7623_pinctrl.c |
gpio_if on the same regmap |
Not implemented yet
Everything below is described by the device tree but has no driver:
Component |
Device tree compatible |
Priority |
Ethernet MAC |
mediatek,mt7623-eth, mediatek,mt7623-ethsys |
High |
Ethernet switch |
mediatek,mt7530 |
High |
eMMC / SD |
mediatek,mt7623-mmc |
High |
Watchdog / reset |
mediatek,mt7623-wdt |
High, needed for reboot |
USB |
mediatek,mt7623-xhci, -tphy, -musb |
Medium |
PCIe |
mediatek,mt7623-pcie |
Medium |
I2C |
mediatek,mt7623-i2c |
Medium |
SPI / SPI-NOR |
mediatek,mt7623-spi, -nor |
Medium |
NAND |
mediatek,mt7623-nfc, -ecc |
Low |
PWM |
mediatek,mt7623-pwm |
Low |
ADC |
mediatek,mt7623-auxadc |
Low |
Thermal |
mediatek,mt7623-thermal |
Low |
RNG |
mediatek,mt7623-rng |
Low |
eFuse |
mediatek,mt7623-efuse |
Low |
PMIC wrapper |
mediatek,mt7623-pwrap |
Low, needed for MT6323 |
Power domains |
mediatek,mt7623-scpsys |
Low |
IOMMU / SMI |
mediatek,mt7623-m4u, -smi-common, -smi-larb |
Low |
Crypto |
mediatek,eip97-crypto |
Low |
DMA |
mediatek,mt7623-hsdma |
Low |
Display / HDMI |
mediatek,mt7623-mmsys, -hdmi, -dsi, -dpi, -mipi-tx |
Low |
GPU |
mediatek,mt7623-mali |
Low |
Source
The work is kept on a branch in a GitHub fork:
At the time of writing the branch carries 16 commits on top of FreeBSD main, adding roughly 4300 lines across 23 files. Apart from three lines of build glue, all of it is new code under sys/arm/mediatek/.
git clone https://github.com/Martinfx/freebsd-src.git cd freebsd-src git checkout max-support-bananapi-bpi-r2-7623
Building
The board is covered by the armv7 GENERIC kernel; the branch adds files.mediatek and the SOC_MEDIATEK option to it, plus a DTB module for the board.
make TARGET=arm TARGET_ARCH=armv7 KERNCONF=GENERIC buildkernel
The device tree blob is built by sys/modules/dtb/mediatek, which is wired into GENERIC through MODULES_EXTRA.
Implementation notes
Generic timer needs GPT6 ungated
On MT6589, MT7623, MT8127 and MT8135 the input clock of the ARM generic timer is gated behind GPT6 in the APXGPT block. Until GPT6 is enabled, CNTPCT never advances and the kernel hangs as soon as the generic timer is used as the event timer.
mt7623_late_init() therefore maps the APXGPT block at 0x10008000, puts GPT6 into free-running mode, and programs CNTFRQ to 13 MHz, because the firmware on this board leaves it unset. It then samples CNTPCT twice to confirm the counter is really ticking, and falls back to a GPT4-based DELAY() implementation if it is not.
Secondary core startup
MT7623 does not use PSCI for SMP. mt7623_mp_start_ap() writes the kernel entry point into the jump register of the MediaTek boot block at 0x10202000, then writes a per-core magic key (0x534c4131, 0x4c415332, 0x41534c33) into the matching core register and kicks the core with an SGI through the GIC distributor. The core count is read from L2CTLR.
Clock drivers
mdtk_clk.c is a small registration layer: each clock domain driver declares tables of fixed, link, mux, gate, divider and PLL nodes, and mdtk_register_clocks() turns them into a clock domain. This keeps the individual domain drivers close to the layout of the Linux driver they were derived from, which makes them easy to check against the datasheet.
The infracfg, pericfg and hifsys drivers additionally implement hwreset_assert, so they act as reset controllers as well.
pinctrl and GPIO
Pin functions live in the GPIO_MODE registers, five 3-bit fields per 32-bit register starting at offset 0x760 with a 0x10 stride, reached through the pctl-a-syscfg regmap. GPIO direction, output and input use one bit per pin, 16 pins per register, at 0x000, 0x500 and 0x630 respectively; each has atomic SET and CLR sub-registers, which the driver uses instead of read-modify-write.
UART
mt7623_uart.c subclasses the ns8250 driver and only overrides the parts MediaTek changed, mainly the interrupt enable register handling (ier_rxbits, ier_mask) plus attach, grab and ungrab. It matches mediatek,mt6577-uart, which is the fallback compatible string on every MT7623 serial node.
TODO
Ordered roughly by usefulness:
Watchdog driver, so that platform_cpu_reset() can reboot the board instead of panicking.
- MMC driver, so the system can be booted from eMMC or microSD.
- Ethernet MAC and MT7530 switch driver, the main reason to run FreeBSD on this board.
Finish pinctrl: bias-disable, bias-pull-up, bias-pull-down and drive strength are not handled yet, only pin muxing.
Move the bring-up debug settings out of sys/arm/conf/GENERIC. The branch currently adds KDB, DDB, GDB, BREAK_TO_DEBUGGER, BOOTVERBOSE, EARLY_PRINTF and the SOCDEV_PA/SOCDEV_VA pair straight into the shared armv7 GENERIC; that is fine for development but has to go into a separate kernel config before this can be proposed for main.
- USB and PCIe.
What is Bananapi-R3?
Peripherals Support Table
Device Tree Node |
Compatible |
Function |
Status |
Notes |
watchdog@1001c000 |
mediatek,mt7986-wdt |
Watchdog Timer |
No driver attached |
Watchdog driver missing |
apmixedsys@1001e000 |
mediatek,mt7986-apmixedsys |
PLL / Clock Controller |
No driver attached |
Required for clock framework |
pinctrl@1001f000 |
mediatek,mt7986a-pinctrl |
Pin Multiplexing / GPIO |
No driver attached |
Critical dependency for GPIO and peripherals |
pwm@10048000 |
mediatek,mt7986-pwm |
PWM Controller |
No driver attached |
PWM output support missing |
rng@1020f000 |
mediatek,mt7986-rng |
Hardware Random Generator |
No driver attached |
Entropy source |
crypto@10320000 |
inside-secure,safexcel-eip97 |
Crypto Accelerator |
No driver attached |
Hardware AES/SHA/IPsec offload |
serial@11002000 |
mediatek,mt7986-uart |
UART1 |
No driver attached |
Clock dependency unresolved |
serial@11003000 |
mediatek,mt7986-uart |
UART2 |
No driver attached |
Clock dependency unresolved |
serial@11004000 |
mediatek,mt7986-uart |
UART3 |
No driver attached |
Clock dependency unresolved |
i2c@11008000 |
mediatek,mt7986-i2c |
I²C Controller |
No driver attached |
Required for sensors and PMICs |
spi@1100a000 |
mediatek,mt7986-spi-ipm |
SPI Controller 0 |
No driver attached |
Flash and peripheral support |
spi@1100b000 |
mediatek,mt7986-spi-ipm |
SPI Controller 1 |
No driver attached |
Flash and peripheral support |
thermal@1100c800 |
mediatek,mt7986-thermal |
Thermal Sensor |
No driver attached |
Temperature monitoring |
adc@1100d000 |
mediatek,mt7986-auxadc |
ADC |
Disabled / No driver |
Analog input support |
usb@11200000 |
mediatek,mt7986-xhci |
USB 3.0 XHCI |
No driver attached |
USB host controller |
mmc@11230000 |
mediatek,mt7986-mmc |
SD/eMMC Controller |
Disabled / No driver |
Storage support |
pcie@11280000 |
mediatek,mt7986-pcie |
PCIe Host Bridge |
No driver attached |
PCIe subsystem support |
t-phy |
mediatek,mt7986-tphy |
USB/PCIe PHY |
No driver attached |
PHY framework required |
efuse@11d00000 |
mediatek,mt7986-efuse |
eFuse Controller |
No driver attached |
Calibration and MAC address storage |
t-phy@11e10000 |
mediatek,mt7986-tphy |
PHY Controller |
No driver attached |
PHY framework required |
ethernet@15100000 |
mediatek,mt7986-eth |
Ethernet MAC + DMA |
No driver attached |
Core networking functionality |
wifi@18000000 |
mediatek,mt7986-wmac |
Integrated Wi-Fi 6 MAC |
No driver attached |
Wireless subsystem |
pwm-fan |
pwm-fan |
PWM Fan Controller |
No driver attached |
Depends on PWM support |
gpio-keys |
gpio-keys |
GPIO Buttons |
No driver attached |
Depends on GPIO framework |
i2c-gpio-0 |
i2c-gpio |
GPIO Bitbang I²C |
No driver attached |
Depends on GPIO support |
i2c-gpio-1 |
i2c-gpio |
GPIO Bitbang I²C |
No driver attached |
Depends on GPIO support |
sfp-1 |
sff,sfp |
SFP Cage |
No driver attached |
Optical module support |
sfp-2 |
sff,sfp |
SFP Cage |
No driver attached |
Optical module support |
Additional Issues
Component |
Issue |
OFW Resource Allocation |
ofwbus0: no default resources for rid = 4, type = 1 |
ARM Generic Timer |
could not allocate irq for optional interrupt 'hyp-virt' |
UART Clock Framework |
uart0: Cannot get UART clock: 6 |
GPIO LED Support |
failed to map pin |
Pinctrl Framework |
Likely root cause of GPIO LED failures |
Clock Framework |
Required by UART, Ethernet, USB, PCIe, GPIO and other peripherals |
Suggested Driver Implementation Order
- MT7986 Clock Framework (apmixedsys / topckgen / infracfg)
- MT7986 Pinctrl
- MT7986 GPIO
- MT7986 Ethernet
- MT7986 XHCI USB
- MT7986 PCIe
- MT7986 I²C
- MT7986 SPI
- MT7986 Wi-Fi (WMAC)
- Remaining drivers (Thermal, RNG, Crypto, PWM, Watchdog)
Notes
The missing clock framework appears to be the primary blocker. Multiple subsystems already fail due to unresolved clock dependencies, including UART devices.
The missing pinctrl driver is also critical because GPIO-based devices (LEDs, GPIO keys, I²C-GPIO) cannot function correctly without proper pin mapping and mux configuration.
Once clock and pinctrl support are available, a significant portion of the currently unattached devices should become functional or at least probe successfully.