diff mbox

[U-Boot,2/4] cmd_mtdparts: use 64 bits for flash size, partition size & offset

Message ID 1378304219-11229-3-git-send-email-paul.burton@imgtec.com
State Accepted
Delegated to: Scott Wood
Headers show

Commit Message

Paul Burton Sept. 4, 2013, 2:16 p.m. UTC
This matches the 64 bit size in struct mtd_info and allows the mtdparts
command to function correctly with a flash >= 4GiB. Format specifiers
for size & offset are given the ll length, matching its use in
drivers/mtd in absence of something like inttypes.h/PRIx64.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---
 common/cmd_mtdparts.c       | 54 ++++++++++++++++++++++++---------------------
 include/jffs2/load_kernel.h |  6 ++---
 2 files changed, 32 insertions(+), 28 deletions(-)

Comments

York Sun Oct. 15, 2013, 5:27 p.m. UTC | #1
On 09/04/2013 07:16 AM, Paul Burton wrote:
> This matches the 64 bit size in struct mtd_info and allows the mtdparts
> command to function correctly with a flash >= 4GiB. Format specifiers
> for size & offset are given the ll length, matching its use in
> drivers/mtd in absence of something like inttypes.h/PRIx64.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> ---
>  common/cmd_mtdparts.c       | 54 ++++++++++++++++++++++++---------------------
>  include/jffs2/load_kernel.h |  6 ++---
>  2 files changed, 32 insertions(+), 28 deletions(-)

I need some help. This patch makes compiling warning for the following
targets

mgcoge kmsupx5 suvd3 mgcoge3ne kmopti2 tuge1 kmvect1 kmcoge5ne pdm360ng
kmeter1 tuxx1

cramfs.c: In function 'cramfs_read_super':
cramfs.c:56:18: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c:61:19: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c: In function 'cramfs_list_inode':
cramfs.c:211:31: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c: In function 'cramfs_ls':
cramfs.c:281:11: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c:294:11: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c: In function 'cramfs_check':
cramfs.c:339:7: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
cramfs.c:342:8: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Can you fix them?

York
diff mbox

Patch

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 3023479..453ed57 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -93,13 +93,13 @@ 
 DECLARE_GLOBAL_DATA_PTR;
 
 /* special size referring to all the remaining space in a partition */
-#define SIZE_REMAINING		0xFFFFFFFF
+#define SIZE_REMAINING		(~0llu)
 
 /* special offset value, it is used when not provided by user
  *
  * this value is used temporarily during parsing, later such offests
  * are recalculated */
-#define OFFSET_NOT_SPECIFIED	0xFFFFFFFF
+#define OFFSET_NOT_SPECIFIED	(~0llu)
 
 /* minimum partition size */
 #define MIN_PART_SIZE		4096
@@ -160,9 +160,9 @@  static int device_del(struct mtd_device *dev);
  * @param retptr output pointer to next char after parse completes (output)
  * @return resulting unsigned int
  */
-static unsigned long memsize_parse (const char *const ptr, const char **retptr)
+static u64 memsize_parse (const char *const ptr, const char **retptr)
 {
-	unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
+	u64 ret = simple_strtoull(ptr, (char **)retptr, 0);
 
 	switch (**retptr) {
 		case 'G':
@@ -193,20 +193,20 @@  static unsigned long memsize_parse (const char *const ptr, const char **retptr)
  * @param buf output buffer
  * @param size size to be converted to string
  */
-static void memsize_format(char *buf, u32 size)
+static void memsize_format(char *buf, u64 size)
 {
 #define SIZE_GB ((u32)1024*1024*1024)
 #define SIZE_MB ((u32)1024*1024)
 #define SIZE_KB ((u32)1024)
 
 	if ((size % SIZE_GB) == 0)
-		sprintf(buf, "%ug", size/SIZE_GB);
+		sprintf(buf, "%llug", size/SIZE_GB);
 	else if ((size % SIZE_MB) == 0)
-		sprintf(buf, "%um", size/SIZE_MB);
+		sprintf(buf, "%llum", size/SIZE_MB);
 	else if (size % SIZE_KB == 0)
-		sprintf(buf, "%uk", size/SIZE_KB);
+		sprintf(buf, "%lluk", size/SIZE_KB);
 	else
-		sprintf(buf, "%u", size);
+		sprintf(buf, "%llu", size);
 }
 
 /**
@@ -310,6 +310,7 @@  static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 	struct mtd_info *mtd = NULL;
 	int i, j;
 	ulong start;
+	u64 offset, size;
 
 	if (get_mtd_info(id->type, id->num, &mtd))
 		return 1;
@@ -321,14 +322,16 @@  static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 		 * Only one eraseregion (NAND, OneNAND or uniform NOR),
 		 * checking for alignment is easy here
 		 */
-		if ((unsigned long)part->offset % mtd->erasesize) {
+		offset = part->offset;
+		if (do_div(offset, mtd->erasesize)) {
 			printf("%s%d: partition (%s) start offset"
 			       "alignment incorrect\n",
 			       MTD_DEV_TYPE(id->type), id->num, part->name);
 			return 1;
 		}
 
-		if (part->size % mtd->erasesize) {
+		size = part->size;
+		if (do_div(size, mtd->erasesize)) {
 			printf("%s%d: partition (%s) size alignment incorrect\n",
 			       MTD_DEV_TYPE(id->type), id->num, part->name);
 			return 1;
@@ -396,7 +399,7 @@  static int part_validate(struct mtdids *id, struct part_info *part)
 		part->size = id->size - part->offset;
 
 	if (part->offset > id->size) {
-		printf("%s: offset %08x beyond flash size %08x\n",
+		printf("%s: offset %08llx beyond flash size %08llx\n",
 				id->mtd_id, part->offset, id->size);
 		return 1;
 	}
@@ -579,8 +582,8 @@  static int part_add(struct mtd_device *dev, struct part_info *part)
 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
 {
 	struct part_info *part;
-	unsigned long size;
-	unsigned long offset;
+	u64 size;
+	u64 offset;
 	const char *name;
 	int name_len;
 	unsigned int mask_flags;
@@ -599,7 +602,7 @@  static int part_parse(const char *const partdef, const char **ret, struct part_i
 	} else {
 		size = memsize_parse(p, &p);
 		if (size < MIN_PART_SIZE) {
-			printf("partition size too small (%lx)\n", size);
+			printf("partition size too small (%llx)\n", size);
 			return 1;
 		}
 	}
@@ -671,14 +674,14 @@  static int part_parse(const char *const partdef, const char **ret, struct part_i
 		part->auto_name = 0;
 	} else {
 		/* auto generated name in form of size@offset */
-		sprintf(part->name, "0x%08lx@0x%08lx", size, offset);
+		sprintf(part->name, "0x%08llx@0x%08llx", size, offset);
 		part->auto_name = 1;
 	}
 
 	part->name[name_len - 1] = '\0';
 	INIT_LIST_HEAD(&part->link);
 
-	debug("+ partition: name %-22s size 0x%08x offset 0x%08x mask flags %d\n",
+	debug("+ partition: name %-22s size 0x%08llx offset 0x%08llx mask flags %d\n",
 			part->name, part->size,
 			part->offset, part->mask_flags);
 
@@ -694,7 +697,7 @@  static int part_parse(const char *const partdef, const char **ret, struct part_i
  * @param size a pointer to the size of the mtd device (output)
  * @return 0 if device is valid, 1 otherwise
  */
-static int mtd_device_validate(u8 type, u8 num, u32 *size)
+static int mtd_device_validate(u8 type, u8 num, u64 *size)
 {
 	struct mtd_info *mtd = NULL;
 
@@ -827,7 +830,7 @@  static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	LIST_HEAD(tmp_list);
 	struct list_head *entry, *n;
 	u16 num_parts;
-	u32 offset;
+	u64 offset;
 	int err = 1;
 
 	debug("===device_parse===\n");
@@ -1072,7 +1075,8 @@  static int generate_mtdparts(char *buf, u32 buflen)
 	struct part_info *part, *prev_part;
 	char *p = buf;
 	char tmpbuf[32];
-	u32 size, offset, len, part_cnt;
+	u64 size, offset;
+	u32 len, part_cnt;
 	u32 maxlen = buflen - 1;
 
 	debug("--- generate_mtdparts ---\n");
@@ -1271,7 +1275,7 @@  static void print_partition_table(void)
 
 		list_for_each(pentry, &dev->parts) {
 			part = list_entry(pentry, struct part_info, link);
-			printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
+			printf("%2d: %-20s0x%08llx\t0x%08llx\t%d\n",
 					part_num, part->name, part->size,
 					part->offset, part->mask_flags);
 #endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
@@ -1298,7 +1302,7 @@  static void list_partitions(void)
 	if (current_mtd_dev) {
 		part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
 		if (part) {
-			printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n",
+			printf("\nactive partition: %s%d,%d - (%s) 0x%08llx @ 0x%08llx\n",
 					MTD_DEV_TYPE(current_mtd_dev->id->type),
 					current_mtd_dev->id->num, current_mtd_partnum,
 					part->name, part->size, part->offset);
@@ -1398,7 +1402,7 @@  static int delete_partition(const char *id)
 
 	if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
 
-		debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08x@0x%08x\n",
+		debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08llx@0x%08llx\n",
 				MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
 				part->name, part->size, part->offset);
 
@@ -1590,7 +1594,7 @@  static int parse_mtdids(const char *const ids)
 	struct list_head *entry, *n;
 	struct mtdids *id_tmp;
 	u8 type, num;
-	u32 size;
+	u64 size;
 	int ret = 1;
 
 	debug("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
@@ -1664,7 +1668,7 @@  static int parse_mtdids(const char *const ids)
 		id->mtd_id[mtd_id_len - 1] = '\0';
 		INIT_LIST_HEAD(&id->link);
 
-		debug("+ id %s%d\t%16d bytes\t%s\n",
+		debug("+ id %s%d\t%16lld bytes\t%s\n",
 				MTD_DEV_TYPE(id->type), id->num,
 				id->size, id->mtd_id);
 
diff --git a/include/jffs2/load_kernel.h b/include/jffs2/load_kernel.h
index e1943e5..dd0d23f 100644
--- a/include/jffs2/load_kernel.h
+++ b/include/jffs2/load_kernel.h
@@ -32,8 +32,8 @@  struct part_info {
 	struct list_head link;
 	char *name;			/* partition name */
 	u8 auto_name;			/* set to 1 for generated name */
-	u32 size;			/* total size of the partition */
-	u32 offset;			/* offset within device */
+	u64 size;			/* total size of the partition */
+	u64 offset;			/* offset within device */
 	void *jffs2_priv;		/* used internaly by jffs2 */
 	u32 mask_flags;			/* kernel MTD mask flags */
 	u32 sector_size;		/* size of sector */
@@ -44,7 +44,7 @@  struct mtdids {
 	struct list_head link;
 	u8 type;			/* device type */
 	u8 num;				/* device number */
-	u32 size;			/* device size */
+	u64 size;			/* device size */
 	char *mtd_id;			/* linux kernel device id */
 };