Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 155309
b: refs/heads/master
c: 0c6c7fa
h: refs/heads/master
i:
  155307: 0c94df2
v: v3
  • Loading branch information
Adrian Hunter authored and Artem Bityutskiy committed Jul 5, 2009
1 parent 8d2094b commit 847ea70
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 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: 1398788fe7b730db10e97dcb9f838603e41922d5
refs/heads/master: 0c6c7fa1313fcb69cae35e34168d2e83b8da854a
1 change: 1 addition & 0 deletions trunk/drivers/mtd/ubi/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
ubi_msg("number of PEBs reserved for bad PEB handling: %d",
ubi->beb_rsvd_pebs);
ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
ubi_msg("image sequence number: %d", ubi->image_seq);

/*
* The below lock makes sure we do not race with 'ubi_thread()' which
Expand Down
2 changes: 2 additions & 0 deletions trunk/drivers/mtd/ubi/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
be32_to_cpu(ec_hdr->vid_hdr_offset));
printk(KERN_DEBUG "\tdata_offset %d\n",
be32_to_cpu(ec_hdr->data_offset));
printk(KERN_DEBUG "\timage_seq %d\n",
be32_to_cpu(ec_hdr->image_seq));
printk(KERN_DEBUG "\thdr_crc %#08x\n",
be32_to_cpu(ec_hdr->hdr_crc));
printk(KERN_DEBUG "erase counter header hexdump:\n");
Expand Down
15 changes: 13 additions & 2 deletions trunk/drivers/mtd/ubi/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,16 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
* This function returns zero if the erase counter header is OK, and %1 if
* not.
*/
static int validate_ec_hdr(const struct ubi_device *ubi,
static int validate_ec_hdr(struct ubi_device *ubi,
const struct ubi_ec_hdr *ec_hdr)
{
long long ec;
int vid_hdr_offset, leb_start;
int vid_hdr_offset, leb_start, image_seq;

ec = be64_to_cpu(ec_hdr->ec);
vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset);
leb_start = be32_to_cpu(ec_hdr->data_offset);
image_seq = be32_to_cpu(ec_hdr->image_seq);

if (ec_hdr->version != UBI_VERSION) {
ubi_err("node with incompatible UBI version found: "
Expand All @@ -597,6 +598,15 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
goto bad;
}

if (!ubi->image_seq_set) {
ubi->image_seq = image_seq;
ubi->image_seq_set = 1;
} else if (ubi->image_seq != image_seq) {
ubi_err("bad image sequence number %d, expected %d",
image_seq, ubi->image_seq);
goto bad;
}

return 0;

bad:
Expand Down Expand Up @@ -742,6 +752,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
ec_hdr->version = UBI_VERSION;
ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset);
ec_hdr->data_offset = cpu_to_be32(ubi->leb_start);
ec_hdr->image_seq = cpu_to_be32(ubi->image_seq);
crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
ec_hdr->hdr_crc = cpu_to_be32(crc);

Expand Down
2 changes: 2 additions & 0 deletions trunk/drivers/mtd/ubi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
if (si->is_empty)
ubi_msg("empty MTD device detected");

ubi->image_seq_set = 1;

/*
* In case of unknown erase counter we use the mean erase counter
* value.
Expand Down
12 changes: 11 additions & 1 deletion trunk/drivers/mtd/ubi/ubi-media.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ enum {
* @ec: the erase counter
* @vid_hdr_offset: where the VID header starts
* @data_offset: where the user data start
* @image_seq: image sequence number
* @padding2: reserved for future, zeroes
* @hdr_crc: erase counter header CRC checksum
*
Expand All @@ -144,6 +145,14 @@ enum {
* volume identifier header and user data, relative to the beginning of the
* physical eraseblock. These values have to be the same for all physical
* eraseblocks.
*
* The @image_seq field is used to validate a UBI image that has been prepared
* for a UBI device. The @image_seq value can be any value, but it must be the
* same on all eraseblocks. UBI will ensure that all new erase counter headers
* also contain this value, and will check the value when scanning at start-up.
* One way to make use of @image_seq is to increase its value by one every time
* an image is flashed over an existing image, then, if the flashing does not
* complete, UBI will detect the error when scanning.
*/
struct ubi_ec_hdr {
__be32 magic;
Expand All @@ -152,7 +161,8 @@ struct ubi_ec_hdr {
__be64 ec; /* Warning: the current limit is 31-bit anyway! */
__be32 vid_hdr_offset;
__be32 data_offset;
__u8 padding2[36];
__be32 image_seq;
__u8 padding2[32];
__be32 hdr_crc;
} __attribute__ ((packed));

Expand Down
4 changes: 4 additions & 0 deletions trunk/drivers/mtd/ubi/ubi.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ struct ubi_wl_entry;
* @vol->readers, @vol->writers, @vol->exclusive,
* @vol->ref_count, @vol->mapping and @vol->eba_tbl.
* @ref_count: count of references on the UBI device
* @image_seq: image sequence number recorded on EC headers
* @image_seq_set: indicates @image_seq is known
*
* @rsvd_pebs: count of reserved physical eraseblocks
* @avail_pebs: count of available physical eraseblocks
Expand Down Expand Up @@ -390,6 +392,8 @@ struct ubi_device {
struct ubi_volume *volumes[UBI_MAX_VOLUMES+UBI_INT_VOL_COUNT];
spinlock_t volumes_lock;
int ref_count;
int image_seq;
int image_seq_set;

int rsvd_pebs;
int avail_pebs;
Expand Down

0 comments on commit 847ea70

Please sign in to comment.