U-Boot sun7i NAND SPL - Cubieboard2 - MTD - Help

1,153 views
Skip to first unread message

Ezaul Zillmer

unread,
Aug 21, 2016, 7:29:18 PM8/21/16
to linux-sunxi
Good evening everyone

We are working to rotate BAT / NAND in a Cubieboard2 with Samsung NAND 316 K9GBG08U0A SCB0

Below show the whole process I am following:


All changed files are attached!


#################################################################################
#################################################################################
sunxi-tools
git clone git://github.com/linux-sunxi/sunxi-tools.git
make misc

#################################################################################
#################################################################################
U-Boot Denx
git clone git://git.denx.de/u-boot.git -b master u-boot-denx

configs/Cubieboard2_defconfig
CONFIG_SUNXI_NAND=y

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- Cubieboard2_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
add NAND
add MTD

.config
follows the attachment


I changed the following files:

######################################
arch/arm/dts/sun7i-a20.dtsi

            nand_clk: clk@01c20080 {
                        #clock-cells = <0>;
                        compatible = "allwinner,sun4i-a10-mod0-clk";
                        reg = <0x01c20080 0x4>;
                        clocks = <&osc24M>, <&pll6 1>, <&pll5 1>;
                        clock-output-names = "nand";
                };

            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>;

                        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>;
                        };

#################################################################################
arch/arm/dts/sun7i-a20-cubieboard2.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";
                };

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

                };

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

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

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

        };
};

#################################################################################
include/configs/sunxi-common.h

#ifdef CONFIG_NAND_SUNXI
#define CONFIG_SYS_NAND_MAX_ECCPOS 1664
#define CONFIG_SPL_NAND_SUPPORT 1
#define CONFIG_SYS_NAND_ONFI_DETECTION
#define CONFIG_SYS_MAX_NAND_DEVICE 8

/* Requirements for UBI */
#define CONFIG_RBTREE
#define CONFIG_LZO
#define CONFIG_CMD_MTDPARTS
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_MTD_PARTITIONS
#define CONFIG_MTD_DEVICE      /* needed for mtdparts commands */
#define MTDIDS_DEFAULT         "nand0=sunxi-nand"
#define MTDPARTS_DEFAULT       "mtdparts=sunxi-nand:"          \
                               "2m(boot0)ro,"                  \
                               "2m(boot0-rescue),"             \
                               "2m(uboot)ro,"                  \
                               "2m(uboot-rescue),"             \
                               "-(rootfs)"
#define CONFIG_CMD_NAND_TRIMFFS

#endif /* CONFIG_NAND_SUNXI */

#ifdef CONFIG_SPL_SPI_SUNXI
#define CONFIG_SPL_SPI_FLASH_SUPPORT    1
#define CONFIG_SYS_SPI_U_BOOT_OFFS      0x000000400000
#endif

#################################################################################
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

compiled perfectly


cp -Rf u-boot-denx/arch/arm/dts/sun7i-a20-cubieboard2.dtb /boot/sun7i-a20-cubieboard2.dtb

#Write U-Boot  MMC
dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8
673+1 records in
673+1 records out
689765 bytes (690 kB) copied, 0.149096 s, 4.6 MB/s

Reboot new U-boot.
=> nand info

Device 0: nand0, sector size 1024 KiB
  Page size       8192 b
  OOB size         640 b
  Erase size   1048576 b
  subpagesize     8192 b
  options     0x    1008
  bbt options 0x   70000

=> mtdparts

device nand0 <sunxi-nand>, # parts = 5
 #: name                          size               offset          mask_flags
 0: boot0                    0x00200000      0x00000000      1
 1: boot0-rescue        0x00200000      0x00200000      0
 2: uboot                    0x00200000      0x00400000      1
 3: uboot-rescue        0x00200000      0x00600000      0
 4: rootfs                    0xff800000        0x00800000      0

active partition: nand0,0 - (boot0) 0x00200000 @ 0x00000000

defaults:
mtdids  : nand0=sunxi-nand
mtdparts: mtdparts=sunxi-nand:2m(boot0)ro,2m(boot0-rescue),2m(uboot)ro,2m(uboot-rescue),-(rootfs)

=> nand erase.chip

NAND erase.chip: device 0 whole chip
Erasing at 0x0 --   0% complete.
nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5
Erasing at 0x38500000 --  22% complete.
nand0: MTD Erase failure: -5
Skipping bad block at  0xffc00000
Skipping bad block at  0xffd00000
Skipping bad block at  0xffe00000
Skipping bad block at  0xfff00000

OK

=> nand scrub.chip -y

NAND scrub.chip: device 0 whole chip
Erasing at 0x0 --   0% complete.
nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5

nand0: MTD Erase failure: -5
Erasing at 0x38500000 --  22% complete.
nand0: MTD Erase failure: -5
Erasing at 0xfff00000 -- 100% complete.
OK

=> reset

## Loading init Ramdisk from Legacy Image at 42000000 ...
   Image Name:   Cubieboard2 UBIFS Ramdisk
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    5215854 Bytes = 5 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 49000000
   Booting using the fdt blob at 0x49000000
   Loading Ramdisk to 49b06000, end 49fff66e ... OK
   Using Device Tree in place at 49000000, end 4900acdc

[    6.097892] nand: device found, Manufacturer ID: 0xec, Chip ID: 0xd7
[    6.104289] nand: Samsung NAND 4GiB 3,3V 8-bit
[    6.108869] nand: 4096 MiB, MLC, erase size: 1024 KiB, page size: 8192, OOB size: 640
[    6.121345] Bad block table found at page 524160, version 0x01
[    6.133247] Bad block table found at page 524032, version 0x01
[    6.162963] 5 ofpart partitions found on MTD device 1c03000.nand
[    6.169164] Creating 5 MTD partitions on "1c03000.nand":
[    6.174533] 0x000000000000-0x000000200000 : "boot0"
[    6.182224] 0x000000200000-0x000000400000 : "boot0-rescue"
[    6.191851] 0x000000400000-0x000000600000 : "uboot"
[    6.198265] 0x000000600000-0x000000800000 : "uboot-rescue"
[    6.205142] 0x000000800000-0x000100000000 : "rootfs"
Begin: Loading essential drivers ... done.

#mtdinfo -a
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:                         1048576 bytes, 1024.0 KiB
Amount of eraseblocks:              2 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size:  8192 bytes
Sub-page size:                            8192 bytes
OOB size:                                   640 bytes
Character device major/minor:   90:0
Bad blocks are allowed:             true
Device is writable:                      true

mtd1
Name:                                         boot0-rescue
Type:                                           mlc-nand
Eraseblock size:                         1048576 bytes, 1024.0 KiB
Amount of eraseblocks:              2 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size:  8192 bytes
Sub-page size:                            8192 bytes
OOB size:                                    640 bytes
Character device major/minor:    90:2
Bad blocks are allowed:              true
Device is writable:                       true

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

mtd3
Name:                                         uboot-rescue
Type:                                           mlc-nand
Eraseblock size:                         1048576 bytes, 1024.0 KiB
Amount of eraseblocks:              2 (2097152 bytes, 2.0 MiB)
Minimum input/output unit size:  8192 bytes
Sub-page size:                           8192 bytes
OOB size:                                   640 bytes
Character device major/minor:   90:6
Bad blocks are allowed:             true
Device is writable:                      true

mtd4
Name:                                          rootfs
Type:                                            mlc-nand
Eraseblock size:                          1048576 bytes, 1024.0 KiB
Amount of eraseblocks:              4088 (4286578688 bytes, 4.0 GiB)
Minimum input/output unit size:  8192 bytes
Sub-page size:                           8192 bytes
OOB size:                                   640 bytes
Character device major/minor:   90:8
Bad blocks are allowed:             true
Device is writable:                      true

###########FLASH_ERASE##############
###flash_erase /dev/mtd0 0 0
Erasing 1024 Kibyte @ 100000 -- 100 % complete

###flash_erase /dev/mtd1 0 0
Erasing 1024 Kibyte @ 100000 -- 100 % complete

###flash_erase /dev/mtd2 0 0
Erasing 1024 Kibyte @ 0 --  0 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 0 (mtd2)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd2: MTD Erase failure
             error 5 (Input/output error)
Erasing 1024 Kibyte @ 100000 -- 50 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 1 (mtd2)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd2: MTD Erase failure
             error 5 (Input/output error)
Erasing 1024 Kibyte @ 100000 -- 100 % complete

###flash_erase /dev/mtd3 0 0
Erasing 1024 Kibyte @ 100000 -- 100 % complete

###flash_erase /dev/mtd4 0 0
Erasing 1024 Kibyte @ 800000 --  0 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 8 (mtd4)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
             error 5 (Input/output error)
Erasing 1024 Kibyte @ 900000 --  0 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 9 (mtd4)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
             error 5 (Input/output error)
Erasing 1024 Kibyte @ 38e00000 -- 22 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 910 (mtd4)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
             error 5 (Input/output error)
Erasing 1024 Kibyte @ ff300000 -- 99 % complete flash_erase: Skipping bad block at ff400000
flash_erase: Skipping bad block at ff500000
flash_erase: Skipping bad block at ff600000
flash_erase: Skipping bad block at ff700000
Erasing 1024 Kibyte @ ff700000 -- 100 % complete

###cd u-boot-denx
###cd spl
###../../sunxi-tools/sunxi-nand-image-builder -p 8192 -o 640 -e 0x100000 -b -u 4096 -c 64/1024 sunxi-spl.bin boot0.bin

###nandwrite -o -n /dev/mtd0 boot0.bin
Writing data to block 0 at offset 0x0

###nandwrite -o -n /dev/mtd1 boot0.bin
Writing data to block 0 at offset 0x0

###cd ..

###nandwrite -p /dev/mtd2 u-boot-dtb.bin
Writing data to block 0 at offset 0x0

### nandwrite -p /dev/mtd3 u-boot-dtb.bin
Writing data to block 0 at offset 0x0

### ubiformat /dev/mtd4 -y
ubiformat: mtd4 (mlc-nand), size 4286578688 bytes (4.0 GiB), 4088 eraseblocks of 1048576 bytes (1024.0 KiB), min. I/O size 8192 bytes
libscan: scanning eraseblock 4087 -- 100 % complete
ubiformat: 4081 eraseblocks have valid erase counter, mean value is 0
ubiformat: 7 bad eraseblocks found, numbers: 8, 9, 910, 4084, 4085, 4086, 4087
ubiformat: formatting eraseblock 4087 -- 100 % complete

###reboot
Shot MMC card and:?

U-Boot SPL 2016.09-rc1-00514-gc98b171-dirty (Aug 21 2016 - 18:28:33)
DRAM: 1024 MiB
CPU: 912000000Hz, AXI/AHB/APB: 3/2/2
Trying to boot from NAND
### ERROR ### Please RESET the board ###


Someone would have a repository there date with all applied u-boot patch
where can I test there?
Boris, Hans has a repository where could this auditioning
if you could pass the test for the purpose cubieboard2
I saw several reports of people who managed to boot but not with cubieboard2

Talves is forgetting something or even going wrong parameters so would like a reliable repository of for NAND / BAT Samsung Sun7i

Thank you very much in advance!



sun7i-a20.dtsi
sun7i-a20-cubieboard2.dts
sunxi-common.h
u-boot.config

Ezaul Zillmer

unread,
Aug 22, 2016, 1:45:06 PM8/22/16
to linux-sunxi
Good afternoon

This repository with appropriate modifications rose mtd nand

Attached files if someone wants to test in your Cubieboard2
Thank Glaucio Klipel

I will put to the test in 15 cubieboard 2 all connected by cluster


git clone https://github.com/NextThingCo/CHIP-u-boot.git -b nextthing/2016.01/next


==============================================================
sunxi-nand-spl.tar.bz2
Reply all
Reply to author
Forward
0 new messages