diff options
Diffstat (limited to 'miscutils/ubi_tools.c')
| -rw-r--r-- | miscutils/ubi_tools.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index dd99a44f4..6f20f300c 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c | |||
| @@ -95,10 +95,11 @@ | |||
| 95 | //usage: "\n -d UBI_NUM UBI device number" | 95 | //usage: "\n -d UBI_NUM UBI device number" |
| 96 | //usage: | 96 | //usage: |
| 97 | //usage:#define ubimkvol_trivial_usage | 97 | //usage:#define ubimkvol_trivial_usage |
| 98 | //usage: "UBI_DEVICE -N NAME -s SIZE" | 98 | //usage: "UBI_DEVICE -N NAME [-s SIZE | -m]" |
| 99 | //usage:#define ubimkvol_full_usage "\n\n" | 99 | //usage:#define ubimkvol_full_usage "\n\n" |
| 100 | //usage: "Create UBI volume\n" | 100 | //usage: "Create UBI volume\n" |
| 101 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" | 101 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" |
| 102 | //usage: "\n -m Set volume size to maximum available" | ||
| 102 | //usage: "\n -n VOLID Volume ID, if not specified, it" | 103 | //usage: "\n -n VOLID Volume ID, if not specified, it" |
| 103 | //usage: "\n will be assigned automatically" | 104 | //usage: "\n will be assigned automatically" |
| 104 | //usage: "\n -N NAME Volume name" | 105 | //usage: "\n -N NAME Volume name" |
| @@ -141,11 +142,19 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 141 | int alignment = 1; | 142 | int alignment = 1; |
| 142 | char *type = NULL; | 143 | char *type = NULL; |
| 143 | 144 | ||
| 144 | opt_complementary = "-1:m+:d+:n+:s+:a+"; | 145 | if (do_mkvol) { |
| 145 | opts = getopt32(argv, "m:d:n:N:s:a:t::", | 146 | opt_complementary = "-1:d+:n+:s+:a+"; |
| 146 | &mtd_num, &dev_num, &vol_id, | 147 | opts = getopt32(argv, "md:n:N:s:a:t::", |
| 147 | &vol_name, &size_bytes, &alignment, &type | 148 | &dev_num, &vol_id, |
| 148 | ); | 149 | &vol_name, &size_bytes, &alignment, &type |
| 150 | ); | ||
| 151 | } else { | ||
| 152 | opt_complementary = "-1:m+:d+:n+:s+:a+"; | ||
| 153 | opts = getopt32(argv, "m:d:n:N:s:a:t::", | ||
| 154 | &mtd_num, &dev_num, &vol_id, | ||
| 155 | &vol_name, &size_bytes, &alignment, &type | ||
| 156 | ); | ||
| 157 | } | ||
| 149 | ubi_ctrl = argv[optind]; | 158 | ubi_ctrl = argv[optind]; |
| 150 | 159 | ||
| 151 | fd = xopen(ubi_ctrl, O_RDWR); | 160 | fd = xopen(ubi_ctrl, O_RDWR); |
| @@ -173,6 +182,36 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 173 | if (do_mkvol) { | 182 | if (do_mkvol) { |
| 174 | struct ubi_mkvol_req req; | 183 | struct ubi_mkvol_req req; |
| 175 | int vol_name_len; | 184 | int vol_name_len; |
| 185 | if (opts & OPTION_M) { | ||
| 186 | unsigned leb_avail; | ||
| 187 | unsigned leb_size; | ||
| 188 | unsigned num; | ||
| 189 | char path[sizeof("/sys/class/ubi/ubi%d/avail_eraseblocks") + sizeof(int)*3]; | ||
| 190 | char *p; | ||
| 191 | char buf[20]; | ||
| 192 | |||
| 193 | if (strncmp(ubi_ctrl, "/dev/ubi", 8) != 0) | ||
| 194 | bb_error_msg_and_die("%s device node not in correct format", "UBI"); | ||
| 195 | num = xstrtou(ubi_ctrl+8, 10); | ||
| 196 | p = path + sprintf(path, "/sys/class/ubi/ubi%d/", num); | ||
| 197 | |||
| 198 | strcpy(p, "avail_eraseblocks"); | ||
| 199 | if ((num = open_read_close(path, buf, sizeof(buf))) <= 1) | ||
| 200 | bb_error_msg_and_die("%s could not get LEB available", "UBI"); | ||
| 201 | buf[num-1] = '\0'; // trim trailing newline | ||
| 202 | leb_avail = xstrtou(buf, 10); | ||
| 203 | |||
| 204 | strcpy(p, "eraseblock_size"); | ||
| 205 | if ((num = open_read_close(path, buf, sizeof(buf))) <= 0) | ||
| 206 | bb_error_msg_and_die("%s could not get LEB size", "UBI"); | ||
| 207 | buf[num-1] = '\0'; // trim trailing newline | ||
| 208 | leb_size = xstrtou(buf, 10); | ||
| 209 | |||
| 210 | size_bytes = leb_avail * leb_size; | ||
| 211 | |||
| 212 | if (size_bytes <= 0) | ||
| 213 | bb_error_msg_and_die("%s invalid maximum size calculated", "UBI"); | ||
| 214 | } else | ||
| 176 | if (!(opts & OPTION_s)) | 215 | if (!(opts & OPTION_s)) |
| 177 | bb_error_msg_and_die("%s size not specified", "UBI"); | 216 | bb_error_msg_and_die("%s size not specified", "UBI"); |
| 178 | if (!(opts & OPTION_N)) | 217 | if (!(opts & OPTION_N)) |
