guowenxue
2024-09-26 7c35a51bbd38a171ee63c79d3d70966181859021
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/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"
}
 
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 "
 
    apt update > /dev/null 2>&1
    apt install -y $systools
}
 
 
function install_devtools()
{
    if command -v debootstrap > /dev/null 2>&1 ; then
        pr_info "All development tools already installed, skip it"
        return 0;
    fi
 
    pr_info "start apt install devlopment tools(commands)"
 
    devtools="u-boot-tools mtd-utils device-tree-compiler binfmt-support \
                qemu qemu-user-static debootstrap debian-archive-keyring "
 
    apt install -y $devtools
}
 
function install_crosstool_aarch32()
{
    # Crosstool for Cortex-A download from ARM Developer
    ARMTOOL_NAME=arm-none-linux-gnueabihf
    CortexA_PACK=gcc-arm-$ARMTOOL_VER-`uname -p`-$ARMTOOL_NAME
    CortexA_TAR=$CortexA_PACK.tar.xz
    CortexA_URL=https://developer.arm.com/-/media/Files/downloads/gnu-a/$ARMTOOL_VER/binrel/
    CortexA_NAME=gcc-aarch32-$ARMTOOL_VER
 
    if [ -d /opt/$CortexA_NAME ]  ; then
        pr_info "Cortex-A crosstool /opt/$CortexA_NAME installed already, skip it"
    else
        if [ ! -s $CortexA_TAR ] ; then
            pr_info "start download cross compiler from ARM Developer for Cortex-A core"
            wget $CortexA_URL/$CortexA_TAR
        fi
 
        pr_info "start decompress cross compiler for Cortex-A core"
        tar -xJf $CortexA_TAR -C /opt
        mv /opt/$CortexA_PACK /opt/$CortexA_NAME
        /opt/$CortexA_NAME/bin/${ARMTOOL_NAME}-gcc -v
        pr_info "cross compiler for Cortex-A installed to \"/opt/$CortexA_NAME\" successfully"
        rm -f $CortexA_TAR
    fi
}
 
function install_crosstool_aarch64()
{
    # Crosstool for Cortex-M download from ARM Developer
    ARMTOOL_NAME=arm-none-eabi
    CortexM_PACK=gcc-$ARMTOOL_NAME-$ARMTOOL_VER-`uname -p`-linux
    CortexM_TAR=$CortexM_PACK.tar.bz2
    CortexM_URL=https://developer.arm.com/-/media/Files/downloads/gnu-rm/$ARMTOOL_VER/
    CortexM_NAME=gcc-cortexM-$ARMTOOL_VER
 
    if [ -d /opt/$CortexM_NAME ]  ; then
        pr_info "Cortex-M crosstool /opt/$CortexM_NAME installed already, skip it"
    else
        if [ ! -s $CortexM_TAR ] ; then
            pr_info "start download cross compiler from ARM Developer for Cortex-M core"
            wget $CortexM_URL/$CortexM_TAR
        fi
 
        pr_info "start decompress cross compiler for Cortex-M core"
        tar -xjf $CortexM_TAR -C /opt
        mv /opt/gcc-$ARMTOOL_NAME-$ARMTOOL_VER /opt/$CortexM_NAME
        /opt/$CortexM_NAME/bin/$ARMTOOL_NAME-gcc -v
        pr_info "cross compiler for Cortex-M installed to \"/opt/$CortexM_NAME\" successfully"
        rm -f $CortexM_TAR
    fi
 
    # Crosstool for Cortex-A download from ARM Developer
    ARMTOOL_NAME=aarch64-none-linux-gnu
    CortexA_PACK=gcc-arm-$ARMTOOL_VER-`uname -p`-$ARMTOOL_NAME
    CortexA_TAR=$CortexA_PACK.tar.xz
    CortexA_URL=https://developer.arm.com/-/media/Files/downloads/gnu-a/$ARMTOOL_VER/binrel/
    CortexA_NAME=gcc-aarch64-$ARMTOOL_VER
 
    if [ -d /opt/$CortexA_NAME ]  ; then
        pr_info "Cortex-A crosstool /opt/$CortexA_NAME installed already, skip it"
    else
        if [ ! -s $CortexA_TAR ] ; then
            pr_info "start download cross compiler from ARM Developer for Cortex-A core"
            wget $CortexA_URL/$CortexA_TAR
        fi
 
        pr_info "start decompress cross compiler for Cortex-A core"
        tar -xJf $CortexA_TAR -C /opt
        mv /opt/$CortexA_PACK /opt/$CortexA_NAME
        /opt/$CortexA_NAME/bin/$ARMTOOL_NAME-gcc -v
        pr_info "cross compiler for Cortex-A installed to \"/opt/$CortexA_NAME\" successfully"
        rm -f $CortexA_TAR
    fi
}
 
if [ `id -u` != 0 ] ; then
    echo ""
    pr_error "This shell script must be excuted as root privilege"
    exit;
fi
 
install_systools
 
install_devtools
 
BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'`
 
if [[ $BOARD =~ mx6ull ]] ; then
    install_crosstool_aarch32
else
    install_crosstool_aarch64
fi