Welcome! Log In Create A New Profile

Advanced

2023.04 U-Boot Kirkwood - ZyXEL NSA325

Posted by bodhi 
2023.04 U-Boot Kirkwood - ZyXEL NSA325
May 26, 2023 09:22PM
In addition to the capabilties provided by u-boot 2017.07-tld-1 for NSA325 , this 2023.04-tld-1 NSA325 u-boot has the following new capabilties:

- Supports for USB 3.0. You can now boot with the rootfs attached to the USB 3.0 port in front.
- Netconsole enhancement. (See Note C.1.2).
- Distro boot (see Note C.2 after the Installation Steps for usage).

=============================================

Update 01 July 2023: Fixed netconsole
Update 26 May 2023

Download at Dropbox

uboot.2023.04-tld-1.nsa325.bodhi.tar
md5sum
15ef315acc142d4704fd4b8eec18b6be
sha256sum
f0eebe427f509179a6fd7c0a5a017180b0c2cdec13f5d71fb27fcf95246cca2b

As always, please verify the hash of what you've downloaded!

This tarball includes 4 files
uboot.2023.04-tld-1.nsa325.kwb
uboot.2023.04-tld-1.nsa325.environment.img
uboot.2023.04-tld-1.nsa325.environment
uboot.2023.04-tld-1.nsa325.boot.scr

A. Preparation

A.1. UART booting

It is strongly recommmended that you try to run kwboot to test this boot image with UART booting before flashing to NAND. This is the rescue path when and if the flashing goes wrong for some reason. See example here. And to download latest ARM kwboot binary for UART booting see here.

A.2. Flashing tools

If you are running an OS (eg. stock FW) that does not provide mtd-utils and uboot-tools (fw_setenv, fw_printenv, flash_erase, nandwrite), you can download the NAND and U-Boot tools binaries here in this thread.


B. Flashing Instruction:

1. Setup fw_env.config

U-Boot envs config should be defined as followed in your /etc/fw_env.config

cat /etc/fw_env.config
 # MTD device name	Device offset	Env. size	Flash sector size	Number of sectors 
/dev/mtd0 0xc0000 0x20000 0x20000

If you don't have /etc/fw_env.config file in your system then go ahead and create this file:

echo "/dev/mtd0 0xc0000 0x20000 0x20000" > /etc/fw_env.config

- And your mtd partitions should be:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00100000 00020000 "uboot"
mtd1: 00080000 00020000 "stock_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"

2. Backup mtd0 and envs

Save your current uBoot image and envs image in mtd0, and save your current u-boot envs with fw_printenv.

2.1 Dumping NAND mtd0:
nanddump --noecc --omitoob -l 0x80000 -f mtd0.nsa325 /dev/mtd0
nanddump --noecc --omitoob -f mtd0.nsa325.envs -s 786432 -l 131072 /dev/mtd0
If installing from stock u-boot, also save stock envs
nanddump --noecc --omitoob -f mtd0.nsa325.envs.stock /dev/mtd1

2.2. Save envs:
fw_printenv > current_envs.txt
For most stock OS, there is no fw_printenv. So it's OK if this step fails.

Copy these files to a persistent storage.

3. Check for bad blocks

Be sure there is no bad block in the first 1M of your NAND. This is very important, if there is bad block in the first 1M (blocks 0 to 7), don't flash u-boot, because you will almost certainly soft-brick your box.

Example of bad block in mtd0:
dmesg | grep -i 'bad'

[    2.413231] Scanning device for bad blocks
[    2.417731] Bad eraseblock 3 at 0x000000060000

This bad eraseblock 3 is the 4th block which resides within mtd0 first 1M (block 0 to block 7). Please stop at this step and post question in this thread for a workaround.

4. Extract the archive to /tmp

cd /tmp
tar xf uboot.2023.04-tld-1.nsa325.bodhi.tar

5. Flash u-boot image to NAND

Be extra careful with the next 2 commands, you should see output that look like below in those steps. If there is error, then do not reboot, post your problem here so we can help.

Erase 4 blocks
flash_erase /dev/mtd0 0 4
Expected output:
Erase Total 4 Units 
Performing Flash Erase of length 131072 at offset 0x60000 done

Write the image
nandwrite /dev/mtd0 /tmp/uboot.2023.04-tld-1.nsa325.kwb
Expected output:
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

6. Flash default u-boot envs image

If you are upgrading from 2017.07-tld-1 u-boot, you can skip this step. But some envs will need to be updated before reboot. See Note section below after the installation steps. Especially if your rootfs is SATA, then you must adjust the env described in Note section "C.1.1 SATA boot envs". Or if you are using netconsole then you must adjust the env described in Note section "C.1.2 Netconsole envs".

Be extra careful with the next 2 commands, you should see output that look like below. If there is error, then do not reboot, post your problem here so we can help.

Erase 1 block
flash_erase /dev/mtd0 0xc0000 1
Expected output:
Erase Total 1 Units
Performing Flash Erase of length 131072 at offset 0xc0000 done

Write the image
nandwrite -s 786432 /dev/mtd0 /tmp/uboot.2023.04-tld-1.nsa325.environment.img
Expected output:
Writing data to block 6 at offset 0xc0000

7. Restore MAC address

Modify the following u-boot variable using fw_setenv:

Restore the MAC address using the saved envs in current_envs.txt. Or find the MAC address on the sticker outside the case. Replace xx:xx:xx:xx:xx:xx with the real values.

fw_setenv ethaddr 'xx:xx:xx:xx:xx:xx'
For sanity check, list you envs again
fw_printenv

Don't reboot if there is error while listing U-Boot envs.

8. (Optional) Activate netconsole

Skip this step if you already have serial console connected. Netconsole can be set up anytime later.

Adjust 192.168.0.xxx and 192.168.0.yyy below to the real numbers in your network configuration. 192.168.0.xxx is this pogoplug static IP address, and 192.168.0.yyy is the IP address of the netconsole server where it will monitor the output from this pogoplug. The ipaddr can be any unique address that you want to use. serverip is IP address of the netconsole server, so usually a Linux box in your network.

fw_setenv preboot  'run preboot_nc'
fw_setenv ipaddr   '192.168.0.xxx'
fw_setenv serverip '192.168.0.yyy'

9. Reboot

Upon reboot, in either serial console or netconsole, U-Boot banner should show:

U-Boot 2023.04-tld-1 (Jun 24 .......)
ZyXEL NSA325 2-Bay Power Media Server

DONE installation.


C. Note

C.1. Envs changes from 2017.07-tld-1 u-to 2023.04-tld-1 u-boot.

As mentioned in Step 6, if you are upgrading from 2017.07-tld-1 u-boot then this is a u-boot drop in replacement (no need to flash new default envs image). However there are changes in envs for 2023.04-tld-1 that need to be retrofitted if you have chosen not flashing the default envs in Step 6.

C.1.1 SATA boot envs

In this new u-boot, the SATA device was changed from "ide" to "sata", and also the command to start it. So if SATA is the boot drive, you must adjust these envs.

fw_setenv devices 'sata usb'
fw_setenv init_sata 'sata init'
fw_setenv scan_disk 'echo running scan_disk ...; scan_done=0; setenv scan_usb "usb start";  setenv scan_sata "sata init";  setenv scan_mmc "mmc rescan"; for dev in $devices; do if test $scan_done -eq 0; then echo Scan device $dev; run scan_$dev; for disknum in $disks; do if test $scan_done -eq 0; then echo device $dev $disknum:1; if load $dev $disknum:1 $load_uimage_addr /boot/uImage 1; then scan_done=1; echo Found bootable drive on $dev $disknum; setenv device $disknum:1; setenv bootdev $dev; fi; fi; done; fi; done'
fw_setenv uenv_init_devices 'echo Initializing devices...; setenv init_usb "usb start";  setenv init_sata "sata init";  setenv init_mmc "mmc rescan"; for devtype in $devices; do run init_$devtype; done'

C.1.2 Netconsole envs

Both serial console and netconsole input and output are now muxed to one console.

So in this new u-boot, the stdin/stdout/stderr netconsole was change from "serial" to "serial,nc". Therefore, if netconsole is used, you must adjust the start_netconsole env.
fw_setenv start_netconsole 'setenv ncip $serverip; setenv bootdelay 10; setenv stdin serial,nc; setenv stdout serial,nc; setenv stderr serial,nc; version'


C.2. Distro Boot

C.2.1 (Optional) Booting all distros

In this new u-boot, I've implemented the Distro Boot capability. So any distro (such as Ubuntu, Alpine, Fedora, etc.) can be booted as long as they conform to the Distro Boot standard. However, for the purpose of booting our Debian Kirkwood kernel released here for this box, it is not relevant and should be ignored.

C.2.2 Using boot.scr to recover from damaged or corrupted envs NAND block

Included in the tarball uboot.2023.04-tld-1.nsa325.bodhi.tar is the script file uboot.2023.04-tld-1.nsa325.boot.scr. This is a Distro-Boot-compliant boot script. It can be used to recover from a damaged/corrupted envs NAND block, or if the envs NAND block has never been flashed (same as corrupted).

So for whatever reason, if in serial console, U-Boot reported the CRC error while loading the envs, using the boot.scr will provide a minimalist booting envs and enable booting into Debian. And then the default envs image can be flashed.

- Mount the USB rootfs on another Linux box. Assuming it is mounted at /media/sdb1.

cd /media/sdb1/boot
cp -a uboot.2023.04-tld-1.nsa325.boot.scr boot.scr
sync

- Unmount and then bring it back to the NSA325. Power up and let it boot automatically. The boot.scr should come into play, and allow booting to Debian.


C.3. uEnv.txt

This capabilty is the same as in previously released u-boot-2017.07-tld-1.

Description TBD.

END of NOTE.

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



Edited 4 time(s). Last edit at 07/08/2023 12:06AM by bodhi.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
June 09, 2023 11:30PM
1st post updated:

Quote

8. (Optional) Activate netconsole

Please do not activate netconsole! I'm troubleshooting a problem, stay tune... .

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
July 01, 2023 03:34PM
I've uploaded a new version:

Quote

Update 01 July 2023: Fixed netconsole

If you've already installed May 26 version, then you only need to flash the new u-boot image as described in step 5:

Quote

5. Flash u-boot image to NAND

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
September 03, 2023 04:09AM
Hi bodhi,

Thank you for your hard work and keeping those devices alive. Where could I find the source code for this updated u-boot? I would like to adapt my u-boot (for Freecom Silverstore HNCN2) so it could boot from the USB 3.0.

Thank you

---------------------------------


Regards,
garagoyun
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
September 03, 2023 02:34PM
garagoyun,

I've sent in the patch to mainline this NSA325 u-boot. It went through review and will be in the mainline tree soon. I also did the same for the Pogo V4 (sometime last year).

The difference between the mainline version of Kirkwood u-boots and my downstream versions here are minor. Some minor changes are not suitable for mainline so I carry the patches here.

And I have not got around to push the Kirkwood 2023.04-tld-1 branch to GitHub yet. But I will upload the rest of the binaries to Dropbox (one by one after I done some tests for each).

So for the Freecom Silverstore HNCN2, you could wait for the u-boot release candidate 2023.10-rc4 and use that version to clone the NSA325 and start from there.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
September 03, 2023 03:40PM
bodhi,

Great! Thank you very much!

---------------------------------


Regards,
garagoyun
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
September 04, 2023 01:19PM
> So for the Freecom Silverstore HNCN2, you could
> wait for the u-boot release candidate 2023.10-rc4
> and use that version to clone the NSA325 and start
> from there.

Actually, I think Oct 2nd (when u-boot 2023.10 wil be released) is a better time to look for the board.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
September 04, 2023 01:46PM
Quote

Actually, I think Oct 2nd (when u-boot 2023.10 wil be released) is a better time to look for the board.

No problems. I am overloaded with work at the moment anyway. I usually have free time towards the end of the year.

Thanks!

---------------------------------


Regards,
garagoyun
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: