Welcome! Log In Create A New Profile

Advanced

Debian on ds218play (rtl1296 cpu) - mostly working

Posted by lonestar 
Debian on ds218play (rtl1296 cpu) - mostly working
August 04, 2023 10:50AM
Hi,

Update: see guide at:
https://forum.doozan.com/read.php?2,135588,135872#msg-135872 (=later post in this thread)


back again. As I have finished my tests with the ds214 and it working as my "productive" NAS now I wanted to see whether I can get my ds218play working. This is a bit different, as it uses an Realtek rtl1296 cpu.

I managed to connect the UART to it and stop at u-boot. Attached you will find some logs for that one.

I can load files via tftp, but at the moment I am searching for a matching kernel + device tree + initrd + rootfs. Any ideas where to start?
There is some branch in u-boot which looks promising for the dts: https://github.com/afaerber/linux/blob/rtd1295-next/arch/arm64/boot/dts/realtek/rtd1296-ds418.dts The ds418 has the same cpu on it. Edit: oops, that was not u-boot but the kernel device tree

Very interestingly it uses a 2-staged bootloader with two different u-boots. Looks like a trusted-firmware system, but apparently the device is not locked.

And yes - I know that fiddling around with the device can brick it ;)
BTW: is there a similar way to boot via serial as on the kirkwood devices?

regards,
Martin



Edited 3 time(s). Last edit at 09/29/2023 09:12AM by lonestar.
Attachments:
open | download - boot.log (7.4 KB)
open | download - uboot.env (3.1 KB)
open | download - dmesg.txt (39.8 KB)
Re: Debian on ds218play (rtl1296 cpu) - work in progress
August 07, 2023 12:07PM
I did some further tests and even found the original kernel config of synology in their gpl sources.
Unfortunately when I use this config on an 6.0.8 kernel the kernel gets quite big (>20MB)

u-boot seems to only support the typical 8MB image, as I get "Loading Kernel Image ... Image too large: increase CONFIG_SYS_BOOTM_LEN".
As I want to avoid having to flash the u-boot instances I will have to downsize the kernel.

So far I have gotten down to 8.84MiB.

My current workflow:
- compile kernel and create uImage with the dtb from the kernel tree (rtd1296-ds418.dtb)
- in the first u-boot use tftp to load the uImage to ram. I currently ignore the initrd as I am not there yet.
- the I use bootr to switch to the second u-boot.
- in the second u-boot I call bootm to boot the image.

Note that the first u-boot does not support bootm and the second one does not support tftp.

I attach my current kernel config, where I hopefully didn't deactivate anything I need and where I still need to find further stuff that can be safely disabled. So if anyone wants to take a look and has some ideas, I am happy :)

.config_downsizing is my current state
rtd1296_kernel_config is the original from the gpl source.

regards,
Martin
Attachments:
open | download - .config_downsizing (128.8 KB)
open | download - rtd1296_kernel_config (149.9 KB)
Re: Debian on ds218play (rtl1296 cpu) - work in progress
August 07, 2023 01:48PM
I spent a little time looking at some similar devices running a RTD1195 and RTD1619 (Buffalo Linkstation LS500 and LS700). I ran into the reference to that two stage u-boot needed for the device-tree's in the mainline kernel but hadn't gotten around to finding it yet.

I don't have much to add at this point but I'm glad to see someone taking a look!
Re: Debian on ds218play (rtl1296 cpu) - work in progress
September 29, 2023 09:11AM
1) Goal:

I wanted to boot debian on my ds218play. Final idea is to have a NAS with an 4 TB SSD and a 6 TB HDD, where the HDD can shut down when unused (and not spin up for several days).

Additionally I wanted to limit the changes to the NAS as much as possible. During tests with my other NAS (ds214) I had issues when saving the u-boot environment, so I wanted to keep this as-is.

As a result I use a method where I only need to change the kernel. I reuse the device tree which is loaded from the flash.

2) Installation:

2.1) Precondition
Make sure to back up the content of you flash device before flashing anything to the NAS.
To do this log in to ssh (can be enabled in the synology software.
Then do a "dd if=/dev/mtdX of=mtdX.dump" for all the 5 flash partitions (X=0-4).

2.2) Serial adapter
See the attached image on how to connect the PINs to the NAS.
GND (blue), TX (yellow), RX (orange)

3) Compile kernel:

3.1) get toolchain
I took the original toolchain from https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%206.2.4%20Tool%20Chains/Realtek%20RTD129x%20Linux%204.4.59/

unpack it and set the path:
export PATH=".../gcc494_glibc220/aarch64-unknown-linux-gnueabi/bin:$PATH"

I used the original toolchain as the kernel is a bit smaller than with a recent compiler.

3.2) compile kernel
I took the original kernel from https://archive.synology.com/download/ToolChain/Synology%20NAS%20GPL%20Source/6.2-25556 -> linux-4.4.x.txz (the rtd1296 version)
The I changes a few things:
- disabled initrd support, so that it ignores the initrd which is passed by u-boot. I can boot debian without the initrd and load the modules later if needed.
- fixed the kernel command line string to "ip=off console=ttyS0,115200 root=/dev/sdb1 rw syno_hdd_enable=85,86 syno_usb_vbus_gpio=23@xhci-hcd.2.auto@0,22@xhci-hcd.5.auto@0 syno_hw_version=DS218play hd_power_on_seq=2 ihd_num=2 netif_num=1 phys_memsize=1024 audio_version=1012363 syno_fw_version=M.306" which is basically the synology u-boot string with the added "root=/dev/sdb1" option. Change this to the location of you root device.
- some other minor changes

see attached kernel config.

CROSS_COMPILE=aarch64-unknown-linux-gnueabi- ARCH=arm64 make menuconfig
- change the settings as you like

CROSS_COMPILE=aarch64-unknown-linux-gnueabi- ARCH=arm64 make -j8 Image.gz
- cross your fingers and compile it.
# important: use the uncompressed image here!!!
# resulting Image.lzma needs to be below ~3000000 bytes
lzma --compress -c arch/arm64/boot/Image > /tmp/Image.lzma


now for the modules:
CROSS_COMPILE=aarch64-unknown-linux-gnueabi- ARCH=arm64 make -j8 modules
mkdir /tmp/modules
CROSS_COMPILE=aarch64-unknown-linux-gnueabi- ARCH=arm64 make modules_install INSTALL_MOD_PATH=/tmp/modules
as root: chmod -R root:root /tmp/modules
cd /tmp/modules ; tar cpzf .../modules.tgz .
we can copy this to the image later, to have the kernel modules available.

4) prepare rootfs
use debootstrap to create a root filesystem. Make sure you have the qemu-user-static installed, as this allows us to execute code as if we were on an arm64 device.

5) Test the new kernel

Install a tftp server on your machine.
Plug in the network cable.
To boot into the first u-boot prompt hold "Space" and plug in the NAS power supply.

# prepare network
env set ipaddr 192.168.1.230
env set serverip 192.168.1.20

# load kernel
tftp 0x0b000000 Image.lzma
# we use the compressed kernel here as we will later flash this and we want to be as close as possible here.
lzmadec 0x0b000000 0x03000000 0x002f0000

# sets bootargs, but those will be ignored as compiled into kernel
run syno_bootargs

rtkspi read 0x000c0000 0x0b000000 0x00040000;lzmadec 0x0b000000 0x01b00000 0x00040000;
#fdt
rtkspi read 0x00000000 0x01f00000 0x00010000;
#initrd -> wil be ignored as no kernel support
rtkspi read 0x003f0000 0x02200000 0x003ff000

# this will boot to the second u-boot and immediately load your kernel.
env set bootcmd bootr;bootr

it should boot to linux now...

6) Make the setup permanent

# prepare network
env set ipaddr 192.168.1.230
env set serverip 192.168.1.20

# load kernel
tftp 0x0b000000 Image.lzma

rtkspi erase 0x00100000 0x002f0000
rtkspi write 0x00100000 0x0b000000 0x002f0000

Now you should always boot to your own linux. To go back to the original firmware (=kernel) just use tftp to load the mtd1.dump from above and flash it the same way.

7) Current state

Working
- booting from flash to internal sata disk works, both disks recognized.
- ethernet works

Not working
- fan speed control (no device detected, synology seems to do this not with the kernel mechanisms, but directly)
- LEDs
- reboot from linux (hangs, needs power cycle)
- mac address is 00:10:20:30:40:50 (yet this is no real issue)

Untested
- USB

Stuff the should be done (but maybe I won't):
- port synology changes to recent kernel
- make an initrd for this setup
- check device tree from synology

Hopefully thats all.

Good luck,
Martin
Attachments:
open | download - config-working (130.1 KB)
open | download - uart_small.jpg (857.9 KB)
Re: Debian on ds218play (rtl1296 cpu) - mostly working
November 05, 2023 03:29AM
Ok, my project is now finished:

The site https://smallhacks.wordpress.com/2012/04/17/working-with-synology-hardware-devsynobios-and-devttys1/
helps a lot about controlling LEDs and FAN.

printf "V10" > /dev/ttyS1
sets the fan speed to 10%

printf "\\x38" > /dev/ttyS1
sets the status LED green.

The site has further constants which can be used to control the LED.

I attached my current fancontrol script, which changes fan speed based on CPU temperature.
Attachments:
open | download - fancontrol.sh (2.1 KB)
Re: Debian on ds218play (rtl1296 cpu) - mostly working
November 05, 2023 12:59PM
Martin,

Thanks for sharing!


> helps a lot about controlling LEDs and FAN.
>
> printf "V10" > /dev/ttyS1
> sets the fan speed to 10%
>
> printf "\\x38" > /dev/ttyS1
> sets the status LED green.

Looks like it's similar to as other Synology boxes. Except that the older boxes use gpio-fan, and UART1 for other commands. Is the PIC16F1829 in this box or other PIC?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Debian on ds218play (rtl1296 cpu) - mostly working
November 05, 2023 02:52PM
Hi bodhi,

unfortunately I don't know how to tell. To take a closer look at the board I would have to dismantle it, which I so far have avoided.
Is there some easier way?

regards,
Martin
Re: Debian on ds218play (rtl1296 cpu) - mostly working
November 05, 2023 03:52PM
Martin,

> unfortunately I don't know how to tell.

> To take a
> closer look at the board I would have to dismantle
> it, which I so far have avoided.
> Is there some easier way?

I don't know either :) The Synology NAS DTSs have documentation for the PIC16F1829 so I thought it's probably somewhere with this box's documentation.

It is not an uncommon HW feature but people don't always document it.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Debian on ds218play (rtl1296 cpu) - work in progress
November 05, 2023 04:24PM
Martin,

https://forum.doozan.com/read.php?2,135588,135872#msg-135872

I did not see you mentioned whether you are using the DTB extracted from stock FW, or using a mainline kernel DTS. If you are using stock DTB, it might be a good idea to attach it to that installtion post.

Also a complete serial boot log (or dmesg log) would be very helpful.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 2 time(s). Last edit at 11/06/2023 12:05AM by bodhi.
Re: Debian on ds218play (rtl1296 cpu) - work in progress
November 07, 2023 01:45PM
Hi bodhi,

I never extracted the dtb from the nas, I am using the stock one, which is automatically loaded by u-boot. I only changed the kernel image and nothing else to avoid breaking the boot process.

I didn't find any documentation regarding the PIC.

I attach the dmesg log of the debian boot to this post.

regards,
Martin
Attachments:
open | download - dmesg.txt (41.9 KB)
Re: Debian on ds218play (rtl1296 cpu) - work in progress
November 07, 2023 02:26PM
Hi Martin,

> I never extracted the dtb from the nas, I am using
> the stock one, which is automatically loaded by
> u-boot. I only changed the kernel image and
> nothing else to avoid breaking the boot process.

Cool! and thanks for the log.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Debian on ds218play (rtl1296 cpu) - work in progress
November 07, 2023 02:38PM
Added to the Wiki thread.

Quote

Realtek SoCs NAS

Debian on Synology DS218play (Realtek SoC RTL1296)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: