From 31e059e1a715f4feb33f968a21945cbd5f7ace0d Mon Sep 17 00:00:00 2001 From: Alexandru Costache Date: Mon, 6 Jan 2025 12:22:53 +0000 Subject: [PATCH] recipes-support: Remove all Xavier AGX and NX devkits related code These devices are in progress of being released on JP5, from a different repository: https://github.com/balena-os/balena-jetson-jp5 Signed-off-by: Alexandru Costache --- .../files/99-resin-bootfiles-xavier | 185 ------------------ .../files/99-resin-bootfiles-xavier-nx-devkit | 173 ---------------- .../hostapp-update-hooks.bbappend | 19 -- 3 files changed, 377 deletions(-) delete mode 100644 layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier delete mode 100644 layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier-nx-devkit diff --git a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier b/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier deleted file mode 100644 index 41ed2b31a..000000000 --- a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/sh -set -o errexit - -# Script which writes the appropriate -# device tree with embedded cmdline -# and updates the kernel, as well as -# the rest of the bootloader binaries - -. /usr/libexec/os-helpers-fs -. /usr/libexec/os-helpers-logging - -DURING_UPDATE=${DURING_UPDATE:-0} -bootloader_device="/dev/mmcblk0boot0" -partspec="/resin-boot/bootfiles/partition_specification194.txt" -bootloader_blob="/resin-boot/bootfiles/boot0_t194.bin.gz" -bootpart_kernel="/mnt/boot/bootfiles/boot_sigheader.img.encrypt" - -# Check if old release made use of -# DURING_UPDATE flag and backport rollback-altboot -# fix to old hook if necessary. -backport_rollback_altboot_fix() -{ - inactive_hook=$(find /mnt/sysroot/active/ | grep "99-resin-bootfiles-xavier") - if grep -q "DURING_UPDATE" "${inactive_hook}"; then - info "No need to backport altboot fix to old hook" - else - info "Will backport rollback-altboot fix to old hook" - sed -i 's/os-helpers-fs/os-helpers-fs \nDURING_UPDATE=${DURING_UPDATE:-0}\nif [ "$DURING_UPDATE" = "0" ]; then target_sysroot="active"; else target_sysroot="inactive"; fi; /g' ${inactive_hook} - sed -i 's|/mnt/sysroot/inactive|/mnt/sysroot/${target_sysroot}|g' ${inactive_hook} - info "Applied rollback-altboot fix to old hostapp-update hook" - fi - - if [ -e ${bootpart_kernel} ]; then - rm ${bootpart_kernel} - info "Removed signed kernel binary from boot partition, it is now located in the rootfs" - else - info "No need to remove kernel binary from boot partition" - fi -} - -get_label_suffix_by_slot() -{ - if [ $1 -eq 0 ]; then - echo '' - else - echo '_b' - fi -} - -if ! command -v tegra-boot-control &> /dev/null -then - info "Could not find tegra-boot-control!" - exit 1 -fi - -redundancy_state=$(/usr/bin/tegra-boot-control -s | awk -F 'Redundancy:' '{print $2}' | awk '{print $1}' | tr -d '\n') -info "Redundancy is currently ${redundancy_state}" - -# Enable boot slot redundancy if not enabled already -tegra-boot-control -e -curr_slot=$(/usr/bin/tegra-boot-control -c) -info "Current active slot is ${curr_slot}" - -if [ "$DURING_UPDATE" = "1" ]; then - backport_rollback_altboot_fix - info "Target active slot is $((target_slot = ! curr_slot))" - target_sysroot="inactive" -else - info "Target active slot stays $((target_slot = curr_slot))" - target_sysroot="active" -fi - -target_part=$(findmnt --noheadings --canonicalize --output SOURCE "/mnt/sysroot/${target_sysroot}" -t ext4) -info "New rootfs partition is ${target_part}" - -target_label_suffix=$(get_label_suffix_by_slot ${target_slot}) -rootstr=$(get_dev_label "${target_part}") -rootl="" - -update_needed() { - current_update_file=${1} - device=${2} - update_size=$(ls -al $current_update_file | awk '{print $5}') - update_md5sum=$(md5sum $current_update_file | awk '{print $1'}) - existing_md5sum=$(dd if=$device bs=1 count=$update_size status=none | md5sum | awk '{print $1}') - - if [ ! "$existing_md5sum" = "$update_md5sum" ]; then - echo 1 - else - echo 0 - fi -} - -case "$rootstr" in - *resin-rootA*) - rootl="A" - ;; - *resin-rootB*) - rootl="B" - ;; - *) - rootl="Undefined" - ;; -esac - -info "New root is resin-root${rootl}" - -dtbname=$(cat "$partspec" | grep "kernel-dtb_b" | cut -d ':' -f 2 | awk -F'_sigheader' '{print $1}') -dtbfile="${dtbname}-root${rootl}_sigheader.dtb.encrypt" -kernel="boot_sigheader.img.encrypt" -partitions=$(cat "${partspec}") - -for n in ${partitions}; do - part_name=$(echo $n | cut -d ':' -f 1) - file_name=$(echo $n | cut -d ':' -f 2) - - if [ -z "${part_name##*kernel*}" ] || [ -z "${part_name##*bootloader-dtb*}" ] || [ $file_name = "none.bin" ]; then - continue - fi - - file_path=$(get_state_path_from_label $part_name) - - if [ "x$file_path" = "x" ]; then - continue - fi - - # On the Xavier AGX, MB1 on 32.6.1 wants both slots _a and _b to have - # 32.6.1 binaries, otherwise it enters debug mode as soon as the retry - # count goes down to 0. We have tried updating only _b slots inside boot0 blob, - # marking old slot as successfull too before switching to the new one, but without - # success. The only solution is to update everything to 32.6.1 and just leave - # the old kernel and kernel dtb in place, for the fallback to take place. - # See: https://github.com/OE4T/meta-tegra/issues/879#issuecomment-1034908517 - dst="${file_path}" - src="/resin-boot/bootfiles/$file_name" - if [ -e ${dst} ]; then - if [ $(update_needed $src $dst) -eq 1 ]; then - info "Will update ${dst} ..." - dd if=${src} of="${dst}" bs=64K conv=fsync - info "Updated ${dst}" - else - info "No need to update ${dst}" - fi - else - info "Partition ${dst} not found" - fi -done - -# DTB contains root partition label, update is mandatory on the new boot slot, before switching it to active -info "Writing ${dtbfile} to specific to bootloader-dtb partition." -dd if=/resin-boot/bootfiles/${dtbfile} of=$(get_state_path_from_label "bootloader-dtb") bs=64K conv=fsync - -info "Writing ${dtbfile} to specific to bootloader-dtb_b partition." -dd if=/resin-boot/bootfiles/${dtbfile} of=$(get_state_path_from_label "bootloader-dtb_b") bs=64K conv=fsync - -dd if=/resin-boot/bootfiles/${dtbfile} of=$(get_state_path_from_label "kernel-dtb${target_label_suffix}") bs=64K conv=fsync - -info "Writing kernel ${kernel} to specific partitions..." - -dd if=/opt/tegra-binaries/${kernel} of=$(get_state_path_from_label "kernel${target_label_suffix}") bs=64K conv=fsync -info "Updating boot image on hw partition mmcblk0boot0..." - -existing_bootloader_md5sum=$(dd if=$bootloader_device bs=1M status=none | md5sum | awk '{print $1}') -update_bootloader_md5sum=$(zcat $bootloader_blob | md5sum | awk '{print $1}') - -if [ ! "$existing_bootloader_md5sum" = "$update_bootloader_md5sum" ]; then - echo 0 > /sys/block/mmcblk0boot0/force_ro - zcat $bootloader_blob | dd of=$bootloader_device bs=64K conv=fsync - echo 1 > /sys/block/mmcblk0boot0/force_ro -fi - -# Update slot selection after the qspi was updated, otherwise -# scratch register contents will be lost -info "Setting active slot to ${target_slot}" -/usr/bin/tegra-boot-control -e -/usr/bin/tegra-boot-control -a ${target_slot} - -if [ "$DURING_UPDATE" = "0" ]; then - /usr/bin/tegra-boot-control -m - info "Running in rollback-altboot, next boot will be from the same slot. Marked boot as successful." -fi - -info "Done." - -sync diff --git a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier-nx-devkit b/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier-nx-devkit deleted file mode 100644 index d75139b5f..000000000 --- a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/files/99-resin-bootfiles-xavier-nx-devkit +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/sh -set -o errexit - -# Script which writes the appropriate -# device tree with embedded cmdline -# and updates the kernel, as well as -# the rest of the bootloader binaries - -. /usr/libexec/os-helpers-fs -. /usr/libexec/os-helpers-logging - -DURING_UPDATE=${DURING_UPDATE:-0} -declare -a UPDATED_PARTITIONS=() -bootloader_device="/dev/mtdblock0" -bootloader_blob="/opt/tegra-binaries/boot0.img" -partspec=$(find "/opt/tegra-binaries/" | grep "partition_specification194_nx") - -# Check if old hook made use of DURING_UPDATE -# and if not, backport rollback-altboot fix -# to it if necessary. -backport_rollback_altboot_fix() -{ - inactive_hook=$(find /mnt/sysroot/active/ | grep "99-resin-bootfiles-xavier-nx-devkit") - if grep -q "DURING_UPDATE" "${inactive_hook}"; then - info "No need to backport altboot fix to old hook" - else - info "Will backport rollback-altboot fix to old hook" - sed -i 's/os-helpers-fs/os-helpers-fs \nDURING_UPDATE=${DURING_UPDATE:-0}\nif [ "$DURING_UPDATE" = "0" ]; then target_sysroot="active"; else target_sysroot="inactive"; fi; /g' ${inactive_hook} - sed -i 's|/mnt/sysroot/inactive|/mnt/sysroot/${target_sysroot}|g' ${inactive_hook} - info "Applied rollback-altboot fix to old hostapp-update hook" - fi -} - -get_label_suffix_by_slot() -{ - if [ $1 -eq 0 ]; then - echo '' - else - echo '_b' - fi -} - -if ! command -v tegra-boot-control &> /dev/null -then - info "Could not find tegra-boot-control!" - exit 1 -fi - -redundancy_state=$(/usr/bin/tegra-boot-control -s | awk -F 'Redundancy:' '{print $2}' | awk '{print $1}' | tr -d '\n') -info "Redundancy is currently ${redundancy_state}" - -# Enable boot slot redundancy if not enabled already -tegra-boot-control -e -curr_slot=$(/usr/bin/tegra-boot-control -c) -info "Current active slot is ${curr_slot}" - -if [ "$DURING_UPDATE" = "1" ]; then - backport_rollback_altboot_fix - info "Target active slot is $((target_slot = ! curr_slot))" - target_sysroot="inactive" -else - info "Target active slot stays $((target_slot = curr_slot))" - target_sysroot="active" -fi - -target_part=$(findmnt --noheadings --canonicalize --output SOURCE "/mnt/sysroot/${target_sysroot}" -t ext4) -info "New rootfs partition is ${target_part}" - -target_label_suffix=$(get_label_suffix_by_slot ${target_slot}) -rootstr=$(get_dev_label "${target_part}") -rootl="" - -update_needed() { - current_update_file=${1} - device=${2} - if [[ " ${UPDATED_PARTITIONS[*]} " =~ " ${device} " ]]; then - echo 0 - else - update_size=$(ls -al $current_update_file | awk '{print $5}') - update_md5sum=$(md5sum $current_update_file | awk '{print $1'}) - existing_md5sum=$(dd if=$device count=1 bs=$update_size status=none | md5sum | awk '{print $1}') - - if [ ! "$existing_md5sum" = "$update_md5sum" ]; then - echo 1 - else - echo 0 - fi - fi -} - -case "$rootstr" in - *resin-rootA*) - rootl="A" - ;; - *resin-rootB*) - rootl="B" - ;; - *) - rootl="Undefined" - ;; -esac - -info "New root is resin-root${rootl}" - -dtbname=$(cat "$partspec" | grep "kernel-dtb_b" | cut -d ':' -f 2 | awk -F'_sigheader' '{print $1}') -dtbfile="${dtbname}-root${rootl}_sigheader.dtb.encrypt" -kernel="boot_sigheader.img.encrypt" -partitions=$(cat ${partspec}) - -for n in ${partitions}; do - part_name=$(echo $n | cut -d ':' -f 1 | cut -d '_' -f 1) - file_name=$(echo $n | cut -d ':' -f 2) - - if [ -z "${part_name##*kernel*}" ] || [ -z "${part_name##*bootloader-dtb*}" ] || [ $file_name = "none.bin" ]; then - continue - fi - - file_path=$(get_state_path_from_label $part_name) - - if [ "x$file_path" = "x" ]; then - continue - fi - - dst="${file_path}${target_label_suffix}" - src="/opt/tegra-binaries/${file_name}" - - if [ -e ${dst} ]; then - if [ $(update_needed $src $dst) -eq 1 ]; then - info "Will update ${dst} ..." - dd if=${src} of="${dst}" bs=64K conv=fsync - UPDATED_PARTITIONS+=(${dst}) - info "Updated ${dst}" - else - info "No need to update ${dst}" - fi - else - info "Duplicate slot for target partition ${dst} not available, ignoring." - fi -done - -# DTB contains root partition, update is mandatory on the new boot slot, before switching it to active -info "Writing ${dtbfile} to specific partitions..." -dd if=/opt/tegra-binaries/${dtbfile} of=$(get_state_path_from_label "kernel-dtb${target_label_suffix}") bs=64K conv=fsync - -info "Writing kernel ${kernel} to specific partitions..." -dd if=/opt/tegra-binaries/${kernel} of=$(get_state_path_from_label "kernel${target_label_suffix}") bs=64K conv=fsync - -existing_bootloader_md5sum=$(dd if=$bootloader_device bs=1M status=none | md5sum | awk '{print $1}') -update_bootloader_md5sum=$(md5sum $bootloader_blob | awk '{print $1}') - -if [ ! "$existing_bootloader_md5sum" = "$update_bootloader_md5sum" ]; then - info "Will update bootloader device" - flash_erase /dev/mtd0 0 0 || true - dd if=$bootloader_blob of=$bootloader_device bs=1M conv=fsync -else - info "No need to update bootloader device" -fi - -# Sync internal memory -sync /dev/mmcblk0 - -# Update slot selection after the qspi was updated, otherwise -# scratch register contents will be lost -info "Setting active slot to ${target_slot}" -/usr/bin/tegra-boot-control -e -/usr/bin/tegra-boot-control -a ${target_slot} - -if [ "$DURING_UPDATE" = "0" ]; then - /usr/bin/tegra-boot-control -m - info "Running in rollback-altboot, next boot will be from the same slot. Marked boot as successful." -fi - -info "Done." diff --git a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/hostapp-update-hooks.bbappend b/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/hostapp-update-hooks.bbappend index bd436f6ef..b6da44cb1 100644 --- a/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/hostapp-update-hooks.bbappend +++ b/layers/meta-balena-jetson/recipes-support/hostapp-update-hooks/hostapp-update-hooks.bbappend @@ -18,25 +18,6 @@ HOSTAPP_HOOKS:append:jetson-nano-2gb-devkit = " 99-resin-uboot \ 99-resin-bootfiles-nano \ " -DEPENDS:append:jetson-xavier = " tegra194-flash-dry" -DEPENDS:append:jetson-xavier-nx-devkit-emmc = " tegra194-nxde-flash-dry" -DEPENDS:append:jetson-xavier-nx-devkit = " tegra194-nxde-sdcard-flash" - -# Xaviers do not use u-boot, but for rollbacks to work -# we need to update the resinOS_uEnv.txt file -HOSTAPP_HOOKS:append:jetson-xavier = " \ - 99-resin-uboot \ - 99-resin-bootfiles-xavier \ -" - -XAVIER_NX_HOOKS = " \ - 99-resin-uboot \ - 99-resin-bootfiles-xavier-nx-devkit \ -" - -HOSTAPP_HOOKS:append:jetson-xavier-nx-devkit-emmc = " ${XAVIER_NX_HOOKS}" -HOSTAPP_HOOKS:append:jetson-xavier-nx-devkit = " ${XAVIER_NX_HOOKS}" - DEPENDS:append:jetson-tx2 = " tegra186-flash-dry" HOSTAPP_HOOKS:append:jetson-tx2 = " \