Primeiramente deve-se criar o driver para a flash a ser utilizada, crie o arquivo driver/mtd/maps/m5282lite.c:
/*
* drivers/mtd/maps/m5282lite.c
*
* Flash map driver for the M5282Lite board
*
* $Id: m5282lite.c,v 1.5 2004/11/04 13:24:14 gleixner Exp $
*
* Copyright 2003-2004, UFRGS
*
* Based on the SVME181 flash map, by Tom Nelson, Dot4, Inc. for TimeSys Corp.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.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/errno.h>
/*
* This driver currently handles only the 2MiB user flash bank 0 on the
* board.
*/
#define FLASH_BASE_ADDR 0xFFE00000 /* 2 MiB */
#define FLASH_BANK_SIZE 0x00200000
MODULE_AUTHOR(“Alan Carvalho de Assis, UFRGS <acassis@inf.ufrgs.br>”);
MODULE_DESCRIPTION(“User-programmable flash device on the M5282Lite board “);
MODULE_LICENSE(“GPL”);
static struct map_info m5282lite_map = {
.name = “M5282Lite”,
.bankwidth = 2,
.size = 0x00200000
};
static struct mtd_partition m5282lite_partitions[] = {
/* Bank 0 */
{
.name = “dbug”, /* dBUG Firmware */
.offset = 0,
.size = 0x00040000, /* 256 KiB */
.mask_flags = MTD_WRITEABLE, /* force read-only */
},
{
.name = “kernel”, /* kernel partition */
.offset = 0x00040000,
.size = 0x000C0000, /* 768 KiB sector */
},
{
.name = “filesystem”, /* filesystem partition */
.offset = 0x00100000,
.size = 0x00100000, /* 1 MiB sector */
}
};
static struct mtd_info *this_mtd;
static int __init init_m5282lite(void)
{
struct mtd_partition *partitions;
int num_parts = sizeof(m5282lite_partitions) / sizeof(struct mtd_partition);
partitions = m5282lite_partitions;
m5282lite_map.virt = ioremap(FLASH_BASE_ADDR, m5282lite_map.size);
if (m5282lite_map.virt == 0) {
printk(KERN_NOTICE “Failed to ioremap FLASH memory area.\n”);
return -EIO;
}
simple_map_init(&m5282lite_map);
this_mtd = do_map_probe(“jedec_probe”, &m5282lite_map);
if (!this_mtd)
{
printk(KERN_NOTICE “M5282Lite error, can’t map”);
iounmap((void *)m5282lite_map.virt);
return -ENXIO;
}
printk(KERN_NOTICE “M5282Lite flash device: %dMiB at 0x%08x\n”,
this_mtd->size >> 20, FLASH_BASE_ADDR);
this_mtd->owner = THIS_MODULE;
add_mtd_partitions(this_mtd, partitions, num_parts);
return 0;
}
static void __exit cleanup_m5282lite(void)
{
if (this_mtd)
{
del_mtd_partitions(this_mtd);
map_destroy(this_mtd);
}
if (m5282lite_map.virt)
{
iounmap((void *)m5282lite_map.virt);
m5282lite_map.virt = 0;
}
return;
}
module_init(init_m5282lite);
module_exit(cleanup_m5282lite);
Agora acrescente a entrada no driver/mtd/maps/Makefile:
obj-$(CONFIG_MTD_M5282LITE) += m5282lite.o
Compile o uClinux com as seguintes opções ativadas:
CONFIG_MTD=y
CONFIG_MTD_PARTITIONS=y
CONFIG_MTD_CHAR=y
CONFIG_MTD_BLOCK=y
CONFIG_MTD_CFI=y
CONFIG_MTD_JEDECPROBE=y
CONFIG_MTD_GEN_PROBE=y
CONFIG_MTD_MAP_BANK_WIDTH_1=y
CONFIG_MTD_MAP_BANK_WIDTH_2=y
CONFIG_MTD_MAP_BANK_WIDTH_4=y
CONFIG_MTD_CFI_I1=y
CONFIG_MTD_CFI_I2=y
CONFIG_MTD_CFI_AMDSTD=y
CONFIG_MTD_CFI_AMDSTD_RETRY=0
CONFIG_MTD_CFI_STAA=y
CONFIG_MTD_CFI_UTIL=y
CONFIG_MTD_M5282LITE=y
Em Kernel hacking, ative Compiled-in Kernel Boot Parameter e acrescente:
root=/dev/mtdblock2
Onde /dev/mtdblock2 é a partição[2] (a nossa “filesystem”). Talvez você queira montar a partição ROMfs que é criada na RAM, para pode entrar no uClinux formatar a mtdblock2. Neste caso acrescente “root=/dev/mtdblock3 rootfstype=romfs” para que o kernel monte esta partição como romfs, do contrário ele tentará montar como jffs2
Entre no diretório romfs/dev e crie os arquivos especial reais:
# for i in $(ls); do a=$(echo $i | tr “@,” ” “); mknod $a; done
Apaque os arquivos usados para gerar os arquivos especiais
# rm @*
Retorne ao diretório uClinux-dist e crie a imagem jffs2:
# mkfs.jffs2 -b -d romfs -o /tftpboot/rootfs.img
Baixar a imagem para o dBUG:
dBUG> dn -i rootfs.img
Gravar a imagem na memória flash (partição filesystem):
dBUG> fl w fff00000 10000 a6408
Onde:
* fff00000 é o endereço da flash onde será gravado;
* 10000 é o endereço da RAM onde imagem foi descarregada;
* a6408 é o tamanho da imagem convertido em hexadecimal.