Welcome! Log In Create A New Profile

Advanced

NSA320 Bad eraseblock

Posted by Pentim 
NSA320 Bad eraseblock
May 24, 2019 02:28PM
Hi everyone,

first of all thx for all your work, you are doing a great job!

I'm trying to install uboot on my zyxel NSA320 device, but during the check for the bad blocks I'm getting this message:

Scanning device for bad blocks
Bad eraseblock 4 at 0x000000080000

Could you please advice me, what I have to do now?
Re: NSA320 Bad eraseblock
May 24, 2019 09:54PM
Pentim,

> Scanning device for bad blocks
> Bad eraseblock 4 at 0x000000080000
>
> Could you please advice me, what I have to do now?

Bad eraseblock 4 is right in the middle of u-boot image in NAND. You should not flash u-boot at the moment without help. It is risky, it could likely brick your box.

What you need to do is:

1. Connect serial console, and run UART booting using kwboot with u-boot image uboot.2017.07-tld-1.nsa320.mtd0.kwb from the tarball (see u-boot instruction, 1st post).

uboot.2017.07-tld-1.nsa320.bodhi.tar

2. After you are succefully starting u-boot image uboot.2017.07-tld-1.nsa320.mtd0.kwb with kwboot consistenly, come back and I'll lay out the steps you need to do to flash new u-boot safely.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: NSA320 Bad eraseblock
May 26, 2019 02:14AM
Hi bodhi,

so I was able to boot with UART

[Type Ctrl-\ + c to quit]


U-Boot 2017.07-tld-1 (Sep 05 2017 - 00:46:11 -0700)
ZyXEL NSA320 2-Bay Power Media Server

SoC:   Kirkwood 88F6281_A1
DRAM:  512 MiB
WARNING: Caches not enabled
NAND:  128 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   egiga0
MV88E1318 PHY initialized on egiga0

What is the next step?



Edited 2 time(s). Last edit at 05/26/2019 02:19AM by Pentim.
Re: NSA320 Bad eraseblock
May 26, 2019 01:30PM
Pentim,

Most of the time, it will be OK when there is enough space in NAND. But that also depending on your current environment where you do the flash (e.g. stock OS). And mtd definition.

There are 11 steps in the installation instruction. You should do step 1 to 5. And then post the log of these steps and their output here. After I check to see if there is anything that could prevent a successful flashing, I will let you know if you should start step 6.

https://forum.doozan.com/read.php?3,12381

Quote

A. Flashing Instruction:


Installation is the same for each u-Boot image, the instruction below is written to include all boxes. So choose the platform name that you are installing for, and copy/paste the appropriate commands.

If you are running kernel that do 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.

1. uBoot 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

- And your mtd partitions should be:

cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00400000 00020000 "uImage"
mtd2: 02000000 00020000 "rootfs"
mtd3: 0db00000 00020000 "data"

Note: for boxes such as Pogo V4 and Zyxel NSA3xx, the mtd partition definition are kept the same as stock definition, therefore is different from the one above.

If you don't have /etc/fw_env.config file in your system then go ahead and create this file with the above content. MTD parts are not important for booting and it can be adjusted later. For users who like to keep the stock mtd definition, there is no need to adjust it to the above definition. As long as mtd0 is defined as 1MB (0x00100000) or greater then it will be OK:
mtd0: 00100000 00020000 "u-boot"

2. Make sure ethaddr is set in uBoot env. It must be set before rebooting the system. However, if you plan to flash the default envs image in step 8 (Flashing default u-boot envs image), then no need to worry about it now. It can be set after you've booted in to Linux. The MAC address will be set to a valid randomly generated local address.
fw_printenv ethaddr

3. Be sure to save your current uBoot image in mtd0, or have a backup image saved somewhere as precaution. And save your current u-boot envs with fw_printenv, or just copy/paste the listing into a text file. Note the nanddump command below allows future restoration to the same box you're backing up, and also can be used to restore a differrent box's mtd0 if needed.

Dumping NAND mtd0:
nanddump --noecc --omitoob -l 0x80000 -f mtd0 /dev/mtd0
Save envs:
fw_printenv > current_envs.txt
or
blparam > current_envs.txt

4. Be sure there is no bad block in the first 1M of your NAND (check dmesg). This is very important, if there is bad block in the first 1M (8 blocks), don't flash u-boot, because you will almost certainly brick your box. Please post your question here (there is a work around for it).

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 block is the 4th block which resides within mtd0 (block 0 to block 7). So u-boot should not be flashed.

5. Extract the archive to /tmp

Among the tar commands below, be careful and execute only one tar command corresponding to your platform that you are installing to, using the tar file that you have downloaded before starting the flashing instruction. Beware of the similar sounding name of different u-boots (nsa310s and nsa310 are two different u-boots).
cd /tmp
tar -xf uboot.2017.07-tld-1.dockstar.bodhi.tar
tar -xf uboot.2017.07-tld-1.goflexhome.bodhi.tar
tar -xf uboot.2017.07-tld-1.goflexnet.bodhi.tar
tar -xf uboot.2017.07-tld-1.iconnect.bodhi.tar
tar -xf uboot.2017.07-tld-1.netgear_ms2110.bodhi.tar
tar -xf uboot.2017.07-tld-1.pogo_e02.bodhi.tar
tar -xf uboot.2017.07-tld-1.pogo_v4.bodhi.tar
tar -xf uboot.2017.07-tld-2.sheevaplug.bodhi.tar
tar -xf uboot.2017.07-tld-1.nsa320.bodhi.tar
tar -xf uboot.2017.07-tld-1.nsa325.bodhi.tar
tar -xf uboot.2017.07-tld-1.nsa310s.bodhi.tar
tar -xf uboot.2017.07-tld-1.nsa310.bodhi.tar

Be extra careful with the next 2 commands in step 6 and 7, 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.

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

7. Write image to NAND

Among the nandwrite commands below, be extra careful and execute only one nandwrite command corresponding to your platform that you are installing to, using the kwb file that you have extracted in step 5. Please double check to make sure the file is for the correct platform. Especially the similar sounding names (e.g. nsa310s and nsa310 are different u-boots).

nandwrite /dev/mtd0 uboot.2017.07-tld-1.dockstar.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.goflexhome.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.goflexnet.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.iconnect.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.netgear_ms2110.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.pogo_e02.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.pogo_v4.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-2.sheevaplug.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.nsa320.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.nsa325.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.nsa310s.mtd0.kwb
nandwrite /dev/mtd0 uboot.2017.07-tld-1.nsa310.mtd0.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

8. Flashing default u-boot envs image (if you are upgrading from 2016.05-tld-1 u-boot, you can skip this step 8).

As described in step 1, u-boot envs must be defined in /etc/fw_env.config as

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

This default envs image supports booting with multiple disk drives (and hubs) attached. The disk drives could be any type (usb, sata, sd card). The scanning logic and default envs were set to automatically boot the box with the following required configuration:

For whatever reason, if you can't set up your configuration to satisfy the following 4 requirements, then don't flash this defaut envs image. It might not boot properly. In this case, section C below can be used to tailor the envs to your specific configuration.

r1. There must be only one partition among all partitions from all drives that contains the kernel files. The 2 kernel files are /boot/uImage and /boot/uInitrd.
r2. The partition that contains the 2 kernel files must be partition 1 in a disk drive
r3. The partition that contains the rootfs must be labeled rootfs
r4. The rootfs partition is recommended to be type Ext3 (this is not a hard requirement, ext4 should boot OK, but Ext3 will ensure no problem).

So the bottom line is if you have only one rootfs in a single Ext3 partition, which is labeled as rootfs, then you're all set.

a. Download the default u-boot envs at Dropbox:

uboot.2016.05-tld-1.environment.bodhi.tar
md5:
3823eef10011b864859d31a76470e0e3
sha256:
c8db95a4225e8d78bdaaaa372bd5a87e4b98f3448dd9c62fc96c72b2df1a997c

This tarball includes 3 files:

uboot.2016.05-tld-1.environment.img (the default envs image to be flashed)
uboot.2016.05-tld-1.environment (the content of the default envs in text format)
uboot.2016.05-tld-1.environment.64K.img (small envs image to be flashed on HP T5325 only).

b. Extract the archive to /tmp
cd /tmp
tar -xf uboot.2016.05-tld-1.environment.bodhi.tar

c. Save current envs with fw_printenv, or just copy/paste the listing into a text file.
fw_printenv > current_envs.txt

d. Flash u-boot envs to NAND location 0xC0000.

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.

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

/usr/sbin/nandwrite -s 786432 /dev/mtd0 uboot.2016.05-tld-1.environment.img
Expected output:
Writing data to block 6 at offset 0xc0000

e. Modify the following u-boot variables using fw_setenv:

e.1 ArcNumber:

Note that arcNumber and machid are not necessary if you are booting with FDT kernel 3.17+ in the latest kernel and rootfs thread. But it does not hurt to set them anyway.

archNumber and machid are required for non-FDT kernel (3.16.x or earlier)

Also note that only some boxes need machid, some don't (so the command fw_setenv machid below clears them).

for Pogo V4/Mobile:
fw_setenv arcNumber 3960
fw_setenv machid f78

for iConnect:
fw_setenv arcNumber 2870
fw_setenv machid

for Stora:
fw_setenv arcNumber 2743
fw_setenv machid

for Dockstar:
fw_setenv arcNumber 2998
fw_setenv machid

for Pogo E02:
fw_setenv arcNumber 3542
fw_setenv machid dd6

for GoFlex Home:
fw_setenv arcNumber 3338
fw_setenv machid


for GoFlex Net:
fw_setenv arcNumber 3089
fw_setenv machid

for Sheevaplug:
fw_setenv arcNumber 2097
fw_setenv machid

for NSA325:
fw_setenv arcNumber 4495
fw_setenv machid

for NSA320:
fw_setenv arcNumber 3956
fw_setenv machid

for NSA310S/320S:
fw_setenv arcNumber 4931
fw_setenv machid

for NSA310:
fw_setenv arcNumber 4022
fw_setenv machid

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'

e.3 uEnv.txt envs correction (optional):

These envs are important to be set if you plan to use uEnv.txt (see section C).

fw_setenv uenv_init_devices 'echo Initializing devices...; setenv init_usb "usb start"; setenv init_ide "ide reset"; setenv init_mmc "mmc rescan"; for devtype in $devices; do run init_$devtype; done'
fw_setenv uenv_read 'echo Loading envs from $device_type $disk_number...; if load $device_type $disk_number:1 $uenv_addr /boot/uEnv.txt; then setenv uenv_loaded 1; echo ... envs loaded; fi'
fw_setenv uenv_load 'run uenv_init_devices; setenv uenv_loaded 0; for devtype in $devices; do for disknum in $disks; do if test $uenv_loaded -eq 0; then setenv device_type $devtype; setenv disk_number $disknum; run uenv_read; fi; done; done;'
fw_setenv uenv_read_disk

And for boxes that boot with SATA as rootfs. Please make this adjustment if your boot drive is SATA. This will help the "ide reset" to work properly. There seems to be a bug in u-boot that if you do "ide reset" too quickly in succession, the SATA drive might have problem spinning up).
fw_setenv bootcmd_uenv 'run uenv_load; if test $uenv_loaded -eq 1; then run uenv_import; fi; sleep 3'


f. Adjust the DTB name to boot with a rootfs that has FDT kernel 3.17+ (this is the normal case):

Find your box DTB file in the rootfs /boot/dts directory and adjust the env to it. For example, if the box is the Dockstar
fw_setenv dtb_file '/boot/dts/kirkwood-dockstar.dtb'

In the special case when you are booting with a non-FDT kernel 3.16 or earlier, or if you have appended the DTB to uImage. Remove the DTB file env. If not sure please post question before continuing.
fw_setenv dtb_file

h. For sanity check, list you envs again
fw_printenv

If there is error in listing u-boot envs, stop here and post your problem so we can help.

Remember to save away your old envs text file created in step c for future reference in case more need to be restored.

i. Done step 8.


9. For sanity check, print out uBoot envs to see if they look OK.
fw_printenv
and then double check the ethaddr env again to be sure. Don't reboot if there is error while listing U-Boot envs.

10. Set up netconsole. It's important to set up neconsole if you don't already have serial console connected. If you have serial console, don't set up netconsole at this moment, because it will interfere with serial console.

If you've flashed the default environments in step 8 then activate netconsole with the following envs:

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 plug IP address, and 192.168.0.yyy is the IP address of the netconsole server where it will monitor the output from the this plug (adjust them to the real values in your own local network settings).

fw_setenv preboot_nc 'setenv nc_ready 0; for pingstat in 1 2 3 4 5; do; sleep 1; if run if_netconsole; then setenv nc_ready 1; fi; done; if test $nc_ready -eq 1; then run start_netconsole; fi'
fw_setenv preboot 'run preboot_nc'
fw_setenv ipaddr '192.168.0.xxx'
fw_setenv serverip '192.168.0.yyy'


11. Reboot. Upon reboot, in either serial console or netconsole, uBoot banner should show:

U-Boot 2017.07-tld-1 (….)
<your box name>

DONE installation.

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



Edited 1 time(s). Last edit at 05/26/2019 01:31PM by bodhi.
Re: NSA320 Bad eraseblock
May 26, 2019 04:23PM
Hi bodhi,

here you are:

Step 1.

cat /etc/fw_env.config 
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR.

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

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"


Step 2.

fw_printenv ethaddr
ethaddr=B0:B2:DC:F0:FA:0D

Step .3

nanddump --noecc --omitoob -l 0x80000 -f mtd0 /dev/mtd1
nanddump: unrecognized option '--noecc'
Usage: nanddump [OPTIONS] MTD-device
Dumps the contents of a nand mtd partition.

           --help     	        display this help and exit
           --version  	        output version information and exit
-f file    --file=file          dump to file
-i         --ignoreerrors       ignore errors
-l length  --length=length      length
-o         --omitoob            omit oob data
-b         --omitbad            omit bad blocks from the dump
-p         --prettyprint        print nice (hexdump)
-s addr    --startaddress=addr  start address

nanddump --omitoob -l 0x80000 -f mtd0 /dev/mtd0
Block size 131072, page size 2048, OOB size 64
Dumping data starting at 0x00000000 and ending at 0x00100000...

nanddump --omitoob -l 0x80000 -f mtd1 /dev/mtd1
Block size 131072, page size 2048, OOB size 64
Dumping data starting at 0x00000000 and ending at 0x00080000...

Step 4.

dmesg | grep -i 'bad' 
Scanning device for bad blocks
Bad eraseblock 4 at 0x000000080000

Step 5.

tar -xf /e-data/cf9da6436268c997f2f576bb789f5347/uboot.2017.07-tld-1.nsa3
20.bodhi.tar 
/tmp # ls -la 
drwxrwxrwx    6 root     root             0 May 26 21:19 .
drwxr-xr-x   19 root     root             0 Jan  1  1970 ..
-rw-rw-rw-    1 root     root            34 May 26 21:09 LCD.txt
-rw-r--r--    1 root     root            11 May 26 21:09 __appwd__
-rw-r--r--    1 root     root           252 May 26 21:11 clidump.zyshd
-rw-r--r--    1 root     root             0 May 26 21:09 diskmap.map
-rw-r--r--    1 root     root            21 May 26 21:19 dropbox.idling
-rw-r--r--    1 root     root            26 May 26 21:09 ediskmap.map
drwxr-xr-x    2 root     root             0 May 26 21:09 fwupgrade
-rw-rw-rw-    1 root     root           253 May 26 21:09 job_controller.log
-rw-------    1 root     root             0 May 26 21:08 libzydb.lock
-rw-r--r--    1 root     root          1389 May 26 21:11 michael.txt
-rw-r--r--    1 root     root           363 May 26 21:09 nsu_progress
-rw-rw-rw-    1 root     root           360 May 26 21:11 sch_debug.log
-rw-r--r--    1 root     root          1065 May 26 21:09 smb.conf
-rw-r--r--    1 root     root          1234 May 26 21:09 smb.conf.new
-rw-rw-rw-    1 root     root            10 May 26 21:09 smb_user
-rw-r--r--    1 root     root          2198 May 26 21:08 startup-config.conf
drwxrwxrwt    4 root     root            80 May 26 21:08 tmpfs
-rw-r--r--    1 root     root        524288 Sep  5  2017 uboot.2017.07-tld-1.nsa320.mtd0.kwb
-rwxr-xr-x    1 root     root             6 Mar 11  2016 user
drwxr-xr-x    4 root     root             0 Mar 11  2016 users
srwx------    1 nobody   root             0 May 26 21:08 wsgi.1519.0.1.sock
srwx------    1 nobody   root             0 May 26 21:09 wsgi.1931.0.1.sock
-rwxr-xr-x    1 root     root             6 Mar 11  2016 y.file
-rw-rw-rw-    1 root     root            36 May 26 21:09 zyfw_debug.log
prwxrwxrwx    1 root     root             0 May 26 21:08 zylog_fifo1
prwxrwxrwx    1 root     root             0 May 26 21:08 zylog_fifo2
prwxrwxrwx    1 root     root             0 May 26 21:08 zylog_fifo3
prwxrwxrwx    1 root     root             0 May 26 21:08 zylog_fifo4
-rw-rw-rw-    1 root     root            23 May 26 21:09 zypkg_log_failed.log
-rw-rw-rw-    1 root     root             4 May 26 21:09 zypkglist_download.progress
drwxr-xr-x   11 root     root             0 May 26 21:08 zyxel
Re: NSA320 Bad eraseblock
May 26, 2019 10:30PM
Pentim,

Go ahead and do Step 6 and 7 to erase and flash u-boot image uboot.2017.07-tld-1.nsa320.mtd0.kwb.

And post the log here.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: NSA320 Bad eraseblock
May 27, 2019 04:23AM
bodhi,

can I restart the device after points 6 and 7? Or it will break something?
Re: NSA320 Bad eraseblock
May 27, 2019 05:45PM
Pentim,

> can I restart the device after points 6 and 7? Or
> it will break something?

Have you done step 6 and 7 and have a log you can post?

The installation is not done, but if step 6 and 7 were successful, and then you accidentally reboot, it will be OK. U-boot will run and you will be able to interrupt it and set envs to boot.

Since you already can kwboot this box, you can always recover if something went wrong.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: NSA320 Bad eraseblock
May 28, 2019 09:47AM
bodhi,

so far so good:

Step 6.

Erasing 128 Kibyte @ 60000 -- 100 % complete

Step 7.

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

what to do as next?



Edited 1 time(s). Last edit at 05/28/2019 12:11PM by Pentim.
Re: NSA320 Bad eraseblock
May 28, 2019 05:00PM
Pentim,

> so far so good:
>
> Step 6.
>
>
> Erasing 128 Kibyte @ 60000 -- 100 % complete
>
>
> Step 7.
>
>
> 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
>
>
> what to do as next?

Continue with step 8 and the rest.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: NSA320 Bad eraseblock
May 29, 2019 02:28AM
bodhi,

it is working!

U-Boot 2017.07-tld-1 (Sep 05 2017 - 00:46:11 -0700)
ZyXEL NSA320 2-Bay Power Media Server

SoC:   Kirkwood 88F6281_A1
DRAM:  512 MiB
WARNING: Caches not enabled
NAND:  128 MiB
In:    serial
Out:   serial
Err:   serial
Net:   egiga0
MV88E1318 PHY initialized on egiga0

Thx man! You are the best!
Re: NSA320 Bad eraseblock
May 29, 2019 05:14AM
Cool!

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