美文网首页开发板相关
nanopi M4开发日记3:裸机开发--make.sh分析

nanopi M4开发日记3:裸机开发--make.sh分析

作者: hkx_x | 来源:发表于2019-02-05 23:06 被阅读0次

    上一篇我们完成了编译U-boot,得到了3个文件烧入后正常启动,编译u-boot使用的是Rockchip提供的make.sh脚本自动完成的编译,这一篇我们就来分析这个make.sh脚本

    首先在make.sh的最前面定义的是全局变量,注意其中的rkbin和工具链的路径设置,是根据自己的开发环境修改的。 然后我们看整个make.sh的运行顺序,在脚本的最后

    那么我们就按照这个顺序进行分析

    首先第一个是prepare(),完成输出目录解析和--help命令解析以及根据默认配置文件生成.config文件 接着是select_toolchain(),完成了对应工具链的配置
    接着是select_chip_info(),选择出芯片的信号信息
    对于RK3399的编译fixup_platform_configure()只设定了输出img的大小
    fixup_platform_configure()
    {
        local count plat
    
    # <*> Fixup rsa/sha pack mode for platforms 固定rsa/sha包(打包)模式的平台
        # RK3308/PX30/RK3326 use RSA-PKCS1 V2.1, it's pack magic is "3"
        if [ $RKCHIP = "PX30" -o $RKCHIP = "RK3326" -o $RKCHIP = "RK3308" ]; then       #RK3308/PX30/RK3326使用rsa 3
            PLATFORM_RSA="--rsa 3"
        # RK3368 use rk big endian SHA256, it's pack magic is "2"
        elif [ $RKCHIP = "RK3368" ]; then                                               #RK3368使用 sha 2
            PLATFORM_SHA="--sha 2"
        # other platforms use default configure
        fi
    
    # <*> Fixup images size pack for platforms  为平台修正image大小包
        if [ $RKCHIP = "RK3308" ]; then
            if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then          #.config中为# CONFIG_ARM64_BOOT_AARCH32 is not set
                PLATFORM_UBOOT_IMG_SIZE="--size 512 2"
                PLATFORM_TRUST_IMG_SIZE="--size 512 2"
            else                                                                        #rk3399配置如下
                PLATFORM_UBOOT_IMG_SIZE="--size 1024 2"
                PLATFORM_TRUST_IMG_SIZE="--size 1024 2"
            fi
        fi
    
    # <*> Fixup PLATFORM_AARCH32 for ARM64 cpu platforms
        if [ $RKCHIP = "RK3308" ]; then                                                 #只有rk3308执行
            if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then
                PLATFORM_AARCH32="AARCH32"
            fi
        fi
    }
    

    sub_commands()是用来处理其他命令和部分芯片的,rk3399不执行此函数,我们在此跳过
    完成了工具链的配置以及在prepare()生成.config文件,接下来是进行unoot的编译

    make CROSS_COMPILE=${TOOLCHAIN_GCC}  all --jobs=${JOB} ${OUTOPT}
    

    最后是打包出3个烧入的文件
    uboot的打包

    pack_uboot_image()          
    {
        local UBOOT_LOAD_ADDR
    
        UBOOT_LOAD_ADDR=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'`   #UBOOT_LOAD_ADDR = 0x00200000,设置u-boot起始地址
        ${RKTOOLS}/loaderimage --pack --uboot ${OUTDIR}/u-boot.bin uboot.img ${UBOOT_LOAD_ADDR} ${PLATFORM_UBOOT_IMG_SIZE}      #调用loaderimage工具,讲u-boot.bin 打包成 uboot.img
    #   ../rkbin/tools                          ./                                              PLATFORM_UBOOT_IMG_SIZE="--size 1024 2"
        # Delete u-boot.img and u-boot-dtb.img, which makes users not be confused with final uboot.img
        if [ -f ${OUTDIR}/u-boot.img ]; then        #删除u-boot.img
            rm ${OUTDIR}/u-boot.img
        fi
    
        if [ -f ${OUTDIR}/u-boot-dtb.img ]; then    #删除u-boot-dtb.img
            rm ${OUTDIR}/u-boot-dtb.img
        fi
    
        echo "pack uboot okay! Input: ${OUTDIR}/u-boot.bin"
    }
    

    loader的打包

    
    pack_loader_image()
    {
        local mode=$1 files ini
    
        if [ ! -f ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini ]; then       #对应MINIALL.ini不存在,退出并报错
            echo "pack loader failed! Can't find: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
            return
        fi
    
        cd ${RKBIN}             #cd../rkbin
    
        if [ "${mode}" = 'all' ]; then                                  #$1==all
            files=`ls ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL*.ini`
            for ini in $files
            do
                if [ -f "$ini" ]; then
                    ${RKTOOLS}/boot_merger --replace tools/rk_tools/ ./ $ini
                    echo "pack loader okay! Input: $ini"
                fi
            done
        else                                                            
            ${RKTOOLS}/boot_merger --replace tools/rk_tools/ ./ ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini     #使用boot_merger按照RK3399MINIALL.ini生成loader文件
            echo "pack loader okay! Input: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
        fi
    
        cd - && mv ${RKBIN}/*_loader_*.bin ./
    }
    
    

    trust的打包

    local TOS TOS_TA DARM_BASE TEE_LOAD_ADDR TEE_OFFSET=0x8400000
    
        # ARM64 uses trust_merger           #ARM64使用的trust_merger
        if grep -Eq ''^CONFIG_ARM64=y'|'^CONFIG_ARM64_BOOT_AARCH32=y'' ${OUTDIR}/.config ; then         
            if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini ]; then      #无法找到对应的TRUST.ini文件
                echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
                return
            fi
    
            cd ${RKBIN}
            ${RKTOOLS}/trust_merger ${PLATFORM_SHA} ${PLATFORM_RSA} ${PLATFORM_TRUST_IMG_SIZE} --replace tools/rk_tools/ ./ ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini
    
            cd - && mv ${RKBIN}/trust.img ./trust.img
            echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
    #后面是ARM32的trust打包,就不考虑了
    

    相关文章

      网友评论

        本文标题:nanopi M4开发日记3:裸机开发--make.sh分析

        本文链接:https://www.haomeiwen.com/subject/flqbsqtx.html