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 |
| 26 | fi |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 27 | fi |
| 28 | |
| 29 | #Parse the specified hardware type |
| 30 | for ((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 |
| 35 | done |
| 36 | |
| 37 | #parameter check |
| 38 | if [ -z $BOARD_TYPE_MAPPING ]; then |
| 39 | echo -e "\033[41;33m Notice: parameter error !!! \033[0m" |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 40 | 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] | 41 | exit 1 |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 42 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 43 | |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 44 | #release flow |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 45 | if [ -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.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 48 | 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 |
| 58 | fi |
| 59 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 60 | #Get the rtos target address (The configuration needs to be consistent with the lscript.h file) |
| 61 | if [ -z $RTOS_TARGET_ADDRESS ]; then |
| 62 | case $BOARD_TYPE_MAPPING in |
| 63 | 'c3_aw409') |
| 64 | RTOS_TARGET_ADDRESS=0x5400000 |
| 65 | ;; |
| 66 | 'c3_aw402') |
Shijie Xiong | 5e88ce6 | 2023-02-09 22:46:55 -0800 | [diff] [blame] | 67 | RTOS_TARGET_ADDRESS=0x7600000 |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 68 | ;; |
jiahao.yang1 | ad51622 | 2024-01-04 15:25:46 +0800 | [diff] [blame] | 69 | 'c3_aw402s') |
| 70 | RTOS_TARGET_ADDRESS=0x7600000 |
| 71 | ;; |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 72 | *) |
| 73 | RTOS_TARGET_ADDRESS=0x9000000 |
| 74 | ;; |
| 75 | esac |
| 76 | fi |
| 77 | |
| 78 | #Get the loading address of rtos2 |
tao.qin | b035527 | 2023-07-21 14:59:21 +0800 | [diff] [blame] | 79 | let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x100000" |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 80 | RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS) |
| 81 | |
shijie.xiong | c143e9c | 2022-11-18 17:58:30 +0800 | [diff] [blame] | 82 | #Clear cache files |
| 83 | [ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 84 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 85 | #Get the current project environment variables |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 86 | source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 87 | |
| 88 | #RTOS object file path |
| 89 | RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos |
| 90 | RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin |
| 91 | RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin |
| 92 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 93 | function toolchain_prepare() { |
| 94 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 95 | CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 96 | TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 97 | rm -rf $RTOS_BASE_DIR/output/toolchains |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 98 | 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.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 102 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 103 | } |
| 104 | |
| 105 | function 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.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 111 | function lz4_rtos() { |
| 112 | pushd $RTOS_BASE_DIR/lib/utilities/lz4 |
| 113 | cp $RTOS_IMAGE_A . |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 114 | #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.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 116 | cp ./self_decompress_firmware.bin $RTOS_IMAGE_A |
shijie.xiong | c6a04f5 | 2023-06-21 13:39:54 +0800 | [diff] [blame] | 117 | rm ./self_decompress_firmware.bin ./rtos_1.bin |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 118 | popd |
| 119 | } |
| 120 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 121 | function bl22_compile() { |
| 122 | if [ -d $BL22_DIR ]; then |
| 123 | pushd $BL22_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 124 | if [ -f ./mk ]; then |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 125 | ./mk c3 $BOARD_TYPE |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame^] | 126 | if [ "$?" -ne 0 ]; then |
| 127 | echo "RTOS-SDK: BL22 compilation failed !!!" |
| 128 | exit 1 |
| 129 | fi |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 130 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 131 | cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin |
| 132 | popd |
| 133 | fi |
| 134 | } |
| 135 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 136 | function package_fastboot() { |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 137 | pushd $UBOOT_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 138 | if [ -d ./fastboot ]; then |
| 139 | rm -rf ./fastboot |
| 140 | fi |
| 141 | mkdir -p ./fastboot |
| 142 | cp $RTOS_IMAGE_A ./fastboot |
| 143 | cp $RTOS_IMAGE_B ./fastboot |
| 144 | cp $RTOS_BUILD_DIR/bl22.bin ./fastboot |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 145 | #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed |
shijie.xiong | c2bab51 | 2022-11-10 17:53:37 +0800 | [diff] [blame] | 146 | #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 147 | #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 148 | ./mk $BOARD_TYPE_MAPPING |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame^] | 149 | if [ "$?" -ne 0 ]; then |
| 150 | echo "RTOS-SDK: Uboot compilation failed !!!" |
| 151 | exit 1 |
| 152 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 153 | popd |
| 154 | } |
| 155 | |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 156 | function debug_info() { |
| 157 | echo "<============ Kconfig RTOS ============>" |
| 158 | cat $RTOS_BASE_DIR/Kconfig |
| 159 | echo "<============ CMakeLists RTOS ============>" |
| 160 | cat $RTOS_BASE_DIR/CMakeLists.txt |
| 161 | echo "<============ XML RTOS ============>" |
| 162 | cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml |
| 163 | echo "<============ XML OLD RTOS ============>" |
| 164 | cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 165 | echo "<============ JENKINS FOR RTOS ============>" |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 166 | } |
| 167 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 168 | #Configure the RTOS environment |
| 169 | if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then |
| 170 | rtos_config_prepare |
| 171 | fi |
| 172 | #Compile toolchain preparation |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 173 | toolchain_prepare |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 174 | #compile the rtos image |
shijie.xiong | 26895eb | 2023-10-09 11:28:08 +0800 | [diff] [blame] | 175 | cd $RTOS_BASE_DIR && make |
shijie.xiong | 01dafeb | 2024-04-03 15:46:49 +0800 | [diff] [blame^] | 176 | if [ "$?" -ne 0 ]; then |
| 177 | echo "RTOS-SDK: RTOS compilation failed !!!" |
| 178 | exit 1 |
| 179 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 180 | #lz4 compression |
| 181 | lz4_rtos |
| 182 | #compile the bl22 image |
| 183 | bl22_compile |
| 184 | #compile the u-boot image |
| 185 | package_fastboot |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 186 | #debug |
| 187 | debug_info |