📄 s3c44b0_29f160.c
字号:
/*
* Flash memory access on SKQ board
*
* Liu Tao <lt@ncic.ac.cn>
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/config.h>
#include <linux/fs.h>
/*(1) 定义29LF160在系统中的起始地址、大小、总线宽度*/
#define WINDOW_ADDR (0X2000000)
#define WINDOW_SIZE (0x00200000)
#define BUSWIDTH 2
static struct mtd_info *mymtd;
__u8 s3c44b0_read8(struct map_info *map, unsigned long ofs)
{
return __raw_readb(map->map_priv_1 + ofs);
}
__u16 s3c44b0_read16(struct map_info *map, unsigned long ofs)
{
return __raw_readw(map->map_priv_1 + ofs);
}
__u32 s3c44b0_read32(struct map_info *map, unsigned long ofs)
{
return __raw_readl(map->map_priv_1 + ofs);
}
void s3c44b0_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{
memcpy(to, (void *)(map->map_priv_1 + from), len);
}
void s3c44b0_write8(struct map_info *map, __u8 d, unsigned long adr)
{
__raw_writeb(d, map->map_priv_1 + adr);
mb();
}
void s3c44b0_write16(struct map_info *map, __u16 d, unsigned long adr)
{
__raw_writew(d, map->map_priv_1 + adr);
mb();
}
void s3c44b0_write32(struct map_info *map, __u32 d, unsigned long adr)
{
__raw_writel(d, map->map_priv_1 + adr);
mb();
}
void s3c44b0_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
{
memcpy((void *)(map->map_priv_1 + to), from, len);
}
struct map_info s3c44b0_map = {
name: "s3c44b0 flash device",
size: WINDOW_SIZE,
buswidth: BUSWIDTH,
read8: s3c44b0_read8,
read16: s3c44b0_read16,
read32: s3c44b0_read32,
copy_from: s3c44b0_copy_from,
write8: s3c44b0_write8,
write16: s3c44b0_write16,
write32: s3c44b0_write32,
copy_to: s3c44b0_copy_to
};
/*
* MTD 'PARTITIONING' STUFF
*/
/*
(2) 定义SST39VF160分区
典型的内存分区应包括:内核引导区、Linux内核区、应用区。其中内核引导区用来保存内核加载程序,
Linux内核区存放的是经过压缩的uClinux内核,应用区则用来保存用户的数据和应用程序,
该区设为我们要采用的JFFS2文件系统。
*/
static struct mtd_partition s3c44b0_partitions[] = {
{
name: "jffs2 (2048K)",
size: 0x1e0000,
offset: 0x020000
}
};
static struct mtd_info *get_mtd_named(char *name)
{
int i;
struct mtd_info *mtd;
for (i = 0; i < MAX_MTD_DEVICES; i++) {
mtd = get_mtd_device(NULL, i);
if (mtd) {
if (strcmp(mtd->name, name) == 0)
return(mtd);
put_mtd_device(mtd);
}
}
return(NULL);
}
int __init init_s3c44b0(void)
{
struct mtd_info *mtd;
int res;
printk(KERN_NOTICE "s3c44b0 flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
s3c44b0_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
if (!s3c44b0_map.map_priv_1) {
printk("Failed to ioremap\n");
return -EIO;
}
mymtd = do_map_probe("jedec_probe", &s3c44b0_map);
if (mymtd) {
mymtd->module = THIS_MODULE;
res = add_mtd_partitions(mymtd, s3c44b0_partitions,
sizeof(s3c44b0_partitions) /
sizeof(struct mtd_partition));
mtd = get_mtd_named("rootfs");
if (mtd) {
ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
put_mtd_device(mtd);
}
return res;
}
iounmap((void *)s3c44b0_map.map_priv_1);
return -ENXIO;
}
static void __exit cleanup_s3c44b0(void)
{
if (mymtd) {
del_mtd_partitions(mymtd);
map_destroy(mymtd);
}
if (s3c44b0_map.map_priv_1) {
iounmap((void *)s3c44b0_map.map_priv_1);
s3c44b0_map.map_priv_1 = 0;
}
}
module_init(init_s3c44b0);
module_exit(cleanup_s3c44b0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -