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