Difference between revisions of "Linux MTD drivers on CM-X270"

From Compulab Mediawiki
Jump to: navigation, search
(New page: == Linux MTD drivers for NAND flash on CM-X270 == Linux kernel BSP for CM-X270 includes [http://www.linux-mtd.infradead.org/ MTD] support. By default the MTD support neither built-in to ...)
 
m (Linux MTD drivers for NAND flash on CM-X270)
Line 11: Line 11:
 
bear in mind that flash layout of MTD drivers is incompatible with
 
bear in mind that flash layout of MTD drivers is incompatible with
 
CompuLab default NAND flash driver. Therefore, it is impossible to use
 
CompuLab default NAND flash driver. Therefore, it is impossible to use
ARMmon built-in NAND access utilities such as `nand flash format` and
+
ARMmon built-in NAND access utilities such as ''nand flash format'' and
`nand write`. The NAND flash erase and modifications will be supported
+
''nand write''. The NAND flash erase and modifications will be supported
 
only in Linux.
 
only in Linux.
  
Line 64: Line 64:
 
[http://packages.debian.org/stable/utils/mtd-tools mtd-tools] Debian
 
[http://packages.debian.org/stable/utils/mtd-tools mtd-tools] Debian
 
package.
 
package.
 
  
 
== Linux MTD driver for NOR Flash on CM-x270 ==
 
== Linux MTD driver for NOR Flash on CM-x270 ==

Revision as of 14:07, 6 March 2008

Linux MTD drivers for NAND flash on CM-X270

Linux kernel BSP for CM-X270 includes MTD support. By default the MTD support neither built-in to the kernel, nor compiled as module. It is available only inside the patch for mainline source tree. This patch includes low-level device access routines and initialization of MTD subsystem.

If you would like to use MTD drivers to access NAND flash on CM-X270 bear in mind that flash layout of MTD drivers is incompatible with CompuLab default NAND flash driver. Therefore, it is impossible to use ARMmon built-in NAND access utilities such as nand flash format and nand write. The NAND flash erase and modifications will be supported only in Linux.

IMPORTANT


Access to the NAND flash using MTD drivers is possible only from within Linux, so you need to have working file system on a device other than NAND flash before using MTD drivers for the first time.


The following example demonstrates how to compile MTD drivers for NAND flash on CM-X270, as well as character and block MTD devices into the kernel:

<*> Memory Technology Device (MTD) support
[ ]   Debugging
< >   MTD concatenating support
[*]   MTD partitioning support
< >     RedBoot partition table parsing
[ ]     Command line partition table parsing
< >     ARM Firmware Suite partition parsing
User Modules And Translation Layers --->
        <*>   Direct char device access to MTD devices
	<*>   Caching block device access to MTD devices
	< >     Readonly block device access to MTD devices
	< >   FTL (Flash Translation Layer) support
	< >   NFTL (NAND Flash Translation Layer) support
	< >   INFTL (Inverse NAND Flash Translation Layer) support
RAM/ROM/Flash chip drivers  --->
Mapping drivers for chip access  --->
Self-contained MTD device drivers  --->
NAND Flash Device Drivers  --->
        [*] NAND Device Support
	[ ]   Verify NAND page writes
	[ ]   NAND ECC Smart Media byte order
	[ ]   iPAQ H1900 flash
	[ ] DiskOnChip 2000, Millennium and Millennium Plus
	[ ] Support for NAND Flash on Sharp SL Series (C7xx + others)
	[ ] Support for NAND Flash Simulator
	[*] Support for NAND Flash on Compulab cm-x270	
OneNAND Flash Device Drivers  --->

At the beginning we'd recommend compiling all the above drivers as loadable kernel modules and verify they are working properly.

Once the MTD drivers are properly working on your system, you can define the desired partitions on the NAND flash, create JFFS2 images and burn them onto the flash using mtd utilities found either on MTD website or in mtd-tools Debian package.

Linux MTD driver for NOR Flash on CM-x270

The NOR flash present on the CM-X270 modules needs to be ocasionally accessed from withing running Linux. It may include field updates, state monitoring and other things. Here we describe how NOR flash of CM-x270 can be accessed.

WARNING


Writing to the bootloader area of the NOR flash may result with disabled board which should be shipped to CompuLab for reprogramming.


Enabling MTD support for NOR flash

The NOR flashes are readily supported by the MTD layer in Linux kernel. The only thing that has to be done is to properly configure the kernel. The following example demonstrates how to include MTD drivers for CFI flash, as well as character and block devices access layers into the kernel:

<*> Memory Technology Device (MTD) support
[ ]   Debugging
< >   MTD concatenating support
[*]   MTD partitioning support
< >     RedBoot partition table parsing
[ ]     Command line partition table parsing
< >     ARM Firmware Suite partition parsing
User Modules And Translation Layers --->
        <*>   Direct char device access to MTD devices
	<*>   Caching block device access to MTD devices
	< >     Readonly block device access to MTD devices
	< >   FTL (Flash Translation Layer) support
	< >   NFTL (NAND Flash Translation Layer) support
	< >   INFTL (Inverse NAND Flash Translation Layer) support
RAM/ROM/Flash chip drivers  --->
	[*] Detect flash chips by Common Flash Interface (CFI) probe
	[*] Support for AMD/Fujitsu flash chips
Mapping drivers for chip access  --->
	[*] CFI Flash device in physical memory map
	(0x00000000) Physical start address of flash mapping
	(0x400000) Physical length of flash mapping
	(2)   Bank width in octets (NEW)

Options description

  • "MTD partitioning support" allows you to define several partitions on your NOR flash device.
  • "Direct char device access to MTD devices" enables access to your MTD partitions through /dev/mtdX device nodes. User-space utilities such as flash_info, flashcp access flash using these devices.
  • "Caching block device access to MTD devices" enables block accesses to the flash device through /dev/mtdblockX device nodes. It is useful if you plan using such utilities as dd
  • "RAM/ROM/Flash chip drivers" submenu defines what device-specific driver should be used to access the flash. You can enable more than one device-specific driver and system will automatically choose the appropriate one.
  • "Physical start address of flash mapping" - physical address of the NOR flash part you would like to map. On the CM-X2XX board NOR flash base physical address is always 0x0. The part of the NOR flash used to store the kernel starts at 0x40000, and the RAMdisk can be stored at 0x1c0000.
  • "Physical length of flash mapping" - the size of the NOR flash on your board.

User-space access

If you have succeeded with kernel configuration you should see the following messages when booting:

physmap flash device: 800000 at 0
phys_mapped_flash: Found 1 x16 devices at 0x0 in 16-bit bank
Amd/Fujitsu Extended Query Table at 0x0040
number of CFI chips: 1
cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness.

To access the NOR device from Linux you should have the /dev/mtd0 and /dev/mtdblock0 device nodes. If they are not present you should create them:

mknod /dev/mtd0 c 90 0
mknod /dev/mtdblock0 b 31 0

From now on you can read the NOR flash contents using these devices.

Updating Kernel

Kernel updates from within Linux are possible with use of MTD drivers for NOR flash. A command

dd if=/dev/mtdblock0 of=/path/to/kernel/image bs=1024 skip=256 count=1776

reads contents of the kernel area in the NOR flash into the /path/to/kernel/image file. This includes kernel size (4 bytes), the kernel image itself and padding to the end of the block.

To update the Linux kernel in the NOR flash of CM-X270, you should first prepend the zImage file created during kernel build, by it's size. For this purpose, you can use, for example, nor_prefix utility available at Linux - Debian filesystem image. Another option is to use the following script:

#!/usr/bin/perl -w

if ( $#ARGV != 1  ) {
    die "USAGE: <kernel image> <nor image>";
}

$kernel_image = $ARGV[0];
$nor_image = $ARGV[1];

open(NOR, ">", $nor_image) or die "open failed";
open(KERN, "<", $kernel_image) or die "open failed";

binmode(NOR);
binmode(KERN);

$size  = (stat($kernel_image))[7];
print NOR pack('i', $size);

while (read(KERN, $buff, 8 * 2**10)) {
    print NOR $buff;
}

close(NOR);
close(KERN);

Suppose, you've created the NOR image for Linux kernel, and called it image.nor. Than, to store this image into the NOR flash you can use the following command:

dd if=image.nor of=/dev/mtdblock0 bs=1024 seek=256