-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_packages.sh
172 lines (139 loc) · 9.37 KB
/
build_packages.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
#!/bin/bash
if [ -z $CWD ]; then
exit
fi
build_kernel_pkg() {
cd $SOURCE
# get kernel version
KERNEL_VERSION=$(get_version $SOURCE/$KERNEL_DIR)
KERNEL=zImage
[[ $KARCH == arm64 || $KARCH == riscv ]] && KERNEL=Image
message "" "copy" "linux-firmware"
# create linux firmware
[[ ! -d "$BUILD/$PKG/kernel-modules/lib/firmware" ]] && mkdir -p $BUILD/$PKG/kernel-modules/lib/firmware
rsync -a --exclude .git $SOURCE/$KERNEL_FIRMWARE_DIR/ $BUILD/$PKG/kernel-modules/lib/firmware/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# adding custom firmware
if [[ $FIRMWARE == "yes" ]];then
cp -vaf $CWD/blobs/firmware/overall/* $BUILD/$PKG/kernel-modules/lib/firmware/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ -d $CWD/blobs/firmware/${BOARD_NAME} ]] && ( cp -vaf $CWD/blobs/firmware/${BOARD_NAME}/* $BUILD/$PKG/kernel-modules/lib/firmware/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1 )
[[ -d $CWD/blobs/firmware/${BOARD_NAME}-${KERNEL_SOURCE} ]] && ( cp -vaf $CWD/blobs/firmware/${BOARD_NAME}-${KERNEL_SOURCE}/* $BUILD/$PKG/kernel-modules/lib/firmware/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1 )
fi
message "" "copy" "kernel"
# install kernel
install -Dm644 $SOURCE/$KERNEL_DIR/arch/${KARCH}/boot/$KERNEL $BUILD/$PKG/kernel-${SOCFAMILY}/boot/vmlinuz-${KERNEL_VERSION}
install -Dm644 $SOURCE/$KERNEL_DIR/System.map $BUILD/$PKG/kernel-${SOCFAMILY}/boot/System.map-${KERNEL_VERSION}
install -Dm644 $SOURCE/$KERNEL_DIR/.config $BUILD/$PKG/kernel-${SOCFAMILY}/boot/config-${KERNEL_VERSION}
if [[ $SOCFAMILY != bcm2* && $BOARD_NAME != x96_max_plus ]]; then
# Make symlinks:
ln -sf System.map-${KERNEL_VERSION} $BUILD/$PKG/kernel-${SOCFAMILY}/boot/System.map
ln -sf config-${KERNEL_VERSION} $BUILD/$PKG/kernel-${SOCFAMILY}/boot/config
ln -sf vmlinuz-${KERNEL_VERSION} $BUILD/$PKG/kernel-${SOCFAMILY}/boot/vmlinuz
ln -sf vmlinuz-${KERNEL_VERSION} $BUILD/$PKG/kernel-${SOCFAMILY}/boot/$KERNEL
else
install -Dm644 $SOURCE/$KERNEL_DIR/arch/${KARCH}/boot/$KERNEL $BUILD/$PKG/kernel-${SOCFAMILY}/boot/$KERNEL
install -Dm644 $SOURCE/$KERNEL_DIR/System.map $BUILD/$PKG/kernel-${SOCFAMILY}/boot/System.map
install -Dm644 $SOURCE/$KERNEL_DIR/.config $BUILD/$PKG/kernel-${SOCFAMILY}/boot/config
fi
message "" "setup" "device tree blobs"
# setup device tree blobs
[[ $SOCFAMILY != bcm2* && $BOARD_NAME != x96_max_plus ]] && ( ln -sf $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtbs/${KERNEL_VERSION} -r $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtb >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1 )
if [[ $SOCFAMILY == bcm2* ]]; then
install -dm755 $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtb
cp -av $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtbs/${KERNEL_VERSION}/broadcom/* \
$BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtb/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
cp -av $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtbs/${KERNEL_VERSION}/broadcom/* \
$BUILD/$PKG/kernel-${SOCFAMILY}/boot/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
cp -av $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtbs/${KERNEL_VERSION}/overlays \
$BUILD/$PKG/kernel-${SOCFAMILY}/boot/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
# amlogic tv box
if [[ $BOARD_NAME == x96_max_plus ]]; then
install -dm755 "$BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtb"
cp -av $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtbs/${KERNEL_VERSION}/* $BUILD/$PKG/kernel-${SOCFAMILY}/boot/dtb/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
cd "$CWD" # fix actual current directory
# clean-up unnecessary files generated during install
find "$BUILD/$PKG/kernel-modules" "$BUILD/$PKG/kernel-headers" \( -name .install -o -name ..install.cmd \) -delete >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "preparation" "of firmware"
# split install_modules -> firmware
install -dm755 "$BUILD/$PKG/kernel-firmware/lib"
if [ -d $BUILD/$PKG/kernel-modules/lib/firmware ];then
cp -af "$BUILD/$PKG/kernel-modules/lib/firmware" "$BUILD/$PKG/kernel-firmware/lib"
rm -rf "$BUILD/$PKG/kernel-modules/lib/firmware"
fi
cd $BUILD/$PKG/kernel-modules/
if [[ ! -z $MODULES ]]; then
install -dm755 "$BUILD/$PKG/kernel-modules/etc/rc.d/"
echo -e "#!/bin/sh\n" > $BUILD/$PKG/kernel-modules/etc/rc.d/rc.modules.local
for mod in $MODULES;do
echo "/sbin/modprobe $mod" >> $BUILD/$PKG/kernel-modules/etc/rc.d/rc.modules.local
done
chmod 755 $BUILD/$PKG/kernel-modules/etc/rc.d/rc.modules.local
fi
cd $BUILD/$PKG/kernel-modules/lib/modules/${KERNEL_VERSION}*
rm build source
ln -s /usr/src/linux-${KERNEL_VERSION} build
ln -s /usr/src/linux-${KERNEL_VERSION} source
# build kernel-source
[[ ! -d "$BUILD/$PKG/kernel-source" ]] && mkdir -p $BUILD/$PKG/kernel-source/usr/src/linux-${KERNEL_VERSION}
rsync -a --exclude .git --delete $SOURCE/$KERNEL_DIR/ $BUILD/$PKG/kernel-source/usr/src/linux-${KERNEL_VERSION}/
cd $BUILD/$PKG/kernel-source/usr/src/linux-${KERNEL_VERSION}/
make ARCH=$KARCH CROSS_COMPILE=$CROSS clean >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# Make sure header files aren't missing...
make ARCH=$KARCH CROSS_COMPILE=$CROSS prepare >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# Don't package the kernel in the sources:
find . -name "*Image" -exec rm "{}" \+
# No need for these:
rm -f .config.old .version
find . -name "*.cmd" -exec rm -f "{}" \+
rm .*.d
cd ..
ln -sf linux-${KERNEL_VERSION} linux
if [[ $DISTR == sla* ]]; then
message "" "create" "package of kernel"
# create kernel package
cd $BUILD/$PKG/kernel-${SOCFAMILY}/ && mkdir "install"
cat "$CWD/packages/kernel/slack-desc.kernel-template" | sed "s:%SOCFAMILY%:${SOCFAMILY}:g" > "$BUILD/$PKG/kernel-${SOCFAMILY}/install/slack-desc"
makepkg -l n -c n $BUILD/$PKG/kernel-${SOCFAMILY}-${KERNEL_VERSION/-/_}-${ARCH}-${PKG_BUILD}${PACKAGER}.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "create" "package kernel-modules"
# create kernel-modules package
cd $BUILD/$PKG/kernel-modules/ && mkdir "install"
cat "$CWD/packages/kernel/slack-desc.kernel-modules" | sed "s:%SOCFAMILY%:${SOCFAMILY}:g" > "$BUILD/$PKG/kernel-modules/install/slack-desc"
makepkg -l n -c n $BUILD/$PKG/kernel-modules-${SOCFAMILY}-${KERNEL_VERSION/-/_}-${ARCH}-${PKG_BUILD}${PACKAGER}.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "create" "package kernel-headers"
# create kernel-headers package
cd $BUILD/$PKG/kernel-headers/ && mkdir "install"
cat "$CWD/packages/kernel/slack-desc.kernel-headers" | sed "s:%SOCFAMILY%:${SOCFAMILY}:g" > "$BUILD/$PKG/kernel-headers/install/slack-desc"
makepkg -l n -c n $BUILD/$PKG/kernel-headers-${SOCFAMILY}-${KERNEL_VERSION/-/_}-${ARCH}-${PKG_BUILD}${PACKAGER}.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "create" "package kernel-firmware"
# create kernel-firmware package
cd $BUILD/$PKG/kernel-firmware/ && mkdir "install"
cat "$CWD/packages/kernel/slack-desc.kernel-firmware" | sed "s:%SOCFAMILY%:${SOCFAMILY}:g" > "$BUILD/$PKG/kernel-firmware/install/slack-desc"
makepkg -l n -c n $BUILD/$PKG/kernel-firmware-${SOCFAMILY}-${KERNEL_VERSION/-/_}-${ARCH}-${PKG_BUILD}${PACKAGER}.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "create" "package kernel-source"
# create kernel-source package
cd $BUILD/$PKG/kernel-source/ && mkdir "install"
cat "$CWD/packages/kernel/slack-desc.kernel-source" | sed "s:%SOCFAMILY%:${SOCFAMILY}:g" > "$BUILD/$PKG/kernel-source/install/slack-desc"
makepkg -l n -c n $BUILD/$PKG/kernel-source-${SOCFAMILY}-${KERNEL_VERSION/-/_}-noarch-${PKG_BUILD}${PACKAGER}.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
cd $BUILD/$PKG
# clear kernel packages directories
[[ -d "$BUILD/$PKG/kernel-${SOCFAMILY}" ]] && \
rm -rf "$BUILD/$PKG/kernel-${SOCFAMILY}" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ -d "$BUILD/$PKG/kernel-modules" ]] && \
rm -rf "$BUILD/$PKG/kernel-modules" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ -d "$BUILD/$PKG/kernel-headers" ]] && \
rm -rf "$BUILD/$PKG/kernel-headers" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ -d "$BUILD/$PKG/kernel-firmware" ]] && \
rm -rf "$BUILD/$PKG/kernel-firmware" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ -d "$BUILD/$PKG/kernel-source" ]] && \
rm -rf "$BUILD/$PKG/kernel-source" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
#---------------------------------------------
# creation of the archive with the bootloader
#---------------------------------------------
create_archive_bootloader() {
message "" "create" "archive bootloader"
cd $BUILD/$OUTPUT/$TOOLS/$BOARD_NAME/ || exit 1
tar cJf $BUILD/$OUTPUT/$IMAGES/boot-${ROOTFS_VERSION}.tar.xz boot || exit 1
}