From a90f6ad1a83f24641bd13c5283826f87aea6d945 2018-11-19 17:26:39 From: Unknown Date: 2018-11-19 17:26:39 Subject: [PATCH] Refactor Use RPI_MODEL and SET_ARCH to define all board relevant settings, crosscompilers, architectures etc... - SET_ARCH=32 is default and used for all boards in 32bit mode - SET_ARCH=64 and RPI_MODEL=3 or 3P activate 64bit mode! - no need to set CROSS_COMPILE, KERNEL_IMAGE, RELEASE_ARCH, KERNEL_DEFCONFIG, KERNEL_ARCH, QEMU_BINARY - build kernel is now a default. i kicked out old kernel v3 and jessie support! they're too old. set buster as default - autodetect if program is running on 3142 => assume it is apt-cacher-ng and set APT_PROXY - next pull includes sakaki kernel for RPI3 and RPi3B+ => see https://github.com/sakaki-/bcmrpi3-kernel-bis --- diff --git a/README.md b/README.md index b232d33..ee9aa81 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rpi23-gen-image ## Introduction -`rpi23-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for Raspberry Pi 2 (RPi2) and Raspberry Pi 3 (RPi3) computers. The script at this time supports the bootstrapping of the Debian (armhf) releases `jessie`, `stretch` and `buster`. Raspberry Pi 3 images are generated for 32-bit mode only. Raspberry Pi 3 64-bit images can be generated using custom configuration parameters (```templates/rpi3-stretch-arm64-4.11.y```). +`rpi23-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for Raspberry Pi 2 (RPi2) and Raspberry Pi 3 (RPi3) computers. The script at this time supports the bootstrapping of the Debian (armhf) releases `stretch` and `buster`. Raspberry Pi 3 images are generated for 32-bit mode only. Raspberry Pi 3 64-bit images can be generated using custom configuration parameters (```templates/rpi3-stretch-arm64-4.11.y```). ## Build dependencies The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user. @@ -9,16 +9,7 @@ The following list of Debian packages must be installed on the build system beca It is recommended to configure the `rpi23-gen-image.sh` script to build and install the latest Raspberry Pi Linux kernel. For the RPi3 this is mandatory. Kernel compilation and linking will be performed on the build system using an ARM (armhf) cross-compiler toolchain. -The script has been tested using the default `crossbuild-essential-armhf` toolchain meta package on Debian Linux `jessie` and `stretch` build systems. Please check the [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) for further information. - -If a Debian Linux `jessie` build system is used it will be required to add the [Debian Cross-toolchains repository](http://emdebian.org/tools/debian/) first: - -``` -echo "deb http://emdebian.org/tools/debian/ jessie main" > /etc/apt/sources.list.d/crosstools.list -sudo -u nobody wget -O - http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add - -dpkg --add-architecture armhf -apt-get update -``` +The script has been tested using the default `crossbuild-essential-armhf` toolchain meta package on Debian Linux and `stretch` build systems. Please check the [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) for further information. ## Command-line parameters The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi23-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi23-gen-image.sh` script. @@ -55,7 +46,7 @@ CONFIG_TEMPLATE=rpi2stretch ./rpi23-gen-image.sh Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process. ##### `APT_PROXY`="" -Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once. +Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once. If `apt-cacher-ng` is running on default `http://127.0.0.1:3142` it is autodetected and you don't need to set this. ##### `APT_INCLUDES`="" A comma separated list of additional packages to be installed by debootstrap during bootstrapping. @@ -76,8 +67,8 @@ Specifiy the target Raspberry Pi hardware model. The script at this time support `3P` = Used for Pi 3 model B+ `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` or `3P` is used. -##### `RELEASE`="jessie" -Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases "jessie", "stretch" and "buster". `BUILD_KERNEL`=true will automatically be set if the Debian releases `stretch` or `buster` are used. +##### `RELEASE`="buster" +Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases "stretch" and "buster". `BUILD_KERNEL`=true will automatically be set if the Debian releases `stretch` or `buster` are used. ##### `RELEASE_ARCH`="armhf" Set the desired Debian release architecture. diff --git a/bootstrap.d/10-bootstrap.sh b/bootstrap.d/10-bootstrap.sh index 8776997..d8cfb69 100644 --- a/bootstrap.d/10-bootstrap.sh +++ b/bootstrap.d/10-bootstrap.sh @@ -19,7 +19,7 @@ if [ "$ENABLE_MINBASE" = true ] ; then fi # Base debootstrap (unpack only) -http_proxy=${APT_PROXY} debootstrap "${APT_EXCLUDES}" --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian" +http_proxy=${APT_PROXY} debootstrap ${APT_EXCLUDES} --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian" # Copy qemu emulator binary to chroot install -m 755 -o root -g root "${QEMU_BINARY}" "${R}${QEMU_BINARY}" diff --git a/bootstrap.d/11-apt.sh b/bootstrap.d/11-apt.sh index f511f43..b833dfa 100644 --- a/bootstrap.d/11-apt.sh +++ b/bootstrap.d/11-apt.sh @@ -12,28 +12,12 @@ if [ -z "$APT_PROXY" ] ; then fi if [ "$BUILD_KERNEL" = false ] ; then - # Install APT pinning configuration for flash-kernel package - install_readonly files/apt/flash-kernel "${ETC_DIR}/apt/preferences.d/flash-kernel" - - # Install APT sources.list - install_readonly files/apt/sources.list "${ETC_DIR}/apt/sources.list" - echo "deb ${COLLABORA_URL} ${RELEASE} rpi2" >> "${ETC_DIR}/apt/sources.list" - - # Upgrade collabora package index and install collabora keyring - chroot_exec apt-get -qq -y update - chroot_exec apt-get -qq -y --allow-unauthenticated install collabora-obs-archive-keyring -else # BUILD_KERNEL=true - # Install APT sources.list - install_readonly files/apt/sources.list "${ETC_DIR}/apt/sources.list" - - # Use specified APT server and release - sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "${ETC_DIR}/apt/sources.list" - sed -i "s/ jessie/ ${RELEASE}/" "${ETC_DIR}/apt/sources.list" -fi - -# Allow the installation of non-free Debian packages -if [ "$ENABLE_NONFREE" = true ] ; then - sed -i "s/ contrib/ contrib non-free/" "${ETC_DIR}/apt/sources.list" + echo "Downloading precompiled kernel" + echo "error: not configured" + exit 1; +# BUILD_KERNEL=true +else + echo "No precompiled kernel repositories were added" fi # Upgrade package index and update all installed packages and changed dependencies diff --git a/rpi23-gen-image.sh b/rpi23-gen-image.sh index 4fd827a..ffbdd07 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -1,9 +1,8 @@ -#!/bin/sh - +#!/bin/bash ######################################################################## # rpi23-gen-image.sh 2015-2017 # -# Advanced Debian "jessie", "stretch" and "buster" bootstrap script for RPi2/3 +# Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -43,57 +42,10 @@ set -x # Raspberry Pi model configuration RPI_MODEL=${RPI_MODEL:=2} -#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} - -#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} - -#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} - -#bcm2709-rpi-2-b.dtb (Used for Pi 2 model B) -RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb} -RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig} - -#bcm2710-rpi-3-b.dtb (Used for Pi 3 model B) -RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb} -RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig} - -#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} - # Debian release -RELEASE=${RELEASE:=jessie} -KERNEL_ARCH=${KERNEL_ARCH:=arm} -RELEASE_ARCH=${RELEASE_ARCH:=armhf} -CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} -COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} -if [ "$KERNEL_ARCH" = "arm64" ] ; then - KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} - KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} -fi - -if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then -#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} -else -#RASPBERRY PI 2, PI 3, PI 3+, AND COMPUTE MODULE 3 DEFAULT Kernel BUILD CONFIGURATION -#https://www.raspberrypi.org/documentation/linux/kernel/building.md - KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} - KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} -fi +RELEASE=${RELEASE:=buster} -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 +#Kernel Branch KERNEL_BRANCH=${KERNEL_BRANCH:=""} # URLs @@ -103,7 +55,7 @@ WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-no COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian} FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git} UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} -VIDEOCORE_URL=${VIDEOCORE_URL=https://github.com/raspberrypi/userland} +VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} # Build directories @@ -130,6 +82,7 @@ WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} # General settings +SET_ARCH=${SET_ARCH:=32} HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} PASSWORD=${PASSWORD:=raspberry} USER_PASSWORD=${USER_PASSWORD:=raspberry} @@ -204,7 +157,7 @@ ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} # Kernel compilation settings -BUILD_KERNEL=${BUILD_KERNEL:=false} +BUILD_KERNEL=${BUILD_KERNEL:=true} KERNEL_REDUCE=${KERNEL_REDUCE:=false} KERNEL_THREADS=${KERNEL_THREADS:=1} KERNEL_HEADERS=${KERNEL_HEADERS:=true} @@ -213,12 +166,6 @@ KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} KERNEL_CCACHE=${KERNEL_CCACHE:=false} -if [ "$KERNEL_ARCH" = "arm64" ] ; then - KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} -else - KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} -fi - # Kernel compilation from source directory settings KERNELSRC_DIR=${KERNELSRC_DIR:=""} KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} @@ -269,37 +216,110 @@ fi #Check if apt-cacher-ng has its default port open on and set APT_PROXY if [ -n "$(lsof -i :3142)" ] ; then HTTP_PROXY=http://127.0.0.1:3142/ +fi + +#make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! +if [ -n "$SET_ARCH" ] ; then + echo "Setting Architecture specific settings" + ################################## + # 64 bit config + ################################## + if [ "$SET_ARCH" = 64 ] ; then + echo "64 bit mode selected - Setting up enviroment" + # 64 bit depended settings + QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} + KERNEL_ARCH=${KERNEL_ARCH:=arm64} + KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} + + if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} + RELEASE_ARCH=${RELEASE_ARCH:=arm64} + KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} + CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} + else + echo "error: Only Raspberry PI 3 and 3B+ support 64bit" + exit 1 + fi + fi -# Set Raspberry Pi model specific configuration -if [ "$RPI_MODEL" = 0 ] ; then - DTB_FILE=${RPI0_DTB_FILE} - UBOOT_CONFIG=${RPI0_UBOOT_CONFIG} -elif [ "$RPI_MODEL" = 1 ] ; then - DTB_FILE=${RPI1_DTB_FILE} - UBOOT_CONFIG=${RPI1_UBOOT_CONFIG} -elif [ "$RPI_MODEL" = 1P ] ; then - DTB_FILE=${RPI1P_DTB_FILE} - UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG} -elif [ "$RPI_MODEL" = 2 ] ; then - 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} -elif [ "$RPI_MODEL" = 3P ] ; then - DTB_FILE=${RPI3P_DTB_FILE} - UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG} + ################################## + # 32 bit config + ################################## + if [ "$SET_ARCH" = 32 ] ; then + echo "32 bit mode selected - Setting up enviroment" + #General 32bit configuration + QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} + KERNEL_ARCH=${KERNEL_ARCH:=arm} + KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} + + #Raspberry setting grouped by board compability + if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then + echo "Setting settings for bcm2835 Raspberry PI boards" + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} + RELEASE_ARCH=${RELEASE_ARCH:=armel} + KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} + CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} + fi + if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + echo "Setting settings for bcm2837 Raspberry PI boards" + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} + RELEASE_ARCH=${RELEASE_ARCH:=armhf} + KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} + CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} + fi + fi +#SET_ARCH not set else - echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!" + echo "error: Please set '32' or '64' as value for SET_ARCH" exit 1 fi -# Check if the internal wireless interface is supported by the RPi model -if [ "$ENABLE_WIRELESS" = true ] && ([ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ]); then + #Device specific configuration and uboot-config + echo "Select DTB-File" + case "$RPI_MODEL" in + 0) + DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} + ;; + 1) + DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} + ;; + 1P) + DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} + ;; + 2) + DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} + ;; + 3) + DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} + ;; + 3P) + DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} + ;; + *) + echo "error: Raspberry Pi model $RPI_MODEL is not supported!" + exit 1 + ;; + esac + echo "$DTB_FILE selected" - echo "error: The selected Raspberry Pi model has no internal wireless interface" - exit 1 -fi +# Check if the internal wireless interface is supported by the RPi model +if [ "$ENABLE_WIRELESS" = true ] ; then + if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then + echo "error: The selected Raspberry Pi model has no internal wireless interface" + exit 1 + else + echo "Raspberry Pi $RPI_MODEL has WIFI support" + fi +fi # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then @@ -309,11 +329,6 @@ if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then fi fi -# Build RPi2/3 Linux kernel if required by Debian release -if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then - BUILD_KERNEL=true -fi - # Add packages required for kernel cross compilation if [ "$BUILD_KERNEL" = true ] ; then if [ "$KERNEL_ARCH" = "arm" ] ; then @@ -536,10 +551,6 @@ if [ "$ENABLE_REDUCE" = true ] ; then fi fi -if [ "$RELEASE" != "jessie" ] ; then - APT_INCLUDES="${APT_INCLUDES},libnss-systemd" -fi - # Configure kernel sources if no KERNELSRC_DIR if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then KERNELSRC_CONFIG=true @@ -589,11 +600,6 @@ fi # Remove c/c++ build environment from the chroot chroot_remove_cc -# Remove apt-utils -if [ "$RELEASE" = "jessie" ] ; then - chroot_exec apt-get purge -qq -y --force-yes apt-utils -fi - # Generate required machine-id MACHINE_ID=$(dbus-uuidgen) echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"