发布时间 : 星期一 文章移植Linux内核到norflash更新完毕开始阅读
开发板上只有Nor Flash,所以为了实现层次文件系统,需要为Linux2.6.20增加Nor Flash MTD驱动支持。其实工作量并不大,因为已经有现成的程序可供参考。
MTD的驱动程序都集中在drivers/mtd里面。我们需要做的,仅仅是在drivers/mtd/maps下增加自己的分区表。因为有参考的代码,所以比较容易。
(1)构建配置选项
首先,根据edb7312.c构建自己的mtd分区表驱动(根据cfi_flagadm.c
这个文件也可以奥,
看情况吧!)。
$cd drivers/mtd/maps/ $cp edb7312.c at91rm9200.c
然后,修改drivers/mtd/maps/Kconfig,增加自己的配置选项。
//拷贝过EDB7312稍作修改即可 config MTD_AT91RM9200
tristate \Flash device mapped on AT91RM9200\ depends on ARM && MTD_CFI help
This enables access to the CFI Flash on the ATMEL AT91RM9200DK board.
If you have such a board, say 'Y' here.
最后,修改Makefile,增加编译项目。 obj-$(CONFIG_MTD_EDB7312) += edb7312.o obj-$(CONFIG_MTD_AT91RM9200) += at91rm9200.o
这样,自己建立的MTD分区表驱动就可以编译进内核了。
(2)修改分区表信息
因为第一步的工作中,at91rm9200.c实际上还是edb7312.c的内容,所以需要根据自己的开发板nor flash的配置做一下修改。
#include
#ifdef CONFIG_MTD_PARTITIONS #include
#define WINDOW_ADDR 0x10000000 /* physical properties of flash */ #define WINDOW_SIZE 0x00800000 /* intel 28F640J3A 8MB */ #define BUSWIDTH 2 /* data bus width 16bits */
/* can be \\\NULL }; */ #define PROBETYPES { \, NULL }
#define MSG_PREFIX \ /* prefix for our printk()'s */ #define MTDID \ /* for mtdparts= partitioning */
static struct mtd_info *mymtd;
struct map_info at91rm9200nor_map = {
.name = \flash on AT91RM9200DK\, .size = WINDOW_SIZE, .bankwidth = BUSWIDTH,
.phys = WINDOW_ADDR, };
#ifdef CONFIG_MTD_PARTITIONS /*
* MTD partitioning stuff */
static struct mtd_partition at91rm9200nor_partitions[5] = {
{
// U-boot 128KB .name = \, .size = 0x20000, .offset = 0 }, {
// uImage 2MB .name = \, .size = 0x200000, .offset = 0x20000 }, {
// RootFS 3MB .name = \, .size = 0x300000, .offset = 0x220000 }, {
// UserFS
.name = \, .size = 0x2C0000, .offset = 0x520000 },
{
// Parameters
.name = \, .size = 0x20000, .offset = 0x7E0000 }, };
static const char *probes[] = { NULL }; #endif
static int mtd_parts_nb = 0;
static struct mtd_partition *mtd_parts = 0;
int __init init_at91rm9200nor(void) {
static const char *rom_probe_types[] = PROBETYPES; const char **type;
const char *part_type = 0;
printk(KERN_NOTICE MSG_PREFIX \at 0xx\\n\, WINDOW_SIZE, WINDOW_ADDR);
at91rm9200nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
if (!at91rm9200nor_map.virt) {
printk(MSG_PREFIX \to ioremap\\n\); return -EIO; }
simple_map_init(&at91rm9200nor_map);
mymtd = 0;
type = rom_probe_types;