2 * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
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.
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.
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
18 * TI AR7 flash partition table.
19 * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/bootmem.h>
29 #include <linux/squashfs_fs.h>
32 unsigned int checksum
;
37 static struct mtd_partition ar7_parts
[5];
39 static int create_mtd_partitions(struct mtd_info
*master
,
40 struct mtd_partition
**pparts
,
43 struct ar7_bin_rec header
;
44 unsigned int offset
, len
;
45 unsigned int pre_size
= master
->erasesize
, post_size
= 0;
46 unsigned int root_offset
= 0xe0000;
50 printk(KERN_INFO
"Parsing AR7 partition map...\n");
52 ar7_parts
[0].name
= "loader";
53 ar7_parts
[0].offset
= 0;
54 ar7_parts
[0].size
= master
->erasesize
;
55 ar7_parts
[0].mask_flags
= MTD_WRITEABLE
;
57 ar7_parts
[1].name
= "config";
58 ar7_parts
[1].offset
= 0;
59 ar7_parts
[1].size
= master
->erasesize
;
60 ar7_parts
[1].mask_flags
= 0;
64 master
->read(master
, offset
, sizeof(header
), &len
, (u_char
*)&header
);
65 if (!strncmp((char *)&header
, "TIENV0.8", 8))
66 ar7_parts
[1].offset
= pre_size
;
67 if (header
.checksum
== 0xfeedfa42)
69 if (header
.checksum
== 0xfeed1281)
71 pre_size
+= master
->erasesize
;
76 if (!ar7_parts
[1].offset
) {
77 ar7_parts
[1].offset
= master
->size
- master
->erasesize
;
78 post_size
= master
->erasesize
;
81 switch (header
.checksum
) {
83 while (header
.length
) {
84 offset
+= sizeof(header
) + header
.length
;
85 master
->read(master
, offset
, sizeof(header
),
86 &len
, (u_char
*)&header
);
88 root_offset
= offset
+ sizeof(header
) + 4;
91 while (header
.length
) {
92 offset
+= sizeof(header
) + header
.length
;
93 master
->read(master
, offset
, sizeof(header
),
94 &len
, (u_char
*)&header
);
96 root_offset
= offset
+ sizeof(header
) + 4 + 0xff;
97 root_offset
&= ~(u32
)0xff;
100 printk(KERN_WARNING
"Unknown magic: %08x\n", header
.checksum
);
104 master
->read(master
, root_offset
, sizeof(header
), &len
, (u_char
*)&header
);
105 if (header
.checksum
!= SQUASHFS_MAGIC
) {
106 root_offset
+= master
->erasesize
- 1;
107 root_offset
&= ~(master
->erasesize
- 1);
110 ar7_parts
[2].name
= "linux";
111 ar7_parts
[2].offset
= pre_size
;
112 ar7_parts
[2].size
= master
->size
- pre_size
- post_size
;
113 ar7_parts
[2].mask_flags
= 0;
115 ar7_parts
[3].name
= "rootfs";
116 ar7_parts
[3].offset
= root_offset
;
117 ar7_parts
[3].size
= master
->size
- root_offset
- post_size
;
118 ar7_parts
[3].mask_flags
= 0;
124 static struct mtd_part_parser ar7_parser
= {
125 .owner
= THIS_MODULE
,
126 .parse_fn
= create_mtd_partitions
,
130 static int __init
ar7_parser_init(void)
132 return register_mtd_parser(&ar7_parser
);
135 module_init(ar7_parser_init
);
137 MODULE_LICENSE("GPL");
138 MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>, Eugene Konev <ejka@openwrt.org>");
139 MODULE_DESCRIPTION("MTD partitioning for TI AR7");