https://www.sfgate.com/politics/article/california-prop-is-historically-unpopular-17581600.php
Good old economically liberal, socially conservative Calif*.
How to mount an UBI image, edit it & save a new UBI image.
UBI/UBIFS is the goofiest file system lions have encountered. There's a method for animals who want to extract an UBI image from a device, edit it, & write it back to the device.
The journey begins with kernel modules.
Device Drivers -> Memory Technology Device (MTD) support -> Enable UBI - Unsorted block images
Device Drivers -> Memory Technology Device (MTD) support -> NAND Device Support -> Support for NAND Flash Simulator
File systems -> Miscellaneous filesystems -> UBIFS file system support
The internet has notes about an mtdnand/Test driver using RAM device. This doesn't work. Only the nandsim/NAND Flash Simulator driver works.
So you've already extracted your .ubi image using fastboot, EDL, dd or something. You must now determine its size in eraseblocks. Divide the .ubi size in bytes by the eraseblock size 131072. The size in eraseblocks is given to the nandsim module. This is the only way to get back the .ubi image after editing it.
Animals who don't want to recompile all their 3rd party modules keep all their newly compiled modules in the build tree instead of using modules_install.
insmod /usr/src/linux-4.9.39/drivers/mtd/mtd.ko
insmod /usr/src/linux-4.9.39/drivers/mtd/nand/nand_ids.ko
insmod /usr/src/linux-4.9.39/drivers/mtd/nand/nand_ecc.ko
insmod /usr/src/linux-4.9.39/drivers/mtd/nand/nand.ko
insmod /usr/src/linux-4.9.39/drivers/mtd/nand/nandsim.ko parts=SIZE IN ERASEBLOCKS first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15
insmod /usr/src/linux-4.9.39/drivers/mtd/ubi/ubi.ko mtd=0
insmod /usr/src/linux-4.9.39/fs/ubifs/ubifs.ko
To verify the size of the mtd device in bytes,
cat /proc/mtd
To change the size of the nandsim, the unloading before the reloading is equally gnarly.
rmmod ubifs
rmmod ubi
rmmod nandsim
rmmod nand
rmmod nand_ids
rmmod nand_ecc
rmmod mtdram
rmmod mtd
Then, we begin to mount the .ubi image.
mkdir /ubi
ubidetach -p /dev/mtd0
This copies the UBI image to the simulated flash device. It usually has a lot of warnings & confirmation prompts.
ubiformat /dev/mtd0 -O 2048 -f ${UBI FILE}
This creates a UBI device on top of the simulated flash device.
ubiattach -O 2048 -p /dev/mtd0
This mounts the UBI device.
mount -t ubifs ubi0 /ubi
Once finished editing, you can get a new .ubi file suitable for writing with fastboot. Using the dd command to truncate the size of the mtd device doesn't work. You must extract the entire mtd device.
umount /ubi
cat /dev/mtd0 > output.ubi
Of course, the alternative to customizing the size of nandsim is creating a new UBIFS from the mounted directory tree, but it's just about as laborious.
It's all a bit pedantic to have a RAM copy of an image in a simulated flash device in an UBI device in a filesystem driver instead of just mounting the image with the filesystem driver like we used to do. Maybe it would have meant replicating a lot of code in the filesystem driver to make it access images of flash devices.
Comments
Post a Comment