uboot 下脚本的开发

来源:互联网 发布:mac ttf字体 编辑:程序博客网 时间:2024/05/17 08:11

http://blog.csdn.net/chocolate001/article/details/7202911

在Uboot下能否将很多命令放在一个脚本文件中,然后一起执行,类似于批处理文件。答案是可以的。

首先在Linux环境创建一个文本文件,在该文件中写好要一起执行的命令,编写的格式和uboot命令行模式下的输入的命令一样。编写完成之后命名成.script文件,例如example.script。

然后将脚本制作成映像文件。使用uboot/tools/下的mkimage命令制作映像。例如mkimage -A ARM -O linux -T script -C none -a 0 -e 0 -n"example script" -d /home/zhangli/example.script example.img。

参数定义如下:

-A,指定目标映像的体系结构,本实验中是ARM

-O,指定目标映像的操作系统,本实验中是Linux;

-T,指定目标映像的类型,本实验中是脚本;

-C,指定目标映像的压缩类型,脚本不需要压缩,none;

-a,设置U-Boot的加载地址(loadaddress),本实验中设为0;

-e,设置U-Boot映像的入口点(entry point)地址,设为0,即从脚本的起始地方开始执行;

-n,设置映像的名称;

-d,制作映像的脚本文件

最后是生成的映像的文件名。参数具体的可选项可以参见http://bbs.chinaunix.net/archiver/?tid-1988490.html。在本实验中,执行上述mkimage命令,会得到如下信息:

 

接下来将制作好的映像(例如,example.img)下载到开发板上(本实验中使用的是DM355),并运行脚本。下载是使用tftp下载,下面以本实验为对命令进行说明。命令如下(加粗的是输入的):

DM355 IPNCVCA1 # tftp 0x82a00000 example.img  //将镜像下载到内存的0x82a00000位置

Found DM9000 ID:90000a46 at address 4000000 !

DM9000 work in 16 bus width

[eth_init]MAC:0:11:22:33:44:55:

TFTP from server 10.10.104.251; our IPaddress is 10.10.104.116

Filename 'example.img'.

Load address: 0x82a00000

Loading: T #

done

Bytes transferred = 133 (85 hex)

DM355 IPNCVCA1 # autoscr  0x82a00000  //执行脚本映像,从内存0x82a00000开始运行

## Executing script at 0x82a00000

ipaddr=10.10.104.116              //脚本的内容,显示环境变量

ipaddr=10.10.104.116

以上是通过两条命令的执行运行脚本的。Uboot中可以自定义环境变量,将以上两条命令放到一个环境变量中,然后运行该环境变量即可。命令如下:

DM355 IPNCVCA1 # setenv testscript 'tftp 0x82a00000example.img;autoscr 0x82a00000'

DM355 IPNCVCA1 # saveenv

Saving Environment to NAND...

Erasing Nand...Writing to Nand... done

DM355 IPNCVCA1 # run testscript

Found DM9000 ID:90000a46 at address 4000000 !

DM9000 work in 16 bus width

[eth_init]MAC:0:11:22:33:44:55:

TFTP from server 10.10.104.251; our IPaddress is 10.10.104.116

Filename 'example.img'.

Load address: 0x82a00000

Loading: *T #

done

Bytes transferred = 133 (85 hex)

## Executing script at 80700000

ipaddr=10.10.104.116

ipaddr=10.10.104.116

 

上面所述的下载下来的脚本映像是放在内存中的,断电之后,再次运行就又需要重新下载,每次都这样十分麻烦,所以将脚本映像存到nand中,运行时再加载到内存。实现的命令如下:

DM355 IPNCVCA1 # tftp 0x82a00000example.img

DM355 IPNCVCA1 # nand write 0x82a000000xf00000 0x80000      //将内存0x82a00000位置开始 写到nand的0xf00000,长度为0x80000(这里的长度根据img文件的大小而定)

DM355 IPNCVCA1 #nand read 0x82a00000 0xf00000 0x80000  //将nand的内容读到内存中

 

NAND read: device 0 offset 0xf00000, size0x80000

 524288 bytes read: OK

DM355 IPNCVCA1 # autoscr 0x82a00000

## Executing script at 82a00000

ipaddr=10.10.104.116

ipaddr=10.10.104.116

DM355 IPNCVCA1 # setenv testscript 'nand read 0x82a00000 0xf00000 0x80000;autosc

r0x82a00000'

DM355 IPNCVCA1 # printenv testscript         //查看环境变量的值

testscript=nand read 0x82a00000 0xf00000 0x80000;autoscr 0x82a00000

DM355 IPNCVCA1 # saveenv

Saving Environment to NAND...

Erasing Nand...Writing to Nand... done

 

重新启动开发板:

Hit any key to stop autoboot:  0

DM355 IPNCVCA1 # run testscript          //运行环境变量

 

NAND read: device 0 offset 0xf00000, size0x80000

 524288 bytes read: OK

## Executing script at 82a00000

ipaddr=10.10.104.116

ipaddr=10.10.104.116

0 0
原创粉丝点击