##// END OF EJS Templates
- remove some whitespace...
Unknown -
r521:13726dc8a192
parent child
Show More
@@ -1,223 +1,223
1 #
1 #
2 # Setup RPi2/3 config and cmdline
2 # Setup RPi2/3 config and cmdline
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 if [ "$BUILD_KERNEL" = true ] ; then
8 if [ "$BUILD_KERNEL" = true ] ; then
9 if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then
9 if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then
10 # Install boot binaries from local directory
10 # Install boot binaries from local directory
11 cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin
11 cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin
12 cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat
12 cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat
13 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat
13 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat
14 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat
14 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat
15 cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf
15 cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf
16 cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf
16 cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf
17 cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf
17 cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf
18 else
18 else
19 # Create temporary directory for boot binaries
19 # Create temporary directory for boot binaries
20 temp_dir=$(as_nobody mktemp -d)
20 temp_dir=$(as_nobody mktemp -d)
21
21
22 # Install latest boot binaries from raspberry/firmware github
22 # Install latest boot binaries from raspberry/firmware github
23 as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
23 as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
24 as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
24 as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
25 as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
25 as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
26 as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
26 as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
27 as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf"
27 as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf"
28 as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
28 as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
29 as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
29 as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
30
30
31 # Move downloaded boot binaries
31 # Move downloaded boot binaries
32 mv "${temp_dir}/"* "${BOOT_DIR}/"
32 mv "${temp_dir}/"* "${BOOT_DIR}/"
33
33
34 # Remove temporary directory for boot binaries
34 # Remove temporary directory for boot binaries
35 rm -fr "${temp_dir}"
35 rm -fr "${temp_dir}"
36
36
37 # Set permissions of the boot binaries
37 # Set permissions of the boot binaries
38 chown -R root:root "${BOOT_DIR}"
38 chown -R root:root "${BOOT_DIR}"
39 chmod -R 600 "${BOOT_DIR}"
39 chmod -R 600 "${BOOT_DIR}"
40 fi
40 fi
41 fi
41 fi
42
42
43 # Setup firmware boot cmdline
43 # Setup firmware boot cmdline
44 if [ "$ENABLE_SPLITFS" = true ] ; then
44 if [ "$ENABLE_SPLITFS" = true ] ; then
45 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
45 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
46 else
46 else
47 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
47 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
48 fi
48 fi
49
49
50 # Add encrypted root partition to cmdline.txt
50 # Add encrypted root partition to cmdline.txt
51 if [ "$ENABLE_CRYPTFS" = true ] ; then
51 if [ "$ENABLE_CRYPTFS" = true ] ; then
52 if [ "$ENABLE_SPLITFS" = true ] ; then
52 if [ "$ENABLE_SPLITFS" = true ] ; then
53 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
53 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
54 else
54 else
55 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
55 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
56 fi
56 fi
57 fi
57 fi
58
58
59 # Enable Kernel messages on standard output
59 # Enable Kernel messages on standard output
60 if [ "$ENABLE_PRINTK" = true ] ; then
60 if [ "$ENABLE_PRINTK" = true ] ; then
61 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
61 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
62 fi
62 fi
63
63
64 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
64 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
65 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
65 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
66
66
67 # Remove IPv6 networking support
67 # Remove IPv6 networking support
68 if [ "$ENABLE_IPV6" = false ] ; then
68 if [ "$ENABLE_IPV6" = false ] ; then
69 CMDLINE="${CMDLINE} ipv6.disable=1"
69 CMDLINE="${CMDLINE} ipv6.disable=1"
70 fi
70 fi
71
71
72 # Automatically assign predictable network interface names
72 # Automatically assign predictable network interface names
73 if [ "$ENABLE_IFNAMES" = false ] ; then
73 if [ "$ENABLE_IFNAMES" = false ] ; then
74 CMDLINE="${CMDLINE} net.ifnames=0"
74 CMDLINE="${CMDLINE} net.ifnames=0"
75 else
75 else
76 CMDLINE="${CMDLINE} net.ifnames=1"
76 CMDLINE="${CMDLINE} net.ifnames=1"
77 fi
77 fi
78
78
79 # Install firmware config
79 # Install firmware config
80 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
80 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
81
81
82 # Locks CPU frequency at maximum
82 # Locks CPU frequency at maximum
83 if [ "$ENABLE_TURBO" = true ] ; then
83 if [ "$ENABLE_TURBO" = true ] ; then
84 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
84 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
85 # helps to avoid sdcard corruption when force_turbo is enabled.
85 # helps to avoid sdcard corruption when force_turbo is enabled.
86 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
86 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
87 fi
87 fi
88
88
89 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
89 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
90
90
91 # Bluetooth enabled
91 # Bluetooth enabled
92 if [ "$ENABLE_BLUETOOTH" = true ] ; then
92 if [ "$ENABLE_BLUETOOTH" = true ] ; then
93 # Create temporary directory for Bluetooth sources
93 # Create temporary directory for Bluetooth sources
94 temp_dir=$(as_nobody mktemp -d)
94 temp_dir=$(as_nobody mktemp -d)
95
95
96 # Fetch Bluetooth sources
96 # Fetch Bluetooth sources
97 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
97 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
98
98
99 # Copy downloaded sources
99 # Copy downloaded sources
100 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
100 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
101
101
102 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
102 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
103 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth
103 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth
104 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
104 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
105
105
106 # Set permissions
106 # Set permissions
107 chown -R root:root "${R}/tmp/pi-bluetooth"
107 chown -R root:root "${R}/tmp/pi-bluetooth"
108
108
109 # Install tools
109 # Install tools
110 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
110 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
111 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
111 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
112
112
113 # make scripts executable
113 # make scripts executable
114 chmod +x "${R}/usr/bin/bthelper"
114 chmod +x "${R}/usr/bin/bthelper"
115 chmod +x "${R}/usr/bin/btuart"
115 chmod +x "${R}/usr/bin/btuart"
116
116
117 # Install bluetooth udev rule
117 # Install bluetooth udev rule
118 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
118 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
119
119
120 # Install Firmware Flash file and apropiate licence
120 # Install Firmware Flash file and apropiate licence
121 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
121 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
122 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
122 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
123 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
123 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
124 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
124 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
125 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
125 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
126
126
127 # Remove temporary directories
127 # Remove temporary directories
128 rm -fr "${temp_dir}"
128 rm -fr "${temp_dir}"
129 rm -fr "${R}"/tmp/pi-bluetooth
129 rm -fr "${R}"/tmp/pi-bluetooth
130
130
131 # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0
131 # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0
132 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
132 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
133
133
134 # set overlay to swap ttyAMA0 and ttyS0
134 # set overlay to swap ttyAMA0 and ttyS0
135 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
135 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
136
136
137 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
137 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
138 if [ "$ENABLE_TURBO" = false ] ; then
138 if [ "$ENABLE_TURBO" = false ] ; then
139 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
139 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
140 fi
140 fi
141 fi
141 fi
142
142
143 # Activate services
143 # Activate services
144 chroot_exec systemctl enable pi-bluetooth.hciuart.service
144 chroot_exec systemctl enable pi-bluetooth.hciuart.service
145
145
146 else # if ENABLE_BLUETOOTH = false
146 else # if ENABLE_BLUETOOTH = false
147 # set overlay to disable bluetooth
147 # set overlay to disable bluetooth
148 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
148 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
149 fi # ENABLE_BLUETOOTH end
149 fi # ENABLE_BLUETOOTH end
150 fi
150 fi
151
151
152 # may need sudo systemctl disable hciuart
152 # may need sudo systemctl disable hciuart
153 if [ "$ENABLE_CONSOLE" = true ] ; then
153 if [ "$ENABLE_CONSOLE" = true ] ; then
154 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
154 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
155 # add string to cmdline
155 # add string to cmdline
156 CMDLINE="${CMDLINE} console=serial0,115200"
156 CMDLINE="${CMDLINE} console=serial0,115200"
157
157
158 # Enable serial console systemd style
158 # Enable serial console systemd style
159 chroot_exec systemctl enable serial-getty\@serial0.service
159 chroot_exec systemctl enable serial-getty\@serial0.service
160 else
160 else
161 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
161 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
162 fi
162 fi
163
163
164 # Install firmware boot cmdline
164 # Install firmware boot cmdline
165 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
165 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
166
166
167 # Setup minimal GPU memory allocation size: 16MB (no X)
167 # Setup minimal GPU memory allocation size: 16MB (no X)
168 if [ "$ENABLE_MINGPU" = true ] ; then
168 if [ "$ENABLE_MINGPU" = true ] ; then
169 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
169 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
170 fi
170 fi
171
171
172 # Setup boot with initramfs
172 # Setup boot with initramfs
173 if [ "$ENABLE_INITRAMFS" = true ] ; then
173 if [ "$ENABLE_INITRAMFS" = true ] ; then
174 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
174 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
175 fi
175 fi
176
176
177 # Create firmware configuration and cmdline symlinks
177 # Create firmware configuration and cmdline symlinks
178 ln -sf firmware/config.txt "${R}/boot/config.txt"
178 ln -sf firmware/config.txt "${R}/boot/config.txt"
179 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
179 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
180
180
181 # Install and setup kernel modules to load at boot
181 # Install and setup kernel modules to load at boot
182 mkdir -p "${LIB_DIR}/modules-load.d/"
182 mkdir -p "${LIB_DIR}/modules-load.d/"
183 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
183 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
184
184
185 # Load hardware random module at boot
185 # Load hardware random module at boot
186 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
186 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
187 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
187 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
188 fi
188 fi
189
189
190 # Load sound module at boot
190 # Load sound module at boot
191 if [ "$ENABLE_SOUND" = true ] ; then
191 if [ "$ENABLE_SOUND" = true ] ; then
192 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
192 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
193 else
193 else
194 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
194 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
195 fi
195 fi
196
196
197 # Enable I2C interface
197 # Enable I2C interface
198 if [ "$ENABLE_I2C" = true ] ; then
198 if [ "$ENABLE_I2C" = true ] ; then
199 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
199 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
200 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
200 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
201 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
201 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
202 fi
202 fi
203
203
204 # Enable SPI interface
204 # Enable SPI interface
205 if [ "$ENABLE_SPI" = true ] ; then
205 if [ "$ENABLE_SPI" = true ] ; then
206 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
206 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
207 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
207 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
208 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
208 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
209 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
209 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
210 fi
210 fi
211 fi
211 fi
212
212
213 # Disable RPi2/3 under-voltage warnings
213 # Disable RPi2/3 under-voltage warnings
214 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
214 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
215 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
215 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
216 fi
216 fi
217
217
218 # Install kernel modules blacklist
218 # Install kernel modules blacklist
219 mkdir -p "${ETC_DIR}/modprobe.d/"
219 mkdir -p "${ETC_DIR}/modprobe.d/"
220 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
220 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
221
221
222 # Install sysctl.d configuration files
222 # Install sysctl.d configuration files
223 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
223 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
@@ -1,31 +1,32
1 logger -t "rc.firstboot" "Regenerating initramfs to remove encrypted root partition auto-expand"
1 logger -t "rc.firstboot" "Regenerating initramfs to remove encrypted root partition auto-expand"
2
2
3 KERNEL_VERSION=$(uname -r)
3 KERNEL_VERSION=$(uname -r)
4 KERNEL_ARCH=$(uname -m)
4 KERNEL_ARCH=$(uname -m)
5 INITRAMFS="/boot/firmware/initramfs-${KERNEL_VERSION}"
5 INITRAMFS="/boot/firmware/initramfs-${KERNEL_VERSION}"
6 INITRAMFS_UBOOT="${INITRAMFS}.uboot"
6 INITRAMFS_UBOOT="${INITRAMFS}.uboot"
7
7
8 # Extract kernel arch
8 # Extract kernel arch
9 case "${KERNEL_ARCH}" in
9 case "${KERNEL_ARCH}" in
10 arm*) KERNEL_ARCH=arm ;;
10 arm*) KERNEL_ARCH=arm ;;
11 aarch64) KERNEL_ARCH=arm64 ;;
11 esac
12 esac
12
13
13 # Regenerate initramfs
14 # Regenerate initramfs
14 if [ -r "${INITRAMFS}" ] ; then
15 if [ -r "${INITRAMFS}" ] ; then
15 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
16 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
16 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
17 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
17 rm -f /etc/initramfs-tools/hooks/expand-tools
18 rm -f /etc/initramfs-tools/hooks/expand-tools
18 rm -f "${INITRAMFS}"
19 rm -f "${INITRAMFS}"
19 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
20 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
20 fi
21 fi
21
22
22 # Convert generated initramfs for U-Boot using mkimage
23 # Convert generated initramfs for U-Boot using mkimage
23 if [ -r "${INITRAMFS_UBOOT}" ] ; then
24 if [ -r "${INITRAMFS_UBOOT}" ] ; then
24 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
25 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
25 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
26 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
26 rm -f /etc/initramfs-tools/hooks/expand-tools
27 rm -f /etc/initramfs-tools/hooks/expand-tools
27 rm -f "${INITRAMFS_UBOOT}"
28 rm -f "${INITRAMFS_UBOOT}"
28 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
29 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
29 mkimage -A "${KERNEL_ARCH}" -T ramdisk -C none -n "initramfs-${KERNEL_VERSION}" -d "${INITRAMFS}" "${INITRAMFS_UBOOT}"
30 mkimage -A "${KERNEL_ARCH}" -T ramdisk -C none -n "initramfs-${KERNEL_VERSION}" -d "${INITRAMFS}" "${INITRAMFS_UBOOT}"
30 rm -f "${INITRAMFS}"
31 rm -f "${INITRAMFS}"
31 fi
32 fi
@@ -1,86 +1,86
1 # This file contains utility functions used by rpi23-gen-image.sh
1 # This file contains utility functions used by rpi23-gen-image.sh
2
2
3 cleanup (){
3 cleanup (){
4 set +x
4 set +x
5 set +e
5 set +e
6
6
7 # Identify and kill all processes still using files
7 # Identify and kill all processes still using files
8 echo "killing processes using mount point ..."
8 echo "killing processes using mount point ..."
9 fuser -k "${R}"
9 fuser -k "${R}"
10 sleep 3
10 sleep 3
11 fuser -9 -k -v "${R}"
11 fuser -9 -k -v "${R}"
12
12
13 # Clean up temporary .password file
13 # Clean up temporary .password file
14 if [ -r ".password" ] ; then
14 if [ -r ".password" ] ; then
15 shred -zu .password
15 shred -zu .password
16 fi
16 fi
17
17
18 # Clean up all temporary mount points
18 # Clean up all temporary mount points
19 echo "removing temporary mount points ..."
19 echo "removing temporary mount points ..."
20 umount -l "${R}/proc" 2> /dev/null
20 umount -l "${R}/proc" 2> /dev/null
21 umount -l "${R}/sys" 2> /dev/null
21 umount -l "${R}/sys" 2> /dev/null
22 umount -l "${R}/dev/pts" 2> /dev/null
22 umount -l "${R}/dev/pts" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
28 trap - 0 1 2 3 6
28 trap - 0 1 2 3 6
29 }
29 }
30
30
31 chroot_exec() {
31 chroot_exec() {
32 # Exec command in chroot
32 # Exec command in chroot
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot "${R}" "$@"
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot "${R}" "$@"
34 }
34 }
35
35
36 as_nobody() {
36 as_nobody() {
37 # Exec command as user nobody
37 # Exec command as user nobody
38 sudo -E -u nobody LANG=C LC_ALL=C "$@"
38 sudo -E -u nobody LANG=C LC_ALL=C "$@"
39 }
39 }
40
40
41 install_readonly() {
41 install_readonly() {
42 # Install file with user read-only permissions
42 # Install file with user read-only permissions
43 install -o root -g root -m 644 "$@"
43 install -o root -g root -m 644 "$@"
44 }
44 }
45
45
46 install_exec() {
46 install_exec() {
47 # Install file with root exec permissions
47 # Install file with root exec permissions
48 install -o root -g root -m 744 "$@"
48 install -o root -g root -m 744 "$@"
49 }
49 }
50
50
51 use_template () {
51 use_template () {
52 # Test if configuration template file exists
52 # Test if configuration template file exists
53 if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then
53 if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then
54 echo "error: configuration template ${CONFIG_TEMPLATE} not found"
54 echo "error: configuration template ${CONFIG_TEMPLATE} not found"
55 exit 1
55 exit 1
56 fi
56 fi
57
57
58 # Load template configuration parameters
58 # Load template configuration parameters
59 . "./templates/${CONFIG_TEMPLATE}"
59 . "./templates/${CONFIG_TEMPLATE}"
60 }
60 }
61
61
62 chroot_install_cc() {
62 chroot_install_cc() {
63 # Install c/c++ build environment inside the chroot
63 # Install c/c++ build environment inside the chroot
64 if [ -z "${COMPILER_PACKAGES}" ] ; then
64 if [ -z "${COMPILER_PACKAGES}" ] ; then
65 COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }')
65 COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }')
66 # Install COMPILER_PACKAGES in chroot
66 # Install COMPILER_PACKAGES in chroot - NEVER do "${COMPILER_PACKAGES}" -> breaks uboot
67 chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install "${COMPILER_PACKAGES}"
67 chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES}
68 fi
68 fi
69 }
69 }
70
70
71 chroot_remove_cc() {
71 chroot_remove_cc() {
72 # Remove c/c++ build environment from the chroot
72 # Remove c/c++ build environment from the chroot
73 if [ -n "${COMPILER_PACKAGES}" ] ; then
73 if [ -n "${COMPILER_PACKAGES}" ] ; then
74 chroot_exec apt-get -qq -y --auto-remove purge "${COMPILER_PACKAGES}"
74 chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES}
75 COMPILER_PACKAGES=""
75 COMPILER_PACKAGES=""
76 fi
76 fi
77 }
77 }
78
78
79 # https://serverfault.com/a/682849 - converts e.g. /24 to 255.255.255.0
79 # https://serverfault.com/a/682849 - converts e.g. /24 to 255.255.255.0
80 cdr2mask ()
80 cdr2mask ()
81 {
81 {
82 # Number of args to shift, 255..255, first non-255 byte, zeroes
82 # Number of args to shift, 255..255, first non-255 byte, zeroes
83 set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
83 set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
84 [ $1 -gt 1 ] && shift $1 || shift
84 [ $1 -gt 1 ] && shift $1 || shift
85 echo ${1-0}.${2-0}.${3-0}.${4-0}
85 echo ${1-0}.${2-0}.${3-0}.${4-0}
86 } No newline at end of file
86 }
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant