Changes between Version 37 and Version 38 of linux/ubi


Ignore:
Timestamp:
06/05/2024 05:06:25 PM (6 months ago)
Author:
Tim Harvey
Comment:

updated nandsim section to add partition details

Legend:

Unmodified
Added
Removed
Modified
  • linux/ubi

    v37 v38  
    263263Often 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.
    264264
    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. As Gateworks boards support two flash sizes, we will show both examples.
     265To 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.
    266266
    267267To create a virtual NAND device on a NAND-less Linux development system:
     
    274274  second_id_byte=0xda \
    275275  third_id_byte=0x90 \
    276   fourth_id_byte=0x95
     276  fourth_id_byte=0x95 \
     277  parts=0x80,0x8,0x778
    277278}}}
    278279 * 2GiB Cyrpess S34ML16G202 FLASH
     
    283284  second_id_byte=0xd5 \
    284285  third_id_byte=0xd2 \
    285   fourth_id_byte=0x95
     286  fourth_id_byte=0x95 \
     287  parts=0x80,0x8,0x778
    286288}}}
    287289 * 2GiB Micron MT29F16G08 FLASH:
     
    292294  second_id_byte=0xd5 \
    293295  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
     303dev:    size   erasesize  name
     304mtd0: 01000000 00020000 "NAND simulator partition 0"
     305mtd1: 00100000 00020000 "NAND simulator partition 1"
     306mtd2: 0ef00000 00020000 "NAND simulator partition 2"
     307}}}
    297308 * 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}}}.
    2983091. populate NAND with an existing ubi:
    299310{{{#!bash
    300 sudo modprobe mtdblock
    301 sudo dd if=image.ubi of=/dev/mtdblock0 bs=2048
    302 }}}
    303  * the mtdblock module creates a {{{/dev/mtdblock0}}} device on your development host
    304  * Note that instead of the dd command above you could also have used {{{ubiformat /dev/mtd0}}} to wipe and format a new ubi but this section is documenting how to extract and alter contents of an existing ubi.
     311sudo modprobe mtdblock # create /dev/mtdblock devices for each partition
     312sudo 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.
    3053161. attach the UBI
    306317{{{#!bash
    307318sudo modprobe ubi
    308 sudo ubiattach /dev/ubi_ctrl -m0 -O2048
     319sudo ubiattach /dev/ubi_ctrl -m2 -O2048
    309320sudo ubinfo -a # optionally show info about the UBI
    310321}}}
     322 * Note the 'm' parameter specifies the mtd device number and we are working with /dev/mtd2 which is the rootfs partition
    3113231. mount the ubifs to host
    312324{{{#!bash
     
    316328ls /mnt/ubi # optionally list contents of mounted filesystem
    317329}}}
     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
    318331
    319332Once you are done working with the files in {{{/mnt/ubi}}} simply unmount the device:
     
    324337If you have altered the filesystem and wish to extract the altered UBI you can detach and use dd to copy it to a file:
    325338{{{#!bash
    326 sudo ubidetach /dev/ubi_ctrl -m0
    327 sudo dd if=/dev/mtdblock0 of=image-updated.ubi bs=2048
    328 }}}
     339sudo ubidetach /dev/ubi_ctrl -m2
     340sudo 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
    329343
    330344And when you are done working with the simulated NAND device completely, remove the {{{nandsim}}} module to free up your system memory: