diff --git a/README-CN.md b/README-CN.md index cb07184..7a5f0de 100644 --- a/README-CN.md +++ b/README-CN.md @@ -1,5 +1,5 @@ ## 介绍 -`rpi23-gen-image.sh` 是一个自动生成树莓派2/3系统镜像的脚本工具, 当前支持自动生成32位 armhf 架构的Debian, 发行版本`jessie`, `stretch` 和 `buster`. 树莓派3 64位镜像需要使用特定的配置参数 (```templates/rpi3-stretch-arm64-4.11.y```). +`rpi23-gen-image.sh` 是一个自动生成树莓派2/3系统镜像的脚本工具, 当前支持自动生成32位 armhf 架构的Debian, 发行版本`jessie`, `stretch` 和 `buster`. 树莓派3 64位镜像需要使用特定的配置参数 (```templates/rpi3-stretch-arm64-4.14.y```). ## 构建环境所依赖的包 一定要安装好下列deb包, 他们是构建过程需要的核心包. 脚本会自动检查, 如果缺少,经用户确认后会自动安装. @@ -151,10 +151,10 @@ CONFIG_TEMPLATE=rpi2stretch ./rpi23-gen-image.sh 允许串行控制台接口. 没有连接显示器键盘的树莓派推荐打开, 此时如果网络无法连接至树莓派, 可以使用串行控制台连至系统. ##### `ENABLE_I2C`=false -允许树莓派2/3的 I2C 接口. 请对照 [树莓派2/3 引脚示意图](http://elinux.org/RPi_Low-level_peripherals) 正确连接 GPIO 引脚. +允许树莓派2/3的 I2C 接口. 请对照 [树莓派2/3 引脚示意图](https://elinux.org/RPi_Low-level_peripherals) 正确连接 GPIO 引脚. ##### `ENABLE_SPI`=false -允许树莓派2/3的 SPI 接口. 请对照 [树莓派2/3 引脚示意图](http://elinux.org/RPi_Low-level_peripherals) 正确连接 GPIO 引脚. +允许树莓派2/3的 SPI 接口. 请对照 [树莓派2/3 引脚示意图](https://elinux.org/RPi_Low-level_peripherals) 正确连接 GPIO 引脚. ##### `ENABLE_IPV6`=true 允许 IPv6 . 通过 systemd-networkd 配置管理网络接口. @@ -199,10 +199,10 @@ CONFIG_TEMPLATE=rpi2stretch ./rpi23-gen-image.sh 卸载包、删除文件以减小体积 详情查看 `REDUCE_*` 参数. ##### `ENABLE_UBOOT`=false -使用 [U-Boot 引导器](http://git.denx.de/?p=u-boot.git;a=summary) 替代树莓派2/3 默认的第二阶段引导器(bootcode.bin). U-Boot 可以通过网络使用 BOOTP/TFTP 协议引导镜像文件. +使用 [U-Boot 引导器](https://git.denx.de/?p=u-boot.git;a=summary) 替代树莓派2/3 默认的第二阶段引导器(bootcode.bin). U-Boot 可以通过网络使用 BOOTP/TFTP 协议引导镜像文件. ##### `UBOOTSRC_DIR`="" -存放已下载 [U-Boot 引导器源文件](http://git.denx.de/?p=u-boot.git;a=summary) 的目录(`u-boot`). +存放已下载 [U-Boot 引导器源文件](https://git.denx.de/?p=u-boot.git;a=summary) 的目录(`u-boot`). ##### `ENABLE_FBTURBO`=false 安装并且允许 [硬件加速的 Xorg 显卡驱动](https://github.com/ssvb/xf86-video-fbturbo) `fbturbo`. 当前仅支持窗口的移动和滚动的硬件加速. @@ -444,7 +444,7 @@ bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-root.img /dev/sdc * [Debian 交叉工具链 Wiki](https://wiki.debian.org/CrossToolchains) * [Github上的树莓派官方固件](https://github.com/raspberrypi/firmware) * [Github上的树莓派官方内核](https://github.com/raspberrypi/linux) -* [U-BOOT git 仓库](http://git.denx.de/?p=u-boot.git;a=summary) +* [U-BOOT git 仓库](https://git.denx.de/?p=u-boot.git;a=summary) * [Xorg DDX fbturbo驱动](https://github.com/ssvb/xf86-video-fbturbo) * [树莓派3无线接口固件](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm80211/brcm) * [Collabora 树莓派2预编译内核](https://repositories.collabora.co.uk/debian/) diff --git a/README.md b/README.md index 1eb16bc..a0a5d67 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,19 @@ # 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```). + ## 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. - -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. +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. -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` 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. @@ -57,28 +50,40 @@ 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. + +##### `KEEP_APT_PROXY`=false +Keep the APT_PROXY settings used in the bootsrapping process in the generated image. ##### `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 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 Raspberry Pi models `2` and `3`. `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` 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`="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`. ##### `RELEASE_ARCH`="armhf" 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. @@ -95,6 +100,12 @@ Set default system timezone. All available timezones can be found in the `/usr/s ##### `EXPANDROOT`=true Expand the root partition and filesystem automatically on first boot. +##### `ENABLE_DPHYSSWAP`=true +Enable swap. The size of the swapfile is chosen relative to the size of the root partition. It'll use the `dphys-swapfile` package for that. + +##### `ENABLE_QEMU`=false +Generate kernel (`vexpress_defconfig`), file system image (`qcow2`) and DTB files that can be used for QEMU full system emulation (`vexpress-A15`). The output files are stored in the `$(pwd)/images/qemu` directory. You can find more information about running the generated image in the QEMU section of this readme file. + --- #### Keyboard settings: @@ -115,7 +126,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. @@ -138,7 +149,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. @@ -150,13 +161,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](http://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](http://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. @@ -168,17 +191,16 @@ Install and enable OpenSSH service. The default configuration of the service doe Allow the installation of non-free Debian packages that do not comply with the DFSG. This is required to install closed-source firmware binary blobs. ##### `ENABLE_WIRELESS`=false -Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm80211/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`. +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. @@ -190,11 +212,17 @@ 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 --- #### Advanced system features: +##### `ENABLE_SYSTEMDSWAP`=false +Enables [Systemd-swap service](https://github.com/Nefelim4ag/systemd-swap). Usefull if `KERNEL_ZSWAP` is enabled. + ##### `ENABLE_MINBASE`=false Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB. @@ -202,10 +230,10 @@ 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](http://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](http://git.denx.de/?p=u-boot.git;a=summary) that will be copied, configured, build and installed inside the chroot. +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. ##### `ENABLE_FBTURBO`=false Install and enable the [hardware accelerated Xorg video driver](https://github.com/ssvb/xf86-video-fbturbo) `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling. @@ -213,11 +241,23 @@ Install and enable the [hardware accelerated Xorg video driver](https://github.c ##### `FBTURBOSRC_DIR`="" 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 [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 [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_NEXMON`=false +Install and enable the [Source code for a C-based firmware patching framework for Broadcom/Cypress WiFi chips that enables you to write your own firmware patches, for example, to enable monitor mode with radiotap headers and frame injection](https://github.com/seemoo-lab/nexmon.git). + +##### `NEXMONSRC_DIR`="" +Path to a directory (`nexmon`) 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. + ##### `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 @@ -238,7 +278,16 @@ Path to a directory with scripts that should be run in the chroot before the ima Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false. ##### `ENABLE_IFNAMES`=true -Enable automatic assignment of predictable, stable network interface names for all local Ethernet, WLAN interfaces. This might create complex and long interface names. This parameter is only supported if the Debian releases `stretch` or `buster` are used. +Enable automatic assignment of predictable, stable network interface names for all local Ethernet, WLAN interfaces. This might create complex and long interface names. + +##### `ENABLE_SPLASH`=true +Enable default Raspberry Pi boot up rainbow splash screen. + +##### `ENABLE_LOGO`=true +Enable default Raspberry Pi console logo (image of four raspberries in the top left corner). + +##### `ENABLE_SILENT_BOOT`=false +Set the verbosity of console messages shown during boot up to a strict minimum. ##### `DISABLE_UNDERVOLT_WARNINGS`= Disable RPi2/3 under-voltage warnings and overlays. Setting the parameter to `1` will disable the warning overlay. Setting it to `2` will additionally allow RPi2/3 turbo mode when low-voltage is present. @@ -247,10 +296,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). @@ -264,11 +313,11 @@ Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enab --- #### Kernel compilation: -##### `BUILD_KERNEL`=false -Build and install the latest RPi2/3 Linux kernel. Currently only the default RPi2/3 kernel configuration is used. `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` is used. +##### `BUILD_KERNEL`=true +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. @@ -286,17 +335,23 @@ 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. +##### `KERNEL_OLDDEFCONFIG`=false +Run `make olddefconfig` to automatically set all new kernel configuration options to their recommended default values. + +##### `KERNEL_CCACHE`=false +Compile the kernel using ccache. This speeds up kernel recompilation by caching previous compilations and detecting when the same compilation is being done again. + ##### `KERNEL_REMOVESRC`=true Remove all kernel sources from the generated OS image after it was built and installed. @@ -318,6 +373,24 @@ With this parameter set to true the script expects the existing kernel sources d ##### `RPI_FIRMWARE_DIR`="" The directory (`firmware`) containing a local copy of the firmware from the [RaspberryPi firmware project](https://github.com/raspberrypi/firmware). Default is to download the latest firmware directly from the project. +##### `KERNEL_DEFAULT_GOV`="ONDEMAND" +Set the default cpu governor at kernel compilation. Supported values are: PERFORMANCE POWERSAVE USERSPACE ONDEMAND CONSERVATIVE SCHEDUTIL + +##### `KERNEL_NF`=false +Enable Netfilter modules as kernel modules + +##### `KERNEL_VIRT`=false +Enable Kernel KVM support (/dev/kvm) + +##### `KERNEL_ZSWAP`=false +Enable Kernel Zswap support. Best use on high RAM load and mediocre CPU load usecases + +##### `KERNEL_BPF`=true +Allow attaching eBPF programs to a cgroup using the bpf syscall (CONFIG_BPF_SYSCALL CONFIG_CGROUP_BPF) [systemd compilations about it - File /lib/systemd/system/systemd-journald.server:36 configures an IP firewall (IPAddressDeny=all), but the local system does not support BPF/cgroup based firewalls] + +##### `KERNEL_SECURITY`=false +Enables Apparmor, integrity subsystem, auditing. + --- #### Reduce disk usage: @@ -365,6 +438,12 @@ Set cipher specification string. `aes-xts*` ciphers are strongly recommended. ##### `CRYPTFS_XTSKEYSIZE`=512 Sets key size in bits. The argument has to be a multiple of 8. +##### `CRYPTFS_DROPBEAR`=false +Enable Dropbear Initramfs support + +##### `CRYPTFS_DROPBEAR_PUBKEY`="" +Provide path to dropbear Public RSA-OpenSSH Key + --- #### Build settings: @@ -382,9 +461,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 | @@ -392,6 +471,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 | @@ -400,7 +480,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 | @@ -426,21 +506,39 @@ 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 -bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie.img /dev/mmcblk0 -dd bs=4M if=./images/jessie/2017-01-23-rpi3-jessie.img of=/dev/mmcblk0 +bmaptool copy ./images/buster/2017-01-23-rpi3-buster.img /dev/mmcblk0 +dd bs=4M if=./images/buster/2017-01-23-rpi3-buster.img of=/dev/mmcblk0 ``` If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive: ```shell -bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-frmw.img /dev/mmcblk0 -bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-root.img /dev/sdc +bmaptool copy ./images/buster/2017-01-23-rpi3-buster-frmw.img /dev/mmcblk0 +bmaptool copy ./images/buster/2017-01-23-rpi3-buster-root.img /dev/sdc +``` + +## QEMU emulation +Start QEMU full system emulation: +```shell +qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=tty1" +``` + +Start QEMU full system emulation and output to console: +```shell +qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio +``` + +Start QEMU full system emulation with SMP and output to console: +```shell +qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -smp cpus=2,maxcpus=2 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio +``` + +Start QEMU full system emulation with cryptfs, initramfs and output to console: +```shell +qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -initrd "initramfs-${KERNEL_VERSION}" -append "root=/dev/mapper/secure cryptdevice=/dev/mmcblk0p2:secure rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio ``` -## Weekly image builds -The image files are provided by JRWR'S I/O PORT and are built once a Sunday at midnight UTC! -* [Debian Stretch Raspberry Pi2/3 Weekly Image Builds](https://jrwr.io/doku.php?id=projects:debianpi) ## External links and references * [Debian worldwide mirror sites](https://www.debian.org/mirror/list) @@ -448,7 +546,7 @@ The image files are provided by JRWR'S I/O PORT and are built once a Sunday at m * [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) * [Official Raspberry Pi Firmware on github](https://github.com/raspberrypi/firmware) * [Official Raspberry Pi Kernel on github](https://github.com/raspberrypi/linux) -* [U-BOOT git repository](http://git.denx.de/?p=u-boot.git;a=summary) +* [U-BOOT git repository](https://git.denx.de/?p=u-boot.git;a=summary) * [Xorg DDX driver fbturbo](https://github.com/ssvb/xf86-video-fbturbo) -* [RPi3 Wireless interface firmware](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm80211/brcm) +* [RPi3 Wireless interface firmware](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm) * [Collabora RPi2 Kernel precompiled](https://repositories.collabora.co.uk/debian/) diff --git a/bootstrap.d/10-bootstrap.sh b/bootstrap.d/10-bootstrap.sh index b0dd8e4..7ea1b87 100644 --- a/bootstrap.d/10-bootstrap.sh +++ b/bootstrap.d/10-bootstrap.sh @@ -7,7 +7,6 @@ VARIANT="" COMPONENTS="main" -EXCLUDES="" # Use non-free Debian packages if needed if [ "$ENABLE_NONFREE" = true ] ; then @@ -19,13 +18,15 @@ if [ "$ENABLE_MINBASE" = true ] ; then VARIANT="--variant=minbase" fi + # Exclude packages if required by Debian release if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then EXCLUDES="--exclude=init,systemd-sysv" fi + # Base debootstrap (unpack only) -http_proxy=${APT_PROXY} debootstrap ${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 7794053..ed81db0 100644 --- a/bootstrap.d/11-apt.sh +++ b/bootstrap.d/11-apt.sh @@ -32,25 +32,28 @@ else # BUILD_KERNEL=true 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" -fi + +# Use specified APT server and release +sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "${ETC_DIR}/apt/sources.list" +sed -i "s/ stretch/ ${RELEASE}/" "${ETC_DIR}/apt/sources.list" # Upgrade package index and update all installed packages and changed dependencies chroot_exec apt-get -qq -y update chroot_exec apt-get -qq -y -u dist-upgrade +# Install additional packages if [ "$APT_INCLUDES_LATE" ] ; then - chroot_exec apt-get -qq -y install $(echo $APT_INCLUDES_LATE |tr , ' ') + chroot_exec apt-get -qq -y install $(echo "$APT_INCLUDES_LATE" |tr , ' ') fi +# Install Debian custom packages if [ -d packages ] ; then for package in packages/*.deb ; do - cp $package ${R}/tmp - chroot_exec dpkg --unpack /tmp/$(basename $package) + cp "$package" "${R}"/tmp + chroot_exec dpkg --unpack /tmp/"$(basename "$package")" done fi + chroot_exec apt-get -qq -y -f install chroot_exec apt-get -qq -y check diff --git a/bootstrap.d/12-locale.sh b/bootstrap.d/12-locale.sh index e69f44c..c086ee2 100644 --- a/bootstrap.d/12-locale.sh +++ b/bootstrap.d/12-locale.sh @@ -6,24 +6,32 @@ . ./functions.sh # Install and setup timezone -echo ${TIMEZONE} > "${ETC_DIR}/timezone" +echo "${TIMEZONE}" > "${ETC_DIR}/timezone" +if [ -f "${ETC_DIR}/localtime" ]; then + # 1. If 11-apt.sh upgrades the package 'tzdata', '/etc/localtime' was created + # because 'dpkg-reconfigure -f noninteractive tzdata' was executed by apt-get. + # 2. If '/etc/localtime' exists, our execution of 'dpkg-reconfigure -f noninteractive tzdata' + # will ignore the our timezone set in '/etc/timezone'. + # 3. Removing /etc/localtime will solve this. + rm -f "${ETC_DIR}/localtime" +fi chroot_exec dpkg-reconfigure -f noninteractive tzdata # Install and setup default locale and keyboard configuration -if [ $(echo "$APT_INCLUDES" | grep ",locales") ] ; then +if [ "$(echo "$APT_INCLUDES" | grep ",locales")" ] ; then # Set locale choice in debconf db, even though dpkg-reconfigure ignores and overwrites them due to some bug # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684134 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685957 # ... so we have to set locales manually if [ "$DEFLOCAL" = "en_US.UTF-8" ] ; then - chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8" | debconf-set-selections + chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8 | debconf-set-selections" else # en_US.UTF-8 should be available anyway : https://www.debian.org/doc/manuals/debian-reference/ch08.en.html#_the_reconfiguration_of_the_locale - chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8" | debconf-set-selections + chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8 | debconf-set-selections" sed -i "/en_US.UTF-8/s/^#//" "${ETC_DIR}/locale.gen" fi sed -i "/${DEFLOCAL}/s/^#//" "${ETC_DIR}/locale.gen" - chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections + chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL} | debconf-set-selections" chroot_exec locale-gen chroot_exec update-locale LANG="${DEFLOCAL}" diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index 45934be..536ced0 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -5,15 +5,23 @@ # Load utility functions . ./functions.sh +# Need to use kali kernel src if nexmon is enabled +if [ "$ENABLE_NEXMON" = true ] ; then + KERNEL_URL="${KALI_KERNEL_URL}" + # Clear Branch and KernelSRC_DIR if using nexmon. Everyone will forget to clone kali kernel instead of nomrla kernel + KERNEL_BRANCH="" + KERNELSRC_DIR="" +fi + # Fetch and build latest raspberry kernel if [ "$BUILD_KERNEL" = true ] ; then # Setup source directory - mkdir -p "${R}/usr/src/linux" + mkdir -p "${KERNEL_DIR}" # Copy existing kernel sources into chroot directory if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then # Copy kernel sources and include hidden files - cp -r "${KERNELSRC_DIR}/". "${R}/usr/src/linux" + cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}" # Clean the kernel sources if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then @@ -25,13 +33,13 @@ if [ "$BUILD_KERNEL" = true ] ; then # Fetch current RPi2/3 kernel sources if [ -z "${KERNEL_BRANCH}" ] ; then - as_nobody git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux + as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux else - as_nobody git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux - fi - + as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux + fi + # Copy downloaded kernel sources - cp -r "${temp_dir}/linux/"* "${R}/usr/src/linux/" + cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}" # Remove temporary directory for kernel sources rm -fr "${temp_dir}" @@ -87,18 +95,353 @@ if [ "$BUILD_KERNEL" = true ] ; then # Load default raspberry kernel configuration make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" - if [ ! -z "$KERNELSRC_USRCONFIG" ] ; then - cp $KERNELSRC_USRCONFIG ${KERNEL_DIR}/.config + #Switch to KERNELSRC_DIR so we can use set_kernel_config + cd "${KERNEL_DIR}" || exit + + if [ "$KERNEL_ARCH" = arm64 ] ; then + #Fix SD_DRIVER upstream and downstream mess in 64bit RPIdeb_config + # use correct driver MMC_BCM2835_MMC instead of MMC_BCM2835_SDHOST - see https://www.raspberrypi.org/forums/viewtopic.php?t=210225 + set_kernel_config CONFIG_MMC_BCM2835 n + set_kernel_config CONFIG_MMC_SDHCI_IPROC n + set_kernel_config CONFIG_USB_DWC2 n + sed -i "s|depends on MMC_BCM2835_MMC && MMC_BCM2835_DMA|depends on MMC_BCM2835_MMC|" "${KERNEL_DIR}"/drivers/mmc/host/Kconfig + + #VLAN got disabled without reason in arm64bit + set_kernel_config CONFIG_IPVLAN m + fi + + # enable ZSWAP see https://askubuntu.com/a/472227 or https://wiki.archlinux.org/index.php/zswap + if [ "$KERNEL_ZSWAP" = true ] ; then + set_kernel_config CONFIG_ZPOOL y + set_kernel_config CONFIG_ZSWAP y + set_kernel_config CONFIG_ZBUD y + set_kernel_config CONFIG_Z3FOLD y + set_kernel_config CONFIG_ZSMALLOC y + set_kernel_config CONFIG_PGTABLE_MAPPING y + set_kernel_config CONFIG_LZO_COMPRESS y + + fi + + # enable basic KVM support; see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453 + if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then + set_kernel_config CONFIG_HAVE_KVM_IRQCHIP y + set_kernel_config CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL y + set_kernel_config CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT y + set_kernel_config CONFIG_HAVE_KVM_EVENTFD y + set_kernel_config CONFIG_HAVE_KVM_IRQFD y + set_kernel_config CONFIG_HAVE_KVM_IRQ_ROUTING y + set_kernel_config CONFIG_HAVE_KVM_MSI y + set_kernel_config CONFIG_KVM y + set_kernel_config CONFIG_KVM_ARM_HOST y + set_kernel_config CONFIG_KVM_ARM_PMU y + set_kernel_config CONFIG_KVM_COMPAT y + set_kernel_config CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT y + set_kernel_config CONFIG_KVM_MMIO y + set_kernel_config CONFIG_KVM_VFIO y + set_kernel_config CONFIG_VHOST m + set_kernel_config CONFIG_VHOST_CROSS_ENDIAN_LEGACY y + set_kernel_config CONFIG_VHOST_NET m + set_kernel_config CONFIG_VIRTUALIZATION y + + set_kernel_config CONFIG_MMU_NOTIFIER y + + # erratum + set_kernel_config ARM64_ERRATUM_834220 y + + # https://sourceforge.net/p/kvm/mailman/message/18440797/ + set_kernel_config CONFIG_PREEMPT_NOTIFIERS y + fi + + # enable apparmor,integrity audit, + if [ "$KERNEL_SECURITY" = true ] ; then + + # security filesystem, security models and audit + set_kernel_config CONFIG_SECURITYFS y + set_kernel_config CONFIG_SECURITY y + set_kernel_config CONFIG_AUDIT y + + # harden strcpy and memcpy + set_kernel_config CONFIG_HARDENED_USERCOPY y + set_kernel_config CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR y + set_kernel_config CONFIG_FORTIFY_SOURCE y + + # integrity sub-system + set_kernel_config CONFIG_INTEGRITY y + set_kernel_config CONFIG_INTEGRITY_ASYMMETRIC_KEYS y + set_kernel_config CONFIG_INTEGRITY_AUDIT y + set_kernel_config CONFIG_INTEGRITY_SIGNATURE y + set_kernel_config CONFIG_INTEGRITY_TRUSTED_KEYRING y + + # This option provides support for retaining authentication tokens and access keys in the kernel. + set_kernel_config CONFIG_KEYS y + set_kernel_config CONFIG_KEYS_COMPAT y + + # Apparmor + set_kernel_config CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE 0 + set_kernel_config CONFIG_SECURITY_APPARMOR_HASH_DEFAULT y + set_kernel_config CONFIG_DEFAULT_SECURITY_APPARMOR y + set_kernel_config CONFIG_SECURITY_APPARMOR y + set_kernel_config CONFIG_SECURITY_APPARMOR_HASH y + set_kernel_config CONFIG_DEFAULT_SECURITY "apparmor" + + # restrictions on unprivileged users reading the kernel + set_kernel_config CONFIG_SECURITY_DMESG_RESTRICT y + + # network security hooks + set_kernel_config CONFIG_SECURITY_NETWORK y + set_kernel_config CONFIG_SECURITY_NETWORK_XFRM y + set_kernel_config CONFIG_SECURITY_PATH y + set_kernel_config CONFIG_SECURITY_YAMA n + + # New Options + if [ "$KERNEL_NF" = true ] ; then + set_kernel_config CONFIG_IP_NF_SECURITY m + set_kernel_config CONFIG_NETLABEL y + set_kernel_config CONFIG_IP6_NF_SECURITY m + fi + set_kernel_config CONFIG_SECURITY_SELINUX n + set_kernel_config CONFIG_SECURITY_SMACK n + set_kernel_config CONFIG_SECURITY_TOMOYO n + set_kernel_config CONFIG_SECURITY_APPARMOR_DEBUG n + set_kernel_config CONFIG_SECURITY_LOADPIN n + set_kernel_config CONFIG_HARDENED_USERCOPY_PAGESPAN n + set_kernel_config CONFIG_IMA n + set_kernel_config CONFIG_EVM n + set_kernel_config CONFIG_FANOTIFY_ACCESS_PERMISSIONS y + set_kernel_config CONFIG_NFSD_V4_SECURITY_LABEL y + set_kernel_config CONFIG_PKCS7_MESSAGE_PARSER y + set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYRING y + set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYS y + set_kernel_config CONFIG_SYSTEM_EXTRA_CERTIFICATE y + set_kernel_config CONFIG_SECONDARY_TRUSTED_KEYRING y + set_kernel_config CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY n + set_kernel_config CONFIG_SYSTEM_TRUSTED_KEYS m + set_kernel_config CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE 4096 + + set_kernel_config CONFIG_ARM64_CRYPTO y + set_kernel_config CONFIG_CRYPTO_SHA256_ARM64 m + set_kernel_config CONFIG_CRYPTO_SHA512_ARM64 m + set_kernel_config CONFIG_CRYPTO_SHA1_ARM64_CE m + set_kernel_config CRYPTO_GHASH_ARM64_CE m + set_kernel_config CRYPTO_SHA2_ARM64_CE m + set_kernel_config CONFIG_CRYPTO_CRCT10DIF_ARM64_CE m + set_kernel_config CONFIG_CRYPTO_CRC32_ARM64_CE m + set_kernel_config CONFIG_CRYPTO_AES_ARM64 m + set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE m + set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE_CCM y + set_kernel_config CONFIG_CRYPTO_AES_ARM64_CE_BLK y + set_kernel_config CONFIG_CRYPTO_AES_ARM64_NEON_BLK m + set_kernel_config CONFIG_CRYPTO_CHACHA20_NEON m + set_kernel_config CONFIG_CRYPTO_AES_ARM64_BS m + set_kernel_config SYSTEM_TRUSTED_KEYS + fi + + # Netfilter kernel support See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406 + if [ "$KERNEL_NF" = true ] ; then + set_kernel_config CONFIG_IP_NF_TARGET_SYNPROXY m + set_kernel_config CONFIG_NETFILTER_XT_TARGET_AUDIT m + set_kernel_config CONFIG_NETFILTER_XT_MATCH_CGROUP m + set_kernel_config CONFIG_NETFILTER_XT_MATCH_IPCOMP m + set_kernel_config CONFIG_NETFILTER_XT_MATCH_SOCKET m + set_kernel_config CONFIG_NFT_FIB_INET m + set_kernel_config CONFIG_NFT_FIB_IPV4 m + set_kernel_config CONFIG_NFT_FIB_IPV6 m + set_kernel_config CONFIG_NFT_FIB_NETDEV m + set_kernel_config CONFIG_NFT_OBJREF m + set_kernel_config CONFIG_NFT_RT m + set_kernel_config CONFIG_NFT_SET_BITMAP m + set_kernel_config CONFIG_NF_CONNTRACK_TIMEOUT y + set_kernel_config CONFIG_NF_LOG_ARP m + set_kernel_config CONFIG_NF_SOCKET_IPV4 m + set_kernel_config CONFIG_NF_SOCKET_IPV6 m + set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m + set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m + set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m + set_kernel_config CONFIG_IP6_NF_IPTABLES m + set_kernel_config CONFIG_IP6_NF_MATCH_AH m + set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m + set_kernel_config CONFIG_IP6_NF_NAT m + set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m + set_kernel_config CONFIG_IP6_NF_TARGET_NPT m + set_kernel_config CONFIG_IP_NF_SECURITY m + set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m + set_kernel_config CONFIG_IP_SET_BITMAP_PORT m + set_kernel_config CONFIG_IP_SET_HASH_IP m + set_kernel_config CONFIG_IP_SET_HASH_IPMARK m + set_kernel_config CONFIG_IP_SET_HASH_IPPORT m + set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m + set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m + set_kernel_config CONFIG_IP_SET_HASH_MAC m + set_kernel_config CONFIG_IP_SET_HASH_NET m + set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m + set_kernel_config CONFIG_IP_SET_HASH_NETNET m + set_kernel_config CONFIG_IP_SET_HASH_NETPORT m + set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m + set_kernel_config CONFIG_IP_SET_LIST_SET m + set_kernel_config CONFIG_NETFILTER_XTABLES m + set_kernel_config CONFIG_NETFILTER_XTABLES m + set_kernel_config CONFIG_NFT_BRIDGE_META m + set_kernel_config CONFIG_NFT_BRIDGE_REJECT m + set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m + set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m + set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m + set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m + set_kernel_config CONFIG_NFT_COMPAT m + set_kernel_config CONFIG_NFT_COUNTER m + set_kernel_config CONFIG_NFT_CT m + set_kernel_config CONFIG_NFT_DUP_IPV4 m + set_kernel_config CONFIG_NFT_DUP_IPV6 m + set_kernel_config CONFIG_NFT_DUP_NETDEV m + set_kernel_config CONFIG_NFT_EXTHDR m + set_kernel_config CONFIG_NFT_FWD_NETDEV m + set_kernel_config CONFIG_NFT_HASH m + set_kernel_config CONFIG_NFT_LIMIT m + set_kernel_config CONFIG_NFT_LOG m + set_kernel_config CONFIG_NFT_MASQ m + set_kernel_config CONFIG_NFT_MASQ_IPV4 m + set_kernel_config CONFIG_NFT_MASQ_IPV6 m + set_kernel_config CONFIG_NFT_META m + set_kernel_config CONFIG_NFT_NAT m + set_kernel_config CONFIG_NFT_NUMGEN m + set_kernel_config CONFIG_NFT_QUEUE m + set_kernel_config CONFIG_NFT_QUOTA m + set_kernel_config CONFIG_NFT_REDIR m + set_kernel_config CONFIG_NFT_REDIR_IPV4 m + set_kernel_config CONFIG_NFT_REDIR_IPV6 m + set_kernel_config CONFIG_NFT_REJECT m + set_kernel_config CONFIG_NFT_REJECT_INET m + set_kernel_config CONFIG_NFT_REJECT_IPV4 m + set_kernel_config CONFIG_NFT_REJECT_IPV6 m + set_kernel_config CONFIG_NFT_SET_HASH m + set_kernel_config CONFIG_NFT_SET_RBTREE m + set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m + set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m + set_kernel_config CONFIG_NF_DEFRAG_IPV4 m + set_kernel_config CONFIG_NF_DEFRAG_IPV6 m + set_kernel_config CONFIG_NF_DUP_IPV4 m + set_kernel_config CONFIG_NF_DUP_IPV6 m + set_kernel_config CONFIG_NF_DUP_NETDEV m + set_kernel_config CONFIG_NF_LOG_BRIDGE m + set_kernel_config CONFIG_NF_LOG_IPV4 m + set_kernel_config CONFIG_NF_LOG_IPV6 m + set_kernel_config CONFIG_NF_NAT_IPV4 m + set_kernel_config CONFIG_NF_NAT_IPV6 m + set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m + set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m + set_kernel_config CONFIG_NF_NAT_PPTP m + set_kernel_config CONFIG_NF_NAT_PROTO_GRE m + set_kernel_config CONFIG_NF_NAT_REDIRECT m + set_kernel_config CONFIG_NF_NAT_SIP m + set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m + set_kernel_config CONFIG_NF_NAT_TFTP m + set_kernel_config CONFIG_NF_REJECT_IPV4 m + set_kernel_config CONFIG_NF_REJECT_IPV6 m + set_kernel_config CONFIG_NF_TABLES m + set_kernel_config CONFIG_NF_TABLES_ARP m + set_kernel_config CONFIG_NF_TABLES_BRIDGE m + set_kernel_config CONFIG_NF_TABLES_INET m + set_kernel_config CONFIG_NF_TABLES_IPV4 m + set_kernel_config CONFIG_NF_TABLES_IPV6 m + set_kernel_config CONFIG_NF_TABLES_NETDEV m + fi + + # Enables BPF syscall for systemd-journald see https://github.com/torvalds/linux/blob/master/init/Kconfig#L848 or https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA + if [ "$KERNEL_BPF" = true ] ; then + set_kernel_config CONFIG_BPF_SYSCALL y + set_kernel_config CONFIG_BPF_EVENTS y + set_kernel_config CONFIG_BPF_STREAM_PARSER y + set_kernel_config CONFIG_CGROUP_BPF y + fi + + # KERNEL_DEFAULT_GOV was set by user + if [ "$KERNEL_DEFAULT_GOV" != powersave ] && [ -n "$KERNEL_DEFAULT_GOV" ] ; then + + case "$KERNEL_DEFAULT_GOV" in + performance) + set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE y + ;; + userspace) + set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE y + ;; + ondemand) + set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND y + ;; + conservative) + set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE y + ;; + shedutil) + set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL y + ;; + *) + echo "error: unsupported default cpu governor" + exit 1 + ;; + esac + + # unset previous default governor + unset_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE + fi + + #Revert to previous directory + cd "${WORKDIR}" || exit + + # Set kernel configuration parameters to enable qemu emulation + if [ "$ENABLE_QEMU" = true ] ; then + echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config + echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config + + if [ "$ENABLE_CRYPTFS" = true ] ; then + { + echo "CONFIG_EMBEDDED=y" + echo "CONFIG_EXPERT=y" + echo "CONFIG_DAX=y" + echo "CONFIG_MD=y" + echo "CONFIG_BLK_DEV_MD=y" + echo "CONFIG_MD_AUTODETECT=y" + echo "CONFIG_BLK_DEV_DM=y" + echo "CONFIG_BLK_DEV_DM_BUILTIN=y" + echo "CONFIG_DM_CRYPT=y" + echo "CONFIG_CRYPTO_BLKCIPHER=y" + echo "CONFIG_CRYPTO_CBC=y" + echo "CONFIG_CRYPTO_XTS=y" + echo "CONFIG_CRYPTO_SHA512=y" + echo "CONFIG_CRYPTO_MANAGER=y" + } >> "${KERNEL_DIR}"/.config + fi + fi + + # Copy custom kernel configuration file + if [ -n "$KERNELSRC_USRCONFIG" ] ; then + cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config + fi + + # Set kernel configuration parameters to their default values + if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then + make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig fi # Start menu-driven kernel configuration (interactive) if [ "$KERNEL_MENUCONFIG" = true ] ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig fi + # end if "$KERNELSRC_CONFIG" = true fi - # Cross compile kernel and modules - make -C "${KERNEL_DIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_BIN_IMAGE}" modules dtbs + # Use ccache to cross compile the kernel + if [ "$KERNEL_CCACHE" = true ] ; then + cc="ccache ${CROSS_COMPILE}gcc" + else + cc="${CROSS_COMPILE}gcc" + fi + + # Cross compile kernel and dtbs + 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 -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 + # end if "$KERNELSRC_PREBUILT" = false fi # Check if kernel compilation was successful @@ -110,12 +453,16 @@ if [ "$BUILD_KERNEL" = true ] ; then # Install kernel modules if [ "$ENABLE_REDUCE" = true ] ; then - make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install + 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 - make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install + 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 [ $(cat ./Makefile | grep "^firmware_install:") ] ; 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 @@ -129,23 +476,41 @@ if [ "$BUILD_KERNEL" = true ] ; then mkdir "${BOOT_DIR}" # Get kernel release version - KERNEL_VERSION=`cat "${KERNEL_DIR}/include/config/kernel.release"` + KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release") # Copy kernel configuration file to the boot directory install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" - # Copy dts and dtb device tree sources and binaries + # Prepare device tree directory mkdir "${BOOT_DIR}/overlays" - + # Ensure the proper .dtb is located if [ "$KERNEL_ARCH" = "arm" ] ; then - install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOT_DIR}/" + for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do + if [ -f "${dtb}" ] ; then + install_readonly "${dtb}" "${BOOT_DIR}/" + fi + done else - install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb "${BOOT_DIR}/" + for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do + if [ -f "${dtb}" ] ; then + install_readonly "${dtb}" "${BOOT_DIR}/" + fi + done fi - install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOT_DIR}/overlays/" - install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" + # Copy compiled dtb device tree files + if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then + for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtbo ; do + if [ -f "${dtb}" ] ; then + install_readonly "${dtb}" "${BOOT_DIR}/overlays/" + fi + done + + if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then + install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" + fi + fi if [ "$ENABLE_UBOOT" = false ] ; then # Convert and copy kernel image to the boot directory @@ -159,27 +524,92 @@ if [ "$BUILD_KERNEL" = true ] ; then if [ "$KERNEL_REMOVESRC" = true ] ; then rm -fr "${KERNEL_DIR}" else - make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare + # Prepare compiled kernel modules + 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 - # Create symlinks for kernel modules - chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build" - chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source" + # Create symlinks for kernel modules + chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build" + chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source" + fi fi else # BUILD_KERNEL=false - # Kernel installation - chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel + if [ "$SET_ARCH" = 64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then + + # Use Sakakis modified kernel if ZSWAP is active + if [ "$KERNEL_ZSWAP" = true ] || [ "$KERNEL_VIRT" = true ] || [ "$KERNEL_NF" = true ] || [ "$KERNEL_BPF" = true ] ; then + RPI3_64_KERNEL_URL="${RPI3_64_BIS_KERNEL_URL}" + fi + + # Create temporary directory for dl + temp_dir=$(as_nobody mktemp -d) + + # Fetch kernel dl + as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL" + + #extract download + tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}" - # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot - chroot_exec apt-get -qq -y install flash-kernel + #move extracted kernel to /boot/firmware + mkdir "${R}/boot/firmware" + cp "${temp_dir}"/boot/* "${R}"/boot/firmware/ + cp -r "${temp_dir}"/lib/* "${R}"/lib/ + + # Remove temporary directory for kernel sources + rm -fr "${temp_dir}" + + # Set permissions of the kernel sources + chown -R root:root "${R}/boot/firmware" + chown -R root:root "${R}/lib/modules" + fi + + # Install Kernel from hypriot comptabile with all Raspberry PI + if [ "$SET_ARCH" = 32 ] ; then + # Create temporary directory for dl + temp_dir=$(as_nobody mktemp -d) + + # Fetch kernel + as_nobody wget -O "${temp_dir}"/kernel.deb -c "$RPI_32_KERNEL_URL" + + # Copy downloaded U-Boot sources + mv "${temp_dir}"/kernel.deb "${R}"/tmp/kernel.deb + + # Set permissions + chown -R root:root "${R}"/tmp/kernel.deb + + # Install kernel + chroot_exec dpkg -i /tmp/kernel.deb + + # move /boot to /boot/firmware to fit script env. + #mkdir "${BOOT_DIR}" + mkdir "${temp_dir}"/firmware + mv "${R}"/boot/* "${temp_dir}"/firmware/ + mv "${temp_dir}"/firmware "${R}"/boot/ + + #same for kernel headers + if [ "$KERNEL_HEADERS" = true ] ; then + # Fetch kernel header + as_nobody wget -O "${temp_dir}"/kernel-header.deb -c "$RPI_32_KERNELHEADER_URL" + mv "${temp_dir}"/kernel-header.deb "${R}"/tmp/kernel-header.deb + chown -R root:root "${R}"/tmp/kernel-header.deb + # Install kernel header + chroot_exec dpkg -i /tmp/kernel-header.deb + rm -f "${R}"/tmp/kernel-header.deb + fi + + # Remove temporary directory and files + rm -fr "${temp_dir}" + rm -f "${R}"/tmp/kernel.deb + fi # Check if kernel installation was successful - VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)" - if [ -z "$VMLINUZ" ] ; then - echo "error: kernel installation failed! (/boot/vmlinuz-* not found)" + KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)" + if [ -z "$KERNEL" ] ; then + echo "error: kernel installation failed! (/boot/kernel* not found)" cleanup exit 1 fi - # Copy vmlinuz kernel to the boot directory - install_readonly "${VMLINUZ}" "${BOOT_DIR}/${KERNEL_IMAGE}" fi diff --git a/bootstrap.d/14-fstab.sh b/bootstrap.d/14-fstab.sh index c9c3ce3..c9e018b 100644 --- a/bootstrap.d/14-fstab.sh +++ b/bootstrap.d/14-fstab.sh @@ -20,16 +20,24 @@ if [ "$ENABLE_CRYPTFS" = true ] ; then # Add encrypted partition to crypttab and fstab install_readonly files/mount/crypttab "${ETC_DIR}/crypttab" - echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETC_DIR}/crypttab" + echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab" if [ "$ENABLE_SPLITFS" = true ] ; then - # Add usb/sda disk to crypttab + # Add usb/sda1 disk to crypttab sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab" fi fi +if [ "$ENABLE_USBBOOT" = true ] ; then + sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab" + sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab" + + # Add usb/sda2 disk to crypttab + sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab" +fi + # Generate initramfs file -if [ "$BUILD_KERNEL" = true ] && [ "$ENABLE_INITRAMFS" = true ] ; then +if [ "$ENABLE_INITRAMFS" = true ] ; then if [ "$ENABLE_CRYPTFS" = true ] ; then # Include initramfs scripts to auto expand encrypted root partition if [ "$EXPANDROOT" = true ] ; then @@ -37,12 +45,64 @@ if [ "$BUILD_KERNEL" = true ] && [ "$ENABLE_INITRAMFS" = true ] ; then install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount" install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools" fi + + if [ "$ENABLE_DHCP" = false ] ; then + # Get cdir from NET_ADDRESS e.g. 24 + cdir=$(${NET_ADDRESS} | cut -d '/' -f2) + + # Convert cdir ro netmask e.g. 24 to 255.255.255.0 + NET_MASK=$(cdr2mask "$cdir") + + # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf + sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf + + # Regenerate initramfs + chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" + fi + + if [ "$CRYPTFS_DROPBEAR" = true ]; then + if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then + install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub + cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys + else + # Create key + chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear + + # Convert dropbear key to openssh key + chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa + + # Get Public Key Part + chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub + + # Delete unwanted lines + sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub + sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub + + # Trust the new key + cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys + + # Save Keys - convert with putty from rsa/openssh to puttkey + cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa + + # Get unlock script + install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh + + # Enable Dropbear inside initramfs + printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" + + # Enable Dropbear inside initramfs + sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear + fi + else + # Disable SSHD inside initramfs + printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" + fi - # Disable SSHD inside initramfs - printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" + # Add cryptsetup modules to initramfs + printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook" # Dummy mapping required by mkinitramfs - echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" + echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" # Generate initramfs with encrypted root partition support chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" diff --git a/bootstrap.d/15-rpi-config.sh b/bootstrap.d/15-rpi-config.sh index 6979b04..b7a8684 100644 --- a/bootstrap.d/15-rpi-config.sh +++ b/bootstrap.d/15-rpi-config.sh @@ -5,62 +5,76 @@ # Load utility functions . ./functions.sh -if [ "$BUILD_KERNEL" = true ] ; then - if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then - # Install boot binaries from local directory - cp ${RPI_FIRMWARE_DIR}/boot/bootcode.bin ${BOOT_DIR}/bootcode.bin - cp ${RPI_FIRMWARE_DIR}/boot/fixup.dat ${BOOT_DIR}/fixup.dat - cp ${RPI_FIRMWARE_DIR}/boot/fixup_cd.dat ${BOOT_DIR}/fixup_cd.dat - cp ${RPI_FIRMWARE_DIR}/boot/fixup_x.dat ${BOOT_DIR}/fixup_x.dat - cp ${RPI_FIRMWARE_DIR}/boot/start.elf ${BOOT_DIR}/start.elf - cp ${RPI_FIRMWARE_DIR}/boot/start_cd.elf ${BOOT_DIR}/start_cd.elf - cp ${RPI_FIRMWARE_DIR}/boot/start_x.elf ${BOOT_DIR}/start_x.elf - else - # Create temporary directory for boot binaries - temp_dir=$(as_nobody mktemp -d) +if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then + # Install boot binaries from local directory + cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin + cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat + cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat + cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat + cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf + cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf + cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf +else + # Create temporary directory for boot binaries + temp_dir=$(as_nobody mktemp -d) - # Install latest boot binaries from raspberry/firmware github - as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin" - as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat" - as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat" - as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat" - as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf" - as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf" - as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf" + # Install latest boot binaries from raspberry/firmware github + as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin" + as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat" + as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat" + as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat" + as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf" + as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf" + as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf" - # Move downloaded boot binaries - mv "${temp_dir}/"* "${BOOT_DIR}/" + # Move downloaded boot binaries + mv "${temp_dir}/"* "${BOOT_DIR}/" - # Remove temporary directory for boot binaries - rm -fr "${temp_dir}" + # Remove temporary directory for boot binaries + rm -fr "${temp_dir}" - # Set permissions of the boot binaries - chown -R root:root "${BOOT_DIR}" - chmod -R 600 "${BOOT_DIR}" - fi + # Set permissions of the boot binaries + chown -R root:root "${BOOT_DIR}" + chmod -R 600 "${BOOT_DIR}" fi # Setup firmware boot cmdline -if [ "$ENABLE_SPLITFS" = true ] ; then - CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1" +if [ "$ENABLE_USBBOOT" = true ] ; then + CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd" else - CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1" + if [ "$ENABLE_SPLITFS" = true ] ; then + CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd" + else + CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline console=tty1 rootwait init=/bin/systemd" + fi fi # Add encrypted root partition to cmdline.txt if [ "$ENABLE_CRYPTFS" = true ] ; then if [ "$ENABLE_SPLITFS" = true ] ; then - CMDLINE=$(echo ${CMDLINE} | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/") + CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/") else - CMDLINE=$(echo ${CMDLINE} | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/") + if [ "$ENABLE_USBBOOT" = true ] ; then + CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/") + else + CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/") + fi fi fi -# Add serial console support -if [ "$ENABLE_CONSOLE" = true ] ; then - CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" +# Enable Kernel messages on standard output +if [ "$ENABLE_PRINTK" = true ] ; then + install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf" +fi + +# Enable Kernel messages on standard output +if [ "$KERNEL_SECURITY" = true ] ; then + install_readonly files/sysctl.d/84-rpi-ASLR.conf "${ETC_DIR}/sysctl.d/84-rpi-ASLR.conf" fi +# Install udev rule for serial alias - serial0 = console serial1=bluetooth +install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules" + # Remove IPv6 networking support if [ "$ENABLE_IPV6" = false ] ; then CMDLINE="${CMDLINE} ipv6.disable=1" @@ -73,17 +87,160 @@ else CMDLINE="${CMDLINE} net.ifnames=1" fi -# Set init to systemd if required by Debian release -if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then - CMDLINE="${CMDLINE} init=/bin/systemd" +# Disable Raspberry Pi console logo +if [ "$ENABLE_LOGO" = false ] ; then + CMDLINE="${CMDLINE} logo.nologo" fi -# Install firmware boot cmdline -echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt" +# Strictly limit verbosity of boot up console messages +if [ "$ENABLE_SILENT_BOOT" = true ] ; then + CMDLINE="${CMDLINE} quiet loglevel=0 rd.systemd.show_status=auto rd.udev.log_priority=0" +fi # Install firmware config install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt" +# Disable Raspberry Pi console logo +if [ "$ENABLE_SLASH" = false ] ; then + echo "disable_splash=1" >> "${BOOT_DIR}/config.txt" +fi + +# Locks CPU frequency at maximum +if [ "$ENABLE_TURBO" = true ] ; then + echo "force_turbo=1" >> "${BOOT_DIR}/config.txt" + # helps to avoid sdcard corruption when force_turbo is enabled. + echo "boot_delay=1" >> "${BOOT_DIR}/config.txt" +fi + +if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then + + # 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://raw.githubusercontent.com/RPi-Distro/bluez-firmware/master/broadcom/BCM43430A1.hcd + + # 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" + + # make scripts executable + chmod +x "${R}/usr/bin/bthelper" + chmod +x "${R}/usr/bin/btuart" + + # 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}/BCM43430A1.hcd" + 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 directories + rm -fr "${temp_dir}" + rm -fr "${R}"/tmp/pi-bluetooth + + # 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 overlay to swap ttyAMA0 and ttyS0 + echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt" + + if [ "$ENABLE_TURBO" = false ] ; then + echo "core_freq=250" >> "${BOOT_DIR}/config.txt" + fi + + fi + + # Activate services + chroot_exec systemctl enable pi-bluetooth.hciuart.service + + else # if ENABLE_BLUETOOTH = false + # set overlay to disable bluetooth + echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt" + fi # ENABLE_BLUETOOTH end +fi + +# may need sudo systemctl disable hciuart +if [ "$ENABLE_CONSOLE" = true ] ; then + echo "enable_uart=1" >> "${BOOT_DIR}/config.txt" + # add string to cmdline + CMDLINE="${CMDLINE} console=serial0,115200" + + if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]|| [ "$RPI_MODEL" = 0 ]; then + # 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 + fi + + # Enable serial console systemd style + chroot_exec systemctl enable serial-getty@serial0.service +else + echo "enable_uart=0" >> "${BOOT_DIR}/config.txt" +fi + +# Disable dphys-swapfile service. Will get enabled on first boot +if [ "$ENABLE_DPHYSSWAP" = true ] ; then + chroot_exec systemctl disable dphys-swapfile +fi + +if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then + # Create temporary directory for systemd-swap sources + temp_dir=$(as_nobody mktemp -d) + + # Fetch systemd-swap sources + as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}" + + # Copy downloaded systemd-swap sources + mv "${temp_dir}/systemd-swap" "${R}/tmp/" + + # Change into downloaded src dir + cd "${R}/tmp/systemd-swap" || exit + + # Build package + bash ./package.sh debian + + # Change back into script root dir + cd "${WORKDIR}" || exit + + # Set permissions of the systemd-swap sources + chown -R root:root "${R}/tmp/systemd-swap" + + # Install package - IMPROVE AND MAKE IT POSSIBLE WITHOUT VERSION NR. + chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap_4.0.1_any.deb + + # Enable service + chroot_exec systemctl enable systemd-swap + + # Remove temporary directory for systemd-swap sources + rm -fr "${temp_dir}" +else + # Enable ZSWAP in cmdline if systemd-swap is not used + if [ "$KERNEL_ZSWAP" = true ] ; then + CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4" + fi +fi + if [ "$KERNEL_SECURITY" = true ] ; then + CMDLINE="${CMDLINE} apparmor=1 security=apparmor" + fi + +# Install firmware boot cmdline +echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt" + # Setup minimal GPU memory allocation size: 16MB (no X) if [ "$ENABLE_MINGPU" = true ] ; then echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt" @@ -94,30 +251,22 @@ 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 ] ; 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 - # Create firmware configuration and cmdline symlinks ln -sf firmware/config.txt "${R}/boot/config.txt" ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt" # Install and setup kernel modules to load at boot -mkdir -p "${R}/lib/modules-load.d/" -install_readonly files/modules/rpi2.conf "${R}/lib/modules-load.d/rpi2.conf" +mkdir -p "${LIB_DIR}/modules-load.d/" +install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf" # Load hardware random module at boot if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then - sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${R}/lib/modules-load.d/rpi2.conf" + sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf" fi # Load sound module at boot if [ "$ENABLE_SOUND" = true ] ; then - sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${R}/lib/modules-load.d/rpi2.conf" + sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" else echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt" fi @@ -125,21 +274,21 @@ fi # Enable I2C interface if [ "$ENABLE_I2C" = true ] ; then echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt" - sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${R}/lib/modules-load.d/rpi2.conf" - sed -i "s/^# i2c-dev/i2c-dev/" "${R}/lib/modules-load.d/rpi2.conf" + sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf" + sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf" fi # Enable SPI interface if [ "$ENABLE_SPI" = true ] ; then echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt" - echo "spi-bcm2708" >> "${R}/lib/modules-load.d/rpi2.conf" - if [ "$RPI_MODEL" = 3 ] ; then - sed -i "s/spi-bcm2708/spi-bcm2835/" "${R}/lib/modules-load.d/rpi2.conf" + echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf" + if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then + sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" fi fi # Disable RPi2/3 under-voltage warnings -if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then +if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt" fi diff --git a/bootstrap.d/20-networking.sh b/bootstrap.d/20-networking.sh index 2229d72..f80f006 100644 --- a/bootstrap.d/20-networking.sh +++ b/bootstrap.d/20-networking.sh @@ -7,11 +7,11 @@ # Install and setup hostname install_readonly files/network/hostname "${ETC_DIR}/hostname" -sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETC_DIR}/hostname" +sed -i "s/^RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hostname" # Install and setup hosts install_readonly files/network/hosts "${ETC_DIR}/hosts" -sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETC_DIR}/hosts" +sed -i "s/RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hosts" # Setup hostname entry with static IP if [ "$NET_ADDRESS" != "" ] ; then @@ -30,10 +30,20 @@ install_readonly files/network/interfaces "${ETC_DIR}/network/interfaces" # Install configuration for interface eth0 install_readonly files/network/eth.network "${ETC_DIR}/systemd/network/eth.network" +if [ "$RPI_MODEL" = 3P ] ; then +printf "\n[Link]\nGenericReceiveOffload=off\nTCPSegmentationOffload=off\nGenericSegmentationOffload=off" >> "${ETC_DIR}/systemd/network/eth.network" +fi + +# Install configuration for interface wl* +install_readonly files/network/wlan.network "${ETC_DIR}/systemd/network/wlan.network" + +#always with dhcp since wpa_supplicant integration is missing +sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan.network" + if [ "$ENABLE_DHCP" = true ] ; then # Enable DHCP configuration for interface eth0 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/eth.network" - + # Set DHCP configuration to IPv4 only if [ "$ENABLE_IPV6" = false ] ; then sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/eth.network" @@ -55,12 +65,16 @@ fi # Remove empty settings from network configuration sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/eth.network" +# Remove empty settings from wlan configuration +sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/wlan.network" # Move systemd network configuration if required by Debian release -if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then - mv -v "${ETC_DIR}/systemd/network/eth.network" "${LIB_DIR}/systemd/network/10-eth.network" - rm -fr "${ETC_DIR}/systemd/network" +mv -v "${ETC_DIR}/systemd/network/eth.network" "${LIB_DIR}/systemd/network/10-eth.network" +# If WLAN is enabled copy wlan configuration too +if [ "$ENABLE_WIRELESS" = true ] ; then + mv -v "${ETC_DIR}/systemd/network/wlan.network" "${LIB_DIR}/systemd/network/11-wlan.network" fi +rm -fr "${ETC_DIR}/systemd/network" # Enable systemd-networkd service chroot_exec systemctl enable systemd-networkd @@ -78,30 +92,45 @@ if [ "$ENABLE_HARDNET" = true ] ; then fi # Enable time sync -if [ "NET_NTP_1" != "" ] ; then +if [ "$NET_NTP_1" != "" ] ; then chroot_exec systemctl enable systemd-timesyncd.service fi # Download the firmware binary blob required to use the RPi3 wireless interface if [ "$ENABLE_WIRELESS" = true ] ; then - if [ ! -d ${WLAN_FIRMWARE_DIR} ] ; then - mkdir -p ${WLAN_FIRMWARE_DIR} + if [ ! -d "${WLAN_FIRMWARE_DIR}" ] ; then + mkdir -p "${WLAN_FIRMWARE_DIR}" fi # Create temporary directory for firmware binary blob temp_dir=$(as_nobody mktemp -d) - # Fetch firmware binary blob - 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" - - # Move downloaded firmware binary blob - mv "${temp_dir}/brcmfmac43430-sdio."* "${WLAN_FIRMWARE_DIR}/" - + # Fetch firmware binary blob for RPI3B+ + if [ "$RPI_MODEL" = 3P ] ; then + # Fetch firmware binary blob for RPi3P + 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" + + # 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 - chown root:root "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* - chmod 600 "${WLAN_FIRMWARE_DIR}/brcmfmac43430-sdio."* fi diff --git a/bootstrap.d/21-firewall.sh b/bootstrap.d/21-firewall.sh index cf36c99..ee9831d 100644 --- a/bootstrap.d/21-firewall.sh +++ b/bootstrap.d/21-firewall.sh @@ -8,7 +8,12 @@ if [ "$ENABLE_IPTABLES" = true ] ; then # Create iptables configuration directory mkdir -p "${ETC_DIR}/iptables" - + + if [ "$KERNEL_NF" = false ] ; then + # iptables-save and -restore are slaves of iptables and thus are set accordingly + chroot_exec update-alternatives --verbose --set iptables /usr/sbin/iptables-legacy + fi + # Install iptables systemd service install_readonly files/iptables/iptables.service "${ETC_DIR}/systemd/system/iptables.service" @@ -23,6 +28,11 @@ if [ "$ENABLE_IPTABLES" = true ] ; then chroot_exec systemctl enable iptables.service if [ "$ENABLE_IPV6" = true ] ; then + if [ "$KERNEL_NF" = false ] ; then + # iptables-save and -restore are slaves of iptables and thus are set accordingly + chroot_exec update-alternatives --verbose --set ip6tables /usr/sbin/ip6tables-legacy + fi + # Install ip6tables systemd service install_readonly files/iptables/ip6tables.service "${ETC_DIR}/systemd/system/ip6tables.service" diff --git a/bootstrap.d/30-security.sh b/bootstrap.d/30-security.sh index 8b0e464..75e3625 100644 --- a/bootstrap.d/30-security.sh +++ b/bootstrap.d/30-security.sh @@ -6,13 +6,13 @@ . ./functions.sh # Generate crypt(3) password string -ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 "${PASSWORD}"` -ENCRYPTED_USER_PASSWORD=`mkpasswd -m sha-512 "${USER_PASSWORD}"` +ENCRYPTED_PASSWORD=$(mkpasswd -m sha-512 "${PASSWORD}") +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 @@ -22,8 +22,3 @@ else # Set no root password to disable root login chroot_exec usermod -p \'!\' root fi - -# Enable serial console systemd style -if [ "$ENABLE_CONSOLE" = true ] ; then - chroot_exec systemctl enable serial-getty\@ttyAMA0.service -fi diff --git a/bootstrap.d/32-sshd.sh b/bootstrap.d/32-sshd.sh index 162fdb2..9d28d51 100644 --- a/bootstrap.d/32-sshd.sh +++ b/bootstrap.d/32-sshd.sh @@ -28,7 +28,7 @@ if [ "$ENABLE_SSHD" = true ] ; then fi # Add SSH (v2) public key for user root - if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then + if [ -n "$SSH_ROOT_PUB_KEY" ] ; then # Create root SSH config directory mkdir -p "${R}/root/.ssh" @@ -52,20 +52,20 @@ if [ "$ENABLE_SSHD" = true ] ; then if [ "$ENABLE_USER" = true ] ; then # Add SSH (v2) public key for user $USER_NAME - if [ ! -z "$SSH_USER_PUB_KEY" ] ; then + if [ -n "$SSH_USER_PUB_KEY" ] ; then # Create $USER_NAME SSH config directory mkdir -p "${R}/home/${USER_NAME}/.ssh" # Set permissions of $USER_NAME SSH config directory chroot_exec chmod 700 "/home/${USER_NAME}/.ssh" - chroot_exec chown ${USER_NAME}:${USER_NAME} "/home/${USER_NAME}/.ssh" + chroot_exec chown "${USER_NAME}":"${USER_NAME}" "/home/${USER_NAME}/.ssh" # Add SSH (v2) public key(s) to authorized_keys file cat "$SSH_USER_PUB_KEY" >> "${R}/home/${USER_NAME}/.ssh/authorized_keys" # Set permissions of $USER_NAME SSH config directory chroot_exec chmod 600 "/home/${USER_NAME}/.ssh/authorized_keys" - chroot_exec chown ${USER_NAME}:${USER_NAME} "/home/${USER_NAME}/.ssh/authorized_keys" + chroot_exec chown "${USER_NAME}":"${USER_NAME}" "/home/${USER_NAME}/.ssh/authorized_keys" if [ "$ENABLE_REDUCE" = false ] || [ "$REDUCE_SSHD" = false ] ; then # Allow SSH public key authentication @@ -85,7 +85,7 @@ if [ "$ENABLE_SSHD" = true ] ; then allowed_users="${allowed_users} ${USER_NAME}" fi - if [ ! -z "$allowed_users" ] ; then + if [ -n "$allowed_users" ] ; then echo "AllowUsers ${allowed_users}" >> "${ETC_DIR}/ssh/sshd_config" fi fi @@ -113,4 +113,4 @@ if [ "$ENABLE_SSHD" = true ] ; then if [ "$ENABLE_REDUCE" = true ] && [ "$REDUCE_SSHD" = true ] ; then sed "s|^DROPBEAR_EXTRA_ARGS=.*|DROPBEAR_EXTRA_ARGS=\"${DROPBEAR_ARGS}\"|g" "${ETC_DIR}/default/dropbear" fi -fi +fi \ No newline at end of file diff --git a/bootstrap.d/41-uboot.sh b/bootstrap.d/41-uboot.sh index cd9e67b..56fca4e 100644 --- a/bootstrap.d/41-uboot.sh +++ b/bootstrap.d/41-uboot.sh @@ -32,7 +32,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then fi # Build and install U-Boot inside chroot - chroot_exec make -j${KERNEL_THREADS} -C /tmp/u-boot/ ${UBOOT_CONFIG} all + chroot_exec make -j"${KERNEL_THREADS}" -C /tmp/u-boot/ "${UBOOT_CONFIG}" all # Copy compiled bootloader binary and set config.txt to load it install_exec "${R}/tmp/u-boot/tools/mkimage" "${R}/usr/sbin/mkimage" @@ -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 @@ -66,11 +66,33 @@ if [ "$ENABLE_UBOOT" = true ] ; then fi fi + 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 + + # instead of sd, boot from usb device + if [ "$ENABLE_USBBOOT" = true ] ; then + sed -i "s|mmc|usb|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 + sed -i "s/^\(setenv machid \).*/\10x000008e0/" "${BOOT_DIR}/uboot.mkimage" + 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/42-fbturbo.sh b/bootstrap.d/42-fbturbo.sh index 7c307af..9291326 100644 --- a/bootstrap.d/42-fbturbo.sh +++ b/bootstrap.d/42-fbturbo.sh @@ -28,12 +28,14 @@ if [ "$ENABLE_FBTURBO" = true ] ; then fi # Install Xorg build dependencies + if [ "$RELEASE" = "jessie" ] || [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then chroot_exec apt-get -q -y --no-install-recommends install xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev elif [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then chroot_exec apt-get -q -y --no-install-recommends --allow-unauthenticated install xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev fi + # Build and install fbturbo driver inside chroot chroot_exec /bin/bash -x <<'EOF' cd /tmp/xf86-video-fbturbo diff --git a/bootstrap.d/43-videocore.sh b/bootstrap.d/43-videocore.sh new file mode 100644 index 0000000..344965c --- /dev/null +++ b/bootstrap.d/43-videocore.sh @@ -0,0 +1,56 @@ +# +# Setup videocore - Raspberry Userland +# + +# Load utility functions +. ./functions.sh + +if [ "$ENABLE_VIDEOCORE" = true ] ; then + # Copy existing videocore sources into chroot directory + if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then + # Copy local videocore sources + cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp/userland" + else + # Create temporary directory for videocore sources + temp_dir=$(as_nobody mktemp -d) + + # Fetch videocore sources + as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}" + + # Copy downloaded videocore sources + mv "${temp_dir}/userland" "${R}/tmp/" + + # Set permissions of the U-Boot sources + chown -R root:root "${R}/tmp/userland" + + # Remove temporary directory for U-Boot sources + rm -fr "${temp_dir}" + fi + + # Create build dir + mkdir "${R}"/tmp/userland/build + + # push us to build directory + 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" + fi + + if [ "$RELEASE_ARCH" = "armel" ] ; then + cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DCMAKE_ASM_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DCMAKE_SYSTEM_PROCESSOR="arm" -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" + fi + + if [ "$RELEASE_ARCH" = "armhf" ] ; then + cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_TOOLCHAIN_FILE="${R}"/tmp/userland/makefiles/cmake/toolchains/arm-linux-gnueabihf.cmake -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" + fi + + #build userland + make -j "$(nproc)" + + #back to root of scriptdir + cd "${WORKDIR}" + + # Remove videocore sources + rm -fr "${R}"/tmp/userland/ +fi diff --git a/bootstrap.d/44-nexmon_monitor_patch.sh b/bootstrap.d/44-nexmon_monitor_patch.sh new file mode 100644 index 0000000..5a260a2 --- /dev/null +++ b/bootstrap.d/44-nexmon_monitor_patch.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# +# Build and Setup nexmon with monitor mode patch +# + +# Load utility functions +. ./functions.sh + +if [ "$ENABLE_NEXMON" = true ] && [ "$ENABLE_WIRELESS" = true ]; then + # Copy existing nexmon sources into chroot directory + if [ -n "$NEXMONSRC_DIR" ] && [ -d "$NEXMONSRC_DIR" ] ; then + # Copy local U-Boot sources + cp -r "${NEXMONSRC_DIR}" "${R}/tmp" + else + # Create temporary directory for nexmon sources + temp_dir=$(as_nobody mktemp -d) + + # Fetch nexmon sources + as_nobody git -C "${temp_dir}" clone "${NEXMON_URL}" + + # Copy downloaded nexmon sources + mv "${temp_dir}/nexmon" "${R}"/tmp/ + + # Set permissions of the nexmon sources + chown -R root:root "${R}"/tmp/nexmon + + # Remove temporary directory for nexmon sources + rm -fr "${temp_dir}" + fi + + # Set script Root + export NEXMON_ROOT="${R}"/tmp/nexmon + + # Build nexmon firmware outside the build system, if we can. + cd "${NEXMON_ROOT}" || exit + + # Make ancient isl build + cd buildtools/isl-0.10 || exit + ./configure + make + cd ../.. || exit + + # Disable statistics + touch DISABLE_STATISTICS + + # Setup Enviroment: see https://github.com/NoobieDog/nexmon/blob/master/setup_env.sh + export KERNEL="${KERNEL_IMAGE}" + export ARCH=arm + export SUBARCH=arm + export CC="${NEXMON_ROOT}"/buildtools/gcc-arm-none-eabi-5_4-2016q2-linux-x86/bin/arm-none-eabi- + export CC="${CC}"gcc + export CCPLUGIN="${NEXMON_ROOT}"/buildtools/gcc-nexmon-plugin/nexmon.so + export ZLIBFLATE="zlib-flate -compress" + export Q=@ + export NEXMON_SETUP_ENV=1 + export HOSTUNAME=$(uname -s) + export PLATFORMUNAME=$(uname -m) + + # Make nexmon + make + + # build patches + if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] ; then + cd "${NEXMON_ROOT}"/patches/bcm43430a1/7_45_41_46/nexmon || exit + sed -i -e 's/all:.*/all: $(RAM_FILE)/g' ${NEXMON_ROOT}/patches/bcm43430a1/7_45_41_46/nexmon/Makefile + make clean + + # We do this so we don't have to install the ancient isl version into /usr/local/lib on systems. + LD_LIBRARY_PATH="${NEXMON_ROOT}"/buildtools/isl-0.10/.libs make ARCH="${KERNEL_ARCH}" CC="${NEXMON_ROOT}"/buildtools/gcc-arm-none-eabi-5_4-2016q2-linux-x86/bin/arm-none-eabi- + + # copy RPi0W & RPi3 firmware + mv "${WLAN_FIRMWARE_DIR}"/brcmfmac43430-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43430-sdio.org.bin + cp "${NEXMON_ROOT}"/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43430-sdio.nexmon.bin + cp -f "${NEXMON_ROOT}"/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43430-sdio.bin + fi + + if [ "$RPI_MODEL" = 3P ] ; then + cd "${NEXMON_ROOT}"/patches/bcm43455c0/7_45_154/nexmon || exit + sed -i -e 's/all:.*/all: $(RAM_FILE)/g' ${NEXMON_ROOT}/patches/bcm43455c0/7_45_154/nexmon/Makefile + make clean + + # We do this so we don't have to install the ancient isl version into /usr/local/lib on systems. + LD_LIBRARY_PATH=${NEXMON_ROOT}/buildtools/isl-0.10/.libs make ARCH="${KERNEL_ARCH}" CC="${NEXMON_ROOT}"/buildtools/gcc-arm-none-eabi-5_4-2016q2-linux-x86/bin/arm-none-eabi- + + # RPi3B+ firmware + mv "${WLAN_FIRMWARE_DIR}"/brcmfmac43455-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43455-sdio.org.bin + cp "${NEXMON_ROOT}"/patches/bcm43455c0/7_45_154/nexmon/brcmfmac43455-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43455-sdio.nexmon.bin + cp -f "${NEXMON_ROOT}"/patches/bcm43455c0/7_45_154/nexmon/brcmfmac43455-sdio.bin "${WLAN_FIRMWARE_DIR}"/brcmfmac43455-sdio.bin + fi + +#Revert to previous directory +cd "${WORKDIR}" || exit + +# Remove nexmon sources +rm -fr "${NEXMON_ROOT}" + +fi diff --git a/bootstrap.d/50-firstboot.sh b/bootstrap.d/50-firstboot.sh index cc76f34..1b17876 100644 --- a/bootstrap.d/50-firstboot.sh +++ b/bootstrap.d/50-firstboot.sh @@ -8,30 +8,35 @@ # Prepare rc.firstboot script cat files/firstboot/10-begin.sh > "${ETC_DIR}/rc.firstboot" -# Ensure openssh server host keys are regenerated on first boot -if [ "$ENABLE_SSHD" = true ] ; then - cat files/firstboot/21-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot" -fi - # Prepare filesystem auto expand if [ "$EXPANDROOT" = true ] ; then if [ "$ENABLE_CRYPTFS" = false ] ; then - cat files/firstboot/22-expandroot.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/20-expandroot.sh >> "${ETC_DIR}/rc.firstboot" else # Regenerate initramfs to remove encrypted root partition auto expand - cat files/firstboot/23-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/21-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" + fi + + # Restart dphys-swapfile so the size of the swap file is relative to the resized root partition + if [ "$ENABLE_DPHYSSWAP" = true ] ; then + cat files/firstboot/23-restart-dphys-swapfile.sh >> "${ETC_DIR}/rc.firstboot" fi fi +# Ensure openssh server host keys are regenerated on first boot +if [ "$ENABLE_SSHD" = true ] ; then + cat files/firstboot/30-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot" +fi + # Ensure that dbus machine-id exists -cat files/firstboot/24-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot" +cat files/firstboot/40-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot" # Create /etc/resolv.conf symlink -cat files/firstboot/25-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot" +cat files/firstboot/41-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot" # Configure automatic network interface names if [ "$ENABLE_IFNAMES" = true ] ; then - cat files/firstboot/26-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/42-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot" fi # Finalize rc.firstboot script diff --git a/bootstrap.d/99-reduce.sh b/bootstrap.d/99-reduce.sh index c339e0d..9576bd6 100644 --- a/bootstrap.d/99-reduce.sh +++ b/bootstrap.d/99-reduce.sh @@ -25,8 +25,8 @@ if [ "$ENABLE_REDUCE" = true ] ; then # Remove all doc files if [ "$REDUCE_DOC" = true ] ; then - find "${R}/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true - find "${R}/usr/share/doc" -empty | xargs rmdir || true + find "${R}/usr/share/doc" -depth -type f ! -name copyright -print0 | xargs -0 rm || true + find "${R}/usr/share/doc" -empty -print0 | xargs -0 rmdir || true fi # Remove all man pages and info files @@ -36,7 +36,7 @@ if [ "$ENABLE_REDUCE" = true ] ; then # Remove all locale translation files if [ "$REDUCE_LOCALE" = true ] ; then - find "${R}/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r + find "${R}/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' -print0 | xargs -0 rm -r fi # Remove hwdb PCI device classes (experimental) @@ -46,12 +46,8 @@ if [ "$ENABLE_REDUCE" = true ] ; then # Replace bash shell by dash shell (experimental) if [ "$REDUCE_BASH" = true ] ; then - if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then - echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --allow-remove-essential bash - else - echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --force-yes bash - fi - + # Purge bash and update alternatives + echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --allow-remove-essential bash chroot_exec update-alternatives --install /bin/bash bash /bin/dash 100 fi @@ -60,11 +56,6 @@ if [ "$ENABLE_REDUCE" = true ] ; then chroot_exec apt-get -qq -y purge alsa-utils libsamplerate0 libasound2 libasound2-data fi - # Re-install tools for managing kernel modules - if [ "$RELEASE" = "jessie" ] ; then - chroot_exec apt-get -qq -y install module-init-tools - fi - # Remove GPU kernels if [ "$ENABLE_MINGPU" = true ] ; then rm -f "${BOOT_DIR}/start.elf" diff --git a/files/apt/flash-kernel b/files/apt/flash-kernel deleted file mode 100644 index 579e562..0000000 --- a/files/apt/flash-kernel +++ /dev/null @@ -1,3 +0,0 @@ -Package: flash-kernel -Pin: origin repositories.collabora.co.uk -Pin-Priority: 1000 diff --git a/files/apt/sources.list b/files/apt/sources.list index ffc2c9b..07e52dc 100644 --- a/files/apt/sources.list +++ b/files/apt/sources.list @@ -1,8 +1,8 @@ -deb http://ftp.debian.org/debian jessie main contrib -#deb-src http://ftp.debian.org/debian jessie main contrib +deb http://ftp.debian.org/debian stretch main contrib +#deb-src http://ftp.debian.org/debian stretch main contrib -deb http://ftp.debian.org/debian/ jessie-updates main contrib -#deb-src http://ftp.debian.org/debian/ jessie-updates main contrib +deb http://ftp.debian.org/debian/ stretch-updates main contrib +#deb-src http://ftp.debian.org/debian/ stretch-updates main contrib -deb http://security.debian.org/ jessie/updates main contrib -#deb-src http://security.debian.org/ jessie/updates main contrib +deb http://security.debian.org/ stretch/updates main contrib +#deb-src http://security.debian.org/ stretch/updates main contrib diff --git a/files/boot/uboot.mkimage b/files/boot/uboot.mkimage index 6ce6500..13267f6 100644 --- a/files/boot/uboot.mkimage +++ b/files/boot/uboot.mkimage @@ -8,6 +8,7 @@ setenv machid 0x00000c42 saveenv # Load the existing Linux kernel into RAM +mmc dev 0 fatload mmc 0:1 ${kernel_addr_r} kernel7.img fatload mmc 0:1 ${fdt_addr_r} ${dtbfile} fatload mmc 0:1 ${ramdisk_addr_r} ${initramfs} 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/firstboot/22-expandroot.sh b/files/firstboot/20-expandroot.sh similarity index 100% rename from files/firstboot/22-expandroot.sh rename to files/firstboot/20-expandroot.sh diff --git a/files/firstboot/23-regenerate-initramfs.sh b/files/firstboot/21-regenerate-initramfs.sh similarity index 98% rename from files/firstboot/23-regenerate-initramfs.sh rename to files/firstboot/21-regenerate-initramfs.sh index 78e2922..1c4f03c 100644 --- a/files/firstboot/23-regenerate-initramfs.sh +++ b/files/firstboot/21-regenerate-initramfs.sh @@ -8,6 +8,7 @@ INITRAMFS_UBOOT="${INITRAMFS}.uboot" # Extract kernel arch case "${KERNEL_ARCH}" in arm*) KERNEL_ARCH=arm ;; + aarch64) KERNEL_ARCH=arm64 ;; esac # Regenerate initramfs diff --git a/files/firstboot/23-restart-dphys-swapfile.sh b/files/firstboot/23-restart-dphys-swapfile.sh new file mode 100644 index 0000000..32c8638 --- /dev/null +++ b/files/firstboot/23-restart-dphys-swapfile.sh @@ -0,0 +1,5 @@ +# Restart dphys-swapfile service if it exists +logger -t "rc.firstboot" "Restarting dphys-swapfile" + +systemctl enable dphys-swapfile +systemctl restart dphys-swapfile diff --git a/files/firstboot/21-generate-ssh-keys.sh b/files/firstboot/30-generate-ssh-keys.sh similarity index 100% rename from files/firstboot/21-generate-ssh-keys.sh rename to files/firstboot/30-generate-ssh-keys.sh diff --git a/files/firstboot/24-generate-machineid.sh b/files/firstboot/40-generate-machineid.sh similarity index 100% rename from files/firstboot/24-generate-machineid.sh rename to files/firstboot/40-generate-machineid.sh diff --git a/files/firstboot/25-create-resolv-symlink.sh b/files/firstboot/41-create-resolv-symlink.sh similarity index 100% rename from files/firstboot/25-create-resolv-symlink.sh rename to files/firstboot/41-create-resolv-symlink.sh diff --git a/files/firstboot/26-config-ifnames.sh b/files/firstboot/42-config-ifnames.sh similarity index 100% rename from files/firstboot/26-config-ifnames.sh rename to files/firstboot/42-config-ifnames.sh diff --git a/files/initramfs/crypt_unlock.sh b/files/initramfs/crypt_unlock.sh new file mode 100644 index 0000000..47b6a8b --- /dev/null +++ b/files/initramfs/crypt_unlock.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +PREREQ="dropbear" + +prereqs() { +echo "$PREREQ" +} + +case "$1" in +prereqs) +prereqs +exit 0 +;; +esac + +. "${CONFDIR}/initramfs.conf" +. /usr/share/initramfs-tools/hook-functions + +if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/crypttab" ] ; then +cat > "${DESTDIR}/bin/unlock" << EOF +#!/bin/sh +if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then +kill \`ps | grep cryptroot | grep -v "grep" | awk '{print \$1}'\` +# following line kill the remote shell right after the passphrase has +# been entered. +kill -9 \`ps | grep "\-sh" | grep -v "grep" | awk '{print \$1}'\` +exit 0 +fi +exit 1 +EOF + +chmod 755 "${DESTDIR}/bin/unlock" + +mkdir -p "${DESTDIR}/lib/unlock" +cat > "${DESTDIR}/lib/unlock/plymouth" << EOF +#!/bin/sh +[ "\$1" == "--ping" ] && exit 1 +/bin/plymouth "\$@" +EOF + +chmod 755 "${DESTDIR}/lib/unlock/plymouth" + +echo To unlock root-partition run "unlock" >> ${DESTDIR}/etc/motd + +fi \ No newline at end of file diff --git a/files/initramfs/expand_encrypted_rootfs b/files/initramfs/expand_encrypted_rootfs index e6896ba..c357b1a 100644 --- a/files/initramfs/expand_encrypted_rootfs +++ b/files/initramfs/expand_encrypted_rootfs @@ -60,15 +60,23 @@ if [ -z "$PART_START" ] ; then return 1 fi +# Get the current last sector of the root partition +PART_END=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 3 -d: | sed 's/[^0-9]//g') +if [ -z "$PART_END" ] ; then + log_warning_msg "${ROOT_DEV} unable to get last sector of the partition" + return 1 +fi + # Get the possible last sector for the root partition PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }') if [ -z "$PART_LAST" ] ; then - log_warning_msg "${ROOT_DEV} unable to get last sector of the partition" + log_warning_msg "${ROOT_DEV} unable to get last possible sector of the partition" return 1 fi ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit -fdisk /dev/${ROOT_DEV} 2> /dev/null < /dev/null <> .config + fi +} + +# unset kernel config parameter +unset_kernel_config() { + # unsets flag with the value of $1, config must exist at "./.config" + TGT="CONFIG_${1#CONFIG_}" + sed -i "s/^${TGT}=.*/# ${TGT} is not set/" .config +} \ No newline at end of file diff --git a/rpi23-gen-image.sh b/rpi23-gen-image.sh index 7a0adb3..b07beb1 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -1,9 +1,8 @@ #!/bin/sh - ######################################################################## # 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 Raspberry Pi # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -31,40 +30,22 @@ fi . ./functions.sh # Load parameters from configuration template file -if [ ! -z "$CONFIG_TEMPLATE" ] ; then +if [ -n "$CONFIG_TEMPLATE" ] ; then use_template 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 RPI_MODEL=${RPI_MODEL:=2} -RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb} -RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig} -RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb} -RPI3_UBOOT_CONFIG=${RPI3_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} -else - KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} - KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} -fi -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 +RELEASE=${RELEASE:=buster} + +# Kernel Branch KERNEL_BRANCH=${KERNEL_BRANCH:=""} # URLs @@ -73,38 +54,50 @@ FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/ WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm} 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:=git://git.denx.de/u-boot.git} +UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} +VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} +BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} +NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git} +SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git} + +# Kernel deb packages for 32bit kernel +RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb} +RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb} +# Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used +RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz} +# Default precompiled 64bit kernel +RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz} +# Generic +RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL} +# Kali kernel src - used if ENABLE_NEXMON=true (they patch the wlan kernel modul) +KALI_KERNEL_URL=${KALI_KERNEL_URL:=https://github.com/Re4son/re4son-raspberrypi-linux.git} # Build directories -BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}} +WORKDIR=$(pwd) +BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}} BUILDDIR="${BASEDIR}/build" -# Prepare date string for default image file name -DATE="$(date +%Y-%m-%d)" -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 - # Chroot directories R="${BUILDDIR}/chroot" ETC_DIR="${R}/etc" LIB_DIR="${R}/lib" BOOT_DIR="${R}/boot/firmware" KERNEL_DIR="${R}/usr/src/linux" -WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm" +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:=""} # General settings +SET_ARCH=${SET_ARCH:=32} HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} PASSWORD=${PASSWORD:=raspberry} USER_PASSWORD=${USER_PASSWORD:=raspberry} DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} TIMEZONE=${TIMEZONE:="Europe/Berlin"} EXPANDROOT=${EXPANDROOT:=true} +ENABLE_DPHYSSWAP=${ENABLE_DPHYSSWAP:=true} # Keyboard settings XKB_MODEL=${XKB_MODEL:=""} @@ -127,8 +120,12 @@ NET_NTP_2=${NET_NTP_2:=""} # APT settings APT_PROXY=${APT_PROXY:=""} APT_SERVER=${APT_SERVER:="ftp.debian.org"} +KEEP_APT_PROXY=${KEEP_APT_PROXY:=false} # 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} @@ -146,6 +143,8 @@ ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} ENABLE_USER=${ENABLE_USER:=true} USER_NAME=${USER_NAME:="pi"} ENABLE_ROOT=${ENABLE_ROOT:=false} +ENABLE_QEMU=${ENABLE_QEMU:=false} +ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} # SSH settings SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} @@ -155,31 +154,43 @@ SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} # Advanced settings +ENABLE_SYSTEMDSWAP=${ENABLE_SYSTEMDSWAP:=false} ENABLE_MINBASE=${ENABLE_MINBASE:=false} ENABLE_REDUCE=${ENABLE_REDUCE:=false} ENABLE_UBOOT=${ENABLE_UBOOT:=false} UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} +ENABLE_USBBOOT=${ENABLE_USBBOOT=false} ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} +ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false} +ENABLE_NEXMON=${ENABLE_NEXMON:=false} +VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} +NEXMONSRC_DIR=${NEXMONSRC_DIR:=""} ENABLE_HARDNET=${ENABLE_HARDNET:=false} ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} +ENABLE_SPLASH=${ENABLE_SPLASH:=true} +ENABLE_LOGO=${ENABLE_LOGO:=true} +ENABLE_SILENT_BOOT=${ENABLE_SILENT_BOOT=false} 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} KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} -if [ "$KERNEL_ARCH" = "arm64" ] ; then - KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} -else - KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} -fi +KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} +KERNEL_CCACHE=${KERNEL_CCACHE:=false} +KERNEL_ZSWAP=${KERNEL_ZSWAP:=false} +KERNEL_VIRT=${KERNEL_VIRT:=false} +KERNEL_BPF=${KERNEL_BPF:=false} +KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=ondemand} +KERNEL_SECURITY=${KERNEL_SECURITY:=false} +KERNEL_NF=${KERNEL_NF:=false} # Kernel compilation from source directory settings KERNELSRC_DIR=${KERNELSRC_DIR:=""} @@ -203,16 +214,20 @@ CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} - -# Stop the Crypto Wars -DISABLE_FBI=${DISABLE_FBI:=false} +#Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup +CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false} +#Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated +CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""} # Chroot scripts directory 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" +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:=""} # Packages required for bootstrapping REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo" @@ -221,64 +236,178 @@ MISSING_PACKAGES="" # Packages installed for c/c++ build environment in chroot (keep empty) COMPILER_PACKAGES="" -set +x +# Check if apt-cacher-ng has port 3142 open and set APT_PROXY +APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d') +if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then + APT_PROXY=http://127.0.0.1:3142/ +fi + +# Setup architecture specific settings +if [ -n "$SET_ARCH" ] ; then + # 64-bit configuration + if [ "$SET_ARCH" = 64 ] ; then + # 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"} + + # Raspberry Pi model specific settings + if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then + if [ "$RPI_MODEL" != 4 ] ; then + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} + else + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2711_defconfig} + fi + + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" + 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, 3B+ and 4 support 64-bit" + exit 1 + fi + fi -# Set Raspberry Pi model specific configuration -if [ "$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} - BUILD_KERNEL=true + # 32-bit configuration + if [ "$SET_ARCH" = 32 ] ; then + # 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"} + + # 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} + RELEASE_ARCH=${RELEASE_ARCH:=armel} + KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} + CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} + fi + + # Raspberry Pi model specific settings + if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$RPI_MODEL" = 4 ] ; then + if [ "$RPI_MODEL" != 4 ] ; then + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} + else + KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2711_defconfig} + fi + + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" + 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 +# 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} + ;; + 4) + DTB_FILE=${DTB_FILE:=bcm2711-rpi-4-b.dtb} + UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_4_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 ] || [ "$RPI_MODEL" = 4 ] ; then + # Include bluetooth packages on supported boards + if [ "$ENABLE_BLUETOOTH" = true ] ; then + APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" + fi + if [ "$ENABLE_WIRELESS" = true ] ; then + APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb" + 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 -# Check if the internal wireless interface is supported by the RPi model -if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" != 3 ] ; then - echo "error: The selected Raspberry Pi model has no internal wireless interface" +if [ "$BUILD_KERNEL" = false ] && [ "$ENABLE_NEXMON" = true ]; then + echo "error: You have to compile kernel sources, if you want to enable nexmon" exit 1 fi +# Prepare date string for default image file name +DATE="$(date +%Y-%m-%d)" +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 + # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported -if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then +if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" exit 1 fi fi -# Build RPi2/3 Linux kernel if required by Debian release -if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then - BUILD_KERNEL=true +# Add cmake to compile videocore sources +if [ "$ENABLE_VIDEOCORE" = true ] ; then + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" fi -# Add packages required for kernel cross compilation -if [ "$BUILD_KERNEL" = true ] ; then - if [ "$KERNEL_ARCH" = "arm" ] ; then - REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" - else - REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" - fi +# Add deps for nexmon +if [ "$ENABLE_NEXMON" = true ] ; then + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool" fi # Add libncurses5 to enable kernel menuconfig if [ "$KERNEL_MENUCONFIG" = true ] ; then - REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev" + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" fi -# Stop the Crypto Wars -if [ "$DISABLE_FBI" = true ] ; then - ENABLE_CRYPTFS=true +# Add ccache compiler cache for (faster) kernel cross (re)compilation +if [ "$KERNEL_CCACHE" = true ] ; then + REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" fi # Add cryptsetup package to enable filesystem encryption if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" - APT_INCLUDES="${APT_INCLUDES},cryptsetup" + APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" + # If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package + if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then + APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs" + fi + if [ -z "$CRYPTFS_PASSWORD" ] ; then echo "error: no password defined (CRYPTFS_PASSWORD)!" exit 1 @@ -293,11 +422,18 @@ fi # Add device-tree-compiler required for building the U-Boot bootloader if [ "$ENABLE_UBOOT" = true ] ; then - APT_INCLUDES="${APT_INCLUDES},device-tree-compiler" + APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" +fi + +if [ "$ENABLE_USBBOOT" = true ] ; then + if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 2 ]; then + echo "error: Booting from USB alone is only supported by Raspberry Pi 3 and 3P" + exit 1 + fi fi # Check if root SSH (v2) public key file exists -if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then +if [ -n "$SSH_ROOT_PUB_KEY" ] ; then 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 @@ -305,16 +441,21 @@ if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then fi # Check if $USER_NAME SSH (v2) public key file exists -if [ ! -z "$SSH_USER_PUB_KEY" ] ; then +if [ -n "$SSH_USER_PUB_KEY" ] ; then 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 +if [ "$ENABLE_NEXMON" = true ] && [ -n "$KERNEL_BRANCH" ] ; then + echo "error: Please unset KERNEL_BRANCH if using ENABLE_NEXMON" + exit 1 +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 @@ -324,12 +465,12 @@ if [ -n "$MISSING_PACKAGES" ] ; then echo "the following packages needed by this script are not installed:" echo "$MISSING_PACKAGES" - echo -n "\ndo you want to install the missing packages right now? [y/n] " - read confirm + printf "\ndo you want to install the missing packages right now? [y/n] " + read -r confirm [ "$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 @@ -356,12 +497,24 @@ if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then exit 1 fi +# 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 + # 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 +# Check if specified NEXMONSRC_DIR directory exists +if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then + echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!" + exit 1 +fi + # 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)!" @@ -384,7 +537,7 @@ fi mkdir -p "${R}" # Check if build directory has enough of free disk space >512MB -if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then +if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then echo "error: ${BUILDDIR} not enough space left to generate the output image!" exit 1 fi @@ -399,16 +552,16 @@ if [ "$ENABLE_MINBASE" = true ] ; then APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" fi -# Add required locales packages -if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then - APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup" -fi - # Add parted package, required to get partprobe utility if [ "$EXPANDROOT" = true ] ; then APT_INCLUDES="${APT_INCLUDES},parted" fi +# Add dphys-swapfile package, required to enable swap +if [ "$ENABLE_DPHYSSWAP" = true ] ; then + APT_INCLUDES="${APT_INCLUDES},dphys-swapfile" +fi + # Add dbus package, recommended if using systemd if [ "$ENABLE_DBUS" = true ] ; then APT_INCLUDES="${APT_INCLUDES},dbus" @@ -416,7 +569,11 @@ fi # Add iptables IPv4/IPv6 package if [ "$ENABLE_IPTABLES" = true ] ; then - APT_INCLUDES="${APT_INCLUDES},iptables" + APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" +fi +# Add apparmor for KERNEL_SECURITY +if [ "$KERNEL_SECURITY" = true ] ; then + APT_INCLUDES="${APT_INCLUDES},apparmor,apparmor-utils,apparmor-profiles,apparmor-profiles-extra,libapparmor-perl" fi # Add openssh server package @@ -462,12 +619,13 @@ if [ "$ENABLE_REDUCE" = true ] ; then # Add dropbear package instead of openssh-server if [ "$REDUCE_SSHD" = true ] ; then - APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")" + APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" fi fi -if [ "$RELEASE" != "jessie" ] ; then - APT_INCLUDES="${APT_INCLUDES},libnss-systemd" +# Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available +if [ "$ENABLE_SYSVINIT" = false ] ; then + APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" fi # Configure kernel sources if no KERNELSRC_DIR @@ -480,6 +638,16 @@ if [ "$KERNEL_REDUCE" = true ] ; then KERNELSRC_CONFIG=false fi +# Configure qemu compatible kernel +if [ "$ENABLE_QEMU" = true ] ; then + DTB_FILE=vexpress-v2p-ca15_a7.dtb + UBOOT_CONFIG=vexpress_ca15_tc2_defconfig + KERNEL_DEFCONFIG="vexpress_defconfig" + if [ "$KERNEL_MENUCONFIG" = false ] ; then + KERNEL_OLDDEFCONFIG=true + fi +fi + # Execute bootstrap scripts for SCRIPT in bootstrap.d/*.sh; do head -n 3 "$SCRIPT" @@ -509,11 +677,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" @@ -532,13 +695,17 @@ umount -l "${R}/sys" rm -rf "${R}/run/*" rm -rf "${R}/tmp/*" +# Clean up APT proxy settings +if [ "$KEEP_APT_PROXY" = false ] ; then + rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" +fi + # Clean up files 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" rm -f "${R}/root/.bash_history" rm -f "${R}/var/lib/urandom/random-seed" @@ -546,28 +713,76 @@ rm -f "${R}/initrd.img" rm -f "${R}/vmlinuz" rm -f "${R}${QEMU_BINARY}" +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/"*.dtbo ; do + if [ -f "${dtb}" ] ; then + install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" + fi + done + fi + + # 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 + + # 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 +fi + # Calculate size of the chroot directory in KB -CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`) +CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") # Calculate the amount of needed 512 Byte sectors TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) -ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS}) +ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") # The root partition is EXT4 # This means more space than the actual used space of the chroot is used. # As overhead for journaling and reserved blocks 35% are added. -ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512) +ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) # Calculate required image size in 512 Byte sectors -IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS}) +IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") # Prepare image file if [ "$ENABLE_SPLITFS" = true ] ; then - 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} + 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}" # Write firmware/boot partition tables sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null < /dev/null <