Uncorrectable ECC error (image for dlink dns320l)

Hello. I'm trying to build image for dlink dns320l. I did this:

diff --git a/target/linux/kirkwood/files/arch/arm/boot/dts/kirkwood-dns320.dts b/target/linux/kirkwood/files/arch/arm/boot/dts/kirkwood-dns320.dts
new file mode 100644
index 0000000000..58bf1face0
--- /dev/null
+++ b/target/linux/kirkwood/files/arch/arm/boot/dts/kirkwood-dns320.dts
@@ -0,0 +1,183 @@
+/dts-v1/;
+
+#include "kirkwood.dtsi"
+#include "kirkwood-6281.dtsi"
+
+/ {
+       model = "D-Link DNS-320L";
+       compatible = "dlink,dns-320l", "marvell,kirkwood-88f6702", "marvell,kirkwood";
+
+       memory {
+               device_type = "memory";
+               reg = <0x00000000 0x10000000>;
+       };
+
+       chosen {
+               bootargs = "console=ttyS0,115200";
+       };
+
+       ocp@f1000000 {
+               serial@12000 {
+                       status = "okay";
+               };
+
+               serial@12100 {
+                       pinctrl-0 = <&pmx_uart1>;
+                       pinctrl-names = "default";
+                       status = "okay";
+               };
+
+               sata@80000 {
+                       status = "okay";
+                       nr-ports = <2>;
+               };
+
+       };
+
+       gpio_keys {
+               compatible = "gpio-keys";
+               pinctrl-0 = <&pmx_button_reset &pmx_button_usb_copy>;
+               pinctrl-names = "default";
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               button@1 {
+                       label = "Reset push button";
+                       linux,code = <0x198>;
+                       gpios = <&gpio0 28 1>;
+               };
+               button@2 {
+                       label = "USB unmount button";
+                       linux,code = <161>;
+                       gpios = <&gpio0 27 1>;
+               };
+       };
+
+       gpio-leds {
+               compatible = "gpio-leds";
+               pinctrl-0 = <&pmx_led_usb_blue &pmx_led_usb_orange
+                            &pmx_led_red_left_hdd &pmx_led_red_right_hdd>;
+               pinctrl-names = "default";
+
+               blue-usb {
+                       label = "dns320l:blue:usb";
+                       gpios = <&gpio0 25 0>;
+               };
+               orange-l_hdd {
+                       label = "dns320l:orange:l_hdd";
+                       gpios = <&gpio0 22 0>;
+               };
+               orange-r_hdd {
+                       label = "dns320l:orange:r_hdd";
+                       gpios = <&gpio0 23 0>;
+               };
+               orange-usb {
+                       label = "dns320l:orange:usb";
+                       gpios = <&gpio0 26 0>;
+               };
+       };
+
+       regulators {
+               compatible = "simple-bus";
+               #address-cells = <1>;
+               #size-cells = <0>;
+               pinctrl-0 = <&pmx_power_sata>;
+               pinctrl-names = "default";
+
+               sata_power: regulator@1 {
+                       compatible = "regulator-fixed";
+                       reg = <1>;
+                       regulator-name = "SATA Power";
+                       regulator-min-microvolt = <5000000>;
+                       regulator-max-microvolt = <5000000>;
+                       enable-active-high;
+                       regulator-always-on;
+                       regulator-boot-on;
+                       gpio = <&gpio1 24 0>;
+               };
+       };
+};
+
+&nand {
+       status = "okay";
+       chip-delay = <35>;
+       pinctrl-0 = <&pmx_nand>;
+       partition@0 {
+               label = "u-boot";
+               reg = <0x0000000 0x100000>;
+               read-only;
+       };
+
+       partition@100000 {
+               label = "firmware";
+               reg = <0x0100000 0x7a00000>;
+       };
+
+       partition@07b00000 {
+               label = "config";
+               reg = <0x7b00000 0x0500000>;
+               read-only;
+       };
+};
+
+
+&pinctrl {
+       pinctrl-0 = <&pmx_button_power>;
+       pinctrl-names = "default";
+
+       pmx_sata0: pmx-sata0 {
+               marvell,pins = "mpp20";
+               marvell,function = "sata1";
+       };
+       pmx_sata1: pmx-sata1 {
+               marvell,pins = "mpp21";
+               marvell,function = "sata0";
+       };
+       pmx_led_red_right_hdd: pmx-led-red-right-hdd {
+               marvell,pins = "mpp22";
+               marvell,function = "gpio";
+       };
+       pmx_led_red_left_hdd: pmx-led-red-left-hdd {
+               marvell,pins = "mpp23";
+               marvell,function = "gpio";
+       };
+       pmx_power_sata: pmx-power-sata {
+               marvell,pins = "mpp24";
+               marvell,function = "gpio";
+       };
+       pmx_led_usb_blue: pmx-led-usb-blue {
+               marvell,pins = "mpp25";
+               marvell,function = "gpio";
+       };
+       pmx_led_usb_orange: pmx-led-usb-orange {
+               marvell,pins = "mpp26";
+               marvell,function = "gpio";
+       };
+       pmx_button_usb_copy: pmx-button-usb-copy {
+               marvell,pins = "mpp27";
+               marvell,function = "gpio";
+       };
+       pmx_button_reset: pmx-button-reset {
+               marvell,pins = "mpp28";
+               marvell,function = "gpio";
+       };
+       pmx_button_power: pmx-button-power { // I can't get this one to trigger a button press...
+               marvell,pins = "mpp29";
+               marvell,function = "gpio";
+       };
+};
+&mdio {
+       status = "okay";
+
+       ethphy0: ethernet-phy@0 {
+               device_type = "ethernet-phy";
+               reg = <0>;
+       };
+};
+
+&eth0 {
+       status = "okay";
+       ethernet0-port@0 {
+               phy-handle = <&ethphy0>;
+       };
+};
diff --git a/target/linux/kirkwood/image/Makefile b/target/linux/kirkwood/image/Makefile
index 60e8654ad3..4e6b9e1f8e 100644
--- a/target/linux/kirkwood/image/Makefile
+++ b/target/linux/kirkwood/image/Makefile
@@ -140,6 +140,17 @@ define Device/ctera_c200-v1
 endef
 TARGET_DEVICES += ctera_c200-v1

+define Device/dlink_dns320
+   DEVICE_VENDOR := D-Link
+   DEVICE_MODEL := DNS320
+   KERNEL_SIZE := 4096k
+   IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi
+   DEVICE_PACKAGES := \
+     kmod-ata-core kmod-ata-marvell-sata \
+     kmod-usb2 kmod-usb-storage
+endef
+TARGET_DEVICES += dlink_dns320
+
 define Device/endian_4i-edge-200
   DEVICE_VENDOR := Endian
   DEVICE_MODEL := 4i Edge 200

I've tried flashing it through uboot with:

tftp 0xa00000 firmware.bin; nand erase 0x0100000 0x7a00000; nand write 0xa00000 0x0100000 0x940000; nand read 0xa00000 0x100000 0x400000; bootm 0xa00000

after boot kernel see splitted "kernel" and "ubi" and dies with millions __nand_correct_data: uncorrectable ECC error errors while attaching ubi.

I've tried booting from tftp with initrd erasing the mtd first from uboot:

nand erase 0x0100000 0x7a00000

nandtest /dev/mtd1 # right after boot works fine. 0 errors, 0 ecc corrections, 0 badblocks
dd if=/dev/zero | nandwrite /dev/mtd1 ; nandtest /dev/mtd1 # works fine
dd if=/dev/random | nandwrite /dev/mtd1; nandtest /dev/mtd1 # works just fine as well
nandwrite /dev/mtd1 /mnt/firmware.bin works fine, but
dd if=/dev/mtd1 of=/dev/null starting to throw tons of __nand_correct_data: uncorrectable ECC error
if i try to dd if=/dev/zero | nandwrite /dev/mtd1 after that it won't recover and keeps throwing errors.
and nandtest keeps showing same ecc errors:

root@OpenWrt:/# nandtest /dev/mtd1
ECC corrections: 22
ECC failures   : 250
Bad blocks     : 0
BBT blocks     : 0

erasing from uboot helps until i try to flash the image.
What am i doing so wrong or what is so wrong with the image?

Try booting an initramfs image and from there use sysupgrade or ubiformat, instead. Ubi doesn't really like you writing ubi-images to NAND directly, it wants to construct its own structures when settings it up.

If that doesn't work, then I don't know, but I'd definitely try initramfs first.

Will try sysupgrade, but it's unlikely to work - nothing can write to mtd, i doubt sysupgrade will succeed at this.

Meanwhile some detailed logs:

writing & booting from nand:

booting from tftp and testing nand:

Yeah, pretty much the same with sysupgrade:

root@OpenWrt:/# sysupgrade -v -F /mnt/firmware_sysupg.bin
Sat Jan  8 07:32:45 UTC 2067 upgrade: Image not in /tmp, copying...
Sat Jan  8 07:32:46 UTC 2067 upgrade: Device dlink,dns-320l not supported by this image
Sat Jan  8 07:32:46 UTC 2067 upgrade: Supported devices: dlink,dns320l
Image check failed but --force given - will update anyway!
Cannot save config while running from ramdisk.
Sat Jan  8 07:32:46 UTC 2067 upgrade: Commencing upgrade. Closing all shell sessions.
Watchdog handover: fd=3
- watchdog -
Watchdog does not have CARDRESET support
Sat Jan  8 07:32:47 UTC 2067 upgrade: Sending TERM to remaining processes ...
Sat Jan  8 07:32:51 UTC 2067 upgrade: Sending KILL to remaining processes ...
[  271.663351] stage2 (1865): drop_caches: 3
Sat Jan  8 07:32:57 UTC 2067 upgrade: Switching to ramdisk...
Sat Jan  8 07:33:00 UTC 2067 upgrade: Performing system upgrade...
Unlocking kernel ...

Writing from <stdin> to kernel ...
[  275.306047] ubi0: attaching mtd3
[  275.309725] __nand_correct_data: uncorrectable ECC error
[  275.315049] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:512, read only 64 bytes, retry
[  275.326426] __nand_correct_data: uncorrectable ECC error
[  275.331744] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:512, read only 64 bytes, retry
[  275.343112] __nand_correct_data: uncorrectable ECC error
[  275.348435] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:512, read only 64 bytes, retry
[  275.359803] __nand_correct_data: uncorrectable ECC error
[  275.365102] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:512, read 64 bytes
[  275.375170] CPU: 0 PID: 2533 Comm: ubiattach Not tainted 5.10.115 #0
[  275.381510] Hardware name: Marvell Kirkwood (Flattened Device Tree)
[  275.387787] [<c0106f50>] (unwind_backtrace) from [<c01047b4>] (show_stack+0x10/0x14)
[  275.395525] [<c01047b4>] (show_stack) from [<c04a153c>] (ubi_io_read+0x11c/0x310)
[  275.403005] [<c04a153c>] (ubi_io_read) from [<c04a1bdc>] (ubi_io_read_vid_hdr+0x4c/0x248)
[  275.411180] [<c04a1bdc>] (ubi_io_read_vid_hdr) from [<c04a6d08>] (ubi_attach+0x4b4/0x15b8)
[  275.419437] [<c04a6d08>] (ubi_attach) from [<c049b4d4>] (ubi_attach_mtd_dev+0x410/0xafc)
[  275.427499] [<c049b4d4>] (ubi_attach_mtd_dev) from [<c049c8f8>] (ctrl_cdev_ioctl+0x180/0x1f0)
[  275.436008] [<c049c8f8>] (ctrl_cdev_ioctl) from [<c023c9cc>] (sys_ioctl+0x148/0x950)
[  275.443739] [<c023c9cc>] (sys_ioctl) from [<c0100040>] (ret_fast_syscall+0x0/0x50)
[  275.451290] Exception stack(0xc2805fa8 to 0xc2805ff0)
[  275.456328] 5fa0:                   00000003 bef1fcdc 00000003 40186f40 bef1fcdc bef1fcc0
[  275.464494] 5fc0: 00000003 bef1fcdc bef1fcdc 00000036 00000003 0001279d 00000000 00000000
[  275.472650] 5fe0: 00023f88 bef1fb90 00011ba0 b6ead94c
[  275.477900] __nand_correct_data: uncorrectable ECC error
[  275.483222] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 1:512, read only 64 bytes, retry
[  275.494589] __nand_correct_data: uncorrectable ECC error
[  275.499910] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 1:512, read only 64 bytes, retry
[  275.511270] __nand_correct_data: uncorrectable ECC error
[  275.516569] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 1:512, read only 64 bytes, retry
[  275.527930] __nand_correct_data: uncorrectable ECC error
[  275.533240] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 1:512, read 64 bytes

if i try with zeroed nand it won't work as well as it's expecting to have mtd with name "ubi"

For one, nandwrite doesn't erase the flash, so it needs to be erased with flash_erase first. Just noticed you writing random data to the flash, then writing the image without erasing the flash in between, which will result in corrupted data.

For another, have you e.g. dumped the u-boot partition with nanddump and checked, if that complains about ECC-errors? Maybe even checked that e.g. binwalk identifies the dump correctly as u-boot? You know, just to check that you can read the NAND without errors?

1 Like

Yes, i dumped original FW, including uboot and factory settings, without any issues. binwalk and visually the dumps seems correct.
dd if=/dev/mtd* of=/dev/null works without any issues but only untill i write the image here. After i write the image it starting to throw errors.

I will experiment with flash_erase today evening, thank you.

Currently OpenWrt does not have support for any of the Kirkwood based D-Link NAS devices. It should be noted that the DNS-320 and DNS-320L are very different and will require separate DTS files. The mainline kernel already contains a DTS file for the DNS-320 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/kirkwood-dns320.dts so please don't use kirkwood-dns320.dts for a DTS file for the DNS-320L. There is a DTS file for DNS-320L available in the file https://www.dropbox.com/s/3ebvvo21csj24ln/linux-5.17.4-kirkwood-tld-1-bodhi.tar.bz2 which uses the kirkwood-dns320-b1.dts name.

1 Like

After Uncorrectable ECC error (image for dlink dns320l) - #4 by tsipa740 i left device unattended and today i found it booted to the right firmware from nand and working mostly fine, except of ethernet. I repeated the exercise and seems like sysupgrade works after like 5m choking with ecc errors.
@WereCatf thank you for this advice

I've used this https://www.aboehler.at/hg/linux-dns320l/raw-rev/223820522d49 so no much difference if it was 320 or 320L, it was based on 3.x kernel and had to be mostly rewritten.

Lol, thanks. What i have really a DNS-320, not 320L which explains the ethernet issue. I bought used device thinking it's 320L.

+++ b/target/linux/kirkwood/files/arch/arm/boot/dts/kirkwood-dns320-ubi.dts
@@ -0,0 +1,19 @@
+/dts-v1/;
+
+#include "kirkwood-dns320.dts"
+/ {
+        model = "D-Link DNS-320 (UBI)";
+        compatible = "dlink,dns320-ubi", "marvell,kirkwood-88f6702", "marvell,kirkwood";
+};
+
+
+&nand {
+       status = "okay";
+       partition@100000 {
+               label = "firmware";
+               reg = <0x0100000 0x7a00000>;
+       };
+       /delete-node/ partition@600000;
+       /delete-node/ partition@b00000;
+       /delete-node/ partition@7100000;
+};
diff --git a/target/linux/kirkwood/image/Makefile b/target/linux/kirkwood/image/Makefile
index 60e8654ad3..749d1d7d43 100644
--- a/target/linux/kirkwood/image/Makefile
+++ b/target/linux/kirkwood/image/Makefile
@@ -140,6 +140,17 @@ define Device/ctera_c200-v1
 endef
 TARGET_DEVICES += ctera_c200-v1

+define Device/dlink_dns320-ubi
+   DEVICE_VENDOR := D-Link
+   DEVICE_MODEL := DNS-320 (UBI)
+   KERNEL_SIZE := 4096k
+   IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi
+   DEVICE_PACKAGES := \
+     kmod-ata-core kmod-ata-marvell-sata \
+     kmod-usb2 kmod-usb-storage kmod-fs-ext4
+endef
+TARGET_DEVICES += dlink_dns320-ubi
+

works like a charm.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.