2 * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
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
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/magic.h>
29 #define FLASH_SIZE 0x800000
30 #define FLASH_PHYS_ADDR 0x10000000
32 /* just interested in part of the full struct */
33 struct squashfs_super_block
{
35 __le32 pad0
[9]; /* it's not really padding */
39 static struct mtd_info
*mymtd
;
41 static struct map_info nor_map
= {
44 phys
: FLASH_PHYS_ADDR
,
48 static struct mtd_partition nor_parts
[] = {
49 { name
: "linux", offset
: 0x40000, size
: FLASH_SIZE
- 0x40000, },
50 { name
: "rootfs", offset
: 0x200000, size
: 0x400000, },
54 int __init
init_mtd_partitions(struct mtd_info
*mtd
, size_t size
)
58 struct squashfs_super_block hdr
;
60 blocksize
= mtd
->erasesize
;
61 if (blocksize
< 0x10000)
64 memset(&hdr
, 0xe5, sizeof(hdr
));
65 /* find and size squashfs */
66 for (off
= (128*1024); off
< size
; off
+= blocksize
) {
67 if (mtd
->read(mtd
, off
, sizeof(hdr
), &len
, (char *)&hdr
) ||
71 if (hdr
.s_magic
== SQUASHFS_MAGIC
) {
72 printk(KERN_INFO
"%s: Filesystem type: squashfs, off=%#x size=%#x\n",
73 mtd
->name
, off
, (unsigned int)hdr
.bytes_used
);
74 /* Update the squashfs start address only! */
75 nor_parts
[1].offset
= off
;
76 nor_parts
[1].size
= FLASH_SIZE
- off
;
83 int __init
init_nor(void)
87 printk(KERN_NOTICE
"ADM8668 NOR flash device: %#x at %#x\n",
88 FLASH_SIZE
, FLASH_PHYS_ADDR
);
90 nor_map
.virt
= ioremap(FLASH_PHYS_ADDR
, FLASH_SIZE
);
92 printk("Failed to ioremap\n");
96 simple_map_init(&nor_map
);
97 mymtd
= do_map_probe("cfi_probe", &nor_map
);
99 iounmap((void *)nor_map
.virt
);
102 mymtd
->owner
= THIS_MODULE
;
103 nr_parts
= init_mtd_partitions(mymtd
, mymtd
->size
);
104 add_mtd_partitions(mymtd
, nor_parts
, nr_parts
);
109 static void __exit
cleanup_nor(void)
112 del_mtd_partitions(mymtd
);
116 iounmap((void *)nor_map
.virt
);
121 module_init(init_nor
);
122 module_exit(cleanup_nor
);
124 MODULE_LICENSE("GPL");
125 MODULE_AUTHOR("Scott Nicholas <neutronscott@scottn.us>");
126 MODULE_DESCRIPTION("MTD map driver for ADM8668 NOR Flash");
This page took 0.050146 seconds and 5 git commands to generate.