diff --git a/README.md b/README.md index 9ba0fcd..1f329c5 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,13 @@ If you want to change e.g. cross-compiler -> Templates always override defaults ##### `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. +- `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. ##### `RELEASE`="buster" Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases `stretch` and `buster`. @@ -153,7 +153,19 @@ 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: 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 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. @@ -173,9 +185,6 @@ Allow the installation of non-free Debian packages that do not comply with the D ##### `ENABLE_WIRELESS`=false 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_BLUETOOTH`=false -Enable Bluetooth interface on the RPi0/3. - ##### `ENABLE_RSYSLOG`=true If set to false, disable and uninstall rsyslog (so logs will be available only in journal files) diff --git a/bootstrap.d/15-rpi-config.sh b/bootstrap.d/15-rpi-config.sh index 387c3ed..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,53 +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" - fi -fi - -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/" - - # Raspberry-sys-mod package for /dev/serial device needed by bluetooth service - as_nobody wget -q -O "${R}/tmp/pi-bluetooth/99-com.rules" https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules - # 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 "${ETC_DIR}/firmware/" - install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${ETC_DIR}/firmware/LICENCE.broadcom_bcm43xx" - install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${ETC_DIR}/firmware/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" - # Install udev rule for bluetooth device - install_readonly "${R}/tmp/pi-bluetooth/99-com.rules" "${ETC_DIR}/udev/rules.d/99-com.rules" - - # Remove temporary directory - rm -fr "${temp_dir}" -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/rpi23-gen-image.sh b/rpi23-gen-image.sh index e313f9e..48d7810 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -70,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:=""} @@ -106,7 +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} @@ -204,7 +207,7 @@ 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 +if [ -n "${APT_CACHER_RUNNING}" ] ; then APT_PROXY=http://127.0.0.1:3142/ fi @@ -292,6 +295,20 @@ case "$RPI_MODEL" in ;; 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)" if [ -z "$KERNEL_BRANCH" ] ; then @@ -300,14 +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 - 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