[adm5120] rewrite of memory detection code, should be fix #1909
[openwrt.git] / target / linux / at91-2.6 / files / drivers / mtd / at91part.c
1 /*
2 * $Id: at91part.c 6948 2007-04-15 04:01:45Z hcg $
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 * Atmel AT91 flash partition table. (Modified by Hamish Guthrie).
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 static struct mtd_partition at91_parts[6];
34
35 static int create_mtd_partitions(struct mtd_info *master,
36 struct mtd_partition **pparts,
37 unsigned long origin)
38 {
39 unsigned int offset, len;
40 unsigned int pre_size = 0x42000, root_max = 0x362400;
41 unsigned char buf[512];
42 struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
43
44 printk("Parsing AT91 partition map...\n");
45
46 at91_parts[0].name = "loaders";
47 at91_parts[0].offset = 0;
48 at91_parts[0].size = 0x21000;
49 at91_parts[0].mask_flags = MTD_WRITEABLE;
50
51 at91_parts[1].name = "ubparams";
52 at91_parts[1].offset = 0x21000;
53 at91_parts[1].size = 0x8400;
54 at91_parts[1].mask_flags = 0;
55
56 at91_parts[2].name = "kernel";
57 at91_parts[2].offset = pre_size;
58 at91_parts[2].size = 0;
59 at91_parts[2].mask_flags = 0;
60
61 at91_parts[3].name = "rootfs";
62 at91_parts[3].offset = 0;
63 at91_parts[3].size = 0;
64 at91_parts[3].mask_flags = 0;
65
66 for(offset = pre_size; offset < root_max; offset += master->erasesize) {
67
68 memset(&buf, 0xe5, sizeof(buf));
69
70 if (master->read(master, offset, sizeof(buf), &len, buf) || len != sizeof(buf))
71 break;
72
73 if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
74 printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n",
75 master->name, (u32) sb->bytes_used);
76
77 at91_parts[3].size = sb->bytes_used;
78 at91_parts[3].offset = offset;
79 len = at91_parts[3].offset + at91_parts[3].size;
80 len = ((len / (master->erasesize * 8)) + 1) * master->erasesize * 8;
81 at91_parts[3].size = len - at91_parts[3].offset;
82 at91_parts[2].size = offset - at91_parts[2].offset;
83 break;
84 }
85 }
86
87 if (at91_parts[3].size == 0) {
88 printk(KERN_NOTICE "%s: Couldn't find root filesystem\n", master->name);
89 return -1;
90 }
91
92 at91_parts[4].name = "rootfs_data";
93 at91_parts[4].offset = root_max;
94 at91_parts[4].size = master->size - root_max;
95 at91_parts[4].mask_flags = 0;
96
97 at91_parts[5].name = "complete";
98 at91_parts[5].offset = 0;
99 at91_parts[5].size = master->size;
100 at91_parts[5].mask_flags = 0;
101
102 *pparts = at91_parts;
103 return 6;
104 }
105
106 static struct mtd_part_parser at91_parser = {
107 .owner = THIS_MODULE,
108 .parse_fn = create_mtd_partitions,
109 .name = "at91part",
110 };
111
112 static int __init at91_parser_init(void)
113 {
114 return register_mtd_parser(&at91_parser);
115 }
116
117 module_init(at91_parser_init);
118
119 MODULE_LICENSE("GPL");
120 MODULE_AUTHOR("Felix Fietkau, Eugene Konev, Hamish Guthrie");
121 MODULE_DESCRIPTION("MTD partitioning for Atmel at91");
This page took 0.056053 seconds and 5 git commands to generate.