#include <uapi/linux/magic.h>
-@@ -250,6 +251,28 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -249,6 +250,28 @@ static int bcm47xxpart_parse(struct mtd_
break;
}
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
- drivers/mtd/bcm47xxpart.c | 124 ++++++++++++++++++++++++++++------------------
- 1 file changed, 77 insertions(+), 47 deletions(-)
+ drivers/mtd/bcm47xxpart.c | 121 ++++++++++++++++++++++++++++------------------
+ 1 file changed, 74 insertions(+), 47 deletions(-)
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
-@@ -83,6 +83,70 @@ out_default:
+@@ -83,6 +83,67 @@ out_default:
return "rootfs";
}
+ struct mtd_partition *parts,
+ size_t parts_len)
+{
-+ struct mtd_partition *part;
+ struct trx_header header;
+ size_t bytes_read;
+ int curr_part = 0;
+
+ /* We have LZMA loader if offset[2] points to sth */
+ if (header.offset[2]) {
-+ part = &parts[curr_part++];
-+ part->name = "loader";
-+ part->offset = trx->offset + header.offset[i];
++ bcm47xxpart_add_part(&parts[curr_part++], "loader",
++ trx->offset + header.offset[i], 0);
+ i++;
+ }
+
+ if (header.offset[i]) {
-+ part = &parts[curr_part++];
-+ part->name = "linux";
-+ part->offset = trx->offset + header.offset[i];
++ bcm47xxpart_add_part(&parts[curr_part++], "linux",
++ trx->offset + header.offset[i], 0);
+ i++;
+ }
+
+ if (header.offset[i]) {
+ size_t offset = trx->offset + header.offset[i];
++ const char *name = bcm47xxpart_trx_data_part_name(master,
++ offset);
+
-+ part = &parts[curr_part++];
-+ part->name = bcm47xxpart_trx_data_part_name(master, offset);
-+ part->offset = offset;
++ bcm47xxpart_add_part(&parts[curr_part++], name, offset, 0);
+ i++;
+ }
+
static int bcm47xxpart_parse(struct mtd_info *master,
struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
-@@ -93,9 +157,7 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -93,9 +154,7 @@ static int bcm47xxpart_parse(struct mtd_
size_t bytes_read;
uint32_t offset;
uint32_t blocksize = master->erasesize;
int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
int err;
-@@ -182,54 +244,14 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -182,54 +241,14 @@ static int bcm47xxpart_parse(struct mtd_
/* TRX */
if (buf[0x000 / 4] == TRX_MAGIC) {
offset = roundup(offset + trx->length, blocksize);
/* Next loop iteration will increase the offset */
offset -= blocksize;
-@@ -307,9 +329,17 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -307,9 +326,17 @@ static int bcm47xxpart_parse(struct mtd_
parts[i + 1].offset : master->size;
parts[i].size = next_part_offset - parts[i].offset;
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
-@@ -147,6 +148,30 @@ static int bcm47xxpart_parse_trx(struct
+@@ -144,6 +145,30 @@ static int bcm47xxpart_parse_trx(struct
return curr_part;
}
static int bcm47xxpart_parse(struct mtd_info *master,
struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
-@@ -157,7 +182,8 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -154,7 +179,8 @@ static int bcm47xxpart_parse(struct mtd_
size_t bytes_read;
uint32_t offset;
uint32_t blocksize = master->erasesize;
int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
int err;
-@@ -246,7 +272,11 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -243,7 +269,11 @@ static int bcm47xxpart_parse(struct mtd_
if (buf[0x000 / 4] == TRX_MAGIC) {
struct trx_header *trx;
bcm47xxpart_add_part(&parts[curr_part++], "firmware",
offset, 0);
-@@ -332,14 +362,20 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -329,14 +359,20 @@ static int bcm47xxpart_parse(struct mtd_
}
/* If there was TRX parse it now */
static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
size_t offset)
{
-@@ -113,19 +141,22 @@ static int bcm47xxpart_parse_trx(struct
+@@ -91,6 +119,7 @@ static int bcm47xxpart_parse_trx(struct
+ {
+ struct trx_header header;
+ size_t bytes_read;
++ size_t offset;
+ int curr_part = 0;
+ int i, err;
+
+@@ -110,21 +139,25 @@ static int bcm47xxpart_parse_trx(struct
+
+ /* We have LZMA loader if offset[2] points to sth */
if (header.offset[2]) {
- part = &parts[curr_part++];
- part->name = "loader";
-- part->offset = trx->offset + header.offset[i];
-+ part->offset = bcm47xxpart_real_offset(master, trx->offset,
-+ header.offset[i]);
+- bcm47xxpart_add_part(&parts[curr_part++], "loader",
+- trx->offset + header.offset[i], 0);
++ offset = bcm47xxpart_real_offset(master, trx->offset,
++ header.offset[i]);
++ bcm47xxpart_add_part(&parts[curr_part++], "loader", offset, 0);
i++;
}
if (header.offset[i]) {
- part = &parts[curr_part++];
- part->name = "linux";
-- part->offset = trx->offset + header.offset[i];
-+ part->offset = bcm47xxpart_real_offset(master, trx->offset,
-+ header.offset[i]);
+- bcm47xxpart_add_part(&parts[curr_part++], "linux",
+- trx->offset + header.offset[i], 0);
++ offset = bcm47xxpart_real_offset(master, trx->offset,
++ header.offset[i]);
++ bcm47xxpart_add_part(&parts[curr_part++], "linux", offset, 0);
i++;
}
if (header.offset[i]) {
- size_t offset = trx->offset + header.offset[i];
-+ size_t offset = bcm47xxpart_real_offset(master, trx->offset,
-+ header.offset[i]);
+- const char *name = bcm47xxpart_trx_data_part_name(master,
+- offset);
++ const char *name;
++
++ offset = bcm47xxpart_real_offset(master, trx->offset,
++ header.offset[i]);
++ name = bcm47xxpart_trx_data_part_name(master, offset);
- part = &parts[curr_part++];
- part->name = bcm47xxpart_trx_data_part_name(master, offset);
+ bcm47xxpart_add_part(&parts[curr_part++], name, offset, 0);
+ i++;
#define ML_MAGIC1 0x39685a42
#define ML_MAGIC2 0x26594131
#define TRX_MAGIC 0x30524448
-@@ -298,6 +299,15 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -297,6 +298,15 @@ static int bcm47xxpart_parse(struct mtd_
MTD_WRITEABLE);
continue;
}