2 * $Id: at91part.c 6948 2007-04-15 04:01:45Z hcg $
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 * Atmel AT91 flash partition table. (Modified by Hamish Guthrie).
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>
33 static struct mtd_partition at91_parts
[6];
35 static int create_mtd_partitions(struct mtd_info
*master
,
36 struct mtd_partition
**pparts
,
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
;
44 printk("Parsing AT91 partition map...\n");
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
;
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;
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;
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;
66 for(offset
= pre_size
; offset
< root_max
; offset
+= master
->erasesize
) {
68 memset(&buf
, 0xe5, sizeof(buf
));
70 if (master
->read(master
, offset
, sizeof(buf
), &len
, buf
) || len
!= sizeof(buf
))
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
);
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
;
87 if (at91_parts
[3].size
== 0) {
88 printk(KERN_NOTICE
"%s: Couldn't find root filesystem\n", master
->name
);
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;
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;
102 *pparts
= at91_parts
;
106 static struct mtd_part_parser at91_parser
= {
107 .owner
= THIS_MODULE
,
108 .parse_fn
= create_mtd_partitions
,
112 static int __init
at91_parser_init(void)
114 return register_mtd_parser(&at91_parser
);
117 module_init(at91_parser_init
);
119 MODULE_LICENSE("GPL");
120 MODULE_AUTHOR("Felix Fietkau, Eugene Konev, Hamish Guthrie");
121 MODULE_DESCRIPTION("MTD partitioning for Atmel at91");