diff --git a/contracts b/contracts index 10917938..c45079c3 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 109179385bb4b862cd7572be14d4c5edddbd93c9 +Subproject commit c45079c380048f9f65967a68cf30f1654195384f diff --git a/layers/meta-balena-topic/recipes-core/images/balena-image-flasher.bbappend b/layers/meta-balena-topic/recipes-core/images/balena-image-flasher.bbappend new file mode 100755 index 00000000..302c369c --- /dev/null +++ b/layers/meta-balena-topic/recipes-core/images/balena-image-flasher.bbappend @@ -0,0 +1,5 @@ +include balena-image.inc + +# Provide any deltas required for the flasher image +BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}\ +" diff --git a/layers/meta-balena-topic/recipes-core/images/balena-image.bbappend b/layers/meta-balena-topic/recipes-core/images/balena-image.bbappend index 987a56f9..653160a2 100755 --- a/layers/meta-balena-topic/recipes-core/images/balena-image.bbappend +++ b/layers/meta-balena-topic/recipes-core/images/balena-image.bbappend @@ -1,45 +1,5 @@ -DEPENDS += "balena-bootscript" +include balena-image.inc -BALENA_BOOT_BIN ?= "" -DEPENDS += "${BALENA_BOOT_BIN}" -# Add components that we need to boot -IMAGE_INSTALL += "\ - bootscript \ - kernel-module-rtl88x2bu \ - iperf3 \ - ${IMAGE_INSTALL_MACHINE_EXTRAS} \ - " - -BALENA_EXTRA_BOOT_FILES:zynqmp = "boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr" -BALENA_EXTRA_BOOT_FILES:zynq = "boot.bin:/boot.bin u-boot.img:/u-boot.img balena-bootscript.scr:/boot.scr" -BALENA_EXTRA_BOOT_FILES:lcbzu9 = "lcb-boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr" -BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}" - -DEVICETREELINKS ??= "system.dtb ${DEVICETREE}" - -# Postprocessing to reduce the amount of work to be done -# by configuration scripts -topicbalena_rootfs_postprocess() { - /bin/echo -e "${DEVICETREELINKS}" | while read LINK TARGET - do - if [ -n "${TARGET}" ] - then - /bin/echo "DT: ${LINK}->${TARGET}" - ln -s ${TARGET} ${IMAGE_ROOTFS}/boot/${LINK} - fi - done -} -ROOTFS_POSTPROCESS_COMMAND += "topicbalena_rootfs_postprocess; " - - -# Sizes in KiB. -# We need to increase the rootfs size to make space for additional drivers in ROOTFS. -# BalenaOS image has a 700MB max size defined in 'image_types_balena.bbclass' -IMAGE_ROOTFS_SIZE="409600" - -# We require access to the git repository here, so we must run outside fakeroot -do_addrevisioninfo() { - git rev-parse --verify --short HEAD >> ${IMAGE_ROOTFS}${sysconfdir}/revision -} -addtask do_addrevisioninfo before do_image after do_rootfs \ No newline at end of file +BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}\ +" diff --git a/layers/meta-balena-topic/recipes-core/images/balena-image.inc b/layers/meta-balena-topic/recipes-core/images/balena-image.inc new file mode 100755 index 00000000..92d6251d --- /dev/null +++ b/layers/meta-balena-topic/recipes-core/images/balena-image.inc @@ -0,0 +1,44 @@ +DEPENDS += "balena-bootscript" + +BALENA_BOOT_BIN ?= "" +DEPENDS += "${BALENA_BOOT_BIN}" + +# Add components that we need to boot +IMAGE_INSTALL += "\ + bootscript \ + kernel-module-rtl88x2bu \ + iperf3 \ + ${IMAGE_INSTALL_MACHINE_EXTRAS} \ + " + +BALENA_EXTRA_BOOT_FILES:zynqmp = "boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr" +BALENA_EXTRA_BOOT_FILES:zynq = "boot.bin:/boot.bin u-boot.img:/u-boot.img balena-bootscript.scr:/boot.scr" +BALENA_EXTRA_BOOT_FILES:lcbzu9 = "lcb-boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr" + +DEVICETREELINKS ??= "system.dtb ${DEVICETREE}" + +# Postprocessing to reduce the amount of work to be done +# by configuration scripts +topicbalena_rootfs_postprocess() { + /bin/echo -e "${DEVICETREELINKS}" | while read LINK TARGET + do + if [ -n "${TARGET}" ] + then + /bin/echo "DT: ${LINK}->${TARGET}" + ln -s ${TARGET} ${IMAGE_ROOTFS}/boot/${LINK} + fi + done +} +ROOTFS_POSTPROCESS_COMMAND += "topicbalena_rootfs_postprocess; " + + +# Sizes in KiB. +# We need to increase the rootfs size to make space for additional drivers in ROOTFS. +# BalenaOS image has a 700MB max size defined in 'image_types_balena.bbclass' +IMAGE_ROOTFS_SIZE="409600" + +# We require access to the git repository here, so we must run outside fakeroot +do_addrevisioninfo() { + git rev-parse --verify --short HEAD >> ${IMAGE_ROOTFS}${sysconfdir}/revision +} +addtask do_addrevisioninfo before do_image after do_rootfs \ No newline at end of file diff --git a/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/files/99-flash-bootloader.txt b/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/files/99-flash-bootloader.txt new file mode 100755 index 00000000..3b554396 --- /dev/null +++ b/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/files/99-flash-bootloader.txt @@ -0,0 +1,50 @@ +#!/bin/sh + +# +# Script used by hostapps updater to flash bootloader onto internal media +# + +set -o errexit + +# machine specific data + +bootbin_file="boot.bin" +bootbin_block_size=512 +bootbin_seek_blocks=64 + +itb_file="u-boot.itb" +itb_block_size=512 +itb_seek_blocks=24576 + +bootscr_file="boot.scr" +bootscr_block_size=512 +bootscr_seek_blocks=16384 + +device="/dev/"$(findmnt --noheadings --canonicalize --output SOURCE /mnt/boot/ | xargs lsblk -no pkname) + +# we sort the update files list by ascending memory addresses these binaries will be written to +update_files="bootbin itb bootscr" + +for i in $update_files; do + current_update_file=$(eval echo \$${i}_file) + block_size=$(eval echo \$${i}_block_size) + seek_blocks=$(eval echo \$${i}_seek_blocks) + + # calculate size and md5sum of the binary to update from the update bundle + update_size=$(stat -c%s /resin-boot/$current_update_file) + update_md5sum=$(md5sum /resin-boot/$current_update_file | awk '{print $1'}) + + # calculate number of bytes to skip when computing the checksum of the data we want to update (i.e. the data already written to $device) + skip_bytes=$((block_size * seek_blocks)) + + # calculate md5sum of the data already written to $device, using $update_size bytes and skipping $skip_bytes from $device + existing_md5sum=$(dd if=$device skip=$skip_bytes bs=1 count=$update_size status=none | md5sum | awk '{print $1}') + + if [ ! "$existing_md5sum" = "$update_md5sum" ] || [ -n "$force_write" ]; then + # we are flashing a binary and let's signal that we need to also flash the remaining binaries + # (if we do not write the remaining binaries when the previous one was written then the board may not boot anymore, due to the nature of the secure boot mechanism on the Rockchip hardware) + force_write=true + echo "Flashing $current_update_file to $device" + dd if=/resin-boot/$current_update_file of=$device conv=fdatasync seek=$seek_blocks bs=$block_size + fi +done \ No newline at end of file diff --git a/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/hostapp-update-hooks.bbappend b/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/hostapp-update-hooks.bbappend new file mode 100755 index 00000000..81e758da --- /dev/null +++ b/layers/meta-balena-topic/recipes-support/resin-init/hostapp-update-hooks/hostapp-update-hooks.bbappend @@ -0,0 +1,6 @@ +FILESEXTRAPATHS_append := ":${THISDIR}/files" + +HOSTAPP_HOOKS += " \ + 99-resin-uboot \ + 99-flash-bootloader \ +" diff --git a/layers/meta-balena-topic/recipes-support/resin-init/resin-init-flasher.bbappend b/layers/meta-balena-topic/recipes-support/resin-init/resin-init-flasher.bbappend new file mode 100755 index 00000000..08015c3b --- /dev/null +++ b/layers/meta-balena-topic/recipes-support/resin-init/resin-init-flasher.bbappend @@ -0,0 +1,2 @@ +# write internal balenaOS image to the eMMC +INTERNAL_DEVICE_KERNEL = "mmcblk0" diff --git a/lcbzu9.coffee b/lcbzu9.coffee index 3e8de55b..dc05e30f 100644 --- a/lcbzu9.coffee +++ b/lcbzu9.coffee @@ -20,10 +20,10 @@ module.exports = yocto: machine: 'lcbzu9' - image: 'balena-image' + image: 'balena-image-flasher' fstype: 'balenaos-img' version: 'yocto-honister' - deployArtifact: 'balena-image-lcbzu9.balenaos-img' + deployArtifact: 'balena-image-flasher-lcbzu9.balenaos-img' configuration: config: diff --git a/scripts/autobuild.sh b/scripts/autobuild.sh index 1a160c8a..3f9b9261 100755 --- a/scripts/autobuild.sh +++ b/scripts/autobuild.sh @@ -12,7 +12,9 @@ mkdir -p build/artefacts for m in *.coffee do MACHINE=`basename $m .coffee` - ./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -s ~/shared_downloads_and_sstate + ./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -i balena-image -s ~/shared_downloads_and_sstate + ./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -i balena-image-flasher -s ~/shared_downloads_and_sstate xz -3 < build/tmp/deploy/images/${MACHINE}/balena-image-${MACHINE}.balenaos-img > build/artefacts/balena-image-${MACHINE}.balenaos-img.xz & + xz -3 < build/tmp/deploy/images/${MACHINE}/balena-image-flasher-${MACHINE}.balenaos-img > build/artefacts/balena-image-flasher-${MACHINE}.balenaos-img.xz & done wait