Changes between Version 15 and Version 16 of linux/ubi
- Timestamp:
- 04/24/2019 08:04:52 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
linux/ubi
v15 v16 1 1 [[PageOutline]] 2 2 3 = Unsorted Block Images (UBI) =3 = Unsorted Block Images (UBI) 4 4 Unsorted block images (UBI) is an erase block management layer for flash memory devices such as raw NAND devices. UBI serves two purposes: 5 5 * tracking NAND flash bad blocks … … 14 14 15 15 16 = FLASH chip geometry =16 = FLASH chip geometry 17 17 [=#flashgeometry] 18 18 Because UBI takes care of bad block tracking and wear leveling, it needs to know some details about the geometry of the raw FLASH device when creating an image. 19 19 20 The geometry data can be found in the datasheet for the specific flash device used. Gateworks uses two different sized devices which do not share geometries. 21 22 23 = UBI use on Gateworks Ventana = 24 UBI is used on the Gateworks Ventana for raw NAND storage. Prior Gateworks product families typically JFFS2. 20 The geometry data can be found in the datasheet for the specific flash device used. Gateworks uses a variety of NAND Flash devices that fall within two different unique geometries we refer to as 'normal' and 'large' which references the erase block size: 21 ||= NAND Part =||= NAND Size =||= Page Size (Bytes) =||= Block Size =||= Logical Erase Block Size =||= Blocks =||= READ_ID Bytes =||= Gateworks Geometry Name =|| 22 || Cypress S34ML16G202 || 2GiB || 2048 || 128KiB || 124KiB || 16384 || 0x01 0xd5 0xd2 0x95 || normal || 23 || Micron MT29F2G08 || 256MiB || 2048 || 128KiB || 124KiB || 2048 || 0x2c 0x90 0x95 0x06 || normal || 24 || Micron MT29F16G08 || 2GiB || 4096 || 256KiB || 248KiB || 8192 || 0x2c 0xd5 0xd1 0xa6 || large || 25 || Micron MT29F8G08 || 1GiB || 4906 || 256KiB || 248KiB || 4096 || 0x2c 0xdc 0x00 0x15 || large || 26 * The 'Page Size', 'Block Size', and max blocks are specified by the NAND datasheet. The Logical Erase Block size can be calculated as: (Block Size) - 2 * (Page Size) 27 28 29 mkfs.ubifs important arguments: 30 * **-r** Build file system from directory DIR 31 * **-F** The -F option causes mkfs.ubifs to set a special flag in the superblock, which triggers a "free space fixup" procedure in the kernel the very first time the filesystem is mounted. This fixup procedure involves finding all empty pages in the UBIFS file system and re-erasing them. This ensures that NAND pages which contain all 0xFF data get fully erased, which removes any problematic non-0xFF data from their OOB areas. 32 * **-m** Minimum I/O unit size (this is the Page Size) 33 * **-e** Logical erase block size (UBI requires 2 minimum I/O units out of each Physical Erase Block (PEB) for overhead thus this is the 'Block Size' minus 2x the Page Size 34 * **-c** Maximum logical erase block count (Number of Blocks; use the largest of the chips in the same geometry in order to create a ubifs that works on all the above NAND devices) 35 * **-x** Compression type - "lzo", "favor_lzo", "zlib" or "none" (default: "lzo") 36 * **-o** Output to FILENAME 37 * **-h** Help, provides full list of options 38 39 ubinize important arguments: 40 * **-o** Output file 41 * **-p** Size of the physical eraseblock of the flash in bytes, KiB, or MiB 42 * **-m** Minimum input/output unit size of the flash in bytes (this is the Page Size) 43 44 = UBI/UBIFS use on Gateworks Ventana 45 UBI is used on the Gateworks Ventana for raw NAND storage. Other Gateworks Product families used NOR FLASH and eMMC. 25 46 26 47 The Gateworks Ventana default U-Boot environment scripts make a few assumptions about booting from NAND flash: … … 35 56 36 57 37 == Creating a UBI using existing rootfs, kernel, and device-tree blobs == 58 38 59 [=#creatingubi] 60 == Creating a UBI/UBIFS using existing rootfs, kernel, and device-tree blobs 39 61 To create a UBI image suitable for booting on a standard Gateworks Ventana bootloader (taking into account the assumptions above) you can do the following on a Linux system provided you have a root filesystem ({{{myrootfs.tar.gz}}}), kernel ({{{uImage}}}), and device-tree dtb files ({{{imx6*-gw*.dtb}}}). 40 62 41 63 42 === 256MB FLASH devices ===43 To create a UBI image suitable for the 256MB FLASH devices:64 === 'normal' geometry FLASH devices (2048 byte page size) 65 To create a UBI image suitable for raw NAND FLASH devices with a 2048 byte page size: 44 66 1. create a temporary directory for our rootfs and untar your filesystem to it 45 67 {{{#!bash … … 53 75 cp uImage imx6*-gw*.dtb 6x_bootscript-ventana tmp/boot/ 54 76 }}} 55 3. create a ubifs image for the 2 56MBdevice geometry:56 {{{#!bash 57 mkfs.ubifs -F -m 2048 -e 124KiB -c 1 912 -x zlib-o root.ubifs -d tmp58 }}} 59 4. use {{{ubinize}}} to create ubi images for the 256MB device geometry which can be written to a suitable raw NAND devices in U-Boot using {{{nand write}}}: 60 {{{#!bash 61 # for the small layout device 77 3. create a ubifs image for the 2048 byte page size 'normal' device geometry: 78 {{{#!bash 79 mkfs.ubifs -F -m 2048 -e 124KiB -c 16248 -o root.ubifs -d tmp 80 }}} 81 * the -c parameter (max-peb-count) of 16248 assures that the filesystem can be sized up to 16248*124KiB or 1.9GiB provided there is remaining space in the ubi 82 4. use {{{ubinize}}} to create a ubi image (which can be written to a suitable raw NAND device in U-Boot using {{{nand write}}} or in Linux via {{{ubiformat}}}): 83 {{{#!bash 62 84 cat <<EOF > ubinize.cfg 63 85 [ubifs] … … 69 91 vol_flags=autoresize 70 92 EOF 71 ubinize -m 2048 -p 128KiB -s 2048 -o image.ubi ubinize.cfg 72 }}} 73 74 75 === 1GB or 2GB FLASH devices === 76 To create a UBI image suitable for the 1GB or larger FLASH devices (Note that the parameters to {{{mkfs.ubifs}}} and {{{ubinize}}} change): 93 # create ubi suitable for 2048byte page size and 128KiB block size devices 94 ubinize -m 2048 -p 128KiB -o image.ubi ubinize.cfg 95 }}} 96 97 98 === 'large' geometry FLASH devices (4096 byte page size) 99 To create a UBI image suitable for raw NAND FLASH devices with a 4096 byte page size: 77 100 1. create a temporary directory for our rootfs and untar your filesystem to it 78 101 {{{#!bash … … 86 109 cp uImage imx6*-gw*.dtb 6x_bootscript-ventana tmp/boot/ 87 110 }}} 88 3. create ubifs images for the 'large' device geometry:89 {{{#!bash 90 mkfs.ubifs -F -m 4096 -e 248KiB -c 8124 - x zlib -o root.ubifs -d tmp91 }}} 92 4. use {{{ubinize}}} to create ubi image for the 'large' device geometry which can be written to a suitable raw NAND devices in U-Boot using nand write: 93 {{{#!bash 94 # for the small layout device 111 3. create ubifs images for the 4096 byte page size 'large' device geometry: 112 {{{#!bash 113 mkfs.ubifs -F -m 4096 -e 248KiB -c 8124 -o root.ubifs -d tmp 114 }}} 115 * the -c parameter (max-peb-count) of 8124 assures that the filesystem can be sized up to 8124*248KiB or 1.9GiB provided there is remaining space in the ubi 116 4. use {{{ubinize}}} to create ubi image (which can be written to a suitable raw NAND device in U-Boot using {{{nand write}} or in Linux via {{{ubiformat}}}: 117 {{{#!bash 95 118 cat <<EOF > ubinize.cfg 96 119 [ubifs] … … 102 125 vol_flags=autoresize 103 126 EOF 104 ubinize -m 4096 -p 256KiB -s 4096 -o image.ubi ubinize.cfg 105 }}} 106 107 === Creating your own .ubifs file 108 {{{#!bash 109 sudo mkfs.ubifs -d /your/rootfs/ -F -m 4096 -e 248KiB -c 8124 -x zlib -o A_large.ubifs 110 }}} 111 112 Essentials: 113 114 * **-r** Build file system from directory DIR 115 * **-F** The -F option causes mkfs.ubifs to set a special flag in the superblock, which triggers a "free space fixup" procedure in the kernel the very first time the filesystem is mounted. This fixup procedure involves finding all empty pages in the UBIFS file system and re-erasing them. This ensures that NAND pages which contain all 0xFF data get fully erased, which removes any problematic non-0xFF data from their OOB areas. 116 * **-m** Minimum I/O unit size 117 * **-e** Logical erase block size 118 * **-c** Maximum logical erase block count 119 * **-x** Compression type - "lzo", "favor_lzo", "zlib" or "none" (default: "lzo") 120 * **-o** Output to FILENAME 121 * **-h** Help, provides full list of options 127 # create ubi suitable for 4096byte page size and 256KiB block size devices 128 ubinize -m 4096 -p 256KiB -o image.ubi ubinize.cfg 129 }}} 130 131 132 122 133 === Bad blocks 123 134 124 NAND flashes have a random amount of initial bad eraseblocks. This means that different devices may have slightly different volume sizes (especially if the UBI auto-resize feature is used).125 126 127 == Working with a UBI in Linux OS (extracting or manipulating contents) ==135 NAND flashes have a random amount of initial bad blocks. This means that different devices may have slightly different volume sizes (especially if the UBI auto-resize feature is used). 136 137 138 == Working with a UBI in Linux OS (extracting or manipulating contents) 128 139 [=#ubiinlinux] 129 140 Linux has support for ubi: … … 161 172 162 173 163 === On a (NAND-less) Linux Development Host ===174 === On a (NAND-less) Linux Development Host using nandsim 164 175 [=#ubiondevhost] 165 176 Often you want to work with UBI and UBIFS images on a Linux Development Host which has no NAND itself. While it is not currently possible to mount a UBI or UBIFS as a loopback device (commonly used for other types of block devices) you can use the nandsim kernel module to simulate a NAND device on a NAND-less Linux development host. … … 169 180 To create a virtual NAND device on a NAND-less Linux development system: 170 181 1. load {{{nandsim}}} module with parameters for specific flash device simulating: 171 * 256M B FLASH (what we refer to as the 'normal' flash device):182 * 256MiB MT29F2G08 FLASH 172 183 {{{#!bash 173 184 sudo rmmod nandsim … … 178 189 fourth_id_byte=0x95 179 190 }}} 180 * 1GB or 2GB FLASH (what we refer to as the 'large' flash device): 191 * 2GiB Cyrpess S34ML16G202 FLASH 192 {{{#!bash 193 sudo rmmod nandsim 194 sudo modprobe nandsim \ 195 first_id_byte=0x01 \ 196 second_id_byte=0xd5 \ 197 third_id_byte=0xd2 \ 198 fourth_id_byte=0x95 199 }}} 200 * 2GiB Micron MT29F16G08 FLASH: 181 201 {{{#!bash 182 202 sudo rmmod nandsim … … 199 219 {{{#!bash 200 220 sudo modprobe ubi 201 sudo ubiattach /dev/ubi_ctrl -m0 -O2048221 sudo ubiattach /dev/ubi_ctrl -m0 202 222 sudo ubiinfo -a # optionally show info about the UBI 203 223 }}} … … 232 252 233 253 234 === On a target board with NAND FLASH ===254 === On a target board with NAND FLASH 235 255 [=#ubiontarget] 236 256 To extract or manipulate the contents of a UBI within the NAND Flash of a Linux system, Linux must be booted from a secondary medium without the NAND FLASH partition being mounted. … … 294 314 setenv ipaddr 192.168.1.1 295 315 setenv serverip 192.168.1.254 296 tftp ${loadaddr} image.ubi && \316 tftpboot ${loadaddr} image.ubi && \ 297 317 nand erase.part rootfs && \ 298 318 nand write ${loadaddr} rootfs ${filesize} … … 348 368 {{{#!bash 349 369 setenv serverip 192.168.1.100 350 tftp nand_split_update.scr370 tftpboot nand_split_update.scr 351 371 source $loadaddr 352 372 }}} … … 369 389 370 390 [=#uboot-ubifs] 371 === Updating NAND FLASH with a ubifs image ===391 === Updating NAND FLASH with a ubifs image 372 392 To update the contents of a ubi with a ubifs in U-Boot: 373 393 {{{#!bash … … 376 396 ubi remove rootfs # remove rootfs volume 377 397 ubi create rootfs a00000 static # create a 10MB volume named rootfs 378 tftp ${loadaddr} ventana/root.ubifs && ubi write ${loadaddr} rootfs ${filesize}398 tftpboot ${loadaddr} ventana/root.ubifs && ubi write ${loadaddr} rootfs ${filesize} 379 399 ubifsmount ubi0:rootfs # mount rootfs volume from ubi 380 400 ubifsls /