[PATCH] sunxi-nand: fix the PIO instead of DMA implementation

Markus Hoffrogge mhoffrogge at gmail.com
Fri Jul 1 16:31:35 CEST 2022


Am Fr., 1. Juli 2022 um 11:57 Uhr schrieb Andre Przywara <
andre.przywara at arm.com>:
Hi Andre,

> On Thu, 30 Jun 2022 23:30:50 +0200
> Markus Hoffrogge <mhoffrogge at gmail.com> wrote:
>
> Hi Markus,
>
> > as this patch has been delegated to you,
>
> thanks for sending the patch, and for the heads up, looks
> like we should add that file somewhere into MAINTAINERS.
> (And please keep people on CC:, to not split up the thread on the
> list).
>
> > I would like to mention, that this patch is superseding
> >  the patch
> https://patchwork.ozlabs.org/project/uboot/patch/20220330204543.3790-1-macroalpha82@gmail.com/
> > raised by Chris Morgan.
>
> So from a first look at it, I like this version better, mostly because
> it's much shorter ;-)
>
> That being said, I tried to stay away from raw NAND as much as possible in
> the past, and thought that our support in U-Boot is very minimal. So can
> someone please enlighten me about the status:
> - AFAIK raw NAND is only supported on the C.H.I.P. Pro, because this is
> one the few devices featuring SLC NAND. I guess the main feature of raw
> NAND is that it's cheaper, so using SLC instead of MLC kind of defeats the
> main purpose of it.
> - Is there a separate SPL story? As in: loading U-Boot proper from NAND
> when the BROM loaded the SPL from there? IIUC read disturbance makes even
> that part non-trivial.
> - Because of the absence of SLC in modern devices, and the prevalence of
> eMMC, raw NAND was rarely used on modern devices (>= H3). So did we ever
> support that? My understanding was that the NAND controller itself is
> fairly similar (is it?), but the MLC problem would still persist.
>

I fully agree, but the MLC problem has been adressed already a while ago
by introducing the slc_mode on mainline Kernel for MLC
with the NAND page pairing approach by Boris Brezillon and Richard
Weinberger.
See
https://bootlin.com/pub/conferences/2016/elce/brezillon-ubi-mlc/ubi-mlc.pdf.

It will half the usable size of the NAND, but I guess it is perfect
and best approach for getting the MLC used in a most robust way.
So this at least should be sufficient for using it for some minimal
rootfs for boot configuration or initial startup OS for configuring and
e.g. attaching/initializing a SATA SSD.

Main motivation is to get the board NAND booting
not to rely on a SD card, since this is weak in rough or
industrial environments and the SDCard slot should be free
for other usage.
The OS will be on a SATA SSD in most usecases anyway.

- How do you actually write to the NAND? It seems like even reading is
> non-trivial, so is this done from U-Boot, (BSP?) Linux, or using vendor
> tools, probably via FEL?
>

Writing to MLC NAND I am doing as follows on a Cubietruck (CT):
  1. I create an Armbian image for SDCARD for the CT with a currently
    user patched CT UBoot and kernel config with the following:
    (I will provide an appropriate patch for this separately later)
    Note: This CT config extension does not break the SDCard boot.
    - enabling SUNXI NAND and SUNXI NAND SPL
      Extended config on UBoot configs/Cubietruck_defconfig:
      [...append to current CT config]
      CONFIG_NAND=y
      CONFIG_NAND_SUNXI=y
      CONFIG_MTD=y
      CONFIG_MTD_RAW_NAND=y
      #
      # SPL loader NAND offsets according to Kernel
      # .dts mtd partitions:
      #
      CONFIG_SYS_NAND_U_BOOT_OFFS=0x400000
      CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND=0x600000
      #
      # CT specific Hynix MLC NAND 27UCG8T2ATR-BC config:
      #
      CONFIG_NAND_SUNXI_SPL_ECC_STRENGTH=64
      CONFIG_NAND_SUNXI_SPL_ECC_SIZE=1024
      CONFIG_NAND_SUNXI_SPL_USABLE_PAGE_SIZE=4096
      CONFIG_SYS_NAND_PAGE_SIZE=8192
      CONFIG_SYS_NAND_OOBSIZE=640
      CONFIG_SYS_NAND_BLOCK_SIZE=0x200000
      [EOF]
    - overlay .dts for the kernel to add nfc node with SPL and UBoot
      NAND partitions 2MB each on NAND blocksize boundaries providing:
      - /dev/mtd0 - SPL
      - /dev/mtd1 - SPL-backup
      - /dev/mtd2 - UBoot
      - /dev/mtd3 - UBoot-backup
      - /dev/mtd4 - UBI (UBI in slc_mode for rootfs - later use)
                    This rootfs yould more or less hold the kernel
                    image and other scripts relevant for booring
                    to be more flexible for updates on the kernel
                    and the boot environment scripts.
    - add mtd-utils package for the OS
    - I will provide a github link for my Armbian fork soon
      its not yet commited
  2. Plugin SDCard and boot CT with this image from SD card
     - copy UBoot SPL ./spl/sunxi-spl-with-ecc.bin to the CT
     - copy UBoot image u-boot-dtb.img to the CT
  3. Logon to CT and run on CT:
     - erase /dev/mtd0
       - sudo flash_erase /dev/mtd0 0 0
     - write the SUNXI UBoot SPL ./spl/sunxi-spl-with-ecc.bin to /dev/mtd0
       - sudo nandwrite -o -n /dev/mtd0 sunxi-spl-with-ecc.bin
     - erase /dev/mtd2
       - sudo flash_erase /dev/mtd2 0 0
     - write u-boot-dtb.img to /dev/mtd2
       - sudo nandwrite -p /dev/mtd2 u-boot-dtb.img
   4. Shutdown CT
   5. Unplug SDCard and reboot
      - Now CT boots from NAND and will find SATA OS, if SATA available

I recently got an H6 TV box, which happens to use raw (MLC) NAND flash. I
> also inherited a Cubietruck, which is MLC as well. So can I use that
> storage, at least for the firmware?
>
>
Yes, CT should work as described above.

If yes, this should be documented somewhere, I guess? Or is it already?
>

No, it is not yet documented.
I am currently working on an approrpiate pull request for Armbian build.
I would like to finish up with the UBI partition setup
to complete that portion.
For this U-Boot CT config I am supposed to provide another patch later.

Where would be the best place to document this on the U-Boot tree ?

br
Markus


>
> Cheers,
> Andre
>
> It should solve the issue in general and does not require to
> > revert to the former DMA implementation.
> >
> > Kind regards
> > Markus
>
>


More information about the U-Boot mailing list