UBI: add empty eraseblocks verification

This patch adds code which makes sure eraseblocks contain all 0xFF
bytes before starting using them. The verification is done only when
debugging checks are enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
This commit is contained in:
Artem Bityutskiy 2009-06-28 19:16:55 +03:00
Родитель 8e4a718ff3
Коммит 40a71a87fa
3 изменённых файлов: 21 добавлений и 10 удалений

Просмотреть файл

@ -93,6 +93,12 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
#define UBI_IO_DEBUG 0 #define UBI_IO_DEBUG 0
#endif #endif
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
#else
#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
#endif
#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
#define DBG_DISABLE_BGT 1 #define DBG_DISABLE_BGT 1
#else #else

Просмотреть файл

@ -98,8 +98,6 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum);
static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
const struct ubi_vid_hdr *vid_hdr); const struct ubi_vid_hdr *vid_hdr);
static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
int len);
static int paranoid_check_empty(struct ubi_device *ubi, int pnum); static int paranoid_check_empty(struct ubi_device *ubi, int pnum);
#else #else
#define paranoid_check_not_bad(ubi, pnum) 0 #define paranoid_check_not_bad(ubi, pnum) 0
@ -107,7 +105,6 @@ static int paranoid_check_empty(struct ubi_device *ubi, int pnum);
#define paranoid_check_ec_hdr(ubi, pnum, ec_hdr) 0 #define paranoid_check_ec_hdr(ubi, pnum, ec_hdr) 0
#define paranoid_check_peb_vid_hdr(ubi, pnum) 0 #define paranoid_check_peb_vid_hdr(ubi, pnum) 0
#define paranoid_check_vid_hdr(ubi, pnum, vid_hdr) 0 #define paranoid_check_vid_hdr(ubi, pnum, vid_hdr) 0
#define paranoid_check_all_ff(ubi, pnum, offset, len) 0
#define paranoid_check_empty(ubi, pnum) 0 #define paranoid_check_empty(ubi, pnum) 0
#endif #endif
@ -244,7 +241,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
return err > 0 ? -EINVAL : err; return err > 0 ? -EINVAL : err;
/* The area we are writing to has to contain all 0xFF bytes */ /* The area we are writing to has to contain all 0xFF bytes */
err = paranoid_check_all_ff(ubi, pnum, offset, len); err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
if (err) if (err)
return err > 0 ? -EINVAL : err; return err > 0 ? -EINVAL : err;
@ -350,7 +347,7 @@ retry:
return -EIO; return -EIO;
} }
err = paranoid_check_all_ff(ubi, pnum, 0, ubi->peb_size); err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
if (err) if (err)
return err > 0 ? -EINVAL : err; return err > 0 ? -EINVAL : err;
@ -672,8 +669,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
if (read_err != -EBADMSG && if (read_err != -EBADMSG &&
check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
/* The physical eraseblock is supposedly empty */ /* The physical eraseblock is supposedly empty */
err = paranoid_check_all_ff(ubi, pnum, 0, err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
ubi->peb_size);
if (err) if (err)
return err > 0 ? UBI_IO_BAD_EC_HDR : err; return err > 0 ? UBI_IO_BAD_EC_HDR : err;
@ -1229,7 +1225,7 @@ exit:
} }
/** /**
* paranoid_check_all_ff - check that a region of flash is empty. * ubi_dbg_check_all_ff - check that a region of flash is empty.
* @ubi: UBI device description object * @ubi: UBI device description object
* @pnum: the physical eraseblock number to check * @pnum: the physical eraseblock number to check
* @offset: the starting offset within the physical eraseblock to check * @offset: the starting offset within the physical eraseblock to check
@ -1239,13 +1235,14 @@ exit:
* @offset of the physical eraseblock @pnum, %1 if not, and a negative error * @offset of the physical eraseblock @pnum, %1 if not, and a negative error
* code if an error occurred. * code if an error occurred.
*/ */
static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
int len)
{ {
size_t read; size_t read;
int err; int err;
loff_t addr = (loff_t)pnum * ubi->peb_size + offset; loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
ubi_assert(!mutex_is_locked(&ubi->dbg_buf_mutex));
mutex_lock(&ubi->dbg_buf_mutex); mutex_lock(&ubi->dbg_buf_mutex);
err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf);
if (err && err != -EUCLEAN) { if (err && err != -EUCLEAN) {

Просмотреть файл

@ -459,6 +459,14 @@ retry:
dbg_wl("PEB %d EC %d", e->pnum, e->ec); dbg_wl("PEB %d EC %d", e->pnum, e->ec);
prot_queue_add(ubi, e); prot_queue_add(ubi, e);
spin_unlock(&ubi->wl_lock); spin_unlock(&ubi->wl_lock);
err = ubi_dbg_check_all_ff(ubi, e->pnum, ubi->vid_hdr_aloffset,
ubi->peb_size - ubi->vid_hdr_aloffset);
if (err) {
dbg_err("new PEB does not contain all 0xFF bytes");
return err > 0 ? -EINVAL : err;
}
return e->pnum; return e->pnum;
} }