I work with embedded devices and want them to be able to resize their MTD partitions via Linux without rebooting.
The problem is that the size of my Linux image has increased, and the current MTD (mtd0) partition it is in is now too small. However, the section immediately after it (mtd1) is the JFFS2 section used to store configuration information, so resizing with a reboot is not an option, as the configuration may be lost.
My goal is this:
1. Copy contents of JFFS2 into /tmp/ 2. Unmount JFFS2 from mtd1 3. Increase the starting offset + reduce size of mtd1 by X bytes (or delete mtd1 and create new mtd of proper size and offset) 4. Mount JFFS2 on new mtd1 and restore contents from /tmp/ 5. Increase the size of mtd0 by X bytes 6. Burn new (larger) Linux image into mtd0 (the new image will contain a device tree with an updated partition structure) 7. Reboot
I found the proposed mtd-utils patch from a couple of years ago:
http://article.gmane.org/gmane.linux.drivers.mtd/30949 http://article.gmane.org/gmane.linux.drivers.mtd/30950 http://article.gmane.org/gmane.linux.drivers.mtd/30951
Using this as a guide, I was able to write kernel and user space code to create a new MTD partition on which I could install JFFS2. However, this code incorrectly deletes partitions. Even after unmounting JFFS2 from mtd1 and calling put_mtd_device
when del_mtd_device
is called the kernel, it complains:
user.notice kernel: Removing MTD device #1 (jffs2) with use count 1
What I would like to know:
1. How to fix the patch to allow deleting my old mtd1 2. How to change the starting offset of mtd1 instead of creating/deleting partitions
I tried to contact the author of the patch, but their email address is no longer valid, so I will be grateful for any suggestions!
UPDATE:It seems that mtd_open()
in mtdchar.c
runs a get_mtd_device()
, which probably explains the additional usecount
increment. But for my application in user space, I need to call open()
on the section to send it to ioctl()
to delete the section: / catch 22? Is there a better way to do this?