1. Configure ubi and ubifs
In. config
Config_mtd_ubi = y
Config_ubifs_fs = y
Config_crypto_algapi = y config_crypto_deflate = y config_crypto_lzo = y config_crc16 = y config_lzo_compress = y config_lzo_decompress = y
Note::If it is configured as a module (=M), You can manually Load
2. Manual attach/detach UBI to MTD
./Ubiattach/Dev/Ubi_ctrl-MMtdnumber
./Ubidetaach/Dev/Ubi_ctrl-MMtdnumber
3. Manual create ubi volume
./Ubimkvol/Dev/Ubi_device_number-s size-N name
Like:
./Ubimkvol/Dev/Ubi0-s 300mib-N ubifs1
4. Mount ubifs volume
Mount-T ubifs ubi0:Ubifs1/tmp/ubifs1
5. ubi node and ubi_ctrl Node
# Cat/sys/class/MISC/Ubi_ctrl/Dev
10:63
Join/DevNoUbi_ctrlThen we can sudo mknodUbi_ctrlC 10 63 create an endpoint
#./Ubiattach/Dev/Ubi_ctrl-M6
# Cat/sys/class/ubi/ubi0/Dev
252:0
After attach ubi0 to mtd6, if/DevIf there is no ubi0, create one. sudo mknod ubi0 C 252 0
6. You can manually create volume, manually Mount ubifs, or create ubi. IMG (create volume, Volume write data) on the PC to burn it into MTD device.
How to generate ubi image and write to MTD Device
./Mkfs. ubifs-r a205_rootdisk-M 4096-e 516096-C40-O ubifs. img
./Ubinize-O ubi. IMG-M 4096-P 512kib ubinize. cfg
./Ubiformat-Q/Dev/Mtd5-F ubi. img
-MMinimum I/O unit size
-E maximum logical erase block count
-C maximum logical erase block count
-X compression type-"lzo", "favor_lzo", "zlib" or "NONE" (default:"Lzo ")
-P size of the physical eraseblock of the flash this ubi image is created for in bytes,
Note::When mkfs. ubifs and ubinize are used in Ubuntu on a PC, We need to compile them with normal GCC and install the lzo library on Ubuntu.:Sudo apt-Get install liblzo2-Dev
Appendix:
1). ubinize. cfg
[Ubifs]
Mode = ubi
Image = ubifs. img
Vol_id = 0
Vol_size = 500mib
Vol_type = dynamic // If vol_type = static, then ubi volume is read only
Vol_name = ubifs0
Vol_flags = autoresize
In this case, when ./Ubiattach/Dev/Ubi_ctrl-MAfter N, you can mount-T ubifs ubi0:Ubifs0/tmp
2) If you want to mount the crafms image
./Ubinize-O ubi. IMG-M 4096-P 512kib ubinize. cfg
./Ubiformat-Q/Dev/Mtd5-F ubi. img
Ubinize. cfg
[Ubifs]
Mode = ubi
Image = cramfs. img
Vol_id = 0
Vol_size = 500mib
Vol_type = dynamic
Vol_name = cramfs
Vol_flags = autoresize
In this way, when ./Ubiattach/Dev/Ubi_ctrl-MAfter N, we can see a MTD device in the CAT/proc/MTD simulation of ubi volume. We only need to mount the mtdblock corresponding to the MTD device (such as Mount-T cramfs/Dev/Mtdblock10/tmp). Note that since cramfs is burned to ubi volume, we can only mount this volume in cramfs mode, and we cannot mount this volume in ubifs mode (Mount-T ubifs ubi0:Cramfs/tmp) mount this volume. But if we use./ubiupdate/Dev/Ubi0_0-T wipe out after cleaning this volume, we can mount this volume in ubifs mode, but mount this volume and enter the Mount directory. Nothing is available.
3) ubinize. cfg of three volume (note that the names in [] cannot be the same, vol_id cannot be the same, vol_name cannot be the same, and vol_flags = auto_resize can only be used on one volume)
[Ubifs1]
Mode = ubi
Image = ubifs. img
Vol_id = 0
Vol_size = 20mib
Vol_type = dynamic
Vol_name = ubifs0
Vol_alignment = 1
[Cramfs1]
Mode = ubi
Image = smallroot. cramfs
Vol_id = 1
Vol_size = 20mib
Vol_type = dynamic
Vol_name = cramfs
Vol_alignment = 1
[Cramfs2]
Mode = ubi
Image = qtroot. cramfs
Vol_id = 2
Vol_size = 50mib
Vol_type = dynamic
Vol_name = cramfs2
Vol_alignment = 1
Vol_flags = autoresize
In this way, when ubi. IMG is written using./ubiformat ./UbiattachThen, we can know three more fake MTD devices.
The first one can use Mount-T ubifs ubi0:Ubifs0/tmp/ubifs1
The second one can use Mount-T cramfs/Dev/Mtdblockn/tmp/cramfs1
The second one can use Mount-T cramfs/Dev/Mtdblockm/tmp/cramfs2
7. How to disable compression?
Ubifs compression may be disabled for whole file system during the image creation time using the "-x none" mkfs. ubifs option. however, if ubifs compression is enabled, it may be disabled for individual files by cleaning the inode compression flag:
$ Chattr-C/mnt/ubifs/File
In shell, or
IOCTL (FD, fs_ioc_getflags, & flags );
Flags & = ~ Fs_compr_fl;
IOCTL (FD, fs_ioc_setflags, & flags );
In C Programs. similarly, if compression is disabled by default, you may enable if for individual inodes by setting the compression flag. note, the code which uses the compression flag works fine on other Linux File-systems, because the flag is just ignored in this case.
It might be a good idea to disable compression for say, MP3 or JPEG files which wocould anyway not compress and ubifs wocould just waste CPU time trying to compress them. the compression may also be disabled if one wants faster file I/O, because ubifs wocould not need to compress or decompress the data on reads and write. however, I/O speed may actually become slower if compression is disabled. indeed, in case of a very fast CPU and very slow flash compressed writes are faster, but this is usually not true for embedded systems.
8. Mount cramfs on ubi volume
UBI volume is fake MTD device.
# Cat/proc/MTD
Dev:Size erasesize name
Mtd0:180000 00080000 "bootloader"
Mtd1: 400000 00080000 "kernel 0"
Mtd2: 400000 00080000 "kernel 1"
Mtd3:80000 00080000 "boot up screen"
MTD4:A0000000080000 "rescue File System"
Mtd5:1400000 00080000 "root file system"
Mtd6:3e80000000080000 "Data area1"
Mtd7:3e80000000080000 "Data area2"
Mtd8:6a400000 00080000 "Data area3"
Mtd9:16380000 00080000 "reserve"
#./Ubiattach/Dev/Ubi_ctrl-M6
#./Ubimkvol/Dev/Ubi0-s 300mib-N ubifs1
# Cat/proc/MTD
Dev:Size erasesize name
Mtd0:180000 00080000 "bootloader"
Mtd1: 400000 00080000 "kernel 0"
Mtd2: 400000 00080000 "kernel 1"
Mtd3:80000 00080000 "boot up screen"
MTD4:A0000000080000 "rescue File System"
Mtd5:1400000 00080000 "root file system"
Mtd6:3e80000000080000 "Data area1"
Mtd7:3e80000000080000 "Data area2"
Mtd8:6a400000 00080000 "Data area3"
Mtd9:16380000 00080000 "reserve"
Mtd10:12c3c000 0007e000 "ubifs1"
# Cp cramfs. img/Dev/Mtdblock10
# Mount-T cramfs/Dev/Mtdblock6/tmp
After create fake MTD device (UBI volume), Mount jffs2
# Mount-T jffs2/Dev/Mtdblock10/mnt
9. ubiupdatevol/dev/ubi0_0-T // wipe out volume
Ubiupdatevol/Dev/Ubi0_0 fs. IMG // write image to volume
./Ubiupdatevol/Dev/Ubi0_0 ubifs. IMG // after which we can mount ubifs:Mount-T ubifs ubi0:Ubifs0/tmp to mount this ubifs
./Ubiupdatevol/Dev/Ubi0_1 smallroot. cramfs // then we can mount-T cramfs/Dev/Mtdblockn/tmp to mount this cramfs
10. Mount vfat
1) Create vfat. IMG (made on PC)
$ Dd If =/Dev/Zero of = vfat. img bs = 1MCount = 20
# Losetup/Dev/Loop0 vfat. img
# Mkfs. vfat/Dev/Loop0
Note::There is a warnning, but ignore it.:Loop device does not match a floppy size, using default HD Params
# Mount-T vfat/Dev/Loop0 vfat_mount_point
Write something to the vfat_mount_point directory, or copy something to this directory
# Umount vfat_mount_point
# Losetup-D/Dev/Loop0
2) use ubinize to package it into ubi. IMG, and then use ubiformat to write it into MTD devie. Method 2: Use ubiupdatevol to wipe out volume first, and then use ubiupdatevol to convert vfat. img
Write volume.
Note::Because emulate MTD device does not support write operations, I mount-T/Dev/Mtdblockn, which is an MTD Device of ubi volume emuluate,
Therefore, Mount vfat can only be read, and writes cannot be saved. (Write can be completed in the test, and LS can be seen, but after sync, restart the unit and re-mount it to see that the written data is not saved, such as vfat)
11. ubifs (read/write/Attach/mount) speed,
Wrtie speed ------------------- speed = 1.66M/S
# Time dd If =/Dev/Zero of =/tmp/ubifs1/zero100MBS = 1MCount = 100; time sync
100 + 0 records in
100 + 0 records out
Real 0M59.13 s
User 0M0.00 s
Sys 0M 4. 62 s
Real 0M1.11 s
User 0M0.00 s
Sys 0M0.74S
Read Speed ----------------------- speed = 2.27M/S
# Time CP ubifs1/zero100M/Dev/NULL; time sync
S3c-nand:1 bit (s)ErrorDetected, corrected successfully
S3c-nand:1 bit (s)ErrorDetected, corrected successfully
S3c-nand:1 bit (s)ErrorDetected, corrected successfully
Real 0M 44. 06 s
User 0M0.14S
Sys 0M 42.67 s
Real 0M0.06 s
User 0M0.00 s
Sys 0M0.01 s
12. Configure ubifs as rootfs
In. config:
Config_cmdline = "console = ttysac0 ubi. MTD = 5 root = ubi0:Rootfs rootfstype = ubifs"
Then if we had wrote root FS ubi image to mtd5, then we can boot up with ubi root FS.
13. RW filesystem change to read only filesystem
#./Ubiattach/dev/ubi_ctrl-M 6
UBI:Attaching mtd6 to ubi0
UBI:Physical eraseblock size:524288 bytes (512 kib)
UBI:Logical eraseblock size:516096 bytes
UBI:Smallest flash I/O Unit:4096
UBI:Vid header offset:4096 (aligned4096)
UBI:Data offset:8192
Peb 0 is bad
Peb 32 is bad
UBI:Attached mtd6 to ubi0
UBI:MTD device name:"Data area1"
UBI:MTD device size:1000 MIB
UBI:Number of good pebs:1998
UBI:Number of bad pebs:2
UBI:Max. Allowed volumes:128
UBI:Wear-leveling threshold:4096
UBI:Number of internal volumes:1
UBI:Number of user volumes:3
UBI:Available pebs:0
UBI:Total number of reserved pebs:1998
UBI:Number of pebs reserved for bad peb handling:19
UBI:Max/mean erase counter:7/0
UBI:Background thread "ubi_bgt0d" started, PID 940
./Ubiupdatevol/Dev/Ubi0_0-T
UBIError:Ubi_io_write: Error-5 while writing4096 bytes to peb 21:4096, written 0 bytes
UBI warning:Ubi_eba_write_leb:Failed to write vid header to LEB 2147479551:0, peb 21
UBI:Try another peb
UBIError:Ubi_io_write: Error-5 while writing4096 bytes to peb 12:4096, written 0 bytes
UBI warning:Ubi_eba_write_leb:Failed to write vid header to LEB 2147479551:0, peb 12
UBI:Try another peb
UBIError:Ubi_io_write: Error-5 while writing4096 bytes to peb 1999:4096, written 0 bytes
UBI warning:Ubi_eba_write_leb:Failed to write vid header to LEB 2147479551:0. peb 1999
UBI:Try another peb
UBIError:Ubi_io_write: Error-5 while writing 24576 bytes to peb 1998:8192, written 0 bytes
UBI warning:Ubi_eba_write_leb:Failed to write 24576 bytes at offset 0 of Leb 2147479551:0. peb 1998
UBI warning:Ubi_ro_mode:Switch to read-only mode
UBIError:Ubi_io_write:Read-only mode
UBIError:Erase_worker:Failed to erase peb 7,Error-30
UBIError:Do_work:Work failedErrorCode-30
UBIError:Ubi_thread:Ubi_bgt0d:Work failedErrorCode-30
Ubiupdatevol: Error!:Cannot truncate volume "/Dev/Ubi0_0"
Error30 (read-only file system)
UBI warning:Vol_cdev_release:Update of volume 0 not finished, volume is damaged
When this problem occurs, flash_eraseall/Dev/Mt6 or/Dev/After mtd7, write the image/Dev/Mtd7 or/Dev/Mtd6 errors
./Ubiformat-Q/Dev/Mtd6-F ubi. img.20M_ None
Libmtd: Error!:Cannot Write 32768 bytes to mtd6 (eraseblock 1, offset 0)
Error5 (input/outputError)
Ubiformat: Error!:Cannot Write eraseblock 1
Error5 (input/outputError)
After this problem occurs, I run
Nand erase:Device 0 offset 0x600000, size 0x400000
RET:0 erase. ADDR:600000
Erasing at 0x600000 -- 12% complete. Ret:0 erase. ADDR:680000
Erasing at 0x680000 -- 25% complete. Ret:0 erase. ADDR:700000
Erasing at 0x700000 -- 37% complete. Ret:0 erase. ADDR:780000
Erasing at 0x780000 -- 50% complete. Ret:0 erase. ADDR:800000
Erasing at 0x800000 -- 62% complete. Ret:0 erase. ADDR:880000
Erasing at 0x880000 -- 75% complete. Ret:0 erase. ADDR:900000
Erasing at 0x900000 -- 87% complete. Ret:0 erase. ADDR:980000
Erasing at 0x980000 -- 100% complete.
OK
Smdk2450 # NAND write c0000000 600000 300000
Nand write:Device 0 offset 0x600000, size 0x300000
0 bytes written: Error
Finally, I used the pen tip fine tine NAND Flash pin (especially/We) and finally saved the flash.
Conclusion:It seems that the flash has been damaged, or the PIN is not in good contact-Because erase is OK, And the NAND read is also OK, the file cannot be written to peb.
Ubifs is read-only.
14. mkfs. ubifs-C Issus (note that fat directory is empty)
Dannylo @ fs1:~ /Cram2fs_tools $./mkfs. ubifs-r fat-M 4096-e 516096-C 10-O test. img
Error:Too low Max. Count of lebs, minimum is 17
Dannylo @ fs1:~ /Cram2fs_tools $./mkfs. ubifs-r fat-M 4096-e 516096-C 19-O test. img
Error:Too commit log lebs, maximum is 2
Dannylo @ fs1:~ /Cram2fs_tools $./mkfs. ubifs-r fat-M 4096-e 516096-C 21-O test. img
Error:Too commit log lebs, maximum is4
Dannylo @ fs1:~ /Cram2fs_tools $./mkfs. ubifs-r fat-M 4096-e 516096-C 22-O test. img
Conclusion:That is, the minimum ubifs. IMG is 11.M. Note that there is no requirement for the size of the cramfs or cram2fs format image to be burned into volume.
15. ubi face bad block
We used NAND markbad in uboot to try mark bad block (the first block in MTD device, the middle block, and the last block). The testing surface can be recognized by UBI scan during attach.
Bad Block NAND skip bad block. When ubiformat is used to burn ubi. IMG, the bad block is automatically skipped.