在运行时调整MTD分区的大小 [英] Resize MTD partitions at runtime

查看:609
本文介绍了在运行时调整MTD分区的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用嵌入式设备,希望使它们能够通过Linux调整MTD分区的大小而无需重新启动.

I am working with embedded devices and would like to enable them to resize their MTD partitions via Linux without rebooting.

问题是我的Linux映像大小增加了,并且它所在的当前MTD分区(mtd0)现在太小了.但是,紧随其后的分区(mtd1)是一个JFFS2节,用于存储配置信息,因此不能选择通过重新引导来调整大小,因为配置可能会丢失.

The problem is that my Linux image size has increased and the current MTD partition (mtd0) in which it resides is now too small. However, the partition right after it (mtd1) is a JFFS2 section used for storing config information, so resizing with a reboot is not an option because the config could be lost.

我的目标是:

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"补丁:

I found a proposed patch to "mtd-utils" from a couple years back:

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时内核仍会抱怨:

Using this as a guide I was able to write kernel and user-space code to create a new MTD partition on which I can mount JFFS2. However, this code does not properly delete partitions. Even after unmounting JFFS2 from mtd1 and calling put_mtd_device, when del_mtd_device is called the kernel complains:

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

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

I tried contacting the author of the patch, but their email is no longer valid, so I would appreciate any suggestions!


更新:

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

It seems that mtd_open() in mtdchar.c triggers a get_mtd_device(), which probably accounts for the extra usecount increment. But my userspace app needs to call open() on the partition to send it an ioctl() for deleting a partition :/ catch 22? Is there a more correct way of doing this?

推荐答案

我最终解决了此问题,方法是使修补的mtd实用程序增加"mtd0"的大小,然后创建正确减小大小的全新分区,以在其上安装JFFS ,这使我有机会将配置信息复制到新的Flash位置.

I ended up solving this issue by having my patched mtd utility increase "mtd0" size, then create a brand new partition of the correct reduced size to mount JFFS on, which gave me a chance to copy the config info into the new flash location.

为了降低复杂性,我也做到了,所以我不能多次运行此应用程序.最终变成了运行一次,执行您的操作,重新启动"类型的程序.

To reduce complexity, I also made it so I couldn't run this app more than once. It ended up being a "run once, do your thing, reboot" type of procedure.

更新:

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

Here's my code, figured it could benefit some folks:

https://github.com/mikzat/mtd_runtime_partition

这篇关于在运行时调整MTD分区的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆