X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/f46a1cc756ba8be68f2ad7b02696734cd68382aa..e929396e1934302d402a5608fecb9554e95d6673:/target/linux/ar71xx/files/drivers/mtd/wrt160nl_part.c?ds=sidebyside diff --git a/target/linux/ar71xx/files/drivers/mtd/wrt160nl_part.c b/target/linux/ar71xx/files/drivers/mtd/wrt160nl_part.c index da54e0ff4..72927f6f2 100644 --- a/target/linux/ar71xx/files/drivers/mtd/wrt160nl_part.c +++ b/target/linux/ar71xx/files/drivers/mtd/wrt160nl_part.c @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -76,26 +77,43 @@ struct wrt160nl_header { struct uimage_header uimage; } __attribute__ ((packed)); -static struct mtd_partition trx_parts[TRX_PARTS]; +#define WRT160NL_UBOOT_LEN 0x40000 +#define WRT160NL_ART_LEN 0x10000 +#define WRT160NL_NVRAM_LEN 0x10000 static int wrt160nl_parse_partitions(struct mtd_info *master, struct mtd_partition **pparts, - unsigned long origin) + struct mtd_part_parser_data *data) { struct wrt160nl_header *header; struct trx_header *theader; struct uimage_header *uheader; + struct mtd_partition *trx_parts; size_t retlen; unsigned int kernel_len; + unsigned int uboot_len; + unsigned int nvram_len; + unsigned int art_len; int ret; + uboot_len = max_t(unsigned int, master->erasesize, WRT160NL_UBOOT_LEN); + nvram_len = max_t(unsigned int, master->erasesize, WRT160NL_NVRAM_LEN); + art_len = max_t(unsigned int, master->erasesize, WRT160NL_ART_LEN); + + trx_parts = kzalloc(TRX_PARTS * sizeof(struct mtd_partition), + GFP_KERNEL); + if (!trx_parts) { + ret = -ENOMEM; + goto out; + } + header = vmalloc(sizeof(*header)); if (!header) { return -ENOMEM; - goto out; + goto free_parts; } - ret = master->read(master, 4 * master->erasesize, sizeof(*header), + ret = master->read(master, uboot_len, sizeof(*header), &retlen, (void *) header); if (ret) goto free_hdr; @@ -123,16 +141,12 @@ static int wrt160nl_parse_partitions(struct mtd_info *master, goto free_hdr; } - kernel_len = uheader->ih_size / master->erasesize; - if (uheader->ih_size % master->erasesize) - kernel_len++; - - kernel_len++; - kernel_len *= master->erasesize; + kernel_len = le32_to_cpu(theader->offsets[1]) + + sizeof(struct cybertan_header); trx_parts[0].name = "u-boot"; trx_parts[0].offset = 0; - trx_parts[0].size = 4 * master->erasesize; + trx_parts[0].size = uboot_len; trx_parts[0].mask_flags = MTD_WRITEABLE; trx_parts[1].name = "kernel"; @@ -142,30 +156,35 @@ static int wrt160nl_parse_partitions(struct mtd_info *master, trx_parts[2].name = "rootfs"; trx_parts[2].offset = trx_parts[1].offset + trx_parts[1].size; - trx_parts[2].size = master->size - 6 * master->erasesize - trx_parts[1].size; + trx_parts[2].size = master->size - uboot_len - nvram_len - art_len - + trx_parts[1].size; trx_parts[2].mask_flags = 0; trx_parts[3].name = "nvram"; - trx_parts[3].offset = master->size - 2 * master->erasesize; - trx_parts[3].size = master->erasesize; + trx_parts[3].offset = master->size - nvram_len - art_len; + trx_parts[3].size = nvram_len; trx_parts[3].mask_flags = MTD_WRITEABLE; trx_parts[4].name = "art"; - trx_parts[4].offset = master->size - master->erasesize; - trx_parts[4].size = master->erasesize; + trx_parts[4].offset = master->size - art_len; + trx_parts[4].size = art_len; trx_parts[4].mask_flags = MTD_WRITEABLE; trx_parts[5].name = "firmware"; - trx_parts[5].offset = 4 * master->erasesize; - trx_parts[5].size = master->size - 6 * master->erasesize; + trx_parts[5].offset = uboot_len; + trx_parts[5].size = master->size - uboot_len - nvram_len - art_len; trx_parts[5].mask_flags = 0; + vfree(header); + *pparts = trx_parts; - ret = TRX_PARTS; + return TRX_PARTS; - free_hdr: +free_hdr: vfree(header); - out: +free_parts: + kfree(trx_parts); +out: return ret; }