Uboot 命令參數大全

    U-Boot上電啓動後,按任意鍵可以退出自動啓動狀態,進入命令行。

    U-Boot 2010.03 (Sep 25 2011 - 16:18:50)
    DRAM: 64 MB
    Flash: 2 MB
    NAND: 64 MiB
    In: serial
    Out: serial
    Err: serial
    Net: CS8900-0
    Hit any key to stop autoboot: 1

    在命令行提示符下,輸入U-Boot的命令並執行。U-Boot可支持幾十個常用命令,通過這些命令,可以對開發板進行調試,引導Linux內核,還可以擦寫Flash完成系統部署等功能。掌握這些命令的使用,才能夠順利地進行嵌入式系統的開發。

    輸入help命令,可以得到當前U-Boot的所有命令列表。每一條命令後面是簡單的命令說明。

    U-Boot還提供了更加詳細的命令幫助,通過help命令還可以查看每個命令的參數說明。由於開發過程的需要,有必要先把U-Boot命令的用法弄清楚。接下來,根據每一條命令的幫助信息,解釋一下這些命令的功能和參數。

    1)bootm命令

    bootm命令可以引導啓動存儲在內存中的程序映像,這些內存包括RAM和可以永久保存的Flash。

    # help bootm
    bootm - boot application image from memory
    Usage:
    bootm [addr [arg ...]]
        - boot application image stored in memory
            passing arguments 'arg ...'; when booting a Linux kernel,
            'arg' can be the address of an initrd image
    Sub-commands to do part of the bootm sequence. The sub-commands must beissued in 
    the order below (it's ok to not issue all sub-commands):
            start [addr [arg ...]] 
            loados - load OS image
            cmdline - OS specific command line processing/setup
            bdt - OS specific bd_t processing
            prep - OS specific prep before relocation or go
            go - start OS

    ● 第1個參數addr是程序映像的地址,這個程序映像必須轉換成U-Boot的格式。
    ● 第2個參數對於引導Linux內核有用,通常作爲U-Boot格式的RAMDISK映像存儲地址;也可以是傳遞給Linux內核的參數(默認情況下傳遞bootargs環境變量給內核)。

    2)bootp命令

    bootp命令要求DHCP服務器分配IP地址,然後通過TFTP協議下載指定的文件到內存。

    # help bootp
    bootp - boot image via network using BOOTP/TFTP protocol

    Usage:
    bootp [loadAddress] [[hostIPaddr:]bootfilename]

    ● 第1個參數是load Address下載文件存放的內存地址。
    ● 第2個參數是bootfilename要下載的文件名稱,這個文件應該在開發主機上準備好。

    3)cmp命令

    cmp命令可以比較兩塊內存中的內容。.b以字節爲單位;.w以字爲單位;.l以長字爲單位。注意:cmp.b中間不能保留空格,需要連續輸入命令。

    # help cmp
    cmp - memory compare

    Usage:
    cmp [.b, .w, .l] addr1 addr2 count

    ● 第1個參數addr1是第一塊內存的起始地址。
    ● 第2個參數addr2是第二塊內存的起始地址。
    ● 第3個參數count是要比較的數目,單位是字節、字或者長字。

    4)cp命令

    cp命令可以在內存中複製數據塊,包括對Flash的讀寫操作。

    # help cp
    cp - memory copy

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

    ● 第1個參數source是要複製的數據塊起始地址。
    ● 第2個參數target是數據塊要複製到的地址。這個地址如果在Flash中,那麼會直接調用寫Flash的函數操作。所以U-Boot寫Flash就使用這個命令,當然需要先把對應Flash區域擦乾淨。
    ● 第3個參數count是要複製的數目,根據cp.b、cp.w、cp.l分別以字節、字、長字爲單位。

    5)crc32命令

    crc32命令可以計算存儲數據的校驗和。

    # help crc32
    crc32 - checksum calculation

    Usage:
    crc32 address count [addr]
        - compute CRC32 checksum [save at addr]

    ● 第1個參數address是需要校驗的數據起始地址。
    ● 第2個參數count是要校驗的數據字節數。
    ● 第3個參數addr用來指定保存結果的地址。

    6)echo命令

    echo命令回顯參數。

    # help echo
    echo - echo args to console

    Usage:
    echo [args..]
        - echo args to console; \c suppresses newline

    7)erase命令

    erase命令可以擦除Flash。參數必須指定Flash擦除的範圍。

    # help erase
    erase - erase FLASH memory

    Usage:
    erase start end
        - erase FLASH from addr 'start' to addr 'end'
    erase start +len
        - erase FLASH from addr 'start' to the end of sect w/addr 'start'+'len'-1
    erase N:SF[-SL]
        - erase sectors SF-SL in FLASH bank # N
    erase bank N
        - erase FLASH bank # N
    erase all
        - erase all FLASH banks

    按照起始地址和結束地址,start必須是擦除塊的起始地址;end必須是擦除末尾塊的結束地址,這種方式最常用。舉例說明:擦除0x20000~0x3ffff區域命令爲erase 20000 3ffff。

    按照組和扇區,N表示Flash的組號,SF表示擦除起始扇區號,SL表示擦除結束扇區號。另外,還可以擦除整個組,擦除組號爲N的整個Flash組。擦除全部Flash只要給出一個all的參數即可。

    8)nand命令

    nand命令可以通過不同的參數實現對Nand Flash的擦除、讀、寫操作。

    常見的幾種命令的含義如下(具體格式見help nand)。

    # help nand
    nand - NAND sub-system

    Usage:
    nand info - show available NAND devices
    nand device [dev] - show or set current device
    nand read - addr off|partition size
    nand write - addr off|partition size
        read/write 'size' bytes starting at offset 'off'
        to/from memory address 'addr', skipping bad blocks.
    nand erase [clean] [off size] - erase 'size' bytes from
        offset 'off' (entire device if not specified)
    nand bad - show bad blocks
    nand dump[.oob] off - dump page
    nand scrub - really clean NAND erasing bad blocks (UNSAFE)
    nand markbad off [...] - mark bad block(s) at offset (UNSAFE)
    nand biterr off - make a bit error at offset (UNSAFE)

    ● nand erase:擦除Nand Flash。
    ● nand read:讀取Nand Flash,遇到flash壞塊時會出錯。
    ● nand write:寫Nand Flash,nand write命令遇到flash壞塊時會出錯。

    9)flinfo命令

    flinfo命令打印全部Flash組的信息,也可以只打印其中某個組。一般嵌入式系統的Flash只有一個組。

    # help flinfo
    flinfo - print FLASH memory information

    Usage:
    flinfo
        - print information for all FLASH memory banks
    flinfo N
        - print information for FLASH memory bank # N

    10)go命令

    go命令可以執行應用程序。

    # help go
    go - start application at address 'addr'

    Usage:
    go addr [arg ...]
        - start application at address 'addr'
        passing 'arg' as arguments

    ● 第1個參數addr是要執行程序的入口地址。
    ● 第2個可選參數是傳遞給程序的參數,可以不用。

    11)iminfo命令

    iminfo命令可以打印程序映像的開頭信息,包含了映像內容的校驗(序列號、頭和校驗和)。

    # help iminfo
    iminfo - print header information for application image

    Usage:
    iminfo addr [addr ...]
        - print header information for application image starting at
        address 'addr' in memory; this includes verification of the
        image contents (magic number, header and payload checksums)

    第1個參數addr指定映像的起始地址。可選的參數是指定更多的映像地址。

    12)loadb命令

    loadb命令可以通過串口線下載二進制格式文件。

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

    Usage:
    loadb [ off ] [ baud ]
        - load binary file over serial line with offset 'off' and baudrate 'baud'

    13)loads命令

    loads命令可以通過串口線下載S-Record格式文件。

    # help loads
    loads - load S-Record file over serial line

    Usage:
    loads [ off ]
        - load S-Record file over serial line with offset 'off'

    14)mw命令

    mw命令可以按照字節、字、長字寫內存,.b、.w、.l的用法與cp命令相同。

    # help mw
    mw - memory write (fill)

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

    ● 第1個參數address是要寫的內存地址。
    ● 第2個參數value是要寫的值。
    ● 第3個可選參數count是要寫單位值的數目。

    15)nfs命令

    nfs命令可以使用NFS網絡協議通過網絡啓動映像。

    # help nfs
    nfs - boot image via network using NFS protocol

    Usage:
    nfs [loadAddress] [[hostIPaddr:]bootfilename]

    16)printenv命令

    printenv命令打印環境變量。可以打印全部環境變量,也可以只打印參數中列出的環境變量。

    # help printenv
    printenv - print environment variables

    Usage:
    printenv
        - print values of all environment variables
    printenv name ...
        - print value of environment variable 'name'

    17)protect命令

    protect命令是對Flash寫保護的操作,可以使能和解除寫保護。

    help protect
    protect - enable or disable FLASH write protection

    Usage:
    protect on start end
        - protect FLASH from addr 'start' to addr 'end'
    protect on start +len
        - protect FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1
    protect on N:SF[-SL]
        - protect sectors SF-SL in FLASH bank # N
    protect on bank N
        - protect FLASH bank # N
    protect on all
        - protect all FLASH banks
    protect off start end
        - make FLASH from addr 'start' to addr 'end' writable
    protect off start +len
        - make FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1 wrtable
    protect off N:SF[-SL]
        - make sectors SF-SL writable in FLASH bank # N
    protect off bank N
        - make FLASH bank # N writable
    protect off all
        - make all FLASH banks writable

    ● 第1個參數on代表使能寫保護;off代表解除寫保護。
    ● 第2和3個參數是指定Flash寫保護操作範圍,與擦除的方式相同。

    18)rarpboot命令

    rarpboot命令可以使用TFTP協議通過網絡啓動映像,也就是把指定的文件下載到指定地址,然後執行。

    # help rarpboot
    rarpboot - boot image via network using RARP/TFTP protocol

    Usage:
    rarpboot [loadAddress] [[hostIPaddr:]bootfilename]

    ● 第1個參數是loadAddress映像文件下載到的內存地址。
    ● 第2個參數是bootfilename要下載執行的鏡像文件。

    19)run命令

    run命令可以執行環境變量中的命令,後面參數可以跟幾個環境變量名。

    # help run
    run - run commands in an environment variable

    Usage:
    run var [...]
        - run the commands in the environment variable(s) 'var'

    20)setenv命令

    setenv命令可以設置環境變量。

    # help setenv
    setenv - set environment variables

    Usage:
    setenv name value ...
        - set environment variable 'name' to 'value ...'
    setenv name
        - delete environment variable 'name'

    ● 第1個參數是name環境變量的名稱。
    ● 第2個參數是value要設置的值,如果沒有第2個參數,表示刪除這個環境變量。

    21)sleep命令

    sleep命令可以使用TFTP協議通過網絡下載文件,按照二進制文件格式下載。另外,使用這個命令,必須配置好相關的環境變量,例如serverip和ipaddr。

    help sleep
    sleep - delay execution for some time

    Usage:
    sleep N
        - delay execution for N seconds (N is _decimal_ !!!)

    sleep命令可以延遲N秒執行,N爲十進制數。

    22)nm命令

    nm命令可以修改內存,可以按照字節、字、長字操作。

    # help nm
    nm - memory modify (constant address)

    Usage:
    nm [.b, .w, .l] address

    參數address是要讀出並且修改的內存地址。

    23)tftpboot命令

    tftpboot命令可以通過使用TFTP協議在網絡上下載二進制格式文件。

    tftpboot - boot image via network using TFTP protocol

    Usage:
    tftpboot [loadAddress] [[hostIPaddr:]bootfilename]

    24)saveenv 命令

    saveenv命令可以保存環境變量到存儲設備。

    # help saveenv
    saveenv - save environment variables to persistent storage

    Usage:
    saveenv

    這些U-Boot命令爲嵌入式系統提供了豐富的開發和調試功能。在Linux內核啓動和調試過程中,都可以用到U-Boot的命令。但是一般情況下,不需要使用全部命令。比如已經支持以太網接口,可以通過tftpboot命令來下載文件,那麼就沒有必要使用串口下載的loadb。反過來,如果開發板需要特殊的調試功能,也可以添加新的命令。

另外還可以參考 http://www.cs.utsa.edu/~tongpingliu/book/UbootCommands.pdf

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章