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