ar7-2.6: make cpmac robust against hardware quirks when the tx or rx dma ring runs...
[openwrt.git] / target / linux / ar7-2.6 / files / drivers / mtd / ar7part.c
1 /*
2 * $Id$
3 *
4 * Copyright (C) 2007 OpenWrt.org
5 *
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.
10 *
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.
15 *
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
19 *
20 * TI AR7 flash partition table.
21 * Based on ar7 map by Felix Fietkau.
22 *
23 */
24
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/bootmem.h>
31 #include <linux/squashfs_fs.h>
32
33 struct ar7_bin_rec {
34 unsigned int checksum;
35 unsigned int length;
36 unsigned int address;
37 };
38
39 static struct mtd_partition ar7_parts[5];
40
41 static int create_mtd_partitions(struct mtd_info *master,
42 struct mtd_partition **pparts,
43 unsigned long origin)
44 {
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;
49 int retries = 10;
50
51 printk("Parsing AR7 partition map...\n");
52
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;
57
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;
62
63 do {
64 offset = pre_size;
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)
69 break;
70 if (header.checksum == 0xfeed1281)
71 break;
72 pre_size += master->erasesize;
73 } while (retries--);
74
75 pre_size = offset;
76
77 if (!ar7_parts[1].offset) {
78 ar7_parts[1].offset = master->size - master->erasesize;
79 post_size = master->erasesize;
80 }
81
82 switch (header.checksum) {
83 case 0xfeedfa42:
84 while (header.length) {
85 offset += sizeof(header) + header.length;
86 master->read(master, offset, sizeof(header),
87 &len, (u_char *)&header);
88 }
89 root_offset = offset + sizeof(header) + 4;
90 break;
91 case 0xfeed1281:
92 while (header.length) {
93 offset += sizeof(header) + header.length;
94 master->read(master, offset, sizeof(header),
95 &len, (u_char *)&header);
96 }
97 root_offset = offset + sizeof(header) + 4 + 0xff;
98 root_offset &= ~(u32)0xff;
99 break;
100 default:
101 printk("Unknown magic: %08x\n", header.checksum);
102 break;
103 }
104
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);
109 }
110
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;
115
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;
120
121 *pparts = ar7_parts;
122 return 4;
123 }
124
125 static struct mtd_part_parser ar7_parser = {
126 .owner = THIS_MODULE,
127 .parse_fn = create_mtd_partitions,
128 .name = "ar7part",
129 };
130
131 static int __init ar7_parser_init(void)
132 {
133 return register_mtd_parser(&ar7_parser);
134 }
135
136 module_init(ar7_parser_init);
137
138 MODULE_LICENSE("GPL");
139 MODULE_AUTHOR("Felix Fietkau, Eugene Konev");
140 MODULE_DESCRIPTION("MTD partitioning for TI AR7");
This page took 0.045852 seconds and 5 git commands to generate.