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;
62 do { /* Try 10 blocks starting from master->erasesize */
64 master
->read(master
, offset
,
65 sizeof(header
), &len
, (u_char
*)&header
);
66 if (!strncmp((char *)&header
, "TIENV0.8", 8))
67 ar7_parts
[1].offset
= pre_size
;
68 if (header
.checksum
== 0xfeedfa42)
70 if (header
.checksum
== 0xfeed1281)
72 pre_size
+= master
->erasesize
;
77 if (!ar7_parts
[1].offset
) {
78 ar7_parts
[1].offset
= master
->size
- master
->erasesize
;
79 post_size
= master
->erasesize
;
82 switch (header
.checksum
) {
84 while (header
.length
) {
85 offset
+= sizeof(header
) + header
.length
;
86 master
->read(master
, offset
, sizeof(header
),
87 &len
, (u_char
*)&header
);
89 root_offset
= offset
+ sizeof(header
) + 4;
92 while (header
.length
) {
93 offset
+= sizeof(header
) + header
.length
;
94 master
->read(master
, offset
, sizeof(header
),
95 &len
, (u_char
*)&header
);
97 root_offset
= offset
+ sizeof(header
) + 4 + 0xff;
98 root_offset
&= ~(u32
)0xff;
101 printk(KERN_WARNING
"Unknown magic: %08x\n", header
.checksum
);
105 master
->read(master
, root_offset
,
106 sizeof(header
), &len
, (u_char
*)&header
);
107 if (header
.checksum
!= SQUASHFS_MAGIC
) {
108 root_offset
+= master
->erasesize
- 1;
109 root_offset
&= ~(master
->erasesize
- 1);
112 ar7_parts
[2].name
= "linux";
113 ar7_parts
[2].offset
= pre_size
;
114 ar7_parts
[2].size
= master
->size
- pre_size
- post_size
;
115 ar7_parts
[2].mask_flags
= 0;
117 ar7_parts
[3].name
= "rootfs";
118 ar7_parts
[3].offset
= root_offset
;
119 ar7_parts
[3].size
= master
->size
- root_offset
- post_size
;
120 ar7_parts
[3].mask_flags
= 0;
126 static struct mtd_part_parser ar7_parser
= {
127 .owner
= THIS_MODULE
,
128 .parse_fn
= create_mtd_partitions
,
132 static int __init
ar7_parser_init(void)
134 return register_mtd_parser(&ar7_parser
);
137 module_init(ar7_parser_init
);
139 MODULE_LICENSE("GPL");
140 MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>, Eugene Konev <ejka@openwrt.org>");
141 MODULE_DESCRIPTION("MTD partitioning for TI AR7");