FreeBSD for Edge / Edge-V

Hi All!
The new build of FreeBSD 13.0-CURRENT is available for download,
NVMe M.2 disk is stable.

https://personalbsd.org/?page_id=2

Screenshot attached.

3 Likes

Hmm, Iā€™m a little nervous about erasing the eMMC, as itā€™s how I can currently reliably tell that the unit still works because it will always boot into the stock Android.

Is there any way to get this image to boot from sdcard without erasing the eMMC, like the LibreELEC images? I tried the hack in the thread, where you copy u-boot from a known good image, but unfortunately it didnā€™t work. (I figured it wouldnā€™t, but wanted to try.)

That is great progress! I canā€™t wait to try it.

Thank you for all the great work and help @SleepWalker, Iā€™ve now got FreeBSD 13-CURRENT running on my EDGE-V! Itā€™s using the NVMe for /usr, swap, /var, and /tmp quite successfully.

I noticed that the fan runs 100% of the time and investigated. I see in dmesg it is enumerated from the DTB correctly:

ofwbus0: <pwm-fan> compat pwm-fan (no driver attached)

But there is no pwm-fan driver on FreeBSD as there is in Linux. I found the source code @ https://github.com/torvalds/linux/blob/master/drivers/hwmon/pwm-fan.c but it is beyond my ability to port this driver over, even assuming any dependencies already exist.

I did discover, however, that both pwm0 and pwm1 can be controlled via the command line using the pwm command:

pwm -f /dev/pwm/pwmc0.0 -D will disable the fan
pwm -f /dev/pwm/pwmc0.0 -E -d 0 -p 0 will enable the fan

The -d represents the duty cycle (in nanoseconds/percentage) and -p represents the period (nanoseconds).

Edit:

Ok, with some guidance from a friend, I was able to get the PWM working correctly. I adapted the script to be more daemon-able and it appropriately slows the fan with the temperature. I created two scripts:

/usr/local/bin/fan.sh - the actual PWM logic
/usr/local/etc/rc.d/pwmfan - the service script

Here is fan.sh:

#!/bin/sh
# fan.sh - automatic control of PWM fan on RK3399

trap quit_fan SIGINT SIGSTOP SIGTERM SIGQUIT

quit_fan() {
    pkill -P $$ sleep
    exit
}

MINTEMP=35
MAXTEMP=50

SYSCTL="/sbin/sysctl"
CUT="/usr/bin/cut"
PWM="/usr/sbin/pwm"
PWM_DEVICE="/dev/pwm/pwmc0.0"

while [ TRUE ]; do
    TEMP=`${SYSCTL} -n hw.temperature.CPU | ${CUT} -d . -f 1`
    DISABLE=0
    if [ "$TEMP" -gt ${MAXTEMP} ]; then
        # set speed to maximum
        PERCENTAGE=0
    elif [ "$TEMP" -le ${MINTEMP} ]; then
        # set speed to minimum
        PERCENTAGE=100
        DISABLE=1
    else
        PERCENTAGE=$((TEMP - MINTEMP))
        PERCENTAGE=$(((PERCENTAGE * 100) / 15))
        echo "Temperature is ${TEMP}, which is percentage ${PERCENTAGE}."
        PERCENTAGE=$((100 - PERCENTAGE))
    fi

    if [ $DISABLE -eq "1" ]; then
       ${PWM} -f ${PWM_DEVICE} -D
    else
        if [ "${PERCENTAGE}" -eq 0 ]; then
            ${PWM} -f ${PWM_DEVICE} -E -d 0 -p 0
        else
            ${PWM} -f ${PWM_DEVICE} -E -d ${PERCENTAGE}% -p 30000
        fi
    fi

    sleep 60 &
    wait $!
done

And here is the service script:

#!/bin/sh
# PWMFAN - rc.d script to control RK3399 PWM fan
# PROVIDE: pwmfan
# REQUIRE: DAEMON

# Enable this script by adding:
# pwmfan_enable="YES"
# ... to /etc/rc.conf

. /etc/rc.subr

# Set the default
: ${pwmfan_enable:="NO"}
: ${pwmfan_runuser:="operator"}

name="pwmfan"
rcvar="pwmfan_enable"

# This is the tool init launches
command="/usr/sbin/daemon"
pidfile="/var/run/${name}.pid"

# This is the tool daemon launches
task="/usr/local/bin/fan.sh"
procname="/bin/sh"

command_args="-f -p ${pidfile} -u ${pwmfan_runuser} ${task}"

load_rc_config $name
run_rc_command "$1"

Make sure both scripts are executable (chmod a+x /usr/local/etc/rc.d/pwmfan /usr/local/bin/fan.sh) and then you can enable & start the service: sysrc pwmfan_enable="YES" ; service pwmfan start

4 Likes

Hi @Sleepwalker !
do u have any news/progress about freebsd for EDGE?

Unfortunately NVMe is only stable when disabling the two A72 cores. Hopefully that is fixed soon. Otherwise, it is very stable and awesome!

1 Like

Have anyone tried opnsense over freebsd? As eth is working, we can use usb to Ethernet adaptor for a second lan.

@SleepWalker Do you plan to continue supporting FreeBSD for edge-v ?
I hope everything is fine with you.

I plan to test this and try to install opnsense using bootstrap explained Here
Might have to add aarch64 on this line

Hello everyone, I am healthy, everything is fine.

Currently Iā€™m porting FreeNAS to the aarch64 platform.

And I want to prepare boot images for KHADAS EDGE-V.

OPNsense has already been compiled for RK3399, so you can take it

https://personalbsd.org/?page_id=2

All success. And the main thing is not to get sick!

4 Likes

Amazing work.
Good to hear from you.
Will wait for edge-v image.

Thanks.

Hello Everyone
I am trying to boot Freebsd using SD card but it fails to boot instead it boots into emmc which have Manjaro in it.

>> FreeBSD EFI boot block
   Loader path: /boot/loader.efi

   Initializing modules: ZFS UFS
   Load Path: /efi\boot\bootaa64.efi
   Load Device: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(1)/SD(1)/HD(1,0x01,0,0)
   Probing 6 block devices...not supported
not supported
not supported
not supported
not supported
not supported
 done
    ZFS found no pools
    UFS found no partitions
Failed to load '/boot/loader.efi'
panic: No bootable partitions found!
## Application terminated, r = 1
EFI LOAD FAILED: continuing...
switch to partitions #0, OK
mmc0(part 0) is current device
Scanning mmc 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
257 bytes read in 19 ms (12.7 KiB/s)
1:      Manjaro ARM
Retrieving file: /extlinux/../initramfs-linux.img
7852408 bytes read in 839 ms (8.9 MiB/s)
Retrieving file: /extlinux/../Image
26223104 bytes read in 2728 ms (9.2 MiB/s)
append: initrd=../initramfs-linux.img console=uart8250,mmio32,0xff1a0000 console=tty1  
Retrieving file: /extlinux/../dtbs/rockchip/rk3399-khadas-edge-v.dtb
73648 bytes read in 45 ms (1.6 MiB/s)
## Flattened Device Tree blob at 01f00000
   Booting using the fdt blob at 0x1f00000
Host not halted after 16000 microseconds.
   Loading Ramdisk to f57a5000, end f5f22178 ... OK
   Loading Device Tree to 00000000f5790000, end 00000000f57a4faf ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.7.0-0.3-MANJARO-ARM (spikerguy@Manjaro) (gcc version 9.0
[    0.000000] Machine model: Khadas Edge-V
[    0.000000] earlycon: uart8250 at MMIO32 0x00000000ff1a0000 (options '')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] efi: UEFI not found

IDK whyit is falling back to emmc boot, maybe @SleepWalker can advice something?

I will try to build opnsense for edge-v but I would like to know if you have uploaded edgev uboot to freebsd repo?
Which pkg are needed for edgev uboot?

Thanks.

Hi
Erase internal emmc before booting from the SD card!

To boot from sd card, you must first clean eMMC
for example, the dd command on Linux or from u-boot
boot# mmc erase 0 1000

If eMMC is empty, you will successfully boot from the SD card.

1 Like

Thanks.
I have manjaro on eMMC and will erase it after taking a backup

Can this script be used in Freebsd? As I donā€™t see you mentioned anything about freebsd here.
Yes the fan is always on.

This is throwing some error. Lan does not have dhcp enabled.
I will try it again and get back,
My board is Edge-V Pro.

I dont see /dev/pwm

root@khadas-edge-v:~ # pwm -f /dev/                                                                          
audit%       diskid/      kbd1@        mmcsd1boot0% stdin@       ugen4.3@                                    
auditpipe%   efi%         kbdmux0%     mmcsd1boot1% stdout@      ugen4.4@                                    
bpf%         fd/          klog%        mmcsd1rpmb%  sysmouse%    uhid0%                                      
bpf0@        fido%        kmem%        msdosfs/     ttyu0.init%  uinput%                                     
console%     full%        led/         music0%      ttyu0.lock%  ukbd0%                                      
consolectl%  geom.ctl%    log@         netdump%     ttyu0%       ums0%                                       
ctty%        gpioc0%      md0%         nfslock%     ttyu1.init%  urandom@                                    
cuau0.init%  gpioc1%      md1%         null%        ttyu1.lock%  usb/                                        
cuau0.lock%  gpioc2%      mdctl%       openfirm%    ttyu1%       usbctl%                                     
cuau0%       gpioc3%      mem%         pci%         ufssuspend%  xpt0%                                       
cuau1.init%  gpioc4%      midistat%    pfil%        ugen0.1@     zero%                                       
cuau1.lock%  iic0%        mmcsd0%      random%      ugen1.1@                                                 
cuau1%       iic1%        mmcsd0s1%    reroot/      ugen2.1@                                                 
devctl%      iic2%        mmcsd0s2%    sequencer0%  ugen3.1@                                                 
devctl2%     input/       mmcsd0s2a%   sndstat%     ugen4.1@                                                 
devstat%     kbd0@        mmcsd1%      stderr@      ugen4.2@  

dhcpclient runs but cannot find an ip, While my router is working and the same cable is used on all the other boards tested on my desk.

Yes, I wrote it specifically for FreeBSD, since it does not have the built-in fan control like Linux.

Iā€™m not sure your LAN message is related to the PWM fan controller at all. Itā€™s possible the Edge-V Pro has a different pwm device. For example, on my RockPro64 board, I had to modify the script to use /dev/pwm/pwmc1.0 instead of /dev/pwm/pwmc0.0.

Try ls -l /dev/pwm/ and then use the pwm command to iterate through the various devices and see which is controlling the fan.

Edit: Oh, I see your update now. Iā€™m not sure why you arenā€™t seeing /dev/pwm/ - does ā€œdmesg | grep -i pwmā€ show anything? Perhaps your DTB is not accurate because youā€™re using the Edge-V Pro?

 # dmesg | grep pwm                                                                      
Clock: clk_vop0_pwm_c, parent: vpll(0), freq: 4000000                                                        
Clock: clk_vop1_pwm_c, parent: vpll(0), freq: 4000000                                                        
Clock: clk_vop1_pwm, parent: clk_vop1_pwm_c(0), freq: 4000000                                                
Clock: clk_vop0_pwm, parent: clk_vop0_pwm_c(0), freq: 4000000                                                
Processing 1 pin-config node(s) in pinctrl-0 for pwm@ff420000                                                
Processing 1 pin-config node(s) in pinctrl-0 for pwm@ff420020                                                
ofwbus0: <pwm@ff420000> mem 0xff420000-0xff42000f compat rockchip,rk3399-pwm (no driver attached)            
ofwbus0: <pwm@ff420010> mem 0xff420010-0xff42001f disabled compat rockchip,rk3399-pwm (no driver attached)   
ofwbus0: <pwm@ff420020> mem 0xff420020-0xff42002f compat rockchip,rk3399-pwm (no driver attached)            
ofwbus0: <pwm@ff420030> mem 0xff420030-0xff42003f disabled compat rockchip,rk3399-pwm (no driver attached)   
ofwbus0: <vdd-log> compat pwm-regulator (no driver attached)                                                 
ofwbus0: <pwm-fan> compat pwm-fan (no driver attached)                                                       
root@khadas-edge-v:~ # 

Yeah, I think thereā€™s something up with your DTB that isnā€™t right. I donā€™t know if thereā€™s an rk3399-khadas-edge-pro.dtb (there isnā€™t on my system, but I havenā€™t updated in awhile). My output has the devices correctly detected:

Clock: pclk_rkpwm_pmu, parent: pclk_pmu_src(0), freq: 48000000
Clock: clk_vop0_pwm_c, parent: vpll(0), freq: 4000000
Clock: clk_vop1_pwm_c, parent: vpll(0), freq: 4000000
Clock: clk_vop1_pwm, parent: clk_vop1_pwm_c(0), freq: 4000000
Clock: clk_vop0_pwm, parent: clk_vop0_pwm_c(0), freq: 4000000
Processing 1 pin-config node(s) in pinctrl-0 for pwm@ff420000
Processing 1 pin-config node(s) in pinctrl-0 for pwm@ff420020
pwm0: <Rockchip PWM> mem 0xff420000-0xff42000f on ofwbus0
pwmbus0: <OFW PWM bus> on pwm0
pwmc0: <PWM Control> channel 0 on pwmbus0
ofwbus0: <pwm@ff420010> mem 0xff420010-0xff42001f disabled compat rockchip,rk3399-pwm (no driver attached)
pwm1: <Rockchip PWM> mem 0xff420020-0xff42002f on ofwbus0
pwmbus1: <OFW PWM bus> on pwm1
pwmc1: <PWM Control> channel 0 on pwmbus1
ofwbus0: <pwm@ff420030> mem 0xff420030-0xff42003f disabled compat rockchip,rk3399-pwm (no driver attached)
ofwbus0: <vdd-log> compat pwm-regulator (no driver attached)
ofwbus0: <pwm-fan> compat pwm-fan (no driver attached)

Yes also I am trying to find the network issue.
I cannot find the reason for lan not getting IP. Must be something similar related to Lan driver in the dtb

Maybe @hyphop can advice something? Is there any difference between Edge-V Basic & Pro in terms of Lan and Pwm-Fan ?

Hi @microdude

You donā€™t perhaps know how to auto enable the fan on Edge-V but using the 4.4 kernel without using any scripts? I want to enable the fan for LibreELEC and the 4.4 kernel is the only one supporting all the video codecs correctly until support is merged into mainline which might only be finished in a yearā€™s time.

See Khadas Edge-V Fan support in Linux 4.4 kernel?

Sorry, I donā€™t. Iā€™m not very familiar with the Linux kernel.

Hello @SleepWalker

Any progress on this? Did you get time to look into emmc boot?