rpi23-gen-image.sh
796 lines
| 25.0 KiB
| application/x-sh
|
BashLexer
Jan Wagner
|
r2 | #!/bin/sh | ||
######################################################################## | ||||
drtyhlpr
|
r120 | # rpi23-gen-image.sh 2015-2017 | ||
Jan Wagner
|
r2 | # | ||
drtyhlpr
|
r217 | # Advanced Debian "jessie", "stretch" and "buster" bootstrap script for RPi2/3 | ||
Jan Wagner
|
r2 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
# | ||||
drtyhlpr
|
r88 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> | ||
# | ||||
drtyhlpr
|
r217 | # Big thanks for patches and enhancements by 20+ github contributors! | ||
Jan Wagner
|
r2 | ######################################################################## | ||
Jan Wagner
|
r76 | # Are we running as root? | ||
if [ "$(id -u)" -ne "0" ] ; then | ||||
echo "error: this script must be executed with root privileges!" | ||||
exit 1 | ||||
fi | ||||
Jan Wagner
|
r72 | # Check if ./functions.sh script exists | ||
if [ ! -r "./functions.sh" ] ; then | ||||
Jan Wagner
|
r77 | echo "error: './functions.sh' required script not found!" | ||
Jan Wagner
|
r72 | exit 1 | ||
fi | ||||
Jan Wagner
|
r67 | # Load utility functions | ||
. ./functions.sh | ||||
Filip Pytloun
|
r45 | |||
drtyhlpr
|
r117 | # Load parameters from configuration template file | ||
Unknown
|
r336 | if [ -n "$CONFIG_TEMPLATE" ] ; then | ||
drtyhlpr
|
r117 | use_template | ||
fi | ||||
Jan Wagner
|
r70 | # Introduce settings | ||
Jan Wagner
|
r2 | set -e | ||
drtyhlpr
|
r94 | echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n" | ||
Jan Wagner
|
r2 | set -x | ||
drtyhlpr
|
r94 | # Raspberry Pi model configuration | ||
RPI_MODEL=${RPI_MODEL:=2} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2708-rpi-0-w.dtb (Used for Pi 0 and PI 0W) | ||
RPI0_DTB_FILE=${RPI0_DTB_FILE:=bcm2708-rpi-0-w.dtb} | ||||
RPI0_UBOOT_CONFIG=${RPI0_UBOOT_CONFIG:=rpi_defconfig} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2708-rpi-b.dtb (Used for Pi 1 model A and B) | ||
RPI1_DTB_FILE=${RPI1_DTB_FILE:=bcm2708-rpi-b.dtb} | ||||
RPI1_UBOOT_CONFIG=${RPI1_UBOOT_CONFIG:=rpi_defconfig} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2708-rpi-b-plus.dtb (Used for Pi 1 model B+ and A+) | ||
RPI1P_DTB_FILE=${RPI1P_DTB_FILE:=bcm2708-rpi-b-plus.dtb} | ||||
RPI1P_UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG:=rpi_defconfig} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2709-rpi-2-b.dtb (Used for Pi 2 model B) | ||
drtyhlpr
|
r94 | RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb} | ||
RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2710-rpi-3-b.dtb (Used for Pi 3 model B) | ||
drtyhlpr
|
r94 | RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb} | ||
RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig} | ||||
drtyhlpr
|
r261 | |||
Unknown
|
r254 | #bcm2710-rpi-3-b-plus.dtb (Used for Pi 3 model B+) | ||
RPI3P_DTB_FILE=${RPI3P_DTB_FILE:=bcm2710-rpi-3-b-plus.dtb} | ||||
RPI3P_UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG:=rpi_3_32b_defconfig} | ||||
drtyhlpr
|
r94 | |||
Jan Wagner
|
r21 | # Debian release | ||
Jan Wagner
|
r2 | RELEASE=${RELEASE:=jessie} | ||
Jan Wagner
|
r71 | KERNEL_ARCH=${KERNEL_ARCH:=arm} | ||
RELEASE_ARCH=${RELEASE_ARCH:=armhf} | ||||
CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} | ||||
Jan Wagner
|
r67 | COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} | ||
Brian J. Tarricone
|
r184 | if [ "$KERNEL_ARCH" = "arm64" ] ; then | ||
KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} | ||||
KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} | ||||
Unknown
|
r255 | fi | ||
drtyhlpr
|
r261 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then | ||
Unknown
|
r254 | #RASPBERRY PI 1, PI ZERO, PI ZERO W, AND COMPUTE MODULE DEFAULT Kernel BUILD CONFIGURATION | ||
KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} | ||||
KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} | ||||
Brian J. Tarricone
|
r184 | else | ||
Unknown
|
r254 | #RASPBERRY PI 2, PI 3, PI 3+, AND COMPUTE MODULE 3 DEFAULT Kernel BUILD CONFIGURATION | ||
#https://www.raspberrypi.org/documentation/linux/kernel/building.md | ||||
Brian J. Tarricone
|
r184 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} | ||
KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} | ||||
fi | ||||
Unknown
|
r254 | |||
Brian J. Tarricone
|
r184 | if [ "$RELEASE_ARCH" = "arm64" ] ; then | ||
QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} | ||||
else | ||||
QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} | ||||
fi | ||||
Bobberty
|
r146 | KERNEL_BRANCH=${KERNEL_BRANCH:=""} | ||
Jan Wagner
|
r2 | |||
drtyhlpr
|
r91 | # URLs | ||
KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux} | ||||
FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot} | ||||
Aman Sharma
|
r234 | WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm} | ||
drtyhlpr
|
r91 | COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian} | ||
FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git} | ||||
Tobias Gruetzmacher
|
r249 | UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} | ||
Unknown
|
r332 | VIDEOCORE_URL=${VIDEOCORE_URL=https://github.com/raspberrypi/userland} | ||
drtyhlpr
|
r91 | |||
Jan Wagner
|
r76 | # Build directories | ||
Denis Mosolov
|
r137 | BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}} | ||
Jan Wagner
|
r77 | BUILDDIR="${BASEDIR}/build" | ||
Bobberty
|
r146 | |||
Denis Mosolov
|
r138 | # Prepare date string for default image file name | ||
DATE="$(date +%Y-%m-%d)" | ||||
Bobberty
|
r146 | if [ -z "$KERNEL_BRANCH" ] ; then | ||
IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | ||||
else | ||||
IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | ||||
fi | ||||
Jan Wagner
|
r82 | |||
# Chroot directories | ||||
Jan Wagner
|
r77 | R="${BUILDDIR}/chroot" | ||
drtyhlpr
|
r94 | ETC_DIR="${R}/etc" | ||
LIB_DIR="${R}/lib" | ||||
BOOT_DIR="${R}/boot/firmware" | ||||
KERNEL_DIR="${R}/usr/src/linux" | ||||
Unknown
|
r355 | WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" | ||
Jan Wagner
|
r2 | |||
Stephen A. Brandli
|
r83 | # Firmware directory: Blank if download from github | ||
drtyhlpr
|
r94 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} | ||
drtyhlpr
|
r93 | |||
Jan Wagner
|
r2 | # General settings | ||
drtyhlpr
|
r94 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} | ||
Jan Wagner
|
r2 | PASSWORD=${PASSWORD:=raspberry} | ||
Denis Mosolov
|
r112 | USER_PASSWORD=${USER_PASSWORD:=raspberry} | ||
Jan Wagner
|
r2 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} | ||
Jan Wagner
|
r32 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} | ||
Filip Pytloun
|
r46 | EXPANDROOT=${EXPANDROOT:=true} | ||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r67 | # Keyboard settings | ||
XKB_MODEL=${XKB_MODEL:=""} | ||||
XKB_LAYOUT=${XKB_LAYOUT:=""} | ||||
XKB_VARIANT=${XKB_VARIANT:=""} | ||||
XKB_OPTIONS=${XKB_OPTIONS:=""} | ||||
# Network settings (DHCP) | ||||
Vincent Knecht
|
r25 | ENABLE_DHCP=${ENABLE_DHCP:=true} | ||
Jan Wagner
|
r67 | |||
# Network settings (static) | ||||
Vincent Knecht
|
r25 | NET_ADDRESS=${NET_ADDRESS:=""} | ||
NET_GATEWAY=${NET_GATEWAY:=""} | ||||
NET_DNS_1=${NET_DNS_1:=""} | ||||
NET_DNS_2=${NET_DNS_2:=""} | ||||
NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} | ||||
NET_NTP_1=${NET_NTP_1:=""} | ||||
NET_NTP_2=${NET_NTP_2:=""} | ||||
Jan Wagner
|
r2 | # APT settings | ||
APT_PROXY=${APT_PROXY:=""} | ||||
APT_SERVER=${APT_SERVER:="ftp.debian.org"} | ||||
# Feature settings | ||||
ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} | ||||
drtyhlpr
|
r125 | ENABLE_I2C=${ENABLE_I2C:=false} | ||
ENABLE_SPI=${ENABLE_SPI:=false} | ||||
Jan Wagner
|
r2 | ENABLE_IPV6=${ENABLE_IPV6:=true} | ||
ENABLE_SSHD=${ENABLE_SSHD:=true} | ||||
drtyhlpr
|
r91 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} | ||
drtyhlpr
|
r94 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} | ||
Jan Wagner
|
r2 | ENABLE_SOUND=${ENABLE_SOUND:=true} | ||
ENABLE_DBUS=${ENABLE_DBUS:=true} | ||||
ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} | ||||
ENABLE_MINGPU=${ENABLE_MINGPU:=false} | ||||
ENABLE_XORG=${ENABLE_XORG:=false} | ||||
Jan Wagner
|
r22 | ENABLE_WM=${ENABLE_WM:=""} | ||
Filip Pytloun
|
r45 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} | ||
ENABLE_USER=${ENABLE_USER:=true} | ||||
Stephen A. Brandli
|
r84 | USER_NAME=${USER_NAME:="pi"} | ||
Filip Pytloun
|
r45 | ENABLE_ROOT=${ENABLE_ROOT:=false} | ||
drtyhlpr
|
r259 | ENABLE_QEMU=${ENABLE_QEMU:=false} | ||
Unknown
|
r275 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} | ||
drtyhlpr
|
r120 | |||
# SSH settings | ||||
SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} | ||||
SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} | ||||
SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} | ||||
SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} | ||||
SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} | ||||
Jan Wagner
|
r2 | |||
# Advanced settings | ||||
Jan Wagner
|
r16 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} | ||
drtyhlpr
|
r90 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} | ||
Jan Wagner
|
r3 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} | ||
drtyhlpr
|
r139 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} | ||
Jan Wagner
|
r20 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} | ||
Unknown
|
r332 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true} | ||
VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} | ||||
drtyhlpr
|
r142 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} | ||
Jan Wagner
|
r2 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} | ||
ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} | ||||
Vincent Knecht
|
r65 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | ||
Jan Wagner
|
r77 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} | ||
drtyhlpr
|
r92 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} | ||
drtyhlpr
|
r130 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} | ||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r55 | # Kernel compilation settings | ||
BUILD_KERNEL=${BUILD_KERNEL:=false} | ||||
Jan Wagner
|
r76 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} | ||
Jan Wagner
|
r67 | KERNEL_THREADS=${KERNEL_THREADS:=1} | ||
Filip Pytloun
|
r60 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} | ||
Jan Wagner
|
r71 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} | ||
Jan Wagner
|
r75 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} | ||
drtyhlpr
|
r248 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} | ||
KERNEL_CCACHE=${KERNEL_CCACHE:=false} | ||||
Brian J. Tarricone
|
r184 | if [ "$KERNEL_ARCH" = "arm64" ] ; then | ||
KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} | ||||
else | ||||
KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} | ||||
fi | ||||
Jan Wagner
|
r75 | |||
# Kernel compilation from source directory settings | ||||
KERNELSRC_DIR=${KERNELSRC_DIR:=""} | ||||
KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} | ||||
KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} | ||||
KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} | ||||
Jan Wagner
|
r55 | |||
Jan Wagner
|
r76 | # Reduce disk usage settings | ||
REDUCE_APT=${REDUCE_APT:=true} | ||||
REDUCE_DOC=${REDUCE_DOC:=true} | ||||
REDUCE_MAN=${REDUCE_MAN:=true} | ||||
Jan Wagner
|
r77 | REDUCE_VIM=${REDUCE_VIM:=false} | ||
Jan Wagner
|
r76 | REDUCE_BASH=${REDUCE_BASH:=false} | ||
REDUCE_HWDB=${REDUCE_HWDB:=true} | ||||
REDUCE_SSHD=${REDUCE_SSHD:=true} | ||||
REDUCE_LOCALE=${REDUCE_LOCALE:=true} | ||||
Jan Wagner
|
r77 | # Encrypted filesystem settings | ||
ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} | ||||
CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} | ||||
CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} | ||||
CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} | ||||
CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} | ||||
Jan Wagner
|
r76 | # Chroot scripts directory | ||
Chris Landa
|
r40 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} | ||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r20 | # Packages required in the chroot build environment | ||
Chris Landa
|
r39 | APT_INCLUDES=${APT_INCLUDES:=""} | ||
drtyhlpr
|
r207 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils" | ||
Unknown
|
r275 | #Packages to exclude from chroot build environment | ||
APT_EXCLUDES=${APT_EXCLUDES:=""} | ||||
Jan Wagner
|
r76 | # Packages required for bootstrapping | ||
drtyhlpr
|
r142 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo" | ||
Jan Wagner
|
r76 | MISSING_PACKAGES="" | ||
Jan Wagner
|
r72 | |||
drtyhlpr
|
r142 | # Packages installed for c/c++ build environment in chroot (keep empty) | ||
COMPILER_PACKAGES="" | ||||
Jan Wagner
|
r76 | set +x | ||
Jan Wagner
|
r72 | |||
Unknown
|
r275 | #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts | ||
if [ "$ENABLE_SYSVINIT" = false ] ; then | ||||
Unknown
|
r276 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" | ||
Unknown
|
r275 | fi | ||
drtyhlpr
|
r94 | # Set Raspberry Pi model specific configuration | ||
drtyhlpr
|
r258 | if [ "$RPI_MODEL" = 0 ] ; then | ||
Unknown
|
r271 | DTB_FILE=${RPI0_DTB_FILE} | ||
UBOOT_CONFIG=${RPI0_UBOOT_CONFIG} | ||||
Unknown
|
r254 | elif [ "$RPI_MODEL" = 1 ] ; then | ||
Unknown
|
r271 | DTB_FILE=${RPI1_DTB_FILE} | ||
UBOOT_CONFIG=${RPI1_UBOOT_CONFIG} | ||||
Unknown
|
r254 | elif [ "$RPI_MODEL" = 1P ] ; then | ||
Unknown
|
r271 | DTB_FILE=${RPI1P_DTB_FILE} | ||
UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG} | ||||
Unknown
|
r254 | elif [ "$RPI_MODEL" = 2 ] ; then | ||
drtyhlpr
|
r94 | DTB_FILE=${RPI2_DTB_FILE} | ||
UBOOT_CONFIG=${RPI2_UBOOT_CONFIG} | ||||
elif [ "$RPI_MODEL" = 3 ] ; then | ||||
DTB_FILE=${RPI3_DTB_FILE} | ||||
UBOOT_CONFIG=${RPI3_UBOOT_CONFIG} | ||||
Unknown
|
r254 | elif [ "$RPI_MODEL" = 3P ] ; then | ||
DTB_FILE=${RPI3P_DTB_FILE} | ||||
UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG} | ||||
drtyhlpr
|
r94 | else | ||
echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!" | ||||
exit 1 | ||||
fi | ||||
# Check if the internal wireless interface is supported by the RPi model | ||||
Unknown
|
r271 | if [ "$ENABLE_WIRELESS" = true ] && ([ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ]); then | ||
drtyhlpr
|
r94 | echo "error: The selected Raspberry Pi model has no internal wireless interface" | ||
exit 1 | ||||
Unknown
|
r250 | fi | ||
drtyhlpr
|
r94 | |||
drtyhlpr
|
r130 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported | ||
Unknown
|
r336 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then | ||
drtyhlpr
|
r132 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then | ||
echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" | ||||
exit 1 | ||||
fi | ||||
drtyhlpr
|
r130 | fi | ||
drtyhlpr
|
r142 | # Build RPi2/3 Linux kernel if required by Debian release | ||
drtyhlpr
|
r217 | if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then | ||
drtyhlpr
|
r94 | BUILD_KERNEL=true | ||
drtyhlpr
|
r92 | fi | ||
Jan Wagner
|
r55 | # Add packages required for kernel cross compilation | ||
if [ "$BUILD_KERNEL" = true ] ; then | ||||
Bobberty
|
r146 | if [ "$KERNEL_ARCH" = "arm" ] ; then | ||
Unknown
|
r270 | if [ "$RELEASE_ARCH" = "armel" ]; then | ||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" | ||||
fi | ||||
if [ "$RELEASE_ARCH" = "armhf" ]; then | ||||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" | ||||
fi | ||||
Unknown
|
r283 | fi | ||
if [ "$RELEASE_ARCH" = "arm64" ]; then | ||||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" | ||||
Bobberty
|
r146 | fi | ||
Jan Wagner
|
r76 | fi | ||
Jan Wagner
|
r75 | |||
Unknown
|
r332 | if [ "$ENABLE_VIDEOCORE" = true ] ; then | ||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" | ||||
fi | ||||
Jan Wagner
|
r76 | # Add libncurses5 to enable kernel menuconfig | ||
if [ "$KERNEL_MENUCONFIG" = true ] ; then | ||||
Unknown
|
r337 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" | ||
Jan Wagner
|
r55 | fi | ||
drtyhlpr
|
r248 | # Add ccache compiler cache for (faster) kernel cross (re)compilation | ||
if [ "$KERNEL_CCACHE" = true ] ; then | ||||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" | ||||
fi | ||||
Jan Wagner
|
r77 | # Add cryptsetup package to enable filesystem encryption | ||
if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | ||||
REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" | ||||
drtyhlpr
|
r259 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" | ||
Jan Wagner
|
r77 | |||
if [ -z "$CRYPTFS_PASSWORD" ] ; then | ||||
echo "error: no password defined (CRYPTFS_PASSWORD)!" | ||||
exit 1 | ||||
fi | ||||
ENABLE_INITRAMFS=true | ||||
fi | ||||
# Add initramfs generation tools | ||||
if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},initramfs-tools" | ||||
fi | ||||
drtyhlpr
|
r114 | # Add device-tree-compiler required for building the U-Boot bootloader | ||
if [ "$ENABLE_UBOOT" = true ] ; then | ||||
drtyhlpr
|
r267 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex" | ||
drtyhlpr
|
r114 | fi | ||
drtyhlpr
|
r120 | # Check if root SSH (v2) public key file exists | ||
Unknown
|
r336 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then | ||
drtyhlpr
|
r120 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then | ||
echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" | ||||
exit 1 | ||||
fi | ||||
fi | ||||
# Check if $USER_NAME SSH (v2) public key file exists | ||||
Unknown
|
r336 | if [ -n "$SSH_USER_PUB_KEY" ] ; then | ||
drtyhlpr
|
r120 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then | ||
echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" | ||||
exit 1 | ||||
fi | ||||
fi | ||||
Jan Wagner
|
r76 | # Check if all required packages are installed on the build system | ||
Jan Wagner
|
r8 | for package in $REQUIRED_PACKAGES ; do | ||
Unknown
|
r336 | if [ "$(dpkg-query -W -f='${Status}' $package)" != "install ok installed" ] ; then | ||
Jan Wagner
|
r75 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" | ||
Jan Wagner
|
r8 | fi | ||
done | ||||
Aurélien COUDERC
|
r106 | # If there are missing packages ask confirmation for install, or exit | ||
Jan Wagner
|
r8 | if [ -n "$MISSING_PACKAGES" ] ; then | ||
echo "the following packages needed by this script are not installed:" | ||||
echo "$MISSING_PACKAGES" | ||||
Unknown
|
r337 | printf "\ndo you want to install the missing packages right now? [y/n] " | ||
Unknown
|
r336 | read -r confirm | ||
Jan Wagner
|
r76 | [ "$confirm" != "y" ] && exit 1 | ||
Jan Wagner
|
r8 | |||
Aurélien COUDERC
|
r106 | # Make sure all missing required packages are installed | ||
Unknown
|
r336 | apt-get -qq -y install "${MISSING_PACKAGES}" | ||
Aurélien COUDERC
|
r106 | fi | ||
Jan Wagner
|
r8 | |||
Jan Wagner
|
r76 | # Check if ./bootstrap.d directory exists | ||
if [ ! -d "./bootstrap.d/" ] ; then | ||||
echo "error: './bootstrap.d' required directory not found!" | ||||
exit 1 | ||||
fi | ||||
# Check if ./files directory exists | ||||
if [ ! -d "./files/" ] ; then | ||||
echo "error: './files' required directory not found!" | ||||
exit 1 | ||||
fi | ||||
# Check if specified KERNELSRC_DIR directory exists | ||||
if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then | ||||
echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" | ||||
exit 1 | ||||
fi | ||||
drtyhlpr
|
r139 | # Check if specified UBOOTSRC_DIR directory exists | ||
if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then | ||||
echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" | ||||
exit 1 | ||||
fi | ||||
Unknown
|
r332 | # Check if specified VIDEOCORESRC_DIR directory exists | ||
if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then | ||||
echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" | ||||
exit 1 | ||||
fi | ||||
drtyhlpr
|
r142 | # Check if specified FBTURBOSRC_DIR directory exists | ||
if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then | ||||
echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" | ||||
exit 1 | ||||
fi | ||||
Jan Wagner
|
r76 | # Check if specified CHROOT_SCRIPTS directory exists | ||
if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then | ||||
echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" | ||||
exit 1 | ||||
fi | ||||
Jan Wagner
|
r77 | # Check if specified device mapping already exists (will be used by cryptsetup) | ||
if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then | ||||
echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" | ||||
exit 1 | ||||
fi | ||||
Jan Wagner
|
r2 | # Don't clobber an old build | ||
Jan Wagner
|
r72 | if [ -e "$BUILDDIR" ] ; then | ||
echo "error: directory ${BUILDDIR} already exists, not proceeding" | ||||
exit 1 | ||||
fi | ||||
Jan Wagner
|
r75 | # Setup chroot directory | ||
Jan Wagner
|
r82 | mkdir -p "${R}" | ||
Jan Wagner
|
r75 | |||
Jan Wagner
|
r72 | # Check if build directory has enough of free disk space >512MB | ||
Unknown
|
r336 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then | ||
Jan Wagner
|
r76 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" | ||
Jan Wagner
|
r2 | exit 1 | ||
fi | ||||
set -x | ||||
# Call "cleanup" function on various signals and errors | ||||
trap cleanup 0 1 2 3 6 | ||||
Jan Wagner
|
r16 | # Add required packages for the minbase installation | ||
drtyhlpr
|
r89 | if [ "$ENABLE_MINBASE" = true ] ; then | ||
Jan Wagner
|
r77 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" | ||
drtyhlpr
|
r89 | fi | ||
# Add required locales packages | ||||
Unknown
|
r287 | if [ "$DEFLOCAL" != "en_US.UTF-8" ] || ([ -n XKB_MODEL ] || [ -n XKB_LAYOUT ] || [ -n XKB_VARIANT ] || [ -n XKB_OPTIONS ]); then | ||
Vincent Knecht
|
r27 | APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup" | ||
Jan Wagner
|
r16 | fi | ||
Filip Pytloun
|
r46 | # Add parted package, required to get partprobe utility | ||
if [ "$EXPANDROOT" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},parted" | ||||
fi | ||||
Jan Wagner
|
r2 | # Add dbus package, recommended if using systemd | ||
if [ "$ENABLE_DBUS" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},dbus" | ||||
fi | ||||
Jan Wagner
|
r17 | # Add iptables IPv4/IPv6 package | ||
if [ "$ENABLE_IPTABLES" = true ] ; then | ||||
Unknown
|
r286 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" | ||
Jan Wagner
|
r17 | fi | ||
Jan Wagner
|
r2 | # Add openssh server package | ||
if [ "$ENABLE_SSHD" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},openssh-server" | ||||
fi | ||||
Jan Wagner
|
r21 | # Add alsa-utils package | ||
if [ "$ENABLE_SOUND" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},alsa-utils" | ||||
fi | ||||
Jan Wagner
|
r2 | # Add rng-tools package | ||
if [ "$ENABLE_HWRANDOM" = true ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},rng-tools" | ||||
fi | ||||
Jan Wagner
|
r20 | # Add fbturbo video driver | ||
if [ "$ENABLE_FBTURBO" = true ] ; then | ||||
# Enable xorg package dependencies | ||||
ENABLE_XORG=true | ||||
fi | ||||
Jan Wagner
|
r22 | # Add user defined window manager package | ||
if [ -n "$ENABLE_WM" ] ; then | ||||
APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" | ||||
Jan Wagner
|
r17 | |||
Jan Wagner
|
r20 | # Enable xorg package dependencies | ||
Jan Wagner
|
r17 | ENABLE_XORG=true | ||
fi | ||||
# Add xorg package | ||||
if [ "$ENABLE_XORG" = true ] ; then | ||||
drtyhlpr
|
r232 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" | ||
Jan Wagner
|
r2 | fi | ||
Jan Wagner
|
r76 | # Replace selected packages with smaller clones | ||
if [ "$ENABLE_REDUCE" = true ] ; then | ||||
# Add levee package instead of vim-tiny | ||||
if [ "$REDUCE_VIM" = true ] ; then | ||||
APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" | ||||
fi | ||||
# Add dropbear package instead of openssh-server | ||||
if [ "$REDUCE_SSHD" = true ] ; then | ||||
Unknown
|
r336 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" | ||
Jan Wagner
|
r76 | fi | ||
fi | ||||
Tohka
|
r239 | if [ "$RELEASE" != "jessie" ] ; then | ||
APT_INCLUDES="${APT_INCLUDES},libnss-systemd" | ||||
fi | ||||
Jan Wagner
|
r76 | # Configure kernel sources if no KERNELSRC_DIR | ||
Jan Wagner
|
r75 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then | ||
KERNELSRC_CONFIG=true | ||||
Jan Wagner
|
r72 | fi | ||
Jan Wagner
|
r76 | # Configure reduced kernel | ||
if [ "$KERNEL_REDUCE" = true ] ; then | ||||
KERNELSRC_CONFIG=false | ||||
fi | ||||
drtyhlpr
|
r259 | # Configure qemu compatible kernel | ||
if [ "$ENABLE_QEMU" = true ] ; then | ||||
drtyhlpr
|
r267 | DTB_FILE=vexpress-v2p-ca15_a7.dtb | ||
UBOOT_CONFIG=vexpress_ca15_tc2_defconfig | ||||
drtyhlpr
|
r259 | KERNEL_DEFCONFIG="vexpress_defconfig" | ||
drtyhlpr
|
r263 | if [ "$KERNEL_MENUCONFIG" = false ] ; then | ||
KERNEL_OLDDEFCONFIG=true | ||||
fi | ||||
drtyhlpr
|
r259 | fi | ||
Jan Wagner
|
r76 | # Execute bootstrap scripts | ||
Jan Wagner
|
r72 | for SCRIPT in bootstrap.d/*.sh; do | ||
Jan Wagner
|
r75 | head -n 3 "$SCRIPT" | ||
. "$SCRIPT" | ||||
Filip Pytloun
|
r56 | done | ||
Jan Wagner
|
r3 | |||
Jan Wagner
|
r76 | ## Execute custom bootstrap scripts | ||
Jan Wagner
|
r72 | if [ -d "custom.d" ] ; then | ||
for SCRIPT in custom.d/*.sh; do | ||||
Jan Wagner
|
r75 | . "$SCRIPT" | ||
Jan Wagner
|
r63 | done | ||
fi | ||||
Jan Wagner
|
r3 | |||
Jan Wagner
|
r76 | # Execute custom scripts inside the chroot | ||
Jan Wagner
|
r72 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then | ||
Chris Landa
|
r40 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" | ||
Jan Wagner
|
r72 | chroot_exec /bin/bash -x <<'EOF' | ||
for SCRIPT in /chroot_scripts/* ; do | ||||
if [ -f $SCRIPT -a -x $SCRIPT ] ; then | ||||
$SCRIPT | ||||
fi | ||||
done | ||||
EOF | ||||
Jan Wagner
|
r82 | rm -rf "${R}/chroot_scripts" | ||
Chris Landa
|
r40 | fi | ||
drtyhlpr
|
r142 | # Remove c/c++ build environment from the chroot | ||
chroot_remove_cc | ||||
Jan Wagner
|
r73 | # Remove apt-utils | ||
drtyhlpr
|
r93 | if [ "$RELEASE" = "jessie" ] ; then | ||
chroot_exec apt-get purge -qq -y --force-yes apt-utils | ||||
fi | ||||
Jan Wagner
|
r73 | |||
Jan Wagner
|
r77 | # Generate required machine-id | ||
MACHINE_ID=$(dbus-uuidgen) | ||||
Jan Wagner
|
r82 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" | ||
drtyhlpr
|
r94 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" | ||
Jan Wagner
|
r77 | |||
Jan Wagner
|
r73 | # APT Cleanup | ||
Filip Pytloun
|
r56 | chroot_exec apt-get -y clean | ||
chroot_exec apt-get -y autoclean | ||||
chroot_exec apt-get -y autoremove | ||||
Jan Wagner
|
r2 | # Unmount mounted filesystems | ||
Jan Wagner
|
r82 | umount -l "${R}/proc" | ||
umount -l "${R}/sys" | ||||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r73 | # Clean up directories | ||
Jan Wagner
|
r82 | rm -rf "${R}/run/*" | ||
rm -rf "${R}/tmp/*" | ||||
Jan Wagner
|
r73 | |||
Jan Wagner
|
r2 | # Clean up files | ||
drtyhlpr
|
r94 | rm -f "${ETC_DIR}/ssh/ssh_host_*" | ||
rm -f "${ETC_DIR}/dropbear/dropbear_*" | ||||
rm -f "${ETC_DIR}/apt/sources.list.save" | ||||
rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" | ||||
rm -f "${ETC_DIR}/*-" | ||||
rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" | ||||
rm -f "${ETC_DIR}/resolv.conf" | ||||
Jan Wagner
|
r82 | rm -f "${R}/root/.bash_history" | ||
rm -f "${R}/var/lib/urandom/random-seed" | ||||
rm -f "${R}/initrd.img" | ||||
rm -f "${R}/vmlinuz" | ||||
Jan Wagner
|
r73 | rm -f "${R}${QEMU_BINARY}" | ||
Jan Wagner
|
r2 | |||
drtyhlpr
|
r259 | if [ "$ENABLE_QEMU" = true ] ; then | ||
# Setup QEMU directory | ||||
mkdir "${BASEDIR}/qemu" | ||||
# Copy kernel image to QEMU directory | ||||
install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" | ||||
# Copy kernel config to QEMU directory | ||||
install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" | ||||
# Copy kernel dtbs to QEMU directory | ||||
for dtb in "${BOOT_DIR}/"*.dtb ; do | ||||
if [ -f "${dtb}" ] ; then | ||||
install_readonly "${dtb}" "${BASEDIR}/qemu/" | ||||
fi | ||||
done | ||||
# Copy kernel overlays to QEMU directory | ||||
if [ -d "${BOOT_DIR}/overlays" ] ; then | ||||
# Setup overlays dtbs directory | ||||
mkdir "${BASEDIR}/qemu/overlays" | ||||
for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do | ||||
if [ -f "${dtb}" ] ; then | ||||
install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" | ||||
fi | ||||
done | ||||
fi | ||||
drtyhlpr
|
r260 | |||
drtyhlpr
|
r267 | # Copy u-boot files to QEMU directory | ||
if [ "$ENABLE_UBOOT" = true ] ; then | ||||
if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then | ||||
install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" | ||||
fi | ||||
if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then | ||||
install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" | ||||
fi | ||||
if [ -f "${BOOT_DIR}/boot.scr" ] ; then | ||||
install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" | ||||
fi | ||||
fi | ||||
drtyhlpr
|
r260 | # Copy initramfs to QEMU directory | ||
if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then | ||||
install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" | ||||
fi | ||||
drtyhlpr
|
r259 | fi | ||
Chris Landa
|
r41 | # Calculate size of the chroot directory in KB | ||
Unknown
|
r336 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") | ||
Jan Wagner
|
r2 | |||
Chris Landa
|
r41 | # Calculate the amount of needed 512 Byte sectors | ||
TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) | ||||
Vincent Knecht
|
r65 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) | ||
Unknown
|
r336 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") | ||
Jan Wagner
|
r2 | |||
Chris Landa
|
r41 | # The root partition is EXT4 | ||
# This means more space than the actual used space of the chroot is used. | ||||
drtyhlpr
|
r242 | # As overhead for journaling and reserved blocks 35% are added. | ||
Unknown
|
r336 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) | ||
Chris Landa
|
r41 | |||
# Calculate required image size in 512 Byte sectors | ||||
Unknown
|
r336 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") | ||
Jan Wagner
|
r2 | |||
# Prepare image file | ||||
Vincent Knecht
|
r65 | if [ "$ENABLE_SPLITFS" = true ] ; then | ||
Unknown
|
r336 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" | ||
dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" | ||||
dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" | ||||
dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" | ||||
Jan Wagner
|
r77 | |||
# Write firmware/boot partition tables | ||||
Denis Mosolov
|
r138 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM | ||
Jan Wagner
|
r77 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | ||
Vincent Knecht
|
r65 | EOM | ||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r77 | # Write root partition table | ||
Denis Mosolov
|
r138 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM | ||
Jan Wagner
|
r77 | ${TABLE_SECTORS},${ROOT_SECTORS},83 | ||
Vincent Knecht
|
r65 | EOM | ||
Jan Wagner
|
r77 | |||
Jan Wagner
|
r71 | # Setup temporary loop devices | ||
Unknown
|
r337 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" | ||
ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" | ||||
Jan Wagner
|
r77 | else # ENABLE_SPLITFS=false | ||
Unknown
|
r336 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" | ||
dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" | ||||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r77 | # Write partition table | ||
Denis Mosolov
|
r138 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM | ||
Jan Wagner
|
r77 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | ||
${ROOT_OFFSET},${ROOT_SECTORS},83 | ||||
Jan Wagner
|
r2 | EOM | ||
Jan Wagner
|
r77 | |||
Jan Wagner
|
r71 | # Setup temporary loop devices | ||
Unknown
|
r337 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" | ||
ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" | ||||
Vincent Knecht
|
r65 | fi | ||
Jan Wagner
|
r2 | |||
Jan Wagner
|
r77 | if [ "$ENABLE_CRYPTFS" = true ] ; then | ||
# Create dummy ext4 fs | ||||
mkfs.ext4 "$ROOT_LOOP" | ||||
# Setup password keyfile | ||||
drtyhlpr
|
r142 | touch .password | ||
Jan Wagner
|
r78 | chmod 600 .password | ||
drtyhlpr
|
r142 | echo -n ${CRYPTFS_PASSWORD} > .password | ||
Jan Wagner
|
r77 | |||
# Initialize encrypted partition | ||||
echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password | ||||
# Open encrypted partition and setup mapping | ||||
cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" | ||||
# Secure delete password keyfile | ||||
shred -zu .password | ||||
# Update temporary loop device | ||||
ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" | ||||
# Wipe encrypted partition (encryption cipher is used for randomness) | ||||
Unknown
|
r336 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" | ||
Jan Wagner
|
r77 | fi | ||
Vincent Knecht
|
r66 | # Build filesystems | ||
Vincent Knecht
|
r65 | mkfs.vfat "$FRMW_LOOP" | ||
mkfs.ext4 "$ROOT_LOOP" | ||||
Jan Wagner
|
r2 | |||
# Mount the temporary loop devices | ||||
mkdir -p "$BUILDDIR/mount" | ||||
Vincent Knecht
|
r65 | mount "$ROOT_LOOP" "$BUILDDIR/mount" | ||
Jan Wagner
|
r2 | |||
mkdir -p "$BUILDDIR/mount/boot/firmware" | ||||
Vincent Knecht
|
r65 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" | ||
Jan Wagner
|
r2 | |||
# Copy all files from the chroot to the loop device mount point directory | ||||
Jan Wagner
|
r82 | rsync -a "${R}/" "$BUILDDIR/mount/" | ||
Jan Wagner
|
r2 | |||
# Unmount all temporary loop devices and mount points | ||||
cleanup | ||||
Jan Wagner
|
r68 | # Create block map file(s) of image(s) | ||
Vincent Knecht
|
r65 | if [ "$ENABLE_SPLITFS" = true ] ; then | ||
Jan Wagner
|
r68 | # Create block map files for "bmaptool" | ||
Denis Mosolov
|
r138 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" | ||
bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" | ||||
Jan Wagner
|
r2 | |||
Vincent Knecht
|
r65 | # Image was successfully created | ||
Unknown
|
r336 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | ||
echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | ||||
Vincent Knecht
|
r65 | else | ||
Jan Wagner
|
r68 | # Create block map file for "bmaptool" | ||
Denis Mosolov
|
r138 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" | ||
Jan Wagner
|
r2 | |||
Vincent Knecht
|
r65 | # Image was successfully created | ||
Unknown
|
r336 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | ||
drtyhlpr
|
r259 | |||
# Create qemu qcow2 image | ||||
if [ "$ENABLE_QEMU" = true ] ; then | ||||
QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | ||||
QEMU_SIZE=16G | ||||
Unknown
|
r336 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 | ||
qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE | ||||
drtyhlpr
|
r259 | |||
echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" | ||||
fi | ||||
Vincent Knecht
|
r65 | fi | ||