diff --git a/meta-mender-tegra/recipes-mender/mender-client/files/mender b/meta-mender-tegra/recipes-mender/mender-client/files/mender new file mode 100644 index 00000000..4f213bed --- /dev/null +++ b/meta-mender-tegra/recipes-mender/mender-client/files/mender @@ -0,0 +1,12 @@ +#!/bin/sh + +echo "Starting mender wrapper" +mender_override $@ + +rc=$? +if [ $rc -eq 0 ]; then + if [ $1 = "install" || $1 = "-install" ]; then + touch /var/lib/mender/mender-install-success + fi +fi + diff --git a/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.service b/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.service new file mode 100644 index 00000000..c9a25274 --- /dev/null +++ b/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.service @@ -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 diff --git a/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.sh b/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.sh new file mode 100644 index 00000000..73d4d7b1 --- /dev/null +++ b/meta-mender-tegra/recipes-mender/mender-client/files/mender-client-commit.sh @@ -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 diff --git a/meta-mender-tegra/recipes-mender/mender-client/mender-client_%.bbappend b/meta-mender-tegra/recipes-mender/mender-client/mender-client_%.bbappend index b8aa365f..eb9acfe2 100644 --- a/meta-mender-tegra/recipes-mender/mender-client/mender-client_%.bbappend +++ b/meta-mender-tegra/recipes-mender/mender-client/mender-client_%.bbappend @@ -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 +} diff --git a/meta-mender-tegra/recipes-mender/tegra-state-scripts/files/redundant-boot-install-script-uboot-check-boot-partition b/meta-mender-tegra/recipes-mender/tegra-state-scripts/files/redundant-boot-install-script-uboot-check-boot-partition new file mode 100644 index 00000000..bfb0ff53 --- /dev/null +++ b/meta-mender-tegra/recipes-mender/tegra-state-scripts/files/redundant-boot-install-script-uboot-check-boot-partition @@ -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 + diff --git a/meta-mender-tegra/recipes-mender/tegra-state-scripts/tegra-state-scripts_1.0.bb b/meta-mender-tegra/recipes-mender/tegra-state-scripts/tegra-state-scripts_1.0.bb index 59317617..692e5a97 100644 --- a/meta-mender-tegra/recipes-mender/tegra-state-scripts/tegra-state-scripts_1.0.bb +++ b/meta-mender-tegra/recipes-mender/tegra-state-scripts/tegra-state-scripts_1.0.bb @@ -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" @@ -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() { @@ -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}"