凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2021-12-29 e46efb150efef6d9e0ce2089c50d3fdd1d069958
update build shell script for SYSTEM,DISTRO and SYSNAME
5 files modified
304 ■■■■ changed files
bsp/build.sh 17 ●●●● patch | view | raw | blame | history
bsp/images/build.sh 16 ●●●●● patch | view | raw | blame | history
bsp/rootfs/build.sh 231 ●●●● patch | view | raw | blame | history
bsp/rootfs/extra_apps.json 24 ●●●● patch | view | raw | blame | history
bsp/tarball/build.sh 16 ●●●●● patch | view | raw | blame | history
bsp/build.sh
@@ -6,12 +6,18 @@
BSP_BRANCH="lf-5.10.52-2.1.0"
CROSS_TOOL=/opt/buildroot/cortexA7/bin/arm-linux-
# $SYSTEM should be buildroot, yocto or debian
# Buildroot distro should be: buildroot-2021.02
# Yocto distro should be    : hardknott
# Debian distro should be   : buster or bullseye
# SYSTEM  should be: buildroot, yocto or debian
# DISTRO  should be: 2021.02, hardknott, buster or bullseye
# SYSNAME should be: buildroot, yocto, buster or bullseye
SYSTEM=buildroot
DISTRO=v2021.02
DISTRO=2021.02
SYSTEM=`echo $SYSTEM | tr 'A-Z' 'a-z'`
if [ $SYSTYPE == "debian" ] ; then
    SYSNAME=${DISTRO}
else
    SYSNAME=${SYSTEM}
fi
set -u
set -e
@@ -28,6 +34,7 @@
    sed -i "s|^SYSTEM=.*|SYSTEM=${SYSTEM}|g" ${DIR}/build.sh
    sed -i "s|^DISTRO=.*|DISTRO=${DISTRO}|g" ${DIR}/build.sh
    sed -i "s|^SYSNAME=.*|SYSNAME=${SYSNAME}|g" ${DIR}/build.sh
}
function do_modify()
bsp/images/build.sh
@@ -23,19 +23,13 @@
BOARD=igkboard
BSP_BRANCH=lf-5.10.52-2.1.0
# $SYSTEM should be buildroot, yocto or debian
# Buildroot distro should be: buildroot-2021.02
# Yocto distro should be    : hardknott
# Debian distro should be   : buster or bullseye
# SYSTEM  should be: buildroot, yocto or debian
# DISTRO  should be: 2021.02, hardknott, buster or bullseye
# SYSNAME should be: buildroot, yocto, buster or bullseye
SYSTEM=buildroot
DISTRO=v2021.02
DISTRO=2021.02
SYSNAME=buildroot
SYSTYPE=`echo $SYSTEM | tr 'A-Z' 'a-z'`
if [ $SYSTYPE == "debian" ] ; then
   SYSNAME=${DISTRO}
else
   SYSNAME=${SYSTYPE}
fi
ROOTFS_DIR=rootfs_${SYSNAME}
TAR_PATH=${PRJ_PATH}/../tarball
bsp/rootfs/build.sh
@@ -5,19 +5,13 @@
BOARD=igkboard
# $SYSTEM should be buildroot, yocto or debian
# Buildroot distro should be: buildroot-2021.02
# Yocto distro should be    : hardknott
# Debian distro should be   : buster or bullseye
# SYSTEM  should be: buildroot, yocto or debian
# DISTRO  should be: 2021.02, hardknott, buster or bullseye
# SYSNAME should be: buildroot, yocto, buster or bullseye
SYSTEM=buildroot
DISTRO=v2021.02
DISTRO=2021.02
SYSNAME=buildroot
SYSTYPE=`echo $SYSTEM | tr 'A-Z' 'a-z'`
if [ $SYSTYPE == "debian" ] ; then
   SYSNAME=${DISTRO}
else
   SYSNAME=${SYSTYPE}
fi
ROOTFS_DIR=rootfs_${SYSNAME}
TAR_PATH=${PRJ_PATH}/../tarball
@@ -29,8 +23,7 @@
DEF_PASSWD=12345
DEF_HOSTNAME=${BOARD}
APT_CONF=extra_apps.json
PATCH_PATH=${PRJ_PATH}/files
APPS_CONF=extra_apps.json
set -u
set -e
@@ -71,7 +64,7 @@
}
# debootstrap fetch debian rootfs
# decompress rootfs packet or debootstrap fetch debian rootfs
function do_fetch()
{
    msg_banner " ${ROOTFS_DIR} do fetch "
@@ -79,16 +72,18 @@
    # try to decompress packet first.
    do_unpack
    # Yocto and buildroot rootfs decompress only
    if [ -d ${ROOTFS_DIR} ] ; then
        return ;
    else
        if [ $SYSTYPE != "debian" ] ; then
        echo " ERROR: miss ${SYSTEM}(${DISTRO}) rootfs, exit now. "
        if [ $SYSTEM != "debian" ] ; then
            echo " ERROR: miss ${SYSTEM}(${DISTRO}) rootfs, exit now. "
            echo ""
            exit;
        fi
    fi
    # debootstrap fetch debian rootfs
    export DEBIAN_FRONTEND=noninteractive
    export DEBCONF_NONINTERACTIVE_SEEN=true
    export LC_ALL=C
@@ -96,6 +91,7 @@
    export LANG=C
    printf "\n\n -- debootstrap fetch start --\n\n"
    echo "debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} http://ftp.cn.debian.org/debian/"
    debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} http://ftp.cn.debian.org/debian/
    chroot ${ROOTFS_DIR} debootstrap/debootstrap --second-stage
@@ -105,112 +101,121 @@
    printf "\n\n -- debootstrap fetch done -- \n\n"
    # Clear the MD5 value to install extra apps
    sed -i -e "s|.*md5val.*|\t\"md5val\":\"MD5_Auto_Generate_Here\"|g" $APT_CONF
    sed -i -e "s|.*md5apt.*|\t\"md5apt\":\"MD5_Auto_Generate_Here\"|g" $APPS_CONF
}
# Install extra apps defined in extra_apps.conf
function do_apt()
function do_extra_apt()
{
    if [ ! -f $APPS_CONF ] ; then
        return ;
    fi
    extra_apps=$(eval jq -r .extra_debian_apps[] $APPS_CONF )
    md5_file=$(eval jq -r .md5apt $APPS_CONF)
    md5_calc=$(eval echo $extra_apps | md5sum | awk '{print $1}')
    if [ $md5_file == $md5_calc ] ; then
        printf "\n\n -- debootstrap apt install already, skip it! --\n\n"
        return ;
    fi
    msg_banner " debootstrap apt install "
    export DEBIAN_FRONTEND=noninteractive
    export DEBCONF_NONINTERACTIVE_SEEN=true
    export LC_ALL=C
    export LANGUAGE=C
    export LANG=C
    msg_banner " debootstrap apt install "
    if [ -f $APT_CONF ] ; then
        extra_apps=$(eval jq -r .extra_apps[] $APT_CONF )
        md5_file=$(eval jq -r .md5val extra_apps.json)
        md5_calc=$(eval echo $extra_apps | md5sum | awk '{print $1}')
    cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
    mount -o bind /proc ${ROOTFS_DIR}/proc
    mount -o bind /dev ${ROOTFS_DIR}/dev
    mount -o bind /dev/pts ${ROOTFS_DIR}/dev/pts
    mount -o bind /sys ${ROOTFS_DIR}/sys
    chroot ${ROOTFS_DIR} apt update
    chroot ${ROOTFS_DIR} apt install -y ${extra_apps}
    umount ${ROOTFS_DIR}/{sys,proc,dev/pts,dev}
        if [ $md5_file == $md5_calc ] ; then
            printf "\n\n -- debootstrap apt install already, skip it! --\n\n"
        else
            printf "\n\n -- debootstrap apt install start --\n\n"
    sed -i -e "s|.*md5apt.*|\t\"md5apt\":\"$md5_calc\"|g" $APPS_CONF
    printf "\n\n -- debootstrap apt install done --\n\n"
            cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
            mount -o bind /proc ${ROOTFS_DIR}/proc
            mount -o bind /dev ${ROOTFS_DIR}/dev
            mount -o bind /dev/pts ${ROOTFS_DIR}/dev/pts
            mount -o bind /sys ${ROOTFS_DIR}/sys
    # modify root password
    chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd"
            chroot ${ROOTFS_DIR} apt update
            chroot ${ROOTFS_DIR} apt install -y ${extra_apps}
            umount ${ROOTFS_DIR}/{sys,proc,dev/pts,dev}
            sed -i -e "s|.*md5val.*|\t\"md5val\":\"$md5_calc\"|g" $APT_CONF
            printf "\n\n -- debootstrap apt install done --\n\n"
            # modify root password
            chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd"
            # add extra user account
            set +e
            grep "$DEF_USER" ${ROOTFS_DIR}/etc/passwd > /dev/null 2>&1
            if [ $? != 0 ] ; then
                printf "\n\n -- setup default user account --\n\n"
                chroot ${ROOTFS_DIR} sh -c "useradd -m -s /bin/bash ${DEF_USER}"
                chroot ${ROOTFS_DIR} sh -c "echo ${DEF_USER}:${DEF_PASSWD} | chpasswd"
                chroot ${ROOTFS_DIR} sh -c "usermod -G video,audio,sudo avnet"
                echo "${DEF_USER}    ALL=(ALL:ALL) NOPASSWD:ALL" >> ${ROOTFS_DIR}/etc/sudoers
            fi
            set -e
        fi
    fi
}
function do_modules()
{
    msg_banner " install linux firmware"
    if [ -s ${TAR_PATH}/firmware.tar.bz2 ] ; then
        tar -xjf ${TAR_PATH}/firmware.tar.bz2 -C ${ROOTFS_DIR}/lib/
    fi
    if [ ! -d ${DRV_PATH}/lib/ ] ; then
        return ;
    fi
    if [ -d ${DRV_PATH}/lib/modules ] ; then
        msg_banner " install kernel modules"
        rm -rf ${ROOTFS_DIR}/lib/modules/
        cp -af ${DRV_PATH}/lib/modules  ${ROOTFS_DIR}/lib/
    fi
}
function do_common()
{
    if [ -s ${PATCH_PATH}/expand_rootfs ] ; then
        cp ${PATCH_PATH}/expand_rootfs ${ROOTFS_DIR}/usr/sbin/
        chmod a+x ${ROOTFS_DIR}/usr/sbin/expand_rootfs
    fi
}
function do_buildroot()
{
    if [ $SYSTYPE != "buildroot" ] ; then
        return ;
    fi
    # add vim alias for vim
    grep "alias vim=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
    # add extra user account
    set +e
    grep "$DEF_USER" ${ROOTFS_DIR}/etc/passwd > /dev/null 2>&1
    if [ $? != 0 ] ; then
       echo "alias vim='vi'" >> ${ROOTFS_DIR}/etc/profile
        printf "\n\n -- setup default user account --\n\n"
        chroot ${ROOTFS_DIR} sh -c "useradd -m -s /bin/bash ${DEF_USER}"
        chroot ${ROOTFS_DIR} sh -c "echo ${DEF_USER}:${DEF_PASSWD} | chpasswd"
        chroot ${ROOTFS_DIR} sh -c "usermod -G video,audio,sudo avnet"
        echo "${DEF_USER}    ALL=(ALL:ALL) NOPASSWD:ALL" >> ${ROOTFS_DIR}/etc/sudoers
    fi
    set -e
}
function install_file()
{
    if [ $# != 1 ] ; then
        return ;
    fi
    if [ -s ${PATCH_PATH}/S30WpaSupplicant ] ; then
        cp ${PATCH_PATH}/S30WpaSupplicant ${ROOTFS_DIR}/etc/init.d/
        chmod a+x ${ROOTFS_DIR}/etc/init.d/S30WpaSupplicant
    # parser the source file and destination install path
    src=`echo $1 | cut -d: -f1`
    dst=${ROOTFS_DIR}/`echo $1 | cut -d: -f2`
    echo "install $src => $dst"
    mkdir -p ${dst}
    # parser to get .tar.gz .tar.bz2 .tar.xz
    tar=`echo "${src#*.}"`
    case $tar in
        tar.gz)
            tar -xzf ${src} -C ${dst}
            ;;
        tar.bz2)
            tar -xjf ${src} -C ${dst}
            ;;
        tar.xz)
            tar -xJf ${src} -C ${dst}
            ;;
        *)
            rm -rf ${dst}/`basename ${src}`
            cp -rf ${src} ${dst}
            ;;
        esac
}
function do_install()
{
    # apt install extra packet for debian rootfs
    if [ $SYSTEM == "debian" ] ; then
        do_extra_apt
    fi
    if [ -s ${PATCH_PATH}/wpa_supplicant.conf ] ; then
        cp ${PATCH_PATH}/wpa_supplicant.conf ${ROOTFS_DIR}/etc/
    fi
    # install common files for all the system
    for row in $( jq -r '.extra_common_files | keys[] as $k | "\($k):\(.[$k])"' $APPS_CONF ) ; do
        install_file $row
    done
    printf "\n\n -- modify buildroot rootfs done --\n\n"
    # install extra files for custom system
    jq_args=".extra_${SYSTEM}_files | keys[] as \$k | \"\(\$k):\(.[\$k])\""
    for row in $( jq -r "${jq_args}" $APPS_CONF ) ; do
        install_file $row
    done
}
function do_modify()
@@ -218,12 +223,6 @@
    msg_banner " modify rootfs environment"
    set +e
    # modify for buildroot rootfs
    do_buildroot
    # modify for all rootfs
    do_common
    # update hostnmae and issue
    echo "Welcome to LingYun IoT Gateway Kit Board GNU/Linux ${SYSTEM}(${DISTRO}) system, default password '$DEF_PASSWD'." > ${ROOTFS_DIR}/etc/issue
@@ -251,6 +250,14 @@
    # permit root ssh login
    sed -i "s|^#PermitRootLogin.*|PermitRootLogin yes|g" ${ROOTFS_DIR}/etc/ssh/sshd_config
    sed -i "s|^#PasswordAuthentication.*|PasswordAuthentication yes|g" ${ROOTFS_DIR}/etc/ssh/sshd_config
    # add vim alias for buildroot and yocto
    if [ $SYSTEM != "debian" ] ; then
        grep "alias vim=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
        if [ $? != 0 ] ; then
            echo "alias vim='vi'" >> ${ROOTFS_DIR}/etc/profile
        fi
    fi
    set -e
@@ -288,15 +295,7 @@
function do_rootfs()
{
    do_fetch
    echo "do rootfs continue "
    # debian rootfs need apt install packet
    if [ $SYSTYPE == "debian" ]  ;then
        do_apt
    fi
    do_modules
    do_install
    do_modify
    do_pack
}
bsp/rootfs/extra_apps.json
@@ -1,9 +1,25 @@
{
    "extra_apps": {
        "basic": "wget curl vim tree file parted locales lsb-release tzdata" ,
    "extra_common_files": {
          "files/expand_rootfs": "/usr/sbin",
          "driver/lib/modules/": "/lib/"
    },
    "extra_yocto_files": {
    },
    "extra_buildroot_files": {
       "files/S30WpaSupplicant": "/etc/init.d/",
       "files/wpa_supplicant.conf": "/etc/"
    },
    "extra_debian_files": {
    },
    "extra_debian_apps": {
        "basic": "wget curl vim tree file parted locales lsb-release tzdata",
        "admin": "net-tools network-manager wireless-tools openssh-server",
        "dev": "v4l-utils"
    },
    "md5val":"d1a25515e757a566ceaa4e0db444e17d"
}
    "md5apt":"MD5_Auto_Generate_Here"
}
bsp/tarball/build.sh
@@ -8,19 +8,13 @@
BSP_BRANCH=lf-5.10.52-2.1.0
# $SYSTEM should be buildroot, yocto or debian
# Buildroot distro should be: buildroot-2021.02
# Yocto distro should be    : hardknott
# Debian distro should be   : buster or bullseye
# SYSTEM  should be: buildroot, yocto or debian
# DISTRO  should be: 2021.02, hardknott, buster or bullseye
# SYSNAME should be: buildroot, yocto, buster or bullseye
SYSTEM=buildroot
DISTRO=v2021.02
DISTRO=2021.02
SYSNAME=buildroot
SYSTYPE=`echo $SYSTEM | tr 'A-Z' 'a-z'`
if [ $SYSTYPE == "debian" ] ; then
   SYSNAME=${DISTRO}
else
   SYSNAME=${SYSTYPE}
fi
ROOTFS_DIR=rootfs_${SYSNAME}
function do_fetch_git()