| | |
| | | #!/bin/bash |
| | | |
| | | # Build Cortex-M FreeRTOS SDK or not |
| | | #BUILD_MCORE=yes |
| | | |
| | | # this project absolute path |
| | | PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
| | | |
| | |
| | | PRFX_PATH=$PRJ_PATH/install |
| | | |
| | | # binaries finally install path if needed |
| | | INST_PATH=/tftp |
| | | #INST_PATH=/tftp |
| | | |
| | | # download taballs path |
| | | TARBALL_PATH=$PRJ_PATH/tarballs |
| | | |
| | | # config file path |
| | | CONF_FILE=$TOP_PATH/config.json |
| | |
| | | echo -e "\033[40;32m $1 \033[0m" |
| | | } |
| | | |
| | | # decompress a packet to destination path |
| | | function do_unpack() |
| | | { |
| | | tarball=$1 |
| | | dstpath=`pwd` |
| | | |
| | | if [[ $# == 2 ]] ; then |
| | | dstpath=$2 |
| | | fi |
| | | |
| | | pr_info "decompress $tarball => $dstpath" |
| | | |
| | | mkdir -p $dstpath |
| | | case $tarball in |
| | | *.tar.gz) |
| | | tar -xzf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.bz2) |
| | | tar -xjf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.xz) |
| | | tar -xJf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.zst) |
| | | tar -I zstd -xf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar) |
| | | tar -xf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.zip) |
| | | unzip -qo $tarball -d $dstpath |
| | | ;; |
| | | |
| | | *) |
| | | pr_error "decompress Unsupport packet: $tarball" |
| | | return 1; |
| | | ;; |
| | | esac |
| | | } |
| | | |
| | | # select firmware version by BSP version |
| | | function export_fmver() |
| | | { |
| | |
| | | { |
| | | 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 BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE` |
| | | export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE` |
| | | export MCORE_COMPILE=`jq -r ".bsp.cortexMtool" $CONF_FILE` |
| | | |
| | | export SRCS="imx-atf uboot-imx imx-mkimage" |
| | | export BRANCH=$BSP_VER |
| | | export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
| | | export ARCH=arm |
| | | |
| | | # i.MX6ULL only need uboot-imx |
| | | if [[ $BOARD =~ mx6ull ]] ; then |
| | | export SRCS="uboot-imx" |
| | | return ; |
| | | fi |
| | | |
| | | export SRCS="uboot-imx imx-atf imx-mkimage" |
| | | 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_ddr4_evk |
| | | IMXBOOT_DTB=imx8mp-ddr4-evk.dtb |
| | | IMXBOOT_TARGETS=flash_evk |
| | | IMXBOOT_DTB=imx8mp-evk.dtb |
| | | MKIMG_BIN_PATH=$PRJ_PATH/imx-mkimage/iMX8M/ |
| | | |
| | | elif [[ $BOARD =~ mx8mm ]] ; then |
| | |
| | | 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 - |
| | | if [[ $BSP_URL =~ github.com ]] ; then |
| | | git clone $BSP_URL/$src.git -b $BRANCH --depth=1 |
| | | else |
| | | mkdir -p $TARBALL_PATH |
| | | |
| | | # Download source code packet |
| | | if [ ! -s $TARBALL_PATH/$src.tar.xz ] ; then |
| | | wget $BSP_URL/imx/bsp/$BSP_VER/$src.tar.xz -P $TARBALL_PATH |
| | | fi |
| | | |
| | | # decompress source code packet |
| | | do_unpack $TARBALL_PATH/$src.tar.xz |
| | | fi |
| | | |
| | | # 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 |
| | | |
| | | # i.MX6ULL only need uboot-imx |
| | | if [[ $BOARD =~ mx6ull ]] ; then |
| | | return ; |
| | | fi |
| | | |
| | | # Download CortexM FreeRTOS SDK if needed |
| | | if [ "$BUILD_MCORE" == "yes" ] ; then |
| | | |
| | | src=cortexm-sdk |
| | | |
| | | cd $PRJ_PATH |
| | | |
| | | if [ -d $src ] ; then |
| | | pr_info "$src source code fetched already" |
| | | else |
| | | pr_info "start fetch $src source code" |
| | | |
| | | if [[ $BSP_URL =~ github.com ]] ; then |
| | | pr_error "INFO: Please download $BOARD CortexM SDK from https://mcuxpresso.nxp.com by manual." |
| | | else |
| | | pack=cortexm-sdk-${BOARD} |
| | | |
| | | # Download source code packet |
| | | if [ ! -s $TARBALL_PATH/$pack.tar.gz ] ; then |
| | | wget $BSP_URL/bsp/$BSP_VER/$pack.tar.gz -P $TARBALL_PATH |
| | | fi |
| | | |
| | | # decompress source code packet |
| | | do_unpack $TARBALL_PATH/$pack.tar.gz $PRJ_PATH/$src |
| | | fi |
| | | fi |
| | | fi |
| | | |
| | | # Download firmware from NXP official URL |
| | | mkdir -p $FMW_PATH && cd $FMW_PATH |
| | | |
| | | for fmw in $FMWS |
| | |
| | | # 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 |
| | | SRC=cortexm-sdk |
| | | |
| | | if [ "$BUILD_MCORE" != "yes" ] ; then |
| | | pr_warn "Skip build Cortex-M core SDK source code '$SRC'" |
| | | return 0; |
| | | fi |
| | | |
| | | if [[ $BOARD =~ mx8mp ]] ; then |
| | | EVK=evkmimx8mp |
| | | fi |
| | | DEMO_PATH=boards/$EVK/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/.*\\') |
| | | MCORE_IMAGE=cortexM-${BOARD}.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 |
| | | pr_error "INFO: Please download $BOARD SDK from https://mcuxpresso.nxp.com by manual and" |
| | | pr_error " decompress it to folder '$PRJ_PATH/$SRC'" |
| | | exit; |
| | | fi |
| | | |
| | | pr_warn "start build $SRC" |
| | | |
| | | cd $PRJ_PATH/${SRC} |
| | | cd $DEMO_PATH |
| | | cd $PRJ_PATH/${SRC}/$DEMO_PATH |
| | | export ARMGCC_DIR=$(echo $MCORE_COMPILE | sed 's\/bin/.*\\') |
| | | |
| | | #bash clean.sh |
| | | if [ ! -s $DEMO_BIN ] ; then |
| | |
| | | fi |
| | | |
| | | set -x |
| | | cp $DEMO_BIN $MKIMG_BIN_PATH/$MCORE_IMAGE |
| | | cp $DEMO_BIN $PRFX_PATH/$MCORE_IMAGE |
| | | set +x |
| | | } |
| | | |
| | | function build_uboot() |
| | | { |
| | | SRC=uboot-imx |
| | | patch_file=$PRJ_PATH/patches/$BOARD/$SRC-$BSP_VER.patch |
| | | defconfig=${BOARD}_defconfig |
| | | |
| | | pr_warn "start build $SRC" |
| | | cd $PRJ_PATH/${SRC} |
| | | |
| | | # do patch if not patched |
| | | if [ ! -s configs/$defconfig -a -s $patch_file ] ; then |
| | | pr_warn "do patch for $SRC now..." |
| | | patch -p1 < $patch_file |
| | | fi |
| | | |
| | | if [ ! -f .config ] ; then |
| | | make ARCH=arm ${BOARD}_defconfig |
| | | fi |
| | | |
| | | make -j${JOBS} CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm |
| | | |
| | | # i.MX6ULL only need uboot-imx |
| | | if [[ $BOARD =~ mx6ull ]] ; then |
| | | cp u-boot-dtb.imx u-boot-${BOARD}.imx |
| | | chmod a+x u-boot-${BOARD}.imx |
| | | set -x |
| | | cp u-boot-${BOARD}.imx $PRFX_PATH |
| | | set +x |
| | | return 0; |
| | | fi |
| | | |
| | | set -x |
| | | cp u-boot.bin $MKIMG_BIN_PATH |
| | |
| | | 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/ddr4_imem_1d*.bin $MKIMG_BIN_PATH |
| | | cp $FMW_PATH/firmware-imx-*/firmware/ddr/synopsys/ddr4_dmem_1d*.bin $MKIMG_BIN_PATH |
| | | cp $FMW_PATH/firmware-imx-*/firmware/ddr/synopsys/ddr4_imem_2d*.bin $MKIMG_BIN_PATH |
| | | cp $FMW_PATH/firmware-imx-*/firmware/ddr/synopsys/ddr4_dmem_2d*.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 REV=A2 $IMXBOOT_TARGETS |
| | | 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 |
| | |
| | | cd $PRJ_PATH |
| | | mkdir -p $PRFX_PATH |
| | | |
| | | build_atf |
| | | #build_cortexM |
| | | build_uboot |
| | | |
| | | # i.MX6ULL only need uboot-imx |
| | | if [[ ${BOARD} =~ mx6ull ]] ; then |
| | | return ; |
| | | fi |
| | | |
| | | build_atf |
| | | build_imxboot |
| | | build_cortexM |
| | | } |
| | | |
| | | function do_install() |
| | |
| | | |
| | | if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then |
| | | pr_info "install bootloader to '$INST_PATH'" |
| | | cp $PRFX_PATH/u-boot-${BOARD}.imx $INST_PATH |
| | | cp $PRFX_PATH/* $INST_PATH |
| | | #sz $PRFX_PATH/u-boot-${BOARD}.imx |
| | | fi |
| | | } |
| | | |
| | |
| | | done |
| | | |
| | | rm -rf $PRJ_PATH/firmware |
| | | rm -rf $PRJ_PATH/cortexm-sdk |
| | | rm -rf $PRJ_PATH/tarballs |
| | | rm -rf $PRFX_PATH |
| | | } |
| | | |