##// END OF EJS Templates
fix: BUILD_KERNEL
Jan Wagner -
r81:7878e85af774
parent child
Show More
@@ -1,252 +1,252
1 1 #
2 2 # Build and Setup RPi2 Kernel
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Fetch and build latest raspberry kernel
9 9 if [ "$BUILD_KERNEL" = true ] ; then
10 10 # Setup source directory
11 11 mkdir -p "$R/usr/src"
12 12
13 13 # Copy existing kernel sources into chroot directory
14 14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 15 # Copy kernel sources
16 16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
17 17
18 18 # Clean the kernel sources
19 19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 20 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 21 fi
22 22 else # KERNELSRC_DIR=""
23 23 # Fetch current raspberrypi kernel sources
24 24 git -C "$R/usr/src" clone --depth=1 https://github.com/raspberrypi/linux
25 25 fi
26 26
27 27 # Calculate optimal number of kernel building threads
28 28 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
29 29 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
30 30 fi
31 31
32 32 # Configure and build kernel
33 33 if [ "$KERNELSRC_PREBUILT" = false ] ; then
34 34 # Remove device, network and filesystem drivers from kernel configuration
35 35 if [ "$KERNEL_REDUCE" = true ] ; then
36 36 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
37 37 sed -i\
38 38 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
39 39 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
40 40 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
41 41 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
42 42 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
43 43 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
44 44 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
45 45 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
46 46 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
47 47 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
48 48 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
49 49 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
50 50 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
51 51 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
52 52 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
53 53 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
54 54 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
55 55 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
56 56 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
57 57 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
58 58 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
59 59 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
60 60 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
61 61 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
62 62 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
63 63 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
64 64 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
65 65 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
66 66 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
67 67 "$R/usr/src/linux/.config"
68 68 fi
69 69
70 70 if [ "$KERNELSRC_CONFIG" = true ] ; then
71 71 # Load default raspberry kernel configuration
72 72 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
73 73
74 74 # Start menu-driven kernel configuration (interactive)
75 75 if [ "$KERNEL_MENUCONFIG" = true ] ; then
76 76 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
77 77 fi
78 78 fi
79 79
80 80 # Cross compile kernel and modules
81 81 make -C "$R/usr/src/linux" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
82 82 fi
83 83
84 84 # Check if kernel compilation was successful
85 85 if [ ! -r "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
86 86 echo "error: kernel compilation failed! (zImage not found)"
87 87 cleanup
88 88 exit 1
89 89 fi
90 90
91 91 # Install kernel modules
92 92 if [ "$ENABLE_REDUCE" = true ] ; then
93 93 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
94 94 else
95 95 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
96 96
97 97 # Install kernel firmware
98 98 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
99 99 fi
100 100
101 101 # Install kernel headers
102 102 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
103 103 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
104 104 fi
105 105
106 106 # Prepare boot (firmware) directory
107 107 mkdir "$R/boot/firmware/"
108 108
109 109 # Get kernel release version
110 110 KERNEL_VERSION=`cat "$R/usr/src/linux/include/config/kernel.release"`
111 111
112 112 # Copy kernel configuration file to the boot directory
113 113 install_readonly "$R/usr/src/linux/.config" "$R/boot/config-${KERNEL_VERSION}"
114 114
115 115 # Copy dts and dtb device tree sources and binaries
116 116 mkdir "$R/boot/firmware/overlays/"
117 117 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "$R/boot/firmware/"
118 118 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "$R/boot/firmware/overlays/"
119 119 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "$R/boot/firmware/overlays/README"
120 120
121 # Copy zImage kernel to the boot directory
122 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" "$R/boot/firmware/kernel7.img"
121 # Convert and copy zImage kernel to the boot directory
122 "$R/usr/src/linux/scripts/mkknlimg" "$R/usr/src/linux/arch/arm/boot/zImage" "$R/boot/firmware/kernel7.img"
123 123
124 124 # Remove kernel sources
125 125 if [ "$KERNEL_REMOVESRC" = true ] ; then
126 126 rm -fr "$R/usr/src/linux"
127 127 fi
128 128
129 129 # Install latest boot binaries from raspberry/firmware github
130 130 wget -q -O "$R/boot/firmware/bootcode.bin" https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin
131 wget -q -O "$R/boot/firmware/fixup_cd.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat
132 131 wget -q -O "$R/boot/firmware/fixup.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat
132 wget -q -O "$R/boot/firmware/fixup_cd.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat
133 133 wget -q -O "$R/boot/firmware/fixup_x.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_x.dat
134 wget -q -O "$R/boot/firmware/start_cd.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf
135 134 wget -q -O "$R/boot/firmware/start.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start.elf
135 wget -q -O "$R/boot/firmware/start_cd.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf
136 136 wget -q -O "$R/boot/firmware/start_x.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_x.elf
137 137
138 138 else # BUILD_KERNEL=false
139 139 # Kernel installation
140 140 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
141 141
142 142 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
143 143 chroot_exec apt-get -qq -y install flash-kernel
144 144
145 145 # Check if kernel installation was successful
146 146 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
147 147 if [ -z "$VMLINUZ" ] ; then
148 148 echo "error: kernel installation failed! (/boot/vmlinuz-* not found)"
149 149 cleanup
150 150 exit 1
151 151 fi
152 152 # Copy vmlinuz kernel to the boot directory
153 153 install_readonly "$VMLINUZ" "$R/boot/firmware/kernel7.img"
154 154 fi
155 155
156 156 # Setup firmware boot cmdline
157 157 if [ "$ENABLE_SPLITFS" = true ] ; then
158 158 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
159 159 else
160 160 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
161 161 fi
162 162
163 163 # Add serial console support
164 164 if [ "$ENABLE_CONSOLE" = true ] ; then
165 165 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
166 166 fi
167 167
168 168 # Remove IPv6 networking support
169 169 if [ "$ENABLE_IPV6" = false ] ; then
170 170 CMDLINE="${CMDLINE} ipv6.disable=1"
171 171 fi
172 172
173 173 # Install firmware boot cmdline
174 174 echo "${CMDLINE}" > "$R/boot/firmware/cmdline.txt"
175 175
176 176 # Add encrypted root partition to cmdline.txt
177 177 if [ "$ENABLE_CRYPTFS" = true ] ; then
178 178 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/" "$R/boot/firmware/cmdline.txt"
179 179 fi
180 180
181 181 # Install firmware config
182 182 install_readonly files/boot/config.txt "$R/boot/firmware/config.txt"
183 183
184 184 # Setup minimal GPU memory allocation size: 16MB (no X)
185 185 if [ "$ENABLE_MINGPU" = true ] ; then
186 186 echo "gpu_mem=16" >> "$R/boot/firmware/config.txt"
187 187 fi
188 188
189 189 # Setup boot with initramfs
190 190 if [ "$ENABLE_INITRAMFS" = true ] ; then
191 191 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "$R/boot/firmware/config.txt"
192 192 fi
193 193
194 194 # Create firmware configuration and cmdline symlinks
195 195 ln -sf firmware/config.txt "$R/boot/config.txt"
196 196 ln -sf firmware/cmdline.txt "$R/boot/cmdline.txt"
197 197
198 198 # Install and setup kernel modules to load at boot
199 199 mkdir -p "$R/lib/modules-load.d/"
200 200 install_readonly files/modules/rpi2.conf "$R/lib/modules-load.d/rpi2.conf"
201 201
202 202 # Load hardware random module at boot
203 203 if [ "$ENABLE_HWRANDOM" = true ] ; then
204 204 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "$R/lib/modules-load.d/rpi2.conf"
205 205 fi
206 206
207 207 # Load sound module at boot
208 208 if [ "$ENABLE_SOUND" = true ] ; then
209 209 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "$R/lib/modules-load.d/rpi2.conf"
210 210 fi
211 211
212 212 # Install kernel modules blacklist
213 213 mkdir -p "$R/etc/modprobe.d/"
214 214 install_readonly files/modules/raspi-blacklist.conf "$R/etc/modprobe.d/raspi-blacklist.conf"
215 215
216 216 # Install and setup fstab
217 217 install_readonly files/mount/fstab "$R/etc/fstab"
218 218
219 219 # Add usb/sda disk root partition to fstab
220 220 if [ "$ENABLE_SPLITFS" = true ] ; then
221 221 sed -i "s/mmcblk0p2/sda1/" "$R/etc/fstab"
222 222 fi
223 223
224 224 # Add encrypted root partition to fstab and crypttab
225 225 if [ "$ENABLE_CRYPTFS" = true ] ; then
226 226 # Replace fstab root partition with encrypted partition mapping
227 227 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "$R/etc/fstab"
228 228
229 229 # Add encrypted partition to crypttab and fstab
230 230 install_readonly files/mount/crypttab "$R/etc/crypttab"
231 231 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "$R/etc/crypttab"
232 232 fi
233 233
234 234 # Generate initramfs file
235 235 if [ "$ENABLE_INITRAMFS" = true ] ; then
236 236 if [ "$ENABLE_CRYPTFS" = true ] ; then
237 237 # Dummy mapping required by mkinitramfs
238 238 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
239 239
240 240 # Generate initramfs with encrypted root partition support
241 241 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
242 242
243 243 # Remove dummy mapping
244 244 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
245 245 else
246 246 # Generate initramfs without encrypted root partition support
247 247 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
248 248 fi
249 249 fi
250 250
251 251 # Install sysctl.d configuration files
252 252 install_readonly files/sysctl.d/81-rpi-vm.conf "$R/etc/sysctl.d/81-rpi-vm.conf"
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant