Need help migrating Kirkwood QNAP NAS from Debian to Arch

This forum is for Marvell Kirkwood devices such as the GoFlex Home/Net, PogoPlug v1/v2, SheevaPlug, and ZyXEL devices.

Need help migrating Kirkwood QNAP NAS from Debian to Arch

Postby stereotype » Tue Aug 03, 2021 2:03 am

Hi there :)

I have a couple of Kirkwood QNAPs (HS-210) currently running Debian 10 / Buster.
However, the next version of Debian won't be supporting this hardware anymore, as per the announcement here:
https://www.cyrius.com/debian/kirkwood/qnap/ts-219/
Seeing I've long wanted to move to Arch anyway, this now gives me the proper incentive to do so.

Currently, my MTD partitions are set up like this:

mtdblock0 / uboot / 524288 bytes
mtdblock4 / uboot conf / 262144 bytes
mtdblock5 / ext2 unused* / 1310720 bytes
mtdblock1 / debian kernel / 2097152 bytes
mtdblock2 / debian initrd / 9437184 bytes
mtdblock3 / ext2 unused* / 3145728 bytes

*The unused partitions are QNAP legacy from the original firmware...

However, the ArchLinuxARM-2021.07-kirkwood-rootfs.tar.gz image sizes are as follows:

initramfs-linux.img / 7071796 bytes
uImage / 4661632 bytes

Meaning the Arch images are much bigger then what the current partitioning scheme allows.
Which probably means I need to resize the MTD partitions, and this is where I need some help / advice, having never done that.

Also, the uboot provided by QNAP seems to be limited to booting kernels from flash only.
Which also probably means I should consider updating uboot?
And if that's the case, I could probably start with a fresh new partition layout, since I need none of what's there now I suppose?

What would be the best path forward?
What are the correct steps to install moonman's uboot v2016.09 on such a device?
And how does one goes about defining a new MTD partition layout in such a scenario?

I don't have access to a serial cable, and plan to do most of the work from within the working Debian install.
I have taken backups of the current firmware, and should be able to restore them if anything goes wrong.
Any help or insights would be greatly appreciated.

Thank you very much in advance... :)


PS: Current uboot conf details:

baudrate=115200
loads_echo=0
ipaddr=192.168.0.50
serverip=192.168.0.1
rootpath=/mnt/ARM_FS/
netmask=255.255.255.0
run_diag=yes
console=console=ttyS0,115200
CASset=min
MALLOC_len=1
ethprime=egiga0
bootargs=console=ttyS0,115200 root=/dev/ram initrd=0xa00000,0x900000 ramdisk=34816
bootcmd=uart1 0x68;cp.l 0xf8200000 0x800000 0x80000;cp.l 0xf8400000 0xa00000 0x240000;bootm 0x800000
ethaddr=00:01:02:03:04:05
ethmtu=1500
usb0Mode=host
netretry=no
rcvrip=169.254.100.100
loadaddr=0x02000000
autoload=no
ethact=egiga0
stdin=serial
stdout=serial
stderr=serial
mainlineLinux=no
enaMonExt=no
enaCpuStream=no
enaWrAllo=no
pexMode=RC
disL2Cache=no
setL2CacheWT=yes
disL2Prefetch=yes
enaICPref=yes
enaDCPref=yes
sata_dma_mode=yes
netbsd_en=no
bootdelay=1
disaMvPnp=no
enaAutoRecovery=yes
pcieTune=no
stereotype
 
Posts: 4
Joined: Tue Jul 20, 2021 1:49 am

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby summers » Tue Aug 03, 2021 8:43 am

As you can access uboot, and have a kernel. The usual starting place is to extract the arch root fs onto an HDD, then use the kernel that the box came with, and point root to the HDD.

This should be enough to boot.

Don't know if the kirkwood uboot has been adapted for you box. Probably easiest to see what you current uboot does. command "help" IIRC lists all commands that you have.

Updating the kernel, well main hurdle is the availability of a device tree for you box, if it exists, and you can pass it to the kernel, then you should be able to boot a modern kernel. Some seem available, e.g:

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/arch/arm/boot/dts/kirkwood-ts419.dtsi

So question is exactly which qnap device you have ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby stereotype » Fri Aug 06, 2021 5:03 am

Thanks for your input, much appreciated.

The device I'm dealing with is a QNAP model HS-210, as mentioned in the top of the post.
A conf file from the original firmware has the following entries:
Model = HS-210
Internal Model = TS-219
Which probably means it's pretty much a TS-219 in a different housing.

How can I check what uboot can do on this box as you suggest? I don't have a serial cable...

I'm aware of this guide here:
https://ramblings.silveira.ws/2014/03/i ... s-212.html
Which was done on very similar hardware, except mine has 512MB RAM.
However, that guide doesn't seem to flash the initrd image like Debian does, and I wonder what the implications are...
Perhaps the arch kernel has enough built-in modules to load initrd from the OS volume itself?
stereotype
 
Posts: 4
Joined: Tue Jul 20, 2021 1:49 am

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby summers » Fri Aug 06, 2021 7:16 am

Ah yes - more information on ts219!

I'd really advise you to get a 3.3V UART cable, I have https://uk.farnell.com/ftdi/ttl-232r-rpi/cable-debug-ttl-232-usb-rpi/dp/2147356# - the ftdi chipset ones are well respected.

The reason to get this cable, is it will give direct access to uboot - and that means you can try things, without bricking the machine. As much as anything changing the stored enviroment variables, e.g with $this->bbcode_second_pass_code('', 'fw_setenv') - and if you get one thing wrong, the machine doesn't boot! I know what I'm doing (reasonably) but still ended up doing a typo when setting env variables on my nsa325 - so had to get the serial cable anyway!

At least with a cable, you can ask uboot to look at the hdd, check you can see the boot partition. Then change the bootargs in memory (e.g. not change the flash env variables). And see if it boots. Even if you get it wrong, next reboot - and it will just revert to what is on the flash!

Looks like the TS219 already has the UART headers mounted on the board: https://www.cyrius.com/debian/kirkwood/qnap/ts-219/serial/.

If you do end up going in the direction of a modern kernel (this is some way down the road) - then looks like device tree exist for TS219, e.g. https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/kirkwood-ts219-6281.dts.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby stereotype » Sat Aug 07, 2021 3:54 am

Thank you.

Indeed it makes a lot of sense to get the UART cable, and I'm about to order one.
I have actually done kernel work in the past while importing a USB driver stack onto a somewhat niche OS, and used a UART terminal extensively for debugging etc.
I was hesitating here cause I'm about to go on an extended business trip and it may be too late by the time the cable arrives.
But seeing I'll probably have some time on my hands while away, I might just take one of the NAS boxes with me.
I'm currently on kernel 4.19 and wanted to be on 5.10 to take advantage of some new btrfs features and migrate some data before my trip, but I suppose that will have to wait until I'm back around Xmas time...

With regards to MTD repartitioning, any insights on how that would work in practical terms?
I suspect both uboot and the kernel would have their own partition mappings?

Also, would the uboot v2016.09 released by moonman here work on this NAS?
I see he provided no instructions, should I ping him directly for further information?

Thanks again...
stereotype
 
Posts: 4
Joined: Tue Jul 20, 2021 1:49 am

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby summers » Sat Aug 07, 2021 6:15 am

You've a couple of questions there, MTD devices, and uboot. I'll deal with them in separate posts. So here MTD devices.

Flash doesn't have a partition table like HDD usually has - its just a block device with bytes you can read from it. The CPU when it boots, has some boot logic directly in the CPU - that tells it to run a *very* specific location on the flash - and thats where uboot lives. So uboot *has* to be at that location.

Uboot then loads the kernel from flash - that we can't see from your env variables. It then executes the kernel.

Now the kernel in the old world always used to on the command line describe the flash. E.g. on mu NSA325:
$this->bbcode_second_pass_code('', 'cat /proc/cmdline
console=ttyS0,115200 mtdparts=orion_nand:0xC0000(uboot),0x40000(uboot_env),0x80000(old_uboot_env),0x80000(key_store),0x80000(info),0xA00000(etc),0xA00000(kernel_1),0x2FC0000(rootfs1),0xA00000(kernel_2),0x2FC0000(rootfs2) root=PARTUUID=94a2dc27-01 rw rootwait')
And you can see the mtdpart - that is setting up where on the flash it draws the lines between the mtd partitions. And thats what happens - the kernel draws some arbitrary lines, to give the partitions. These could be changed, and the partitions would change (but not the data on the flash!)

Now its a bit more complex, in the modern world, the flash layout is usually described in the device tree as well. I'm not sure if the kernel respects this. E.g. for the TS219 we have:
https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/kirkwood-ts219.dtsi
And you can see the flash layout described there. Now the kernel *may* use that to set the partitions, but whats clear is that the mtdparts command line takes priority. So thats what I current use on my NSA325.

Now why does the kernel just set some arbitrary lines to cut the flash up into partitions. Really its just so its convenient to access it, so kernel, and uboot, and env variables have their own areas, and tools to access those areas. Now if you want to make the kernel area larger - thats a hassle. You either need to change the mtdparts command line when you boot - or need to split the kernel up into partition sized chunks - and then write the chunks to to the respective MTD partitions.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby summers » Sat Aug 07, 2021 6:57 am

Now onto uboot. Yes @moonman did the latest arch version, but IIRC @WarheadsSE did the original version. Its then complicated becuase bohdi also develops one here : https://forum.doozan.com/read.php?3,12381. Now whats clear is that kirkwood uboot hasn't been mainlined. I looked at doing this, but its complicated becuase of how the marvel cpu are described in the modern kernel, and how pinctl has changed in the modern kernel.

Anyway - no, you can't just take their uboot, and use it. uboot is configured to know where to find the various bits of hardware, so flash, ide controllers etc. Now QNAP NAS may not be wired up like my NSA325, or a sheevaplug etc.

Probably an idea to reach out to bohdi etc - as to how much variety there is in kirkwood boards, and what information you need to get - to even get it into the arch or bohdi versions. BTW - to my mind these aren't really maintained; they were got to a working state - and thats all that was needed to boot the kernel. And work stopped there.

Realistically though uboot is the last thing to update, firstly as long as the original uboot is there and working, you have a way into the machine. Then as long as uboot, can load the kernel - and you can boot.

I'll put some more in this post when I get time - of where the important bits are in uboot - and why not so straight forward to change to an QNAP NAS.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby summers » Sat Aug 07, 2021 11:45 am

So its worth going through what is needed to set up uboot for a box - and why it isn't trivial to use one version on a different box. Might as well work from @moonman version: https://github.com/moonman/u-boot - and for an example look at sheevaplug - as its kirkwood, and was one of the first uboot was set up for.

First a configuration file is needed: https://github.com/moonman/u-boot/blob/2016.09/configs/sheevaplug_defconfig - and most of that could probably be used on a QNAP NAS.

Certain options are set up in: https://github.com/moonman/u-boot/blob/2016.09/include/configs/sheevaplug.h - and you can see some things, like the device tree set up as environment variable would need changing for the QNAP NAS.

Then there is low level code to set up the board: https://github.com/moonman/u-boot/tree/2016.09/board/Marvell/sheevaplug, you can see its setting up the memory type, its setting up how the CPU pins are wired, how the ethernet is done, how leds are wired etc.

Now for the QNAP NAS at least some of this would change, e.g. how close is the QNAP NAS to a reference design. Also to make it worse, if you look at moving to a modern uboot - and you'll find the whole set up has evolved - uboot is now far more device tree based. So if you want to go modern, its more work - but more easily maintainable, and moved between different boxes - but much of this work for kirkwood in mainline, hasn't been done yet.

So getting a updated uboot for QNAP NAS is a bit of work, and you need to know what you are doing ....
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Need help migrating Kirkwood QNAP NAS from Debian to Arc

Postby stereotype » Thu Aug 12, 2021 7:30 am

Thank you very much for all that info, much appreciated indeed.

I've got the UART cable on the way, might arrive in a week or so.

I think the main blocker atm are the MTD partitions.
But if I don't really need initrd to be flashed onto NAND, then I suppose I have enough space for the kernel only using the larger of those partitions.
From then on it's just a matter of updating uboot's conf, which should be easy having the UART cable etc.

I'll have to weigh in whether it is worth trying to update uboot, but the above should be enough to get arch running.

Thanks once again. I'll update the thread as things progress...
stereotype
 
Posts: 4
Joined: Tue Jul 20, 2021 1:49 am


Return to Marvell Kirkwood

Who is online

Users browsing this forum: No registered users and 7 guests