Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-24 Thread Heiko Schocher

Hello Scott,

Am 23.04.2015 19:48, schrieb Scott Wood:

On Thu, 2015-04-23 at 13:12 +0200, Heiko Schocher wrote:

Hello Scott,

Am 23.04.2015 08:55, schrieb Scott Wood:

On Thu, 2015-04-23 at 07:57 +0200, Heiko Schocher wrote:

Hello Scott,

Am 23.04.2015 00:47, schrieb Scott Wood:

On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:

+int str2off(const char *p, loff_t *num);
+int str2long(const char *p, ulong *num);


These should be moved somewhere more generic, especially if they're no
longer file-local.


Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
we add a mtd_ prefix to them? I think these functions are mtd specific ...


What is mtd-specific about them?


Hmm... I thought:

return *p != '\0'  *endptr == '\0';

is more or less mtd specific ... but you are right, it is not really
mtd specific ... so I move them to ./lib/vsprintf.c ... Ok?


OK.  Maybe change the return to bool while you're at it, to make it
clear that it isn't return-zero-on-success.


Hmm.. tried this, but I get:

  CC  common/cmd_test.o
In file included from /home/hs/abb/imx6/u-boot/include/common.h:760:0,
 from /home/hs/abb/imx6/u-boot/common/cmd_test.c:17:
/home/hs/abb/imx6/u-boot/include/vsprintf.h:176:1: error: unknown type name 
'bool'
/home/hs/abb/imx6/u-boot/include/vsprintf.h:177:1: error: unknown type name 
'bool'
/home/hs/abb/imx6/u-boot/scripts/Makefile.build:276: recipe for target 
'common/cmd_test.o' failed
make[2]: *** [common/cmd_test.o] Error 1
/home/hs/abb/imx6/u-boot/Makefile:1156: recipe for target 'common' failed
make[1]: *** [common] Error 2

reason is in common/cmd_test.c:

/*
 * Define _STDBOOL_H here to avoid macro expansion of true and false.
 * If the future code requires macro true or false, remove this define
 * and undef true and false before U_BOOT_CMD. This define and comment
 * shall be removed if change to U_BOOT_CMD is made to take string
 * instead of stringifying it.
 */
#define _STDBOOL_H

#include common.h

Hmm... I tend to say, this is another patch changing the returntype
from int to bool ...

bye,
Heiko
--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-24 Thread Scott Wood
On Fri, 2015-04-24 at 06:59 +0200, Heiko Schocher wrote:
 Hello Scott,
 
 Am 23.04.2015 19:48, schrieb Scott Wood:
  On Thu, 2015-04-23 at 13:12 +0200, Heiko Schocher wrote:
  Hello Scott,
 
  Am 23.04.2015 08:55, schrieb Scott Wood:
  On Thu, 2015-04-23 at 07:57 +0200, Heiko Schocher wrote:
  Hello Scott,
 
  Am 23.04.2015 00:47, schrieb Scott Wood:
  On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:
  +int str2off(const char *p, loff_t *num);
  +int str2long(const char *p, ulong *num);
 
  These should be moved somewhere more generic, especially if they're no
  longer file-local.
 
  Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
  we add a mtd_ prefix to them? I think these functions are mtd specific 
  ...
 
  What is mtd-specific about them?
 
  Hmm... I thought:
 
  return *p != '\0'  *endptr == '\0';
 
  is more or less mtd specific ... but you are right, it is not really
  mtd specific ... so I move them to ./lib/vsprintf.c ... Ok?
 
  OK.  Maybe change the return to bool while you're at it, to make it
  clear that it isn't return-zero-on-success.
 
 Hmm.. tried this, but I get:
 
CC  common/cmd_test.o
 In file included from /home/hs/abb/imx6/u-boot/include/common.h:760:0,
   from /home/hs/abb/imx6/u-boot/common/cmd_test.c:17:
 /home/hs/abb/imx6/u-boot/include/vsprintf.h:176:1: error: unknown type name 
 'bool'
 /home/hs/abb/imx6/u-boot/include/vsprintf.h:177:1: error: unknown type name 
 'bool'
 /home/hs/abb/imx6/u-boot/scripts/Makefile.build:276: recipe for target 
 'common/cmd_test.o' failed
 make[2]: *** [common/cmd_test.o] Error 1
 /home/hs/abb/imx6/u-boot/Makefile:1156: recipe for target 'common' failed
 make[1]: *** [common] Error 2
 
 reason is in common/cmd_test.c:
 
 /*
   * Define _STDBOOL_H here to avoid macro expansion of true and false.
   * If the future code requires macro true or false, remove this define
   * and undef true and false before U_BOOT_CMD. This define and comment
   * shall be removed if change to U_BOOT_CMD is made to take string
   * instead of stringifying it.
   */
 #define _STDBOOL_H

Ugh.  Maybe add a variant of U_BOOT_CMD_COMPLETE that takes a string for
the user-visible name that is separate from the C-visible symbol used
for the ll entry.

Or you could either define bool manually, or do what the comment says
and undef true/false.

 #include common.h
 
 Hmm... I tend to say, this is another patch changing the returntype
 from int to bool ...

It's related because you're moving it from being a local static function
to being an API exposed treewide, so higher standards apply.

Another option would be to convert it to returning zero on success and a
negative error code on error.

-Scott


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-23 Thread Scott Wood
On Thu, 2015-04-23 at 13:12 +0200, Heiko Schocher wrote:
 Hello Scott,
 
 Am 23.04.2015 08:55, schrieb Scott Wood:
  On Thu, 2015-04-23 at 07:57 +0200, Heiko Schocher wrote:
  Hello Scott,
 
  Am 23.04.2015 00:47, schrieb Scott Wood:
  On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:
  +int str2off(const char *p, loff_t *num);
  +int str2long(const char *p, ulong *num);
 
  These should be moved somewhere more generic, especially if they're no
  longer file-local.
 
  Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
  we add a mtd_ prefix to them? I think these functions are mtd specific 
  ...
 
  What is mtd-specific about them?
 
 Hmm... I thought:
 
 return *p != '\0'  *endptr == '\0';
 
 is more or less mtd specific ... but you are right, it is not really
 mtd specific ... so I move them to ./lib/vsprintf.c ... Ok?

OK.  Maybe change the return to bool while you're at it, to make it
clear that it isn't return-zero-on-success.

-Scott


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-23 Thread Scott Wood
On Thu, 2015-04-23 at 07:57 +0200, Heiko Schocher wrote:
 Hello Scott,
 
 Am 23.04.2015 00:47, schrieb Scott Wood:
  On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:
  @@ -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;
  +  }
 
  Use only one tab per indentation level.
 
 You mean the line MTD_DEV_TYPE_NAND, nand_info[idx].size)) { ?
 
 I have to move MTD_xx to the opening bracket to avoid checkpatch.pl
 errors ...
 
 If you mean the puts ... line ... fixed.

I meant the puts and return lines.

  diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
  index 8666413..2861af5 100644
  --- a/include/linux/mtd/mtd.h
  +++ b/include/linux/mtd/mtd.h
  @@ -482,5 +482,12 @@ int add_mtd_device(struct mtd_info *mtd);
int del_mtd_device(struct mtd_info *mtd);
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, 
  int);
int del_mtd_partitions(struct mtd_info *);
  +
  +int str2off(const char *p, loff_t *num);
  +int str2long(const char *p, ulong *num);
 
  These should be moved somewhere more generic, especially if they're no
  longer file-local.
 
 Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
 we add a mtd_ prefix to them? I think these functions are mtd specific ...

What is mtd-specific about them?

-Scott


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-23 Thread Heiko Schocher

Hello Scott,

Am 23.04.2015 08:55, schrieb Scott Wood:

On Thu, 2015-04-23 at 07:57 +0200, Heiko Schocher wrote:

Hello Scott,

Am 23.04.2015 00:47, schrieb Scott Wood:

On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:

@@ -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;
+   }


Use only one tab per indentation level.


You mean the line MTD_DEV_TYPE_NAND, nand_info[idx].size)) { ?

I have to move MTD_xx to the opening bracket to avoid checkpatch.pl
errors ...

If you mean the puts ... line ... fixed.


I meant the puts and return lines.


diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 8666413..2861af5 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -482,5 +482,12 @@ int add_mtd_device(struct mtd_info *mtd);
   int del_mtd_device(struct mtd_info *mtd);
   int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
   int del_mtd_partitions(struct mtd_info *);
+
+int str2off(const char *p, loff_t *num);
+int str2long(const char *p, ulong *num);


These should be moved somewhere more generic, especially if they're no
longer file-local.


Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
we add a mtd_ prefix to them? I think these functions are mtd specific ...


What is mtd-specific about them?


Hmm... I thought:

return *p != '\0'  *endptr == '\0';

is more or less mtd specific ... but you are right, it is not really
mtd specific ... so I move them to ./lib/vsprintf.c ... Ok?

bye,
Heiko
--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-22 Thread Scott Wood
On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:
 @@ -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;
 + }

Use only one tab per indentation level.

 diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
 index 8666413..2861af5 100644
 --- a/include/linux/mtd/mtd.h
 +++ b/include/linux/mtd/mtd.h
 @@ -482,5 +482,12 @@ int add_mtd_device(struct mtd_info *mtd);
  int del_mtd_device(struct mtd_info *mtd);
  int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
  int del_mtd_partitions(struct mtd_info *);
 +
 +int str2off(const char *p, loff_t *num);
 +int str2long(const char *p, ulong *num);

These should be moved somewhere more generic, especially if they're no
longer file-local.

 +int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
 + loff_t *maxsize, int devtype, int chipsize);
 +int arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
 +  loff_t *size, loff_t *maxsize, int devtype, int chipsize);

Add an mtd prefix.

-Scott


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-22 Thread Heiko Schocher

Hello Scott,

Am 23.04.2015 00:47, schrieb Scott Wood:

On Mon, 2015-04-20 at 07:47 +0200, Heiko Schocher wrote:

@@ -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;
+   }


Use only one tab per indentation level.


You mean the line MTD_DEV_TYPE_NAND, nand_info[idx].size)) { ?

I have to move MTD_xx to the opening bracket to avoid checkpatch.pl
errors ...

If you mean the puts ... line ... fixed.


diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 8666413..2861af5 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -482,5 +482,12 @@ int add_mtd_device(struct mtd_info *mtd);
  int del_mtd_device(struct mtd_info *mtd);
  int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
  int del_mtd_partitions(struct mtd_info *);
+
+int str2off(const char *p, loff_t *num);
+int str2long(const char *p, ulong *num);


These should be moved somewhere more generic, especially if they're no
longer file-local.


Hmm... the code is currently in drivers/mtd/mtd_uboot.c ... maybe
we add a mtd_ prefix to them? I think these functions are mtd specific ...


+int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
+   loff_t *maxsize, int devtype, int chipsize);
+int arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
+loff_t *size, loff_t *maxsize, int devtype, int chipsize);


Add an mtd prefix.


Done.

Thanks for your time!

bye,
Heiko
--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-22 Thread Jagan Teki
On 20 April 2015 at 11:17, 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

Reviewed-by: Jagannadha Sutradharudu Teki jagannadh.t...@gmail.com


 ---

 Changes in v2:
 - none
 Series-changes: 3
 - add comments from scott wood:
   - align MTD_DEV_TYPE_NAND correct
   - remove unnecessary inline
   - rework jffs2 header problem later
 - rebase with d6c1ffc7d23f4fe4ae8c91101861055b8e1501b6
 Series-changes: 4
 - rebased against 385a08a60f042061b004642d6b9bb6cfb794ad5a
 Series-changes: 5
 - add comment from Scott Wood:
   keep the continuation line aligned with the arguments

  common/cmd_nand.c   | 142 
 +---
  common/cmd_onenand.c|  19 ++-
  drivers/mtd/Makefile|   4 +-
  drivers/mtd/mtd_uboot.c | 114 ++
  include/linux/mtd/mtd.h |   7 +++
  5 files changed, 156 insertions(+), 130 deletions(-)
  create mode 100644 drivers/mtd/mtd_uboot.c

 diff --git a/common/cmd_nand.c b/common/cmd_nand.c
 index 17fa7ea..184335d 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;
 +   }
 +   

[U-Boot] [PATCH v5 2/3] mtd, nand: move common functions from cmd_nand.c to common place

2015-04-19 Thread Heiko Schocher
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

---

Changes in v2:
- none
Series-changes: 3
- add comments from scott wood:
  - align MTD_DEV_TYPE_NAND correct
  - remove unnecessary inline
  - rework jffs2 header problem later
- rebase with d6c1ffc7d23f4fe4ae8c91101861055b8e1501b6
Series-changes: 4
- rebased against 385a08a60f042061b004642d6b9bb6cfb794ad5a
Series-changes: 5
- add comment from Scott Wood:
  keep the continuation line aligned with the arguments

 common/cmd_nand.c   | 142 +---
 common/cmd_onenand.c|  19 ++-
 drivers/mtd/Makefile|   4 +-
 drivers/mtd/mtd_uboot.c | 114 ++
 include/linux/mtd/mtd.h |   7 +++
 5 files changed, 156 insertions(+), 130 deletions(-)
 create mode 100644 drivers/mtd/mtd_uboot.c

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 17fa7ea..184335d 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;
}
@@ -595,7 +491,11 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
printf(\nNAND %s: , cmd);