Saturday, November 24, 2012

Understanding Disk Partition in Flash For Embedded Linux System

Understanding Disk Partition in Flash For Embedded Linux System

by cawan (cawan[at]ieee.org or chuiyewleong[at]hotmail.com)

on 25/11/2012

Flash chip is divided in blocks. So, the block number is equivalent to page frame
number of RAM. However, due to the physical characteristic of flash chip, it is
really not easy to operate the flash in term of block number. In addition, there
are variety of flash technology, nand flash, nor flash, slc, mlc..., and they have
quite different physical characteristic among each others. In embedded system design,
the physical access of specific flash chip is usually managed by respective device
driver, which is normally known as MTD driver. So, the MTD driver will treat the
flash in block level, and the rest in higher level will treat the flash in logical
address level. In other words, the MTD driver will perform mapping of logical address
to the appropriate block number of the flash. Therefore, those incontinuous blocks
in flash can be mapped into a series of continuous logical addresses in high level.
Well, it is something similar to the flat model of memory management with MMU support.
So, we know that linux kernel will talk to flash chip by using logical address right
now. Hence, in order to create partition, it is just about to define the partition
info somewhere in the flash and allows global access. For most of the cases in
embedded system, the first few blocks of the flash are normally the candidates to
store global environment variables, including the partition info. Besides, it is
important to note that block 0 is usually reserved for bootloader. Sometimes, the
global environment variables are just simply coexist with bootloader in block 0.
So, the question right now is how to manipulate the global environment variables,
let's say how we can define new partition ? The answer is simple, it is bootloader.
As what we know, most of the bootloader supports a configuration interface to let
user to perform certain operations to the hardware such as to format the flash chip
or to verify the checksum of a range of memory. Of course, it is available to define
partition by manipulating the appropriate global environment variable. For each
partition, it just needs to define the start address and length of the partition in
flash, yes, that's it. Let's show an example in MIPS platform.

(0x00)    4 l.cs0_size 0x08000000
(0x00)    4 l.cs0_parts 0x00000007
(0x00)    4 l.cs0_part1_offset 0x00000000
(0x00)    4 l.cs0_part1_size 0x00080000
(0x00)    4 l.cs0_part2_offset 0x00080000
(0x00)    4 l.cs0_part2_size 0x00040000
(0x00)    4 l.cs0_part3_offset 0x000c0000
(0x00)    4 l.cs0_part3_size 0x00740000
(0x00)    4 l.cs0_part4_offset 0x00800000
(0x00)    4 l.cs0_part4_size 0x01000000
(0x00)    4 l.cs0_part5_offset 0x01800000
(0x00)    4 l.cs0_part5_size 0x00800000
(0x00)    4 l.cs0_part6_offset 0x02000000
(0x00)    4 l.cs0_part6_size 0x03200000
(0x00)    4 l.cs0_part7_offset 0x05200000
(0x00)    4 l.cs0_part7_size 0x00200000
(0x00)    4 l.cs0_part8_offset 0x05400000
(0x00)    4 l.cs0_part8_size 0x03200000
(0x00)    4 l.cs0_part9_offset 0x08600000
(0x00)    4 l.cs0_part9_size 0x03200000

Well, the flash chip is at chip select 0 (cs0), and its size is 128 MB (0x08000000).
Besides, there are 7 system partitions as defined in (l.cs0_parts). For each of the
system partition, the offset and size are clearly defined. In addition, there are
2 user partitions are defined as cs0_part8 and cs0_part9, with respective offset and
size individually. With such info in global environment variables, it is just a
simple job to implement a kernel module in linux to create block devices for
partitions. Of course it is just dealing with logical address, and the MTD driver
will do the rest of the jobs for us. So, once the partition are represented in block
device, then any ramdisk image file can be duplicated onto it and make ready to be
mounted by the system for general operation. Regarding how to create ramdisk image
file and duplicate it onto a partition, please refer my previous paper in this blog,
"How To Create A Ramdisk File and Make Use in Embedded System ?".

pdf version:

http://www.scribd.com/doc/114285765/Understanding-Disk-Partition-in-Flash-for-Embedded-Linux-System

No comments:

Post a Comment