天天看點

linux核心mtd分區,linux-kernel – 在運作時調整MTD分區大小

我正在使用嵌入式裝置,并希望能夠通過

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

我嘗試聯系該更新檔的作者,但他們的電子郵件不再有效,是以我将不勝感激任何建議!

更新:

似乎mtdchar.c中的mtd_open()觸發了get_mtd_device(),這可能會占用額外的usecount增量.但我的使用者空間應用程式需要調用分區上的open()來發送一個ioctl()來删除分區:/ catch 22?有沒有更正确的方法呢?