blob: ed40abee87bb7458ca2c4d85b25b14b3c9eb2841 [file] [log] [blame]
shijie.xiong1369b8c2022-03-31 15:22:51 +08001#! /bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8RTOS_BUILD_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..)
shijie.xiong348ce692023-07-03 16:04:10 +08009BUILD_SYSTEM_DIR=$RTOS_BUILD_DIR/build_system
shijie.xiong1369b8c2022-03-31 15:22:51 +080010
shijie.xiong348ce692023-07-03 16:04:10 +080011export RTOS_BUILD_DIR
12
13# Parsing large package combination information
shijie.xiongbc5d3672022-04-01 17:52:16 +080014function package_target_verify() {
15
shijie.xiong348ce692023-07-03 16:04:10 +080016 ARCH_PREFIX=""
17 PRODUCT_SUFFIX=""
18
shijie.xiongbc5d3672022-04-01 17:52:16 +080019 #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.xiong1369b8c2022-03-31 15:22:51 +080028 #parameter check
shijie.xiongbc5d3672022-04-01 17:52:16 +080029 if [ -z "$PACKAGE_ARRY" ]; then
shijie.xiong9a3c9042022-04-12 17:51:55 +080030 echo -e "\033[41;33m package list is not set, please execute source scripts/pkg_env.sh \033[0m"
shijie.xiongbc5d3672022-04-01 17:52:16 +080031 exit 1
shijie.xiong1369b8c2022-03-31 15:22:51 +080032 fi
shijie.xiongbc5d3672022-04-01 17:52:16 +080033
34 #parameter check
shijie.xiong348ce692023-07-03 16:04:10 +080035 j=0
shijie.xiongbc5d3672022-04-01 17:52:16 +080036 for ((loop = 0; loop < ${#PACKAGE_ARRY[@]}; loop += 4)); do
shijie.xiong348ce692023-07-03 16:04:10 +080037 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.xiong1369b8c2022-03-31 15:22:51 +080044 done
shijie.xiongbc5d3672022-04-01 17:52:16 +080045
shijie.xiong348ce692023-07-03 16:04:10 +080046 # set the board configuration path
47 IMAGE_BOARD_CONFIG_DIR="$RTOS_BUILD_DIR/image_packer/${pkg_soc[0]}/"
shijie.xiongbc5d3672022-04-01 17:52:16 +080048
shijie.xiong348ce692023-07-03 16:04:10 +080049 # 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.xiong1369b8c2022-03-31 15:22:51 +080055}
56
shijie.xiong348ce692023-07-03 16:04:10 +080057function compile_rtos_for_arm() {
58 # target file path
59 OUTPUT_PATH=${RTOS_BUILD_DIR}/output/$1-$3-$4
shijie.xiong1369b8c2022-03-31 15:22:51 +080060
shijie.xiong348ce692023-07-03 16:04:10 +080061 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.xiong1369b8c2022-03-31 15:22:51 +080066
shijie.xiong348ce692023-07-03 16:04:10 +080067 # Clean up rtos compilation intermediate files
68 rm -rf $OUTPUT_PATH
shijie.xiong82d1b622022-06-28 14:33:57 +080069
shijie.xiong348ce692023-07-03 16:04:10 +080070 # 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.xiong82d1b622022-06-28 14:33:57 +080073
shijie.xiong348ce692023-07-03 16:04:10 +080074 # 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.xiong1369b8c2022-03-31 15:22:51 +080076
shijie.xiong348ce692023-07-03 16:04:10 +080077 # start compile flow
shijie.xiong1369b8c2022-03-31 15:22:51 +080078 pushd $RTOS_BUILD_DIR
79
shijie.xiong348ce692023-07-03 16:04:10 +080080 source scripts/env.sh $1 $2 $3 $4
shijie.xiong1369b8c2022-03-31 15:22:51 +080081
shijie.xiong348ce692023-07-03 16:04:10 +080082 if [ "$BACKTRACE_ENABLE" = "1" ]; then
shijie.xiong1369b8c2022-03-31 15:22:51 +080083 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.xiong1369b8c2022-03-31 15:22:51 +080092 fi
93
shijie.xiong348ce692023-07-03 16:04:10 +080094 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.xiong1369b8c2022-03-31 15:22:51 +0800111 popd
112}
113
shijie.xiong348ce692023-07-03 16:04:10 +0800114function 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.xiong1369b8c2022-03-31 15:22:51 +0800134 else
shijie.xiong348ce692023-07-03 16:04:10 +0800135 test -f ${BINARY_FILE} && cp ${BINARY_FILE} $AML_IMAGE_STORAGE_PATH/${KERNEL}-signed.bin
shijie.xiong1369b8c2022-03-31 15:22:51 +0800136 fi
shijie.xiongbc5d3672022-04-01 17:52:16 +0800137
shijie.xiong348ce692023-07-03 16:04:10 +0800138 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.xiong1369b8c2022-03-31 15:22:51 +0800142}
143
shijie.xiong348ce692023-07-03 16:04:10 +0800144# Compile rtos for all architectures
145function 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
156function 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.xiong1369b8c2022-03-31 15:22:51 +0800173 exit 1
174 else
shijie.xiong446f12c2022-11-30 10:24:17 +0800175 pushd $RTOS_BUILD_DIR/boot/u-boot
shijie.xiong348ce692023-07-03 16:04:10 +0800176 ./mk $uboot_type
177 test -f build/u-boot.bin && cp -av build/u-boot.bin* $AML_IMAGE_STORAGE_PATH
shijie.xiong1369b8c2022-03-31 15:22:51 +0800178 popd
179 fi
180}
181
shijie.xiong348ce692023-07-03 16:04:10 +0800182function 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.xiongbc5d3672022-04-01 17:52:16 +0800200package_target_verify
shijie.xiong348ce692023-07-03 16:04:10 +0800201compile_rtos_for_all
202build_bootloader
203aml_image_package