From d507d86f8fbd51611fff18eb487d836243c0e7c5 Mon Sep 17 00:00:00 2001 From: Holger Dengler Date: Wed, 30 Aug 2017 18:38:52 +0200 Subject: cmd: set filesize variable in ubi read After a successful read of a UBI volume, the variable filesize is set to the number of read bytes. To boot linux with a raw initramfs/initrd, you must specify the exact size of the initramfs/initrd image in boot command. If the initramfs/inird is read from UBI volume, $filesize is required to access the number of read bytes. Example: ubi read ${loadaddr} kernelvol ubi read ${fdtaddr} dtbvol ubi read ${initrd_addr} initrdvol bootz ${loadaddr} ${initrd_addr}:${filesize} ${fdt_addr} Signed-off-by: Holger Dengler Reviewed-by: Heiko Schocher (cherry picked from commit 985fa93e61706a78fad130b006aefa1c098145de) [backported to 2016.11] Signed-off-by: Stefan Agner Acked-by: Marcel Ziswiler --- cmd/ubi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/ubi.c b/cmd/ubi.c index 7d0d7e7a80..3dc4cae277 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -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) @@ -373,6 +374,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 +400,9 @@ int ubi_volume_read(char *volume, char *buf, size_t size) len = size > tbuf_size ? tbuf_size : size; } while (size); + if (!size) + setenv_hex("filesize", len_read); + free(tbuf); return err; } -- cgit v1.2.3