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.bur...@imgtec.com
---
common/cmd_mtdparts.c | 54 -
include/jffs2/load_kernel.h | 6 ++---
2 files changed, 32 insertions(+), 28 deletions(-)
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 0x
+#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 0x
+#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,