Changes I Made to the Rock Pi S
In this post I detail the changes I made to the base system once I had a Linux OS running on the Radxa Rock Pi S.
Device Tree Overlays and Changes
The Rock Pi S has a quad-core ARM A53-based RK3308B CPU spec’d at 1.0GHz. However with a simple application of a device tree overlay one can overclock the CPU up to 1.3GHz. This overlay is already within the Linux system in the /boot/dtb/rockship/overlay directory named ‘b@1.3ghz.dtbo’. Opening the /boot/armbianEnv.txt file and adding the named overlay in the ‘overlays’ line:
verbosity=1
bootlogo=false
console=serial
overlay_prefix=rk3308
fdtfile=rockchip/rk3308-rock-pi-s.dtb
extraargs=cma=16M
rootdev=UUID=15b5cdb8-4ce1-4589-8e65-170bf9fbda6a
rootfstype=ext4
overlays=b@1.3ghz
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
Next, I modified the ‘rk3308-rock-pi-s.dtb’ device tree binary (DTB) to enable the ‘pwm2’, ‘pwm3’, and ‘i2c1’ devices on the Rock Pi S. I copied the previously mentioned DTB to the user home directory. Then I de-compiled the DTB to a DTS with the following command:
dtc -I dtb -O dts rk3308-rock-pi-s.dtb -o rk3308-rock-pi-s.dts
I copied the resulting DTS and named it ‘rk3308-rock-pi-s.dts.original’. I then deleted the copied DTB as I would be generating a new one with the same name in the same directory shortly. Opening the DTS file in Vim, I changed the ‘status’ property for the ‘pwm2’ and ‘pwm3’ devices from “disabled” to “okay”. Saved the file, then compiled the DTS file to a DTB using the following command:
dtc -I dts -O dtb -o rk3308-rock-pi-s.dtb rk3308-rock-pi-s.dts
The resulting DTB was copied into the /boot/dtb/rockchip directory overwriting the previous file. The system was rebooted in order for the changes to take place.
Custom systemd Units
I defined two custom units for systemd:
- ‘rtc-ds3231.service’ for executing the ‘rtc_init.sh’ script on bootup, setup for the external real-time clock (RTC) module for keeping time
- ‘rockpis-hw-setup.service’ for executing the ‘rockpis-hw-setup.sh’ script, configuring the sysfs GPIOs and PWMs.
The content of the RTC unit file:
[Unit]
Description=DS3231 RTC Service
#After=multi-user.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/bin/bash /home/bdn/rtc_init.sh
StandardOutput=journal
StandardError=journal
SyslogIdentifier=Service-RTC-DS3231
[Install]
WantedBy=multi-user.target
The content of the associated shell script:
#!/bin/bash
# script to initial the DS3231 real-time clock (RTC)
echo ds3231 0x68 > /sys/class/i2c-dev/i2c-1/device/new_device
hwclock -s -f /dev/rtc0
hwclock -w
The content of the HW unit file:
[Unit]
Description=HW Setup Service
After=multi-user.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/bin/bash /home/bdn/rockpis-hw-setup.sh
StandardOutput=journal
StandardError=journal
SyslogIdentifier=Service-HW-Setup
[Install]
WantedBy=multi-user.target
The content of the associated shell script:
#!/usr/bin/env bash
# See Radxa Rock Pi S v1.3 pinout for more information
# PWM2
echo 0 > /sys/class/pwm/pwmchip1/export
# PWM3
echo 0 > /sys/class/pwm/pwmchip2/export
# GPIOs on header #1
echo 68 > /sys/class/gpio/export
echo 17 > /sys/class/gpio/export
echo 55 > /sys/class/gpio/export
echo 54 > /sys/class/gpio/export
echo 56 > /sys/class/gpio/export
echo 69 > /sys/class/gpio/export
echo 74 > /sys/class/gpio/export
echo 73 > /sys/class/gpio/export
echo 71 > /sys/class/gpio/export
# GPIOs on header #2
echo 109 > /sys/class/gpio/export
echo 107 > /sys/class/gpio/export
echo 76 > /sys/class/gpio/export
echo 72 > /sys/class/gpio/export
echo 77 > /sys/class/gpio/export
echo 78 > /sys/class/gpio/export
echo 79 > /sys/class/gpio/export
echo 80 > /sys/class/gpio/export
echo 108 > /sys/class/gpio/export
echo 106 > /sys/class/gpio/export
echo 75 > /sys/class/gpio/export
echo 70 > /sys/class/gpio/export
I needed to install the ‘i2c-tools’ package for the i2cdetect utility and the ‘util-linux-extra’ package for the hwclock utility. Make sure the permissions on the custom systemd unit files is ‘644’ upon installing them to the etc/systemd/system directory. The services are run during boot-up and so far work without issue. The external real-time clock module associated with the RTC service is mated to pins 4 (+5V), 6 (ground), 5 (I2C1_SDA), and 7 (I2C1_SCL); all on header #1. The systemd service ‘systemd-timesyncd’ needs to be disabled.
Netplan Changes
I desired for the Rock Pi S to have a static IP address on the network. The Armbian Linux running on the Rock Pi S uses Netplan to setup and configure networking for the device. To configure for a static IP address, a Netplan YAML file ’20-static-ip.yaml’ was created with the following content:
network:
version: 2
renderer: networkd
ethernets:
end0:
addresses:
- 192.168.0.111/24
routes:
- to: default
via: 192.168.0.1
nameservers:
addresses:
- 208.67.222.222
- 208.67.220.220
The file was saved in the /etc/netplan directory. The default file ’10-dhcp-all-interfaces.yaml’ needs to be removed from the /etc/netplan directory. I copied the default configuration file to the user home directory then deleted it from the Netplan directory. I executed sudo netplan try to make sure there were no errors with the static IP configuration file, then ran sudo netplan apply to apply the changes. If Netplan complains about the permissions on the file, set the permissions with the chmod command to ‘600’. Make sure the file’s owner is ‘root’.
udev Changes
In order to use the gpiochip{N} devices from a user-space application, the permissions on the devices needed changing. These devices will be in the /dev directory. First, create the ‘gpio’ group:
sudo groupadd gpio
Next, add the current user to the ‘gpio’ group:
sudo usermod -aG gpio $USER
I created the ’99-com.rules’ file in the /etc/udev/rules.d directory with the following content:
SUBSYSTEM=="gpio*", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /dev/gpiochip0; chmod 660 /dev/gpiochip0'"
SUBSYSTEM=="gpio*", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /dev/gpiochip1; chmod 660 /dev/gpiochip1'"
SUBSYSTEM=="gpio*", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /dev/gpiochip2; chmod 660 /dev/gpiochip2'"
SUBSYSTEM=="gpio*", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /dev/gpiochip3; chmod 660 /dev/gpiochip3'"
SUBSYSTEM=="gpio*", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /dev/gpiochip4; chmod 660 /dev/gpiochip4'"
Make sure the file owner is set to ‘root’ and the permissions on the file is ‘644’. The changes took place after a reboot.
I will update and correct mistakes as I find them, this post was done quick and dirty.
Attempt to Prevent Kernel Updates
I do not want the RT kernel overwritten with a non-RT kernel during updates, so I performed the following command after researching on the internet:
sudo apt-mark hold linux-image-current-rockchip64 linux-dtb-current-rockchip64 linux-u-boot-rockpi-s-current
I will find out later if this holds up.