generic: mtd backport for Spansion S25FL164K
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-4.1 / 400-mtd-add-rootfs-split-support.patch
1 --- a/drivers/mtd/Kconfig
2 +++ b/drivers/mtd/Kconfig
3 @@ -12,6 +12,23 @@ menuconfig MTD
4
5 if MTD
6
7 +menu "OpenWrt specific MTD options"
8 +
9 +config MTD_ROOTFS_ROOT_DEV
10 + bool "Automatically set 'rootfs' partition to be root filesystem"
11 + default y
12 +
13 +config MTD_SPLIT_FIRMWARE
14 + bool "Automatically split firmware partition for kernel+rootfs"
15 + default y
16 +
17 +config MTD_SPLIT_FIRMWARE_NAME
18 + string "Firmware partition name"
19 + depends on MTD_SPLIT_FIRMWARE
20 + default "firmware"
21 +
22 +endmenu
23 +
24 config MTD_TESTS
25 tristate "MTD tests support (DANGEROUS)"
26 depends on m
27 --- a/drivers/mtd/mtdpart.c
28 +++ b/drivers/mtd/mtdpart.c
29 @@ -29,10 +29,12 @@
30 #include <linux/kmod.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/partitions.h>
33 +#include <linux/magic.h>
34 #include <linux/err.h>
35 #include <linux/kconfig.h>
36
37 #include "mtdcore.h"
38 +#include "mtdsplit/mtdsplit.h"
39
40 /* Our partition linked list */
41 static LIST_HEAD(mtd_partitions);
42 @@ -46,13 +48,14 @@ struct mtd_part {
43 struct list_head list;
44 };
45
46 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
47 +
48 /*
49 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
50 * the pointer to that structure with this macro.
51 */
52 #define PART(x) ((struct mtd_part *)(x))
53
54 -
55 /*
56 * MTD methods which simply translate the effective address and pass through
57 * to the _real_ device.
58 @@ -578,8 +581,10 @@ static int mtd_add_partition_attrs(struc
59 return ret;
60 }
61
62 -int mtd_add_partition(struct mtd_info *master, const char *name,
63 - long long offset, long long length)
64 +
65 +static int
66 +__mtd_add_partition(struct mtd_info *master, const char *name,
67 + long long offset, long long length, bool dup_check)
68 {
69 struct mtd_partition part;
70 struct mtd_part *new;
71 @@ -611,6 +616,7 @@ int mtd_add_partition(struct mtd_info *m
72 mutex_unlock(&mtd_partitions_mutex);
73
74 add_mtd_device(&new->mtd);
75 + mtd_partition_split(master, new);
76
77 mtd_add_partition_attrs(new);
78
79 @@ -618,6 +624,12 @@ int mtd_add_partition(struct mtd_info *m
80 }
81 EXPORT_SYMBOL_GPL(mtd_add_partition);
82
83 +int mtd_add_partition(struct mtd_info *master, const char *name,
84 + long long offset, long long length)
85 +{
86 + return __mtd_add_partition(master, name, offset, length, true);
87 +}
88 +
89 int mtd_del_partition(struct mtd_info *master, int partno)
90 {
91 struct mtd_part *slave, *next;
92 @@ -643,6 +655,35 @@ int mtd_del_partition(struct mtd_info *m
93 }
94 EXPORT_SYMBOL_GPL(mtd_del_partition);
95
96 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
97 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
98 +#else
99 +#define SPLIT_FIRMWARE_NAME "unused"
100 +#endif
101 +
102 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
103 +{
104 +}
105 +
106 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
107 + int offset, int size)
108 +{
109 +}
110 +
111 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
112 +{
113 + static int rootfs_found = 0;
114 +
115 + if (rootfs_found)
116 + return;
117 +
118 + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
119 + config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
120 + split_firmware(master, part);
121 +
122 + arch_split_mtd_part(master, part->mtd.name, part->offset,
123 + part->mtd.size);
124 +}
125 /*
126 * This function, given a master MTD object and a partition table, creates
127 * and registers slave MTD objects which are bound to the master according to
128 @@ -672,6 +713,7 @@ int add_mtd_partitions(struct mtd_info *
129 mutex_unlock(&mtd_partitions_mutex);
130
131 add_mtd_device(&slave->mtd);
132 + mtd_partition_split(master, slave);
133 mtd_add_partition_attrs(slave);
134
135 cur_offset = slave->offset + slave->mtd.size;
136 --- a/include/linux/mtd/partitions.h
137 +++ b/include/linux/mtd/partitions.h
138 @@ -84,5 +84,7 @@ int mtd_add_partition(struct mtd_info *m
139 long long offset, long long length);
140 int mtd_del_partition(struct mtd_info *master, int partno);
141 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
142 +extern void __weak arch_split_mtd_part(struct mtd_info *master,
143 + const char *name, int offset, int size);
144
145 #endif