kernel: add missing patch
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 400-mtd-add-rootfs-split-support.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: make rootfs split/detection more generic - patch can be moved to generic-2.6 after testing on other platforms
3
4 lede-commit: 328e660b31f0937d52c5ae3d6e7029409918a9df
5 Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 ---
7  drivers/mtd/Kconfig            | 17 +++++++++++++++++
8  drivers/mtd/mtdpart.c          | 35 +++++++++++++++++++++++++++++++++++
9  include/linux/mtd/partitions.h |  2 ++
10  3 files changed, 54 insertions(+)
11
12 diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
13 index 5a2d71729b9a..f5ac04e288eb 100644
14 --- a/drivers/mtd/Kconfig
15 +++ b/drivers/mtd/Kconfig
16 @@ -12,6 +12,23 @@ menuconfig MTD
17  
18  if MTD
19  
20 +menu "OpenWrt specific MTD options"
21 +
22 +config MTD_ROOTFS_ROOT_DEV
23 +       bool "Automatically set 'rootfs' partition to be root filesystem"
24 +       default y
25 +
26 +config MTD_SPLIT_FIRMWARE
27 +       bool "Automatically split firmware partition for kernel+rootfs"
28 +       default y
29 +
30 +config MTD_SPLIT_FIRMWARE_NAME
31 +       string "Firmware partition name"
32 +       depends on MTD_SPLIT_FIRMWARE
33 +       default "firmware"
34 +
35 +endmenu
36 +
37  config MTD_TESTS
38         tristate "MTD tests support (DANGEROUS)"
39         depends on m
40 diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
41 index dd86b430e46e..33d152d1876a 100644
42 --- a/drivers/mtd/mtdpart.c
43 +++ b/drivers/mtd/mtdpart.c
44 @@ -29,10 +29,12 @@
45  #include <linux/kmod.h>
46  #include <linux/mtd/mtd.h>
47  #include <linux/mtd/partitions.h>
48 +#include <linux/magic.h>
49  #include <linux/of.h>
50  #include <linux/err.h>
51  
52  #include "mtdcore.h"
53 +#include "mtdsplit/mtdsplit.h"
54  
55  /* Our partition linked list */
56  static LIST_HEAD(mtd_partitions);
57 @@ -52,6 +54,8 @@ struct mtd_part {
58         struct list_head list;
59  };
60  
61 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
62 +
63  /*
64   * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
65   * the pointer to that structure.
66 @@ -678,6 +682,7 @@ int mtd_add_partition(struct mtd_info *parent, const char *name,
67         mutex_unlock(&mtd_partitions_mutex);
68  
69         add_mtd_device(&new->mtd);
70 +       mtd_partition_split(parent, new);
71  
72         mtd_add_partition_attrs(new);
73  
74 @@ -756,6 +761,35 @@ int mtd_del_partition(struct mtd_info *mtd, int partno)
75  }
76  EXPORT_SYMBOL_GPL(mtd_del_partition);
77  
78 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
79 +#define SPLIT_FIRMWARE_NAME    CONFIG_MTD_SPLIT_FIRMWARE_NAME
80 +#else
81 +#define SPLIT_FIRMWARE_NAME    "unused"
82 +#endif
83 +
84 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
85 +{
86 +}
87 +
88 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
89 +                                int offset, int size)
90 +{
91 +}
92 +
93 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
94 +{
95 +       static int rootfs_found = 0;
96 +
97 +       if (rootfs_found)
98 +               return;
99 +
100 +       if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
101 +           IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
102 +               split_firmware(master, part);
103 +
104 +       arch_split_mtd_part(master, part->mtd.name, part->offset,
105 +                           part->mtd.size);
106 +}
107  /*
108   * This function, given a master MTD object and a partition table, creates
109   * and registers slave MTD objects which are bound to the master according to
110 @@ -787,6 +821,7 @@ int add_mtd_partitions(struct mtd_info *master,
111                 mutex_unlock(&mtd_partitions_mutex);
112  
113                 add_mtd_device(&slave->mtd);
114 +               mtd_partition_split(master, slave);
115                 mtd_add_partition_attrs(slave);
116                 if (parts[i].types)
117                         mtd_parse_part(slave, parts[i].types);
118 diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
119 index c4beb70dacbd..320a791290c5 100644
120 --- a/include/linux/mtd/partitions.h
121 +++ b/include/linux/mtd/partitions.h
122 @@ -109,5 +109,7 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
123                       long long offset, long long length);
124  int mtd_del_partition(struct mtd_info *master, int partno);
125  uint64_t mtd_get_device_size(const struct mtd_info *mtd);
126 +extern void __weak arch_split_mtd_part(struct mtd_info *master,
127 +                                      const char *name, int offset, int size);
128  
129  #endif
130 -- 
131 2.11.0
132