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 |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 30 | echo -e "\033[41;33m package list is not set, please execute 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 | |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 57 | function package_kernel_for_mcuboot() { |
| 58 | MCUBOOT_LIB_DIR=${RTOS_BUILD_DIR}/lib/mcuboot |
| 59 | MCUBOOT_SIGNTOOL_DIR=${MCUBOOT_LIB_DIR}/scripts |
| 60 | MCUBOOT_SIGNTOOL=${MCUBOOT_SIGNTOOL_DIR}/imgtool.py |
| 61 | MCUBOOT_OUT_DIR=${RTOS_BUILD_DIR}/output/$1-$2-mcuboot |
| 62 | MCUBOOT_CFG=$MCUBOOT_OUT_DIR/$KERNEL/.config |
| 63 | IMGTOOL_INPUT_FILE=$OUTPUT_PATH/$KERNEL/$KERNEL.bin |
| 64 | IMGTOOL_OUTPUT_FILE=$OUTPUT_PATH/images/$KERNEL-signed.bin |
| 65 | |
| 66 | KERNEL_SLOT_SZ="$(grep -E \ |
| 67 | "^CONFIG_LIB_MCUBOOT_KERNEL_SIZE=" "$MCUBOOT_CFG" | cut -d '=' -f2)" |
| 68 | |
| 69 | python3 $MCUBOOT_SIGNTOOL sign --key $MCUBOOT_LIB_DIR/root-rsa-2048.pem \ |
| 70 | --header-size 0x1000 --align 4 --slot-size ${KERNEL_SLOT_SZ} \ |
| 71 | --pad --version 1.0.0 --pad-header --load-addr 0x10000 \ |
| 72 | ${IMGTOOL_INPUT_FILE} \ |
| 73 | ${IMGTOOL_OUTPUT_FILE} |
| 74 | |
fugui.zhang | d2a41d6 | 2023-10-13 09:54:35 +0800 | [diff] [blame] | 75 | cp ${IMGTOOL_OUTPUT_FILE} ${IMAGE_PATH}/rtos-mcuImage |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 76 | |
| 77 | PRODUCT_CFG=${RTOS_BUILD_DIR}/output/$1-$2-$3/$KERNEL/.config |
| 78 | BT_INPUT_FILE=${RTOS_BUILD_DIR}/boards/${pkg_arch[0]}/${pkg_board[0]}/bt_fw.bin |
| 79 | BT_OUTPUT_FILE=$AML_IMAGE_STORAGE_PATH/bt-signed.bin |
| 80 | BT_SLOT_SZ="$(grep -E "^CONFIG_LIB_MCUBOOT_BT_SIZE=" "$MCUBOOT_CFG" | cut -d '=' -f2)" |
| 81 | |
| 82 | python3 $MCUBOOT_SIGNTOOL sign --key $MCUBOOT_LIB_DIR/root-rsa-2048.pem \ |
| 83 | --header-size 0x1000 --align 4 --slot-size ${BT_SLOT_SZ} \ |
| 84 | --version 1.0.0 \ |
| 85 | --pad-header \ |
| 86 | ${BT_INPUT_FILE} \ |
| 87 | ${BT_OUTPUT_FILE} |
| 88 | cp $BT_OUTPUT_FILE ${IMAGE_PATH}/bt |
| 89 | |
| 90 | } |
| 91 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 92 | function compile_rtos_for_arm() { |
| 93 | # target file path |
| 94 | OUTPUT_PATH=${RTOS_BUILD_DIR}/output/$1-$3-$4 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 95 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 96 | IMAGE_PATH=${OUTPUT_PATH}/images |
| 97 | BINARY_FILE=${IMAGE_PATH}/${KERNEL}-signed.bin |
| 98 | DEBUG_FILE_PREFIX=${OUTPUT_PATH}/${KERNEL}/${KERNEL} |
| 99 | XIP_CONFIG_FILE=${RTOS_BUILD_DIR}/boards/$1/$3/lscript.h |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 100 | BUILD_DISASSEMBLY_FILE=${DEBUG_FILE_PREFIX}.lst |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 101 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 102 | # Clean up rtos compilation intermediate files |
| 103 | rm -rf $OUTPUT_PATH |
shijie.xiong | 82d1b62 | 2022-06-28 14:33:57 +0800 | [diff] [blame] | 104 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 105 | # determine whether to enable the xip function |
| 106 | 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] | 107 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 108 | # start compile flow |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 109 | pushd $RTOS_BUILD_DIR |
| 110 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 111 | source scripts/env.sh $1 $2 $3 $4 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 112 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 113 | if [ "$BACKTRACE_ENABLE" = "1" ]; then |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 114 | make backtrace |
| 115 | else |
| 116 | make |
| 117 | fi |
| 118 | |
| 119 | if [ $? -ne 0 ]; then |
| 120 | echo "bulid rtos image faile error:$?" |
| 121 | popd |
| 122 | exit 1 |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 123 | fi |
| 124 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 125 | if [ "$RTOS_XIP" = "1" ]; then |
| 126 | make -f ${BUILD_SYSTEM_DIR}/xip.mk xip |
| 127 | cp ${OUTPUT_PATH}/${KERNEL}/${KERNEL}.bin ${BINARY_FILE} |
| 128 | fi |
| 129 | |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 130 | # rtos load address |
| 131 | RTOS_LOAD_ADDR=$(sed -n 's/^0*\([0-9a-fA-F]*\) <__image_copy_start>:/0x\1/p' $BUILD_DISASSEMBLY_FILE | sed 's/0x0*/0x/') |
| 132 | |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 133 | if [ -n "$BUILD_MCUBOOT" ]; then |
| 134 | package_kernel_for_mcuboot $1 $3 $4 |
| 135 | else |
| 136 | mkimage -A ${ARCH} -O u-boot -T standalone -C none -a ${RTOS_LOAD_ADDR} \ |
| 137 | -e ${RTOS_LOAD_ADDR} -n rtos -d ${BINARY_FILE} ${IMAGE_PATH}/rtos-uImage |
| 138 | fi |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 139 | |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 140 | if [ "$RTOS_XIP" = "1" ]; then |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 141 | cp ${OUTPUT_PATH}/freertos/freertos_b.bin ${IMAGE_PATH}/rtos-xipA |
| 142 | cp ${IMAGE_PATH}/* $AML_IMAGE_STORAGE_PATH/ |
| 143 | else |
fugui.zhang | d2a41d6 | 2023-10-13 09:54:35 +0800 | [diff] [blame] | 144 | test -f ${IMAGE_PATH}/rtos-mcuImage && cp \ |
| 145 | ${IMAGE_PATH}/rtos-mcuImage $AML_IMAGE_STORAGE_PATH/rtos-mcuImage |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 146 | fi |
| 147 | |
| 148 | test -f ${DEBUG_FILE_PREFIX}.lst && cp ${DEBUG_FILE_PREFIX}.lst $AML_IMAGE_STORAGE_PATH/$1-$3.lst |
| 149 | test -f ${DEBUG_FILE_PREFIX}.map && cp ${DEBUG_FILE_PREFIX}.map $AML_IMAGE_STORAGE_PATH/$1-$3.map |
| 150 | |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 151 | popd |
| 152 | } |
| 153 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 154 | function compile_rtos_for_other() { |
| 155 | # target file path |
| 156 | OUTPUT_PATH=${RTOS_BUILD_DIR}/output/$1-$3-$4 |
| 157 | |
| 158 | IMAGE_PATH=${OUTPUT_PATH}/images |
| 159 | BINARY_FILE=${IMAGE_PATH}/${KERNEL}-signed.bin |
| 160 | DEBUG_FILE_PREFIX=${OUTPUT_PATH}/${KERNEL}/${KERNEL} |
| 161 | |
| 162 | # Clean up rtos compilation intermediate files |
| 163 | rm -rf $OUTPUT_PATH |
| 164 | |
| 165 | # start compile flow |
| 166 | pushd $RTOS_BUILD_DIR |
| 167 | |
| 168 | source scripts/env.sh $1 $2 $3 $4 |
| 169 | |
| 170 | make |
| 171 | |
| 172 | if [ "$1" == "xtensa" ]; then |
| 173 | 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] | 174 | else |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 175 | 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] | 176 | fi |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 177 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 178 | test -f ${DEBUG_FILE_PREFIX}.lst && cp ${DEBUG_FILE_PREFIX}.lst $AML_IMAGE_STORAGE_PATH/$1-$3.lst |
| 179 | test -f ${DEBUG_FILE_PREFIX}.map && cp ${DEBUG_FILE_PREFIX}.map $AML_IMAGE_STORAGE_PATH/$1-$3.map |
| 180 | |
| 181 | popd |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 182 | } |
| 183 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 184 | # Compile rtos for all architectures |
| 185 | function compile_rtos_for_all() { |
| 186 | for ((loop = 0; loop < ${#pkg_board[@]}; loop += 1)); do |
| 187 | if [[ ${pkg_arch[loop]} == *"arm"* ]]; then |
| 188 | compile_rtos_for_arm ${pkg_arch[loop]} ${pkg_soc[loop]} ${pkg_board[loop]} ${pkg_product[loop]} |
| 189 | else |
| 190 | compile_rtos_for_other ${pkg_arch[loop]} ${pkg_soc[loop]} ${pkg_board[loop]} ${pkg_product[loop]} |
| 191 | fi |
| 192 | done |
| 193 | } |
| 194 | |
| 195 | # Compile the bootloader |
| 196 | function build_bootloader() { |
| 197 | echo "start compiling bootloader ..." |
| 198 | echo "<-------------- ${pkg_arch[0]} ${pkg_soc[0]} ${pkg_board[0]} ${pkg_product[0]} -------------->" |
| 199 | |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 200 | if [ "$1" == "mcuboot" ]; then |
| 201 | source $RTOS_BUILD_DIR/scripts/package_mcuboot.sh |
| 202 | compile_mcuboot ${pkg_arch[0]} ${pkg_soc[0]} ${pkg_board[0]} mcuboot $AML_IMAGE_STORAGE_PATH |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 203 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_mcuboot.conf |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 204 | echo "Compilation of MCUBoot is successful" |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 205 | else |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 206 | #Select the packaging configuration file. |
| 207 | if [ -e "$AML_IMAGE_STORAGE_PATH/dspboot.bin" ]; then |
| 208 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package.conf |
| 209 | elif [ -e "$AML_IMAGE_STORAGE_PATH/rtos-xipA.bin" ]; then |
| 210 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_xip.conf |
| 211 | elif [ -e "$AML_IMAGE_STORAGE_PATH/u-boot.bin" ]; then |
| 212 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_ndsp.conf |
| 213 | fi |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 214 | #Select the compile parameters of the bootstrap |
| 215 | case ${pkg_board[0]} in |
| 216 | 'ad401_a113l') |
| 217 | uboot_type="a1_ad401_nand_rtos" |
| 218 | ;; |
| 219 | 'ad403_a113l') |
| 220 | uboot_type="a1_ad403_nor_rtos" |
| 221 | ;; |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 222 | 'ad401_a113l_hifi4a_psram') |
| 223 | uboot_type="a1_ad401_nor_rtos" |
| 224 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_dsp.conf |
| 225 | ;; |
| 226 | 'ad403_a113l_hifi4a') |
| 227 | uboot_type="a1_ad403_nand_rtos" |
| 228 | AML_PACKAGE_CONFIG_FILE=$IMAGE_BOARD_CONFIG_DIR/aml_upgrade_package_dsp.conf |
| 229 | ;; |
fugui.zhang | 4266657 | 2023-09-27 16:33:20 +0800 | [diff] [blame] | 230 | *) ;; |
| 231 | esac |
| 232 | |
| 233 | if [ -z "$uboot_type" ]; then |
| 234 | echo "Waring: Select board(${pkg_board[0]}) not support compile uboot" |
| 235 | exit 1 |
| 236 | else |
| 237 | pushd $RTOS_BUILD_DIR/boot/u-boot |
| 238 | ./mk $uboot_type |
| 239 | test -f build/u-boot.bin && cp -av build/u-boot.bin* $AML_IMAGE_STORAGE_PATH |
| 240 | popd |
| 241 | fi |
shijie.xiong | 1369b8c | 2022-03-31 15:22:51 +0800 | [diff] [blame] | 242 | fi |
| 243 | } |
| 244 | |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 245 | function aml_image_package() { |
| 246 | install $IMAGE_BOARD_CONFIG_DIR/platform.conf $AML_IMAGE_STORAGE_PATH/ |
| 247 | install $IMAGE_BOARD_CONFIG_DIR/usb_flow.aml $AML_IMAGE_STORAGE_PATH/ |
| 248 | install $IMAGE_BOARD_CONFIG_DIR/aml_sdc_burn.ini $AML_IMAGE_STORAGE_PATH/ |
| 249 | |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 250 | cp $AML_PACKAGE_CONFIG_FILE $AML_IMAGE_STORAGE_PATH/aml_upgrade_package.conf |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 251 | |
| 252 | $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 |
| 253 | |
| 254 | cd $AML_IMAGE_STORAGE_PATH && rm $(ls | grep -v ".lst" | grep -v ".map" | grep -v ".img") |
| 255 | } |
| 256 | |
shijie.xiong | bc5d367 | 2022-04-01 17:52:16 +0800 | [diff] [blame] | 257 | package_target_verify |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 258 | compile_rtos_for_all |
shijie.xiong | a955b2e | 2024-11-20 13:40:48 +0800 | [diff] [blame] | 259 | build_bootloader uboot |
shijie.xiong | 348ce69 | 2023-07-03 16:04:10 +0800 | [diff] [blame] | 260 | aml_image_package |