Install Debian 10 Buster on Netgear ReadyNAS RN104 (RN102)

V 1.0 2019-08-28 Stefan Katerkamp

This is how I set up Debian 10 Buster on a Netgear ReadyNAS RN104 NAS Hardware. An ARM Armada-370 based hardware which was sold around 2013-2016 or so. Power consumption of an idle system with disks in standby mode is about 24 Watt.

Note that this install deletes the original Netgear firmware in NAND. Reason is that we use the bigger ubifs partition instead of minirootfs for initrd. This makes life easier as we don’t have to create our own device tree blob.

Connection to U-Boot console is a prerequisite. We tftp Debian Net Installer into RAM and run it from there. All needed packages get pulled in via Ethernet from a debian pool server.

Result is a plain vanilla Debian Buster system which will boot kernel and initrd from built in NAND flash, and then chroots to /boot and /root on a hard disk in the box. This means, about 16GB of disk space is used for the system, all other disk space can be used for payload.

Hardware Preparations

RN104 serial console access is a basic prerequisite. It is accessible behind the sticker on the upper left corner in the back. I am using a FTDI FT232RL adapter. Set the Vccio Jumper to 3.3V. Upper left pin goes to TX, lower left to GND, and upper right to RX:

to TX
  |
  o o-- to RX
  o o
  |
to GND

Finally connect the USB cable to some other computer near it, and connect to it with your favorite serial interface program like cu, picocom or screen.

cu -s 115200 -l /dev/ttyUSB0
Hint

If screen is garbled and you are using KDE Konsole, reset it with Shift-Ctrl-K.

Connect the RN104 to a LAN with Internet access and DHCP server via an Ethernet cable, use the upper port.

Make sure a fresh hard disk is installed in the ReadyNAS.

Set up TFTP server

Select a system in the LAN which will act as a TFTP server. Note down the IPv4 address of this server. (Example: 192.168.20.102). Install tftp server:

ip addr
apt install tftpd
Hint

Fix write permissons of the TFTP server data directory for your account so you don’t need to work as superuser: sudo chown $USER /srv/tftp.

Prepare Debian Installer Images

I had no success booting vmlinuz and initrd.gz directly on my ReadyNAS Firmware V.6.0 using bootz. However, old uImage/uInitrd format works. So we need to convert our debian installer files into this format.

Log in to your workstation. We need the u-boot-tools package:

sudo apt install u-boot-tools

Download d-i images for the RN104 and build the uImage:

cd /tmp
rm -f initrd.gz vmlinuz armada-370-netgear-rn104.dtb
wget http://ftp.debian.org/debian/dists/buster/main/installer-armhf/current/images/netboot/initrd.gz
wget http://ftp.debian.org/debian/dists/buster/main/installer-armhf/current/images/netboot/vmlinuz
wget http://ftp.debian.org/debian/dists/buster/main/installer-armhf/current/images/device-tree/armada-370-netgear-rn104.dtb
cat vmlinuz armada-370-netgear-rn104.dtb > vmlinuz_rn104
mkimage -A arm -O linux -T multi -C none -a 0x04000000 -e 0x04000000 \
 -n "Debian Buster armhf installer" -d vmlinuz_rn104:initrd.gz uImage_di_rn104

Copy the uImage_di_rn104 file to the TFTP server data directory /srv/tftp.

Prepare U-Boot settings

Open serial console window and power on the ReadyNAS box. Quickly hit Return key to interrupt automatic boot sequence and get into U-Boot CLI. To make life easier adapt bootdelay to 10 seconds:

setenv bootdelay 10
saveenv

This is needed for mtdparts and load_addr, its factory default and looks like this:

printenv mtdparts
mtdparts=armada-nand:0x180000@0(u-boot),0x20000@0x180000(u-boot-env),0x600000@0x200000(uImage),0x400000@0x800000(minirootfs),-(ubifs)
printenv load_addr
0x02000000

Check that partition definition is recognized:

Marvell>> mtdparts

device nand0 <armada-nand>, # parts = 5
 #: name                size            offset          mask_flags
 0: u-boot              0x000000180000          0x000000000000          0
 1: u-boot-env          0x000000020000          0x000000180000          0
 2: uImage              0x000000600000          0x000000200000          0
 3: minirootfs          0x000000400000          0x000000800000          0
 4: ubifs               0x000007400000          0x000000c00000          0

active partition: nand0,0 - (u-boot) 0x000000180000 @ 0x000000000000

defaults:
mtdids  : none
mtdparts: none

Marvell>> nand info

Device 0: nand0, sector size 128 KiB
  Page size      2048 b
  OOB size         64 b
  Erase size   131072 b

Adapt boot settings to match increased file sizes. U-Boot settings have to match the Linux RN104 dtb. Debian kernel ignores mtdparts command line arg (CONFIG_MTD_CMDLINE_PARTS is not set). This is used by U-Boot only.

We are going to install kernel and DTB into NAND uImage partition, and initrd into NAND ubifs partition. Upon boot, we copy the complete uImage area (0x600000 bytes) and just parts of ubifs (0xf00000 bytes) for speed.

Adapt the boot command sequence for it:

setenv bootcmd 'nand read 0x2000000 uImage 0x600000;nand read 0x3000000 ubifs 0xf00000;bootm 0x2000000 0x3000000'
saveenv

For ease of use, save TFTP server IPv4 address in U-Boot env, example for IP 192.168.20.102:

setenv serverip 192.168.20.102
saveenv

Run Debian Installer

Download the installer image and run it. As no IP address is set but an Ethernet cable exists, U-Boot sets up an IPv4 connection using DHCP automatically:

tftp uImage_di_rn104
bootm

Now kernel boots and d-i gets started as usual. Use eth0 for the Ethernet port. Due to little memory in the box d-i guided partitioning creates a quite small swap partition of just 500MB. You may want to partition disk manually.

Now all should run fine till the installation is finished. This may take a while, be patient.

Finally, you’ll see a a red screen. Failing step is: Make the system bootable.

Hit Return key to continue. Debian installer main menu shows up.

Select Execute a shell, Continue and get the command prompt.

Check this:

cat /proc/mtd
dev:    size   erasesize  name
mtd0: 08000000 00020000 "pxa3xx_nand-0"

MTD has no partitions. For whatever reason…​ (Let me know if you have an idea.)

This stops us from writing to NAND and boot Linux from there. The target contains a proper kernel and initrd, so lets build our uImage from that, chroot into it:

mount --bind /proc /target/proc
mount --bind /sys /target/sys
mount --bind /dev /target/dev
mount --bind /dev/pts /target/dev/pts
chroot /target /bin/bash

Create the uImage.

Note

this uImage is specific to the host and an uImage created on another system cannot be reused. So you might wish to add the hostname to it, i.e. vmlinux_rn104_myhost:

cd /boot
cat vmlinuz dtb > vmlinuz_rn104
mkimage -A arm -O linux -T multi -C none -a 0x04000000 -e 0x04000000 -n "Debian Buster armhf" -d vmlinuz_rn104:initrd.img uImage_rn104

Transfer (scp) this uImage_rn104 to the tftp server.

In d-i, exit, exit and Finish the installation. Then continue to reboot. System shuts down and U-Boot comes up.

Interrupt U-Boot autoboot sequence. If the screen looks garbled, reset Konsole: Shift-Ctrl-K.

Load and execute our uImage:

tftp uImage_rn104
bootm

Kernel boots, and login prompt appears. Login as root. Check if NAND flash is partitioned properly:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00180000 00020000 "u-boot"
mtd1: 00020000 00020000 "u-boot-env"
mtd2: 00600000 00020000 "uImage"
mtd3: 00400000 00020000 "minirootfs"
mtd4: 07400000 00020000 "ubifs"

This looks good now. Lets install kernel and initrd to RN104 flash. Configure flash-kernel database:

cat >> /etc/flash-kernel/db <<EOF
Machine: NETGEAR ReadyNAS 104
DTB-Id: armada-370-netgear-rn104.dtb
DTB-Append: yes
Mtd-Kernel: uImage
Mtd-Initrd: ubifs
U-Boot-Kernel-Address: 0x04000000
U-Boot-Initrd-Address: 0x06000000
Required-Packages: u-boot-tools
Bootloader-Sets-Incorrect-Root: yes
EOF

Keep initramfs size moderate and load only needed ones, this speeds up boot:

sed -i -e s/MODULES=most/MODULES=dep/ /etc/initramfs-tools/initramfs.conf

Build and flash:

update-initramfs -u -k 4.19.0-5-armmp

Reboot:

sync; reboot

Now the system boots properly from U-Boot and NAND flash into Debian Buster.

Essential packages

Log in as Root.

apt -y install u-boot-tools i2c-tools fancontrol hddtemp software-properties-common

Prepare u-boot-tools config:

cat <EOR >/etc/fw_env.config
# RN104
# MTD device name  Device offset  Env size  Flash sector size
/dev/mtd1          0x0000         0x20000    0x20000
EOR

I2c

grep i2c-dev /etc/modules || echo i2c-dev >> /etc/modules

RTC

Work in progress.

RN104 has a RS5C372 RTC, but with standard Debian kernel CONFIG_RTC_DRV_RSC372 is not set.

apt install module-assistant m-a prepare m-a update m-a a-i rtc-rs5c372

Fancontrol

We need to create /etc/fancontrol. Run pwmconfig, answer yes to run it. Yes to generate detailed correlation. Yes to setup config file. Select 1 to configure hwmon1/pwm1.

INTERVAL=10
DEVPATH=hwmon0=devices/virtual/thermal/thermal_zone0 hwmon1=devices/platform/soc/soc:internal-regs/d0011000.i2c/i2c-0/0-003e
DEVNAME=hwmon0=d0018300.thermal hwmon1=g762
FCTEMPS=hwmon1/pwm1=hwmon0/temp1_input
FCFANS= hwmon1/pwm1=hwmon1/fan1_input
MINTEMP=hwmon1/pwm1=20
MAXTEMP=hwmon1/pwm1=50
MINSTART=hwmon1/pwm1=60
MINSTOP=hwmon1/pwm1=45
MINPWM=hwmon1/pwm1=45
MAXPWM=hwmon1/pwm1=225

D-I Rescue Boot

Just in case, this is how to boot D-I in rescue mode:

setenv bootargs $console rescue/enable=true
tftp uImage-installer-rn104
bootm