Skip to content

Instantly share code, notes, and snippets.

@kylemanna
Last active September 12, 2024 15:33
Show Gist options
  • Save kylemanna/641e921fa07179963606799201a31841 to your computer and use it in GitHub Desktop.
Save kylemanna/641e921fa07179963606799201a31841 to your computer and use it in GitHub Desktop.
FriendlyElec NanoPi R5S Linux PTP Support

Build Notes

Environment

Use systemd-nspawn on Arch Linux with debootstrap:

sudo debootstrap --include=systemd-container --components=main,universe jammy ubuntu22.04-rk3568 http://archive.ubuntu.com/ubuntu/

Packages to install:

apt install wget curl git python2 android-sdk-libsparse-utils build-essential bison bc cpio time gawk unzip unzip libncurses-dev file python3-distutils

Load environment:

sudo systemd-nspawn -b --bind ~/tmp/repos/sd-fuse_rk3568:/build/sd-fuse_rk3568 -D ~/tmp/ubuntu22.04-rk3568

Successful build

./build.sh rk3568.mk
...
[INFO]: prepare rootfs.img ...                                                         
WARNING: tempfile is deprecated; consider using mktemp instead.                       
Creating filesystem with parameters:                                                                                                                                         
    Size: 444596224                                                                   
    Block size: 4096                                                                  
    Blocks per group: 32768                                                           
    Inodes per group: 6784                                                            
    Inode size: 256                                                                                                                                                          
    Journal blocks: 1696                                                                                                                                                     
    Label: rootfs                                                                                                                                                            
    Blocks: 108544                                                                                                                                                           
    Block groups: 4                                                                                                                                                          
    Reserved block group size: 31                                                                                                                                            
    Suggest size: 406847488                                                                                                                                                  
Created filesystem with 10881/27136 inodes and 94843/108544 blocks                                                                                                           
'/build/friendlywrt22-rk3568/scripts/sd-fuse/prebuilt/parameter.template' -> 'friendlywrt22/parameter.txt'                                                                   
generating friendlywrt22/parameter.txt done.                                          
0                                                                                     
generating friendlywrt22/rootfs.img done.                                             
0                                                                                                                                                                            
Generating empty userdata.img (size:104857600)                                        
Creating filesystem with parameters:                                                  
    Size: 104857600                                                                                                                                                          
    Block size: 4096                                                                  
    Blocks per group: 32768                                                                                                                                                  
    Inodes per group: 6400                                                                                                                                                   
    Inode size: 256                                                                                                                                                          
    Journal blocks: 1024                                                                                                                                                     
    Label: userdata                                                                                                                                                          
    Blocks: 25600                                                                                                                                                            
    Block groups: 1                                                                                                                                                          
    Reserved block group size: 7                                                                                                                                             
    Suggest size: 25165824                                                                                                                                                   
Created filesystem with 11/6400 inodes and 1438/25600 blocks                                                                                                                 
-----------------------------------------                                                                                                                                    
rootfs dir:                                                                           
        /build/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.8yKkb9usV               
boot dir:                                                                              
        /build/friendlywrt22-rk3568/scripts/sd-fuse/out/boot.cVJLeBie5                 
-----------------------------------------                                              
Creating RAW image: out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img (1000 MB)       
---------------------------------                                                      
0+0 records in                                                                         
0+0 records out                                                                        
0 bytes copied, 2.0559e-05 s, 0.0 kB/s                                                 
----------------------------------------------------------------                       
[out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img] capacity = 953MB, 999999488 bytes                                                                                        
current out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img partition:                  
----------------------------------------------------------------                       
parsing ./friendlywrt22/parameter.txt:                                                 
create new GPT 9:                                                                      
----------------------------------------------------------------                       
copy from: ./friendlywrt22 to out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img       
 [RAW. 0]:      284 KB | ./friendlywrt22/idbloader.img  > 100% : done.                 
 [RAW. 1]:     4096 KB | ./friendlywrt22/uboot.img      > 100% : done.                 
 [RAW. 2]:       48 KB | ./friendlywrt22/misc.img       > 100% : done.                 
 [RAW. 3]:        1 KB | ./friendlywrt22/dtbo.img       > 100% : done.                 
 [RAW. 4]:     3387 KB | ./friendlywrt22/resource.img   > 100% : done.                 
 [RAW. 5]:    37832 KB | ./friendlywrt22/kernel.img     > 100% : done.                 
 [RAW. 6]:     7308 KB | ./friendlywrt22/boot.img       > 100% : done.                 
 [RAW. 8]:   375850 KB | ./friendlywrt22/rootfs.img     > 100% : done.                 
 [RAW. 9]:     5752 KB | ./friendlywrt22/userdata.img   > 100% : done.                 
----------------------------------------------------------------                       
---------------------------------                                                      
RAW image successfully created (15:19:08).                                             
-rw-rw-r-- 1 build build 999999488 Sep 25 15:19 out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img                                                                            
Tip: You can compress it to save disk space.                                           
-----------------------------------------                                              
Run the following command for sdcard install:                                          
        sudo dd if=out/friendlywrt_22.03_20220925_rk3568_arm64_sd.img bs=1M of=/dev/sdX                                                                                       
-----------------------------------------                                              

README

Boot logs from default FriendlyWRT 21.02

[    1.994124] Linux version 5.10.66 (ubuntu@4cca3b9617ec) (aarch64-linux-gnu-gcc (ctng-1.23.0-150g-FA) 6.4.0, GNU ld (ctng-1.23.0-150g-FA) 2.28) #1 SMP Mon Jun 13 17:24:31 CST 2022
[    1.999626] Machine model: FriendlyElec NanoPi R5S                                                                                                                         
...
[   12.584026] r8125: loading out-of-tree module taints kernel.
[   12.586112] r8125 2.5Gigabit Ethernet driver 9.009.00-NAPI loaded
[   12.586229] r8125 0000:01:00.0: enabling device (0000 -> 0003)
[   12.604586] r8125: This product is covered by one or more of the following patents: US6,570,884, US6,115,776, and US6,327,625.
[   12.606651] r8125  Copyright (C) 2022 Realtek NIC software team <[email protected]> 
[   12.606651]  This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>. 
[   12.606651]  This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>. 
[   12.606932] r8125 2.5Gigabit Ethernet driver 9.009.00-NAPI loaded
[   12.607024] r8125 0001:11:00.0: enabling device (0000 -> 0003)
[   12.624794] r8125 0001:11:00.0 (unnamed net_device) (uninitialized): Invalid ether addr 00:00:00:00:00:00
[   12.624831] r8125 0001:11:00.0 (unnamed net_device) (uninitialized): Random ether addr 2a:dd:27:05:d1:69
[   12.625441] r8125: This product is covered by one or more of the following patents: US6,570,884, US6,115,776, and US6,327,625.
[   12.627485] r8125  Copyright (C) 2022 Realtek NIC software team <[email protected]> 
[   12.627485]  This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>. 
[   12.627485]  This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>. 

...
[   16.630001] rk_gmac-dwmac fe2a0000.ethernet eth0: PHY [stmmac-0:01] driver [RTL8211F Gigabit Ethernet] (irq=82)
[   16.632696] rk_gmac-dwmac fe2a0000.ethernet eth0: No Safety Features support found
[   16.632722] rk_gmac-dwmac fe2a0000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   16.632994] rk_gmac-dwmac fe2a0000.ethernet eth0: registered PTP clock
[   16.633857] rk_gmac-dwmac fe2a0000.ethernet eth0: configuring for phy/rgmii link mode
[   20.152148] rk_gmac-dwmac fe2a0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx

Sysfs PTP contents

root@FriendlyWrt:~# ls -lR /sys/class/ptp/ptp0/
/sys/class/ptp/ptp0/:
total 0
-r--r--r-- 1 root root 4096 Aug  4 17:07 clock_name
-r--r--r-- 1 root root 4096 Aug  4 17:07 dev
lrwxrwxrwx 1 root root    0 Aug  4 17:07 device -> ../../../fe2a0000.ethernet
-r--r--r-- 1 root root 4096 Aug  4 17:07 max_adjustment
-r--r--r-- 1 root root 4096 Aug  4 17:07 n_alarms
-r--r--r-- 1 root root 4096 Aug  4 17:07 n_external_timestamps
-r--r--r-- 1 root root 4096 Aug  4 17:07 n_periodic_outputs
-r--r--r-- 1 root root 4096 Aug  4 17:07 n_programmable_pins
drwxr-xr-x 2 root root    0 Aug  4 17:07 power
-r--r--r-- 1 root root 4096 Aug  4 17:07 pps_available
lrwxrwxrwx 1 root root    0 Aug  4 17:07 subsystem -> ../../../../../class/ptp
-rw-r--r-- 1 root root 4096 Aug  4 17:07 uevent

/sys/class/ptp/ptp0/power:
total 0
-rw-r--r-- 1 root root 4096 Aug  4 17:09 async
-rw-r--r-- 1 root root 4096 Aug  4 17:09 autosuspend_delay_ms
-rw-r--r-- 1 root root 4096 Aug  4 17:09 control
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_active_kids
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_active_time
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_enabled
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_status
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_suspended_time
-r--r--r-- 1 root root 4096 Aug  4 17:09 runtime_usage

phc_ctl output for eth0

root@FriendlyWrt:~# phc_ctl -q  eth0
phc_ctl[507.439]: 
capabilities:
  62500000 maximum frequency adjustment (ppb)
  0 programable alarms
  0 external time stamp channels
  0 programmable periodic signals
  0 configurable input/output pins
  doesn't have pulse per second support
  doesn't have cross timestamping support

PCI output from lspci

root@FriendlyWrt:/sys/class/net/eth1# lspci -nnk
0000:00:00.0 PCI bridge [0604]: Rockchip Electronics Co., Ltd RK3568 Remote Signal Processor [1d87:3566] (rev 01)
        Kernel driver in use: pcieport
lspci: Unable to load libkmod resources: error -12
0000:01:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
        Subsystem: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125]
        Kernel driver in use: r8125
0001:10:00.0 PCI bridge [0604]: Rockchip Electronics Co., Ltd RK3568 Remote Signal Processor [1d87:3566] (rev 01)
        Kernel driver in use: pcieport
0001:11:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
        Subsystem: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125]
        Kernel driver in use: r8125

Conclusion:

  • The RK3568 integrated MAC with in-tree driver rk_gmac-dwmac does support advanced PTP timestampping.
  • The out-of-tree r8125 v9.0.0 doesn't seem to fully enable PTP support present in the driver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment