#!/bin/bash # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) # top project absolute path TOP_PATH=$(realpath $PRJ_PATH/..) # binaries build prefix install path PRFX_PATH=$PRJ_PATH/install # binaries finally install path if needed INST_PATH=/tftp # config file path CONF_FILE=$TOP_PATH/config.json # shell script will exit once get command error set -e #+-------------------------+ #| Shell script functions | #+-------------------------+ function pr_error() { echo -e "\033[40;31m $1 \033[0m" } function pr_warn() { echo -e "\033[40;33m $1 \033[0m" } function pr_info() { echo -e "\033[40;32m $1 \033[0m" } # select firmware version by BSP version function export_fmver() { if [[ $BSP_VER =~ 6.1.36 ]] ; then export FMW_IMX=firmware-imx-8.21 fi export FMWS="$FMW_IMX" export FMW_URL=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/ export FMW_PATH=$PRJ_PATH/firmware/ } # parser configure file and export environment variable function export_env() { export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` export GIT_URL=`jq -r ".bsp.giturl" $CONF_FILE | tr 'A-Z' 'a-z'` export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE | tr 'A-Z' 'a-z'` export MCORE_COMPILE=`jq -r ".bsp.cortexMtool" $CONF_FILE | tr 'A-Z' 'a-z'` export SRCS="imx-atf uboot-imx imx-mkimage" export BRANCH=$BSP_VER export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` export ARCH=arm export_fmver export SRCS="imx-atf uboot-imx imx-mkimage" if [[ $BOARD =~ mx8mp ]] ; then ATF_PLATFORM=imx8mp IMX_BOOT_SOC_TARGET=iMX8MP IMXBOOT_TARGETS=flash_evk IMXBOOT_DTB=imx8mp-evk.dtb MKIMG_BIN_PATH=$PRJ_PATH/imx-mkimage/iMX8M/ elif [[ $BOARD =~ mx8mm ]] ; then ATF_PLATFORM=imx8mm IMX_BOOT_SOC_TARGET=iMX8MM IMXBOOT_TARGETS=flash_ddr4_evk IMXBOOT_DTB=imx8mm-ddr4-evk.dtb MKIMG_BIN_PATH=$PRJ_PATH/imx-mkimage/iMX8M/ fi } function do_fetch() { cd $PRJ_PATH for src in $SRCS do if [ -d $src ] ; then pr_info "$src source code fetched already" continue fi pr_info "start fetch $src source code" git clone $GIT_URL/$src.git -b $BRANCH --depth=1 # do patch if patch file exist PATCH_FILE=$PRJ_PATH/patches/$BOARD/$src-$BSP_VER.patch if [ -s $PATCH_FILE ] ; then pr_warn "do patch for $src now..." cd $src patch -p1 < $PATCH_FILE cd - fi done mkdir -p $FMW_PATH && cd $FMW_PATH for fmw in $FMWS do if [ -d $fmw ] ; then pr_info "Firmware $fmw fetch already" continue fi pr_info "start fetch $fmw firmware" wget $FMW_URL/$fmw.bin bash $fmw.bin --auto-accept > /dev/null 2>&1 done rm -f *.bin } function build_atf() { SRC=imx-atf pr_warn "start build $SRC" cd $PRJ_PATH/${SRC} make -j${JOBS} CROSS_COMPILE=${CROSS_COMPILE} PLAT=$ATF_PLATFORM bl31 set -x cp build/$ATF_PLATFORM/release/bl31.bin $MKIMG_BIN_PATH set +x } # Cortex-M SDK download from https://mcuxpresso.nxp.com/ by manual function build_cortexM() { SRC=mcore-sdk DEMO_PATH=boards/$MCORE_BOARD/multicore_examples/rpmsg_lite_str_echo_rtos/armgcc DEMO_BIN=release/rpmsg_lite_str_echo_rtos.bin export ARMGCC_DIR=$(echo $MCORE_COMPILE | sed 's\/bin/.*\\') if [ ! -d $PRJ_PATH/$SRC ] ; then if [ "$MCORE_BUILD" == "yes" ] ; then pr_error "INFO: Please download $BOARD SDK from https://mcuxpresso.nxp.com" pr_error " by manual and decompress it to folder '$SRC'" exit; else pr_warn "Skip build Cortex-M core SDK source code '$SRC'" return ; fi fi pr_warn "start build $SRC" cd $PRJ_PATH/${SRC} cd $DEMO_PATH #bash clean.sh if [ ! -s $DEMO_BIN ] ; then bash build_release.sh fi set -x cp $DEMO_BIN $MKIMG_BIN_PATH/$MCORE_IMAGE set +x } function build_uboot() { SRC=uboot-imx pr_warn "start build $SRC" cd $PRJ_PATH/${SRC} if [ ! -f .config ] ; then make ARCH=arm ${BOARD}_defconfig fi make -j${JOBS} CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm set -x cp u-boot.bin $MKIMG_BIN_PATH cp u-boot-nodtb.bin $MKIMG_BIN_PATH cp spl/u-boot-spl.bin $MKIMG_BIN_PATH cp arch/arm/dts/${BOARD}.dtb $MKIMG_BIN_PATH/$IMXBOOT_DTB cp tools/mkimage $MKIMG_BIN_PATH/mkimage_uboot set +x } # The diagram below illustrate a signed iMX8 flash.bin image layout: # reference: uboot-imx/doc/imx/habv4/guides/mx8m_secure_boot.txt # # +-----------------------------+ # | | # | *Signed HDMI/DP FW | # | | # +-----------------------------+ # | Padding | # ------- +-----------------------------+ -------- # ^ | IVT - SPL | ^ # Signed | +-----------------------------+ | # Data | | u-boot-spl.bin | | # | | + | | SPL # v | DDR FW | | Image # ------- +-----------------------------+ | # | CSF - SPL + DDR FW | v # +-----------------------------+ -------- # | Padding | # ------- +-----------------------------+ -------- # Signed ^ | FDT - FIT | ^ # Data | +-----------------------------+ | # v | IVT - FIT | | # ------- +-----------------------------+ | # | CSF - FIT | | # ------- +-----------------------------+ | FIT # ^ | u-boot-nodtb.bin | | Image # | +-----------------------------+ | # Signed | | OP-TEE (Optional) | | # Data | +-----------------------------+ | # | | bl31.bin (ATF) | | # | +-----------------------------+ | # v | u-boot.dtb | v # ------- +-----------------------------+ -------- # # # Reference: <> 4.5.13 How to build imx-boot image by using imx-mkimage function build_imxboot() { SRC=imx-mkimage pr_warn "start build $SRC" cd $PRJ_PATH/${SRC} # iMX8MP, iMX8MP if [[ $BOARD =~ mx8m ]] ; then pr_info "Copy DDR4 firmware to $MKIMG_BIN_PATH" cp $FMW_PATH/firmware-imx-*/firmware/hdmi/cadence/signed_hdmi_imx8m.bin $MKIMG_BIN_PATH cp $FMW_PATH/firmware-imx-*/firmware/ddr/synopsys/lpddr4_pmu_train_[1-2]d_imem_202006.bin $MKIMG_BIN_PATH cp $FMW_PATH/firmware-imx-*/firmware/ddr/synopsys/lpddr4_pmu_train_[1-2]d_dmem_202006.bin $MKIMG_BIN_PATH fi make SOC=$IMX_BOOT_SOC_TARGET $IMXBOOT_TARGETS cp $MKIMG_BIN_PATH/flash.bin u-boot-${BOARD}.imx chmod a+x u-boot-${BOARD}.imx cp u-boot-${BOARD}.imx $PRFX_PATH } function do_build() { cd $PRJ_PATH mkdir -p $PRFX_PATH build_atf #build_cortexM build_uboot build_imxboot } function do_install() { cd $PRJ_PATH echo "" pr_info "bootloader installed to '$PRFX_PATH'" ls $PRFX_PATH && echo "" if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then pr_info "install bootloader to '$INST_PATH'" cp $PRFX_PATH/u-boot-${BOARD}.imx $INST_PATH fi } function do_clean() { for d in $SRCS do rm -rf $PRJ_PATH/$d done rm -rf $PRJ_PATH/firmware rm -rf $PRFX_PATH } #+-------------------------+ #| Shell script body entry | #+-------------------------+ cd $PRJ_PATH export_env if [[ $# == 1 && $1 == -c ]] ;then pr_warn "start clean bootloader" do_clean exit; fi pr_warn "start build bootloader for ${BOARD}" do_fetch do_build do_install