]> git.sur5r.net Git - u-boot/blobdiff - cmd/ubi.c
cmd: ubi: print load size after establishing volume size
[u-boot] / cmd / ubi.c
index 7d0d7e7a80a7ed7712be84110ca3b61c8da085a0..9c3cabc262aaa692ca8fbe3b630d6810450e8db6 100644 (file)
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -308,7 +308,7 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t size,
                return ENODEV;
 
        rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad);
-       if (size < 0 || size > rsvd_bytes) {
+       if (size > rsvd_bytes) {
                printf("size > volume size! Aborting!\n");
                return EINVAL;
        }
@@ -334,6 +334,7 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
        unsigned long long tmp;
        struct ubi_volume *vol;
        loff_t offp = 0;
+       size_t len_read;
 
        vol = ubi_find_volume(volume);
        if (vol == NULL)
@@ -355,6 +356,8 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
                size = vol->used_bytes;
        }
 
+       printf("Read %u bytes from volume %s to %p\n", size, volume, buf);
+
        if (vol->corrupted)
                printf("read from corrupted volume %d", vol->vol_id);
        if (offp + size > vol->used_bytes)
@@ -373,6 +376,7 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
        tmp = offp;
        off = do_div(tmp, vol->usable_leb_size);
        lnum = tmp;
+       len_read = size;
        do {
                if (off + len >= vol->usable_leb_size)
                        len = vol->usable_leb_size - off;
@@ -398,6 +402,9 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
                len = size > tbuf_size ? tbuf_size : size;
        } while (size);
 
+       if (!size)
+               env_set_hex("filesize", len_read);
+
        free(tbuf);
        return err;
 }
@@ -600,7 +607,8 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                }
                /* E.g., create volume size */
                if (argc == 4) {
-                       size = simple_strtoull(argv[3], NULL, 16);
+                       if (argv[3][0] != '-')
+                               size = simple_strtoull(argv[3], NULL, 16);
                        argc--;
                }
                /* Use maximum available size */
@@ -668,9 +676,6 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                }
 
                if (argc == 3) {
-                       printf("Read %lld bytes from volume %s to %lx\n", size,
-                              argv[3], addr);
-
                        return ubi_volume_read(argv[3], (char *)addr, size);
                }
        }
@@ -691,8 +696,9 @@ U_BOOT_CMD(
                " - Display volume and ubi layout information\n"
        "ubi check volumename"
                " - check if volumename exists\n"
-       "ubi create[vol] volume [size] [type] [id]"
-               " - create volume name with size\n"
+       "ubi create[vol] volume [size] [type] [id]\n"
+               " - create volume name with size ('-' for maximum"
+               " available size)\n"
        "ubi write[vol] address volume size"
                " - Write volume from address with size\n"
        "ubi write.part address volume size [fullsize]\n"