Changes between Version 37 and Version 38 of linux/ubi
- Timestamp:
- 06/05/2024 05:06:25 PM (6 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
linux/ubi
v37 v38 263 263 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. 264 264 265 To create a simulated NAND device you need to know the first four bytes returned by the READ_ID flash command, which identifies the characteristics of the device. These values can be found in the datasheet of the FLASH devices. A s Gateworks boards support two flash sizes, we will show both examples.265 To create a simulated NAND device you need to know the first four bytes returned by the READ_ID flash command, which identifies the characteristics of the device. These values can be found in the datasheet of the FLASH devices. Additionally you need to define the partitions used via the 'parts' kernel parameter. As Gateworks boards support two flash sizes, we will show both examples. 266 266 267 267 To create a virtual NAND device on a NAND-less Linux development system: … … 274 274 second_id_byte=0xda \ 275 275 third_id_byte=0x90 \ 276 fourth_id_byte=0x95 276 fourth_id_byte=0x95 \ 277 parts=0x80,0x8,0x778 277 278 }}} 278 279 * 2GiB Cyrpess S34ML16G202 FLASH … … 283 284 second_id_byte=0xd5 \ 284 285 third_id_byte=0xd2 \ 285 fourth_id_byte=0x95 286 fourth_id_byte=0x95 \ 287 parts=0x80,0x8,0x778 286 288 }}} 287 289 * 2GiB Micron MT29F16G08 FLASH: … … 292 294 second_id_byte=0xd5 \ 293 295 third_id_byte=0xd1 \ 294 fourth_id_byte=0xa6 295 }}} 296 * the above create a {{{/dev/mtd0}}} device on your development host 296 fourth_id_byte=0xa6 \ 297 parts=0x80,0x8,0x778 298 }}} 299 * the parts argument provides a comma separated list of partition sizes (in units of erase blocks) used to partition the NAND device and the choices above matches the partitions Gateworks uses for the Ventana boards which is defined via the U-Boot env var 'mtdparts' which by default is set to 'mtdparts=nand:16m(uboot),1m(env),-(rootfs)' 300 * the above creates the following MTD devices (which you can see via /proc/mtd): 301 {{{#!bash 302 $ cat /proc/mtd 303 dev: size erasesize name 304 mtd0: 01000000 00020000 "NAND simulator partition 0" 305 mtd1: 00100000 00020000 "NAND simulator partition 1" 306 mtd2: 0ef00000 00020000 "NAND simulator partition 2" 307 }}} 297 308 * by default nandsim will use RAM backed storage which makes for much faster read/write access, however if you are cramped for RAM space and simulating a large device (ie 2GB) you can add a {{{cache_file=/tmp/nandimage}}} param to {{{nandsim}}} to tell it to use a file-backed storage instead. You can remove the file once you {{{rmmod nandsim}}}. 298 309 1. populate NAND with an existing ubi: 299 310 {{{#!bash 300 sudo modprobe mtdblock 301 sudo dd if=image.ubi of=/dev/mtdblock 0bs=2048302 }}} 303 * the mtdblock module creates a {{{/dev/mtdblock0}}} device on your development host304 * Note that instead of the dd command above you could also have used {{{ubiformat /dev/mtd 0}}} to wipe and format a new ubi but this section is documenting how to extract and alter contents of an existing ubi.311 sudo modprobe mtdblock # create /dev/mtdblock devices for each partition 312 sudo dd if=image.ubi of=/dev/mtdblock2 bs=2048 313 }}} 314 * Note we are working with the 3rd MTD partition {{{/dev/mtd2}}} and {{{/dev/mtdblock2}}} as this is the partition where we store the rootfs 315 * Note that instead of the dd command above you could also have used {{{ubiformat /dev/mtd2}}} to wipe and format a new ubi but this section is documenting how to extract and alter contents of an existing ubi. 305 316 1. attach the UBI 306 317 {{{#!bash 307 318 sudo modprobe ubi 308 sudo ubiattach /dev/ubi_ctrl -m 0-O2048319 sudo ubiattach /dev/ubi_ctrl -m2 -O2048 309 320 sudo ubinfo -a # optionally show info about the UBI 310 321 }}} 322 * Note the 'm' parameter specifies the mtd device number and we are working with /dev/mtd2 which is the rootfs partition 311 323 1. mount the ubifs to host 312 324 {{{#!bash … … 316 328 ls /mnt/ubi # optionally list contents of mounted filesystem 317 329 }}} 330 * Note that mount operates on the UBI device of which we have 1 of (thus ubi0) where we have used ubiattach to attach it to the 3rd partition (-m2) above 318 331 319 332 Once you are done working with the files in {{{/mnt/ubi}}} simply unmount the device: … … 324 337 If you have altered the filesystem and wish to extract the altered UBI you can detach and use dd to copy it to a file: 325 338 {{{#!bash 326 sudo ubidetach /dev/ubi_ctrl -m0 327 sudo dd if=/dev/mtdblock0 of=image-updated.ubi bs=2048 328 }}} 339 sudo ubidetach /dev/ubi_ctrl -m2 340 sudo dd if=/dev/mtdblock2 of=image-updated.ubi bs=2048 341 }}} 342 * Note the 'm' parameter specifies the mtd device number and we are working with /dev/mtd2 which is the rootfs partition 329 343 330 344 And when you are done working with the simulated NAND device completely, remove the {{{nandsim}}} module to free up your system memory: