Files
BPI-CM9-Linux/aml-comp/uboot/bl30/rtos_sdk/scripts/pkg_env.sh
T

209 lines
5.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#
# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
#
# SPDX-License-Identifier: MIT
#
###############################################################
# Function: choose board and product, set environment variables.
###############################################################
RTOS_ROOT_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0})))
export RTOS_ROOT_DIR
usage() {
echo "Usage: source $BASH_SOURCE [arch_name] [soc_name] [board_name] [product_name]"
echo "−h: display help."
echo ""
}
version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
# $1: arch
# $2: soc
# $3: board
# $4: product
check_package_combination() {
i=0
for arch in ${ARCHES[*]}; do
[[ "$1" == "$arch" ]] && break
i=$((i + 1))
done
[ $i -ge ${#ARCHES[*]} ] && return 1
i=0
for soc in ${SOCS[*]}; do
[[ "$2" == "$soc" ]] && break
i=$((i + 1))
done
[ "$i" -ge ${#SOCS[*]} ] && return 2
i=0
for board in ${BOARDS[*]}; do
[[ "$3" == "$board" ]] && break
i=$((i + 1))
done
[ "$i" -ge ${#BOARDS[*]} ] && return 3
i=0
for product in ${PRODUCTS[*]}; do
[[ "$4" == "$product" ]] && break
i=$((i + 1))
done
[ "$i" -ge ${#PRODUCTS[*]} ] && return 4
return 0
}
function parse_package_combination() {
unset ARCHES SOCS BOARDS PRODUCTS
ARCHES=($(find $RTOS_ROOT_DIR/rtos/*/arch -mindepth 1 -maxdepth 1 -type d ! -name ".*" | \
xargs basename -a | sort -n))
SOCS=($(find $RTOS_ROOT_DIR/rtos/*/soc -mindepth 2 -maxdepth 2 -type d ! -name ".*" | \
xargs basename -a | sort -n))
BOARDS=($(find $RTOS_ROOT_DIR/rtos/*/boards -mindepth 2 -maxdepth 2 -type d ! -name ".*" | \
xargs basename -a | sort -n))
PRODUCTS=($(find $RTOS_ROOT_DIR/rtos/*/products -mindepth 1 -maxdepth 1 -type d ! -name ".*" | \
xargs basename -a | sort -n))
PACKAGE_COMBINATION_INPUT="$PWD/image_packer/package_combination.in"
export PACKAGE_COMBINATION="$PWD/output/package_combination.txt"
if [ ! -d "$PWD/output" ]; then
mkdir -p $PWD/output
fi
if [ ! -s "$PACKAGE_COMBINATION" ] || [ $PACKAGE_COMBINATION -ot $PACKAGE_COMBINATION_INPUT ]; then
: >$PACKAGE_COMBINATION
while IFS= read -r LINE; do
valid_line=true
read -a ARRY <<< "$LINE"
for ((loop = 0; loop < ${#ARRY[@]}; loop += 4)); do
arch=${ARRY[loop]}
soc=${ARRY[loop + 1]}
board=${ARRY[loop + 2]}
product=${ARRY[loop + 3]}
check_package_combination $arch $soc $board $product
if [ $? -ne 0 ]; then
valid_line=false
break
fi
done
if [ "$valid_line" = false ]; then
continue
fi
echo $LINE >>$PACKAGE_COMBINATION
done <$PACKAGE_COMBINATION_INPUT
fi
}
function apply_default_patches()
{
AML_PATCHES_PATH="$RTOS_ROOT_DIR/aml-patches"
if [ -d $AML_PATCHES_PATH ] && [ -n "$(find $AML_PATCHES_PATH -name '*.patch')" ] \
&& [ ! -f $RTOS_ROOT_DIR/.aml-rtos-patch-done ]; then
echo "Appling Patches in $RTOS_ROOT_DIR/aml-patches"
touch $RTOS_ROOT_DIR/.aml-rtos-patch-done
for PatchFolder in $(for p in $(find $AML_PATCHES_PATH -name *.patch \
-printf "%P\n"); do dirname $p; done | sort -u | xargs);
do
if [ -d $RTOS_ROOT_DIR/$PatchFolder ]; then
PROJ_PATH=$RTOS_ROOT_DIR/$PatchFolder
else
echo "$RTOS_ROOT_DIR/$PatchFolder not exist"
continue
fi
for Patch in $(find $AML_PATCHES_PATH/$PatchFolder -maxdepth 1 \
-name '*.patch' -printf "%P\n" | sort | xargs)
do
echo "Try applying patch: $AML_PATCHES_PATH/$PatchFolder/$Patch..."
if git -C $PROJ_PATH apply --check \
$AML_PATCHES_PATH/$PatchFolder/$Patch; then
git -C $PROJ_PATH am $AML_PATCHES_PATH/$PatchFolder/$Patch
else
echo "$PatchFolder/$Patch can't be applied to $PROJ_PATH"
return 1
fi
echo "....Done"
done
done
else
return 0
fi
}
CMAKE_FILE=$(which cmake)
if [ -x /opt/cmake-3.18.4-Linux-x86_64/bin/cmake ]; then
export PATH=/opt/cmake-3.18.4-Linux-x86_64/bin/:$PATH
elif [ -n "$CMAKE_FILE" ]; then
CMAKE_VERSION=$(cmake --version)
pattern="cmake version "
CMAKE_VERSION=$(echo ${CMAKE_VERSION#*${pattern}})
pattern=" CMake"
CMAKE_VERSION=$(echo ${CMAKE_VERSION%${pattern}*})
if version_lt $CMAKE_VERSION "3.13.1"; then
echo "cmake version $CMAKE_VERSION < 3.13.1!"
echo "Please upgrade cmake!"
return 0
fi
else
echo "cmake not found!"
echo "Please install cmake!"
return 0
fi
NINJA_FILE=$(which ninja)
if [ -z "$NINJA_FILE" ]; then
echo "ninja not found!"
echo "Please install ninja!"
return 0
fi
apply_default_patches
parse_package_combination
if [ -n "$1" ] && [ $1 == "-h" ]; then
usage
return 0
elif [ $# -eq 2 ] && [ $2 == "gen_all" ]; then
CHOICE_PACKAGE=$1
echo "Choose project:$CHOICE_PACKAGE"
else
unset CHOICE_PACKAGE
if [ -z "$CHOICE_PACKAGE" ]; then
echo "Available projects:"
#show all package combinations
j=0
while IFS= read -r LINE; do
NR=$j
echo -e "\t$NR. ${LINE[@]}"
j=$((j + 1))
done <$PACKAGE_COMBINATION
read -p "Choose your project: " CHOICE_PACKAGE
# Determine whether it is a digital number
expr $CHOICE_PACKAGE + 1 >/dev/null 2>&1
if [[ $? -ne 0 ]] || [[ $CHOICE_PACKAGE -ge $j ]]; then
echo "Wrong choice!"
return 0
fi
fi
fi
KERNEL=freertos
export KERNEL CHOICE_PACKAGE
LINK_SRC_PACKAGE=$RTOS_ROOT_DIR/rtos/speaker/scripts/gen_package.sh
LINK_DST_PACKAGE=$RTOS_ROOT_DIR/gen_package.sh
if [[ -f "$LINK_SRC_PACKAGE" ]]; then
ln -sfn "$LINK_SRC_PACKAGE" "$LINK_DST_PACKAGE"
else
echo "Please ensure the $LINK_SRC_PACKAGE is exist or execute repo sync"
return 1
fi
return 0