blob: e88e7865115f0287fe0e40b2beb16ce3be79fd62 [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
12BOARD_DEFINE_REF=(c3_aw409 c3_aw402 c3_aw419)
13BOARD_DEFINE_PAR=(aw409_c302x aw402_c302x aw419_c308l)
14
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"
40 echo -e "\033[33m board_type: aw409_c302x / aw402_c302x / aw419_c308l\033[0m"
41 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
45if [ -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
56fi
57
shijie.xiong1361fbb2023-01-06 11:01:31 +080058#Get the rtos target address (The configuration needs to be consistent with the lscript.h file)
59if [ -z $RTOS_TARGET_ADDRESS ]; then
60 case $BOARD_TYPE_MAPPING in
61 'c3_aw409')
62 RTOS_TARGET_ADDRESS=0x5400000
63 ;;
64 'c3_aw402')
Shijie Xiong5e88ce62023-02-09 22:46:55 -080065 RTOS_TARGET_ADDRESS=0x7600000
shijie.xiong1361fbb2023-01-06 11:01:31 +080066 ;;
67 *)
68 RTOS_TARGET_ADDRESS=0x9000000
69 ;;
70 esac
71fi
72
73#Get the loading address of rtos2
74let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x200000"
75RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS)
76
shijie.xiongc143e9c2022-11-18 17:58:30 +080077#Clear cache files
78[ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output
shijie.xionga5091132022-12-13 15:16:17 +080079
shijie.xiongffcaf582022-11-08 17:16:58 +080080#Get the current project environment variables
shijie.xionga5091132022-12-13 15:16:17 +080081source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +080082
83#RTOS object file path
84RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos
85RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin
86RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin
87
shijie.xiong1361fbb2023-01-06 11:01:31 +080088function toolchain_prepare() {
89 echo "<============ TOOLCHAIN INFO RTOS ============>"
90 CROSSTOOL=$RTOS_BASE_DIR/arch/$ARCH/toolchain/$COMPILER*$TOOLCHAIN_KEYWORD
shijie.xiong82037e82023-03-01 14:34:41 +080091 TOOLCHAIN_DIR=$RTOS_BASE_DIR/output/toolchains/$COMPILER-$TOOLCHAIN_KEYWORD
shijie.xiong1361fbb2023-01-06 11:01:31 +080092 rm -rf $RTOS_BASE_DIR/output/toolchains
shijie.xiong82037e82023-03-01 14:34:41 +080093 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.xiong1361fbb2023-01-06 11:01:31 +080097 echo "<============ TOOLCHAIN INFO RTOS ============>"
98}
99
100function 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.xiongfec9efd2022-11-10 11:32:33 +0800106function lz4_rtos() {
107 pushd $RTOS_BASE_DIR/lib/utilities/lz4
108 cp $RTOS_IMAGE_A .
shijie.xiong1361fbb2023-01-06 11:01:31 +0800109 #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.xiongfec9efd2022-11-10 11:32:33 +0800111 cp ./self_decompress_firmware.bin $RTOS_IMAGE_A
112 popd
113}
114
shijie.xiongffcaf582022-11-08 17:16:58 +0800115function bl22_compile() {
116 if [ -d $BL22_DIR ]; then
117 pushd $BL22_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800118 if [ -f ./mk ]; then
shijie.xiong1361fbb2023-01-06 11:01:31 +0800119 ./mk c3 $BOARD_TYPE
shijie.xiongfec9efd2022-11-10 11:32:33 +0800120 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800121 cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin
122 popd
123 fi
124}
125
shijie.xiongffcaf582022-11-08 17:16:58 +0800126function package_fastboot() {
shijie.xiongffcaf582022-11-08 17:16:58 +0800127 pushd $UBOOT_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800128 if [ -d ./fastboot ]; then
129 rm -rf ./fastboot
130 fi
131 mkdir -p ./fastboot
132 cp $RTOS_IMAGE_A ./fastboot
133 cp $RTOS_IMAGE_B ./fastboot
134 cp $RTOS_BUILD_DIR/bl22.bin ./fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +0800135 #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed
shijie.xiongc2bab512022-11-10 17:53:37 +0800136 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800137 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed
shijie.xionga5091132022-12-13 15:16:17 +0800138 ./mk $BOARD_TYPE_MAPPING
shijie.xiongffcaf582022-11-08 17:16:58 +0800139 popd
140}
141
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800142function debug_info() {
143 echo "<============ Kconfig RTOS ============>"
144 cat $RTOS_BASE_DIR/Kconfig
145 echo "<============ CMakeLists RTOS ============>"
146 cat $RTOS_BASE_DIR/CMakeLists.txt
147 echo "<============ XML RTOS ============>"
148 cat $RTOS_BUILD_DIR/rtos_sdk_manifest.xml
149 echo "<============ XML OLD RTOS ============>"
150 cat $RTOS_BUILD_DIR/rtos_sdk_manifest_old.xml
shijie.xionga5091132022-12-13 15:16:17 +0800151 echo "<============ JENKINS FOR RTOS ============>"
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800152}
153
shijie.xiong1361fbb2023-01-06 11:01:31 +0800154#Configure the RTOS environment
155if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
156 rtos_config_prepare
157fi
158#Compile toolchain preparation
shijie.xionga5091132022-12-13 15:16:17 +0800159toolchain_prepare
shijie.xiongffcaf582022-11-08 17:16:58 +0800160#compile the rtos image
161cd $RTOS_BASE_DIR && make scatter
162#lz4 compression
163lz4_rtos
164#compile the bl22 image
165bl22_compile
166#compile the u-boot image
167package_fastboot
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800168#debug
169debug_info