您的位置:首页 > 其它

uboot部分命令使用心得

2013-01-22 17:38 351 查看
1.用help可以查看当前uboot支持的命令

默认的,输入help,可以查看到目前uboot支持的所有所有命令的名称和简单的解释,比如:

# help

? - alias for 'help'

asdebug - AS3536 debug shell

base - print or set address offset

bdinfo - print Board Info structure

bootm - boot application image from memory

bootp - boot image via network using BOOTP/TFTP protocol

cmp - memory compare

cp - memory copy

crc32 - checksum calculation

erase - erase FLASH memory

ext2load- load binary file from a Ext2 filesystem

ext2ls - list files in a directory (default /)

flinfo - print FLASH memory information

go - start application at address 'addr'

help - print online help

loadb - load binary file over serial line (kermit mode)

loads - load S-Record file over serial line

loady - load binary file over serial line (ymodem mode)

loop - infinite loop on address range

md - memory display

mm - memory modify (auto-incrementing)

mmc - mmc - MMC sub system

mmcinfo - mmcinfo <dev num>-- display MMC info

mtest - simple RAM test

mw - memory write (fill)

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

reset - Perform RESET of the CPU

saveenv - save environment variables to persistent storage

setenv - set environment variables

tftpboot- boot image via network using TFTP protocol

version - print monitor version

2.help加上命令名,可以查看该命令详细的解释

对于这个,估计对于很多人,早就知道了。不过,对于我,之前自己也是一直没注意,不了解一个命令的具体用法,很是郁闷。后来无意间发现这个用法。而且,如果能这么用,应该是你的uboot中有这个:

#define CONFIG_SYS_LONGHELP /* undef to save memory */

意思是支持Long Help,如果真是需要节省空间,可以取消此定义。不过实际情况多数是,定义了几K的空间存储这些命令和相关的信息,空间足够,所以一般最好加上此定义。

其用法比如:

# help cp

cp [.b, .w, .l] source target count

- copy memory

3.cp操作,已经包含了对于(Nor)Flash的操作

对于这点,是对应我之前,在自己实现了对应的Nor Flash的命令后,

想要通过命令行对Nor Flash的读写,结果自己去多余地实现了一些命令,

最后却发现,本来系统就有cp等命令,就已经包含了对Flash的操作。

对应地,代码里面也能找到的,感兴趣的自己去看common\cmd_mem.c中do_mem_cp()的:

#ifndef CONFIG_SYS_NO_FLASH

/* check if we are copying to Flash */

if ( (addr2info(dest) != NULL)

#ifdef CONFIG_HAS_DATAFLASH

&& (!addr_dataflash(dest))

#endif

) {

int rc;

puts ("Copy to Flash... ");

rc = flash_write ((char *)addr, dest, count*size);

if (rc != 0) {

flash_perror (rc);

return (1);

}

puts ("done\n");

return 0;

}

#endif

4.使用setenv变量时候,变量里面有特殊字符时,其前面要加转义字符"\"

对于setenv的基本用法是:

# help setenv

setenv name value ...

- set environment variable 'name' to 'value ...'

setenv name

- delete environment variable 'name'

只不过要注意的是,如果一个变量名称中间带一些特殊字符,比如我上次遇到的分号";"那么,就要用转义字符反斜杠"\"了,否则,默认即使是对于setenv,遇到";"就结束了,后面的内容,识别成第二条命令了。

比如对于,

bootcmd=tftpboot uImage;bootm 0x40f00000

我想要设置成

bootcmd=tftpboot crifan/uImage;bootm 0x40f00000

那么就要写成:

setenv bootcmd tftpboot crifan/uImage\;bootm 0x40f00000

如果写成

setenv bootcmd tftpboot crifan/uImage;bootm 0x40f00000

那么实际执行的是:

setenv设置bootcmd为tftpboot crifan/uImage,然后继续执行bootm 0x40f00000

其他类似的,如果命令中有特殊字符,也是类似";",要加上转义的"\"。

注:

(1)如果uboot代码里面实现了saveenv,那么在setenv后,可以用saveenv去将所有的变量都存储起来。具体存到哪里,要根据是uboot中的定义决定。比如

#define CONFIG_ENV_IS_IN_SPI_FLASH

就是定义成存储环境变量到SPI Flash里面。其他有的也有存到Nand Flash里面的。

(2)变量里面的数字,不论是否加0x前缀,都是16进制的。比如写了1000,实际是0x1000,注意不要搞错了。

5.fatls/ext2ls 中的interface的含义

具体用法是:

# help ext2ls

ext2ls <interface> <dev[:part]> [directory]

- list files from 'dev' on 'interface' in a 'directory'

但是,看help,并不能让我完全明白到底如何用。后来无意间在百度到一个帖子里,看到了具体用法:

fatls usb 0

所以才明白,这些命令中的interface,就是指具体是什么介质(usb,mmc等)

所以,对于自己的sd卡,此处可以这么用:

fatls mmc 0

就可以显示fat里面的内容。

题外话:不过,此处fatls和fatload,都有bug,一个是fatls根目录显示有问题,另外,好像对于FAT16(即FAT)支持也有问题,网上那个高手只是说了问题,并没完全给解决代码,自己目前不熟悉fat表,所以无法解决问题。。。

6.输入部分命令,也可以识别

这个是后来才发现的,打印环境变量是用:

printenv- print environment variables

不过,无意间输入print,printe等,uboot也能识别,再加上也遇到过对于某个usbslave命令,我只输入了usb,也可以运行usbslave。所以才明白,原来Uboot里面,是可以识别部分命令的。应该类似于Linux下面输入部分命令支持Tab键补全的意思。

7. md/cp/mw/cmp等内存操作命令,可以加.b .w .l分别以字节,字,双字去操作

这个算不上需要注意的,只不过自己之前不知道,后来才知道用法而已。

其实本身命令说明里面已经有了:

# help md

md [.b, .w, .l] address [# of objects]

- memory display

# help cp

cp [.b, .w, .l] source target count

- copy memory

# help mw

mw [.b, .w, .l] address value [count]

- write memory

说明一下,md是memory display,mw是memory write,cp是copy。

这些内存操作命令,都可以通过加后缀.b .w .l去实现以不同的位宽去操作。

比如:

# md.b 0x40000000

40000000: 80 a0 00 00 00 00 01 00 00 90 00 02 00 00 00 01 ................

40000010: 80 00 00 10 00 01 00 00 00 00 00 10 00 00 04 00 ................

40000020: 00 00 00 10 00 00 10 20 00 00 00 00 00 04 00 01 ....... ........

40000030: 40 00 00 00 80 00 00 00 80 00 00 01 04 00 00 00 @...............

# md.w 0x40000000

40000000: a080 0000 0000 0001 9000 0200 0000 0100 ................

40000010: 0080 1000 0100 0000 0000 1000 0000 0004 ................

40000020: 0000 1000 0000 2010 0000 0000 0400 0100 ....... ........

40000030: 0040 0000 0080 0000 0080 0100 0004 0000 @...............

40000040: 0020 0000 0000 0000 0000 0000 0000 0000 ...............

40000050: 0020 2008 0008 1000 1004 0000 0008 0100 .. ............

40000060: 0200 0040 0040 0000 0008 1002 0040 0100 ..@.@.......@...

40000070: 0000 0000 0080 0000 0000 0200 0008 0000 ................

# md.l 0x40000000

40000000: 0000a080 00010000 02009000 01000000 ................

40000010: 10000080 00000100 10000000 00040000 ................

40000020: 10000000 20100000 00000000 01000400 ....... ........

40000030: 00000040 00000080 01000080 00000004 @...............

40000040: 00000020 00000000 00000000 00000000 ...............

40000050: 20080020 10000008 00001004 01000008 .. ............

40000060: 00400200 00000040 10020008 01000040 ..@.@.......@...

40000070: 00000000 00000080 02000000 00000008 ................

40000080: 00000000 00000000 00000004 20000000 ...............

40000090: 00000000 00400000 20000004 00000000 ......@.... ....

400000a0: 00000000 01000000 02000000 00000000 ................

400000b0: 02000004 00000000 00000000 00000000 ................

400000c0: 00000800 02000000 10410000 20000104 ..........A....

400000d0: 01000000 01000000 00000008 00001000 ................

400000e0: 00000000 00000000 00000140 00000004 ........@.......

400000f0: 30000000 02840008 00000000 20400000 ...0..........@

其他类似的,都是一样的用法。比如cp.b,就是以字节为单位去执行拷贝操作
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: