Uboot的使用-1

    xiaoxiao2021-12-14  19

    一、什么是uboot U-Boot -- the Universal Boot Loader  u---通用的,所谓的通用:    1、支持多种架构的CPU:x86、powerPC、ARM、MIPS....    2、支持多种CPU的电子板:mini2440、smdkv210、smdk2410.......    3、支持多种操作系统,如:linux、wince、vxworks...... boot是一个bootloader    1、boot       做CPU级初始化、板级初始化,完成一个硬件平台的启动    2、loader       加载操作系统内容,并启动内核.....,后面与uboot没有任何关系 uboot是一个源码开放的bootloader,源码可以随意修改,并免费使用。 uboot的官网: ftp://ftp.denx.de/pub/u-boot/ http://www.denx.de/wiki/U-Boot/WebHome 注意: 我们uboot官网下载源码的时候,该uboot源码必须支持Samsung  S5PV210,最 好能支持基于S5PV210的某个电子板(SMDKV210). ================================================================== ======================================= 二、uboot的使用 1、查看uboot支持的命令 GEC210 # ? GEC210 # help ?       - alias for 'help' autoscr - run script from memory base     - print or set address offset bdinfo  - print Board Info structure 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 dcache  - enable or disable data cache dhcp    - invoke DHCP client to obtain IP/boot params dnw     - initialize USB device and ready to receive for Windows  server (specific) echo    - echo args to console erase   - erase FLASH memory exit    - exit script ext2format - disk format by ext2 ext2load- load binary file from a Ext2 filesystem ext2ls  - list files in a directory (default /) ext3format - disk format by ext3 ext4format - disk format by ext4 fastboot- use USB Fastboot protocol fatformat - disk format by FAT32 fatinfo - print information about filesystem fatload - load binary file from a dos filesystem fatls   - list files in a directory (default /) fdisk   - fdisk for sd/mmc. flinfo  - print FLASH memory information go      - start application at address 'addr' help    - print online help 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 loady   - load binary file over serial line (ymodem mode) loop     - infinite loop on address range md       - memory display mm       - memory modify (auto-incrementing) MMC sub systemprint MMC informationmovi - sd/mmc r/w sub system  for SMDK board mtest    - simple RAM test mw       - memory write (fill) nand    - NAND sub-system 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 reset   - Perform RESET of the CPU reginfo - print register information reset   - Perform RESET of the CPU run     - run commands in an environment variable saveenv - save environment variables to persistent storage sdfuse  - read images from FAT partition of SD card and write them  to booting device. setenv  - set environment variables sleep   - delay execution for some time test    - minimal test like /bin/sh tftpboot- boot image via network using TFTP protocol version - print monitor version 以上命令是uboot通用的命令,与具体的硬件平台和操作系统没有关系。 我们可不可以向uboot中,增加一个命令??? 可以!! 2、version GEC210 # version U-Boot 1.3.4 (Aug  9 2013 - 15:03:53) for GEC210 3、bdinfo(bd) GEC210 # bdinfo arch_number = 0x00000998  //uboot针对board的一个ID号,会与kernel对 应ID做对比,如果相符,内核就会启动。 env_t       = 0x00000000 boot_params = 0x30000100  //uboot在启动kernel的时候,会传递参数给 kernel,uboot将参数放在0x30000100地址上 DRAM bank   = 0x00000000  //DDR2 ch0 -> start    = 0x30000000 -> size     = 0x10000000 DRAM bank   = 0x00000001  //DDR2 ch1 -> start    = 0x40000000 -> size     = 0x10000000 ethaddr     = 00:40:5C:26:0A:5B //MAC地址 ip_addr     = 192.168.1.190 //ip地址 baudrate    = 115200 bps  //串口的波特率 4、printenv(pri) GEC210 # printenv baudrate=115200 ethaddr=00:40:5c:26:0a:5b netmask=255.255.255.0 bootargs=console=ttySAC0,115200 init=/linuxrc root=/dev/mtdblock4  rootfstype=yaffs rw machid=0x998 ipaddr=192.168.1.190 gatewayip=192.168.1.1 bootdelay=5 bootcmd=nand read 0x30008000 0x600000 0x500000;bootm 0x30008000 serverip=192.168.1.9 stdin=serial stdout=serial stderr=serial 1)bootargs  ----启动参数  args ---arguments    告诉内核,如何找到rootfs,并且启动linux的第一个进程(init)   (1)console=ttySAC0,115200 //内核使用的控制台是uart0,115200bps   (2)init=/linuxrc 启动的linux第一个进程是/linuxrc  ,即启动shell 命令环境        lrwxrwxrwx    1 root     root            11 Sep  5  2012  linuxrc -> bin/busybox        busybox---->生成shell工具   (3)root=/dev/mtdblock4  //存放的是rootfs(nand的第四个分区),告 诉内核去哪里挂在rootfs        [root@YueQian /]# ls /dev/mtdblock4 -l        brw-rw----    1 root     root       31,   4 Jan  1 13:08  /dev/mtdblock4  //nand flash的第四个分区   (4)rootfstype=yaffs rw        挂在的rootfs的格式,并且是可读写的。    #setenv bootargs 'console=ttySAC0,115200 init=/linuxrc  root=/dev/mtdblock4 rootfstype=yaffs rw'    #saveenv 2)machid=0x998 uboot针对该平台的机器ID    #setenv machid 0x999 3)ipaddr=192.168.1.190   //GEC210平台IP #setenv ipaddr 192.168.1.110 #saveenv 4)gatewayip=192.168.1.1 #setenv gatewayip 192.168.1.1 #saveenv 5)serverip=192.168.1.9 #setenv serverip 192.168.1.9 #saveenv 技巧: # setenv  severip 192.168.1.9 #setenv severip  #saveenv 6)bootdelay=5  //启动操作系统的等待时间 #setenv bootdelay 3 #saveenv 7)bootcmd 启动命令 cmd ---command    告诉uboot去哪里找内核映像(uImage/zImage),并且启动内核映像    (1)read 0x30008000 0x600000 0x500000; 从nand flash的0x600000地址拷贝0x500000大小的内容(linux的内 核映像)到DDR2内存的0x30008000地址下    (2)bootm 0x30008000         从0x30008000地址上开始启动内核映像         从nand中启动内核     #setenv  bootcmd 'nand read 0x30008000 0x600000 0x500000;bootm  0x30008000'     #saveenv     自动下载裸机程序,并启动裸机程序     #setenv bootcmd 'tftp 0x30000000 led.bin; go 0x30000000'     #saveenv     从网络启动内核映像     #setenv bootcmd 'tftp 0x30008000 uImage; bootm 0x30008000'     #saveenv      ================================================================== ======================================= 三、如何应用uboot去更新u-boot.bin、zImage、rootfs.img 思路:先使用tftp将要更新的文件下载到DDR2内存中,然后在进行nand的烧写 1、如何更新uboot #tftp 0x400000000 u-boot.bin #nand erase 0x0 0x100000 #nand write 0x40000000 0x0 0x100000 2、使用uboot更新自zImage #tftp 0x40000000 zImage #nand erase 0x600000 0x500000 #nand write 0x40000000 0x600000 0x500000 3、使用uboot更新rootfs #tftp 0x40000000 rootfs.img #nand erase 0xe00000 0xf200000 //242MB #nand write.yaffs 0x40000000 0xe00000  0xxxxx  //0xxxx--->实际的下 载大小,tftp的传输后的报告 ================================================================== ======================================= 四、uboot输出 stage1:相当于BL1,这段代码完成CPU级初始化,最关键初始化时钟和内存, 该阶段代码是汇编写的。 stage2:相当于BL2,使用C做的,这部分代码都是通用的代码。主要是完成 uboot工具和操作系统的启动..... //1、在ARM汇编,BL1 OK  //2、BL2 U-Boot 1.3.4 (Aug  9 2013 - 15:03:53) for GEC210 CPU:  S5PV210@1000MHz(OK)         APLL = 1000MHz, HclkMsys = 200MHz, PclkMsys = 100MHz         MPLL = 667MHz, EPLL = 96MHz                        HclkDsys = 166MHz, PclkDsys = 83MHz                        HclkPsys = 133MHz, PclkPsys = 66MHz                        SCLKA2M  = 200MHz Serial = CLKUART  Board:   GEC210 DRAM:    512 MB Flash:   8 MB   //nor flash SD/MMC: 3724MB NAND:    256 MB  In:      serial Out:     serial Err:     serial backlight_brigness_init Enter into Normal mode Hit any key to stop autoboot:  0  //3、去启动设备(nand flash、SD卡),找内核映像(uImage、zImage),拷 贝到DDR2内存中 NAND read: device 0 offset 0x600000, size 0x500000 Main area read (40 blocks):  5242880 bytes read: OK get_format //4、uboot去分析内核映像文件的头(uImage) -------- 1 -------- ## Booting kernel from Legacy Image at 30008000 ...    Image Name:   linux-2.6.35.7    Created:      2013-07-02   7:40:27 UTC    Image Type:   ARM Linux Kernel Image (uncompressed)    Data Size:    4065428 Bytes =  3.9 MB    Load Address: 30008000  //加载地址    Entry Point:  30008040  //入口地址    Verifying Checksum ... OK get_format -------- 1 --------    XIP Kernel Image ... OK OK Using machid 0x998 from environment //5、启动内核 Starting kernel ... Uncompressing Linux... done, booting the kernel. //6、调用了kernel [    0.000000] Initializing cgroup subsys cpu [    0.000000] Linux version 2.6.35.7-GEC210  (root@localhost.localdomain) (gcc version 4.4.1 (Sourcery G++ Lite  2009q3-67) ) #183 PREEMPT Tue Jul 2 15:38:19 CST 2013 [    0.000000] CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7),  cr=10c53c7f [    0.000000] CPU: VIPT nonaliasing data cache, VIPT nonaliasing  instruction cache

    [    0.000000] Machine: GEC210

    转载请注明原文地址: https://ju.6miu.com/read-969726.html

    最新回复(0)