# Binaries generated with the following script: # https://github.com/mendersoftware/mender-convert-integration-scripts/blob/master/build-uboot-rpi.sh # Raspberry Pi does not support GRUB bootloader integration, fallback to U-boot. MENDER_GRUB_EFI_INTEGRATION=n # Nothing to copy MENDER_COPY_BOOT_GAP=n # 4MB alignment MENDER_PARTITION_ALIGNMENT="4194304" RASPBERRYPI_BINARIES="${RASPBERRYPI_CONFIG}-2020.01.tar.gz" RASPBERRYPI_BINARIES_URL="${MENDER_STORAGE_URL}/mender-convert/uboot/raspberrypi/${RASPBERRYPI_BINARIES}" function platform_modify() { mkdir -p work/rpi/binaries run_and_log_cmd "wget -q ${RASPBERRYPI_BINARIES_URL} -P work/rpi/binaries" run_and_log_cmd "tar xzvf work/rpi/binaries/${RASPBERRYPI_BINARIES} -C work/rpi/binaries" # By default, we modify cmdline.txt. # # In Ubuntu, the file is called btcmd.txt; if this file exists, use it instead CMDLINE="cmdline.txt" if [ -f work/boot/btcmd.txt ]; then CMDLINE="btcmd.txt" fi # Make a copy of Linux kernel arguments and modify. run_and_log_cmd "cp work/boot/$CMDLINE work/rpi/$CMDLINE" # Set a dynamic rootfs part (required for Mender A/B update strategy) run_and_log_cmd "sed -i 's/\b[ ]root=[^ ]*/ root=\${mender_kernel_root}/' work/rpi/$CMDLINE" # Root filesystem can not be resized when the disk is partition according # to Mender layout, where the rootfs partition is the not last one which # is a requirement to be able to do an "online" resize. # # This disables resize of rootfs on boot but applies the changes to # cmdline.txt that are performed in the init_resize.sh script. # # Extracted from /usr/lib/raspi-config/init_resize.sh run_and_log_cmd "sed -i 's| init=/usr/lib/raspi-config/init_resize\.sh||' work/rpi/$CMDLINE" run_and_log_cmd "sed -i 's| sdhci\.debug_quirks2=4||' work/rpi/$CMDLINE" if ! grep -q splash work/rpi/$CMDLINE; then run_and_log_cmd "sed -i 's/ quiet//g' work/rpi/$CMDLINE" fi # Update Linux kernel command arguments with our custom configuration run_and_log_cmd "sudo cp work/rpi/$CMDLINE work/boot/" # Mask udisks2.service, otherwise it will mount the inactive part and we # might write an update while it is mounted which often result in # corruptions. # # TODO: Find a way to only blacklist mmcblk0pX devices instead of masking # the service. run_and_log_cmd "sudo ln -sf /dev/null work/rootfs/etc/systemd/system/udisks2.service" # Ubuntu Server images actually use U-boot by default on RPi3 and the # layout is slightly different on the boot partition. That is why we need # additional logic here to determine what we are converting. if [ -e work/boot/uboot_rpi_4_32b.bin ] && [ -e work/boot/vmlinuz ]; then RASPBERRYPI_KERNEL_IMAGE="vmlinuz" RASPBERRYPI_BOOTLOADER_IMAGE="uboot_rpi_4_32b.bin" elif [ -e work/boot/uboot.bin ] && [ -e work/boot/vmlinuz ]; then RASPBERRYPI_KERNEL_IMAGE="vmlinuz" RASPBERRYPI_BOOTLOADER_IMAGE="uboot.bin" else RASPBERRYPI_BOOTLOADER_IMAGE="${RASPBERRYPI_KERNEL_IMAGE}" fi # Extract Linux kernel and install to /boot directory on rootfs if it doesn't already exist. # If it already exists, the input image is likely already converted so we just want to use # the existing kernel image. if [ ! -f "work/rootfs/boot/${MENDER_KERNEL_IMAGETYPE}" ]; then run_and_log_cmd "sudo cp work/boot/${RASPBERRYPI_KERNEL_IMAGE} work/rootfs/boot/${MENDER_KERNEL_IMAGETYPE}" fi # Replace kernel with U-boot and add boot script run_and_log_cmd "sudo mkdir -p work/rootfs/uboot" run_and_log_cmd "sudo cp work/rpi/binaries/u-boot.bin work/boot/${RASPBERRYPI_BOOTLOADER_IMAGE}" run_and_log_cmd "sudo cp work/rpi/binaries/boot.scr work/boot" run_and_log_cmd "sudo cp work/rpi/binaries/fw_env.config work/rootfs/etc/" run_and_log_cmd "sudo cp work/rpi/binaries/uboot-git-log.txt work/boot" # Raspberry Pi applications expect to find this on the device and in some # cases parse the options to determine the functionality. Create symlinks # to all files for f in $(ls -1 work/boot); do run_and_log_cmd "sudo ln -fs /uboot/${f} work/rootfs/boot/${f}" done # Raspberry Pi headless configuration and other first boot scripts inspect the boot partition # for files. Modify the hard-coded mount point for the partition from /boot to /uboot. # Integrate with systemd services with "/boot/" hardcoded files_to_modify=$(find work/rootfs/lib/ -type f -name "*.service" | xargs grep '/boot/' | cut -d: -f1 | uniq) # MEN-5944: Integrate with raspberrypi-sys-mods/firstboot # See: https://github.com/RPi-Distro/raspberrypi-sys-mods if [ -f "work/rootfs/usr/lib/raspberrypi-sys-mods/firstboot" ]; then files_to_modify="$files_to_modify work/rootfs/usr/lib/raspberrypi-sys-mods/firstboot" fi # MEN-5954: Integrate with userconf-pi/userconf-service # See: https://github.com/RPi-Distro/userconf-pi if [ -f "work/rootfs/usr/lib/userconf-pi/userconf-service" ]; then files_to_modify="$files_to_modify work/rootfs/usr/lib/userconf-pi/userconf-service" fi # MEN-5955: Integrate with raspberrypi-net-mods/wpa_copy # See: https://github.com/RPi-Distro/raspberrypi-net-mods if [ -f "work/rootfs/usr/lib/raspberrypi-net-mods/wpa_copy" ]; then files_to_modify="$files_to_modify work/rootfs/usr/lib/raspberrypi-net-mods/wpa_copy" fi # Modify the files and log the changes for f in $files_to_modify; do run_and_log_cmd "sed -i.bak 's|/boot|/uboot|g' ${f}" log_debug "Modified file ${f}\n$(diff -u ${f}.bak ${f})" rm ${f}.bak done log_info "Certain service files have been changed to align with our /uboot boot partition mount point. See convert.log for more information" run_and_log_cmd "sudo install -m 755 work/rpi/binaries/fw_printenv work/rootfs/sbin/fw_printenv" run_and_log_cmd "sudo ln -fs /sbin/fw_printenv work/rootfs/sbin/fw_setenv" # Remove original 'resize2fs_once' script and its symbolic link. if [ -L work/rootfs/etc/rc3.d/S01resize2fs_once ]; then run_and_log_cmd "sudo unlink work/rootfs/etc/rc3.d/S01resize2fs_once" fi run_and_log_cmd "sudo rm -f work/rootfs/etc/init.d/resize2fs_once" # Enable UART. This is required for U-Boot to operate correctly, see # https://source.denx.de/u-boot/u-boot/-/blob/master/arch/arm/mach-bcm283x/Kconfig log_info "Enabling UART in U-Boot configuration" cat <<- EOF >> work/boot/config.txt # Enable UART enable_uart=1 EOF }