[FE training-materials-updates] labs/sysdev-flash-filesystems: misc improvements

Thomas Petazzoni thomas.petazzoni at free-electrons.com
Tue May 26 13:21:55 CEST 2015


Repository : git://git.free-electrons.com/training-materials.git

On branch  : mtd-rework-WIP
Link       : http://git.free-electrons.com/training-materials/commit/?id=01aabd8c728c7a6dbee5c2cbc02f1f8e3e842ed1

>---------------------------------------------------------------

commit 01aabd8c728c7a6dbee5c2cbc02f1f8e3e842ed1
Author: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Date:   Tue May 26 13:21:27 2015 +0200

    labs/sysdev-flash-filesystems: misc improvements
    
    Signed-off-by: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>


>---------------------------------------------------------------

01aabd8c728c7a6dbee5c2cbc02f1f8e3e842ed1
 labs/sysdev-flash-filesystems/flash-map.dia        | 209 ++++++++++++++++++---
 .../sysdev-flash-filesystems.tex                   |  97 +++++-----
 2 files changed, 225 insertions(+), 81 deletions(-)

diff --git a/labs/sysdev-flash-filesystems/flash-map.dia b/labs/sysdev-flash-filesystems/flash-map.dia
index 15cfa21..9a785c3 100644
--- a/labs/sysdev-flash-filesystems/flash-map.dia
+++ b/labs/sysdev-flash-filesystems/flash-map.dia
@@ -718,7 +718,7 @@ backup#</dia:string>
         <dia:point val="40,19"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="39.4513,16.9982;40.5674,21.0018"/>
+        <dia:rectangle val="39.4513,17.0262;40.5487,20.9737"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -736,7 +736,7 @@ UBI#</dia:string>
             <dia:real val="0.80000000000000004"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="40,17.6119"/>
+            <dia:point val="40,17.6212"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -923,7 +923,7 @@ UBI#</dia:string>
         <dia:point val="38.5,16.5"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="37.9062,16.2514;39.1053,16.7486"/>
+        <dia:rectangle val="37.9062,16.2688;39.0938,16.7312"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -937,7 +937,7 @@ UBI#</dia:string>
             <dia:real val="0.49388886988162994"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="38.5,16.6305"/>
+            <dia:point val="38.5,16.6363"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -982,10 +982,10 @@ UBI#</dia:string>
     </dia:object>
     <dia:object type="Standard - Text" version="1" id="O30">
       <dia:attribute name="obj_pos">
-        <dia:point val="32,18.75"/>
+        <dia:point val="32,18.4"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="31.3388,18.3762;32.6613,19.1237"/>
+        <dia:rectangle val="31.3388,18.0263;32.6613,18.7738"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -999,7 +999,7 @@ UBI#</dia:string>
             <dia:real val="0.80000000000000004"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="32,18.9712"/>
+            <dia:point val="32,18.6213"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -1012,9 +1012,6 @@ UBI#</dia:string>
       <dia:attribute name="valign">
         <dia:enum val="2"/>
       </dia:attribute>
-      <dia:connections>
-        <dia:connection handle="0" to="O29" connection="8"/>
-      </dia:connections>
     </dia:object>
     <dia:object type="Standard - Box" version="0" id="O31">
       <dia:attribute name="obj_pos">
@@ -1047,10 +1044,10 @@ UBI#</dia:string>
     </dia:object>
     <dia:object type="Standard - Text" version="1" id="O32">
       <dia:attribute name="obj_pos">
-        <dia:point val="35.25,18.75"/>
+        <dia:point val="35.2,18.4"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="34.2437,18.3762;36.2563,19.1237"/>
+        <dia:rectangle val="34.1938,18.0263;36.2063,18.7738"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -1064,7 +1061,7 @@ UBI#</dia:string>
             <dia:real val="0.80000000000000004"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="35.25,18.9712"/>
+            <dia:point val="35.2,18.6213"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -1077,9 +1074,6 @@ UBI#</dia:string>
       <dia:attribute name="valign">
         <dia:enum val="2"/>
       </dia:attribute>
-      <dia:connections>
-        <dia:connection handle="0" to="O31" connection="8"/>
-      </dia:connections>
     </dia:object>
     <dia:object type="Standard - Box" version="0" id="O33">
       <dia:attribute name="obj_pos">
@@ -1112,10 +1106,10 @@ UBI#</dia:string>
     </dia:object>
     <dia:object type="Standard - Text" version="1" id="O34">
       <dia:attribute name="obj_pos">
-        <dia:point val="39.75,18.75"/>
+        <dia:point val="39.8,18.4"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="38.0588,17.9763;41.4413,19.5237"/>
+        <dia:rectangle val="38.1088,17.6263;41.4913,19.1738"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -1130,7 +1124,7 @@ Filesystem#</dia:string>
             <dia:real val="0.80000000000000004"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="39.75,18.5712"/>
+            <dia:point val="39.8,18.2213"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -1143,9 +1137,6 @@ Filesystem#</dia:string>
       <dia:attribute name="valign">
         <dia:enum val="2"/>
       </dia:attribute>
-      <dia:connections>
-        <dia:connection handle="0" to="O33" connection="8"/>
-      </dia:connections>
     </dia:object>
     <dia:object type="Standard - Box" version="0" id="O35">
       <dia:attribute name="obj_pos">
@@ -1178,10 +1169,10 @@ Filesystem#</dia:string>
     </dia:object>
     <dia:object type="Standard - Text" version="1" id="O36">
       <dia:attribute name="obj_pos">
-        <dia:point val="45.75,18.75"/>
+        <dia:point val="45.8,18.4"/>
       </dia:attribute>
       <dia:attribute name="obj_bb">
-        <dia:rectangle val="44.0588,17.9763;47.4413,19.5237"/>
+        <dia:rectangle val="44.1088,17.6263;47.4913,19.1738"/>
       </dia:attribute>
       <dia:attribute name="text">
         <dia:composite type="text">
@@ -1196,7 +1187,172 @@ Filesystem#</dia:string>
             <dia:real val="0.80000000000000004"/>
           </dia:attribute>
           <dia:attribute name="pos">
-            <dia:point val="45.75,18.5712"/>
+            <dia:point val="45.8,18.2213"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="1"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="2"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O37">
+      <dia:attribute name="obj_pos">
+        <dia:point val="32,19.6"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="31.42,19.3525;32.58,19.8475"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#static#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.52916664630174637"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="32,19.7475"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="1"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="2"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O38">
+      <dia:attribute name="obj_pos">
+        <dia:point val="35.2,19.6"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="34.62,19.3525;35.78,19.8475"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#static#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.52916664630174637"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="35.2,19.7475"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="1"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="2"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O39">
+      <dia:attribute name="obj_pos">
+        <dia:point val="39.7,19.6"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="38.7963,19.3525;40.6037,19.8475"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#dynamic#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.52916664630174637"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="39.7,19.7475"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="1"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="2"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O40">
+      <dia:attribute name="obj_pos">
+        <dia:point val="34.6,27.8"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="33.6962,27.5525;35.5037,28.0475"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#dynamic#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.52916664630174637"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="34.6,27.9475"/>
+          </dia:attribute>
+          <dia:attribute name="color">
+            <dia:color val="#000000"/>
+          </dia:attribute>
+          <dia:attribute name="alignment">
+            <dia:enum val="1"/>
+          </dia:attribute>
+        </dia:composite>
+      </dia:attribute>
+      <dia:attribute name="valign">
+        <dia:enum val="2"/>
+      </dia:attribute>
+    </dia:object>
+    <dia:object type="Standard - Text" version="1" id="O41">
+      <dia:attribute name="obj_pos">
+        <dia:point val="45.7,19.6"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="44.7839,19.3339;46.6037,19.8661"/>
+      </dia:attribute>
+      <dia:attribute name="text">
+        <dia:composite type="text">
+          <dia:attribute name="string">
+            <dia:string>#dynamic#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="font">
+            <dia:font family="sans" style="0" name="Helvetica"/>
+          </dia:attribute>
+          <dia:attribute name="height">
+            <dia:real val="0.52916664630174637"/>
+          </dia:attribute>
+          <dia:attribute name="pos">
+            <dia:point val="45.7,19.7413"/>
           </dia:attribute>
           <dia:attribute name="color">
             <dia:color val="#000000"/>
@@ -1209,9 +1365,6 @@ Filesystem#</dia:string>
       <dia:attribute name="valign">
         <dia:enum val="2"/>
       </dia:attribute>
-      <dia:connections>
-        <dia:connection handle="0" to="O35" connection="8"/>
-      </dia:connections>
     </dia:object>
   </dia:layer>
 </dia:diagram>
diff --git a/labs/sysdev-flash-filesystems/sysdev-flash-filesystems.tex b/labs/sysdev-flash-filesystems/sysdev-flash-filesystems.tex
index 2a2bd47..cb464ac 100644
--- a/labs/sysdev-flash-filesystems/sysdev-flash-filesystems.tex
+++ b/labs/sysdev-flash-filesystems/sysdev-flash-filesystems.tex
@@ -20,12 +20,14 @@ make our system use its internal flash storage.
 Create an MTD partition to be attached to the UBI layer (the partitions
 previously used to store the kernel image and the DTB should be merged
 with this UBI partition).
-Kernel and DTB images will should be stored in two separate static
+
+The kernel and DTB images will be stored in two separate {\em static}
 (read-only) UBI volumes.
-The root filesystem will be a UBIFS volume (still mounted in a read-only).
-Read/write data will be stored in a UBIFS file system too.
-As for the kernel and DTB images, the root and data filesystems will be
-placed in a UBI volumes (this time we will use dynamic volumes).
+
+The root filesystem will be a UBI volume storing a UBIFS filesystem
+mounted read-only, the web server upload data will be stored in
+another UBI volume storing a UBIFS filesystem mounted
+read/write. These volumes will be {\em dynamic} volumes.
 
 Which gives the following layout:
 
@@ -53,10 +55,6 @@ directory from the previous lab.
 Now, we will get back to the root filesystem contents in the
 \code{nfsroot} directory, and will generate a UBIFS image from them.
 
-First enable the ubi tools in busybox (\code{ubiattach},
-\code{ubidetach}, \code{ubimkvol}, ...), then recompile and reinstall
-\code{busybox} in you rootfs directory.
-
 Now, modify the \code{/etc/init.d/rcS} file to mount a UBIFS filesystem
 on the \code{data} volume (we will declare UBI volumes in the next
 section), instead of an ext3 filesystem on the third MMC disk partition.
@@ -69,9 +67,9 @@ options as for the data filesystem.
 Create a ubinize config file where you will define the 4 volumes
 described above, then use the \code{ubinize} tool to generate your
 UBI image.
-Warning: do not use the autoresize flag (\code{vol_flags=autoresize})
-(U-Boot corrupts the UBI metadata when trying to resize expand the
-volume).
+
+Warning: do not use the autoresize flag (\code{vol_flags=autoresize}):
+U-Boot corrupts the UBI metadata when trying to expand the volume.
 
 Remember that some of these volumes are static (read-only) and some are
 not.
@@ -127,9 +125,9 @@ not.
 
 \section{MTD partitioning and flashing}
 
-Look at the way default flash partitions are defined in the board
-Device Tree sources
-(\code{arch/arm/boot/dts/at91-sama5d3_xplained.dts}).
+Look at the way the default flash partitions are defined in the board
+Device Tree source (\code{arch/arm/boot/dts/at91-sama5d3_xplained.dts}
+in your kernel tree).
 
 However, they do not match the way we wish to organize our flash
 storage. Therefore, we will define our own partitions at boot time,
@@ -159,16 +157,13 @@ command \code{nand write}.
 
 \section{Loading kernel and DTB images from UBI and booting it}
 
-Attach the UBI partition to the UBI layer and verify that all the
-UBI volumes are present.
+From Linux (still booting from the external MMC), attach the UBI
+partition to the UBI layer and verify that all the UBI volumes are
+present.
 
-Now, retrieve the kernel and DTB images from their respective UBI
-volumes and try to boot them. If it works, you can modify your
-\code{bootcmd} accordingly.
-
-
-Don't forget that you can write U-Boot scripts to automate these
-procedures. This is very handy to avoid mistakes when typing commands!
+Now back in U-Boot, retrieve the kernel and DTB images from their
+respective UBI volumes and try to boot them. If it works, you can
+modify your \code{bootcmd} accordingly.
 
 Set the \code{bootargs} variable so that:
 
@@ -180,37 +175,33 @@ Set the \code{bootargs} variable so that:
 \item The root filesystem is mounted from the 7\textsuperscript{th}
   partition, and is mounted read-only (kernel parameter
   \code{ro}).
-  \begin{itemize}
-  \item \bf{Important: even if this partition is mounted read-only,
-      the MTD partition itself must be declared as read-write.
-      Otherwise, Linux won't be able to perform ECC checks on it,
-      which involve both reading and writing.}
-  \end{itemize}
 \end{itemize}
 
-Boot the target, check that MTD partitions and UBI volumes are correctly
-configured, and that your system still works as expected. Your root
-filesystem should be mounted read-only, while the data filesystem should
-be mounted read-write, allowing you to upload data using the web server.
+Boot the target, check that the MTD partitions and UBI volumes are
+correctly configured, and that your system still works as
+expected. Your root filesystem should be mounted read-only, while the
+data filesystem should be mounted read-write, allowing you to upload
+data using the web server.
 
 %Useful u-boot environment variables
 %mtdids=nand0=atmel_nand
 %mtdparts=mtdparts=atmel_nand:256k(bootstrap),512k(u-boot),256k(u-boot-env1),256k(u-boot-env2),-(UBI)
-%bootargs_base=console=ttyS0,115200 rootfstype=ubifs root=ubi0:root ip=dhcp ubi.mtd=4 rw
+%bootargs_base=console=ttyS0,115200 rootfstype=ubifs root=ubi0:root ip=dhcp ubi.mtd=4 ro
 %bootcmd=mtdparts; ubi part UBI; ubi readvol 0x21000000 kernel; ubi readvol 0x22000000 dtb; setenv bootargs $bootargs_base $mtdparts; bootz 0x21000000 - 0x22000000
 %flash=mtdparts; nand erase.part UBI; tftp 0x21000000 test.ubi; nand write.trimffs 0x21000000 UBI $filesize
 
-\section{Resizing an existing volume and creating a new one}
+\section{Going further}
 
-In some cases you might want to adpat your NAND partitioning without
-re-flashing everything. Thanks to UBI this is possible.
+\subsection{Resizing an existing volume and creating a new one}
 
-Resize the \code{data} volume to occupy the remaining 50MiB.
+In some cases you might need to adapt your NAND partitioning without
+re-flashing everything. Thanks to UBI this is possible.
 
-Create a new \code{log} volume of 16MiB
-Mount this volume as a UBIFS filesystem and see what happens.
+From Linux, resize the \code{data} volume to occupy the remaining
+50MiB, and then create a new \code{log} volume of 16MiB. Mount this
+volume as a UBIFS filesystem and see what happens.
 
-Update your init script to mount the UBI \code{log} volume on /var/log.
+Update your init script to mount the UBI \code{log} volume on \code{/var/log}.
 Reboot your system and check that the \code{log} is correcly mounted.
 
 % Hints:
@@ -220,8 +211,7 @@ Reboot your system and check that the \code{log} is correcly mounted.
 %mount -t ubifs ubi0:log /var/log
 %
 
-
-\section{Going further}
+\subsection{Atomic update}
 
 UBI also provides an atomic update feature, which is particularly useful
 if you need to safely upgrade sensitive parts of your system (kernel,
@@ -232,7 +222,7 @@ the second kernel volume if the first one is corrupted:
 \begin{itemize}
   \item First create a new static volume to store your kernel backup
   \item Flash a valid kernel on the backup volume
-  \item Modify your bootcmd to fallback to the backup volume if the first one
+  \item Modify your \code{bootcmd} to fallback to the backup volume if the first one
     is corrupted
   \item Now try to update the kernel volume and interrupt the process before
     it has finished and see what happens (unplug the platform)
@@ -244,25 +234,26 @@ the second kernel volume if the first one is corrupted:
 
 %TODO: provide a correction
 
-\section{Going even further}
+\subsection{Using {\em squashfs} for the root filesystem}
 
 Root filesystems are often a sensitive part of your system, and you don't
 want it to be corrupted, hence some people decide to use read-only
 file system for their rootfs and use another file system to store their
 auxiliary data.
 
-\code{squashfs} is one of these read-only file systems, the problem is:
-it expects to be mounted on a block device.
+\code{squashfs} is one of these read-only file systems. However,
+\code{squashfs} expects to be mounted on a block device.
+
+Use the {\em ubiblk} layer to emulate a read-only block device on top
+of a static UBI volume to mount a {\em squashfs} filesystem as the
+root filesystem:
 
-Use the ubiblk layer to emulate a read-only block device on top of a static
-UBI volume to mount a rootfs squashfs filesystem:
 \begin{itemize}
-  \item First Create a squashfs image with your rootfs content
+  \item First create a {\em squashfs} image with your rootfs content
   \item Then create a new static volume to store your squashfs and update it with
     your squashfs image
-  \item Enable and setup the ubiblk layer
+  \item Enable and setup the {\em ubiblk} layer
   \item Boot on your new rootfs
 \end{itemize}
 
 %TODO: provide a correction
-



More information about the training-materials-updates mailing list