HOWTO: Booting from SD card using U-Boot
By Bill » Saturday, January 30 2010, 00:34
Many many people want to know how to boot their Mini2440 or Micro2440 off of an SD card and I'm going to show you how.
For this to work, you'll need to make sure you have U-Boot up and running on your device and that when you have an SD card in the slot, and type mmc, it recognizes your card. If not, you'll need to upgrade your u-boot to the latest. You can follow my directions here to compile and flash u-boot to your device.
I'm using an 8GB SD card. I think they're pretty affordable these days to use 8 and 16GB cards. I don't see any reason to go smaller. But thats up to you. Depending on what you need, 2 and 4 might be ok
SD Card Partition Scheme
For this to work, you'll need to partition your SD card in to 3 partitions.
- Partition 1: Swap Space 512MB
- Partition 2: Boot Partition 20MB
- Partition 3: Root Filesystem - The remainder of the free space
Since your device only has 64MB RAM, having a decent size swap partition is a good idea.
SD Card File Systems
You'll need to create file systems as follows.
- Run mkswap on /dev/mmcblk0p1
- Run mkfs.ext2fs on /dev/mmcblk0p2
- Run mkfs.ext3fs on /dev/mmcblk0p3
Mount partitions 2 and 3 somewhere separate.
Copying uImage and and Untarring the Rootfs to the SD card
Now assuming you've successfully created a uImage kernel, and you've got a tar.gz'd root filesystem created by OpenEmbedded, you're ready for the next step. Otherwise read my entry here on getting started with OpenEmbedded.
In your openembedded build directory, theres a deploy directory called tmp/deploy/glibc/images/mini2440/ which contains your jffs images, targz images and whatever other format you asked openembedded to make in its configuration. Change to that directory now.
Copy whichever uImage you want from the above mentioned directory to where you mounted partition 2 (Your boot partition on the SD card). Rename it to uImage for making this easier.
Now while still in your images directory inside your openembedded build directory, run the following command to untar and ungzip one of the root filesystems to your SD cards ext3 partition (Partition 3)
sparky> $ tar xzvfo xorg-image-rootfs.tar.gz -C /path/to/mounted /sd/card/rootfs/partition
You should now be able to unmount both partitions.
Your SD card is finished and it's time to move on to configuring U-Boot....
Configuring U-Boot to boot the kernel and rootfs from SD Card
These are the bootarg and bootcmd environment variables you need to set on your Mini2440 or Micro2440.
MINI2440# setenv bootcmd mmcinit \; ext2load mmc 0:2 0x31000000 uImage \; bootm 0x31000000 MINI2440# saveenv
What this does is tells U-Boot to first initialize the sd card reader, use the ext2load command to load from SD card 0, Partition 2 (the boot partition) the file uImage and store it at memory location 0x31000000, and then to finally use bootm to boot from memory location 0x31000000.
Now we need to set the bootargs variable.
MINI2440# setenv bootargs console=ttySAC0,115200 mini2440=1tb \ rootfstype=ext3 root=/dev/mmcblk0p3 rw rootwait MINI2440# saveenv
This tells u-boot to pass these options on to the kernel. Most importantly here is that your root device is partition 3 on the SD card, and that your filesystem time is ext3.
UPDATE: Please make sure you've added a rootwait or bootdelay=3 to the end of your bootargs. This allows the kernel to wait for the SD card to become available/visible to the kernel.
Conclusion
That's basically it. I've read where some people needed a bootdelay on the bootargs for the kernel. I've not needed that. I followed my own instructions above and created a bootable system today so I know this works. At least for me. I'm happy to listen to anyone's success stories.
I know these HOWTOs are a bit sloppy, but the commands are all here with a little explanation in plain english as to why you're doing this. I hope it helps. Please let me know of any corrections or if you see me doing anything extremely stupid. I'm still quite new to this.
//Bill Sargent
Questions? comments? Need help? Go to my forum here, and ask.

Comments
I tried that with emdebian but I get tis error mesage:
lib80211: common routines for IEEE802.11 drivers
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c2410-rtc s3c2410-rtc: setting system clock to 2010-05-08 21:49:59 UTC (1273355399)
Root-NFS: No NFS server available, giving up.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "mmcblk0p3" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
1f00 256 mtdblock0 (driver?)
1f01 128 mtdblock1 (driver?)
1f02 5120 mtdblock2 (driver?)
1f03 125568 mtdblock3 (driver?)
1f04 131072 mtdblock4 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
Backtrace:
<c0035270> (dump_backtrace+0x0/0x10c) from <c0399df8> (dump_stack+0x18/0x1c)
<c0399de0> (dump_stack+0x0/0x1c) from <c0399e48> (panic+0x4c/0x134)
<c0399dfc> (panic+0x0/0x134) from <c0008e9c> (mount_block_root+0x178/0x234)
<c0008d24> (mount_block_root+0x0/0x234) from <c0009008> (mount_root+0xb0/0xf4)
<c0008f58> (mount_root+0x0/0xf4) from <c0009144> (prepare_namespace+0xf8/0x190)
<c000904c> (prepare_namespace+0x0/0x190) from <c00084c0> (kernel_init+0xf0/0x124)
<c00083d0> (kernel_init+0x0/0x124) from <c004d1c0> (do_exit+0x0/0x62c)
Do you have any idea?
what xzvfo needs for?
Hello xbyte1024,
I've not used embedian. If it is using a differently configured kernel, it may not be configured for MMC support. If you know how to configure the kernel with embedian, I'd recomment looking at that and compiling it directly into the kernel, and not as a module. You can do that, or obtain a kernel built specifically for this device. I'd recommend that anyway.
Using xzvfo with tar means this...
x - eXtract ...
z - use gZip
v - verbose
f - the input is a file (the tar.gz)
o - overwrite
Type tar --help for more information.
Thanks,
Bill
Thx Bill
I will try oe too according to your blog
I use the kernel described here because it have gpio support:
http://members.cox.net/ebrombaugh1/...
I thought that kernel was distribution free!
Hey xbyte1024,
I'll probably write a new blog entry soon on compiling and configuring a kernel with a crosscompiler for the mini2440 and you'll be able to enable gpio with that. So keep me bookmarked :)
Thanks
Bill
You will remain bookmarked anyway... There is valuable information in here :)
I tried with the kernel and file-system you suggested in http://bill.station51.net/index.php...
(I had done the steps long time ago) and I take the same error message!
I installed the u-boot with the modification to run from RAM. Is it possible ti blame this?
If yes, how can I update it? I fount this but with that warnings I wander if an easier way exists.
If it is not the problem I will do the steps from the beginning to, just to be sure.
Hi, xbyte1024,
No I don't believe it's the problem with the modification. Your bootloader is actually loading the kernel just fine. Could you show me your bootargs?
Thanks,
Bill
At this time i tried this:
bootargs=console=ttySAC0,115200 root="mmc 0:3" rootfstype=ext3 mini2440=1tb
But before that I used yours copy-pasted.
The partitions now is same as yours (except the size, I have 2GB card) and I formated them via gparted. (I didn't understand if you used a specific way to make them)
Thanks
byte
Hi xbyte1024,
The mmc 0:3 won't work as a root device. You can only specify a /dev/ based block device name, or device number in hexadecimal. (Which I dont know how to do it in hex). I would try /dev/mmcblk0p3 ... It really should be that. Are you sure that your filesystem is ext3? After reading that again, it really looks like the filesystem isn't correct. Maybe you should format it to ext2 or or ext4 and try that. I'm not 100% sure at the moment which filesystems are actually built in to the kernel by default anymore. I Don't have a working system at the moment to look. But this looks more now like a filesystem error than a partition problem. I'm suspecting either ext3 isn't built in to the kernel.
My friend it is /dev/mmcblk0p3!
I recompiled openembeded and used mostly your instructions (accept i builded gpe-image ingted of console-image). I used the kernel I mention above (emeb's instructions) and the modifications suggested here http://www.friendlyarm.net/forum/to... by Paul.
The graphic environment activates only to show progress bar for boot and sut-down and I don't know why yet, but the command line works fine. The /sys/class/gpio exist's and I will soon find out if it works.
The weird is when I tried to run emdebian it didn't work with the classic message. I returned to oe and it appeared the kernel panic message again. After a restart it seems to be OK. So my problems could probably ended up sooner if I tried that restart without changes. (just a theory)
thank u for your answers
byte
Bill I have one more question.
As I understand from your writings you must have more than one mini 2440 so you have some experience. did you ever encountered the kernel panic message I mention to my first post?
Now I can boot but I usually need several reset before pass the critical point of the boot proses. If I reboot via linux the problem is the same.
If linux starts it can work for hours without problem. The problem is just the start.
Have you ever encountered something like this?
Do you have any idea what causes it?
Thanks
Byte
Hi xbyte1024,
I have not had that problem, not without specifying the device block name wrong.... I have more than 1 mini2440, but they're identical. I've not been active with the boards in several months because of health reasons. So there could always be things that I'm not aware of that are happening with different compilers and git repositories. It could also be newer boards that have different configurations from what I've used. It's also possible that your board is bad if you've not tried this on another board. But ultimately I suspect it's something really easy that you and I are both overlooking, I just don't know what it is....
There's always the possibility that your SD card isn't Linux compatible... ?? I had trouble with a couple of SD cards that wouldn't work in linux at all.
Bill
Thanks Bill
Tomorrow I will receive a Kingston SD so I will test that possibility.
I will try other changes too. If I find something I will announce it here. Someone will probably need this.
Hello!
I'm having some issues booting from SD card like in this guide, one of my cards work and two don't. The kernel says "Kernel panic - not syncing: VFS Unable to find root fs on unknown-block(2,0)". Before that it says:
s3c-sdi s3c2440-sdi: powered down.
mmc0: error -110 whilst initialising SD card
s3c-sdi s3c2440-sdi: powered down.
It just hangs after the kernel panic. But if I remove the memory card just after the kernel has loaded from the SD, and insert it again after 3-4 seconds, it works just fine! So could this be a problem with the kernel or what? And on one of my cards it works just as it should, but I can't believe that all my other cards are bad in some way... All my cards have the same files and are partitioned in the same way. I have compiled the kernel myself from the git source.
Also, if I first try to boot the board from a "bad" card, and then reset it without the memorycard inserted, it still finds the kernel from ram and I can insert a "bad" card after 3-4 seconds after start, and it will boot fine.
If you have time, could you please upload a working kernel uImage just so I could try if something is wrong with mine?
Hi Stereo_m,
Are all of your SD cards the same brand and size? I have had all kinds of random things happen with different brands. I have 1 good working SD card right now... I don't think it's your kernel screwing up. It's more likely that the card isnt working as it should in the reader. When you write to your sd card, are you unmounting it before you remove it? Also, check the kernel logs on your system that you're writing the SD card with and make sure there are no errors while you're writing to the SD card. You might seem some IO errors in there if the card is starting to go bad, and that could make the filesystem corrupt.
Oh and if you're able to reset the board without a memory card and it still finds the kernel, you're not booting the kernel thats on the SD card at all... you're booting a kernel that is in NAND. When you hit the reset button on the board, it clears the RAM.
Bill
Hello,
Anyone having trouble booting from SD card might want to see my newest entry... I found a little fix for some of the problems people are having with the kernel panicking and not seeing the rootfs.
http://bill.station51.net/index.php...
The corection with the rootwait worked for me.
Geat job!!!