凌云实验室IGKBoard开发板BSP开发相关文件
guowenxue
2023-07-27 360dc73380a7960d781e98205284b33d5881aed1
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
#!/bin/bash
# Description: This shell script used to generate patch file
#      Author: guowenxue <guowenxue@gmail.com>
#     Version: 1.0.0
 
# this project absolute path
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
 
# top project absolute path
TOP_PATH=$(realpath $PRJ_PATH/..)
 
# download taballs path
TARBALL_PATH=$PRJ_PATH/tarballs
 
# config file path
CONF_FILE=$TOP_PATH/config.json
 
# patch file path
PATCH_PATH=${PRJ_PATH}/patches
 
# 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"
}
 
# parser configure file and export environment variable
function export_env()
{
    export SRC=$(basename $1)
    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 CROSS_COMPILE=`jq -r ".bsp.crosstool" $CONF_FILE | tr 'A-Z' 'a-z'`
    export JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
    export PATCH=$SRC-$BSP_VER
 
    if [[ $BOARD =~ 6ull ]] ; then
 
        export ARCH=arm
 
    elif [[ $BOARD =~ 8mp ]] ; then
 
        export ARCH=arm64
 
    fi
}
 
function do_prepare()
{
    cd $PRJ_PATH
 
    if [ ! -d $SRC ] ;  then
        pr_error "\nERROR: source code $SRC not exist, exit now\n\n"
        exit;
    fi
 
    pr_info "cleanup $SRC soruce code packet"
    cd $SRC
    make ARCH=$ARCH distclean -j $JOBS
    cd -
 
    mv $SRC $PATCH
 
    pr_info "decompress orignal soruce code packet"
    tar -xJf $TARBALL_PATH/$SRC.tar.xz
}
 
function do_patch()
{
    pr_info "generate patch file"
 
    if [[ $SRC =~ linux ]] ; then
        diff -Nuar --no-dereference $SRC $PATCH > $PATCH.patch
    elif [[ $SRC =~ uboot ]] ; then
        diff -Nuar -x "tools" $SRC $PATCH > $PATCH.patch
    fi
 
    pr_info "recovery $SRC soruce code"
    rm -rf ${SRC}
    mv $PATCH ${SRC}
}
 
if [ $# != 1 ] ; then
    pr_info "$0 usage example:"
    pr_info "$0 uboot-imx/"
    pr_info "$0 linux-imx/"
    exit
fi
 
export_env $1
do_prepare
do_patch