zoukankan      html  css  js  c++  java
  • 从0移植uboot(三) _编译最小可用uboot

    来源:Linux社区  作者:xiaojiang1025  :http://www.linuxidc.com/Linux/2017-02/141020.htm

     

    前两篇介绍了uboot-2013.01的配置原理以及大体的运行流程,本文将讨论如何对uboot源码进行配置,将一个可用的uboot烧录到SD卡中。

    定制自己的core board

    市面上能买到的开发板的核心板基本都是基于官方参考板制作的,所以虽然标准操作是"定制"自己的core board,但鉴于我的板子的核心板是基于三星的参考板做的,所以我们做的主要工作就是按照(一)中的原理,编写(山寨)我们"自己的"核心板配置。我们需要的目录是"board/samsung/origen/",这部分的主要功能就是将其中的文件"改名字"。首先来认识一下原版以示尊重

    board/samsung/origen/

    $ls board/samsung/origen/
    lowlevel_init.S  Makefile  mem_setup.S  mmc_boot.c  origen.c  origen_setup.h  tools

    接下来就开始我们的山寨工作

    //山寨参考板目录
    $cp -arf ./board/samsung/origen ./board/samsung/xboot
    
    //山寨关键文件
    $mv ./board/samsung/xboot/origen.c ./board/samsung/xboot/xboot.c

    uboot的编译系统和内核的类似,所以Makefile也得改(./board/samsung/xboot/Makefile)
    from

     30 ifndef CONFIG_SPL_BUILD
     31 COBJS   += origen.o
     32 endif

    to

     30 ifndef CONFIG_SPL_BUILD
     31 COBJS   += xboot.o
     32 endif
    

    include/configs/origen.h

    用于配置整个板子的头文件也不能放过

    $cp include/configs/origen.h include/configs/xboot.h

    from

    104 #define CONFIG_SYS_PROMPT               "ORIGEN # "
    133 #define CONFIG_IDENT_STRING             " for ORIGEN"

    to

    104 #define CONFIG_SYS_PROMPT               "xboot # "
    133 #define CONFIG_IDENT_STRING             " for xboot"

    boards.cfg

    最后,别忘了我在上文提到的boards.cfg文件,如果这里面不动手脚,我们的板子是不会被Makefile找到的,So,

     284 origen                       arm         armv7       origen              samsung        exynos
     285 xboot                        arm         armv7       xboot               samsung        exynos  

    和之前一样,至此,我们就可以先编译一下过过手瘾(顺便检查一下配置^-^),

      1 #!/bin/bash            
      2 CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')
      3 export ARCH=arm
      4 export CROSS_COMPILE=/opt/arm-cross-compile/arm-2014.05/bin/arm-none-linux-gnueabi-
      5 newName="xboot"
      6 make distclean
      7 make ${newName}_config
      8 make  -j${CPU_NUM}
    

    上面是编译的小脚本,下面是编译的输出。

    编译and烧录

    按照(一)中介绍的,此时已经可以"make xboot_config;make -8"并得到uboot.bin,但此时这个uboot.bin是不能直接烧录的。但无论如何,请暂且记住它的大小:176568byte。接下来,我们需要对uboot.bin进行一系列处理使它能够在exynos4412上运行,这其中要用到下面的几个命令或三星提供的工具软件,这些操作的目的就是根据三星的芯片的启动要求对uboot.bin 进行一些处理,包括在特定长度的位置加上和校验信息以及插入一些文件段。

    $split -b 14336 uboot.bin bl2
    $chksum
    $add_padding
    $rm bl2a*
    $cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin >xboot.bin

    我们可以使用脚本一次性完成上面的工作。

    make -j${CPU_NUM}
     
    cp tools/mkimage /usr/bin/
    cp u-boot.bin ${ROOTDIR}/sdfuse_q
    
    cd ${ROOTDIR}/sdfuse_q
    split -b 14336 u-boot.bin bl2   #split u-boot to bl2a... why14336???==>参考三星bl2对uboot的校验方式,它会读取14336处的CS校验码
    make     #编译chksum
    ${ROOTDIR}/sdfuse_q/chksum      #源码显示程序生成的校验码并没有回写到uboot,即uboot还是没有校验,不知道为什么还成功了,但是这个>
    ${ROOTDIR}/sdfuse_q/add_padding
    rm bl2a*
    cp u-boot.bin ${ROOTDIR}/CodeSign4SecureBoot/
    
    cd ${ROOTDIR}/CodeSign4SecureBoot
    cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin > u-boot-${newName}.bin
    rm ./u-boot.bin
    cp -a ./u-boot-${newName}.bin $TFTPDIR
    cp ./u-boot-${newName}.bin ../mk_sdboot/
     
    cd ${ROOTDIR}/mk_sdboot
    sudo ./sd_fusing_exynos4x12.sh /dev/sdb u-boot-${newName}.bin 

    至此,我们就得到了一个能使用的镜像xboot.bin,这个xboot.bin的大小:527104byte!然后我们就可以使用另外的一些工具烧录到SD卡,注意如果你的开发主机对直接读取SD卡的支持不是很好的话,可以使用读卡器,不论是虚拟机还是Linux主机,对USB设备的支持还是让人满意的,烧录很简单,我们只需要执行下下面的"./sd_fusing_exynos4x12.sh /dev/your_SD_device u-boot-xboot.bin"即可,这个脚本是三星公司提供的,就是将镜像烧录到SD卡中,下面是我用的,贴出来供参考。

    #!/bin/sh
    #
    # Copyright (C) 2010 Samsung Electronics Co., Ltd.
    #              http://www.samsung.com/
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License version 2 as
    # published by the Free Software Foundation.
    # sd_fusing_exynos4x12.sh
    ####################################
    reader_type1="/dev/sd"
    reader_type2="/dev/mmcblk0"
    
    if [ -z $2 ]
    then
        echo "usage: ./sd_fusing.sh <SD Reader's device file> <filename>"
        exit 0
    fi
    
    param1=`echo "$1" | awk '{print substr($1,1,7)}'`
    
    if [ "$param1" = "$reader_type1" ]
    then
        partition=$1"1"
    elif [ "$1" = "$reader_type2" ]
    then
        partition=$1"p1"
    else
        echo "Unsupported SD reader"
        exit 0
    fi
    
    if [ -b $1 ]       
    then
        echo "$1 reader is identified."
    else
        echo "$1 is NOT identified."
        exit 0
    fi
    
    ####################################
    echo "----------------------------------"
    echo $partition
    echo "----------------------------------"
    
    # format
    umount $partition 2> /dev/null
    
    echo "$2 fusing..."
    dd iflag=dsync oflag=dsync if=./$2 of=$1 seek=1 && 
            echo "$2 image has been fused successfully."
    
    ####################################
    #<Message Display>
    echo "Eject SD ca

    将启动模式调整到从SD卡启动,uboot就可以跑起来了。

  • 相关阅读:
    101. Symmetric Tree(js)
    100. Same Tree(js)
    99. Recover Binary Search Tree(js)
    98. Validate Binary Search Tree(js)
    97. Interleaving String(js)
    96. Unique Binary Search Trees(js)
    95. Unique Binary Search Trees II(js)
    94. Binary Tree Inorder Traversal(js)
    93. Restore IP Addresses(js)
    92. Reverse Linked List II(js)
  • 原文地址:https://www.cnblogs.com/icefree/p/8491271.html
Copyright © 2011-2022 走看看