shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: MIT |
| 6 | # |
| 7 | |
| 8 | RTOS_BUILD_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..) |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 9 | BUILD_SYSTEM_DIR=$RTOS_BUILD_DIR/build_system |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 10 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 11 | export RTOS_BUILD_DIR |
| 12 | |
| 13 | # Parsing large package combination information |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 14 | function package_target_verify() { |
| 15 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 16 | ARCH_PREFIX="" |
| 17 | PRODUCT_SUFFIX="" |
| 18 | |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 19 | #Get the packed sequence selected by the user |
| 20 | j=0 |
| 21 | while IFS= read -r LINE; do |
| 22 | if [ $j == $CHOICE_PACKAGE ]; then |
| 23 | PACKAGE_ARRY=($(echo $LINE | tr ' ' ' ')) |
| 24 | fi |
| 25 | j=$((j + 1)) |
| 26 | done <$PACKAGE_COMBINATION |
| 27 | |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 28 | #parameter check |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 29 | if [ -z "$PACKAGE_ARRY" ]; then |
shijie.xiong | 9a3c904 | 2022-04-12 17:51:55 +0800 | [diff] [blame] | 30 | echo -e "\033[41;33m package list is not set, please execute source scripts/pkg_env.sh \033[0m" |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 31 | exit 1 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 32 | fi |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 33 | |
| 34 | #parameter check |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 35 | j=0 |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 36 | for ((loop = 0; loop < ${#PACKAGE_ARRY[@]}; loop += 4)); do |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 37 | pkg_arch[j]=${PACKAGE_ARRY[loop]} |
| 38 | pkg_soc[j]=${PACKAGE_ARRY[loop + 1]} |
| 39 | pkg_board[j]=${PACKAGE_ARRY[loop + 2]} |
| 40 | pkg_product[j]=${PACKAGE_ARRY[loop + 3]} |
| 41 | ARCH_PREFIX="$ARCH_PREFIX""${pkg_arch[j]}""-" |
| 42 | PRODUCT_SUFFIX="$PRODUCT_SUFFIX""-""${pkg_product[j]}" |
| 43 | j+=1 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 44 | done |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 45 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 46 | # set the board configuration path |
| 47 | IMAGE_BOARD_CONFIG_DIR="$RTOS_BUILD_DIR/image_packer/${pkg_soc[0]}/" |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 48 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 49 | # mirror storage path |
| 50 | AML_IMAGE_STORAGE_PATH=$RTOS_BUILD_DIR/output/packages/"${ARCH_PREFIX}""${pkg_soc[0]}"-"${pkg_board[0]}" |
| 51 | |
| 52 | # create mirror file directory |
| 53 | rm -fr $AML_IMAGE_STORAGE_PATH |
| 54 | mkdir -p $AML_IMAGE_STORAGE_PATH |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 55 | } |
| 56 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 57 | function compile_rtos_for_arm() { |
| 58 | # target file path |
| 59 | OUTPUT_PATH=${RTOS_BUILD_DIR}/output/$1-$3-$4 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 60 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 61 | IMAGE_PATH=${OUTPUT_PATH}/images |
| 62 | BINARY_FILE=${IMAGE_PATH}/${KERNEL}-signed.bin |
| 63 | DEBUG_FILE_PREFIX=${OUTPUT_PATH}/${KERNEL}/${KERNEL} |
| 64 | XIP_CONFIG_FILE=${RTOS_BUILD_DIR}/boards/$1/$3/lscript.h |
| 65 | BUILD_LINK_FILE=${RTOS_BUILD_DIR}/boards/$1/$3/lscript.h |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 66 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 67 | # Clean up rtos compilation intermediate files |
| 68 | rm -rf $OUTPUT_PATH |
shijie.xiong | 82d1b62 | 2022-06-28 14:33:57 +0800 | [diff] [blame] | 69 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 70 | # rtos load address |
| 71 | LINE=$(grep -m 1 "configTEXT_BASE" $BUILD_LINK_FILE) |
| 72 | RTOS_LOAD_ADDR=$(echo "$LINE" | grep -oP '0x[0-9a-fA-F]+') |
shijie.xiong | 82d1b62 | 2022-06-28 14:33:57 +0800 | [diff] [blame] | 73 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 74 | # determine whether to enable the xip function |
| 75 | RTOS_XIP=$(grep -E "^#define\s+CONFIG_XIP\s+[01]$" "$XIP_CONFIG_FILE" | awk '{print $3}') |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 76 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 77 | # start compile flow |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 78 | pushd $RTOS_BUILD_DIR |
| 79 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 80 | source scripts/env.sh $1 $2 $3 $4 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 81 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 82 | if [ "$BACKTRACE_ENABLE" = "1" ]; then |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 83 | make backtrace |
| 84 | else |
| 85 | make |
| 86 | fi |
| 87 | |
| 88 | if [ $? -ne 0 ]; then |
| 89 | echo "bulid rtos image faile error:$?" |
| 90 | popd |
| 91 | exit 1 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 92 | fi |
| 93 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 94 | if [ "$RTOS_XIP" = "1" ]; then |
| 95 | make -f ${BUILD_SYSTEM_DIR}/xip.mk xip |
| 96 | cp ${OUTPUT_PATH}/${KERNEL}/${KERNEL}.bin ${BINARY_FILE} |
| 97 | fi |
| 98 | |
| 99 | mkimage -A ${ARCH} -O u-boot -T standalone -C none -a ${RTOS_LOAD_ADDR} -e ${RTOS_LOAD_ADDR} -n rtos -d ${BINARY_FILE} ${IMAGE_PATH}/rtos-uImage |
| 100 | |
| 101 | if [ "$RTOS_XIP" = "1" ]; then |
| 102 | cp ${OUTPUT_PATH}/freertos/freertos_b.bin ${IMAGE_PATH}/rtos-xipA |
| 103 | cp ${IMAGE_PATH}/* $AML_IMAGE_STORAGE_PATH/ |
| 104 | else |
| 105 | test -f ${IMAGE_PATH}/rtos-uImage && cp ${IMAGE_PATH}/rtos-uImage $AML_IMAGE_STORAGE_PATH/rtos-uImage |
| 106 | fi |
| 107 | |
| 108 | test -f ${DEBUG_FILE_PREFIX}.lst && cp ${DEBUG_FILE_PREFIX}.lst $AML_IMAGE_STORAGE_PATH/$1-$3.lst |
| 109 | test -f ${DEBUG_FILE_PREFIX}.map && cp ${DEBUG_FILE_PREFIX}.map $AML_IMAGE_STORAGE_PATH/$1-$3.map |
| 110 | |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 111 | popd |
| 112 | } |
| 113 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 114 | function compile_rtos_for_other() { |
| 115 | # target file path |
| 116 | OUTPUT_PATH=${RTOS_BUILD_DIR}/output/$1-$3-$4 |
| 117 | |
| 118 | IMAGE_PATH=${OUTPUT_PATH}/images |
| 119 | BINARY_FILE=${IMAGE_PATH}/${KERNEL}-signed.bin |
| 120 | DEBUG_FILE_PREFIX=${OUTPUT_PATH}/${KERNEL}/${KERNEL} |
| 121 | |
| 122 | # Clean up rtos compilation intermediate files |
| 123 | rm -rf $OUTPUT_PATH |
| 124 | |
| 125 | # start compile flow |
| 126 | pushd $RTOS_BUILD_DIR |
| 127 | |
| 128 | source scripts/env.sh $1 $2 $3 $4 |
| 129 | |
| 130 | make |
| 131 | |
| 132 | if [ "$1" == "xtensa" ]; then |
| 133 | test -f ${BINARY_FILE} && cp ${BINARY_FILE} $AML_IMAGE_STORAGE_PATH/dspboot.bin |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 134 | else |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 135 | test -f ${BINARY_FILE} && cp ${BINARY_FILE} $AML_IMAGE_STORAGE_PATH/${KERNEL}-signed.bin |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 136 | fi |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 137 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 138 | test -f ${DEBUG_FILE_PREFIX}.lst && cp ${DEBUG_FILE_PREFIX}.lst $AML_IMAGE_STORAGE_PATH/$1-$3.lst |
| 139 | test -f ${DEBUG_FILE_PREFIX}.map && cp ${DEBUG_FILE_PREFIX}.map $AML_IMAGE_STORAGE_PATH/$1-$3.map |
| 140 | |
| 141 | popd |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 142 | } |
| 143 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 144 | # Compile rtos for all architectures |
| 145 | function compile_rtos_for_all() { |
| 146 | for ((loop = 0; loop < ${#pkg_board[@]}; loop += 1)); do |
| 147 | if [[ ${pkg_arch[loop]} == *"arm"* ]]; then |
| 148 | compile_rtos_for_arm ${pkg_arch[loop]} ${pkg_soc[loop]} ${pkg_board[loop]} ${pkg_product[loop]} |
| 149 | else |
| 150 | compile_rtos_for_other ${pkg_arch[loop]} ${pkg_soc[loop]} ${pkg_board[loop]} ${pkg_product[loop]} |
| 151 | fi |
| 152 | done |
| 153 | } |
| 154 | |
| 155 | # Compile the bootloader |
| 156 | function build_bootloader() { |
| 157 | echo "start compiling bootloader ..." |
| 158 | echo "<-------------- ${pkg_arch[0]} ${pkg_soc[0]} ${pkg_board[0]} ${pkg_product[0]} -------------->" |
| 159 | |
| 160 | #Select the compile parameters of the bootstrap |
| 161 | case ${pkg_board[0]} in |
| 162 | 'ad401_a113l') |
| 163 | uboot_type="a1_ad401_nand_rtos" |
| 164 | ;; |
| 165 | 'ad403_a113l') |
| 166 | uboot_type="a1_ad403_nand_rtos" |
| 167 | ;; |
| 168 | *) ;; |
| 169 | esac |
| 170 | |
| 171 | if [ -z "$uboot_type" ]; then |
| 172 | echo "Waring: Select board(${pkg_board[0]}) not support compile uboot" |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 173 | exit 1 |
| 174 | else |
shijie.xiong | 446f12c | 2022-11-30 10:24:17 +0800 | [diff] [blame] | 175 | pushd $RTOS_BUILD_DIR/boot/u-boot |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 176 | ./mk $uboot_type |
| 177 | test -f build/u-boot.bin && cp -av build/u-boot.bin* $AML_IMAGE_STORAGE_PATH |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 178 | popd |
| 179 | fi |
| 180 | } |
| 181 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 182 | function aml_image_package() { |
| 183 | install $IMAGE_BOARD_CONFIG_DIR/platform.conf $AML_IMAGE_STORAGE_PATH/ |
| 184 | install $IMAGE_BOARD_CONFIG_DIR/usb_flow.aml $AML_IMAGE_STORAGE_PATH/ |
| 185 | install $IMAGE_BOARD_CONFIG_DIR/aml_sdc_burn.ini $AML_IMAGE_STORAGE_PATH/ |
| 186 | |
| 187 | if [ -e "$AML_IMAGE_STORAGE_PATH/dspboot.bin" ]; then |
| 188 | cp $IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package.conf $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.conf |
| 189 | elif [ -e "$AML_IMAGE_STORAGE_PATH/rtos-xipA.bin" ]; then |
| 190 | cp $IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_xip.conf $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.conf |
| 191 | else |
| 192 | cp $IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_ndsp.conf $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.conf |
| 193 | fi |
| 194 | |
| 195 | $RTOS_BUILD_DIR/image_packer/aml_image_v2_packer -r $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.conf $AML_IMAGE_STORAGE_PATH $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.img |
| 196 | |
| 197 | cd $AML_IMAGE_STORAGE_PATH && rm $(ls | grep -v ".lst" | grep -v ".map" | grep -v ".img") |
| 198 | } |
| 199 | |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 200 | package_target_verify |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 201 | compile_rtos_for_all |
| 202 | build_bootloader |
| 203 | aml_image_package |