Skip to contentSkip to conversation

MTD with non-power-of-2 page size

DISCUSSION Dave Kitchen 3 participants 5 messages Aug 12, 2015 – Aug 19, 2015

lore
Share & tools
lore
#0 lore raw

I have just started to work with barebox on an Atmel at91sam9g45 processor.
The board has an Atmel AT45DB161 dataflash configured as 528-byte page size.
I find that eg saveenv command does not run as the page erase fails with EINVAL. On tracing this is fired from the page size and offset correction code [mtd/core,c mtd_erase_align()] which uses bit masking to align the size and offset. Unfortunately bit-masking does not work with non-power-of-2 pages. Has anyone else addressed this problem?

The 'trivial' exercise of replacing the bit masks by modulo [%] operator does not succeed as the compiler I am using (gcc!) does not support long-long divmod.

Regards
Dave Kitchen
InSync technology Ltd

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw
Quoted 9 lines · Dave Kitchen

I have just started to work with barebox on an Atmel at91sam9g45 processor. The board has an Atmel AT45DB161 dataflash configured as 528-byte page size. I find that eg saveenv command does not run as the page erase fails with EINVAL. On tracing this is fired from the page size and offset correction code [mtd/core,c mtd_erase_align()] which uses bit masking to align the size and offset. Unfortunately bit-masking does not work with non-power-of-2 pages. Has anyone else addressed this problem?

Yes, it's a bit of an annoying problem...

The easy solution (if you can spare the space) is to increase the partition size, e.g. 128*528 should work (which is what I'm currently using) and any multiple thereof. I'm fairly certain that 64*528 (and any multiple thereof) should also work, but it was a while since I messed around with that so you'll have to test it yourself.

You can also reprogram the device to present pages that are power-of-two, but you should be aware that you lose some space (pages*16) and the process is not reversible (you've been warned!), see the datasheet for more information.

Best,
Simon Aittamaa

Quoted 9 lines

The 'trivial' exercise of replacing the bit masks by modulo [%] operator does not succeed as the compiler I am using (gcc!) does not support long-long divmod.

Regards
Dave Kitchen
InSync technology Ltd

Quoted 4 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
In reply to Dave Kitchen

Hi Dave,

Quoted 10 lines · Dave Kitchen

I have just started to work with barebox on an Atmel at91sam9g45 processor. The board has an Atmel AT45DB161 dataflash configured as 528-byte page size. I find that eg saveenv command does not run as the page erase fails with EINVAL. On tracing this is fired from the page size and offset correction code [mtd/core,c mtd_erase_align()] which uses bit masking to align the size and offset. Unfortunately bit-masking does not work with non-power-of-2 pages. Has anyone else addressed this problem?

Quoted 3 lines

The 'trivial' exercise of replacing the bit masks by modulo [%] operator does not succeed as the compiler I am using (gcc!) does not support long-long divmod.

You could use do_div here which returns the remainder. Also see the mtd_div_by_eb() and mtd_mod_by_eb() functions which may be what you are looking for.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Hi Sascha

Thank you for the hint. I now have running code with the non-power-of-2 page size.
Shall I try and generate/submit a patch for this? The code may be marginally slower in the power-of-2 case than the original, but I defy anyone to notice if they are using spi boot!

Regards
Dave

Quoted 23 lines · Sascha Hauer

Hi Dave,

Quoted 10 lines · Dave Kitchen

I have just started to work with barebox on an Atmel at91sam9g45 processor. The board has an Atmel AT45DB161 dataflash configured as 528-byte page size. I find that eg saveenv command does not run as the page erase fails with EINVAL. On tracing this is fired from the page size and offset correction code [mtd/core,c mtd_erase_align()] which uses bit masking to align the size and offset. Unfortunately bit-masking does not work with non-power-of-2 pages. Has anyone else addressed this problem?

Quoted 3 lines

The 'trivial' exercise of replacing the bit masks by modulo [%] operator does not succeed as the compiler I am using (gcc!) does not support long-long divmod.

You could use do_div here which returns the remainder. Also see the mtd_div_by_eb() and mtd_mod_by_eb() functions which may be what you are looking for.

Sascha

Signature · 13 lines
Dave Kitchen
InSync technology Ltd
Tilbrook House
2-4 Grenehurst Way
Petersfield
GU31 4AZ
+44(0) 1730 235117
-fwd

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
Quoted 5 lines · Dave Kitchen

Hi Sascha

Thank you for the hint. I now have running code with the non-power-of-2 page size.
Shall I try and generate/submit a patch for this?

Yes please.

Quoted 3 lines

The code may be
marginally slower in the power-of-2 case than the original, but I defy anyone to notice if they are using spi boot!

Well this code is not only executed for SPI Flashes but also NAND flashes. Anyway, the speed penalty should be negligible.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox