mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: create bitflips in the correct page
@ 2017-03-14  7:10 Sascha Hauer
  2017-03-14  7:10 ` [PATCH 2/2] mtd: when creating bitflips the offset has to be page aligned Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2017-03-14  7:10 UTC (permalink / raw)
  To: Barebox List

In mtd_peb_create_bitflips() buf always points to the first page in a
block. If we want to create bitflips in other pages we have to add the
offset into the block.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/peb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index 66227d4ffb..c97697f6f9 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -610,7 +610,7 @@ int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
 	for (i = 0; i < num_bitflips; i++) {
 		int offs;
 		int bit;
-		u8 *pos = buf;
+		u8 *pos = buf + offset;
 
 		if (random) {
 			offs = random32() % len;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] mtd: when creating bitflips the offset has to be page aligned
  2017-03-14  7:10 [PATCH 1/2] mtd: create bitflips in the correct page Sascha Hauer
@ 2017-03-14  7:10 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-03-14  7:10 UTC (permalink / raw)
  To: Barebox List

mtd_peb_create_bitflips() assumes the offset is page aligned. Enforce
this and in the nand_bitlfip command print a warning if it's not
aligned.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/nand-bitflip.c | 4 ++++
 drivers/mtd/peb.c       | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/commands/nand-bitflip.c b/commands/nand-bitflip.c
index fe56f222cf..a8a97c153a 100644
--- a/commands/nand-bitflip.c
+++ b/commands/nand-bitflip.c
@@ -69,6 +69,10 @@ static int do_nand_bitflip(int argc, char *argv[])
 
 	block += mtd_div_by_eb(offset, meminfo.mtd);
 	offset = mtd_mod_by_eb(offset, meminfo.mtd);
+	if ((int)offset % meminfo.mtd->writesize) {
+		printf("offset has to be pagesize aligned\n");
+		return 1;
+	}
 
 	if (!check) {
 		ret = mtd_peb_create_bitflips(meminfo.mtd, block, offset, meminfo.writesize,
diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index c97697f6f9..c35b63f2fd 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -565,6 +565,8 @@ int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
 
 	if (offset < 0 || offset + len > mtd->erasesize)
 		return -EINVAL;
+	if (offset % mtd->writesize)
+		return -EINVAL;
 	if (len <= 0)
 		return -EINVAL;
 	if (num_bitflips <= 0)
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-14  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14  7:10 [PATCH 1/2] mtd: create bitflips in the correct page Sascha Hauer
2017-03-14  7:10 ` [PATCH 2/2] mtd: when creating bitflips the offset has to be page aligned Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox