New file |
| | |
| | | #!/bin/bash |
| | | # This shell script used to install system tools |
| | | |
| | | # this project absolute path |
| | | PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
| | | |
| | | # top project absolute path |
| | | TOP_PATH=$(realpath $PRJ_PATH/..) |
| | | |
| | | # config file path |
| | | CONF_FILE=$TOP_PATH/config.json |
| | | |
| | | # NXP document suggest cross compiler from ARM Developer: |
| | | # https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads |
| | | ARMTOOL_VER=10.3-2021.07 |
| | | |
| | | # shell script will exit once get command error |
| | | set -e |
| | | |
| | | #+-------------------------+ |
| | | #| Shell script functions | |
| | | #+-------------------------+ |
| | | |
| | | function pr_error() { |
| | | echo -e "\033[40;31m $1 \033[0m" |
| | | } |
| | | |
| | | function pr_warn() { |
| | | echo -e "\033[40;33m $1 \033[0m" |
| | | } |
| | | |
| | | function pr_info() { |
| | | echo -e "\033[40;32m $1 \033[0m" |
| | | } |
| | | |
| | | # decompress a packet to destination path |
| | | function do_unpack() |
| | | { |
| | | tarball=$1 |
| | | dstpath=`pwd` |
| | | |
| | | if [[ $# == 2 ]] ; then |
| | | dstpath=$2 |
| | | fi |
| | | |
| | | pr_info "decompress $tarball => $dstpath" |
| | | |
| | | mkdir -p $dstpath |
| | | case $tarball in |
| | | *.tar.gz) |
| | | tar -xzf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.bz2) |
| | | tar -xjf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.xz) |
| | | tar -xJf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar.zst) |
| | | tar -I zstd -xf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.tar) |
| | | tar -xf $tarball -C $dstpath |
| | | ;; |
| | | |
| | | *.zip) |
| | | unzip -qo $tarball -d $dstpath |
| | | ;; |
| | | |
| | | *) |
| | | pr_error "decompress Unsupport packet: $tarball" |
| | | return 1; |
| | | ;; |
| | | esac |
| | | } |
| | | |
| | | # parser configure file and export environment variable |
| | | function export_env() |
| | | { |
| | | export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
| | | export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
| | | export BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE` |
| | | export CROSS_COMPILE=`jq -r ".bsp.crosstool" $CONF_FILE` |
| | | } |
| | | |
| | | function install_systools() |
| | | { |
| | | if command -v jq > /dev/null 2>&1 ; then |
| | | pr_info "All system tools already installed, skip it" |
| | | return 0; |
| | | fi |
| | | |
| | | pr_info "start apt install system tools(commands)" |
| | | |
| | | systools="coreutils jq wget curl tree gawk sed unzip cpio bc lzop zstd rsync kmod kpartx \ |
| | | desktop-file-utils iputils-ping xterm diffstat chrpath asciidoc docbook-utils help2man \ |
| | | build-essential gcc g++ make cmake automake groff socat flex texinfo bison texi2html \ |
| | | git cvs subversion mercurial autoconf autoconf-archive parted dosfstools \ |
| | | python3 python3-pip python3-pexpect python3-git python3-jinja2 \ |
| | | lib32z1 libssl-dev libncurses-dev libgl1-mesa-dev libglu1-mesa-dev libsdl1.2-dev \ |
| | | u-boot-tools mtd-utils device-tree-compiler binfmt-support " |
| | | |
| | | apt update > /dev/null 2>&1 |
| | | apt install -y $systools |
| | | } |
| | | |
| | | function install_crosstool() |
| | | { |
| | | # Crosstool installed path |
| | | CROSSTOOL_PATH=`dirname $CROSS_COMPILE` |
| | | |
| | | # crosstool name and version |
| | | tmp="${CROSS_COMPILE%/bin/*}" |
| | | CROSSTOOL_NAME="${tmp##*/}" |
| | | |
| | | # crosstool installed path |
| | | CROSSTOOL_DIR="${CROSS_COMPILE%%/$CROSSTOOL_NAME/*}/" |
| | | |
| | | |
| | | if [ -d $CROSSTOOL_PATH ] ; then |
| | | pr_info "Crosstool already installed to $CROSSTOOL_PATH, skip it" |
| | | return ; |
| | | fi |
| | | |
| | | wget $BSP_URL/at91/bsp/$BSP_VER/$CROSSTOOL_NAME.tar.xz |
| | | |
| | | # decompress source code packet |
| | | mkdir -p $CROSSTOOL_DIR |
| | | do_unpack $CROSSTOOL_NAME.tar.xz $CROSSTOOL_DIR |
| | | |
| | | # show cross compiler version information |
| | | ${CROSS_COMPILE}gcc -v |
| | | |
| | | rm -f $CROSSTOOL_NAME.tar.xz |
| | | } |
| | | |
| | | if [ `id -u` != 0 ] ; then |
| | | echo "" |
| | | pr_error "This shell script must be excuted as root privilege" |
| | | exit; |
| | | fi |
| | | |
| | | export_env |
| | | |
| | | install_systools |
| | | |
| | | install_crosstool |
| | | |