分享

u-boot 从SD卡启动kernel (转)

 WUCANADA 2013-03-28

u-boot 从SD卡启动kernel 相关


转贴1:
Loading your Kernel Image from the SD Reader:Step 1: Initialize the SD reader on your device by issuing the mmc command.MINI2440 # mmc
trying to detect SD Card...
Manufacturer:      0x03, OEM "SD"
Product name:     "SD08G", revision 8.0
Serial number:      4392543921
Manufacturing date: 7/2008
CRC:                       0x6, b0 = 1
READ_BL_LEN=15, C_SIZE_MULT=0, C_SIZE=365
size = 0
SD Card detected RCA: 0xd555 type: SDHC
MINI2440 #Step 2: Load in to ram, the kernel image from the SD card using the fatload command.MINI2440 # fatload mmc 0:1 0x32000000 uImage.bin
reading uImage.binThis loads the file uImage from the mmc (SD) Device 0, on parition 1 in to the ram at memory location 0x32000000 (6 zeros)Step 3: Erase the kernel partition and write the kernel in memory to the kernel partition.MINI2440# nand erase kernel
Erasing.......
MINI2440# nand write.e 0x32000000 kernelThis writes using ecc blocks ( the .e part) the kernel that's located in 0x32000000 to the kernel partition. 
Loading your Root Filesystem Image from the SD Reader:Step 1: Initialize the SD reader as we did in step 1 above.Step 2: Use the fatload command as we did above to load your root filesystem image in to ram.Step 3: Erase the rootfs partition and write the image you loaded in ram, to NAND.MINI2440# nand erase rootfs
MINI2440# nand write.jffs2 0x32000000 rootfs $(filesize)This writes a jffs2 filesystem to the rootfs partition. For this command you need to pass the file size of the image in hex, but fortunately u-boot is some what smart here, and has provided us a variable that contains the file size of the last file transferred to ram. So you just use $(filesize) as the size at the end and it knows what to do.Before you can boot this, you need to set some environment variables in U-Boot.Setting the Environment Variables for bootingStep 1: Set the bootcmd variable to tell U-Boot what type of kernel image you have and what partition its on.MINI2440# setenv bootcmd nboot.e kernel \; bootm
MINI2440# saveenvThis tells u-boot to read the kernel using ecc blocks from the kernel partition and to use bootm as the type of image (uImage) and saves the environment variables.Step 2: Set the bootargs variable to tell u-boot what to pass to the kernel command line.MINI2440# setenv bootargs root=/dev/mtdblock3 rootfstype=jffs2 console=ttySAC0,115200 mini2440=1tb
MINI2440# saveenv
This tells u-boot to tell the kernel that you're booting from mtdblock3 (rootfs partition), your filesystem is jffs2, your console is ttySA0 at 115200 baud, and the last argument tells the kernel what size display you have. 1tb is for the 7" display, and 0tb is for the 3.5" display.Now assuming everything worked as it should, you can reset your board and it should begin booting linux.http://blog./u3/103534/showart_2162101.html

从sd卡启动之文件系统制作

分类: arm 654人阅读 评论(0) 收藏 举报

    在调试andriod的代码时候发现了一个问题。在andriod调试的时候无法进入常规的文件系统进行简单的操作。由于想要把alsa移植到210的开 发板中,发现“/”文件系统是无法进行读写的。在根文件系统下有一个system的目录可以进行读写但是执行命令的时候发现无法操作,顾想到了可读写的文 件系统的移植。因此记录下来这篇文章以便后用,也为了遇到相同问题的开发者提供微薄的帮助。

    1,fdisk的使用。

    2,拷贝文件。

    3,修改内核的编译选项。

    4,修改uboot启动参数。

    5,硬件上的必要准备。

 

    1,fdisk:

    首先要介绍的是fdisk的操作。在omap的开发的时候就遇到了sd卡的制作问题。其实网上很多的介绍。在这里只是针对本次操作的介绍,不涉及的内容网上可以查阅到。

    我的环境是ubuntu10.04的OS。在插上SD卡后会发现dev目录下多了sdb。(如果不确定可以使用dmesg查看kernel的log)。

    fdisk /dev/sdb

    按照提示先把所有的分区信息删除,然后再是使用 p 打印出磁盘信息。保证没有分区。

    再接着为磁盘分区,分区的时候使用的是命令 n。按照提示输入相应的指令 p。

    这里注意分区的大小和容量的信息。default可以选择系统提示默认值,但是第二个参数是要有判断的。我使用的SD卡1G。

    选择如下:

root@edward-laptop:~# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 966 MB, 966787072 bytes
30 heads, 62 sectors/track, 1015 cylinders
Units = cylinders of 1860 * 512 = 952320 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x238e5adc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         200      185969   83  Linux
/dev/sdb2             201         600      372000   83  Linux

 

    以上信息因实际情况而异,可以个人调整。在得到了以上信息后执行命令如下:

    sudo mkfs.ext4 /dev/sdb2 把第二分区的空间格式化为EXT4的文件格式。在这命令以后 mount /dev/sdb2 /mnt 把SD卡的第二分区挂到mnt的目录下。进入mnt目录可以发现多了一个lost+found的文件夹。做过文件系统的都会发现这个是制作文件系统的必备 信息,可以上网查找相关资料。有了这个文件夹也说明formate成功了。

 

    2,拷贝文件

    在这里我有疑问,ext4作为文件系统类型支不支持SD卡类型的设备操作?请高手回答一下这个问题。

    我们之前使用过的任何一种文件系统都是会有基本的目录如:/etc /dev /bin /lib /sbin /proc /usr 等。把这些内容拷贝到挂载完毕后的目录/mnt 或者是任何一种你指定的了文件夹。同步数据后。umount /mnt。拔出SD卡文件系统制作完毕。

 

    3,修改编译选项:

    在上面的文件系统制作的SD时,选用了mkfs。ext4这条指令,顾把SD卡的第二个分区格式化为ext4的文件系统。在kernel的.config 文件中应该把相应的文件系统的支持列表中添加EXT4的支持。

    如下:

..............

#
# File systems
#
CONFIG_EXT2_FS=y
# CONFIG_EXT2_FS_XATTR is not set
# CONFIG_EXT2_FS_XIP is not set
# CONFIG_EXT3_FS is not set
CONFIG_EXT4_FS=y
CONFIG_EXT4_USE_FOR_EXT23=y
# CONFIG_EXT4_FS_XATTR is not set
# CONFIG_EXT4_DEBUG is not set
CONFIG_JBD2=y
# CONFIG_JBD2_DEBUG is not set
# CONFIG_REISERFS_FS is not set
# CONFIG_JFS_FS is not set

...............

 

    4,修改uboot的启动参数

    这个过程相对比较简单,就是一条指令:set bootargs "noinitrd root=/dev/mmcblk0p2 rw console=ttySAC0"。对这条指令介绍一下:

  root指定了文件系统设备的载体:SD卡的第二个分区

  static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)这个函数中可以看到sprintf(md->disk->disk_name, "mmcblk%d", devidx);,SD卡的设备是以mmcblkXpX的方式命名。具体的命名规则还没有调试过代码。但是要指定第二分区的设备名为:mmcblk0p2 表示partition。

  

    5,uboot上的必要准备

    这个过程简单但是必要。

    使用tftp命令下载uImage到开发板上:tftp 0x30800000 uImage

    设置好了以上参数bootargs后执行:bootm 30800000

    最后启动开发板。可以挂载SD卡上的文件系统,并且以这个文件系统作为根文件启动。这时候犹豫是EXT4的文件系统,可以读写保存数据。


转贴2:
uboot从usb(fat)分区加载内核
agou 发表于 2009-12-12 16:29:00 第一步:
内核的支持。修改linux source中的.config文件。
CONFIG_CMDLINE="console=ttyS0,115200 mem=160m ip=off noinitrd root=8:1 rw rootfstype=ext2 rootdelay=10"
8为sda(即U盘)的主设备号,1为第一个分区,是ext2系统,rootdelay表示延迟10秒加载,原因为usb一般加载比较慢。注意,usb-storage支持要编进内核。

第二步:
U盘的准备。
分 成2个区,第一个分区为ext2格式,用于放rootfs,一般不用vfat,因为vfat不支持特殊文件,这个区比较大。第二个分区为vfat格式,用 于放vmlinux内核文件,供bootloader加载。为什么要用vfat放这个文件,原因在于uboot只支持vfat的usb文件系统。

第三步:
bootloader的设置。 注意,其中 usb 0:2指的是vfat分区,因为vfat在第二个分区。
# setenv bootcmd usb start\; fatload usb 0:2 0x84000000 vmlinux\; bootelf 0x84000000
# saveenv
#reset
http://blog./b/18215/archives/2009/68951.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多