Difference between revisions of "Create a FLASH partition to store user's HOME"

From ArmadeusWiki
Jump to: navigation, search
(APF27)
(Declare partition in U-Boot)
 
(12 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
==Declare partition in U-Boot==
 
==Declare partition in U-Boot==
{{Warning|You may loose the content of your current rootfs partition if going further. So be sure to have backuped your data before.}}
+
{{Warning|You '''WILL''' loose the content of your current rootfs partition if going further. So be sure to have backuped your data before.}}
===APF27===
+
 
* Check your NAND FLASH size:
+
{| border="1" cellpadding="10" cellspacing="0" summary="PWM usage depending on kernel version" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! APF9328 || APF27 || APF51 || APF28
 +
|--------
 +
|
 +
|* Check your NAND FLASH size:
 
<pre class="apf">
 
<pre class="apf">
 
BIOS> nand info
 
BIOS> nand info
Line 12: Line 17:
 
Device 0: NAND 256MiB 1,8V 16-bit, sector size 128 KiB
 
Device 0: NAND 256MiB 1,8V 16-bit, sector size 128 KiB
 
</pre>
 
</pre>
* So here I have 256MBytes. Then check current partitionning:
+
* So here I have 256MBytes. Then check current partitioning:
 
<pre class="apf">
 
<pre class="apf">
 
BIOS> printenv mtdparts
 
BIOS> printenv mtdparts
 
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
 
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
 
</pre>
 
</pre>
* I have the default APF27 partitionning scheme. Now I will reduce rootfs size to 200 MBytes (0x0C800000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
+
* I have the default APF27 partitioning scheme. Now I will reduce rootfs size to 200 MBytes (0x0C800000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
 
U-Boot 1.3.4:
 
U-Boot 1.3.4:
 
<pre class="apf">
 
<pre class="apf">
Line 32: Line 37:
 
mtdparts=mtdparts=mxc_nand.0:1M(u-boot)ro,512K(env),512K(env2),512k(firmware),512K(dtb),5M(kernel),200M(rootfs),-(user)
 
mtdparts=mtdparts=mxc_nand.0:1M(u-boot)ro,512K(env),512K(env2),512k(firmware),512K(dtb),5M(kernel),200M(rootfs),-(user)
 
</pre>
 
</pre>
* Erase the created partition (which now starts at (rootfs_offset + rootfs_len) = 0x0CE80000: (U-Boot 1.3.4)
+
* Erase the created partition:
U-Boot 1.3.4:
+
{| border="1" cellpadding="10" cellspacing="0" summary="erase" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! U-Boot 201x.xx || U-Boot 1.3.4
 +
|--------
 +
|<pre class="apf">
 +
BIOS> nand erase.part user                             
 +
</pre>
 +
|(which now starts at (rootfs_offset + rootfs_len) = 0x0ce80000
 
<pre class="apf">
 
<pre class="apf">
BIOS> nand erase 0x0CE80000
+
BIOS> nand erase 0x0ce80000
 
</pre>
 
</pre>
U-Boot 2011.12:
+
|}
 +
|* Check your NAND FLASH size:
 
<pre class="apf">
 
<pre class="apf">
BIOS> nand erase.part user
+
BIOS> reset
 +
U-Boot 2013.04 (...
 +
 
 +
NAND:  512 MiB
 +
...
 
</pre>
 
</pre>
* Save your changes, update the rootfs partition (U-Boot 2011.12) and boot Linux:
+
* So here we have 512 MBytes. Then check current partitioning:
 +
<pre class="apf">
 +
BIOS> printenv mtdparts
 +
mtdparts=mtdparts=mxc_nand:1M(u-boot)ro,512K(env),512K(env2),1M(firmware),512K(dtb),512K(splash),8M(kernel),-(rootfs)
 +
</pre>
 +
* Here we have the default [[APF51]] partitioning scheme (rootfs of 500 MBytes). Now I will reduce rootfs size to 450 MBytes (0x1c200000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
 +
<pre class=apf>
 +
BIOS> setenv mtdparts 'mtdparts=mxc_nand:1M(u-boot)ro,512K(env),512K(env2),1M(firmware)
 +
,512K(dtb),512K(splash),8M(kernel),450M(rootfs),-(user)'
 +
</pre>
 +
<pre class=apf>
 +
BIOS> setenv addubifsargs 'setenv bootargs ${bootargs} ubi.mtd=rootfs ubi.mtd=user root=ubi0:rootfs rootfstype=ubifs'
 +
</pre>
 +
<pre class=apf>
 +
BIOS> nand erase.part user
  
 +
NAND erase.part: device 0 offset 0x1ce00000, size 0x3200000
 +
OK
 +
</pre>
 +
|
 +
|}
 +
* Save your changes, update the rootfs partition (U-Boot 201x.xx) and boot Linux:
 
<pre class="apf">
 
<pre class="apf">
 
BIOS> saveenv
 
BIOS> saveenv
Line 48: Line 85:
 
BIOS> boot
 
BIOS> boot
 
</pre>
 
</pre>
 
===APF9328/APF51/APF28===
 
TODO
 
  
 
==Linux==
 
==Linux==
* In Linux boot message you should see you newly created partition detected:
+
* In Linux boot message you should see your newly created partition is detected:
<pre class="apf">
+
{| border="1" cellpadding="10" cellspacing="0" summary="MTD boot log" class="wikitable"
6 cmdlinepart partitions found on MTD device mxc_nand.0                                                                                                                            
+
|- style="background:#efefef;" align="center"
Creating 6 MTD partitions on "mxc_nand.0":                                                                                                                                        
+
! Boards with U-Boot 1.3.4 (offset may vary) || Boards with U-Boot >= 2013.xx (offset may vary)
0x000000000000-0x0000000a0000 : "U-boot"                                                                                                                                          
+
|--------
0x0000000a0000-0x000000100000 : "U-boot_env"                                                                                                                                      
+
|<pre class="apf">
0x000000100000-0x000000180000 : "firmware"                                                                                                                                        
+
6 cmdlinepart partitions found on MTD device mxc_nand.0
0x000000180000-0x000000680000 : "kernel"                                                                                                                                          
+
Creating 6 MTD partitions on "mxc_nand.0":
0x000000680000-0x00000ce80000 : "rootfs"                                                                                                                                          
+
0x000000000000-0x0000000a0000 : "U-boot"
 +
0x0000000a0000-0x000000100000 : "U-boot_env"
 +
0x000000100000-0x000000180000 : "firmware"
 +
0x000000180000-0x000000680000 : "kernel"
 +
0x000000680000-0x00000ce80000 : "rootfs"
 
0x00000ce80000-0x000010000000 : "user"
 
0x00000ce80000-0x000010000000 : "user"
 
</pre>
 
</pre>
* Check a device node was created for your new partition (''/dev/mtdblock5''):
+
|<pre class="apf">
 +
9 cmdlinepart partitions found on MTD device mxc_nand
 +
Creating 9 MTD partitions on "mxc_nand":
 +
0x000000000000-0x000000100000 : "u-boot"
 +
0x000000100000-0x000000180000 : "env"
 +
0x000000180000-0x000000200000 : "env2"
 +
0x000000200000-0x000000300000 : "firmware"
 +
0x000000300000-0x000000380000 : "dtb"
 +
0x000000380000-0x000000400000 : "splash"
 +
0x000000400000-0x000000c00000 : "kernel"
 +
0x000000c00000-0x00001ce00000 : "rootfs"
 +
0x00001ce00000-0x000020000000 : "user"
 +
</pre>
 +
|}
 +
 
 +
* you can also see it in ''/proc/mtd'':
 +
{| border="1" cellpadding="10" cellspacing="0" summary="/proc/mtd" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! Example for APF28 with U-Boot 2012.02 || Example for APF51 with U-Boot 2013.04
 +
|--------
 +
|<pre class="apf">
 +
# cat /proc/mtd
 +
dev:    size  erasesize  name
 +
mtd0: 00300000 00020000 "u-boot"
 +
mtd1: 00080000 00020000 "env"
 +
mtd2: 00080000 00020000 "env2"
 +
mtd3: 00080000 00020000 "dtb"
 +
mtd4: 00080000 00020000 "splash"
 +
mtd5: 00800000 00020000 "kernel"
 +
mtd6: 1c200000 00020000 "rootfs"
 +
mtd7: 03200000 00020000 "user"
 +
</pre>
 +
|
 
<pre class="apf">
 
<pre class="apf">
# ls /dev/mtdblock*
+
# cat /proc/mtd
/dev/mtdblock0 /dev/mtdblock2  /dev/mtdblock4
+
dev:    size  erasesize name
/dev/mtdblock1  /dev/mtdblock3  /dev/mtdblock5
+
mtd0: 00100000 00020000 "u-boot"
 +
mtd1: 00080000 00020000 "env"
 +
mtd2: 00080000 00020000 "env2"
 +
mtd3: 00100000 00020000 "firmware"
 +
mtd4: 00080000 00020000 "dtb"
 +
mtd5: 00080000 00020000 "splash"
 +
mtd6: 00800000 00020000 "kernel"
 +
mtd7: 1c200000 00020000 "rootfs"
 +
mtd8: 03200000 00020000 "user"
 
</pre>
 
</pre>
* For JFFS2: create a temporary mount point and mount the partition. It will be automatically formatted to JFSS2:
+
|}
 +
* From now on, please note the MTD number of your user partition. In previous table it was 7 on [[APF28]] and 8 on [[APF51]]. Then define it in shell:
 +
<pre class="apf">
 +
# export MTD_ID=8        (for example on APF51 with U-Boot >= 2013.04)
 +
</pre>
 +
 
 +
* Check a device node was created for your new partition:
 +
<pre class="apf">
 +
# ls -al /dev/mtdblock$MTD_ID
 +
brw-rw----    1 root    disk      31,  8 Jan  1 00:00 /dev/mtdblock8
 +
</pre>
 +
 
 +
* Now it's time to format your new ''user'' partition (preferably with UBIFS on new boards/BSP versions):
 +
{| border="1" cellpadding="10" cellspacing="0" summary="Format" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! UBIFS || JFFS2
 +
|--------
 +
|* For UBIFS, create a temporary mount point, format and mount the partition:
 
<pre class="apf">
 
<pre class="apf">
 
# mkdir /tmp/nand
 
# mkdir /tmp/nand
# mount -t jffs2 /dev/mtdblock5 /tmp/nand
+
# ubidetach -m $MTD_ID
# ls /tmp/nand/
+
# ubiformat /dev/mtd$MTD_ID
 +
# ubiattach /dev/ubi_ctrl -m $MTD_ID
 +
# ubimkvol /dev/ubi1 -m -N user
 +
# mount -t ubifs ubi1:user /tmp/nand
 +
# ls /tmp/nand
 
</pre>
 
</pre>
* For UBIFS: create a temporary mount point, format and mount the partition:
+
|* For JFFS2, create a temporary mount point and mount the partition. It will be automatically formatted:
 
<pre class="apf">
 
<pre class="apf">
 
# mkdir /tmp/nand
 
# mkdir /tmp/nand
# ubiformat /dev/mtd5
+
# mount -t jffs2 /dev/mtdblock$MTD_ID /tmp/nand
# ubiattach /dev/ubi_ctrl -m 5
+
# ubimkvol /dev/ubi1 -s 40MiB -N user
+
# mount -t ubifs ubi1:user /mnt/nand
+
 
# ls /tmp/nand/
 
# ls /tmp/nand/
 
</pre>
 
</pre>
 +
|}
 +
 
* Move your user data to the partition:
 
* Move your user data to the partition:
 
<pre class="apf">
 
<pre class="apf">
Line 90: Line 188:
 
# cp -r /root/.[ab]* /tmp/nand/
 
# cp -r /root/.[ab]* /tmp/nand/
 
</pre>
 
</pre>
* Makes it automatically mounted at every boot by adding it to ''/etc/fstab'':
+
 
JFFS2:
+
* Make it automatically mounted at every boot by adding it to ''/etc/fstab'':
<pre class="apf">
+
{| border="1" cellpadding="10" cellspacing="0" summary="fstab" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! UBIFS || JFFS2
 +
|--------
 +
|<pre class="apf">
 
# vi /etc/fstab
 
# vi /etc/fstab
 
...
 
...
sysfs          /sys          sysfs    defaults         0      0         
+
sysfs          /sys          sysfs    defaults               0      0         
usbfs          /proc/bus/usb  usbfs    defaults         0      0
+
usbfs          /proc/bus/usb  usbfs    defaults               0      0
/dev/mtdblock5  /root          jffs2   defaults         0      0   <<-----------------
+
ubi1:user      /root          ubifs   defaults,noatime,rw    0      0     <<------
 
</pre>
 
</pre>
UBIFS:
+
|<pre class="apf">
<pre class="apf">
+
 
# vi /etc/fstab
 
# vi /etc/fstab
 
...
 
...
 
sysfs          /sys          sysfs    defaults          0      0         
 
sysfs          /sys          sysfs    defaults          0      0         
 
usbfs          /proc/bus/usb  usbfs    defaults          0      0
 
usbfs          /proc/bus/usb  usbfs    defaults          0      0
ubi1:user      /mnt/nand      ubifs   defaults,noatime,rw    0      0   <<-----------------
+
/dev/mtdblock7  /root          jffs2   defaults         0      0     <<-------
 
</pre>
 
</pre>
 +
|}
 
* Now you're done. Reboot and enjoy ! ;-)
 
* Now you're done. Reboot and enjoy ! ;-)
 
<pre class="apf">
 
<pre class="apf">
Line 117: Line 219:
 
none                    64.0k        0    64.0k  0% /dev
 
none                    64.0k        0    64.0k  0% /dev
 
tmpfs                    61.2M    44.0k    61.1M  0% /tmp
 
tmpfs                    61.2M    44.0k    61.1M  0% /tmp
>>> /dev/mtdblock5           49.5M      4.0M    45.5M  8% /root <<<
+
>>> /dev/mtdblock7           49.5M      4.0M    45.5M  8% /root <<<
 
# ls /root/
 
# ls /root/
 
</pre>
 
</pre>
 
* Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat the ''/etc/fstab'' modification step above !
 
* Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat the ''/etc/fstab'' modification step above !

Latest revision as of 10:58, 26 February 2015

If you ever did some hacking/devt on your APF board and used /root/ to download or install your experiments, I'm sure you got frustrated when it comes the time where you had to reflash the whole rootfs. Indeed, by default, /root/ is located in the same partition as the rootfs image and so everything you did will be overwritten. Well, you can always backup your data on a SD/microSD or through NFS before doing the rootfs flashing, but I think that, like me, you are little bit lazy ;-).

So in this small tutorial I will explain you how to modify the FLASH setup to store your personnal data on a separated partition and so avoid the backup process when updating your rootfs.

Declare partition in U-Boot

Warning Warning: You WILL loose the content of your current rootfs partition if going further. So be sure to have backuped your data before.


APF9328 APF27 APF51 APF28
* Check your NAND FLASH size:
BIOS> nand info

Device 0: NAND 256MiB 1,8V 16-bit, sector size 128 KiB
  • So here I have 256MBytes. Then check current partitioning:
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
  • I have the default APF27 partitioning scheme. Now I will reduce rootfs size to 200 MBytes (0x0C800000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:

U-Boot 1.3.4:

BIOS> setenv mtdparts mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
BIOS> setenv rootfs_len 0x0C800000

U-Boot 2011.12:

BIOS> setenv mtdparts mtdparts=mxc_nand.0:1M(u-boot)ro,512K(env),512K(env2),512k(firmware),512K(dtb),5M(kernel),200M(rootfs),-(user)
BIOS> setenv addubifsargs 'setenv bootargs ${bootargs} ubi.mtd=rootfs ubi.mtd=user root=ubi0:rootfs rootfstype=ubifs'
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand.0:1M(u-boot)ro,512K(env),512K(env2),512k(firmware),512K(dtb),5M(kernel),200M(rootfs),-(user)
  • Erase the created partition:
U-Boot 201x.xx U-Boot 1.3.4
BIOS> nand erase.part user                              
(which now starts at (rootfs_offset + rootfs_len) = 0x0ce80000
BIOS> nand erase 0x0ce80000
* Check your NAND FLASH size:
BIOS> reset
U-Boot 2013.04 (...

NAND:  512 MiB
...
  • So here we have 512 MBytes. Then check current partitioning:
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand:1M(u-boot)ro,512K(env),512K(env2),1M(firmware),512K(dtb),512K(splash),8M(kernel),-(rootfs)
  • Here we have the default APF51 partitioning scheme (rootfs of 500 MBytes). Now I will reduce rootfs size to 450 MBytes (0x1c200000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
BIOS> setenv mtdparts 'mtdparts=mxc_nand:1M(u-boot)ro,512K(env),512K(env2),1M(firmware)
,512K(dtb),512K(splash),8M(kernel),450M(rootfs),-(user)'
BIOS> setenv addubifsargs 'setenv bootargs ${bootargs} ubi.mtd=rootfs ubi.mtd=user root=ubi0:rootfs rootfstype=ubifs'
BIOS> nand erase.part user

NAND erase.part: device 0 offset 0x1ce00000, size 0x3200000
OK
  • Save your changes, update the rootfs partition (U-Boot 201x.xx) and boot Linux:
BIOS> saveenv
BIOS> run update_rootfs
BIOS> boot

Linux

  • In Linux boot message you should see your newly created partition is detected:
Boards with U-Boot 1.3.4 (offset may vary) Boards with U-Boot >= 2013.xx (offset may vary)
6 cmdlinepart partitions found on MTD device mxc_nand.0
Creating 6 MTD partitions on "mxc_nand.0":
0x000000000000-0x0000000a0000 : "U-boot"
0x0000000a0000-0x000000100000 : "U-boot_env"
0x000000100000-0x000000180000 : "firmware"
0x000000180000-0x000000680000 : "kernel"
0x000000680000-0x00000ce80000 : "rootfs"
0x00000ce80000-0x000010000000 : "user"
9 cmdlinepart partitions found on MTD device mxc_nand
Creating 9 MTD partitions on "mxc_nand":
0x000000000000-0x000000100000 : "u-boot"
0x000000100000-0x000000180000 : "env"
0x000000180000-0x000000200000 : "env2"
0x000000200000-0x000000300000 : "firmware"
0x000000300000-0x000000380000 : "dtb"
0x000000380000-0x000000400000 : "splash"
0x000000400000-0x000000c00000 : "kernel"
0x000000c00000-0x00001ce00000 : "rootfs"
0x00001ce00000-0x000020000000 : "user"
  • you can also see it in /proc/mtd:
Example for APF28 with U-Boot 2012.02 Example for APF51 with U-Boot 2013.04
# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00300000 00020000 "u-boot"
mtd1: 00080000 00020000 "env"
mtd2: 00080000 00020000 "env2"
mtd3: 00080000 00020000 "dtb"
mtd4: 00080000 00020000 "splash"
mtd5: 00800000 00020000 "kernel"
mtd6: 1c200000 00020000 "rootfs"
mtd7: 03200000 00020000 "user"
# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00080000 00020000 "env"
mtd2: 00080000 00020000 "env2"
mtd3: 00100000 00020000 "firmware"
mtd4: 00080000 00020000 "dtb"
mtd5: 00080000 00020000 "splash"
mtd6: 00800000 00020000 "kernel"
mtd7: 1c200000 00020000 "rootfs"
mtd8: 03200000 00020000 "user"
  • From now on, please note the MTD number of your user partition. In previous table it was 7 on APF28 and 8 on APF51. Then define it in shell:
# export MTD_ID=8        (for example on APF51 with U-Boot >= 2013.04)
  • Check a device node was created for your new partition:
# ls -al /dev/mtdblock$MTD_ID
brw-rw----    1 root     disk       31,   8 Jan  1 00:00 /dev/mtdblock8
  • Now it's time to format your new user partition (preferably with UBIFS on new boards/BSP versions):
UBIFS JFFS2
* For UBIFS, create a temporary mount point, format and mount the partition:
# mkdir /tmp/nand
# ubidetach -m $MTD_ID
# ubiformat /dev/mtd$MTD_ID
# ubiattach /dev/ubi_ctrl -m $MTD_ID
# ubimkvol /dev/ubi1 -m -N user
# mount -t ubifs ubi1:user /tmp/nand
# ls /tmp/nand
* For JFFS2, create a temporary mount point and mount the partition. It will be automatically formatted:
# mkdir /tmp/nand
# mount -t jffs2 /dev/mtdblock$MTD_ID /tmp/nand
# ls /tmp/nand/
  • Move your user data to the partition:
# cp -r /root/* /tmp/nand/
# cp -r /root/.[ab]* /tmp/nand/
  • Make it automatically mounted at every boot by adding it to /etc/fstab:
UBIFS JFFS2
# vi /etc/fstab
...
sysfs           /sys           sysfs    defaults               0      0        
usbfs           /proc/bus/usb  usbfs    defaults               0      0
ubi1:user       /root          ubifs    defaults,noatime,rw    0      0      <<------
# vi /etc/fstab
...
sysfs           /sys           sysfs    defaults          0      0        
usbfs           /proc/bus/usb  usbfs    defaults          0      0
/dev/mtdblock7  /root          jffs2    defaults          0      0      <<-------
  • Now you're done. Reboot and enjoy ! ;-)
# reboot
...
# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  200.0M     17.8M    182.2M   9% /
/dev/root               200.0M     17.8M    182.2M   9% /
none                     64.0k         0     64.0k   0% /dev
tmpfs                    61.2M     44.0k     61.1M   0% /tmp
>>> /dev/mtdblock7           49.5M      4.0M     45.5M   8% /root <<<
# ls /root/
  • Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat the /etc/fstab modification step above !