shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +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 root directory |
| 9 | RTOS_BASE_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..) |
| 10 | |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 11 | #Board Mapping Combination |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 12 | BOARD_DEFINE_REF=(c3_aw409 c3_aw402 c3_aw402s c3_aw419) |
| 13 | BOARD_DEFINE_PAR=(aw409_c302x aw402_c302x aw402s_c302x aw419_c308l) |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 14 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 15 | ## external resource path ## |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 16 | if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 17 | echo -e "\033[41;33m Notice: parameter error !!! \033[0m" |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 18 | echo -e "\033[33m usage: ./c3_fastboot.sh bl22_path u-boot_path board_type (optional:load_address)\033[0m" |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 19 | exit 1 |
| 20 | else |
| 21 | BL22_DIR=$1 |
| 22 | UBOOT_DIR=$2 |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 23 | BOARD_TYPE=$3 |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 24 | if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then |
| 25 | RTOS_TARGET_ADDRESS=$4 |
yongbing.he | ec6f30c | 2024-06-19 11:27:18 +0800 | [diff] [blame] | 26 | |
| 27 | fi |
| 28 | if [ $5 ] && [[ "$5" =~ ^SENSOR=.* ]]; then |
| 29 | SENSOR_TYPE=${5#SENSOR=} |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 30 | fi |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | #Parse the specified hardware type |
| 34 | for ((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 |
| 39 | done |
| 40 | |
| 41 | #parameter check |
| 42 | if [ -z $BOARD_TYPE_MAPPING ]; then |
| 43 | echo -e "\033[41;33m Notice: parameter error !!! \033[0m" |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 44 | echo -e "\033[33m board_type: aw409_c302x / aw402_c302x / aw402s_c302x / aw419_c308l\033[0m" |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 45 | exit 1 |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 46 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 47 | |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 48 | #release flow |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 49 | if [ -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.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 52 | 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 |
| 62 | fi |
| 63 | |
yongbing.he | ec6f30c | 2024-06-19 11:27:18 +0800 | [diff] [blame] | 64 | if [ -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 |
| 73 | fi |
| 74 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 75 | #Get the rtos target address (The configuration needs to be consistent with the lscript.h file) |
| 76 | if [ -z $RTOS_TARGET_ADDRESS ]; then |
| 77 | case $BOARD_TYPE_MAPPING in |
| 78 | 'c3_aw409') |
| 79 | RTOS_TARGET_ADDRESS=0x5400000 |
| 80 | ;; |
| 81 | 'c3_aw402') |
Shijie Xiong | 5e88ce6 | 2023-02-09 22:46:55 -0800 | [diff] [blame] | 82 | RTOS_TARGET_ADDRESS=0x7600000 |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 83 | ;; |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 84 | 'c3_aw402s') |
| 85 | RTOS_TARGET_ADDRESS=0x7600000 |
| 86 | ;; |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 87 | *) |
| 88 | RTOS_TARGET_ADDRESS=0x9000000 |
| 89 | ;; |
| 90 | esac |
| 91 | fi |
| 92 | |
shijie.xiong | 415cba5 | 2024-06-18 17:00:52 +0800 | [diff] [blame] | 93 | #Retrieve the size of the DDRFIP space |
| 94 | case $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 | ;; |
| 107 | esac |
| 108 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 109 | #Get the loading address of rtos2 |
tao.qin | b035527 | 2023-07-21 14:59:21 +0800 | [diff] [blame] | 110 | let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x100000" |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 111 | RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS) |
| 112 | |
shijie.xiong | c143e9c | 2022-11-18 17:58:30 +0800 | [diff] [blame] | 113 | #Clear cache files |
| 114 | [ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 115 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 116 | #Get the current project environment variables |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 117 | source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 118 | |
| 119 | #RTOS object file path |
| 120 | RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos |
| 121 | RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin |
| 122 | RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin |
| 123 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 124 | function toolchain_prepare() { |
| 125 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 126 | CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 127 | TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 128 | rm -rf $RTOS_BASE_DIR/output/toolchains |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 129 | 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.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 133 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 134 | } |
| 135 | |
| 136 | function 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.he | ec6f30c | 2024-06-19 11:27:18 +0800 | [diff] [blame] | 142 | function 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.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 149 | function lz4_rtos() { |
| 150 | pushd $RTOS_BASE_DIR/lib/utilities/lz4 |
| 151 | cp $RTOS_IMAGE_A . |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 152 | #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.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 154 | cp ./self_decompress_firmware.bin $RTOS_IMAGE_A |
shijie.xiong | c6a04f5 | 2023-06-21 13:39:54 +0800 | [diff] [blame] | 155 | rm ./self_decompress_firmware.bin ./rtos_1.bin |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 156 | popd |
| 157 | } |
| 158 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 159 | function bl22_compile() { |
| 160 | if [ -d $BL22_DIR ]; then |
| 161 | pushd $BL22_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 162 | if [ -f ./mk ]; then |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 163 | ./mk c3 $BOARD_TYPE |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame] | 164 | if [ "$?" -ne 0 ]; then |
| 165 | echo "RTOS-SDK: BL22 compilation failed !!!" |
| 166 | exit 1 |
| 167 | fi |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 168 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 169 | cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin |
| 170 | popd |
| 171 | fi |
| 172 | } |
| 173 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 174 | function package_fastboot() { |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 175 | pushd $UBOOT_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 176 | 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.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 183 | #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed |
shijie.xiong | c2bab51 | 2022-11-10 17:53:37 +0800 | [diff] [blame] | 184 | #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 185 | #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed |
shijie.xiong | 415cba5 | 2024-06-18 17:00:52 +0800 | [diff] [blame] | 186 | 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.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame] | 188 | if [ "$?" -ne 0 ]; then |
shijie.xiong | 07f3b2b | 2024-04-12 14:01:11 +0800 | [diff] [blame] | 189 | if [ -d ./fastboot ]; then |
| 190 | rm -rf ./fastboot |
| 191 | fi |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame] | 192 | echo "RTOS-SDK: Uboot compilation failed !!!" |
| 193 | exit 1 |
| 194 | fi |
shijie.xiong | 07f3b2b | 2024-04-12 14:01:11 +0800 | [diff] [blame] | 195 | |
| 196 | if [ -d ./fastboot ]; then |
| 197 | rm -rf ./fastboot |
| 198 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 199 | popd |
| 200 | } |
| 201 | |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 202 | function 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.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 211 | echo "<============ JENKINS FOR RTOS ============>" |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 212 | } |
| 213 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 214 | #Configure the RTOS environment |
| 215 | if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then |
| 216 | rtos_config_prepare |
| 217 | fi |
yongbing.he | ec6f30c | 2024-06-19 11:27:18 +0800 | [diff] [blame] | 218 | #choose sensor |
| 219 | sensor_config_choose |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 220 | #Compile toolchain preparation |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 221 | toolchain_prepare |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 222 | #compile the rtos image |
shijie.xiong | 26895eb | 2023-10-09 11:28:08 +0800 | [diff] [blame] | 223 | cd $RTOS_BASE_DIR && make |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame] | 224 | if [ "$?" -ne 0 ]; then |
| 225 | echo "RTOS-SDK: RTOS compilation failed !!!" |
| 226 | exit 1 |
| 227 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 228 | #lz4 compression |
| 229 | lz4_rtos |
| 230 | #compile the bl22 image |
| 231 | bl22_compile |
| 232 | #compile the u-boot image |
| 233 | package_fastboot |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 234 | #debug |
| 235 | debug_info |