##// END OF EJS Templates
0
Unknown -
r513:27accd49aa7c
parent child
Show More
@@ -1,96 +1,99
1 #
1 #
2 # Setup fstab and initramfs
2 # Setup fstab and initramfs
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install and setup fstab
8 # Install and setup fstab
9 install_readonly files/mount/fstab "${ETC_DIR}/fstab"
9 install_readonly files/mount/fstab "${ETC_DIR}/fstab"
10
10
11 if [ "$ENABLE_UBOOTUSB" = true ] ; then
11 if [ "$ENABLE_UBOOTUSB" = true ] ; then
12 sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab"
12 sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab"
13 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab"
13 sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab"
14 fi
14 fi
15
15
16 # Add usb/sda disk root partition to fstab
16 # Add usb/sda disk root partition to fstab
17 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
17 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
18 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
18 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
19 fi
19 fi
20
20
21 # Add encrypted root partition to fstab and crypttab
21 # Add encrypted root partition to fstab and crypttab
22 if [ "$ENABLE_CRYPTFS" = true ] ; then
22 if [ "$ENABLE_CRYPTFS" = true ] ; then
23 # Replace fstab root partition with encrypted partition mapping
23 # Replace fstab root partition with encrypted partition mapping
24 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
24 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
25
25
26 # Add encrypted partition to crypttab and fstab
26 # Add encrypted partition to crypttab and fstab
27 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
27 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
28 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
28 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
29
29
30 if [ "$ENABLE_SPLITFS" = true ] ; then
30 if [ "$ENABLE_SPLITFS" = true ] ; then
31 # Add usb/sda disk to crypttab
31 # Add usb/sda disk to crypttab
32 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
32 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
33 fi
33 fi
34 fi
34 fi
35
35
36 # Generate initramfs file
36 # Generate initramfs file
37 if [ "$ENABLE_INITRAMFS" = true ] ; then
37 if [ "$ENABLE_INITRAMFS" = true ] ; then
38 if [ "$ENABLE_CRYPTFS" = true ] ; then
38 if [ "$ENABLE_CRYPTFS" = true ] ; then
39 # Include initramfs scripts to auto expand encrypted root partition
39 # Include initramfs scripts to auto expand encrypted root partition
40 if [ "$EXPANDROOT" = true ] ; then
40 if [ "$EXPANDROOT" = true ] ; then
41 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
41 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
42 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
42 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
43 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
43 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
44 fi
44 fi
45
45
46 if [ "$CRYPTFS_DROPBEAR" = true ]; then
46 if [ "$CRYPTFS_DROPBEAR" = true ]; then
47 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
47 if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then
48 install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
48 install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
49 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys
49 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys
50 else
50 else
51 # Create key
51 # Create key
52 chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear
52 chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear
53
53
54 # Convert dropbear key to openssh key
54 # Convert dropbear key to openssh key
55 chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa
55 chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa
56
56
57 # Get Public Key Part
57 # Get Public Key Part
58 chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub
58 chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub
59
59
60 # Delete unwanted lines
60 # Delete unwanted lines
61 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
61 sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
62 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
62 sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub
63
63
64 # Trust the new key
64 # Trust the new key
65 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys
65 cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys
66
66
67 # Save Keys - convert with putty from rsa/openssh to puttkey
67 # Save Keys - convert with putty from rsa/openssh to puttkey
68 cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa
68 cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa
69
69
70 # Get unlock script
70 # Get unlock script
71 install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh
71 install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh
72
72
73 # Enable Dropbear inside initramfs
73 # Enable Dropbear inside initramfs
74 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
74 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
75
75
76 # Enable Dropbear inside initramfs
76 # Enable Dropbear inside initramfs
77 sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear
77 sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear
78 fi
78 fi
79 else
79 else
80 # Disable SSHD inside initramfs
80 # Disable SSHD inside initramfs
81 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
81 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
82 fi
82 fi
83
83
84 # Add cryptsetup modules to initramfs
84 # Add cryptsetup modules to initramfs
85 printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook"
85 printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook"
86
86
87 # Dummy mapping required by mkinitramfs
87 # Dummy mapping required by mkinitramfs
88 echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
88 echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
89
89
90 # Generate initramfs with encrypted root partition support
91 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
92
90 # Remove dummy mapping
93 # Remove dummy mapping
91 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
94 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
92 fi
95 else
93
96 # Generate initramfs without encrypted root partition support
94 # Generate initramfs
95 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
97 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
96 fi
98 fi
99 fi
@@ -1,271 +1,271
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_UBOOTUSB" = true ] ; then
44 if [ "$ENABLE_UBOOTUSB" = true ] ; then
45 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
45 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
46 else
46 else
47 if [ "$ENABLE_SPLITFS" = true ] ; then
47 if [ "$ENABLE_SPLITFS" = true ] ; then
48 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
48 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
49 else
49 else
50 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
50 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd"
51 fi
51 fi
52 fi
52 fi
53
53
54 # Add encrypted root partition to cmdline.txt
54 # Add encrypted root partition to cmdline.txt
55 if [ "$ENABLE_CRYPTFS" = true ] ; then
55 if [ "$ENABLE_CRYPTFS" = true ] ; then
56 if [ "$ENABLE_SPLITFS" = true ] ; then
56 if [ "$ENABLE_SPLITFS" = true ] ; then
57 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
57 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
58 else
58 else
59 if [ "$ENABLE_UBOOTUSB" = true ] ; then
59 if [ "$ENABLE_UBOOTUSB" = true ] ; then
60 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/")
60 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/")
61 else
61 else
62 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
62 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
63 fi
63 fi
64 fi
64 fi
65 fi
65 fi
66
66
67 # Enable Kernel messages on standard output
67 # Enable Kernel messages on standard output
68 if [ "$ENABLE_PRINTK" = true ] ; then
68 if [ "$ENABLE_PRINTK" = true ] ; then
69 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
69 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
70 fi
70 fi
71
71
72 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
72 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
73 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
73 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
74
74
75 # Remove IPv6 networking support
75 # Remove IPv6 networking support
76 if [ "$ENABLE_IPV6" = false ] ; then
76 if [ "$ENABLE_IPV6" = false ] ; then
77 CMDLINE="${CMDLINE} ipv6.disable=1"
77 CMDLINE="${CMDLINE} ipv6.disable=1"
78 fi
78 fi
79
79
80 # Automatically assign predictable network interface names
80 # Automatically assign predictable network interface names
81 if [ "$ENABLE_IFNAMES" = false ] ; then
81 if [ "$ENABLE_IFNAMES" = false ] ; then
82 CMDLINE="${CMDLINE} net.ifnames=0"
82 CMDLINE="${CMDLINE} net.ifnames=0"
83 else
83 else
84 CMDLINE="${CMDLINE} net.ifnames=1"
84 CMDLINE="${CMDLINE} net.ifnames=1"
85 fi
85 fi
86
86
87 # Install firmware config
87 # Install firmware config
88 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
88 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
89
89
90 # Locks CPU frequency at maximum
90 # Locks CPU frequency at maximum
91 if [ "$ENABLE_TURBO" = true ] ; then
91 if [ "$ENABLE_TURBO" = true ] ; then
92 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
92 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
93 # helps to avoid sdcard corruption when force_turbo is enabled.
93 # helps to avoid sdcard corruption when force_turbo is enabled.
94 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
94 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
95 fi
95 fi
96
96
97 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
97 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
98
98
99 # Bluetooth enabled
99 # Bluetooth enabled
100 if [ "$ENABLE_BLUETOOTH" = true ] ; then
100 if [ "$ENABLE_BLUETOOTH" = true ] ; then
101 # Create temporary directory for Bluetooth sources
101 # Create temporary directory for Bluetooth sources
102 temp_dir=$(as_nobody mktemp -d)
102 temp_dir=$(as_nobody mktemp -d)
103
103
104 # Fetch Bluetooth sources
104 # Fetch Bluetooth sources
105 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
105 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
106
106
107 # Copy downloaded sources
107 # Copy downloaded sources
108 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
108 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
109
109
110 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
110 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
111 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
111 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
112 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
112 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
113
113
114 # Set permissions
114 # Set permissions
115 chown -R root:root "${R}/tmp/pi-bluetooth"
115 chown -R root:root "${R}/tmp/pi-bluetooth"
116
116
117 # Install tools
117 # Install tools
118 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
118 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
119 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
119 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
120
120
121 # make scripts executable
121 # make scripts executable
122 chmod +x "${R}/usr/bin/bthelper"
122 chmod +x "${R}/usr/bin/bthelper"
123 chmod +x "${R}/usr/bin/btuart"
123 chmod +x "${R}/usr/bin/btuart"
124
124
125 # Install bluetooth udev rule
125 # Install bluetooth udev rule
126 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
126 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
127
127
128 # Install Firmware Flash file and apropiate licence
128 # Install Firmware Flash file and apropiate licence
129 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
129 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
130 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
130 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
131 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
131 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
132 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
132 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
133 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
133 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
134
134
135 # Remove temporary directories
135 # Remove temporary directories
136 rm -fr "${temp_dir}"
136 rm -fr "${temp_dir}"
137 rm -fr "${R}"/tmp/pi-bluetooth
137 rm -fr "${R}"/tmp/pi-bluetooth
138
138
139 # 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
139 # 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
140 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
140 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
141
141
142 # set overlay to swap ttyAMA0 and ttyS0
142 # set overlay to swap ttyAMA0 and ttyS0
143 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
143 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
144
144
145 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
145 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
146 if [ "$ENABLE_TURBO" = false ] ; then
146 if [ "$ENABLE_TURBO" = false ] ; then
147 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
147 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
148 fi
148 fi
149 fi
149 fi
150
150
151 # Activate services
151 # Activate services
152 chroot_exec systemctl enable pi-bluetooth.hciuart.service
152 chroot_exec systemctl enable pi-bluetooth.hciuart.service
153
153
154 else # if ENABLE_BLUETOOTH = false
154 else # if ENABLE_BLUETOOTH = false
155 # set overlay to disable bluetooth
155 # set overlay to disable bluetooth
156 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
156 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
157 fi # ENABLE_BLUETOOTH end
157 fi # ENABLE_BLUETOOTH end
158 fi
158 fi
159
159
160 # may need sudo systemctl disable hciuart
160 # may need sudo systemctl disable hciuart
161 if [ "$ENABLE_CONSOLE" = true ] ; then
161 if [ "$ENABLE_CONSOLE" = true ] ; then
162 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
162 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
163 # add string to cmdline
163 # add string to cmdline
164 CMDLINE="${CMDLINE} console=serial0,115200"
164 CMDLINE="${CMDLINE} console=serial0,115200"
165
165
166 # Enable serial console systemd style
166 # Enable serial console systemd style
167 chroot_exec systemctl enable serial-getty@serial0.service
167 chroot_exec systemctl enable serial-getty@serial0.service
168 else
168 else
169 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
169 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
170 fi
170 fi
171
171
172 if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then
172 if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then
173 # Create temporary directory for systemd-swap sources
173 # Create temporary directory for systemd-swap sources
174 temp_dir=$(as_nobody mktemp -d)
174 temp_dir=$(as_nobody mktemp -d)
175
175
176 # Fetch systemd-swap sources
176 # Fetch systemd-swap sources
177 as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}"
177 as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}"
178
178
179 # Copy downloaded systemd-swap sources
179 # Copy downloaded systemd-swap sources
180 mv "${temp_dir}/systemd-swap" "${R}/tmp/"
180 mv "${temp_dir}/systemd-swap" "${R}/tmp/"
181
181
182 # Change into downloaded src dir
182 # Change into downloaded src dir
183 cd "${R}/tmp/systemd-swap" || exit
183 cd "${R}/tmp/systemd-swap" || exit
184
184
185 # Build package
185 # Build package
186 bash ./package.sh debian
186 bash ./package.sh debian
187
187
188 # Change back into script root dir
188 # Change back into script root dir
189 cd "${WORKDIR}" || exit
189 cd "${WORKDIR}" || exit
190
190
191 # Set permissions of the systemd-swap sources
191 # Set permissions of the systemd-swap sources
192 chown -R root:root "${R}/tmp/systemd-swap"
192 chown -R root:root "${R}/tmp/systemd-swap"
193
193
194 # Install package
194 # Install package
195 chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap_*_any.deb
195 chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap*.deb
196
196
197 # Enable service
197 # Enable service
198 chroot_exec systemctl enable systemd-swap
198 chroot_exec systemctl enable systemd-swap
199
199
200 # Remove temporary directory for systemd-swap sources
200 # Remove temporary directory for systemd-swap sources
201 rm -fr "${temp_dir}"
201 rm -fr "${temp_dir}"
202 else
202 else
203 # Enable ZSWAP in cmdline if systemd-swap is not used
203 # Enable ZSWAP in cmdline if systemd-swap is not used
204 if [ "$KERNEL_ZSWAP" = true ] ; then
204 if [ "$KERNEL_ZSWAP" = true ] ; then
205 CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
205 CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
206 fi
206 fi
207 fi
207 fi
208 if [ "$KERNEL_SECURITY" = true ] ; then
208 if [ "$KERNEL_SECURITY" = true ] ; then
209 CMDLINE="${CMDLINE} apparmor=1 security=apparmor"
209 CMDLINE="${CMDLINE} apparmor=1 security=apparmor"
210 fi
210 fi
211
211
212 # Install firmware boot cmdline
212 # Install firmware boot cmdline
213 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
213 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
214
214
215 # Setup minimal GPU memory allocation size: 16MB (no X)
215 # Setup minimal GPU memory allocation size: 16MB (no X)
216 if [ "$ENABLE_MINGPU" = true ] ; then
216 if [ "$ENABLE_MINGPU" = true ] ; then
217 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
217 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
218 fi
218 fi
219
219
220 # Setup boot with initramfs
220 # Setup boot with initramfs
221 if [ "$ENABLE_INITRAMFS" = true ] ; then
221 if [ "$ENABLE_INITRAMFS" = true ] ; then
222 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
222 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
223 fi
223 fi
224
224
225 # Create firmware configuration and cmdline symlinks
225 # Create firmware configuration and cmdline symlinks
226 ln -sf firmware/config.txt "${R}/boot/config.txt"
226 ln -sf firmware/config.txt "${R}/boot/config.txt"
227 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
227 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
228
228
229 # Install and setup kernel modules to load at boot
229 # Install and setup kernel modules to load at boot
230 mkdir -p "${LIB_DIR}/modules-load.d/"
230 mkdir -p "${LIB_DIR}/modules-load.d/"
231 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
231 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
232
232
233 # Load hardware random module at boot
233 # Load hardware random module at boot
234 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
234 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
235 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
235 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
236 fi
236 fi
237
237
238 # Load sound module at boot
238 # Load sound module at boot
239 if [ "$ENABLE_SOUND" = true ] ; then
239 if [ "$ENABLE_SOUND" = true ] ; then
240 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
240 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
241 else
241 else
242 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
242 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
243 fi
243 fi
244
244
245 # Enable I2C interface
245 # Enable I2C interface
246 if [ "$ENABLE_I2C" = true ] ; then
246 if [ "$ENABLE_I2C" = true ] ; then
247 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
247 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
248 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
248 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
249 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
249 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
250 fi
250 fi
251
251
252 # Enable SPI interface
252 # Enable SPI interface
253 if [ "$ENABLE_SPI" = true ] ; then
253 if [ "$ENABLE_SPI" = true ] ; then
254 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
254 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
255 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
255 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
256 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
256 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
257 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
257 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
258 fi
258 fi
259 fi
259 fi
260
260
261 # Disable RPi2/3 under-voltage warnings
261 # Disable RPi2/3 under-voltage warnings
262 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
262 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
263 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
263 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
264 fi
264 fi
265
265
266 # Install kernel modules blacklist
266 # Install kernel modules blacklist
267 mkdir -p "${ETC_DIR}/modprobe.d/"
267 mkdir -p "${ETC_DIR}/modprobe.d/"
268 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
268 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
269
269
270 # Install sysctl.d configuration files
270 # Install sysctl.d configuration files
271 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
271 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
@@ -1,874 +1,875
1 #!/bin/sh
1 #!/bin/sh
2 ########################################################################
2 ########################################################################
3 # rpi23-gen-image.sh 2015-2017
3 # rpi23-gen-image.sh 2015-2017
4 #
4 #
5 # Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi
5 # Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi
6 #
6 #
7 # This program is free software; you can redistribute it and/or
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
10 # of the License, or (at your option) any later version.
11 #
11 #
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 #
13 #
14 # Big thanks for patches and enhancements by 20+ github contributors!
14 # Big thanks for patches and enhancements by 20+ github contributors!
15 ########################################################################
15 ########################################################################
16
16
17 # Are we running as root?
17 # Are we running as root?
18 if [ "$(id -u)" -ne "0" ] ; then
18 if [ "$(id -u)" -ne "0" ] ; then
19 echo "error: this script must be executed with root privileges!"
19 echo "error: this script must be executed with root privileges!"
20 exit 1
20 exit 1
21 fi
21 fi
22
22
23 # Check if ./functions.sh script exists
23 # Check if ./functions.sh script exists
24 if [ ! -r "./functions.sh" ] ; then
24 if [ ! -r "./functions.sh" ] ; then
25 echo "error: './functions.sh' required script not found!"
25 echo "error: './functions.sh' required script not found!"
26 exit 1
26 exit 1
27 fi
27 fi
28
28
29 # Load utility functions
29 # Load utility functions
30 . ./functions.sh
30 . ./functions.sh
31
31
32 # Load parameters from configuration template file
32 # Load parameters from configuration template file
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 use_template
34 use_template
35 fi
35 fi
36
36
37 # Introduce settings
37 # Introduce settings
38 set -e
38 set -e
39 echo -n -e "\n#\n# RPi 0/1/2/3 Bootstrap Settings\n#\n"
39 echo -n -e "\n#\n# RPi 0/1/2/3 Bootstrap Settings\n#\n"
40 set -x
40 set -x
41
41
42 # Raspberry Pi model configuration
42 # Raspberry Pi model configuration
43 RPI_MODEL=${RPI_MODEL:=2}
43 RPI_MODEL=${RPI_MODEL:=2}
44
44
45 # Debian release
45 # Debian release
46 RELEASE=${RELEASE:=buster}
46 RELEASE=${RELEASE:=buster}
47
47
48 # Kernel Branch
48 # Kernel Branch
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
50
50
51 # URLs
51 # URLs
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
59 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
59 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
60 NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git}
60 NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git}
61 SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git}
61 SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git}
62
62
63
63 # Kernel deb packages for 32bit kernel
64 # Kernel deb packages for 32bit kernel
64 RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb}
65 RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb}
65 RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb}
66 RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb}
66 # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used
67 # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used
67 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz}
68 RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz}
68 # Default precompiled 64bit kernel
69 # Default precompiled 64bit kernel
69 RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz}
70 RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz}
70 # Generic
71 # Generic
71 RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL}
72 RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL}
72 # Kali kernel src - used if ENABLE_NEXMON=true (they patch the wlan kernel modul)
73 # Kali kernel src - used if ENABLE_NEXMON=true (they patch the wlan kernel modul)
73 KALI_KERNEL_URL=${KALI_KERNEL_URL:=https://github.com/Re4son/re4son-raspberrypi-linux.git}
74 KALI_KERNEL_URL=${KALI_KERNEL_URL:=https://github.com/Re4son/re4son-raspberrypi-linux.git}
74
75
75 # Build directories
76 # Build directories
76 WORKDIR=$(pwd)
77 WORKDIR=$(pwd)
77 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
78 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
78 BUILDDIR="${BASEDIR}/build"
79 BUILDDIR="${BASEDIR}/build"
79
80
80 # Chroot directories
81 # Chroot directories
81 R="${BUILDDIR}/chroot"
82 R="${BUILDDIR}/chroot"
82 ETC_DIR="${R}/etc"
83 ETC_DIR="${R}/etc"
83 LIB_DIR="${R}/lib"
84 LIB_DIR="${R}/lib"
84 BOOT_DIR="${R}/boot/firmware"
85 BOOT_DIR="${R}/boot/firmware"
85 KERNEL_DIR="${R}/usr/src/linux"
86 KERNEL_DIR="${R}/usr/src/linux"
86 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
87 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
87 BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt"
88 BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt"
88
89
89 # Firmware directory: Blank if download from github
90 # Firmware directory: Blank if download from github
90 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
91 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
91
92
92 # General settings
93 # General settings
93 SET_ARCH=${SET_ARCH:=32}
94 SET_ARCH=${SET_ARCH:=32}
94 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
95 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
95 PASSWORD=${PASSWORD:=raspberry}
96 PASSWORD=${PASSWORD:=raspberry}
96 USER_PASSWORD=${USER_PASSWORD:=raspberry}
97 USER_PASSWORD=${USER_PASSWORD:=raspberry}
97 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
98 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
98 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
99 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
99 EXPANDROOT=${EXPANDROOT:=true}
100 EXPANDROOT=${EXPANDROOT:=true}
100
101
101 # Keyboard settings
102 # Keyboard settings
102 XKB_MODEL=${XKB_MODEL:=""}
103 XKB_MODEL=${XKB_MODEL:=""}
103 XKB_LAYOUT=${XKB_LAYOUT:=""}
104 XKB_LAYOUT=${XKB_LAYOUT:=""}
104 XKB_VARIANT=${XKB_VARIANT:=""}
105 XKB_VARIANT=${XKB_VARIANT:=""}
105 XKB_OPTIONS=${XKB_OPTIONS:=""}
106 XKB_OPTIONS=${XKB_OPTIONS:=""}
106
107
107 # Network settings (DHCP)
108 # Network settings (DHCP)
108 ENABLE_DHCP=${ENABLE_DHCP:=true}
109 ENABLE_DHCP=${ENABLE_DHCP:=true}
109
110
110 # Network settings (static)
111 # Network settings (static)
111 NET_ADDRESS=${NET_ADDRESS:=""}
112 NET_ADDRESS=${NET_ADDRESS:=""}
112 NET_GATEWAY=${NET_GATEWAY:=""}
113 NET_GATEWAY=${NET_GATEWAY:=""}
113 NET_DNS_1=${NET_DNS_1:=""}
114 NET_DNS_1=${NET_DNS_1:=""}
114 NET_DNS_2=${NET_DNS_2:=""}
115 NET_DNS_2=${NET_DNS_2:=""}
115 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
116 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
116 NET_NTP_1=${NET_NTP_1:=""}
117 NET_NTP_1=${NET_NTP_1:=""}
117 NET_NTP_2=${NET_NTP_2:=""}
118 NET_NTP_2=${NET_NTP_2:=""}
118
119
119 # APT settings
120 # APT settings
120 APT_PROXY=${APT_PROXY:=""}
121 APT_PROXY=${APT_PROXY:=""}
121 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
122 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
122
123
123 # Feature settings
124 # Feature settings
124 ENABLE_PRINTK=${ENABLE_PRINTK:=false}
125 ENABLE_PRINTK=${ENABLE_PRINTK:=false}
125 ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false}
126 ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false}
126 ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false}
127 ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false}
127 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
128 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
128 ENABLE_I2C=${ENABLE_I2C:=false}
129 ENABLE_I2C=${ENABLE_I2C:=false}
129 ENABLE_SPI=${ENABLE_SPI:=false}
130 ENABLE_SPI=${ENABLE_SPI:=false}
130 ENABLE_IPV6=${ENABLE_IPV6:=true}
131 ENABLE_IPV6=${ENABLE_IPV6:=true}
131 ENABLE_SSHD=${ENABLE_SSHD:=true}
132 ENABLE_SSHD=${ENABLE_SSHD:=true}
132 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
133 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
133 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
134 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
134 ENABLE_SOUND=${ENABLE_SOUND:=true}
135 ENABLE_SOUND=${ENABLE_SOUND:=true}
135 ENABLE_DBUS=${ENABLE_DBUS:=true}
136 ENABLE_DBUS=${ENABLE_DBUS:=true}
136 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
137 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
137 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
138 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
138 ENABLE_XORG=${ENABLE_XORG:=false}
139 ENABLE_XORG=${ENABLE_XORG:=false}
139 ENABLE_WM=${ENABLE_WM:=""}
140 ENABLE_WM=${ENABLE_WM:=""}
140 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
141 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
141 ENABLE_USER=${ENABLE_USER:=true}
142 ENABLE_USER=${ENABLE_USER:=true}
142 USER_NAME=${USER_NAME:="pi"}
143 USER_NAME=${USER_NAME:="pi"}
143 ENABLE_ROOT=${ENABLE_ROOT:=false}
144 ENABLE_ROOT=${ENABLE_ROOT:=false}
144 ENABLE_QEMU=${ENABLE_QEMU:=false}
145 ENABLE_QEMU=${ENABLE_QEMU:=false}
145 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
146 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
146
147
147 # SSH settings
148 # SSH settings
148 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
149 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
149 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
150 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
150 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
151 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
151 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
152 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
152 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
153 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
153
154
154 # Advanced settings
155 # Advanced settings
155 ENABLE_SYSTEMDSWAP=${ENABLE_SYSTEMDSWAP:=false}
156 ENABLE_SYSTEMDSWAP=${ENABLE_SYSTEMDSWAP:=false}
156 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
157 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
157 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
158 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
158 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
159 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
159 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
160 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
160 ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
161 ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
161 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
162 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
162 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false}
163 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false}
163 ENABLE_NEXMON=${ENABLE_NEXMON:=false}
164 ENABLE_NEXMON=${ENABLE_NEXMON:=false}
164 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
165 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
165 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
166 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
166 NEXMONSRC_DIR=${NEXMONSRC_DIR:=""}
167 NEXMONSRC_DIR=${NEXMONSRC_DIR:=""}
167 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
168 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
168 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
169 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
169 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
170 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
170 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
171 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
171 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
172 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
172 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
173 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
173
174
174 # Kernel compilation settings
175 # Kernel compilation settings
175 BUILD_KERNEL=${BUILD_KERNEL:=true}
176 BUILD_KERNEL=${BUILD_KERNEL:=true}
176 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
177 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
177 KERNEL_THREADS=${KERNEL_THREADS:=1}
178 KERNEL_THREADS=${KERNEL_THREADS:=1}
178 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
179 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
179 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
180 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
180 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
181 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
181 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
182 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
182 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
183 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
183 KERNEL_ZSWAP=${KERNEL_ZSWAP:=false}
184 KERNEL_ZSWAP=${KERNEL_ZSWAP:=false}
184 KERNEL_VIRT=${KERNEL_VIRT:=false}
185 KERNEL_VIRT=${KERNEL_VIRT:=false}
185 KERNEL_BPF=${KERNEL_BPF:=false}
186 KERNEL_BPF=${KERNEL_BPF:=false}
186 KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=powersave}
187 KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=powersave}
187 KERNEL_SECURITY=${KERNEL_SECURITY:=false}
188 KERNEL_SECURITY=${KERNEL_SECURITY:=false}
188
189
189 # Kernel compilation from source directory settings
190 # Kernel compilation from source directory settings
190 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
191 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
191 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
192 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
192 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
193 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
193 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
194 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
194
195
195 # Reduce disk usage settings
196 # Reduce disk usage settings
196 REDUCE_APT=${REDUCE_APT:=true}
197 REDUCE_APT=${REDUCE_APT:=true}
197 REDUCE_DOC=${REDUCE_DOC:=true}
198 REDUCE_DOC=${REDUCE_DOC:=true}
198 REDUCE_MAN=${REDUCE_MAN:=true}
199 REDUCE_MAN=${REDUCE_MAN:=true}
199 REDUCE_VIM=${REDUCE_VIM:=false}
200 REDUCE_VIM=${REDUCE_VIM:=false}
200 REDUCE_BASH=${REDUCE_BASH:=false}
201 REDUCE_BASH=${REDUCE_BASH:=false}
201 REDUCE_HWDB=${REDUCE_HWDB:=true}
202 REDUCE_HWDB=${REDUCE_HWDB:=true}
202 REDUCE_SSHD=${REDUCE_SSHD:=true}
203 REDUCE_SSHD=${REDUCE_SSHD:=true}
203 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
204 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
204
205
205 # Encrypted filesystem settings
206 # Encrypted filesystem settings
206 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
207 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
207 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
208 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
208 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
209 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
209 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
210 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
210 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
211 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
211 #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup
212 #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup
212 CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false}
213 CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false}
213 #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated
214 #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated
214 CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""}
215 CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""}
215
216
216 # Chroot scripts directory
217 # Chroot scripts directory
217 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
218 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
218
219
219 # Packages required in the chroot build environment
220 # Packages required in the chroot build environment
220 APT_INCLUDES=${APT_INCLUDES:=""}
221 APT_INCLUDES=${APT_INCLUDES:=""}
221 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd"
222 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd"
222
223
223 #Packages to exclude from chroot build environment
224 #Packages to exclude from chroot build environment
224 APT_EXCLUDES=${APT_EXCLUDES:=""}
225 APT_EXCLUDES=${APT_EXCLUDES:=""}
225
226
226 # Packages required for bootstrapping
227 # Packages required for bootstrapping
227 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
228 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
228 MISSING_PACKAGES=""
229 MISSING_PACKAGES=""
229
230
230 # Packages installed for c/c++ build environment in chroot (keep empty)
231 # Packages installed for c/c++ build environment in chroot (keep empty)
231 COMPILER_PACKAGES=""
232 COMPILER_PACKAGES=""
232
233
233 # Check if apt-cacher-ng has port 3142 open and set APT_PROXY
234 # Check if apt-cacher-ng has port 3142 open and set APT_PROXY
234 APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')
235 APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')
235 if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then
236 if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then
236 APT_PROXY=http://127.0.0.1:3142/
237 APT_PROXY=http://127.0.0.1:3142/
237 fi
238 fi
238
239
239 # netselect-apt does not know buster yet
240 # netselect-apt does not know buster yet
240 if [ "$RELEASE" = "buster" ] ; then
241 if [ "$RELEASE" = "buster" ] ; then
241 RLS=testing
242 RLS=testing
242 else
243 else
243 RLS="$RELEASE"
244 RLS="$RELEASE"
244 fi
245 fi
245
246
246 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
247 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
247 rm "$(pwd)/files/apt/sources.list"
248 rm "$(pwd)/files/apt/sources.list"
248 fi
249 fi
249
250
250 if [ "$ENABLE_NONFREE" = true ] ; then
251 if [ "$ENABLE_NONFREE" = true ] ; then
251 netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
252 netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
252 else
253 else
253 netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
254 netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
254 fi
255 fi
255
256
256 # sed and cut the result string so we can use it as APT_SERVER
257 # sed and cut the result string so we can use it as APT_SERVER
257 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|')
258 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|')
258
259
259 # make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
260 # make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
260 if [ -n "$SET_ARCH" ] ; then
261 if [ -n "$SET_ARCH" ] ; then
261 # 64-bit configuration
262 # 64-bit configuration
262 if [ "$SET_ARCH" = 64 ] ; then
263 if [ "$SET_ARCH" = 64 ] ; then
263 # General 64-bit depended settings
264 # General 64-bit depended settings
264 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
265 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
265 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
266 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
266 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
267 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
267
268
268 # Raspberry Pi model specific settings
269 # Raspberry Pi model specific settings
269 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
270 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
270 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
271 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
271 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
272 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
272 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
273 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
273 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
274 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
274 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
275 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
275 else
276 else
276 echo "error: Only Raspberry PI 3 and 3B+ support 64-bit"
277 echo "error: Only Raspberry PI 3 and 3B+ support 64-bit"
277 exit 1
278 exit 1
278 fi
279 fi
279 fi
280 fi
280
281
281 # 32-bit configuration
282 # 32-bit configuration
282 if [ "$SET_ARCH" = 32 ] ; then
283 if [ "$SET_ARCH" = 32 ] ; then
283 # General 32-bit dependend settings
284 # General 32-bit dependend settings
284 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
285 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
285 KERNEL_ARCH=${KERNEL_ARCH:=arm}
286 KERNEL_ARCH=${KERNEL_ARCH:=arm}
286 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
287 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
287
288
288 # Raspberry Pi model specific settings
289 # Raspberry Pi model specific settings
289 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
290 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
290 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
291 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
291 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
292 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
292 RELEASE_ARCH=${RELEASE_ARCH:=armel}
293 RELEASE_ARCH=${RELEASE_ARCH:=armel}
293 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
294 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
294 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
295 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
295 fi
296 fi
296
297
297 # Raspberry Pi model specific settings
298 # Raspberry Pi model specific settings
298 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
299 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
299 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
300 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
300 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
301 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
301 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
302 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
302 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
303 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
303 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
304 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
304 fi
305 fi
305 fi
306 fi
306 # SET_ARCH not set
307 # SET_ARCH not set
307 else
308 else
308 echo "error: Please set '32' or '64' as value for SET_ARCH"
309 echo "error: Please set '32' or '64' as value for SET_ARCH"
309 exit 1
310 exit 1
310 fi
311 fi
311 # Device specific configuration and U-Boot configuration
312 # Device specific configuration and U-Boot configuration
312 case "$RPI_MODEL" in
313 case "$RPI_MODEL" in
313 0)
314 0)
314 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
315 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
315 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
316 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
316 ;;
317 ;;
317 1)
318 1)
318 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
319 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
319 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
320 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
320 ;;
321 ;;
321 1P)
322 1P)
322 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
323 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
323 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
324 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
324 ;;
325 ;;
325 2)
326 2)
326 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
327 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
327 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
328 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
328 ;;
329 ;;
329 3)
330 3)
330 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
331 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
331 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
332 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
332 ;;
333 ;;
333 3P)
334 3P)
334 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
335 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
335 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
336 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
336 ;;
337 ;;
337 *)
338 *)
338 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
339 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
339 exit 1
340 exit 1
340 ;;
341 ;;
341 esac
342 esac
342
343
343 # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard
344 # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard
344 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
345 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
345 # Include bluetooth packages on supported boards
346 # Include bluetooth packages on supported boards
346 if [ "$ENABLE_BLUETOOTH" = true ] ; then
347 if [ "$ENABLE_BLUETOOTH" = true ] ; then
347 APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez"
348 APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez"
348 fi
349 fi
349 if [ "$ENABLE_WIRELESS" = true ] ; then
350 if [ "$ENABLE_WIRELESS" = true ] ; then
350 APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb"
351 APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb,firmware-brcm80211"
351 fi
352 fi
352 else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard
353 else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard
353 # Check if the internal wireless interface is not supported by the RPi model
354 # Check if the internal wireless interface is not supported by the RPi model
354 if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then
355 if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then
355 echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth"
356 echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth"
356 exit 1
357 exit 1
357 fi
358 fi
358 fi
359 fi
359
360
360 if [ "$BUILD_KERNEL" = false ] && [ "$ENABLE_NEXMON" = true ]; then
361 if [ "$BUILD_KERNEL" = false ] && [ "$ENABLE_NEXMON" = true ]; then
361 echo "error: You have to compile kernel sources, if you want to enable nexmon"
362 echo "error: You have to compile kernel sources, if you want to enable nexmon"
362 exit 1
363 exit 1
363 fi
364 fi
364
365
365 # Prepare date string for default image file name
366 # Prepare date string for default image file name
366 DATE="$(date +%Y-%m-%d)"
367 DATE="$(date +%Y-%m-%d)"
367 if [ -z "$KERNEL_BRANCH" ] ; then
368 if [ -z "$KERNEL_BRANCH" ] ; then
368 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
369 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
369 else
370 else
370 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
371 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
371 fi
372 fi
372
373
373 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
374 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
374 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
375 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
375 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
376 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
376 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
377 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
377 exit 1
378 exit 1
378 fi
379 fi
379 fi
380 fi
380
381
381 set +x
382 set +x
382
383
383 # Add cmake to compile videocore sources
384 # Add cmake to compile videocore sources
384 if [ "$ENABLE_VIDEOCORE" = true ] ; then
385 if [ "$ENABLE_VIDEOCORE" = true ] ; then
385 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
386 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
386 fi
387 fi
387
388
388 # Add deps for nexmon
389 # Add deps for nexmon
389 if [ "$ENABLE_NEXMON" = true ] ; then
390 if [ "$ENABLE_NEXMON" = true ] ; then
390 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool"
391 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool"
391 fi
392 fi
392
393
393 # Add libncurses5 to enable kernel menuconfig
394 # Add libncurses5 to enable kernel menuconfig
394 if [ "$KERNEL_MENUCONFIG" = true ] ; then
395 if [ "$KERNEL_MENUCONFIG" = true ] ; then
395 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
396 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
396 fi
397 fi
397
398
398 # Add ccache compiler cache for (faster) kernel cross (re)compilation
399 # Add ccache compiler cache for (faster) kernel cross (re)compilation
399 if [ "$KERNEL_CCACHE" = true ] ; then
400 if [ "$KERNEL_CCACHE" = true ] ; then
400 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
401 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
401 fi
402 fi
402
403
403 # Add cryptsetup package to enable filesystem encryption
404 # Add cryptsetup package to enable filesystem encryption
404 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
405 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
405 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
406 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
406 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
407 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
407
408
408 # If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package
409 # If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package
409 if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then
410 if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then
410 APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs"
411 APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs"
411 fi
412 fi
412
413
413 if [ -z "$CRYPTFS_PASSWORD" ] ; then
414 if [ -z "$CRYPTFS_PASSWORD" ] ; then
414 echo "error: no password defined (CRYPTFS_PASSWORD)!"
415 echo "error: no password defined (CRYPTFS_PASSWORD)!"
415 exit 1
416 exit 1
416 fi
417 fi
417 ENABLE_INITRAMFS=true
418 ENABLE_INITRAMFS=true
418 fi
419 fi
419
420
420 # Add initramfs generation tools
421 # Add initramfs generation tools
421 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
422 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
422 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
423 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
423 fi
424 fi
424
425
425 # Add device-tree-compiler required for building the U-Boot bootloader
426 # Add device-tree-compiler required for building the U-Boot bootloader
426 if [ "$ENABLE_UBOOT" = true ] ; then
427 if [ "$ENABLE_UBOOT" = true ] ; then
427 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
428 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
428 else
429 else
429 if [ "$ENABLE_UBOOTUSB" = true ] ; then
430 if [ "$ENABLE_UBOOTUSB" = true ] ; then
430 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
431 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
431 exit 1
432 exit 1
432 fi
433 fi
433 fi
434 fi
434
435
435 # Check if root SSH (v2) public key file exists
436 # Check if root SSH (v2) public key file exists
436 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
437 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
437 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
438 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
438 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
439 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
439 exit 1
440 exit 1
440 fi
441 fi
441 fi
442 fi
442
443
443 # Check if $USER_NAME SSH (v2) public key file exists
444 # Check if $USER_NAME SSH (v2) public key file exists
444 if [ -n "$SSH_USER_PUB_KEY" ] ; then
445 if [ -n "$SSH_USER_PUB_KEY" ] ; then
445 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
446 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
446 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
447 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
447 exit 1
448 exit 1
448 fi
449 fi
449 fi
450 fi
450
451
451 if [ "$ENABLE_NEXMON" = true ] && [ -n "$KERNEL_BRANCH" ] ; then
452 if [ "$ENABLE_NEXMON" = true ] && [ -n "$KERNEL_BRANCH" ] ; then
452 echo "error: Please unset KERNEL_BRANCH if using ENABLE_NEXMON"
453 echo "error: Please unset KERNEL_BRANCH if using ENABLE_NEXMON"
453 exit 1
454 exit 1
454 fi
455 fi
455
456
456 # Check if all required packages are installed on the build system
457 # Check if all required packages are installed on the build system
457 for package in $REQUIRED_PACKAGES ; do
458 for package in $REQUIRED_PACKAGES ; do
458 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
459 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
459 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
460 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
460 fi
461 fi
461 done
462 done
462
463
463 # If there are missing packages ask confirmation for install, or exit
464 # If there are missing packages ask confirmation for install, or exit
464 if [ -n "$MISSING_PACKAGES" ] ; then
465 if [ -n "$MISSING_PACKAGES" ] ; then
465 echo "the following packages needed by this script are not installed:"
466 echo "the following packages needed by this script are not installed:"
466 echo "$MISSING_PACKAGES"
467 echo "$MISSING_PACKAGES"
467
468
468 printf "\ndo you want to install the missing packages right now? [y/n] "
469 printf "\ndo you want to install the missing packages right now? [y/n] "
469 read -r confirm
470 read -r confirm
470 [ "$confirm" != "y" ] && exit 1
471 [ "$confirm" != "y" ] && exit 1
471
472
472 # Make sure all missing required packages are installed
473 # Make sure all missing required packages are installed
473 apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"`
474 apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"`
474 fi
475 fi
475
476
476 # Check if ./bootstrap.d directory exists
477 # Check if ./bootstrap.d directory exists
477 if [ ! -d "./bootstrap.d/" ] ; then
478 if [ ! -d "./bootstrap.d/" ] ; then
478 echo "error: './bootstrap.d' required directory not found!"
479 echo "error: './bootstrap.d' required directory not found!"
479 exit 1
480 exit 1
480 fi
481 fi
481
482
482 # Check if ./files directory exists
483 # Check if ./files directory exists
483 if [ ! -d "./files/" ] ; then
484 if [ ! -d "./files/" ] ; then
484 echo "error: './files' required directory not found!"
485 echo "error: './files' required directory not found!"
485 exit 1
486 exit 1
486 fi
487 fi
487
488
488 # Check if specified KERNELSRC_DIR directory exists
489 # Check if specified KERNELSRC_DIR directory exists
489 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
490 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
490 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
491 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
491 exit 1
492 exit 1
492 fi
493 fi
493
494
494 # Check if specified UBOOTSRC_DIR directory exists
495 # Check if specified UBOOTSRC_DIR directory exists
495 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
496 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
496 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
497 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
497 exit 1
498 exit 1
498 fi
499 fi
499
500
500 # Check if specified VIDEOCORESRC_DIR directory exists
501 # Check if specified VIDEOCORESRC_DIR directory exists
501 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
502 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
502 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
503 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
503 exit 1
504 exit 1
504 fi
505 fi
505
506
506 # Check if specified FBTURBOSRC_DIR directory exists
507 # Check if specified FBTURBOSRC_DIR directory exists
507 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
508 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
508 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
509 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
509 exit 1
510 exit 1
510 fi
511 fi
511
512
512 # Check if specified NEXMONSRC_DIR directory exists
513 # Check if specified NEXMONSRC_DIR directory exists
513 if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then
514 if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then
514 echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!"
515 echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!"
515 exit 1
516 exit 1
516 fi
517 fi
517
518
518 # Check if specified CHROOT_SCRIPTS directory exists
519 # Check if specified CHROOT_SCRIPTS directory exists
519 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
520 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
520 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
521 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
521 exit 1
522 exit 1
522 fi
523 fi
523
524
524 # Check if specified device mapping already exists (will be used by cryptsetup)
525 # Check if specified device mapping already exists (will be used by cryptsetup)
525 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
526 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
526 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
527 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
527 exit 1
528 exit 1
528 fi
529 fi
529
530
530 # Don't clobber an old build
531 # Don't clobber an old build
531 if [ -e "$BUILDDIR" ] ; then
532 if [ -e "$BUILDDIR" ] ; then
532 echo "error: directory ${BUILDDIR} already exists, not proceeding"
533 echo "error: directory ${BUILDDIR} already exists, not proceeding"
533 exit 1
534 exit 1
534 fi
535 fi
535
536
536 # Setup chroot directory
537 # Setup chroot directory
537 mkdir -p "${R}"
538 mkdir -p "${R}"
538
539
539 # Check if build directory has enough of free disk space >512MB
540 # Check if build directory has enough of free disk space >512MB
540 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
541 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
541 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
542 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
542 exit 1
543 exit 1
543 fi
544 fi
544
545
545 set -x
546 set -x
546
547
547 # Call "cleanup" function on various signals and errors
548 # Call "cleanup" function on various signals and errors
548 trap cleanup 0 1 2 3 6
549 trap cleanup 0 1 2 3 6
549
550
550 # Add required packages for the minbase installation
551 # Add required packages for the minbase installation
551 if [ "$ENABLE_MINBASE" = true ] ; then
552 if [ "$ENABLE_MINBASE" = true ] ; then
552 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
553 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
553 fi
554 fi
554
555
555 # Add parted package, required to get partprobe utility
556 # Add parted package, required to get partprobe utility
556 if [ "$EXPANDROOT" = true ] ; then
557 if [ "$EXPANDROOT" = true ] ; then
557 APT_INCLUDES="${APT_INCLUDES},parted"
558 APT_INCLUDES="${APT_INCLUDES},parted"
558 fi
559 fi
559
560
560 # Add dbus package, recommended if using systemd
561 # Add dbus package, recommended if using systemd
561 if [ "$ENABLE_DBUS" = true ] ; then
562 if [ "$ENABLE_DBUS" = true ] ; then
562 APT_INCLUDES="${APT_INCLUDES},dbus"
563 APT_INCLUDES="${APT_INCLUDES},dbus"
563 fi
564 fi
564
565
565 # Add iptables IPv4/IPv6 package
566 # Add iptables IPv4/IPv6 package
566 if [ "$ENABLE_IPTABLES" = true ] ; then
567 if [ "$ENABLE_IPTABLES" = true ] ; then
567 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
568 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
568 fi
569 fi
569 # Add apparmor for KERNEL_SECURITY
570 # Add apparmor for KERNEL_SECURITY
570 if [ "$KERNEL_SECURITY" = true ] ; then
571 if [ "$KERNEL_SECURITY" = true ] ; then
571 APT_INCLUDES="${APT_INCLUDES},apparmor,apparmor-utils,apparmor-profiles,apparmor-profiles-extra,libapparmor-perl"
572 APT_INCLUDES="${APT_INCLUDES},apparmor,apparmor-utils,apparmor-profiles,apparmor-profiles-extra,libapparmor-perl"
572 fi
573 fi
573
574
574 # Add openssh server package
575 # Add openssh server package
575 if [ "$ENABLE_SSHD" = true ] ; then
576 if [ "$ENABLE_SSHD" = true ] ; then
576 APT_INCLUDES="${APT_INCLUDES},openssh-server"
577 APT_INCLUDES="${APT_INCLUDES},openssh-server"
577 fi
578 fi
578
579
579 # Add alsa-utils package
580 # Add alsa-utils package
580 if [ "$ENABLE_SOUND" = true ] ; then
581 if [ "$ENABLE_SOUND" = true ] ; then
581 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
582 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
582 fi
583 fi
583
584
584 # Add rng-tools package
585 # Add rng-tools package
585 if [ "$ENABLE_HWRANDOM" = true ] ; then
586 if [ "$ENABLE_HWRANDOM" = true ] ; then
586 APT_INCLUDES="${APT_INCLUDES},rng-tools"
587 APT_INCLUDES="${APT_INCLUDES},rng-tools"
587 fi
588 fi
588
589
589 # Add fbturbo video driver
590 # Add fbturbo video driver
590 if [ "$ENABLE_FBTURBO" = true ] ; then
591 if [ "$ENABLE_FBTURBO" = true ] ; then
591 # Enable xorg package dependencies
592 # Enable xorg package dependencies
592 ENABLE_XORG=true
593 ENABLE_XORG=true
593 fi
594 fi
594
595
595 # Add user defined window manager package
596 # Add user defined window manager package
596 if [ -n "$ENABLE_WM" ] ; then
597 if [ -n "$ENABLE_WM" ] ; then
597 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
598 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
598
599
599 # Enable xorg package dependencies
600 # Enable xorg package dependencies
600 ENABLE_XORG=true
601 ENABLE_XORG=true
601 fi
602 fi
602
603
603 # Add xorg package
604 # Add xorg package
604 if [ "$ENABLE_XORG" = true ] ; then
605 if [ "$ENABLE_XORG" = true ] ; then
605 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
606 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
606 fi
607 fi
607
608
608 # Replace selected packages with smaller clones
609 # Replace selected packages with smaller clones
609 if [ "$ENABLE_REDUCE" = true ] ; then
610 if [ "$ENABLE_REDUCE" = true ] ; then
610 # Add levee package instead of vim-tiny
611 # Add levee package instead of vim-tiny
611 if [ "$REDUCE_VIM" = true ] ; then
612 if [ "$REDUCE_VIM" = true ] ; then
612 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
613 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
613 fi
614 fi
614
615
615 # Add dropbear package instead of openssh-server
616 # Add dropbear package instead of openssh-server
616 if [ "$REDUCE_SSHD" = true ] ; then
617 if [ "$REDUCE_SSHD" = true ] ; then
617 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
618 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
618 fi
619 fi
619 fi
620 fi
620
621
621 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
622 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
622 if [ "$ENABLE_SYSVINIT" = false ] ; then
623 if [ "$ENABLE_SYSVINIT" = false ] ; then
623 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
624 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
624 fi
625 fi
625
626
626 # Configure kernel sources if no KERNELSRC_DIR
627 # Configure kernel sources if no KERNELSRC_DIR
627 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
628 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
628 KERNELSRC_CONFIG=true
629 KERNELSRC_CONFIG=true
629 fi
630 fi
630
631
631 # Configure reduced kernel
632 # Configure reduced kernel
632 if [ "$KERNEL_REDUCE" = true ] ; then
633 if [ "$KERNEL_REDUCE" = true ] ; then
633 KERNELSRC_CONFIG=false
634 KERNELSRC_CONFIG=false
634 fi
635 fi
635
636
636 # Configure qemu compatible kernel
637 # Configure qemu compatible kernel
637 if [ "$ENABLE_QEMU" = true ] ; then
638 if [ "$ENABLE_QEMU" = true ] ; then
638 DTB_FILE=vexpress-v2p-ca15_a7.dtb
639 DTB_FILE=vexpress-v2p-ca15_a7.dtb
639 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
640 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
640 KERNEL_DEFCONFIG="vexpress_defconfig"
641 KERNEL_DEFCONFIG="vexpress_defconfig"
641 if [ "$KERNEL_MENUCONFIG" = false ] ; then
642 if [ "$KERNEL_MENUCONFIG" = false ] ; then
642 KERNEL_OLDDEFCONFIG=true
643 KERNEL_OLDDEFCONFIG=true
643 fi
644 fi
644 fi
645 fi
645
646
646 # Execute bootstrap scripts
647 # Execute bootstrap scripts
647 for SCRIPT in bootstrap.d/*.sh; do
648 for SCRIPT in bootstrap.d/*.sh; do
648 head -n 3 "$SCRIPT"
649 head -n 3 "$SCRIPT"
649 . "$SCRIPT"
650 . "$SCRIPT"
650 done
651 done
651
652
652 ## Execute custom bootstrap scripts
653 ## Execute custom bootstrap scripts
653 if [ -d "custom.d" ] ; then
654 if [ -d "custom.d" ] ; then
654 for SCRIPT in custom.d/*.sh; do
655 for SCRIPT in custom.d/*.sh; do
655 . "$SCRIPT"
656 . "$SCRIPT"
656 done
657 done
657 fi
658 fi
658
659
659 # Execute custom scripts inside the chroot
660 # Execute custom scripts inside the chroot
660 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
661 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
661 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
662 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
662 chroot_exec /bin/bash -x <<'EOF'
663 chroot_exec /bin/bash -x <<'EOF'
663 for SCRIPT in /chroot_scripts/* ; do
664 for SCRIPT in /chroot_scripts/* ; do
664 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
665 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
665 $SCRIPT
666 $SCRIPT
666 fi
667 fi
667 done
668 done
668 EOF
669 EOF
669 rm -rf "${R}/chroot_scripts"
670 rm -rf "${R}/chroot_scripts"
670 fi
671 fi
671
672
672 # Remove c/c++ build environment from the chroot
673 # Remove c/c++ build environment from the chroot
673 chroot_remove_cc
674 chroot_remove_cc
674
675
675 # Generate required machine-id
676 # Generate required machine-id
676 MACHINE_ID=$(dbus-uuidgen)
677 MACHINE_ID=$(dbus-uuidgen)
677 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
678 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
678 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
679 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
679
680
680 # APT Cleanup
681 # APT Cleanup
681 chroot_exec apt-get -y clean
682 chroot_exec apt-get -y clean
682 chroot_exec apt-get -y autoclean
683 chroot_exec apt-get -y autoclean
683 chroot_exec apt-get -y autoremove
684 chroot_exec apt-get -y autoremove
684
685
685 # Unmount mounted filesystems
686 # Unmount mounted filesystems
686 umount -l "${R}/proc"
687 umount -l "${R}/proc"
687 umount -l "${R}/sys"
688 umount -l "${R}/sys"
688
689
689 # Clean up directories
690 # Clean up directories
690 rm -rf "${R}/run/*"
691 rm -rf "${R}/run/*"
691 rm -rf "${R}/tmp/*"
692 rm -rf "${R}/tmp/*"
692
693
693 # Clean up files
694 # Clean up files
694 rm -f "${ETC_DIR}/ssh/ssh_host_*"
695 rm -f "${ETC_DIR}/ssh/ssh_host_*"
695 rm -f "${ETC_DIR}/dropbear/dropbear_*"
696 rm -f "${ETC_DIR}/dropbear/dropbear_*"
696 rm -f "${ETC_DIR}/apt/sources.list.save"
697 rm -f "${ETC_DIR}/apt/sources.list.save"
697 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
698 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
698 rm -f "${ETC_DIR}/*-"
699 rm -f "${ETC_DIR}/*-"
699 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
700 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
700 rm -f "${ETC_DIR}/resolv.conf"
701 rm -f "${ETC_DIR}/resolv.conf"
701 rm -f "${R}/root/.bash_history"
702 rm -f "${R}/root/.bash_history"
702 rm -f "${R}/var/lib/urandom/random-seed"
703 rm -f "${R}/var/lib/urandom/random-seed"
703 rm -f "${R}/initrd.img"
704 rm -f "${R}/initrd.img"
704 rm -f "${R}/vmlinuz"
705 rm -f "${R}/vmlinuz"
705 rm -f "${R}${QEMU_BINARY}"
706 rm -f "${R}${QEMU_BINARY}"
706
707
707 if [ "$ENABLE_QEMU" = true ] ; then
708 if [ "$ENABLE_QEMU" = true ] ; then
708 # Setup QEMU directory
709 # Setup QEMU directory
709 mkdir "${BASEDIR}/qemu"
710 mkdir "${BASEDIR}/qemu"
710
711
711 # Copy kernel image to QEMU directory
712 # Copy kernel image to QEMU directory
712 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
713 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
713
714
714 # Copy kernel config to QEMU directory
715 # Copy kernel config to QEMU directory
715 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
716 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
716
717
717 # Copy kernel dtbs to QEMU directory
718 # Copy kernel dtbs to QEMU directory
718 for dtb in "${BOOT_DIR}/"*.dtb ; do
719 for dtb in "${BOOT_DIR}/"*.dtb ; do
719 if [ -f "${dtb}" ] ; then
720 if [ -f "${dtb}" ] ; then
720 install_readonly "${dtb}" "${BASEDIR}/qemu/"
721 install_readonly "${dtb}" "${BASEDIR}/qemu/"
721 fi
722 fi
722 done
723 done
723
724
724 # Copy kernel overlays to QEMU directory
725 # Copy kernel overlays to QEMU directory
725 if [ -d "${BOOT_DIR}/overlays" ] ; then
726 if [ -d "${BOOT_DIR}/overlays" ] ; then
726 # Setup overlays dtbs directory
727 # Setup overlays dtbs directory
727 mkdir "${BASEDIR}/qemu/overlays"
728 mkdir "${BASEDIR}/qemu/overlays"
728
729
729 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
730 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
730 if [ -f "${dtb}" ] ; then
731 if [ -f "${dtb}" ] ; then
731 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
732 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
732 fi
733 fi
733 done
734 done
734 fi
735 fi
735
736
736 # Copy u-boot files to QEMU directory
737 # Copy u-boot files to QEMU directory
737 if [ "$ENABLE_UBOOT" = true ] ; then
738 if [ "$ENABLE_UBOOT" = true ] ; then
738 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
739 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
739 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
740 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
740 fi
741 fi
741 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
742 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
742 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
743 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
743 fi
744 fi
744 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
745 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
745 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
746 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
746 fi
747 fi
747 fi
748 fi
748
749
749 # Copy initramfs to QEMU directory
750 # Copy initramfs to QEMU directory
750 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
751 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
751 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
752 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
752 fi
753 fi
753 fi
754 fi
754
755
755 # Calculate size of the chroot directory in KB
756 # Calculate size of the chroot directory in KB
756 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
757 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
757
758
758 # Calculate the amount of needed 512 Byte sectors
759 # Calculate the amount of needed 512 Byte sectors
759 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
760 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
760 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
761 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
761 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
762 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
762
763
763 # The root partition is EXT4
764 # The root partition is EXT4
764 # This means more space than the actual used space of the chroot is used.
765 # This means more space than the actual used space of the chroot is used.
765 # As overhead for journaling and reserved blocks 35% are added.
766 # As overhead for journaling and reserved blocks 35% are added.
766 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
767 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
767
768
768 # Calculate required image size in 512 Byte sectors
769 # Calculate required image size in 512 Byte sectors
769 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
770 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
770
771
771 # Prepare image file
772 # Prepare image file
772 if [ "$ENABLE_SPLITFS" = true ] ; then
773 if [ "$ENABLE_SPLITFS" = true ] ; then
773 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
774 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
774 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
775 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
775 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
776 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
776 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
777 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
777
778
778 # Write firmware/boot partition tables
779 # Write firmware/boot partition tables
779 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
780 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
780 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
781 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
781 EOM
782 EOM
782
783
783 # Write root partition table
784 # Write root partition table
784 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
785 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
785 ${TABLE_SECTORS},${ROOT_SECTORS},83
786 ${TABLE_SECTORS},${ROOT_SECTORS},83
786 EOM
787 EOM
787
788
788 # Setup temporary loop devices
789 # Setup temporary loop devices
789 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
790 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
790 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
791 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
791 else # ENABLE_SPLITFS=false
792 else # ENABLE_SPLITFS=false
792 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
793 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
793 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
794 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
794
795
795 # Write partition table
796 # Write partition table
796 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
797 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
797 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
798 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
798 ${ROOT_OFFSET},${ROOT_SECTORS},83
799 ${ROOT_OFFSET},${ROOT_SECTORS},83
799 EOM
800 EOM
800
801
801 # Setup temporary loop devices
802 # Setup temporary loop devices
802 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
803 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
803 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
804 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
804 fi
805 fi
805
806
806 if [ "$ENABLE_CRYPTFS" = true ] ; then
807 if [ "$ENABLE_CRYPTFS" = true ] ; then
807 # Create dummy ext4 fs
808 # Create dummy ext4 fs
808 mkfs.ext4 "$ROOT_LOOP"
809 mkfs.ext4 "$ROOT_LOOP"
809
810
810 # Setup password keyfile
811 # Setup password keyfile
811 touch .password
812 touch .password
812 chmod 600 .password
813 chmod 600 .password
813 echo -n ${CRYPTFS_PASSWORD} > .password
814 echo -n ${CRYPTFS_PASSWORD} > .password
814
815
815 # Initialize encrypted partition
816 # Initialize encrypted partition
816 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
817 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
817
818
818 # Open encrypted partition and setup mapping
819 # Open encrypted partition and setup mapping
819 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
820 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
820
821
821 # Secure delete password keyfile
822 # Secure delete password keyfile
822 shred -zu .password
823 shred -zu .password
823
824
824 # Update temporary loop device
825 # Update temporary loop device
825 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
826 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
826
827
827 # Wipe encrypted partition (encryption cipher is used for randomness)
828 # Wipe encrypted partition (encryption cipher is used for randomness)
828 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
829 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
829 fi
830 fi
830
831
831 # Build filesystems
832 # Build filesystems
832 mkfs.vfat "$FRMW_LOOP"
833 mkfs.vfat "$FRMW_LOOP"
833 mkfs.ext4 "$ROOT_LOOP"
834 mkfs.ext4 "$ROOT_LOOP"
834
835
835 # Mount the temporary loop devices
836 # Mount the temporary loop devices
836 mkdir -p "$BUILDDIR/mount"
837 mkdir -p "$BUILDDIR/mount"
837 mount "$ROOT_LOOP" "$BUILDDIR/mount"
838 mount "$ROOT_LOOP" "$BUILDDIR/mount"
838
839
839 mkdir -p "$BUILDDIR/mount/boot/firmware"
840 mkdir -p "$BUILDDIR/mount/boot/firmware"
840 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
841 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
841
842
842 # Copy all files from the chroot to the loop device mount point directory
843 # Copy all files from the chroot to the loop device mount point directory
843 rsync -a "${R}/" "$BUILDDIR/mount/"
844 rsync -a "${R}/" "$BUILDDIR/mount/"
844
845
845 # Unmount all temporary loop devices and mount points
846 # Unmount all temporary loop devices and mount points
846 cleanup
847 cleanup
847
848
848 # Create block map file(s) of image(s)
849 # Create block map file(s) of image(s)
849 if [ "$ENABLE_SPLITFS" = true ] ; then
850 if [ "$ENABLE_SPLITFS" = true ] ; then
850 # Create block map files for "bmaptool"
851 # Create block map files for "bmaptool"
851 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
852 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
852 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
853 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
853
854
854 # Image was successfully created
855 # Image was successfully created
855 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
856 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
856 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
857 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
857 else
858 else
858 # Create block map file for "bmaptool"
859 # Create block map file for "bmaptool"
859 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
860 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
860
861
861 # Image was successfully created
862 # Image was successfully created
862 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
863 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
863
864
864 # Create qemu qcow2 image
865 # Create qemu qcow2 image
865 if [ "$ENABLE_QEMU" = true ] ; then
866 if [ "$ENABLE_QEMU" = true ] ; then
866 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
867 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
867 QEMU_SIZE=16G
868 QEMU_SIZE=16G
868
869
869 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
870 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
870 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
871 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
871
872
872 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
873 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
873 fi
874 fi
874 fi
875 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant