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
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 01:58PM
hi,
1. got only 4 partitions:
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000
root@debian:/boot# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00400000 00020000 "uImage"
mtd2: 02000000 00020000 "rootfs"
mtd3: 05b00000 00020000 "data"

2. Bad blocks are:
root@debian:/boot/nand_backup# dmesg | grep -i 'bad'
[ 8.632478] Scanning device for bad blocks
[ 8.642563] Bad eraseblock 100 at 0x000000c80000
[ 8.653102] Bad eraseblock 200 at 0x000001900000
[ 281.253499] sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 281.278377] sd 0:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

May i proceeed from your rootfs USB as boot/target system with ssd and hdd still does noe treplay on SSH, installed ACPI and get orange flasing led...
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 02:28PM
zebe,

Quote

1. got only 4 partitions:
# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000
root@debian:/boot# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00400000 00020000 "uImage"
mtd2: 02000000 00020000 "rootfs"
mtd3: 05b00000 00020000 "data"

That was because during installation for the u-boot 2017.07-tld-1, you did not adjust your mtdparts as instructed:

Quote
https://forum.doozan.com/read.php?3,12381
e.2 Box specific envs:

Then for all boxes, restore these 2 envs using the saved envs text in step c (replace xxx with the real saved values)
fw_setenv mtdparts 'xxxxxxxxx'
fw_setenv ethaddr 'xx:xx:xx:xx:xx:xx'

But it is OK. After you install this u-boot 2023.04-tld-1, it will be corrected automatically in the envs.

Quote

2. Bad blocks are:
root@debian:/boot/nand_backup# dmesg | grep -i 'bad'
[    8.632478] Scanning device for bad blocks
[    8.642563] Bad eraseblock 100 at 0x000000c80000
[    8.653102] Bad eraseblock 200 at 0x000001900000
[  281.253499] sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[  281.278377] sd 0:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

The above bad blocks are OK. They are far from mtd0, which is the 1st MB (blocks 0 to 7).

Quote
Instruction
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.

And yes you can flash the new u-boot image and its envs image. Your mtd0 is 1MB as shown below:

Quote

root@debian:/boot# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00400000 00020000 "uImage"
mtd2: 02000000 00020000 "rootfs"
mtd3: 05b00000 00020000 "data"

====

With all that said, it is always a good idea to connect serial console so you can see the booting progress. And rescue your box (if you had made some mistake during installation, or there is a power outage during the flashing operations).

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



Edited 1 time(s). Last edit at 10/29/2023 02:31PM by bodhi.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 02:54PM
... And i did it, so far w/out Uart and.. got into bootloop.
So Uart eventually inavoidable (
Suspect syntax errors because i used bash syntax: Export Variable = no-paretheses-value instead of that
Tcsh/no setenv, printenv command available/. May it be so?



Edited 3 time(s). Last edit at 10/29/2023 02:59PM by zebe.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 04:06PM
> So Uart eventually inavoidable (
> Suspect syntax errors because i used bash syntax:
> Export Variable = no-paretheses-value instead of
> that
> Tcsh/no setenv, printenv command available/. May
> it be so?

Yes. The envs must be set exactly as stated in the instruction.

Now before hooking up serial console, you can try using the USB rescue rootfs to boot again

But to ensure it will boot, set the envs to exactly as default values. Do this:

Mount the USB rootfs on another Linux box. Assuming it is mounted at /media/sdb1. And you still have the uEnv.txt there in /boot.

cd /media/sdb1/boot
mv uEnv.txt uEnv.txt.rescue

Copy the default envs file from the u-boot tarball to this USB rootfs, and make a new uEnv.txt.

cp -a uboot.2023.04-tld-1.nsa325.environment uEnv.txt

And then edit the uEnv.txt files to replace what's currently there with
device=0:1
device_type=usb
devices=usb
disk_number=0
disks=0 1 2 3

And then sync, umount, remove the USB rootfs, bring it back to the NSA325, cold start. Basically follow the same steps in the How-To you have done once before.

After you have booted into the USB rootfs, you can proceed to fix the envs in NAND so it will boot properly without uEnv.txt.

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



Edited 1 time(s). Last edit at 10/29/2023 04:08PM by bodhi.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 04:58PM
Ok, this means i should switch from bash to tcsh first because there is no setenv, printenvcommand otherwise...?
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 05:06PM
The setenv and printenv commands are u-boot shell commands, not Linux shell commands. Therefore the shell you are using from Linux have no bearing. From Linux you would use the fw_printenv and fw_setenv commands after first setting the appropriate values in /etc/fw_env.config.

Ray
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 29, 2023 05:11PM
zebe,

> Ok, this means i should switch from bash to tcsh
> first because there is no setenv, printenvcommand
> otherwise...?

No. As I said, you need to basically copy/paste the fw_setenvs commands as instructed in the Installation Steps. If you have problem doing that, then it's a hint that you are not doing the installation correctly. And a standard Debian default shell should be used.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
October 30, 2023 08:38AM
OK but unfortunately still cant ping my box, UART to be done eventually..
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
November 06, 2023 12:05PM
OK,hi again.
\Booting w.random eth addres...



Edited 6 time(s). Last edit at 11/06/2023 02:05PM by zebe.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
November 06, 2023 01:34PM
zebe,

With serial console connected, power up, and let it boot automatically, all the way into Debian. Log in, and

cat /proc/mtd
cat /etc/fw_env.config
fw_printenv
mount

And post the entire serial console log here (post everything on your terminal).

And btw, don't do fsck -A. When you want to check file system, it should be per partition. Like:
e2fsck /dev/sda1
e2fsck /dev/sdb1

..... so on

This box mtd5 is prone for that ecc error. It can be ignored, we are not booting stock OS on NAND.

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



Edited 1 time(s). Last edit at 11/06/2023 07:55PM by bodhi.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
November 07, 2023 06:03AM
Cant get consistent eth0 w/DHCP in my LAN.
Unless i command reboot via UART link...



Edited 4 time(s). Last edit at 11/07/2023 12:44PM by zebe.
Re: 2023.04 U-Boot Kirkwood - ZyXEL NSA325
November 07, 2023 01:46PM
https://forum.doozan.com/read.php?3,135222,136102#msg-136102

> With serial console connected, power up, and let
> it boot automatically, all the way into Debian.
> Log in, and
>
>
> cat /proc/mtd
> cat /etc/fw_env.config
> fw_printenv
> mount
>
>
> And post the entire serial console log here (post
> everything on your terminal).

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
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: