}
cleanmarker.totlen = cpu_to_je32(8);
}
- cleanmarker.hdr_crc = cpu_to_je32 (crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
+ cleanmarker.hdr_crc = cpu_to_je32 (mtd_crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
}
for (eb = 0; eb < (mtd.size / mtd.eb_size); eb++) {
#include <stdint.h>
/* Return a 32-bit CRC of the contents of the buffer */
-extern uint32_t crc32(uint32_t val, const void *ss, int len);
+extern uint32_t mtd_crc32(uint32_t val, const void *ss, int len);
#endif /* __CRC32_H__ */
/* Set accurate for CRC check */
node->u.nodetype = cpu_to_je16(type);
- crc = crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
if (crc != je32_to_cpu (node->u.hdr_crc)) {
printf ("Wrong hdr_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->u.hdr_crc), crc);
p += 4;
je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
- crc = crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
if (crc != je32_to_cpu (node->i.node_crc)) {
printf ("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.node_crc), crc);
p += PAD(je32_to_cpu (node->i.totlen));
continue;
}
- crc = crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
+ crc = mtd_crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
if (crc != je32_to_cpu(node->i.data_crc)) {
printf ("Wrong data_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.data_crc), crc);
p += PAD(je32_to_cpu (node->i.totlen));
je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
node->d.nsize, name);
- crc = crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
if (crc != je32_to_cpu (node->d.node_crc)) {
printf ("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.node_crc), crc);
p += PAD(je32_to_cpu (node->d.totlen));
continue;
}
- crc = crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
+ crc = mtd_crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
if (crc != je32_to_cpu(node->d.name_crc)) {
printf ("Wrong name_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.name_crc), crc);
p += PAD(je32_to_cpu (node->d.totlen));
je32_to_cpu (node->s.sum_num),
je32_to_cpu (node->s.cln_mkr));
- crc = crc32 (0, node, sizeof (struct jffs2_raw_summary) - 8);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_raw_summary) - 8);
if (crc != je32_to_cpu (node->s.node_crc)) {
printf ("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.node_crc), crc);
p += PAD(je32_to_cpu (node->s.totlen));
continue;
}
- crc = crc32(0, p + sizeof (struct jffs2_raw_summary), je32_to_cpu (node->s.totlen) - sizeof(struct jffs2_raw_summary));
+ crc = mtd_crc32(0, p + sizeof (struct jffs2_raw_summary), je32_to_cpu (node->s.totlen) - sizeof(struct jffs2_raw_summary));
if (crc != je32_to_cpu(node->s.sum_crc)) {
printf ("Wrong data_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.sum_crc), crc);
p += PAD(je32_to_cpu (node->s.totlen));
continue;
}
- crc = crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
if (crc != je32_to_cpu (node->u.hdr_crc)) {
printf ("Wrong hdr_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->u.hdr_crc), crc);
}
newnode.i.magic = cnv_e16 (node->i.magic);
newnode.i.nodetype = cnv_e16 (node->i.nodetype);
newnode.i.totlen = cnv_e32 (node->i.totlen);
- newnode.i.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+ newnode.i.hdr_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
newnode.i.ino = cnv_e32 (node->i.ino);
newnode.i.version = cnv_e32 (node->i.version);
mode.v32 = node->i.mode.m;
newnode.i.flags = cnv_e16 (node->i.flags);
if (recalccrc) {
len = je32_to_cpu(node->i.csize);
- newnode.i.data_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_inode), len));
+ newnode.i.data_crc = cpu_to_e32 ( mtd_crc32(0, p + sizeof (struct jffs2_raw_inode), len));
} else
newnode.i.data_crc = cnv_e32 (node->i.data_crc);
- newnode.i.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_inode) - 8));
+ newnode.i.node_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_raw_inode) - 8));
write (fd, &newnode, sizeof (struct jffs2_raw_inode));
write (fd, p + sizeof (struct jffs2_raw_inode), PAD (je32_to_cpu (node->i.totlen) - sizeof (struct jffs2_raw_inode)));
newnode.d.magic = cnv_e16 (node->d.magic);
newnode.d.nodetype = cnv_e16 (node->d.nodetype);
newnode.d.totlen = cnv_e32 (node->d.totlen);
- newnode.d.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+ newnode.d.hdr_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
newnode.d.pino = cnv_e32 (node->d.pino);
newnode.d.version = cnv_e32 (node->d.version);
newnode.d.ino = cnv_e32 (node->d.ino);
newnode.d.type = node->d.type;
newnode.d.unused[0] = node->d.unused[0];
newnode.d.unused[1] = node->d.unused[1];
- newnode.d.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_dirent) - 8));
+ newnode.d.node_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_raw_dirent) - 8));
if (recalccrc)
- newnode.d.name_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize));
+ newnode.d.name_crc = cpu_to_e32 ( mtd_crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize));
else
newnode.d.name_crc = cnv_e32 (node->d.name_crc);
newnode.u.magic = cnv_e16 (node->u.magic);
newnode.u.nodetype = cnv_e16 (node->u.nodetype);
newnode.u.totlen = cnv_e32 (node->u.totlen);
- newnode.u.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+ newnode.u.hdr_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
write (fd, &newnode, sizeof (struct jffs2_unknown_node));
len = PAD(je32_to_cpu (node->u.totlen) - sizeof (struct jffs2_unknown_node));
newnode.s.magic = cnv_e16 (node->s.magic);
newnode.s.nodetype = cnv_e16 (node->s.nodetype);
newnode.s.totlen = cnv_e32 (node->s.totlen);
- newnode.s.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+ newnode.s.hdr_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
newnode.s.sum_num = cnv_e32 (node->s.sum_num);
newnode.s.cln_mkr = cnv_e32 (node->s.cln_mkr);
newnode.s.padded = cnv_e32 (node->s.padded);
- newnode.s.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_summary) - 8));
+ newnode.s.node_crc = cpu_to_e32 (mtd_crc32 (0, &newnode, sizeof (struct jffs2_raw_summary) - 8));
// summary header
p += sizeof (struct jffs2_raw_summary);
p += sizeof (struct jffs2_sum_marker);
// generate new crc on sum data
- newnode.s.sum_crc = cpu_to_e32 ( crc32(0, ((char *) node) + sizeof (struct jffs2_raw_summary),
+ newnode.s.sum_crc = cpu_to_e32 ( mtd_crc32(0, ((char *) node) + sizeof (struct jffs2_raw_summary),
je32_to_cpu (node->s.totlen) - sizeof (struct jffs2_raw_summary)));
// write out new node header
0x2d02ef8dL
};
-uint32_t crc32(uint32_t val, const void *ss, int len)
+uint32_t mtd_crc32(uint32_t val, const void *ss, int len)
{
const unsigned char *s = ss;
ch->group_type = UBIFS_NO_NODE_GROUP;
ch->sqnum = cpu_to_le64(++c->max_sqnum);
ch->padding[0] = ch->padding[1] = 0;
- crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
+ crc = mtd_crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
ch->crc = cpu_to_le32(crc);
}
pad_len -= UBIFS_PAD_NODE_SZ;
pad_node->pad_len = cpu_to_le32(pad_len);
- crc = crc32(UBIFS_CRC32_INIT, buf + 8,
+ crc = mtd_crc32(UBIFS_CRC32_INIT, buf + 8,
UBIFS_PAD_NODE_SZ - 8);
ch->crc = cpu_to_le32(crc);
continue;
}
- if (crc32(-1, thispkt.data, PKT_SIZE) != ntohl(thispkt.hdr.thiscrc)) {
+ if (mtd_crc32(-1, thispkt.data, PKT_SIZE) != ntohl(thispkt.hdr.thiscrc)) {
printf("\nDiscard %08x pkt %d with bad CRC (%08x not %08x)\n",
block_nr * meminfo.erasesize, ntohs(thispkt.hdr.pkt_nr),
- crc32(-1, thispkt.data, PKT_SIZE),
+ mtd_crc32(-1, thispkt.data, PKT_SIZE),
ntohl(thispkt.hdr.thiscrc));
badcrcs++;
continue;
/* Paranoia */
gettimeofday(&start, NULL);
- if (crc32(-1, decode_buf, meminfo.erasesize) != eraseblocks[block_nr].crc) {
+ if (mtd_crc32(-1, decode_buf, meminfo.erasesize) != eraseblocks[block_nr].crc) {
printf("\nCRC mismatch for block #%d: want %08x got %08x\n",
block_nr, eraseblocks[block_nr].crc,
- crc32(-1, decode_buf, meminfo.erasesize));
+ mtd_crc32(-1, decode_buf, meminfo.erasesize));
exit(1);
}
gettimeofday(&now, NULL);
fflush(stdout);
pktbuf.hdr.resend = 0;
- pktbuf.hdr.totcrc = htonl(crc32(-1, image, st.st_size));
+ pktbuf.hdr.totcrc = htonl(mtd_crc32(-1, image, st.st_size));
pktbuf.hdr.nr_blocks = htonl(nr_blocks);
pktbuf.hdr.blocksize = htonl(erasesize);
pktbuf.hdr.thislen = htonl(PKT_SIZE);
printf("\rChecking block CRCS.... %d/%d",
block_nr + 1, nr_blocks);
fflush(stdout);
- block_crcs[block_nr] = crc32(-1, image + (block_nr * erasesize), erasesize);
+ block_crcs[block_nr] = mtd_crc32(-1, image + (block_nr * erasesize), erasesize);
}
printf("\nImage size %ld KiB (0x%08lx). %d blocks at %d pkts/block\n"
fec_encode_linear(fec, blockptr, pktbuf.data, actualpkt, PKT_SIZE);
- pktbuf.hdr.thiscrc = htonl(crc32(-1, pktbuf.data, PKT_SIZE));
+ pktbuf.hdr.thiscrc = htonl(mtd_crc32(-1, pktbuf.data, PKT_SIZE));
pktbuf.hdr.block_crc = htonl(block_crcs[block_nr]);
pktbuf.hdr.block_nr = htonl(block_nr);
pktbuf.hdr.pkt_nr = htons(actualpkt);
cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
cleanmarker.totlen = cpu_to_je32(cleanmarker_size);
- cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, sizeof(struct jffs2_unknown_node)-4));
+ cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(struct jffs2_unknown_node)-4));
}
void process_options (int argc, char **argv)
isum.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
isum.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
isum.totlen = cpu_to_je32(infosize);
- isum.hdr_crc = cpu_to_je32(crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
+ isum.hdr_crc = cpu_to_je32(mtd_crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
isum.padded = cpu_to_je32(0);
if (add_cleanmarkers && found_cleanmarkers) {
sm->offset = offset;
sm->magic = magic;
- isum.sum_crc = cpu_to_je32(crc32(0, tpage, datasize));
- isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
+ isum.sum_crc = cpu_to_je32(mtd_crc32(0, tpage, datasize));
+ isum.node_crc = cpu_to_je32(mtd_crc32(0, &isum, sizeof(isum) - 8));
full_write(data_buffer + data_ofs, &isum, sizeof(isum));
full_write(data_buffer + data_ofs, tpage, datasize);
node->u.nodetype = cpu_to_je16(type);
- crc = crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_unknown_node) - 4);
if (crc != je32_to_cpu (node->u.hdr_crc)) {
printf ("Wrong hdr_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - file_buffer, je32_to_cpu (node->u.hdr_crc), crc);
p += 4;
je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
- crc = crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
if (crc != je32_to_cpu (node->i.node_crc)) {
printf ("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - file_buffer, je32_to_cpu (node->i.node_crc), crc);
p += PAD(je32_to_cpu (node->i.totlen));
continue;
}
- crc = crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
+ crc = mtd_crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
if (crc != je32_to_cpu(node->i.data_crc)) {
printf ("Wrong data_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - file_buffer, je32_to_cpu (node->i.data_crc), crc);
p += PAD(je32_to_cpu (node->i.totlen));
je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
node->d.nsize, name);
- crc = crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
+ crc = mtd_crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
if (crc != je32_to_cpu (node->d.node_crc)) {
printf ("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - file_buffer, je32_to_cpu (node->d.node_crc), crc);
p += PAD(je32_to_cpu (node->d.totlen));
continue;
}
- crc = crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
+ crc = mtd_crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
if (crc != je32_to_cpu(node->d.name_crc)) {
printf ("Wrong name_crc at 0x%08zx, 0x%08x instead of 0x%08x\n", p - file_buffer, je32_to_cpu (node->d.name_crc), crc);
p += PAD(je32_to_cpu (node->d.totlen));
obsolete ? "Obsolete" : "",
p - file_buffer, je32_to_cpu (node->x.totlen),
je32_to_cpu(node->x.xid), je32_to_cpu(node->x.version));
- crc = crc32(0, node, sizeof (struct jffs2_raw_xattr) - 4);
+ crc = mtd_crc32(0, node, sizeof (struct jffs2_raw_xattr) - 4);
if (crc != je32_to_cpu(node->x.node_crc)) {
printf("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n",
p - file_buffer, je32_to_cpu(node->x.node_crc), crc);
continue;
}
length = node->x.name_len + 1 + je16_to_cpu(node->x.value_len);
- crc = crc32(0, node->x.data, length);
+ crc = mtd_crc32(0, node->x.data, length);
if (crc != je32_to_cpu(node->x.data_crc)) {
printf("Wrong data_crc at 0x%08zx, 0x%08x instead of 0x%08x\n",
p - file_buffer, je32_to_cpu(node->x.data_crc), crc);
obsolete ? "Obsolete" : "",
p - file_buffer, je32_to_cpu(node->r.totlen),
je32_to_cpu(node->r.ino), je32_to_cpu(node->r.xid));
- crc = crc32(0, node, sizeof (struct jffs2_raw_xref) - 4);
+ crc = mtd_crc32(0, node, sizeof (struct jffs2_raw_xref) - 4);
if (crc != je32_to_cpu(node->r.node_crc)) {
printf("Wrong node_crc at 0x%08zx, 0x%08x instead of 0x%08x\n",
p - file_buffer, je32_to_cpu(node->r.node_crc), crc);
continue;
}
- crc = crc32(UBI_CRC32_INIT, &ech, UBI_EC_HDR_SIZE_CRC);
+ crc = mtd_crc32(UBI_CRC32_INIT, &ech, UBI_EC_HDR_SIZE_CRC);
if (be32_to_cpu(ech.hdr_crc) != crc) {
si->corrupted_cnt += 1;
si->ec[eb] = EB_CORRUPTED;
}
for (i = 0; i < ui->max_volumes; i++) {
- uint32_t crc = crc32(UBI_CRC32_INIT, &vtbl[i],
+ uint32_t crc = mtd_crc32(UBI_CRC32_INIT, &vtbl[i],
UBI_VTBL_RECORD_SIZE_CRC);
vtbl[i].crc = cpu_to_be32(crc);
}
vtbl_rec->name[vi->name_len] = '\0';
vtbl_rec->name_len = cpu_to_be16(vi->name_len);
- tmp = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC);
+ tmp = mtd_crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC);
vtbl_rec->crc = cpu_to_be32(tmp);
return 0;
}
hdr->data_offset = cpu_to_be32(ui->data_offs);
hdr->image_seq = cpu_to_be32(ui->image_seq);
- crc = crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
+ crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
hdr->hdr_crc = cpu_to_be32(crc);
}
if (vi->type == UBI_VID_STATIC) {
hdr->data_size = cpu_to_be32(data_size);
hdr->used_ebs = cpu_to_be32(vi->used_ebs);
- crc = crc32(UBI_CRC32_INIT, data, data_size);
+ crc = mtd_crc32(UBI_CRC32_INIT, data, data_size);
hdr->data_crc = cpu_to_be32(crc);
}
- crc = crc32(UBI_CRC32_INIT, hdr, UBI_VID_HDR_SIZE_CRC);
+ crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_VID_HDR_SIZE_CRC);
hdr->hdr_crc = cpu_to_be32(crc);
}
err = -1;
goto out_close;
}
- crc = crc32(crc, buf, read);
+ crc = mtd_crc32(crc, buf, read);
}
printf("0x%08x\n", crc);
return errmsg("bad UBI magic %#08x, should be %#08x",
be32_to_cpu(hdr->magic), UBI_EC_HDR_MAGIC);
- crc = crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
+ crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
if (be32_to_cpu(hdr->hdr_crc) != crc)
return errmsg("bad CRC %#08x, should be %#08x\n",
crc, be32_to_cpu(hdr->hdr_crc));
hdr->image_seq = cpu_to_be32(image_seq);
hdr->ec = cpu_to_be64(ec);
- crc = crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
+ crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
hdr->hdr_crc = cpu_to_be32(crc);
return 0;