Skip to content

Commit

Permalink
Adding scripts 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 and will run as a one shot service.
  • Loading branch information
Siddhant Jajoo committed Nov 7, 2020
1 parent 1683cf7 commit 98e373c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
19 changes: 19 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,19 @@
#!/bin/sh

echo "Starting mender wrapper"

echo $@ | grep 'install\|-install' > /dev/null
if [ $? -eq 0 ]; then
/etc/mender/verify-boot-rootfs-slot-alignment-uboot || exit 1
fi

mender_override $@

rc=$?
if [ $rc -eq 0 ]; then
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,11 @@
[Unit]
Description=Automatic Mender Commit Service
After=mender-client.service

[Service]
ExecStart=/etc/mender/mender-client-commit.sh
Type=oneshot
StandardOutput=journal+console

[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 || exit 0

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
@@ -0,0 +1,56 @@
#!/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 "RootfsPart" /etc/mender/mender.conf /var/lib/mender/mender.conf | grep ${mender_boot_partition} | 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 in case priorities are equal
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
elif [ $priority_slot0 -gt $priority_slot1 ]; then
nvbootctrl_slot=0
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!!!!! *********************"
echo "Partition mismatch for boot and rootfs on reboot"
echo "mender boot slot: ${mender_boot_slot}"
echo "nvbootctrl slot: ${nvbootctrl_slot}"
echo "Setting the current nvbootctrl slot manually to the value of mender boot slot"
nvbootctrl set-active-boot-slot ${mender_boot_slot}

echo "********************* WARNING!!!!! *********************"
echo "Dumping partition information"
echo `nvbootctrl get-current-slot`
echo `nvbootctrl dump-slots-info`
echo `fw_printenv -n mender_boot_part`

echo "********************* WARNING!!!!! *********************"
echo "Disabling mender-client systemd service to prevent any more updates"
systemctl stop mender-client

echo "Reboot the device to set the active slot before proceeding for a mender -install or mender -commit"
exit 1
else
echo "Verified"
fi

exit 0
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
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_append_mender-uboot = " \
file://mender \
file://mender-client-commit.service \
file://mender-client-commit.sh \
file://verify-boot-rootfs-slot-alignment-uboot \
"

FILES_${PN}_append_mender-uboot = " ${systemd_system_unitdir}/mender-client-commit.service"
FILES_${PN}_append_mender-uboot = " ${sysconfdir}/mender/mender-client-commit.sh"
FILES_${PN}_append_mender-uboot = " ${bindir}/mender"
FILES_${PN}_append_mender-uboot = " ${sysconfdir}/mender/verify-boot-rootfs-slot-alignment-uboot"

SYSTEMD_SERVICE_${PN}_append_mender-uboot = " 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
install -m 0755 ${WORKDIR}/verify-boot-rootfs-slot-alignment-uboot ${D}${sysconfdir}/mender/verify-boot-rootfs-slot-alignment-uboot
}

0 comments on commit 98e373c

Please sign in to comment.