A Novice how to for MCF5249C3

by Sivam Version 1.0.

dBug Monitor

dBUG>

You can download the uClinux kernel to the SDRAM of the MCF5249c3 thro' serial port or thro' Ethernet download.


To download serially enter the command as

dBug> dl image.s19

then to execute the kernel, enter the command as

dBug> go 0x00020000

as soon as u enter the go command , the kernel should start executing and give boot up messages on the PC's Hyperterminal

Instead of getting boot up messages in the hyperterminal, if u are scared with error messages in the dBug prompt like

Illegal Stack type!

User Defined vector #255

PC: FFFFFFFF SR: FFFF [ T.S.M.111 ... XN2VC]

AN: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 FFFFFFF0

00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

FFFFFFFF : DC.W 0XFF00

then it's time to check the dBug firmware's version.

dBug>version

If the version command returns you like this , EVS Firmware v2e.1a.1c or any of the v2 series then we need to upgrade the Firmware with v3 becos V2 series has RAM and Ethernet access bugs.

It took me 24 Hours to figure out there is firmware problem in the board. Thanks to greg for enlightning me on this. The easiest method to upgrade the Firmware is thro' a BDM cable and CF Flash utility.

You can get the CF Flash utility from this site , http://e-www.motorola.com/collateral/CFFLASHER.htm

and you can get the latest firmware from Motorola's site.

Creating MTD/JFFS2 filesystem in MCF5249C3

Get the Latest uClinux distribution from the uClinux site.
To include JFFS2 support in the uClinux for MCF5249C3 board enable the following while doing Make xconfig,
my Config reads like this...

#
# Memory Technology Devices (MTD)
#
CONFIG_MTD=y
CONFIG_MTD_DEBUG=y
CONFIG_MTD_DEBUG_VERBOSE=3
CONFIG_MTD_PARTITIONS=y
CONFIG_MTD_CMDLINE_PARTS=y

#
# User Modules And Translation Layers
#
CONFIG_MTD_CHAR=y
CONFIG_MTD_BLOCK_RO=y

#
# RAM/ROM/Flash chip drivers
#
CONFIG_MTD_CFI=y
CONFIG_MTD_JEDECPROBE=y
CONFIG_MTD_GEN_PROBE=y
CONFIG_MTD_CFI_AMDSTD=y
CONFIG_MTD_RAM=y
CONFIG_MTD_ROM=y

#
# Mapping drivers for chip access
#
CONFIG_MTD_UCLINUX=y

#
# Block devices
#

CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_SIZE=4096
CONFIG_BLK_DEV_BLKMEM=y
CONFIG_AMDFLASH=y
CONFIG_FLASH8MB=y
CONFIG_FLASH16BIT=y
CONFIG_EXTRA_FLASH=y
CONFIG_BLK_STATS=y



and please ensure the Generic uClinux driver for ROM / RAM Support option is selected. Also enable the erase and mkfs.jffs2 under the mtd-utils section in Flash tools.

Now go to the uClinux-dist/linux-2.4.x/drivers/mtd/maps/ directory.

Now take a backup of the file uClinux.c into uClinux_bkp.c as we have choosen the Generic UClinux driver for ROM / RAM option in the Makefile. uClinux.c will be compiled and included in the kernel as Flash Driver. So we will replace this uClinux.c file with our uClinux.c file ( Greg pls forgive me for meddling with u'r file ).


To create our Flash partition i have taken 5407 flash driver as reference and modified for MCF5249C3 and Thanks to Kadionik for his wonderful how to on MTD.

/****************************************************************************/
/*
* Flash memory access on uClinux MCF5249 board uclinux.c
*
/****************************************************************************/
/*
*
* Normal mappings of chips in physical memory
*/
#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>


#define WINDOW_ADDR 0xffe00000 //Flash Starting Address
#define WINDOW_SIZE 0x200000
#define BUSWIDTH 2


static struct mtd_info *mymtd;

__u8 m5249c3_read8(struct map_info *map, unsigned long ofs)
{
return __raw_readb(map->map_priv_1 + ofs);
}

__u16 m5249c3_read16(struct map_info *map, unsigned long ofs)
{
return __raw_readw(map->map_priv_1 + ofs);
}

__u32 m5249c3_read32(struct map_info *map, unsigned long ofs)
{
return __raw_readl(map->map_priv_1 + ofs);
}

void m5249c3_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{
memcpy_fromio(to, map->map_priv_1 + from, len);
}

void m5249c3_write8(struct map_info *map, __u8 d, unsigned long adr)
{
__raw_writeb(d, map->map_priv_1 + adr);
mb();
}

void m5249c3_write16(struct map_info *map, __u16 d, unsigned long adr)
{
__raw_writew(d, map->map_priv_1 + adr);
mb();
}

void m5249c3_write32(struct map_info *map, __u32 d, unsigned long adr)
{
__raw_writel(d, map->map_priv_1 + adr);
mb();
}

void m5249c3_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
{
memcpy_toio(map->map_priv_1 + to, from, len);
}

struct map_info m5249c3_map = {
name: "MCF5249C3 flash device",
size: WINDOW_SIZE,
buswidth: BUSWIDTH,
read8: m5249c3_read8,
read16: m5249c3_read16,
read32: m5249c3_read32,
copy_from: m5249c3_copy_from,
write8: m5249c3_write8,
write16: m5249c3_write16,
write32: m5249c3_write32,
copy_to: m5249c3_copy_to
};

/*
* MTD 'PARTITIONING' STUFF
*/
static struct mtd_partition m5249c3_partitions[] = {

{
name: "Colilo (256K)",
size: 0x40000,
offset: 0x0
},
{
name: "Kernel (1024K)",
size: 0x100000,
offset: 0x40000
},

{
name : "JFFS (768K)",
size : 0xc0000,
offset: 0x140000
}


};

int __init init_m5249c3(void)
{
printk(KERN_NOTICE "m5249c3 flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
m5249c3_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);

if (!m5249c3_map.map_priv_1) {

printk("Failed to ioremap\n");

return -EIO;

}

mymtd = do_map_probe("cfi_probe", &m5249c3_map);

if (mymtd) {
mymtd->module = THIS_MODULE;
mymtd->erasesize = 0x40000;
return add_mtd_partitions(mymtd, m5249c3_partitions,
sizeof(m5249c3_partitions) sizeof(struct mtd_partition));
}

iounmap((void *)m5249c3_map.map_priv_1);
return -ENXIO;
}

static void __exit cleanup_m5249c3(void)
{
if (mymtd) {
del_mtd_partitions(mymtd);
map_destroy(mymtd);
}
if (m5249c3_map.map_priv_1) {
iounmap((void *)m5249c3_map.map_priv_1);
m5249c3_map.map_priv_1 = 0;
}
}

module_init(init_m5249c3);
module_exit(cleanup_m5249c3);




The MTD partition structure is the cue in it. I have created 3 partitions and i have given one for colilo, one for the kernel and the third partition for my data storage. Ofcourse we can create as many partitions as we like. But when we set the size in the mtd_partition structure pls ensure you have given the size with correct sector boundary. The boundary size should be in multiples of u'r sector size else the partition will be mounted as Read only partition.

Now we have created the flash driver. We have to modify the Major numbers for the flash device and Blkmem. Change the Number from default 31 to 30 or any other number and ensure that it should not conflict with any other devices Major number.

linux-2.4.x/drivers/block/blkmem.c and linux-2.4.x/include/linux/major.h u can find out the numbers in these files and can change it.

Now we have done with the driver and major numbers. Now we have to create the actual device nodes.

Go to the Vendors/Motorola/M5249C3/ directory. Open the Makefile and add the Flash partition device nodes like this,

DEVICES = \

mtd0,c,90,0 mtd1,c,90,2 mtd2,c,90,4 \

mtdblock0,b,31,0 mtdblock1,b,31,1 mtdblock2,b,31 \

as i created 3 partitions in my flash, i created 3 device nodes . Based on your number of partitions u can create as many nodes as you want.

That's it. We are ready to have our Jffs2 running on our MCF5249C3 board.

Do the following,

i) make dep
ii) make

Now load the kernel and after getting the shell prompt, mount your flash partition like this,

/>mount -t jffs2 /dev/mtdblock2 /mnt
mtdblock_open

ok

and do a cd to mnt directory.

u can now write files on this partition. when u done with the flash don't forget to unmount the flash.

/>umount /mnt



Colilo + uClinux

Now you will see the Kernel bootup messages in the serial port. Now we are ready with colilo + uClinux + MTD Partition.

Happy Porting !!!!