-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_rpi_os.sh
executable file
·543 lines (433 loc) · 12 KB
/
build_rpi_os.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# @author ARJUN C R (arjuncr00@acrlinux.com)
#
# web site https://www.acrlinux.com
#
#!/bin/bash
int_build_env()
{
export SCRIPT_NAME="RASPBERRY PI OS"
export SCRIPT_VERSION="1.7"
export LINUX_NAME="acr-linux"
export DISTRIBUTION_VERSION="2020.5"
export IMAGE_NAME="minimal-acrlinux-rpi-${SCRIPT_VERSION}.img"
export BUILD_OTHER_DIR="build_script_for_other"
# BASE
export KERNEL_BRANCH="4.x"
export KERNEL_VERSION=""5.6.14
export BUSYBOX_VERSION="1.30.1"
export SYSLINUX_VERSION="6.03"
export UBOOT_VERSION="2019.10"
# EXTRAS
export NCURSES_VERSION="6.1"
# CROSS COMPILE
export ARCH="arm"
export CROSS_GCC="arm-linux-gnueabihf-"
export MCPU="cortex-a7"
export BASEDIR=`realpath --no-symlinks $PWD`
export SOURCEDIR=${BASEDIR}/light-os
export ROOTFSDIR=${BASEDIR}/rootfs
export IMGDIR=${BASEDIR}/img
export RPI_BOOT=${BASEDIR}/rpi_boot
export UBOOT_DIR=${BASEDIR}/raspberry-pi-uboot
export RPI_KERNEL_DIR=${BASEDIR}/linux
export CONFIG_ETC_DIR="${BASEDIR}/os-configs/etc"
export RPI_BASE_BIN=${BASEDIR}/rpi_base_bin
export WORKSPACE="${BASEDIR}/workspace"
#export CFLAGS=-m64
#export CXXFLAGS=-m64
#setting JFLAG
if [ -z "$2" ]
then
export JFLAG=4
else
export JFLAG=$2
fi
export CROSS_COMPILE=$BASEDIR/cross-gcc-arm/gcc-arm-8.2-x86_64-arm-linux-gnueabihf/bin/$CROSS_GCC
#configs
export RPI_OS_KCONFIG="$BASEDIR/configs/kernel/rpi_os_kconfig"
export RPI_OS_BUSYBOX_CONFIG="$BASEDIR/configs/busybox/rpi_os_busybox_config"
export RPI_OS_UBOOT_CONFIG="$BASEDIR/configs/uboot/rpi_os_uboot_config"
}
prepare_dirs () {
cd ${BASEDIR}
if [ ! -d ${SOURCEDIR} ];
then
mkdir ${SOURCEDIR}
fi
if [ ! -d ${ROOTFSDIR} ];
then
mkdir ${ROOTFSDIR}
fi
if [ ! -d ${IMGDIR} ];
then
mkdir ${IMGDIR}
mkdir -p ${IMGDIR}/bootloader
mkdir -p ${IMGDIR}/boot
mkdir -p ${IMGDIR}/boot/overlays
mkdir -p ${IMGDIR}/kernel
fi
if [ ! -d ${WORKSPACE} ];
then
mkdir ${WORKSPACE}
fi
}
build_kernel () {
cd ${SOURCEDIR}
if [ ! -d ${WORKSPACE}/linux-${KERNEL_VERSION} ];
then
echo "copying kernel src to workspace"
cp -r linux-${KERNEL_VERSION} ${WORKSPACE}
echo "copying kernel patch to workspace"
cp -r kernel-patch ${WORKSPACE}
cd ${WORKSPACE}/linux-${KERNEL_VERSION}
for patch in $(ls ../kernel-patch | grep '^[000-999]*_.*.patch'); do
echo "applying patch .... '$patch'."
patch -p1 < ../kernel-patch/${patch}
done
fi
cd ${WORKSPACE}/linux-${KERNEL_VERSION}
if [ "$1" == "-c" ]
then
make clean -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE
elif [ "$1" == "-b" ]
then
cp $RPI_OS_KCONFIG .config
make oldconfig -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE zImage modules dtbs
make modules_install
cp arch/arm/boot/dts/*.dtb $IMGDIR/boot/
cp arch/arm/boot/dts/overlays/*.dtb* $IMGDIR/boot/overlays/
cp arch/arm/boot/dts/overlays/README $IMGDIR/boot/overlays/
cp arch/arm/boot/zImage $IMGDIR/kernel/rpi-kernel.img
fi
}
build_busybox () {
cd ${SOURCEDIR}
if [ ! -d ${WORKSPACE}/busybox-${BUSYBOX_VERSION} ];
then
cp -r busybox-${BUSYBOX_VERSION} ${WORKSPACE}
echo "copying busybox patch to workspace"
cp -r busybox-patch ${WORKSPACE}
cd ${WORKSPACE}/busybox-${BUSYBOX_VERSION}
for patch in $(ls ../busybox-patch | grep '^[000-999]*_.*.patch'); do
echo "applying patch .... '$patch'."
patch -p1 < ../busybox-patch/${patch}
done
fi
cd busybox-${BUSYBOX_VERSION}
if [ "$1" == "-c" ]
then
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE clean
elif [ "$1" == "-b" ]
then
cp $RPI_OS_BUSYBOX_CONFIG .config
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig
sed -i 's|.*CONFIG_STATIC.*|CONFIG_STATIC=y|' .config
make ARCH=$arm CROSS_COMPILE=$CROSS_COMPIL busybox \
-j ${JFLAG}
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE install \
-j ${JFLAG}
rm -rf ${ROOTFSDIR} && mkdir ${ROOTFSDIR}
cd _install
cp -R . ${ROOTFSDIR}
rm ${ROOTFSDIR}/linuxrc
fi
}
build_uboot () {
cd $UBOOT_DIR
if [ -f u-boot-2019.10.tar.bz2 ]
then
tar -xf u-boot-2019.10.tar.bz2
rm u-boot-2019.10.tar.bz2
fi
if [ ! -d ${WORKSPACE}/u-boot-${UBOOT_VERSION} ];
then
echo "copying uboot to workspace"
cp -r u-boot-${UBOOT_VERSION} ${WORKSPACE}
echo "copying uboot patch to workspace"
cp -r uboot-patch ${WORKSPACE}
cd u-boot-${UBOOT_VERSION}
for patch in $(ls ../uboot-patch | grep '^[000-999]*_.*.patch'); do
echo "applying patch .... '$patch'."
patch -p1 < ../uboot-patch/${patch}
done
fi
cd u-boot-${UBOOT_VERSION}
if [ "$1" == "-c" ]
then
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE distclean
elif [ "$1" == "-b" ]
then
cp $RPI_OS_UBOOT_CONFIG .config
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE u-boot.bin
cp u-boot.bin $IMGDIR/bootloader
else
echo "Command Not Supported"
fi
}
build_extras () {
#build_ncurses
cd ${BASEDIR}/${BUILD_OTHER_DIR}
if [ "$1" == "-c" ]
then
./build_other_main.sh --clean
elif [ "$1" == "-b" ]
then
./build_other_main.sh --build
fi
}
generate_rootfs () {
cd ${ROOTFSDIR}
rm -f linuxrc
mkdir dev
mkdir etc
mkdir proc
mkdir src
mkdir sys
mkdir var
mkdir var/log
mkdir srv
mkdir lib
mkdir root
mkdir boot
mkdir tmp && chmod 1777 tmp
mkdir -pv usr/{,local/}{bin,include,lib{,64},sbin,src}
mkdir -pv usr/{,local/}share/{doc,info,locale,man}
mkdir -pv usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
mkdir -pv etc/rc{0,1,2,3,4,5,6,S}.d
mkdir -pv etc/init.d
cd etc
cp $CONFIG_ETC_DIR/motd .
cp $CONFIG_ETC_DIR/hosts .
cp $CONFIG_ETC_DIR/resolv.conf .
cp $CONFIG_ETC_DIR/fstab .
rm -r init.d/*
install -m ${CONFMODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/init.d/functions init.d/functions
install -m ${CONFMODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/init.d/network init.d/network
install -m ${MODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/startup rcS.d/S01startup
install -m ${MODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/shutdown init.d/shutdown
chmod +x init.d/*
ln -s init.d/network rc0.d/K01network
ln -s init.d/network rc1.d/K01network
ln -s init.d/network rc2.d/S01network
ln -s init.d/network rc3.d/S01network
ln -s init.d/network rc4.d/S01network
ln -s init.d/network rc5.d/S01network
ln -s init.d/network rc6.d/K01network
ln -s init.d/network rcS.d/S01network
cp $CONFIG_ETC_DIR/inittab .
cp $CONFIG_ETC_DIR/group .
cp $CONFIG_ETC_DIR/passwd .
cd ${ROOTFSDIR}
cp $CONFIG_ETC_DIR/init .
chmod +x init
#creating initial device node
mknod -m 622 dev/console c 5 1
mknod -m 666 dev/null c 1 3
mknod -m 666 dev/zero c 1 5
mknod -m 666 dev/ptmx c 5 2
mknod -m 666 dev/tty c 5 0
mknod -m 666 dev/tty1 c 4 1
mknod -m 666 dev/tty2 c 4 2
mknod -m 666 dev/tty3 c 4 3
mknod -m 666 dev/tty4 c 4 4
mknod -m 444 dev/random c 1 8
mknod -m 444 dev/urandom c 1 9
mknod -m 666 dev/ram b 1 1
mknod -m 666 dev/mem c 1 1
mknod -m 666 dev/kmem c 1 2
chown root:tty dev/{console,ptmx,tty,tty1,tty2,tty3,tty4}
# sudo chown -R root:root .
find . | cpio -R root:root -H newc -o | gzip > ${IMGDIR}/rootfs.gz
}
generate_image () {
dd of=${IMAGE_NAME} seek=2200M bs=1 count=0
mkdir /mnt/rpi-boot
mkdir /mnt/rpi-rootfs
parted ${IMAGE_NAME} mktable msdos
parted ${IMAGE_NAME} mkpart primary fat32 8192s 260MB
parted ${IMAGE_NAME} mkpart primary ext4 260MB 100%
dd if=/dev/zero of=${IMAGE_NAME} bs=1 count=440 conv=notrunc
losetup /dev/loop100 ${IMAGE_NAME} --offset $((8192*512)) --sizelimit $((499712*512))
losetup /dev/loop101 ${IMAGE_NAME} --offset $((507904*512)) --sizelimit $((3997696*512))
mkfs.vfat -F 32 -n BOOT /dev/loop100
mkfs.ext4 -L rootfs /dev/loop101
mount /dev/loop100 /mnt/rpi-boot
mount /dev/loop101 /mnt/rpi-rootfs
cp -r ${RPI_BASE_BIN}/* /mnt/rpi-boot
cp ${IMGDIR}/bootloader/u-boot.bin /mnt/rpi-boot/
echo "kernel=u-boot.bin" >> /mnt/rpi-boot/config.txt
sed -i 's/root=PARTUUID=[a-z0-9]*-02/root=\/dev\/mmcblk0p2/' /mnt/rpi-boot/cmdline.txt
#sed -i 's/^PARTUUID=[a-z0-9]*-01/\/dev\/mmcblk0p1/' /mnt/rpi-rootfs/etc/fstab
#sed -i 's/^PARTUUID=[a-z0-9]*-02/\/dev\/mmcblk0p2/' /mnt/rpi-rootfs/etc/fstab
losetup -d /dev/loop100
losetup -d /dev/loop101
umount /dev/loop100
umount /dev/loop101
rm -r /mnt/rpi-boot
rm -r /mnt/rpi-rootfs
}
test_qemu () {
cd ${BASEDIR}
if [ -f ${IMAGE_NAME} ];
then
qemu-system-arm -kernel kernel_qemu/kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda ${IMAGE_NAME}
fi
exit 1
}
clean_files () {
rm -rf ${SOURCEDIR}
rm -rf ${ROOTFSDIR}
rm -rf ${ISODIR}
rm -rf ${RPI_BOOT}
rm -rf ${IMGDIR}
rm -rf ${UBOOT_DIR}
rm -rf ${RPI_KERNEL_DIR}
rm -rf ${WORKSPACE}
}
init_work_dir()
{
prepare_dirs
}
clean_work_dir()
{
clean_files
}
build_all()
{
build_kernel -b
build_busybox -b
build_uboot -b
build_extras -b
}
rebuild_all()
{
clean_all
build_all
}
clean_all()
{
build_kernel -c
build_busybox -c
build_uboot -c
build_extras -c
}
wipe_rebuild()
{
clean_work_dir
init_work_dir
rebuild_all
}
help_msg()
{
echo -e "#################################################################################\n"
echo -e "########################$SCRIPT_VERSION Utility to Build RPI OS##############################\n"
echo -e "#################################################################################\n"
echo -e "Help message --help\n"
echo -e "Build All: --build-all\n"
echo -e "Rebuild All: --rebuild-all\n"
echo -e "Clean All: --clean-all\n"
echo -e "Wipe and rebuild --wipe-rebuild\n"
echo -e "Building kernel: --build-kernel --rebuild-kernel --clean-kernel\n"
echo -e "Building busybx: --build-busybox --rebuild-busybox --clean-busybox\n"
echo -e "Building uboot: --build-uboot --rebuild-uboot --clean-uboot\n"
echo -e "Building other soft: --build-other --rebuild-other --clean-other\n"
echo -e "Creating root-fs: --create-rootfs\n"
echo -e "Create ISO Image: --create-img\n"
echo -e "Cleaning work dir: --clean-work-dir\n"
echo -e "Test with Qemu --Run-qemu\n"
echo "###################################################################################"
}
option()
{
if [ -z "$1" ]
then
help_msg
exit 1
fi
if [ "$1" == "--build-all" ]
then
build_all
fi
if [ "$1" == "--rebuild-all" ]
then
rebuild_all
fi
if [ "$1" == "--clean-all" ]
then
clean_all
fi
if [ "$1" == "--wipe-rebuild" ]
then
wipe_rebuild
fi
if [ "$1" == "--build-kernel" ]
then
build_kernel -b
elif [ "$1" == "--rebuild-kernel" ]
then
build_kernel -c
build_kernel -b
elif [ "$1" == "--clean-kernel" ]
then
build_kernel -c
fi
if [ "$1" == "--build-busybox" ]
then
build_busybox -b
elif [ "$1" == "--rebuild-busybox" ]
then
build_busybox -c
build_busybox -b
elif [ "$1" == "--clean-busybox" ]
then
build_busybox -c
fi
if [ "$1" == "--build-uboot" ]
then
build_uboot -b
elif [ "$1" == "--rebuild-uboot" ]
then
build_uboot -c
build_uboot -b
elif [ "$1" == "--clean-uboot" ]
then
build_uboot -c
fi
if [ "$1" == "--build-other" ]
then
build_extras -b
elif [ "$1" == "--rebuild-other" ]
then
build_extras -c
build_extras -b
elif [ "$1" == "--clean-other" ]
then
build_extras -c
fi
if [ "$1" == "--create-rootfs" ]
then
generate_rootfs
fi
if [ "$1" == "--create-img" ]
then
generate_image
fi
if [ "$1" == "--clean-work-dir" ]
then
clean_work_dir
fi
if [ "$1" == "--Run-qemu" ]
then
test_qemu
fi
}
main()
{
int_build_env
init_work_dir
option $1
}
#starting of script
main $1