Possible rootfs-version-check bug

We’re using rootfs-version-check but we have problems with getting INCONSISTENT updates and rollbacks.

I’m looking at https://raw.githubusercontent.com/mendersoftware/mender-update-modules/master/rootfs-version-check/module/rootfs-version-check

It appears that it forgets to set mender_boot_part_hex to $passive_num in ArtifactInstall and ArtifactRollback. Does anyone know if this is in fact a bug? I know drew wrote this script so I’m tagging him here: @drewmoseley

#!/bin/sh

set -ue

# Is expected to contain two variable definitions with device paths:
# - MENDER_ROOTFS_PART_A
# - MENDER_ROOTFS_PART_B
. /etc/mender/rootfs-version-check.conf

MENDER_ROOTFS_PART_A_NUMBER="$(echo "$MENDER_ROOTFS_PART_A" | egrep -o '[0-9]+$')"
MENDER_ROOTFS_PART_B_NUMBER="$(echo "$MENDER_ROOTFS_PART_B" | egrep -o '[0-9]+$')"

active_num="$(fw_printenv mender_boot_part)"
active_num="${active_num#mender_boot_part=}"
if test $active_num -eq $MENDER_ROOTFS_PART_A_NUMBER; then
    passive=$MENDER_ROOTFS_PART_B
    passive_num=$MENDER_ROOTFS_PART_B_NUMBER
else
    passive=$MENDER_ROOTFS_PART_A
    passive_num=$MENDER_ROOTFS_PART_A_NUMBER
fi

compare_versions_or_exit() {
    local COMPARE_VERSIONS="/usr/share/mender/utils/mender-compare-versions"

    if [ ! -x "${COMPARE_VERSIONS}" ]; then
        echo "Unable to locate mender-compare-versions executable."
        exit 1
    fi
    # This script needs to be provided by the integrator and customized specifically for their naming scheme.
    if ! "${COMPARE_VERSIONS}" "$(cat header/artifact_name)" "$(cat current_artifact_name)"; then
        echo "Refusing to install $(cat header/artifact_name) over current version $(cat current_artifact_name)."
        exit 1
    fi

    echo "Allowing installation of $(cat header/artifact_name) over current version $(cat current_artifact_name)."
}

case "$1" in
    Download)
        compare_versions_or_exit
        file="$(cat stream-next)"
        cat "$file" > $passive
        if [ "$(cat stream-next)" != "" ]; then
            echo "More than one file in payload"
            exit 1
        fi
        ;;

    ArtifactInstall)
        fw_setenv -s - <<EOF
mender_boot_part $passive_num
upgrade_available 1
bootcount 0
EOF
        ;;

    PerformsFullUpdate)
        echo "Yes"
        ;;

    NeedsArtifactReboot)
        echo "Automatic"
        ;;

    SupportsRollback)
        echo "Yes"
        ;;

    ArtifactVerifyReboot)
        if test "$(fw_printenv upgrade_available)" != "upgrade_available=1"; then
            exit 1
        fi
        ;;

    ArtifactVerifyRollbackReboot)
        if test "$(fw_printenv upgrade_available)" = "upgrade_available=1"; then
            exit 1
        fi
        ;;

    ArtifactCommit)
        compare_versions_or_exit
        fw_setenv upgrade_available 0
        ;;

    ArtifactRollback)
        if test "$(fw_printenv upgrade_available)" = "upgrade_available=1"; then
            fw_setenv -s - <<EOF
mender_boot_part $passive_num
upgrade_available 0
EOF
        fi
        ;;
esac
exit 0

Wow. Yes, that does seem like a miss in this script. Do you have a reliable enough reproduction scenario where you can modify the script, test and submit a PR?

cc @Alan @lramirez

Drew

I’ve currently got a fix in ArtifactInstall_Leave_99 that uses uboot’s uEnv.txt file to reset mender_boot_part_hex to be mender_boot_part. I could potentially remove that fix and then fix the rootfs_version_check script and see what goes wrong. This fix has worked for successful upgrades but I get INCONSISTENT on my devices when there is a rollback.

Setting mender_boot_part_hex to mender_boot_part will work on devices like the Technexion pico-pi imx6ull that we’re using but it may be a problem on devices with enough partitions to have mender_boot_part_hex be different than mender_boot_part

I think I can test the script and submit a PR

I tested the fixed script in our baseline and got no INCONSISTENT errors where I would have expected them. I’ve put in a PR to the original repository. https://github.com/mendersoftware/mender-update-modules/pull/20