Skip to contentSkip to conversation

fix for mtd partitions for erase_size != 2^X

PATCH In review Peter Menzebach 2 participants 5 messages Sep 23, 2005 – Oct 3, 2005 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix for mtd partitions for erase_size != 2^X

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.

mtd/mtdpart.c 2005-09-23 09:29:37.000000000 +0200 renamed from mtd/mtdpart.c.orig 2005-09-23 09:28:07.000000000 +0200 +3 -3
@@ -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);
#1 lore raw
Quoted 10 lines · Peter Menzebach

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.

Quoted 15 lines
mtd/mtdpart.c 2005-09-23 09:29:37.000000000 +0200 renamed from mtd/mtdpart.c.orig 2005-09-23 09:28:07.000000000 +0200 +3 -3
@@ -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,
Quoted 1 line
                        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

Signature · 4 lines
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..."
#2 lore raw
Quoted 7 lines · Jörn Engel

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

Are you sure, this is not as complicated as my version ;) ? But if you like it, no problem.

Shall I resubmit the patch?

Is there any known good way to submit a patch here? I have two mailer here, but the mailing list refuses both (as attachment and inline attachment).

Best regards
Peter

Signature · 3 lines
Peter Menzebach
Menzebach und Wolff IT-Consulting GbR
Phone +49 751 355 387 1
#3 lore raw
In reply to Jörn Engel
Quoted 49 lines · Jörn Engel
Quoted 9 lines · Peter Menzebach

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.

Quoted 15 lines
mtd/mtdpart.c 2005-09-23 09:29:37.000000000 +0200 renamed from mtd/mtdpart.c.orig 2005-09-23 09:28:07.000000000 +0200 +3 -3
@@ -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,
Quoted 1 line
                       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) {
mtd/mtdpart.c 2005-09-23 09:29:37.000000000 +0200 renamed from mtd/mtdpart.c.orig 2005-09-23 09:28:07.000000000 +0200 +1 -2
-            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,
Quoted 7 lines

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

Here the patch again. As the macro does not seem to reduce the complexity of the line seriously and would be used only once, I did put in a comment, which explains inline, what should go on there.

The patch now as link:
http://www.mw-itcon.de/patches/patch.dataflash.mtdpart.c

Best regards
Peter

Signature · 3 lines
Peter Menzebach
Menzebach und Wolff IT-Consulting GbR
Phone +49 751 355 387 1
#4 lore raw
Quoted 4 lines · Peter Menzebach
Quoted 1 line

Here the patch again. As the macro does not seem to reduce the complexity of the line seriously and would be used only once, I did put in a comment, which explains inline, what should go on there.

All right. I still don't like it, but since I don't have any better idea...

Jörn

Signature · 3 lines
Das Aufregende am Schreiben ist es, eine Ordnung zu schaffen, wo
vorher keine existiert hat.
-- Doris Lessing