Patch from Magnus to fix issues with bad blocks and dumping a boot image. Need to clean up the patch a bit. Also reverted mtdutils.s to korg/eclair-release

This commit is contained in:
Koushik K. Dutta 2010-02-24 13:13:34 -08:00
parent 5740b042b5
commit a37e9b1f19
2 changed files with 12 additions and 84 deletions

View File

@ -97,7 +97,7 @@ int main(int argc, char **argv)
unlink(argv[2]);
die("error opening %s: %s\n", argv[1], strerror(errno));
}
/* - comment out this outdated shit
if (!strcmp(argv[1], "system") ||
!strcmp(argv[1], "cache") ||
!strcmp(argv[1], "userdata")) {
@ -107,6 +107,13 @@ int main(int argc, char **argv)
read_size = BLOCK_SIZE;
read_func = mtd_read_data;
}
*/
// - use mtd_read_data only, clean this up later
read_size = BLOCK_SIZE;
read_func = mtd_read_data;
// printf("debug: partition size: %d\n", partition_size);
total = 0;
while ((len = read_func(in, buf, read_size)) > 0) {
@ -119,12 +126,15 @@ int main(int argc, char **argv)
total += BLOCK_SIZE;
}
// printf("debug: bytes read: %d\n", total);
/* packetlss - don't assume every eraseblock is ok
if (total != partition_size) {
close(fd);
unlink(argv[2]);
die("error reading %s", argv[1]);
}
*/
mtd_read_close(in);
if (close(fd)) {

View File

@ -38,7 +38,6 @@ struct MtdPartition {
struct MtdReadContext {
const MtdPartition *partition;
char *buffer;
size_t read_size;
size_t consumed;
int fd;
};
@ -565,84 +564,3 @@ off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos) {
}
return pos;
}
ssize_t mtd_read_raw(MtdReadContext *ctx, char *data, size_t len)
{
static const int SPARE_SIZE = (2048 >> 5);
struct mtd_info_user mtd_info;
struct mtd_oob_buf oob_buf;
struct nand_ecclayout ecc_layout;
struct nand_oobfree *fp;
unsigned char ecc[SPARE_SIZE];
char *src, *dst;
int i, n, ret;
/*
* FIXME: These two ioctls should be cached in MtdReadContext.
*/
ret = ioctl(ctx->fd, MEMGETINFO, &mtd_info);
if (ret < 0)
return -1;
ret = ioctl(ctx->fd, ECCGETLAYOUT, &ecc_layout);
if (ret < 0)
return -1;
ctx->read_size = mtd_info.writesize;
ctx->consumed = ctx->read_size;
/*
* Read next good data block.
*/
ret = read_block(ctx->partition, ctx->fd, data);
if (ret < 0)
return -1;
dst = src = data + ctx->read_size;
/*
* Read OOB data for last block read in read_block().
*/
oob_buf.start = lseek(ctx->fd, 0, SEEK_CUR) - ctx->read_size;
oob_buf.length = mtd_info.oobsize;
oob_buf.ptr = (unsigned char *) src;
ret = ioctl(ctx->fd, MEMREADOOB, &oob_buf);
if (ret < 0)
return -1;
/*
* As yaffs and yaffs2 use mode MEM_OOB_AUTO, but mtdchar uses
* MEM_OOB_PLACE, copy the spare data down the hard way.
*
* Safe away ECC data:
*/
for (i = 0; i < ecc_layout.eccbytes; i++) {
ecc[i] = src[ecc_layout.eccpos[i]];
}
for ( ; i < SPARE_SIZE; i++) {
ecc[i] = 0;
}
/*
* Copy yaffs2 spare data down.
*/
n = ecc_layout.oobavail;
fp = &ecc_layout.oobfree[0];
while (n) {
if (fp->offset) {
memmove(dst, src + fp->offset, fp->length);
}
dst += fp->length;
n -= fp->length;
++fp;
}
/*
* Restore ECC data behind spare data.
*/
memcpy(dst, ecc, (ctx->read_size >> 5) - ecc_layout.oobavail);
return ctx->read_size + (ctx->read_size >> 5);
}