当前位置:   article > 正文

U-boot(一):uboot基础_uboot和u-boot

uboot和u-boot

        本文主要基于S5PV210探讨uboot的命令,tftp服务器搭建,uboot的源码树分析和编译。

uboot
        部署:uboot(180~400K的裸机程序)在Flash(可上电读取)、OS在FLash(nand)
        启动过程:上电后先执行uboot、uboot初始化DDR和Flash,将OS从Flash中读到DDR中启动OS,uboot结束
        特点:开机直接启动,引导操作系统内核启动并给内核传参

        uboot对Flash和DDR管理:uboot在Flash起始地址(扇区0/1,SoC决定,大小512KB/1MB),环境变量大小32KB左右,kernel大小3MB/5MB,rootfs大小2/3G,其余为自由分区,各分区紧挨排布,不堆叠

tftp服务器搭建

        预备:

                windows10

                unbuntu14.04

                S5PV210开发板

        网络配置:

               windows10配置:以太网配置IP:192.168.100.99,255.255.255.0,192.168.100.1

                ubuntu配置:NAT网卡连接网络,桥接网卡(网络模式选择以太网对应模式):192.168.100.100,255.255.255.0,192.168.100.1

                uboot(已烧录ubbot到210的sd卡)

  1. set ipaddr 192.168.100.27
  2. set gatewayip 192.168.100.1
  3. set serverip 192.168.100.100
  4. save

         uboot的IP配置及网络测试

   

           ubuntu部署tftp

  1. apt-get install tftp-hpa tftpd-hpa xinetd -y
  2. vim /etc/default/tftpd-hpa
  3. # /etc/default/tftpd-hpa
  4. TFTP_USERNAME="tftp"
  5. TFTP_DIRECTORY="/root/tftp_file"
  6. TFTP_ADDRESS="0.0.0.0:69"
  7. TFTP_OPTIONS="-l -c -s"
  8. vim /etc/xinetd.d/tftp
  9. service tftp
  10. {
  11. socket_type = dgram
  12. wait = yes
  13. disable = no
  14. user = root
  15. protocol = udp
  16. server = /usr/sbin/in.tftpd
  17. server_args = -s /root/tftp_file
  18. #log_on_success += PID HOST DURATION
  19. #log_on_failure += HOST
  20. per_source = 11
  21. cps =100 2
  22. flags =IPv4
  23. }
  24. service tftpd-hpa start
  25. mkdir /root/tftp_file
  26. chmod 777 /root/tftp_file
  27. 测试
  28. cd ~
  29. touch /root/tftp_file/a.txt
  30. tftp 127.0.0.1
  31. get a.txt
  32. quit
  33. ls /root/a.txt
  34. root目录下有下载完成的a.txt(来自/root/tftp_file)

          tftp测试

  1. ububtu:上传zImage到/root/tftp_file
  2. uboot:
  3. tftp 30008000 zImage
  4. movi read kernel 30008000
  5. bootm 30008000

      

uboot命令
        基础
                bdinfo:查看开发板基础信息             

  1. x210 # bdinfo
  2. arch_number = 0x00000998
  3. env_t = 0x00000000
  4. boot_params = 0x30000100
  5. DRAM bank = 0x00000000
  6. -> start = 0x30000000
  7. -> size = 0x10000000
  8. DRAM bank = 0x00000001
  9. -> start = 0x40000000
  10. -> size = 0x10000000
  11. ethaddr = 00:40:5C:26:0A:5B
  12. ip_addr = 192.168.1.88
  13. baudrate = 115200 bps


                version:查看uboot版本

  1. x210 # version
  2. U-Boot 1.3.4-dirty (May 21 2016 - 18:17:00) for x210


                print/printenv:打印环境变量
                set/setenv:设置(删除)环境变量
                save/saveenv:保存环境变量
                reset:重启
                poweroff:关机
                注意:设置和打印和删除的环境变量均为uboot启动时从flash中读到DDR中的环境变量,save可将set设置的命令同步到flash中

        ddr
                md:打印内存值
                md [.b, .w, .l] address [# of objects]
                b:byte(1字节),w:word(2字节),l:long(4字节)
                address:起始地址,后跟字节长度
        

  1. x210 # help md
  2. md [.b, .w, .l] address [# of objects]
  3. - memory display
  4. x210 # md.b 30000000
  5. 30000000: f2 28 3e 74 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b .(>t..4.......I.
  6. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  7. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  8. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  9. x210 # md.w 30000000
  10. 30000000: 28f2 743e cc83 9a34 9aae a298 d7c6 9b49 .(>t..4.......I.
  11. 30000010: abff b1bb fadb 3c55 ff9f f4ff be7e d1ff ......U<....~...
  12. 30000020: fcf3 d73f fffe e2fe b79f ebde ff9f efae ..?.............
  13. 30000030: f58e e7de f93d e27c f86e f81f eddc fd7e ....=.|.n.....~.
  14. 30000040: afbf fb93 7d6d 41ef febf edd8 6ffb 4bee ....m}.A.....o.K
  15. 30000050: c259 79ed dd59 ae78 c718 cdca 2f49 fcea Y..yY.x.....I/..
  16. 30000060: fdb5 8e6a 3def e3be 6eab feed def7 eeab ..j..=...n......
  17. 30000070: f6f1 f6be 0935 59bd f0ff eab6 0f9b dc5b ....5..Y......[.
  18. x210 # md.l 30000000
  19. 30000000: 743e28f2 9a34cc83 a2989aae 9b49d7c6 .(>t..4.......I.
  20. 30000010: b1bbabff 3c55fadb f4ffff9f d1ffbe7e ......U<....~...
  21. 30000020: d73ffcf3 e2fefffe ebdeb79f efaeff9f ..?.............
  22. 30000030: e7def58e e27cf93d f81ff86e fd7eeddc ....=.|.n.....~.
  23. 30000040: fb93afbf 41ef7d6d edd8febf 4bee6ffb ....m}.A.....o.K
  24. 30000050: 79edc259 ae78dd59 cdcac718 fcea2f49 Y..yY.x.....I/..
  25. 30000060: 8e6afdb5 e3be3def feed6eab eeabdef7 ..j..=...n......
  26. 30000070: f6bef6f1 59bd0935 eab6f0ff dc5b0f9b ....5..Y......[.
  27. 30000080: 1141df55 9f98bd6a e3d83e9e 39fcabf5 U.A.j....>.....9
  28. 30000090: ac479f9a dca771e2 6b61c763 cec95d3d ..G..q..c.ak=]..
  29. 300000a0: a4c8ceff ffbbebaa ea22aebf fa8ecf9e ..........".....
  30. 300000b0: ed7bfffe a1277d2b f4b4ff56 cb81deff ..{.+}'.V.......
  31. 300000c0: d59d27e4 af0d3eed beed2ebf b399b789 .'...>..........
  32. 300000d0: 5cd5bd57 ffa8bef9 b52cf9a9 ede94ff6 W..\......,..O..
  33. 300000e0: 3eedc9f7 9ecab7ff 6a0bf777 6b1b46f9 ...>....w..j.F.k
  34. 300000f0: 73e639bb 255a8ccf 2ebfb8cb 7a3a5d37 .9.s..Z%....7]:z
  35. x210 #


                nm:修改指定内存地址的数据
                nm [.b, .w, .l] address

  1. x210 # md.b 30000000
  2. 30000000: f2 28 3e 74 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b .(>t..4.......I.
  3. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  4. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  5. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  6. x210 # nm.b 30000000
  7. 30000000: f2 ? 11
  8. 30000000: 11 ? q
  9. x210 # md.b 30000000
  10. 30000000: 11 28 3e 74 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b .(>t..4.......I.
  11. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  12. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  13. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.


                mm:递归修改指定内存地址的数据
                mm [.b, .w, .l] address
       

  1. x210 # mm.b 30000000
  2. 30000000: 11 ? f2
  3. 30000001: 28 ? 11
  4. 30000002: 3e ? q
  5. x210 # md.b 30000000
  6. 30000000: f2 11 3e 74 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b ..>t..4.......I.
  7. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  8. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  9. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.


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

  1. x210 # mw.b 30000000 668899 2
  2. x210 # md.b 30000000
  3. 30000000: 99 99 3e 74 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b ..>t..4.......I.
  4. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  5. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  6. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  7. x210 # mw.b 30000000 668899 4
  8. x210 # md.b 30000000
  9. 30000000: 99 99 99 99 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b ......4.......I.
  10. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  11. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  12. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  13. x210 #

 
                cp将原地址数据复制到目标地址
                cp [.b, .w, .l] source target count

  1. x210 # md.b 30000000
  2. 30000000: 99 99 99 99 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b ......4.......I.
  3. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  4. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  5. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  6. x210 # md.b 30008000
  7. 30008000: f2 28 7f f7 9f ef ff ba bf ba f8 eb d6 f7 ba ff .(..............
  8. 30008010: ff ab f3 e3 db fa 4d 3e df df c6 f6 be ab ee f9 ......M>........
  9. 30008020: f7 fc bf ff 7f ff bf e3 bf 9f df ef 97 ff ee e3 ................
  10. 30008030: 8e f5 de ef 39 f9 fe e7 ff ff ff fa ff ff ff fb ....9...........
  11. x210 # cp.b 30000000 30008000 4
  12. x210 # md.b 30008000
  13. 30008000: 99 99 99 99 9f ef ff ba bf ba f8 eb d6 f7 ba ff ................
  14. 30008010: ff ab f3 e3 db fa 4d 3e df df c6 f6 be ab ee f9 ......M>........
  15. 30008020: f7 fc bf ff 7f ff bf e3 bf 9f df ef 97 ff ee e3 ................
  16. 30008030: 8e f5 de ef 39 f9 fe e7 ff ff ff fa ff ff ff fb ....9...........


                cmp:比较两个地址段数据
                cmp [.b, .w, .l] addr1 addr2 count

  1. x210 # md.b 30000000
  2. 30000000: 99 99 99 99 83 cc 34 9a ae 9a 98 a2 c6 d7 49 9b ......4.......I.
  3. 30000010: ff ab bb b1 db fa 55 3c 9f ff ff f4 7e be ff d1 ......U<....~...
  4. 30000020: f3 fc 3f d7 fe ff fe e2 9f b7 de eb 9f ff ae ef ..?.............
  5. 30000030: 8e f5 de e7 3d f9 7c e2 6e f8 1f f8 dc ed 7e fd ....=.|.n.....~.
  6. x210 # md.b 30008000
  7. 30008000: 99 99 99 99 9f ef ff ba bf ba f8 eb d6 f7 ba ff ................
  8. 30008010: ff ab f3 e3 db fa 4d 3e df df c6 f6 be ab ee f9 ......M>........
  9. 30008020: f7 fc bf ff 7f ff bf e3 bf 9f df ef 97 ff ee e3 ................
  10. 30008030: 8e f5 de ef 39 f9 fe e7 ff ff ff fa ff ff ff fb ....9...........
  11. x210 # md.b 30009000
  12. 30009000: 5e f3 dd ff d7 f9 db e5 dc 9f df e7 f3 73 fd f4 ^............s..
  13. 30009010: 3c ff b6 ef c7 f5 bf f4 6f fd a6 f7 ff f2 a5 f7 <.......o.......
  14. 30009020: f7 ff ff ff f6 d7 e9 f3 cf 3f b3 ef ff 7f fc e1 .........?......
  15. 30009030: dc fd 77 f3 cd ff fd fb ed 93 ff ef 3f ff fe ec ..w.........?...
  16. x210 # cmp.b 30000000 30008000 1
  17. Total of 1 byte were the same
  18. x210 # cmp.b 30000000 30009000 1
  19. byte at 0x30000000 (0x99) != byte at 0x30009000 (0x5e)
  20. Total of 0 bytes were the same
  21. x210 #

        网络
                ipaddr:地址
                serverip:tftp服务器地址
                dhcp:自动获取地址
                ping:查看网络

        启动
                boot:读取环境变量bootcmd启动Linux
                bootz:启动 zImage 
                bootm: 启动 uImage 
                Image为内核映像文件
                zImage为映像压缩文件
                uImage是uboot映像文件,在zImage前加上64字节头,说明内核的版本、加载位置、生成时间、大小等信息

        flash
                nand scrub:擦除整个NAND,擦除bad block标记
                nand erase addr1 count:擦除NAND,count擦除字节数
                nand write addr offset count:内存数据写入NAND,offset是偏移地址
                nand read addr offset count :NAND数据读取到内存
                nand bad:测试NAND FLASH坏块    

                mmc info 设备的信息

  1. x210 # mmcinfo
  2. Device: S3C_HSMMC0
  3. Manufacturer ID: 11
  4. RCA: 0
  5. OEM: 100
  6. Name: 004GA
  7. Tran Speed: 52000000
  8. Rd Block Len: 512
  9. MMC version 4.0
  10. High Capacity: Yes
  11. Size: 3776MB (block: 7733248)
  12. Bus Width: 4-bit


                mmc rescan [mode] 扫描开发板上MMC设备,包括EMMC和SD卡
                mmc list 查看开发板MMC设备

  1. x210 # mmc list
  2. S3C_HSMMC0_dev0
  3. S3C_HSMMC2_dev1


                mmc dev 切换当前MMC设备:mmc dev [dev] [part]
                [dev]切换MMC设备号,[part]分区号
                mmc part查看分区
                mmc read 读取mmc设备数据 

                movi init  初始化moviNAND并显示信息
                movi read  {u-boot | kernel} {addr} [bytes(hex)] 读取某地址sd/mmc信息
                movi write {fwbl1 | u-boot | kernel} {addr} [bytes(hex)]写入数据sd/mmc的某地址

uboot源码树

        api:硬件功能函数API
        api_examples:硬件功能函数API示例代码
        board:开发板相关,部分依据厂商名分类,部分依据芯片型号分类
        common:cmd和env相关及控制台、crc校验等
        cpu:架构相关(arch目录)
        doc:说明文档
        drivers:驱动代码
        examples:示例代码
        fs:文件系统
        include:头文件
        lib相关:库文件,lib_arm是arm架构库文件,lib_generic是通用库文件
        libfdt:设备树
        nand_spl:nand相关
        net:网络相关
        onenand:onenand相关
        post:上电自检程序
        sd_fusing:烧录uboot到SD卡的代码
        tools:工具
        Makefile:uboot源代码的主Makefile(主要)
        arm_config.mk:arm架构编译的makefile

PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__


        config.mk:配置相关的Makefile
        rules.mk:uboot的Makefile使用规则

  1. _depend: $(obj).depend
  2. $(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(SRCS)
  3. @rm -f $@
  4. @for f in $(SRCS); do \
  5. g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
  6. $(CC) -M $(HOST_CFLAGS) $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
  7. done


        mkconfig:uboot配置阶段开发板类型配置(主要)
        mk:编译脚本

  1. #!/bin/sh
  2. make distclean
  3. make x210_sd_config
  4. make -j4


        MAKEALL:协助编译uboot的脚本
        image_split:分割uboot.bin到BL1的脚本

split -b 8064 u-boot.bin bl2.bin


        mkmovi:iNand/SD卡启动有关
        Changelog文:版本修改记录
        gitignore:git工具文件

git ls-files -i --exclude-standard


        COPYING:GPL许可版权声明
        MAINTAINERS:维护者
        CREDITS:鸣谢
        README:导读

 

编译uboot 

 

        基于210官方的qt包中的uboot包编译烧录

  1. 解压包
  2. tar -jxvf qt_x210v3s_160307.tar.bz2 -C qt_x210v3s_160307
  3. cd qt_x210v3s_160307/uboot
  4. 配置编译工具链(配置自己的工具链路径)
  5. vim Makefile
  6. #CROSS_COMPILE = arm-linux-
  7. #CROSS_COMPILE = /usr/local/arm/4.4.1-eabi-cortex-a8/usr/bin/arm-linux-
  8. #CROSS_COMPILE = /usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-
  9. #CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
  10. CROSS_COMPILE = /root/arm-2009q3/bin/arm-none-linux-gnueabi-
  11. #############方式(1)##############
  12. 生成开发板配置
  13. make x210_sd_config
  14. 编译
  15. make -j4
  16. 生成u-boot.bin可用于烧录
  17. ############方式(2)###############
  18. ./mk
  19. 生成u-boot.bin可用于烧录
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/730951
推荐阅读
相关标签
  

闽ICP备14008679号