bbrezillon / linux-sunxi

sunxi linux kernel
Other
9 stars 16 forks source link

the problem of using MLC nand #3

Open den4gh opened 6 years ago

den4gh commented 6 years ago

Hello! I need help. Sorry fo my English. I have a board like a cubietrack. I try to use Micron 29F32G08CBADA I compiled mainline U-Boot 2017.09 and Linux kernel version 4.13.0 Nand is work in u-boot. But is not work in a linux kernel! I followed the directions by NAND_Howto I read many other information. when i try to any write operations in linux I get the input/output error: [root@alarm ~]# flash_erase /dev/mtd3 0 0 Erasing 2048 Kibyte @ 0 -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 0 (mtd3) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) Erasing 2048 Kibyte @ b6faecb000000006 -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 1 (m) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) Erasing 2048 Kibyte @ b6faecb00000000c -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 2 (m) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) ...

some log`s:

U-Boot 2017.09-rc3-00062-g6ef2f90-dirty (Sep 06 2017 - 02:31:55 +0700) Allwinner Technology

CPU: Allwinner A20 (SUN7I) Model: Cubietech Cubietruck I2C: ready DRAM: 512 MiB NAND: 4096 MiB

=> nand info Device 0: nand0, sector size 2048 KiB Page size 8192 b OOB size 744 b Erase size 2097152 b subpagesize 8192 b options 0x40001000 bbt options 0x00060000 => nand bad

Device 0 bad blocks: 0e400000 70000000 79000000 bd000000 fe400000 ff800000 ffa00000 ffc00000 ffe00000

=> mtdparts

device nand0 , # parts = 5

: name size offset mask_flags

0: boot0 0x00200000 0x00000000 0 1: test 0x00600000 0x00200000 0 2: uboot 0x00200000 0x00800000 0 3: boot 0x02000000 0x00a00000 0 4: rootfs 0xfd600000 0x02a00000 0 active partition: nand0,0 - (boot0) 0x00200000 @ 0x00000000 defaults: mtdids : nand0=sunxi-nand mtdparts: mtdparts=sunxi-nand:2m(boot0),6m(test),2m(uboot),32m(boot),-(rootfs)

=> ubi part nand0,4 ubi0: attaching mtd1 ubi0: scanning is finished ubi0: attached mtd1 (name "mtd=4", size 4054 MiB) ubi0: PEB size: 2097152 bytes (2048 KiB), LEB size: 2080768 bytes ubi0: min./max. I/O unit sizes: 8192/8192, sub-page size 8192 ubi0: VID header offset: 8192 (aligned 8192), data offset: 16384 ubi0: good PEBs: 2018, bad PEBs: 9, corrupted PEBs: 0 128
ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 0 ubi0: available PEBs: 1966, total reserved PEBs: 52, PEBs reserved for bad PEB handling: 31

=> ubi create myvol1 0x2000000 s 0
Creating static volume myvol1 of size 33554432

=> ubi info UBI: MTD device name: "mtd=4"
UBI: MTD device size: 4054 MiB
UBI: physical eraseblock size: 2097152 bytes (2048 KiB)
UBI: logical eraseblock size: 2080768 bytes
UBI: number of good PEBs: 2018
UBI: number of bad PEBs: 9
UBI: smallest flash I/O unit: 8192
UBI: VID header offset: 8192 (aligned 8192)
UBI: data offset: 16384
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 2
UBI: available PEBs: 1949
UBI: total number of reserved PEBs: 69
UBI: number of PEBs reserved for bad PEB handling: 31
UBI: max/mean erase counter: 2/1

=> ubi create myvol2 0x2000000 d 0
Creating dynamic volume myvol2 of size 33554432
exit not allowed from main input shell.
=> ubi remove myvol2
Volume myvol2 not found!
=> ubi create myvol2 0x2000000 d 1
Creating dynamic volume myvol2 of size 33554432

=> ubi info l Volume information dump:
vol_id 0
reserved_pebs 17
alignment 1
data_pad 0
vol_type 4
name_len 6
usable_leb_size 2080768
used_ebs 0
used_bytes 0
last_eb_bytes 2080768
corrupted 0
upd_marker 0
name myvol1
Volume information dump:
vol_id 1
reserved_pebs 17
alignment 1
data_pad 0
vol_type 3
name_len 6
usable_leb_size 2080768
used_ebs 17
used_bytes 35373056
last_eb_bytes 2080768
corrupted 0
upd_marker 0
name myvol2
Volume information dump:
vol_id 2147479551
reserved_pebs 2
alignment 1
data_pad 0
vol_type 3
name_len 13
usable_leb_size 2080768
used_ebs 2
used_bytes 4161536
last_eb_bytes 2
corrupted 0
upd_marker 0
name layout volume

in U-BOOT all works good!

My devicetree additions is the same in u-boot and linux kernel: I add to sun7i-a20.dtsi //soc@01c00000 { // ... nfc: nand@01c03000 { compatible = "allwinner,sun4i-a10-nand"; reg = <0x01c03000 0x1000>; interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; clocks = <&ahb_gates 13>, <&nand_clk>; clock-names = "ahb", "mod"; dmas = <&dma SUN4I_DMA_DEDICATED 3>; dma-names = "rxtx"; status = "disabled";

address-cells = <1>;

        #size-cells = <0>;
    };

//  ...
//  pio: pinctrl@01c20800 {
//      ...

        nand_pins_a: nand_base0@0 {
            allwinner,pins = "PC0", "PC1", "PC2",
                    "PC5", "PC8", "PC9", "PC10",
                    "PC11", "PC12", "PC13", "PC14",
                    "PC15", "PC16";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs0_pins_a: nand_cs@0 {
            allwinner,pins = "PC4";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs1_pins_a: nand_cs@1 {
            allwinner,pins = "PC3";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs2_pins_a: nand_cs@2 {
            allwinner,pins = "PC17";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs3_pins_a: nand_cs@3 {
            allwinner,pins = "PC18";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs4_pins_a: nand_cs@4 {
            allwinner,pins = "PC19";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs5_pins_a: nand_cs@5 {
            allwinner,pins = "PC20";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs6_pins_a: nand_cs@6 {
            allwinner,pins = "PC21";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_cs7_pins_a: nand_cs@7 {
            allwinner,pins = "PC22";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_rb0_pins_a: nand_rb@0 {
            allwinner,pins = "PC6";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

        nand_rb1_pins_a: nand_rb@1 {
            allwinner,pins = "PC7";
            allwinner,function = "nand0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        };

//      ...
//  };
//};

I add to sun7i-a20-cubietruck.dts

&nfc {
    pinctrl-names = "default";
    pinctrl-0 = <&nand_pins_a &nand_cs0_pins_a &nand_rb0_pins_a>;
    status = "okay"; 
    nand@0 {
        #address-cells = <2>;
        #size-cells = <2>;
        reg = <0>;
        allwinner,rb = <0>;
        nand-ecc-mode = "hw";
        nand-ecc-strength = <40>;
        nand-ecc-step-size = <1024>;
        nand-rnd-mode = "hw";
        nand-randomizer-seeds = /bits/ 16 <
            0x2b75 0x0bd0 0x5ca3 0x62d1 0x1c93 0x07e9 0x2162 0x3a72
            0x0d67 0x67f9 0x1be7 0x077d 0x032f 0x0dac 0x2716 0x2436
            0x7922 0x1510 0x3860 0x5287 0x480f 0x4252 0x1789 0x5a2d
            0x2a49 0x5e10 0x437f 0x4b4e 0x2f45 0x216e 0x5cb7 0x7130
            0x2a3f 0x60e4 0x4dc9 0x0ef0 0x0f52 0x1bb9 0x6211 0x7a56
            0x226d 0x4ea7 0x6f36 0x3692 0x38bf 0x0c62 0x05eb 0x4c55
            0x60f4 0x728c 0x3b6f 0x2037 0x7f69 0x0936 0x651a 0x4ceb
            0x6218 0x79f3 0x383f 0x18d9 0x4f05 0x5c82 0x2912 0x6f17
            0x6856 0x5938 0x1007 0x61ab 0x3e7f 0x57c2 0x542f 0x4f62
            0x7454 0x2eac 0x7739 0x42d4 0x2f90 0x435a 0x2e52 0x2064
            0x637c 0x66ad 0x2c90 0x0bad 0x759c 0x0029 0x0986 0x7126
            0x1ca7 0x1605 0x386a 0x27f5 0x1380 0x6d75 0x24c3 0x0f8e
            0x2b7a 0x1418 0x1fd1 0x7dc1 0x2d8e 0x43af 0x2267 0x7da3
            0x4e3d 0x1338 0x50db 0x454d 0x764d 0x40a3 0x42e6 0x262b
            0x2d2e 0x1aea 0x2e17 0x173d 0x3a6e 0x71bf 0x25f9 0x0a5d
            0x7c57 0x0fbe 0x46ce 0x4939 0x6b17 0x37bb 0x3e91 0x76db>;
        onfi,nand-timing-mode = <0x1f>;
        nand-on-flash-bbt;
        boot0@0 {
            label = "boot0";
            reg = /bits/ 64 <0x0 0x200000>;
            nand-ecc-mode = "hw_syndrome";
            nand-rnd-mode = "hw";
        };

        test@200000 {
            label = "test";
            reg = /bits/ 64 <0x200000 0x600000>;
            nand-ecc-mode = "hw_syndrome";
            nand-rnd-mode = "hw";
        };

        uboot@800000 {
            label = "uboot";
            reg = /bits/ 64 <0x800000 0x200000>;
            nand-ecc-mode = "hw";
            nand-rnd-mode = "hw";
        };

        boot@0a00000 {
            label = "boot";
            reg = /bits/ 64 <0x0a00000 0x2000000>;
            nand-ecc-mode = "hw";
            nand-rnd-mode = "hw";
        };

        rootfs@0x02a00000 {
            label = "rootfs";
            reg = /bits/ 64 <0x02a00000 0xed600000>;
            nand-ecc-mode = "hw";
            nand-rnd-mode = "hw";
        };
    };
};

Starting kernel ...

[ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.13.0-rc3-g26c5ceb-dirty (gcc version 6.3.1 20170109 (Linaro GCC 6.3-2017 [ 0.000000] CPU: ARMv7 Processor [410fc074] revision 4 (ARMv7), cr=10c5387d [ 0.000000] CPU: div instructions available: patching division code

[ 1.234372] nand: device found, Manufacturer ID: 0x2c, Chip ID: 0x44 [ 1.240801] nand: Micron MT29F32G08CBADA3W [ 1.244897] nand: 4096 MiB, MLC, erase size: 2048 KiB, page size: 8192, OOB size: 744 [ 1.264020] Bad block table not found for chip 0 [ 1.278608] Bad block table not found for chip 0 [ 1.283237] Scanning device for bad blocks [ 1.307904] Bad eraseblock 21 at 0x000002a00000 [ 1.313368] Bad eraseblock 22 at 0x000002c00000 ... [ 12.581254] Bad eraseblock 2044 at 0x0000ff800000 [ 12.587820] Bad eraseblock 2046 at 0x0000ffc00000 [ 12.593470] Bad eraseblock 2047 at 0x0000ffe00000 [ 12.598269] nand_bbt: error while erasing BBT block -5 [ 12.604362] nand_bbt: error -30 while marking block 2045 bad [ 12.610031] No space left to write bad block table [ 12.614816] nand_bbt: error while writing bad block table -28 [ 12.620591] sunxi_nand 1c03000.nand: nand_scan_tail failed: -28 [ 12.626504] sunxi_nand 1c03000.nand: failed to init nand chips [ 12.632486] sunxi_nand: probe of 1c03000.nand failed with error -28 [ 12.639744] libphy: Fixed MDIO Bus: probed

[root@alarm ~]# ls /dev/mtd
ls: cannot access '/dev/mtd
': No such file or directory

then I coment in sun7i-a20-cubietruck.dts //nand-on-flash-bbt; and coment in /drivers/mtd/nand/nand_base.c in nand_erase_nand(..) function

Starting kernel ... [ 12.491595] Bad eraseblock 2047 at 0x0000ffe00000
[ 12.502590] 5 ofpart partitions found on MTD device 1c03000.nand
[ 12.508661] Creating 5 MTD partitions on "1c03000.nand":
[ 12.513984] 0x000000000000-0x000000200000 : "boot0"
[ 12.519434] 0x000000200000-0x000000800000 : "test"
[ 12.524601] 0x000000800000-0x000000a00000 : "uboot"
[ 12.529924] 0x000000a00000-0x000002a00000 : "boot"
[ 12.535097] 0x000002a00000-0x0000f0000000 : "rootfs"
[ 12.544322] libphy: Fixed MDIO Bus: probed

[root@alarm ~]# mtdinfo -a

mtd0
Name: boot0
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:0
Bad blocks are allowed: true
Device is writable: true

mtd1
Name: test
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 3 (6291456 bytes, 6.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:2
Bad blocks are allowed: true
Device is writable: true

mtd2
Name: uboot
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:4
Bad blocks are allowed: true
Device is writable: true

mtd3
Name: boot
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 16 (33554432 bytes, 32.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:6
Bad blocks are allowed: true
Device is writable: true

mtd4
Name: rootfs
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1899 (3982491648 bytes, 3.7 GiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:8
Bad blocks are allowed: true
Device is writable: true


[root@alarm ~]# mtdinfo -a -u
Count of MTD devices: 5
Present MTD devices: mtd0, mtd1, mtd2, mtd3, mtd4
Sysfs interface supported: yes

mtd0
Name: boot0
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:0
Bad blocks are allowed: true
Device is writable: true
Default UBI VID header offset: 8192
Default UBI data offset: 16384
Default UBI LEB size: 2080768 bytes, 2.0 MiB
Maximum UBI volumes count: 128

mtd1
Name: test
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 3 (6291456 bytes, 6.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:2
Bad blocks are allowed: true
Device is writable: true
Default UBI VID header offset: 8192
Default UBI data offset: 16384
Default UBI LEB size: 2080768 bytes, 2.0 MiB
Maximum UBI volumes count: 128

mtd2
Name: uboot
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:4
Bad blocks are allowed: true
Device is writable: true
Default UBI VID header offset: 8192
Default UBI data offset: 16384
Default UBI LEB size: 2080768 bytes, 2.0 MiB
Maximum UBI volumes count: 128

mtd3
Name: boot
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 16 (33554432 bytes, 32.0 MiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:6
Bad blocks are allowed: true
Device is writable: true
Default UBI VID header offset: 8192
Default UBI data offset: 16384
Default UBI LEB size: 2080768 bytes, 2.0 MiB
Maximum UBI volumes count: 128

mtd4
Name: rootfs
Type: mlc-nand
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 1899 (3982491648 bytes, 3.7 GiB)
Minimum input/output unit size: 8192 bytes
Sub-page size: 8192 bytes
OOB size: 744 bytes
Character device major/minor: 90:8
Bad blocks are allowed: true
Device is writable: true
Default UBI VID header offset: 8192
Default UBI data offset: 16384
Default UBI LEB size: 2080768 bytes, 2.0 MiB
Maximum UBI volumes count: 128

[root@alarm ~]# flash_erase /dev/mtd3 0 0 Erasing 2048 Kibyte @ 0 -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 0 (mtd3) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) Erasing 2048 Kibyte @ b6faecb000000006 -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 1 (m) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) Erasing 2048 Kibyte @ b6faecb00000000c -- 167944 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 2 (m) error 5 (Input/output error) flash_erase: error!: /dev/mtd3: MTD Erase failure error 5 (Input/output error) ... ubiformat and dd leads to the same error.

Please tell me what am I doing wrong? Maybe the NAND is faulty?

Sincerely, Denis Romanenko

den4gh commented 6 years ago

I was changed the Nand to Micron MT29F32G08CBACAWP and maked corect dt files and its work.

[ 1.242975] nand: Micron MT29F32G08CBACAWP [ 1.247071] nand: 4096 MiB, MLC, erase size: 1024 KiB, page size: 4096, OOB size: 224 [ 1.256275] Bad block table found at page 1048320, version 0x00 [ 1.263211] Bad block table not found for chip 0 [ 1.268087] nand_bbt: ECC error in BBT at 0x0000fff00005 [ 1.273415] Scanning device for bad blocks [ 1.278004] Bad eraseblock 0 at 0x000000000000 [ 1.321202] Bad eraseblock 90 at 0x000005a00000 [ 1.326150] Bad eraseblock 91 at 0x000005b00000 [ 1.621227] Bad eraseblock 675 at 0x00002a300000 [ 1.683093] Bad eraseblock 790 at 0x000031600000 [ 1.696180] Bad eraseblock 807 at 0x000032700000 [ 1.826571] Bad eraseblock 1060 at 0x000042400000 [ 2.013759] Bad eraseblock 1427 at 0x000059300000 [ 2.072163] Bad eraseblock 1535 at 0x00005ff00000 [ 2.107273] Bad eraseblock 1596 at 0x000063c00000 [ 2.130886] Bad eraseblock 1634 at 0x000066200000 [ 2.267804] Bad eraseblock 1900 at 0x000076c00000 [ 2.286960] Bad eraseblock 1929 at 0x000078900000 [ 2.334454] Bad eraseblock 2015 at 0x00007df00000 [ 3.057294] Bad block table written to 0x0000fff00000, version 0x01 [ 3.067386] Bad block table written to 0x0000ffe00000, version 0x01 [ 3.079989] 5 ofpart partitions found on MTD device 1c03000.nand [ 3.086005] Creating 5 MTD partitions on "1c03000.nand": [ 3.091367] 0x000000000000-0x000000200000 : "boot0" [ 3.096814] 0x000000200000-0x000000800000 : "test" [ 3.102050] 0x000000800000-0x000000a00000 : "uboot" [ 3.107268] 0x000000a00000-0x000002a00000 : "boot" [ 3.112533] 0x000002a00000-0x000080000000 : "rootfs" [ 3.121934] libphy: Fixed MDIO Bus: probed

hmm.. I will try to find other 29F32G08CBADA maybe its faulty...