common: Use new numeric setenv functions

Use setenv_ulong(), setenv_hex() and setenv_addr() in common/

Signed-off-by: Simon Glass <sjg@chromium.org>
master
Simon Glass 11 years ago
parent bfc5996643
commit 41ef372c1a
  1. 11
      common/cmd_bootm.c
  2. 4
      common/cmd_cbfs.c
  3. 4
      common/cmd_cramfs.c
  4. 4
      common/cmd_fdos.c
  5. 4
      common/cmd_jffs2.c
  6. 12
      common/cmd_load.c
  7. 4
      common/cmd_mtdparts.c
  8. 12
      common/cmd_nand.c
  9. 3
      common/cmd_nvedit.c
  10. 4
      common/cmd_reiser.c
  11. 39
      common/cmd_setexpr.c
  12. 4
      common/cmd_unzip.c
  13. 7
      common/cmd_ximg.c
  14. 3
      common/cmd_zfs.c
  15. 4
      common/cmd_zip.c

@ -452,9 +452,7 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
/* Don't start if "autostart" is set to "no" */ /* Don't start if "autostart" is set to "no" */
if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) { if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
char buf[32]; setenv_hex("filesize", images.os.image_len);
sprintf(buf, "%lX", images.os.image_len);
setenv("filesize", buf);
return 0; return 0;
} }
appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep); appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
@ -529,17 +527,14 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
case BOOTM_STATE_RAMDISK: case BOOTM_STATE_RAMDISK:
{ {
ulong rd_len = images.rd_end - images.rd_start; ulong rd_len = images.rd_end - images.rd_start;
char str[17];
ret = boot_ramdisk_high(&images.lmb, images.rd_start, ret = boot_ramdisk_high(&images.lmb, images.rd_start,
rd_len, &images.initrd_start, &images.initrd_end); rd_len, &images.initrd_start, &images.initrd_end);
if (ret) if (ret)
return ret; return ret;
sprintf(str, "%lx", images.initrd_start); setenv_hex("initrd_start", images.initrd_start);
setenv("initrd_start", str); setenv_hex("initrd_end", images.initrd_end);
sprintf(str, "%lx", images.initrd_end);
setenv("initrd_end", str);
} }
break; break;
#endif #endif

@ -65,7 +65,6 @@ int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
const struct cbfs_cachenode *file; const struct cbfs_cachenode *file;
unsigned long offset; unsigned long offset;
unsigned long count; unsigned long count;
char buf[12];
long size; long size;
if (argc < 3) { 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); printf("\n%ld bytes read\n", size);
sprintf(buf, "%lX", size); setenv_hex("filesize", size);
setenv("filesize", buf);
return 0; return 0;
} }

@ -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); size = cramfs_load ((char *) offset, &part, filename);
if (size > 0) { if (size > 0) {
char buf[10];
printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n", printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
size, offset); size, offset);
sprintf(buf, "%x", size); setenv_hex("filesize", size);
setenv("filesize", buf);
} else { } else {
printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename); printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
} }

@ -40,7 +40,6 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
char *name; char *name;
char *ep; char *ep;
int size; int size;
char buf [12];
int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
/* pre-set load_addr */ /* 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); flush_cache (load_addr, size);
sprintf(buf, "%x", size); setenv_hex("filesize", size);
setenv("filesize", buf);
printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
size, load_addr); size, load_addr);

@ -525,11 +525,9 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
} }
if (size > 0) { if (size > 0) {
char buf[10];
printf("### %s load complete: %d bytes loaded to 0x%lx\n", printf("### %s load complete: %d bytes loaded to 0x%lx\n",
fsname, size, offset); fsname, size, offset);
sprintf(buf, "%x", size); setenv_hex("filesize", size);
setenv("filesize", buf);
} else { } else {
printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
} }

@ -149,7 +149,6 @@ static ulong load_serial(long offset)
int type; /* return code for record type */ int type; /* return code for record type */
ulong addr; /* load address from S-Record */ ulong addr; /* load address from S-Record */
ulong size; /* number of bytes transferred */ ulong size; /* number of bytes transferred */
char buf[32];
ulong store_addr; ulong store_addr;
ulong start_addr = ~0; ulong start_addr = ~0;
ulong end_addr = 0; ulong end_addr = 0;
@ -198,8 +197,7 @@ static ulong load_serial(long offset)
start_addr, end_addr, size, size start_addr, end_addr, size, size
); );
flush_cache(start_addr, size); flush_cache(start_addr, size);
sprintf(buf, "%lX", size); setenv_hex("filesize", size);
setenv("filesize", buf);
return (addr); return (addr);
case SREC_START: case SREC_START:
break; 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) static ulong load_serial_bin(ulong offset)
{ {
int size, i; int size, i;
char buf[32];
set_kerm_bin_mode((ulong *) offset); set_kerm_bin_mode((ulong *) offset);
size = k_recv(); size = k_recv();
@ -539,8 +536,7 @@ static ulong load_serial_bin(ulong offset)
flush_cache(offset, size); flush_cache(offset, size);
printf("## Total Size = 0x%08x = %d Bytes\n", size, size); printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
sprintf(buf, "%X", size); setenv_hex("filesize", size);
setenv("filesize", buf);
return offset; return offset;
} }
@ -965,7 +961,6 @@ static int getcxmodem(void) {
static ulong load_serial_ymodem(ulong offset) static ulong load_serial_ymodem(ulong offset)
{ {
int size; int size;
char buf[32];
int err; int err;
int res; int res;
connection_info_t info; connection_info_t info;
@ -1012,8 +1007,7 @@ static ulong load_serial_ymodem(ulong offset)
flush_cache(offset, size); flush_cache(offset, size);
printf("## Total Size = 0x%08x = %d Bytes\n", size, size); printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
sprintf(buf, "%X", size); setenv_hex("filesize", size);
setenv("filesize", buf);
return offset; return offset;
} }

@ -230,7 +230,6 @@ static void memsize_format(char *buf, u32 size)
*/ */
static void index_partitions(void) static void index_partitions(void)
{ {
char buf[16];
u16 mtddevnum; u16 mtddevnum;
struct part_info *part; struct part_info *part;
struct list_head *dentry; struct list_head *dentry;
@ -244,8 +243,7 @@ static void index_partitions(void)
dev = list_entry(dentry, struct mtd_device, link); dev = list_entry(dentry, struct mtd_device, link);
if (dev == current_mtd_dev) { if (dev == current_mtd_dev) {
mtddevnum += current_mtd_partnum; mtddevnum += current_mtd_partnum;
sprintf(buf, "%d", mtddevnum); setenv_ulong("mtddevnum", mtddevnum);
setenv("mtddevnum", buf);
break; break;
} }
mtddevnum += dev->num_parts; mtddevnum += dev->num_parts;

@ -373,7 +373,6 @@ static void nand_print_and_set_info(int idx)
{ {
nand_info_t *nand = &nand_info[idx]; nand_info_t *nand = &nand_info[idx];
struct nand_chip *chip = nand->priv; struct nand_chip *chip = nand->priv;
char buf[32];
printf("Device %d: ", idx); printf("Device %d: ", idx);
if (chip->numchips > 1) 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); printf(" Erase size %8d b\n", nand->erasesize);
/* Set geometry info */ /* Set geometry info */
sprintf(buf, "%x", nand->writesize); setenv_hex("nand_writesize", nand->writesize);
setenv("nand_writesize", buf); setenv_hex("nand_oobsize", nand->oobsize);
setenv_hex("nand_erasesize", nand->erasesize);
sprintf(buf, "%x", nand->oobsize);
setenv("nand_oobsize", buf);
sprintf(buf, "%x", nand->erasesize);
setenv("nand_erasesize", buf);
} }
static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count, static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,

@ -891,8 +891,7 @@ NXTARG: ;
envp->flags = ACTIVE_FLAG; envp->flags = ACTIVE_FLAG;
#endif #endif
} }
sprintf(buf, "%zX", (size_t)(len + offsetof(env_t, data))); setenv_hex("filesize", len + offsetof(env_t, data));
setenv("filesize", buf);
return 0; return 0;

@ -100,7 +100,6 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ulong addr = 0, filelen; ulong addr = 0, filelen;
disk_partition_t info; disk_partition_t info;
block_dev_desc_t *dev_desc = NULL; block_dev_desc_t *dev_desc = NULL;
char buf [12];
unsigned long count; unsigned long count;
char *addr_str; char *addr_str;
@ -175,8 +174,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
load_addr = addr; load_addr = addr;
printf ("\n%ld bytes read\n", filelen); printf ("\n%ld bytes read\n", filelen);
sprintf(buf, "%lX", filelen); setenv_hex("filesize", filelen);
setenv("filesize", buf);
return filelen; return filelen;
} }

@ -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[]) static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{ {
ulong a, b; ulong a, b;
char buf[16]; ulong value;
int w; int w;
/* Validate arguments */ /* 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); a = get_arg(argv[2], w);
if (argc == 3) { if (argc == 3) {
sprintf(buf, "%lx", a); setenv_hex(argv[1], a);
setenv(argv[1], buf);
return 0; 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); b = get_arg(argv[4], w);
switch (argv[3][0]) { switch (argv[3][0]) {
case '|': sprintf(buf, "%lx", (a | b)); break; case '|':
case '&': sprintf(buf, "%lx", (a & b)); break; value = a | b;
case '+': sprintf(buf, "%lx", (a + b)); break; break;
case '^': sprintf(buf, "%lx", (a ^ b)); break; case '&':
case '-': sprintf(buf, "%lx", (a - b)); break; value = a & b;
case '*': sprintf(buf, "%lx", (a * b)); break; break;
case '/': sprintf(buf, "%lx", (a / b)); break; case '+':
case '%': sprintf(buf, "%lx", (a % b)); break; 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: default:
printf("invalid op\n"); printf("invalid op\n");
return 1; return 1;
} }
setenv(argv[1], buf); setenv_hex(argv[1], value);
return 0; return 0;
} }

@ -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, dst;
unsigned long src_len = ~0UL, dst_len = ~0UL; unsigned long src_len = ~0UL, dst_len = ~0UL;
char buf[32];
switch (argc) { switch (argc) {
case 4: case 4:
@ -46,8 +45,7 @@ static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1; return 1;
printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len); printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
sprintf(buf, "%lX", src_len); setenv_hex("filesize", src_len);
setenv("filesize", buf);
return 0; return 0;
} }

@ -50,7 +50,6 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
ulong data, len, count; ulong data, len, count;
int verify; int verify;
int part = 0; int part = 0;
char pbuf[10];
image_header_t *hdr; image_header_t *hdr;
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
const char *uname = NULL; const char *uname = NULL;
@ -256,10 +255,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
puts("OK\n"); puts("OK\n");
} }
sprintf(pbuf, "%8lx", data); setenv_hex("fileaddr", data);
setenv("fileaddr", pbuf); setenv_hex("filesize", len);
sprintf(pbuf, "%8lx", len);
setenv("filesize", pbuf);
return 0; return 0;
} }

@ -129,8 +129,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
load_addr = addr; load_addr = addr;
printf("%llu bytes read\n", zfile.size); printf("%llu bytes read\n", zfile.size);
sprintf(buf, "%llX", zfile.size); setenv_hex("filesize", zfile.size);
setenv("filesize", buf);
return 0; return 0;
} }

@ -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, dst;
unsigned long src_len, dst_len = ~0UL; unsigned long src_len, dst_len = ~0UL;
char buf[32];
switch (argc) { switch (argc) {
case 5: case 5:
@ -47,8 +46,7 @@ static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1; return 1;
printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len); printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len);
sprintf(buf, "%lX", dst_len); setenv_hex("filesize", dst_len);
setenv("filesize", buf);
return 0; return 0;
} }

Loading…
Cancel
Save