Chinaunix首页 | 论坛 | 博客
  • 博客访问: 232051
  • 博文数量: 61
  • 博客积分: 125
  • 博客等级: 入伍新兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-23 23:28
文章分类

全部博文(61)

文章存档

2014年(37)

2013年(21)

2012年(3)

分类: LINUX

2012-11-18 11:12:36

U-boot的使用(一) 转自:http://blog.chinaunix.net/u1/34474/showart.php?id=2212095
作者:Tekkaman Ninja(大侠)
===========================================
我一贯认为:对于一个技术类的东西,你连用都不会用,那根本就不可能会开发。就好像一个人连Linux都不会用,那还谈何开发Linux程序呢?
同样的要开发和移植U-boot,首先要对U-boot有一定的了解,起码要会使用。
所以这里我们首先熟悉一下U-boot的使用以及如何将U-boot烧入mini2440。
当然在这之前首先必须保证你的板子上已经有了U-boot。如果没有那就先烧上一个吧。针对mini2440的U-boot-2009.11的bin文件我已经上传到了博客中,可以直接烧入,请到这里下载:

u-boot-2009.11 for mini2440 Source release

把它烧到mini2440的NAND或者NOR Flash的起始地址即可,你可以使用OpenJTAG下载烧写:

关于OpenOCD的安装和配置(以mini2440+OpenJTAG为例)

也可以用板上已有的boottloader烧写,也可以适用H-JTAG用并口烧(这是最直接最快的)。


常用的U-boot命令详解
U-boot发展到现在,他的命令行模式已经非常接近Linux下的shell了,在我编译的U-boot-2009.11中的命令行模式模式下支持“Tab”键的命令补全和命令的历史记录功能。而且如果你输入的命令的前几个字符和别的命令不重复,那么你就只需要打这几个字符即可,比如我想看这个U-boot的版本号,命令就是“ version”,但是在所有的命令中没有其他任何一个的命令是由“v”开头的,所以只需要输入“v”即可。

[u-boot@MINI2440]# version

U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# v

U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# base
Base Address: 0x00000000
[u-boot@MINI2440]# ba
Base Address: 0x00000000
由于U-boot支持的命令实在太多,一个一个细讲不现实,也没有必要。所以下面我挑一些烧写和引导常用命令介绍一下,其他的命令大家就举一反三,或者“help”吧!

(1)获取帮助
命令:help 或 ?
功能:查看当前U-boot版本中支持的所有命令。

[u-boot@MINI2440]# help
? - alias for 'help'
askenv - get environment variables from stdin
base - print or set address offset
bdinfo - print Board Info structure
bmp - manipulate BMP image data
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
bootelf - Boot from an ELF image in memory
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
bootvx - Boot vxWorks from an ELF image
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
date - get/set/reset date & time
dcache - enable or disable data cache
dhcp - boot image via network using DHCP/TFTP protocol
echo - echo args to console
editenv - edit environment variable
eeprom - EEPROM sub-system
erase - erase FLASH memory
exit - exit script
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls - list files in a directory (default /)
flinfo - print FLASH memory information
fsinfo - print information about filesystems
fsload - load binary file from a filesystem image
go - start application at address 'addr'
help - print online help
i2c - I2C sub-system
icache - enable or disable instruction cache
iminfo - print header information for application image
imls - list all images found in flash
imxtract- extract a part of a multi-image
itest - return true/false on integer compare
loadb - load binary file over serial line (kermit mode)
loads - load S-Record file over serial line
loadx - load binary file over serial line (xmodem mode)
loady - load binary file over serial line (ymodem mode)
loop - infinite loop on address range
ls - list files in a directory (default /)
md - memory display
mm - memory modify (auto-incrementing address)
mmc - MMC sub-system
mtest - simple RAM read/write test
mw - memory write (fill)
nand - NAND sub-system
nboot - boot from NAND device
nfs - boot image via network using NFS protocol
nm - memory modify (constant address)
ping - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
protect - enable or disable FLASH write protection
rarpboot- boot image via network using RARP/TFTP protocol
reginfo - print register information
reset - Perform RESET of the CPU
run - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv - set environment variables
showvar - print local hushshell variables
sleep - delay execution for some time
source - run script from memory
test - minimal test like /bin/sh
tftpboot- boot image via network using TFTP protocol
unzip - unzip a memory region
usb - USB sub-system
usbboot - boot from USB device
version - print monitor version
如果你想获取某条命令的更详细的帮助,可以使用:

help <你想要查的指令>
或者 ? <你想要查的指令> ,
甚至 h <你想要查的指令缩写>。
以bmp指令为例:

[u-boot@MINI2440]# help bmp
bmp - manipulate BMP image data

Usage:
bmp info  - display image info
bmp display  [x y] - display image at x,y
[u-boot@MINI2440]# ? bmp
bmp - manipulate BMP image data

Usage:
bmp info  - display image info
bmp display  [x y] - display image at x,y
[u-boot@MINI2440]# h bm
bmp - manipulate BMP image data

Usage:
bmp info  - display image info
bmp display  [x y] - display image at x,y
(2)环境变量(environment variables,简称ENV)与相关指令
和shell类似,U-Boot也有环境变量。一些U-boot默认的环境变量如下:

环 境 变 量 解 释 说 明
bootdelay 执行自动启动(bootcmd中的命令)的等候秒数
baudrate 串口控制台的波特率
netmask 以太网的网络掩码
ethaddr 以太网的MAC地址
bootfile 默认的下载文件名
bootargs 传递给Linux内核的启动参数
bootcmd 自动启动时执行命令
serverip TFTP服务器端的IP地址
ipaddr 本地的IP地址
stdin 标准输入设备,一般是串口
stdout 标准输出,一般是串口,也可是LCD(VGA)
stderr 标准出错,一般是串口,也可是LCD(VGA)

要看到你的板上的ENV值可使用printenv命令,例如我的板子:

[u-boot@MINI2440]# printenv
bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.0.1:/home/tekkaman/working/nfs/rootfs ip=192.168.0.2:192.168.0.1::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
bootcmd=nfs 0×30008000 192.168.0.1:/home/tekkaman/working/nfs/zImage.img;bootm
bootdelay=1
baudrate=115200
ethaddr=08:08:11:18:12:27
ipaddr=192.168.0.2
serverip=192.168.0.1
gatewayip=192.168.0.1
netmask=255.255.255.0
tekkaman=bmp d 70000
stdin=serial
stdout=serial
stderr=serial
ethact=dm9000

Environment size: 470/131068 bytes

你会发现有些有的ENV我没有,还有一个“tekkaman”的ENV。原因是如果你没有设置这个环境变量就不会打印出,你也可以自己定义ENV,并在命令中使用${ENV}来调用它。同时你也可以删除这个ENV。设置ENV的命令是setenv,格式为:

setenv name value

第1个参数是环境变量的名称。
第2个参数是要设置的值,如果没有第2个参数,表示删除这个环境变量。
例如:我先将”tekkaman”参数删除,再设置,最后在一个命令串中调用。

[u-boot@MINI2440]# printenv tekkaman
tekkaman=bmp d 70000
[u-boot@MINI2440]# setenv tekkaman
[u-boot@MINI2440]# printenv tekkaman
## Error: "tekkaman" not defined
[u-boot@MINI2440]# setenv tekkaman echo "I am Tekkaman Ninja!"
[u-boot@MINI2440]# printenv tekkaman
tekkaman=echo I am Tekkaman
[u-boot@MINI2440]# echo I Love Linux ;${tekkaman}
I Love Linux
I am Tekkaman

当你设置了ENV,它只保存在内存中,如果你要它保存在存放ENV的固态存储器中,请使用:saveenv。

[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done

如果在启动的时候会看到U-boot打印出:“Warning – bad CRC, using default environment”,说明U-boot没有在存放ENV的固态存储器中找到有效的ENV,只好使用你在编译的时候定义的默认ENV。如果U-boot存放ENV的固态存储器的驱动是OK的,那么只要运行 saveenv就可以把默认ENV写入固态存储器,下次启动就不会有这个警告了。
ENV可以放在许多固体存储器中,对于mini2440来说Nor Flash、Nand Flash或EEPROM都可以,就看你如何配置了(include/configs下的配置文件)。例如:
Nor Flash:

#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE            0x20000    /* Total Size of Environment Sector */

Nand Flash:

#define CONFIG_ENV_IS_IN_NAND 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE            0x20000    /* Total Size of Environment Sector */

EEPROM:

#define CONFIG_ENV_IS_IN_EEPROM 1 /* use EEPROM for environment vars */
#define CONFIG_ENV_OFFSET 0x000 /* environment starts at offset 0 */
#define CONFIG_ENV_SIZE     0x400 /* 1KB */

CONFIG_ENV_OFFSET是在整个存储器中的偏移地址;
CONFIG_ENV_SIZE是指其使用的大小。
注意 CONFIG_ENV_OFFSET和 CONFIG_ENV_SIZE 的设置,不要覆盖了其他分区。
 
 
 



U-boot的使用(二) 转自:http://blog.chinaunix.net/u1/34474/showart.php?id=2212162
作者:Tekkaman Ninja(大侠)
============================================

(3)串口传输命令
命令:

loadb   - load binary file over serial line (kermit mode)
loadx   - load binary file over serial line (xmodem mode)
loady   - load binary file over serial line (ymodem mode)
功能:以不同的协议从串口获取文件.。
格式基本都为:

load? [ off ] [ baud ]
第1个参数是下载到SDRAM的地址,如果不填,就是用默认配置:CONFIG_SYS_LOAD_ADDR
第2个参数是波特率,一般不填,用默认的115200.

在windows下的超级终端可以用这些协议发送文件,但是在ubuntu下基本只能用kermit协议。一下使用C-kermit来发送一个文件到mini2440。

[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...
上面已经启动了U-boot的kermit传输协议,这时按下 Ctrl + \ , 再按 c, 切换到C-kermit的命令行模式,输入命令:send <文件路径>,回车。

[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...

(Back at MAGI-Linux)
----------------------------------------------------
C-Kermit 8.0.211, 10 Apr 2004, for Linux
 Copyright (C) 1985, 2004,
  Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/home/tekkaman/桌面/) C-Kermit>send /home/tekkaman/development/share/zImage.img
C-kermit就开始传送,并且显示一个传送界面,并动态显示传送进度。

C-Kermit 8.0.211, 10 Apr 2004, MAGI-Linux

Current Directory: /home/tekkaman/??~L?~]?
Communication Device: /dev/ttyUSB0
Communication Speed: 115200
              Parity: none
         RTT/Timeout: 01 / 02
             SENDING: /home/tekkaman/development/share/zImage.img => zImage.img
           File Type: BINARY
           File Size: 2277540
        Percent Done: 19 /////////-

                          ...10...20...30...40...50...60...70...80...90..100
 Estimated Time Left: 00:03:35
  Transfer Rate, CPS: 8536
        Window Slots: 1 of 1
         Packet Type: D
        Packet Count: 557
       Packet Length: 1000
         Error Count: 0
          Last Error:
        Last Message:

X to cancel file, Z to cancel group,  to resend last packet,
E to send Error packet, ^C to quit immediately, ^L to refresh screen.
传送完毕后,输入c ,回到U-boot的串口界面。

[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...

(Back at MAGI-Linux)
----------------------------------------------------
C-Kermit 8.0.211, 10 Apr 2004, for Linux
 Copyright (C) 1985, 2004,
  Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/home/tekkaman/桌面/) C-Kermit>send /home/tekkaman/development/share/zImage.img
(/home/tekkaman/桌面/) C-Kermit>c
Connecting to /dev/ttyUSB0, speed 115200
 Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------
## Total Size = 0x0022c0a4 = 2277540 Bytes
## Start Addr = 0x30008000
(4)网络命令
只要你的网卡驱动没问题,那么你就可以通过网络来传输文件到开发板,这可比串口快多了。你可以直接用交叉网线连接开发板和电脑,也可以用普通直连网线连接路由器,再连到电脑,不过记得配置好网络,关闭防火墙哦。
先测试网络是否通了,现在开发板使用ping 命令,看看是否可以ping通电脑:

[u-boot@MINI2440]# ping 192.168.1.100
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
host 192.168.1.100 is alive
如果出现:

[u-boot@MINI2440]# ping 192.168.1.100
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
ping failed; host 192.168.1.100 is not alive
这样无法ping通的事,可能是:
1、U-boot网卡驱动有问题
2、U-boot网络协议延时配置有问题
3、网络参数配置问题,比如IP等,Host和Target都有可能有问题。Host最好关闭IPv6。
实在找不到原因,用Wireshark抓包看看。

如果网络畅通,下面就可以使用下面的命令从tftp目录或者nfs目录下载文件到SDRAM了。
命令:

dhcp    - boot image via network using DHCP/TFTP protocol
rarpboot- boot image via network using RARP/TFTP protocol
nfs     - boot image via network using NFS protocol
tftpboot- boot image via network using TFTP protocol
bootp   - boot image via network using BOOTP/TFTP protocol
这几个命令的格式都是:

<指令> [目的SDRAM地址] [[主机IP:]文件名]
注意:
要使用dhcp、rarpboot或 bootp 等功能要路由器或Host的支持。
如果没有输入[目的SDRAM地址],系统就是用编译时定义的CONFIG_SYS_LOAD_ADDR作为目的SDRAM地址
如果tftpboot和nfs命令没有定义[主机IP:],则使用ENV中的serverip
其它命令必需定义[主机IP:],否则会使用提供动态IP服务的主机IP作为[主机IP:]。

使用范例:

[u-boot@MINI2440]# nfs 0x30008000 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]# tftp 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]# dhcp 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
BOOTP broadcast 1
BOOTP broadcast 2
DHCP client bound to address 192.168.1.101
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: ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# bootp 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
BOOTP broadcast 1
BOOTP broadcast 2
DHCP client bound to address 192.168.1.101
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: ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# rarpboot 192.168.1.100:u-boot.bin
我的路由器没有开rarp协议,所以rarpboot 无法使用,要使用dhcp或 bootp 也是要路由或Host支持的。

(5)Nand Flash操作指令

常用的Nand Flash指令如下:

指令 功能
nand info 显示可使用的Nand Flash
nand device [dev] 显示或设定当前使用的Nand Flash
nand read  addr off  size Nand Flash读取命令,从Nand的 off 偏移地址处读取size 字节的数据到SDRAM的addr地址。
nand write   addr off  size Nand Flash烧写命令,将SDRAM的addr地址处的size 字节的数据烧写到Nand的 off 偏移地址。
nand write[.yaffs[1]]    addr off size 烧写yaffs 映像专用的命令,.yaffs1 for 512+16 NAND
nand erase [clean] [off size] Nand Flash檫除命令,擦除Nand Flash的 off 偏移地址处的size 字节的数据
nand bad 显示Nand Flash的坏块
nand dump[.oob] off 显示Nand Flash中的数据(16进制)
nand scrub 彻底擦除整块Nand Flash中的数据,包括OOB。可以擦除软件坏块标志。
nand markbad off 标示 Nand的 off 偏移地址处的块为坏块

使用范例:

[u-boot@MINI2440]# nand info

Device 0: NAND 128MiB 3,3V 8-bit, sector size 128 KiB
[u-boot@MINI2440]# nand device 0
Device 0: NAND 128MiB 3,3V 8-bit... is now current device
[u-boot@MINI2440]# nand read 0x30008000 0x60000 200000

NAND read: device 0 offset 0x60000, size 0x200000
 2097152 bytes read: OK
[u-boot@MINI2440]# nand bad

Device 0 bad blocks:
  030a0000
  030c0000
  030e0000
  07ee0000
[u-boot@MINI2440]# nand markbad 0x500000
block 0x00500000 successfully marked as bad
[u-boot@MINI2440]# nand bad

Device 0 bad blocks:
  00500000
  030a0000
  030c0000
  030e0000
  07ee0000
[u-boot@MINI2440]# nand scrub

NAND scrub: device 0 whole chip
Warning: scrub option will erase all factory set bad
         There is no reliable way to recover them.
         Use this command only for testing purposes if you
         are sure of what you are

Really scrub this NAND flash?
Erasing at 0x2f4000008000000 -- 0% complete.
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5

NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5

NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x7ea000008000000 -- 0% complete.
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x7fe000008000000 -- 0% complete.
OK
[u-boot@MINI2440]# nand bad

Device 0 bad blocks:
  030a0000
  030c0000
  030e0000
  07ee0000
[u-boot@MINI2440]# nand dump 0x8000
Page 00008000 dump:
    ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         (略)
OOB:
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
[u-boot@MINI2440]# tftp 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 write 0x30008000 0 40000

NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK
[u-boot@MINI2440]# nand dump 0x8000
Page 00008000 dump:
    00 00 53 e1 01 00 00 2a 15 40 e0 e3 19 00 00 ea
         (略)
    60 30 97 e5 03 00 54 e1 f6 ff ff ba 00 40 a0 e3
OOB:
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    ff ff ff ff ff ff ff ff
    65 a9 6b f3 ff 33 fc 30
    f3 33 cf 33 0f f0 ff 00
    cc 0f 59 55 57 96 a5 5b
nboot 指令也是一条Nand Flash 读取指令,它是将Nand Flash 的 offset 偏移地址的内核映像读取到SDRAM的loadAddr位置。它会自动读取到内核映像(使用mkimage处理过的)的结束,所以不用给出读取大小。

格式:nboot  loadAddr  dev  offset
使用范例:

[u-boot@MINI2440]# tftp 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]# nand erase 0x100000 300000

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

NAND write: device 0 offset 0x100000, size 0x300000
Writing at 0x3e000000020000 -- 100% is complete. 3145728 bytes written: OK
[u-boot@MINI2440]# nand device 0
Device 0: NAND 128MiB 3,3V 8-bit... is now current device
[u-boot@MINI2440]# nboot 30008000 0 0x100000

Loading from NAND 128MiB 3,3V 8-bit, offset 0x100000
   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

 [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
(略)
 
 
 
U-boot的使用(三) 转自:http://blog.chinaunix.net/u1/34474/showart.php?id=2212192
作者:Tekkaman Ninja(大侠)
============================================

(6) 内存/寄存器操作指令
nm      修改内存值 (指定地址)
格式: nm [.b, .w, .l] address

mm     修改内存值(地址自动加一)
格式:  mm [.b, .w, .l] address

md       显示内存值
格式:  md [.b, .w, .l] address [# of objects]

mw     用指定的数据填充内存
格式:  mw [.b, .w, .l] address value [count]

cp      内存的拷贝(包括内存与Nor Flash间的数据拷贝)
格式:cp [.b, .w, .l] source target count
上面是查看和修改内存值的指令,可以查看和修改SDRAM和寄存器值。
[.b, .w, .l]代表了查看和修改形式:Byte、word、long

使用范例:

[u-boot@MINI2440]# md.b 0x30008000 20
30008000: cc 33 fe 33 cc b3 4c 33 ac 33 de 33 5c 13 cc 33 .3.3..L3.3.3\..3
30008010: cc 32 cc 31 dc 33 cf 33 cc 33 4e 33 8f 13 cc 33 .2.1.3.3.3N3...3
[u-boot@MINI2440]# md.w 0x30008000 20
30008000: 33cc 33fe b3cc 334c 33ac 33de 135c 33cc .3.3..L3.3.3\..3
30008010: 32cc 31cc 33dc 33cf 33cc 334e 138f 33cc .2.1.3.3.3N3...3
30008020: 338c 33cd 33cc 7bcc 3bcc 33cc 135e 734c .3.3.3.{.;.3^.Ls
30008030: 7bdc 37cc 31dc 33c4 038c 33e8 77cc 13cc .{.7.1.3...3.w..
[u-boot@MINI2440]# md.l 0x30008000 20
30008000: 33fe33cc 334cb3cc 33de33ac 33cc135c .3.3..L3.3.3\..3
30008010: 31cc32cc 33cf33dc 334e33cc 33cc138f .2.1.3.3.3N3...3
30008020: 33cd338c 7bcc33cc 33cc3bcc 734c135e .3.3.3.{.;.3^.Ls
30008030: 37cc7bdc 33c431dc 33e8038c 13cc77cc .{.7.1.3...3.w..
30008040: 234c77ce 33dc339c 33ec3ece f3cc36ec .wL#.3.3.>.3.6..
30008050: 37dc33cc 73cc3f5c 17dd314c 33cc62e8 .3.7\?.sL1...b.3
30008060: b6cc33dc 33c233cc 33cc32cc 33cc3f68 .3...3.3.2.3h?.3
30008070: 73cc31cc b3cc33cc 33cc37c9 33df13cc .1.s.3...7.3...3
[u-boot@MINI2440]# nm 0x30008000
30008000: 33fe33cc ? 12345678
30008000: 12345678 ? 34567890
30008000: 34567890 ? q
[u-boot@MINI2440]# nm.b 0x30008000
30008000: 90 ? 11
30008000: 11 ? 12
30008000: 12 ? q
[u-boot@MINI2440]# mm 0x30008000
30008000: 34567812 ? 54321123
30008004: 334cb3cc ? 12345678
30008008: 33de33ac ? 21234543
3000800c: 33cc135c ? q
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: 23 11 32 54 78 56 34 12 43 45 23 21 5c 13 cc 33 #.2TxV4.CE#!\..3
30008010: cc 32 cc 31 dc 33 cf 33 cc 33 4e 33 8f 13 cc 33 .2.1.3.3.3N3...3
[u-boot@MINI2440]# mw.b 0x30008000 aa 10
[u-boot@MINI2440]# mw.b 0x30008010 55 10
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
30008010: 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU
[u-boot@MINI2440]# cp.b 0x30008000 0x30008010 10
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
30008010: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
你可以试着修改LED相连的GPIO寄存器的数据寄存器值,可以控制LED的点亮!
先熄灭后点亮LED1的范例:(这个实验要结合芯片数据手册和mini2440的原理图来理解)
[u-boot@MINI2440]# md 0×56000014 1
56000014: 00000600 ….
[u-boot@MINI2440]# nm.w 0×56000014
56000014: 0600 ? 620 (熄灭)
56000014: 0620 ? 600 (点亮)

(7) Nor Flash指令
Nor Flash 的命令经常用于烧写数据到Nor Flash 。

flinfo  打印Flash存储器的信息,并列出所有Sector。
flinfo  N 单独打Flash存储器N Block的信息。(在有多块Nor Flash时使用)
使用范例:

[u-boot@MINI2440]# flinfo

Bank # 1: SST: 1x SST39VF1601 (2MB)
  Size: 2 MB in 32 Sectors
  Sector Start Addresses:
    00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
    00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
    000A0000 000B0000 000C0000 000D0000 000E0000
    000F0000 00100000 00110000 00120000 00130000
    00140000 00150000 00160000 00170000 00180000
    00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# flinfo 1

Bank # 1: SST: 1x SST39VF1601 (2MB)
  Size: 2 MB in 32 Sectors
  Sector Start Addresses:
    00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
    00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
    000A0000 000B0000 000C0000 000D0000 000E0000
    000F0000 00100000 00110000 00120000 00130000
    00140000 00150000 00160000 00170000 00180000
    00190000 001A0000 001B0000 001C0000 001D0000
    001E0000 001F0000
[u-boot@MINI2440]# flinfo 2
Only FLASH Banks # 1 ... # 1 supported
后面带有(RO)的说明这个Sector已经写保护了。

因为Nor Flash的读取接口和SDRAM是一样的,所以Nor Flash的读取也是使用md命令。范例如下:

[u-boot@MINI2440]# md.b 0x0 20
00000000: 12 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
00000010: 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
[u-boot@MINI2440]# md 0x0 20
00000000: ea000012 e59ff014 e59ff014 e59ff014 ................
00000010: e59ff014 e59ff014 e59ff014 e59ff014 ................
00000020: 33f80260 33f802c0 33f80320 33f80380 `..3...3 ..3...3
00000030: 33f803e0 33f80440 33f804a0 deadbeef ...3@..3...3....
00000040: 33f80000 33f80000 33fbe8dc 3400374c ...3...3...3L7.4
00000050: e10f0000 e3c0001f e38000d3 e129f000 ..............).
00000060: e3a00453 e3a01000 e5801000 e3e01000 S...............
00000070: e59f0488 e5801000 e59f1484 e59f0484 ................
但由于Nor Flash的烧写时序和SDRAM的写入不同,烧写Nor Flash 不能使用mm等命令,只能使用cp命令从内存拷贝到Nor Flash,而且烧写之前必须解除保护并擦除!命令如下:

protect :对Flash 写保护的操作,可以使能和解除写保护。
格式:

protect on/off start end
protect on/off start +end
protect on/off N:SF[-SL]
protect on/off bank N
protect on/off all
第1 个参数on 代表使能写保护;off 代表解除写保护。
第2 、3 参数是指定Flash 写保护操作范围

start end是照起始地址和结束地址定义范围,start是擦除块的起始地址;end 是擦除末尾块的结束地址。
例如:擦除Sector 2和Sector 3区域命令为erase 20000 3ffff 。

start +end是照起始地址和操作字节数定义范围,这种方式最常用。start是擦除块的起始地址;end 是擦除的字节数。
例如:擦除Sector 2和Sector 3区域命令为erase 20000 +20000

N:SF[-SL]是按照组和扇区,N 表示Flash 的Block号,SF 表示擦除起始Sector号,SL 表示擦除结束Sector号。
例如:擦除Block1 的Sector 2和Sector 3区域命令为erase 1:2-3。

bank N是擦除整个Block,擦除Block号为N 的整个Flash。

all是擦除全部Flash。

注意:Nor Flash擦除的最小单位是Sector,也就是0×10000字节,如果你定义的大小不满1 Sector或超过Sector的边界,那么被定义到的Sector会被全部擦除。

erase :擦除Flash的命令
格式:

erase start end
erase start +end
erase N:SF[-SL]
erase bank N
erase all
参数是指定Flash 擦除操作范围,跟写保护的方式相同。

以下的范例将mini2440的Nor Flash的Sector 16写保护,再解除保护,擦除数据,最后将起始的20字节拷贝到Sector 16。

[u-boot@MINI2440]# flinfo 1

Bank # 1: SST: 1x SST39VF1601 (2MB)
  Size: 2 MB in 32 Sectors
  Sector Start Addresses:
    00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
    00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
    000A0000 000B0000 000C0000 000D0000 000E0000
    000F0000 00100000 00110000 00120000 00130000
    00140000 00150000 00160000 00170000 00180000
    00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# protect on 1:16-16
Protect Flash Sectors 16-16 in Bank # 1
[u-boot@MINI2440]# flinfo 1

Bank # 1: SST: 1x SST39VF1601 (2MB)
  Size: 2 MB in 32 Sectors
  Sector Start Addresses:
    00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
    00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
    000A0000 000B0000 000C0000 000D0000 000E0000
    000F0000 00100000 (RO) 00110000 00120000 00130000
    00140000 00150000 00160000 00170000 00180000
    00190000 001A0000 001B0000 001C0000 001D0000
    001E0000 001F0000
[u-boot@MINI2440]# protect off 0x100000 0x10ffff
Un-Protect Flash Sectors 16-16 in Bank # 1
[u-boot@MINI2440]# flinfo 1

Bank # 1: SST: 1x SST39VF1601 (2MB)
  Size: 2 MB in 32 Sectors
  Sector Start Addresses:
    00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
    00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
    000A0000 000B0000 000C0000 000D0000 000E0000
    000F0000 00100000 00110000 00120000 00130000
    00140000 00150000 00160000 00170000 00180000
    00190000 001A0000 001B0000 001C0000 001D0000
    001E0000 001F0000
[u-boot@MINI2440]# erase 0x100000 +20
Erasing sector 16 ... ok.
Erased 1 sectors
[u-boot@MINI2440]# cp.b 0x0 0x100000 0x20
Copy to Flash... done
[u-boot@MINI2440]# md.b 100000 20
00100000: 12 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
00100010: 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
(8) USB 操作指令
指令 功能
usb reset 初始化USB控制器
usb stop [f] 关闭USB控制器
usb tree 已连接的USB设备树
usb info [dev] 显示USB设备[dev]的信息
usb storage 显示已连接的USB存储设备
usb dev [dev] 显示和设置当前USB存储设备
usb part [dev] 显示USB存储设备[dev]的分区信息
usb read addr blk# cnt 读取USB存储设备数据

在所有的命令使用前,必须先插入USB设备,然后使用:usb reset,以初始化USB控制器,获取设备信息。
我将一个4G的kingstonU盘(可引导盘)插入 mini2440,然后读取他的头512 字节(MBR):

[u-boot@MINI2440]# usb reset
(Re)start USB...
USB: scanning bus for devices... 2 USB Device(s) found
       scanning bus for storage devices... 1 Storage Device(s) found
[u-boot@MINI2440]# usb tree

Device Tree:
  1 Hub (12 Mb/s, 0mA)
  | OHCI Root Hub
  |
  +-2 Mass Storage (12 Mb/s, 100mA)
       Kingston DT 101 II 0019E02CB6EB5B8B1B120051

[u-boot@MINI2440]# usb info
1: Hub, USB Revision 1.10
 - OHCI Root Hub
 - Class: Hub
 - PacketSize: 8 Configurations: 1
 - Vendor: 0x0000 Product 0x0000 Version 0.0
   Configuration: 1
   - Interfaces: 1 Self Powered 0mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 1
     - Class Hub
     - Endpoint 1 In Interrupt MaxPacket 2 Interval 255ms

2: Mass Storage, USB Revision 2.0
 - Kingston DT 101 II 0019E02CB6EB5B8B1B120051
 - Class: (from Interface) Mass Storage
 - PacketSize: 64 Configurations: 1
 - Vendor: 0x0951 Product 0x1613 Version 1.0
   Configuration: 1
   - Interfaces: 1 Bus Powered 100mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 2
     - Class Mass Storage, Transp. SCSI, Bulk only
     - Endpoint 1 In Bulk MaxPacket 64
     - Endpoint 2 Out Bulk MaxPacket 64

[u-boot@MINI2440]# usb storage
  Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
            Type: Removable Hard Disk
            Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
[u-boot@MINI2440]# usb dev 0

USB device 0:
    Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
            Type: Removable Hard Disk
            Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
... is now current device
[u-boot@MINI2440]# usb part 0
print_part of 0

Partition Map for USB device 0 -- Partition Type: DOS

Partition Start Sector Num Sectors Type
    4 63 7935937 c
[u-boot@MINI2440]# usb read 0x30008000 0 200

USB read: device 0 block # 0, count 512 ... .........................
512 blocks read: OK
[u-boot@MINI2440]# md.b 0x30008000 200
30008000: fa 31 c0 8e d8 8e c0 8e d0 bc 00 7c fb fc 89 e6    .1.........|....
30008010: bf 00 06 b9 00 01 f3 a5 ea dc 06 00 00 10 00 01    ................
30008020: 00 00 7c 00 00 00 00 00 00 00 00 00 00 80 3f 00    ..|...........?.
30008030: ff 00 ed 01 1e 0e 1f 3a 16 10 00 74 06 1f ea 36    .......:...t...6
30008040: e7 00 f0 3d fb 54 75 05 8c d8 fb eb 1d 80 fc 08    ...=.Tu.........
30008050: 75 1b e8 81 00 8a 36 13 00 fe ce 8b 0e 15 00 86    u.....6.........
30008060: cd c0 e1 06 0a 0e 11 00 31 c0 f8 eb 65 80 fc 02    ........1...e...
30008070: 72 cb 80 fc 04 77 c6 60 80 cc 40 50 be 00 00 c7    r....w.`..@P....
30008080: 04 10 00 30 e4 89 44 02 89 5c 04 8c 44 06 66 31    ...0..D..\..D.f1
30008090: c0 66 89 44 0c 88 f0 f6 26 11 00 88 cf 88 eb c0    .f.D....&.......
300080a0: ef 06 81 e1 3f 00 01 c8 48 89 c7 a1 13 00 f7 26    ....?...H......&
300080b0: 11 00 f7 e3 01 f8 81 d2 00 00 89 44 08 89 54 0a    ...........D..T.
300080c0: 58 30 c0 8a 16 10 00 e8 0c 00 88 26 03 00 61 a1    X0.........&..a.
300080d0: 02 00 1f ca 02 00 9c ff 1e 22 00 c3 80 fa 8f 7f    ........."......
300080e0: 04 88 16 2d 06 be 87 07 e8 8d 00 be be 07 31 c0    ...-..........1.
300080f0: b9 04 00 f6 04 80 74 03 40 89 f5 81 c6 10 00 e2    ......t.@.......
30008100: f2 48 74 02 cd 18 bf 05 00 be 1d 06 c7 44 02 01    .Ht..........D..
30008110: 00 66 8b 46 08 66 89 44 08 b8 00 42 8a 16 2d 06    .f.F.f.D...B..-.
30008120: cd 13 73 0d 4f 74 49 30 e4 8a 16 2d 06 cd 13 eb    ..s.OtI0...-....
30008130: d8 a1 fe 7d 3d 55 aa 75 37 fa 66 a1 4c 00 66 a3    ...}=U.u7.f.L.f.
30008140: 3f 06 be 13 04 8b 04 48 89 04 c1 e0 06 8e c0 31    ?......H.......1
30008150: ff be 1d 06 b9 60 00 fc f3 a5 c7 06 4c 00 17 00    .....`......L...
30008160: a3 4e 00 fb 8a 16 2d 06 89 ee fa ea 00 7c 00 00    .N....-......|..
30008170: be aa 07 e8 02 00 eb fe ac 20 c0 74 09 b4 0e bb    ......... .t....
30008180: 07 00 cd 10 eb f2 c3 53 74 61 72 74 20 62 6f 6f    .......Start boo
30008190: 74 69 6e 67 20 66 72 6f 6d 20 55 53 42 20 64 65    ting from USB de
300081a0: 76 69 63 65 2e 2e 2e 0d 0a 00 42 6f 6f 74 20 66    vice......Boot f
300081b0: 61 69 6c 65 64 00 00 00 ea eb d4 ca 00 00 00 00    ailed...........
300081c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
300081d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
300081e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 01    ................
300081f0: 01 00 0c fe 7f ec 3f 00 00 00 c1 17 79 00 55 aa    ......?.....y.U.
(9) SD卡(MMC)指令
SD卡的使用命令比较简单,只有初始化和设备信息的显示,读写是通过文件系统命令实现的。

mmc init [dev] - 初始化MMC子系统
mmc device [dev] - 查看和设置当前设备
使用和USB类似,在所有的命令使用前,必须先插入SD卡,然后使用:mmc init,以初始化MMC 控制器,获取设备信息。
我在mini2440中插入1GB SD卡:

[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 "Product 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]# mmc device
mmc1 is current device
(10) FAT文件系统指令
fatinfo:显示文件系统的相关信息
格式:fatinfo
Interface:代表接口,如usb、mmc;
dev:代表设备编号,如0、1……;
part:代表存储设备中的分区,如1、2……。
fatload:从FAT32文件系统中读取二进制文件到SDRAM。
格式:fatload      [bytes]
Interface、dev和part同上;
addr:代表写入SDRAM的地址;
filename:代表存储设备中的文件名;
bytes:代表从存储设备中读取的文件大小,可不填;如果填的数据比文件小,就只读取bytes字节,如果填的数据比文件大,也只读取文件的大小。
fatls:列出FAT32文件系统中目录里的文件。
格式:fatls   [directory]
Interface、dev和part同上;
directoryr:代表所要查看的目录,可不填,默认为/。
这些指令基本上要和U盘或者SD卡同时使用,主要用于读取这些移动存储器上的FAT32分区。

使用范例:

[u-boot@MINI2440]# usb part 0
print_part of 0

Partition Map for USB device 0 -- Partition Type: DOS

Partition Start Sector Num Sectors Type
    4 63 7935937 c
[u-boot@MINI2440]# fatinfo usb 0:4
Interface: USB
  Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
            Type: Removable Hard Disk
            Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
Partition 4: Filesystem: FAT32 "7600_16385_"
 [u-boot@MINI2440]# fatls usb 0:4
            boot/
            efi/
            sources/
            support/
            upgrade/
       43 autorun.inf
   383562 bootmgr
   111880 setup.exe
   256220 u-boot.bin

4 file(s), 5 dir(s)

[u-boot@MINI2440]# fatls usb 0:4 /boot/
            ./
            ../
            fonts/
            zh-cn/
   262144 bcd
  3170304 boot.sdi
     1024 bootfix.bin
    97280 bootsect.exe
     4096 etfsboot.com
   485440 memtest.exe

6 file(s), 4 dir(s)
[u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin
reading u-boot.bin
........................

256220 bytes read
 [u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin 200
reading u-boot.bin

512 bytes read
(11) 系统引导指令
boot 和bootd 都是运行ENV”bootcmd”中指定的指令。

bootm 指令是专门用于启动在SDRAM中的用U-boot的mkimage工具处理过的内核映像。

格式:bootm [addr [arg ...]]
addr 是内核映像所在的SDRAM中的地址
当启动的是Linux内核时,’arg’ 可以是 initrd 的地址。

[u-boot@MINI2440]# setenv bootcmd tftp\;bootm
[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done
[u-boot@MINI2440]# boot
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)
## 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
(略)

U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)

 modified by tekkamanninja (tekkamanninja@163.com)
 Love Linux

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Video: 240x320x16 20kHz 62Hz
In: serial
Out: serial
Err: serial
Net: dm9000
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
modified by tekkamanninja
(tekkamanninja@163.com)
Love Linux
Hit any key to stop autoboot: 0
[u-boot@MINI2440]# bootd
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)
## 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 ...
(略)
(12)EEPROM 读写指令
eeprom – I2C 接口的EEPROM 读写指令
格式:

eeprom read  addr off cnt
eeprom write addr off cnt
第一个参数addr 是要写入或读出的数据在SDRAM中的存放地址;
第二个参数off 是在EEPROM中的偏移;
第三个参数cnt 是读写的数据字节数。

使用范例:

[u-boot@MINI2440]# md.b 0x30008000 2
30008000: aa aa ..
[u-boot@MINI2440]# eeprom read 0x30008000 10 2

EEPROM @0x50 read: addr 30008000 off 0010 count 2 ... done
[u-boot@MINI2440]# md.b 0x30008000 2
30008000: ff ff ..
 [u-boot@MINI2440]# mm.b 0x30008000
30008000: ff ? aa
30008001: ff ? 55
30008002: aa ? q
[u-boot@MINI2440]# md.b 0x30008000 2
30008000: aa 55 .U
[u-boot@MINI2440]# eeprom write 0x30008000 10 2

EEPROM @0x50 write: addr 30008000 off 0010 count 2 ... done
[u-boot@MINI2440]# eeprom read 0x30008010 10 2

EEPROM @0x50 read: addr 30008010 off 0010 count 2 ... done
[u-boot@MINI2440]# md.b 0x30008010 2
30008010: aa 55 .U
(13)设置和读取RTC指令
date – 设置和读取RTC
格式:

date [MMDDhhmm[[CC]YY][.ss]]
MM:月份

DD:日期

hh:小时

mm 分钟

CC:年份的前两个数字

YY:年份的后两个数字

ss:秒数

使用范例:

[u-boot@MINI2440]# date
Date: 1980-00-06 (Thursday) Time: 20:30:25
[u-boot@MINI2440]# date 041100582010.20
Date: 2010-04-11 (Sunday) Time: 0:58:20
(14)脚本运行指令
run var [...]
var :ENV中的脚本名

使用范例:

[u-boot@MINI2440]# setenv a_run_test echo $bootfile \; version
[u-boot@MINI2440]# run a_run_test
zImage.img

U-Boot 2009.11 ( 4??? 04 2010 - 12:09:25)
(15)系统重启指令
reset – 重启CPU

[u-boot@MINI2440]# reset
resetting ...
 

U-Boot 2009.11 ( 4??? 04 2010 - 12:09:25)

 modified by tekkamanninja (tekkamanninja@163.com)
 Love Linux

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Video: 240x320x16 20kHz 62Hz
In: serial
Out: serial
Err: serial
Net: dm9000
U-Boot 2009.11 ( 4??? 04 2010 - 12:09:25)
modified by tekkamanninja
(tekkamanninja@163.com)
Love Linux
Hit any key to stop autoboot: 0
[u-boot@MINI2440]#
 
 
 
关于OpenOCD的安装配置(以mini2440+OpenJTAG为例)
 
 
 
关于OpenOCD的安装和配置(以mini2440+OpenJTAG为例)


    前几天买了一个OpenJTAG,准备用于U-boot的调试和开发。其实OpenJTAG和openmoko的Debugboard V3在硬件上是一样的。如果你之前在 晕到死 下装过openmoko的Debugboard V3的驱动,那插上OpenJTAG就可以用,并识别为openmoko的Debugboard。openmoko的Debugboard还比OpenJTAG多了一个HUB芯片,多扩出了两个USB口,并添加了专为openmoko手机设计的FPC接口。可以说OpenJTAG就是openmoko的Debugboard的简化版,如果已经有openmoko的Debugboard的朋友,就无须购买OpenJTAG了。
    买来后学习了一下《Eclipse,OpenOCD,OpenJTAG 嵌入式开发教程》(以下简称教程)。首先要学习的是使用OpenJTAG调试的基本原理,这个在教程的“1.2 嵌入式软件的交叉开发系统”中有很好的介绍,大家一定要看一下。之后的关键是如何配置OpenOCD,使其可以认出你开发板上的芯片和flash。在教程中介绍的是使用他们编译好的0.1.0版本的OpenOCD和已经写好的openocd.cfg配置文件。但是作为一个嵌入式Linux学习者,我们要知道这些东西这么用,也得知道这些东西是怎么来的吧。如果以后换了一个硬件平台还是得自己配置。所以借此机会,我通过上网查阅资料,稍微研究了一下OpenOCD的安装配置。在这里我介绍一下我在调试mini2440上的安装配置情况。

--------------------------------------------------------------------------------
一、安装
   如果你使用的是ubuntu系统,可以通过新立德直接安装openocd。这样会自动安装依赖的软件(其中关键的是libftdi).安装好的版本是OpenOCD-0.2.0和libftdi-0.13。这种方法最简单省事,但也有局限性,不同版本的openocd的配置文件会有差异,并不通用。如果你想要使用最新的openocd,那就得自己下载安装了。
   (0)下载最新版libftdi ,这是OpenJTAG使用的FT2232D 芯片的底层驱动库。(如果提示无法找到某些头文件,就用新立德安装就好了。需要先安装libusb-dev)
       下载解包后只要:./configure; make; sudo make install 就好了。
       当然,你也可以通过git的方式 下载源代码。
      
        如果你也想安装ftdi-eeprom(烧写FT2232所连接的e2prom的工具),可用同样的方法下载安装。(必须安装libconfuse-dev)


以下两种方式选一种:

--------------------------------------------------------------------------------

   (1)下载最新版openocd (最新开发版,想做小白鼠的使用)
        在你想要保存openocd的目录下执行:
git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
 

        这样就会在当前目录下创建一个openocd的目录,并将代码下载于此。


   (2)进入openocd的目录,执行:
./bootstrap
./configure --enable-maintainer-mode  --enable-ft2232_libftdi
make
sudo make install
 



我编译安装完后的版本是:
tekkaman@MAGI:~/developer/OpenJTAG/openocd/openocd$ openocd -v
Open On-Chip Debugger 0.4.0-dev-00093-g2b1bd97 (2009-11-08-13:24)
$URL$
For bug reports, read
   
 

--------------------------------------------------------------------------------

  (1)下载最新稳定版openocd (最新稳定版,想稳定的使用)
  (2)解压并进入openocd的目录,执行:
./configure --enable-maintainer-mode  --enable-ft2232_libftdi
make
sudo make install
 



我编译安装完后的版本是:

tekkaman@MAGI:~/桌面/openocd_cfg$ openocd -v

Open On-Chip Debugger 0.3.0 (2009-11-08-13:52)

$URL$

For bug reports, read



 

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

二、配置
   当你在某个目录执行openocd的时候,openocd会自动查找当前文件夹下的openocd.cfg配置文件,如果你在启动时加了 -f 的参数,那么openocd会使用你指定的配置文件。
   配置文件是至关重要的,直接关系到OpenOCD是否可以通过OpenJTAG认到你的开发板和flash芯片。详细的讲解最好是看OpenOCD的用户指南或者在线参考手册。现在我简要介绍一下配置文件的结构。
   配置文件所要配置的命令主要分为以下五个部分:
   
   1、Daemon (守护):主要是配置openocd对外的通讯所使用的本地TCP/IP端口,如gdb、telnet所使用的端口,我的配置如下


telnet_port 4444
tcl_port 6666

#-------------------------------------------------------------------------
# GDB Setup
#-------------------------------------------------------------------------

gdb_port 3333
gdb_breakpoint_override hard
gdb_memory_map enable
gdb_flash_program enable


 

   
   2、interface(接口):也就是openocd所操作的连接开发板的调试器,我使用的是OpenJTAG,配置如下:


interface ft2232
ft2232_vid_pid 0x1457 0x5118
ft2232_layout "jtagkey_prototype_v1"
ft2232_device_desc "USB<=>JTAG&RS232"
 

      如果你使用的是并口或别的调试器,你可以看看在/usr/share/openocd/scripts/interface目录中是否有合适您的文件。
   
   3、target(目标):可以理解为被调试的目标CPU,我的mini2440的target是S3C2440,而被支持的CPU你可以在/usr/share/openocd/scripts/target找到。我个人认为只应该针对的是CPU核心,比如S3C2440的核心是ARM920T,所以同系列的CPU只要将S3C2440的配置稍加改动即可。我的配置如下:


if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME s3c2440
}
if { [info exists ENDIAN] } {
   set _ENDIAN $ENDIAN
} else {
  # this defaults to a bigendian
   set _ENDIAN little
}
if { [info exists CPUTAPID ] } {
   set _CPUTAPID $CPUTAPID
} else {
  # force an error till we get a good number
   set _CPUTAPID 0x0032409d
}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0x0f-expected-id $_CPUTAPID
target create mini2440 arm920t -endian $_ENDIAN -chain-position $_CHIPNAME.cpu -variant arm920t

mini2440 configure -work-area-virt 0 -work-area-phys 0x200000-work-area-size 0x4000 -work-area-backup 1






#reset configuration

reset_config trst_and_srst
 

   
   4、board(主板):指的是目标板上的配置,其实主要是针对板子上的Flash和PLD等可通过JTAG编程的设备配置的。针对mini2440,我的配置是:


# Flash
# 1MBx16 NOR Flash
flash bank cfi 0x0 0x200000 2 2 mini2440 jedec_probe

# NAND
nand device s3c2440 mini2440
 


配置好了这个,就可以通过Openocd来读写nand flash了。但是SST的Nor flash 似乎还不支持烧写。


   5、其他:还有一些JTAG口设置等等,请参考OpenOCD的用户指南。


以下是我的可用的openocd.cfg(针对openocd-0.3.0+OpenJTAG+mini2440):
 文件: openocd.cfg.tar.gz
大小: 0KB
下载: 下载
 




--------------------------------------------------------------------------------



在教程中介绍的烧写u-boot到flash的方法是现将他们的u-boot现导入内存,并启动。使用u-boot去烧写u-boot,这种方法是最快最好的方法。
但是现在的openocd可以直接烧写nand flash(前提是你在配置文件中配置正确)。步骤如下:
(1)启动openocd,并通过telnet登录。
(2)让openocd探测板上的nand flash。
(3)利用nand命令擦除、再写入。
具体命令:
在一个shell中启动
tekkaman@MAGI:~/桌面/openocd_cfg$ sudo openocd
Open On-Chip Debugger 0.3.0 (2009-11-08-13:52)
$URL$
For bug reports, read
   

force hard breakpoints
jtag_nsrst_delay: 100
jtag_ntrst_delay: 100
    TargetName Type Endian TapName State
-- ------------------ ---------- ------ ------------------------------
 0* mini2440 arm920t little s3c2440.cpu unknown
12000 kHz
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain
Info : clock speed 6000 kHz
Info : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg:0x04e, part: 0x0324, ver: 0x0)
Info : Embedded ICE version 2



 



在另一shell中:
tekkaman@MAGI:~/桌面/openocd_cfg$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> poll
background polling: on
TAP: s3c2440.cpu (enabled)
target state: halted
target halted in ARM state due to breakpoint, current mode:Supervisor
cpsr: 0x400000d3 pc: 0x0105daf4
MMU: disabled, D-Cache: disabled, I-Cache: disabled
> nand probe 0
NAND flash device 'NAND 128MiB 3,3V 8-bit' found
> nand erase 0 0 0x60000   #注释:擦除大小必须是0x20000(block size)的整数倍
s3c2440_read_block_data: reading data: 0x91a89e8, 0xbfea3d6a, 6

erased blocks 0 to 3 on NAND flash device #0 'NAND 128MiB 3,3V 8-bit'
> nand write 0 u-boot.bin 0
wrote file u-boot.bin to NAND flash 0 up to offset 0x00043800 in 287.407043s



 
 
 
u-boot-2009.11 for mini2440 Source release
 
 
 
u-boot-2009.11 for mini2440 Source release

    u-boot-2009.11出来了有一个月了,我利用元旦的时间和周末的时间移植到了mini2440上,这次不再生成补丁,而是直接上传至github上供大家下载.下载地址:

下面是针对MINI2440编译好的bin文件,可在MINI2440上直接使用。

 文件: u-boot.bin_tekkaman_2009.11.tar.bz2
大小: 123KB
下载: 下载
 

   

   此次的u-boot-2009.11_tekkaman所实现的功能和原来的u-boot-2009.08最后一个github更新的功能相同.
特性归纳如下:

1、同时支持S3C2410和S3C2440 (2410没板测试)
2、支持串口 xmodem协议 (参考)
3、支持网卡芯片DM9000
4、支持不同NAND Flash的读写,并自动识别所使用的nand flash是512B/page还是2KB/page,实现在64MB\128MB\256MB\1GB NAND flash的启动。

5、支持IIC接口EEPROM的操作,并可保存ENV(参考hiboy的)
6、自动识别S3C2440的启动方式是Nor boot还是Nand boot,调用不同的自拷贝程序,实现不论是Nor boot还是Nand boot,都可以烧写同一个bin文件。(nor flash为SST39VF1601)
7、支持烧写yaffs文件系统映象

8、添加支持读取SD卡中的FAT32文件系统,现在U-boot已经支持从U盘或SD卡上启动Linux 内核。

9、添加支持OpenOCD导入内存启动,其实就是在一切flash识别之前,检测自己是否在内存,如果已在内存就跳过自拷贝程序。

10、支持NEC 3.5寸LCD输出console信息和BMP图片、logo。(参考openmoko)
 


--------------------------------------------------------------------------------

2010年4月13日更新:添加USB下载功能

   很早就知道 的uboot有USB下载功能,也想移植一个,但是很惭愧,我对USB不熟,一开始没有移植成功。后来参考了 hugerat.cublog.cn  和  Apollo5520.cublog.cn  两个高手的移植过程以后,我将其移植到了u-boot-2009.11上。
   由于u-boot-2009.08到u-boot-2009.11改变了很多寄存器基地址的获取函数和寄存器结构体的名字,所以这次的移植在这方面改动较大。此外还删除了一下没用的代码,稍微整理了一下代码,使其在编译时没有出现任何警告。
   这个功能的使用我会再写一篇小教程。
   源码请到我的Git下载:
   下面是编译好的bin文件,可在mini2440中直接使用。由于增加功能以后bin文件大小已经大于了0x40000,所以我也修改了ENV的OFFSET。
U-boot:0x0~0x60000
u-boot参数区: 0x60000~0x80000
 
 

阅读(2071) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Android深入浅出之Audio 第一部分 AudioTrack分析

给主人留下些什么吧!~~