Commit 3261ebd7 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Artem Bityutskiy

UBI: kill homegrown endian macros

Kill UBI's homegrown endianess handling and replace it with
the standard kernel endianess handling.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent bf07803a
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
{ {
dbg_msg("erase counter header dump:"); dbg_msg("erase counter header dump:");
dbg_msg("magic %#08x", ubi32_to_cpu(ec_hdr->magic)); dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic));
dbg_msg("version %d", (int)ec_hdr->version); dbg_msg("version %d", (int)ec_hdr->version);
dbg_msg("ec %llu", (long long)ubi64_to_cpu(ec_hdr->ec)); dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec));
dbg_msg("vid_hdr_offset %d", ubi32_to_cpu(ec_hdr->vid_hdr_offset)); dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset));
dbg_msg("data_offset %d", ubi32_to_cpu(ec_hdr->data_offset)); dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset));
dbg_msg("hdr_crc %#08x", ubi32_to_cpu(ec_hdr->hdr_crc)); dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc));
dbg_msg("erase counter header hexdump:"); dbg_msg("erase counter header hexdump:");
ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE); ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE);
} }
...@@ -52,20 +52,20 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) ...@@ -52,20 +52,20 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
{ {
dbg_msg("volume identifier header dump:"); dbg_msg("volume identifier header dump:");
dbg_msg("magic %08x", ubi32_to_cpu(vid_hdr->magic)); dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic));
dbg_msg("version %d", (int)vid_hdr->version); dbg_msg("version %d", (int)vid_hdr->version);
dbg_msg("vol_type %d", (int)vid_hdr->vol_type); dbg_msg("vol_type %d", (int)vid_hdr->vol_type);
dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag); dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag);
dbg_msg("compat %d", (int)vid_hdr->compat); dbg_msg("compat %d", (int)vid_hdr->compat);
dbg_msg("vol_id %d", ubi32_to_cpu(vid_hdr->vol_id)); dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id));
dbg_msg("lnum %d", ubi32_to_cpu(vid_hdr->lnum)); dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum));
dbg_msg("leb_ver %u", ubi32_to_cpu(vid_hdr->leb_ver)); dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver));
dbg_msg("data_size %d", ubi32_to_cpu(vid_hdr->data_size)); dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size));
dbg_msg("used_ebs %d", ubi32_to_cpu(vid_hdr->used_ebs)); dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs));
dbg_msg("data_pad %d", ubi32_to_cpu(vid_hdr->data_pad)); dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad));
dbg_msg("sqnum %llu", dbg_msg("sqnum %llu",
(unsigned long long)ubi64_to_cpu(vid_hdr->sqnum)); (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
dbg_msg("hdr_crc %08x", ubi32_to_cpu(vid_hdr->hdr_crc)); dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc));
dbg_msg("volume identifier header hexdump:"); dbg_msg("volume identifier header hexdump:");
} }
...@@ -106,12 +106,12 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) ...@@ -106,12 +106,12 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
*/ */
void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
{ {
int name_len = ubi16_to_cpu(r->name_len); int name_len = be16_to_cpu(r->name_len);
dbg_msg("volume table record %d dump:", idx); dbg_msg("volume table record %d dump:", idx);
dbg_msg("reserved_pebs %d", ubi32_to_cpu(r->reserved_pebs)); dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs));
dbg_msg("alignment %d", ubi32_to_cpu(r->alignment)); dbg_msg("alignment %d", be32_to_cpu(r->alignment));
dbg_msg("data_pad %d", ubi32_to_cpu(r->data_pad)); dbg_msg("data_pad %d", be32_to_cpu(r->data_pad));
dbg_msg("vol_type %d", (int)r->vol_type); dbg_msg("vol_type %d", (int)r->vol_type);
dbg_msg("upd_marker %d", (int)r->upd_marker); dbg_msg("upd_marker %d", (int)r->upd_marker);
dbg_msg("name_len %d", name_len); dbg_msg("name_len %d", name_len);
...@@ -129,7 +129,7 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) ...@@ -129,7 +129,7 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
r->name[0], r->name[1], r->name[2], r->name[3], r->name[0], r->name[1], r->name[2], r->name[3],
r->name[4]); r->name[4]);
} }
dbg_msg("crc %#08x", ubi32_to_cpu(r->crc)); dbg_msg("crc %#08x", be32_to_cpu(r->crc));
} }
/** /**
......
...@@ -425,10 +425,10 @@ retry: ...@@ -425,10 +425,10 @@ retry:
} else if (err == UBI_IO_BITFLIPS) } else if (err == UBI_IO_BITFLIPS)
scrub = 1; scrub = 1;
ubi_assert(lnum < ubi32_to_cpu(vid_hdr->used_ebs)); ubi_assert(lnum < be32_to_cpu(vid_hdr->used_ebs));
ubi_assert(len == ubi32_to_cpu(vid_hdr->data_size)); ubi_assert(len == be32_to_cpu(vid_hdr->data_size));
crc = ubi32_to_cpu(vid_hdr->data_crc); crc = be32_to_cpu(vid_hdr->data_crc);
ubi_free_vid_hdr(ubi, vid_hdr); ubi_free_vid_hdr(ubi, vid_hdr);
} }
...@@ -518,7 +518,7 @@ retry: ...@@ -518,7 +518,7 @@ retry:
goto out_put; goto out_put;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr); err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr);
if (err) if (err)
goto write_error; goto write_error;
...@@ -634,11 +634,11 @@ int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum, ...@@ -634,11 +634,11 @@ int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum,
} }
vid_hdr->vol_type = UBI_VID_DYNAMIC; vid_hdr->vol_type = UBI_VID_DYNAMIC;
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
vid_hdr->vol_id = cpu_to_ubi32(vol_id); vid_hdr->vol_id = cpu_to_be32(vol_id);
vid_hdr->lnum = cpu_to_ubi32(lnum); vid_hdr->lnum = cpu_to_be32(lnum);
vid_hdr->compat = ubi_get_compat(ubi, vol_id); vid_hdr->compat = ubi_get_compat(ubi, vol_id);
vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); vid_hdr->data_pad = cpu_to_be32(vol->data_pad);
retry: retry:
pnum = ubi_wl_get_peb(ubi, dtype); pnum = ubi_wl_get_peb(ubi, dtype);
...@@ -692,7 +692,7 @@ write_error: ...@@ -692,7 +692,7 @@ write_error:
return err; return err;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
ubi_msg("try another PEB"); ubi_msg("try another PEB");
goto retry; goto retry;
} }
...@@ -748,17 +748,17 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum, ...@@ -748,17 +748,17 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum,
return err; return err;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
vid_hdr->vol_id = cpu_to_ubi32(vol_id); vid_hdr->vol_id = cpu_to_be32(vol_id);
vid_hdr->lnum = cpu_to_ubi32(lnum); vid_hdr->lnum = cpu_to_be32(lnum);
vid_hdr->compat = ubi_get_compat(ubi, vol_id); vid_hdr->compat = ubi_get_compat(ubi, vol_id);
vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); vid_hdr->data_pad = cpu_to_be32(vol->data_pad);
crc = crc32(UBI_CRC32_INIT, buf, data_size); crc = crc32(UBI_CRC32_INIT, buf, data_size);
vid_hdr->vol_type = UBI_VID_STATIC; vid_hdr->vol_type = UBI_VID_STATIC;
vid_hdr->data_size = cpu_to_ubi32(data_size); vid_hdr->data_size = cpu_to_be32(data_size);
vid_hdr->used_ebs = cpu_to_ubi32(used_ebs); vid_hdr->used_ebs = cpu_to_be32(used_ebs);
vid_hdr->data_crc = cpu_to_ubi32(crc); vid_hdr->data_crc = cpu_to_be32(crc);
retry: retry:
pnum = ubi_wl_get_peb(ubi, dtype); pnum = ubi_wl_get_peb(ubi, dtype);
...@@ -813,7 +813,7 @@ write_error: ...@@ -813,7 +813,7 @@ write_error:
return err; return err;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
ubi_msg("try another PEB"); ubi_msg("try another PEB");
goto retry; goto retry;
} }
...@@ -854,17 +854,17 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum, ...@@ -854,17 +854,17 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum,
return err; return err;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
vid_hdr->vol_id = cpu_to_ubi32(vol_id); vid_hdr->vol_id = cpu_to_be32(vol_id);
vid_hdr->lnum = cpu_to_ubi32(lnum); vid_hdr->lnum = cpu_to_be32(lnum);
vid_hdr->compat = ubi_get_compat(ubi, vol_id); vid_hdr->compat = ubi_get_compat(ubi, vol_id);
vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); vid_hdr->data_pad = cpu_to_be32(vol->data_pad);
crc = crc32(UBI_CRC32_INIT, buf, len); crc = crc32(UBI_CRC32_INIT, buf, len);
vid_hdr->vol_type = UBI_VID_STATIC; vid_hdr->vol_type = UBI_VID_STATIC;
vid_hdr->data_size = cpu_to_ubi32(len); vid_hdr->data_size = cpu_to_be32(len);
vid_hdr->copy_flag = 1; vid_hdr->copy_flag = 1;
vid_hdr->data_crc = cpu_to_ubi32(crc); vid_hdr->data_crc = cpu_to_be32(crc);
retry: retry:
pnum = ubi_wl_get_peb(ubi, dtype); pnum = ubi_wl_get_peb(ubi, dtype);
...@@ -924,7 +924,7 @@ write_error: ...@@ -924,7 +924,7 @@ write_error:
return err; return err;
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
ubi_msg("try another PEB"); ubi_msg("try another PEB");
goto retry; goto retry;
} }
...@@ -965,17 +965,17 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -965,17 +965,17 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
uint32_t crc; uint32_t crc;
void *buf, *buf1 = NULL; void *buf, *buf1 = NULL;
vol_id = ubi32_to_cpu(vid_hdr->vol_id); vol_id = be32_to_cpu(vid_hdr->vol_id);
lnum = ubi32_to_cpu(vid_hdr->lnum); lnum = be32_to_cpu(vid_hdr->lnum);
dbg_eba("copy LEB %d:%d, PEB %d to PEB %d", vol_id, lnum, from, to); dbg_eba("copy LEB %d:%d, PEB %d to PEB %d", vol_id, lnum, from, to);
if (vid_hdr->vol_type == UBI_VID_STATIC) { if (vid_hdr->vol_type == UBI_VID_STATIC) {
data_size = ubi32_to_cpu(vid_hdr->data_size); data_size = be32_to_cpu(vid_hdr->data_size);
aldata_size = ALIGN(data_size, ubi->min_io_size); aldata_size = ALIGN(data_size, ubi->min_io_size);
} else } else
data_size = aldata_size = data_size = aldata_size =
ubi->leb_size - ubi32_to_cpu(vid_hdr->data_pad); ubi->leb_size - be32_to_cpu(vid_hdr->data_pad);
buf = vmalloc(aldata_size); buf = vmalloc(aldata_size);
if (!buf) if (!buf)
...@@ -1054,10 +1054,10 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, ...@@ -1054,10 +1054,10 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
*/ */
if (data_size > 0) { if (data_size > 0) {
vid_hdr->copy_flag = 1; vid_hdr->copy_flag = 1;
vid_hdr->data_size = cpu_to_ubi32(data_size); vid_hdr->data_size = cpu_to_be32(data_size);
vid_hdr->data_crc = cpu_to_ubi32(crc); vid_hdr->data_crc = cpu_to_be32(crc);
} }
vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
err = ubi_io_write_vid_hdr(ubi, to, vid_hdr); err = ubi_io_write_vid_hdr(ubi, to, vid_hdr);
if (err) if (err)
......
...@@ -557,9 +557,9 @@ static int validate_ec_hdr(const struct ubi_device *ubi, ...@@ -557,9 +557,9 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
long long ec; long long ec;
int vid_hdr_offset, leb_start; int vid_hdr_offset, leb_start;
ec = ubi64_to_cpu(ec_hdr->ec); ec = be64_to_cpu(ec_hdr->ec);
vid_hdr_offset = ubi32_to_cpu(ec_hdr->vid_hdr_offset); vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset);
leb_start = ubi32_to_cpu(ec_hdr->data_offset); leb_start = be32_to_cpu(ec_hdr->data_offset);
if (ec_hdr->version != UBI_VERSION) { if (ec_hdr->version != UBI_VERSION) {
ubi_err("node with incompatible UBI version found: " ubi_err("node with incompatible UBI version found: "
...@@ -640,7 +640,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum, ...@@ -640,7 +640,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum,
read_err = err; read_err = err;
} }
magic = ubi32_to_cpu(ec_hdr->magic); magic = be32_to_cpu(ec_hdr->magic);
if (magic != UBI_EC_HDR_MAGIC) { if (magic != UBI_EC_HDR_MAGIC) {
/* /*
* The magic field is wrong. Let's check if we have read all * The magic field is wrong. Let's check if we have read all
...@@ -684,7 +684,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum, ...@@ -684,7 +684,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum,
} }
crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);
if (hdr_crc != crc) { if (hdr_crc != crc) {
if (verbose) { if (verbose) {
...@@ -729,12 +729,12 @@ int ubi_io_write_ec_hdr(const struct ubi_device *ubi, int pnum, ...@@ -729,12 +729,12 @@ int ubi_io_write_ec_hdr(const struct ubi_device *ubi, int pnum,
dbg_io("write EC header to PEB %d", pnum); dbg_io("write EC header to PEB %d", pnum);
ubi_assert(pnum >= 0 && pnum < ubi->peb_count); ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
ec_hdr->magic = cpu_to_ubi32(UBI_EC_HDR_MAGIC); ec_hdr->magic = cpu_to_be32(UBI_EC_HDR_MAGIC);
ec_hdr->version = UBI_VERSION; ec_hdr->version = UBI_VERSION;
ec_hdr->vid_hdr_offset = cpu_to_ubi32(ubi->vid_hdr_offset); ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset);
ec_hdr->data_offset = cpu_to_ubi32(ubi->leb_start); ec_hdr->data_offset = cpu_to_be32(ubi->leb_start);
crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
ec_hdr->hdr_crc = cpu_to_ubi32(crc); ec_hdr->hdr_crc = cpu_to_be32(crc);
err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
if (err) if (err)
...@@ -757,13 +757,13 @@ static int validate_vid_hdr(const struct ubi_device *ubi, ...@@ -757,13 +757,13 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
{ {
int vol_type = vid_hdr->vol_type; int vol_type = vid_hdr->vol_type;
int copy_flag = vid_hdr->copy_flag; int copy_flag = vid_hdr->copy_flag;
int vol_id = ubi32_to_cpu(vid_hdr->vol_id); int vol_id = be32_to_cpu(vid_hdr->vol_id);
int lnum = ubi32_to_cpu(vid_hdr->lnum); int lnum = be32_to_cpu(vid_hdr->lnum);
int compat = vid_hdr->compat; int compat = vid_hdr->compat;
int data_size = ubi32_to_cpu(vid_hdr->data_size); int data_size = be32_to_cpu(vid_hdr->data_size);
int used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); int used_ebs = be32_to_cpu(vid_hdr->used_ebs);
int data_pad = ubi32_to_cpu(vid_hdr->data_pad); int data_pad = be32_to_cpu(vid_hdr->data_pad);
int data_crc = ubi32_to_cpu(vid_hdr->data_crc); int data_crc = be32_to_cpu(vid_hdr->data_crc);
int usable_leb_size = ubi->leb_size - data_pad; int usable_leb_size = ubi->leb_size - data_pad;
if (copy_flag != 0 && copy_flag != 1) { if (copy_flag != 0 && copy_flag != 1) {
...@@ -914,7 +914,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum, ...@@ -914,7 +914,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum,
read_err = err; read_err = err;
} }
magic = ubi32_to_cpu(vid_hdr->magic); magic = be32_to_cpu(vid_hdr->magic);
if (magic != UBI_VID_HDR_MAGIC) { if (magic != UBI_VID_HDR_MAGIC) {
/* /*
* If we have read all 0xFF bytes, the VID header probably does * If we have read all 0xFF bytes, the VID header probably does
...@@ -957,7 +957,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum, ...@@ -957,7 +957,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum,
} }
crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
if (hdr_crc != crc) { if (hdr_crc != crc) {
if (verbose) { if (verbose) {
...@@ -1007,10 +1007,10 @@ int ubi_io_write_vid_hdr(const struct ubi_device *ubi, int pnum, ...@@ -1007,10 +1007,10 @@ int ubi_io_write_vid_hdr(const struct ubi_device *ubi, int pnum,
if (err) if (err)
return err > 0 ? -EINVAL: err; return err > 0 ? -EINVAL: err;
vid_hdr->magic = cpu_to_ubi32(UBI_VID_HDR_MAGIC); vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
vid_hdr->version = UBI_VERSION; vid_hdr->version = UBI_VERSION;
crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
vid_hdr->hdr_crc = cpu_to_ubi32(crc); vid_hdr->hdr_crc = cpu_to_be32(crc);
err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
if (err) if (err)
...@@ -1060,7 +1060,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, ...@@ -1060,7 +1060,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
int err; int err;
uint32_t magic; uint32_t magic;
magic = ubi32_to_cpu(ec_hdr->magic); magic = be32_to_cpu(ec_hdr->magic);
if (magic != UBI_EC_HDR_MAGIC) { if (magic != UBI_EC_HDR_MAGIC) {
ubi_err("bad magic %#08x, must be %#08x", ubi_err("bad magic %#08x, must be %#08x",
magic, UBI_EC_HDR_MAGIC); magic, UBI_EC_HDR_MAGIC);
...@@ -1105,7 +1105,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) ...@@ -1105,7 +1105,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
goto exit; goto exit;
crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);
if (hdr_crc != crc) { if (hdr_crc != crc) {
ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc);
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
...@@ -1137,7 +1137,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, ...@@ -1137,7 +1137,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
int err; int err;
uint32_t magic; uint32_t magic;
magic = ubi32_to_cpu(vid_hdr->magic); magic = be32_to_cpu(vid_hdr->magic);
if (magic != UBI_VID_HDR_MAGIC) { if (magic != UBI_VID_HDR_MAGIC) {
ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x", ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x",
magic, pnum, UBI_VID_HDR_MAGIC); magic, pnum, UBI_VID_HDR_MAGIC);
...@@ -1187,7 +1187,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) ...@@ -1187,7 +1187,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
goto exit; goto exit;
crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
if (hdr_crc != crc) { if (hdr_crc != crc) {
ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " ubi_err("bad VID header CRC at PEB %d, calculated %#08x, "
"read %#08x", pnum, crc, hdr_crc); "read %#08x", pnum, crc, hdr_crc);
......
...@@ -132,9 +132,9 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, ...@@ -132,9 +132,9 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
const struct ubi_scan_volume *sv, int pnum) const struct ubi_scan_volume *sv, int pnum)
{ {
int vol_type = vid_hdr->vol_type; int vol_type = vid_hdr->vol_type;
int vol_id = ubi32_to_cpu(vid_hdr->vol_id); int vol_id = be32_to_cpu(vid_hdr->vol_id);
int used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); int used_ebs = be32_to_cpu(vid_hdr->used_ebs);
int data_pad = ubi32_to_cpu(vid_hdr->data_pad); int data_pad = be32_to_cpu(vid_hdr->data_pad);
if (sv->leb_count != 0) { if (sv->leb_count != 0) {
int sv_vol_type; int sv_vol_type;
...@@ -200,7 +200,7 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, ...@@ -200,7 +200,7 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id,
struct ubi_scan_volume *sv; struct ubi_scan_volume *sv;
struct rb_node **p = &si->volumes.rb_node, *parent = NULL; struct rb_node **p = &si->volumes.rb_node, *parent = NULL;
ubi_assert(vol_id == ubi32_to_cpu(vid_hdr->vol_id)); ubi_assert(vol_id == be32_to_cpu(vid_hdr->vol_id));
/* Walk the volume RB-tree to look if this volume is already present */ /* Walk the volume RB-tree to look if this volume is already present */
while (*p) { while (*p) {
...@@ -225,8 +225,8 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, ...@@ -225,8 +225,8 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id,
si->max_sqnum = 0; si->max_sqnum = 0;
sv->vol_id = vol_id; sv->vol_id = vol_id;
sv->root = RB_ROOT; sv->root = RB_ROOT;
sv->used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); sv->used_ebs = be32_to_cpu(vid_hdr->used_ebs);
sv->data_pad = ubi32_to_cpu(vid_hdr->data_pad); sv->data_pad = be32_to_cpu(vid_hdr->data_pad);
sv->compat = vid_hdr->compat; sv->compat = vid_hdr->compat;
sv->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME sv->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME
: UBI_STATIC_VOLUME; : UBI_STATIC_VOLUME;
...@@ -268,10 +268,10 @@ static int compare_lebs(const struct ubi_device *ubi, ...@@ -268,10 +268,10 @@ static int compare_lebs(const struct ubi_device *ubi,
int len, err, second_is_newer, bitflips = 0, corrupted = 0; int len, err, second_is_newer, bitflips = 0, corrupted = 0;
uint32_t data_crc, crc; uint32_t data_crc, crc;
struct ubi_vid_hdr *vidh = NULL; struct ubi_vid_hdr *vidh = NULL;
unsigned long long sqnum2 = ubi64_to_cpu(vid_hdr->sqnum); unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);
if (seb->sqnum == 0 && sqnum2 == 0) { if (seb->sqnum == 0 && sqnum2 == 0) {
long long abs, v1 = seb->leb_ver, v2 = ubi32_to_cpu(vid_hdr->leb_ver); long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);
/* /*
* UBI constantly increases the logical eraseblock version * UBI constantly increases the logical eraseblock version
...@@ -355,7 +355,7 @@ static int compare_lebs(const struct ubi_device *ubi, ...@@ -355,7 +355,7 @@ static int compare_lebs(const struct ubi_device *ubi,
/* Read the data of the copy and check the CRC */ /* Read the data of the copy and check the CRC */
len = ubi32_to_cpu(vid_hdr->data_size); len = be32_to_cpu(vid_hdr->data_size);
buf = vmalloc(len); buf = vmalloc(len);
if (!buf) { if (!buf) {
err = -ENOMEM; err = -ENOMEM;
...@@ -366,7 +366,7 @@ static int compare_lebs(const struct ubi_device *ubi, ...@@ -366,7 +366,7 @@ static int compare_lebs(const struct ubi_device *ubi,
if (err && err != UBI_IO_BITFLIPS) if (err && err != UBI_IO_BITFLIPS)
goto out_free_buf; goto out_free_buf;
data_crc = ubi32_to_cpu(vid_hdr->data_crc); data_crc = be32_to_cpu(vid_hdr->data_crc);
crc = crc32(UBI_CRC32_INIT, buf, len); crc = crc32(UBI_CRC32_INIT, buf, len);
if (crc != data_crc) { if (crc != data_crc) {
dbg_bld("PEB %d CRC error: calculated %#08x, must be %#08x", dbg_bld("PEB %d CRC error: calculated %#08x, must be %#08x",
...@@ -425,10 +425,10 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -425,10 +425,10 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si,
struct ubi_scan_leb *seb; struct ubi_scan_leb *seb;
struct rb_node **p, *parent = NULL; struct rb_node **p, *parent = NULL;
vol_id = ubi32_to_cpu(vid_hdr->vol_id); vol_id = be32_to_cpu(vid_hdr->vol_id);
lnum = ubi32_to_cpu(vid_hdr->lnum); lnum = be32_to_cpu(vid_hdr->lnum);
sqnum = ubi64_to_cpu(vid_hdr->sqnum); sqnum = be64_to_cpu(vid_hdr->sqnum);
leb_ver = ubi32_to_cpu(vid_hdr->leb_ver); leb_ver = be32_to_cpu(vid_hdr->leb_ver);
dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d",
pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips);
...@@ -523,7 +523,7 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -523,7 +523,7 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si,
if (sv->highest_lnum == lnum) if (sv->highest_lnum == lnum)
sv->last_data_size = sv->last_data_size =
ubi32_to_cpu(vid_hdr->data_size); be32_to_cpu(vid_hdr->data_size);
return 0; return 0;
} else { } else {
...@@ -560,7 +560,7 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -560,7 +560,7 @@ int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si,
if (sv->highest_lnum <= lnum) { if (sv->highest_lnum <= lnum) {
sv->highest_lnum = lnum; sv->highest_lnum = lnum;
sv->last_data_size = ubi32_to_cpu(vid_hdr->data_size); sv->last_data_size = be32_to_cpu(vid_hdr->data_size);
} }
if (si->max_sqnum < sqnum) if (si->max_sqnum < sqnum)
...@@ -687,7 +687,7 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi, ...@@ -687,7 +687,7 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
return -EINVAL; return -EINVAL;
} }
ec_hdr->ec = cpu_to_ubi64(ec); ec_hdr->ec = cpu_to_be64(ec);
err = ubi_io_sync_erase(ubi, pnum, 0); err = ubi_io_sync_erase(ubi, pnum, 0);
if (err < 0) if (err < 0)
...@@ -818,7 +818,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum ...@@ -818,7 +818,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
return -EINVAL; return -EINVAL;
} }
ec = ubi64_to_cpu(ech->ec); ec = be64_to_cpu(ech->ec);
if (ec > UBI_MAX_ERASECOUNTER) { if (ec > UBI_MAX_ERASECOUNTER) {
/* /*
* Erase counter overflow. The EC headers have 64 bits * Erase counter overflow. The EC headers have 64 bits
...@@ -856,9 +856,9 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum ...@@ -856,9 +856,9 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
goto adjust_mean_ec; goto adjust_mean_ec;
} }
vol_id = ubi32_to_cpu(vidh->vol_id); vol_id = be32_to_cpu(vidh->vol_id);
if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOL_ID) { if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOL_ID) {
int lnum = ubi32_to_cpu(vidh->lnum); int lnum = be32_to_cpu(vidh->lnum);
/* Unsupported internal volume */ /* Unsupported internal volume */
switch (vidh->compat) { switch (vidh->compat) {
...@@ -1261,12 +1261,12 @@ static int paranoid_check_si(const struct ubi_device *ubi, ...@@ -1261,12 +1261,12 @@ static int paranoid_check_si(const struct ubi_device *ubi,
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (seb->sqnum != ubi64_to_cpu(vidh->sqnum)) { if (seb->sqnum != be64_to_cpu(vidh->sqnum)) {
ubi_err("bad sqnum %llu", seb->sqnum); ubi_err("bad sqnum %llu", seb->sqnum);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (sv->vol_id != ubi32_to_cpu(vidh->vol_id)) { if (sv->vol_id != be32_to_cpu(vidh->vol_id)) {
ubi_err("bad vol_id %d", sv->vol_id); ubi_err("bad vol_id %d", sv->vol_id);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
...@@ -1276,22 +1276,22 @@ static int paranoid_check_si(const struct ubi_device *ubi, ...@@ -1276,22 +1276,22 @@ static int paranoid_check_si(const struct ubi_device *ubi,
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (seb->lnum != ubi32_to_cpu(vidh->lnum)) { if (seb->lnum != be32_to_cpu(vidh->lnum)) {
ubi_err("bad lnum %d", seb->lnum); ubi_err("bad lnum %d", seb->lnum);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (sv->used_ebs != ubi32_to_cpu(vidh->used_ebs)) { if (sv->used_ebs != be32_to_cpu(vidh->used_ebs)) {
ubi_err("bad used_ebs %d", sv->used_ebs); ubi_err("bad used_ebs %d", sv->used_ebs);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (sv->data_pad != ubi32_to_cpu(vidh->data_pad)) { if (sv->data_pad != be32_to_cpu(vidh->data_pad)) {
ubi_err("bad data_pad %d", sv->data_pad); ubi_err("bad data_pad %d", sv->data_pad);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (seb->leb_ver != ubi32_to_cpu(vidh->leb_ver)) { if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) {
ubi_err("bad leb_ver %u", seb->leb_ver); ubi_err("bad leb_ver %u", seb->leb_ver);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
...@@ -1300,12 +1300,12 @@ static int paranoid_check_si(const struct ubi_device *ubi, ...@@ -1300,12 +1300,12 @@ static int paranoid_check_si(const struct ubi_device *ubi,
if (!last_seb) if (!last_seb)
continue; continue;
if (sv->highest_lnum != ubi32_to_cpu(vidh->lnum)) { if (sv->highest_lnum != be32_to_cpu(vidh->lnum)) {
ubi_err("bad highest_lnum %d", sv->highest_lnum); ubi_err("bad highest_lnum %d", sv->highest_lnum);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
if (sv->last_data_size != ubi32_to_cpu(vidh->data_size)) { if (sv->last_data_size != be32_to_cpu(vidh->data_size)) {
ubi_err("bad last_data_size %d", sv->last_data_size); ubi_err("bad last_data_size %d", sv->last_data_size);
goto bad_vid_hdr; goto bad_vid_hdr;
} }
......
...@@ -319,10 +319,10 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ...@@ -319,10 +319,10 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
/* Fill volume table record */ /* Fill volume table record */
memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record)); memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record));
vtbl_rec.reserved_pebs = cpu_to_ubi32(vol->reserved_pebs); vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs);
vtbl_rec.alignment = cpu_to_ubi32(vol->alignment); vtbl_rec.alignment = cpu_to_be32(vol->alignment);
vtbl_rec.data_pad = cpu_to_ubi32(vol->data_pad); vtbl_rec.data_pad = cpu_to_be32(vol->data_pad);
vtbl_rec.name_len = cpu_to_ubi16(vol->name_len); vtbl_rec.name_len = cpu_to_be16(vol->name_len);
if (vol->vol_type == UBI_DYNAMIC_VOLUME) if (vol->vol_type == UBI_DYNAMIC_VOLUME)
vtbl_rec.vol_type = UBI_VID_DYNAMIC; vtbl_rec.vol_type = UBI_VID_DYNAMIC;
else else
...@@ -502,7 +502,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) ...@@ -502,7 +502,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
/* Change volume table record */ /* Change volume table record */
memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
vtbl_rec.reserved_pebs = cpu_to_ubi32(reserved_pebs); vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
if (err) if (err)
goto out_acc; goto out_acc;
...@@ -650,7 +650,7 @@ static void paranoid_check_volume(const struct ubi_device *ubi, int vol_id) ...@@ -650,7 +650,7 @@ static void paranoid_check_volume(const struct ubi_device *ubi, int vol_id)
long long n; long long n;
const char *name; const char *name;
reserved_pebs = ubi32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs);
if (!vol) { if (!vol) {
if (reserved_pebs) { if (reserved_pebs) {
...@@ -764,9 +764,9 @@ static void paranoid_check_volume(const struct ubi_device *ubi, int vol_id) ...@@ -764,9 +764,9 @@ static void paranoid_check_volume(const struct ubi_device *ubi, int vol_id)
} }
} }
alignment = ubi32_to_cpu(ubi->vtbl[vol_id].alignment); alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment);
data_pad = ubi32_to_cpu(ubi->vtbl[vol_id].data_pad); data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad);
name_len = ubi16_to_cpu(ubi->vtbl[vol_id].name_len); name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len);
upd_marker = ubi->vtbl[vol_id].upd_marker; upd_marker = ubi->vtbl[vol_id].upd_marker;
name = &ubi->vtbl[vol_id].name[0]; name = &ubi->vtbl[vol_id].name[0];
if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC) if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
......
...@@ -93,7 +93,7 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, ...@@ -93,7 +93,7 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
vtbl_rec = &empty_vtbl_record; vtbl_rec = &empty_vtbl_record;
else { else {
crc = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC);
vtbl_rec->crc = cpu_to_ubi32(crc); vtbl_rec->crc = cpu_to_be32(crc);
} }
dbg_msg("change record %d", idx); dbg_msg("change record %d", idx);
...@@ -141,18 +141,18 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -141,18 +141,18 @@ static int vtbl_check(const struct ubi_device *ubi,
for (i = 0; i < ubi->vtbl_slots; i++) { for (i = 0; i < ubi->vtbl_slots; i++) {
cond_resched(); cond_resched();
reserved_pebs = ubi32_to_cpu(vtbl[i].reserved_pebs); reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
alignment = ubi32_to_cpu(vtbl[i].alignment); alignment = be32_to_cpu(vtbl[i].alignment);
data_pad = ubi32_to_cpu(vtbl[i].data_pad); data_pad = be32_to_cpu(vtbl[i].data_pad);
upd_marker = vtbl[i].upd_marker; upd_marker = vtbl[i].upd_marker;
vol_type = vtbl[i].vol_type; vol_type = vtbl[i].vol_type;
name_len = ubi16_to_cpu(vtbl[i].name_len); name_len = be16_to_cpu(vtbl[i].name_len);
name = &vtbl[i].name[0]; name = &vtbl[i].name[0];
crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC);
if (ubi32_to_cpu(vtbl[i].crc) != crc) { if (be32_to_cpu(vtbl[i].crc) != crc) {
ubi_err("bad CRC at record %u: %#08x, not %#08x", ubi_err("bad CRC at record %u: %#08x, not %#08x",
i, crc, ubi32_to_cpu(vtbl[i].crc)); i, crc, be32_to_cpu(vtbl[i].crc));
ubi_dbg_dump_vtbl_record(&vtbl[i], i); ubi_dbg_dump_vtbl_record(&vtbl[i], i);
return 1; return 1;
} }
...@@ -225,8 +225,8 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -225,8 +225,8 @@ static int vtbl_check(const struct ubi_device *ubi,
/* Checks that all names are unique */ /* Checks that all names are unique */
for (i = 0; i < ubi->vtbl_slots - 1; i++) { for (i = 0; i < ubi->vtbl_slots - 1; i++) {
for (n = i + 1; n < ubi->vtbl_slots; n++) { for (n = i + 1; n < ubi->vtbl_slots; n++) {
int len1 = ubi16_to_cpu(vtbl[i].name_len); int len1 = be16_to_cpu(vtbl[i].name_len);
int len2 = ubi16_to_cpu(vtbl[n].name_len); int len2 = be16_to_cpu(vtbl[n].name_len);
if (len1 > 0 && len1 == len2 && if (len1 > 0 && len1 == len2 &&
!strncmp(vtbl[i].name, vtbl[n].name, len1)) { !strncmp(vtbl[i].name, vtbl[n].name, len1)) {
...@@ -288,13 +288,13 @@ retry: ...@@ -288,13 +288,13 @@ retry:
} }
vid_hdr->vol_type = UBI_VID_DYNAMIC; vid_hdr->vol_type = UBI_VID_DYNAMIC;
vid_hdr->vol_id = cpu_to_ubi32(UBI_LAYOUT_VOL_ID); vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOL_ID);
vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT; vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
vid_hdr->data_size = vid_hdr->used_ebs = vid_hdr->data_size = vid_hdr->used_ebs =
vid_hdr->data_pad = cpu_to_ubi32(0); vid_hdr->data_pad = cpu_to_be32(0);
vid_hdr->lnum = cpu_to_ubi32(copy); vid_hdr->lnum = cpu_to_be32(copy);
vid_hdr->sqnum = cpu_to_ubi64(++si->max_sqnum); vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum);
vid_hdr->leb_ver = cpu_to_ubi32(old_seb ? old_seb->leb_ver + 1: 0); vid_hdr->leb_ver = cpu_to_be32(old_seb ? old_seb->leb_ver + 1: 0);
/* The EC header is already there, write the VID header */ /* The EC header is already there, write the VID header */
err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);
...@@ -503,19 +503,19 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, ...@@ -503,19 +503,19 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
for (i = 0; i < ubi->vtbl_slots; i++) { for (i = 0; i < ubi->vtbl_slots; i++) {
cond_resched(); cond_resched();
if (ubi32_to_cpu(vtbl[i].reserved_pebs) == 0) if (be32_to_cpu(vtbl[i].reserved_pebs) == 0)
continue; /* Empty record */ continue; /* Empty record */
vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
if (!vol) if (!vol)
return -ENOMEM; return -ENOMEM;
vol->reserved_pebs = ubi32_to_cpu(vtbl[i].reserved_pebs); vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
vol->alignment = ubi32_to_cpu(vtbl[i].alignment); vol->alignment = be32_to_cpu(vtbl[i].alignment);
vol->data_pad = ubi32_to_cpu(vtbl[i].data_pad); vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
vol->name_len = ubi16_to_cpu(vtbl[i].name_len); vol->name_len = be16_to_cpu(vtbl[i].name_len);
vol->usable_leb_size = ubi->leb_size - vol->data_pad; vol->usable_leb_size = ubi->leb_size - vol->data_pad;
memcpy(vol->name, vtbl[i].name, vol->name_len); memcpy(vol->name, vtbl[i].name, vol->name_len);
vol->name[vol->name_len] = '\0'; vol->name[vol->name_len] = '\0';
...@@ -721,7 +721,7 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) ...@@ -721,7 +721,7 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si)
int i, err; int i, err;
struct ubi_scan_volume *sv; struct ubi_scan_volume *sv;
empty_vtbl_record.crc = cpu_to_ubi32(0xf116c36b); empty_vtbl_record.crc = cpu_to_be32(0xf116c36b);
/* /*
* The number of supported volumes is limited by the eraseblock size * The number of supported volumes is limited by the eraseblock size
......
...@@ -667,7 +667,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int tortur ...@@ -667,7 +667,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int tortur
dbg_wl("erased PEB %d, new EC %llu", e->pnum, ec); dbg_wl("erased PEB %d, new EC %llu", e->pnum, ec);
ec_hdr->ec = cpu_to_ubi64(ec); ec_hdr->ec = cpu_to_be64(ec);
err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr); err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
if (err) if (err)
...@@ -1634,7 +1634,7 @@ static int paranoid_check_ec(const struct ubi_device *ubi, int pnum, int ec) ...@@ -1634,7 +1634,7 @@ static int paranoid_check_ec(const struct ubi_device *ubi, int pnum, int ec)
goto out_free; goto out_free;
} }
read_ec = ubi64_to_cpu(ec_hdr->ec); read_ec = be64_to_cpu(ec_hdr->ec);
if (ec != read_ec) { if (ec != read_ec) {
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
ubi_err("read EC is %lld, should be %d", read_ec, ec); ubi_err("read EC is %lld, should be %d", read_ec, ec);
......
...@@ -74,42 +74,13 @@ enum { ...@@ -74,42 +74,13 @@ enum {
UBI_COMPAT_REJECT = 5 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 */ /* Sizes of UBI headers */
#define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr) #define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)
#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr) #define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
/* Sizes of UBI headers without the ending CRC */ /* Sizes of UBI headers without the ending CRC */
#define UBI_EC_HDR_SIZE_CRC (UBI_EC_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(ubi32_t)) #define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
/** /**
* struct ubi_ec_hdr - UBI erase counter header. * struct ubi_ec_hdr - UBI erase counter header.
...@@ -137,14 +108,14 @@ typedef struct { ...@@ -137,14 +108,14 @@ typedef struct {
* eraseblocks. * eraseblocks.
*/ */
struct ubi_ec_hdr { struct ubi_ec_hdr {
ubi32_t magic; __be32 magic;
uint8_t version; __u8 version;
uint8_t padding1[3]; __u8 padding1[3];
ubi64_t ec; /* Warning: the current limit is 31-bit anyway! */ __be64 ec; /* Warning: the current limit is 31-bit anyway! */
ubi32_t vid_hdr_offset; __be32 vid_hdr_offset;
ubi32_t data_offset; __be32 data_offset;
uint8_t padding2[36]; __u8 padding2[36];
ubi32_t hdr_crc; __be32 hdr_crc;
} __attribute__ ((packed)); } __attribute__ ((packed));
/** /**
...@@ -262,22 +233,22 @@ struct ubi_ec_hdr { ...@@ -262,22 +233,22 @@ struct ubi_ec_hdr {
* software (say, cramfs) on top of the UBI volume. * software (say, cramfs) on top of the UBI volume.
*/ */
struct ubi_vid_hdr { struct ubi_vid_hdr {
ubi32_t magic; __be32 magic;
uint8_t version; __u8 version;
uint8_t vol_type; __u8 vol_type;
uint8_t copy_flag; __u8 copy_flag;
uint8_t compat; __u8 compat;
ubi32_t vol_id; __be32 vol_id;
ubi32_t lnum; __be32 lnum;
ubi32_t leb_ver; /* obsolete, to be removed, don't use */ __be32 leb_ver; /* obsolete, to be removed, don't use */
ubi32_t data_size; __be32 data_size;
ubi32_t used_ebs; __be32 used_ebs;
ubi32_t data_pad; __be32 data_pad;
ubi32_t data_crc; __be32 data_crc;
uint8_t padding1[4]; __u8 padding1[4];
ubi64_t sqnum; __be64 sqnum;
uint8_t padding2[12]; __u8 padding2[12];
ubi32_t hdr_crc; __be32 hdr_crc;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* Internal UBI volumes count */ /* Internal UBI volumes count */
...@@ -306,7 +277,7 @@ struct ubi_vid_hdr { ...@@ -306,7 +277,7 @@ struct ubi_vid_hdr {
#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record) #define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
/* Size of the volume table record without the ending CRC */ /* 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_vtbl_record - a record in the volume table. * struct ubi_vtbl_record - a record in the volume table.
...@@ -346,15 +317,15 @@ struct ubi_vid_hdr { ...@@ -346,15 +317,15 @@ struct ubi_vid_hdr {
* Empty records contain all zeroes and the CRC checksum of those zeroes. * Empty records contain all zeroes and the CRC checksum of those zeroes.
*/ */
struct ubi_vtbl_record { struct ubi_vtbl_record {
ubi32_t reserved_pebs; __be32 reserved_pebs;
ubi32_t alignment; __be32 alignment;
ubi32_t data_pad; __be32 data_pad;
uint8_t vol_type; __u8 vol_type;
uint8_t upd_marker; __u8 upd_marker;
ubi16_t name_len; __be16 name_len;
uint8_t name[UBI_VOL_NAME_MAX+1]; __u8 name[UBI_VOL_NAME_MAX+1];
uint8_t padding2[24]; __u8 padding2[24];
ubi32_t crc; __be32 crc;
} __attribute__ ((packed)); } __attribute__ ((packed));
#endif /* !__UBI_HEADER_H__ */ #endif /* !__UBI_HEADER_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment