Commit 39ac34473f3c96e77cbe03a49141771ed1639486

Authored by Paul Burton
Committed by Scott Wood
1 parent 40462e541d

cmd_mtdparts: use 64 bits for flash size, partition size & offset

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>
Acked-by: Stefan Roese <sr@denx.de>

Showing 2 changed files with 32 additions and 28 deletions Side-by-side Diff

common/cmd_mtdparts.c
... ... @@ -93,13 +93,13 @@
93 93 DECLARE_GLOBAL_DATA_PTR;
94 94  
95 95 /* special size referring to all the remaining space in a partition */
96   -#define SIZE_REMAINING 0xFFFFFFFF
  96 +#define SIZE_REMAINING (~0llu)
97 97  
98 98 /* special offset value, it is used when not provided by user
99 99 *
100 100 * this value is used temporarily during parsing, later such offests
101 101 * are recalculated */
102   -#define OFFSET_NOT_SPECIFIED 0xFFFFFFFF
  102 +#define OFFSET_NOT_SPECIFIED (~0llu)
103 103  
104 104 /* minimum partition size */
105 105 #define MIN_PART_SIZE 4096
106 106  
... ... @@ -160,9 +160,9 @@
160 160 * @param retptr output pointer to next char after parse completes (output)
161 161 * @return resulting unsigned int
162 162 */
163   -static unsigned long memsize_parse (const char *const ptr, const char **retptr)
  163 +static u64 memsize_parse (const char *const ptr, const char **retptr)
164 164 {
165   - unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
  165 + u64 ret = simple_strtoull(ptr, (char **)retptr, 0);
166 166  
167 167 switch (**retptr) {
168 168 case 'G':
169 169  
170 170  
171 171  
172 172  
... ... @@ -193,20 +193,20 @@
193 193 * @param buf output buffer
194 194 * @param size size to be converted to string
195 195 */
196   -static void memsize_format(char *buf, u32 size)
  196 +static void memsize_format(char *buf, u64 size)
197 197 {
198 198 #define SIZE_GB ((u32)1024*1024*1024)
199 199 #define SIZE_MB ((u32)1024*1024)
200 200 #define SIZE_KB ((u32)1024)
201 201  
202 202 if ((size % SIZE_GB) == 0)
203   - sprintf(buf, "%ug", size/SIZE_GB);
  203 + sprintf(buf, "%llug", size/SIZE_GB);
204 204 else if ((size % SIZE_MB) == 0)
205   - sprintf(buf, "%um", size/SIZE_MB);
  205 + sprintf(buf, "%llum", size/SIZE_MB);
206 206 else if (size % SIZE_KB == 0)
207   - sprintf(buf, "%uk", size/SIZE_KB);
  207 + sprintf(buf, "%lluk", size/SIZE_KB);
208 208 else
209   - sprintf(buf, "%u", size);
  209 + sprintf(buf, "%llu", size);
210 210 }
211 211  
212 212 /**
... ... @@ -310,6 +310,7 @@
310 310 struct mtd_info *mtd = NULL;
311 311 int i, j;
312 312 ulong start;
  313 + u64 offset, size;
313 314  
314 315 if (get_mtd_info(id->type, id->num, &mtd))
315 316 return 1;
316 317  
... ... @@ -321,14 +322,16 @@
321 322 * Only one eraseregion (NAND, OneNAND or uniform NOR),
322 323 * checking for alignment is easy here
323 324 */
324   - if ((unsigned long)part->offset % mtd->erasesize) {
  325 + offset = part->offset;
  326 + if (do_div(offset, mtd->erasesize)) {
325 327 printf("%s%d: partition (%s) start offset"
326 328 "alignment incorrect\n",
327 329 MTD_DEV_TYPE(id->type), id->num, part->name);
328 330 return 1;
329 331 }
330 332  
331   - if (part->size % mtd->erasesize) {
  333 + size = part->size;
  334 + if (do_div(size, mtd->erasesize)) {
332 335 printf("%s%d: partition (%s) size alignment incorrect\n",
333 336 MTD_DEV_TYPE(id->type), id->num, part->name);
334 337 return 1;
... ... @@ -395,7 +398,7 @@
395 398 part->size = id->size - part->offset;
396 399  
397 400 if (part->offset > id->size) {
398   - printf("%s: offset %08x beyond flash size %08x\n",
  401 + printf("%s: offset %08llx beyond flash size %08llx\n",
399 402 id->mtd_id, part->offset, id->size);
400 403 return 1;
401 404 }
... ... @@ -578,8 +581,8 @@
578 581 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
579 582 {
580 583 struct part_info *part;
581   - unsigned long size;
582   - unsigned long offset;
  584 + u64 size;
  585 + u64 offset;
583 586 const char *name;
584 587 int name_len;
585 588 unsigned int mask_flags;
... ... @@ -598,7 +601,7 @@
598 601 } else {
599 602 size = memsize_parse(p, &p);
600 603 if (size < MIN_PART_SIZE) {
601   - printf("partition size too small (%lx)\n", size);
  604 + printf("partition size too small (%llx)\n", size);
602 605 return 1;
603 606 }
604 607 }
605 608  
... ... @@ -670,14 +673,14 @@
670 673 part->auto_name = 0;
671 674 } else {
672 675 /* auto generated name in form of size@offset */
673   - sprintf(part->name, "0x%08lx@0x%08lx", size, offset);
  676 + sprintf(part->name, "0x%08llx@0x%08llx", size, offset);
674 677 part->auto_name = 1;
675 678 }
676 679  
677 680 part->name[name_len - 1] = '\0';
678 681 INIT_LIST_HEAD(&part->link);
679 682  
680   - debug("+ partition: name %-22s size 0x%08x offset 0x%08x mask flags %d\n",
  683 + debug("+ partition: name %-22s size 0x%08llx offset 0x%08llx mask flags %d\n",
681 684 part->name, part->size,
682 685 part->offset, part->mask_flags);
683 686  
... ... @@ -693,7 +696,7 @@
693 696 * @param size a pointer to the size of the mtd device (output)
694 697 * @return 0 if device is valid, 1 otherwise
695 698 */
696   -static int mtd_device_validate(u8 type, u8 num, u32 *size)
  699 +static int mtd_device_validate(u8 type, u8 num, u64 *size)
697 700 {
698 701 struct mtd_info *mtd = NULL;
699 702  
... ... @@ -826,7 +829,7 @@
826 829 LIST_HEAD(tmp_list);
827 830 struct list_head *entry, *n;
828 831 u16 num_parts;
829   - u32 offset;
  832 + u64 offset;
830 833 int err = 1;
831 834  
832 835 debug("===device_parse===\n");
... ... @@ -1071,7 +1074,8 @@
1071 1074 struct part_info *part, *prev_part;
1072 1075 char *p = buf;
1073 1076 char tmpbuf[32];
1074   - u32 size, offset, len, part_cnt;
  1077 + u64 size, offset;
  1078 + u32 len, part_cnt;
1075 1079 u32 maxlen = buflen - 1;
1076 1080  
1077 1081 debug("--- generate_mtdparts ---\n");
... ... @@ -1270,7 +1274,7 @@
1270 1274  
1271 1275 list_for_each(pentry, &dev->parts) {
1272 1276 part = list_entry(pentry, struct part_info, link);
1273   - printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
  1277 + printf("%2d: %-20s0x%08llx\t0x%08llx\t%d\n",
1274 1278 part_num, part->name, part->size,
1275 1279 part->offset, part->mask_flags);
1276 1280 #endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
... ... @@ -1297,7 +1301,7 @@
1297 1301 if (current_mtd_dev) {
1298 1302 part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
1299 1303 if (part) {
1300   - printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n",
  1304 + printf("\nactive partition: %s%d,%d - (%s) 0x%08llx @ 0x%08llx\n",
1301 1305 MTD_DEV_TYPE(current_mtd_dev->id->type),
1302 1306 current_mtd_dev->id->num, current_mtd_partnum,
1303 1307 part->name, part->size, part->offset);
... ... @@ -1397,7 +1401,7 @@
1397 1401  
1398 1402 if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
1399 1403  
1400   - debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08x@0x%08x\n",
  1404 + debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08llx@0x%08llx\n",
1401 1405 MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
1402 1406 part->name, part->size, part->offset);
1403 1407  
... ... @@ -1589,7 +1593,7 @@
1589 1593 struct list_head *entry, *n;
1590 1594 struct mtdids *id_tmp;
1591 1595 u8 type, num;
1592   - u32 size;
  1596 + u64 size;
1593 1597 int ret = 1;
1594 1598  
1595 1599 debug("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
... ... @@ -1663,7 +1667,7 @@
1663 1667 id->mtd_id[mtd_id_len - 1] = '\0';
1664 1668 INIT_LIST_HEAD(&id->link);
1665 1669  
1666   - debug("+ id %s%d\t%16d bytes\t%s\n",
  1670 + debug("+ id %s%d\t%16lld bytes\t%s\n",
1667 1671 MTD_DEV_TYPE(id->type), id->num,
1668 1672 id->size, id->mtd_id);
1669 1673  
include/jffs2/load_kernel.h
... ... @@ -32,8 +32,8 @@
32 32 struct list_head link;
33 33 char *name; /* partition name */
34 34 u8 auto_name; /* set to 1 for generated name */
35   - u32 size; /* total size of the partition */
36   - u32 offset; /* offset within device */
  35 + u64 size; /* total size of the partition */
  36 + u64 offset; /* offset within device */
37 37 void *jffs2_priv; /* used internaly by jffs2 */
38 38 u32 mask_flags; /* kernel MTD mask flags */
39 39 u32 sector_size; /* size of sector */
... ... @@ -44,7 +44,7 @@
44 44 struct list_head link;
45 45 u8 type; /* device type */
46 46 u8 num; /* device number */
47   - u32 size; /* device size */
  47 + u64 size; /* device size */
48 48 char *mtd_id; /* linux kernel device id */
49 49 };
50 50