How to update nand flash on pcDuino3:


09/25/2014 - applicable to pcDuino3

WARNING: If you mess up on the below, you can waste the nand flash or the SD. This is offered as friendly talk and nothing more. Learn what you are doing with root, cp and the command line shell. I wrote this to remind myself when I have to do create a updated bootable nand. It may not work for you at all and could be disastrous. If you understand and agree with this paragraph, you may continue reading.

This is a procedure to update the nand flash of a pcDuinov3 with a customized kernel and ubuntu that has been already tested as a microSD bootable system. It is a near copy of a post I made on the pcduino.com forums concerning this issue.

In preparation, I rebuilt the kernel from sunxi-linux. I created a bootable uSD from board-config.sh which I then, after moving the uSD back to my cross-compile system, copied my boot and module changes to. This gave me a bootable SD. I then installed all the packages I needed while booted from that uSD, plus did customizations to the boot parameters such as static IP, hostname, user accounts etc. What follows is what I did to get that bootable SD copied back to the nand devices (nanda and nandd). All the preparation is beyond the scope of this document.

NOTES:
/media/78E4-BAF3 is my boot partition on uSD, yours will be different
I am using 3.4.79 kernel and my nand had 3.4.29, both may be different for you
This is done logged in as root, I do not use sudo (you may be able to do sudo su to get to an appropriate shell to administer a unix-like system)

Making nand bootable with new kernel and modules, boot from the uSD and do the following:

df -h #confirm we are booted from uSD

Filesystem                           Size  Used Avail Use% Mounted on
/dev/mmcblk0p2                       3.6G  1.4G  2.1G  39% /
none                                 438M  4.0K  438M   1% /dev
none                                 438M  4.0K  438M   1% /tmp
none                                  88M  252K   88M   1% /run
none                                 5.0M     0  5.0M   0% /run/lock
none                                 438M     0  438M   0% /run/shm
none                                 438M     0  438M   0% /var/tmp
none                                 438M  592K  438M   1% /var/log
/dev/mmcblk0p1                        16M  6.3M  9.8M  39% /media/78E4-BAF3

mkdir /media/boot #create mount point for boot flash part of nand
mkdir /media/rootfs #create mount point for root part of flash
mount /dev/nanda /media/boot #mount the boot flash
mount /dev/nandd /media/rootfs #mount the root flash
cp /media/78E4-BAF3/script.bin /media/boot/ #xfer to boot flash
cp /media/78E4-BAF3/uImage /media/boot/ #xfer to boot flash
mv /media/rootfs/lib/modules/3.4.29+ /media/rootfs/lib/modules/3429plus #get rid of old modules
cp /lib/modules/3.4.79+ /media/rootfs/lib/modules/ -ar #add new library to flash root file system
At this point, the nand will be bootable with the new kernel and new modules, but do not reboot. Next is to copy the pre-configured Linux distribution to the nandd. This process is not right, just the best I could figure out so far, it should be done with dd and when booted from a third device. Many errors will pop up and I am hoping they are because we are copying a live file system (we have no choice since we have no additional device to boot from). This also takes a very long time. Many of these directories should not be copied, but I shotgunned in the interest of getting this done. /etc/fstab must be plain vanilla with no UUIDs specified. THERE IS NO GUARANTEE THAT THIS WILL WORK FOR ANYONE if they don't have the same use case I do. Warning, you may just as likely end up with an unbootable nandd.

cp -ax /allwinner /media/rootfs
cp -ax /bin /media/rootfs
cp -ax /boot /media/rootfs
cp -ax /boot-mmc /media/rootfs
cp -ax /dev /media/rootfs #probably a mistake
cp -ax /etc /media/rootfs
cp -ax /home /media/rootfs
cp -ax /lib /media/rootfs
cp -ax /lost+found /media/rootfs
cp -ax /mnt /media/rootfs
cp -ax /opt /media/rootfs
cp -ax /root /media/rootfs
cp -ax /run /media/rootfs
cp -ax /sbin /media/rootfs
cp -ax /selinux /media/rootfs
cp -ax /srv /media/rootfs
cp -ax /sys /media/rootfs #pretty sure this is a mistake
cp -ax /system /media/rootfs
cp -ax /usr /media/rootfs #this will take forever on a configured system, expect more than .5 hours
cp -ax /var /media/rootfs

sync;umount /media/rootfs;umount /media/boot;poweroff
Physically remove uSD. Reapply power. After boot:

df #look to see we are booted from nand, nanda should show up as device supporting /.

Test to determine that customizations to your Linux are present in the nand booted pcduino3.

Even if you have a bootable system, test thoroughly, my needs are only to have ethernet, HDMI, uSD, and keyboard working. I have not tested any other devices because I don't use them. I take no responsibility for this process, it is offered as friendly talk only. I will say that this did work for me, all customizations present and I've not found any missing pieces thus far.