aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mtd/ubi-header.h166
-rw-r--r--ubi-utils/src/eb_chain.c42
-rw-r--r--ubi-utils/src/libubigen.c56
-rw-r--r--ubi-utils/src/pfi2bin.c14
-rw-r--r--ubi-utils/src/ubigen.h27
-rw-r--r--ubi-utils/src/unubi.c68
-rw-r--r--ubi-utils/src/unubi_analyze.c46
7 files changed, 211 insertions, 208 deletions
diff --git a/include/mtd/ubi-header.h b/include/mtd/ubi-header.h
index c003d98..69d5d7e 100644
--- a/include/mtd/ubi-header.h
+++ b/include/mtd/ubi-header.h
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Authors: Artem B. Bityutskiy
+ * Authors: Artem Bityutskiy (Битюцкий Артём)
* Thomas Gleixner
* Frank Haverkamp
* Oliver Lohmann
@@ -58,6 +58,43 @@ enum {
};
/*
+ * Volume flags used in the volume table record.
+ *
+ * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume
+ *
+ * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume
+ * table. UBI automatically re-sizes the volume which has this flag and makes
+ * the volume to be of largest possible size. This means that if after the
+ * initialization UBI finds out that there are available physical eraseblocks
+ * present on the device, it automatically appends all of them to the volume
+ * (the physical eraseblocks reserved for bad eraseblocks handling and other
+ * reserved physical eraseblocks are not taken). So, if there is a volume with
+ * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical
+ * eraseblocks will be zero after UBI is loaded, because all of them will be
+ * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared
+ * after the volume had been initialized.
+ *
+ * The auto-resize feature is useful for device production purposes. For
+ * example, different NAND flash chips may have different amount of initial bad
+ * eraseblocks, depending of particular chip instance. Manufacturers of NAND
+ * chips usually guarantee that the amount of initial bad eraseblocks does not
+ * exceed certain percent, e.g. 2%. When one creates an UBI image which will be
+ * flashed to the end devices in production, he does not know the exact amount
+ * of good physical eraseblocks the NAND chip on the device will have, but this
+ * number is required to calculate the volume sized and put them to the volume
+ * table of the UBI image. In this case, one of the volumes (e.g., the one
+ * which will store the root file system) is marked as "auto-resizable", and
+ * UBI will adjust its size on the first boot if needed.
+ *
+ * Note, first UBI reserves some amount of physical eraseblocks for bad
+ * eraseblock handling, and then re-sizes the volume, not vice-versa. This
+ * means that the pool of reserved physical eraseblocks will always be present.
+ */
+enum {
+ UBI_VTBL_AUTORESIZE_FLG = 0x01,
+};
+
+/*
* Compatibility constants used by internal volumes.
*
* @UBI_COMPAT_DELETE: delete this internal volume before anything is written
@@ -74,42 +111,13 @@ enum {
UBI_COMPAT_REJECT = 5
};
-/*
- * ubi16_t/ubi32_t/ubi64_t - 16, 32, and 64-bit integers used in UBI on-flash
- * data structures.
- */
-typedef struct {
- uint16_t int16;
-} __attribute__ ((packed)) ubi16_t;
-
-typedef struct {
- uint32_t int32;
-} __attribute__ ((packed)) ubi32_t;
-
-typedef struct {
- uint64_t int64;
-} __attribute__ ((packed)) ubi64_t;
-
-/*
- * In this implementation of UBI uses the big-endian format for on-flash
- * integers. The below are the corresponding conversion macros.
- */
-#define cpu_to_ubi16(x) ((ubi16_t){__cpu_to_be16(x)})
-#define ubi16_to_cpu(x) ((uint16_t)__be16_to_cpu((x).int16))
-
-#define cpu_to_ubi32(x) ((ubi32_t){__cpu_to_be32(x)})
-#define ubi32_to_cpu(x) ((uint32_t)__be32_to_cpu((x).int32))
-
-#define cpu_to_ubi64(x) ((ubi64_t){__cpu_to_be64(x)})
-#define ubi64_to_cpu(x) ((uint64_t)__be64_to_cpu((x).int64))
-
/* Sizes of UBI headers */
#define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)
#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
/* Sizes of UBI headers without the ending CRC */
-#define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(ubi32_t))
-#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(ubi32_t))
+#define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32))
+#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
/**
* struct ubi_ec_hdr - UBI erase counter header.
@@ -137,14 +145,14 @@ typedef struct {
* eraseblocks.
*/
struct ubi_ec_hdr {
- ubi32_t magic;
- uint8_t version;
- uint8_t padding1[3];
- ubi64_t ec; /* Warning: the current limit is 31-bit anyway! */
- ubi32_t vid_hdr_offset;
- ubi32_t data_offset;
- uint8_t padding2[36];
- ubi32_t hdr_crc;
+ __be32 magic;
+ __u8 version;
+ __u8 padding1[3];
+ __be64 ec; /* Warning: the current limit is 31-bit anyway! */
+ __be32 vid_hdr_offset;
+ __be32 data_offset;
+ __u8 padding2[36];
+ __be32 hdr_crc;
} __attribute__ ((packed));
/**
@@ -262,22 +270,22 @@ struct ubi_ec_hdr {
* software (say, cramfs) on top of the UBI volume.
*/
struct ubi_vid_hdr {
- ubi32_t magic;
- uint8_t version;
- uint8_t vol_type;
- uint8_t copy_flag;
- uint8_t compat;
- ubi32_t vol_id;
- ubi32_t lnum;
- ubi32_t leb_ver; /* obsolete, to be removed, don't use */
- ubi32_t data_size;
- ubi32_t used_ebs;
- ubi32_t data_pad;
- ubi32_t data_crc;
- uint8_t padding1[4];
- ubi64_t sqnum;
- uint8_t padding2[12];
- ubi32_t hdr_crc;
+ __be32 magic;
+ __u8 version;
+ __u8 vol_type;
+ __u8 copy_flag;
+ __u8 compat;
+ __be32 vol_id;
+ __be32 lnum;
+ __be32 leb_ver; /* obsolete, to be removed, don't use */
+ __be32 data_size;
+ __be32 used_ebs;
+ __be32 data_pad;
+ __be32 data_crc;
+ __u8 padding1[4];
+ __be64 sqnum;
+ __u8 padding2[12];
+ __be32 hdr_crc;
} __attribute__ ((packed));
/* Internal UBI volumes count */
@@ -289,19 +297,11 @@ struct ubi_vid_hdr {
*/
#define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
-/*
- * IDs of internal UBI volumes.
- *
- * %UBI_LAYOUT_VOL_ID: layout volume ID
- */
-enum {
- UBI_LAYOUT_VOL_ID = UBI_INTERNAL_VOL_START,
-};
-
/* The layout volume contains the volume table */
+#define UBI_LAYOUT_VOL_ID UBI_INTERNAL_VOL_START
#define UBI_LAYOUT_VOLUME_EBS 2
-#define UBI_LAYOUT_VOLUME_NAME "The layout volume"
+#define UBI_LAYOUT_VOLUME_NAME "layout volume"
#define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
/* The maximum number of volumes per one UBI device */
@@ -311,13 +311,13 @@ enum {
#define UBI_VOL_NAME_MAX 127
/* Size of the volume table record */
-#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vol_tbl_record)
+#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
/* Size of the volume table record without the ending CRC */
-#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(ubi32_t))
+#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
/**
- * struct ubi_vol_tbl_record - a record in the volume table.
+ * struct ubi_vtbl_record - a record in the volume table.
* @reserved_pebs: how many physical eraseblocks are reserved for this volume
* @alignment: volume alignment
* @data_pad: how many bytes are unused at the end of the each physical
@@ -326,19 +326,20 @@ enum {
* @upd_marker: if volume update was started but not finished
* @name_len: volume name length
* @name: the volume name
- * @padding2: reserved, zeroes
+ * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG)
+ * @padding: reserved, zeroes
* @crc: a CRC32 checksum of the record
*
* The volume table records are stored in the volume table, which is stored in
* the layout volume. The layout volume consists of 2 logical eraseblock, each
* of which contains a copy of the volume table (i.e., the volume table is
- * duplicated). The volume table is an array of &struct ubi_vol_tbl_record
+ * duplicated). The volume table is an array of &struct ubi_vtbl_record
* objects indexed by the volume ID.
*
* If the size of the logical eraseblock is large enough to fit
* %UBI_MAX_VOLUMES records, the volume table contains %UBI_MAX_VOLUMES
* records. Otherwise, it contains as many records as it can fit (i.e., size of
- * logical eraseblock divided by sizeof(struct ubi_vol_tbl_record)).
+ * logical eraseblock divided by sizeof(struct ubi_vtbl_record)).
*
* The @upd_marker flag is used to implement volume update. It is set to %1
* before update and set to %0 after the update. So if the update operation was
@@ -353,16 +354,17 @@ enum {
*
* Empty records contain all zeroes and the CRC checksum of those zeroes.
*/
-struct ubi_vol_tbl_record {
- ubi32_t reserved_pebs;
- ubi32_t alignment;
- ubi32_t data_pad;
- uint8_t vol_type;
- uint8_t upd_marker;
- ubi16_t name_len;
- uint8_t name[UBI_VOL_NAME_MAX+1];
- uint8_t padding2[24];
- ubi32_t crc;
+struct ubi_vtbl_record {
+ __be32 reserved_pebs;
+ __be32 alignment;
+ __be32 data_pad;
+ __u8 vol_type;
+ __u8 upd_marker;
+ __be16 name_len;
+ __u8 name[UBI_VOL_NAME_MAX+1];
+ __u8 flags;
+ __u8 padding[23];
+ __be32 crc;
} __attribute__ ((packed));
#endif /* !__UBI_HEADER_H__ */
diff --git a/ubi-utils/src/eb_chain.c b/ubi-utils/src/eb_chain.c
index 471efad..a018ae6 100644
--- a/ubi-utils/src/eb_chain.c
+++ b/ubi-utils/src/eb_chain.c
@@ -65,9 +65,9 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new)
return 0;
}
- new_vol = ubi32_to_cpu(new->vid.vol_id);
- new_num = ubi32_to_cpu(new->vid.lnum);
- new_ver = ubi32_to_cpu(new->vid.leb_ver);
+ new_vol = __be32_to_cpu(new->vid.vol_id);
+ new_num = __be32_to_cpu(new->vid.lnum);
+ new_ver = __be32_to_cpu(new->vid.leb_ver);
/** TRAVERSE HORIZONTALY **/
@@ -75,8 +75,8 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new)
prev = NULL;
/* traverse until vol_id/lnum align */
- vol = ubi32_to_cpu(cur->vid.vol_id);
- num = ubi32_to_cpu(cur->vid.lnum);
+ vol = __be32_to_cpu(cur->vid.vol_id);
+ num = __be32_to_cpu(cur->vid.lnum);
while ((new_vol > vol) || ((new_vol == vol) && (new_num > num))) {
/* insert new at end of chain */
if (cur->next == NULL) {
@@ -88,8 +88,8 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new)
prev = cur;
cur = cur->next;
- vol = ubi32_to_cpu(cur->vid.vol_id);
- num = ubi32_to_cpu(cur->vid.lnum);
+ vol = __be32_to_cpu(cur->vid.vol_id);
+ num = __be32_to_cpu(cur->vid.lnum);
}
if (prev == NULL)
@@ -111,7 +111,7 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new)
prev = NULL;
/* traverse until versions align */
- ver = ubi32_to_cpu(cur->vid.leb_ver);
+ ver = __be32_to_cpu(cur->vid.leb_ver);
while (new_ver < ver) {
/* insert new at bottom of history */
if (hist->older == NULL) {
@@ -124,7 +124,7 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new)
prev = hist;
hist = hist->older;
- ver = ubi32_to_cpu(hist->vid.leb_ver);
+ ver = __be32_to_cpu(hist->vid.leb_ver);
}
if (prev == NULL) {
@@ -168,8 +168,8 @@ eb_chain_position(struct eb_info **head, uint32_t vol_id, uint32_t *lnum,
cur = *head;
while (cur != NULL) {
- vol = ubi32_to_cpu(cur->vid.vol_id);
- num = ubi32_to_cpu(cur->vid.lnum);
+ vol = __be32_to_cpu(cur->vid.vol_id);
+ num = __be32_to_cpu(cur->vid.lnum);
if ((vol_id == vol) && ((lnum == NULL) || (*lnum == num))) {
*pos = cur;
@@ -210,24 +210,24 @@ eb_chain_print(FILE* stream, struct eb_info *head)
struct eb_info *hist;
fprintf(stream, "%08x %-8u %08x %-4s%-4s",
- ubi32_to_cpu(cur->vid.vol_id),
- ubi32_to_cpu(cur->vid.lnum),
- ubi32_to_cpu(cur->vid.leb_ver),
+ __be32_to_cpu(cur->vid.vol_id),
+ __be32_to_cpu(cur->vid.lnum),
+ __be32_to_cpu(cur->vid.leb_ver),
cur->ec_crc_ok ? "ok":"bad",
cur->vid_crc_ok ? "ok":"bad");
if (cur->vid.vol_type == UBI_VID_STATIC)
fprintf(stream, "%-4s", cur->data_crc_ok ? "ok":"bad");
else fprintf(stream, "%-4s", cur->data_crc_ok ? "ok":"ign");
fprintf(stream, " %-4d %08x %-8u %-8llu\n", cur->phys_block,
- cur->phys_addr, ubi32_to_cpu(cur->vid.data_size),
- ubi64_to_cpu(cur->ec.ec));
+ cur->phys_addr, __be32_to_cpu(cur->vid.data_size),
+ __be64_to_cpu(cur->ec.ec));
hist = cur->older;
while (hist != NULL) {
fprintf(stream, "%08x %-8u %08x %-4s%-4s",
- ubi32_to_cpu(hist->vid.vol_id),
- ubi32_to_cpu(hist->vid.lnum),
- ubi32_to_cpu(hist->vid.leb_ver),
+ __be32_to_cpu(hist->vid.vol_id),
+ __be32_to_cpu(hist->vid.lnum),
+ __be32_to_cpu(hist->vid.leb_ver),
hist->ec_crc_ok ? "ok":"bad",
hist->vid_crc_ok ? "ok":"bad");
if (hist->vid.vol_type == UBI_VID_STATIC)
@@ -235,8 +235,8 @@ eb_chain_print(FILE* stream, struct eb_info *head)
else fprintf(stream, "%-4s", hist->data_crc_ok ? "ok":"ign");
fprintf(stream, " %-4d %08x %-8u %-8llu (*)\n",
hist->phys_block, hist->phys_addr,
- ubi32_to_cpu(hist->vid.data_size),
- ubi64_to_cpu(hist->ec.ec));
+ __be32_to_cpu(hist->vid.data_size),
+ __be64_to_cpu(hist->ec.ec));
hist = hist->older;
}
diff --git a/ubi-utils/src/libubigen.c b/ubi-utils/src/libubigen.c
index d65f055..87c8c40 100644
--- a/ubi-utils/src/libubigen.c
+++ b/ubi-utils/src/libubigen.c
@@ -78,7 +78,7 @@ validate_ubi_info(ubi_info_t u)
return EUBIGEN_INVALID_TYPE;
}
- if (ubi32_to_cpu(u->ec->vid_hdr_offset) < UBI_VID_HDR_SIZE) {
+ if (__be32_to_cpu(u->ec->vid_hdr_offset) < UBI_VID_HDR_SIZE) {
return EUBIGEN_INVALID_HDR_OFFSET;
}
@@ -142,16 +142,16 @@ add_static_info(ubi_info_t u, size_t data_size, ubigen_action_t action)
uint32_t crc = clc_crc32(crc32_table, UBI_CRC32_INIT,
u->ptr_data, data_size);
- u->v->data_size = cpu_to_ubi32(data_size);
- u->v->data_crc = cpu_to_ubi32(crc);
+ u->v->data_size = __cpu_to_be32(data_size);
+ u->v->data_crc = __cpu_to_be32(crc);
if (action & BROKEN_DATA_CRC) {
u->v->data_crc =
- cpu_to_ubi32(ubi32_to_cpu(u->v->data_crc) + 1);
+ __cpu_to_be32(__be32_to_cpu(u->v->data_crc) + 1);
}
if (action & BROKEN_DATA_SIZE) {
u->v->data_size =
- cpu_to_ubi32(ubi32_to_cpu(u->v->data_size) + 1);
+ __cpu_to_be32(__be32_to_cpu(u->v->data_size) + 1);
}
}
@@ -161,9 +161,9 @@ write_vid_hdr(ubi_info_t u, ubigen_action_t action)
uint32_t crc = clc_crc32(crc32_table, UBI_CRC32_INIT,
u->v, UBI_VID_HDR_SIZE_CRC);
/* Write VID header */
- u->v->hdr_crc = cpu_to_ubi32(crc);
+ u->v->hdr_crc = __cpu_to_be32(crc);
if (action & BROKEN_HDR_CRC) {
- u->v->hdr_crc = cpu_to_ubi32(ubi32_to_cpu(u->v->hdr_crc) + 1);
+ u->v->hdr_crc = __cpu_to_be32(__be32_to_cpu(u->v->hdr_crc) + 1);
}
memcpy(u->ptr_vid_hdr, u->v, UBI_VID_HDR_SIZE);
}
@@ -197,7 +197,7 @@ ubigen_write_leb(ubi_info_t u, ubigen_action_t action)
add_static_info(u, read, action);
}
- u->v->lnum = cpu_to_ubi32(u->blks_written);
+ u->v->lnum = __cpu_to_be32(u->blks_written);
if (action & MARK_AS_UPDATE) {
u->v->copy_flag = (u->v->copy_flag)++;
@@ -267,19 +267,19 @@ dump_info(ubi_info_t u ubi_unused)
fprintf(stderr, "ubi volume\n");
fprintf(stderr, "version : %8d\n", u->v->version);
- fprintf(stderr, "vol_id : %8d\n", ubi32_to_cpu(u->v->vol_id));
+ fprintf(stderr, "vol_id : %8d\n", __be32_to_cpu(u->v->vol_id));
fprintf(stderr, "vol_type : %8s\n",
u->v->vol_type == UBI_VID_STATIC ?
"static" : "dynamic");
fprintf(stderr, "used_ebs : %8d\n",
- ubi32_to_cpu(u->v->used_ebs));
+ __be32_to_cpu(u->v->used_ebs));
fprintf(stderr, "peb_size : 0x%08x\n", u->peb_size);
fprintf(stderr, "leb_size : 0x%08x\n", u->leb_size);
fprintf(stderr, "data_pad : 0x%08x\n",
- ubi32_to_cpu(u->v->data_pad));
+ __be32_to_cpu(u->v->data_pad));
fprintf(stderr, "leb_total : %8d\n", u->leb_total);
fprintf(stderr, "header offs : 0x%08x\n",
- ubi32_to_cpu(u->ec->vid_hdr_offset));
+ __be32_to_cpu(u->ec->vid_hdr_offset));
fprintf(stderr, "bytes_total : %8d\n", u->bytes_total);
fprintf(stderr, " + in MiB : %8.2f M\n",
((float)(u->bytes_total)) / 1024 / 1024);
@@ -372,31 +372,31 @@ ubigen_create(ubi_info_t* u, uint32_t vol_id, uint8_t vol_type,
res->fp_out = fp_out;
/* vid hdr data which doesn't change */
- res->v->magic = cpu_to_ubi32(UBI_VID_HDR_MAGIC);
+ res->v->magic = __cpu_to_be32(UBI_VID_HDR_MAGIC);
res->v->version = version ? version : UBI_VERSION;
res->v->vol_type = vol_type;
- res->v->vol_id = cpu_to_ubi32(vol_id);
+ res->v->vol_id = __cpu_to_be32(vol_id);
res->v->compat = compat_flag;
- res->v->data_pad = cpu_to_ubi32(res->data_pad);
+ res->v->data_pad = __cpu_to_be32(res->data_pad);
/* static only: used_ebs */
if (res->v->vol_type == UBI_VID_STATIC) {
- res->v->used_ebs = cpu_to_ubi32(byte_to_blk
+ res->v->used_ebs = __cpu_to_be32(byte_to_blk
(res->bytes_total,
res->leb_size));
}
/* ec hdr (fixed, doesn't change) */
- res->ec->magic = cpu_to_ubi32(UBI_EC_HDR_MAGIC);
+ res->ec->magic = __cpu_to_be32(UBI_EC_HDR_MAGIC);
res->ec->version = version ? version : UBI_VERSION;
- res->ec->ec = cpu_to_ubi64(ec);
- res->ec->vid_hdr_offset = cpu_to_ubi32(vid_hdr_offset);
+ res->ec->ec = __cpu_to_be64(ec);
+ res->ec->vid_hdr_offset = __cpu_to_be32(vid_hdr_offset);
- res->ec->data_offset = cpu_to_ubi32(data_offset);
+ res->ec->data_offset = __cpu_to_be32(data_offset);
crc = clc_crc32(crc32_table, UBI_CRC32_INIT, res->ec,
UBI_EC_HDR_SIZE_CRC);
- res->ec->hdr_crc = cpu_to_ubi32(crc);
+ res->ec->hdr_crc = __cpu_to_be32(crc);
/* prepare a read buffer */
res->buf = (uint8_t*) malloc (res->peb_size * sizeof(uint8_t));
@@ -407,8 +407,8 @@ ubigen_create(ubi_info_t* u, uint32_t vol_id, uint8_t vol_type,
/* point to distinct regions within the buffer */
res->ptr_ec_hdr = res->buf;
- res->ptr_vid_hdr = res->buf + ubi32_to_cpu(res->ec->vid_hdr_offset);
- res->ptr_data = res->buf + ubi32_to_cpu(res->ec->vid_hdr_offset)
+ res->ptr_vid_hdr = res->buf + __be32_to_cpu(res->ec->vid_hdr_offset);
+ res->ptr_data = res->buf + __be32_to_cpu(res->ec->vid_hdr_offset)
+ UBI_VID_HDR_SIZE;
rc = validate_ubi_info(res);
@@ -458,7 +458,7 @@ ubigen_get_leb_total(ubi_info_t u, size_t* total)
int
ubigen_set_lvol_rec(ubi_info_t u, size_t reserved_bytes,
- const char* vol_name, struct ubi_vol_tbl_record *lvol_rec)
+ const char* vol_name, struct ubi_vtbl_record *lvol_rec)
{
uint32_t crc;
@@ -468,19 +468,19 @@ ubigen_set_lvol_rec(ubi_info_t u, size_t reserved_bytes,
memset(lvol_rec, 0x0, UBI_VTBL_RECORD_SIZE);
lvol_rec->reserved_pebs =
- cpu_to_ubi32(byte_to_blk(reserved_bytes, u->leb_size));
- lvol_rec->alignment = cpu_to_ubi32(u->alignment);
+ __cpu_to_be32(byte_to_blk(reserved_bytes, u->leb_size));
+ lvol_rec->alignment = __cpu_to_be32(u->alignment);
lvol_rec->data_pad = u->v->data_pad;
lvol_rec->vol_type = u->v->vol_type;
lvol_rec->name_len =
- cpu_to_ubi16((uint16_t)strlen((const char*)vol_name));
+ __cpu_to_be16((uint16_t)strlen((const char*)vol_name));
memcpy(lvol_rec->name, vol_name, UBI_VOL_NAME_MAX + 1);
crc = clc_crc32(crc32_table, UBI_CRC32_INIT,
lvol_rec, UBI_VTBL_RECORD_SIZE_CRC);
- lvol_rec->crc = cpu_to_ubi32(crc);
+ lvol_rec->crc = __cpu_to_be32(crc);
return 0;
}
diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c
index 35af86c..7f31938 100644
--- a/ubi-utils/src/pfi2bin.c
+++ b/ubi-utils/src/pfi2bin.c
@@ -238,7 +238,7 @@ err:
static int
convert_ubi_volume(pfi_ubi_t ubi, pdd_data_t pdd, list_t raw_pebs,
- struct ubi_vol_tbl_record *vol_tab,
+ struct ubi_vtbl_record *vol_tab,
size_t *ebs_written, io_t io)
{
int rc = 0;
@@ -336,7 +336,7 @@ my_fmemopen (void *buf, size_t size, const char *opentype)
*/
static int
write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs,
- struct ubi_vol_tbl_record *vol_tab, size_t vol_tab_size,
+ struct ubi_vtbl_record *vol_tab, size_t vol_tab_size,
size_t *ebs_written, io_t io)
{
int rc = 0;
@@ -478,15 +478,15 @@ err:
}
static int
-init_vol_tab(struct ubi_vol_tbl_record **vol_tab, size_t *vol_tab_size)
+init_vol_tab(struct ubi_vtbl_record **vol_tab, size_t *vol_tab_size)
{
uint32_t crc;
size_t i;
- struct ubi_vol_tbl_record* res = NULL;
+ struct ubi_vtbl_record* res = NULL;
*vol_tab_size = UBI_MAX_VOLUMES * UBI_VTBL_RECORD_SIZE;
- res = (struct ubi_vol_tbl_record*) calloc(1, *vol_tab_size);
+ res = (struct ubi_vtbl_record*) calloc(1, *vol_tab_size);
if (vol_tab == NULL) {
return -ENOMEM;
}
@@ -494,7 +494,7 @@ init_vol_tab(struct ubi_vol_tbl_record **vol_tab, size_t *vol_tab_size)
for (i = 0; i < UBI_MAX_VOLUMES; i++) {
crc = clc_crc32(crc32_table, UBI_CRC32_INIT,
&(res[i]), UBI_VTBL_RECORD_SIZE_CRC);
- res[i].crc = cpu_to_ubi32(crc);
+ res[i].crc = __cpu_to_be32(crc);
}
*vol_tab = res;
@@ -513,7 +513,7 @@ create_raw(io_t io)
list_t pfi_ubis = mk_empty(); /* list of ubi sections from a pfi */
list_t raw_pebs = mk_empty(); /* list of raw eraseblocks */
- struct ubi_vol_tbl_record *vol_tab = NULL;
+ struct ubi_vtbl_record *vol_tab = NULL;
pdd_data_t pdd = NULL;
rc = init_vol_tab (&vol_tab, &vol_tab_size);
diff --git a/ubi-utils/src/ubigen.h b/ubi-utils/src/ubigen.h
index 9e9e8ec..bf4b384 100644
--- a/ubi-utils/src/ubigen.h
+++ b/ubi-utils/src/ubigen.h
@@ -1,5 +1,3 @@
-#ifndef __UBIGEN_H__
-#define __UBIGEN_H__
/*
* Copyright (c) International Business Machines Corp., 2006
*
@@ -22,23 +20,26 @@
* An utility to update UBI volumes.
*/
-#include <stdio.h> /* FILE */
+#ifndef __UBIGEN_H__
+#define __UBIGEN_H__
+
+#include <stdio.h>
#include <stdint.h>
#include <mtd/ubi-header.h>
+#include <asm/byteorder.h>
#ifdef __cplusplus
extern "C" {
#endif
-#define DEFAULT_BLOCKSIZE (128 * 1024)
-#define DEFAULT_PAGESIZE (2*1024)
-
-#define EUBIGEN_INVALID_TYPE 1
-#define EUBIGEN_INVALID_HDR_OFFSET 2
-#define EUBIGEN_INVALID_ALIGNMENT 3
-#define EUBIGEN_TOO_SMALL_EB 4
-#define EUBIGEN_MAX_ERROR 5
+#define DEFAULT_BLOCKSIZE (128 * 1024)
+#define DEFAULT_PAGESIZE (2*1024)
+#define EUBIGEN_INVALID_TYPE 1
+#define EUBIGEN_INVALID_HDR_OFFSET 2
+#define EUBIGEN_INVALID_ALIGNMENT 3
+#define EUBIGEN_TOO_SMALL_EB 4
+#define EUBIGEN_MAX_ERROR 5
typedef enum action {
NO_ERROR = 0x00000000,
@@ -140,10 +141,10 @@ int ubigen_write_broken_update(ubi_info_t u, uint32_t blk);
* else Error.
*/
int ubigen_set_lvol_rec(ubi_info_t u, size_t reserved_bytes,
- const char* name, struct ubi_vol_tbl_record *lvol_rec);
+ const char* name, struct ubi_vtbl_record *lvol_rec);
#ifdef __cplusplus
}
#endif
-#endif /* __UBIGEN_H__ */
+#endif /* !__UBIGEN_H__ */
diff --git a/ubi-utils/src/unubi.c b/ubi-utils/src/unubi.c
index a50eff6..5c1d324 100644
--- a/ubi-utils/src/unubi.c
+++ b/ubi-utils/src/unubi.c
@@ -414,7 +414,7 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
size_t i, max;
fpos_t temp;
FILE* fpout = NULL;
- struct ubi_vol_tbl_record rec;
+ struct ubi_vtbl_record rec;
if (fpin == NULL || cur == NULL || path == NULL)
return -2;
@@ -428,10 +428,10 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
fsetpos(fpin, &cur->eb_top);
if (rc < 0)
return -1;
- fseek(fpin, ubi32_to_cpu(cur->ec.data_offset), SEEK_CUR);
+ fseek(fpin, __be32_to_cpu(cur->ec.data_offset), SEEK_CUR);
/* prepare output file */
- if (ubi32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOL_ID)
+ if (__be32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOL_ID)
return -2;
memset(filename, 0, MAXPATH + 1);
snprintf(filename, MAXPATH, FN_VITBL, path, num);
@@ -442,7 +442,7 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
/* loop through entries */
fprintf(fpout,
"index\trpebs\talign\ttype\tcrc\t\tname\n");
- max = bsize - ubi32_to_cpu(cur->ec.data_offset);
+ max = bsize - __be32_to_cpu(cur->ec.data_offset);
for (i = 0; i < (max / sizeof(rec)); i++) {
int blank = 1;
char *ptr, *base;
@@ -464,7 +464,7 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
/* check crc */
crc = clc_crc32(crc32_table, UBI_CRC32_INIT, &rec,
UBI_VTBL_RECORD_SIZE_CRC);
- if (crc != ubi32_to_cpu(rec.crc))
+ if (crc != __be32_to_cpu(rec.crc))
continue;
/* check for empty */
@@ -487,16 +487,16 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
type = "static\0";
/* prep name string */
- rec.name[ubi16_to_cpu(rec.name_len)] = '\0';
+ rec.name[__be16_to_cpu(rec.name_len)] = '\0';
sprintf(name, "%s", rec.name);
/* print record line to fpout */
fprintf(fpout, "%u\t%u\t%u\t%s\t0x%08x\t%s\n",
i,
- ubi32_to_cpu(rec.reserved_pebs),
- ubi32_to_cpu(rec.alignment),
+ __be32_to_cpu(rec.reserved_pebs),
+ __be32_to_cpu(rec.alignment),
type,
- ubi32_to_cpu(rec.crc),
+ __be32_to_cpu(rec.crc),
name);
}
@@ -534,7 +534,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
/* when vol_id is null, then do all */
if (vol_id == NULL) {
cur = *head;
- vol = ubi32_to_cpu(cur->vid.vol_id);
+ vol = __be32_to_cpu(cur->vid.vol_id);
} else {
vol = *vol_id;
eb_chain_position(head, vol, NULL, &cur);
@@ -556,7 +556,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
while (cur != NULL) {
size_t i;
- if (ubi32_to_cpu(cur->vid.vol_id) != vol) {
+ if (__be32_to_cpu(cur->vid.vol_id) != vol) {
/* close out file */
fclose(fpout);
@@ -565,7 +565,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
goto out;
/* begin with next */
- vol = ubi32_to_cpu(cur->vid.vol_id);
+ vol = __be32_to_cpu(cur->vid.vol_id);
num = 0;
snprintf(filename, MAXPATH, FN_VOLWH, path, vol);
fpout = fopen(filename, "wb");
@@ -576,7 +576,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
}
}
- while (num < ubi32_to_cpu(cur->vid.lnum)) {
+ while (num < __be32_to_cpu(cur->vid.lnum)) {
/* FIXME haver: I hope an empty block is
written out so that the binary has no holes
... */
@@ -589,13 +589,13 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
rc = fsetpos(fpin, &(cur->eb_top));
if (rc < 0)
goto out;
- fseek(fpin, ubi32_to_cpu(cur->ec.data_offset), SEEK_CUR);
+ fseek(fpin, __be32_to_cpu(cur->ec.data_offset), SEEK_CUR);
if (cur->vid.vol_type == UBI_VID_DYNAMIC)
/* FIXME It might be that alignment has influence */
data_size = block_size - header_size;
else
- data_size = ubi32_to_cpu(cur->vid.data_size);
+ data_size = __be32_to_cpu(cur->vid.data_size);
for (i = 0; i < data_size; i++) {
int c = fgetc(fpin);
@@ -683,7 +683,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
}
/* check erasecounter header magic */
- if (ubi32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC) {
+ if (__be32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC) {
snprintf(reason, MAXPATH, ".invalid.ec_magic");
goto invalid;
}
@@ -691,7 +691,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* check erasecounter header crc */
crc = clc_crc32(crc32_table, UBI_CRC32_INIT, &(cur->ec),
UBI_EC_HDR_SIZE_CRC);
- if (ubi32_to_cpu(cur->ec.hdr_crc) != crc) {
+ if (__be32_to_cpu(cur->ec.hdr_crc) != crc) {
snprintf(reason, MAXPATH, ".invalid.ec_hdr_crc");
goto invalid;
}
@@ -700,7 +700,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
rc = fsetpos(fpin, &(cur->eb_top));
if (rc != 0)
goto err;
- fseek(fpin, ubi32_to_cpu(cur->ec.vid_hdr_offset), SEEK_CUR);
+ fseek(fpin, __be32_to_cpu(cur->ec.vid_hdr_offset), SEEK_CUR);
rc = fread(&cur->vid, 1, sizeof(cur->vid), fpin);
if (rc == 0)
goto out; /* EOF */
@@ -712,14 +712,14 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* if the magic number is 0xFFFFFFFF, then it's very likely
* that the volume is empty */
- if (ubi32_to_cpu(cur->vid.magic) == 0xffffffff) {
+ if (__be32_to_cpu(cur->vid.magic) == 0xffffffff) {
snprintf(reason, MAXPATH, ".empty");
goto invalid;
}
/* vol_id should be in bounds */
- if ((ubi32_to_cpu(cur->vid.vol_id) >= UBI_MAX_VOLUMES) &&
- (ubi32_to_cpu(cur->vid.vol_id) <
+ if ((__be32_to_cpu(cur->vid.vol_id) >= UBI_MAX_VOLUMES) &&
+ (__be32_to_cpu(cur->vid.vol_id) <
UBI_INTERNAL_VOL_START)) {
snprintf(reason, MAXPATH, ".invalid");
goto invalid;
@@ -727,7 +727,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
raw_path = FN_NSURE;
/* check volume id header magic */
- if (ubi32_to_cpu(cur->vid.magic) != UBI_VID_HDR_MAGIC) {
+ if (__be32_to_cpu(cur->vid.magic) != UBI_VID_HDR_MAGIC) {
snprintf(reason, MAXPATH, ".invalid.vid_magic");
goto invalid;
}
@@ -736,7 +736,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* check volume id header crc */
crc = clc_crc32(crc32_table, UBI_CRC32_INIT, &(cur->vid),
UBI_VID_HDR_SIZE_CRC);
- if (ubi32_to_cpu(cur->vid.hdr_crc) != crc) {
+ if (__be32_to_cpu(cur->vid.hdr_crc) != crc) {
snprintf(reason, MAXPATH, ".invalid.vid_hdr_crc");
goto invalid;
}
@@ -744,11 +744,11 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* check data crc, but only for a static volume */
if (cur->vid.vol_type == UBI_VID_STATIC) {
- rc = data_crc(fpin, ubi32_to_cpu(cur->vid.data_size),
+ rc = data_crc(fpin, __be32_to_cpu(cur->vid.data_size),
&crc);
if (rc < 0)
goto err;
- if (ubi32_to_cpu(cur->vid.data_crc) != crc) {
+ if (__be32_to_cpu(cur->vid.data_crc) != crc) {
snprintf(reason, MAXPATH, ".invalid.data_crc");
goto invalid;
}
@@ -771,7 +771,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* extract info-table */
if (a->itable &&
- (ubi32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOL_ID)) {
+ (__be32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOL_ID)) {
extract_itable(fpin, cur, a->bsize,
itable_num, a->odir_path);
itable_num++;
@@ -799,10 +799,10 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
always right ... */
size = a->bsize - a->hsize;
} else
- size = ubi32_to_cpu(cur->vid.data_size);
+ size = __be32_to_cpu(cur->vid.data_size);
fseek(fpin,
- ubi32_to_cpu(cur->ec.data_offset),
+ __be32_to_cpu(cur->ec.data_offset),
SEEK_CUR);
}
else if (a->vol_split == SPLIT_RAW)
@@ -811,9 +811,9 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
snprintf(filename, MAXPATH, FN_VOLSP,
a->odir_path,
- ubi32_to_cpu(cur->vid.vol_id),
- ubi32_to_cpu(cur->vid.lnum),
- ubi32_to_cpu(cur->vid.leb_ver), count);
+ __be32_to_cpu(cur->vid.vol_id),
+ __be32_to_cpu(cur->vid.lnum),
+ __be32_to_cpu(cur->vid.leb_ver), count);
rc = extract_data(fpin, size, filename);
if (rc < 0)
goto err;
@@ -834,9 +834,9 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
snprintf(filename, MAXPATH, raw_path,
a->odir_path,
count,
- ubi32_to_cpu(cur->vid.vol_id),
- ubi32_to_cpu(cur->vid.lnum),
- ubi32_to_cpu(cur->vid.leb_ver),
+ __be32_to_cpu(cur->vid.vol_id),
+ __be32_to_cpu(cur->vid.lnum),
+ __be32_to_cpu(cur->vid.leb_ver),
reason);
rc = extract_data(fpin, a->bsize, filename);
diff --git a/ubi-utils/src/unubi_analyze.c b/ubi-utils/src/unubi_analyze.c
index c2fbe47..2ab3b87 100644
--- a/ubi-utils/src/unubi_analyze.c
+++ b/ubi-utils/src/unubi_analyze.c
@@ -151,7 +151,7 @@ unubi_analyze_ec_hdr(struct eb_info *first, const char *path)
count = 0;
cur = first;
while (cur != NULL) {
- erase_counts[count] = ubi64_to_cpu(cur->ec.ec);
+ erase_counts[count] = __be64_to_cpu(cur->ec.ec);
cur = cur->next;
count++;
}
@@ -167,21 +167,21 @@ unubi_analyze_ec_hdr(struct eb_info *first, const char *path)
crc = clc_crc32(crc32_table, UBI_CRC32_INIT, &cur->ec,
UBI_EC_HDR_SIZE_CRC);
- if ((ubi32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC) ||
- (crc != ubi32_to_cpu(cur->ec.hdr_crc)))
+ if ((__be32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC) ||
+ (crc != __be32_to_cpu(cur->ec.hdr_crc)))
fprintf(fpdata, "# ");
fprintf(fpdata, "%u %llu %llu", count,
- ubi64_to_cpu(cur->ec.ec),
+ __be64_to_cpu(cur->ec.ec),
erase_counts[count]);
- if (ubi32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC)
+ if (__be32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC)
fprintf(fpdata, " ## bad magic: %08x",
- ubi32_to_cpu(cur->ec.magic));
+ __be32_to_cpu(cur->ec.magic));
- if (crc != ubi32_to_cpu(cur->ec.hdr_crc))
+ if (crc != __be32_to_cpu(cur->ec.hdr_crc))
fprintf(fpdata, " ## CRC mismatch: given=%08x, "
- "calc=%08x", ubi32_to_cpu(cur->ec.hdr_crc),
+ "calc=%08x", __be32_to_cpu(cur->ec.hdr_crc),
crc);
fprintf(fpdata, "\n");
@@ -303,8 +303,8 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
count = 0;
cur = *head;
while (cur != NULL) {
- leb_versions[count] = ubi32_to_cpu(cur->vid.leb_ver);
- data_sizes[count] = ubi32_to_cpu(cur->vid.data_size);
+ leb_versions[count] = __be32_to_cpu(cur->vid.leb_ver);
+ data_sizes[count] = __be32_to_cpu(cur->vid.data_size);
cur = cur->next;
count++;
}
@@ -317,9 +317,9 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
fprintf(fpdata, "# x_axis vol_id lnum y1_axis leb_ver "
"y2_axis data_size\n");
while (cur != NULL) {
- y1 = norm_index(ubi32_to_cpu(cur->vid.leb_ver), leb_versions,
+ y1 = norm_index(__be32_to_cpu(cur->vid.leb_ver), leb_versions,
breadth);
- y2 = norm_index(ubi32_to_cpu(cur->vid.data_size), data_sizes,
+ y2 = norm_index(__be32_to_cpu(cur->vid.data_size), data_sizes,
breadth);
if ((y1 == -1) || (y2 == -1)) {
@@ -329,12 +329,12 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
fprintf(fpdata, "%u %u %u %u %u %u %u\n",
count,
- ubi32_to_cpu(cur->vid.vol_id),
- ubi32_to_cpu(cur->vid.lnum),
+ __be32_to_cpu(cur->vid.vol_id),
+ __be32_to_cpu(cur->vid.lnum),
y1,
- ubi32_to_cpu(cur->vid.leb_ver),
+ __be32_to_cpu(cur->vid.leb_ver),
y2,
- ubi32_to_cpu(cur->vid.data_size));
+ __be32_to_cpu(cur->vid.data_size));
cur = cur->next;
count++;
}
@@ -350,13 +350,13 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
while (cur != NULL) {
if (count > 0)
fprintf(fpplot, ", ");
- if (step != ubi32_to_cpu(cur->vid.vol_id)) {
- step = ubi32_to_cpu(cur->vid.vol_id);
+ if (step != __be32_to_cpu(cur->vid.vol_id)) {
+ step = __be32_to_cpu(cur->vid.vol_id);
fprintf(fpplot, "\"%d\" %d 0", step, count);
}
else
fprintf(fpplot, "\"%d\" %d 1",
- ubi32_to_cpu(cur->vid.lnum), count);
+ __be32_to_cpu(cur->vid.lnum), count);
cur = cur->next;
count++;
}
@@ -369,7 +369,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
fprintf(fpplot, "set ylabel \"leb version\"\n");
fprintf(fpplot, "set ytics (");
while (cur->next != NULL) {
- y1 = norm_index(ubi32_to_cpu(cur->vid.leb_ver), leb_versions,
+ y1 = norm_index(__be32_to_cpu(cur->vid.leb_ver), leb_versions,
breadth);
if (y1 == -1) {
@@ -380,7 +380,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
if (count > 0)
fprintf(fpplot, ", ");
- fprintf(fpplot, "\"%u\" %u", ubi32_to_cpu(cur->vid.leb_ver),
+ fprintf(fpplot, "\"%u\" %u", __be32_to_cpu(cur->vid.leb_ver),
y1);
cur = cur->next;
@@ -394,7 +394,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
fprintf(fpplot, "set y2label \"data size\"\n");
fprintf(fpplot, "set y2tics (");
while (cur != NULL) {
- y2 = norm_index(ubi32_to_cpu(cur->vid.data_size),
+ y2 = norm_index(__be32_to_cpu(cur->vid.data_size),
data_sizes, breadth);
if (y2 == -1) {
@@ -405,7 +405,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path)
if (count > 0)
fprintf(fpplot, ", ");
- fprintf(fpplot, "\"%u\" %u", ubi32_to_cpu(cur->vid.data_size),
+ fprintf(fpplot, "\"%u\" %u", __be32_to_cpu(cur->vid.data_size),
y2);
cur = cur->next;