blob: 92b0927e46910477f4dbb3af5eb33730fc74236e [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
26 fi
shijie.xionga5091132022-12-13 15:16:17 +080027fi
28
29#Parse the specified hardware type
30for ((i = 0; i < ${#BOARD_DEFINE_PAR[@]}; i++)); do
31 if [ ${BOARD_DEFINE_PAR[i]} == $BOARD_TYPE ]; then
32 BOARD_TYPE_MAPPING=${BOARD_DEFINE_REF[i]}
33 break
34 fi
35done
36
37#parameter check
38if [ -z $BOARD_TYPE_MAPPING ]; then
39 echo -e "\033[41;33m Notice: parameter error !!! \033[0m"
jiahao.yang1ad516222024-01-04 15:25:46 +080040 echo -e "\033[33m board_type: aw409_c302x / aw402_c302x / aw402s_c302x / aw419_c308l\033[0m"
shijie.xionga5091132022-12-13 15:16:17 +080041 exit 1
shijie.xiongfec9efd2022-11-10 11:32:33 +080042fi
shijie.xiongffcaf582022-11-08 17:16:58 +080043
shijie.xiong82037e82023-03-01 14:34:41 +080044#release flow
jiahao.yang1ad516222024-01-04 15:25:46 +080045if [ -d $RTOS_BASE_DIR/binary_release ] && [ -d $RTOS_BASE_DIR/bl22_bin ] &&\
46 { [ "$BOARD_TYPE_MAPPING" == "c3_aw402" ] ||\
47 [ "$BOARD_TYPE_MAPPING" == "c3_aw402s" ]; }; then
shijie.xiong82037e82023-03-01 14:34:41 +080048 pushd $UBOOT_DIR
49 if [ -d ./fastboot ]; then
50 rm -rf ./fastboot
51 fi
52 mkdir -p ./fastboot
53 cp $RTOS_BASE_DIR/binary_release/* ./fastboot
54 cp $RTOS_BASE_DIR/bl22_bin/bl22.bin ./fastboot
55 ./mk $BOARD_TYPE_MAPPING
56 popd
57 exit 0
58fi
59
shijie.xiong1361fbb2023-01-06 11:01:31 +080060#Get the rtos target address (The configuration needs to be consistent with the lscript.h file)
61if [ -z $RTOS_TARGET_ADDRESS ]; then
62 case $BOARD_TYPE_MAPPING in
63 'c3_aw409')
64 RTOS_TARGET_ADDRESS=0x5400000
65 ;;
66 'c3_aw402')
Shijie Xiong5e88ce62023-02-09 22:46:55 -080067 RTOS_TARGET_ADDRESS=0x7600000
shijie.xiong1361fbb2023-01-06 11:01:31 +080068 ;;
jiahao.yang1ad516222024-01-04 15:25:46 +080069 'c3_aw402s')
70 RTOS_TARGET_ADDRESS=0x7600000
71 ;;
shijie.xiong1361fbb2023-01-06 11:01:31 +080072 *)
73 RTOS_TARGET_ADDRESS=0x9000000
74 ;;
75 esac
76fi
77
shijie.xiong415cba52024-06-18 17:00:52 +080078#Retrieve the size of the DDRFIP space
79case $BOARD_TYPE_MAPPING in
80'c3_aw409')
81 UBOOT_DDR_FIP_SIZE=128m
82 ;;
83'c3_aw402')
84 UBOOT_DDR_FIP_SIZE=128m
85 ;;
86'c3_aw402s')
87 UBOOT_DDR_FIP_SIZE=256m
88 ;;
89*)
90 UBOOT_DDR_FIP_SIZE=256m
91 ;;
92esac
93
shijie.xiong1361fbb2023-01-06 11:01:31 +080094#Get the loading address of rtos2
tao.qinb0355272023-07-21 14:59:21 +080095let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x100000"
shijie.xiong1361fbb2023-01-06 11:01:31 +080096RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS)
97
shijie.xiongc143e9c2022-11-18 17:58:30 +080098#Clear cache files
99[ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output
shijie.xionga5091132022-12-13 15:16:17 +0800100
shijie.xiongffcaf582022-11-08 17:16:58 +0800101#Get the current project environment variables
shijie.xionga5091132022-12-13 15:16:17 +0800102source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800103
104#RTOS object file path
105RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos
106RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin
107RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin
108
shijie.xiong1361fbb2023-01-06 11:01:31 +0800109function toolchain_prepare() {
110 echo "<============ TOOLCHAIN INFO RTOS ============>"
111 CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD
shijie.xiong82037e82023-03-01 14:34:41 +0800112 TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD
shijie.xiong1361fbb2023-01-06 11:01:31 +0800113 rm -rf $RTOS_BASE_DIR/output/toolchains
shijie.xiong82037e82023-03-01 14:34:41 +0800114 mkdir -p $TOOLCHAIN_DIR
115 tar -xf $CROSSTOOL.tar.xz -C $TOOLCHAIN_DIR --strip-components=1
116 ls -la $TOOLCHAIN_DIR/bin
117 $TOOLCHAIN_DIR/bin/aarch64-none-elf-gcc -v
shijie.xiong1361fbb2023-01-06 11:01:31 +0800118 echo "<============ TOOLCHAIN INFO RTOS ============>"
119}
120
121function rtos_config_prepare() {
122 CONFIG_FILE=$RTOS_BASE_DIR/boards/$ARCH/$BOARD/lscript.h
123 sed -i '/.*#define configTEXT_BASE*/c\#define configTEXT_BASE '${RTOS_TARGET_ADDRESS}'' $CONFIG_FILE
124 sed -i '/.*#define CONFIG_SCATTER_LOAD_ADDRESS*/c\#define CONFIG_SCATTER_LOAD_ADDRESS '${RTOS2_TARGET_ADDRESS}'' $CONFIG_FILE
125}
126
shijie.xiongfec9efd2022-11-10 11:32:33 +0800127function lz4_rtos() {
128 pushd $RTOS_BASE_DIR/lib/utilities/lz4
129 cp $RTOS_IMAGE_A .
shijie.xiong1361fbb2023-01-06 11:01:31 +0800130 #Get the rtos target address
131 ./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 +0800132 cp ./self_decompress_firmware.bin $RTOS_IMAGE_A
shijie.xiongc6a04f52023-06-21 13:39:54 +0800133 rm ./self_decompress_firmware.bin ./rtos_1.bin
shijie.xiongfec9efd2022-11-10 11:32:33 +0800134 popd
135}
136
shijie.xiongffcaf582022-11-08 17:16:58 +0800137function bl22_compile() {
138 if [ -d $BL22_DIR ]; then
139 pushd $BL22_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800140 if [ -f ./mk ]; then
shijie.xiong1361fbb2023-01-06 11:01:31 +0800141 ./mk c3 $BOARD_TYPE
shijie.xiong01dafeb2024-04-03 15:46:49 +0800142 if [ "$?" -ne 0 ]; then
143 echo "RTOS-SDK: BL22 compilation failed !!!"
144 exit 1
145 fi
shijie.xiongfec9efd2022-11-10 11:32:33 +0800146 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800147 cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin
148 popd
149 fi
150}
151
shijie.xiongffcaf582022-11-08 17:16:58 +0800152function package_fastboot() {
shijie.xiongffcaf582022-11-08 17:16:58 +0800153 pushd $UBOOT_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800154 if [ -d ./fastboot ]; then
155 rm -rf ./fastboot
156 fi
157 mkdir -p ./fastboot
158 cp $RTOS_IMAGE_A ./fastboot
159 cp $RTOS_IMAGE_B ./fastboot
160 cp $RTOS_BUILD_DIR/bl22.bin ./fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800161 #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed
shijie.xiongc2bab512022-11-10 17:53:37 +0800162 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800163 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed
shijie.xiong415cba52024-06-18 17:00:52 +0800164 echo "./mk $BOARD_TYPE_MAPPING --build-nogit --ipc-ddr-size $UBOOT_DDR_FIP_SIZE"
165 ./mk $BOARD_TYPE_MAPPING --build-nogit --ipc-ddr-size $UBOOT_DDR_FIP_SIZE
shijie.xiong01dafeb2024-04-03 15:46:49 +0800166 if [ "$?" -ne 0 ]; then
shijie.xiong07f3b2b2024-04-12 14:01:11 +0800167 if [ -d ./fastboot ]; then
168 rm -rf ./fastboot
169 fi
shijie.xiong01dafeb2024-04-03 15:46:49 +0800170 echo "RTOS-SDK: Uboot compilation failed !!!"
171 exit 1
172 fi
shijie.xiong07f3b2b2024-04-12 14:01:11 +0800173
174 if [ -d ./fastboot ]; then
175 rm -rf ./fastboot
176 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800177 popd
178}
179
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800180function debug_info() {
181 echo "<============ Kconfig RTOS ============>"
182 cat $RTOS_BASE_DIR/Kconfig
183 echo "<============ CMakeLists RTOS ============>"
184 cat $RTOS_BASE_DIR/CMakeLists.txt
185 echo "<============ XML RTOS ============>"
186 cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml
187 echo "<============ XML OLD RTOS ============>"
188 cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml
shijie.xionga5091132022-12-13 15:16:17 +0800189 echo "<============ JENKINS FOR RTOS ============>"
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800190}
191
shijie.xiong1361fbb2023-01-06 11:01:31 +0800192#Configure the RTOS environment
193if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
194 rtos_config_prepare
195fi
196#Compile toolchain preparation
shijie.xionga5091132022-12-13 15:16:17 +0800197toolchain_prepare
shijie.xiongffcaf582022-11-08 17:16:58 +0800198#compile the rtos image
shijie.xiong26895eb2023-10-09 11:28:08 +0800199cd $RTOS_BASE_DIR && make
shijie.xiong01dafeb2024-04-03 15:46:49 +0800200if [ "$?" -ne 0 ]; then
201 echo "RTOS-SDK: RTOS compilation failed !!!"
202 exit 1
203fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800204#lz4 compression
205lz4_rtos
206#compile the bl22 image
207bl22_compile
208#compile the u-boot image
209package_fastboot
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800210#debug
211debug_info