560
edits
Changes
no edit summary
The purpose of this tutorial is to show how to flash a complete linux (u-boot + kernel + rootfs) into the internal storage of the system.
==Prepare the files==
First, it will be needed to prepare the following elements:
First, we will start with the case of using a NAND flash as internal storage.
{| class="contenttable sortable"
|-
| style="border-color: #ffb521;"|'''<span class="note"><u>Note</u>:</span>''' '''it will be used some special tools collected in the Mtdutils package. More info here: [http://jira.isee.biz:8090/display/LINUX/Mtdutils Mtdutils]'''
|}
It is recommendable to test the NAND flash and its partitions:
Now we can flash the MLO in the first partition '''/dev/mtd0'''. It important to know that in this case (because it is a NAND flash and we have to record the MLO) we have to flash it four times in the first 4 blocks of this partition. In order to know the exact addresses we can check the documentation of the chip developer (in this case: [http://jira.isee.biz:8090/pages/viewpage.action?pageId=6619137 AM335x U-Boot User's Guide (Texas Documentation)] <span class="mw-headline">'''NAND Layout'''</span>) and will get the offset addresses '''[0x0 0x20000 0x40000 0x60000]''' . For each one of this addresses we have to write:
nandwrite -p -s <address> [https://en.wikipedia.org/wiki/UBIFS /dev/mtd0 <your_MLO>[https://en.wikipedia.org/wiki/UBIFS /dev/mtd0</address>
For example:
Then we will flash into the second partition '''/dev/mtd1''' the u-boot.img:
nandwrite -p /dev/mtd1 <your_u-boot.img>
For example:
nandwrite -p /dev/mtd1 /home/root/flash_files/u-boot.img
In order to flash the rootfs we use the <a class="external-link" href="https://en.wikipedia.org/wiki/UBIFS" rel="nofollow">UBIFS] (<span class="mw-redirect">filesystem</span> for unmanaged flash memory devices) in the last partition '''/dev/mtd3'''. We are using a UBIFS in order to do it:]
ubiformat /dev/mtd3<br data-attributes="%20/">ubiattach -p /dev/mtd3<br data-attributes="%20/">ubimkvol /dev/ubi0 -N filesystem -m
mkdir /tmp/flashroot<br data-attributes="%20/">mount -t ubifs ubi0:rootfs /tmp/flashroot/<br data-attributes="%20/">cd /tmp/flashroot/<br data-attributes="%20/">tar -xf -C .<br data-attributes="%20/">cd /<br data-attributes="%20/">umount /tmp/flashroot<br data-attributes="%20/">ubidetach -p /dev/mtd3
mkdir /tmp/flashroot<br data-attributes="%20/">mount -t ubifs ubi0:rootfs /tmp/flashroot/<br data-attributes="%20/">cd /tmp/flashroot/<br data-attributes="%20/">tar -xf /home/root/flash_files/my_rootfs.tar -C .<br data-attributes="%20/">cd /<br data-attributes="%20/">umount /tmp/flashroot<br data-attributes="%20/">ubidetach -p /dev/mtd3
mkdir -p /tmp/mmcblk2p1<br data-attributes="%20/">mkdir -p /tmp/mmcblk2p2<br data-attributes="%20/">mount -t vfat /dev/mmcblk2p1 /tmp/mmcblk2p1<br data-attributes="%20/">mount -t ext3 /dev/mmcblk2p2 /tmp/mmcblk2p2
{| class="contenttable sortable"|-| style="border-color: #ffb521;"|'''<preu> Note</preu>: If your system has automatically mounted the partitions you have to umount them again by using:''' umount /run/media/mmcblk2*|}
Now we can flash the rest of the elements (by default the zImage and the dtb are place inside the rootfs boot folder).<br />First we extract the rootfs we want to flash in the temporary folder of the second partition ()
tar -xf -C /tmp/mmcblk2p2/<br data-attributes="%20/">For example:<br data-attributes="%20/">tar -xf<br data-attributes="%20/">/opt/firmware/isee-fsl-image-dev-imx6dl-igep0046d10-20170712121141.rootfs.<br data-attributes="%20/">tar.bz2 -C /tmp/mmcblk2p2/
RO_PROTECTION=`cat /sys/block/mmcblk2/force_ro`<br data-attributes="%20/">echo 0 > /sys/block/mmcblk2/force_ro<br data-attributes="%20/">dd if= of=/dev/mmcblk2 bs=512 seek=2 2> /dev/null<br data-attributes="%20/">echo $RO_PROTECTION > /sys/block/mmcblk2/force_ro<br data-attributes="%20/">sync
RO_PROTECTION=`cat /sys/block/mmcblk2/force_ro`<br data-attributes="%20/">echo 0 > /sys/block/mmcblk2/force_ro<br data-attributes="%20/">dd if=/tmp/mmcblk2p2/boot/u-boot.imx of=/dev/mmcblk2 bs=512 seek=2 2><br data-attributes="%20/">/dev/null<br data-attributes="%20/">echo $RO_PROTECTION > /sys/block/mmcblk2/force_ro<br data-attributes="%20/">sync