##// END OF EJS Templates
fix: typos in DTB for all
drtyhlpr -
r261:91e980935736
parent child
Show More
@@ -1,56 +1,59
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 # Add usb/sda disk root partition to fstab
11 # Add usb/sda disk root partition to fstab
12 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
12 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
13 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
13 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
14 fi
14 fi
15
15
16 # Add encrypted root partition to fstab and crypttab
16 # Add encrypted root partition to fstab and crypttab
17 if [ "$ENABLE_CRYPTFS" = true ] ; then
17 if [ "$ENABLE_CRYPTFS" = true ] ; then
18 # Replace fstab root partition with encrypted partition mapping
18 # Replace fstab root partition with encrypted partition mapping
19 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
19 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
20
20
21 # Add encrypted partition to crypttab and fstab
21 # Add encrypted partition to crypttab and fstab
22 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
22 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
23 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
23 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
24
24
25 if [ "$ENABLE_SPLITFS" = true ] ; then
25 if [ "$ENABLE_SPLITFS" = true ] ; then
26 # Add usb/sda disk to crypttab
26 # Add usb/sda disk to crypttab
27 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
27 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
28 fi
28 fi
29 fi
29 fi
30
30
31 # Generate initramfs file
31 # Generate initramfs file
32 if [ "$BUILD_KERNEL" = true ] && [ "$ENABLE_INITRAMFS" = true ] ; then
32 if [ "$BUILD_KERNEL" = true ] && [ "$ENABLE_INITRAMFS" = true ] ; then
33 if [ "$ENABLE_CRYPTFS" = true ] ; then
33 if [ "$ENABLE_CRYPTFS" = true ] ; then
34 # Include initramfs scripts to auto expand encrypted root partition
34 # Include initramfs scripts to auto expand encrypted root partition
35 if [ "$EXPANDROOT" = true ] ; then
35 if [ "$EXPANDROOT" = true ] ; then
36 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
36 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
37 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
37 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
38 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
38 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
39 fi
39 fi
40
40
41 # Disable SSHD inside initramfs
41 # Disable SSHD inside initramfs
42 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
42 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
43
43
44 # Add cryptsetup modules to initramfs
45 printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook"
46
44 # Dummy mapping required by mkinitramfs
47 # Dummy mapping required by mkinitramfs
45 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
48 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
46
49
47 # Generate initramfs with encrypted root partition support
50 # Generate initramfs with encrypted root partition support
48 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
51 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
49
52
50 # Remove dummy mapping
53 # Remove dummy mapping
51 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
54 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
52 else
55 else
53 # Generate initramfs without encrypted root partition support
56 # Generate initramfs without encrypted root partition support
54 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
57 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
55 fi
58 fi
56 fi
59 fi
@@ -1,746 +1,752
1 #!/bin/sh
1 #!/bin/sh
2
2
3 ########################################################################
3 ########################################################################
4 # rpi23-gen-image.sh 2015-2017
4 # rpi23-gen-image.sh 2015-2017
5 #
5 #
6 # Advanced Debian "jessie", "stretch" and "buster" bootstrap script for RPi2/3
6 # Advanced Debian "jessie", "stretch" and "buster" bootstrap script for RPi2/3
7 #
7 #
8 # This program is free software; you can redistribute it and/or
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
11 # of the License, or (at your option) any later version.
12 #
12 #
13 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
14 #
14 #
15 # Big thanks for patches and enhancements by 20+ github contributors!
15 # Big thanks for patches and enhancements by 20+ github contributors!
16 ########################################################################
16 ########################################################################
17
17
18 # Are we running as root?
18 # Are we running as root?
19 if [ "$(id -u)" -ne "0" ] ; then
19 if [ "$(id -u)" -ne "0" ] ; then
20 echo "error: this script must be executed with root privileges!"
20 echo "error: this script must be executed with root privileges!"
21 exit 1
21 exit 1
22 fi
22 fi
23
23
24 # Check if ./functions.sh script exists
24 # Check if ./functions.sh script exists
25 if [ ! -r "./functions.sh" ] ; then
25 if [ ! -r "./functions.sh" ] ; then
26 echo "error: './functions.sh' required script not found!"
26 echo "error: './functions.sh' required script not found!"
27 exit 1
27 exit 1
28 fi
28 fi
29
29
30 # Load utility functions
30 # Load utility functions
31 . ./functions.sh
31 . ./functions.sh
32
32
33 # Load parameters from configuration template file
33 # Load parameters from configuration template file
34 if [ ! -z "$CONFIG_TEMPLATE" ] ; then
34 if [ ! -z "$CONFIG_TEMPLATE" ] ; then
35 use_template
35 use_template
36 fi
36 fi
37
37
38 # Introduce settings
38 # Introduce settings
39 set -e
39 set -e
40 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
40 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
41 set -x
41 set -x
42
42
43 # Raspberry Pi model configuration
43 # Raspberry Pi model configuration
44 RPI_MODEL=${RPI_MODEL:=2}
44 RPI_MODEL=${RPI_MODEL:=2}
45
45 #bcm2708-rpi-0-w.dtb (Used for Pi 0 and PI 0W)
46 #bcm2708-rpi-0-w.dtb (Used for Pi 0 and PI 0W)
46 RPI0_DTB_FILE=${RPI0_DTB_FILE:=bcm2708-rpi-0-w.dtb}
47 RPI0_DTB_FILE=${RPI0_DTB_FILE:=bcm2708-rpi-0-w.dtb}
47 RPI0_UBOOT_CONFIG=${RPI0_UBOOT_CONFIG:=rpi_defconfig}
48 RPI0_UBOOT_CONFIG=${RPI0_UBOOT_CONFIG:=rpi_defconfig}
49
48 #bcm2708-rpi-b.dtb (Used for Pi 1 model A and B)
50 #bcm2708-rpi-b.dtb (Used for Pi 1 model A and B)
49 RPI1_DTB_FILE=${RPI1_DTB_FILE:=bcm2708-rpi-b.dtb}
51 RPI1_DTB_FILE=${RPI1_DTB_FILE:=bcm2708-rpi-b.dtb}
50 RPI1_UBOOT_CONFIG=${RPI1_UBOOT_CONFIG:=rpi_defconfig}
52 RPI1_UBOOT_CONFIG=${RPI1_UBOOT_CONFIG:=rpi_defconfig}
53
51 #bcm2708-rpi-b-plus.dtb (Used for Pi 1 model B+ and A+)
54 #bcm2708-rpi-b-plus.dtb (Used for Pi 1 model B+ and A+)
52 RPI1P_DTB_FILE=${RPI1P_DTB_FILE:=bcm2708-rpi-b-plus.dtb}
55 RPI1P_DTB_FILE=${RPI1P_DTB_FILE:=bcm2708-rpi-b-plus.dtb}
53 RPI1P_UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG:=rpi_defconfig}
56 RPI1P_UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG:=rpi_defconfig}
57
54 #bcm2709-rpi-2-b.dtb (Used for Pi 2 model B)
58 #bcm2709-rpi-2-b.dtb (Used for Pi 2 model B)
55 RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb}
59 RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb}
56 RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig}
60 RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig}
61
57 #bcm2710-rpi-3-b.dtb (Used for Pi 3 model B)
62 #bcm2710-rpi-3-b.dtb (Used for Pi 3 model B)
58 RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb}
63 RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb}
59 RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig}
64 RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig}
65
60 #bcm2710-rpi-3-b-plus.dtb (Used for Pi 3 model B+)
66 #bcm2710-rpi-3-b-plus.dtb (Used for Pi 3 model B+)
61 RPI3P_DTB_FILE=${RPI3P_DTB_FILE:=bcm2710-rpi-3-b-plus.dtb}
67 RPI3P_DTB_FILE=${RPI3P_DTB_FILE:=bcm2710-rpi-3-b-plus.dtb}
62 RPI3P_UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG:=rpi_3_32b_defconfig}
68 RPI3P_UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG:=rpi_3_32b_defconfig}
63
69
64 # Debian release
70 # Debian release
65 RELEASE=${RELEASE:=jessie}
71 RELEASE=${RELEASE:=jessie}
66 KERNEL_ARCH=${KERNEL_ARCH:=arm}
72 KERNEL_ARCH=${KERNEL_ARCH:=arm}
67 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
73 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
68 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
74 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
69 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
75 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
70 if [ "$KERNEL_ARCH" = "arm64" ] ; then
76 if [ "$KERNEL_ARCH" = "arm64" ] ; then
71 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
77 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
72 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
78 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
73 fi
79 fi
74
80
75 if [ "$RPI_MODEL" = 0 || "$RPI_MODEL" = 1 || "$RPI_MODEL" = 1P ] ; then
81 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
76 #RASPBERRY PI 1, PI ZERO, PI ZERO W, AND COMPUTE MODULE DEFAULT Kernel BUILD CONFIGURATION
82 #RASPBERRY PI 1, PI ZERO, PI ZERO W, AND COMPUTE MODULE DEFAULT Kernel BUILD CONFIGURATION
77 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
83 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
78 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
84 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
79 else
85 else
80 #RASPBERRY PI 2, PI 3, PI 3+, AND COMPUTE MODULE 3 DEFAULT Kernel BUILD CONFIGURATION
86 #RASPBERRY PI 2, PI 3, PI 3+, AND COMPUTE MODULE 3 DEFAULT Kernel BUILD CONFIGURATION
81 #https://www.raspberrypi.org/documentation/linux/kernel/building.md
87 #https://www.raspberrypi.org/documentation/linux/kernel/building.md
82 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
88 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
83 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
89 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
84 fi
90 fi
85
91
86 if [ "$RELEASE_ARCH" = "arm64" ] ; then
92 if [ "$RELEASE_ARCH" = "arm64" ] ; then
87 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
93 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
88 else
94 else
89 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
95 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
90 fi
96 fi
91 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
97 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
92
98
93 # URLs
99 # URLs
94 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
100 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
95 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
101 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
96 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
102 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
97 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
103 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
98 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
104 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
99 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
105 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
100
106
101 # Build directories
107 # Build directories
102 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
108 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
103 BUILDDIR="${BASEDIR}/build"
109 BUILDDIR="${BASEDIR}/build"
104
110
105 # Prepare date string for default image file name
111 # Prepare date string for default image file name
106 DATE="$(date +%Y-%m-%d)"
112 DATE="$(date +%Y-%m-%d)"
107 if [ -z "$KERNEL_BRANCH" ] ; then
113 if [ -z "$KERNEL_BRANCH" ] ; then
108 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
114 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
109 else
115 else
110 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
116 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
111 fi
117 fi
112
118
113 # Chroot directories
119 # Chroot directories
114 R="${BUILDDIR}/chroot"
120 R="${BUILDDIR}/chroot"
115 ETC_DIR="${R}/etc"
121 ETC_DIR="${R}/etc"
116 LIB_DIR="${R}/lib"
122 LIB_DIR="${R}/lib"
117 BOOT_DIR="${R}/boot/firmware"
123 BOOT_DIR="${R}/boot/firmware"
118 KERNEL_DIR="${R}/usr/src/linux"
124 KERNEL_DIR="${R}/usr/src/linux"
119 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
125 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
120
126
121 # Firmware directory: Blank if download from github
127 # Firmware directory: Blank if download from github
122 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
128 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
123
129
124 # General settings
130 # General settings
125 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
131 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
126 PASSWORD=${PASSWORD:=raspberry}
132 PASSWORD=${PASSWORD:=raspberry}
127 USER_PASSWORD=${USER_PASSWORD:=raspberry}
133 USER_PASSWORD=${USER_PASSWORD:=raspberry}
128 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
134 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
129 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
135 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
130 EXPANDROOT=${EXPANDROOT:=true}
136 EXPANDROOT=${EXPANDROOT:=true}
131
137
132 # Keyboard settings
138 # Keyboard settings
133 XKB_MODEL=${XKB_MODEL:=""}
139 XKB_MODEL=${XKB_MODEL:=""}
134 XKB_LAYOUT=${XKB_LAYOUT:=""}
140 XKB_LAYOUT=${XKB_LAYOUT:=""}
135 XKB_VARIANT=${XKB_VARIANT:=""}
141 XKB_VARIANT=${XKB_VARIANT:=""}
136 XKB_OPTIONS=${XKB_OPTIONS:=""}
142 XKB_OPTIONS=${XKB_OPTIONS:=""}
137
143
138 # Network settings (DHCP)
144 # Network settings (DHCP)
139 ENABLE_DHCP=${ENABLE_DHCP:=true}
145 ENABLE_DHCP=${ENABLE_DHCP:=true}
140
146
141 # Network settings (static)
147 # Network settings (static)
142 NET_ADDRESS=${NET_ADDRESS:=""}
148 NET_ADDRESS=${NET_ADDRESS:=""}
143 NET_GATEWAY=${NET_GATEWAY:=""}
149 NET_GATEWAY=${NET_GATEWAY:=""}
144 NET_DNS_1=${NET_DNS_1:=""}
150 NET_DNS_1=${NET_DNS_1:=""}
145 NET_DNS_2=${NET_DNS_2:=""}
151 NET_DNS_2=${NET_DNS_2:=""}
146 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
152 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
147 NET_NTP_1=${NET_NTP_1:=""}
153 NET_NTP_1=${NET_NTP_1:=""}
148 NET_NTP_2=${NET_NTP_2:=""}
154 NET_NTP_2=${NET_NTP_2:=""}
149
155
150 # APT settings
156 # APT settings
151 APT_PROXY=${APT_PROXY:=""}
157 APT_PROXY=${APT_PROXY:=""}
152 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
158 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
153
159
154 # Feature settings
160 # Feature settings
155 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
161 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
156 ENABLE_I2C=${ENABLE_I2C:=false}
162 ENABLE_I2C=${ENABLE_I2C:=false}
157 ENABLE_SPI=${ENABLE_SPI:=false}
163 ENABLE_SPI=${ENABLE_SPI:=false}
158 ENABLE_IPV6=${ENABLE_IPV6:=true}
164 ENABLE_IPV6=${ENABLE_IPV6:=true}
159 ENABLE_SSHD=${ENABLE_SSHD:=true}
165 ENABLE_SSHD=${ENABLE_SSHD:=true}
160 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
166 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
161 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
167 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
162 ENABLE_SOUND=${ENABLE_SOUND:=true}
168 ENABLE_SOUND=${ENABLE_SOUND:=true}
163 ENABLE_DBUS=${ENABLE_DBUS:=true}
169 ENABLE_DBUS=${ENABLE_DBUS:=true}
164 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
170 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
165 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
171 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
166 ENABLE_XORG=${ENABLE_XORG:=false}
172 ENABLE_XORG=${ENABLE_XORG:=false}
167 ENABLE_WM=${ENABLE_WM:=""}
173 ENABLE_WM=${ENABLE_WM:=""}
168 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
174 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
169 ENABLE_USER=${ENABLE_USER:=true}
175 ENABLE_USER=${ENABLE_USER:=true}
170 USER_NAME=${USER_NAME:="pi"}
176 USER_NAME=${USER_NAME:="pi"}
171 ENABLE_ROOT=${ENABLE_ROOT:=false}
177 ENABLE_ROOT=${ENABLE_ROOT:=false}
172 ENABLE_QEMU=${ENABLE_QEMU:=false}
178 ENABLE_QEMU=${ENABLE_QEMU:=false}
173
179
174 # SSH settings
180 # SSH settings
175 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
181 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
176 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
182 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
177 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
183 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
178 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
184 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
179 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
185 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
180
186
181 # Advanced settings
187 # Advanced settings
182 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
188 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
183 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
189 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
184 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
190 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
185 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
191 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
186 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
192 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
187 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
193 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
188 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
194 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
189 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
195 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
190 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
196 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
191 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
197 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
192 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
198 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
193 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
199 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
194
200
195 # Kernel compilation settings
201 # Kernel compilation settings
196 BUILD_KERNEL=${BUILD_KERNEL:=false}
202 BUILD_KERNEL=${BUILD_KERNEL:=false}
197 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
203 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
198 KERNEL_THREADS=${KERNEL_THREADS:=1}
204 KERNEL_THREADS=${KERNEL_THREADS:=1}
199 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
205 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
200 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
206 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
201 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
207 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
202 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
208 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
203 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
209 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
204
210
205 if [ "$KERNEL_ARCH" = "arm64" ] ; then
211 if [ "$KERNEL_ARCH" = "arm64" ] ; then
206 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
212 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
207 else
213 else
208 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
214 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
209 fi
215 fi
210
216
211 # Kernel compilation from source directory settings
217 # Kernel compilation from source directory settings
212 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
218 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
213 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
219 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
214 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
220 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
215 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
221 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
216
222
217 # Reduce disk usage settings
223 # Reduce disk usage settings
218 REDUCE_APT=${REDUCE_APT:=true}
224 REDUCE_APT=${REDUCE_APT:=true}
219 REDUCE_DOC=${REDUCE_DOC:=true}
225 REDUCE_DOC=${REDUCE_DOC:=true}
220 REDUCE_MAN=${REDUCE_MAN:=true}
226 REDUCE_MAN=${REDUCE_MAN:=true}
221 REDUCE_VIM=${REDUCE_VIM:=false}
227 REDUCE_VIM=${REDUCE_VIM:=false}
222 REDUCE_BASH=${REDUCE_BASH:=false}
228 REDUCE_BASH=${REDUCE_BASH:=false}
223 REDUCE_HWDB=${REDUCE_HWDB:=true}
229 REDUCE_HWDB=${REDUCE_HWDB:=true}
224 REDUCE_SSHD=${REDUCE_SSHD:=true}
230 REDUCE_SSHD=${REDUCE_SSHD:=true}
225 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
231 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
226
232
227 # Encrypted filesystem settings
233 # Encrypted filesystem settings
228 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
234 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
229 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
235 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
230 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
236 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
231 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
237 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
232 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
238 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
233
239
234 # Chroot scripts directory
240 # Chroot scripts directory
235 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
241 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
236
242
237 # Packages required in the chroot build environment
243 # Packages required in the chroot build environment
238 APT_INCLUDES=${APT_INCLUDES:=""}
244 APT_INCLUDES=${APT_INCLUDES:=""}
239 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
245 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
240
246
241 # Packages required for bootstrapping
247 # Packages required for bootstrapping
242 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
248 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
243 MISSING_PACKAGES=""
249 MISSING_PACKAGES=""
244
250
245 # Packages installed for c/c++ build environment in chroot (keep empty)
251 # Packages installed for c/c++ build environment in chroot (keep empty)
246 COMPILER_PACKAGES=""
252 COMPILER_PACKAGES=""
247
253
248 set +x
254 set +x
249
255
250 # Set Raspberry Pi model specific configuration
256 # Set Raspberry Pi model specific configuration
251 if [ "$RPI_MODEL" = 0 ] ; then
257 if [ "$RPI_MODEL" = 0 ] ; then
252 DTB_FILE=${RPI2_DTB_FILE}
258 DTB_FILE=${RPI2_DTB_FILE}
253 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
259 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
254 elif [ "$RPI_MODEL" = 1 ] ; then
260 elif [ "$RPI_MODEL" = 1 ] ; then
255 DTB_FILE=${RPI2_DTB_FILE}
261 DTB_FILE=${RPI2_DTB_FILE}
256 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
262 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
257 elif [ "$RPI_MODEL" = 1P ] ; then
263 elif [ "$RPI_MODEL" = 1P ] ; then
258 DTB_FILE=${RPI2_DTB_FILE}
264 DTB_FILE=${RPI2_DTB_FILE}
259 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
265 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
260 elif [ "$RPI_MODEL" = 2 ] ; then
266 elif [ "$RPI_MODEL" = 2 ] ; then
261 DTB_FILE=${RPI2_DTB_FILE}
267 DTB_FILE=${RPI2_DTB_FILE}
262 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
268 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
263 elif [ "$RPI_MODEL" = 3 ] ; then
269 elif [ "$RPI_MODEL" = 3 ] ; then
264 DTB_FILE=${RPI3_DTB_FILE}
270 DTB_FILE=${RPI3_DTB_FILE}
265 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
271 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
266 BUILD_KERNEL=true
272 BUILD_KERNEL=true
267 elif [ "$RPI_MODEL" = 3P ] ; then
273 elif [ "$RPI_MODEL" = 3P ] ; then
268 DTB_FILE=${RPI3P_DTB_FILE}
274 DTB_FILE=${RPI3P_DTB_FILE}
269 UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG}
275 UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG}
270 BUILD_KERNEL=true
276 BUILD_KERNEL=true
271 else
277 else
272 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
278 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
273 exit 1
279 exit 1
274 fi
280 fi
275
281
276 # Check if the internal wireless interface is supported by the RPi model
282 # Check if the internal wireless interface is supported by the RPi model
277 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" = 2 ]; then
283 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" = 2 ]; then
278 echo "error: The selected Raspberry Pi model has no internal wireless interface"
284 echo "error: The selected Raspberry Pi model has no internal wireless interface"
279 exit 1
285 exit 1
280 fi
286 fi
281
287
282 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
288 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
283 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
289 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
284 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
290 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
285 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
291 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
286 exit 1
292 exit 1
287 fi
293 fi
288 fi
294 fi
289
295
290 # Build RPi2/3 Linux kernel if required by Debian release
296 # Build RPi2/3 Linux kernel if required by Debian release
291 if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
297 if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
292 BUILD_KERNEL=true
298 BUILD_KERNEL=true
293 fi
299 fi
294
300
295 # Add packages required for kernel cross compilation
301 # Add packages required for kernel cross compilation
296 if [ "$BUILD_KERNEL" = true ] ; then
302 if [ "$BUILD_KERNEL" = true ] ; then
297 if [ "$KERNEL_ARCH" = "arm" ] ; then
303 if [ "$KERNEL_ARCH" = "arm" ] ; then
298 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
304 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
299 else
305 else
300 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
306 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
301 fi
307 fi
302 fi
308 fi
303
309
304 # Add libncurses5 to enable kernel menuconfig
310 # Add libncurses5 to enable kernel menuconfig
305 if [ "$KERNEL_MENUCONFIG" = true ] ; then
311 if [ "$KERNEL_MENUCONFIG" = true ] ; then
306 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
312 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
307 fi
313 fi
308
314
309 # Add ccache compiler cache for (faster) kernel cross (re)compilation
315 # Add ccache compiler cache for (faster) kernel cross (re)compilation
310 if [ "$KERNEL_CCACHE" = true ] ; then
316 if [ "$KERNEL_CCACHE" = true ] ; then
311 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
317 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
312 fi
318 fi
313
319
314 # Add cryptsetup package to enable filesystem encryption
320 # Add cryptsetup package to enable filesystem encryption
315 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
321 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
316 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
322 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
317 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
323 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
318
324
319 if [ -z "$CRYPTFS_PASSWORD" ] ; then
325 if [ -z "$CRYPTFS_PASSWORD" ] ; then
320 echo "error: no password defined (CRYPTFS_PASSWORD)!"
326 echo "error: no password defined (CRYPTFS_PASSWORD)!"
321 exit 1
327 exit 1
322 fi
328 fi
323 ENABLE_INITRAMFS=true
329 ENABLE_INITRAMFS=true
324 fi
330 fi
325
331
326 # Add initramfs generation tools
332 # Add initramfs generation tools
327 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
333 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
328 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
334 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
329 fi
335 fi
330
336
331 # Add device-tree-compiler required for building the U-Boot bootloader
337 # Add device-tree-compiler required for building the U-Boot bootloader
332 if [ "$ENABLE_UBOOT" = true ] ; then
338 if [ "$ENABLE_UBOOT" = true ] ; then
333 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
339 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
334 fi
340 fi
335
341
336 # Check if root SSH (v2) public key file exists
342 # Check if root SSH (v2) public key file exists
337 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
343 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
338 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
344 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
339 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
345 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
340 exit 1
346 exit 1
341 fi
347 fi
342 fi
348 fi
343
349
344 # Check if $USER_NAME SSH (v2) public key file exists
350 # Check if $USER_NAME SSH (v2) public key file exists
345 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
351 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
346 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
352 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
347 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
353 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
348 exit 1
354 exit 1
349 fi
355 fi
350 fi
356 fi
351
357
352 # Check if all required packages are installed on the build system
358 # Check if all required packages are installed on the build system
353 for package in $REQUIRED_PACKAGES ; do
359 for package in $REQUIRED_PACKAGES ; do
354 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
360 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
355 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
361 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
356 fi
362 fi
357 done
363 done
358
364
359 # If there are missing packages ask confirmation for install, or exit
365 # If there are missing packages ask confirmation for install, or exit
360 if [ -n "$MISSING_PACKAGES" ] ; then
366 if [ -n "$MISSING_PACKAGES" ] ; then
361 echo "the following packages needed by this script are not installed:"
367 echo "the following packages needed by this script are not installed:"
362 echo "$MISSING_PACKAGES"
368 echo "$MISSING_PACKAGES"
363
369
364 echo -n "\ndo you want to install the missing packages right now? [y/n] "
370 echo -n "\ndo you want to install the missing packages right now? [y/n] "
365 read confirm
371 read confirm
366 [ "$confirm" != "y" ] && exit 1
372 [ "$confirm" != "y" ] && exit 1
367
373
368 # Make sure all missing required packages are installed
374 # Make sure all missing required packages are installed
369 apt-get -qq -y install ${MISSING_PACKAGES}
375 apt-get -qq -y install ${MISSING_PACKAGES}
370 fi
376 fi
371
377
372 # Check if ./bootstrap.d directory exists
378 # Check if ./bootstrap.d directory exists
373 if [ ! -d "./bootstrap.d/" ] ; then
379 if [ ! -d "./bootstrap.d/" ] ; then
374 echo "error: './bootstrap.d' required directory not found!"
380 echo "error: './bootstrap.d' required directory not found!"
375 exit 1
381 exit 1
376 fi
382 fi
377
383
378 # Check if ./files directory exists
384 # Check if ./files directory exists
379 if [ ! -d "./files/" ] ; then
385 if [ ! -d "./files/" ] ; then
380 echo "error: './files' required directory not found!"
386 echo "error: './files' required directory not found!"
381 exit 1
387 exit 1
382 fi
388 fi
383
389
384 # Check if specified KERNELSRC_DIR directory exists
390 # Check if specified KERNELSRC_DIR directory exists
385 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
391 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
386 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
392 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
387 exit 1
393 exit 1
388 fi
394 fi
389
395
390 # Check if specified UBOOTSRC_DIR directory exists
396 # Check if specified UBOOTSRC_DIR directory exists
391 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
397 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
392 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
398 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
393 exit 1
399 exit 1
394 fi
400 fi
395
401
396 # Check if specified FBTURBOSRC_DIR directory exists
402 # Check if specified FBTURBOSRC_DIR directory exists
397 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
403 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
398 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
404 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
399 exit 1
405 exit 1
400 fi
406 fi
401
407
402 # Check if specified CHROOT_SCRIPTS directory exists
408 # Check if specified CHROOT_SCRIPTS directory exists
403 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
409 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
404 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
410 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
405 exit 1
411 exit 1
406 fi
412 fi
407
413
408 # Check if specified device mapping already exists (will be used by cryptsetup)
414 # Check if specified device mapping already exists (will be used by cryptsetup)
409 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
415 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
410 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
416 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
411 exit 1
417 exit 1
412 fi
418 fi
413
419
414 # Don't clobber an old build
420 # Don't clobber an old build
415 if [ -e "$BUILDDIR" ] ; then
421 if [ -e "$BUILDDIR" ] ; then
416 echo "error: directory ${BUILDDIR} already exists, not proceeding"
422 echo "error: directory ${BUILDDIR} already exists, not proceeding"
417 exit 1
423 exit 1
418 fi
424 fi
419
425
420 # Setup chroot directory
426 # Setup chroot directory
421 mkdir -p "${R}"
427 mkdir -p "${R}"
422
428
423 # Check if build directory has enough of free disk space >512MB
429 # Check if build directory has enough of free disk space >512MB
424 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
430 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
425 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
431 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
426 exit 1
432 exit 1
427 fi
433 fi
428
434
429 set -x
435 set -x
430
436
431 # Call "cleanup" function on various signals and errors
437 # Call "cleanup" function on various signals and errors
432 trap cleanup 0 1 2 3 6
438 trap cleanup 0 1 2 3 6
433
439
434 # Add required packages for the minbase installation
440 # Add required packages for the minbase installation
435 if [ "$ENABLE_MINBASE" = true ] ; then
441 if [ "$ENABLE_MINBASE" = true ] ; then
436 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
442 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
437 fi
443 fi
438
444
439 # Add required locales packages
445 # Add required locales packages
440 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
446 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
441 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
447 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
442 fi
448 fi
443
449
444 # Add parted package, required to get partprobe utility
450 # Add parted package, required to get partprobe utility
445 if [ "$EXPANDROOT" = true ] ; then
451 if [ "$EXPANDROOT" = true ] ; then
446 APT_INCLUDES="${APT_INCLUDES},parted"
452 APT_INCLUDES="${APT_INCLUDES},parted"
447 fi
453 fi
448
454
449 # Add dbus package, recommended if using systemd
455 # Add dbus package, recommended if using systemd
450 if [ "$ENABLE_DBUS" = true ] ; then
456 if [ "$ENABLE_DBUS" = true ] ; then
451 APT_INCLUDES="${APT_INCLUDES},dbus"
457 APT_INCLUDES="${APT_INCLUDES},dbus"
452 fi
458 fi
453
459
454 # Add iptables IPv4/IPv6 package
460 # Add iptables IPv4/IPv6 package
455 if [ "$ENABLE_IPTABLES" = true ] ; then
461 if [ "$ENABLE_IPTABLES" = true ] ; then
456 APT_INCLUDES="${APT_INCLUDES},iptables"
462 APT_INCLUDES="${APT_INCLUDES},iptables"
457 fi
463 fi
458
464
459 # Add openssh server package
465 # Add openssh server package
460 if [ "$ENABLE_SSHD" = true ] ; then
466 if [ "$ENABLE_SSHD" = true ] ; then
461 APT_INCLUDES="${APT_INCLUDES},openssh-server"
467 APT_INCLUDES="${APT_INCLUDES},openssh-server"
462 fi
468 fi
463
469
464 # Add alsa-utils package
470 # Add alsa-utils package
465 if [ "$ENABLE_SOUND" = true ] ; then
471 if [ "$ENABLE_SOUND" = true ] ; then
466 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
472 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
467 fi
473 fi
468
474
469 # Add rng-tools package
475 # Add rng-tools package
470 if [ "$ENABLE_HWRANDOM" = true ] ; then
476 if [ "$ENABLE_HWRANDOM" = true ] ; then
471 APT_INCLUDES="${APT_INCLUDES},rng-tools"
477 APT_INCLUDES="${APT_INCLUDES},rng-tools"
472 fi
478 fi
473
479
474 # Add fbturbo video driver
480 # Add fbturbo video driver
475 if [ "$ENABLE_FBTURBO" = true ] ; then
481 if [ "$ENABLE_FBTURBO" = true ] ; then
476 # Enable xorg package dependencies
482 # Enable xorg package dependencies
477 ENABLE_XORG=true
483 ENABLE_XORG=true
478 fi
484 fi
479
485
480 # Add user defined window manager package
486 # Add user defined window manager package
481 if [ -n "$ENABLE_WM" ] ; then
487 if [ -n "$ENABLE_WM" ] ; then
482 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
488 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
483
489
484 # Enable xorg package dependencies
490 # Enable xorg package dependencies
485 ENABLE_XORG=true
491 ENABLE_XORG=true
486 fi
492 fi
487
493
488 # Add xorg package
494 # Add xorg package
489 if [ "$ENABLE_XORG" = true ] ; then
495 if [ "$ENABLE_XORG" = true ] ; then
490 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
496 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
491 fi
497 fi
492
498
493 # Replace selected packages with smaller clones
499 # Replace selected packages with smaller clones
494 if [ "$ENABLE_REDUCE" = true ] ; then
500 if [ "$ENABLE_REDUCE" = true ] ; then
495 # Add levee package instead of vim-tiny
501 # Add levee package instead of vim-tiny
496 if [ "$REDUCE_VIM" = true ] ; then
502 if [ "$REDUCE_VIM" = true ] ; then
497 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
503 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
498 fi
504 fi
499
505
500 # Add dropbear package instead of openssh-server
506 # Add dropbear package instead of openssh-server
501 if [ "$REDUCE_SSHD" = true ] ; then
507 if [ "$REDUCE_SSHD" = true ] ; then
502 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
508 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
503 fi
509 fi
504 fi
510 fi
505
511
506 if [ "$RELEASE" != "jessie" ] ; then
512 if [ "$RELEASE" != "jessie" ] ; then
507 APT_INCLUDES="${APT_INCLUDES},libnss-systemd"
513 APT_INCLUDES="${APT_INCLUDES},libnss-systemd"
508 fi
514 fi
509
515
510 # Configure kernel sources if no KERNELSRC_DIR
516 # Configure kernel sources if no KERNELSRC_DIR
511 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
517 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
512 KERNELSRC_CONFIG=true
518 KERNELSRC_CONFIG=true
513 fi
519 fi
514
520
515 # Configure reduced kernel
521 # Configure reduced kernel
516 if [ "$KERNEL_REDUCE" = true ] ; then
522 if [ "$KERNEL_REDUCE" = true ] ; then
517 KERNELSRC_CONFIG=false
523 KERNELSRC_CONFIG=false
518 fi
524 fi
519
525
520 # Configure qemu compatible kernel
526 # Configure qemu compatible kernel
521 if [ "$ENABLE_QEMU" = true ] ; then
527 if [ "$ENABLE_QEMU" = true ] ; then
522 KERNEL_DEFCONFIG="vexpress_defconfig"
528 KERNEL_DEFCONFIG="vexpress_defconfig"
523 KERNEL_OLDDEFCONFIG=true
529 KERNEL_OLDDEFCONFIG=true
524 fi
530 fi
525
531
526 # Execute bootstrap scripts
532 # Execute bootstrap scripts
527 for SCRIPT in bootstrap.d/*.sh; do
533 for SCRIPT in bootstrap.d/*.sh; do
528 head -n 3 "$SCRIPT"
534 head -n 3 "$SCRIPT"
529 . "$SCRIPT"
535 . "$SCRIPT"
530 done
536 done
531
537
532 ## Execute custom bootstrap scripts
538 ## Execute custom bootstrap scripts
533 if [ -d "custom.d" ] ; then
539 if [ -d "custom.d" ] ; then
534 for SCRIPT in custom.d/*.sh; do
540 for SCRIPT in custom.d/*.sh; do
535 . "$SCRIPT"
541 . "$SCRIPT"
536 done
542 done
537 fi
543 fi
538
544
539 # Execute custom scripts inside the chroot
545 # Execute custom scripts inside the chroot
540 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
546 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
541 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
547 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
542 chroot_exec /bin/bash -x <<'EOF'
548 chroot_exec /bin/bash -x <<'EOF'
543 for SCRIPT in /chroot_scripts/* ; do
549 for SCRIPT in /chroot_scripts/* ; do
544 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
550 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
545 $SCRIPT
551 $SCRIPT
546 fi
552 fi
547 done
553 done
548 EOF
554 EOF
549 rm -rf "${R}/chroot_scripts"
555 rm -rf "${R}/chroot_scripts"
550 fi
556 fi
551
557
552 # Remove c/c++ build environment from the chroot
558 # Remove c/c++ build environment from the chroot
553 chroot_remove_cc
559 chroot_remove_cc
554
560
555 # Remove apt-utils
561 # Remove apt-utils
556 if [ "$RELEASE" = "jessie" ] ; then
562 if [ "$RELEASE" = "jessie" ] ; then
557 chroot_exec apt-get purge -qq -y --force-yes apt-utils
563 chroot_exec apt-get purge -qq -y --force-yes apt-utils
558 fi
564 fi
559
565
560 # Generate required machine-id
566 # Generate required machine-id
561 MACHINE_ID=$(dbus-uuidgen)
567 MACHINE_ID=$(dbus-uuidgen)
562 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
568 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
563 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
569 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
564
570
565 # APT Cleanup
571 # APT Cleanup
566 chroot_exec apt-get -y clean
572 chroot_exec apt-get -y clean
567 chroot_exec apt-get -y autoclean
573 chroot_exec apt-get -y autoclean
568 chroot_exec apt-get -y autoremove
574 chroot_exec apt-get -y autoremove
569
575
570 # Unmount mounted filesystems
576 # Unmount mounted filesystems
571 umount -l "${R}/proc"
577 umount -l "${R}/proc"
572 umount -l "${R}/sys"
578 umount -l "${R}/sys"
573
579
574 # Clean up directories
580 # Clean up directories
575 rm -rf "${R}/run/*"
581 rm -rf "${R}/run/*"
576 rm -rf "${R}/tmp/*"
582 rm -rf "${R}/tmp/*"
577
583
578 # Clean up files
584 # Clean up files
579 rm -f "${ETC_DIR}/ssh/ssh_host_*"
585 rm -f "${ETC_DIR}/ssh/ssh_host_*"
580 rm -f "${ETC_DIR}/dropbear/dropbear_*"
586 rm -f "${ETC_DIR}/dropbear/dropbear_*"
581 rm -f "${ETC_DIR}/apt/sources.list.save"
587 rm -f "${ETC_DIR}/apt/sources.list.save"
582 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
588 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
583 rm -f "${ETC_DIR}/*-"
589 rm -f "${ETC_DIR}/*-"
584 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
590 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
585 rm -f "${ETC_DIR}/resolv.conf"
591 rm -f "${ETC_DIR}/resolv.conf"
586 rm -f "${R}/root/.bash_history"
592 rm -f "${R}/root/.bash_history"
587 rm -f "${R}/var/lib/urandom/random-seed"
593 rm -f "${R}/var/lib/urandom/random-seed"
588 rm -f "${R}/initrd.img"
594 rm -f "${R}/initrd.img"
589 rm -f "${R}/vmlinuz"
595 rm -f "${R}/vmlinuz"
590 rm -f "${R}${QEMU_BINARY}"
596 rm -f "${R}${QEMU_BINARY}"
591
597
592 if [ "$ENABLE_QEMU" = true ] ; then
598 if [ "$ENABLE_QEMU" = true ] ; then
593 # Setup QEMU directory
599 # Setup QEMU directory
594 mkdir "${BASEDIR}/qemu"
600 mkdir "${BASEDIR}/qemu"
595
601
596 # Copy kernel image to QEMU directory
602 # Copy kernel image to QEMU directory
597 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
603 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
598
604
599 # Copy kernel config to QEMU directory
605 # Copy kernel config to QEMU directory
600 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
606 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
601
607
602 # Copy kernel dtbs to QEMU directory
608 # Copy kernel dtbs to QEMU directory
603 for dtb in "${BOOT_DIR}/"*.dtb ; do
609 for dtb in "${BOOT_DIR}/"*.dtb ; do
604 if [ -f "${dtb}" ] ; then
610 if [ -f "${dtb}" ] ; then
605 install_readonly "${dtb}" "${BASEDIR}/qemu/"
611 install_readonly "${dtb}" "${BASEDIR}/qemu/"
606 fi
612 fi
607 done
613 done
608
614
609 # Copy kernel overlays to QEMU directory
615 # Copy kernel overlays to QEMU directory
610 if [ -d "${BOOT_DIR}/overlays" ] ; then
616 if [ -d "${BOOT_DIR}/overlays" ] ; then
611 # Setup overlays dtbs directory
617 # Setup overlays dtbs directory
612 mkdir "${BASEDIR}/qemu/overlays"
618 mkdir "${BASEDIR}/qemu/overlays"
613
619
614 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
620 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
615 if [ -f "${dtb}" ] ; then
621 if [ -f "${dtb}" ] ; then
616 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
622 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
617 fi
623 fi
618 done
624 done
619 fi
625 fi
620
626
621 # Copy initramfs to QEMU directory
627 # Copy initramfs to QEMU directory
622 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
628 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
623 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
629 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
624 fi
630 fi
625 fi
631 fi
626
632
627 # Calculate size of the chroot directory in KB
633 # Calculate size of the chroot directory in KB
628 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
634 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
629
635
630 # Calculate the amount of needed 512 Byte sectors
636 # Calculate the amount of needed 512 Byte sectors
631 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
637 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
632 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
638 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
633 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
639 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
634
640
635 # The root partition is EXT4
641 # The root partition is EXT4
636 # This means more space than the actual used space of the chroot is used.
642 # This means more space than the actual used space of the chroot is used.
637 # As overhead for journaling and reserved blocks 35% are added.
643 # As overhead for journaling and reserved blocks 35% are added.
638 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512)
644 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512)
639
645
640 # Calculate required image size in 512 Byte sectors
646 # Calculate required image size in 512 Byte sectors
641 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
647 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
642
648
643 # Prepare image file
649 # Prepare image file
644 if [ "$ENABLE_SPLITFS" = true ] ; then
650 if [ "$ENABLE_SPLITFS" = true ] ; then
645 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
651 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
646 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
652 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
647 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
653 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
648 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
654 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
649
655
650 # Write firmware/boot partition tables
656 # Write firmware/boot partition tables
651 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
657 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
652 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
658 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
653 EOM
659 EOM
654
660
655 # Write root partition table
661 # Write root partition table
656 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
662 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
657 ${TABLE_SECTORS},${ROOT_SECTORS},83
663 ${TABLE_SECTORS},${ROOT_SECTORS},83
658 EOM
664 EOM
659
665
660 # Setup temporary loop devices
666 # Setup temporary loop devices
661 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
667 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
662 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
668 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
663 else # ENABLE_SPLITFS=false
669 else # ENABLE_SPLITFS=false
664 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
670 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
665 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
671 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
666
672
667 # Write partition table
673 # Write partition table
668 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
674 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
669 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
675 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
670 ${ROOT_OFFSET},${ROOT_SECTORS},83
676 ${ROOT_OFFSET},${ROOT_SECTORS},83
671 EOM
677 EOM
672
678
673 # Setup temporary loop devices
679 # Setup temporary loop devices
674 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
680 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
675 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
681 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
676 fi
682 fi
677
683
678 if [ "$ENABLE_CRYPTFS" = true ] ; then
684 if [ "$ENABLE_CRYPTFS" = true ] ; then
679 # Create dummy ext4 fs
685 # Create dummy ext4 fs
680 mkfs.ext4 "$ROOT_LOOP"
686 mkfs.ext4 "$ROOT_LOOP"
681
687
682 # Setup password keyfile
688 # Setup password keyfile
683 touch .password
689 touch .password
684 chmod 600 .password
690 chmod 600 .password
685 echo -n ${CRYPTFS_PASSWORD} > .password
691 echo -n ${CRYPTFS_PASSWORD} > .password
686
692
687 # Initialize encrypted partition
693 # Initialize encrypted partition
688 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
694 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
689
695
690 # Open encrypted partition and setup mapping
696 # Open encrypted partition and setup mapping
691 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
697 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
692
698
693 # Secure delete password keyfile
699 # Secure delete password keyfile
694 shred -zu .password
700 shred -zu .password
695
701
696 # Update temporary loop device
702 # Update temporary loop device
697 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
703 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
698
704
699 # Wipe encrypted partition (encryption cipher is used for randomness)
705 # Wipe encrypted partition (encryption cipher is used for randomness)
700 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
706 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
701 fi
707 fi
702
708
703 # Build filesystems
709 # Build filesystems
704 mkfs.vfat "$FRMW_LOOP"
710 mkfs.vfat "$FRMW_LOOP"
705 mkfs.ext4 "$ROOT_LOOP"
711 mkfs.ext4 "$ROOT_LOOP"
706
712
707 # Mount the temporary loop devices
713 # Mount the temporary loop devices
708 mkdir -p "$BUILDDIR/mount"
714 mkdir -p "$BUILDDIR/mount"
709 mount "$ROOT_LOOP" "$BUILDDIR/mount"
715 mount "$ROOT_LOOP" "$BUILDDIR/mount"
710
716
711 mkdir -p "$BUILDDIR/mount/boot/firmware"
717 mkdir -p "$BUILDDIR/mount/boot/firmware"
712 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
718 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
713
719
714 # Copy all files from the chroot to the loop device mount point directory
720 # Copy all files from the chroot to the loop device mount point directory
715 rsync -a "${R}/" "$BUILDDIR/mount/"
721 rsync -a "${R}/" "$BUILDDIR/mount/"
716
722
717 # Unmount all temporary loop devices and mount points
723 # Unmount all temporary loop devices and mount points
718 cleanup
724 cleanup
719
725
720 # Create block map file(s) of image(s)
726 # Create block map file(s) of image(s)
721 if [ "$ENABLE_SPLITFS" = true ] ; then
727 if [ "$ENABLE_SPLITFS" = true ] ; then
722 # Create block map files for "bmaptool"
728 # Create block map files for "bmaptool"
723 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
729 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
724 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
730 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
725
731
726 # Image was successfully created
732 # Image was successfully created
727 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
733 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
728 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
734 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
729 else
735 else
730 # Create block map file for "bmaptool"
736 # Create block map file for "bmaptool"
731 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
737 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
732
738
733 # Image was successfully created
739 # Image was successfully created
734 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
740 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
735
741
736 # Create qemu qcow2 image
742 # Create qemu qcow2 image
737 if [ "$ENABLE_QEMU" = true ] ; then
743 if [ "$ENABLE_QEMU" = true ] ; then
738 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
744 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
739 QEMU_SIZE=16G
745 QEMU_SIZE=16G
740
746
741 qemu-img convert -f raw -O qcow2 $IMAGE_NAME.img $QEMU_IMAGE.qcow2
747 qemu-img convert -f raw -O qcow2 $IMAGE_NAME.img $QEMU_IMAGE.qcow2
742 qemu-img resize $QEMU_IMAGE.qcow2 $QEMU_SIZE
748 qemu-img resize $QEMU_IMAGE.qcow2 $QEMU_SIZE
743
749
744 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
750 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
745 fi
751 fi
746 fi
752 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant