Installing LEDE on NSA325


@bobafetthotmail
Hi bobafetthotmail I've bought NSA325, since I haven't found any guide to flash it on LEDE I saw the pull request with how to guide.

My question is, does NSA310 and NSA325 have the same procedure?
Also does flashing the bin file will automatically the original uboot to uboot with ubifs support?
Does flashing LEDE according to the guide will automatically boot to UBIFS without modifying uboot too much?
Because I saw the guide on openwrt https://forum.openwrt.org/viewtopic.php?pid=316900#p316900 there's a lot do but I want to boot it out first from jffs2 to test it out first but if it's already booting on UBI then it's awesome!

I saw u-boot-nsa325 on bin folder and there are 3 files u-boot.bin, u-boot.img, and u-boot.kwb are these files that I need to replace the uboot from 0x1000000?

I want to proceed with caution as I'm not familiar with kirkwood uboot environment yet.
One last thing how can I generate UBIFS image from buildroot.

Thanks!

Yes the procedure is the same for nsa310 and 325, but it's better if you do it as I say now as the original procedure does not deal with cases where there are bad blocks in flash (and I had another user with bad blocks that pointed this out).

All kirkwoods are using UBI with kernel+squash+Ubifs in it.
The squashfs root partition allows "reset to default" functionality and it was deemed more useful than saving a few MB on devices that have like 128 MB or more available.

There is an image for 325 too, it is currently only in development snapshot, so be aware that you won't be able to update some packages soon after you installed the device, as is the case for all snapshot builds https://downloads.lede-project.org/snapshots/targets/kirkwood/generic/

As usual, it might be less frustrating to make an image with Image Builder with all packages you need and then sysupgrade with that every now and then.

Follow the tutorial here http://forum.doozan.com/read.php?3,12381 to backup all stock partitions and install uboot (it also provides tools). The image that you must use is the "u-boot.kwb" one. Ignore the part of the tutorial about flashing envs manually, the LEDE uboot has them compiled in already.

Then reboot, press a key to stop auto-booting and add new env for the mac address so it will be initialized with the right address.
The MAC address is usually on a sticker under the device (one of the two codes is the serial),
it should begin with "107BEF" as it is assigned to ZyXEL.

write in the u-boot console (use your MAC address instead of the example)

setenv ethaddr 10:7B:EF:00:00:00
saveenv

Download with your PC and place http://downloads.lede-project.org/snapshots/targets/kirkwood/generic/lede-kirkwood-nsa325-initramfs-uImage in a normal flash drive formatted with FAT32.

Insert the flash drive in a USB 2.0 port of the NAS (back ports), then write (copy-paste) in the serial console:

usb reset; fatload usb 0 0x800000 lede-kirkwood-nsa325-initramfs-uImage; bootm 0x800000

This loads that firmware image and starts up a LEDE firmware that runs from RAM. When it's done starting up, do a sysupgrade as normal.

cd /tmp
wget http://downloads.lede-project.org/snapshots/targets/kirkwood/generic/lede-kirkwood-nsa325-squashfs-sysupgrade.tar
sysupgrade lede-kirkwood-nsa325-squashfs-sysupgrade.tar

This takes care of reformatting the internal flash with ubi and dealing properly with bad blocks.

After the reboot it should be running LEDE from flash.

Currently the Sata and USB leds work but are not used, but there is a PR where I enable them (on both the 310 and 325) https://github.com/lede-project/source/pull/938
It will eventually be merged, I hope.

Btw, this procedure is the same for all kirkwood devices, just adjust the file names.

@bobafetthotmail
My device has different partition, The expected behavior was different from the guide.
When I'm deleting 4 blocks it only deletes one.

/e-data/4089-AD8E/tools # flash_erase /dev/mtd0 0 4 Erasing 128 Kibyte @ 60000 -- 100 % complete

now when I flash the uboot I get this

/e-data/4089-AD8E # nandwrite /dev/mtd0 kirkwood/generic/u-boot-nsa325/u-boot.kw b Input file is not page aligned Data did not fit into device, due to bad blocks : Success

/etc/fw_env.config

MTD device name Device offset Env. size Flash sector size Number of sectors NAND example /dev/mtd1 0x0000 0x20000 0x20000 4

cat /proc/mtd

mtd0: 00100000 00020000 "uboot" mtd1: 00080000 00020000 "uboot_env" mtd2: 00080000 00020000 "key_store" mtd3: 00080000 00020000 "info" mtd4: 00a00000 00020000 "etc" mtd5: 00a00000 00020000 "kernel_1" mtd6: 02fc0000 00020000 "rootfs1" mtd7: 00a00000 00020000 "kernel_2" mtd8: 02fc0000 00020000 "rootfs2"

original env

bootargs=console=ttyS0,115200 mtdparts=nand_mtd:0x100000(uboot),0x80000(uboot_env),0x80000(key_store),0x80000(info),0xA00000(etc),0xA00000(kernel_1),0x2FC0000(rootfs1),0xA00000(kernel_2),0x2FC0000(rootfs2) root=/dev/nfs rw init=/init bootcmd=nand read.e 0x2000000 $(kernel_addr) 0xA00000; bootm 0x2000000 bootdelay=2 baudrate=115200 loads_echo=0 ipaddr=10.4.52.165 serverip=10.4.52.7 rootpath=/srv/ubuntu netmask=255.255.255.0 nandEcc=1bit kernel_addr=C80000 MODEL_ID=AA03 PRODUCT_NAME=NSA-325 FEATURE_BIT=00 CONTRY_TYPE=FF VENDOR_NAME=MitraStar Technology Corp. run_diag=yes ethaddr=FC:F5:28:00:00:00

after flashing uboot

Warning: Bad CRC, using default environment bootargs=console=ttyS0,115200 mtdparts=nand_mtd:0x100000(uboot),0x80000(uboot_env),0x80000(key_store),0x80000(info),0xA00000(etc),0xA00000(kernel_1),0x2FC0000(rootfs1),0xA00000(kernel_2),0x2FC0000(rootfs2) root=/dev/nfs rw init=/init bootcmd=nand read.e 0x2000000 $(kernel_addr) 0xA00000; bootm 0x2000000 bootdelay=2 baudrate=115200 nandEcc=1bit kernel_addr=480000 MODEL_ID=A203 PRODUCT_NAME=NSA-310 FEATURE_BIT=00 CONTRY_TYPE=FF VENDOR_NAME=ZyXEL Communications Corp.

@bobafetthotmail
Ok I've used bodhi uboot it writes properly

/ # nandwrite /dev/mtd0 /e-data/4089-AD8E/uboot.2016.05-tld-1.nsa325.mtd0.kwb
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000

I check the env there's nothing there should I proceed loading LEDE on ram and start sysupgrade?

/ # fw_printenv
Warning: Bad CRC, using default environment
bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; bootm
bootdelay=5
baudrate=115200

damnit, I'll have to look into this, again. I just checked and I can't get any of the uboots in that folder to work on mine too.

I check the env there's nothing there should I proceed loading LEDE on ram and start sysupgrade?

Bodhi's uboot isn't set for starting up LEDE (nor anything else, see the envs?).
Since currently the LEDE uboot is broken for some reason, configure bodhi's uboot it to boot LEDE from ubi (same configuration used in LEDE uboot). From the bodhi's uboot console write:

setenv mtdparts=mtdparts=orion_nand:0x0c0000(uboot),0x80000(uboot_env),0x7ec0000(ubi)
setenv bootargs_lede ''
setenv bootcmd 'run bootargs_lede; ubi part ubi; ubi read 0x800000 kernel; bootm 0x800000'
setenv console=console=ttyS0,115200
setenv ethaddr 10:7B:EF:00:00:00 (put your mac address instead of the example one)
setenv mtdids=nand0=orion_nand
saveenv

then you can load LEDE in RAM and sysupgrade.

@bobafetthotmail
Ok here's what I did I reverted two commits related to kirkwood u-boot
https://git.lede-project.org/?p=source.git;a=commit;h=55920643b1e968c37906fc120f63ff1085161b9b
https://git.lede-project.org/?p=source.git;a=commit;h=c95c3165b9497c17353a54976b9aa3fcaeee9677

https://git.lede-project.org/?p=source.git&a=search&h=HEAD&st=commit&s=kirkwood

When I tried it I get different error.

/ # nandwrite -a /dev/mtd0 /e-data/4089-AD8E/kirkwood/generic/u-boot-nsa325/u-boot.kwb Input file is not page-aligned. Use the padding option. nandwrite: error!: Data was only partially written due to error. error 0 (Success)

I added padding and here's what I found.

/ # nandwrite -p /dev/mtd0 /e-data/4089-AD8E/kirkwood/generic/u-boot-nsa325/u-boot.kwb Writing data to block 0 at offset 0x0 Writing data to block 1 at offset 0x20000 Writing data to block 2 at offset 0x40000 Writing data to block 3 at offset 0x60000

It's writes properly but it still doesn't have env's. I haven't turn off my device yet unsure what to do... As I only have backup of mtd0 and without the env's.

EDIT:
After successfully flashing bodhi uboot, can I restart my device without env's in uboot? Wouldn't that cause problem not able to access serial because of no env's set on uboot?

I just managed to get the uboot flashed from uboot.
place the u-boot.kwb file in the flash drive on usb port and then

usb reset; fatload usb 0 0x1000000 u-boot.kwb; nand erase 0x00000 0x100000; nand write 0x1000000 0x00000 0x100000; reset

It's writes properly but it still doesn't have env's

That's normal, LEDE uboot has default envs hardcoded so it works even without envs on flash. What is the output of

printenv

It should be

NSA325> printenv
baudrate=115200
bootcmd=ubi part ubi; ubi read 0x800000 kernel; bootm 0x800000
bootdelay=3
console=console=ttyS0,115200
ethact=egiga0
mtdids=nand0=orion_nand
mtdparts=mtdparts=orion_nand:0x0c0000(uboot),0x80000(uboot_env),0x7ec0000(ubi)
stderr=serial
stdin=serial
stdout=serial

So, adding -p (padding) on nandwrite will work as well?

Anyway's ill try your suggestion and go yolo!

[quote="gendouhydeist, post:6, topic:3611, full:true"]I haven't turn off my device yet unsure what to do... As I only have backup of mtd0 and without the env's.[/quote]If you are using stock firmware, then you won't be able to see/change envs as bodhi and LEDE uboot use different place for envs, and in case of LEDE uboot it does not even need them.

If you did a nand_erase and then flashed with -p (padding) and it flashes properly, you can go ahead and reboot. Then through serial console you can communicate with the new uboot and load LEDE from the usb thumbdrive.

Also, don't worry too much, most kirkwoods like NSA325 can be rescued from a bad uboot flash with kwboot tool (and a serial connection) by sending them the u-boot.kwb file over serial http://forum.doozan.com/read.php?3,7852

I use this command in my linux system to use kwboot on my nsa325 (adjust paths for your files)

sudo  /home/alby/bin/kwboot -b /home/alby/Desktop/u-boot.kwb -p -t /dev/ttyUSB0 -B 115200

I'm using flash_erase... what's the difference from nand_erase?

[quote="gendouhydeist, post:10, topic:3611, full:true"]
I'm using flash_erase... what's the difference from nand_erase?
[/quote]that's ok, I keep mixing up uboot commands ("nand erase" is for erasing from uboot serial console) with commands you give from Linux.

I just wanted to make sure you erased the flash before writing with nandwrite and the -p option. If you did that and there were no errors you can reboot and do the last step through serial console.

Sorry for the confusion :confounded: I'm not in my best shape.

I should be the one telling you sorry, sorry for taking your time... anyways you answered all my question you're awesome thanks! I can proceed now without worries.

another minor correction, the command to boot LEDE ram image is

usb reset; fatload usb 0 0x800000 lede-kirkwood-nsa325-initramfs-uImage.bin; bootm 0x800000

because the file is lede-kirkwood-nsa325-initramfs-uImage.bin

1 Like

@bobafetthotmail

There's some warnings and error don't know if it's ok. But it boots fine though.

Here's the log

root@LEDE:/tmp# sysupgrade lede-kirkwood-nsa325-squashfs-sysupgrade.tar
Image metadata not found
Cannot save config while running from ramdisk.
Watchdog handover: fd=3
- watchdog -
killall: telnetd: no process killed
Sending TERM to remaining processes ... ubusd logd netifd odhcpd dnsmasq ntpd
Sending KILL to remaining processes ...
[  256.290639] ubi0: attaching mtd2
[  256.470750] ubi0: scanning is finished
[  256.474591] ubi0 error: ubi_read_volume_table: the layout volume was not found
[  256.481976] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd2, error -22
ubiattach: error!: cannot attach mtd2
           error 22 (Invalid argument)
ubiformat: mtd2 (nand), size 132907008 bytes (126.8 MiB), 1014 eraseblocks of 13                                                                                                                                                             1072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 1013 -- 100 % complete
ubiformat: 285 eraseblocks are supposedly empty
ubiformat: warning!: 729 of 1014 eraseblocks contain non-UBI data
ubiformat: warning!: only 0 of 1014 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 1013 -- 100 % complete
[  266.111597] ubi0: attaching mtd2
[  266.329011] ubi0: scanning is finished
[  266.343378] ubi0: attached mtd2 (name "ubi", size 126 MiB)
[  266.348886] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[  266.355805] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[  266.362541] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
[  266.369351] ubi0: good PEBs: 1014, bad PEBs: 0, corrupted PEBs: 0
[  266.375473] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[  266.382728] ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 725550722
[  266.391806] ubi0: available PEBs: 990, total reserved PEBs: 24, PEBs reserved for bad PEB handling: 20
[  266.401165] ubi0: background thread "ubi_bgt0d" started, PID 2437
UBI device number 0, total 1014 LEBs (130830336 bytes, 124.8 MiB), available 990 LEBs (127733760 bytes, 121.8 MiB), LEB size 129024 bytes (126.0 KiB)
Volume ID 0, size 16 LEBs (2064384 bytes, 2.0 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "kernel", alignment 1
Volume ID 1, size 10 LEBs (1290240 bytes, 1.2 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs", alignment 1
Set volume size to 124379136
Volume ID 2, size 964 LEBs (124379136 bytes, 118.6 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs_data", alignment 1
sysupgrade successful
umount: can't unmount /dev: Resource busy
umount: can't unmount /tmp: Resource busy
umount: can't unmount /: Invalid argument
[  267.854438] reboot: Restarting system

EDIT:
It only detects one drive T_T but it powers up.

There's some warnings and error don't know if it's ok.

Yeah, that's normal. the flash wasn't partitioned as ubi in stock firmware so it's normal that sysupgrade does not find old LEDE partitions ("failed to attach mtd2") and that there is "non-UBI data" on flash (the old firmware).
The sysupgrade first tries to find LEDE partitions to do a normal upgrade, if it does not find them it will reformat flash.

It only detects one drive T_T but it powers up.

This is not normal, here it sees both sata drives.
Do you see the drive in uboot? I see that uboot detects both sata drives.

Here is the serial output from current uboot in my nsa325 (the Sata disks are called IDE here)

U-Boot 2017.03 (May 09 2017 - 08:01:07 +0000)
ZyXEL NSA325 2-Bay Power Media Server

SoC:   Kirkwood 88F6282_A1
DRAM:  512 MiB
WARNING: Caches not enabled
NAND:  128 MiB
MMC:                                                                                                                         
In:    serial                                                                                                                
Out:   serial                                                                                                                
Err:   serial                                                                                                                
Net:   egiga0                                                                                                                
MV88E1318 PHY initialized on egiga0                                                                                          
IDE:   Bus 0: .........OK Bus 1: .OK                                                                                         
  Device 0: Model: ST31500341AS Firm: CC1H Ser#: 9VS0YM5D                                                                    
            Type: Hard Disk                                                                                                  
            Supports 48-bit addressing                                                                                       
            Capacity: 1430799.3 MB = 1397.2 GB (2930277168 x 512)                                                            
  Device 1: Model: ST31500341AS Firm: CC1H Ser#: 9VS0YKA5                                                                    
            Type: Hard Disk                                                                                                  
            Supports 48-bit addressing                                                                                       
            Capacity: 1430799.3 MB = 1397.2 GB (2930277168 x 512)                                                            
Hit any key to stop autoboot:  0                                                                                             
NSA325>             

and here the part of dmesg (or bootup log) of LEDE where it shows that the disks are seen by Linux.

[    1.243597] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl F300)
[    1.303615] ata1.00: ATA-8: ST31500341AS, CC1H, max UDMA/133
[    1.309302] ata1.00: 2930277168 sectors, multi 0: LBA48 NCQ (depth 31/32)
[    1.393624] ata1.00: configured for UDMA/133
[    1.398204] scsi 0:0:0:0: Direct-Access     ATA      ST31500341AS     CC1H PQ: 0 ANSI: 5
[    1.407127] sd 0:0:0:0: [sda] 2930277168 512-byte logical blocks: (1.50 TB/1.36 TiB)
[    1.415276] sd 0:0:0:0: [sda] Write Protect is off
[    1.420172] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    1.478460]  sda: sda1 sda2 sda3
[    1.482715] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.913587] ata2: SATA link up 3.0 Gbps (SStatus 123 SControl F300)
[    1.973614] ata2.00: ATA-8: ST31500341AS, CC1H, max UDMA/133
[    1.979293] ata2.00: 2930277168 sectors, multi 0: LBA48 NCQ (depth 31/32)
[    2.063617] ata2.00: configured for UDMA/133
[    2.068172] scsi 1:0:0:0: Direct-Access     ATA      ST31500341AS     CC1H PQ: 0 ANSI: 5
[    2.077009] sd 1:0:0:0: [sdb] 2930277168 512-byte logical blocks: (1.50 TB/1.36 TiB)
[    2.085133] sd 1:0:0:0: [sdb] Write Protect is off
[    2.090013] sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.145699]  sdb: sdb1 sdb2 sdb3

I checked it again it's working fine thanks anyway.

BTW I just notice that power trigger doesn't work. I already applied the patch you submitted led trigger.

Power button works fine here and I just reinstalled to make sure everything was fine (I still haven't found time to set it up for "production" use anyway).
The power button is defined as POWER in the dtb and dealt with by kmod-gpio-button-hotplug package that should be installed by default in the image.

The power button on the casing is kinda flimsy though, you need to make sure you press on the lower part of it or it flexes in without pressing the actual switch on the board.

/dev/ubi0_2 is maxed out? I only have few packages installed here.

[code]root@LEDE:~# opkg install screen
Installing screen (4.5.1-1) to root...
Collected errors:

  • verify_pkg_installable: Only have 0kb available on filesystem /overlay, pkg screen needs 166
  • opkg_install_cmd: Cannot install package screen. [/code]

root@LEDE:~# df -h Filesystem Size Used Available Use% Mounted on /dev/root 9.8M 9.8M 0 100% /rom tmpfs 251.2M 1.3M 249.9M 1% /tmp /dev/ubi0_2 101.6M 101.6M 0 100% /overlay overlayfs:/overlay 101.6M 101.6M 0 100% / tmpfs 512.0K 0 512.0K 0% /dev

Uhm, is this from your own build from source (to apply that patch) or from LEDE prebuilt image? Because here I used the LEDE prebuilt image and overlay is empty (as normal)

root@LEDE:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 1.3M      1.3M         0 100% /rom
tmpfs                   250.8M     52.0K    250.8M   0% /tmp
/dev/ubi0_2             109.6M     36.0K    104.8M   0% /overlay
overlayfs:/overlay      109.6M     36.0K    104.8M   0% /
tmpfs                   512.0K         0    512.0K   0% /dev

a full overlay might explain why something isn't working properly, as on boot first boot it could not generate board-specific scripts.

Try a reset as here, and if that fails, try with LEDE prebuilt image (or Image Builder from here).

Failsafe reset doesn't work though. Will try the second method.

root@(none):/# mount_root [ 78.072827] mount_root: loading kmods from internal overlay [ 78.087900] kmodloader: loading kernel modules from //etc/modules-boot.d/* [ 78.096930] kmodloader: done loading kernel modules from //etc/modules-boot.d/* [ 79.701533] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 1064 [ 79.734923] UBIFS (ubi0:2): recovery needed [ 79.913477] UBIFS (ubi0:2): recovery completed [ 79.918029] UBIFS (ubi0:2): UBIFS: mounted UBI device 0, volume 2, name "rootfs_data" [ 79.925905] UBIFS (ubi0:2): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes [ 79.935870] UBIFS (ubi0:2): FS size: 114057216 bytes (108 MiB, 884 LEBs), journal size 5677056 bytes (5 MiB, 44 LEBs) [ 79.946529] UBIFS (ubi0:2): reserved for root: 4952683 bytes (4836 KiB) [ 79.953178] UBIFS (ubi0:2): media format: w4/r0 (latest is w4/r0), UUID F97708EB-4E86-49E7-8339-3D676A37FEDC, small LPT model ^[[A[ 79.966725] block: attempting to load /tmp/ubifs_cfg/upper/etc/config/fstab [ 79.976112] block: extroot: not configured [ 79.980363] UBIFS (ubi0:2): un-mount UBI device 0 [ 79.985122] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" stops [ 80.020528] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 1066 [ 80.124327] UBIFS (ubi0:2): UBIFS: mounted UBI device 0, volume 2, name "rootfs_data" [ 80.132197] UBIFS (ubi0:2): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes [ 80.142175] UBIFS (ubi0:2): FS size: 114057216 bytes (108 MiB, 884 LEBs), journal size 5677056 bytes (5 MiB, 44 LEBs) [ 80.152838] UBIFS (ubi0:2): reserved for root: 4952683 bytes (4836 KiB) [ 80.159494] UBIFS (ubi0:2): media format: w4/r0 (latest is w4/r0), UUID F97708EB-4E86-49E7-8339-3D676A37FEDC, small LPT model [ 80.648195] block: attempting to load /tmp/ubifs_cfg/upper/etc/config/fstab [ 80.657078] block: extroot: not configured [ 80.662279] mount_root: switching to ubifs overlay root@(none):/# umount /overlay && jffs2reset && reboot [ 84.816019] jffs2reset: This will erase all settings and remove any installed packages. Are you sure? [N/y] y [ 87.054779] jffs2reset: /dev/ubi0_2 is not mounted [ 87.059624] ubi0 error: ubi_open_volume: cannot open device 0, volume 2, error -16 [ 87.067289] jffs2reset: /dev/ubi0_2 will be erased on next mount [ 87.073366] jffs2reset: writing /dev/ubi0_2 failed: Bad file descriptor