diff options
author | Matteo Croce <technoboy85@gmail.com> | 2008-03-11 21:25:06 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2008-04-22 15:48:12 -0400 |
commit | f0797881d59ab93d7d92c55411e0573977d909d4 (patch) | |
tree | aeee6ac91a72631c57e201143e3d73af1a040c5e /drivers | |
parent | 5c249c5a57dce2b47f1fb92093201b3a7013cb57 (diff) |
[MTD] AR7 mtd partition map
Signed-off-by: Matteo Croce <technoboy85@gmail.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Eugene Konev <ejka@imfi.kspu.ru>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/Kconfig | 6 | ||||
-rw-r--r-- | drivers/mtd/Makefile | 1 | ||||
-rw-r--r-- | drivers/mtd/ar7part.c | 146 |
3 files changed, 153 insertions, 0 deletions
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index e8503341e3b1..eed06d068fd1 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig | |||
@@ -158,6 +158,12 @@ config MTD_OF_PARTS | |||
158 | the partition map from the children of the flash node, | 158 | the partition map from the children of the flash node, |
159 | as described in Documentation/powerpc/booting-without-of.txt. | 159 | as described in Documentation/powerpc/booting-without-of.txt. |
160 | 160 | ||
161 | config MTD_AR7_PARTS | ||
162 | tristate "TI AR7 partitioning support" | ||
163 | depends on MTD_PARTITIONS | ||
164 | ---help--- | ||
165 | TI AR7 partitioning support | ||
166 | |||
161 | comment "User Modules And Translation Layers" | 167 | comment "User Modules And Translation Layers" |
162 | 168 | ||
163 | config MTD_CHAR | 169 | config MTD_CHAR |
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index 538e33d11d46..4b77335715f0 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile | |||
@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o | |||
11 | obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o | 11 | obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o |
12 | obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o | 12 | obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o |
13 | obj-$(CONFIG_MTD_AFS_PARTS) += afs.o | 13 | obj-$(CONFIG_MTD_AFS_PARTS) += afs.o |
14 | obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o | ||
14 | obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o | 15 | obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o |
15 | 16 | ||
16 | # 'Users' - code which presents functionality to userspace. | 17 | # 'Users' - code which presents functionality to userspace. |
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c new file mode 100644 index 000000000000..7722608d5a83 --- /dev/null +++ b/drivers/mtd/ar7part.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | * Copyright © 2007 Eugene Konev <ejka@openwrt.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | * | ||
18 | * TI AR7 flash partition table. | ||
19 | * Based on ar7 map by Felix Fietkau <nbd@openwrt.org> | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/slab.h> | ||
25 | |||
26 | #include <linux/mtd/mtd.h> | ||
27 | #include <linux/mtd/partitions.h> | ||
28 | #include <linux/bootmem.h> | ||
29 | #include <linux/magic.h> | ||
30 | |||
31 | #define AR7_PARTS 4 | ||
32 | #define ROOT_OFFSET 0xe0000 | ||
33 | |||
34 | #define LOADER_MAGIC1 le32_to_cpu(0xfeedfa42) | ||
35 | #define LOADER_MAGIC2 le32_to_cpu(0xfeed1281) | ||
36 | |||
37 | struct ar7_bin_rec { | ||
38 | unsigned int checksum; | ||
39 | unsigned int length; | ||
40 | unsigned int address; | ||
41 | }; | ||
42 | |||
43 | static struct mtd_partition ar7_parts[AR7_PARTS]; | ||
44 | |||
45 | static int create_mtd_partitions(struct mtd_info *master, | ||
46 | struct mtd_partition **pparts, | ||
47 | unsigned long origin) | ||
48 | { | ||
49 | struct ar7_bin_rec header; | ||
50 | unsigned int offset, len; | ||
51 | unsigned int pre_size = master->erasesize, post_size = 0; | ||
52 | unsigned int root_offset = ROOT_OFFSET; | ||
53 | |||
54 | int retries = 10; | ||
55 | |||
56 | ar7_parts[0].name = "loader"; | ||
57 | ar7_parts[0].offset = 0; | ||
58 | ar7_parts[0].size = master->erasesize; | ||
59 | ar7_parts[0].mask_flags = MTD_WRITEABLE; | ||
60 | |||
61 | ar7_parts[1].name = "config"; | ||
62 | ar7_parts[1].offset = 0; | ||
63 | ar7_parts[1].size = master->erasesize; | ||
64 | ar7_parts[1].mask_flags = 0; | ||
65 | |||
66 | do { /* Try 10 blocks starting from master->erasesize */ | ||
67 | offset = pre_size; | ||
68 | master->read(master, offset, | ||
69 | sizeof(header), &len, (u8 *)&header); | ||
70 | if (!strncmp((char *)&header, "TIENV0.8", 8)) | ||
71 | ar7_parts[1].offset = pre_size; | ||
72 | if (header.checksum == LOADER_MAGIC1) | ||
73 | break; | ||
74 | if (header.checksum == LOADER_MAGIC2) | ||
75 | break; | ||
76 | pre_size += master->erasesize; | ||
77 | } while (retries--); | ||
78 | |||
79 | pre_size = offset; | ||
80 | |||
81 | if (!ar7_parts[1].offset) { | ||
82 | ar7_parts[1].offset = master->size - master->erasesize; | ||
83 | post_size = master->erasesize; | ||
84 | } | ||
85 | |||
86 | switch (header.checksum) { | ||
87 | case LOADER_MAGIC1: | ||
88 | while (header.length) { | ||
89 | offset += sizeof(header) + header.length; | ||
90 | master->read(master, offset, sizeof(header), | ||
91 | &len, (u8 *)&header); | ||
92 | } | ||
93 | root_offset = offset + sizeof(header) + 4; | ||
94 | break; | ||
95 | case LOADER_MAGIC2: | ||
96 | while (header.length) { | ||
97 | offset += sizeof(header) + header.length; | ||
98 | master->read(master, offset, sizeof(header), | ||
99 | &len, (u8 *)&header); | ||
100 | } | ||
101 | root_offset = offset + sizeof(header) + 4 + 0xff; | ||
102 | root_offset &= ~(u32)0xff; | ||
103 | break; | ||
104 | default: | ||
105 | printk(KERN_WARNING "Unknown magic: %08x\n", header.checksum); | ||
106 | break; | ||
107 | } | ||
108 | |||
109 | master->read(master, root_offset, | ||
110 | sizeof(header), &len, (u8 *)&header); | ||
111 | if (header.checksum != SQUASHFS_MAGIC) { | ||
112 | root_offset += master->erasesize - 1; | ||
113 | root_offset &= ~(master->erasesize - 1); | ||
114 | } | ||
115 | |||
116 | ar7_parts[2].name = "linux"; | ||
117 | ar7_parts[2].offset = pre_size; | ||
118 | ar7_parts[2].size = master->size - pre_size - post_size; | ||
119 | ar7_parts[2].mask_flags = 0; | ||
120 | |||
121 | ar7_parts[3].name = "rootfs"; | ||
122 | ar7_parts[3].offset = root_offset; | ||
123 | ar7_parts[3].size = master->size - root_offset - post_size; | ||
124 | ar7_parts[3].mask_flags = 0; | ||
125 | |||
126 | *pparts = ar7_parts; | ||
127 | return AR7_PARTS; | ||
128 | } | ||
129 | |||
130 | static struct mtd_part_parser ar7_parser = { | ||
131 | .owner = THIS_MODULE, | ||
132 | .parse_fn = create_mtd_partitions, | ||
133 | .name = "ar7part", | ||
134 | }; | ||
135 | |||
136 | static int __init ar7_parser_init(void) | ||
137 | { | ||
138 | return register_mtd_parser(&ar7_parser); | ||
139 | } | ||
140 | |||
141 | module_init(ar7_parser_init); | ||
142 | |||
143 | MODULE_LICENSE("GPL"); | ||
144 | MODULE_AUTHOR( "Felix Fietkau <nbd@openwrt.org>, " | ||
145 | "Eugene Konev <ejka@openwrt.org>"); | ||
146 | MODULE_DESCRIPTION("MTD partitioning for TI AR7"); | ||