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