kernel: bump 4.14 to 4.14.158
[openwrt/openwrt.git] / target / linux / generic / pending-4.14 / 404-mtd-add-more-helper-functions.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: kernel/3.10: add separate rootfs partition parser
3
4 lede-commit: daec7ad7688415156e2730e401503d09bd3acf91
5 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
6 ---
7 drivers/mtd/mtdpart.c | 29 +++++++++++++++++++++++++++++
8 include/linux/mtd/mtd.h | 18 ++++++++++++++++++
9 include/linux/mtd/partitions.h | 2 ++
10 3 files changed, 49 insertions(+)
11
12 --- a/drivers/mtd/mtdpart.c
13 +++ b/drivers/mtd/mtdpart.c
14 @@ -1260,6 +1260,24 @@ int mtd_is_partition(const struct mtd_in
15 }
16 EXPORT_SYMBOL_GPL(mtd_is_partition);
17
18 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
19 +{
20 + if (!mtd_is_partition(mtd))
21 + return (struct mtd_info *)mtd;
22 +
23 + return mtd_to_part(mtd)->parent;
24 +}
25 +EXPORT_SYMBOL_GPL(mtdpart_get_master);
26 +
27 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
28 +{
29 + if (!mtd_is_partition(mtd))
30 + return 0;
31 +
32 + return mtd_to_part(mtd)->offset;
33 +}
34 +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
35 +
36 /* Returns the size of the entire flash chip */
37 uint64_t mtd_get_device_size(const struct mtd_info *mtd)
38 {
39 --- a/include/linux/mtd/mtd.h
40 +++ b/include/linux/mtd/mtd.h
41 @@ -494,6 +494,24 @@ static inline uint32_t mtd_mod_by_eb(uin
42 return do_div(sz, mtd->erasesize);
43 }
44
45 +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
46 +{
47 + if (mtd_mod_by_eb(sz, mtd) == 0)
48 + return sz;
49 +
50 + /* Round up to next erase block */
51 + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
52 +}
53 +
54 +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
55 +{
56 + if (mtd_mod_by_eb(sz, mtd) == 0)
57 + return sz;
58 +
59 + /* Round down to the start of the current erase block */
60 + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
61 +}
62 +
63 static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
64 {
65 if (mtd->writesize_shift)
66 --- a/include/linux/mtd/partitions.h
67 +++ b/include/linux/mtd/partitions.h
68 @@ -116,6 +116,8 @@ int mtd_is_partition(const struct mtd_in
69 int mtd_add_partition(struct mtd_info *master, const char *name,
70 long long offset, long long length);
71 int mtd_del_partition(struct mtd_info *master, int partno);
72 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
73 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
74 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
75
76 #endif