diff mbox

[U-Boot,12/20] common: Use new numeric setenv functions

Message ID 1356548233-5570-13-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Dec. 26, 2012, 6:57 p.m. UTC
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_bootm.c    |   11 +++--------
 common/cmd_cbfs.c     |    4 +---
 common/cmd_cramfs.c   |    4 +---
 common/cmd_fdos.c     |    4 +---
 common/cmd_jffs2.c    |    4 +---
 common/cmd_load.c     |   12 +++---------
 common/cmd_mtdparts.c |    4 +---
 common/cmd_nand.c     |   12 +++---------
 common/cmd_nvedit.c   |    3 +--
 common/cmd_reiser.c   |    4 +---
 common/cmd_setexpr.c  |   39 +++++++++++++++++++++++++++------------
 common/cmd_unzip.c    |    4 +---
 common/cmd_ximg.c     |    7 ++-----
 common/cmd_zfs.c      |    3 +--
 common/cmd_zip.c      |    4 +---
 15 files changed, 48 insertions(+), 71 deletions(-)

Comments

Simon Glass Feb. 15, 2013, 11:55 p.m. UTC | #1
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass <sjg@chromium.org> wrote:
> Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to x86/master.

> ---
>  common/cmd_bootm.c    |   11 +++--------
>  common/cmd_cbfs.c     |    4 +---
>  common/cmd_cramfs.c   |    4 +---
>  common/cmd_fdos.c     |    4 +---
>  common/cmd_jffs2.c    |    4 +---
>  common/cmd_load.c     |   12 +++---------
>  common/cmd_mtdparts.c |    4 +---
>  common/cmd_nand.c     |   12 +++---------
>  common/cmd_nvedit.c   |    3 +--
>  common/cmd_reiser.c   |    4 +---
>  common/cmd_setexpr.c  |   39 +++++++++++++++++++++++++++------------
>  common/cmd_unzip.c    |    4 +---
>  common/cmd_ximg.c     |    7 ++-----
>  common/cmd_zfs.c      |    3 +--
>  common/cmd_zip.c      |    4 +---
>  15 files changed, 48 insertions(+), 71 deletions(-)
>
Tom Rini Feb. 18, 2013, 10:08 p.m. UTC | #2
On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:

> Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
[snip]
> diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c
> index fbee861..5a35cc1 100644
> --- a/common/cmd_fdos.c
> +++ b/common/cmd_fdos.c
[snip]
> @@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>      }
>      flush_cache (load_addr, size);
>  
> -    sprintf(buf, "%x", size);
> -    setenv("filesize", buf);
> +	setenv_hex("filesize", size);

Tab and space mixing in the function.  I'll fix if git am
--whitespace=fix doesn't spot and fix.
Simon Glass Feb. 24, 2013, 5:45 p.m. UTC | #3
Hi Tom,

On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini <trini@ti.com> wrote:
> On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
>
>> Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
> [snip]
>> diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c
>> index fbee861..5a35cc1 100644
>> --- a/common/cmd_fdos.c
>> +++ b/common/cmd_fdos.c
> [snip]
>> @@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>>      }
>>      flush_cache (load_addr, size);
>>
>> -    sprintf(buf, "%x", size);
>> -    setenv("filesize", buf);
>> +     setenv_hex("filesize", size);
>
> Tab and space mixing in the function.  I'll fix if git am
> --whitespace=fix doesn't spot and fix.

I'll change it back to spaces so that it is consistent, even if
checkpatch is upset. There are now 5 patches changed so I will send
out the whole series again.

>
> --
> Tom

Regards,
Simon
Tom Rini Feb. 24, 2013, 8:53 p.m. UTC | #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/24/2013 12:45 PM, Simon Glass wrote:
> Hi Tom,
> 
> On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini <trini@ti.com> wrote:
>> On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
>> 
>>> Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
>>> 
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> [snip]
>>> diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index 
>>> fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ 
>>> b/common/cmd_fdos.c
>> [snip]
>>> @@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, 
>>> int argc, char * const argv[]) } flush_cache (load_addr, 
>>> size);
>>> 
>>> -    sprintf(buf, "%x", size); -    setenv("filesize", buf); + 
>>> setenv_hex("filesize", size);
>> 
>> Tab and space mixing in the function.  I'll fix if git am 
>> --whitespace=fix doesn't spot and fix.
> 
> I'll change it back to spaces so that it is consistent, even if 
> checkpatch is upset. There are now 5 patches changed so I will send
> out the whole series again.

Right, we should always be consistent with the file.  From my read of
the series, this was the only one where the file used spaces and the
new insert was tabs, that's what I'm getting at.  I guess the others
didn't stick out as obviously?

- -- 
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRKn3kAAoJENk4IS6UOR1WV5gP/Ro7jY8wwUV0O4UMYuFidIVG
9SsElNnJoFaoO+qske9MAR6YknpJNb0hu10ZSZWoA+Db1gGeHMwAydG/F8eYJOad
IE26MJVzzSbjmsQx7UJcRKNPfDLKWcZDUMtDC+2YAjT8PvUDRkOqHKqLc/WxcawM
ytsw7o+6lf7GWYABjjEdJkRqd4kd+lq+l6sQoBk0qqQkergjP4+Si3BN3h77ZupV
8hTA7idf3/6ezKjHB3jyMl5kSFrgEPPdhrRNlaYAFriYKpDIwINHEWAYXgQpAtWW
YSA0CQBKZMVE9liMWy3ZWDFslcfk0i72H3m2IP1kNsyRRx0wuekkUlVONc9AQoVe
x3aSnw3LDt0b3SaGhoMLwVKoL6ZI6IKUfAvJNh/tmc/vNbrDmrot2z8mPd4ccKp4
AfrhlpH4KE8eU6zsVpsVWJ85LHaIBu/5SvW73UFLCDZwwnUUIKCj4A903cweCuoG
i8VrY11OliR/yABz+NRRek7Y8pyBMqq40ES4lZJYrcKXwi0k3OwAraCrA73IZeg3
d50ME2WTBQ+tR0cFfp8BZxTVYxrTpHA2diOHL7rdFRfAlii3Wt6Ee9Zbb+ozir6q
TKfxVqJYmHpTYiEt6CuYpq6GD+wQnWbAYkZw5DbmEeq65UUid/UUPcLhDhEinmg6
wbo0UcLD2TLRqc9IS9fX
=lxH4
-----END PGP SIGNATURE-----
Simon Glass Feb. 25, 2013, 3:42 a.m. UTC | #5
Hi Tom,

On Sun, Feb 24, 2013 at 12:53 PM, Tom Rini <trini@ti.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/24/2013 12:45 PM, Simon Glass wrote:
>> Hi Tom,
>>
>> On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini <trini@ti.com> wrote:
>>> On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
>>>
>>>> Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
>>>>
>>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> [snip]
>>>> diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index
>>>> fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++
>>>> b/common/cmd_fdos.c
>>> [snip]
>>>> @@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag,
>>>> int argc, char * const argv[]) } flush_cache (load_addr,
>>>> size);
>>>>
>>>> -    sprintf(buf, "%x", size); -    setenv("filesize", buf); +
>>>> setenv_hex("filesize", size);
>>>
>>> Tab and space mixing in the function.  I'll fix if git am
>>> --whitespace=fix doesn't spot and fix.
>>
>> I'll change it back to spaces so that it is consistent, even if
>> checkpatch is upset. There are now 5 patches changed so I will send
>> out the whole series again.
>
> Right, we should always be consistent with the file.  From my read of
> the series, this was the only one where the file used spaces and the
> new insert was tabs, that's what I'm getting at.  I guess the others
> didn't stick out as obviously?

Well I didn't see any other similar problem. There are a few warnings
- in one case I am moving code and then fixing it up in a later
commit. But I think this is the only one where I am deliberating
following the prevailing style to fit in with the surrounding code.

Regards,
Simon

>
> - --
> Tom
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJRKn3kAAoJENk4IS6UOR1WV5gP/Ro7jY8wwUV0O4UMYuFidIVG
> 9SsElNnJoFaoO+qske9MAR6YknpJNb0hu10ZSZWoA+Db1gGeHMwAydG/F8eYJOad
> IE26MJVzzSbjmsQx7UJcRKNPfDLKWcZDUMtDC+2YAjT8PvUDRkOqHKqLc/WxcawM
> ytsw7o+6lf7GWYABjjEdJkRqd4kd+lq+l6sQoBk0qqQkergjP4+Si3BN3h77ZupV
> 8hTA7idf3/6ezKjHB3jyMl5kSFrgEPPdhrRNlaYAFriYKpDIwINHEWAYXgQpAtWW
> YSA0CQBKZMVE9liMWy3ZWDFslcfk0i72H3m2IP1kNsyRRx0wuekkUlVONc9AQoVe
> x3aSnw3LDt0b3SaGhoMLwVKoL6ZI6IKUfAvJNh/tmc/vNbrDmrot2z8mPd4ccKp4
> AfrhlpH4KE8eU6zsVpsVWJ85LHaIBu/5SvW73UFLCDZwwnUUIKCj4A903cweCuoG
> i8VrY11OliR/yABz+NRRek7Y8pyBMqq40ES4lZJYrcKXwi0k3OwAraCrA73IZeg3
> d50ME2WTBQ+tR0cFfp8BZxTVYxrTpHA2diOHL7rdFRfAlii3Wt6Ee9Zbb+ozir6q
> TKfxVqJYmHpTYiEt6CuYpq6GD+wQnWbAYkZw5DbmEeq65UUid/UUPcLhDhEinmg6
> wbo0UcLD2TLRqc9IS9fX
> =lxH4
> -----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index f7595c0..2debfe3 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -447,9 +447,7 @@  static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
 
 	/* Don't start if "autostart" is set to "no" */
 	if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
-		char buf[32];
-		sprintf(buf, "%lX", images.os.image_len);
-		setenv("filesize", buf);
+		setenv_hex("filesize", images.os.image_len);
 		return 0;
 	}
 	appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
@@ -523,17 +521,14 @@  static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
 		case BOOTM_STATE_RAMDISK:
 		{
 			ulong rd_len = images.rd_end - images.rd_start;
-			char str[17];
 
 			ret = boot_ramdisk_high(&images.lmb, images.rd_start,
 				rd_len, &images.initrd_start, &images.initrd_end);
 			if (ret)
 				return ret;
 
-			sprintf(str, "%lx", images.initrd_start);
-			setenv("initrd_start", str);
-			sprintf(str, "%lx", images.initrd_end);
-			setenv("initrd_end", str);
+			setenv_hex("initrd_start", images.initrd_start);
+			setenv_hex("initrd_end", images.initrd_end);
 		}
 			break;
 #endif
diff --git a/common/cmd_cbfs.c b/common/cmd_cbfs.c
index 3b6cfd8..f51534b 100644
--- a/common/cmd_cbfs.c
+++ b/common/cmd_cbfs.c
@@ -65,7 +65,6 @@  int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	const struct cbfs_cachenode *file;
 	unsigned long offset;
 	unsigned long count;
-	char buf[12];
 	long size;
 
 	if (argc < 3) {
@@ -95,8 +94,7 @@  int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 
 	printf("\n%ld bytes read\n", size);
 
-	sprintf(buf, "%lX", size);
-	setenv("filesize", buf);
+	setenv_hex("filesize", size);
 
 	return 0;
 }
diff --git a/common/cmd_cramfs.c b/common/cmd_cramfs.c
index e7f496e..0e43ab6 100644
--- a/common/cmd_cramfs.c
+++ b/common/cmd_cramfs.c
@@ -146,11 +146,9 @@  int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		size = cramfs_load ((char *) offset, &part, filename);
 
 	if (size > 0) {
-		char buf[10];
 		printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
 			size, offset);
-		sprintf(buf, "%x", size);
-		setenv("filesize", buf);
+		setenv_hex("filesize", size);
 	} else {
 		printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
 	}
diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c
index fbee861..5a35cc1 100644
--- a/common/cmd_fdos.c
+++ b/common/cmd_fdos.c
@@ -40,7 +40,6 @@  int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
     char *name;
     char *ep;
     int size;
-    char buf [12];
     int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
 
     /* pre-set load_addr */
@@ -91,8 +90,7 @@  int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
     }
     flush_cache (load_addr, size);
 
-    sprintf(buf, "%x", size);
-    setenv("filesize", buf);
+	setenv_hex("filesize", size);
 
     printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
 	   size, load_addr);
diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
index 27296dd..4a4a000 100644
--- a/common/cmd_jffs2.c
+++ b/common/cmd_jffs2.c
@@ -525,11 +525,9 @@  int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		}
 
 		if (size > 0) {
-			char buf[10];
 			printf("### %s load complete: %d bytes loaded to 0x%lx\n",
 				fsname, size, offset);
-			sprintf(buf, "%x", size);
-			setenv("filesize", buf);
+			setenv_hex("filesize", size);
 		} else {
 			printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
 		}
diff --git a/common/cmd_load.c b/common/cmd_load.c
index 2c8dab1..e56b983 100644
--- a/common/cmd_load.c
+++ b/common/cmd_load.c
@@ -149,7 +149,6 @@  static ulong load_serial(long offset)
 	int	type;				/* return code for record type	*/
 	ulong	addr;				/* load address from S-Record	*/
 	ulong	size;				/* number of bytes transferred	*/
-	char	buf[32];
 	ulong	store_addr;
 	ulong	start_addr = ~0;
 	ulong	end_addr   =  0;
@@ -198,8 +197,7 @@  static ulong load_serial(long offset)
 			    start_addr, end_addr, size, size
 		    );
 		    flush_cache(start_addr, size);
-		    sprintf(buf, "%lX", size);
-		    setenv("filesize", buf);
+		    setenv_hex("filesize", size);
 		    return (addr);
 		case SREC_START:
 		    break;
@@ -519,7 +517,6 @@  static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc,
 static ulong load_serial_bin(ulong offset)
 {
 	int size, i;
-	char buf[32];
 
 	set_kerm_bin_mode((ulong *) offset);
 	size = k_recv();
@@ -539,8 +536,7 @@  static ulong load_serial_bin(ulong offset)
 	flush_cache(offset, size);
 
 	printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-	sprintf(buf, "%X", size);
-	setenv("filesize", buf);
+	setenv_hex("filesize", size);
 
 	return offset;
 }
@@ -965,7 +961,6 @@  static int getcxmodem(void) {
 static ulong load_serial_ymodem(ulong offset)
 {
 	int size;
-	char buf[32];
 	int err;
 	int res;
 	connection_info_t info;
@@ -1012,8 +1007,7 @@  static ulong load_serial_ymodem(ulong offset)
 	flush_cache(offset, size);
 
 	printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-	sprintf(buf, "%X", size);
-	setenv("filesize", buf);
+	setenv_hex("filesize", size);
 
 	return offset;
 }
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 06fc171..0cfca0c 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -230,7 +230,6 @@  static void memsize_format(char *buf, u32 size)
  */
 static void index_partitions(void)
 {
-	char buf[16];
 	u16 mtddevnum;
 	struct part_info *part;
 	struct list_head *dentry;
@@ -244,8 +243,7 @@  static void index_partitions(void)
 			dev = list_entry(dentry, struct mtd_device, link);
 			if (dev == current_mtd_dev) {
 				mtddevnum += current_mtd_partnum;
-				sprintf(buf, "%d", mtddevnum);
-				setenv("mtddevnum", buf);
+				setenv_ulong("mtddevnum", mtddevnum);
 				break;
 			}
 			mtddevnum += dev->num_parts;
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 1568594..6ebd333 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -373,7 +373,6 @@  static void nand_print_and_set_info(int idx)
 {
 	nand_info_t *nand = &nand_info[idx];
 	struct nand_chip *chip = nand->priv;
-	char buf[32];
 
 	printf("Device %d: ", idx);
 	if (chip->numchips > 1)
@@ -385,14 +384,9 @@  static void nand_print_and_set_info(int idx)
 	printf("  Erase size %8d b\n", nand->erasesize);
 
 	/* Set geometry info */
-	sprintf(buf, "%x", nand->writesize);
-	setenv("nand_writesize", buf);
-
-	sprintf(buf, "%x", nand->oobsize);
-	setenv("nand_oobsize", buf);
-
-	sprintf(buf, "%x", nand->erasesize);
-	setenv("nand_erasesize", buf);
+	setenv_hex("nand_writesize", nand->writesize);
+	setenv_hex("nand_oobsize", nand->oobsize);
+	setenv_hex("nand_erasesize", nand->erasesize);
 }
 
 static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 44e88aa..d646d90 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -891,8 +891,7 @@  NXTARG:		;
 		envp->flags = ACTIVE_FLAG;
 #endif
 	}
-	sprintf(buf, "%zX", (size_t)(len + offsetof(env_t, data)));
-	setenv("filesize", buf);
+	setenv_hex("filesize", len + offsetof(env_t, data));
 
 	return 0;
 
diff --git a/common/cmd_reiser.c b/common/cmd_reiser.c
index e658618..717c7f6 100644
--- a/common/cmd_reiser.c
+++ b/common/cmd_reiser.c
@@ -100,7 +100,6 @@  int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ulong addr = 0, filelen;
 	disk_partition_t info;
 	block_dev_desc_t *dev_desc = NULL;
-	char buf [12];
 	unsigned long count;
 	char *addr_str;
 
@@ -175,8 +174,7 @@  int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	load_addr = addr;
 
 	printf ("\n%ld bytes read\n", filelen);
-	sprintf(buf, "%lX", filelen);
-	setenv("filesize", buf);
+	setenv_hex("filesize", filelen);
 
 	return filelen;
 }
diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c
index 5a04295..7a38e94 100644
--- a/common/cmd_setexpr.c
+++ b/common/cmd_setexpr.c
@@ -53,7 +53,7 @@  static ulong get_arg(char *s, int w)
 static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	ulong a, b;
-	char buf[16];
+	ulong value;
 	int w;
 
 	/* Validate arguments */
@@ -67,8 +67,7 @@  static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	a = get_arg(argv[2], w);
 
 	if (argc == 3) {
-		sprintf(buf, "%lx", a);
-		setenv(argv[1], buf);
+		setenv_hex(argv[1], a);
 
 		return 0;
 	}
@@ -76,20 +75,36 @@  static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	b = get_arg(argv[4], w);
 
 	switch (argv[3][0]) {
-	case '|': sprintf(buf, "%lx", (a | b)); break;
-	case '&': sprintf(buf, "%lx", (a & b)); break;
-	case '+': sprintf(buf, "%lx", (a + b)); break;
-	case '^': sprintf(buf, "%lx", (a ^ b)); break;
-	case '-': sprintf(buf, "%lx", (a - b)); break;
-	case '*': sprintf(buf, "%lx", (a * b)); break;
-	case '/': sprintf(buf, "%lx", (a / b)); break;
-	case '%': sprintf(buf, "%lx", (a % b)); break;
+	case '|':
+		value = a | b;
+		break;
+	case '&':
+		value = a & b;
+		break;
+	case '+':
+		value = a + b;
+		break;
+	case '^':
+		value = a ^ b;
+		break;
+	case '-':
+		value = a - b;
+		break;
+	case '*':
+		value = a * b;
+		break;
+	case '/':
+		value = a / b;
+		break;
+	case '%':
+		value = a % b;
+		break;
 	default:
 		printf("invalid op\n");
 		return 1;
 	}
 
-	setenv(argv[1], buf);
+	setenv_hex(argv[1], value);
 
 	return 0;
 }
diff --git a/common/cmd_unzip.c b/common/cmd_unzip.c
index 43ed791..7470c2b 100644
--- a/common/cmd_unzip.c
+++ b/common/cmd_unzip.c
@@ -28,7 +28,6 @@  static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	unsigned long src, dst;
 	unsigned long src_len = ~0UL, dst_len = ~0UL;
-	char buf[32];
 
 	switch (argc) {
 		case 4:
@@ -46,8 +45,7 @@  static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 
 	printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
-	sprintf(buf, "%lX", src_len);
-	setenv("filesize", buf);
+	setenv_hex("filesize", src_len);
 
 	return 0;
 }
diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c
index 42a7eba..ea0a26e 100644
--- a/common/cmd_ximg.c
+++ b/common/cmd_ximg.c
@@ -50,7 +50,6 @@  do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 	ulong		data, len, count;
 	int		verify;
 	int		part = 0;
-	char		pbuf[10];
 	image_header_t	*hdr;
 #if defined(CONFIG_FIT)
 	const char	*uname = NULL;
@@ -256,10 +255,8 @@  do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 		puts("OK\n");
 	}
 
-	sprintf(pbuf, "%8lx", data);
-	setenv("fileaddr", pbuf);
-	sprintf(pbuf, "%8lx", len);
-	setenv("filesize", pbuf);
+	setenv_hex("fileaddr", data);
+	setenv_hex("filesize", len);
 
 	return 0;
 }
diff --git a/common/cmd_zfs.c b/common/cmd_zfs.c
index 1df0c4d..900e977 100644
--- a/common/cmd_zfs.c
+++ b/common/cmd_zfs.c
@@ -129,8 +129,7 @@  static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 	load_addr = addr;
 
 	printf("%llu bytes read\n", zfile.size);
-	sprintf(buf, "%llX", zfile.size);
-	setenv("filesize", buf);
+	setenv_hex("filesize", zfile.size);
 
 	return 0;
 }
diff --git a/common/cmd_zip.c b/common/cmd_zip.c
index a73c86d..8607da8 100644
--- a/common/cmd_zip.c
+++ b/common/cmd_zip.c
@@ -28,7 +28,6 @@  static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	unsigned long src, dst;
 	unsigned long src_len, dst_len = ~0UL;
-	char buf[32];
 
 	switch (argc) {
 		case 5:
@@ -47,8 +46,7 @@  static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 
 	printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len);
-	sprintf(buf, "%lX", dst_len);
-	setenv("filesize", buf);
+	setenv_hex("filesize", dst_len);
 
 	return 0;
 }