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 |
| 12 | BOARD_DEFINE_REF=(c3_aw409 c3_aw402 c3_aw419) |
| 13 | BOARD_DEFINE_PAR=(aw409_c302x aw402_c302x aw419_c308l) |
| 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" |
| 40 | echo -e "\033[33m board_type: aw409_c302x / aw402_c302x / aw419_c308l\033[0m" |
| 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 |
| 45 | if [ -d $RTOS_BASE_DIR/binary_release ] && [ -d $RTOS_BASE_DIR/bl22_bin ] && [ "$BOARD_TYPE_MAPPING" == "c3_aw402" ]; then |
| 46 | pushd $UBOOT_DIR |
| 47 | if [ -d ./fastboot ]; then |
| 48 | rm -rf ./fastboot |
| 49 | fi |
| 50 | mkdir -p ./fastboot |
| 51 | cp $RTOS_BASE_DIR/binary_release/* ./fastboot |
| 52 | cp $RTOS_BASE_DIR/bl22_bin/bl22.bin ./fastboot |
| 53 | ./mk $BOARD_TYPE_MAPPING |
| 54 | popd |
| 55 | exit 0 |
| 56 | fi |
| 57 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 58 | #Get the rtos target address (The configuration needs to be consistent with the lscript.h file) |
| 59 | if [ -z $RTOS_TARGET_ADDRESS ]; then |
| 60 | case $BOARD_TYPE_MAPPING in |
| 61 | 'c3_aw409') |
| 62 | RTOS_TARGET_ADDRESS=0x5400000 |
| 63 | ;; |
| 64 | 'c3_aw402') |
Shijie Xiong | 5e88ce6 | 2023-02-09 22:46:55 -0800 | [diff] [blame] | 65 | RTOS_TARGET_ADDRESS=0x7600000 |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 66 | ;; |
| 67 | *) |
| 68 | RTOS_TARGET_ADDRESS=0x9000000 |
| 69 | ;; |
| 70 | esac |
| 71 | fi |
| 72 | |
| 73 | #Get the loading address of rtos2 |
| 74 | let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x200000" |
| 75 | RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS) |
| 76 | |
shijie.xiong | c143e9c | 2022-11-18 17:58:30 +0800 | [diff] [blame] | 77 | #Clear cache files |
| 78 | [ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 79 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 80 | #Get the current project environment variables |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 81 | source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 82 | |
| 83 | #RTOS object file path |
| 84 | RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos |
| 85 | RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin |
| 86 | RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin |
| 87 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 88 | function toolchain_prepare() { |
| 89 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 90 | CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 91 | TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 92 | rm -rf $RTOS_BASE_DIR/output/toolchains |
shijie.xiong | 82037e8 | 2023-03-01 14:34:41 +0800 | [diff] [blame] | 93 | mkdir -p $TOOLCHAIN_DIR |
| 94 | tar -xf $CROSSTOOL.tar.xz -C $TOOLCHAIN_DIR --strip-components=1 |
| 95 | ls -la $TOOLCHAIN_DIR/bin |
| 96 | $TOOLCHAIN_DIR/bin/aarch64-none-elf-gcc -v |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 97 | echo "<============ TOOLCHAIN INFO RTOS ============>" |
| 98 | } |
| 99 | |
| 100 | function rtos_config_prepare() { |
| 101 | CONFIG_FILE=$RTOS_BASE_DIR/boards/$ARCH/$BOARD/lscript.h |
| 102 | sed -i '/.*#define configTEXT_BASE*/c\#define configTEXT_BASE '${RTOS_TARGET_ADDRESS}'' $CONFIG_FILE |
| 103 | sed -i '/.*#define CONFIG_SCATTER_LOAD_ADDRESS*/c\#define CONFIG_SCATTER_LOAD_ADDRESS '${RTOS2_TARGET_ADDRESS}'' $CONFIG_FILE |
| 104 | } |
| 105 | |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 106 | function lz4_rtos() { |
| 107 | pushd $RTOS_BASE_DIR/lib/utilities/lz4 |
| 108 | cp $RTOS_IMAGE_A . |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 109 | #Get the rtos target address |
| 110 | ./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] | 111 | cp ./self_decompress_firmware.bin $RTOS_IMAGE_A |
shijie.xiong | c6a04f5 | 2023-06-21 13:39:54 +0800 | [diff] [blame] | 112 | rm ./self_decompress_firmware.bin ./rtos_1.bin |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 113 | popd |
| 114 | } |
| 115 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 116 | function bl22_compile() { |
| 117 | if [ -d $BL22_DIR ]; then |
| 118 | pushd $BL22_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 119 | if [ -f ./mk ]; then |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 120 | ./mk c3 $BOARD_TYPE |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 121 | fi |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 122 | cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin |
| 123 | popd |
| 124 | fi |
| 125 | } |
| 126 | |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 127 | function package_fastboot() { |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 128 | pushd $UBOOT_DIR |
shijie.xiong | fec9efd | 2022-11-10 11:32:33 +0800 | [diff] [blame] | 129 | if [ -d ./fastboot ]; then |
| 130 | rm -rf ./fastboot |
| 131 | fi |
| 132 | mkdir -p ./fastboot |
| 133 | cp $RTOS_IMAGE_A ./fastboot |
| 134 | cp $RTOS_IMAGE_B ./fastboot |
| 135 | cp $RTOS_BUILD_DIR/bl22.bin ./fastboot |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 136 | #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed |
shijie.xiong | c2bab51 | 2022-11-10 17:53:37 +0800 | [diff] [blame] | 137 | #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 138 | #./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] | 139 | ./mk $BOARD_TYPE_MAPPING |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 140 | popd |
| 141 | } |
| 142 | |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 143 | function debug_info() { |
| 144 | echo "<============ Kconfig RTOS ============>" |
| 145 | cat $RTOS_BASE_DIR/Kconfig |
| 146 | echo "<============ CMakeLists RTOS ============>" |
| 147 | cat $RTOS_BASE_DIR/CMakeLists.txt |
| 148 | echo "<============ XML RTOS ============>" |
| 149 | cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml |
| 150 | echo "<============ XML OLD RTOS ============>" |
| 151 | cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 152 | echo "<============ JENKINS FOR RTOS ============>" |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 153 | } |
| 154 | |
shijie.xiong | 1361fbb | 2023-01-06 11:01:31 +0800 | [diff] [blame] | 155 | #Configure the RTOS environment |
| 156 | if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then |
| 157 | rtos_config_prepare |
| 158 | fi |
| 159 | #Compile toolchain preparation |
shijie.xiong | a509113 | 2022-12-13 15:16:17 +0800 | [diff] [blame] | 160 | toolchain_prepare |
shijie.xiong | ffcaf58 | 2022-11-08 17:16:58 +0800 | [diff] [blame] | 161 | #compile the rtos image |
| 162 | cd $RTOS_BASE_DIR && make scatter |
| 163 | #lz4 compression |
| 164 | lz4_rtos |
| 165 | #compile the bl22 image |
| 166 | bl22_compile |
| 167 | #compile the u-boot image |
| 168 | package_fastboot |
shijie.xiong | 5fc0ac1 | 2022-11-21 10:08:21 +0800 | [diff] [blame] | 169 | #debug |
| 170 | debug_info |