Skip to content

Commit

Permalink
Adding mender tegra-state-script to align boot and rootfs partition
Browse files Browse the repository at this point in the history
The mender boot slot values are not in sync with nvbootctrl slot values. The values are updated correctly in the mender_boot_part variable,
but the nvbootctrl fails to sync up with the latest boot partition to use on the next reboot after a mender update sometimes.

This commit would rectify the issue by identifying the mismatch and giving a Warning and dumping all the data for debug.
At the same time it would set the active boot partition based on the value in mender_boot_partition, so that there is no mismatch going forward.
This script would run after every mender update.
  • Loading branch information
Siddhant Jajoo committed Nov 6, 2020
1 parent 1683cf7 commit d47757d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
12 changes: 12 additions & 0 deletions meta-mender-tegra/recipes-mender/mender-client/files/mender
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

echo "Starting mender wrapper"
mender_override $@

rc=$?
if [ $rc -eq 0 ]; then
if [ $1 = "install" || $1 = "-install" ]; then

This comment has been minimized.

Copy link
@dwalkes

dwalkes Nov 6, 2020

@jajoosiddhant In think install can be after global options, so it would probably be better to grep for " install " or " -install ", so I think you could use:

echo $@ | grep  ' install \| -install ' > /dev/null
if [ $? -eq 0 ]; then
touch /var/lib/mender/mender-install-success
fi
fi

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Automatice Mender Commit Service
After=basic.target

[Service]
ExecStart=/etc/mender/mender-client-commit.sh
Type=oneshot

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

/etc/mender/verify-boot-rootfs-slot-alignment-uboot

if [ -f /var/lib/mender/mender-install-success ]; then
/usr/bin/mender -commit
rc=$?
if [ $rc -eq 0 ]; then
rm /var/lib/mender/mender-install-success
fi
fi
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
RDEPENDS_${PN}_append_tegra = "${@' tegra-bup-payload libubootenv-fake' if d.getVar('PREFERRED_PROVIDER_virtual/bootloader').startswith('cboot') else ''}"

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
file://mender \
file://mender-client-commit.service \
file://mender-client-commit.sh \
"

FILES_${PN} += "${systemd_system_unitdir}/mender-client-commit.service"
FILES_${PN} += "${sysconfdir}/mender/mender-client-commit.sh"
FILES_${PN} += "${bindir}/mender"

SYSTEMD_SERVICE_${PN} = "mender-client-commit.service"

do_install_append_mender-uboot() {
mv ${D}${bindir}/mender ${D}${bindir}/mender_override
install -m 0755 ${WORKDIR}/mender ${D}${bindir}/mender
install -d ${D}${sysconfdir}/mender/scripts
install -m 0755 ${WORKDIR}/mender-client-commit.sh ${D}${sysconfdir}/mender/mender-client-commit.sh
install -m 0644 ${WORKDIR}/mender-client-commit.service ${D}${systemd_system_unitdir}/mender-client-commit.service
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

echo "Verify if nvbootctrl slot matches rootfs partition"

# This variable will be populated with the partition number to boot from
mender_boot_partition=`fw_printenv -n mender_boot_part`
devnam=`grep -h "$mender_boot_partition" /etc/mender/mender.conf /var/lib/mender/mender.conf | tr -d '" ' | sed "s/RootfsPart//" | cut -f1 -d":"`

# Fetching corresponding boot slot
if [ $devnam = A ]; then
mender_boot_slot=0
elif [ $devnam = B ]; then
mender_boot_slot=1
fi

# Have default value here
nvbootctrl_slot=`nvbootctrl get-current-slot`
priority_slot0=`nvbootctrl dump-slots-info | grep 'priority' | awk 'FNR == 1 {print $4}' | cut -d ',' -f 1`
priority_slot1=`nvbootctrl dump-slots-info | grep 'priority' | awk 'FNR == 2 {print $4}' | cut -d ',' -f 1`

# Determining the boot slot that would be used after reboot
# Whichever boot slot would have the higher priority, that would be used in the next boot.
if [ $priority_slot1 -gt $priority_slot0 ]; then
nvbootctrl_slot=1
fi

# Checking if the mender and nvbootctrl align to the same boot slots
# if not set nvbootctrl active boot slot sane as mender_boot_slot
# Dumping Warning prints to stderr since mender state scripts logs only read stderr.
if [ $mender_boot_slot -ne $nvbootctrl_slot ]; then
echo "********************* WARNING!!!!! *********************" >&2
echo "Partition mismatch for boot and rootfs on reboot" >&2
echo "mender boot slot: ${mender_boot_slot}" >&2
echo "nvbootctrl slot: ${nvbootctrl_slot}" >&2
echo "Setting the current nvbootctrl slot manually to the value of mender boot slot" >&2
nvbootctrl set-active-boot-slot ${mender_boot_slot}

echo "Dumping partition information" >&2
echo `nvbootctrl get-current-slot` >&2
echo `nvbootctrl dump-slots-info` >&2
echo `fw_printenv -n mender_boot_part` >&2

echo "Rebooting the device to set the active slot before proceeding for an update" >&2
echo "Entire process would be required again to mender update"
reboot
fi

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SRC_URI = " \
file://redundant-boot-rollback-script \
file://redundant-boot-rollback-script-uboot \
file://redundant-boot-rollback-reboot-script \
file://redundant-boot-install-script-uboot-check-boot-partition \
"

LICENSE = "Apache-2.0"
Expand All @@ -31,6 +32,7 @@ copy_install_script_mender-uboot() {
cp ${S}/redundant-boot-install-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_80_bl-update
cp ${S}/redundant-boot-rollback-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactRollback_Leave_80_bl-rollback
cp ${S}/redundant-boot-commit-check-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactCommit_Enter_80_bl-check-update
cp ${S}/redundant-boot-install-script-uboot-check-boot-partition ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Enter_90_check-boot-partition
}

copy_other_scripts() {
Expand Down Expand Up @@ -60,4 +62,10 @@ do_deploy_prepend() {
rm -rf ${DEPLOYDIR}/mender-state-scripts
}

FILES_${PN} += "${sysconfdir}/mender/verify-boot-rootfs-slot-alignment-uboot"
do_install_append_mender-uboot() {
install -d -m 755 ${D}${sysconfdir}/mender/scripts/
install -m 755 ${S}/redundant-boot-install-script-uboot-check-boot-partition ${D}${sysconfdir}/mender/verify-boot-rootfs-slot-alignment-uboot
}

PACKAGE_ARCH = "${MACHINE_ARCH}"

0 comments on commit d47757d

Please sign in to comment.