mtd_peb_write broken on dataflash
As mtd_peb_write checks for alignment, it fails writing to dataflash:
barebox$ state -s
ERROR: state: Failed to write PEB 0, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 1, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 2, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write state to at least 1 buckets. Successfully written to 0 buckets
ERROR: state: Failed to write packed state, -5
state: I/O error
Patch bellow is a naive fix just to show where problem is.
There's also problem erasing dataflash:
barebox$ erase /dev/dataflash0.barebox-state
erase: Invalid argument
I guess we'll run into similar issue for MTD_RAM, so question is whenever we want such a strict check here at all. Opinions?
Thank you.
--- drivers/mtd/peb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/peb.c +1 -1
@@ -376,7 +376,7 @@ int mtd_peb_write(struct mtd_info *mtd, const void *buf, int pnum, int offset,return -EINVAL ;if (len <=0 )return -EINVAL ; -if (len % (mtd->writesize >> mtd->subpage_sft)) +if (mtd->type !=MTD_DATAFLASH && len % (mtd->writesize >> mtd->subpage_sft))return -EINVAL ;if (mtd_peb_is_bad (mtd, pnum))return -EINVAL ;
Signature · 7 lines
2.19.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Ladis,
Quoted 10 lines · Ladislav Michl
As
mtd_peb_writechecks for alignment, it fails writing to dataflash:
barebox$ state -s
ERROR: state: Failed to write PEB 0, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 1, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 2, -22
ERROR: state: Failed to write circular to 0 length 48, -22
How I read the code the length should be writesize aligned...
drivers/mtd/peb.c int mtd_peb_write(struct mtd_info *mtd, const void *buf, int pnum, int offset, · line 379
Quoted 10 lines
drivers/mtd/peb.c +1
-1@@ -376,7 +376,7 @@ int mtd_peb_write(struct mtd_info *mtd, const void *buf, int pnum, int offset,return -EINVAL ;if (len <=0 )return -EINVAL ; -if (len % (mtd->writesize >> mtd->subpage_sft)) +if (mtd->type !=MTD_DATAFLASH && len % (mtd->writesize >> mtd->subpage_sft))
So how big is mtd->writesize here and is this value correct?
In state_storage_mtd_buckets_init() we have:
if (circular)
writesize = meminfo->writesize;
else
writesize = meminfo->erasesize;How big are meminfo->writesize and meminfo->erasesize here and which path is chosen?
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
Quoted 14 lines · Sascha Hauer
Hi Ladis,
Quoted 10 lines · Ladislav Michl
As
mtd_peb_writechecks for alignment, it fails writing to dataflash:
barebox$ state -s
ERROR: state: Failed to write PEB 0, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 1, -22
ERROR: state: Failed to write circular to 0 length 48, -22
WARNING: state: Failed to write state backend bucket, -22
ERROR: state: Failed to write PEB 2, -22
ERROR: state: Failed to write circular to 0 length 48, -22
Quoted 1 line
How I read the code the length should be writesize aligned...
It is perfectly valid to write less to dataflash... But see bellow.
Quoted 4 lines
Quoted 4 lines
drivers/mtd/peb.c +0
-0
Quoted 8 lines
drivers/mtd/peb.c int mtd_peb_write(struct mtd_info *mtd, const void *buf, int pnum, int offset, · line 379
Quoted 6 lines
drivers/mtd/peb.c +1
-1@@ -376,7 +376,7 @@ int mtd_peb_write(struct mtd_info *mtd, const void *buf, int pnum, int offset,return -EINVAL ;if (len <=0 )return -EINVAL ; -if (len % (mtd->writesize >> mtd->subpage_sft)) +if (mtd->type !=MTD_DATAFLASH && len % (mtd->writesize >> mtd->subpage_sft))So how big is
mtd->writesizehere and is this value correct?
Yes, it is correct:
dataflash@00: AT45DB041x (528 KBytes) pagesize 264 bytes (OTP)
Quoted 9 lines
In
state_storage_mtd_buckets_init()we have:if (circular) writesize = meminfo->writesize; else writesize = meminfo->erasesize;How big are
meminfo->writesizeandmeminfo->erasesizehere and which path is chosen?
writesize: 264
erasesize: 264subpage_sft: 0
circular: true
But later we are trying to write 48 bytes:
dataflash0.barebox-state: write 48 bytes to PEB 0:0
ladis
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox