README.ubi 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. -------------------
  2. UBI usage in U-Boot
  3. -------------------
  4. UBI support in U-Boot is broken down into five separate commands.
  5. The first is the ubi command, which has six subcommands:
  6. => help ubi
  7. ubi - ubi commands
  8. Usage:
  9. ubi part [part] [offset]
  10. - Show or set current partition (with optional VID header offset)
  11. ubi info [l[ayout]] - Display volume and ubi layout information
  12. ubi create[vol] volume [size] [type] - create volume name with size
  13. ubi write[vol] address volume size - Write volume from address with size
  14. ubi write.part address volume size [fullsize]
  15. - Write part of a volume from address
  16. ubi read[vol] address volume [size] - Read volume to address with size
  17. ubi remove[vol] volume - Remove volume
  18. [Legends]
  19. volume: character name
  20. size: specified in bytes
  21. type: s[tatic] or d[ynamic] (default=dynamic)
  22. The first command that is needed to be issues is "ubi part" to connect
  23. one mtd partition to the UBI subsystem. This command will either create
  24. a new UBI device on the requested MTD partition. Or it will attach a
  25. previously created UBI device. The other UBI commands will only work
  26. when such a UBI device is attached (via "ubi part"). Here an example:
  27. => mtdparts
  28. device nor0 <1fc000000.nor_flash>, # parts = 6
  29. #: name size offset mask_flags
  30. 0: kernel 0x00200000 0x00000000 0
  31. 1: dtb 0x00040000 0x00200000 0
  32. 2: root 0x00200000 0x00240000 0
  33. 3: user 0x01ac0000 0x00440000 0
  34. 4: env 0x00080000 0x01f00000 0
  35. 5: u-boot 0x00080000 0x01f80000 0
  36. active partition: nor0,0 - (kernel) 0x00200000 @ 0x00000000
  37. defaults:
  38. mtdids : nor0=1fc000000.nor_flash
  39. mtdparts: mtdparts=1fc000000.nor_flash:2m(kernel),256k(dtb),2m(root),27392k(user),512k(env),512k(u-boot)
  40. => ubi part root
  41. Creating 1 MTD partitions on "nor0":
  42. 0x000000240000-0x000000440000 : "mtd=2"
  43. UBI: attaching mtd1 to ubi0
  44. UBI: physical eraseblock size: 262144 bytes (256 KiB)
  45. UBI: logical eraseblock size: 262016 bytes
  46. UBI: smallest flash I/O unit: 1
  47. UBI: VID header offset: 64 (aligned 64)
  48. UBI: data offset: 128
  49. UBI: attached mtd1 to ubi0
  50. UBI: MTD device name: "mtd=2"
  51. UBI: MTD device size: 2 MiB
  52. UBI: number of good PEBs: 8
  53. UBI: number of bad PEBs: 0
  54. UBI: max. allowed volumes: 128
  55. UBI: wear-leveling threshold: 4096
  56. UBI: number of internal volumes: 1
  57. UBI: number of user volumes: 1
  58. UBI: available PEBs: 0
  59. UBI: total number of reserved PEBs: 8
  60. UBI: number of PEBs reserved for bad PEB handling: 0
  61. UBI: max/mean erase counter: 2/1
  62. Now that the UBI device is attached, this device can be modified
  63. using the following commands:
  64. ubi info Display volume and ubi layout information
  65. ubi createvol Create UBI volume on UBI device
  66. ubi removevol Remove UBI volume from UBI device
  67. ubi read Read data from UBI volume to memory
  68. ubi write Write data from memory to UBI volume
  69. ubi write.part Write data from memory to UBI volume, in parts
  70. Here a few examples on the usage:
  71. => ubi create testvol
  72. Creating dynamic volume testvol of size 1048064
  73. => ubi info l
  74. UBI: volume information dump:
  75. UBI: vol_id 0
  76. UBI: reserved_pebs 4
  77. UBI: alignment 1
  78. UBI: data_pad 0
  79. UBI: vol_type 3
  80. UBI: name_len 7
  81. UBI: usable_leb_size 262016
  82. UBI: used_ebs 4
  83. UBI: used_bytes 1048064
  84. UBI: last_eb_bytes 262016
  85. UBI: corrupted 0
  86. UBI: upd_marker 0
  87. UBI: name testvol
  88. UBI: volume information dump:
  89. UBI: vol_id 2147479551
  90. UBI: reserved_pebs 2
  91. UBI: alignment 1
  92. UBI: data_pad 0
  93. UBI: vol_type 3
  94. UBI: name_len 13
  95. UBI: usable_leb_size 262016
  96. UBI: used_ebs 2
  97. UBI: used_bytes 524032
  98. UBI: last_eb_bytes 2
  99. UBI: corrupted 0
  100. UBI: upd_marker 0
  101. UBI: name layout volume
  102. => ubi info
  103. UBI: MTD device name: "mtd=2"
  104. UBI: MTD device size: 2 MiB
  105. UBI: physical eraseblock size: 262144 bytes (256 KiB)
  106. UBI: logical eraseblock size: 262016 bytes
  107. UBI: number of good PEBs: 8
  108. UBI: number of bad PEBs: 0
  109. UBI: smallest flash I/O unit: 1
  110. UBI: VID header offset: 64 (aligned 64)
  111. UBI: data offset: 128
  112. UBI: max. allowed volumes: 128
  113. UBI: wear-leveling threshold: 4096
  114. UBI: number of internal volumes: 1
  115. UBI: number of user volumes: 1
  116. UBI: available PEBs: 0
  117. UBI: total number of reserved PEBs: 8
  118. UBI: number of PEBs reserved for bad PEB handling: 0
  119. UBI: max/mean erase counter: 4/1
  120. => ubi write 800000 testvol 80000
  121. Volume "testvol" found at volume id 0
  122. => ubi read 900000 testvol 80000
  123. Volume testvol found at volume id 0
  124. read 524288 bytes from volume 0 to 900000(buf address)
  125. => cmp.b 800000 900000 80000
  126. Total of 524288 bytes were the same
  127. Next, the ubifsmount command allows you to access filesystems on the
  128. UBI partition which has been attached with the ubi part command:
  129. => help ubifsmount
  130. ubifsmount - mount UBIFS volume
  131. Usage:
  132. ubifsmount <volume-name>
  133. - mount 'volume-name' volume
  134. For example:
  135. => ubifsmount ubi0:recovery
  136. UBIFS: mounted UBI device 0, volume 0, name "recovery"
  137. UBIFS: mounted read-only
  138. UBIFS: file system size: 46473216 bytes (45384 KiB, 44 MiB, 366 LEBs)
  139. UBIFS: journal size: 6348800 bytes (6200 KiB, 6 MiB, 50 LEBs)
  140. UBIFS: media format: w4/r0 (latest is w4/r0)
  141. UBIFS: default compressor: LZO
  142. UBIFS: reserved for root: 0 bytes (0 KiB)
  143. Note that unlike Linux, U-Boot can only have one active UBI partition
  144. at a time, which can be referred to as ubi0, and must be supplied along
  145. with the name of the filesystem you are mounting.
  146. Once a UBI filesystem has been mounted, the ubifsls command allows you
  147. to list the contents of a directory in the filesystem:
  148. => help ubifsls
  149. ubifsls - list files in a directory
  150. Usage:
  151. ubifsls [directory]
  152. - list files in a 'directory' (default '/')
  153. For example:
  154. => ubifsls
  155. 17442 Thu Jan 01 02:57:38 1970 imx28-evk.dtb
  156. 2998146 Thu Jan 01 02:57:43 1970 zImage
  157. And the ubifsload command allows you to load a file from a UBI
  158. filesystem:
  159. => help ubifsload
  160. ubifsload - load file from an UBIFS filesystem
  161. Usage:
  162. ubifsload <addr> <filename> [bytes]
  163. - load file 'filename' to address 'addr'
  164. For example:
  165. => ubifsload ${loadaddr} zImage
  166. Loading file 'zImage' to addr 0x42000000 with size 2998146 (0x002dbf82)...
  167. Done
  168. Finally, you can unmount the UBI filesystem with the ubifsumount
  169. command:
  170. => help ubifsumount
  171. ubifsumount - unmount UBIFS volume
  172. Usage:
  173. ubifsumount - unmount current volume
  174. For example:
  175. => ubifsumount
  176. Unmounting UBIFS volume recovery!
  177. Usage of the UBI CRC skip-check flag of static volumes:
  178. -------------------------------------------------------
  179. Some users of static UBI volumes implement their own integrity check,
  180. thus making the volume CRC check done at open time useless. For
  181. instance, this is the case when one use the ubiblock + dm-verity +
  182. squashfs combination, where dm-verity already checks integrity of the
  183. block device but this time at the block granularity instead of verifying
  184. the whole volume.
  185. Skipping this test drastically improves the boot-time.
  186. U-Boot now supports the "skip_check" flag to optionally skip the CRC
  187. check at open time.
  188. Usage: Case A - Upon UBI volume creation:
  189. You can optionally add "--skipcheck" to the "ubi create" command:
  190. ubi create[vol] volume [size] [type] [id] [--skipcheck]
  191. - create volume name with size ('-' for maximum available size)
  192. Usage: Case B - With an already existing UBI volume:
  193. Use the "ubi skipcheck" command:
  194. ubi skipcheck volume on/off - Set or clear skip_check flag in volume header
  195. Example:
  196. => ubi skipcheck rootfs0 on
  197. Setting skip_check on volume rootfs0
  198. BTW: This saves approx. 10 seconds Linux bootup time on a MT7688 based
  199. target with 128MiB of SPI NAND.