a40i pack

#!/bin/bash
#
# pack/pack
# (c) Copyright 2013
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# James Deng <csjamesdeng@allwinnertech.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

 

############################ Notice #####################################
# a. Some config files priority is as follows:
#    - xxx_${platform}.{cfg|fex} > xxx.{cfg|fex}
#    - ${chip}/${board}/*.{cfg|fex} > ${chip}/default/*.{cfg|fex}
#    - ${chip}/default/*.cfg > common/imagecfg/*.cfg
#    - ${chip}/default/*.fex > common/partition/*.fex
#  e.g. sun8iw7p1/configs/perf/image_linux.cfg > sun8iw7p1/configs/default/image_linux.cfg
#       > common/imagecfg/image_linux.cfg > sun8iw7p1/configs/perf/image.cfg
#       > sun8iw7p1/configs/default/image.cfg > common/imagecfg/image.cfg
#
# b. Support Nor storages rule:
#    - Need to create sys_partition_nor.fex or sys_partition_nor_${platform}.fex
#    - Add "{filename = "full_img.fex",     maintype = "12345678", \
#      subtype = "FULLIMG_00000000",}" to image[_${platform}].cfg
#
# c. Switch uart port
#    - Need to add your chip configs into pctools/linux/card_debug_pin
#    - Call pack with 'debug' parameters




if [ $(basename `pwd`) != "pack" ] ; then
    echo "Please run at the top directory of pack"
    exit 1
fi

 

function pack_error()
{
    echo -e "\033[47;31mERROR: $*\033[0m"
}

 

function pack_warn()
{
    echo -e "\033[47;34mWARN: $*\033[0m"
}

 

function pack_info()
{
    echo -e "\033[47;30mINFO: $*\033[0m"
}

 

. ../build/shflags

 

# define option, format:
#   'long option' 'default value' 'help message' 'short option'
DEFINE_string 'chip' '' 'chip to build, e.g. sun7i' 'c'
DEFINE_string 'platform' '' 'platform to build, e.g. linux, android, camdroid' 'p'
DEFINE_string 'board' '' 'board to build, e.g. evb' 'b'
DEFINE_string 'kernel' '' 'kernel to build, e.g. linux-3.4, linux-3.10' 'k'
DEFINE_string 'debug_mode' 'uart0' 'config debug mode, e.g. uart0, card0' 'd'
DEFINE_string 'signture' 'none' 'pack boot signture to do secure boot' 's'
DEFINE_string 'mode' 'normal' 'pack dump firmware' 'm'
DEFINE_string 'function' 'android' 'pack private firmware' 'f'

 

# parse the command-line
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

 

PACK_CHIP=${FLAGS_chip}
PACK_PLATFORM=${FLAGS_platform}
PACK_BOARD=${FLAGS_board}
PACK_KERN=${FLAGS_kernel}
PACK_DEBUG=${FLAGS_debug_mode}
PACK_SIG=${FLAGS_signture}
PACK_MODE=${FLAGS_mode}
PACK_FUNC=${FLAGS_function}

 

ROOT_DIR=`pwd`
TOOLS_DIR="${ROOT_DIR}/pctools/linux"
LICHEE_OUT="../../out/${PACK_CHIP}/${PACK_PLATFORM}/common"
OTA_TEST_NAME="ota_test"
if [ -d ${LICHEE_OUT} ] ; then
    LICHEE_OUT=`cd ${LICHEE_OUT}; pwd`
else
    pack_error "build lichee before you pack"
    exit 1
fi

 

if [ -n "`echo ${PACK_CHIP} | grep "sun5[0-9]i"`" ]; then
    export ARCH=arm64
else
    export ARCH=arm
fi

 

export PATH=${TOOLS_DIR}/mod_update:${TOOLS_DIR}/openssl:${TOOLS_DIR}/eDragonEx:${TOOLS_DIR}/fsbuild200:${TOOLS_DIR}/android:$PATH

 

tools_file_list=(
common/tools/split_xxxx.fex
chips/${PACK_CHIP}/tools/split_xxxx.fex
common/tools/usbtool_test.fex
chips/${PACK_CHIP}/tools/usbtool_test.fex
common/tools/cardscript.fex
common/tools/cardscript_secure.fex
chips/${PACK_CHIP}/tools/cardscript.fex
chips/${PACK_CHIP}/tools/cardscript_secure.fex
common/tools/cardtool.fex
chips/${PACK_CHIP}/tools/cardtool.fex
common/tools/usbtool.fex
chips/${PACK_CHIP}/tools/usbtool.fex
common/tools/aultls32.fex
chips/${PACK_CHIP}/tools/aultls32.fex
common/tools/aultools.fex
chips/${PACK_CHIP}/tools/aultools.fex
)

 

configs_file_list=(
common/toc/toc1.fex
common/toc/toc0.fex
common/toc/boot_package.fex
common/dtb/sunxi.fex
common/imagecfg/*.cfg
common/partition/sys_partition_dump.fex
common/partition/sys_partition_private.fex
chips/${PACK_CHIP}/configs/default/*
chips/${PACK_CHIP}/configs/${PACK_BOARD}/*.fex
chips/${PACK_CHIP}/configs/${PACK_BOARD}/*.cfg
)

 

boot_resource_list=(
chips/${PACK_CHIP}/boot-resource/boot-resource:out/
chips/${PACK_CHIP}/boot-resource/boot-resource.ini:out/
chips/${PACK_CHIP}/configs/${PACK_BOARD}/bootlogo.bmp:out/boot-resource/
chips/${PACK_CHIP}/configs/${PACK_BOARD}/bootlogo.bmp:out/bootlogo.bmp
)

 

usr_resource_list=(
chips/${PACK_CHIP}/usr-resource/usr-resource:out/
chips/${PACK_CHIP}/usr-resource/usr-resource.ini:out/
)

 

boot_file_list=(
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_nand_${PACK_CHIP}.bin:out/boot0_nand.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_sdcard_${PACK_CHIP}.bin:out/boot0_sdcard.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_spinor_${PACK_CHIP}.bin:out/boot0_spinor.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/fes1_${PACK_CHIP}.bin:out/fes1.fex
chips/${PACK_CHIP}/bin/u-boot-${PACK_CHIP}.bin:out/u-boot.fex
chips/${PACK_CHIP}/bin/bl31.bin:out/monitor.fex
chips/${PACK_CHIP}/bin/scp.bin:out/scp.fex
chips/${PACK_CHIP}/bin/u-boot-spinor-${PACK_CHIP}.bin:out/u-boot-spinor.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_nand_${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/boot0_nand-${OTA_TEST_NAME}.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_sdcard_${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/boot0_sdcard-${OTA_TEST_NAME}.fex
chips/${PACK_CHIP}/bin/${LICHEE_BOARD}/boot0_spinor_${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/boot0_spinor-${OTA_TEST_NAME}.fex
chips/${PACK_CHIP}/bin/u-boot-${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/u-boot-${OTA_TEST_NAME}.fex
chips/${PACK_CHIP}/bin/u-boot-spinor-${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/u-boot-spinor-${OTA_TEST_NAME}.fex
)

 

boot_file_secure=(
chips/${PACK_CHIP}/bin/semelis_${PACK_CHIP}.bin:out/semelis.bin
chips/${PACK_CHIP}/bin/sboot_${PACK_CHIP}.bin:out/sboot.bin
chips/${PACK_CHIP}/bin/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/sboot-${OTA_TEST_NAME}.bin
)

 

a64_boot_file_secure=(
chips/${PACK_CHIP}/bin/optee_${PACK_CHIP}.bin:out/optee.fex
chips/${PACK_CHIP}/bin/sboot_${PACK_CHIP}.bin:out/sboot.bin
# chips/${PACK_CHIP}/bin/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:out/sboot-${OTA_TEST_NAME}.bin
)

 

#
# This function can get the realpath between $SRC and $DST
#
function get_realpath()
{
    local src=$(cd $1; pwd);
    local dst=$(cd $2; pwd);
    local res="./";
    local tmp="$dst"

 

    while [ "${src##*$tmp}" == "${src}" ]; do
        tmp=${tmp%/*};
        res=$res"../"
    done
    res="$res${src#*$tmp/}"

 

    printf "%s" $res
}

 

function show_boards()
{
    printf "\nAll avaiable chips, platforms and boards:\n\n"
    printf "Chip            Board\n"
    for chipdir in $(find chips/ -mindepth 1 -maxdepth 1 -type d) ; do
        chip=`basename ${chipdir}`
        printf "${chip}\n"
        for boarddir in $(find chips/${chip}/configs/${platform} \
            -mindepth 1 -maxdepth 1 -type d) ; do
            board=`basename ${boarddir}`
            printf "                ${board}\n"
        done
    done
    printf "\nFor Usage:\n"
    printf "     $(basename $0) -h\n\n"
}

 

function uart_switch()
{
    rm -rf out/awk_debug_card0
    touch out/awk_debug_card0
    TX=`awk  '$0~"'$PACK_CHIP'"{print $2}' pctools/linux/card_debug_pin`
    RX=`awk  '$0~"'$PACK_CHIP'"{print $3}' pctools/linux/card_debug_pin`
    PORT=`awk  '$0~"'$PACK_CHIP'"{print $4}' pctools/linux/card_debug_pin`
    MS=`awk  '$0~"'$PACK_CHIP'"{print $5}' pctools/linux/card_debug_pin`
    CK=`awk  '$0~"'$PACK_CHIP'"{print $6}' pctools/linux/card_debug_pin`
    DO=`awk  '$0~"'$PACK_CHIP'"{print $7}' pctools/linux/card_debug_pin`
    DI=`awk  '$0~"'$PACK_CHIP'"{print $8}' pctools/linux/card_debug_pin`

 

    BOOT_UART_ST=`awk  '$0~"'$PACK_CHIP'"{print $2}' pctools/linux/card_debug_string`
    BOOT_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $3}' pctools/linux/card_debug_string`
    BOOT_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $4}' pctools/linux/card_debug_string`
    BOOT_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $5}' pctools/linux/card_debug_string`
    UART0_ST=`awk  '$0~"'$PACK_CHIP'"{print $6}' pctools/linux/card_debug_string`
    UART0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $7}' pctools/linux/card_debug_string`
    UART0_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $8}' pctools/linux/card_debug_string`
    UART0_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $9}' pctools/linux/card_debug_string`
    UART0_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $10}' pctools/linux/card_debug_string`
    UART1_ST=`awk  '$0~"'$PACK_CHIP'"{print $11}' pctools/linux/card_debug_string`
    JTAG_ST=`awk  '$0~"'$PACK_CHIP'"{print $12}' pctools/linux/card_debug_string`
    MS_ST=`awk  '$0~"'$PACK_CHIP'"{print $13}' pctools/linux/card_debug_string`
    CK_ST=`awk  '$0~"'$PACK_CHIP'"{print $14}' pctools/linux/card_debug_string`
    DO_ST=`awk  '$0~"'$PACK_CHIP'"{print $15}' pctools/linux/card_debug_string`
    DI_ST=`awk  '$0~"'$PACK_CHIP'"{print $16}' pctools/linux/card_debug_string`
    MMC0_ST=`awk  '$0~"'$PACK_CHIP'"{print $17}' pctools/linux/card_debug_string`
    MMC0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $18}' pctools/linux/card_debug_string`

 

    echo '$0!~";" && $0~"'$BOOT_TX_ST'"{if(C)$0="'$BOOT_TX_ST' = '$TX'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$BOOT_RX_ST'"{if(C)$0="'$BOOT_RX_ST' = '$RX'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$BOOT_PORT_ST'"{if(C)$0="'$BOOT_PORT_ST' = '$PORT'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 0";A=0} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"\\['$MMC0_ST'\\]"{A=1}  \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$UART0_TX_ST'"{if(B)$0="'$UART0_TX_ST' = '$TX'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$UART0_RX_ST'"{if(B)$0="'$UART0_RX_ST' = '$RX'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"\\['$UART0_ST'\\]"{B=1} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$UART0_USED_ST'"{if(B)$0="'$UART0_USED_ST' = 1"}  \' >> out/awk_debug_card0
    echo '/^'$UART0_PORT_ST'/{next} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"\\['$UART1_ST'\\]"{B=0} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"\\['$BOOT_UART_ST'\\]"{C=1} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"\\['$JTAG_ST'\\]"{C=0} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$MS_ST'"{$0="'$MS_ST' = '$MS'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$CK_ST'"{$0="'$CK_ST' = '$CK'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$DO_ST'"{$0="'$DO_ST' = '$DO'"} \' >> out/awk_debug_card0
    echo '$0!~";" && $0~"'$DI_ST'"{$0="'$DI_ST' = '$DI'"} \' >> out/awk_debug_card0
    echo '1' >> out/awk_debug_card0

 

    awk -f out/awk_debug_card0 out/sys_config.fex > out/sys_config_debug.fex
    rm -f out/sys_config.fex
    mv out/sys_config_debug.fex out/sys_config.fex
    echo "uart -> card0"
}

 

function copy_ota_test_file()
{
    printf "ota test bootloader by diff bootlogo\n"
    mv out/boot-resource/bootlogo_ota_test.bmp out/boot-resource/bootlogo.bmp

 

    printf "copying ota test boot file\n"
    if [ -f sys_partition_nor.fex -o \
        -f sys_partition_nor_${PACK_PLATFORM}.fex ];  then
        mv out/boot0_spinor-${OTA_TEST_NAME}.fex    out/boot0_spinor.fex
        mv out/u-boot-spinor-${OTA_TEST_NAME}.fex   out/u-boot-spinor.fex
    else
        mv out/boot0_nand-${OTA_TEST_NAME}.fex      out/boot0_nand.fex
        mv out/boot0_sdcard-${OTA_TEST_NAME}.fex    out/boot0_sdcard.fex
        mv out/u-boot-${OTA_TEST_NAME}.fex      out/u-boot.fex
    fi

 

    if [ "x${PACK_SIG}" = "xsecure" -o  "x${PACK_SIG}" = "prev_refurbish"] ; then
        printf "Copying ota test secure boot file\n"
        mv out/sboot-${OTA_TEST_NAME}.bin out/sboot.bin
    fi

 

    printf "OTA test env by bootdelay(10) and logolevel(8)\n"
    sed -i 's/\(logolevel=\).*/\18/' out/env.cfg
    sed -i 's/\(bootdelay=\).*/\110/' out/env.cfg
}

 

function do_prepare()
{
    if [ -z "${PACK_CHIP}" -o -z "${PACK_PLATFORM}" -o -z "${PACK_BOARD}" ] ; then
        pack_error "Invalid parameters Chip: ${PACK_CHIP}, \
            Platform: ${PACK_PLATFORM}, Board: ${PACK_BOARD}"
        show_boards
        exit 1
    fi

 

    if [ ! -d chips/${PACK_CHIP}/configs/${PACK_BOARD} ] ; then
        pack_error "Board's directory \
            \"chips/${PACK_CHIP}/configs/${PACK_BOARD}\" is not exist."
        show_boards
        exit 1
    fi

 

    if [ -z "${PACK_KERN}" ] ; then
        printf "No kernel param, parse it from .buildconfig\n"
        PACK_KERN=`awk -F LICHEE_KERN_VER= '{printf $2}' ../../.buildconfig`
        if [ -z "${PACK_KERN}" ] ; then
            pack_error "Failed to parse kernel param from .buildconfig"
            exit 1
        fi
    fi

 

    # Cleanup
    rm -rf out/
    pwd
    read -p "out" out
    mkdir -p out/
    pwd
    read -p "out" out

 

    printf "copying tools file\n"
    for file in ${tools_file_list[@]} ; do
        cp -f $file out/ 2> /dev/null
    done

 

        cp -f chips/${PACK_CHIP}/configs/${PACK_BOARD}/*${LICHEE_RESOLUTION}.fex chips/${PACK_CHIP}/configs/${PACK_BOARD}/sys_config.fex

 

    printf "copying configs file\n"
    for file in ${configs_file_list[@]} ; do
        cp -f $file out/ 2> /dev/null
    done
        cp -f chips/${PACK_CHIP}/configs/${PACK_BOARD}/*${LICHEE_RESOLUTION}.fex out/sys_config.fex

 

    # If platform config files exist, we will cover the default files
    # For example, mv out/image_linux.cfg out/image.cfg
    find ./out/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
        sed "s#\(.*\)_${PACK_PLATFORM}\(\..*\)#mv -fv & \1\2#e"

 

    if [ "x${PACK_MODE}" = "xdump" ] ; then
        cp -vf out/sys_partition_dump.fex out/sys_partition.fex
        cp -vf out/usbtool_test.fex out/usbtool.fex
    elif [ "x${PACK_FUNC}" = "xprvt" ] ; then
        cp -vf out/sys_partition_private.fex out/sys_partition.fex
    fi

 

    printf "copying boot resource\n"
    for file in ${boot_resource_list[@]} ; do
        cp -rf `echo $file | awk -F: '{print $1}'` \
            `echo $file | awk -F: '{print $2}'` 2>/dev/null
    done
    
    printf "copying usr resource\n"
    for file in ${usr_resource_list[@]} ; do
        cp -rf `echo $file | awk -F: '{print $1}'` \
            `echo $file | awk -F: '{print $2}'` 2>/dev/null
    done



    lzma -k out/bootlogo.bmp

 

    printf "copying boot file\n"
    for file in ${boot_file_list[@]} ; do
        cp -f `echo $file | awk -F: '{print $1}'` \
            `echo $file | awk -F: '{print $2}'` 2>/dev/null
    done

 

    if [ "x${ARCH}" != "xarm64" ] ; then
        if [ "x${PACK_SIG}" = "xsecure" -o  "x${PACK_SIG}" = "xprev_refurbish" ] ; then
            printf "copying secure boot file\n"
            for file in ${boot_file_secure[@]} ; do
                cp -f `echo $file | awk -F: '{print $1}'` \
                    `echo $file | awk -F: '{print $2}'`
            done
        fi
    else
        if [ "x${PACK_SIG}" = "xsecure" -o  "x${PACK_SIG}" = "xprev_refurbish" ] ; then
            printf "copying arm64 secure boot file\n"
            for file in ${a64_boot_file_secure[@]} ; do
                cp -f `echo $file | awk -F: '{print $1}'` \
                    `echo $file | awk -F: '{print $2}'`
            done
        fi
    fi

 

    if [ "x${PACK_SIG}" = "xsecure" ] ; then
        printf "add burn_secure_mode in target in sys config\n"
        sed -i -e '/^\[target\]/a\burn_secure_mode=1' out/sys_config.fex
        sed -i -e '/^\[platform\]/a\secure_without_OS=0' out/sys_config.fex
    elif [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
        printf "add burn_secure_mode in target in sys config\n"
        sed -i -e '/^\[target\]/a\burn_secure_mode=1' out/sys_config.fex
        sed -i -e '/^\[platform\]/a\secure_without_OS=1' out/sys_config.fex
    else
        sed -i '/^burn_secure_mod/d' out/sys_config.fex
        sed -i '/^secure_without_OS/d' out/sys_config.fex
    fi

 

    if [ "x${PACK_MODE}" = "xota_test" ] ; then
        printf "copy ota test file\n"
        copy_ota_test_file
    fi

 

    # Here, we can switch uart to card or normal
    if [ "x${PACK_DEBUG}" = "xcard0" -a "x${PACK_MODE}" != "xdump" \
        -a "x${PACK_FUNC}" != "xprvt" ] ; then \
        uart_switch
    fi

 

    sed -i 's/\\boot-resource/\/boot-resource/g' out/boot-resource.ini
    sed -i 's/\\usr-resource/\/usr-resource/g' out/usr-resource.ini
    sed -i 's/\\\\/\//g' out/image.cfg
    sed -i 's/^imagename/;imagename/g' out/image.cfg

 

    IMG_NAME="${PACK_CHIP}_${PACK_PLATFORM}_${PACK_BOARD}_${PACK_DEBUG}"

 

    if [ "x${PACK_SIG}" != "xnone" ]; then
        IMG_NAME="${IMG_NAME}_${PACK_SIG}"
    fi

 

    if [ "x${PACK_MODE}" = "xdump" -o "x${PACK_MODE}" = "xota_test" ] ; then
        IMG_NAME="${IMG_NAME}_${PACK_MODE}"
    fi

 

    if [ "x${PACK_FUNC}" = "xprvt" ] ; then
        IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
    fi

 

    if [ "x${PACK_FUNC}" = "xprev_refurbish" ] ; then
        IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
    fi

 

    if [ "x${PACK_SIG}" != "xnone" ]; then
        MAIN_VERION=`awk  '$0~"MAIN_VERSION"{printf"%d", $3}' common/version/version_base.mk`
        SUB_VERION=`awk  '$0~"SUB_VERSION"{printf"%d", $3}' common/version/version_base.mk`

 

        IMG_NAME="${IMG_NAME}_v${MAIN_VERION}-${SUB_VERION}-${LICHEE_RESOLUTION}.img"
    else
        IMG_NAME="${IMG_NAME}-${LICHEE_RESOLUTION}.img"
    fi

 

    echo "imagename = $IMG_NAME" >> out/image.cfg
    echo "" >> out/image.cfg

 

    if [ "x${PACK_PLATFORM}" = "xdragonboard" ] ; then
        sed -i '/\[nand0_para\]/a\nand0_dragonboard = 1' out/sys_config.fex
    fi
}

 

function do_ini_to_dts()
{
    if [ "x${PACK_KERN}" != "xlinux-3.10" ] ; then
        return
    fi

 

    local DTC_COMPILER=${LICHEE_OUT}/../../../../$PACK_KERN/scripts/dtc/dtc
    local DTC_DEP_FILE=${LICHEE_OUT}/../../../../$PACK_KERN/arch/$ARCH/boot/dts/.${PACK_CHIP}-${PACK_BOARD}.dtb.d.dtc.tmp
    local DTC_SRC_PATH=${LICHEE_OUT}/../../../../$PACK_KERN/arch/$ARCH/boot/dts/
    local DTC_SRC_FILE=${LICHEE_OUT}/../../../../$PACK_KERN/arch/$ARCH/boot/dts/.${PACK_CHIP}-${PACK_BOARD}.dtb.dts
    local DTC_INI_FILE_BASE=${LICHEE_OUT}/../../../../tools/pack/out/sys_config.fex
    local DTC_INI_FILE=${LICHEE_OUT}/../../../../tools/pack/out/sys_config_fix.fex
    cp $DTC_INI_FILE_BASE $DTC_INI_FILE
    sed -i "s/\(\[dram\)_para\(\]\)/\1\2/g" $DTC_INI_FILE
    sed -i "s/\(\[nand[0-9]\)_para\(\]\)/\1\2/g" $DTC_INI_FILE

 

    if [ ! -f $DTC_COMPILER ]; then
        pack_error "Script_to_dts: Can not find dtc compiler.\n"
        exit 1
    fi
    if [ ! -f $DTC_DEP_FILE ]; then
        printf "Script_to_dts: Can not find [%s-%s.dts]. Will use common dts file instead.\n" ${PACK_CHIP} ${PACK_BOARD}
        DTC_DEP_FILE=${LICHEE_OUT}/../../../../$PACK_KERN/arch/$ARCH/boot/dts/.${PACK_CHIP}-soc.dtb.d.dtc.tmp
        DTC_SRC_FILE=${LICHEE_OUT}/../../../../$PACK_KERN/arch/$ARCH/boot/dts/.${PACK_CHIP}-soc.dtb.dts
    fi

 

    $DTC_COMPILER -O dtb -o ${LICHEE_OUT}/sunxi.dtb \
        -b 0            \
        -i $DTC_SRC_PATH    \
        -F $DTC_INI_FILE    \
        -d $DTC_DEP_FILE $DTC_SRC_FILE
    if [ $? -ne 0 ]; then
        pack_error "Conver script to dts failed"
        exit 1
    fi

 

    printf "Conver script to dts ok.\n"

 

    # It'is used for debug dtb
    $DTC_COMPILER -I dtb -O dts -o ${LICHEE_OUT}/.sunxi.dts ${LICHEE_OUT}/sunxi.dtb

 

    return
}

 

function do_common()
{
    cd out/

 

    busybox unix2dos sys_config.fex
    busybox unix2dos sys_partition.fex
    script  sys_config.fex > /dev/null
    script  sys_partition.fex > /dev/null
    cp -f   sys_config.bin config.fex

 

    if [ "x${PACK_PLATFORM}" = "xdragonboard" ] ; then
        busybox dos2unix test_config.fex
        cp test_config.fex boot-resource/
        busybox unix2dos test_config.fex
        script test_config.fex > /dev/null
        cp test_config.bin boot-resource/
    fi

 

    # Those files for SpiNor. We will try to find sys_partition_nor.fex
    if [ -f sys_partition_nor.fex ];  then

 

        if [ -f "${LICHEE_OUT}/sunxi.dtb" ]; then
            cp ${LICHEE_OUT}/sunxi.dtb sunxi.fex
            update_uboot_fdt u-boot-spinor.fex sunxi.fex u-boot-spinor.fex >/dev/null
        fi

 

        # Here, will create sys_partition_nor.bin
        busybox unix2dos sys_partition_nor.fex
        script  sys_partition_nor.fex > /dev/null
        update_boot0 boot0_spinor.fex   sys_config.bin SDMMC_CARD > /dev/null
        update_uboot u-boot-spinor.fex  sys_config.bin >/dev/null

 

        if [ -f boot_package_nor.cfg ]; then
            echo "pack boot package"
            busybox unix2dos boot_package.cfg
            dragonsecboot -pack boot_package_nor.cfg
            cp boot_package.fex boot_package_nor.fex
        fi
        # Ugly, but I don't have a better way to change it.
        # We just set env's downloadfile name to env_nor.cfg in sys_partition_nor.fex
        # And if env_nor.cfg is not exist, we should copy one.
        if [ ! -f env_nor.cfg ]; then
            cp -f env.cfg env_nor.cfg >/dev/null 2<&1
        fi

 

        # Fixup boot mode for SPINor, just can bootm
        sed -i '/^boot_normal/s#\<boota\>#bootm#g' env_nor.cfg

 

        u_boot_env_gen env_nor.cfg env_nor.fex >/dev/null
    fi



    if [ -f "${LICHEE_OUT}/sunxi.dtb" ]; then
        cp ${LICHEE_OUT}/sunxi.dtb sunxi.fex
        fastdtb sunxi.fex
        update_uboot_fdt u-boot.fex sunxi.fex u-boot.fex
    fi

 

    # Those files for Nand or Card
    update_boot0 boot0_nand.fex sys_config.bin NAND > /dev/null
    update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
    update_uboot u-boot.fex         sys_config.bin > /dev/null
    update_fes1  fes1.fex           sys_config.bin > /dev/null
    fsbuild      boot-resource.ini  split_xxxx.fex > /dev/null
    fsbuild      usr-resource.ini  split_xxxx.fex > /dev/null

 

    if [ -f boot_package.cfg ]; then
            echo "pack boot package"
            busybox unix2dos boot_package.cfg
            dragonsecboot -pack boot_package.cfg

 

        if [ $? -ne 0 ]
        then
            pack_error "dragon pack run error"
            exit 1
        fi
    fi

 

    if [ "x${PACK_FUNC}" = "xprvt" ] ; then
        u_boot_env_gen env_burn.cfg env.fex > /dev/null
    else
        u_boot_env_gen env.cfg env.fex > /dev/null
    fi

 

    if [ -f "$LICHEE_OUT/arisc" ]; then
        ln -sf $(get_realpath $LICHEE_OUT ./)/arisc arisc.fex
    fi
}

 

function do_finish()
{
    # Yeah, it should contain all files into full_img.fex for spinor
    # Because, as usually, spinor image size is very small.
    # If fail to create full_img.fex, we should fake it empty.

 

    # WTF, it is so ugly!!! It must be sunxi_mbr.fex & sys_partition.bin,
    # not sunxi_mbr_xxx.fex & sys_partition_xxx.bin. In order to advoid this
    # loathsome thing, we need to backup & copy files. Check whether
    # sys_partition_nor.bin is exist, and create sunxi_mbr.fex for Nor.
    if [ -f sys_partition_nor.bin ]; then

 

        update_mbr sys_partition_nor.bin 1 sunxi_mbr_nor.fex
        if [ $? -ne 0 ]; then
            pack_error "update_mbr failed"
            exit 1
        fi
        #when use devicetree, the size of uboot+dtb is larger then 256K
        if [ "x${PACK_KERN}" = "xlinux-3.10" ] ; then
            BOOT1_FILE=boot_package_nor.fex
            LOGIC_START=496 #496+16=512K
            merge_full_img --out full_img.fex \
                      --boot0 boot0_spinor.fex \
                      --boot1 ${BOOT1_FILE} \
                  --mbr sunxi_mbr_nor.fex \
                  --logic_start ${LOGIC_START} \
                  --partition sys_partition_nor.bin
            if [ $? -ne 0 ]; then
                pack_error "merge_full_img failed"
                exit 1
            fi
        else
            #BOOT1_FILE=u-boot-spinor.fex
            #LOGIC_START=240 #240+16=256K
            merge_package full_img.fex boot0_spinor.fex \
                    u-boot-spinor.fex sunxi_mbr_nor.fex sys_partition_nor.bin
        fi

 

    fi

 

    if [ ! -f full_img.fex ]; then
        echo "full_img.fex is empty" > full_img.fex
    fi

 

    update_mbr          sys_partition.bin 4 
    if [ $? -ne 0 ]; then
        pack_error "update_mbr failed"
        exit 1
    fi
    dragon image.cfg    sys_partition.fex
        if [ $? -eq 0 ]; then
        if [ -e ${IMG_NAME} ]; then
            mv ${IMG_NAME} ../${IMG_NAME}
            echo '----------image is at----------'
            echo -e '\033[0;31;1m'
            echo ${ROOT_DIR}/${IMG_NAME}
            echo -e '\033[0m'
        fi
        fi
    cd ..
    printf "pack finish\n"
}

 

function do_signature()
{
    printf "prepare for signature by openssl\n"
    if [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
        if [ "x${ARCH}" = "xarm64" ] ; then
            cp -v ../common/sign_config/dragon_toc_a64_no_secureos.cfg dragon_toc.cfg
        else
            cp -v ../common/sign_config/dragon_toc_no_secureos.cfg dragon_toc.cfg
        fi
    else
        if [ "x${ARCH}" = "xarm64" ] ; then
            cp -v ../common/sign_config/dragon_toc_a64.cfg dragon_toc.cfg
        else
            if [ "x${PACK_PLATFORM}" = "xlinux" ] ; then
                cp -v ../common/sign_config/dragon_toc.cfg dragon_toc.cfg
            elif [ "x${PACK_PLATFORM}" = "xandroid" ] ; then
                cp -v ../common/sign_config/dragon_toc.cfg dragon_toc.cfg
            fi
        fi
    fi

 

    if [ $? -ne 0 ]
    then
        pack_error "dragon toc config file is not exist"
        exit 1
    fi

 

    rm -f cardscript.fex
    mv cardscript_secure.fex cardscript.fex
    if [ $? -ne 0 ]
    then
        pack_error "dragon cardscript_secure.fex file is not exist"
        exit 1
    fi

 

    dragonsecboot -toc0 dragon_toc.cfg ../common/keys  > /dev/null
    if [ $? -ne 0 ]
    then
        pack_error "dragon toc0 run error"
        exit 1
    fi

 

    update_toc0  toc0.fex           sys_config.bin
    if [ $? -ne 0 ]
    then
        pack_error "update toc0 run error"
        exit 1
    fi

 

    dragonsecboot -toc1 dragon_toc.cfg ../common/keys ../common/sign_config/cnf_base.cnf ../common/version/version_base.mk
    if [ $? -ne 0 ]
    then
        pack_error "dragon toc1 run error"
        exit 1
    fi

 

    echo "secure signature ok!"
}

 

################################ Platform func ################################
function do_pack_android()
{
    local link_real=$(get_realpath ${ANDROID_IMAGE_OUT} ./)

 

    printf "packing for android\n"

 

    if [ -z "${ANDROID_IMAGE_OUT}" ] ; then
        pack_error "please specify ANDROID_IMAGE_OUT env"
        exit 1
    fi

 

    ln -sf ${link_real}/boot.img boot.fex
    ln -sf ${link_real}/system.img system.fex
    ln -sf ${link_real}/recovery.img recovery.fex

 

    if [ -f ${ANDROID_IMAGE_OUT}/userdata.img ] ; then
        ln -sf ${link_real}/userdata.img userdata.fex
    fi

 

    if [ "x${PACK_SIG}" = "xsig" ] ; then
        echo "signature sunxi mbr"
        signature sunxi_mbr.fex dlinfo.fex
        echo "signature over"
    elif [ "x${PACK_SIG}" = "xsecure" ] ; then
        echo "secure"
        do_signature
    elif [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
        echo "prev_refurbish"
        do_signature
    else
        echo "normal"
    fi
}

 

function do_pack_androidm()
{
    local link_real=$(get_realpath ${ANDROID_IMAGE_OUT} ./)

 

    printf "packing for android\n"

 

    if [ -z "${ANDROID_IMAGE_OUT}" ] ; then
        pack_error "please specify ANDROID_IMAGE_OUT env"
        exit 1
    fi

 

    ln -sf ${link_real}/boot.img boot.fex
    ln -sf ${link_real}/system.img system.fex
    ln -sf ${link_real}/recovery.img recovery.fex

 

    if [ -f ${ANDROID_IMAGE_OUT}/userdata.img ] ; then
        ln -sf ${link_real}/userdata.img userdata.fex
    fi

 

    if [ "x${PACK_SIG}" = "xsig" ] ; then
        echo "signature sunxi mbr"
        signature sunxi_mbr.fex dlinfo.fex
        echo "signature over"
    elif [ "x${PACK_SIG}" = "xsecure" ] ; then
        echo "secure"
        do_signature
    elif [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
        echo "prev_refurbish"
        do_signature
    else
        echo "normal"
    fi
}
function do_pack_camdroid()
{
    local link_real=$(get_realpath ${CAMLINUX_IMAGE_OUT} ./)

 

    printf "packing for camdroid\n"

 

    if [ -z "${CAMLINUX_IMAGE_OUT}" ] ; then
        pack_error "please specify CAMLINUX_IMAGE_OUT env"
        exit 1
    fi

 

    ln -sf ${link_real}/boot.img boot.fex
    ln -sf ${link_real}/system.img rootfs.fex
}

 

function do_pack_dragonboard()
{
    local link_real=$(get_realpath ${LICHEE_OUT} ./)
    printf "packing for dragonboard\n"

 

    ln -sf ${link_real}/boot.img boot.fex
    ln -sf ${link_real}/rootfs.ext4 rootfs.fex
}

 

function do_pack_linux()
{
    local link_real=$(get_realpath ${LICHEE_OUT} ./)

 

    printf "packing for linux\n"

 

    ln -sf ${link_real}/vmlinux.tar.bz2 vmlinux.fex
    ln -sf ${link_real}/boot.img        boot.fex
    ln -sf ${link_real}/rootfs.ext4     rootfs.fex

 

    # Those files is ready for SPINor.
    ln -sf ${link_real}/uImage          kernel.fex
    ln -sf ${link_real}/rootfs.squashfs rootfs_squashfs.fex

 

    if [ "x${PACK_SIG}" = "xsecure" ] ; then
        echo "secure"
        do_signature
    elif [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
        echo "prev_refurbish"
        do_signature
    else
        echo "normal"
    fi
}
echo liujunhua test
do_prepare
read -p  "pause" t 
do_ini_to_dts
read -p  "pause" t 
do_common
read -p  "pause" t 
do_pack_${PACK_PLATFORM}
read -p  "pause" t 
do_finish
 
第一步:准备 do_prepare
1)建立打包的工作文件夹  ./out
2)copying tools file
3)
 
第一步:设备树do_ini_to_dts
 
posted @ 2021-04-25 14:28  liujunhuasd  阅读(349)  评论(0编辑  收藏  举报