4 * Copyright (C) 2007 OpenWrt.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * TI AR7 flash partition table.
21 * Based on ar7 map by Felix Fietkau.
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/bootmem.h>
31 #include <linux/squashfs_fs.h>
34 unsigned int checksum
;
39 static struct mtd_partition ar7_parts
[5];
41 static int create_mtd_partitions(struct mtd_info
*master
,
42 struct mtd_partition
**pparts
,
45 struct ar7_bin_rec header
;
46 unsigned int offset
, len
;
47 unsigned int pre_size
= master
->erasesize
, post_size
= 0,
48 root_offset
= 0xe0000;
51 printk("Parsing AR7 partition map...\n");
53 ar7_parts
[0].name
= "loader";
54 ar7_parts
[0].offset
= 0;
55 ar7_parts
[0].size
= master
->erasesize
;
56 ar7_parts
[0].mask_flags
= MTD_WRITEABLE
;
58 ar7_parts
[1].name
= "config";
59 ar7_parts
[1].offset
= 0;
60 ar7_parts
[1].size
= master
->erasesize
;
61 ar7_parts
[1].mask_flags
= 0;
65 master
->read(master
, offset
, 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("Unknown magic: %08x\n", header
.checksum
);
105 master
->read(master
, root_offset
, sizeof(header
), &len
, (u_char
*)&header
);
106 if (header
.checksum
!= SQUASHFS_MAGIC
) {
107 root_offset
+= master
->erasesize
- 1;
108 root_offset
&= ~(master
->erasesize
- 1);
111 ar7_parts
[2].name
= "linux";
112 ar7_parts
[2].offset
= pre_size
;
113 ar7_parts
[2].size
= master
->size
- pre_size
- post_size
;
114 ar7_parts
[2].mask_flags
= 0;
116 ar7_parts
[3].name
= "rootfs";
117 ar7_parts
[3].offset
= root_offset
;
118 ar7_parts
[3].size
= master
->size
- root_offset
- post_size
;
119 ar7_parts
[3].mask_flags
= 0;
125 static struct mtd_part_parser ar7_parser
= {
126 .owner
= THIS_MODULE
,
127 .parse_fn
= create_mtd_partitions
,
131 static int __init
ar7_parser_init(void)
133 return register_mtd_parser(&ar7_parser
);
136 module_init(ar7_parser_init
);
138 MODULE_LICENSE("GPL");
139 MODULE_AUTHOR("Felix Fietkau, Eugene Konev");
140 MODULE_DESCRIPTION("MTD partitioning for TI AR7");