Is it better to boot from NAND Flash than SD?

Started by David Goadby, June 08, 2013, 04:11:23 pm

Previous topic - Next topic

David Goadby

June 08, 2013, 04:11:23 pm Last Edit: June 09, 2013, 01:03:16 pm by David Goadby
The A10s Mico-4GB has NAND Flash memory on it. I had planned to use the non-4GB version and boot from the MicroSD card. It's not a cost thing but the ease of deployment and upgrade using the SD seemed sensible. The SD/MMC is planned for data storage.

Having a couple of days off from the project I wondered if there is a performance advantage in using the on-board NAND Flash? If there is then I guess I need to be able to transfer my production Debian image from the MicroSD card to the Flash memory.

The obvious way would be to put the required Debian image including boot partition the SD/MMC socket, and then boot Debian from the MicroSD. Then do a dd from SD/MMC to the NAND Flash

Is there another way to do this? Has anyone tried it?

David Goadby

09/06/2013 - correct my silly mistake of calling the 4GB NAND Flash - EEPROM.

olimex

EEPROM is too small to hold any image
it's for holding MAC address and some Linux variables info

David Goadby

June 09, 2013, 12:25:43 pm #2 Last Edit: June 09, 2013, 01:03:59 pm by David Goadby
No, my mistake I meant the NAND flash. I have corrected the original post.

Regards

David Goadby

olimex


David Goadby

Thanks for the info. Is there anything special about it that stops me doing a dd to it with a Debian image?

I assume that we have to make sure the MicroSD card is non-booting from then on to ensure we boot from NAND.

Can we boot from the SD/MMC or is that not included in the boot process?

David Goadby

giovanni.v

Quote from: David Goadby on June 10, 2013, 12:54:23 am
Is there anything special about it that stops me doing a dd to it with a Debian image?


dd will write to but probably the only result will be to destroy the nand content: this kind of operation can be done only if the nand is exposed as MTD device by the kernel. I'm working on an A10 using a 3.0.62 kernel and the nand drivers seems not there, I don't now about the A10S but I'd read it's more close to A13 rather than A10.

You can try cross-building the sunxy-tools (https://github.com/linux-sunxi/sunxi-tools/) for the target or grab the binaries somewere... like the cubian debian image: https://github.com/cubieplayer/Cubian.
Quote
I assume that we have to make sure the MicroSD card is non-booting from then on to ensure we boot from NAND.


The nand flash has lower priority in the boot process, the sd card will be tried first.
TeeBX VoIP communication platform
http://code.google.com/p/teebx/

BoneOS cross platform build system and application framework
http://sourceforge.net/projects/boneos/
--8<--
Lightweight++ Business Friendly++ Open++

hno

Quote from: David Goadby on June 10, 2013, 12:54:23 am
Thanks for the info. Is there anything special about it that stops me doing a dd to it with a Debian image?


Doing a plain dd will not work very well. You can do a dd of the root partition after a little preparation, but usually better to do a file level copy. You likely want to resize the rootfs anyway.


One way to install on NAND is to boot from sdcard, then use nandpart from sunxi-tools to repartition the NAND as you please, but leave nanda as a FAT partition with same file contents (may be reformatted if you copy back the files). nandb is also reserved (u-boot config) but safe to destroy while installing. The rest is free for you to reclaim and reuse as fit.

When done with the partition layout then reboot to activate the new layout, format filesystems as appropriate and copy your root filesystem over (and nanda fat partition files if you changed nanda partitioning).

One secure way to clone the rootfs while running from the same is to

  mkdir /mnt/root
  mkdir /mnt/newroot
  mount --bind / /mnt/root
  mount /dev/nandc /mnt/newroot
  cd /mnt/root
  find . -depth -print0 | cpio -pdmv /mnt/newroot/

Then edit fstab (/mnt/newroot/etc/fstab) in the new root filesystem to reflect the correct device names, /dev/nandX instead of /dev/mmcblk0pY

Drop the kernel uImage and any uInitrd image if you need one in the nanda partition so stock Allwinner u-boot is able to load them without too much fuzz.

Then poweroff, remove the sdcard and power on and halt the boot process at the u-boot prompt. Now you need to change the bootcmd to load the right kernel (+ optional initrd) and set the right kernel command line.

  setenv load_uimage fatload nanda 44000000 uImage
  setenv bootargs console=ttyS0,115200 root=/dev/nandc
  setenv boot_uimage bootm 44000000
  setenv bootcmd run load_uimage boot_uimage
  saveenv

Or if you need an uInitrd then

  setenv load_uimage fatload nanda 44000000 uImage
  setenv load_uinitrd fatload nanda 48000000 uInitrd
  setenv bootargs console=ttyS0,115200 root=/dev/nandc
  setenv boot_uimage bootm 44000000 48000000
  setenv bootcmd run load_uimage load_uinitrd boot_uimage
  saveenv

You may need to modify the bootargs line with any extra arguments needed by your os. But most don't need any other arguments.

Now you should be ready to try booting from nand.

  boot  (or reboot the board)


Note: As long as you have a usable bootable sdcard and a backup of the files that is in nanda then you have what is needed to completely repartition the visible parts of the nand and install. The boot0/boot1 bootloader stages are also in nand but in an reserved area not easily reached from Linux so there is very low risk of rendering the nand unbootable.

And should you fail completely then livesuit can restore the nand content if needed.

To recap, the goal is

1. nanda with original files + kernel uImage and optional uInitrd.

2. nandb reserved for u-boot environment

3. nandc for /

4. optional other partitions as you see fit

5. u-boot environment set to load the right kernel and kernel command line for your os.

David Goadby

June 12, 2013, 12:43:25 pm #7 Last Edit: June 12, 2013, 07:27:50 pm by David Goadby
Thanks very much "Hno" for a very comprehensive answer. I have saved a copy for future reference.

The process does seem quite tricky and I wonder how Olimex pre-load the 4GB chips with Android. ie is there a quick way?

Although the NAND Flash is faster, after reading through the process required, my post-manufacture installation might be easier and faster if I just pop-in clones of my SD master card.

Just extra basic question: to interrupt the UBoot process do I just need to look at the serial port output in a similar way as the A13? I will try it later.

Thanks again!

Regards

David Goadby