blob: c8faad038254634357fc0c3cc2a9fbe73e138852 [file] [log] [blame]
shijie.xiongffcaf582022-11-08 17:16:58 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8#RTOS root directory
9RTOS_BASE_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..)
10
shijie.xionga5091132022-12-13 15:16:17 +080011#Board Mapping Combination
jiahao.yang1ad516222024-01-04 15:25:46 +080012BOARD_DEFINE_REF=(c3_aw409 c3_aw402 c3_aw402s c3_aw419)
13BOARD_DEFINE_PAR=(aw409_c302x aw402_c302x aw402s_c302x aw419_c308l)
shijie.xionga5091132022-12-13 15:16:17 +080014
shijie.xiongffcaf582022-11-08 17:16:58 +080015## external resource path ##
shijie.xionga5091132022-12-13 15:16:17 +080016if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
shijie.xiongfec9efd2022-11-10 11:32:33 +080017 echo -e "\033[41;33m Notice: parameter error !!! \033[0m"
shijie.xiong1361fbb2023-01-06 11:01:31 +080018 echo -e "\033[33m usage: ./c3_fastboot.sh bl22_path u-boot_path board_type (optional:load_address)\033[0m"
shijie.xiongfec9efd2022-11-10 11:32:33 +080019 exit 1
20else
21 BL22_DIR=$1
22 UBOOT_DIR=$2
shijie.xionga5091132022-12-13 15:16:17 +080023 BOARD_TYPE=$3
shijie.xiong1361fbb2023-01-06 11:01:31 +080024 if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
25 RTOS_TARGET_ADDRESS=$4
yongbing.heec6f30c2024-06-19 11:27:18 +080026
27 fi
28 if [ $5 ] && [[ "$5" =~ ^SENSOR=.* ]]; then
29 SENSOR_TYPE=${5#SENSOR=}
shijie.xiong1361fbb2023-01-06 11:01:31 +080030 fi
shijie.xionga5091132022-12-13 15:16:17 +080031fi
32
33#Parse the specified hardware type
34for ((i = 0; i < ${#BOARD_DEFINE_PAR[@]}; i++)); do
35 if [ ${BOARD_DEFINE_PAR[i]} == $BOARD_TYPE ]; then
36 BOARD_TYPE_MAPPING=${BOARD_DEFINE_REF[i]}
37 break
38 fi
39done
40
41#parameter check
42if [ -z $BOARD_TYPE_MAPPING ]; then
43 echo -e "\033[41;33m Notice: parameter error !!! \033[0m"
jiahao.yang1ad516222024-01-04 15:25:46 +080044 echo -e "\033[33m board_type: aw409_c302x / aw402_c302x / aw402s_c302x / aw419_c308l\033[0m"
shijie.xionga5091132022-12-13 15:16:17 +080045 exit 1
shijie.xiongfec9efd2022-11-10 11:32:33 +080046fi
shijie.xiongffcaf582022-11-08 17:16:58 +080047
shijie.xiong82037e82023-03-01 14:34:41 +080048#release flow
jiahao.yang1ad516222024-01-04 15:25:46 +080049if [ -d $RTOS_BASE_DIR/binary_release ] && [ -d $RTOS_BASE_DIR/bl22_bin ] &&\
50 { [ "$BOARD_TYPE_MAPPING" == "c3_aw402" ] ||\
51 [ "$BOARD_TYPE_MAPPING" == "c3_aw402s" ]; }; then
shijie.xiong82037e82023-03-01 14:34:41 +080052 pushd $UBOOT_DIR
53 if [ -d ./fastboot ]; then
54 rm -rf ./fastboot
55 fi
56 mkdir -p ./fastboot
57 cp $RTOS_BASE_DIR/binary_release/* ./fastboot
58 cp $RTOS_BASE_DIR/bl22_bin/bl22.bin ./fastboot
59 ./mk $BOARD_TYPE_MAPPING
60 popd
61 exit 0
62fi
63
yongbing.heec6f30c2024-06-19 11:27:18 +080064if [ -z $SENSOR_TYPE ]; then
65 case $BOARD_TYPE_MAPPING in
66 'c3_aw402')
67 SENSOR_TYPE=SC301IOT
68 ;;
69 *)
70 SENSOR_TYPE=IMX290
71 ;;
72 esac
73fi
74
shijie.xiong1361fbb2023-01-06 11:01:31 +080075#Get the rtos target address (The configuration needs to be consistent with the lscript.h file)
76if [ -z $RTOS_TARGET_ADDRESS ]; then
77 case $BOARD_TYPE_MAPPING in
78 'c3_aw409')
79 RTOS_TARGET_ADDRESS=0x5400000
80 ;;
81 'c3_aw402')
Shijie Xiong5e88ce62023-02-09 22:46:55 -080082 RTOS_TARGET_ADDRESS=0x7600000
shijie.xiong1361fbb2023-01-06 11:01:31 +080083 ;;
jiahao.yang1ad516222024-01-04 15:25:46 +080084 'c3_aw402s')
85 RTOS_TARGET_ADDRESS=0x7600000
86 ;;
shijie.xiong1361fbb2023-01-06 11:01:31 +080087 *)
88 RTOS_TARGET_ADDRESS=0x9000000
89 ;;
90 esac
91fi
92
shijie.xiong415cba52024-06-18 17:00:52 +080093#Retrieve the size of the DDRFIP space
94case $BOARD_TYPE_MAPPING in
95'c3_aw409')
96 UBOOT_DDR_FIP_SIZE=128m
97 ;;
98'c3_aw402')
99 UBOOT_DDR_FIP_SIZE=128m
100 ;;
101'c3_aw402s')
102 UBOOT_DDR_FIP_SIZE=256m
103 ;;
104*)
105 UBOOT_DDR_FIP_SIZE=256m
106 ;;
107esac
108
shijie.xiong1361fbb2023-01-06 11:01:31 +0800109#Get the loading address of rtos2
tao.qinb0355272023-07-21 14:59:21 +0800110let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x100000"
shijie.xiong1361fbb2023-01-06 11:01:31 +0800111RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS)
112
shijie.xiongc143e9c2022-11-18 17:58:30 +0800113#Clear cache files
114[ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output
shijie.xionga5091132022-12-13 15:16:17 +0800115
shijie.xiongffcaf582022-11-08 17:16:58 +0800116#Get the current project environment variables
shijie.xionga5091132022-12-13 15:16:17 +0800117source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800118
119#RTOS object file path
120RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos
121RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin
122RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin
123
shijie.xiong1361fbb2023-01-06 11:01:31 +0800124function toolchain_prepare() {
125 echo "<============ TOOLCHAIN INFO RTOS ============>"
126 CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD
shijie.xiong82037e82023-03-01 14:34:41 +0800127 TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD
shijie.xiong1361fbb2023-01-06 11:01:31 +0800128 rm -rf $RTOS_BASE_DIR/output/toolchains
shijie.xiong82037e82023-03-01 14:34:41 +0800129 mkdir -p $TOOLCHAIN_DIR
130 tar -xf $CROSSTOOL.tar.xz -C $TOOLCHAIN_DIR --strip-components=1
131 ls -la $TOOLCHAIN_DIR/bin
132 $TOOLCHAIN_DIR/bin/aarch64-none-elf-gcc -v
shijie.xiong1361fbb2023-01-06 11:01:31 +0800133 echo "<============ TOOLCHAIN INFO RTOS ============>"
134}
135
136function rtos_config_prepare() {
137 CONFIG_FILE=$RTOS_BASE_DIR/boards/$ARCH/$BOARD/lscript.h
138 sed -i '/.*#define configTEXT_BASE*/c\#define configTEXT_BASE '${RTOS_TARGET_ADDRESS}'' $CONFIG_FILE
139 sed -i '/.*#define CONFIG_SCATTER_LOAD_ADDRESS*/c\#define CONFIG_SCATTER_LOAD_ADDRESS '${RTOS2_TARGET_ADDRESS}'' $CONFIG_FILE
140}
141
yongbing.heec6f30c2024-06-19 11:27:18 +0800142function sensor_config_choose() {
143 sed -i '/CONFIG_SENSOR_SC401AI/d' $RTOS_BASE_DIR/boards/$ARCH/$BOARD/defconfig
144 if [ "${SENSOR_TYPE}" == "SC401AI" ]; then
145 sed -i '$ a CONFIG_SENSOR_SC401AI=y' $RTOS_BASE_DIR/boards/$ARCH/$BOARD/defconfig
146 fi
147}
148
shijie.xiongfec9efd2022-11-10 11:32:33 +0800149function lz4_rtos() {
150 pushd $RTOS_BASE_DIR/lib/utilities/lz4
151 cp $RTOS_IMAGE_A .
shijie.xiong1361fbb2023-01-06 11:01:31 +0800152 #Get the rtos target address
153 ./self_decompress_tool.sh -a ./self_decompress_head.bin -b ./rtos_1.bin -l 0x04c00000 -j $RTOS_TARGET_ADDRESS -d 0 -s $RTOS2_TARGET_ADDRESS
shijie.xiongfec9efd2022-11-10 11:32:33 +0800154 cp ./self_decompress_firmware.bin $RTOS_IMAGE_A
shijie.xiongc6a04f52023-06-21 13:39:54 +0800155 rm ./self_decompress_firmware.bin ./rtos_1.bin
shijie.xiongfec9efd2022-11-10 11:32:33 +0800156 popd
157}
158
shijie.xiongffcaf582022-11-08 17:16:58 +0800159function bl22_compile() {
160 if [ -d $BL22_DIR ]; then
161 pushd $BL22_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800162 if [ -f ./mk ]; then
shijie.xiong1361fbb2023-01-06 11:01:31 +0800163 ./mk c3 $BOARD_TYPE
shijie.xiong01dafeb2024-04-03 15:46:49 +0800164 if [ "$?" -ne 0 ]; then
165 echo "RTOS-SDK: BL22 compilation failed !!!"
166 exit 1
167 fi
shijie.xiongfec9efd2022-11-10 11:32:33 +0800168 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800169 cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin
170 popd
171 fi
172}
173
shijie.xiongffcaf582022-11-08 17:16:58 +0800174function package_fastboot() {
shijie.xiongffcaf582022-11-08 17:16:58 +0800175 pushd $UBOOT_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800176 if [ -d ./fastboot ]; then
177 rm -rf ./fastboot
178 fi
179 mkdir -p ./fastboot
180 cp $RTOS_IMAGE_A ./fastboot
181 cp $RTOS_IMAGE_B ./fastboot
182 cp $RTOS_BUILD_DIR/bl22.bin ./fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800183 #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed
shijie.xiongc2bab512022-11-10 17:53:37 +0800184 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800185 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed
shijie.xiong415cba52024-06-18 17:00:52 +0800186 echo "./mk $BOARD_TYPE_MAPPING --build-nogit --ipc-ddr-size $UBOOT_DDR_FIP_SIZE"
187 ./mk $BOARD_TYPE_MAPPING --build-nogit --ipc-ddr-size $UBOOT_DDR_FIP_SIZE
shijie.xiong01dafeb2024-04-03 15:46:49 +0800188 if [ "$?" -ne 0 ]; then
shijie.xiong07f3b2b2024-04-12 14:01:11 +0800189 if [ -d ./fastboot ]; then
190 rm -rf ./fastboot
191 fi
shijie.xiong01dafeb2024-04-03 15:46:49 +0800192 echo "RTOS-SDK: Uboot compilation failed !!!"
193 exit 1
194 fi
shijie.xiong07f3b2b2024-04-12 14:01:11 +0800195
196 if [ -d ./fastboot ]; then
197 rm -rf ./fastboot
198 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800199 popd
200}
201
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800202function debug_info() {
203 echo "<============ Kconfig RTOS ============>"
204 cat $RTOS_BASE_DIR/Kconfig
205 echo "<============ CMakeLists RTOS ============>"
206 cat $RTOS_BASE_DIR/CMakeLists.txt
207 echo "<============ XML RTOS ============>"
208 cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml
209 echo "<============ XML OLD RTOS ============>"
210 cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml
shijie.xionga5091132022-12-13 15:16:17 +0800211 echo "<============ JENKINS FOR RTOS ============>"
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800212}
213
shijie.xiong1361fbb2023-01-06 11:01:31 +0800214#Configure the RTOS environment
215if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
216 rtos_config_prepare
217fi
yongbing.heec6f30c2024-06-19 11:27:18 +0800218#choose sensor
219sensor_config_choose
shijie.xiong1361fbb2023-01-06 11:01:31 +0800220#Compile toolchain preparation
shijie.xionga5091132022-12-13 15:16:17 +0800221toolchain_prepare
shijie.xiongffcaf582022-11-08 17:16:58 +0800222#compile the rtos image
shijie.xiong26895eb2023-10-09 11:28:08 +0800223cd $RTOS_BASE_DIR && make
shijie.xiong01dafeb2024-04-03 15:46:49 +0800224if [ "$?" -ne 0 ]; then
225 echo "RTOS-SDK: RTOS compilation failed !!!"
226 exit 1
227fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800228#lz4 compression
229lz4_rtos
230#compile the bl22 image
231bl22_compile
232#compile the u-boot image
233package_fastboot
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800234#debug
235debug_info