summaryrefslogtreecommitdiff
path: root/ubi-utils/new-utils
diff options
context:
space:
mode:
Diffstat (limited to 'ubi-utils/new-utils')
-rw-r--r--ubi-utils/new-utils/src/common.h5
-rw-r--r--ubi-utils/new-utils/src/ubiformat.c15
-rw-r--r--ubi-utils/new-utils/src/ubinize.c26
3 files changed, 38 insertions, 8 deletions
diff --git a/ubi-utils/new-utils/src/common.h b/ubi-utils/new-utils/src/common.h
index 720dec1..fdc69db 100644
--- a/ubi-utils/new-utils/src/common.h
+++ b/ubi-utils/new-utils/src/common.h
@@ -68,6 +68,11 @@ extern "C" {
fprintf(stderr, PROGRAM_NAME ": warning!: " fmt "\n", ##__VA_ARGS__); \
} while(0)
+static inline int is_power_of_2(unsigned long long n)
+{
+ return (n != 0 && ((n & (n - 1)) == 0));
+}
+
long long ubiutils_get_bytes(const char *str);
void ubiutils_print_bytes(long long bytes, int bracket);
void ubiutils_print_text(FILE *stream, const char *txt, int len);
diff --git a/ubi-utils/new-utils/src/ubiformat.c b/ubi-utils/new-utils/src/ubiformat.c
index e49c84b..8bb6cfc 100644
--- a/ubi-utils/new-utils/src/ubiformat.c
+++ b/ubi-utils/new-utils/src/ubiformat.c
@@ -129,6 +129,8 @@ static int parse_opt(int argc, char * const argv[])
args.subpage_size = ubiutils_get_bytes(optarg);
if (args.subpage_size <= 0)
return errmsg("bad sub-page size: \"%s\"", optarg);
+ if (!is_power_of_2(args.subpage_size))
+ return errmsg("sub-page size should be power of 2");
break;
case 'O':
@@ -516,10 +518,15 @@ int main(int argc, char * const argv[])
if (args.subpage_size == 0)
args.subpage_size = mtd.min_io_size;
- else if (args.subpage_size > mtd.min_io_size ||
- mtd.min_io_size % args.subpage_size) {
- errmsg("bad sub-page size %d", args.subpage_size);
- goto out_close;
+ else {
+ if (args.subpage_size > mtd.min_io_size) {
+ errmsg("sub-page cannot be larger then min. I/O unit");
+ goto out_close;
+ }
+
+ if (mtd.min_io_size % args.subpage_size) {
+ errmsg("min. I/O unit size should be multiple of sub-page size");
+ }
}
/*
diff --git a/ubi-utils/new-utils/src/ubinize.c b/ubi-utils/new-utils/src/ubinize.c
index dab224b..cd4952d 100644
--- a/ubi-utils/new-utils/src/ubinize.c
+++ b/ubi-utils/new-utils/src/ubinize.c
@@ -177,12 +177,16 @@ static int parse_opt(int argc, char * const argv[])
args.min_io_size = ubiutils_get_bytes(optarg);
if (args.min_io_size <= 0)
return errmsg("bad min. I/O unit size: \"%s\"", optarg);
+ if (!is_power_of_2(args.min_io_size))
+ return errmsg("min. I/O unit size should be power of 2");
break;
case 's':
args.subpage_size = ubiutils_get_bytes(optarg);
if (args.subpage_size <= 0)
return errmsg("bad sub-page size: \"%s\"", optarg);
+ if (!is_power_of_2(args.subpage_size))
+ return errmsg("sub-page size should be power of 2");
break;
case 'O':
@@ -241,9 +245,21 @@ static int parse_opt(int argc, char * const argv[])
if (args.subpage_size < 0)
args.subpage_size = args.min_io_size;
+ if (args.subpage_size > args.min_io_size)
+ return errmsg("sub-page cannot be larger then min. I/O unit");
+
+ if (args.peb_size % args.min_io_size)
+ return errmsg("physical eraseblock should be multiple of min. I/O units");
+
+ if (args.min_io_size % args.subpage_size)
+ return errmsg("min. I/O unit size should be multiple of sub-page size");
+
if (!args.f_out)
return errmsg("output file was not specified (use -h for help)");
+ if (args.vid_hdr_offs && args.vid_hdr_offs + UBI_VID_HDR_SIZE >= args.peb_size)
+ return errmsg("bad VID header position");
+
return 0;
}
@@ -408,10 +424,12 @@ int main(int argc, char * const argv[])
args.subpage_size, args.vid_hdr_offs,
args.ubi_ver);
- verbose(args.verbose, "LEB size: %d", ui.leb_size);
- verbose(args.verbose, "PEB size: %d", ui.peb_size);
- verbose(args.verbose, "min_io_size: %d", ui.min_io_size);
- verbose(args.verbose, "VID offset: %d", ui.vid_hdr_offs);
+ verbose(args.verbose, "LEB size: %d", ui.leb_size);
+ verbose(args.verbose, "PEB size: %d", ui.peb_size);
+ verbose(args.verbose, "min. I/O size: %d", ui.min_io_size);
+ verbose(args.verbose, "sub-page size: %d", ui.min_io_size);
+ verbose(args.verbose, "VID offset: %d", ui.vid_hdr_offs);
+ verbose(args.verbose, "data offset: %d", ui.data_offs);
vtbl = ubigen_create_empty_vtbl(&ui);
if (!vtbl)