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