AW: how to change size of MTD partitions at runtime

Kuefmann Andreas ICM CP RD SD 1 andreas.kuefmann at siemens.com
Thu Sep 2 10:52:36 EDT 2004


Hi William,

thanks for your proposal. I'll give it a try.

The "partition table" is part of the bootloader's (U-Boot) environment.
So the first step would be to update the bootloader's environment
to reflect the new partition sizes.
Then I'd try to write the changes to the proc filesystem and hope
that there are no side effects when doing so.

thanks,
- Andy

-----Ursprüngliche Nachricht-----
Von: William J Beksi [mailto:wjbeksi at setabox.com] 
Gesendet: Mittwoch, 1. September 2004 17:35
An: Kuefmann Andreas ICM CP RD SD 1
Cc: 'linux-mtd at lists.infradead.org'
Betreff: Re: how to change size of MTD partitions at runtime


Hi,
Kuefmann Andreas ICM CP RD SD 1 wrote:

>Hi all,
>
>I'm searching for a solution to dynamically change the size of MTD 
>partitions at runtime.
>
>This functionality is required for a flash update of kernel and/or 
>rootfs in the special case that the new kernel/rootfs is larger than 
>the old one. (in an embedded environment)
>
>1.)
>there is no problem in erasing the flash, e.g eraseall /dev/mtd?, 
>(acting from a chrooted environment)
>
>2.)
>However, reprogramming the flash with a larger image (now exceeding the 
>limits of the previous partition) isn't as easy as a cp newimage.img 
>/dev/mtd?.
>
>The MTD layer will still rely on the (old) partition sizes that were 
>valid during system startup. (taken over from a U-BOOT environment)
>  
>
I'm using the proc filesytem to dynamically change the mtd partition 
sizes on my flash at runtime. I added a function to mtdcore.c that looks 
like this:
static int mtd_write_proc (struct file *filp, const char *buf, unsigned 
long count, void *data) 
{
    int value;
    struct mtd_info *this;
    unsigned long pos = (unsigned long)(filp->f_pos);
   
    down(&mtd_table_mutex);

    while (pos < count) {
       /* Get the partition number. */
       if (pos == 0) {
          value = antoi(buf, pos, count);
          this = mtd_table[value];
       }
       /* Change size of the partition (in Mb). */
       if (pos == 2) {
          value = antoi(buf, pos, count);
          this->size = value*1024*1024;
       }  
       pos++;
    }
    up(&mtd_table_mutex);
    return count;
}
The partition table values can be changed by writing the partition 
number and size (in megabytes) to /proc/mtd: echo 1 3 > /proc/mtd ||
||I'm not sure if this is the best way to dynamically change the
partition sizes at runtime, nor is it very safe.

>My question now is:
>- How can I manage to force a re-read of the partition table?
>
>
>  
>
Where do you keep your partition table? I'm using a cramfs filesystem 
and LinuxBIOS on nand flash. I reserve the first block of the flash to 
store a partition table, bad block list, and other information. I have a 
set of user space utilites for reading and writing the partition table.

--
William J Beksi

>______________________________________________________
>Linux MTD discussion mailing list
>http://lists.infradead.org/mailman/listinfo/linux-mtd/
>
>  
>





More information about the linux-mtd mailing list