XNAND2-Update

From embeddedTS Manuals
Revision as of 10:15, 19 December 2016 by Mpeters (talk | contribs) (Changed first paragraph to eliza's version, added XNAND2 between 'new' and 'nandctl' per eliza request.)

An XNAND2 based image will work on boards with either the old XNAND boot code or the new XNAND2 boot code.  However boards with XNAND2 boot code will not work with an old XNAND image, so it is important to update all production programing/imaging processes to utilize the XNAND2 nandctl.  The following section provides you with the necessary information to update an existing XNAND image with the new XNAND2 nandctl software.

You will need a workstation running Linux to prepare this update. From your Linux workstation (or Virtual Machine), open a terminal window and copy your original production dd file to the local home directory.  For purposes of this article we will call this xnandimg.dd.  You will also need the new XNAND2 nandctl binary in the same local directory.

Next run this command:

sudo fdisk -l xnandimg.dd

This will produce some technical output very similar to this:

Disk xnandimg.dd: 268 MB, 268435456 bytes
255 heads, 63 sectors/track, 32 cylinders, total 524288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
xnandimg.dd1               1        5119        2559+  da  Non-FS data
xnandimg.dd2            5120       10239        2560   da  Non-FS data
xnandimg.dd3           10240      524287      257024   83  Linux

We need two important pieces of information:  The start sector of the initrd partition, and the sector size.  In the case of the test file above, this is sector 5120, and 512 bytes.  Multiply these two numbers to obtain the necessary offset:  5120 * 512 = 2621440.

From here it is possible to mount the image's initrd partition directly inside the parent file system:

mkdir mnt
sudo mount -orw,loop,offset=$((5120*512)) xnandimg.dd mnt

You can now copy the new XNAND2 nandctl directly into the disk image:

cp nandctl mnt/sbin/nandctl
sync

It is now safe to unmount the updated image and rename appropriately:

sudo umount mnt
mv xnandimg.dd xnand2img.dd