1ae8082c7SStefan Roese------------------- 2ae8082c7SStefan RoeseUBI usage in U-Boot 3ae8082c7SStefan Roese------------------- 4ae8082c7SStefan Roese 5cc63bb05SPaul B. HensonUBI support in U-Boot is broken down into five separate commands. 6cc63bb05SPaul B. HensonThe first is the ubi command, which has six subcommands: 7ae8082c7SStefan Roese 8ae8082c7SStefan Roese=> help ubi 9ae8082c7SStefan Roeseubi - ubi commands 10ae8082c7SStefan Roese 11ae8082c7SStefan RoeseUsage: 12ae8082c7SStefan Roeseubi part [part] [offset] 13ae8082c7SStefan Roese - Show or set current partition (with optional VID header offset) 14ae8082c7SStefan Roeseubi info [l[ayout]] - Display volume and ubi layout information 15ae8082c7SStefan Roeseubi create[vol] volume [size] [type] - create volume name with size 16ae8082c7SStefan Roeseubi write[vol] address volume size - Write volume from address with size 17*cc734f5aSPaul Burtonubi write.part address volume size [fullsize] 18*cc734f5aSPaul Burton - Write part of a volume from address 19ae8082c7SStefan Roeseubi read[vol] address volume [size] - Read volume to address with size 20ae8082c7SStefan Roeseubi remove[vol] volume - Remove volume 21ae8082c7SStefan Roese[Legends] 22ae8082c7SStefan Roese volume: character name 23ae8082c7SStefan Roese size: specified in bytes 24ae8082c7SStefan Roese type: s[tatic] or d[ynamic] (default=dynamic) 25ae8082c7SStefan Roese 26ae8082c7SStefan Roese 27ae8082c7SStefan RoeseThe first command that is needed to be issues is "ubi part" to connect 28ae8082c7SStefan Roeseone mtd partition to the UBI subsystem. This command will either create 29ae8082c7SStefan Roesea new UBI device on the requested MTD partition. Or it will attach a 30ae8082c7SStefan Roesepreviously created UBI device. The other UBI commands will only work 31ae8082c7SStefan Roesewhen such a UBI device is attached (via "ubi part"). Here an example: 32ae8082c7SStefan Roese 33ae8082c7SStefan Roese=> mtdparts 34ae8082c7SStefan Roese 35ae8082c7SStefan Roesedevice nor0 <1fc000000.nor_flash>, # parts = 6 36ae8082c7SStefan Roese #: name size offset mask_flags 37ae8082c7SStefan Roese 0: kernel 0x00200000 0x00000000 0 38ae8082c7SStefan Roese 1: dtb 0x00040000 0x00200000 0 39ae8082c7SStefan Roese 2: root 0x00200000 0x00240000 0 40ae8082c7SStefan Roese 3: user 0x01ac0000 0x00440000 0 41ae8082c7SStefan Roese 4: env 0x00080000 0x01f00000 0 42ae8082c7SStefan Roese 5: u-boot 0x00080000 0x01f80000 0 43ae8082c7SStefan Roese 44ae8082c7SStefan Roeseactive partition: nor0,0 - (kernel) 0x00200000 @ 0x00000000 45ae8082c7SStefan Roese 46ae8082c7SStefan Roesedefaults: 47ae8082c7SStefan Roesemtdids : nor0=1fc000000.nor_flash 48ae8082c7SStefan Roesemtdparts: mtdparts=1fc000000.nor_flash:2m(kernel),256k(dtb),2m(root),27392k(user),512k(env),512k(u-boot) 49ae8082c7SStefan Roese 50ae8082c7SStefan Roese=> ubi part root 51ae8082c7SStefan RoeseCreating 1 MTD partitions on "nor0": 52ae8082c7SStefan Roese0x000000240000-0x000000440000 : "mtd=2" 53ae8082c7SStefan RoeseUBI: attaching mtd1 to ubi0 54ae8082c7SStefan RoeseUBI: physical eraseblock size: 262144 bytes (256 KiB) 55ae8082c7SStefan RoeseUBI: logical eraseblock size: 262016 bytes 56ae8082c7SStefan RoeseUBI: smallest flash I/O unit: 1 57ae8082c7SStefan RoeseUBI: VID header offset: 64 (aligned 64) 58ae8082c7SStefan RoeseUBI: data offset: 128 59ae8082c7SStefan RoeseUBI: attached mtd1 to ubi0 60ae8082c7SStefan RoeseUBI: MTD device name: "mtd=2" 61ae8082c7SStefan RoeseUBI: MTD device size: 2 MiB 62ae8082c7SStefan RoeseUBI: number of good PEBs: 8 63ae8082c7SStefan RoeseUBI: number of bad PEBs: 0 64ae8082c7SStefan RoeseUBI: max. allowed volumes: 128 65ae8082c7SStefan RoeseUBI: wear-leveling threshold: 4096 66ae8082c7SStefan RoeseUBI: number of internal volumes: 1 67ae8082c7SStefan RoeseUBI: number of user volumes: 1 68ae8082c7SStefan RoeseUBI: available PEBs: 0 69ae8082c7SStefan RoeseUBI: total number of reserved PEBs: 8 70ae8082c7SStefan RoeseUBI: number of PEBs reserved for bad PEB handling: 0 71ae8082c7SStefan RoeseUBI: max/mean erase counter: 2/1 72ae8082c7SStefan Roese 73ae8082c7SStefan Roese 74ae8082c7SStefan RoeseNow that the UBI device is attached, this device can be modified 75ae8082c7SStefan Roeseusing the following commands: 76ae8082c7SStefan Roese 77ae8082c7SStefan Roeseubi info Display volume and ubi layout information 78ae8082c7SStefan Roeseubi createvol Create UBI volume on UBI device 79ae8082c7SStefan Roeseubi removevol Remove UBI volume from UBI device 80ae8082c7SStefan Roeseubi read Read data from UBI volume to memory 81ae8082c7SStefan Roeseubi write Write data from memory to UBI volume 82*cc734f5aSPaul Burtonubi write.part Write data from memory to UBI volume, in parts 83ae8082c7SStefan Roese 84ae8082c7SStefan Roese 85ae8082c7SStefan RoeseHere a few examples on the usage: 86ae8082c7SStefan Roese 87ae8082c7SStefan Roese=> ubi create testvol 88ae8082c7SStefan RoeseCreating dynamic volume testvol of size 1048064 89ae8082c7SStefan Roese 90ae8082c7SStefan Roese=> ubi info l 91ae8082c7SStefan RoeseUBI: volume information dump: 92ae8082c7SStefan RoeseUBI: vol_id 0 93ae8082c7SStefan RoeseUBI: reserved_pebs 4 94ae8082c7SStefan RoeseUBI: alignment 1 95ae8082c7SStefan RoeseUBI: data_pad 0 96ae8082c7SStefan RoeseUBI: vol_type 3 97ae8082c7SStefan RoeseUBI: name_len 7 98ae8082c7SStefan RoeseUBI: usable_leb_size 262016 99ae8082c7SStefan RoeseUBI: used_ebs 4 100ae8082c7SStefan RoeseUBI: used_bytes 1048064 101ae8082c7SStefan RoeseUBI: last_eb_bytes 262016 102ae8082c7SStefan RoeseUBI: corrupted 0 103ae8082c7SStefan RoeseUBI: upd_marker 0 104ae8082c7SStefan RoeseUBI: name testvol 105ae8082c7SStefan Roese 106ae8082c7SStefan RoeseUBI: volume information dump: 107ae8082c7SStefan RoeseUBI: vol_id 2147479551 108ae8082c7SStefan RoeseUBI: reserved_pebs 2 109ae8082c7SStefan RoeseUBI: alignment 1 110ae8082c7SStefan RoeseUBI: data_pad 0 111ae8082c7SStefan RoeseUBI: vol_type 3 112ae8082c7SStefan RoeseUBI: name_len 13 113ae8082c7SStefan RoeseUBI: usable_leb_size 262016 114ae8082c7SStefan RoeseUBI: used_ebs 2 115ae8082c7SStefan RoeseUBI: used_bytes 524032 116ae8082c7SStefan RoeseUBI: last_eb_bytes 2 117ae8082c7SStefan RoeseUBI: corrupted 0 118ae8082c7SStefan RoeseUBI: upd_marker 0 119ae8082c7SStefan RoeseUBI: name layout volume 120ae8082c7SStefan Roese 121ae8082c7SStefan Roese=> ubi info 122ae8082c7SStefan RoeseUBI: MTD device name: "mtd=2" 123ae8082c7SStefan RoeseUBI: MTD device size: 2 MiB 124ae8082c7SStefan RoeseUBI: physical eraseblock size: 262144 bytes (256 KiB) 125ae8082c7SStefan RoeseUBI: logical eraseblock size: 262016 bytes 126ae8082c7SStefan RoeseUBI: number of good PEBs: 8 127ae8082c7SStefan RoeseUBI: number of bad PEBs: 0 128ae8082c7SStefan RoeseUBI: smallest flash I/O unit: 1 129ae8082c7SStefan RoeseUBI: VID header offset: 64 (aligned 64) 130ae8082c7SStefan RoeseUBI: data offset: 128 131ae8082c7SStefan RoeseUBI: max. allowed volumes: 128 132ae8082c7SStefan RoeseUBI: wear-leveling threshold: 4096 133ae8082c7SStefan RoeseUBI: number of internal volumes: 1 134ae8082c7SStefan RoeseUBI: number of user volumes: 1 135ae8082c7SStefan RoeseUBI: available PEBs: 0 136ae8082c7SStefan RoeseUBI: total number of reserved PEBs: 8 137ae8082c7SStefan RoeseUBI: number of PEBs reserved for bad PEB handling: 0 138ae8082c7SStefan RoeseUBI: max/mean erase counter: 4/1 139ae8082c7SStefan Roese 140ae8082c7SStefan Roese=> ubi write 800000 testvol 80000 141ae8082c7SStefan RoeseVolume "testvol" found at volume id 0 142ae8082c7SStefan Roese 143ae8082c7SStefan Roese=> ubi read 900000 testvol 80000 144ae8082c7SStefan RoeseVolume testvol found at volume id 0 145ae8082c7SStefan Roeseread 524288 bytes from volume 0 to 900000(buf address) 146ae8082c7SStefan Roese 147ae8082c7SStefan Roese=> cmp.b 800000 900000 80000 148ae8082c7SStefan RoeseTotal of 524288 bytes were the same 149cc63bb05SPaul B. Henson 150cc63bb05SPaul B. Henson 151cc63bb05SPaul B. HensonNext, the ubifsmount command allows you to access filesystems on the 152cc63bb05SPaul B. HensonUBI partition which has been attached with the ubi part command: 153cc63bb05SPaul B. Henson 154cc63bb05SPaul B. Henson=> help ubifsmount 155cc63bb05SPaul B. Hensonubifsmount - mount UBIFS volume 156cc63bb05SPaul B. Henson 157cc63bb05SPaul B. HensonUsage: 158cc63bb05SPaul B. Hensonubifsmount <volume-name> 159cc63bb05SPaul B. Henson - mount 'volume-name' volume 160cc63bb05SPaul B. Henson 161cc63bb05SPaul B. HensonFor example: 162cc63bb05SPaul B. Henson 163cc63bb05SPaul B. Henson=> ubifsmount ubi0:recovery 164cc63bb05SPaul B. HensonUBIFS: mounted UBI device 0, volume 0, name "recovery" 165cc63bb05SPaul B. HensonUBIFS: mounted read-only 166cc63bb05SPaul B. HensonUBIFS: file system size: 46473216 bytes (45384 KiB, 44 MiB, 366 LEBs) 167cc63bb05SPaul B. HensonUBIFS: journal size: 6348800 bytes (6200 KiB, 6 MiB, 50 LEBs) 168cc63bb05SPaul B. HensonUBIFS: media format: w4/r0 (latest is w4/r0) 169cc63bb05SPaul B. HensonUBIFS: default compressor: LZO 170cc63bb05SPaul B. HensonUBIFS: reserved for root: 0 bytes (0 KiB) 171cc63bb05SPaul B. Henson 172cc63bb05SPaul B. HensonNote that unlike Linux, U-Boot can only have one active UBI partition 173cc63bb05SPaul B. Hensonat a time, which can be referred to as ubi0, and must be supplied along 174cc63bb05SPaul B. Hensonwith the name of the filesystem you are mounting. 175cc63bb05SPaul B. Henson 176cc63bb05SPaul B. Henson 177cc63bb05SPaul B. HensonOnce a UBI filesystem has been mounted, the ubifsls command allows you 178cc63bb05SPaul B. Hensonto list the contents of a directory in the filesystem: 179cc63bb05SPaul B. Henson 180cc63bb05SPaul B. Henson 181cc63bb05SPaul B. Henson=> help ubifsls 182cc63bb05SPaul B. Hensonubifsls - list files in a directory 183cc63bb05SPaul B. Henson 184cc63bb05SPaul B. HensonUsage: 185cc63bb05SPaul B. Hensonubifsls [directory] 186cc63bb05SPaul B. Henson - list files in a 'directory' (default '/') 187cc63bb05SPaul B. Henson 188cc63bb05SPaul B. HensonFor example: 189cc63bb05SPaul B. Henson 190cc63bb05SPaul B. Henson=> ubifsls 191cc63bb05SPaul B. Henson 17442 Thu Jan 01 02:57:38 1970 imx28-evk.dtb 192cc63bb05SPaul B. Henson 2998146 Thu Jan 01 02:57:43 1970 zImage 193cc63bb05SPaul B. Henson 194cc63bb05SPaul B. Henson 195cc63bb05SPaul B. HensonAnd the ubifsload command allows you to load a file from a UBI 196cc63bb05SPaul B. Hensonfilesystem: 197cc63bb05SPaul B. Henson 198cc63bb05SPaul B. Henson 199cc63bb05SPaul B. Henson=> help ubifsload 200cc63bb05SPaul B. Hensonubifsload - load file from an UBIFS filesystem 201cc63bb05SPaul B. Henson 202cc63bb05SPaul B. HensonUsage: 203cc63bb05SPaul B. Hensonubifsload <addr> <filename> [bytes] 204cc63bb05SPaul B. Henson - load file 'filename' to address 'addr' 205cc63bb05SPaul B. Henson 206cc63bb05SPaul B. HensonFor example: 207cc63bb05SPaul B. Henson 208cc63bb05SPaul B. Henson=> ubifsload ${loadaddr} zImage 209cc63bb05SPaul B. HensonLoading file 'zImage' to addr 0x42000000 with size 2998146 (0x002dbf82)... 210cc63bb05SPaul B. HensonDone 211cc63bb05SPaul B. Henson 212cc63bb05SPaul B. Henson 213cc63bb05SPaul B. HensonFinally, you can unmount the UBI filesystem with the ubifsumount 214cc63bb05SPaul B. Hensoncommand: 215cc63bb05SPaul B. Henson 216cc63bb05SPaul B. Henson=> help ubifsumount 217cc63bb05SPaul B. Hensonubifsumount - unmount UBIFS volume 218cc63bb05SPaul B. Henson 219cc63bb05SPaul B. HensonUsage: 220cc63bb05SPaul B. Hensonubifsumount - unmount current volume 221cc63bb05SPaul B. Henson 222cc63bb05SPaul B. HensonFor example: 223cc63bb05SPaul B. Henson 224cc63bb05SPaul B. Henson=> ubifsumount 225cc63bb05SPaul B. HensonUnmounting UBIFS volume recovery! 226