常用 U-boot命令详解

发布者:Jinyu521最新更新时间:2024-08-30 来源: cnblogs关键字:U-boot命令  shell 手机看文章 扫描二维码
随时随地手机看文章
[u-boot@MINI2440]# tftpboot 30008000 192.168.1.100:u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'u-boot.bin'.
Load address: 0x30008000
Loading: T ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# nand erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x2000000000004 --
0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0 0x40000

NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK


4) 通过NFS 服务烧入Nand Flash:

[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/u-boot.bin'.
Load address: 0x30008000
Loading: ###################################################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# nand erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x2000000000004 --
0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0 0x40000

NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK



内核引导

内核的引导步骤如下:
(1)用U-boot的mkimage工具处理内核映像zImage。
(2)通过网络、串口、U盘、SD卡等方式将处理过的内核映像传输到SDRAM的一定位置(一般使用0x30008000)
(3)然后使用”bootm'等内核引导命令来启动内核。

为什么要用U-boot的mkimage工具处理内核映像zImage?
因为在用bootm命令引导内核的时候,bootm需要读取一个64字节的文件头,来获取这个内核映象所针对的CPU体系结构、OS、加载到内存中的位置、在内存中入口点的位置以及映象名等等信息。这样bootm才能为OS设置好启动环境,并跳入内核映象的入口点。而mkimage就是添加这个文件头的专用工具。具体的实现请看U-boot中bootm的源码和mkimage的源码。
mkimage工具的使用:

参数说明:
-A指定CPU的体系结构,可用值有:alpha、arm
、x86、ia64、mips、mips64、ppc 、s390、sh、sparc 、sparc64、m68k等
-O指定操作系统类型,可用值有:openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos
-T指定映象类型,可用值有:standalone、kernel、ramdisk、multi、firmware、script、filesystem
-C指定映象压缩方式,可用值有:
none
不压缩(一般使用这个,因为zImage是已经被bzip2压缩过的自解压内核)
gzip 用gzip的压缩方式
bzip2 用bzip2的压缩方式
-a指定映象在内存中的加载地址,映象下载到内存中时,要按照用mkimage制作映象时,这个参数所指定的地址值来下载
-e
指定映象运行的入口点地址,这个地址就是-a参数指定的值加上0x40(因为前面有个mkimage添加的0x40个字节的头)
-n
指定映象名
-d指定制作映象的源文件

以下是制作内核映像的命令示例:
mkimage -n 'tekkaman' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img



以下是使用范例:
1) 通过SD卡引导内核:
首先SD卡中必须有FAT32文件系统,并在里面存放了处理过的内核映像文件。

[u-boot@MINI2440]# mmc init


mmc: Probing for SDHC ...
mmc: SD 2.0 or later card found
trying to detect SD Card...
Manufacturer:
0x00, OEM 'roduct name:
'
', revision 0.0
Serial number:
7864775
Manufacturing date: 11/2006
CRC:
0x4f, b0 = 1
READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095
size = 0
SD Card detected RCA: 0x2 type: SD
mmc1 is available
[u-boot@MINI2440]# fatload mmc 1 30008000 zImage.img
reading zImage.img

2277540 bytes read
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...

Image Name:
tekkaman

Created:
2010-03-29
12:59:51 UTC

Image Type:
ARM Linux Kernel Image (uncompressed)

Data Size:
2277476 Bytes =
2.2 MB

Load Address: 30008000

Entry Point:
30008040

Verifying Checksum ... OK

XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
(略)



2) 通过TFTP服务引导内核:

[u-boot@MINI2440]# tftpboot 0x30008000 192.168.1.100:zImage.img
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'zImage.img'.
Load address: 0x30008000
Loading: T #################################################################


#################################################################


##########################
done
Bytes transferred = 2277540 (22c0a4 hex)
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...

Image Name:
tekkaman

Created:
2010-03-29
12:59:51 UTC

Image Type:
ARM Linux Kernel Image (uncompressed)

Data Size:
2277476 Bytes =
2.2 MB

Load Address: 30008000

Entry Point:
30008040

Verifying Checksum ... OK

XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
(略)



3) 通过NFS服务引导内核:

[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/zImage.img
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/zImage.img'.
Load address: 0x30008000
Loading: #################################################################


#################################################################


#################################################################


#################################################################


#################################################################


#################################################################


#######################################################
done
Bytes transferred = 2277540 (22c0a4 hex)
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...

Image Name:
tekkaman

Created:
2010-03-29
12:59:51 UTC

Image Type:
ARM Linux Kernel Image (uncompressed)

Data Size:
2277476 Bytes =
2.2 MB

Load Address: 30008000

Entry Point:
30008040

Verifying Checksum ... OK

XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
(略)


4) 通过Nand Flash引导内核:
   首先要将处理过的内核映像文件烧入Nand Flash的一定位置(由内核分区表决定)。以后每次启动时用Nand Flash的读取命令先将这个内核映像文件读到内存的一定位置(由制作内核映像时的-a参数决定),再使用bootm命令引导内核。
内核映像文件的烧入:

[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/zImage.img
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/zImage.img'.
Load address: 0x30008000
Loading: #################################################################


#################################################################


#################################################################


#################################################################


#################################################################


#################################################################


#######################################################
done
Bytes transferred = 2277540 (22c0a4 hex)
[u-boot@MINI2440]# nand erase 0x80000 0x300000

NAND erase: device 0 offset 0x80000, size 0x300000
Erasing at 0x36000001800000 --
0% complete.
OK
[u-boot@MINI2440]#
nand write 30008000 0x80000 300000

NAND write: device 0 offset 0x80000, size 0x300000

Writing at 0x36000000020000 -- 100% is complete. 3145728 bytes written: OK



内核引导:

[u-boot@MINI2440]#
nand read 30008000 0x80000 300000

NAND read: device 0 offset 0x80000, size 0x300000

3145728 bytes read: OK
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...

Image Name:
tekkaman

Created:
2010-03-29
12:59:51 UTC

Image Type:
ARM Linux Kernel Image (uncompressed)

Data Size:
2277476 Bytes =
2.2 MB

Load Address: 30008000

Entry Point:
30008040

Verifying Checksum ... OK

XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440


[1] [2] [3] [4] [5]
关键字:U-boot命令  shell 引用地址:常用 U-boot命令详解

上一篇:在u-boot中添加命令
下一篇:使用BusyBox制作linux根文件系统(CramFS+mdev)

小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved