Welcome! Log In Create A New Profile

Advanced

Debian on Zyxel NAS326

Posted by Kirsch 
Re: Zyxel NAS326 - Debian / Boot from USB?
January 27, 2017 05:30AM
Does anyone know how to enable SSH or telnet in stock OS without using serial console?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 27, 2017 05:42AM
Quote
bodhi
Does anyone know how to enable SSH or telnet in stock OS without using serial console?

There's a "universal_usb_key_func" toolkit. Download from here. It includes a script to enable telnet + README file inside. You can just launch your code from USB drive even without telnet.
More documentation how usb_key_func.sh works.

Quote
bodhi
BTW, one thing that we have not figured out is which MCU this box has, I don't recall.

I believe it was in the bootlog (SoC: MV88F6810 Rev A0 = Single Core up to 2.0GHz Armada 38x, running at 1332MHz):
Board: RD-NAS-88F6820-DDR3
SoC:   MV88F6810 Rev A0
       running 1 CPUs
CPU:   ARM Cortex A9 MPCore (Rev 1) LE
       CPU 0
       CPU    @ 1332 [MHz]
       L2     @ 666 [MHz]
       TClock @ 250 [MHz]
       DDR    @ 666 [MHz]
       DDR 32 Bit Width, FastPath Memory Access, DLB Enabled, ECC Disabled
DRAM:  512 MiB
NAND:  256 MiB

$ cat /proc/cpuinfo 
processor	: 0
model name	: ARMv7 Processor rev 1 (v7l)
BogoMIPS	: 50.00
Features	: half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x4
CPU part	: 0xc09
CPU revision	: 1

Hardware	: Marvell Armada 380/385 (Device Tree)



Edited 4 time(s). Last edit at 01/29/2017 06:01PM by rr4m.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 27, 2017 06:45AM
rr4m,

Thanks!

I've figured out a foolproof way to boot from USB (therefore also HDD) automatically without serial console input! I'll post that shortly after some more testing.

That's why I want to see telnet/ssh behave so I can write the instruction to allow users without serial console to set up to boot USB. With a giant disclaimer, of course :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 27, 2017 07:29AM
You're welcome!
Re: Zyxel NAS326 - Debian / Boot from USB?
January 27, 2017 11:03PM
This is step 4 in the release thread for how to set envs to run the rootfs from USB or HDD without serial console intervention.

And please note that this u-boot hack is ony for the Zyxel NAS326, it will not work for different MVEBU NAS, or any NAS :). Doing this on a different box without examining its stock u-boot source code will very likely brick it!


Quote

4. Enter the following commands (copy and paste to the console prompt):

setenv usb_init 'mw.l f1018100 20420000; mw.l f1018140 003E8800; sleep 3; usb start'
setenv usb_set_bootargs 'setenv bootargs "console=ttyS0,115200 root=LABEL=rootfs rootdelay=10 $mtdparts earlyprintk=serial"'
setenv usb_bootcmd 'echo Booting from USB ...; setenv fdt_skip_update yes; run usb_init; ext2load usb 0:1 0x800000 /boot/uImage; ext2load usb 0:1 0x1100000 /boot/uInitrd;  ext2load usb 0:1 0x1c00000 /boot/dts/armada-380-zyxel-nas326.dtb;  run usb_set_bootargs; bootm  0x800000 0x1100000 0x1c00000'
setenv curr_bootfrom 1
setenv next_bootfrom 1
setenv set_bootargs_stock 'setenv bootargs "console=ttyS0,115200 ubi.mtd=4,2048 rootfstype=ubifs root=ubi0:rootfs1 rw rootdelay=2"'
setenv bootcmd_stock_1 'run set_bootargs_stock; echo Booting from NAND kernel 1 ...; nand read 0x2000000 0x00E00000 0xF00000 && bootz 0x2000000'
setenv bootcmd_stock_2 'run set_bootargs_stock; echo Booting from NAND kernel 2 ...; nand read 0x2000000 0x08700000 0xF00000 && bootz 0x2000000'
setenv bootcmd_custom 'if run usb_bootcmd; then; else if run bootcmd_stock_1; then; else run bootcmd_stock_2; reset; fi; fi'
setenv kernel_addr_1 '0x00000000; run bootcmd_custom; '
saveenv

and then
boot

And see sections below step 4 for how to reseve this back to stock.

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



Edited 2 time(s). Last edit at 01/28/2017 01:04AM by bodhi.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 28, 2017 09:48AM
Random question time:

Is there anything that can be done to enable ECC? I've seen Armada 38x have ECC support.
https://origin-www.marvell.com/embedded-processors/armada-38x/

I'm probably a nut, but I'd like to have ECC in a server, even if it eats up some RAM.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 29, 2017 02:55AM
bobafetthotmail Wrote:
-------------------------------------------------------
> Random question time:
>
> Is there anything that can be done to enable ECC?
> I've seen Armada 38x have ECC support.
> https://origin-www.marvell.com/embedded-processors
> /armada-38x/
>
> I'm probably a nut, but I'd like to have ECC in a
> server, even if it eats up some RAM.

I never give this much thought, I guess since Zyxel disabled it in u-boot, it must have regular RAM. It could be enable in u-boot if the hardware supports it.

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



Edited 1 time(s). Last edit at 01/29/2017 02:56AM by bodhi.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 29, 2017 03:43AM
bodhi Wrote:
-------------------------------------------------------
> bobafetthotmail Wrote:
> --------------------------------------------------
> -----
> > Random question time:
> >
> > Is there anything that can be done to enable ECC
> ?
> > I've seen Armada 38x have ECC support.
> > https://origin-www.marvell.com/embedded-processo
> rs
> > /armada-38x/
> >
> > I'm probably a nut, but I'd like to have ECC in
> a
> > server, even if it eats up some RAM.
>
> I never give this much thought, I guess since Zyxe
> l disabled it in u-boot, it must have regular RAM.
> It could be enable in u-boot if the hardware suppo
> rts it.

Afaik there is no "ECC ram" chips, ECC ram banks on PCs have one additional RAM chip to compensate for the space taken up by parity bits, but the ECC is handled by the ram controller itself.

I think (hope) that if you enable ECC on this box you will lose some of the available RAM due to space used by parity, but it should otherwise work. But being this an embedded system it might need more setup code than on PCs where it's all handled by board firmware, I don't know.

There is also a linux driver for error detection in Linux if ECC is enabled in hardware, but it is not required for ECC to work, it's just for Linux to detect the errors. https://github.com/MarvellEmbeddedProcessors/linux-marvell/blob/c8ae519736bba6de02ace596b438f14d168648ae/drivers/edac/highbank_mc_edac.c

If you don't want to do this because you aren't interested in this feature, it's fine for me, I'm not asking you to work for free. :)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 29, 2017 04:41AM
> Afaik there is no "ECC ram" chips, ECC ram banks o
> n PCs have one additional RAM chip to compensate f
> or the space taken up by parity bits, but the ECC
> is handled by the ram controller itself.

I thought so too. But I did not look at the board for this so I don't really know.

> I think (hope) that if you enable ECC on this box
> you will lose some of the available RAM due to spa
> ce used by parity, but it should otherwise work. B
> ut being this an embedded system it might need mor
> e setup code than on PCs where it's all handled by
> board firmware, I don't know.
>
> There is also a linux driver for error detection i
> n Linux if ECC is enabled in hardware, but it is n
> ot required for ECC to work, it's just for Linux t
> o detect the errors. https://github.com/MarvellEmb
> eddedProcessors/linux-marvell/blob/c8ae519736bba6d
> e02ace596b438f14d168648ae/drivers/edac/highbank_mc
> _edac.c
>
> If you don't want to do this because you aren't in
> terested in this feature, it's fine for me, I'm no
> t asking you to work for free. :)

I know :) We are only speculating here so no works spent :) If we were to investigate this, the 1st thing we need is to successfully kwboot the box. The 2nd is enabling ECC in the new uboot.

But the big hurdle now is kwboot does not work. So I have not even bother start building new u-boot for it. I don't have NDA with Marvell so I can't get any hint (i.e. bootROM 1.73 source code) from them. I can't use my work email to register (Marvell's requirement).

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 30, 2017 01:45AM
bodhi Wrote:
-------------------------------------------------------
> If we were to investigate this, the 1st t
> hing we need is to successfully kwboot the box.
>
> But the big hurdle now is kwboot does not work.

What is missing for that?

Meanwhile, I've found something random by googling.

binary uboots and kwboot sources for kwbooting a non-descript marvell Armada 38x board https://github.com/nitroshift/armada-38x-bootloader-recovery-files

The patch that added kwboot support for armada 38X in uboot sources https://patchwork.ozlabs.org/patch/510488/

this wiki page of solid-run that deals with clearfrog, a armada 388 board with info about what to do to get uart booting in the "Booting the uart version of u-boot" paragraph and link to a script they use (that sends magic numbers that might work for you too).
http://wiki.solid-run.com/doku.php?id=products:a38x:software:development:u-boot



Edited 4 time(s). Last edit at 01/30/2017 02:18AM by bobafetthotmail.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 30, 2017 03:10AM
bobafetthotmail,

Thanks for the info!

> binary uboots and kwboot sources for kwbooting a n
> on-descript marvell Armada 38x board https://githu
> b.com/nitroshift/armada-38x-bootloader-recovery-fi
> les
>
> The patch that added kwboot support for armada 38X
> in uboot sources https://patchwork.ozlabs.org/patc
> h/510488/

I've seen these files. But have not tried them. What I have tried was the u-boot uart image I built from Zyxel GPL source. I also tried a new SPL image from mainline build for a38x.

>
> this wiki page of solid-run that deals with clearf
> rog, a armada 388 board with info about what to do
> to get uart booting in the "Booting the uart versi
> on of u-boot" paragraph and link to a script they
> use (that sends magic numbers that might work for
> you too).
> http://wiki.solid-run.com/doku.php?id=products:a38
> x:software:development:u-boot

This is interesting. That download-serial.sh script basically does what kwboot does in the beginning. The magic number sequence is well known (bb, 11,...). All Marvell SoC BootROM implement this.

But they did it in 2 steps. This must have been during development. In the final product, Clearfog have a DIP switch that can be used to set the SAR (sample at reset) register to always boot from UART. This is the reason their UART booting always work (the handshake is not needed).

kwboot does this all within itsefl: in a loop, send magic sequence numbers, and then wait for a NAK, if received the NAK exit the loop . And then send the payload.

The real problem is my kwboot runs never successful caught a NAK coming back from the NAS326, so no handshake occured.

excerpts from the attaches kwboot.c file.
static unsigned char kwboot_msg_boot[] = {
	0xBB, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
};
case 'b':
			bootmsg = kwboot_msg_boot;
			imgpath = optarg;
			break;
rc = kwboot_bootmsg(tty, bootmsg);
		if (rc) {
			perror("bootmsg");
			goto out;
		}


kwboot_bootmsg(int tty, void *msg)
{
	int rc;
	char c;

	if (msg == NULL)
		kwboot_printv("Please reboot the target into UART boot mode...");
	else
		kwboot_printv("Sending boot message. Please reboot the target...");

	do {
		rc = tcflush(tty, TCIOFLUSH);
		if (rc)
			break;

		rc = kwboot_tty_send(tty, msg, 8);
		if (rc) {
			usleep(msg_req_delay * 1000);
			continue;
		}

		rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo);

		kwboot_spinner();

	} while (rc || c != NAK);

	kwboot_printv("\n");

	return rc;
}

I think the key to get it running successfully is in the -q (msg_req_delay) and -s (msg_rsp_timeo) timeout values , which we can provide as optargs to kwboot. But this is a very tedious trial and erorr test with the range from 1 to n.

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



Edited 3 time(s). Last edit at 01/30/2017 03:35AM by bodhi.
Attachments:
open | download - kwboot.c (13.7 KB)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 30, 2017 06:09AM
bodhi Wrote:
-------------------------------------------------------
> I think the key to get it running successfully is
> in the -q (msg_req_delay) and -s (msg_rsp_timeo) t
> imeout values , which we can provide as optargs to
> kwboot. But this is a very tedious trial and erorr
> test with the range from 1 to n.

I think the c program in the script could be modified/used to get this info. Apart from DELAY const that looks like what msg_req_delay should be (if it was not multiplied by 1000), the script just spams the magic numbers 6000 times, checks the nack and repeat.

It seems like they didn't know what were the right values for kwbooting either.

Failing that, i would automate the test you said.
I would use a usb power relay (usb-controlled power switch, basically), put a brick on the power button on the NAS to keep it pressed, and set a script on the linux system to turn on the power, do the test with kwboot, if it fails shut down power relay, and repeat the cycle with next values. A kirkwood box is good enough for this job too.

I use some cheap chinese boards supported by crelay https://github.com/ondrej1024/crelay (also supports other relay boards) for other home automation projects that involve flipping switches remotely.



Edited 2 time(s). Last edit at 01/30/2017 06:30AM by bobafetthotmail.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 30, 2017 01:32PM
bobafetthotmail,

> It seems like they didn't know what were the right
> values for kwbooting either.

Right. Each board has different set of q/s values. That's the reason why Stefan Roese added these optargs. It seems the BootROM logic is not very robust in the handshaking part. People have to guess the right values. So the SAR approach is a way to eliminate this unknown.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 31, 2017 12:20AM
bobafetthotmail,

> I use some cheap chinese boards supported by crela
> y https://github.com/ondrej1024/crelay (also suppo
> rts other relay boards) for other home automation
> projects that involve flipping switches remotely.

This looks like a really good approach for testing if I can find it cheap enough :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
January 31, 2017 03:37AM
bodhi Wrote:
-------------------------------------------------------
>
> This looks like a really good approach for testing
> if I can find it cheap enough :)

The chinese boards are found under the link "HID API compatible relay cards (1/2/4/8 channel)" in the github readme, they cost around 5$ for a 2-switch board.
This is one of the many many many chinese sellers selling the same boards I also use http://www.ebay.com/itm/5V-USB-Relay-2-Channel-Programmable-Computer-Control-For-Smart-Home-New/400985242702

The non-chinese ones are more expensive but are shipped faster.
Re: Zyxel NAS326 - Debian / Boot from USB?
January 31, 2017 04:05AM
Thanks, for a dirt cheap 6 bucks, I'll get one :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
February 02, 2017 03:47AM
> I also use http://www.ebay.com/itm/5V-USB-Relay-2-Channel-Programmable-Computer-Control-For-Smart-Home-New/400985242702

Ordered one. It's a slow boat from China so will revisit this in a few weeks or so :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
February 04, 2017 03:59PM
I'm done building this kernel and rootfs. The known problem with SPI will need to be fixed in u-boot. The ethernet MAC address problem probably will be fixed in next kernel release (so we don't have to hard code it in /etc/network/interfaces).

Will upload new rootfs and new instruction for NSA326 soon in the release thread.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
February 05, 2017 04:57PM
Please see the release thread for the new rootfs and updated installation procedure.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
February 05, 2017 06:52PM
I've recently found an interesting blog - a guy launches Debian on different Netgear NAS devices.

The following article is about Debian on Netgear ReadyNAS 102 (Armada 370 based one). He also gathered Marvell's docs I was looking for (Armada 370 functional spec + Armada 370 hardware spec pdfs) - from those times when they were publicly available with no restriction, no registration and no NDA.

Take a look - there are things to learn.
jochen
Re: Zyxel NAS326 - Debian / Boot from USB?
February 16, 2017 02:46PM
bodhi Wrote:
-------------------------------------------------------
> Does anyone know how to enable SSH or telnet in st
> ock OS without using serial console?

Hi Bodhi,

you can enable SSH or Telnet through the web-interface. Just go to Control Panel -> Terminal -> Enable SSH/Telnet Service.

I bought a NAS326 after reading here about the successfull work. Now I wonder, can you tell me how to boot the debian rootfs from usb without opening the case and attaching the serial console?

I'd really appreciate your help!

Kind regards,
Jochen
Re: Zyxel NAS326 - Debian / Boot from USB?
February 16, 2017 03:19PM
Jochen,

Thanks for pointing this out! I was thinking about using the USB script to do this (because it also serves as a recovery path when things go wrong). But web interface would be a more friendly way. So perhaps I will write installation instruction starting with this option.

In the release thread: http://forum.doozan.com/read.php?2,32146,
I've mentioned section B:

Quote

Installation for NAS326 box can be done with serial console connected (section A), or inside stock OS (section B).

I have not got around to write this. But it is really almost the same as section A, except that you would set the u-boot envs at stock OS command line. So take a look at section A in the release thread to see how it can be done inside stock OS (given you already have ssh connection).

All that said, I would need to run through the procedure to verify it myself before posting section B instruction. So if you're not sure, you should wait a few days for updated section B.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
jochen
Re: Zyxel NAS326 - Debian / Boot from USB?
February 17, 2017 12:18PM
Hello Bodhi,

I prepared the rootfs on a USB stick as described in your release thread. Then I took the commands from A2.4, replaced /^setenv/ with fw_setenv and executed them as root. When I boot with the USB stick in the front port, it seems to hang somewhere. Since I have no console attached I don't know where exactly.

Did I miss something? Do you have an advice for me what I can do besides opening the case?

Thanks for your help!

Jochen
jochen
Re: Zyxel NAS326 - Debian / Boot from USB?
February 17, 2017 01:24PM
update: I executed the fw_setenv commands again and rebooted. Now it works! I really don't know what's different now...
Re: Zyxel NAS326 - Debian / Boot from USB?
February 17, 2017 03:46PM
jochen,


Probably the box was booting back to kernel 2 when you set them the first time and missed something? Did you save the listing of the envs with fw_printenv after the first try? if you did please post here. It would be interesting to see what were the first time settings of the envs look like.

But it's cool that it worked for you on 2nd try :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Zyxel NAS326 - Debian / Boot from USB?
February 18, 2017 04:07AM
jochen,

> update: I executed the fw_setenv commands again an
> d rebooted. Now it works! I really don't know what
> 's different now...

Thanks for testing :) I've confirmed that it is actually booting to kernel 2 if you set the envs the way I wrote for serial console. And when you booted back to stock OS and set it the 2nd time, it would work!

One more fw_setenv is needed if setting up in stock OS. I will post the instruction in section B in the release thread,

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
nano326
Re: Zyxel NAS326 - Debian / Boot from USB?
February 18, 2017 10:30AM
Hi bodhi,

I am also successfully using Debian on the NAS326 now with openmediavault 3.x installed.
Works great so far. :-)
Thanks!

Do you know how to configure the wakeup?
Is it done through standard rtcwake way?

How can I control the LEDs?
In stock firmware the HDD LEDs start slow blinking to indicate spindown.

Concerning performance: should the performanc of Debian be equal to the stock firmware?
My impression is that it is slower by factor 2.
Tested with a rsync job over 700GB: stock firmware and Debian
The rsync job did not need to copy anything actually, because all files were already in the destination.
It took about 3 minutes on the stock firmware and about 6 minutes on Debian.
Re: Zyxel NAS326 - Debian / Boot from USB?
February 18, 2017 06:37PM
nano326,


> I am also successfully using Debian on the NAS326
> now with openmediavault 3.x installed.
> Works great so far. :-)
> Thanks!

Cool!

> Do you know how to configure the wakeup?
> Is it done through standard rtcwake way?

I have not looked into this subject, it's one of the minor items along with SPI flash, that I've postponed until I have more time.

>
> How can I control the LEDs?
> In stock firmware the HDD LEDs start slow blinking
> to indicate spindown.
>

Take a look in /etc/rc.local in the rootfs to see how I set up the commands to trigger LEDs.


> Concerning performance: should the performanc of D
> ebian be equal to the stock firmware?
> My impression is that it is slower by factor 2.
> Tested with a rsync job over 700GB: stock firmware
> and Debian
> The rsync job did not need to copy anything actual
> ly, because all files were already in the destinat
> ion.
> It took about 3 minutes on the stock firmware and
> about 6 minutes on Debian.

The rootfs I released is a basic rootfs, straight from Debian standard debootstrap process, so it has not been tuned. Especially when you install OMV, the performance tuning becomes more important. I'd expect users who have installed this to do that to maximize performance for NFS, Samba,... I have limited free time so I'm always hesitate to start any time-consuming project other than bringing up new boxes and build new kernels :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
nano326
Re: Zyxel NAS326 - Debian / Boot from USB?
February 19, 2017 11:09AM
bodhi Wrote:
-------------------------------------------------------

> > Do you know how to configure the wakeup?
> > Is it done through standard rtcwake way?
>
> I have not looked into this subject, it's one of t
> he minor items along with SPI flash, that I've pos
> tponed until I have more time.

I have tested rtcwake way and I can report success!
If you set "rtcwake -60 -m off", the system will shuwdown completely and automatically wake up again after 60 seconds.
Great!

> >
> > How can I control the LEDs?
> > In stock firmware the HDD LEDs start slow blinki
> ng
> > to indicate spindown.
> >
>
> Take a look in /etc/rc.local in the rootfs to see
> how I set up the commands to trigger LEDs.

Thanks. I was looking for the "heartbeat" trigger.
However, now I have to find out how to automatically switch the LED to heartbeat when it is spun down and vice versa.

Do you know how to enable wake-on-lan?
ethtool does not seem to support this on the HW.
nano326
Re: Zyxel NAS326 - Debian / Boot from USB?
February 19, 2017 11:10AM
nano326 Wrote:
-
> If you set "rtcwake -60 -m off", the system will s

must be "rtcwake -s 60 -m off"
Author:

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: