Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164044
b: refs/heads/master
c: de75c77
h: refs/heads/master
v: v3
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Aug 14, 2009
1 parent c2cf203 commit 7a3d808
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 867996b15c1f0a98d2c405bada907e97499ba8c2
refs/heads/master: de75c771b4cc4da963164a538a8448128301bc35
46 changes: 31 additions & 15 deletions trunk/drivers/mtd/ubi/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,30 +476,46 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
*/
static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
{
int err;
int err, err1;
size_t written;
loff_t addr;
uint32_t data = 0;
struct ubi_vid_hdr vid_hdr;

addr = (loff_t)pnum * ubi->peb_size + ubi->vid_hdr_aloffset;
err = ubi->mtd->write(ubi->mtd, addr, 4, &written, (void *)&data);
if (err) {
ubi_err("error %d while writing 4 bytes to PEB %d:%d, written "
"%zd bytes", err, pnum, ubi->vid_hdr_aloffset, written);
ubi_dbg_dump_stack();
return err;
if (!err) {
addr -= ubi->vid_hdr_aloffset;
err = ubi->mtd->write(ubi->mtd, addr, 4, &written,
(void *)&data);
if (!err)
return 0;
}

addr -= ubi->vid_hdr_aloffset;
err = ubi->mtd->write(ubi->mtd, addr, 4, &written, (void *)&data);
if (err) {
ubi_err("error %d while writing 4 bytes to PEB %d:%d, written "
"%zd bytes", err, pnum, 0, written);
ubi_dbg_dump_stack();
return err;
}
/*
* We failed to write to the media. This was observed with Spansion
* S29GL512N NOR flash. Most probably the eraseblock erasure was
* interrupted at a very inappropriate moment, so it became unwritable.
* In this case we probably anyway have garbage in this PEB.
*/
err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0);
if (err1 == UBI_IO_BAD_VID_HDR)
/*
* The VID header is corrupted, so we can safely erase this
* PEB and not afraid that it will be treated as a valid PEB in
* case of an unclean reboot.
*/
return 0;

return 0;
/*
* The PEB contains a valid VID header, but we cannot invalidate it.
* Supposedly the flash media or the driver is screwed up, so return an
* error.
*/
ubi_err("cannot invalidate PEB %d, write returned %d read returned %d",
pnum, err, err1);
ubi_dbg_dump_flash(ubi, pnum, 0, ubi->peb_size);
return -EIO;
}

/**
Expand Down

0 comments on commit 7a3d808

Please sign in to comment.