4c4720341efe4d6afb516793fe63fde85f43ad9f
[librecmc/librecmc-fossil.git] /
1 --- a/drivers/mtd/bcm47xxpart.c
2 +++ b/drivers/mtd/bcm47xxpart.c
3 @@ -40,6 +40,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 @@ -50,7 +51,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 @@ -58,6 +59,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 @@ -151,6 +172,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 @@ -186,8 +209,9 @@ static int bcm47xxpart_parse(struct mtd_
57                          * we want to have jffs2 (overlay) in the same mtd.
58                          */
59                         if (trx->offset[i]) {
60 +                               name = bcm47xxpart_trx_data_part_name(master, offset + trx->offset[i]);
61                                 bcm47xxpart_add_part(&parts[curr_part++],
62 -                                                    "rootfs",
63 +                                                    name,
64                                                      offset + trx->offset[i],
65                                                      0);
66                                 i++;