liyujie
2025-08-28 d9927380ed7c8366f762049be9f3fee225860833
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
 
function build_usage()
{
    printf "Usage: build [args]
    build               - default build all
    build bootloader    - only build bootloader
    build buildroot     - only build buildroot
    build kernel        - only build kernel
    build clean         - clean all
    build distclean     - distclean all
"
    return 0
}
 
function pack_usage()
{
    printf "Usage: pack [args]
    pack                - pack firmware
    pack -d             - pack firmware with debug info output to card0
    pack -s             - pack firmware with secureboot
    pack -sd            - pack firmware with secureboot and debug info output to card0
"
    return 0
}
 
function build_help()
{
    printf "Invoke . build/envsetup.sh from your shell to add the following functions to your environment:
    croot               - Changes directory to the top of the tree.
    cbrandy             - Changes directory to the brandy
    cbr                 - Changes directory to the buildroot
    cconfigs            - Changes directory to the board's config
    cdevice             - Changes directory to the product's config
    cdts                - Changes directory to the dts.
    ckernel             - Changes directory to the kernel
    cout                - Changes directory to the board's output
"
    build_usage
    pack_usage
 
    return 0
}
 
function load_config()
{
   local cfgkey=$1
   local cfgfile=$2
   local defval=$3
   local val=""
 
   [ -f "$cfgfile" ] && val="$(sed -n "/^\s*export\s\+$cfgkey\s*=/h;\${x;p}" $cfgfile | sed -e 's/^[^=]\+=//g' -e 's/^\s\+//g' -e 's/\s\+$//g')"
   eval echo "${val:-"$defval"}"
}
 
function croot()
{
   cd $LICHEE_TOP_DIR
}
 
function ckernel()
{
   local dkey="LICHEE_KERN_DIR"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function saveconfig()
{
   local dkey1="LICHEE_KERN_DIR"
   local dkey2="LICHEE_ARCH"
   local dkey3="LICHEE_KERN_DEFCONF_ABSOLUTE"
 
   local dval1=$(load_config $dkey1 $LICHEE_TOP_DIR/.buildconfig)
   local dval2=$(load_config $dkey2 $LICHEE_TOP_DIR/.buildconfig)
   local dval3=$(load_config $dkey3 $LICHEE_TOP_DIR/.buildconfig)
 
   [ -z "$dval1" ] && echo "ERROR: $dkey1 not set in .buildconfig" && return 1
   [ -z "$dval2" ] && echo "ERROR: $dkey2 not set in .buildconfig" && return 1
   [ -z "$dval3" ] && echo "ERROR: $dkey3 not set in .buildconfig" && return 1
 
   (cd $dval1 && make ARCH=$dval2 savedefconfig && mv defconfig $dval3)
}
 
function cdts()
{
   local dkey1="LICHEE_KERN_DIR"
   local dkey2="LICHEE_ARCH"
 
   local dval1=$(load_config $dkey1 $LICHEE_TOP_DIR/.buildconfig)
   local dval2=$(load_config $dkey2 $LICHEE_TOP_DIR/.buildconfig)
 
   [ -z "$dval1" ] && echo "ERROR: $dkey1 not set in .buildconfig" && return 1
   [ -z "$dval2" ] && echo "ERROR: $dkey2 not set in .buildconfig" && return 1
 
   local dval=$dval1/arch/$dval2/boot/dts
   [ "$dval2" == "arm64" ] && dval=$dval/sunxi
   cd $dval
}
 
function cdevice()
{
   local dkey="LICHEE_PRODUCT_CONFIG_DIR"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function cconfigs()
{
   local dkey="LICHEE_BOARD_CONFIG_DIR"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function cout()
{
   local dkey="LICHEE_PLAT_OUT"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function cbrandy()
{
   local dkey="LICHEE_BRANDY_DIR"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function cbr()
{
   local dkey="LICHEE_BR_DIR"
   local dval=$(load_config $dkey $LICHEE_TOP_DIR/.buildconfig)
   [ -z "$dval" ] && echo "ERROR: $dkey not set in .buildconfig" && return 1
   cd $dval
}
 
function printconfig()
{
   cat $LICHEE_TOP_DIR/.buildconfig
}
 
function pack()
{
   local mode=$@
   if [ $# -gt 1 ]; then
       echo "too much args"
       return 1
   fi
 
   if [ "x$mode" == "x" ]; then
       ./build.sh pack
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "x-d" ]; then
       ./build.sh pack_debug
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "x-s" ]; then
       ./build.sh pack_secure
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "x-sd" ]; then
       ./build.sh pack_debug_secure
       [ $? -ne 0 ] && return 1
   else
       echo "unkwon commad."
       pack_usage
   fi
}
 
function build()
{
   local mode=$@
   if [ $# -gt 1 ]; then
       echo "too much args"
       return 1
   fi
 
   if [ "x$mode" == "x" ]; then
       ./build.sh
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xbrandy" ]; then
       ./build.sh brandy
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xkernel" ]; then
       ./build.sh kernel
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xbuildroot" ]; then
       ./build.sh buildroot
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xdistclean" ]; then
       ./build.sh distclean
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xclean" ]; then
       ./build.sh clean
       [ $? -ne 0 ] && return 1
   elif [ "x$mode" == "xhelp" ]; then
       build_help
       [ $? -ne 0 ] && return 1
   else
       echo "unkwon commad."
       build_usage
   fi
}
 
if [ ! -f build/envsetup.sh ] || [ ! -f build.sh ]; then
   echo "MUST do this in LICHEE_TOP_DIR."
else
   ./build.sh config
   export LICHEE_TOP_DIR=$(pwd)
fi