common: Use new numeric setenv functions

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

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2013-02-24 17:33:22 +00:00
parent bfc5996643
commit 41ef372c1a
15 changed files with 48 additions and 71 deletions

View file

@ -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" */
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);
@ -529,17 +527,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

View file

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

View file

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

View file

@ -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);

View file

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

View file

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

View file

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

View file

@ -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,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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