-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_image.sh
executable file
·263 lines (213 loc) · 6.5 KB
/
build_image.sh
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/sh
#rk1-image root dir
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
BUILD_PATH=$DIR/build
ARMBIAN_PATH=$BUILD_PATH/armbian-build
ARMBIAN_IMAGE_PATH=$ARMBIAN_PATH/output/images
########################################################
Main() {
# read all variable from config file
source $DIR/config
if [ -d $BUILD_PATH ]; then
rm -rf "$BUILD_PATH"
fi
mkdir -p $BUILD_PATH
#download armbian src
ArmbianSrcInit;
#compile armbian
if [ -z "${1}" ]
then
echo "error No Image selected"
exit 1;
fi
if [ $1 = "server" ]
then
echo "Compile Server Image"
ArmbianCompileServer;
elif [ $1 = "desktop" ]
then
echo "Compile Desktop Image"
ArmbianCompileDesktop;
else
echo "error wrong Image selected"
fi
CreateUsbFlashUpdate;
} # Main
########################################################
ArmbianSrcInit()
{
echo "install armbian required package"
# if docker dosn't exist install it
if ! command -v docker &> /dev/null
then
echo "installing docker"
curl -fsSL https://get.docker.com -o $BUILD_PATH/get-docker.sh
sudo sh $BUILD_PATH/get-docker.sh
fi
sudo apt-get -y -qq install git
#get armbian-biuld
if [ -d $ARMBIAN_PATH ]; then
rm -rf "$ARMBIAN_PATH"
fi
echo "clone armbian-build branch $ARMBIAN_REPO_BRANCH"
git clone --depth=1 --branch=$ARMBIAN_BRANCH https://github.com/armbian/build $ARMBIAN_PATH
#get armbian userpatches
rm -rf $ARMBIAN_PATH/userpatches/
cp -r $DIR/userpatches/ $ARMBIAN_PATH/userpatches/
# if [ -d $ARMBIAN_PATH/userpatches ]; then
# echo "update armbian userpatches repo"
# git -C $ARMBIAN_PATH/userpatches pull
# else
# echo "clone armbian userpatches repo"
# git clone --depth=1 https://github.com/mahdichi/armbian_userpatches $ARMBIAN_PATH/userpatches/
# fi
#copy config to overlay for access in chroot
cp $DIR/config $ARMBIAN_PATH/userpatches/overlay/
} # ArmbianSrcInit
########################################################
ArmbianCompileServer()
{
#https://docs.armbian.com/Developer-Guide_Build-Options/
$ARMBIAN_PATH/compile.sh \
BOARD=fxblox-rk1 \
BRANCH=vendor \
RELEASE=jammy \
EXTRAWIFI=yes \
BUILD_DESKTOP=no \
BUILD_MINIMAL=yes \
KERNEL_CONFIGURE=no \
KERNEL_GIT=shallow \
CONSOLE_AUTOLOGIN=yes \
EXPERT="yes" \
CLEAN_LEVEL=oldcache \
NETWORKING_STACK=network-manager \
PACKAGE_LIST_BOARD="\
cmake libi2c-dev \
gdb git gcc net-tools rfkill bluetooth bluez bluez-tools blueman \
logrotate python3-pip mergerfs inotify-tools python3-dbus dnsmasq-base \
python3-dev python-is-python3 python3-pip python3-gi python3-gi-cairo gir1.2-gtk-3.0 dnsmasq-base lshw \
debhelper build-essential ntfs-3g fakeroot lockfile-progs \
libip6tc2 libnftnl11 iptables \
" \
#usbmount: ebhelper build-essential ntfs-3g fakeroot lockfile-progs
#docker: libip6tc2 libnftnl11 iptables
#fula: logrotate
} # ArmbianCompileServer
########################################################
ArmbianCompileDesktop()
{
$ARMBIAN_PATH/compile.sh \
BOARD=fxblox-rk1 \
BRANCH=vendor \
BUILD_DESKTOP=yes \
BUILD_MINIMAL=no \
DESKTOP_APPGROUPS_SELECTED='3dsupport browsers chat desktop_tools editors email internet multimedia office remote_desktop' \
DESKTOP_ENVIRONMENT=gnome \
DESKTOP_ENVIRONMENT_CONFIG_NAME=config_base \
KERNEL_CONFIGURE=no \
RELEASE=jammy \
KERNEL_GIT=shallow \
EXPERT="yes" \
CLEAN_LEVEL=oldcache \
\
PACKAGE_LIST_BOARD="\
cmake libi2c-dev \
gdb git gcc net-tools rfkill bluetooth bluez bluez-tools blueman \
logrotate python3-pip mergerfs inotify-tools python3-dbus dnsmasq-base \
python3-dev python-is-python3 python3-pip python3-gi python3-gi-cairo gir1.2-gtk-3.0 dnsmasq-base lshw \
debhelper build-essential ntfs-3g fakeroot lockfile-progs \
libip6tc2 libnftnl11 iptables \
" \
#usbmount: ebhelper build-essential ntfs-3g fakeroot lockfile-progs
#docker: libip6tc2 libnftnl11 iptables
#fula: logrotate
} # ArmbianCompileDesktop
########################################################
CreateUsbFlashUpdate()
{
echo "Create USB Flash Update files"
echo "Split update file to 1GB parts"
split -d -a 1 -b 1G $ARMBIAN_IMAGE_PATH/*.img $BUILD_PATH/update.img. --verbose
echo "create boot script"
fileCnt=$(ls -l $BUILD_PATH/update.img.* | wc -l)
touch $BUILD_PATH/boot.cmd
cat > $BUILD_PATH/boot.cmd <<- EOF
echo "******************************************"
echo "usb update starting"
echo "******************************************"
setenv load_addr "0x9000000"
setenv load_size "0x40000000"
setenv load_addr_part_0 "0x0000000"
setenv load_addr_part_1 "0x0200000"
setenv load_addr_part_2 "0x0400000"
setenv load_addr_part_3 "0x0600000"
setenv load_addr_part_4 "0x0800000"
setenv load_addr_part_5 "0x0A00000"
setenv load_addr_part_6 "0x0C00000"
setenv load_addr_part_7 "0x0E00000"
setenv load_addr_part_8 "0x1000000"
setenv load_addr_part_9 "0x1200000"
EOF
cat >> $BUILD_PATH/boot.cmd <<- EOF
mmc rescan
mmc list
mmc dev 0
usb reset
usb dev 0
mmc list
mmc dev
if test -e usb 0:1 update.img.0 ; then
echo "******************************************"
echo "usb: there is update file"
#turn on red led
gpio clear gpio211
#turn off blue led
gpio set gpio212
EOF
#for (( i=0; i<$fileCnt; i++ ))
#do
i=0
while [ "$i" -lt $fileCnt ]; do
cat >> $BUILD_PATH/boot.cmd <<- EOF
size usb 0:1 update.img.$i
echo "usb: part $i image size: \${filesize} bytes"
echo "usb: wait for copy part $i image to DDR"
fatload usb 0:1 \${load_addr} update.img.$i
echo "usb: part $i copy complete"
setexpr file_size_blk \${filesize} / 0x200
echo "emmc: part $i image block size: \${file_size_blk}"
echo "emmc: wait for copy part $i image to eMMC"
mmc write \${load_addr} \${load_addr_part_$i} \${file_size_blk}
echo "emmc: part $i copy completed"
EOF
i=$(( i + 1 ))
done
cat >> $BUILD_PATH/boot.cmd <<- EOF
rkimgtest mmc 0
echo " "
echo "please remove USB"
echo ""
echo "******************************************"
#turn off red led
gpio set gpio211
#turn on blue led
gpio clear gpio212
while true ; do ;
gpio set gpio212 &&
usb reset &&
gpio clear gpio212 &&
usb reset &&
; done;
fi
EOF
# boot script
sudo apt-get -qq install u-boot-tools
mkimage -C none -A arm -T script -d $BUILD_PATH/boot.cmd $BUILD_PATH/boot.scr
# zip output
echo "zip all update file to $BUILD_PATH/update.zip"
cd $BUILD_PATH
sudo rm -f update.zip
zip -s 1900m -r update.zip update.img.* boot.scr
} #CreateUsbFlashUpdate
########################################################
Main "$@"