Skip to content

Commit

Permalink
Merge pull request #245 from balena-os/jetson_select_ab_slots_on_update
Browse files Browse the repository at this point in the history
jetson: Update next active slots on HUP
  • Loading branch information
bulldozer-balena[bot] authored Feb 2, 2022
2 parents 925ad57 + 6598fad commit 5789f27
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 61 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LIC_FILES_CHKSUM = "file://${BALENA_COREBASE}/COPYING.Apache-2.0;md5=89aea4e17d9

IMAGE_ROOTFS_ALIGNMENT ?= "4"

BOOT_BINDIFF="boot0_t194_agx.bindiff"

DEPENDS = " \
coreutils-native \
virtual/bootloader \
Expand All @@ -22,6 +24,7 @@ SRC_URI = " \
file://resinOS-flash194.xml \
file://partition_specification194.txt \
file://cti-rogue-32-4-3-pinmux.cfg \
file://${BOOT_BINDIFF} \
"

PINMUXCFG = "tegra19x-mb1-pinmux-p2888-0000-a04-p2822-0000-b01.cfg"
Expand All @@ -44,7 +47,7 @@ LNXFILE="${KERNEL_IMAGETYPE}${KERNEL_INITRAMFS}-${MACHINE}.bin"
IMAGE_TEGRAFLASH_KERNEL ?= "${DEPLOY_DIR_IMAGE}/${LNXFILE}"
BINARY_INSTALL_PATH = "/opt/tegra-binaries"

OS_KERNEL_CMDLINE = "${@bb.utils.contains('DEVELOPMENT_IMAGE','1','console=ttyTHS0,115200n8 console=tty1 debug loglevel=7','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
OS_KERNEL_CMDLINE = "${@bb.utils.contains('DISTRO_FEATURES','osdev-image','console=ttyTHS0,115200n8 console=tty1 ','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
ROOTA_ARGS="root=LABEL=resin-rootA ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"
ROOTB_ARGS="root=LABEL=resin-rootB ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"

Expand Down Expand Up @@ -253,6 +256,24 @@ do_configure() {
dd if=${DEPLOY_DIR_IMAGE}/bootfiles/mem_coldboot_sigheader.bct.encrypt of=boot0.img seek=720896 bs=1 conv=notrunc
dd if=${DEPLOY_DIR_IMAGE}/bootfiles/mem_coldboot_sigheader.bct.encrypt of=boot0.img seek=925696 bs=1 conv=notrunc

# Although the device will boot fine, rtcpu may not run as expected unless
# we patch the boot blob to resemble entirely the one created during provisioning by the flashing tools.
# Example dmesg logs of this failure:
# tegra-hsp-mailbox ivc-bc00000.rtcpu: IOVM setup error: 110
# tegra186-cam-rtcpu bc00000.rtcpu: command: 0x00000000: empty mailbox timeout
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=557072 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=560096 skip=32 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=561168 skip=64 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=562176 skip=96 bs=1 count=320 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=563536 skip=416 bs=1 count=320 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=587152 skip=736 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=638992 skip=768 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=642016 skip=800 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=643088 skip=832 bs=1 count=32 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=644096 skip=864 bs=1 count=320 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=645456 skip=1184 bs=1 count=320 conv=notrunc
dd if=${WORKDIR}/${BOOT_BINDIFF} of=boot0.img seek=669072 skip=1504 bs=1 count=32 conv=notrunc

cp boot0.img ${DEPLOY_DIR_IMAGE}/bootfiles/
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LNXFILE="${KERNEL_IMAGETYPE}${KERNEL_INITRAMFS}-${MACHINE}.bin"
IMAGE_TEGRAFLASH_KERNEL ?= "${DEPLOY_DIR_IMAGE}/${LNXFILE}"
BINARY_INSTALL_PATH = "/opt/tegra-binaries"

OS_KERNEL_CMDLINE = "${@bb.utils.contains('DEVELOPMENT_IMAGE','1','console=ttyTHS0,115200n8 console=tty1 debug loglevel=7','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
OS_KERNEL_CMDLINE = "${@bb.utils.contains('DISTRO_FEATURES','osdev-image','console=ttyTHS0,115200n8 console=tty1 debug loglevel=7','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
ROOTA_ARGS="root=LABEL=resin-rootA ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"
ROOTB_ARGS="root=LABEL=resin-rootB ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"

Expand Down Expand Up @@ -139,6 +139,7 @@ signfile() {
--scr_cold_boot_config tegra194-mb1-bct-scr-cbb-mini-p3668.cfg \
--br_cmd_config tegra194-mb1-bct-reset-p3668-0001-a00.cfg \
--dev_params tegra194-br-bct-qspi.cfg \
--trim_bpmp_dtb \
--bin "${bins}"
}

Expand Down Expand Up @@ -370,6 +371,12 @@ do_configure() {
dd if=${BOOT_BINDIFF} of=boot0.img seek=15101952 skip=18224 bs=1 count=128 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=15405568 skip=18352 bs=1 count=48 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=15560704 skip=18400 bs=1 count=128 conv=notrunc

# Added starting with 32.6.1
dd if=${BOOT_BINDIFF} of=boot0.img seek=31067056 skip=18528 bs=1 count=16 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=31067104 skip=18544 bs=1 count=32 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=31068160 skip=18576 bs=1 count=64 conv=notrunc

}

do_install() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LNXFILE="${KERNEL_IMAGETYPE}${KERNEL_INITRAMFS}-${MACHINE}.bin"
IMAGE_TEGRAFLASH_KERNEL ?= "${DEPLOY_DIR_IMAGE}/${LNXFILE}"
BINARY_INSTALL_PATH = "/opt/tegra-binaries"

OS_KERNEL_CMDLINE = "${@bb.utils.contains('DEVELOPMENT_IMAGE','1','console=ttyTHS0,115200n8 console=tty1 debug loglevel=7','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
OS_KERNEL_CMDLINE = "${@bb.utils.contains('DISTRO_FEATURES','osdev-image','console=ttyTHS0,115200n8 console=tty1 debug loglevel=7','console=null quiet splash vt.global_cursor_default=0 consoleblank=0',d)}"
ROOTA_ARGS="root=LABEL=resin-rootA ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"
ROOTB_ARGS="root=LABEL=resin-rootB ro rootwait rootfstype=ext4 ${KERNEL_ARGS} ${OS_KERNEL_CMDLINE}"

Expand Down Expand Up @@ -140,6 +140,7 @@ signfile() {
--scr_cold_boot_config tegra194-mb1-bct-scr-cbb-mini-p3668.cfg \
--br_cmd_config tegra194-mb1-bct-reset-p3668-0001-a00.cfg \
--dev_params tegra194-br-bct-qspi.cfg \
--trim_bpmp_dtb \
--bin "${bins}"
}

Expand Down Expand Up @@ -176,7 +177,7 @@ do_configure() {
done

for f in ${STAGING_DATADIR}/tegraflash/tegra194-*-bpmp-*.dtb; do
ln -s $f .
cp $f .
cp $f ${DEPLOY_DIR_IMAGE}/bootfiles/
done

Expand Down Expand Up @@ -221,7 +222,6 @@ do_configure() {
# Make bootable image from kernel and sign it
cp ${DEPLOY_DIR_IMAGE}/${LNXFILE} ${LNXFILE}
ln -sf ${STAGING_BINDIR_NATIVE}/tegra186-flash/mkbootimg ./

# mkbootimg really needs initrd, even if empty
touch initrd
./mkbootimg --kernel ${LNXFILE} --ramdisk initrd --board mmcblk0p1 --output boot.img
Expand Down Expand Up @@ -335,7 +335,7 @@ do_configure() {
#dd if=${DEPLOY_DIR_IMAGE}/bootfiles/cbo.dtb seek=33161216 bs=1 conv=notrunc
#dd if=${DEPLOY_DIR_IMAGE}/bootfiles/cbo.dtb seek=33226752 bs=1 conv=notrunc

# For 32.5.1 /opt/tegra-binaries/boot0.img MD5 should have the same MD5
# For 32.6.1 /opt/tegra-binaries/boot0.img MD5 should have the same MD5
# even if building images for compatible carrier boards. If it isn't identical,
# then board won't boot after HUP.
cp ${WORKDIR}/${BOOT_BINDIFF} .
Expand Down Expand Up @@ -367,6 +367,11 @@ do_configure() {
dd if=${BOOT_BINDIFF} of=boot0.img seek=15101952 skip=18224 bs=1 count=128 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=15405568 skip=18352 bs=1 count=48 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=15560704 skip=18400 bs=1 count=128 conv=notrunc

# Needed on 32.6.1
dd if=${BOOT_BINDIFF} of=boot0.img seek=31067056 skip=18528 bs=1 count=16 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=31067104 skip=18544 bs=1 count=32 conv=notrunc
dd if=${BOOT_BINDIFF} of=boot0.img seek=31068160 skip=18576 bs=1 count=64 conv=notrunc
}

do_install() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Mark boot slot as successful once the system is up

[Service]
Type=oneshot
ExecStart=/bin/sh -c /usr/bin/mark_active_tegra_boot_slot.sh

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Ensure reduntant boot is enabled
if /usr/bin/tegra-boot-control -e ; then
echo "Tegra redundant boot: enabled successfully"
else
echo "Tegra redundant boot: failed to enable!"
fi;

# If the boot process was
# able to start the rollback service, we can
# mark the current boot as successful
# Othrwise if not marked, the old kernel
# and dtb slots will be used after 3 attempts
# as per https://forums.developer.nvidia.com/t/failed-bootloader-watchdog-recovery/154380/5
if /usr/bin/tegra-boot-control -m ; then
echo "Tegra redundant boot: marked successful boot"
else
echo "Tegra redundant boot: failed to record successful boot"
fi

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

# libuuid was split from the main
# util-linux later, after Dunfell
DEPENDS:remove = "util-linux-libuuid"
DEPENDS:append = " util-linux"

SRC_URI += " \
file://mark_active_tegra_boot_slot.sh \
file://mark-active-slot.service \
"

# Once redundant boot is enabled, each boot
# needs to be marked as successful once
# the system is up to prevent the tegra
# bootloaders from decrementing boot count
# and reverting to the previous slot. If
# redundant boot is disabled, default slot _a
# is used.
SYSTEMD_PACKAGES += " ${PN}"
SYSTEMD_SERVICE:${PN} += " mark-active-slot.service"

# Upon rollback to a release that does not have
# this feature implemented, the _a slots will
# be used by default, without chaning behavior.
do_install:append() {
install -m 0755 ${WORKDIR}/mark_active_tegra_boot_slot.sh ${D}${bindir}/
install -m 0644 ${WORKDIR}/mark-active-slot.service ${D}${systemd_unitdir}/system/
}

FILES:${PN} += " \
/lib/systemd/system/mark-active-slot.service \
"
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ IMAGE_INSTALL:append:jetson-xavier = " \
tegra-nvpmodel \
tegra-configs-nvstartup \
tegra-configs-udev \
tegra-boot-tools \
"

IMAGE_INSTALL:append:jetson-xavier-nx-devkit-emmc = " \
Expand All @@ -130,6 +131,7 @@ IMAGE_INSTALL:append:jetson-xavier-nx-devkit-emmc = " \
tegra-configs-nvstartup \
tegra-configs-udev \
mtd-utils \
tegra-boot-tools \
"

IMAGE_INSTALL:append:jetson-xavier-nx-devkit = " \
Expand All @@ -145,6 +147,7 @@ IMAGE_INSTALL:append:jetson-xavier-nx-devkit = " \
tegra-wifi \
tegra-firmware-rtl8822 \
tegra-udrm-probeconf \
tegra-boot-tools \
"

IMAGE_INSTALL:append:jetson-tx2 = " \
Expand Down
Loading

0 comments on commit 5789f27

Please sign in to comment.