diff --git a/README.md b/README.md index a074381..8257fc8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # 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 `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.14.y```). +`rpi23-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for all Raspberry Pi computers. The script at this time supports the bootstrapping of the Debian (armhf/armel) releases `stretch` and `buster`. Raspberry Pi 0/1/2/3 images are generated for 32-bit mode only. Raspberry Pi 3 supports 64-bit images that can be generated using custom configuration parameters (```templates/rpi3-stretch-arm64-4.14.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. ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo``` -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. +It is recommended to configure the `rpi23-gen-image.sh` script to build and install the latest Raspberry Pi Linux kernel. For the Raspberry 3 this is mandatory. Kernel compilation and linking will be performed on the build system using an ARM (armhf/armel) cross-compiler toolchain. -The script has been tested using the default `crossbuild-essential-armhf` toolchain meta package on Debian Linux `stretch` build systems. Please check the [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) for further information. +The script has been tested using the default `crossbuild-essential-armhf` and `crossbuild-essential-armel` toolchain meta packages on Debian Linux `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. @@ -49,27 +49,25 @@ Set Debian packages server address. Choose a server from the list of Debian worl 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. +A comma-separated list of additional packages to be installed by debootstrap during bootstrapping. ##### `APT_INCLUDES_LATE`="" -A comma separated list of additional packages to be installed by apt after bootstrapping and after APT sources are set up. This is useful for packages with pre-depends, which debootstrap do not handle well. +A comma-separated list of additional packages to be installed by apt after bootstrapping and after APT sources are set up. This is useful for packages with pre-depends, which debootstrap do not handle well. --- #### General system settings: ##### `SET_ARCH`=32 -Set Architecture to default 32bit. If you want to to compile 64bit (RPI3 or RPI3+) set it to `64`. This option will set every needed crosscompiler or boeard specific option for a successful build. -If you want to change e.g. cross-compiler -> Templates always override defaults +Set Architecture to default 32bit. If you want to compile 64-bit (RPI3 or RPI3+) set it to `64`. This option will set every needed cross-compiler or board specific option for a successful build. ##### `RPI_MODEL`=2 -Specifiy the target Raspberry Pi hardware model. The script at this time supports the following Raspberry Pi models: -`0` = Used for Raspberry Pi 0 and Raspberry Pi 0 W -`1` = Used for Pi 1 model A and B -`1P` = Used for Pi 1 model B+ and A+ -`2` = Used for Pi 2 model B -`3` = Used for Pi 3 model B -`3P` = Used for Pi 3 model B+ -`BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` or `3P` is used. +Specify the target Raspberry Pi hardware model. The script at this time supports the following Raspberry Pi models: +- `0` = Raspberry Pi 0 and Raspberry Pi 0 W +- `1` = Raspberry Pi 1 model A and B +- `1P` = Raspberry Pi 1 model B+ and A+ +- `2` = Raspberry Pi 2 model B +- `3` = Raspberry Pi 3 model B +- `3P` = Raspberry Pi 3 model B+ ##### `RELEASE`="buster" Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases `stretch` and `buster`. @@ -78,7 +76,7 @@ Set the desired Debian release name. The script at this time supports the bootst Set the desired Debian release architecture. ##### `HOSTNAME`="rpi$RPI_MODEL-$RELEASE" -Set system host name. It's recommended that the host name is unique in the corresponding subnet. +Set system hostname. It's recommended that the hostname is unique in the corresponding subnet. ##### `PASSWORD`="raspberry" Set system `root` password. It's **STRONGLY** recommended that you choose a custom password. @@ -118,7 +116,7 @@ Set extra xkb configuration options. --- #### Networking settings (DHCP): -This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.` +This parameter is used to set up networking auto-configuration in `/etc/systemd/network/eth.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.` ##### `ENABLE_DHCP`=true Set the system to use DHCP. This requires an DHCP server. @@ -141,7 +139,7 @@ Set the IP address for the first DNS server. Set the IP address for the second DNS server. ##### `NET_DNS_DOMAINS`="" -Set the default DNS search domains to use for non fully qualified host names. +Set the default DNS search domains to use for non fully qualified hostnames. ##### `NET_NTP_1`="" Set the IP address for the first NTP server. @@ -153,13 +151,25 @@ Set the IP address for the second NTP server. #### Basic system features: ##### `ENABLE_CONSOLE`=true -Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2/3. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system. +Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2/3. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system. On RPI `0` `3` `3P` the CPU speed is locked at lowest speed. + +##### `ENABLE_PRINTK`=false +Enables printing kernel messages to konsole. printk is `3 4 1 3` as in raspbian. + +##### `ENABLE_BLUETOOTH`=false +Enable onboard Bluetooth interface on the RPi0/3/3P. See: [Configuring the GPIO serial port on Raspbian jessie and stretch](https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/). + +##### `ENABLE_MINIUART_OVERLAY`=false +Enable Bluetooth to use this. Adds overlay to swap UART0 with UART1. Enabling (slower) Bluetooth and full speed serial console. - RPI `0` `3` `3P` have a fast `hardware UART0` (ttyAMA0) and a `mini UART1` (ttyS0)! RPI `1` `1P` `2` only have a `hardware UART0`. `UART0` is considered better, because is faster and more stable than `mini UART1`. By default the Bluetooth modem is mapped to the `hardware UART0` and `mini UART` is used for console. The `mini UART` is a problem for the serial console, because its baudrate depends on the CPU frequency, which is changing on runtime. Resulting in a volatile baudrate and thus in an unusable serial console. + +##### `ENABLE_TURBO`=false +Enable Turbo mode. This setting locks cpu at the highest frequency. As setting ENABLE_CONSOLE=true locks RPI to lowest CPU speed, this is can be used additionally to lock cpu hat max speed. Need a good power supply and probably cooling for the Raspberry PI. ##### `ENABLE_I2C`=false -Enable I2C interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins. +Enable I2C interface on the RPi 0/1/2/3. Please check the [RPi 0/1/2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins. ##### `ENABLE_SPI`=false -Enable SPI interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins. +Enable SPI interface on the RPi 0/1/2/3. Please check the [RPi 0/1/2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins. ##### `ENABLE_IPV6`=true Enable IPv6 support. The network interface configuration is managed via systemd-networkd. @@ -174,14 +184,13 @@ Allow the installation of non-free Debian packages that do not comply with the D Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm) that is required to run the internal wireless interface of the Raspberry Pi model `3`. This parameter is ignored if the specified `RPI_MODEL` is not `3`. ##### `ENABLE_RSYSLOG`=true -If set to false, disable and uninstall rsyslog (so logs will be available only -in journal files) +If set to false, disable and uninstall rsyslog (so logs will be available only in journal files) ##### `ENABLE_SOUND`=true Enable sound hardware and install Advanced Linux Sound Architecture. ##### `ENABLE_HWRANDOM`=true -Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled. +Enable Hardware Random Number Generator. Strong random numbers are important for most network-based communications that use encryption. It's recommended to be enabled. ##### `ENABLE_MINGPU`=false Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU. @@ -193,7 +202,7 @@ Install and enable D-Bus message bus. Please note that systemd should work witho Install Xorg open-source X Window System. ##### `ENABLE_WM`="" -Install a user defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi23-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`. +Install a user-defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi23-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`. ##### `ENABLE_SYSVINIT`=false Support for halt,init,poweroff,reboot,runlevel,shutdown,telinit commands @@ -208,7 +217,7 @@ Use debootstrap script variant `minbase` which only includes essential packages Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information. ##### `ENABLE_UBOOT`=false -Replace the default RPi2/3 second stage bootloader (bootcode.bin) with [U-Boot bootloader](https://git.denx.de/?p=u-boot.git;a=summary). U-Boot can boot images via the network using the BOOTP/TFTP protocol. +Replace the default RPi 0/1/2/3 second stage bootloader (bootcode.bin) with [U-Boot bootloader](https://git.denx.de/?p=u-boot.git;a=summary). U-Boot can boot images via the network using the BOOTP/TFTP protocol. ##### `UBOOTSRC_DIR`="" Path to a directory (`u-boot`) of [U-Boot bootloader sources](https://git.denx.de/?p=u-boot.git;a=summary) that will be copied, configured, build and installed inside the chroot. @@ -220,16 +229,16 @@ Install and enable the [hardware accelerated Xorg video driver](https://github.c Path to a directory (`xf86-video-fbturbo`) of [hardware accelerated Xorg video driver sources](https://github.com/ssvb/xf86-video-fbturbo) that will be copied, configured, build and installed inside the chroot. ##### `ENABLE_VIDEOCORE`=false -Install and enable the [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) `vcgencmd`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling. +Install and enable the [ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) `vcgencmd`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling. ##### `VIDEOCORESRC_DIR`="" -Path to a directory (`userland`) of [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) that will be copied, configured, build and installed inside the chroot. +Path to a directory (`userland`) of [ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) that will be copied, configured, build and installed inside the chroot. ##### `ENABLE_IPTABLES`=false Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service. ##### `ENABLE_USER`=true -Create non-root user with password `USER_PASSWORD`=raspberry. Unless overridden with `USER_NAME`=user, username will be `pi`. +Create non-root user with password `USER_PASSWORD`=raspberry. Unless overridden with `USER_NAME`=user, the username will be `pi`. ##### `USER_NAME`=pi Non-root user to create. Ignored if `ENABLE_USER`=false @@ -259,10 +268,10 @@ Disable RPi2/3 under-voltage warnings and overlays. Setting the parameter to `1` #### SSH settings: ##### `SSH_ENABLE_ROOT`=false -Enable password root login via SSH. This may be a security risk with default password, use only in trusted environments. `ENABLE_ROOT` must be set to `true`. +Enable password-based root login via SSH. This may be a security risk with the default password set, use only in trusted environments. `ENABLE_ROOT` must be set to `true`. ##### `SSH_DISABLE_PASSWORD_AUTH`=false -Disable password based SSH authentication. Only public key based SSH (v2) authentication will be supported. +Disable password-based SSH authentication. Only public key based SSH (v2) authentication will be supported. ##### `SSH_LIMIT_USERS`=false Limit the users that are allowed to login via SSH. Only allow user `USER_NAME`=pi and root if `SSH_ENABLE_ROOT`=true to login. This parameter will be ignored if `dropbear` SSH is used (`REDUCE_SSHD`=true). @@ -277,10 +286,10 @@ Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enab #### Kernel compilation: ##### `BUILD_KERNEL`=true -Build and install the latest RPi2/3 Linux kernel. Currently only the default RPi2/3 kernel configuration is used. +Build and install the latest RPi 0/1/2/3 Linux kernel. Currently only the default RPi 0/1/2/3 kernel configuration is used. ##### `CROSS_COMPILE`="arm-linux-gnueabihf-" -This sets the cross compile enviornment for the compiler. +This sets the cross-compile environment for the compiler. ##### `KERNEL_ARCH`="arm" This sets the kernel architecture for the compiler. @@ -298,13 +307,13 @@ Sets the QEMU enviornment for the Debian archive. If not set, `QEMU_BINARY` will Sets the default config for kernel compiling. If not set, `KERNEL_DEFCONFIG` will be set to "bcmrpi3\_defconfig" automatically if building for arm64. ##### `KERNEL_REDUCE`=false -Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental). +Reduce the size of the generated kernel by removing unwanted devices, network and filesystem drivers (experimental). ##### `KERNEL_THREADS`=1 Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation. ##### `KERNEL_HEADERS`=true -Install kernel headers with built kernel. +Install kernel headers with the built kernel. ##### `KERNEL_MENUCONFIG`=false Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated. @@ -400,9 +409,9 @@ The functions of this script that are required for the different stages of the b | `10-bootstrap.sh` | Debootstrap basic system | | `11-apt.sh` | Setup APT repositories | | `12-locale.sh` | Setup Locales and keyboard settings | -| `13-kernel.sh` | Build and install RPi2/3 Kernel | +| `13-kernel.sh` | Build and install RPi 0/1/2/3 Kernel | | `14-fstab.sh` | Setup fstab and initramfs | -| `15-rpi-config.sh` | Setup RPi2/3 config and cmdline | +| `15-rpi-config.sh` | Setup RPi 0/1/2/3 config and cmdline | | `20-networking.sh` | Setup Networking | | `21-firewall.sh` | Setup Firewall | | `30-security.sh` | Setup Users and Security settings | @@ -410,6 +419,7 @@ The functions of this script that are required for the different stages of the b | `32-sshd.sh` | Setup SSH and public keys | | `41-uboot.sh` | Build and Setup U-Boot | | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver | +| `43-videocore.sh` | Build and Setup videocore libraries | | `50-firstboot.sh` | First boot actions | | `99-reduce.sh` | Reduce the disk space usage | @@ -418,7 +428,7 @@ All the required configuration files that will be copied to the generated OS ima | Directory | Description | | --- | --- | | `apt` | APT management configuration files | -| `boot` | Boot and RPi2/3 configuration files | +| `boot` | Boot and RPi 0/1/2/3 configuration files | | `dpkg` | Package Manager configuration | | `etc` | Configuration files and rc scripts | | `firstboot` | Scripts that get executed on first boot | @@ -444,7 +454,7 @@ script -c 'APT_SERVER=ftp.de.debian.org ./rpi23-gen-image.sh' ./build.log ``` ## Flashing the image file -After the image file was successfully created by the `rpi23-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2/3 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`. +After the image file was successfully created by the `rpi23-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi 0/1/2/3 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`. ##### Flashing examples: ```shell diff --git a/bootstrap.d/12-locale.sh b/bootstrap.d/12-locale.sh index c469ec3..9817d7a 100644 --- a/bootstrap.d/12-locale.sh +++ b/bootstrap.d/12-locale.sh @@ -28,10 +28,10 @@ if [ "$(echo "$APT_INCLUDES" | grep ",locales")" ] ; then chroot_exec update-locale LANG="${DEFLOCAL}" # Install and setup default keyboard configuration - if [ "$XKB_MODEL" != "pc105" ] ; then + if [ "$XKB_MODEL" != "" ] ; then sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKB_MODEL}\"/" "${ETC_DIR}/default/keyboard" fi - if [ "$XKB_LAYOUT" != "us" ] ; then + if [ "$XKB_LAYOUT" != "" ] ; then sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKB_LAYOUT}\"/" "${ETC_DIR}/default/keyboard" fi if [ "$XKB_VARIANT" != "" ] ; then diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index e86ae33..a662049 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -108,7 +108,7 @@ if [ "$BUILD_KERNEL" = true ] ; then echo "CONFIG_CRYPTO_XTS=y" echo "CONFIG_CRYPTO_SHA512=y" echo "CONFIG_CRYPTO_MANAGER=y" - } >> ${KERNEL_DIR}/.config + } >> "${KERNEL_DIR}"/.config fi fi @@ -139,7 +139,7 @@ if [ "$BUILD_KERNEL" = true ] ; then make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs # Cross compile kernel modules - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules fi fi @@ -153,16 +153,16 @@ if [ "$BUILD_KERNEL" = true ] ; then # Install kernel modules if [ "$ENABLE_REDUCE" = true ] ; then - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install fi else - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install fi # Install kernel firmware - if [ "$(grep "^firmware_install:" "${KERNEL_DIR}/Makefile")" ] ; then + if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install fi fi @@ -225,8 +225,8 @@ if [ "$BUILD_KERNEL" = true ] ; then rm -fr "${KERNEL_DIR}" else # Prepare compiled kernel modules - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then - if [ "$(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then + if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare fi diff --git a/bootstrap.d/15-rpi-config.sh b/bootstrap.d/15-rpi-config.sh index de86adf..eda69bd 100644 --- a/bootstrap.d/15-rpi-config.sh +++ b/bootstrap.d/15-rpi-config.sh @@ -56,9 +56,100 @@ if [ "$ENABLE_CRYPTFS" = true ] ; then fi fi -# Add serial console support +#locks cpu at max frequency +if [ "$ENABLE_TURBO" = true ] ; then + echo "force_turbo=1" >> "${BOOT_DIR}/config.txt" +fi + +if [ "$ENABLE_PRINTK" = true ] ; then + install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf" +fi + +# Install udev rule for serial alias +install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules" + +if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + + # RPI0,3,3P Use default ttyS0 (mini-UART)as serial interface + SET_SERIAL="ttyS0" + + # Bluetooth enabled + if [ "$ENABLE_BLUETOOTH" = true ] ; then + # Create temporary directory for Bluetooth sources + temp_dir=$(as_nobody mktemp -d) + + # Fetch Bluetooth sources + as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}" + + # Copy downloaded sources + mv "${temp_dir}/pi-bluetooth" "${R}/tmp/" + + # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/ + as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth + as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth + + # Set permissions + chown -R root:root "${R}/tmp/pi-bluetooth" + + # Install tools + install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart" + install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper" + + # Install bluetooth udev rule + install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules" + + # Install Firmware Flash file and apropiate licence + mkdir -p "$BLUETOOTH_FIRMWARE_DIR" + install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" + install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" + install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service" + install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service" + + # Remove temporary directory + rm -fr "${temp_dir}" + + # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0 + if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then + SET_SERIAL="ttyAMA0" + + # set overlay to swap ttyAMA0 and ttyS0 + echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt" + + # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken + if [ "$ENABLE_TURBO" = false ] ; then + echo "core_freq=250" >> "${BOOT_DIR}/config.txt" + fi + + # Activate services + chroot_exec systemctl enable pi-bluetooth.hciuart.service + #chroot_exec systemctl enable pi-bluetooth.bthelper@.service + else + chroot_exec systemctl enable pi-bluetooth.hciuart.service + #chroot_exec systemctl enable pi-bluetooth.bthelper@.service + fi + + else # if ENABLE_BLUETOOTH = false + # set overlay to disable bluetooth + echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt" + fi # ENABLE_BLUETOOTH end + +else + # RPI1,1P,2 Use default ttyAMA0 (full UART) as serial interface + SET_SERIAL="ttyAMA0" +fi + +# may need sudo systemctl disable hciuart if [ "$ENABLE_CONSOLE" = true ] ; then - CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" + echo "enable_uart=1" >> "${BOOT_DIR}/config.txt" + # add string to cmdline + CMDLINE="${CMDLINE} console=serial0,115200" + + # Enable serial console systemd style + chroot_exec systemctl enable serial-getty\@"$SET_SERIAL".service +else + echo "enable_uart=0" >> "${BOOT_DIR}/config.txt" + # disable serial console systemd style + chroot_exec systemctl disable serial-getty\@"$SET_SERIAL".service fi # Remove IPv6 networking support @@ -89,42 +180,6 @@ if [ "$ENABLE_INITRAMFS" = true ] ; then echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt" fi -# Disable RPi3 Bluetooth and restore ttyAMA0 serial device -if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then - if [ "$ENABLE_CONSOLE" = true ] && [ "$ENABLE_UBOOT" = false ] ; then - echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt" - echo "enable_uart=1" >> "${BOOT_DIR}/config.txt" - else - # Create temporary directory for Bluetooth sources - temp_dir=$(as_nobody mktemp -d) - - # Fetch Bluetooth sources - as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}" - - # Copy downloaded sources - mv "${temp_dir}/pi-bluetooth" "${R}/tmp/" - - # Set permissions - chown -R root:root "${R}/tmp/pi-bluetooth" - - # Install tools - install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart" - install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper" - - # Install bluetooth udev rule - install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules" - - # Install Firmware Flash file and apropiate licence - mkdir "${ETC_DIR}/firmware/" - - wget -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth - wget -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth - - # Get /dev/serial back for compability - wget -O "${ETC_DIR}/udev/rules.d/99-com.rules" https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules - fi -fi - # Create firmware configuration and cmdline symlinks ln -sf firmware/config.txt "${R}/boot/config.txt" ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt" diff --git a/bootstrap.d/20-networking.sh b/bootstrap.d/20-networking.sh index 3ca9f60..3aca05f 100644 --- a/bootstrap.d/20-networking.sh +++ b/bootstrap.d/20-networking.sh @@ -107,28 +107,26 @@ if [ "$ENABLE_WIRELESS" = true ] ; then as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.bin" as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.txt" as_nobody wget -q -O "${temp_dir}/brcmfmac43455-sdio.clm_blob" "${WLAN_FIRMWARE_URL}/brcmfmac43455-sdio.clm_blob" + + # Move downloaded firmware binary blob + mv "${temp_dir}/brcmfmac43455-sdio."* "${WLAN_FIRMWARE_DIR}/" + + # Set permissions of the firmware binary blob + chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* + chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* elif [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 0 ] ; then # Fetch firmware binary blob for RPi3 as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.bin" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.bin" as_nobody wget -q -O "${temp_dir}/brcmfmac43430-sdio.txt" "${WLAN_FIRMWARE_URL}/brcmfmac43430-sdio.txt" - fi - - # Move downloaded firmware binary blob - if [ "$RPI_MODEL" = 3P ] ; then - mv "${temp_dir}/brcmfmac43455-sdio."* "${WLAN_FIRMWARE_DIR}/" - elif [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 0 ] ; then - mv "${temp_dir}/brcmfmac43430-sdio."* "${WLAN_FIRMWARE_DIR}/" + + # Move downloaded firmware binary blob + mv "${temp_dir}/brcmfmac43430-sdio."* "${WLAN_FIRMWARE_DIR}/" + + # Set permissions of the firmware binary blob + chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* + chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* fi # Remove temporary directory for firmware binary blob rm -fr "${temp_dir}" - - # Set permissions of the firmware binary blob - if [ "$RPI_MODEL" = 3P ] ; then - chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* - chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43455-sdio."* - elif [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 0 ] ; then - chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* - chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* - fi fi diff --git a/bootstrap.d/30-security.sh b/bootstrap.d/30-security.sh index 5fbfc7a..8ad8275 100644 --- a/bootstrap.d/30-security.sh +++ b/bootstrap.d/30-security.sh @@ -11,8 +11,8 @@ ENCRYPTED_USER_PASSWORD=$(mkpasswd -m sha-512 "${USER_PASSWORD}") # Setup default user if [ "$ENABLE_USER" = true ] ; then - chroot_exec adduser --gecos $USER_NAME --add_extra_groups --disabled-password $USER_NAME - chroot_exec usermod -a -G sudo -p "${ENCRYPTED_USER_PASSWORD}" $USER_NAME + chroot_exec adduser --gecos "$USER_NAME" --add_extra_groups --disabled-password "$USER_NAME" + chroot_exec usermod -a -G sudo -p "${ENCRYPTED_USER_PASSWORD}" "$USER_NAME" fi # Setup root password or not diff --git a/bootstrap.d/41-uboot.sh b/bootstrap.d/41-uboot.sh index 6d42bde..dded27d 100644 --- a/bootstrap.d/41-uboot.sh +++ b/bootstrap.d/41-uboot.sh @@ -41,7 +41,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then # Install and setup U-Boot command file install_readonly files/boot/uboot.mkimage "${BOOT_DIR}/uboot.mkimage" - printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" + printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat "${BOOT_DIR}"/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" if [ "$ENABLE_INITRAMFS" = true ] ; then # Convert generated initramfs for U-Boot using mkimage @@ -51,7 +51,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then rm -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" # Configure U-Boot to load generated initramfs - printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" + printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat "${BOOT_DIR}"/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" printf "\nbootz \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" else # ENABLE_INITRAMFS=false # Remove initramfs from U-Boot mkfile @@ -65,19 +65,21 @@ if [ "$ENABLE_UBOOT" = true ] ; then printf "\nbootz \${kernel_addr_r} - \${fdt_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" fi fi - - if [ "$KERNEL_ARCH" = "arm64" ] ; then - echo "Setting up config.txt to boot 64bit uboot" - - printf "\n# 64bit-mode" >> "${BOOT_DIR}/config.txt" - printf "\n# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md" >> "${BOOT_DIR}/config.txt" - printf "\narm_64bit=1" >> "${BOOT_DIR}/config.txt" + if [ "$SET_ARCH" = 64 ] ; then + echo "Setting up config.txt to boot 64bit uboot" + { + printf "\n# 64bit-mode" + printf "\n# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md" + printf "\narm_64bit=1" + } >> "${BOOT_DIR}/config.txt" + + #in 64bit uboot booti is used instead of bootz [like in KERNEL_BIN_IMAGE=zImage (armv7)|| Image(armv8)] sed -i "s|bootz|booti|g" "${BOOT_DIR}/uboot.mkimage" fi # Set mkfile to use the correct dtb file - sed -i "s/^\(setenv dtbfile \).*/\1${DTB_FILE}/" "${BOOT_DIR}/uboot.mkimage" + sed -i "s|bcm2709-rpi-2-b.dtb|${DTB_FILE}|" "${BOOT_DIR}/uboot.mkimage" # Set mkfile to use the correct mach id if [ "$ENABLE_QEMU" = true ] ; then @@ -85,7 +87,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then fi # Set mkfile to use kernel image - sed -i "s/^\(fatload mmc 0:1 \${kernel_addr_r} \).*/\1${KERNEL_IMAGE}/" "${BOOT_DIR}/uboot.mkimage" + sed -i "s|kernel7.img|${KERNEL_IMAGE}|" "${BOOT_DIR}/uboot.mkimage" # Remove all leading blank lines sed -i "/./,\$!d" "${BOOT_DIR}/uboot.mkimage" diff --git a/bootstrap.d/43-videocore.sh b/bootstrap.d/43-videocore.sh index d42590c..b8ff518 100644 --- a/bootstrap.d/43-videocore.sh +++ b/bootstrap.d/43-videocore.sh @@ -8,16 +8,16 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then # Copy existing videocore sources into chroot directory if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then - # Copy local U-Boot sources + # Copy local videocore sources cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp/userland" else - # Create temporary directory for U-Boot sources + # Create temporary directory for videocore sources temp_dir=$(as_nobody mktemp -d) - # Fetch U-Boot sources + # Fetch videocore sources as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}" - # Copy downloaded U-Boot sources + # Copy downloaded videocore sources mv "${temp_dir}/userland" "${R}/tmp/" # Set permissions of the U-Boot sources @@ -31,7 +31,7 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then mkdir "${R}"/tmp/userland/build # push us to build directory - pushd "${R}"/tmp/userland/build + cd "${R}"/tmp/userland/build if [ "$RELEASE_ARCH" = "arm64" ] ; then cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" @@ -48,6 +48,6 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then #build userland make -j "$(nproc)" - #pop us out of build dir - popd + #back to root of scriptdir + cd "${WORKDIR}" fi diff --git a/files/etc/99-com.rules b/files/etc/99-com.rules new file mode 100644 index 0000000..fd6621d --- /dev/null +++ b/files/etc/99-com.rules @@ -0,0 +1,33 @@ +SUBSYSTEM=="input", GROUP="input", MODE="0660" +SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" +SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" +SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660" + +SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660" +SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\ + chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\ + chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\ + chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\ +'" + +KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\ + ALIASES=/proc/device-tree/aliases; \ + if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \ + echo 0;\ + elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \ + echo 1; \ + else \ + exit 1; \ + fi\ +'", SYMLINK+="serial%c" + +KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\ + ALIASES=/proc/device-tree/aliases; \ + if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \ + echo 0; \ + elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \ + echo 1; \ + else \ + exit 1; \ + fi \ +'", SYMLINK+="serial%c" diff --git a/files/sysctl.d/83-rpi-printk.conf b/files/sysctl.d/83-rpi-printk.conf new file mode 100644 index 0000000..f8948fb --- /dev/null +++ b/files/sysctl.d/83-rpi-printk.conf @@ -0,0 +1 @@ +kernel.printk = 3 4 1 3 \ No newline at end of file diff --git a/functions.sh b/functions.sh index 6ee31da..74ca846 100644 --- a/functions.sh +++ b/functions.sh @@ -30,22 +30,22 @@ cleanup (){ chroot_exec() { # Exec command in chroot - LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $* + LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot "${R}" "$@" } as_nobody() { # Exec command as user nobody - sudo -E -u nobody LANG=C LC_ALL=C $* + sudo -E -u nobody LANG=C LC_ALL=C "$@" } install_readonly() { # Install file with user read-only permissions - install -o root -g root -m 644 $* + install -o root -g root -m 644 "$@" } install_exec() { # Install file with root exec permissions - install -o root -g root -m 744 $* + install -o root -g root -m 744 "$@" } use_template () { @@ -64,14 +64,14 @@ chroot_install_cc() { if [ -z "${COMPILER_PACKAGES}" ] ; then COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }') # Install COMPILER_PACKAGES in chroot - chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} + chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install "${COMPILER_PACKAGES}" fi } chroot_remove_cc() { # Remove c/c++ build environment from the chroot - if [ ! -z "${COMPILER_PACKAGES}" ] ; then - chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} + if [ -n "${COMPILER_PACKAGES}" ] ; then + chroot_exec apt-get -qq -y --auto-remove purge "${COMPILER_PACKAGES}" COMPILER_PACKAGES="" fi } diff --git a/rpi23-gen-image.sh b/rpi23-gen-image.sh index 34e54e4..575252a 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -2,7 +2,7 @@ ######################################################################## # rpi23-gen-image.sh 2015-2017 # -# Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3 +# Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -36,7 +36,7 @@ fi # Introduce settings set -e -echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n" +echo -n -e "\n#\n# RPi 0/1/2/3 Bootstrap Settings\n#\n" set -x # Raspberry Pi model configuration @@ -59,7 +59,8 @@ VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} # Build directories -BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}} +WORKDIR=$(pwd) +BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}} BUILDDIR="${BASEDIR}/build" # Chroot directories @@ -69,6 +70,7 @@ LIB_DIR="${R}/lib" BOOT_DIR="${R}/boot/firmware" KERNEL_DIR="${R}/usr/src/linux" WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" +BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt" # Firmware directory: Blank if download from github RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} @@ -105,6 +107,9 @@ APT_PROXY=${APT_PROXY:=""} APT_SERVER=${APT_SERVER:="ftp.debian.org"} # Feature settings +ENABLE_PRINTK=${ENABLE_PRINTK:=false} +ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false} +ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false} ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} ENABLE_I2C=${ENABLE_I2C:=false} ENABLE_SPI=${ENABLE_SPI:=false} @@ -186,7 +191,7 @@ CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} # Packages required in the chroot build environment APT_INCLUDES=${APT_INCLUDES:=""} -APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup" +APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd" # Packages to exclude from chroot build environment APT_EXCLUDES=${APT_EXCLUDES:=""} @@ -200,16 +205,22 @@ COMPILER_PACKAGES="" set +x +#Check if apt-cacher-ng has port 3142 open and set APT_PROXY +APT_CACHER_RUNNING=$(lsof -i :3142 | grep apt-cacher-ng | cut -d ' ' -f3 | uniq) +if [ -n "${APT_CACHER_RUNNING}" ] ; then + APT_PROXY=http://127.0.0.1:3142/ +fi + # Setup architecture specific settings if [ -n "$SET_ARCH" ] ; then - # 64 bit configuration + # 64-bit configuration if [ "$SET_ARCH" = 64 ] ; then - # General 64 bit depended settings + # General 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"} - # Board specific settings + # Raspberry Pi model specific settings if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} @@ -217,19 +228,19 @@ if [ -n "$SET_ARCH" ] ; then KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} else - echo "error: Only Raspberry PI 3 and 3B+ support 64 bit" + echo "error: Only Raspberry PI 3 and 3B+ support 64-bit" exit 1 fi fi - # 32 bit configuration + # 32-bit configuration if [ "$SET_ARCH" = 32 ] ; then - # General 32 bit dependend settings + # General 32-bit dependend settings QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} KERNEL_ARCH=${KERNEL_ARCH:=arm} KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} - # Hardware specific settings + # Raspberry Pi model specific settings if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} @@ -238,7 +249,7 @@ if [ -n "$SET_ARCH" ] ; then CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} fi - # Hardware specific settings + # Raspberry Pi model specific settings if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} @@ -252,37 +263,51 @@ else echo "error: Please set '32' or '64' as value for SET_ARCH" exit 1 fi - # Device specific configuration and U-Boot configuration - 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 +# Device specific configuration and U-Boot configuration +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 + +# Raspberry PI 0,3,3P with Bluetooth and Wifi onboard +if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + # Include bluetooth packages on supported boards + if [ "$ENABLE_BLUETOOTH" = true ] && [ "$ENABLE_CONSOLE" = false ]; then + APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" + fi +else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard + # Check if the internal wireless interface is not supported by the RPi model + if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then + echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth" + exit 1 + fi +fi # Prepare date string for default image file name DATE="$(date +%Y-%m-%d)" @@ -292,16 +317,6 @@ else IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} 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 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then @@ -347,6 +362,14 @@ if [ "$ENABLE_UBOOT" = true ] ; then APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" fi +if [ "$ENABLE_BLUETOOTH" = true ] ; then + if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + if [ "$ENABLE_CONSOLE" = false ] ; then + APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" + fi + fi +fi + # Check if root SSH (v2) public key file exists if [ -n "$SSH_ROOT_PUB_KEY" ] ; then if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then @@ -365,7 +388,7 @@ fi # Check if all required packages are installed on the build system for package in $REQUIRED_PACKAGES ; do - if [ "$(dpkg-query -W -f='${Status}' $package)" != "install ok installed" ] ; then + if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then MISSING_PACKAGES="${MISSING_PACKAGES} $package" fi done @@ -380,7 +403,7 @@ if [ -n "$MISSING_PACKAGES" ] ; then [ "$confirm" != "y" ] && exit 1 # Make sure all missing required packages are installed - apt-get -qq -y install "${MISSING_PACKAGES}" + apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"` fi # Check if ./bootstrap.d directory exists diff --git a/templates/rpi0buster b/templates/rpi0buster new file mode 100644 index 0000000..3300983 --- /dev/null +++ b/templates/rpi0buster @@ -0,0 +1,5 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=0 +RELEASE=buster +BUILD_KERNEL=true +# ENABLE_BLUETOOTH=false diff --git a/templates/rpi0stretch b/templates/rpi0stretch new file mode 100644 index 0000000..6c47d50 --- /dev/null +++ b/templates/rpi0stretch @@ -0,0 +1,5 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=0 +RELEASE=stretch +BUILD_KERNEL=true +# ENABLE_BLUETOOTH=false diff --git a/templates/rpi1Pbuster b/templates/rpi1Pbuster new file mode 100644 index 0000000..c1e846f --- /dev/null +++ b/templates/rpi1Pbuster @@ -0,0 +1,4 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=1P +RELEASE=buster +BUILD_KERNEL=true diff --git a/templates/rpi1Pstretch b/templates/rpi1Pstretch new file mode 100644 index 0000000..209107d --- /dev/null +++ b/templates/rpi1Pstretch @@ -0,0 +1,4 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=1P +RELEASE=stretch +BUILD_KERNEL=true diff --git a/templates/rpi1buster b/templates/rpi1buster new file mode 100644 index 0000000..b365f59 --- /dev/null +++ b/templates/rpi1buster @@ -0,0 +1,4 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=3 +RELEASE=buster +BUILD_KERNEL=true diff --git a/templates/rpi1stretch b/templates/rpi1stretch new file mode 100644 index 0000000..735dea2 --- /dev/null +++ b/templates/rpi1stretch @@ -0,0 +1,4 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=2 +RELEASE=stretch +BUILD_KERNEL=true diff --git a/templates/rpi2stretch b/templates/rpi2stretch index a67c72f..735dea2 100644 --- a/templates/rpi2stretch +++ b/templates/rpi2stretch @@ -1,3 +1,4 @@ # Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=2 RELEASE=stretch BUILD_KERNEL=true diff --git a/templates/rpi3Pbuster b/templates/rpi3Pbuster new file mode 100644 index 0000000..8f308de --- /dev/null +++ b/templates/rpi3Pbuster @@ -0,0 +1,6 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=3P +RELEASE=buster +BUILD_KERNEL=true +# ENABLE_WIRELESS=false +# ENABLE_BLUETOOTH=false diff --git a/templates/rpi3Pstretch b/templates/rpi3Pstretch new file mode 100644 index 0000000..904535e --- /dev/null +++ b/templates/rpi3Pstretch @@ -0,0 +1,6 @@ +# Configuration template file used by rpi23-gen-image.sh +RPI_MODEL=3P +RELEASE=stretch +BUILD_KERNEL=true +# ENABLE_WIRELESS=false +# ENABLE_BLUETOOTH=false diff --git a/templates/rpi3buster b/templates/rpi3buster index b365f59..cc0dc1e 100644 --- a/templates/rpi3buster +++ b/templates/rpi3buster @@ -2,3 +2,5 @@ RPI_MODEL=3 RELEASE=buster BUILD_KERNEL=true +# ENABLE_WIRELESS=false +# ENABLE_BLUETOOTH=false diff --git a/templates/rpi3stretch b/templates/rpi3stretch index 70a063e..b6566cd 100644 --- a/templates/rpi3stretch +++ b/templates/rpi3stretch @@ -2,3 +2,5 @@ RPI_MODEL=3 RELEASE=stretch BUILD_KERNEL=true +# ENABLE_WIRELESS=false +# ENABLE_BLUETOOTH=false