kernel: 3.14: update bcm47xxpart
[openwrt.git] / target / linux / generic / patches-3.14 / 431-mtd-bcm47xxpart-support-TRX-data-partition-being-UBI.patch
1 --- a/drivers/mtd/bcm47xxpart.c
2 +++ b/drivers/mtd/bcm47xxpart.c
3 @@ -36,6 +36,7 @@
4  #define ML_MAGIC2                      0x26594131
5  #define TRX_MAGIC                      0x30524448
6  #define SQSH_MAGIC                     0x71736873      /* shsq */
7 +#define UBI_EC_MAGIC                   0x23494255      /* UBI# */
8  
9  struct trx_header {
10         uint32_t magic;
11 @@ -46,7 +47,7 @@ struct trx_header {
12         uint32_t offset[3];
13  } __packed;
14  
15 -static void bcm47xxpart_add_part(struct mtd_partition *part, char *name,
16 +static void bcm47xxpart_add_part(struct mtd_partition *part, const char *name,
17                                  u64 offset, uint32_t mask_flags)
18  {
19         part->name = name;
20 @@ -54,6 +55,26 @@ static void bcm47xxpart_add_part(struct
21         part->mask_flags = mask_flags;
22  }
23  
24 +static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
25 +                                                 size_t offset)
26 +{
27 +       uint32_t buf;
28 +       size_t bytes_read;
29 +
30 +       if (mtd_read(master, offset, sizeof(&buf), &bytes_read,
31 +                    (uint8_t *)&buf) < 0) {
32 +               pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
33 +                       offset);
34 +               goto out_default;
35 +       }
36 +
37 +       if (buf == UBI_EC_MAGIC)
38 +               return "ubi";
39 +
40 +out_default:
41 +       return "rootfs";
42 +}
43 +
44  static int bcm47xxpart_parse(struct mtd_info *master,
45                              struct mtd_partition **pparts,
46                              struct mtd_part_parser_data *data)
47 @@ -147,6 +168,8 @@ static int bcm47xxpart_parse(struct mtd_
48  
49                 /* TRX */
50                 if (buf[0x000 / 4] == TRX_MAGIC) {
51 +                       const char *name;
52 +
53                         if (BCM47XXPART_MAX_PARTS - curr_part < 4) {
54                                 pr_warn("Not enough partitions left to register trx, scanning stopped!\n");
55                                 break;
56 @@ -177,7 +200,9 @@ static int bcm47xxpart_parse(struct mtd_
57                          * trx->length - trx->offset[i]. We don't fill it as
58                          * we want to have jffs2 (overlay) in the same mtd.
59                          */
60 -                       bcm47xxpart_add_part(&parts[curr_part++], "rootfs",
61 +                       name = bcm47xxpart_trx_data_part_name(master,
62 +                                                             offset + trx->offset[i]);
63 +                       bcm47xxpart_add_part(&parts[curr_part++], name,
64                                              offset + trx->offset[i], 0);
65                         i++;
66