@@ -1,172 +1,183 | |||||
1 | # |
|
1 | # | |
2 | # Build and Setup RPi2/3 Kernel |
|
2 | # Build and Setup RPi2/3 Kernel | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | # Load utility functions |
|
5 | # Load utility functions | |
6 | . ./functions.sh |
|
6 | . ./functions.sh | |
7 |
|
7 | |||
8 | # Fetch and build latest raspberry kernel |
|
8 | # Fetch and build latest raspberry kernel | |
9 | if [ "$BUILD_KERNEL" = true ] ; then |
|
9 | if [ "$BUILD_KERNEL" = true ] ; then | |
10 | # Setup source directory |
|
10 | # Setup source directory | |
11 | mkdir -p "${R}/usr/src" |
|
11 | mkdir -p "${R}/usr/src" | |
12 |
|
12 | |||
13 | # Copy existing kernel sources into chroot directory |
|
13 | # Copy existing kernel sources into chroot directory | |
14 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then |
|
14 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then | |
15 | # Copy kernel sources |
|
15 | # Copy kernel sources | |
16 | cp -r "${KERNELSRC_DIR}" "${R}/usr/src" |
|
16 | cp -r "${KERNELSRC_DIR}" "${R}/usr/src" | |
17 |
|
17 | |||
18 | # Clean the kernel sources |
|
18 | # Clean the kernel sources | |
19 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
19 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then | |
20 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper |
|
20 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper | |
21 | fi |
|
21 | fi | |
22 | else # KERNELSRC_DIR="" |
|
22 | else # KERNELSRC_DIR="" | |
23 | # Create temporary directory for kernel sources |
|
23 | # Create temporary directory for kernel sources | |
24 | temp_dir=$(sudo -u nobody mktemp -d) |
|
24 | temp_dir=$(sudo -u nobody mktemp -d) | |
25 |
|
25 | |||
26 | # Fetch current RPi2/3 kernel sources |
|
26 | # Fetch current RPi2/3 kernel sources | |
27 | sudo -E -u nobody git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" |
|
27 | if [ -z "${KERNEL_BRANCH}" ] ; then | |
|
28 | sudo -E -u nobody git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" | |||
|
29 | else | |||
|
30 | sudo -E -u nobody git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" | |||
|
31 | fi | |||
28 |
|
32 | |||
29 | # Copy downloaded kernel sources |
|
33 | # Copy downloaded kernel sources | |
30 | mv "${temp_dir}/linux" "${R}/usr/src/" |
|
34 | mv "${temp_dir}/linux" "${R}/usr/src/" | |
31 |
|
35 | |||
32 | # Remove temporary directory for kernel sources |
|
36 | # Remove temporary directory for kernel sources | |
33 | rm -fr "${temp_dir}" |
|
37 | rm -fr "${temp_dir}" | |
34 |
|
38 | |||
35 | # Set permissions of the kernel sources |
|
39 | # Set permissions of the kernel sources | |
36 | chown -R root:root "${R}/usr/src" |
|
40 | chown -R root:root "${R}/usr/src" | |
37 | fi |
|
41 | fi | |
38 |
|
42 | |||
39 | # Calculate optimal number of kernel building threads |
|
43 | # Calculate optimal number of kernel building threads | |
40 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then |
|
44 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then | |
41 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) |
|
45 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) | |
42 | fi |
|
46 | fi | |
43 |
|
47 | |||
44 | # Configure and build kernel |
|
48 | # Configure and build kernel | |
45 | if [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
49 | if [ "$KERNELSRC_PREBUILT" = false ] ; then | |
46 | # Remove device, network and filesystem drivers from kernel configuration |
|
50 | # Remove device, network and filesystem drivers from kernel configuration | |
47 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
51 | if [ "$KERNEL_REDUCE" = true ] ; then | |
48 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
52 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |
49 | sed -i\ |
|
53 | sed -i\ | |
50 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ |
|
54 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ | |
51 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ |
|
55 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ | |
52 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ |
|
56 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ | |
53 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ |
|
57 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ | |
54 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ |
|
58 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ | |
55 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ |
|
59 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ | |
56 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ |
|
60 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ | |
57 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ |
|
61 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ | |
58 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ |
|
62 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ | |
59 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ |
|
63 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ | |
60 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ |
|
64 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ | |
61 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ |
|
65 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ | |
62 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ |
|
66 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ | |
63 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ |
|
67 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ | |
64 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ |
|
68 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ | |
65 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ |
|
69 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ | |
66 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ |
|
70 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ | |
67 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ |
|
71 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ | |
68 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ |
|
72 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ | |
69 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ |
|
73 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ | |
70 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ |
|
74 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ | |
71 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ |
|
75 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ | |
72 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ |
|
76 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ | |
73 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ |
|
77 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ | |
74 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ |
|
78 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ | |
75 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ |
|
79 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ | |
76 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ |
|
80 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ | |
77 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ |
|
81 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ | |
78 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ |
|
82 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ | |
79 | "${KERNEL_DIR}/.config" |
|
83 | "${KERNEL_DIR}/.config" | |
80 | fi |
|
84 | fi | |
81 |
|
85 | |||
82 | if [ "$KERNELSRC_CONFIG" = true ] ; then |
|
86 | if [ "$KERNELSRC_CONFIG" = true ] ; then | |
83 | # Load default raspberry kernel configuration |
|
87 | # Load default raspberry kernel configuration | |
84 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
88 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |
85 |
|
89 | |||
86 | if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then |
|
90 | if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then | |
87 | cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config |
|
91 | cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config | |
88 | fi |
|
92 | fi | |
89 |
|
93 | |||
90 | # Start menu-driven kernel configuration (interactive) |
|
94 | # Start menu-driven kernel configuration (interactive) | |
91 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
95 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
92 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig |
|
96 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig | |
93 | fi |
|
97 | fi | |
94 | fi |
|
98 | fi | |
95 |
|
99 | |||
96 | # Cross compile kernel and modules |
|
100 | # Cross compile kernel and modules | |
97 |
make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" |
|
101 | make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_BIN_IMAGE}" modules dtbs | |
98 | fi |
|
102 | fi | |
99 |
|
103 | |||
100 | # Check if kernel compilation was successful |
|
104 | # Check if kernel compilation was successful | |
101 |
if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/ |
|
105 | if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then | |
102 |
echo "error: kernel compilation failed! ( |
|
106 | echo "error: kernel compilation failed! (kernel image not found)" | |
103 | cleanup |
|
107 | cleanup | |
104 | exit 1 |
|
108 | exit 1 | |
105 | fi |
|
109 | fi | |
106 |
|
110 | |||
107 | # Install kernel modules |
|
111 | # Install kernel modules | |
108 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
112 | if [ "$ENABLE_REDUCE" = true ] ; then | |
109 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install |
|
113 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install | |
110 | else |
|
114 | else | |
111 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install |
|
115 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install | |
112 |
|
116 | |||
113 | # Install kernel firmware |
|
117 | # Install kernel firmware | |
114 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install |
|
118 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install | |
115 | fi |
|
119 | fi | |
116 |
|
120 | |||
117 | # Install kernel headers |
|
121 | # Install kernel headers | |
118 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then |
|
122 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then | |
119 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install |
|
123 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install | |
120 | fi |
|
124 | fi | |
121 |
|
125 | |||
122 | # Prepare boot (firmware) directory |
|
126 | # Prepare boot (firmware) directory | |
123 | mkdir "${BOOT_DIR}" |
|
127 | mkdir "${BOOT_DIR}" | |
124 |
|
128 | |||
125 | # Get kernel release version |
|
129 | # Get kernel release version | |
126 | KERNEL_VERSION=`cat "${KERNEL_DIR}/include/config/kernel.release"` |
|
130 | KERNEL_VERSION=`cat "${KERNEL_DIR}/include/config/kernel.release"` | |
127 |
|
131 | |||
128 | # Copy kernel configuration file to the boot directory |
|
132 | # Copy kernel configuration file to the boot directory | |
129 | install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" |
|
133 | install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" | |
130 |
|
134 | |||
131 | # Copy dts and dtb device tree sources and binaries |
|
135 | # Copy dts and dtb device tree sources and binaries | |
132 | mkdir "${BOOT_DIR}/overlays" |
|
136 | mkdir "${BOOT_DIR}/overlays" | |
133 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOT_DIR}/" |
|
137 | ||
|
138 | # Ensure the proper .dtb is located | |||
|
139 | if [ "$KERNEL_ARCH" = "arm" ] ; then | |||
|
140 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOT_DIR}/" | |||
|
141 | else | |||
|
142 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb "${BOOT_DIR}/" | |||
|
143 | fi | |||
|
144 | ||||
134 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOT_DIR}/overlays/" |
|
145 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOT_DIR}/overlays/" | |
135 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" |
|
146 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" | |
136 |
|
147 | |||
137 | if [ "$ENABLE_UBOOT" = false ] ; then |
|
148 | if [ "$ENABLE_UBOOT" = false ] ; then | |
138 |
# Convert and copy |
|
149 | # Convert and copy kernel image to the boot directory | |
139 |
"${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/ |
|
150 | "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" | |
140 | else |
|
151 | else | |
141 |
# Copy |
|
152 | # Copy kernel image to the boot directory | |
142 |
install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/ |
|
153 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" | |
143 | fi |
|
154 | fi | |
144 |
|
155 | |||
145 | # Remove kernel sources |
|
156 | # Remove kernel sources | |
146 | if [ "$KERNEL_REMOVESRC" = true ] ; then |
|
157 | if [ "$KERNEL_REMOVESRC" = true ] ; then | |
147 | rm -fr "${KERNEL_DIR}" |
|
158 | rm -fr "${KERNEL_DIR}" | |
148 | else |
|
159 | else | |
149 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare |
|
160 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare | |
150 |
|
161 | |||
151 | # Create symlinks for kernel modules |
|
162 | # Create symlinks for kernel modules | |
152 | ln -sf "${KERNEL_DIR}" "${R}/lib/modules/${KERNEL_VERSION}/build" |
|
163 | ln -sf "${KERNEL_DIR}" "${R}/lib/modules/${KERNEL_VERSION}/build" | |
153 | ln -sf "${KERNEL_DIR}" "${R}/lib/modules/${KERNEL_VERSION}/source" |
|
164 | ln -sf "${KERNEL_DIR}" "${R}/lib/modules/${KERNEL_VERSION}/source" | |
154 | fi |
|
165 | fi | |
155 |
|
166 | |||
156 | else # BUILD_KERNEL=false |
|
167 | else # BUILD_KERNEL=false | |
157 | # Kernel installation |
|
168 | # Kernel installation | |
158 | chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel |
|
169 | chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel | |
159 |
|
170 | |||
160 | # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot |
|
171 | # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot | |
161 | chroot_exec apt-get -qq -y install flash-kernel |
|
172 | chroot_exec apt-get -qq -y install flash-kernel | |
162 |
|
173 | |||
163 | # Check if kernel installation was successful |
|
174 | # Check if kernel installation was successful | |
164 | VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)" |
|
175 | VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)" | |
165 | if [ -z "$VMLINUZ" ] ; then |
|
176 | if [ -z "$VMLINUZ" ] ; then | |
166 | echo "error: kernel installation failed! (/boot/vmlinuz-* not found)" |
|
177 | echo "error: kernel installation failed! (/boot/vmlinuz-* not found)" | |
167 | cleanup |
|
178 | cleanup | |
168 | exit 1 |
|
179 | exit 1 | |
169 | fi |
|
180 | fi | |
170 | # Copy vmlinuz kernel to the boot directory |
|
181 | # Copy vmlinuz kernel to the boot directory | |
171 | install_readonly "${VMLINUZ}" "${BOOT_DIR}/${KERNEL_IMAGE}" |
|
182 | install_readonly "${VMLINUZ}" "${BOOT_DIR}/${KERNEL_IMAGE}" | |
172 | fi |
|
183 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant