diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-01-25 17:54:50 +0200 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-01-25 17:54:50 +0200 |
commit | ce6f15501c7f93ec887e9b2ef764ed4adee75a4c (patch) | |
tree | d1142ac63621a2e2d56da688f7b95746e30360d6 /ubi-utils/old-tools | |
parent | 22c86621f29f4ef7166fa16c9c0b1fd6aff2f887 (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')
-rw-r--r-- | ubi-utils/old-tools/src/eb_chain.c | 43 | ||||
-rw-r--r-- | ubi-utils/old-tools/src/libubigen.c | 54 | ||||
-rw-r--r-- | ubi-utils/old-tools/src/pfi2bin.c | 2 | ||||
-rw-r--r-- | ubi-utils/old-tools/src/ubigen.h | 1 | ||||
-rw-r--r-- | ubi-utils/old-tools/src/unubi.c | 67 | ||||
-rw-r--r-- | ubi-utils/old-tools/src/unubi_analyze.c | 47 |
6 files changed, 109 insertions, 105 deletions
diff --git a/ubi-utils/old-tools/src/eb_chain.c b/ubi-utils/old-tools/src/eb_chain.c index a018ae6..4647cf4 100644 --- a/ubi-utils/old-tools/src/eb_chain.c +++ b/ubi-utils/old-tools/src/eb_chain.c @@ -26,6 +26,7 @@ #include <errno.h> #include <stdlib.h> #include <string.h> +#include <mtd_swab.h> #include "unubi_analyze.h" #include "crc32.h" @@ -65,9 +66,9 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new) return 0; } - 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); + 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 +76,8 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new) prev = NULL; /* traverse until vol_id/lnum align */ - vol = __be32_to_cpu(cur->vid.vol_id); - num = __be32_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 +89,8 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new) prev = cur; cur = cur->next; - vol = __be32_to_cpu(cur->vid.vol_id); - num = __be32_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 +112,7 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new) prev = NULL; /* traverse until versions align */ - ver = __be32_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 +125,7 @@ eb_chain_insert(struct eb_info **head, struct eb_info *new) prev = hist; hist = hist->older; - ver = __be32_to_cpu(hist->vid.leb_ver); + ver = be32_to_cpu(hist->vid.leb_ver); } if (prev == NULL) { @@ -168,8 +169,8 @@ eb_chain_position(struct eb_info **head, uint32_t vol_id, uint32_t *lnum, cur = *head; while (cur != NULL) { - vol = __be32_to_cpu(cur->vid.vol_id); - num = __be32_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 +211,24 @@ eb_chain_print(FILE* stream, struct eb_info *head) struct eb_info *hist; fprintf(stream, "%08x %-8u %08x %-4s%-4s", - __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), 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, __be32_to_cpu(cur->vid.data_size), - __be64_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", - __be32_to_cpu(hist->vid.vol_id), - __be32_to_cpu(hist->vid.lnum), - __be32_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 +236,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, - __be32_to_cpu(hist->vid.data_size), - __be64_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/old-tools/src/libubigen.c b/ubi-utils/old-tools/src/libubigen.c index 87c8c40..d2cd087 100644 --- a/ubi-utils/old-tools/src/libubigen.c +++ b/ubi-utils/old-tools/src/libubigen.c @@ -78,7 +78,7 @@ validate_ubi_info(ubi_info_t u) return EUBIGEN_INVALID_TYPE; } - if (__be32_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_be32(data_size); - u->v->data_crc = __cpu_to_be32(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_be32(__be32_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_be32(__be32_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_be32(crc); + u->v->hdr_crc = cpu_to_be32(crc); if (action & BROKEN_HDR_CRC) { - u->v->hdr_crc = __cpu_to_be32(__be32_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_be32(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", __be32_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", - __be32_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", - __be32_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", - __be32_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_be32(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_be32(vol_id); + res->v->vol_id = cpu_to_be32(vol_id); res->v->compat = compat_flag; - res->v->data_pad = __cpu_to_be32(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_be32(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_be32(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_be64(ec); - res->ec->vid_hdr_offset = __cpu_to_be32(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_be32(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_be32(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 + __be32_to_cpu(res->ec->vid_hdr_offset); - res->ptr_data = res->buf + __be32_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); @@ -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_be32(byte_to_blk(reserved_bytes, u->leb_size)); - lvol_rec->alignment = __cpu_to_be32(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_be16((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_be32(crc); + lvol_rec->crc = cpu_to_be32(crc); return 0; } diff --git a/ubi-utils/old-tools/src/pfi2bin.c b/ubi-utils/old-tools/src/pfi2bin.c index fc16760..3300df2 100644 --- a/ubi-utils/old-tools/src/pfi2bin.c +++ b/ubi-utils/old-tools/src/pfi2bin.c @@ -494,7 +494,7 @@ init_vol_tab(struct ubi_vtbl_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_be32(crc); + res[i].crc = cpu_to_be32(crc); } *vol_tab = res; diff --git a/ubi-utils/old-tools/src/ubigen.h b/ubi-utils/old-tools/src/ubigen.h index 0f43a46..07f845f 100644 --- a/ubi-utils/old-tools/src/ubigen.h +++ b/ubi-utils/old-tools/src/ubigen.h @@ -25,6 +25,7 @@ #include <stdio.h> /* FILE */ #include <stdint.h> #include <mtd/ubi-header.h> +#include <mtd_swab.h> #ifdef __cplusplus extern "C" { 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); diff --git a/ubi-utils/old-tools/src/unubi_analyze.c b/ubi-utils/old-tools/src/unubi_analyze.c index 2ab3b87..182100e 100644 --- a/ubi-utils/old-tools/src/unubi_analyze.c +++ b/ubi-utils/old-tools/src/unubi_analyze.c @@ -35,6 +35,7 @@ #include <limits.h> #include <sys/types.h> #include <sys/stat.h> +#include <mtd_swab.h> #include "unubi_analyze.h" #include "crc32.h" @@ -151,7 +152,7 @@ unubi_analyze_ec_hdr(struct eb_info *first, const char *path) count = 0; cur = first; while (cur != NULL) { - erase_counts[count] = __be64_to_cpu(cur->ec.ec); + erase_counts[count] = be64_to_cpu(cur->ec.ec); cur = cur->next; count++; } @@ -167,21 +168,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 ((__be32_to_cpu(cur->ec.magic) != UBI_EC_HDR_MAGIC) || - (crc != __be32_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, - __be64_to_cpu(cur->ec.ec), + be64_to_cpu(cur->ec.ec), erase_counts[count]); - if (__be32_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", - __be32_to_cpu(cur->ec.magic)); + be32_to_cpu(cur->ec.magic)); - if (crc != __be32_to_cpu(cur->ec.hdr_crc)) + if (crc != be32_to_cpu(cur->ec.hdr_crc)) fprintf(fpdata, " ## CRC mismatch: given=%08x, " - "calc=%08x", __be32_to_cpu(cur->ec.hdr_crc), + "calc=%08x", be32_to_cpu(cur->ec.hdr_crc), crc); fprintf(fpdata, "\n"); @@ -303,8 +304,8 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path) count = 0; cur = *head; while (cur != NULL) { - leb_versions[count] = __be32_to_cpu(cur->vid.leb_ver); - data_sizes[count] = __be32_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 +318,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(__be32_to_cpu(cur->vid.leb_ver), leb_versions, + y1 = norm_index(be32_to_cpu(cur->vid.leb_ver), leb_versions, breadth); - y2 = norm_index(__be32_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 +330,12 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path) fprintf(fpdata, "%u %u %u %u %u %u %u\n", count, - __be32_to_cpu(cur->vid.vol_id), - __be32_to_cpu(cur->vid.lnum), + be32_to_cpu(cur->vid.vol_id), + be32_to_cpu(cur->vid.lnum), y1, - __be32_to_cpu(cur->vid.leb_ver), + be32_to_cpu(cur->vid.leb_ver), y2, - __be32_to_cpu(cur->vid.data_size)); + be32_to_cpu(cur->vid.data_size)); cur = cur->next; count++; } @@ -350,13 +351,13 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path) while (cur != NULL) { if (count > 0) fprintf(fpplot, ", "); - if (step != __be32_to_cpu(cur->vid.vol_id)) { - step = __be32_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", - __be32_to_cpu(cur->vid.lnum), count); + be32_to_cpu(cur->vid.lnum), count); cur = cur->next; count++; } @@ -369,7 +370,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(__be32_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 +381,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path) if (count > 0) fprintf(fpplot, ", "); - fprintf(fpplot, "\"%u\" %u", __be32_to_cpu(cur->vid.leb_ver), + fprintf(fpplot, "\"%u\" %u", be32_to_cpu(cur->vid.leb_ver), y1); cur = cur->next; @@ -394,7 +395,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(__be32_to_cpu(cur->vid.data_size), + y2 = norm_index(be32_to_cpu(cur->vid.data_size), data_sizes, breadth); if (y2 == -1) { @@ -405,7 +406,7 @@ unubi_analyze_vid_hdr(struct eb_info **head, const char *path) if (count > 0) fprintf(fpplot, ", "); - fprintf(fpplot, "\"%u\" %u", __be32_to_cpu(cur->vid.data_size), + fprintf(fpplot, "\"%u\" %u", be32_to_cpu(cur->vid.data_size), y2); cur = cur->next; |