blob: e6160821ae05f71d8af840e94e9d368c348ed8d6 [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
78#Get the loading address of rtos2
tao.qinb0355272023-07-21 14:59:21 +080079let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x100000"
shijie.xiong1361fbb2023-01-06 11:01:31 +080080RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS)
81
shijie.xiongc143e9c2022-11-18 17:58:30 +080082#Clear cache files
83[ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output
shijie.xionga5091132022-12-13 15:16:17 +080084
shijie.xiongffcaf582022-11-08 17:16:58 +080085#Get the current project environment variables
shijie.xionga5091132022-12-13 15:16:17 +080086source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +080087
88#RTOS object file path
89RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos
90RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin
91RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin
92
shijie.xiong1361fbb2023-01-06 11:01:31 +080093function toolchain_prepare() {
94 echo "<============ TOOLCHAIN INFO RTOS ============>"
95 CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD
shijie.xiong82037e82023-03-01 14:34:41 +080096 TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD
shijie.xiong1361fbb2023-01-06 11:01:31 +080097 rm -rf $RTOS_BASE_DIR/output/toolchains
shijie.xiong82037e82023-03-01 14:34:41 +080098 mkdir -p $TOOLCHAIN_DIR
99 tar -xf $CROSSTOOL.tar.xz -C $TOOLCHAIN_DIR --strip-components=1
100 ls -la $TOOLCHAIN_DIR/bin
101 $TOOLCHAIN_DIR/bin/aarch64-none-elf-gcc -v
shijie.xiong1361fbb2023-01-06 11:01:31 +0800102 echo "<============ TOOLCHAIN INFO RTOS ============>"
103}
104
105function rtos_config_prepare() {
106 CONFIG_FILE=$RTOS_BASE_DIR/boards/$ARCH/$BOARD/lscript.h
107 sed -i '/.*#define configTEXT_BASE*/c\#define configTEXT_BASE '${RTOS_TARGET_ADDRESS}'' $CONFIG_FILE
108 sed -i '/.*#define CONFIG_SCATTER_LOAD_ADDRESS*/c\#define CONFIG_SCATTER_LOAD_ADDRESS '${RTOS2_TARGET_ADDRESS}'' $CONFIG_FILE
109}
110
shijie.xiongfec9efd2022-11-10 11:32:33 +0800111function lz4_rtos() {
112 pushd $RTOS_BASE_DIR/lib/utilities/lz4
113 cp $RTOS_IMAGE_A .
shijie.xiong1361fbb2023-01-06 11:01:31 +0800114 #Get the rtos target address
115 ./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 +0800116 cp ./self_decompress_firmware.bin $RTOS_IMAGE_A
shijie.xiongc6a04f52023-06-21 13:39:54 +0800117 rm ./self_decompress_firmware.bin ./rtos_1.bin
shijie.xiongfec9efd2022-11-10 11:32:33 +0800118 popd
119}
120
shijie.xiongffcaf582022-11-08 17:16:58 +0800121function bl22_compile() {
122 if [ -d $BL22_DIR ]; then
123 pushd $BL22_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800124 if [ -f ./mk ]; then
shijie.xiong1361fbb2023-01-06 11:01:31 +0800125 ./mk c3 $BOARD_TYPE
shijie.xiongfec9efd2022-11-10 11:32:33 +0800126 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800127 cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin
128 popd
129 fi
130}
131
shijie.xiongffcaf582022-11-08 17:16:58 +0800132function package_fastboot() {
shijie.xiongffcaf582022-11-08 17:16:58 +0800133 pushd $UBOOT_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800134 if [ -d ./fastboot ]; then
135 rm -rf ./fastboot
136 fi
137 mkdir -p ./fastboot
138 cp $RTOS_IMAGE_A ./fastboot
139 cp $RTOS_IMAGE_B ./fastboot
140 cp $RTOS_BUILD_DIR/bl22.bin ./fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800141 #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed
shijie.xiongc2bab512022-11-10 17:53:37 +0800142 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800143 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed
shijie.xionga5091132022-12-13 15:16:17 +0800144 ./mk $BOARD_TYPE_MAPPING
shijie.xiongffcaf582022-11-08 17:16:58 +0800145 popd
146}
147
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800148function debug_info() {
149 echo "<============ Kconfig RTOS ============>"
150 cat $RTOS_BASE_DIR/Kconfig
151 echo "<============ CMakeLists RTOS ============>"
152 cat $RTOS_BASE_DIR/CMakeLists.txt
153 echo "<============ XML RTOS ============>"
154 cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml
155 echo "<============ XML OLD RTOS ============>"
156 cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml
shijie.xionga5091132022-12-13 15:16:17 +0800157 echo "<============ JENKINS FOR RTOS ============>"
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800158}
159
shijie.xiong1361fbb2023-01-06 11:01:31 +0800160#Configure the RTOS environment
161if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
162 rtos_config_prepare
163fi
164#Compile toolchain preparation
shijie.xionga5091132022-12-13 15:16:17 +0800165toolchain_prepare
shijie.xiongffcaf582022-11-08 17:16:58 +0800166#compile the rtos image
shijie.xiong26895eb2023-10-09 11:28:08 +0800167cd $RTOS_BASE_DIR && make
shijie.xiongffcaf582022-11-08 17:16:58 +0800168#lz4 compression
169lz4_rtos
170#compile the bl22 image
171bl22_compile
172#compile the u-boot image
173package_fastboot
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800174#debug
175debug_info