diff options
Diffstat (limited to 'ubi-utils/src')
-rw-r--r-- | ubi-utils/src/common.c | 1 | ||||
-rw-r--r-- | ubi-utils/src/common.h | 1 | ||||
-rw-r--r-- | ubi-utils/src/libubigen.c | 7 | ||||
-rw-r--r-- | ubi-utils/src/mtdinfo.c | 2 | ||||
-rw-r--r-- | ubi-utils/src/ubiformat.c | 4 | ||||
-rw-r--r-- | ubi-utils/src/ubinize.c | 41 |
6 files changed, 40 insertions, 16 deletions
diff --git a/ubi-utils/src/common.c b/ubi-utils/src/common.c index 50a07ab..3fd470b 100644 --- a/ubi-utils/src/common.c +++ b/ubi-utils/src/common.c @@ -27,6 +27,7 @@ #include <string.h> #include <ctype.h> #include <stdlib.h> +#include "common.h" /** * get_multiplier - convert size specifier to an integer multiplier. diff --git a/ubi-utils/src/common.h b/ubi-utils/src/common.h index 56fa020..955c50f 100644 --- a/ubi-utils/src/common.h +++ b/ubi-utils/src/common.h @@ -20,6 +20,7 @@ #define __UBI_UTILS_COMMON_H__ #include <stdio.h> +#include <ctype.h> #include <string.h> #include <errno.h> diff --git a/ubi-utils/src/libubigen.c b/ubi-utils/src/libubigen.c index a34963e..db58cae 100644 --- a/ubi-utils/src/libubigen.c +++ b/ubi-utils/src/libubigen.c @@ -46,9 +46,11 @@ * @min_io_size if does not exist) * @vid_hdr_offs: offset of the VID header * @ubi_ver: UBI version + * @image_seq: UBI image sequence number */ void ubigen_info_init(struct ubigen_info *ui, int peb_size, int min_io_size, - int subpage_size, int vid_hdr_offs, int ubi_ver) + int subpage_size, int vid_hdr_offs, int ubi_ver, + uint32_t image_seq) { if (!vid_hdr_offs) { vid_hdr_offs = UBI_EC_HDR_SIZE + subpage_size - 1; @@ -64,6 +66,7 @@ void ubigen_info_init(struct ubigen_info *ui, int peb_size, int min_io_size, ui->data_offs *= min_io_size; ui->leb_size = peb_size - ui->data_offs; ui->ubi_ver = ubi_ver; + ui->image_seq = image_seq; ui->max_volumes = ui->leb_size / UBI_VTBL_RECORD_SIZE; if (ui->max_volumes > UBI_MAX_VOLUMES) @@ -157,8 +160,8 @@ void ubigen_init_ec_hdr(const struct ubigen_info *ui, hdr->version = ui->ubi_ver; hdr->ec = cpu_to_be64(ec); hdr->vid_hdr_offset = cpu_to_be32(ui->vid_hdr_offs); - hdr->data_offset = cpu_to_be32(ui->data_offs); + hdr->image_seq = cpu_to_be32(ui->image_seq); crc = crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC); hdr->hdr_crc = cpu_to_be32(crc); diff --git a/ubi-utils/src/mtdinfo.c b/ubi-utils/src/mtdinfo.c index a7ce834..be8b1ff 100644 --- a/ubi-utils/src/mtdinfo.c +++ b/ubi-utils/src/mtdinfo.c @@ -215,7 +215,7 @@ static int print_dev_info(libmtd_t libmtd, const struct mtd_info *mtd_info, int } ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, mtd.subpage_size, - 0, 1); + 0, 1, 0); printf("Default UBI VID header offset: %d\n", ui.vid_hdr_offs); printf("Default UBI data offset: %d\n", ui.data_offs); printf("Default UBI LEB size: "); diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c index 55ce7aa..a2ca572 100644 --- a/ubi-utils/src/ubiformat.c +++ b/ubi-utils/src/ubiformat.c @@ -875,7 +875,7 @@ int main(int argc, char * const argv[]) normsg("use erase counter %lld for all eraseblocks", args.ec); ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, mtd.subpage_size, - args.vid_hdr_offs, args.ubi_ver); + args.vid_hdr_offs, args.ubi_ver, 0); if (si->vid_hdr_offs != -1 && ui.vid_hdr_offs != si->vid_hdr_offs) { /* @@ -895,7 +895,7 @@ int main(int argc, char * const argv[]) printf("yes\n"); } else ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, 0, - si->vid_hdr_offs, args.ubi_ver); + si->vid_hdr_offs, args.ubi_ver, 0); normsg("use offsets %d and %d", ui.vid_hdr_offs, ui.data_offs); } diff --git a/ubi-utils/src/ubinize.c b/ubi-utils/src/ubinize.c index 0762aa8..8d62362 100644 --- a/ubi-utils/src/ubinize.c +++ b/ubi-utils/src/ubinize.c @@ -38,7 +38,7 @@ #include <libiniparser.h> #include "common.h" -#define PROGRAM_VERSION "1.1" +#define PROGRAM_VERSION "1.2" #define PROGRAM_NAME "ubinize" static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION @@ -70,12 +70,17 @@ static const char *optionsstr = " (default is 0)\n" "-x, --ubi-ver=<num> UBI version number to put to EC headers\n" " (default is 1)\n" +"-Q, --image-seq=<num> 32-bit UBI image sequence number to use\n" +" (by default a random number is picked)\n" "-v, --verbose be verbose\n" "-h, --help print help message\n" "-V, --version print program version"; static const char *usage = -"Usage: " PROGRAM_NAME " [-o filename] [-h] [-V] [--output=<filename>] [--help]\n" +"Usage: " PROGRAM_NAME " [-o filename] [-p <bytes>] [-m <bytes>] [-s <bytes>] [-O <num>] [-e <num>]\n" +"\t\t[-x <num>] [-Q <num>] [-v] [-h] [-V] [--output=<filename>] [--peb-size=<bytes>]\n" +"\t\t[--min-io-size=<bytes>] [--sub-page-size=<bytes>] [--vid-hdr-offset=<num>]\n" +"\t\t[--erase-counter=<num>] [--ubi-ver=<num>] [--image-seq=<num>] [--verbose] [--help]\n" "\t\t[--version] ini-file\n" "Example: " PROGRAM_NAME " -o ubi.img -p 16KiB -m 512 -s 256 cfg.ini - create UBI image\n" " 'ubi.img' as described by configuration file 'cfg.ini'"; @@ -121,6 +126,7 @@ struct option long_options[] = { { .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' }, { .name = "erase-counter", .has_arg = 1, .flag = NULL, .val = 'e' }, { .name = "ubi-ver", .has_arg = 1, .flag = NULL, .val = 'x' }, + { .name = "image-seq", .has_arg = 1, .flag = NULL, .val = 'Q' }, { .name = "verbose", .has_arg = 0, .flag = NULL, .val = 'v' }, { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, @@ -137,6 +143,7 @@ struct args { int vid_hdr_offs; int ec; int ubi_ver; + long long image_seq; int verbose; dictionary *dict; }; @@ -146,6 +153,7 @@ static struct args args = { .min_io_size = -1, .subpage_size = -1, .ubi_ver = 1, + .image_seq = -1, }; static int parse_opt(int argc, char * const argv[]) @@ -154,7 +162,7 @@ static int parse_opt(int argc, char * const argv[]) int key; char *endp; - key = getopt_long(argc, argv, "o:p:m:s:O:e:x:vhV", long_options, NULL); + key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:vhV", long_options, NULL); if (key == -1) break; @@ -207,6 +215,12 @@ static int parse_opt(int argc, char * const argv[]) return errmsg("bad UBI version: \"%s\"", optarg); break; + case 'Q': + args.image_seq = strtoul(optarg, &endp, 0); + if (*endp != '\0' || endp == optarg || args.image_seq > 0xFFFFFFFF) + return errmsg("bad UBI image sequence number: \"%s\"", optarg); + break; + case 'v': args.verbose = 1; break; @@ -267,6 +281,10 @@ static int parse_opt(int argc, char * const argv[]) return errmsg("VID header offset has to be multiple of min. I/O unit size"); } + if (!args.image_seq == -1) { + srand(getpid()); + args.image_seq = random(); + } return 0; } @@ -449,14 +467,15 @@ int main(int argc, char * const argv[]) ubigen_info_init(&ui, args.peb_size, args.min_io_size, 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. I/O size: %d", ui.min_io_size); - verbose(args.verbose, "sub-page size: %d", args.subpage_size); - verbose(args.verbose, "VID offset: %d", ui.vid_hdr_offs); - verbose(args.verbose, "data offset: %d", ui.data_offs); + args.ubi_ver, args.image_seq); + + 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", args.subpage_size); + verbose(args.verbose, "VID offset: %d", ui.vid_hdr_offs); + verbose(args.verbose, "data offset: %d", ui.data_offs); + verbose(args.verbose, "UBI image sequence number: %u", ui.image_seq); vtbl = ubigen_create_empty_vtbl(&ui); if (!vtbl) |