我正在使用嵌入式设备,并希望使他们能够通过 Linux 调整其 MTD 分区的大小而无需重新启动。
问题是我的 Linux 映像大小增加了,并且它所在的当前 MTD 分区 (mtd0) 现在太小了。但是,紧随其后的分区 (mtd1) 是用于存储配置信息的 JFFS2 部分,因此不能通过重新启动来调整大小,因为配置可能会丢失。
我的目标是这样的:
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
几年前,我发现了“mtd-utils”的提议补丁:
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
以此为指导,我能够编写内核和用户空间代码来创建一个新的 MTD 分区,我可以在该分区上挂载 JFFS2。但是,此代码无法正确删除分区。即使从 mtd1 卸载 JFFS2 并调用put_mtd_device
,何时del_mtd_device
调用内核也会抱怨:
user.notice kernel: Removing MTD device #1 (jffs2) with use count 1
我想知道的是:
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
我尝试联系补丁的作者,但他们的电子邮件不再有效,所以我将不胜感激任何建议!
更新:
似乎mtd_open()
inmtdchar.c
触发了 a get_mtd_device()
,这可能是额外usecount
增量的原因。但是我的用户空间应用程序需要调用open()
分区来发送它ioctl()
来删除分区:/ catch 22? 有没有更正确的方法来做到这一点?