blob: cf93777feca98dd845cc37e674f42cad018b2a6c [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.xiong1361fbb2023-01-06 11:01:31 +080044#Get the rtos target address (The configuration needs to be consistent with the lscript.h file)
45if [ -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
57fi
58
59#Get the loading address of rtos2
60let "RTOS2_TARGET_ADDRESS=$RTOS_TARGET_ADDRESS+0x200000"
61RTOS2_TARGET_ADDRESS=$(printf '0x%x\n' $RTOS2_TARGET_ADDRESS)
62
shijie.xiongc143e9c2022-11-18 17:58:30 +080063#Clear cache files
64[ -d $RTOS_BASE_DIR/output ] && rm -rf $RTOS_BASE_DIR/output
shijie.xionga5091132022-12-13 15:16:17 +080065
shijie.xiongffcaf582022-11-08 17:16:58 +080066#Get the current project environment variables
shijie.xionga5091132022-12-13 15:16:17 +080067source $RTOS_BASE_DIR/scripts/env.sh arm64 c3 $BOARD_TYPE fastboot
shijie.xiongffcaf582022-11-08 17:16:58 +080068
69#RTOS object file path
70RTOS_BUILD_DIR=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/freertos
71RTOS_IMAGE_A=$RTOS_BUILD_DIR/rtos_1.bin
72RTOS_IMAGE_B=$RTOS_BUILD_DIR/rtos_2.bin
73
shijie.xiong1361fbb2023-01-06 11:01:31 +080074function 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
85function 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.xiongfec9efd2022-11-10 11:32:33 +080091function lz4_rtos() {
92 pushd $RTOS_BASE_DIR/lib/utilities/lz4
93 cp $RTOS_IMAGE_A .
shijie.xiong1361fbb2023-01-06 11:01:31 +080094 #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.xiongfec9efd2022-11-10 11:32:33 +080096 cp ./self_decompress_firmware.bin $RTOS_IMAGE_A
97 popd
98}
99
shijie.xiongffcaf582022-11-08 17:16:58 +0800100function bl22_compile() {
101 if [ -d $BL22_DIR ]; then
102 pushd $BL22_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800103 if [ -f ./mk ]; then
shijie.xiong1361fbb2023-01-06 11:01:31 +0800104 ./mk c3 $BOARD_TYPE
shijie.xiongfec9efd2022-11-10 11:32:33 +0800105 fi
shijie.xiongffcaf582022-11-08 17:16:58 +0800106 cp ./bl22.bin $RTOS_BUILD_DIR/bl22.bin
107 popd
108 fi
109}
110
shijie.xiongffcaf582022-11-08 17:16:58 +0800111function package_fastboot() {
shijie.xiongffcaf582022-11-08 17:16:58 +0800112 pushd $UBOOT_DIR
shijie.xiongfec9efd2022-11-10 11:32:33 +0800113 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.xiongffcaf582022-11-08 17:16:58 +0800120 #./mk c3_aw419 --update-bl2 --bl31 ./blob-bl31.bin.signed
shijie.xiongc2bab512022-11-10 17:53:37 +0800121 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./blob-bl31.bin.signed
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800122 #./mk c3_aw419 --update-bl2 --update-bl2e --bl31 ./fip/blob-bl31.bin.signed
shijie.xionga5091132022-12-13 15:16:17 +0800123 ./mk $BOARD_TYPE_MAPPING
shijie.xiongffcaf582022-11-08 17:16:58 +0800124 popd
125}
126
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800127function 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.xionga5091132022-12-13 15:16:17 +0800136 echo "<============ JENKINS FOR RTOS ============>"
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800137}
138
shijie.xiong1361fbb2023-01-06 11:01:31 +0800139#Configure the RTOS environment
140if [ $4 ] && [[ "$4" =~ ^0x.* ]]; then
141 rtos_config_prepare
142fi
143#Compile toolchain preparation
shijie.xionga5091132022-12-13 15:16:17 +0800144toolchain_prepare
shijie.xiongffcaf582022-11-08 17:16:58 +0800145#compile the rtos image
146cd $RTOS_BASE_DIR && make scatter
147#lz4 compression
148lz4_rtos
149#compile the bl22 image
150bl22_compile
151#compile the u-boot image
152package_fastboot
shijie.xiong5fc0ac12022-11-21 10:08:21 +0800153#debug
154debug_info