Re: [U-Boot] [PATCH v3 2/3] mtd, nand: move common functions from cmd_nand.c to common place
Hello Jagan, Am 04.11.2014 21:55, schrieb Jagan Teki: Hi Heiko Schocher, Nice pick - On 5 September 2014 11:08, Heiko Schocherh...@denx.de wrote: move common functions from cmd_nand.c (for calculating offset and size from cmdline paramter) to common place, so they could used from other commands which use mtd partitions. For onenand the arg_off_size() is left in common/cmd_onenand.c. It should use now the common arg_off() function, but as I could not test onenand I let it there ... Signed-off-by: Heiko Schocherh...@denx.de Cc: Scott Woodscottw...@freescale.com Cc: Tom Rinitr...@ti.com --- - changes for v2: none - changes for v3: - add comments from scott wood: - align MTD_DEV_TYPE_NAND correct - remove unnecessary inline - rework jffs2 header problem later - rebase with d6c1ffc7d23f4fe4ae8c91101861055b8e1501b6 --- common/cmd_nand.c | 140 +--- common/cmd_onenand.c| 19 +++ drivers/mtd/Makefile| 4 +- drivers/mtd/mtd_uboot.c | 114 +++ include/linux/mtd/mtd.h | 7 +++ 5 files changed, 154 insertions(+), 130 deletions(-) create mode 100644 drivers/mtd/mtd_uboot.c diff --git a/common/cmd_nand.c b/common/cmd_nand.c index f9ced9d..099ba00 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -133,115 +133,6 @@ static int set_dev(int dev) return 0; } -static inline int str2off(const char *p, loff_t *num) -{ - char *endptr; - - *num = simple_strtoull(p,endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static inline int str2long(const char *p, ulong *num) -{ - char *endptr; - - *num = simple_strtoul(p,endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ -#ifdef CONFIG_CMD_MTDPARTS - struct mtd_device *dev; - struct part_info *part; - u8 pnum; - int ret; - - ret = mtdparts_init(); - if (ret) - return ret; - - ret = find_dev_and_part(partname,dev,pnum,part); - if (ret) - return ret; - - if (dev-id-type != MTD_DEV_TYPE_NAND) { - puts(not a NAND device\n); - return -1; - } - - *off = part-offset; - *size = part-size; - *maxsize = part-size; - *idx = dev-id-num; - - ret = set_dev(*idx); - if (ret) - return ret; - - return 0; -#else - puts(offset is not a number\n); - return -1; -#endif -} - -static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ - if (!str2off(arg, off)) - return get_part(arg, idx, off, size, maxsize); - - if (*off= nand_info[*idx].size) { - puts(Offset exceeds device limit\n); - return -1; - } - - *maxsize = nand_info[*idx].size - *off; - *size = *maxsize; - return 0; -} - -static int arg_off_size(int argc, char *const argv[], int *idx, - loff_t *off, loff_t *size, loff_t *maxsize) -{ - int ret; - - if (argc == 0) { - *off = 0; - *size = nand_info[*idx].size; - *maxsize = *size; - goto print; - } - - ret = arg_off(argv[0], idx, off, size, maxsize); - if (ret) - return ret; - - if (argc == 1) - goto print; - - if (!str2off(argv[1], size)) { - printf('%s' is not a number\n, argv[1]); - return -1; - } - - if (*size *maxsize) { - puts(Size exceeds partition or device limit\n); - return -1; - } - -print: - printf(device %d , *idx); - if (*size == nand_info[*idx].size) - puts(whole chip\n); - else - printf(offset 0x%llx, size 0x%llx\n, - (unsigned long long)*off, (unsigned long long)*size); - return 0; -} - #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK static void print_status(ulong start, ulong end, ulong erasesize, int status) { @@ -322,7 +213,12 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) goto usage; /* We don't care about size, or maxsize. */ - if (arg_off(argv[2],idx,addr,maxsize,maxsize)) { + if (arg_off(argv[2],idx,addr,maxsize,maxsize, + MTD_DEV_TYPE_NAND, nand_info[idx].size)) { + puts(Offset or partition name expected\n); + return 1; + } + if (set_dev(idx)) { puts(Offset or partition name expected\n); return 1; } @@ -592,7 +488,10 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const
Re: [U-Boot] [PATCH v3 2/3] mtd, nand: move common functions from cmd_nand.c to common place
Hi Heiko Schocher, Nice pick - On 5 September 2014 11:08, Heiko Schocher h...@denx.de wrote: move common functions from cmd_nand.c (for calculating offset and size from cmdline paramter) to common place, so they could used from other commands which use mtd partitions. For onenand the arg_off_size() is left in common/cmd_onenand.c. It should use now the common arg_off() function, but as I could not test onenand I let it there ... Signed-off-by: Heiko Schocher h...@denx.de Cc: Scott Wood scottw...@freescale.com Cc: Tom Rini tr...@ti.com --- - changes for v2: none - changes for v3: - add comments from scott wood: - align MTD_DEV_TYPE_NAND correct - remove unnecessary inline - rework jffs2 header problem later - rebase with d6c1ffc7d23f4fe4ae8c91101861055b8e1501b6 --- common/cmd_nand.c | 140 +--- common/cmd_onenand.c| 19 +++ drivers/mtd/Makefile| 4 +- drivers/mtd/mtd_uboot.c | 114 +++ include/linux/mtd/mtd.h | 7 +++ 5 files changed, 154 insertions(+), 130 deletions(-) create mode 100644 drivers/mtd/mtd_uboot.c diff --git a/common/cmd_nand.c b/common/cmd_nand.c index f9ced9d..099ba00 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -133,115 +133,6 @@ static int set_dev(int dev) return 0; } -static inline int str2off(const char *p, loff_t *num) -{ - char *endptr; - - *num = simple_strtoull(p, endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static inline int str2long(const char *p, ulong *num) -{ - char *endptr; - - *num = simple_strtoul(p, endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ -#ifdef CONFIG_CMD_MTDPARTS - struct mtd_device *dev; - struct part_info *part; - u8 pnum; - int ret; - - ret = mtdparts_init(); - if (ret) - return ret; - - ret = find_dev_and_part(partname, dev, pnum, part); - if (ret) - return ret; - - if (dev-id-type != MTD_DEV_TYPE_NAND) { - puts(not a NAND device\n); - return -1; - } - - *off = part-offset; - *size = part-size; - *maxsize = part-size; - *idx = dev-id-num; - - ret = set_dev(*idx); - if (ret) - return ret; - - return 0; -#else - puts(offset is not a number\n); - return -1; -#endif -} - -static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ - if (!str2off(arg, off)) - return get_part(arg, idx, off, size, maxsize); - - if (*off = nand_info[*idx].size) { - puts(Offset exceeds device limit\n); - return -1; - } - - *maxsize = nand_info[*idx].size - *off; - *size = *maxsize; - return 0; -} - -static int arg_off_size(int argc, char *const argv[], int *idx, - loff_t *off, loff_t *size, loff_t *maxsize) -{ - int ret; - - if (argc == 0) { - *off = 0; - *size = nand_info[*idx].size; - *maxsize = *size; - goto print; - } - - ret = arg_off(argv[0], idx, off, size, maxsize); - if (ret) - return ret; - - if (argc == 1) - goto print; - - if (!str2off(argv[1], size)) { - printf('%s' is not a number\n, argv[1]); - return -1; - } - - if (*size *maxsize) { - puts(Size exceeds partition or device limit\n); - return -1; - } - -print: - printf(device %d , *idx); - if (*size == nand_info[*idx].size) - puts(whole chip\n); - else - printf(offset 0x%llx, size 0x%llx\n, - (unsigned long long)*off, (unsigned long long)*size); - return 0; -} - #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK static void print_status(ulong start, ulong end, ulong erasesize, int status) { @@ -322,7 +213,12 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) goto usage; /* We don't care about size, or maxsize. */ - if (arg_off(argv[2], idx, addr, maxsize, maxsize)) { + if (arg_off(argv[2], idx, addr, maxsize, maxsize, + MTD_DEV_TYPE_NAND, nand_info[idx].size)) { + puts(Offset or partition name expected\n); + return 1; + } + if (set_dev(idx)) { puts(Offset or partition name expected\n); return 1;
[U-Boot] [PATCH v3 2/3] mtd, nand: move common functions from cmd_nand.c to common place
move common functions from cmd_nand.c (for calculating offset and size from cmdline paramter) to common place, so they could used from other commands which use mtd partitions. For onenand the arg_off_size() is left in common/cmd_onenand.c. It should use now the common arg_off() function, but as I could not test onenand I let it there ... Signed-off-by: Heiko Schocher h...@denx.de Cc: Scott Wood scottw...@freescale.com Cc: Tom Rini tr...@ti.com --- - changes for v2: none - changes for v3: - add comments from scott wood: - align MTD_DEV_TYPE_NAND correct - remove unnecessary inline - rework jffs2 header problem later - rebase with d6c1ffc7d23f4fe4ae8c91101861055b8e1501b6 --- common/cmd_nand.c | 140 +--- common/cmd_onenand.c| 19 +++ drivers/mtd/Makefile| 4 +- drivers/mtd/mtd_uboot.c | 114 +++ include/linux/mtd/mtd.h | 7 +++ 5 files changed, 154 insertions(+), 130 deletions(-) create mode 100644 drivers/mtd/mtd_uboot.c diff --git a/common/cmd_nand.c b/common/cmd_nand.c index f9ced9d..099ba00 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -133,115 +133,6 @@ static int set_dev(int dev) return 0; } -static inline int str2off(const char *p, loff_t *num) -{ - char *endptr; - - *num = simple_strtoull(p, endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static inline int str2long(const char *p, ulong *num) -{ - char *endptr; - - *num = simple_strtoul(p, endptr, 16); - return *p != '\0' *endptr == '\0'; -} - -static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ -#ifdef CONFIG_CMD_MTDPARTS - struct mtd_device *dev; - struct part_info *part; - u8 pnum; - int ret; - - ret = mtdparts_init(); - if (ret) - return ret; - - ret = find_dev_and_part(partname, dev, pnum, part); - if (ret) - return ret; - - if (dev-id-type != MTD_DEV_TYPE_NAND) { - puts(not a NAND device\n); - return -1; - } - - *off = part-offset; - *size = part-size; - *maxsize = part-size; - *idx = dev-id-num; - - ret = set_dev(*idx); - if (ret) - return ret; - - return 0; -#else - puts(offset is not a number\n); - return -1; -#endif -} - -static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, - loff_t *maxsize) -{ - if (!str2off(arg, off)) - return get_part(arg, idx, off, size, maxsize); - - if (*off = nand_info[*idx].size) { - puts(Offset exceeds device limit\n); - return -1; - } - - *maxsize = nand_info[*idx].size - *off; - *size = *maxsize; - return 0; -} - -static int arg_off_size(int argc, char *const argv[], int *idx, - loff_t *off, loff_t *size, loff_t *maxsize) -{ - int ret; - - if (argc == 0) { - *off = 0; - *size = nand_info[*idx].size; - *maxsize = *size; - goto print; - } - - ret = arg_off(argv[0], idx, off, size, maxsize); - if (ret) - return ret; - - if (argc == 1) - goto print; - - if (!str2off(argv[1], size)) { - printf('%s' is not a number\n, argv[1]); - return -1; - } - - if (*size *maxsize) { - puts(Size exceeds partition or device limit\n); - return -1; - } - -print: - printf(device %d , *idx); - if (*size == nand_info[*idx].size) - puts(whole chip\n); - else - printf(offset 0x%llx, size 0x%llx\n, - (unsigned long long)*off, (unsigned long long)*size); - return 0; -} - #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK static void print_status(ulong start, ulong end, ulong erasesize, int status) { @@ -322,7 +213,12 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) goto usage; /* We don't care about size, or maxsize. */ - if (arg_off(argv[2], idx, addr, maxsize, maxsize)) { + if (arg_off(argv[2], idx, addr, maxsize, maxsize, + MTD_DEV_TYPE_NAND, nand_info[idx].size)) { + puts(Offset or partition name expected\n); + return 1; + } + if (set_dev(idx)) { puts(Offset or partition name expected\n); return 1; } @@ -592,7 +488,10 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf(\nNAND %s: , cmd); /* skip first two or three arguments, look for offset and size */ if