guowenxue
2024-07-18 b8d02950d8c50611c2784c7a40e0b3003acf8d49
commit | author | age
849fbd 1 #!/bin/bash
G 2 # This shell script used to install system tools
3
e2a28d 4 # this project absolute path
G 5 PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
6
7 # top project absolute path
8 TOP_PATH=$(realpath $PRJ_PATH/..)
9
10 # config file path
11 CONF_FILE=$TOP_PATH/config.json
12
13 # NXP document suggest cross compiler from ARM Developer:
14 #   https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
15 ARMTOOL_VER=10.3-2021.07
16
17 # shell script will exit once get command error
18 set -e
19
20 #+-------------------------+
21 #| Shell script functions  |
22 #+-------------------------+
23
849fbd 24 function pr_error() {
e2a28d 25     echo -e "\033[40;31m $1 \033[0m"
849fbd 26 }
G 27
e2a28d 28 function pr_warn() {
G 29     echo -e "\033[40;33m $1 \033[0m"
30 }
31
849fbd 32 function pr_info() {
e2a28d 33     echo -e "\033[40;32m $1 \033[0m"
849fbd 34 }
G 35
36 function install_systools()
37 {
38     if command -v jq > /dev/null 2>&1 ; then
39         pr_info "All system tools already installed, skip it"
40         return 0;
41     fi
42
43     pr_info "start apt install system tools(commands)"
44
45     systools="coreutils jq wget curl tree gawk sed unzip cpio bc lzop zstd rsync kmod kpartx \
46         desktop-file-utils iputils-ping xterm diffstat chrpath asciidoc docbook-utils help2man \
47         build-essential gcc g++ make cmake automake groff socat flex texinfo bison texi2html \
48         git cvs subversion mercurial autoconf autoconf-archive parted dosfstools \
49         python3 python3-pip python3-pexpect python3-git python3-jinja2 \
50         lib32z1 libssl-dev libncurses-dev libgl1-mesa-dev libglu1-mesa-dev libsdl1.2-dev "
51
52     apt update > /dev/null 2>&1
53     apt install -y $systools
54 }
55
56
57 function install_devtools()
58 {
59     if command -v debootstrap > /dev/null 2>&1 ; then
60         pr_info "All development tools already installed, skip it"
61         return 0;
62     fi
63
64     pr_info "start apt install devlopment tools(commands)"
65
66     devtools="u-boot-tools mtd-utils device-tree-compiler binfmt-support \
67                 qemu qemu-user-static debootstrap debian-archive-keyring "
68
69     apt install -y $devtools
70 }
71
e2a28d 72 function install_crosstool_imx6()
849fbd 73 {
e2a28d 74     # Crosstool for Cortex-A download from ARM Developer
G 75     ARMTOOL_NAME=arm-none-linux-gnueabihf
76     CortexA_PACK=gcc-arm-$ARMTOOL_VER-`uname -p`-$ARMTOOL_NAME
77     CortexA_TAR=$CortexA_PACK.tar.xz
78     CortexA_URL=https://developer.arm.com/-/media/Files/downloads/gnu-a/$ARMTOOL_VER/binrel/
79     CortexA_NAME=gcc-aarch32-$ARMTOOL_VER
849fbd 80
e2a28d 81     if [ -d /opt/$CortexA_NAME ]  ; then
G 82         pr_info "Cortex-A crosstool /opt/$CortexA_NAME installed already, skip it"
83     else
84         if [ ! -s $CortexA_TAR ] ; then
85             pr_info "start download cross compiler from ARM Developer for Cortex-A core"
86             wget $CortexA_URL/$CortexA_TAR
87         fi
88
89         pr_info "start decompress cross compiler for Cortex-A core"
90         tar -xJf $CortexA_TAR -C /opt
91         mv /opt/$CortexA_PACK /opt/$CortexA_NAME
92         /opt/$CortexA_NAME/bin/${ARMTOOL_NAME}-gcc -v
93         pr_info "cross compiler for Cortex-A installed to \"/opt/$CortexA_NAME\" successfully"
94         rm -f $CortexA_TAR
95     fi
96 }
97
98 function install_crosstool_imx8()
99 {
100     # Crosstool for Cortex-M download from ARM Developer
101     ARMTOOL_NAME=arm-none-eabi
102     CortexM_PACK=gcc-$ARMTOOL_NAME-$ARMTOOL_VER-`uname -p`-linux
849fbd 103     CortexM_TAR=$CortexM_PACK.tar.bz2
G 104     CortexM_URL=https://developer.arm.com/-/media/Files/downloads/gnu-rm/$ARMTOOL_VER/
105     CortexM_NAME=gcc-cortexM-$ARMTOOL_VER
106
107     if [ -d /opt/$CortexM_NAME ]  ; then
108         pr_info "Cortex-M crosstool /opt/$CortexM_NAME installed already, skip it"
109     else
110         if [ ! -s $CortexM_TAR ] ; then
111             pr_info "start download cross compiler from ARM Developer for Cortex-M core"
112             wget $CortexM_URL/$CortexM_TAR
113         fi
114
115         pr_info "start decompress cross compiler for Cortex-M core"
116         tar -xjf $CortexM_TAR -C /opt
e2a28d 117         mv /opt/gcc-$ARMTOOL_NAME-$ARMTOOL_VER /opt/$CortexM_NAME
G 118         /opt/$CortexM_NAME/bin/$ARMTOOL_NAME-gcc -v
849fbd 119         pr_info "cross compiler for Cortex-M installed to \"/opt/$CortexM_NAME\" successfully"
e2a28d 120         rm -f $CortexM_TAR
849fbd 121     fi
G 122
123     # Crosstool for Cortex-A download from ARM Developer
e2a28d 124     ARMTOOL_NAME=aarch64-none-linux-gnu
G 125     CortexA_PACK=gcc-arm-$ARMTOOL_VER-`uname -p`-$ARMTOOL_NAME
849fbd 126     CortexA_TAR=$CortexA_PACK.tar.xz
G 127     CortexA_URL=https://developer.arm.com/-/media/Files/downloads/gnu-a/$ARMTOOL_VER/binrel/
128     CortexA_NAME=gcc-aarch64-$ARMTOOL_VER
129
130     if [ -d /opt/$CortexA_NAME ]  ; then
131         pr_info "Cortex-A crosstool /opt/$CortexA_NAME installed already, skip it"
132     else
133         if [ ! -s $CortexA_TAR ] ; then
134             pr_info "start download cross compiler from ARM Developer for Cortex-A core"
135             wget $CortexA_URL/$CortexA_TAR
136         fi
137
138         pr_info "start decompress cross compiler for Cortex-A core"
139         tar -xJf $CortexA_TAR -C /opt
140         mv /opt/$CortexA_PACK /opt/$CortexA_NAME
e2a28d 141         /opt/$CortexA_NAME/bin/$ARMTOOL_NAME-gcc -v
849fbd 142         pr_info "cross compiler for Cortex-A installed to \"/opt/$CortexA_NAME\" successfully"
e2a28d 143         rm -f $CortexA_TAR
849fbd 144     fi
G 145 }
146
e2a28d 147 if [ `id -u` != 0 ] ; then
G 148     echo ""
149     pr_error "This shell script must be excuted as root privilege"
150     exit;
151 fi
849fbd 152
G 153 install_systools
154
155 install_devtools
156
e2a28d 157 BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'`
G 158
159 if [[ $BOARD =~ mx6ull ]] ; then
160     install_crosstool_imx6
161 else
162     install_crosstool_imx8
163 fi
849fbd 164