kernel: Add missing includes mtdsplit_*.c
[openwrt/openwrt.git] / target / linux / generic / files / drivers / mtd / mtdsplit / mtdsplit_eva.c
1 /*
2 * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
3 * Copyright (C) 2015 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
8 *
9 */
10
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.h>
17 #include <linux/byteorder/generic.h>
18 #include <linux/of.h>
19
20 #include "mtdsplit.h"
21
22 #define EVA_NR_PARTS 2
23 #define EVA_MAGIC 0xfeed1281
24 #define EVA_FOOTER_SIZE 0x18
25 #define EVA_DUMMY_SQUASHFS_SIZE 0x100
26
27 struct eva_image_header {
28 uint32_t magic;
29 uint32_t size;
30 };
31
32 static int mtdsplit_parse_eva(struct mtd_info *master,
33 const struct mtd_partition **pparts,
34 struct mtd_part_parser_data *data)
35 {
36 struct mtd_partition *parts;
37 struct eva_image_header hdr;
38 size_t retlen;
39 unsigned long kernel_size, rootfs_offset;
40 int err;
41
42 err = mtd_read(master, 0, sizeof(hdr), &retlen, (void *) &hdr);
43 if (err)
44 return err;
45
46 if (retlen != sizeof(hdr))
47 return -EIO;
48
49 if (le32_to_cpu(hdr.magic) != EVA_MAGIC)
50 return -EINVAL;
51
52 kernel_size = le32_to_cpu(hdr.size) + EVA_FOOTER_SIZE;
53
54 /* rootfs starts at the next 0x10000 boundary: */
55 rootfs_offset = round_up(kernel_size, 0x10000);
56
57 /* skip the dummy EVA squashfs partition (with wrong endianness): */
58 rootfs_offset += EVA_DUMMY_SQUASHFS_SIZE;
59
60 if (rootfs_offset >= master->size)
61 return -EINVAL;
62
63 err = mtd_check_rootfs_magic(master, rootfs_offset, NULL);
64 if (err)
65 return err;
66
67 parts = kzalloc(EVA_NR_PARTS * sizeof(*parts), GFP_KERNEL);
68 if (!parts)
69 return -ENOMEM;
70
71 parts[0].name = KERNEL_PART_NAME;
72 parts[0].offset = 0;
73 parts[0].size = kernel_size;
74
75 parts[1].name = ROOTFS_PART_NAME;
76 parts[1].offset = rootfs_offset;
77 parts[1].size = master->size - rootfs_offset;
78
79 *pparts = parts;
80 return EVA_NR_PARTS;
81 }
82
83 static const struct of_device_id mtdsplit_eva_of_match_table[] = {
84 { .compatible = "avm,eva-firmware" },
85 {},
86 };
87
88 static struct mtd_part_parser mtdsplit_eva_parser = {
89 .owner = THIS_MODULE,
90 .name = "eva-fw",
91 .of_match_table = mtdsplit_eva_of_match_table,
92 .parse_fn = mtdsplit_parse_eva,
93 .type = MTD_PARSER_TYPE_FIRMWARE,
94 };
95
96 static int __init mtdsplit_eva_init(void)
97 {
98 register_mtd_parser(&mtdsplit_eva_parser);
99
100 return 0;
101 }
102
103 subsys_initcall(mtdsplit_eva_init);