Installing LEDE on NSA325

done, also done the nsa310b

Great, thanks! :slight_smile:

I try this with my Dockstar

First:
i change the bootparameters:

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

I erase the ubi partition with
nand erase.part ubi

Then i boot
usb reset; fatload usb 0 0x800000 lockstar-initramfs-uImage; bootm 0x800000

This boot the device with LEDE

After this i do this on the command line:

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

After restarting the device start the kernel but after +- 10 seconds the device restart automatic again and again

How can i resolve this. There is no extra information (or errors) what i can see on the display (after booting kernel).

This solution works well RAID not working after Update LEDE 17.01.0 final GoFlexNet

But it can't save something....

Dockstar has different flash partitions, so you need to adjust the mtdparts line accordingly for uboot
see here for the patch where that is set https://github.com/lede-project/source/blob/master/target/linux/kirkwood/patches-4.4/140-dockstar.patch

the following should be the right command for dockstar, you should just need to change this in the uboot and it should boot up fine

setenv mtdparts=mtdparts=orion_nand:0x0xe0000(uboot),0x100000(u-boot environment),0x0x200000(second stage u-boot),0x0xfe00000(ubi)
saveenv

Afaik, the "second stage uboot" is unused if you have flashed lede uboot as primary uboot. Stock uboot can't boot LEDE on ubi partitions.

if you want to flash LEDE uboot, flash the file .kwb file, not the img or bin files

WARNING people that want to flash on other kirkwood please check their flash partitions, see the patch for your device in this github folder first

https://github.com/lede-project/source/tree/master/target/linux/kirkwood/patches-4.4

Hi @bobafetthotmail, @gendouhydeist, @jongerenchaos

I had a Lenovo Iomega EZ Media & Backup Center with 1 bay, and I think it have similar hardware, and I want to know how I could try to install LEDE on it. Since this is a different device I created another thread about:

Raid is also working fine on NSA310.

@bobafetthotmail I have bought my 3rd NSA310. I would like to try install uboot and rootfs using original software (Just in case I have serial cable). I will follow this instruction but install uboot from Openwrt. https://forum.doozan.com/read.php?3,12381,12381#msg-12381
What about rootfs ? Is it possible to install at once both things (uboot anr rootfs) ?
My current structure of nand:

~ # cat /proc/mtd
dev:    size   erasesize  name
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"

Yes, but if you have bad blocks the installation will fail (break on boot). Booting the initramfs image and doing a sysupgrade will always work even if you have bad blocks.
Openwrt firmware is formatting with ubi first (and this deals with bad blocks), while uboot just flashes raw binaries.

@bobafetthotmail For uboot there needs to be 8 first "good" blocks. What about rootfs (basic no addtional packages) ? In my case:

~ # dmesg | grep -i 'bad'
Scanning device for bad blocks
Bad eraseblock 476 at 0x000003b80000
Bad eraseblock 557 at 0x0000045a0000
Bad eraseblock 720 at 0x000005a00000
Bad eraseblock 857 at 0x000006b20000
Bad eraseblock 861 at 0x000006ba0000

So maybe it is enough to install and than use sysupgrade ? Will sysupgrade also format using ubi ?
Original OS has (plus tools from https://forum.doozan.com/read.php?3,27280):

~ # flash_eraseall --help
Usage: flash_eraseall [OPTION] MTD_DEVICE
Erases all of the specified MTD device.

  -j, --jffs2    format the device for jffs2
  -q, --quiet    don't display progress messages
      --silent   same as --quiet
      --help     display this help and exit
      --version  output version information and exit
~ # ls tools/
busybox        e2fsck         flash_erase    fw_env.config  fw_printenv    fw_setenv      nanddump       nandwrite

I would like to try. If it fail I can always connect via serial and flash again.
What should be the syntax (offsets, partitions - partition structure in previous post) for :
/usr/sbin/flash_erase /dev/mtd0 0xc0000 1 ??
and
/usr/sbin/nandwrite -s 786432 /dev/mtd0 zyxel_nsa310b-squashfs-factory.bin ??
Thanks

the ubi partition in openwrt should start at mtd2 in stock firmware, if you can flash from there it might work.
see this is the openwrt mtd partitions https://github.com/openwrt/openwrt/blob/master/target/linux/kirkwood/patches-4.14/107-01-zyxel-nsa3x0-common-nand-partitions.patch

@bobafetthotmail
Is openwrt-kirkwood-zyxel_nsa310b-squashfs-factory.bin with uboot ?
maybe I can nandwrite /dev/mtd0 openwrt-kirkwood-zyxel_nsa310b-squashfs-factory.bin ?
Or different way:
offset is 0x0140000 (1310720)
So maybe:
/usr/sbin/nandwrite -s 1310720 /dev/mtd0 zyxel_nsa310b-squashfs-sysupgrade.bin
or
/usr/sbin/nandwrite -s 1310720 /dev/mtd2 zyxel_nsa310b-squashfs-sysupgrade.bin

No it is not.

OK, My idea was not working.

~/tools # ./nandwrite -s 1310720 /dev/mtd0 /tmp/openwrt-kirkwood-zyxel_nsa310b-squashfs-sysupgrade.bin 
Input file is not page-aligned. Use the padding option.
nandwrite: error!: Data was only partially written due to error
           error 0 (Success)
~/tools # ./nandwrite -s 1310720 /dev/mtd0 /tmp/openwrt-kirkwood-zyxel_nsa310b-squashfs-sysupgrade.bin -p
Image 3471534 bytes, NAND page 2048 bytes, OOB area 64 bytes, device size 1048576 bytes
nandwrite: error!: Input file does not fit into device
           error 0 (Success)
nandwrite: error!: Data was only partially written due to error
           error 0 (Success)
~/tools # ./nandwrite -s 1310720 /dev/mtd2 /tmp/openwrt-kirkwood-zyxel_nsa310b-squashfs-sysupgrade.bin -p
Image 3471534 bytes, NAND page 2048 bytes, OOB area 64 bytes, device size 524288 bytes
nandwrite: error!: Input file does not fit into device
           error 0 (Success)
nandwrite: error!: Data was only partially written due to error
           error 0 (Success)

@bobafetthotmail and Paul Wassi(p-wassi) - I don't know his nickname in this forum
I found two issue:
The uImage from https://downloads.openwrt.org/snapshots/targets/kirkwood/generic/openwrt-kirkwood-zyxel_nsa310b-initramfs-uImage
doesn't contains driver kmod-r8169 so there is no ethernet connection
So I build by myself and this issue was resolved
But issue which I wasn't able to resolve is that u-boot don'y see "ubi" partition after sysupgrade:

root@OpenWrt:/mnt# sysupgrade openwrt-kirkwood-zyxel_nsa310b-squashfs-sysupgrade
.bin
Image not in /tmp, copying...
Cannot save config while running from ramdisk.
Commencing upgrade. All shell sessions will be closed now.
Watchdog handover: fd=3
- watchdog -
killall: telnetd: no process killed
Sending TERM to remaining processes ... ubusd logd netifd odhcpd ntpd dnsmasq
Sending KILL to remaining processes ...
Performing system upgrade...
[  162.850447] ubi0: attaching mtd2
[  162.997255] ubi0: scanning is finished
[  163.001156] ubi0 error: ubi_read_volume_table: the layout volume was not found
[  163.008630] 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.7 MiB), 1014 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 1013 -- 100 % complete
ubiformat: 331 eraseblocks are supposedly empty
ubiformat: 5 bad eraseblocks found, numbers: 466, 547, 710, 847, 851
ubiformat: warning!: 678 of 1009 eraseblocks contain non-UBI data
ubiformat: warning!: only 0 of 1009 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
[  172.681062] ubi0: attaching mtd2
[  172.857696] ubi0: scanning is finished
[  172.872814] ubi0: attached mtd2 (name "ubi", size 126 MiB)
[  172.878330] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[  172.885269] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[  172.892022] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
[  172.898852] ubi0: good PEBs: 1009, bad PEBs: 5, corrupted PEBs: 0
[  172.904968] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[  172.912238] ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 603085179
[  172.921341] ubi0: available PEBs: 990, total reserved PEBs: 19, PEBs reserved for bad PEB handling: 15
[  172.930724] ubi0: background thread "ubi_bgt0d" started, PID 2662
UBI device number 0, total 1009 LEBs (130185216 bytes, 124.1 MiB), available 990 LEBs (127733760 bytes, 121.8 MiB), LEB size 129024 bytes (126.0 KiB)
Volume ID 0, size 17 LEBs (2193408 bytes, 2.0 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "kernel", alignment 1
Volume ID 1, size 11 LEBs (1419264 bytes, 1.3 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs", alignment 1
Set volume size to 124121088
Volume ID 2, size 962 LEBs (124121088 bytes, 118.3 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
[  174.567357] reboot: Restarting system


U-Boot 2018.03 (Jun 05 2018 - 19:54:00 +0000)
ZyXEL NSA310 1-Bay Power Media Server

SoC:   Kirkwood 88F6281_A1
DRAM:  256 MiB
WARNING: Caches not enabled
NAND:  128 MiB
MMC:
Loading Environment from NAND... OK
In:    serial
Out:   serial
Err:   serial
Net:   egiga0
PHY reset timed out
MV88E1318 PHY initialized on egiga0
Hit any key to stop autoboot:  0
unexpected character 'b' at the end of partition
Error initializing mtdparts!
incorrect device type in ubi
Partition ubi not found!
Error, no UBI device/partition selected!
Wrong Image Format for bootm command
Error occured, error code = 112
ERROR: can't get kernel image!
NSA310>

I found in history that Paul ask you:

@bobafetthotmail I've done some more changes to your 010 patch for Pogoplug v4.
This patch has touched configuration options for the whole kirkwood target. If those
changes are needed, then this should probably go into a patch seperated from the
device support.

And you never reply. I found that you confirm that uboot 2017.09 is working fine but never confirm that uboot 2018.03 compile by gcc 7.3 is working for you ? Do you have a chance to test it ?

I mean this commit: https://github.com/openwrt/openwrt/commit/f21cd9640052a733e1759519e3d7ca0f9453653b

Never tried the uimage from there, the uimage I built with the same sources always worked. Will try this and open a bug report if needed.

This weekend I will test it.

Did you try pulling power adapter (to shut down the device) and attach it again after 5 seconds?

I also had issues where uboot fails to boot after it was upgraded but they were solved by a hardware power off. (RAM was not cleared properly I guess)

Did you try pulling power adapter (to shut down the device) and attach it again after 5 seconds?

I also had issues where uboot fails to boot after it was upgraded but they were solved by a hardware power off. (RAM was not cleared properly I guess)

I tried and didn't help. I will try uboot 2017.9 which was fine in your case.
Regarding uImage. Maybe it is also worth to add vfat module and USB-storage. That way we system starts you have the same options as uboot - can mount USB stick and install image from it.

Maybe this commit is related:
https://github.com/openwrt/openwrt/commit/daf19649dbf101ce7ae17abf84eeed7a30b41275
If I find a time I will try.

@bobafetthotmail
The issue wasn't cause by above commit. What is the correct command to upgrade uboot from lede/openwrt ?
mtd -r write u-boot.trx uboot ?
when I have:

root@OpenWrt:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 000c0000 00020000 "uboot"
mtd1: 00080000 00020000 "uboot_env"
mtd2: 07ec0000 00020000 "ubi"

I always installed uboot from inside uboot (or from stock firmware).

The command should be correct, but the tool will not work because the uboot partition is marked read-only inside OpenWrt.

You must add mtd-rw package in your firmware to ignore this limitation, see it here in packages repository/feed https://github.com/openwrt/packages/blob/master/kernel/mtd-rw/Makefile

use the uboot file called "u-boot.kwb". The other two don't work, I don't know why. There is no u-boot.trx for kirkwood.