NXP i.MX EVK board build tools
guowenxue
2023-11-14 658bbdce56f39e74b151e1fd75cf2544f5263e86
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
164
165
166
167
#!/bin/bash
# This shell script used to fetch debian root file system
 
# this project absolute path
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
 
# the target board name and ARCH(armel/armhf/arm64)
BOARD=igkboard
ARCH=armhf
ARCH=arm64
 
# Debian 11 (bullseye)
CODENAME=bullseye
VERSION=11
 
# Debian 12 (bookworm)
CODENAME=bookworm
VERSION=12
 
# rootfs directory name
ROOTFS_DIR=rootfs-debian-$CODENAME
 
# rootfs configuration
DEF_PASSWD=12345
 
# 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"
}
 
# Debian 12 depends on the new keyring
# https://packages.debian.org/sid/all/debian-archive-keyring/download
function update_keyring()
{
    debname=debian-archive-keyring
    debversion=2023.3
 
    set +e
    dpkg -l $debname > /dev/null 2>&1
    if [ $? == 0 ] ; then
        dpkg -s debian-archive-keyring | grep Version: | grep $debversion > /dev/null 2>&1
        if [ $? != 0 ] ; then
            pr_info "updating $debname"
            apt purge -y $debname
        else
            pr_info "$debname is latest"
            return;
        fi
    fi
    set -e
 
    pr_info "install $debname now"
    wget http://ftp.us.debian.org/debian/pool/main/d/$debname/${debname}_${debversion}_all.deb > /dev/null
    dpkg -i ${debname}_${debversion}_all.deb
    rm -f ${debname}_${debversion}_all.deb
}
 
function do_install()
{
    pr_warn "\ninstall system tools"
 
    update_keyring
 
    debootstrap --version > /dev/null 2>&1
    if [ $? == 0 ] ; then
       pr_info "system tools installed already"
       return ;
    fi
 
    apt install binfmt-support qemu qemu-user-static debootstrap
}
 
function do_fetch()
{
    pr_warn "\ndebootstrap fetch"
 
    if [ -f ${ROOTFS_DIR}/bin/bash ] ; then
       pr_info "debain rootfs fetched already"
       return ;
    fi
    debootstrap --arch=${ARCH} --foreign ${CODENAME} ${ROOTFS_DIR} http://ftp.debian.org/debian/
 
    cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
    DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} debootstrap/debootstrap --second-stage
    DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} dpkg --configure -a
    rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static
}
 
function modify_rootfs()
{
    pr_warn "\nmodify rootfs environment"
 
    # update hostnmae and issue
    echo $BOARD > ${ROOTFS_DIR}/etc/hostname
    echo "Debian GNU/Linux $VERSION \n \l, default password '$DEF_PASSWD'" > ${ROOTFS_DIR}/etc/issue
 
    # update dns server
    echo "nameserver 223.5.5.5" > ${ROOTFS_DIR}/etc/resolv.conf
    echo "nameserver 114.114.114.114" >> ${ROOTFS_DIR}/etc/resolv.conf
 
    set +e
    # add ls alias for display with color
    grep "color=auto" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
    if [ $? != 0 ] ; then
       echo "alias ls='ls --color=auto'" >> ${ROOTFS_DIR}/etc/profile
    fi
 
    grep "^PermitRootLogin" ${ROOTFS_DIR}/etc/ssh/sshd_config > /dev/null 2>&1
    if [ $? != 0 ] ; then
       echo "PermitRootLogin yes" >> ${ROOTFS_DIR}/etc/ssh/sshd_config
    fi
    set -e
}
 
function do_conf()
{
    EXTRA_APPS="vim net-tools network-manager tree file parted locales lsb-release tzdata wireless-tools openssh-server"
 
    pr_warn "\ndebootstrap configure"
 
    cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
    DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt update
    DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt install -y ${EXTRA_APPS}
    DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd"
    rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static
 
    modify_rootfs
}
 
function do_pack()
{
    pr_warn "\npackage $ROOTFS_DIR"
 
    cd $PRJ_PATH/$ROOTFS_DIR
    tar -cJf ../$ROOTFS_DIR.tar.xz *
}
 
#+-------------------------+
#| Shell script body start |
#+-------------------------+
 
if [ `id -u` != 0 ] ; then
   pr_error "ERRROR: This shell script must excuted as root privilege."
   exit 0;
fi
 
do_install
 
do_fetch
 
do_conf
 
do_pack