Signed-off-by: Paul B. Henson <[email protected]>
---
miscutils/ubi_tools.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index dd99a44..6cb7cd5 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -95,10 +95,11 @@
//usage: "\n -d UBI_NUM UBI device number"
//usage:
//usage:#define ubimkvol_trivial_usage
-//usage: "UBI_DEVICE -N NAME -s SIZE"
+//usage: "UBI_DEVICE -N NAME [-s SIZE | -m]"
//usage:#define ubimkvol_full_usage "\n\n"
//usage: "Create UBI volume\n"
//usage: "\n -a ALIGNMENT Volume alignment (default 1)"
+//usage: "\n -m Set volume size to maximum available"
//usage: "\n -n VOLID Volume ID, if not specified, it"
//usage: "\n will be assigned automatically"
//usage: "\n -N NAME Volume name"
@@ -141,11 +142,19 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
int alignment = 1;
char *type = NULL;
- opt_complementary = "-1:m+:d+:n+:s+:a+";
- opts = getopt32(argv, "m:d:n:N:s:a:t::",
- &mtd_num, &dev_num, &vol_id,
- &vol_name, &size_bytes, &alignment, &type
- );
+ if (do_mkvol) {
+ opt_complementary = "-1:d+:n+:s+:a+";
+ opts = getopt32(argv, "md:n:N:s:a:t::",
+ &dev_num, &vol_id,
+ &vol_name, &size_bytes, &alignment, &type
+ );
+ } else {
+ opt_complementary = "-1:m+:d+:n+:s+:a+";
+ opts = getopt32(argv, "m:d:n:N:s:a:t::",
+ &mtd_num, &dev_num, &vol_id,
+ &vol_name, &size_bytes, &alignment, &type
+ );
+ }
ubi_ctrl = argv[optind];
fd = xopen(ubi_ctrl, O_RDWR);
@@ -173,6 +182,30 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
if (do_mkvol) {
struct ubi_mkvol_req req;
int vol_name_len;
+ if (opts & OPTION_M) {
+ unsigned leb_avail;
+ unsigned leb_size;
+ unsigned ubinum;
+ char
buf[sizeof("/sys/class/ubi/ubi%d/avail_eraseblocks") + sizeof(int)*3];
+
+ if (sscanf(ubi_ctrl, "/dev/ubi%u", &ubinum) != 1)
+ bb_error_msg_and_die("%s device node not in
correct format", "UBI");
+
+ sprintf(buf, "/sys/class/ubi/ubi%d/avail_eraseblocks",
ubinum);
+ if (open_read_close(buf, buf, sizeof(buf)) <= 0)
+ bb_error_msg_and_die("%s could not get LEB
available", "UBI");
+ if (sscanf(buf, "%u", &leb_avail) != 1)
+ bb_error_msg_and_die("%s could not get LEB
available", "UBI");
+ sprintf(buf, "/sys/class/ubi/ubi%d/eraseblock_size",
ubinum);
+ if (open_read_close(buf, buf, sizeof(buf)) <= 0)
+ bb_error_msg_and_die("%s could not get LEB
size", "UBI");
+ if (sscanf(buf, "%u", &leb_size) != 1)
+ bb_error_msg_and_die("%s could not get LEB
size", "UBI");
+ size_bytes = leb_avail * leb_size;
+
+ if (size_bytes <= 0)
+ bb_error_msg_and_die("%s invalid maximum size
calculated", "UBI");
+ } else
if (!(opts & OPTION_s))
bb_error_msg_and_die("%s size not specified", "UBI");
if (!(opts & OPTION_N))
--
1.7.8.6
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox