X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=cmd%2Fubi.c;h=9c3cabc262aaa692ca8fbe3b630d6810450e8db6;hb=68c7025d99dbac9ddf1a166a19efc3f9e98f1301;hp=4a92d840b6ccd9e2239838fe180b8381a697f765;hpb=6beacfcff81bdc04c10a440971b0fb683ee57534;p=u-boot diff --git a/cmd/ubi.c b/cmd/ubi.c index 4a92d840b6..9c3cabc262 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #undef ubi_msg @@ -162,7 +162,7 @@ bad: return err; } -static int ubi_create_vol(char *volume, int64_t size, int dynamic) +static int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id) { struct ubi_mkvol_req req; int err; @@ -172,7 +172,7 @@ static int ubi_create_vol(char *volume, int64_t size, int dynamic) else req.vol_type = UBI_STATIC_VOLUME; - req.vol_id = UBI_VOL_NUM_AUTO; + req.vol_id = vol_id; req.alignment = 1; req.bytes = size; @@ -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; } @@ -577,10 +584,17 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (strncmp(argv[1], "create", 6) == 0) { int dynamic = 1; /* default: dynamic volume */ + int id = UBI_VOL_NUM_AUTO; /* Use maximum available size */ size = 0; + /* E.g., create volume size type vol_id */ + if (argc == 6) { + id = simple_strtoull(argv[5], NULL, 16); + argc--; + } + /* E.g., create volume size type */ if (argc == 5) { if (strncmp(argv[4], "s", 1) == 0) @@ -593,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 */ @@ -603,7 +618,7 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } /* E.g., create volume */ if (argc == 3) - return ubi_create_vol(argv[2], size, dynamic); + return ubi_create_vol(argv[2], size, dynamic, id); } if (strncmp(argv[1], "remove", 6) == 0) { @@ -661,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); } } @@ -684,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]" - " - 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"