Thursday, April 09, 2009

mtd partitions in u-boot

With the recent merge of mtdparts patch for beagleboard u-boot

Texas Instruments X-Loader 1.4.2 (Jan 30 2009 - 19:16:17)
Loading u-boot.bin from nand


U-Boot 2009.03-00325-gf75a729 (Apr 09 2009 - 13:36:05)

OMAP3530-GP rev 2, CPU-OPP2 L3-165MHz
OMAP3 Beagle board + LPDDR/NAND
DRAM: 256 MB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Board revision C
Die ID #0a8600030000000004013f780600a00e
OMAP3 beagleboard.org #

you can now do cool things without having to remember the offsets of which partition was where.... (lets say you want to copy the kernel to nand flash)

Step1: setup the partitions

OMAP3 beagleboard.org # mtdparts default

Step 2: erase the nand flash for kernel partition

OMAP3 beagleboard.org # nand erase kernel

NAND erase: device 0 offset 0x280000, size 0x400000
Erasing at 0x660000 -- 100% complete.
OK

Step 3: copy the kernel from RAM to the kernel partition in nand flash:

OMAP3 beagleboard.org # nand write 0x80000000 kernel

NAND write: device 0 offset 0x280000, size 0x400000
4194304 bytes written: OK

and you are done..
lets say you want to copy the kernel from flash back to ram....
OMAP3 beagleboard.org # nand read 0x80000000 kernel

NAND read: device 0 offset 0x280000, size 0x400000
4194304 bytes read: OK


oh and if you want to checkout what are the available partitions, then:
OMAP3 beagleboard.org # mtdparts

device nand0 , # parts = 5
#: name size offset mask_flags
0: x-loader 0x00080000 0x00000000 0
1: u-boot 0x001e0000 0x00080000 0
2: u-boot-env 0x00020000 0x00260000 0
3: kernel 0x00400000 0x00280000 0
4: fs 0x0f980000 0x00680000 0

active partition: nand0,0 - (x-loader) 0x00080000 @ 0x00000000

defaults:
mtdids : nand0=nand
mtdparts: mtdparts=nand:512k(x-loader),1920k(u-boot),128k(u-boot-env),4m(kernel),-(fs)

See http://www.denx.de/wiki/DULG/UBootCmdGroupFlash#UBootCmdFlMtdparts for more info

4 comments:

Rohit said...

Thanks !!! a nice post on rerely explained area.
I've a basic question on mtdparts. I use a mini2440 with 128MB Nand. u-boot once loaded always show 4 partitions: Uboot, env, kernel and root.

I am at loss as to who has provided me with these partitions? Is it the U-boot who is "creating these partitions" ? If so where in source code ?
If you could explain more it'll be great.

Cheers
Rohit

ajaygnsharma said...

Please read this document(section5.9.3.5. mtdparts) on how to create the mtdparts.

http://www.denx.de/wiki/DULG/UBootCmdGroupFlash

Yes the partitions are created in the source code config file.

Cal said...

For my 8148 platform, the mtd partitions are defined in the kernel source tree. For my specific platform, the file is arch/arm/mach-omap2/board-d500.c. Hopefully, you have a similar file (i.e. board-xxx.c).

Cal said...

For my 8148 platform, the mtd partitions are defined in the kernel source tree. For my specific platform, the file is arch/arm/mach-omap2/board-d500.c. Hopefully, you have a similar file (i.e. board-xxx.c).