5 UBI support in U-Boot is broken down into five separate commands.
6 The first is the ubi command, which has six subcommands:
12 ubi part [part] [offset]
13 - Show or set current partition (with optional VID header offset)
14 ubi info [l[ayout]] - Display volume and ubi layout information
15 ubi create[vol] volume [size] [type] - create volume name with size
16 ubi write[vol] address volume size - Write volume from address with size
17 ubi read[vol] address volume [size] - Read volume to address with size
18 ubi remove[vol] volume - Remove volume
20 volume: character name
21 size: specified in bytes
22 type: s[tatic] or d[ynamic] (default=dynamic)
25 The first command that is needed to be issues is "ubi part" to connect
26 one mtd partition to the UBI subsystem. This command will either create
27 a new UBI device on the requested MTD partition. Or it will attach a
28 previously created UBI device. The other UBI commands will only work
29 when such a UBI device is attached (via "ubi part"). Here an example:
33 device nor0 <1fc000000.nor_flash>, # parts = 6
34 #: name size offset mask_flags
35 0: kernel 0x00200000 0x00000000 0
36 1: dtb 0x00040000 0x00200000 0
37 2: root 0x00200000 0x00240000 0
38 3: user 0x01ac0000 0x00440000 0
39 4: env 0x00080000 0x01f00000 0
40 5: u-boot 0x00080000 0x01f80000 0
42 active partition: nor0,0 - (kernel) 0x00200000 @ 0x00000000
45 mtdids : nor0=1fc000000.nor_flash
46 mtdparts: mtdparts=1fc000000.nor_flash:2m(kernel),256k(dtb),2m(root),27392k(user),512k(env),512k(u-boot)
49 Creating 1 MTD partitions on "nor0":
50 0x000000240000-0x000000440000 : "mtd=2"
51 UBI: attaching mtd1 to ubi0
52 UBI: physical eraseblock size: 262144 bytes (256 KiB)
53 UBI: logical eraseblock size: 262016 bytes
54 UBI: smallest flash I/O unit: 1
55 UBI: VID header offset: 64 (aligned 64)
57 UBI: attached mtd1 to ubi0
58 UBI: MTD device name: "mtd=2"
59 UBI: MTD device size: 2 MiB
60 UBI: number of good PEBs: 8
61 UBI: number of bad PEBs: 0
62 UBI: max. allowed volumes: 128
63 UBI: wear-leveling threshold: 4096
64 UBI: number of internal volumes: 1
65 UBI: number of user volumes: 1
66 UBI: available PEBs: 0
67 UBI: total number of reserved PEBs: 8
68 UBI: number of PEBs reserved for bad PEB handling: 0
69 UBI: max/mean erase counter: 2/1
72 Now that the UBI device is attached, this device can be modified
73 using the following commands:
75 ubi info Display volume and ubi layout information
76 ubi createvol Create UBI volume on UBI device
77 ubi removevol Remove UBI volume from UBI device
78 ubi read Read data from UBI volume to memory
79 ubi write Write data from memory to UBI volume
82 Here a few examples on the usage:
85 Creating dynamic volume testvol of size 1048064
88 UBI: volume information dump:
95 UBI: usable_leb_size 262016
97 UBI: used_bytes 1048064
98 UBI: last_eb_bytes 262016
103 UBI: volume information dump:
104 UBI: vol_id 2147479551
110 UBI: usable_leb_size 262016
112 UBI: used_bytes 524032
116 UBI: name layout volume
119 UBI: MTD device name: "mtd=2"
120 UBI: MTD device size: 2 MiB
121 UBI: physical eraseblock size: 262144 bytes (256 KiB)
122 UBI: logical eraseblock size: 262016 bytes
123 UBI: number of good PEBs: 8
124 UBI: number of bad PEBs: 0
125 UBI: smallest flash I/O unit: 1
126 UBI: VID header offset: 64 (aligned 64)
127 UBI: data offset: 128
128 UBI: max. allowed volumes: 128
129 UBI: wear-leveling threshold: 4096
130 UBI: number of internal volumes: 1
131 UBI: number of user volumes: 1
132 UBI: available PEBs: 0
133 UBI: total number of reserved PEBs: 8
134 UBI: number of PEBs reserved for bad PEB handling: 0
135 UBI: max/mean erase counter: 4/1
137 => ubi write 800000 testvol 80000
138 Volume "testvol" found at volume id 0
140 => ubi read 900000 testvol 80000
141 Volume testvol found at volume id 0
142 read 524288 bytes from volume 0 to 900000(buf address)
144 => cmp.b 800000 900000 80000
145 Total of 524288 bytes were the same
148 Next, the ubifsmount command allows you to access filesystems on the
149 UBI partition which has been attached with the ubi part command:
152 ubifsmount - mount UBIFS volume
155 ubifsmount <volume-name>
156 - mount 'volume-name' volume
160 => ubifsmount ubi0:recovery
161 UBIFS: mounted UBI device 0, volume 0, name "recovery"
162 UBIFS: mounted read-only
163 UBIFS: file system size: 46473216 bytes (45384 KiB, 44 MiB, 366 LEBs)
164 UBIFS: journal size: 6348800 bytes (6200 KiB, 6 MiB, 50 LEBs)
165 UBIFS: media format: w4/r0 (latest is w4/r0)
166 UBIFS: default compressor: LZO
167 UBIFS: reserved for root: 0 bytes (0 KiB)
169 Note that unlike Linux, U-Boot can only have one active UBI partition
170 at a time, which can be referred to as ubi0, and must be supplied along
171 with the name of the filesystem you are mounting.
174 Once a UBI filesystem has been mounted, the ubifsls command allows you
175 to list the contents of a directory in the filesystem:
179 ubifsls - list files in a directory
183 - list files in a 'directory' (default '/')
188 17442 Thu Jan 01 02:57:38 1970 imx28-evk.dtb
189 2998146 Thu Jan 01 02:57:43 1970 zImage
192 And the ubifsload command allows you to load a file from a UBI
197 ubifsload - load file from an UBIFS filesystem
200 ubifsload <addr> <filename> [bytes]
201 - load file 'filename' to address 'addr'
205 => ubifsload ${loadaddr} zImage
206 Loading file 'zImage' to addr 0x42000000 with size 2998146 (0x002dbf82)...
210 Finally, you can unmount the UBI filesystem with the ubifsumount
214 ubifsumount - unmount UBIFS volume
217 ubifsumount - unmount current volume
222 Unmounting UBIFS volume recovery!