SEARCH
TOOLBOX
LANGUAGES
modified on 9 February 2012 at 21:15 ••• 144,126 views

Boot from SD/MMC

From Manuals

(Difference between revisions)
Jump to: navigation, search
(To boot Kernel and Rootfs from SD/MMC card (Without NAND))
(Creating a Bootable Filesystem on microSD card using a Windows PC)
 
(28 intermediate revisions not shown)
Line 1: Line 1:
__TOC__
__TOC__
=Boot from SD/MMC=
=Boot from SD/MMC=
 +
This procedure explains how to boot a kernel image and root filesystem from a microSD card. Booting from a microSD card gives applications a wide range of options including portability, multiple distributions, larger storage space, etc. The microSD card has lower disk I/O performance than NAND, but the difference is not significant for embedded applications that perform most operations in RAM. A NAND is not required when booting from a microSD card if the kernel is included with the root filesystem.
-
==To boot Kernel and Rootfs from SD/MMC card (Without NAND)==
+
Note: The EXT2 filesystem does not implement journaling. Proper shutdown procedures should be followed.
-
1) Download u-boot-2010.03. (Its recommended that load can be built before going further)
+
-
 
+
-
2) Copy board/micromint folder and /include/configs/electrum100.h from u-boot-2009.08.
+
-
 
+
-
3) Add the following Configurations to enable MMC support.
+
   
   
-
#define CONFIG_CMD_EXT2 1
+
==Creating a Bootable Filesystem on microSD card using a Linux PC==
-
#define CONFIG_CMD_FAT 1
+
1) Partition the microSD card and create a filesystem on the first partition. Generally this is done on a Linux PC. Insert the microSD card and enter the following commands:
-
#define CONFIG_MMC 1
+
-
#define CONFIG_GENERIC_MMC 1
+
-
#define CONFIG_CMD_MMC 1
+
-
#define CONFIG_GENERIC_ATMEL_MCI 1
+
-
#define MMCI_BASE 0xFFFA8000
+
-
4) Then create an init routine in your platform code:
+
   
   
-
  /* this is a weak define that we are overriding */
+
  $ fdisk /dev/mmcblk0
-
#ifdef CONFIG_GENERIC_ATMEL_MCI
+
-
int board_mmc_init(bd_t *bd)
+
-
{
+
-
at91_mci0_hw_init((1 << 0) || (1 << 1));
+
-
/* This calls the atmel_mmc_init in gen_atmel_mci.c */
+
-
        return atmel_mmc_init(bd);
+
-
}
+
-
#endif
+
-
5) Change line 86 of uboot*/cpu/arm926ejs/at91/at91sam9260_devices.c to
+
-
 
+
-
#if defined(CONFIG_ATMEL_MCI) || defined(CONFIG_GENERIC_ATMEL_MCI)
+
-
6) Apply the following patch: http://www.mail-archive.com/u-boot@lists.denx.de/msg31713.html
+
-
 
+
-
7) Build the u-boot-2010.03
+
-
 
+
-
$make bootloader
+
-
8) Update the Boot strapper and Boot-loader into Electrum100 using SAM-BA application
+
-
 
+
-
9) Execute the command:
+
   
   
-
  Electrum>> mmc list
+
  Command (m for help): o                          # create a new partition table
-
Electrum>> mmc rescan 0
+
Building a new DOS disklabel with disk identifier 0xc57e78f0.
-
 
+
Changes will remain in memory only, until you decide to write them.
-
10) Now copy the Kernel Image and rootfs into SD card (Refer the section: Creating a Bootable filesystem on SD card).
+
After that, of course, the previous content won't be recoverable.
-
 
+
-
11) Check the card using "mmc rescan 0" command
+
-
 
+
-
12) change the boot args to load root file system from SD card.
+
   
   
-
  bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.231:192.168.1.249::255.255.255.0::eth0:none
+
  Command (m for help): n                          # create a new partition
-
13) To load the Kernel from EXT2 change the boot commands
+
Command action
 +
    e  extended
 +
    p  primary partition (1-4)
 +
p                                                # select primary partition
 +
Partition number (1-4): 1                        # select first partition (default)
 +
First cylinder (1-1203, default 1):             # select first cylinder (default)
 +
Using default value 1
 +
Last cylinder, +cylinders or +size{K,M,G} (1-1203, default 1203):  
 +
                                                  # select last cylinder (default)
 +
Using default value 1203
 +
 +
Command (m for help): a                          # set boot blag
 +
Partition number (1-4): 1                        # for first partition
 +
 +
Command (m for help): w                          # write changes
 +
The partition table has been altered!
 +
 +
Calling ioctl() to re-read partition table.
 +
Syncing disks.
 
 
-
  Electrum>> setenv bootcmd mmcinfo\; ext2load mmc 0:1 0x22000000 uImage-2.6.31.9\; bootm
+
  $ mkfs -t ext2  /dev/mmcblk0p1
-
  Electrum>> saveenv
+
  $ mkdir /mnt/sdcard
-
  Electrum>> reset
+
  $ mount /dev/mmcblk0p1 /mnt/sdcard
-
==Creating a Bootable Filesystem on SD card==
+
2) Copy the desired root filesystem to the microSD card. The filesystem should contain a kernel (e.g. uImage-2.6.33.20-1-at91) in the top directory and the corresponding modules directory in /lib/modules. The command below assumes the root filesystem is in the /home/electrum/rootfs/ directory of your Linux PC. On most Linux distributions you need to be running as root to copy device (/dev) nodes. This copy may take several minutes depending on the filesystem contents and the speed (class) of your card.
-
1) The first step is to make a bootable file system on the SD card. Insert the card into the slot of a running plug. Enter the following commands:
+
   
   
-
  >fdisk /dev/mmcblk0
+
  # cp -pr /home/electrum/rootfs/* /mnt/sdcard
-
press "o"  / create a new partition table
+
 
-
press "n"  / create a new partition
+
3) The microSD card should now contain your root filesystem. Confirm the disk usage with the df command prior to unmounting.  
-
press "p"  / it's a primary partition
+
-
press "1"  / partition #1
+
-
press enter / default first cylinder
+
-
press enter / default last cylinder
+
-
press "a"  / set the boot flag
+
-
press "1" / ... for partition #1
+
-
press "w" / save changes
+
-
+
-
>mkfs -t ext2  /dev/mmcblk0p1
+
-
>mkdir /mnt/sdcard
+
-
>mount /dev/mmcblk0p1 /mnt/sdcard
+
-
>df
+
-
2) Now copy your existing nand file system onto the sd card. This may take 5-10 minutes.
+
-
+
-
root#: cp -r /rootfs/* /mnt/sdcard
+
-
3) The SD card should now mirror your internal nand flash, which you can confirm with df -h, etc.  
+
   
   
 +
$ df
  Filesystem          1K-blocks      Used Available Use% Mounted on
  Filesystem          1K-blocks      Used Available Use% Mounted on
-
  rootfs                  519168    185612    333556  36% /
+
  ...
-
tmpfs                  257816        0    257816  0% /lib/init/rw
+
-
varrun                  257816      260    257556  1% /var/run
+
-
varlock                257816        0    257816  0% /var/lock
+
-
udev                    257816        12    257804  1% /dev
+
-
tmpfs                  257816        0    257816  0% /dev/shm
+
-
tmpfs                  257816    21824    235992  9% /var/cache/apt
+
  /dev/mmcblk0p1        7707056    516216  6799340  8% /mnt/sdcard
  /dev/mmcblk0p1        7707056    516216  6799340  8% /mnt/sdcard
 +
$ umount /mnt/sdcard
-
your SD card now has a bootable system. The next step is to boot it.
+
Your microSD card now has a bootable system. The next step is to change the bootloader configuration to boot from it instead of NAND.
-
==Booting from the SD Card==
+
 
-
You need to interact with u-boot now. You must do this from a program talking to the usb-serial port, not from an ssh shell (duh).  
+
==Creating a Bootable Filesystem on microSD card using a Windows PC==
 +
1) Download the [http://www.micromint.com/updates/electrum/win32diskimager-binary.zip win32diskimager-binary.zip] file.
 +
 
 +
2) Download the [http://www.micromint.com/updates/electrum/SD_Card_Linux_Kernel_File_System_Image.zip latest Linux and file system image file].
 +
 
 +
3) Unzip the files into a single directory.
 +
 
 +
4) Insert the microSD card into a USB to SD card adapter. Note: win32diskimager does not function well with card readers built into PCs.
 +
 
 +
5) Open the Win32DiskImager application.
 +
 
 +
6) If Windows asks allow the Win32DiskImager application to run.
 +
 
 +
7) Browse for the desired image file in the directory where it was unzipped.
 +
 
 +
8) Make sure the correct drive is selected.
 +
 
 +
9) Click on the "Write" button.
 +
 
 +
==Booting from the microSD Card==
 +
1) Enter the U-boot console via the serial console port (COM1) to change the bootloader configuration you need to . If the board is up, reboot using
   
   
-
  >shutdown -r now
+
  # shutdown -r now
-
When u-boot appears, stop it by typing ENTER a few times, to stop it from booting automatically.
+
When the U-Boot messages appear on the console, stop the automatic boot by pressing SPACE twice.
 +
 
 +
2) Insert the microSD card and confirm it is accessible using the rescan command.
 +
 
 +
Electrum> mmc rescan 0
 +
 
 +
3)  Change the bootargs and bootcmd parameters. List the current values in case you need to restore them. Use the kernel version loaded in your card (uImage-2.6.33.20-1-at91 in the example).
 +
Electrum> printenv bootargs
 +
bootargs=console=ttyS0,115200 root=/dev/mtdblock6 mtdparts=atmel_nand:256k(bootstrap)ro,256k(uboot)ro,256k(env1),
 +
256k(env2),1024k(user),2M(linux),-(root) rw rootfstype=jffs2
   
   
-
  Electrum>> printenv bootargs
+
  Electrum> setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.231:192.168.1.249::255.255.255.0::
-
bootargs console=ttyS0,115200 root=/dev/nfs rw ip=192.168.1.231:192.168.1.249::255.255.255.0::
+
-
eth0: nfsroot=192.168.1.249:/media/disk/rootfs
+
-
This is the line that you'll need to change. Change it to
+
-
+
-
Electrum>> setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.231:192.168.1.249::255.255.255.0::
+
  eth0:none
  eth0:none
-
  Electrum>> printenv bootargs (if you like, just to confirm that you did it right)
+
 +
  Electrum> printenv bootcmd
 +
bootcmd=nand read 0x22000000 0x200000 0x200000; bootm
 +
 +
Electrum> setenv bootcmd mmcinfo\; ext2load mmc 0:1 0x22000000 uImage-2.6.33.20-1-at91\; bootm
 +
 +
4) Save the bootloader environment and boot the board.
 +
 
 +
Electrum>> saveenv
  Electrum>> boot
  Electrum>> boot

Current revision as of 21:15, 9 February 2012

Contents

Boot from SD/MMC

This procedure explains how to boot a kernel image and root filesystem from a microSD card. Booting from a microSD card gives applications a wide range of options including portability, multiple distributions, larger storage space, etc. The microSD card has lower disk I/O performance than NAND, but the difference is not significant for embedded applications that perform most operations in RAM. A NAND is not required when booting from a microSD card if the kernel is included with the root filesystem.

Note: The EXT2 filesystem does not implement journaling. Proper shutdown procedures should be followed.

Creating a Bootable Filesystem on microSD card using a Linux PC

1) Partition the microSD card and create a filesystem on the first partition. Generally this is done on a Linux PC. Insert the microSD card and enter the following commands:

$ fdisk /dev/mmcblk0

Command (m for help): o                          # create a new partition table
Building a new DOS disklabel with disk identifier 0xc57e78f0.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Command (m for help): n                          # create a new partition
Command action
   e   extended
   p   primary partition (1-4)
p                                                # select primary partition
Partition number (1-4): 1                        # select first partition (default)
First cylinder (1-1203, default 1):              # select first cylinder (default)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1203, default 1203): 
                                                 # select last cylinder (default)
Using default value 1203

Command (m for help): a                          # set boot blag
Partition number (1-4): 1                        # for first partition

Command (m for help): w                          # write changes
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
	
$ mkfs -t ext2  /dev/mmcblk0p1
$ mkdir /mnt/sdcard
$ mount /dev/mmcblk0p1 /mnt/sdcard

2) Copy the desired root filesystem to the microSD card. The filesystem should contain a kernel (e.g. uImage-2.6.33.20-1-at91) in the top directory and the corresponding modules directory in /lib/modules. The command below assumes the root filesystem is in the /home/electrum/rootfs/ directory of your Linux PC. On most Linux distributions you need to be running as root to copy device (/dev) nodes. This copy may take several minutes depending on the filesystem contents and the speed (class) of your card.

# cp -pr /home/electrum/rootfs/* /mnt/sdcard

3) The microSD card should now contain your root filesystem. Confirm the disk usage with the df command prior to unmounting.

$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
...
/dev/mmcblk0p1         7707056    516216   6799340   8% /mnt/sdcard
$ umount /mnt/sdcard

Your microSD card now has a bootable system. The next step is to change the bootloader configuration to boot from it instead of NAND.

Creating a Bootable Filesystem on microSD card using a Windows PC

1) Download the win32diskimager-binary.zip file.

2) Download the latest Linux and file system image file.

3) Unzip the files into a single directory.

4) Insert the microSD card into a USB to SD card adapter. Note: win32diskimager does not function well with card readers built into PCs.

5) Open the Win32DiskImager application.

6) If Windows asks allow the Win32DiskImager application to run.

7) Browse for the desired image file in the directory where it was unzipped.

8) Make sure the correct drive is selected.

9) Click on the "Write" button.

Booting from the microSD Card

1) Enter the U-boot console via the serial console port (COM1) to change the bootloader configuration you need to . If the board is up, reboot using

# shutdown -r now

When the U-Boot messages appear on the console, stop the automatic boot by pressing SPACE twice.

2) Insert the microSD card and confirm it is accessible using the rescan command.

Electrum> mmc rescan 0

3) Change the bootargs and bootcmd parameters. List the current values in case you need to restore them. Use the kernel version loaded in your card (uImage-2.6.33.20-1-at91 in the example).

Electrum> printenv bootargs
bootargs=console=ttyS0,115200 root=/dev/mtdblock6 mtdparts=atmel_nand:256k(bootstrap)ro,256k(uboot)ro,256k(env1),
256k(env2),1024k(user),2M(linux),-(root) rw rootfstype=jffs2

Electrum> setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.231:192.168.1.249::255.255.255.0::
eth0:none

Electrum> printenv bootcmd
bootcmd=nand read 0x22000000 0x200000 0x200000; bootm

Electrum> setenv bootcmd mmcinfo\; ext2load mmc 0:1 0x22000000 uImage-2.6.33.20-1-at91\; bootm

4) Save the bootloader environment and boot the board.

Electrum>> saveenv
Electrum>> boot