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