summaryrefslogtreecommitdiff
path: root/ubi-utils/old-tools/src/unubi.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-01-25 17:54:50 +0200
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-01-25 17:54:50 +0200
commitce6f15501c7f93ec887e9b2ef764ed4adee75a4c (patch)
treed1142ac63621a2e2d56da688f7b95746e30360d6 /ubi-utils/old-tools/src/unubi.c
parent22c86621f29f4ef7166fa16c9c0b1fd6aff2f887 (diff)
ubi-utils: use mtd_swab.h
Do not relay on asm/byteorder and use mtd_swab.h instead Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'ubi-utils/old-tools/src/unubi.c')
-rw-r--r--ubi-utils/old-tools/src/unubi.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/ubi-utils/old-tools/src/unubi.c b/ubi-utils/old-tools/src/unubi.c
index 8d16192..8a022a3 100644
--- a/ubi-utils/old-tools/src/unubi.c
+++ b/ubi-utils/old-tools/src/unubi.c
@@ -50,6 +50,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <mtd/ubi-header.h>
+#include <mtd_swab.h>
#include "crc32.h"
#include "unubi_analyze.h"
@@ -428,10 +429,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, __be32_to_cpu(cur->ec.data_offset), SEEK_CUR);
+ fseek(fpin, be32_to_cpu(cur->ec.data_offset), SEEK_CUR);
/* prepare output file */
- if (__be32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOLUME_ID)
+ if (be32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOLUME_ID)
return -2;
memset(filename, 0, MAXPATH + 1);
snprintf(filename, MAXPATH, FN_VITBL, path, num);
@@ -442,7 +443,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 - __be32_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 +465,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 != __be32_to_cpu(rec.crc))
+ if (crc != be32_to_cpu(rec.crc))
continue;
/* check for empty */
@@ -487,16 +488,16 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
type = "static\0";
/* prep name string */
- rec.name[__be16_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,
- __be32_to_cpu(rec.reserved_pebs),
- __be32_to_cpu(rec.alignment),
+ be32_to_cpu(rec.reserved_pebs),
+ be32_to_cpu(rec.alignment),
type,
- __be32_to_cpu(rec.crc),
+ be32_to_cpu(rec.crc),
name);
}
@@ -534,7 +535,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 = __be32_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 +557,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
while (cur != NULL) {
size_t i;
- if (__be32_to_cpu(cur->vid.vol_id) != vol) {
+ if (be32_to_cpu(cur->vid.vol_id) != vol) {
/* close out file */
fclose(fpout);
@@ -565,7 +566,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
goto out;
/* begin with next */
- vol = __be32_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 +577,7 @@ rebuild_volume(FILE * fpin, uint32_t *vol_id, struct eb_info **head,
}
}
- while (num < __be32_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 +590,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, __be32_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 = __be32_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 +684,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
}
/* check erasecounter header magic */
- if (__be32_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 +692,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 (__be32_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 +701,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, __be32_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 +713,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 (__be32_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 ((__be32_to_cpu(cur->vid.vol_id) >= UBI_MAX_VOLUMES) &&
- (__be32_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 +728,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
raw_path = FN_NSURE;
/* check volume id header magic */
- if (__be32_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 +737,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 (__be32_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 +745,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, __be32_to_cpu(cur->vid.data_size),
+ rc = data_crc(fpin, be32_to_cpu(cur->vid.data_size),
&crc);
if (rc < 0)
goto err;
- if (__be32_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 +772,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
/* extract info-table */
if (a->itable &&
- (__be32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOLUME_ID)) {
+ (be32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOLUME_ID)) {
extract_itable(fpin, cur, a->bsize,
itable_num, a->odir_path);
itable_num++;
@@ -799,10 +800,10 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
always right ... */
size = a->bsize - a->hsize;
} else
- size = __be32_to_cpu(cur->vid.data_size);
+ size = be32_to_cpu(cur->vid.data_size);
fseek(fpin,
- __be32_to_cpu(cur->ec.data_offset),
+ be32_to_cpu(cur->ec.data_offset),
SEEK_CUR);
}
else if (a->vol_split == SPLIT_RAW)
@@ -811,9 +812,9 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
snprintf(filename, MAXPATH, FN_VOLSP,
a->odir_path,
- __be32_to_cpu(cur->vid.vol_id),
- __be32_to_cpu(cur->vid.lnum),
- __be32_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 +835,9 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
snprintf(filename, MAXPATH, raw_path,
a->odir_path,
count,
- __be32_to_cpu(cur->vid.vol_id),
- __be32_to_cpu(cur->vid.lnum),
- __be32_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);