[OpenWrt-Devel] [PATCH V2] Fix for mvebu (WRT1900AC/WRT1200AC/etc) boot counter

Bjørn Mork bjorn at mork.no
Wed Aug 19 03:27:21 EDT 2015


Rob Mosher <nyt-openwrt at countercultured.net> writes:

> +#define BOOTCOUNT_MAGIC	0x20110811
> +
> +struct bootcounter {
> +	uint32_t magic;
> +	uint32_t count;
> +	uint32_t checksum;
> +};

Maybe make it clear that these numbers are stored in little endian
order?  Or will that always be the native endianness?

> +static char page[2048];
> +
> +int mtd_resetbc(const char *mtd)
> +{
> +	struct mtd_info_user mtd_info;
> +	struct bootcounter *curr = (struct bootcounter *)page;
> +	unsigned int i;
> +	int last_count = 0;
> +	int num_bc;
> +	int fd;
> +	int ret;
> +
> +	fd = mtd_check_open(mtd);
> +
> +	if (ioctl(fd, MEMGETINFO, &mtd_info) < 0) {
> +		fprintf(stderr, "failed to get mtd info!\n");
> +		return -1;
> +	}
> +
> +	num_bc = mtd_info.size / mtd_info.writesize;
> +
> +	for (i = 0; i < num_bc; i++) {
> +		pread(fd, curr, sizeof(*curr), i * mtd_info.writesize);
> +
> +		if (curr->magic != BOOTCOUNT_MAGIC && curr->magic != 0xffffffff) {
> +			fprintf(stderr, "unexpected magic %08x, bailing out\n", curr->magic);
> +			goto out;
> +		}

Maybe verify the checksum sanity as well as an extra failsafe?

> +		mtd resetbc s_env

What good does it do to make the partition name an input parameter?
It's just as static as the BOOTCOUNT_MAGIC, AFAICT.


Bjørn
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list