在运行时调整MTD分区的大小

mik*_*ail 5 partitioning linux-kernel embedded-linux

我正在使用嵌入式设备,希望使它们能够通过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
Run Code Online (Sandbox Code Playgroud)

几年前,我找到了一个提议的“ 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
Run Code Online (Sandbox Code Playgroud)

以此为指导,我能够编写内核和用户空间代码来创建一个新的MTD分区,可以在其上安装JFFS2。但是,此代码不能正确删除分区。即使从mtd1卸载JFFS2并调用后put_mtd_device,当del_mtd_device被调用时,内核也会抱怨:

user.notice kernel: Removing MTD device #1 (jffs2) with use count 1 
Run Code Online (Sandbox Code Playgroud)

我想知道的是:

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
Run Code Online (Sandbox Code Playgroud)

我尝试与补丁作者联系,但他们的电子邮件不再有效,因此,我将不胜感激!


更新:

似乎mtd_open()mtdchar.c触发器中get_mtd_device(),这可能占了额外的usecount增量。但是我的用户空间应用程序需要调用open()该分区以将其发送给它ioctl()以删除分区:/ catch 22?有更正确的方法吗?

mik*_*ail 3

我最终解决了这个问题,方法是让我的修补后的 mtd 实用程序增加“mtd0”大小,然后创建一个正确减小大小的全新分区来安装 JFFS,这使我有机会将配置信息复制到新的闪存位置。

为了降低复杂性,我还做到了这一点,这样我就不能多次运行这个应用程序。它最终成为“运行一次,做你的事情,重新启动”类型的过程。


更新:

这是我的代码,认为它可以使一些人受益:

https://github.com/mikzat/mtd_runtime_partition