mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/5] mtd: Update internal API to support 64-bit device size
@ 2014-03-10 11:39 Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 2/5] mtd: Support for 4GB partitions Dmitry Lavnikevich
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

MTD internal API presently uses 32-bit values to represent device
size. This patch updates them to 64-bits but leaves the external API
unchanged.

In general, changing from 32-bit to 64-bit values cause little
or no changes to the majority of the code with the following
exceptions:
  - printk message formats;
  - division and modulus of 64-bit values (mtd_div_by_wb,
    mtd_div_by_eb may be used in some of such cases).

Was tested on phyFLEX i.MX6.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
 commands/nandtest.c                 |  2 +-
 commands/partition.c                | 11 ++++++-----
 drivers/mtd/core.c                  |  2 +-
 drivers/mtd/devices/m25p80.c        |  5 +++--
 drivers/mtd/devices/mtd_dataflash.c |  2 +-
 drivers/mtd/mtdoob.c                |  2 +-
 drivers/mtd/mtdraw.c                |  2 +-
 include/linux/mtd/mtd-abi.h         | 12 +++++++++++-
 include/linux/mtd/mtd.h             |  9 ++++++++-
 lib/libmtd.c                        | 10 +++++-----
 10 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/commands/nandtest.c b/commands/nandtest.c
index 0da5444..c64f244 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -277,7 +277,7 @@ static int do_nandtest(int argc, char *argv[])
 	}
 	if (length + flash_offset > meminfo.size) {
 		printf("Length 0x%08llx + offset 0x%08llx exceeds "
-				"device size 0x%08x\n", length,
+				"device size 0x%08llx\n", length,
 				flash_offset, meminfo.size);
 		goto err;
 	}
diff --git a/commands/partition.c b/commands/partition.c
index 6d37471..f825722 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -42,10 +42,11 @@
 #define PART_ADD_DEVNAME (1 << 0)
 
 static int mtd_part_do_parse_one(char *devname, const char *partstr,
-				 char **endp, unsigned long *offset,
-				 off_t devsize, size_t *retsize, unsigned int pflags)
+				 char **endp, loff_t *offset,
+				 loff_t devsize, size_t *retsize,
+				 unsigned int pflags)
 {
-	ulong size;
+	loff_t size;
 	char *end;
 	char buf[PATH_MAX] = {};
 	unsigned long flags = 0;
@@ -114,8 +115,8 @@ static int do_addpart(int argc, char *argv[])
 {
 	char *devname;
 	char *endp;
-	unsigned long offset = 0;
-	off_t devsize;
+	loff_t offset = 0;
+	loff_t devsize;
 	struct stat s;
 	int opt;
 	unsigned int flags = PART_ADD_DEVNAME;
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 6db1c6d..7efb03c 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -397,7 +397,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
 	mtd->cdev.mtd = mtd;
 
 	if (IS_ENABLED(CONFIG_PARAMETER)) {
-		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
+		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%llu");
 		dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u");
 		dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->oobsize, "%u");
 		dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 9594011..757a717 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -273,8 +273,9 @@ static int erase_sector(struct m25p *flash, u32 offset, u32 command)
 static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
 	struct m25p *flash = mtd_to_m25p(mtd);
-	u32 addr, len;
+	u32 addr;
 	uint32_t rem;
+	uint64_t len;
 
 	dev_dbg(&flash->spi->dev, "%s at 0x%llx, len %lld\n",
 			__func__, (long long)instr->addr,
@@ -896,7 +897,7 @@ static int m25p_probe(struct device_d *dev)
 	flash->mtd.type = MTD_NORFLASH;
 	flash->mtd.writesize = 1;
 	flash->mtd.flags = MTD_CAP_NORFLASH;
-	flash->mtd.size = info->sector_size * info->n_sectors;
+	flash->mtd.size = (uint64_t)info->sector_size * info->n_sectors;
 	flash->mtd.erase = m25p80_erase;
 	flash->mtd.read = m25p80_read;
 
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index cdc0120..fa31b61 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -625,7 +625,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 
 	device = &priv->mtd;
 	device->name = (pdata && pdata->name) ? pdata->name : "dataflash";
-	device->size = nr_pages * pagesize;
+	device->size = nr_pages * (uint64_t)pagesize;
 	device->erasesize = pagesize;
 	device->writesize = pagesize;
 	device->type = MTD_DATAFLASH;
diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
index 1e88b53..54888cd 100644
--- a/drivers/mtd/mtdoob.c
+++ b/drivers/mtd/mtdoob.c
@@ -78,7 +78,7 @@ static int add_mtdoob_device(struct mtd_info *mtd, char *devname, void **priv)
 
 	mtdoob = xzalloc(sizeof(*mtdoob));
 	mtdoob->cdev.ops = &mtd_ops_oob;
-	mtdoob->cdev.size = (mtd->size / mtd->writesize) * mtd->oobsize;
+	mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * mtd->oobsize;
 	mtdoob->cdev.name = asprintf("%s_oob%d", devname, mtd->class_dev.id);
 	mtdoob->cdev.priv = mtdoob;
 	mtdoob->cdev.dev = &mtd->class_dev;
diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
index be34723..33ca05d 100644
--- a/drivers/mtd/mtdraw.c
+++ b/drivers/mtd/mtdraw.c
@@ -290,7 +290,7 @@ static int add_mtdraw_device(struct mtd_info *mtd, char *devname, void **priv)
 	mtdraw->mtd = mtd;
 
 	mtdraw->cdev.ops = (struct file_operations *)&mtd_raw_fops;
-	mtdraw->cdev.size = mtd->size / mtd->writesize *
+	mtdraw->cdev.size = mtd_div_by_wb(mtd->size, mtd) *
 		(mtd->writesize + mtd->oobsize);
 	mtdraw->cdev.name = asprintf("%s.raw", mtd->cdev.name);
 	mtdraw->cdev.priv = mtdraw;
diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
index 11d51e2..c1ba55b 100644
--- a/include/linux/mtd/mtd-abi.h
+++ b/include/linux/mtd/mtd-abi.h
@@ -9,6 +9,8 @@
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
+#include <asm-generic/div64.h>
+
 struct erase_info_user {
 	uint32_t start;
 	uint32_t length;
@@ -73,7 +75,7 @@ enum {
 struct mtd_info_user {
 	uint8_t type;
 	uint32_t flags;
-	uint32_t size;	 // Total size of the MTD
+	uint64_t size;	 /* Total size of the MTD */
 	uint32_t erasesize;
 	uint32_t writesize;
 	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
@@ -173,6 +175,14 @@ enum mtd_file_modes {
 	MTD_MODE_RAW,
 };
 
+
+static inline uint32_t mtd_user_div_by_eb(uint64_t sz,
+	struct mtd_info_user *mtd_user)
+{
+	do_div(sz, mtd_user->erasesize);
+	return sz;
+}
+
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
 #endif /* __MTD_ABI_H__ */
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 402e497..d337455 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -86,7 +86,7 @@ struct mtd_oob_ops {
 struct mtd_info {
 	u_char type;
 	u_int32_t flags;
-	u_int32_t size;	 // Total size of the MTD
+	u_int64_t size;	 /* Total size of the MTD */
 
 	/* "Major" erase size for the device. Naïve users may take this
 	 * to be the only erase size available, or may use the more detailed
@@ -253,6 +253,13 @@ static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
 {
 	return do_div(sz, mtd->erasesize);
 }
+
+static inline uint32_t mtd_div_by_wb(uint64_t sz, struct mtd_info *mtd)
+{
+	do_div(sz, mtd->writesize);
+	return sz;
+}
+
 	/* Kernel-side ioctl definitions */
 
 extern int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id);
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 1606b87..56672bd 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -195,7 +195,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	     void *buf, int len)
 {
 	int ret, rd = 0;
-	off_t seek;
+	loff_t seek;
 
 	ret = mtd_valid_erase_block(mtd, eb);
 	if (ret)
@@ -209,7 +209,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	}
 
 	/* Seek to the beginning of the eraseblock */
-	seek = (off_t)eb * mtd->eb_size + offs;
+	seek = (loff_t)eb * mtd->eb_size + offs;
 	if (lseek(fd, seek, SEEK_SET) != seek)
 		return sys_errmsg("cannot seek %s to offset %llu",
 				  mtd->node, (unsigned long long)seek);
@@ -229,7 +229,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	      void *buf, int len)
 {
 	int ret;
-	off_t seek;
+	loff_t seek;
 
 	ret = mtd_valid_erase_block(mtd, eb);
 	if (ret)
@@ -255,7 +255,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	}
 
 	/* Seek to the beginning of the eraseblock */
-	seek = (off_t)eb * mtd->eb_size + offs;
+	seek = (loff_t)eb * mtd->eb_size + offs;
 	if (lseek(fd, seek, SEEK_SET) != seek)
 		return sys_errmsg("cannot seek %s to offset %llu",
 				  mtd->node, (unsigned long long)seek);
@@ -326,7 +326,7 @@ int mtd_get_dev_info(const char *node, struct mtd_dev_info *mtd)
 		goto out_close;
 	}
 
-	mtd->eb_cnt = ui.size / ui.erasesize;
+	mtd->eb_cnt = mtd_user_div_by_eb(ui.size, &ui);
 
 	switch(mtd->type) {
 	case MTD_ABSENT:
-- 
1.9.0


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

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

* [PATCH 2/5] mtd: Support for 4GB partitions
  2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
@ 2014-03-10 11:39 ` Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 3/5] ubi: Fix for creating ubi volumes with 64bit size Dmitry Lavnikevich
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

This patch implements correct way of creating partitions on mtd
devices with size >= 4GB.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
 commands/partition.c    | 4 ++--
 drivers/mtd/partition.c | 4 ++--
 include/linux/mtd/mtd.h | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index f825722..44b91d1 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -59,11 +59,11 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 		size = SIZE_REMAINING;
 		end = (char *)partstr + 1;
 	} else {
-		size = strtoul_suffix(partstr, &end, 0);
+		size = strtoull_suffix(partstr, &end, 0);
 	}
 
 	if (*end == '@')
-		*offset = strtoul_suffix(end+1, &end, 0);
+		*offset = strtoull_suffix(end+1, &end, 0);
 
 	if (size == SIZE_REMAINING)
 		size = devsize - *offset;
diff --git a/drivers/mtd/partition.c b/drivers/mtd/partition.c
index 85f486d..1b8d36e 100644
--- a/drivers/mtd/partition.c
+++ b/drivers/mtd/partition.c
@@ -90,8 +90,8 @@ static int mtd_part_block_markbad(struct mtd_info *mtd, loff_t ofs)
 	return res;
 }
 
-struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset, size_t size,
-		unsigned long flags, const char *name)
+struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset,
+		uint64_t size, unsigned long flags, const char *name)
 {
 	struct mtd_part *slave;
 	struct mtd_info *slave_mtd;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index d337455..165bc88 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -277,8 +277,8 @@ struct mtd_notifier {
 	struct list_head list;
 };
 
-struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset, size_t size,
-		unsigned long flags, const char *name);
+struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset,
+		uint64_t size, unsigned long flags, const char *name);
 void mtd_del_partition(struct mtd_info *mtd);
 
 extern void register_mtd_user (struct mtd_notifier *new);
-- 
1.9.0


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

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

* [PATCH 3/5] ubi: Fix for creating ubi volumes with 64bit size
  2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 2/5] mtd: Support for 4GB partitions Dmitry Lavnikevich
@ 2014-03-10 11:39 ` Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 4/5] nand: mxs: Check for up to 4 NAND chips Dmitry Lavnikevich
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

Since MTD is already supports >= 4GB device sizes it is better to
allow ubi valumes also be created of larger sizes.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
 commands/ubi.c         | 4 ++--
 drivers/mtd/ubi/cdev.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 57ae790..8a409c2 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -15,12 +15,12 @@ static int do_ubimkvol(int argc, char *argv[])
 {
 	struct ubi_mkvol_req req;
 	int fd, ret;
-	size_t size;
+	uint64_t size;
 
 	if (argc != 4)
 		return COMMAND_ERROR_USAGE;
 
-	size = strtoul_suffix(argv[3], NULL, 0);
+	size = strtoull_suffix(argv[3], NULL, 0);
 	req.name_len = min_t(int, strlen(argv[2]), UBI_VOL_NAME_MAX);
 	strncpy(req.name, argv[2], req.name_len);
 	req.name[req.name_len] = 0;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 129f2e2..b97739a 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -220,7 +220,7 @@ static int ubi_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
 		break;
 	case UBI_IOCMKVOL:
 		if (!req->bytes)
-			req->bytes = ubi->avail_pebs * ubi->leb_size;
+			req->bytes = (__s64)ubi->avail_pebs * ubi->leb_size;
 		return ubi_create_volume(ubi, req);
 	};
 
-- 
1.9.0


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

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

* [PATCH 4/5] nand: mxs: Check for up to 4 NAND chips
  2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 2/5] mtd: Support for 4GB partitions Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 3/5] ubi: Fix for creating ubi volumes with 64bit size Dmitry Lavnikevich
@ 2014-03-10 11:39 ` Dmitry Lavnikevich
  2014-03-10 11:39 ` [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash Dmitry Lavnikevich
  2014-03-12 20:28 ` [PATCH 1/5] mtd: Update internal API to support 64-bit device size Sascha Hauer
  4 siblings, 0 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

Since i.MX6 has only one R/B actual pin, if there are several R/B
signals (from different NAND chips) they must be connected to this
pin.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
 drivers/mtd/nand/nand_mxs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index d1e4b57..237a423 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -33,6 +33,7 @@
 #include <dma/apbh-dma.h>
 #include <stmp-device.h>
 #include <asm/mmu.h>
+#include <mach/generic.h>
 
 #define	MX28_BLOCK_SFTRST				(1 << 31)
 #define	MX28_BLOCK_CLKGATE				(1 << 30)
@@ -427,7 +428,13 @@ static int mxs_nand_device_ready(struct mtd_info *mtd)
 
 	if (nand_info->version > GPMI_VERSION_TYPE_MX23) {
 		tmp = readl(gpmi_regs + GPMI_STAT);
-		tmp >>= (GPMI_STAT_READY_BUSY_OFFSET + nand_info->cur_chip);
+		/* i.MX6 has only one R/B actual pin, so if there are several
+		   R/B signals they must be all connected to this pin */
+		if (cpu_is_mx6())
+			tmp >>= GPMI_STAT_READY_BUSY_OFFSET;
+		else
+			tmp >>= (GPMI_STAT_READY_BUSY_OFFSET +
+					 nand_info->cur_chip);
 	} else {
 		tmp = readl(gpmi_regs + GPMI_DEBUG);
 		tmp >>= (GPMI_DEBUG_READY0_OFFSET + nand_info->cur_chip);
@@ -1304,7 +1311,7 @@ static int mxs_nand_probe(struct device_d *dev)
 	nand->ecc.strength	= 8;
 
 	/* first scan to find the device and get the page size */
-	err = nand_scan_ident(mtd, 1, NULL);
+	err = nand_scan_ident(mtd, 4, NULL);
 	if (err)
 		goto err2;
 
-- 
1.9.0


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

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

* [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash
  2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
                   ` (2 preceding siblings ...)
  2014-03-10 11:39 ` [PATCH 4/5] nand: mxs: Check for up to 4 NAND chips Dmitry Lavnikevich
@ 2014-03-10 11:39 ` Dmitry Lavnikevich
  2014-03-12 20:28 ` [PATCH 1/5] mtd: Update internal API to support 64-bit device size Sascha Hauer
  4 siblings, 0 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

Was tested on NAND with {writesize=4096, oobsize=224} and
{writesize=2048, oobsize=64}.

This patch will not break any NAND that was working
before. Implemented calculation way may be used for other NAND chips
with writesize == 2048 but oobsize != 64.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
 drivers/mtd/nand/nand_mxs.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 237a423..b06b558 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -234,18 +234,31 @@ static uint32_t mxs_nand_aux_status_offset(void)
 static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
 						uint32_t page_oob_size)
 {
+	int ecc_chunk_count = mxs_nand_ecc_chunk_cnt(page_data_size);
+	int ecc_strength = 0;
+	int gf_len = 13;  /* length of Galois Field for non-DDR nand */
+
+	/*
+	 * Possibly this if-else calculation may be removed since
+	 * ecc_strength calculated after it is taken from kernel driver
+	 * and therefore should work for all cases. But it was tested only
+	 * on devices with {data_size = 2046, oob_size = 64} and
+	 * {data_size = 4096, oob_size = 224} configuration.
+	 */
 	if (page_data_size == 2048)
 		return 8;
-
-	if (page_data_size == 4096) {
+	else if (page_data_size == 4096) {
 		if (page_oob_size == 128)
 			return 8;
-
 		if (page_oob_size == 218)
 			return 16;
 	}
 
-	return 0;
+	ecc_strength = ((page_oob_size - MXS_NAND_METADATA_SIZE) * 8)
+		/ (gf_len * ecc_chunk_count);
+
+	/* We need the minor even number. */
+	return rounddown(ecc_strength, 2);
 }
 
 static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
-- 
1.9.0


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

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
                   ` (3 preceding siblings ...)
  2014-03-10 11:39 ` [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash Dmitry Lavnikevich
@ 2014-03-12 20:28 ` Sascha Hauer
  2014-03-12 20:51   ` Alexander Aring
  4 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2014-03-12 20:28 UTC (permalink / raw)
  To: Dmitry Lavnikevich; +Cc: Grigory Milev, barebox

On Mon, Mar 10, 2014 at 02:39:49PM +0300, Dmitry Lavnikevich wrote:
> MTD internal API presently uses 32-bit values to represent device
> size. This patch updates them to 64-bits but leaves the external API
> unchanged.
> 
> In general, changing from 32-bit to 64-bit values cause little
> or no changes to the majority of the code with the following
> exceptions:
>   - printk message formats;
>   - division and modulus of 64-bit values (mtd_div_by_wb,
>     mtd_div_by_eb may be used in some of such cases).
> 
> Was tested on phyFLEX i.MX6.
>

changed master_offset to 64bit aswell and applied this series.

Thanks
 Sascha
 
> Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
> Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
> ---
>  commands/nandtest.c                 |  2 +-
>  commands/partition.c                | 11 ++++++-----
>  drivers/mtd/core.c                  |  2 +-
>  drivers/mtd/devices/m25p80.c        |  5 +++--
>  drivers/mtd/devices/mtd_dataflash.c |  2 +-
>  drivers/mtd/mtdoob.c                |  2 +-
>  drivers/mtd/mtdraw.c                |  2 +-
>  include/linux/mtd/mtd-abi.h         | 12 +++++++++++-
>  include/linux/mtd/mtd.h             |  9 ++++++++-
>  lib/libmtd.c                        | 10 +++++-----
>  10 files changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/commands/nandtest.c b/commands/nandtest.c
> index 0da5444..c64f244 100644
> --- a/commands/nandtest.c
> +++ b/commands/nandtest.c
> @@ -277,7 +277,7 @@ static int do_nandtest(int argc, char *argv[])
>  	}
>  	if (length + flash_offset > meminfo.size) {
>  		printf("Length 0x%08llx + offset 0x%08llx exceeds "
> -				"device size 0x%08x\n", length,
> +				"device size 0x%08llx\n", length,
>  				flash_offset, meminfo.size);
>  		goto err;
>  	}
> diff --git a/commands/partition.c b/commands/partition.c
> index 6d37471..f825722 100644
> --- a/commands/partition.c
> +++ b/commands/partition.c
> @@ -42,10 +42,11 @@
>  #define PART_ADD_DEVNAME (1 << 0)
>  
>  static int mtd_part_do_parse_one(char *devname, const char *partstr,
> -				 char **endp, unsigned long *offset,
> -				 off_t devsize, size_t *retsize, unsigned int pflags)
> +				 char **endp, loff_t *offset,
> +				 loff_t devsize, size_t *retsize,
> +				 unsigned int pflags)
>  {
> -	ulong size;
> +	loff_t size;
>  	char *end;
>  	char buf[PATH_MAX] = {};
>  	unsigned long flags = 0;
> @@ -114,8 +115,8 @@ static int do_addpart(int argc, char *argv[])
>  {
>  	char *devname;
>  	char *endp;
> -	unsigned long offset = 0;
> -	off_t devsize;
> +	loff_t offset = 0;
> +	loff_t devsize;
>  	struct stat s;
>  	int opt;
>  	unsigned int flags = PART_ADD_DEVNAME;
> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
> index 6db1c6d..7efb03c 100644
> --- a/drivers/mtd/core.c
> +++ b/drivers/mtd/core.c
> @@ -397,7 +397,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
>  	mtd->cdev.mtd = mtd;
>  
>  	if (IS_ENABLED(CONFIG_PARAMETER)) {
> -		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
> +		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%llu");
>  		dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u");
>  		dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->oobsize, "%u");
>  		dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 9594011..757a717 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -273,8 +273,9 @@ static int erase_sector(struct m25p *flash, u32 offset, u32 command)
>  static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
>  {
>  	struct m25p *flash = mtd_to_m25p(mtd);
> -	u32 addr, len;
> +	u32 addr;
>  	uint32_t rem;
> +	uint64_t len;
>  
>  	dev_dbg(&flash->spi->dev, "%s at 0x%llx, len %lld\n",
>  			__func__, (long long)instr->addr,
> @@ -896,7 +897,7 @@ static int m25p_probe(struct device_d *dev)
>  	flash->mtd.type = MTD_NORFLASH;
>  	flash->mtd.writesize = 1;
>  	flash->mtd.flags = MTD_CAP_NORFLASH;
> -	flash->mtd.size = info->sector_size * info->n_sectors;
> +	flash->mtd.size = (uint64_t)info->sector_size * info->n_sectors;
>  	flash->mtd.erase = m25p80_erase;
>  	flash->mtd.read = m25p80_read;
>  
> diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
> index cdc0120..fa31b61 100644
> --- a/drivers/mtd/devices/mtd_dataflash.c
> +++ b/drivers/mtd/devices/mtd_dataflash.c
> @@ -625,7 +625,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
>  
>  	device = &priv->mtd;
>  	device->name = (pdata && pdata->name) ? pdata->name : "dataflash";
> -	device->size = nr_pages * pagesize;
> +	device->size = nr_pages * (uint64_t)pagesize;
>  	device->erasesize = pagesize;
>  	device->writesize = pagesize;
>  	device->type = MTD_DATAFLASH;
> diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
> index 1e88b53..54888cd 100644
> --- a/drivers/mtd/mtdoob.c
> +++ b/drivers/mtd/mtdoob.c
> @@ -78,7 +78,7 @@ static int add_mtdoob_device(struct mtd_info *mtd, char *devname, void **priv)
>  
>  	mtdoob = xzalloc(sizeof(*mtdoob));
>  	mtdoob->cdev.ops = &mtd_ops_oob;
> -	mtdoob->cdev.size = (mtd->size / mtd->writesize) * mtd->oobsize;
> +	mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * mtd->oobsize;
>  	mtdoob->cdev.name = asprintf("%s_oob%d", devname, mtd->class_dev.id);
>  	mtdoob->cdev.priv = mtdoob;
>  	mtdoob->cdev.dev = &mtd->class_dev;
> diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
> index be34723..33ca05d 100644
> --- a/drivers/mtd/mtdraw.c
> +++ b/drivers/mtd/mtdraw.c
> @@ -290,7 +290,7 @@ static int add_mtdraw_device(struct mtd_info *mtd, char *devname, void **priv)
>  	mtdraw->mtd = mtd;
>  
>  	mtdraw->cdev.ops = (struct file_operations *)&mtd_raw_fops;
> -	mtdraw->cdev.size = mtd->size / mtd->writesize *
> +	mtdraw->cdev.size = mtd_div_by_wb(mtd->size, mtd) *
>  		(mtd->writesize + mtd->oobsize);
>  	mtdraw->cdev.name = asprintf("%s.raw", mtd->cdev.name);
>  	mtdraw->cdev.priv = mtdraw;
> diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
> index 11d51e2..c1ba55b 100644
> --- a/include/linux/mtd/mtd-abi.h
> +++ b/include/linux/mtd/mtd-abi.h
> @@ -9,6 +9,8 @@
>  
>  #ifndef DOXYGEN_SHOULD_SKIP_THIS
>  
> +#include <asm-generic/div64.h>
> +
>  struct erase_info_user {
>  	uint32_t start;
>  	uint32_t length;
> @@ -73,7 +75,7 @@ enum {
>  struct mtd_info_user {
>  	uint8_t type;
>  	uint32_t flags;
> -	uint32_t size;	 // Total size of the MTD
> +	uint64_t size;	 /* Total size of the MTD */
>  	uint32_t erasesize;
>  	uint32_t writesize;
>  	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
> @@ -173,6 +175,14 @@ enum mtd_file_modes {
>  	MTD_MODE_RAW,
>  };
>  
> +
> +static inline uint32_t mtd_user_div_by_eb(uint64_t sz,
> +	struct mtd_info_user *mtd_user)
> +{
> +	do_div(sz, mtd_user->erasesize);
> +	return sz;
> +}
> +
>  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
>  
>  #endif /* __MTD_ABI_H__ */
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 402e497..d337455 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -86,7 +86,7 @@ struct mtd_oob_ops {
>  struct mtd_info {
>  	u_char type;
>  	u_int32_t flags;
> -	u_int32_t size;	 // Total size of the MTD
> +	u_int64_t size;	 /* Total size of the MTD */
>  
>  	/* "Major" erase size for the device. Naïve users may take this
>  	 * to be the only erase size available, or may use the more detailed
> @@ -253,6 +253,13 @@ static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
>  {
>  	return do_div(sz, mtd->erasesize);
>  }
> +
> +static inline uint32_t mtd_div_by_wb(uint64_t sz, struct mtd_info *mtd)
> +{
> +	do_div(sz, mtd->writesize);
> +	return sz;
> +}
> +
>  	/* Kernel-side ioctl definitions */
>  
>  extern int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id);
> diff --git a/lib/libmtd.c b/lib/libmtd.c
> index 1606b87..56672bd 100644
> --- a/lib/libmtd.c
> +++ b/lib/libmtd.c
> @@ -195,7 +195,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
>  	     void *buf, int len)
>  {
>  	int ret, rd = 0;
> -	off_t seek;
> +	loff_t seek;
>  
>  	ret = mtd_valid_erase_block(mtd, eb);
>  	if (ret)
> @@ -209,7 +209,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
>  	}
>  
>  	/* Seek to the beginning of the eraseblock */
> -	seek = (off_t)eb * mtd->eb_size + offs;
> +	seek = (loff_t)eb * mtd->eb_size + offs;
>  	if (lseek(fd, seek, SEEK_SET) != seek)
>  		return sys_errmsg("cannot seek %s to offset %llu",
>  				  mtd->node, (unsigned long long)seek);
> @@ -229,7 +229,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
>  	      void *buf, int len)
>  {
>  	int ret;
> -	off_t seek;
> +	loff_t seek;
>  
>  	ret = mtd_valid_erase_block(mtd, eb);
>  	if (ret)
> @@ -255,7 +255,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
>  	}
>  
>  	/* Seek to the beginning of the eraseblock */
> -	seek = (off_t)eb * mtd->eb_size + offs;
> +	seek = (loff_t)eb * mtd->eb_size + offs;
>  	if (lseek(fd, seek, SEEK_SET) != seek)
>  		return sys_errmsg("cannot seek %s to offset %llu",
>  				  mtd->node, (unsigned long long)seek);
> @@ -326,7 +326,7 @@ int mtd_get_dev_info(const char *node, struct mtd_dev_info *mtd)
>  		goto out_close;
>  	}
>  
> -	mtd->eb_cnt = ui.size / ui.erasesize;
> +	mtd->eb_cnt = mtd_user_div_by_eb(ui.size, &ui);
>  
>  	switch(mtd->type) {
>  	case MTD_ABSENT:
> -- 
> 1.9.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-12 20:28 ` [PATCH 1/5] mtd: Update internal API to support 64-bit device size Sascha Hauer
@ 2014-03-12 20:51   ` Alexander Aring
  2014-03-12 20:53     ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Alexander Aring @ 2014-03-12 20:51 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Grigory Milev, barebox, Dmitry Lavnikevich

Hi Sascha,

On Wed, Mar 12, 2014 at 09:28:48PM +0100, Sascha Hauer wrote:
> On Mon, Mar 10, 2014 at 02:39:49PM +0300, Dmitry Lavnikevich wrote:
> > MTD internal API presently uses 32-bit values to represent device
> > size. This patch updates them to 64-bits but leaves the external API
> > unchanged.
> > 
> > In general, changing from 32-bit to 64-bit values cause little
> > or no changes to the majority of the code with the following
> > exceptions:
> >   - printk message formats;
> >   - division and modulus of 64-bit values (mtd_div_by_wb,
> >     mtd_div_by_eb may be used in some of such cases).
> > 
> > Was tested on phyFLEX i.MX6.
> >
> 
> changed master_offset to 64bit aswell and applied this series.
> 
ok, cool!

But.. damn it there is still a ugly comment in lib/libmtd.c:

"NOTE: No support for 64 bit sizes yet!"

hehe. :-)

- Alex

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

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-12 20:51   ` Alexander Aring
@ 2014-03-12 20:53     ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2014-03-12 20:53 UTC (permalink / raw)
  To: Alexander Aring; +Cc: Grigory Milev, barebox, Dmitry Lavnikevich

On Wed, Mar 12, 2014 at 09:51:46PM +0100, Alexander Aring wrote:
> Hi Sascha,
> 
> On Wed, Mar 12, 2014 at 09:28:48PM +0100, Sascha Hauer wrote:
> > On Mon, Mar 10, 2014 at 02:39:49PM +0300, Dmitry Lavnikevich wrote:
> > > MTD internal API presently uses 32-bit values to represent device
> > > size. This patch updates them to 64-bits but leaves the external API
> > > unchanged.
> > > 
> > > In general, changing from 32-bit to 64-bit values cause little
> > > or no changes to the majority of the code with the following
> > > exceptions:
> > >   - printk message formats;
> > >   - division and modulus of 64-bit values (mtd_div_by_wb,
> > >     mtd_div_by_eb may be used in some of such cases).
> > > 
> > > Was tested on phyFLEX i.MX6.
> > >
> > 
> > changed master_offset to 64bit aswell and applied this series.
> > 
> ok, cool!
> 
> But.. damn it there is still a ugly comment in lib/libmtd.c:
> 
> "NOTE: No support for 64 bit sizes yet!"

Maybe this should be removed by somebody who has tested this code with
devices > 4GB. I don't have the hardware for this.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-11  7:50       ` Alexander Aring
@ 2014-03-12 20:28         ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2014-03-12 20:28 UTC (permalink / raw)
  To: Alexander Aring
  Cc: Grigory Milev, barebox, Dmitry Lavnikevich, Dmitry Lavnikevich

On Tue, Mar 11, 2014 at 08:50:44AM +0100, Alexander Aring wrote:
> On Tue, Mar 11, 2014 at 06:29:22AM +0100, Sascha Hauer wrote:
> > > offset but we should do it right at first time.
> > 
> > Yes, right. We should make this uint64_t.
> > 
> 
> There are also more things which needs a uint64_t like the offset
> parameter of libmtd_* functions. :-/

The libmtd functions should be 64bit already. The remaining bits are in
Dmitrys series.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-11  5:29     ` Sascha Hauer
@ 2014-03-11  7:50       ` Alexander Aring
  2014-03-12 20:28         ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Alexander Aring @ 2014-03-11  7:50 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: Grigory Milev, barebox, Dmitry Lavnikevich, Dmitry Lavnikevich

On Tue, Mar 11, 2014 at 06:29:22AM +0100, Sascha Hauer wrote:
> > offset but we should do it right at first time.
> 
> Yes, right. We should make this uint64_t.
> 

There are also more things which needs a uint64_t like the offset
parameter of libmtd_* functions. :-/

- Alex

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

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-10  8:02   ` Alexander Aring
@ 2014-03-11  5:29     ` Sascha Hauer
  2014-03-11  7:50       ` Alexander Aring
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2014-03-11  5:29 UTC (permalink / raw)
  To: Alexander Aring
  Cc: Grigory Milev, barebox, Dmitry Lavnikevich, Dmitry Lavnikevich

On Mon, Mar 10, 2014 at 09:02:15AM +0100, Alexander Aring wrote:
> Hi Sascha,
> 
> we talked some time ago about >= 4GB mtd support. This patch series add
> only a size for uint64_t. But then we also need to change

That even wasn't so long ago ;)

> 
> uint32_t master_offset;
> 
> in mtd_info to:
> 
> uint64_t master_offset;
> 
> otherwise we can't create mtd partitions with a uint64_t offset. Or I am
> wrong with that? I mean... maybe they don't want to make a uint64_t
> offset but we should do it right at first time.

Yes, right. We should make this uint64_t.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-10  7:20 ` Sascha Hauer
  2014-03-10  8:02   ` Alexander Aring
@ 2014-03-10 11:37   ` Dmitry Lavnikevich
  1 sibling, 0 replies; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-10 11:37 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Grigory Milev, barebox

Hello Sascha,

eyah, I've had some problems sending mails with git send-email
through my proxy so tried to use thunderbird to pass patches outside.
Which apparently did some improvisation on them :)

Anyway, I have fixed my sendmail and will resend patches soon.

Best regards,
Lavnikevich Dmitry

On 03/10/14 10:20, Sascha Hauer wrote:
> Hi Dmitry,
>
> On Fri, Mar 07, 2014 at 02:14:45PM +0300, Dmitry Lavnikevich wrote:
>> MTD internal API presently uses 32-bit values to represent device
>> size. This patch updates them to 64-bits but leaves the external API
>> unchanged.
>>
>> In general, changing from 32-bit to 64-bit values cause little
>> or no changes to the majority of the code with the following
>> exceptions:
>>    - printk message formats;
>>    - division and modulus of 64-bit values (mtd_div_by_wb,
>>      mtd_div_by_eb may be used in some of such cases).
>>
>> Was tested on phyFLEX i.MX6.
>>
>> Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
>> Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
> Your patches look all good. Unfortunately I can't apply them because
> your mailer wraps lines.
>
>> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
>> index 6db1c6d..7efb03c 100644
>> --- a/drivers/mtd/core.c
>> +++ b/drivers/mtd/core.c
>> @@ -397,7 +397,7 @@ int add_mtd_device(struct mtd_info *mtd, char
>> *devname, int device_id)
>>   	mtd->cdev.mtd = mtd;
>>    	if (IS_ENABLED(CONFIG_PARAMETER)) {
>> -		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
>> +		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%llu");
>>   		dev_add_param_int_ro(&mtd->class_dev, "erasesize",
>> mtd->erasesize, "%u");
> For example here.
>
>>   	flash->mtd.read = m25p80_read;
>>   diff --git a/drivers/mtd/devices/mtd_dataflash.c
> Here is one space too much before 'diff'
>
>> diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
>> index 11d51e2..c1ba55b 100644
>> --- a/include/linux/mtd/mtd-abi.h
>> +++ b/include/linux/mtd/mtd-abi.h
>> @@ -9,6 +9,8 @@
>>    #ifndef DOXYGEN_SHOULD_SKIP_THIS
>>   +#include <asm-generic/div64.h>
>> +
> Here also is one space too much.
>
> Could you try resending it using git-send-email?
>
> Sascha
>


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

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-10  7:20 ` Sascha Hauer
@ 2014-03-10  8:02   ` Alexander Aring
  2014-03-11  5:29     ` Sascha Hauer
  2014-03-10 11:37   ` Dmitry Lavnikevich
  1 sibling, 1 reply; 15+ messages in thread
From: Alexander Aring @ 2014-03-10  8:02 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: Grigory Milev, barebox, Dmitry Lavnikevich, Dmitry Lavnikevich

Hi Sascha,

we talked some time ago about >= 4GB mtd support. This patch series add
only a size for uint64_t. But then we also need to change

uint32_t master_offset;

in mtd_info to:

uint64_t master_offset;

otherwise we can't create mtd partitions with a uint64_t offset. Or I am
wrong with that? I mean... maybe they don't want to make a uint64_t
offset but we should do it right at first time.

- Alex

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

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

* Re: [PATCH 1/5] mtd: Update internal API to support 64-bit device size
  2014-03-07 11:14 Dmitry Lavnikevich
@ 2014-03-10  7:20 ` Sascha Hauer
  2014-03-10  8:02   ` Alexander Aring
  2014-03-10 11:37   ` Dmitry Lavnikevich
  0 siblings, 2 replies; 15+ messages in thread
From: Sascha Hauer @ 2014-03-10  7:20 UTC (permalink / raw)
  To: Dmitry Lavnikevich; +Cc: Grigory Milev, barebox, Dmitry Lavnikevich

Hi Dmitry,

On Fri, Mar 07, 2014 at 02:14:45PM +0300, Dmitry Lavnikevich wrote:
> MTD internal API presently uses 32-bit values to represent device
> size. This patch updates them to 64-bits but leaves the external API
> unchanged.
> 
> In general, changing from 32-bit to 64-bit values cause little
> or no changes to the majority of the code with the following
> exceptions:
>   - printk message formats;
>   - division and modulus of 64-bit values (mtd_div_by_wb,
>     mtd_div_by_eb may be used in some of such cases).
> 
> Was tested on phyFLEX i.MX6.
> 
> Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
> Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>

Your patches look all good. Unfortunately I can't apply them because
your mailer wraps lines.

> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
> index 6db1c6d..7efb03c 100644
> --- a/drivers/mtd/core.c
> +++ b/drivers/mtd/core.c
> @@ -397,7 +397,7 @@ int add_mtd_device(struct mtd_info *mtd, char
> *devname, int device_id)
>  	mtd->cdev.mtd = mtd;
>   	if (IS_ENABLED(CONFIG_PARAMETER)) {
> -		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
> +		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%llu");
>  		dev_add_param_int_ro(&mtd->class_dev, "erasesize",
> mtd->erasesize, "%u");

For example here.

>  	flash->mtd.read = m25p80_read;
>  diff --git a/drivers/mtd/devices/mtd_dataflash.c

Here is one space too much before 'diff'

> diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
> index 11d51e2..c1ba55b 100644
> --- a/include/linux/mtd/mtd-abi.h
> +++ b/include/linux/mtd/mtd-abi.h
> @@ -9,6 +9,8 @@
>   #ifndef DOXYGEN_SHOULD_SKIP_THIS
>  +#include <asm-generic/div64.h>
> +

Here also is one space too much.

Could you try resending it using git-send-email?

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/5] mtd: Update internal API to support 64-bit device size
@ 2014-03-07 11:14 Dmitry Lavnikevich
  2014-03-10  7:20 ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Lavnikevich @ 2014-03-07 11:14 UTC (permalink / raw)
  To: barebox; +Cc: Grigory Milev, Dmitry Lavnikevich

MTD internal API presently uses 32-bit values to represent device
size. This patch updates them to 64-bits but leaves the external API
unchanged.

In general, changing from 32-bit to 64-bit values cause little
or no changes to the majority of the code with the following
exceptions:
   - printk message formats;
   - division and modulus of 64-bit values (mtd_div_by_wb,
     mtd_div_by_eb may be used in some of such cases).

Was tested on phyFLEX i.MX6.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
  commands/nandtest.c                 |  2 +-
  commands/partition.c                | 11 ++++++-----
  drivers/mtd/core.c                  |  2 +-
  drivers/mtd/devices/m25p80.c        |  5 +++--
  drivers/mtd/devices/mtd_dataflash.c |  2 +-
  drivers/mtd/mtdoob.c                |  2 +-
  drivers/mtd/mtdraw.c                |  2 +-
  include/linux/mtd/mtd-abi.h         | 12 +++++++++++-
  include/linux/mtd/mtd.h             |  9 ++++++++-
  lib/libmtd.c                        | 10 +++++-----
  10 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/commands/nandtest.c b/commands/nandtest.c
index 0da5444..c64f244 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -277,7 +277,7 @@ static int do_nandtest(int argc, char *argv[])
  	}
  	if (length + flash_offset > meminfo.size) {
  		printf("Length 0x%08llx + offset 0x%08llx exceeds "
-				"device size 0x%08x\n", length,
+				"device size 0x%08llx\n", length,
  				flash_offset, meminfo.size);
  		goto err;
  	}
diff --git a/commands/partition.c b/commands/partition.c
index 6d37471..f825722 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -42,10 +42,11 @@
  #define PART_ADD_DEVNAME (1 << 0)
   static int mtd_part_do_parse_one(char *devname, const char *partstr,
-				 char **endp, unsigned long *offset,
-				 off_t devsize, size_t *retsize, unsigned int pflags)
+				 char **endp, loff_t *offset,
+				 loff_t devsize, size_t *retsize,
+				 unsigned int pflags)
  {
-	ulong size;
+	loff_t size;
  	char *end;
  	char buf[PATH_MAX] = {};
  	unsigned long flags = 0;
@@ -114,8 +115,8 @@ static int do_addpart(int argc, char *argv[])
  {
  	char *devname;
  	char *endp;
-	unsigned long offset = 0;
-	off_t devsize;
+	loff_t offset = 0;
+	loff_t devsize;
  	struct stat s;
  	int opt;
  	unsigned int flags = PART_ADD_DEVNAME;
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 6db1c6d..7efb03c 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -397,7 +397,7 @@ int add_mtd_device(struct mtd_info *mtd, char 
*devname, int device_id)
  	mtd->cdev.mtd = mtd;
   	if (IS_ENABLED(CONFIG_PARAMETER)) {
-		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
+		dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%llu");
  		dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, 
"%u");
  		dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->oobsize, "%u");
  		dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 9594011..757a717 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -273,8 +273,9 @@ static int erase_sector(struct m25p *flash, u32 
offset, u32 command)
  static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
  {
  	struct m25p *flash = mtd_to_m25p(mtd);
-	u32 addr, len;
+	u32 addr;
  	uint32_t rem;
+	uint64_t len;
   	dev_dbg(&flash->spi->dev, "%s at 0x%llx, len %lld\n",
  			__func__, (long long)instr->addr,
@@ -896,7 +897,7 @@ static int m25p_probe(struct device_d *dev)
  	flash->mtd.type = MTD_NORFLASH;
  	flash->mtd.writesize = 1;
  	flash->mtd.flags = MTD_CAP_NORFLASH;
-	flash->mtd.size = info->sector_size * info->n_sectors;
+	flash->mtd.size = (uint64_t)info->sector_size * info->n_sectors;
  	flash->mtd.erase = m25p80_erase;
  	flash->mtd.read = m25p80_read;
  diff --git a/drivers/mtd/devices/mtd_dataflash.c 
b/drivers/mtd/devices/mtd_dataflash.c
index cdc0120..fa31b61 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -625,7 +625,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
   	device = &priv->mtd;
  	device->name = (pdata && pdata->name) ? pdata->name : "dataflash";
-	device->size = nr_pages * pagesize;
+	device->size = nr_pages * (uint64_t)pagesize;
  	device->erasesize = pagesize;
  	device->writesize = pagesize;
  	device->type = MTD_DATAFLASH;
diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
index 1e88b53..54888cd 100644
--- a/drivers/mtd/mtdoob.c
+++ b/drivers/mtd/mtdoob.c
@@ -78,7 +78,7 @@ static int add_mtdoob_device(struct mtd_info *mtd, 
char *devname, void **priv)
   	mtdoob = xzalloc(sizeof(*mtdoob));
  	mtdoob->cdev.ops = &mtd_ops_oob;
-	mtdoob->cdev.size = (mtd->size / mtd->writesize) * mtd->oobsize;
+	mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * mtd->oobsize;
  	mtdoob->cdev.name = asprintf("%s_oob%d", devname, mtd->class_dev.id);
  	mtdoob->cdev.priv = mtdoob;
  	mtdoob->cdev.dev = &mtd->class_dev;
diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
index be34723..33ca05d 100644
--- a/drivers/mtd/mtdraw.c
+++ b/drivers/mtd/mtdraw.c
@@ -290,7 +290,7 @@ static int add_mtdraw_device(struct mtd_info *mtd, 
char *devname, void **priv)
  	mtdraw->mtd = mtd;
   	mtdraw->cdev.ops = (struct file_operations *)&mtd_raw_fops;
-	mtdraw->cdev.size = mtd->size / mtd->writesize *
+	mtdraw->cdev.size = mtd_div_by_wb(mtd->size, mtd) *
  		(mtd->writesize + mtd->oobsize);
  	mtdraw->cdev.name = asprintf("%s.raw", mtd->cdev.name);
  	mtdraw->cdev.priv = mtdraw;
diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
index 11d51e2..c1ba55b 100644
--- a/include/linux/mtd/mtd-abi.h
+++ b/include/linux/mtd/mtd-abi.h
@@ -9,6 +9,8 @@
   #ifndef DOXYGEN_SHOULD_SKIP_THIS
  +#include <asm-generic/div64.h>
+
  struct erase_info_user {
  	uint32_t start;
  	uint32_t length;
@@ -73,7 +75,7 @@ enum {
  struct mtd_info_user {
  	uint8_t type;
  	uint32_t flags;
-	uint32_t size;	 // Total size of the MTD
+	uint64_t size;	 /* Total size of the MTD */
  	uint32_t erasesize;
  	uint32_t writesize;
  	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
@@ -173,6 +175,14 @@ enum mtd_file_modes {
  	MTD_MODE_RAW,
  };
  +
+static inline uint32_t mtd_user_div_by_eb(uint64_t sz,
+	struct mtd_info_user *mtd_user)
+{
+	do_div(sz, mtd_user->erasesize);
+	return sz;
+}
+
  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
   #endif /* __MTD_ABI_H__ */
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 402e497..d337455 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -86,7 +86,7 @@ struct mtd_oob_ops {
  struct mtd_info {
  	u_char type;
  	u_int32_t flags;
-	u_int32_t size;	 // Total size of the MTD
+	u_int64_t size;	 /* Total size of the MTD */
   	/* "Major" erase size for the device. Naïve users may take this
  	 * to be the only erase size available, or may use the more detailed
@@ -253,6 +253,13 @@ static inline uint32_t mtd_mod_by_eb(uint64_t sz, 
struct mtd_info *mtd)
  {
  	return do_div(sz, mtd->erasesize);
  }
+
+static inline uint32_t mtd_div_by_wb(uint64_t sz, struct mtd_info *mtd)
+{
+	do_div(sz, mtd->writesize);
+	return sz;
+}
+
  	/* Kernel-side ioctl definitions */
   extern int add_mtd_device(struct mtd_info *mtd, char *devname, int 
device_id);
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 1606b87..56672bd 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -195,7 +195,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int 
fd, int eb, int offs,
  	     void *buf, int len)
  {
  	int ret, rd = 0;
-	off_t seek;
+	loff_t seek;
   	ret = mtd_valid_erase_block(mtd, eb);
  	if (ret)
@@ -209,7 +209,7 @@ int libmtd_read(const struct mtd_dev_info *mtd, int 
fd, int eb, int offs,
  	}
   	/* Seek to the beginning of the eraseblock */
-	seek = (off_t)eb * mtd->eb_size + offs;
+	seek = (loff_t)eb * mtd->eb_size + offs;
  	if (lseek(fd, seek, SEEK_SET) != seek)
  		return sys_errmsg("cannot seek %s to offset %llu",
  				  mtd->node, (unsigned long long)seek);
@@ -229,7 +229,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int 
fd, int eb, int offs,
  	      void *buf, int len)
  {
  	int ret;
-	off_t seek;
+	loff_t seek;
   	ret = mtd_valid_erase_block(mtd, eb);
  	if (ret)
@@ -255,7 +255,7 @@ int libmtd_write(const struct mtd_dev_info *mtd, int 
fd, int eb, int offs,
  	}
   	/* Seek to the beginning of the eraseblock */
-	seek = (off_t)eb * mtd->eb_size + offs;
+	seek = (loff_t)eb * mtd->eb_size + offs;
  	if (lseek(fd, seek, SEEK_SET) != seek)
  		return sys_errmsg("cannot seek %s to offset %llu",
  				  mtd->node, (unsigned long long)seek);
@@ -326,7 +326,7 @@ int mtd_get_dev_info(const char *node, struct 
mtd_dev_info *mtd)
  		goto out_close;
  	}
  -	mtd->eb_cnt = ui.size / ui.erasesize;
+	mtd->eb_cnt = mtd_user_div_by_eb(ui.size, &ui);
   	switch(mtd->type) {
  	case MTD_ABSENT:
-- 
1.8.5.1


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

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

end of thread, other threads:[~2014-03-12 20:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
2014-03-10 11:39 ` [PATCH 2/5] mtd: Support for 4GB partitions Dmitry Lavnikevich
2014-03-10 11:39 ` [PATCH 3/5] ubi: Fix for creating ubi volumes with 64bit size Dmitry Lavnikevich
2014-03-10 11:39 ` [PATCH 4/5] nand: mxs: Check for up to 4 NAND chips Dmitry Lavnikevich
2014-03-10 11:39 ` [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash Dmitry Lavnikevich
2014-03-12 20:28 ` [PATCH 1/5] mtd: Update internal API to support 64-bit device size Sascha Hauer
2014-03-12 20:51   ` Alexander Aring
2014-03-12 20:53     ` Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2014-03-07 11:14 Dmitry Lavnikevich
2014-03-10  7:20 ` Sascha Hauer
2014-03-10  8:02   ` Alexander Aring
2014-03-11  5:29     ` Sascha Hauer
2014-03-11  7:50       ` Alexander Aring
2014-03-12 20:28         ` Sascha Hauer
2014-03-10 11:37   ` Dmitry Lavnikevich

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