@@ -1,46 +1,52 | |||||
1 | # |
|
1 | # | |
2 | # Setup videocore - Raspberry Userland |
|
2 | # Setup videocore - Raspberry Userland | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | # Load utility functions |
|
5 | # Load utility functions | |
6 | . ./functions.sh |
|
6 | . ./functions.sh | |
7 |
|
7 | |||
8 | if [ "$ENABLE_VIDEOCORE" = true ] ; then |
|
8 | if [ "$ENABLE_VIDEOCORE" = true ] ; then | |
9 | # Copy existing videocore sources into chroot directory |
|
9 | # Copy existing videocore sources into chroot directory | |
10 | if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then |
|
10 | if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then | |
11 | # Copy local U-Boot sources |
|
11 | # Copy local U-Boot sources | |
12 | cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp" |
|
12 | cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp/userland" | |
13 | else |
|
13 | else | |
14 | # Create temporary directory for U-Boot sources |
|
14 | # Create temporary directory for U-Boot sources | |
15 | temp_dir=$(as_nobody mktemp -d) |
|
15 | temp_dir=$(as_nobody mktemp -d) | |
16 |
|
16 | |||
17 | # Fetch U-Boot sources |
|
17 | # Fetch U-Boot sources | |
18 | as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}" |
|
18 | as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}" | |
19 |
|
19 | |||
20 | # Copy downloaded U-Boot sources |
|
20 | # Copy downloaded U-Boot sources | |
21 | mv "${temp_dir}/userland" "${R}/tmp/" |
|
21 | mv "${temp_dir}/userland" "${R}/tmp/" | |
22 |
|
22 | |||
23 | # Set permissions of the U-Boot sources |
|
23 | # Set permissions of the U-Boot sources | |
24 | chown -R root:root "${R}/tmp/userland" |
|
24 | chown -R root:root "${R}/tmp/userland" | |
25 |
|
25 | |||
26 | # Remove temporary directory for U-Boot sources |
|
26 | # Remove temporary directory for U-Boot sources | |
27 | rm -fr "${temp_dir}" |
|
27 | rm -fr "${temp_dir}" | |
28 | fi |
|
28 | fi | |
29 |
|
29 | |||
|
30 | # Create build dir | |||
|
31 | mkdir "${R}"/tmp/userland/build | |||
|
32 | # push us to build directory | |||
|
33 | pushd "${R}"/tmp/userland/build | |||
|
34 | ||||
30 | if [ "$RELEASE_ARCH" = "arm64" ] ; then |
|
35 | if [ "$RELEASE_ARCH" = "arm64" ] ; then | |
31 |
cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DVIDEOCORE_BUILD_DIR="${R}" |
|
36 | cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" | |
32 | fi |
|
37 | fi | |
33 |
|
38 | |||
34 | if [ "$RELEASE_ARCH" = "armel" ] ; then |
|
39 | if [ "$RELEASE_ARCH" = "armel" ] ; then | |
35 |
cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DCMAKE_ASM_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DCMAKE_SYSTEM_PROCESSOR="arm" -DVIDEOCORE_BUILD_DIR="${R}" |
|
40 | cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DCMAKE_ASM_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DCMAKE_SYSTEM_PROCESSOR="arm" -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" | |
36 | fi |
|
41 | fi | |
37 |
|
42 | |||
38 | if [ "$RELEASE_ARCH" = "armhf" ] ; then |
|
43 | if [ "$RELEASE_ARCH" = "armhf" ] ; then | |
39 |
cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_TOOLCHAIN_FILE="${R}"/tmp/userland/makefiles/cmake/toolchains/arm-linux-gnueabihf.cmake -DVIDEOCORE_BUILD_DIR="${R}" |
|
44 | cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_TOOLCHAIN_FILE="${R}"/tmp/userland/makefiles/cmake/toolchains/arm-linux-gnueabihf.cmake -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" | |
40 | fi |
|
45 | fi | |
41 |
|
46 | |||
42 | #build userland |
|
47 | #build userland | |
43 | make -j "$(nproc)" |
|
48 | make -j "$(nproc)" | |
|
49 | popd | |||
44 | #include default_installdir in path |
|
50 | #include default_installdir in path | |
45 | # chroot_exec export PATH="${PATH}":/opt/vc/bin |
|
51 | # chroot_exec export PATH="${PATH}":/opt/vc/bin | |
46 | fi |
|
52 | fi |
@@ -1,828 +1,829 | |||||
1 | #!/bin/bash |
|
1 | #!/bin/bash | |
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 RPi2/3 |
|
5 | # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3 | |
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# RPi2/3 Bootstrap Settings\n#\n" |
|
39 | echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n" | |
40 | set -x |
|
40 | set -x | |
41 |
|
41 | |||
42 | # Raspberry Pi model configuration |
|
42 | # Raspberry Pi model configuration | |
43 | export RPI_MODEL=${RPI_MODEL:=2} |
|
43 | export RPI_MODEL=${RPI_MODEL:=2} | |
44 |
|
44 | |||
45 | # Debian release |
|
45 | # Debian release | |
46 | export RELEASE=${RELEASE:=buster} |
|
46 | export RELEASE=${RELEASE:=buster} | |
47 |
|
47 | |||
48 | #Kernel Branch |
|
48 | #Kernel Branch | |
49 | export KERNEL_BRANCH=${KERNEL_BRANCH:=""} |
|
49 | export 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 | #BIS= Kernel has KVM and zswap enabled |
|
59 | #BIS= Kernel has KVM and zswap enabled | |
60 | 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} |
|
60 | 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} | |
61 | #default bcmrpi3_defconfig target kernel |
|
61 | #default bcmrpi3_defconfig target kernel | |
62 | 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} |
|
62 | 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} | |
|
63 | #enhanced kernel | |||
63 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_BIS_KERNEL_URL} |
|
64 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_BIS_KERNEL_URL} | |
64 | #https://aur.archlinux.org/packages/pi-bluetooth/ |
|
65 | #https://aur.archlinux.org/packages/pi-bluetooth/ | |
65 | BLUETOOTH_URL=${BLUETOOTH_URL:=https://aur.archlinux.org/pi-bluetooth.git} |
|
66 | BLUETOOTH_URL=${BLUETOOTH_URL:=https://aur.archlinux.org/pi-bluetooth.git} | |
66 |
|
67 | |||
67 | # Build directories |
|
68 | # Build directories | |
68 | BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}} |
|
69 | BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}} | |
69 | BUILDDIR="${BASEDIR}/build" |
|
70 | BUILDDIR="${BASEDIR}/build" | |
70 |
|
71 | |||
71 | # Prepare date string for default image file name |
|
72 | # Prepare date string for default image file name | |
72 | DATE="$(date +%Y-%m-%d)" |
|
73 | DATE="$(date +%Y-%m-%d)" | |
73 | if [ -z "$KERNEL_BRANCH" ] ; then |
|
74 | if [ -z "$KERNEL_BRANCH" ] ; then | |
74 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
75 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
75 | else |
|
76 | else | |
76 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
77 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
77 | fi |
|
78 | fi | |
78 |
|
79 | |||
79 | # Chroot directories |
|
80 | # Chroot directories | |
80 | R="${BUILDDIR}/chroot" |
|
81 | R="${BUILDDIR}/chroot" | |
81 | ETC_DIR="${R}/etc" |
|
82 | ETC_DIR="${R}/etc" | |
82 | LIB_DIR="${R}/lib" |
|
83 | LIB_DIR="${R}/lib" | |
83 | BOOT_DIR="${R}/boot/firmware" |
|
84 | BOOT_DIR="${R}/boot/firmware" | |
84 | KERNEL_DIR="${R}/usr/src/linux" |
|
85 | KERNEL_DIR="${R}/usr/src/linux" | |
85 | WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm" |
|
86 | WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm" | |
86 |
|
87 | |||
87 | # Firmware directory: Blank if download from github |
|
88 | # Firmware directory: Blank if download from github | |
88 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} |
|
89 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} | |
89 | # General settings |
|
90 | # General settings | |
90 | SET_ARCH=${SET_ARCH:=32} |
|
91 | SET_ARCH=${SET_ARCH:=32} | |
91 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} |
|
92 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} | |
92 | PASSWORD=${PASSWORD:=raspberry} |
|
93 | PASSWORD=${PASSWORD:=raspberry} | |
93 | USER_PASSWORD=${USER_PASSWORD:=raspberry} |
|
94 | USER_PASSWORD=${USER_PASSWORD:=raspberry} | |
94 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} |
|
95 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} | |
95 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} |
|
96 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} | |
96 | EXPANDROOT=${EXPANDROOT:=true} |
|
97 | EXPANDROOT=${EXPANDROOT:=true} | |
97 |
|
98 | |||
98 | # Keyboard settings |
|
99 | # Keyboard settings | |
99 | XKB_MODEL=${XKB_MODEL:=""} |
|
100 | XKB_MODEL=${XKB_MODEL:=""} | |
100 | XKB_LAYOUT=${XKB_LAYOUT:=""} |
|
101 | XKB_LAYOUT=${XKB_LAYOUT:=""} | |
101 | XKB_VARIANT=${XKB_VARIANT:=""} |
|
102 | XKB_VARIANT=${XKB_VARIANT:=""} | |
102 | XKB_OPTIONS=${XKB_OPTIONS:=""} |
|
103 | XKB_OPTIONS=${XKB_OPTIONS:=""} | |
103 |
|
104 | |||
104 | # Network settings (DHCP) |
|
105 | # Network settings (DHCP) | |
105 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
106 | ENABLE_DHCP=${ENABLE_DHCP:=true} | |
106 |
|
107 | |||
107 | # Network settings (static) |
|
108 | # Network settings (static) | |
108 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
109 | NET_ADDRESS=${NET_ADDRESS:=""} | |
109 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
110 | NET_GATEWAY=${NET_GATEWAY:=""} | |
110 | NET_DNS_1=${NET_DNS_1:=""} |
|
111 | NET_DNS_1=${NET_DNS_1:=""} | |
111 | NET_DNS_2=${NET_DNS_2:=""} |
|
112 | NET_DNS_2=${NET_DNS_2:=""} | |
112 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} |
|
113 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} | |
113 | NET_NTP_1=${NET_NTP_1:=""} |
|
114 | NET_NTP_1=${NET_NTP_1:=""} | |
114 | NET_NTP_2=${NET_NTP_2:=""} |
|
115 | NET_NTP_2=${NET_NTP_2:=""} | |
115 |
|
116 | |||
116 | # APT settings |
|
117 | # APT settings | |
117 | APT_PROXY=${APT_PROXY:=""} |
|
118 | APT_PROXY=${APT_PROXY:=""} | |
118 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} |
|
119 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} | |
119 |
|
120 | |||
120 | # Feature settings |
|
121 | # Feature settings | |
121 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} |
|
122 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} | |
122 | ENABLE_I2C=${ENABLE_I2C:=false} |
|
123 | ENABLE_I2C=${ENABLE_I2C:=false} | |
123 | ENABLE_SPI=${ENABLE_SPI:=false} |
|
124 | ENABLE_SPI=${ENABLE_SPI:=false} | |
124 | ENABLE_IPV6=${ENABLE_IPV6:=true} |
|
125 | ENABLE_IPV6=${ENABLE_IPV6:=true} | |
125 | ENABLE_SSHD=${ENABLE_SSHD:=true} |
|
126 | ENABLE_SSHD=${ENABLE_SSHD:=true} | |
126 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} |
|
127 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} | |
127 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} |
|
128 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} | |
128 | ENABLE_SOUND=${ENABLE_SOUND:=true} |
|
129 | ENABLE_SOUND=${ENABLE_SOUND:=true} | |
129 | ENABLE_DBUS=${ENABLE_DBUS:=true} |
|
130 | ENABLE_DBUS=${ENABLE_DBUS:=true} | |
130 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} |
|
131 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} | |
131 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} |
|
132 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} | |
132 | ENABLE_XORG=${ENABLE_XORG:=false} |
|
133 | ENABLE_XORG=${ENABLE_XORG:=false} | |
133 | ENABLE_WM=${ENABLE_WM:=""} |
|
134 | ENABLE_WM=${ENABLE_WM:=""} | |
134 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} |
|
135 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} | |
135 | ENABLE_USER=${ENABLE_USER:=true} |
|
136 | ENABLE_USER=${ENABLE_USER:=true} | |
136 | USER_NAME=${USER_NAME:="pi"} |
|
137 | USER_NAME=${USER_NAME:="pi"} | |
137 | ENABLE_ROOT=${ENABLE_ROOT:=false} |
|
138 | ENABLE_ROOT=${ENABLE_ROOT:=false} | |
138 | ENABLE_QEMU=${ENABLE_QEMU:=false} |
|
139 | ENABLE_QEMU=${ENABLE_QEMU:=false} | |
139 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} |
|
140 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} | |
140 |
|
141 | |||
141 | # SSH settings |
|
142 | # SSH settings | |
142 | SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} |
|
143 | SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} | |
143 | SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} |
|
144 | SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} | |
144 | SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} |
|
145 | SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} | |
145 | SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} |
|
146 | SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} | |
146 | SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} |
|
147 | SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} | |
147 |
|
148 | |||
148 | # Advanced settings |
|
149 | # Advanced settings | |
149 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} |
|
150 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} | |
150 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} |
|
151 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} | |
151 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} |
|
152 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} | |
152 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} |
|
153 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} | |
153 | ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false} |
|
154 | ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false} | |
154 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
155 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} | |
155 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true} |
|
156 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true} | |
156 | VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} |
|
157 | VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} | |
157 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} |
|
158 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} | |
158 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
159 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} | |
159 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
160 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} | |
160 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} |
|
161 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | |
161 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} |
|
162 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} | |
162 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} |
|
163 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} | |
163 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} |
|
164 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} | |
164 |
|
165 | |||
165 | # Kernel compilation settings |
|
166 | # Kernel compilation settings | |
166 | BUILD_KERNEL=${BUILD_KERNEL:=true} |
|
167 | BUILD_KERNEL=${BUILD_KERNEL:=true} | |
167 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} |
|
168 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} | |
168 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
169 | KERNEL_THREADS=${KERNEL_THREADS:=1} | |
169 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
170 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} | |
170 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
171 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} | |
171 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} |
|
172 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} | |
172 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} |
|
173 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} | |
173 | KERNEL_CCACHE=${KERNEL_CCACHE:=false} |
|
174 | KERNEL_CCACHE=${KERNEL_CCACHE:=false} | |
174 | KERNEL_ZSWAP=${KERNEL_ZSWAP:=true} |
|
175 | KERNEL_ZSWAP=${KERNEL_ZSWAP:=true} | |
175 | KERNEL_VIRT=${KERNEL_VIRT:=true} |
|
176 | KERNEL_VIRT=${KERNEL_VIRT:=true} | |
176 |
|
177 | |||
177 | # Kernel compilation from source directory settings |
|
178 | # Kernel compilation from source directory settings | |
178 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} |
|
179 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} | |
179 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} |
|
180 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} | |
180 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
181 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} | |
181 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
182 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} | |
182 |
|
183 | |||
183 | # Reduce disk usage settings |
|
184 | # Reduce disk usage settings | |
184 | REDUCE_APT=${REDUCE_APT:=true} |
|
185 | REDUCE_APT=${REDUCE_APT:=true} | |
185 | REDUCE_DOC=${REDUCE_DOC:=true} |
|
186 | REDUCE_DOC=${REDUCE_DOC:=true} | |
186 | REDUCE_MAN=${REDUCE_MAN:=true} |
|
187 | REDUCE_MAN=${REDUCE_MAN:=true} | |
187 | REDUCE_VIM=${REDUCE_VIM:=false} |
|
188 | REDUCE_VIM=${REDUCE_VIM:=false} | |
188 | REDUCE_BASH=${REDUCE_BASH:=false} |
|
189 | REDUCE_BASH=${REDUCE_BASH:=false} | |
189 | REDUCE_HWDB=${REDUCE_HWDB:=true} |
|
190 | REDUCE_HWDB=${REDUCE_HWDB:=true} | |
190 | REDUCE_SSHD=${REDUCE_SSHD:=true} |
|
191 | REDUCE_SSHD=${REDUCE_SSHD:=true} | |
191 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} |
|
192 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} | |
192 |
|
193 | |||
193 | # Encrypted filesystem settings |
|
194 | # Encrypted filesystem settings | |
194 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} |
|
195 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} | |
195 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} |
|
196 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} | |
196 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} |
|
197 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} | |
197 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} |
|
198 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} | |
198 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} |
|
199 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} | |
199 |
|
200 | |||
200 | # Chroot scripts directory |
|
201 | # Chroot scripts directory | |
201 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
202 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} | |
202 |
|
203 | |||
203 | # Packages required in the chroot build environment |
|
204 | # Packages required in the chroot build environment | |
204 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
205 | APT_INCLUDES=${APT_INCLUDES:=""} | |
205 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup" |
|
206 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup" | |
206 |
|
207 | |||
207 | #Packages to exclude from chroot build environment |
|
208 | #Packages to exclude from chroot build environment | |
208 | APT_EXCLUDES=${APT_EXCLUDES:=""} |
|
209 | APT_EXCLUDES=${APT_EXCLUDES:=""} | |
209 |
|
210 | |||
210 | # Packages required for bootstrapping |
|
211 | # Packages required for bootstrapping | |
211 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt" |
|
212 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt" | |
212 | MISSING_PACKAGES="" |
|
213 | MISSING_PACKAGES="" | |
213 |
|
214 | |||
214 | # Packages installed for c/c++ build environment in chroot (keep empty) |
|
215 | # Packages installed for c/c++ build environment in chroot (keep empty) | |
215 | COMPILER_PACKAGES="" |
|
216 | COMPILER_PACKAGES="" | |
216 |
|
217 | |||
217 | #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts |
|
218 | #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts | |
218 | if [ "$ENABLE_SYSVINIT" = false ] ; then |
|
219 | if [ "$ENABLE_SYSVINIT" = false ] ; then | |
219 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" |
|
220 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" | |
220 | fi |
|
221 | fi | |
221 |
|
222 | |||
222 | #Check if apt-cacher-ng has its default port open on and set APT_PROXY |
|
223 | #Check if apt-cacher-ng has its default port open on and set APT_PROXY | |
223 | if [ -n "$(lsof -i :3142)" ] ; then |
|
224 | if [ -n "$(lsof -i :3142)" ] ; then | |
224 | HTTP_PROXY=http://127.0.0.1:3142/ |
|
225 | HTTP_PROXY=http://127.0.0.1:3142/ | |
225 | fi |
|
226 | fi | |
226 |
|
227 | |||
227 | #ipinfo=$(curl ipinfo.io | grep country ) |
|
228 | #ipinfo=$(curl ipinfo.io | grep country ) | |
228 | #grep -o '\"[^"]*\"' $ipinfo | tr -d '"' |
|
229 | #grep -o '\"[^"]*\"' $ipinfo | tr -d '"' | |
229 | #grep -Po '"country":.*?[^\\]",' $(curl ipinfo.io | grep country ) |
|
230 | #grep -Po '"country":.*?[^\\]",' $(curl ipinfo.io | grep country ) | |
230 | #sed -i "s,http:,https:,g" "${ETC_DIR}/apt/sources.list" |
|
231 | #sed -i "s,http:,https:,g" "${ETC_DIR}/apt/sources.list" | |
231 | #autconfigure best apt server to not spam ftp.debian.org |
|
232 | #autconfigure best apt server to not spam ftp.debian.org | |
232 | #rm files/apt/sources.list |
|
233 | #rm files/apt/sources.list | |
233 | #netselect-apt does not know buster yet |
|
234 | #netselect-apt does not know buster yet | |
234 | if [ "$RELEASE" = "buster" ] ; then |
|
235 | if [ "$RELEASE" = "buster" ] ; then | |
235 | RLS=testing |
|
236 | RLS=testing | |
236 | else |
|
237 | else | |
237 | RLS="$RELEASE" |
|
238 | RLS="$RELEASE" | |
238 | fi |
|
239 | fi | |
239 |
|
240 | |||
240 | if [ -f "$(pwd)/files/apt/sources.list" ] ; then |
|
241 | if [ -f "$(pwd)/files/apt/sources.list" ] ; then | |
241 | rm "$(pwd)/files/apt/sources.list" |
|
242 | rm "$(pwd)/files/apt/sources.list" | |
242 | fi |
|
243 | fi | |
243 |
|
244 | |||
244 | if [ "$ENABLE_NONFREE" = true ] ; then |
|
245 | if [ "$ENABLE_NONFREE" = true ] ; then | |
245 | netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
246 | netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" | |
246 | else |
|
247 | else | |
247 | netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
248 | netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" | |
248 | fi |
|
249 | fi | |
249 |
|
250 | |||
250 | #sed and cut the result string so we can use it as APT_SERVER |
|
251 | #sed and cut the result string so we can use it as APT_SERVER | |
251 | APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3) |
|
252 | APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3) | |
252 | APT_SERVER=${APT_SERVER::-1} |
|
253 | APT_SERVER=${APT_SERVER::-1} | |
253 |
|
254 | |||
254 | #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! |
|
255 | #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! | |
255 | if [ -n "$SET_ARCH" ] ; then |
|
256 | if [ -n "$SET_ARCH" ] ; then | |
256 | echo "Setting Architecture specific settings" |
|
257 | echo "Setting Architecture specific settings" | |
257 | ################################## |
|
258 | ################################## | |
258 | # 64 bit config |
|
259 | # 64 bit config | |
259 | ################################## |
|
260 | ################################## | |
260 | if [ "$SET_ARCH" = 64 ] ; then |
|
261 | if [ "$SET_ARCH" = 64 ] ; then | |
261 | echo "64 bit mode selected - Setting up enviroment" |
|
262 | echo "64 bit mode selected - Setting up enviroment" | |
262 | # 64 bit depended settings |
|
263 | # 64 bit depended settings | |
263 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} |
|
264 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} | |
264 | KERNEL_ARCH=${KERNEL_ARCH:=arm64} |
|
265 | KERNEL_ARCH=${KERNEL_ARCH:=arm64} | |
265 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} |
|
266 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} | |
266 |
|
267 | |||
267 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
268 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
268 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" |
|
269 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" | |
269 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} |
|
270 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} | |
270 | RELEASE_ARCH=${RELEASE_ARCH:=arm64} |
|
271 | RELEASE_ARCH=${RELEASE_ARCH:=arm64} | |
271 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} |
|
272 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} | |
272 | CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} |
|
273 | CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} | |
273 | else |
|
274 | else | |
274 | echo "error: Only Raspberry PI 3 and 3B+ support 64bit" |
|
275 | echo "error: Only Raspberry PI 3 and 3B+ support 64bit" | |
275 | exit 1 |
|
276 | exit 1 | |
276 | fi |
|
277 | fi | |
277 | fi |
|
278 | fi | |
278 |
|
279 | |||
279 | ################################## |
|
280 | ################################## | |
280 | # 32 bit config |
|
281 | # 32 bit config | |
281 | ################################## |
|
282 | ################################## | |
282 | if [ "$SET_ARCH" = 32 ] ; then |
|
283 | if [ "$SET_ARCH" = 32 ] ; then | |
283 | echo "32 bit mode selected - Setting up enviroment" |
|
284 | echo "32 bit mode selected - Setting up enviroment" | |
284 | #General 32bit configuration |
|
285 | #General 32bit configuration | |
285 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
286 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} | |
286 | KERNEL_ARCH=${KERNEL_ARCH:=arm} |
|
287 | KERNEL_ARCH=${KERNEL_ARCH:=arm} | |
287 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} |
|
288 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} | |
288 |
|
289 | |||
289 | #Raspberry setting grouped by board compability |
|
290 | #Raspberry setting grouped by board compability | |
290 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then |
|
291 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then | |
291 | echo "Setting settings for bcm2835 Raspberry PI boards" |
|
292 | echo "Setting settings for bcm2835 Raspberry PI boards" | |
292 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" |
|
293 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" | |
293 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} |
|
294 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} | |
294 | RELEASE_ARCH=${RELEASE_ARCH:=armel} |
|
295 | RELEASE_ARCH=${RELEASE_ARCH:=armel} | |
295 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} |
|
296 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} | |
296 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} |
|
297 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} | |
297 | fi |
|
298 | fi | |
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 | echo "Setting settings for bcm2837 Raspberry PI boards" |
|
300 | echo "Setting settings for bcm2837 Raspberry PI boards" | |
300 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
301 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" | |
301 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
302 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} | |
302 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} |
|
303 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} | |
303 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} |
|
304 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} | |
304 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} |
|
305 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} | |
305 | fi |
|
306 | fi | |
306 | fi |
|
307 | fi | |
307 | #SET_ARCH not set |
|
308 | #SET_ARCH not set | |
308 | else |
|
309 | else | |
309 | echo "error: Please set '32' or '64' as value for SET_ARCH" |
|
310 | echo "error: Please set '32' or '64' as value for SET_ARCH" | |
310 | exit 1 |
|
311 | exit 1 | |
311 | fi |
|
312 | fi | |
312 |
|
313 | |||
313 | #Device specific configuration |
|
314 | #Device specific configuration | |
314 | echo "Select DTB-File" |
|
315 | echo "Select DTB-File" | |
315 | case "$RPI_MODEL" in |
|
316 | case "$RPI_MODEL" in | |
316 | 0) |
|
317 | 0) | |
317 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} |
|
318 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} | |
318 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
319 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
319 | ;; |
|
320 | ;; | |
320 | 1) |
|
321 | 1) | |
321 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} |
|
322 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} | |
322 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
323 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
323 | ;; |
|
324 | ;; | |
324 | 1P) |
|
325 | 1P) | |
325 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} |
|
326 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} | |
326 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
327 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
327 | ;; |
|
328 | ;; | |
328 | 2) |
|
329 | 2) | |
329 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} |
|
330 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} | |
330 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} |
|
331 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} | |
331 | ;; |
|
332 | ;; | |
332 | 3) |
|
333 | 3) | |
333 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
334 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} | |
334 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
335 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} | |
335 | ;; |
|
336 | ;; | |
336 | 3P) |
|
337 | 3P) | |
337 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
338 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} | |
338 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
339 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} | |
339 | ;; |
|
340 | ;; | |
340 | *) |
|
341 | *) | |
341 | echo "error: Raspberry Pi model $RPI_MODEL is not supported!" |
|
342 | echo "error: Raspberry Pi model $RPI_MODEL is not supported!" | |
342 | exit 1 |
|
343 | exit 1 | |
343 | ;; |
|
344 | ;; | |
344 | esac |
|
345 | esac | |
345 | echo "$DTB_FILE selected" |
|
346 | echo "$DTB_FILE selected" | |
346 |
|
347 | |||
347 | #DEBUG off |
|
348 | #DEBUG off | |
348 | set +x |
|
349 | set +x | |
349 |
|
350 | |||
350 | # Check if the internal wireless interface is supported by the RPi model |
|
351 | # Check if the internal wireless interface is supported by the RPi model | |
351 | if [ "$ENABLE_WIRELESS" = true ] ; then |
|
352 | if [ "$ENABLE_WIRELESS" = true ] ; then | |
352 | if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then |
|
353 | if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then | |
353 | echo "error: The selected Raspberry Pi model has no internal wireless interface" |
|
354 | echo "error: The selected Raspberry Pi model has no internal wireless interface" | |
354 | exit 1 |
|
355 | exit 1 | |
355 | else |
|
356 | else | |
356 | echo "Raspberry Pi $RPI_MODEL has WIFI support" |
|
357 | echo "Raspberry Pi $RPI_MODEL has WIFI support" | |
357 | fi |
|
358 | fi | |
358 | fi |
|
359 | fi | |
359 |
|
360 | |||
360 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported |
|
361 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported | |
361 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then |
|
362 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then | |
362 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then |
|
363 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then | |
363 | echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" |
|
364 | echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" | |
364 | exit 1 |
|
365 | exit 1 | |
365 | fi |
|
366 | fi | |
366 | fi |
|
367 | fi | |
367 |
|
368 | |||
368 | if [ "$ENABLE_VIDEOCORE" = true ] ; then |
|
369 | if [ "$ENABLE_VIDEOCORE" = true ] ; then | |
369 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" |
|
370 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" | |
370 | fi |
|
371 | fi | |
371 |
|
372 | |||
372 | # Add libncurses5 to enable kernel menuconfig |
|
373 | # Add libncurses5 to enable kernel menuconfig | |
373 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
374 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
374 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" |
|
375 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" | |
375 | fi |
|
376 | fi | |
376 |
|
377 | |||
377 | # Add ccache compiler cache for (faster) kernel cross (re)compilation |
|
378 | # Add ccache compiler cache for (faster) kernel cross (re)compilation | |
378 | if [ "$KERNEL_CCACHE" = true ] ; then |
|
379 | if [ "$KERNEL_CCACHE" = true ] ; then | |
379 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" |
|
380 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" | |
380 | fi |
|
381 | fi | |
381 |
|
382 | |||
382 | # Add cryptsetup package to enable filesystem encryption |
|
383 | # Add cryptsetup package to enable filesystem encryption | |
383 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
384 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
384 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" |
|
385 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" | |
385 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" |
|
386 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" | |
386 |
|
387 | |||
387 | if [ -z "$CRYPTFS_PASSWORD" ] ; then |
|
388 | if [ -z "$CRYPTFS_PASSWORD" ] ; then | |
388 | echo "error: no password defined (CRYPTFS_PASSWORD)!" |
|
389 | echo "error: no password defined (CRYPTFS_PASSWORD)!" | |
389 | exit 1 |
|
390 | exit 1 | |
390 | fi |
|
391 | fi | |
391 | ENABLE_INITRAMFS=true |
|
392 | ENABLE_INITRAMFS=true | |
392 | fi |
|
393 | fi | |
393 |
|
394 | |||
394 | # Add initramfs generation tools |
|
395 | # Add initramfs generation tools | |
395 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
396 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
396 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" |
|
397 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" | |
397 | fi |
|
398 | fi | |
398 |
|
399 | |||
399 | # Add device-tree-compiler required for building the U-Boot bootloader |
|
400 | # Add device-tree-compiler required for building the U-Boot bootloader | |
400 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
401 | if [ "$ENABLE_UBOOT" = true ] ; then | |
401 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" |
|
402 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" | |
402 | else |
|
403 | else | |
403 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
404 | if [ "$ENABLE_UBOOTUSB" = true ] ; then | |
404 | echo "error: Enabling UBOOTUSB requires u-boot to be enabled" |
|
405 | echo "error: Enabling UBOOTUSB requires u-boot to be enabled" | |
405 | exit 1 |
|
406 | exit 1 | |
406 | fi |
|
407 | fi | |
407 | fi |
|
408 | fi | |
408 |
|
409 | |||
409 | # Check if root SSH (v2) public key file exists |
|
410 | # Check if root SSH (v2) public key file exists | |
410 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then |
|
411 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then | |
411 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then |
|
412 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then | |
412 | echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" |
|
413 | echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" | |
413 | exit 1 |
|
414 | exit 1 | |
414 | fi |
|
415 | fi | |
415 | fi |
|
416 | fi | |
416 |
|
417 | |||
417 | # Check if $USER_NAME SSH (v2) public key file exists |
|
418 | # Check if $USER_NAME SSH (v2) public key file exists | |
418 | if [ -n "$SSH_USER_PUB_KEY" ] ; then |
|
419 | if [ -n "$SSH_USER_PUB_KEY" ] ; then | |
419 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then |
|
420 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then | |
420 | echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" |
|
421 | echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" | |
421 | exit 1 |
|
422 | exit 1 | |
422 | fi |
|
423 | fi | |
423 | fi |
|
424 | fi | |
424 |
|
425 | |||
425 | # Check if all required packages are installed on the build system |
|
426 | # Check if all required packages are installed on the build system | |
426 | for package in $REQUIRED_PACKAGES ; do |
|
427 | for package in $REQUIRED_PACKAGES ; do | |
427 | if [ "$(dpkg-query -W -f='${Status}' $package)" != "install ok installed" ] ; then |
|
428 | if [ "$(dpkg-query -W -f='${Status}' $package)" != "install ok installed" ] ; then | |
428 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
429 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" | |
429 | fi |
|
430 | fi | |
430 | done |
|
431 | done | |
431 |
|
432 | |||
432 | # If there are missing packages ask confirmation for install, or exit |
|
433 | # If there are missing packages ask confirmation for install, or exit | |
433 | if [ -n "$MISSING_PACKAGES" ] ; then |
|
434 | if [ -n "$MISSING_PACKAGES" ] ; then | |
434 | echo "the following packages needed by this script are not installed:" |
|
435 | echo "the following packages needed by this script are not installed:" | |
435 | echo "$MISSING_PACKAGES" |
|
436 | echo "$MISSING_PACKAGES" | |
436 |
|
437 | |||
437 | printf "\ndo you want to install the missing packages right now? [y/n] " |
|
438 | printf "\ndo you want to install the missing packages right now? [y/n] " | |
438 | read -r confirm |
|
439 | read -r confirm | |
439 | [ "$confirm" != "y" ] && exit 1 |
|
440 | [ "$confirm" != "y" ] && exit 1 | |
440 |
|
441 | |||
441 | # Make sure all missing required packages are installed |
|
442 | # Make sure all missing required packages are installed | |
442 | apt-get -qq -y install "${MISSING_PACKAGES}" |
|
443 | apt-get -qq -y install "${MISSING_PACKAGES}" | |
443 | fi |
|
444 | fi | |
444 |
|
445 | |||
445 | # Check if ./bootstrap.d directory exists |
|
446 | # Check if ./bootstrap.d directory exists | |
446 | if [ ! -d "./bootstrap.d/" ] ; then |
|
447 | if [ ! -d "./bootstrap.d/" ] ; then | |
447 | echo "error: './bootstrap.d' required directory not found!" |
|
448 | echo "error: './bootstrap.d' required directory not found!" | |
448 | exit 1 |
|
449 | exit 1 | |
449 | fi |
|
450 | fi | |
450 |
|
451 | |||
451 | # Check if ./files directory exists |
|
452 | # Check if ./files directory exists | |
452 | if [ ! -d "./files/" ] ; then |
|
453 | if [ ! -d "./files/" ] ; then | |
453 | echo "error: './files' required directory not found!" |
|
454 | echo "error: './files' required directory not found!" | |
454 | exit 1 |
|
455 | exit 1 | |
455 | fi |
|
456 | fi | |
456 |
|
457 | |||
457 | # Check if specified KERNELSRC_DIR directory exists |
|
458 | # Check if specified KERNELSRC_DIR directory exists | |
458 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
459 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then | |
459 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" |
|
460 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" | |
460 | exit 1 |
|
461 | exit 1 | |
461 | fi |
|
462 | fi | |
462 |
|
463 | |||
463 | # Check if specified UBOOTSRC_DIR directory exists |
|
464 | # Check if specified UBOOTSRC_DIR directory exists | |
464 | if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then |
|
465 | if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then | |
465 | echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" |
|
466 | echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" | |
466 | exit 1 |
|
467 | exit 1 | |
467 | fi |
|
468 | fi | |
468 |
|
469 | |||
469 | # Check if specified VIDEOCORESRC_DIR directory exists |
|
470 | # Check if specified VIDEOCORESRC_DIR directory exists | |
470 | if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then |
|
471 | if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then | |
471 | echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" |
|
472 | echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" | |
472 | exit 1 |
|
473 | exit 1 | |
473 | fi |
|
474 | fi | |
474 |
|
475 | |||
475 | # Check if specified FBTURBOSRC_DIR directory exists |
|
476 | # Check if specified FBTURBOSRC_DIR directory exists | |
476 | if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then |
|
477 | if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then | |
477 | echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" |
|
478 | echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" | |
478 | exit 1 |
|
479 | exit 1 | |
479 | fi |
|
480 | fi | |
480 |
|
481 | |||
481 | # Check if specified CHROOT_SCRIPTS directory exists |
|
482 | # Check if specified CHROOT_SCRIPTS directory exists | |
482 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
483 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then | |
483 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" |
|
484 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" | |
484 | exit 1 |
|
485 | exit 1 | |
485 | fi |
|
486 | fi | |
486 |
|
487 | |||
487 | # Check if specified device mapping already exists (will be used by cryptsetup) |
|
488 | # Check if specified device mapping already exists (will be used by cryptsetup) | |
488 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then |
|
489 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then | |
489 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" |
|
490 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" | |
490 | exit 1 |
|
491 | exit 1 | |
491 | fi |
|
492 | fi | |
492 |
|
493 | |||
493 | # Don't clobber an old build |
|
494 | # Don't clobber an old build | |
494 | if [ -e "$BUILDDIR" ] ; then |
|
495 | if [ -e "$BUILDDIR" ] ; then | |
495 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
496 | echo "error: directory ${BUILDDIR} already exists, not proceeding" | |
496 | exit 1 |
|
497 | exit 1 | |
497 | fi |
|
498 | fi | |
498 |
|
499 | |||
499 | # Setup chroot directory |
|
500 | # Setup chroot directory | |
500 | mkdir -p "${R}" |
|
501 | mkdir -p "${R}" | |
501 |
|
502 | |||
502 | # Check if build directory has enough of free disk space >512MB |
|
503 | # Check if build directory has enough of free disk space >512MB | |
503 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then |
|
504 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then | |
504 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" |
|
505 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" | |
505 | exit 1 |
|
506 | exit 1 | |
506 | fi |
|
507 | fi | |
507 |
|
508 | |||
508 | set -x |
|
509 | set -x | |
509 |
|
510 | |||
510 | # Call "cleanup" function on various signals and errors |
|
511 | # Call "cleanup" function on various signals and errors | |
511 | trap cleanup 0 1 2 3 6 |
|
512 | trap cleanup 0 1 2 3 6 | |
512 |
|
513 | |||
513 | # Add required packages for the minbase installation |
|
514 | # Add required packages for the minbase installation | |
514 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
515 | if [ "$ENABLE_MINBASE" = true ] ; then | |
515 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" |
|
516 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" | |
516 | fi |
|
517 | fi | |
517 |
|
518 | |||
518 | # Add parted package, required to get partprobe utility |
|
519 | # Add parted package, required to get partprobe utility | |
519 | if [ "$EXPANDROOT" = true ] ; then |
|
520 | if [ "$EXPANDROOT" = true ] ; then | |
520 | APT_INCLUDES="${APT_INCLUDES},parted" |
|
521 | APT_INCLUDES="${APT_INCLUDES},parted" | |
521 | fi |
|
522 | fi | |
522 |
|
523 | |||
523 | # Add dbus package, recommended if using systemd |
|
524 | # Add dbus package, recommended if using systemd | |
524 | if [ "$ENABLE_DBUS" = true ] ; then |
|
525 | if [ "$ENABLE_DBUS" = true ] ; then | |
525 | APT_INCLUDES="${APT_INCLUDES},dbus" |
|
526 | APT_INCLUDES="${APT_INCLUDES},dbus" | |
526 | fi |
|
527 | fi | |
527 |
|
528 | |||
528 | # Add iptables IPv4/IPv6 package |
|
529 | # Add iptables IPv4/IPv6 package | |
529 | if [ "$ENABLE_IPTABLES" = true ] ; then |
|
530 | if [ "$ENABLE_IPTABLES" = true ] ; then | |
530 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" |
|
531 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" | |
531 | fi |
|
532 | fi | |
532 |
|
533 | |||
533 | # Add openssh server package |
|
534 | # Add openssh server package | |
534 | if [ "$ENABLE_SSHD" = true ] ; then |
|
535 | if [ "$ENABLE_SSHD" = true ] ; then | |
535 | APT_INCLUDES="${APT_INCLUDES},openssh-server" |
|
536 | APT_INCLUDES="${APT_INCLUDES},openssh-server" | |
536 | fi |
|
537 | fi | |
537 |
|
538 | |||
538 | # Add alsa-utils package |
|
539 | # Add alsa-utils package | |
539 | if [ "$ENABLE_SOUND" = true ] ; then |
|
540 | if [ "$ENABLE_SOUND" = true ] ; then | |
540 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" |
|
541 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" | |
541 | fi |
|
542 | fi | |
542 |
|
543 | |||
543 | # Add rng-tools package |
|
544 | # Add rng-tools package | |
544 | if [ "$ENABLE_HWRANDOM" = true ] ; then |
|
545 | if [ "$ENABLE_HWRANDOM" = true ] ; then | |
545 | APT_INCLUDES="${APT_INCLUDES},rng-tools" |
|
546 | APT_INCLUDES="${APT_INCLUDES},rng-tools" | |
546 | fi |
|
547 | fi | |
547 |
|
548 | |||
548 | # Add fbturbo video driver |
|
549 | # Add fbturbo video driver | |
549 | if [ "$ENABLE_FBTURBO" = true ] ; then |
|
550 | if [ "$ENABLE_FBTURBO" = true ] ; then | |
550 | # Enable xorg package dependencies |
|
551 | # Enable xorg package dependencies | |
551 | ENABLE_XORG=true |
|
552 | ENABLE_XORG=true | |
552 | fi |
|
553 | fi | |
553 |
|
554 | |||
554 | # Add user defined window manager package |
|
555 | # Add user defined window manager package | |
555 | if [ -n "$ENABLE_WM" ] ; then |
|
556 | if [ -n "$ENABLE_WM" ] ; then | |
556 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" |
|
557 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" | |
557 |
|
558 | |||
558 | # Enable xorg package dependencies |
|
559 | # Enable xorg package dependencies | |
559 | ENABLE_XORG=true |
|
560 | ENABLE_XORG=true | |
560 | fi |
|
561 | fi | |
561 |
|
562 | |||
562 | # Add xorg package |
|
563 | # Add xorg package | |
563 | if [ "$ENABLE_XORG" = true ] ; then |
|
564 | if [ "$ENABLE_XORG" = true ] ; then | |
564 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" |
|
565 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" | |
565 | fi |
|
566 | fi | |
566 |
|
567 | |||
567 | # Replace selected packages with smaller clones |
|
568 | # Replace selected packages with smaller clones | |
568 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
569 | if [ "$ENABLE_REDUCE" = true ] ; then | |
569 | # Add levee package instead of vim-tiny |
|
570 | # Add levee package instead of vim-tiny | |
570 | if [ "$REDUCE_VIM" = true ] ; then |
|
571 | if [ "$REDUCE_VIM" = true ] ; then | |
571 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" |
|
572 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" | |
572 | fi |
|
573 | fi | |
573 |
|
574 | |||
574 | # Add dropbear package instead of openssh-server |
|
575 | # Add dropbear package instead of openssh-server | |
575 | if [ "$REDUCE_SSHD" = true ] ; then |
|
576 | if [ "$REDUCE_SSHD" = true ] ; then | |
576 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" |
|
577 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" | |
577 | fi |
|
578 | fi | |
578 | fi |
|
579 | fi | |
579 |
|
580 | |||
580 | # Configure kernel sources if no KERNELSRC_DIR |
|
581 | # Configure kernel sources if no KERNELSRC_DIR | |
581 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
582 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then | |
582 | KERNELSRC_CONFIG=true |
|
583 | KERNELSRC_CONFIG=true | |
583 | fi |
|
584 | fi | |
584 |
|
585 | |||
585 | # Configure reduced kernel |
|
586 | # Configure reduced kernel | |
586 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
587 | if [ "$KERNEL_REDUCE" = true ] ; then | |
587 | KERNELSRC_CONFIG=false |
|
588 | KERNELSRC_CONFIG=false | |
588 | fi |
|
589 | fi | |
589 |
|
590 | |||
590 | # Configure qemu compatible kernel |
|
591 | # Configure qemu compatible kernel | |
591 | if [ "$ENABLE_QEMU" = true ] ; then |
|
592 | if [ "$ENABLE_QEMU" = true ] ; then | |
592 | DTB_FILE=vexpress-v2p-ca15_a7.dtb |
|
593 | DTB_FILE=vexpress-v2p-ca15_a7.dtb | |
593 | UBOOT_CONFIG=vexpress_ca15_tc2_defconfig |
|
594 | UBOOT_CONFIG=vexpress_ca15_tc2_defconfig | |
594 | KERNEL_DEFCONFIG="vexpress_defconfig" |
|
595 | KERNEL_DEFCONFIG="vexpress_defconfig" | |
595 | if [ "$KERNEL_MENUCONFIG" = false ] ; then |
|
596 | if [ "$KERNEL_MENUCONFIG" = false ] ; then | |
596 | KERNEL_OLDDEFCONFIG=true |
|
597 | KERNEL_OLDDEFCONFIG=true | |
597 | fi |
|
598 | fi | |
598 | fi |
|
599 | fi | |
599 |
|
600 | |||
600 | # Execute bootstrap scripts |
|
601 | # Execute bootstrap scripts | |
601 | for SCRIPT in bootstrap.d/*.sh; do |
|
602 | for SCRIPT in bootstrap.d/*.sh; do | |
602 | head -n 3 "$SCRIPT" |
|
603 | head -n 3 "$SCRIPT" | |
603 | . "$SCRIPT" |
|
604 | . "$SCRIPT" | |
604 | done |
|
605 | done | |
605 |
|
606 | |||
606 | ## Execute custom bootstrap scripts |
|
607 | ## Execute custom bootstrap scripts | |
607 | if [ -d "custom.d" ] ; then |
|
608 | if [ -d "custom.d" ] ; then | |
608 | for SCRIPT in custom.d/*.sh; do |
|
609 | for SCRIPT in custom.d/*.sh; do | |
609 | . "$SCRIPT" |
|
610 | . "$SCRIPT" | |
610 | done |
|
611 | done | |
611 | fi |
|
612 | fi | |
612 |
|
613 | |||
613 | # Execute custom scripts inside the chroot |
|
614 | # Execute custom scripts inside the chroot | |
614 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
615 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then | |
615 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
616 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" | |
616 | chroot_exec /bin/bash -x <<'EOF' |
|
617 | chroot_exec /bin/bash -x <<'EOF' | |
617 | for SCRIPT in /chroot_scripts/* ; do |
|
618 | for SCRIPT in /chroot_scripts/* ; do | |
618 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
619 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then | |
619 | $SCRIPT |
|
620 | $SCRIPT | |
620 | fi |
|
621 | fi | |
621 | done |
|
622 | done | |
622 | EOF |
|
623 | EOF | |
623 | rm -rf "${R}/chroot_scripts" |
|
624 | rm -rf "${R}/chroot_scripts" | |
624 | fi |
|
625 | fi | |
625 |
|
626 | |||
626 | # Remove c/c++ build environment from the chroot |
|
627 | # Remove c/c++ build environment from the chroot | |
627 | chroot_remove_cc |
|
628 | chroot_remove_cc | |
628 |
|
629 | |||
629 | # Generate required machine-id |
|
630 | # Generate required machine-id | |
630 | MACHINE_ID=$(dbus-uuidgen) |
|
631 | MACHINE_ID=$(dbus-uuidgen) | |
631 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" |
|
632 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" | |
632 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" |
|
633 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" | |
633 |
|
634 | |||
634 | # APT Cleanup |
|
635 | # APT Cleanup | |
635 | chroot_exec apt-get -y clean |
|
636 | chroot_exec apt-get -y clean | |
636 | chroot_exec apt-get -y autoclean |
|
637 | chroot_exec apt-get -y autoclean | |
637 | chroot_exec apt-get -y autoremove |
|
638 | chroot_exec apt-get -y autoremove | |
638 |
|
639 | |||
639 | # Unmount mounted filesystems |
|
640 | # Unmount mounted filesystems | |
640 | umount -l "${R}/proc" |
|
641 | umount -l "${R}/proc" | |
641 | umount -l "${R}/sys" |
|
642 | umount -l "${R}/sys" | |
642 |
|
643 | |||
643 | # Clean up directories |
|
644 | # Clean up directories | |
644 | rm -rf "${R}/run/*" |
|
645 | rm -rf "${R}/run/*" | |
645 | rm -rf "${R}/tmp/*" |
|
646 | rm -rf "${R}/tmp/*" | |
646 |
|
647 | |||
647 | # Clean up files |
|
648 | # Clean up files | |
648 | rm -f "${ETC_DIR}/ssh/ssh_host_*" |
|
649 | rm -f "${ETC_DIR}/ssh/ssh_host_*" | |
649 | rm -f "${ETC_DIR}/dropbear/dropbear_*" |
|
650 | rm -f "${ETC_DIR}/dropbear/dropbear_*" | |
650 | rm -f "${ETC_DIR}/apt/sources.list.save" |
|
651 | rm -f "${ETC_DIR}/apt/sources.list.save" | |
651 | rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" |
|
652 | rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" | |
652 | rm -f "${ETC_DIR}/*-" |
|
653 | rm -f "${ETC_DIR}/*-" | |
653 | rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" |
|
654 | rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" | |
654 | rm -f "${ETC_DIR}/resolv.conf" |
|
655 | rm -f "${ETC_DIR}/resolv.conf" | |
655 | rm -f "${R}/root/.bash_history" |
|
656 | rm -f "${R}/root/.bash_history" | |
656 | rm -f "${R}/var/lib/urandom/random-seed" |
|
657 | rm -f "${R}/var/lib/urandom/random-seed" | |
657 | rm -f "${R}/initrd.img" |
|
658 | rm -f "${R}/initrd.img" | |
658 | rm -f "${R}/vmlinuz" |
|
659 | rm -f "${R}/vmlinuz" | |
659 | rm -f "${R}${QEMU_BINARY}" |
|
660 | rm -f "${R}${QEMU_BINARY}" | |
660 |
|
661 | |||
661 | if [ "$ENABLE_QEMU" = true ] ; then |
|
662 | if [ "$ENABLE_QEMU" = true ] ; then | |
662 | # Setup QEMU directory |
|
663 | # Setup QEMU directory | |
663 | mkdir "${BASEDIR}/qemu" |
|
664 | mkdir "${BASEDIR}/qemu" | |
664 |
|
665 | |||
665 | # Copy kernel image to QEMU directory |
|
666 | # Copy kernel image to QEMU directory | |
666 | install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" |
|
667 | install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" | |
667 |
|
668 | |||
668 | # Copy kernel config to QEMU directory |
|
669 | # Copy kernel config to QEMU directory | |
669 | install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" |
|
670 | install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" | |
670 |
|
671 | |||
671 | # Copy kernel dtbs to QEMU directory |
|
672 | # Copy kernel dtbs to QEMU directory | |
672 | for dtb in "${BOOT_DIR}/"*.dtb ; do |
|
673 | for dtb in "${BOOT_DIR}/"*.dtb ; do | |
673 | if [ -f "${dtb}" ] ; then |
|
674 | if [ -f "${dtb}" ] ; then | |
674 | install_readonly "${dtb}" "${BASEDIR}/qemu/" |
|
675 | install_readonly "${dtb}" "${BASEDIR}/qemu/" | |
675 | fi |
|
676 | fi | |
676 | done |
|
677 | done | |
677 |
|
678 | |||
678 | # Copy kernel overlays to QEMU directory |
|
679 | # Copy kernel overlays to QEMU directory | |
679 | if [ -d "${BOOT_DIR}/overlays" ] ; then |
|
680 | if [ -d "${BOOT_DIR}/overlays" ] ; then | |
680 | # Setup overlays dtbs directory |
|
681 | # Setup overlays dtbs directory | |
681 | mkdir "${BASEDIR}/qemu/overlays" |
|
682 | mkdir "${BASEDIR}/qemu/overlays" | |
682 |
|
683 | |||
683 | for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do |
|
684 | for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do | |
684 | if [ -f "${dtb}" ] ; then |
|
685 | if [ -f "${dtb}" ] ; then | |
685 | install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" |
|
686 | install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" | |
686 | fi |
|
687 | fi | |
687 | done |
|
688 | done | |
688 | fi |
|
689 | fi | |
689 |
|
690 | |||
690 | # Copy u-boot files to QEMU directory |
|
691 | # Copy u-boot files to QEMU directory | |
691 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
692 | if [ "$ENABLE_UBOOT" = true ] ; then | |
692 | if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then |
|
693 | if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then | |
693 | install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" |
|
694 | install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" | |
694 | fi |
|
695 | fi | |
695 | if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then |
|
696 | if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then | |
696 | install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" |
|
697 | install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" | |
697 | fi |
|
698 | fi | |
698 | if [ -f "${BOOT_DIR}/boot.scr" ] ; then |
|
699 | if [ -f "${BOOT_DIR}/boot.scr" ] ; then | |
699 | install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" |
|
700 | install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" | |
700 | fi |
|
701 | fi | |
701 | fi |
|
702 | fi | |
702 |
|
703 | |||
703 | # Copy initramfs to QEMU directory |
|
704 | # Copy initramfs to QEMU directory | |
704 | if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then |
|
705 | if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then | |
705 | install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" |
|
706 | install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" | |
706 | fi |
|
707 | fi | |
707 | fi |
|
708 | fi | |
708 |
|
709 | |||
709 | # Calculate size of the chroot directory in KB |
|
710 | # Calculate size of the chroot directory in KB | |
710 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") |
|
711 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") | |
711 |
|
712 | |||
712 | # Calculate the amount of needed 512 Byte sectors |
|
713 | # Calculate the amount of needed 512 Byte sectors | |
713 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
714 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) | |
714 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) |
|
715 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) | |
715 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") |
|
716 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") | |
716 |
|
717 | |||
717 | # The root partition is EXT4 |
|
718 | # The root partition is EXT4 | |
718 | # This means more space than the actual used space of the chroot is used. |
|
719 | # This means more space than the actual used space of the chroot is used. | |
719 | # As overhead for journaling and reserved blocks 35% are added. |
|
720 | # As overhead for journaling and reserved blocks 35% are added. | |
720 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) |
|
721 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) | |
721 |
|
722 | |||
722 | # Calculate required image size in 512 Byte sectors |
|
723 | # Calculate required image size in 512 Byte sectors | |
723 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") |
|
724 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") | |
724 |
|
725 | |||
725 | # Prepare image file |
|
726 | # Prepare image file | |
726 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
727 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
727 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" |
|
728 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" | |
728 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" |
|
729 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" | |
729 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" |
|
730 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" | |
730 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" |
|
731 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" | |
731 |
|
732 | |||
732 | # Write firmware/boot partition tables |
|
733 | # Write firmware/boot partition tables | |
733 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM |
|
734 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM | |
734 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
735 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
735 | EOM |
|
736 | EOM | |
736 |
|
737 | |||
737 | # Write root partition table |
|
738 | # Write root partition table | |
738 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM |
|
739 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM | |
739 | ${TABLE_SECTORS},${ROOT_SECTORS},83 |
|
740 | ${TABLE_SECTORS},${ROOT_SECTORS},83 | |
740 | EOM |
|
741 | EOM | |
741 |
|
742 | |||
742 | # Setup temporary loop devices |
|
743 | # Setup temporary loop devices | |
743 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" |
|
744 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" | |
744 | ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" |
|
745 | ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" | |
745 | else # ENABLE_SPLITFS=false |
|
746 | else # ENABLE_SPLITFS=false | |
746 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" |
|
747 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" | |
747 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" |
|
748 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" | |
748 |
|
749 | |||
749 | # Write partition table |
|
750 | # Write partition table | |
750 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM |
|
751 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM | |
751 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
752 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
752 | ${ROOT_OFFSET},${ROOT_SECTORS},83 |
|
753 | ${ROOT_OFFSET},${ROOT_SECTORS},83 | |
753 | EOM |
|
754 | EOM | |
754 |
|
755 | |||
755 | # Setup temporary loop devices |
|
756 | # Setup temporary loop devices | |
756 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" |
|
757 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" | |
757 | ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" |
|
758 | ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" | |
758 | fi |
|
759 | fi | |
759 |
|
760 | |||
760 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
761 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
761 | # Create dummy ext4 fs |
|
762 | # Create dummy ext4 fs | |
762 | mkfs.ext4 "$ROOT_LOOP" |
|
763 | mkfs.ext4 "$ROOT_LOOP" | |
763 |
|
764 | |||
764 | # Setup password keyfile |
|
765 | # Setup password keyfile | |
765 | touch .password |
|
766 | touch .password | |
766 | chmod 600 .password |
|
767 | chmod 600 .password | |
767 | echo -n ${CRYPTFS_PASSWORD} > .password |
|
768 | echo -n ${CRYPTFS_PASSWORD} > .password | |
768 |
|
769 | |||
769 | # Initialize encrypted partition |
|
770 | # Initialize encrypted partition | |
770 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password |
|
771 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password | |
771 |
|
772 | |||
772 | # Open encrypted partition and setup mapping |
|
773 | # Open encrypted partition and setup mapping | |
773 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" |
|
774 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" | |
774 |
|
775 | |||
775 | # Secure delete password keyfile |
|
776 | # Secure delete password keyfile | |
776 | shred -zu .password |
|
777 | shred -zu .password | |
777 |
|
778 | |||
778 | # Update temporary loop device |
|
779 | # Update temporary loop device | |
779 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" |
|
780 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" | |
780 |
|
781 | |||
781 | # Wipe encrypted partition (encryption cipher is used for randomness) |
|
782 | # Wipe encrypted partition (encryption cipher is used for randomness) | |
782 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" |
|
783 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" | |
783 | fi |
|
784 | fi | |
784 |
|
785 | |||
785 | # Build filesystems |
|
786 | # Build filesystems | |
786 | mkfs.vfat "$FRMW_LOOP" |
|
787 | mkfs.vfat "$FRMW_LOOP" | |
787 | mkfs.ext4 "$ROOT_LOOP" |
|
788 | mkfs.ext4 "$ROOT_LOOP" | |
788 |
|
789 | |||
789 | # Mount the temporary loop devices |
|
790 | # Mount the temporary loop devices | |
790 | mkdir -p "$BUILDDIR/mount" |
|
791 | mkdir -p "$BUILDDIR/mount" | |
791 | mount "$ROOT_LOOP" "$BUILDDIR/mount" |
|
792 | mount "$ROOT_LOOP" "$BUILDDIR/mount" | |
792 |
|
793 | |||
793 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
794 | mkdir -p "$BUILDDIR/mount/boot/firmware" | |
794 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" |
|
795 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" | |
795 |
|
796 | |||
796 | # Copy all files from the chroot to the loop device mount point directory |
|
797 | # Copy all files from the chroot to the loop device mount point directory | |
797 | rsync -a "${R}/" "$BUILDDIR/mount/" |
|
798 | rsync -a "${R}/" "$BUILDDIR/mount/" | |
798 |
|
799 | |||
799 | # Unmount all temporary loop devices and mount points |
|
800 | # Unmount all temporary loop devices and mount points | |
800 | cleanup |
|
801 | cleanup | |
801 |
|
802 | |||
802 | # Create block map file(s) of image(s) |
|
803 | # Create block map file(s) of image(s) | |
803 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
804 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
804 | # Create block map files for "bmaptool" |
|
805 | # Create block map files for "bmaptool" | |
805 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" |
|
806 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" | |
806 | bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" |
|
807 | bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" | |
807 |
|
808 | |||
808 | # Image was successfully created |
|
809 | # Image was successfully created | |
809 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
810 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
810 | echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
811 | echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
811 | else |
|
812 | else | |
812 | # Create block map file for "bmaptool" |
|
813 | # Create block map file for "bmaptool" | |
813 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" |
|
814 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" | |
814 |
|
815 | |||
815 | # Image was successfully created |
|
816 | # Image was successfully created | |
816 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
817 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
817 |
|
818 | |||
818 | # Create qemu qcow2 image |
|
819 | # Create qemu qcow2 image | |
819 | if [ "$ENABLE_QEMU" = true ] ; then |
|
820 | if [ "$ENABLE_QEMU" = true ] ; then | |
820 | QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
821 | QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
821 | QEMU_SIZE=16G |
|
822 | QEMU_SIZE=16G | |
822 |
|
823 | |||
823 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 |
|
824 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 | |
824 | qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE |
|
825 | qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE | |
825 |
|
826 | |||
826 | echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" |
|
827 | echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" | |
827 | fi |
|
828 | fi | |
828 | fi |
|
829 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant