[PATCH] fix for mtd partitions for erase_size != 2^X
Jörn Engel
joern at wohnheim.fh-wedel.de
Sun Sep 25 09:16:30 EDT 2005
On Fri, 23 September 2005 20:02:42 +0200, Peter Menzebach wrote:
>
> Here a trivial patch,
> which allows correct creation of mtd partitions, which have erase sizes
> which are not a power of 2.
>
> Best regards
> Peter
>
> Sorry, I didn't succeed to get the patch accepted by the mailing list as
> attachment.
I actually prefer inline. Except that your mailer seems to have
messed things up - grr.
> --- drivers/mtd/mtdpart.c.orig 2005-09-23 09:28:07.000000000 +0200
> +++ drivers/mtd/mtdpart.c 2005-09-23 09:29:37.000000000 +0200
> @@ -465,9 +465,9 @@
> if (slave->offset == MTDPART_OFS_APPEND)
> slave->offset = cur_offset;
> if (slave->offset == MTDPART_OFS_NXTBLK) {
> - u_int32_t emask = master->erasesize-1;
> - slave->offset = (cur_offset + emask) & ~emask;
> - if (slave->offset != cur_offset) {
> + slave->offset = cur_offset;
> + if ((cur_offset % master->erasesize) != 0) {
> + slave->offset = ((cur_offset / master->erasesize) + 1)
> * master->erasesize;
> printk(KERN_NOTICE "Moving partition %d: "
> "0x%08x -> 0x%08x\n", i,
> cur_offset, slave->offset);
Looks complicated. I guess we could use the equivalent of this:
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
in some header. Then your patch would be as simple as
if (slave->offset == MTDPART_OFS_APPEND)
slave->offset = cur_offset;
if (slave->offset == MTDPART_OFS_NXTBLK) {
- u_int32_t emask = master->erasesize-1;
- slave->offset = (cur_offset + emask) & ~emask;
+ slave->offset = TRUE_ALIGN(cur_offset, master->erasesize);
if (slave->offset != cur_offset) {
printk(KERN_NOTICE "Moving partition %d: "
"0x%08x -> 0x%08x\n", i,
Maybe this:
#define TRUE_ALIGN(x,a) (((x)+(a)-1) - ((x)+(a)-1) % a)
The macro is still complicated, but we just have to get it right once.
Jörn
--
Public Domain - Free as in Beer
General Public - Free as in Speech
BSD License - Free as in Enterprise
Shared Source - Free as in "Work will make you..."
More information about the linux-mtd
mailing list