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