Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tegra: Add support for commit service and verifying root and boot slot alignment #1

Open
wants to merge 5 commits into
base: dunfell
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
dwalkes marked this conversation as resolved.
Show resolved Hide resolved
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
}