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

Switch from NVIDIA bootloader tools to tegra-boot-tools #32

Merged
merged 5 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
quiet=
if [ "$1" = "-n" ]; then
quiet="yes"
shift
if [ -z "$1" ]; then
echo "ERR: missing var name with -n" >&2
exit 1
fi
fi
if [ -z "$1" ]; then
echo "mender_boot_part=`tegra-boot-control --current-slot`"
exit 0
fi
while [ -n "$1" ]; do
case "$1" in
mender_boot_part|mender_boot_part_hex)
[ -n "$quiet" ] || echo -n "$1="
tegra-boot-control --current-slot
;;
mender_uboot_separator)
[ -n "$quiet" ] || echo -n "$1="
echo "something other than just 1"
;;
upgrade_available)
[ -n "$quiet" ] || echo -n "$1="
if [ -e "/var/lib/mender/upgrade_available" ]; then
echo "1"
else
echo "0"
fi
;;
*)
echo "ERR: no such variable: $1" >&2
exit 1
esac
shift
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"

RDEPENDS_${PN} += "tegra-boot-tools"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
slotsfx=""
mayberoot=""
for bootarg in `cat /proc/cmdline`; do
case "$bootarg" in
boot.slot_suffix=*) slotsfx="${bootarg##boot.slot_suffix=}" ;;
root=*) mayberoot="${bootarg##root=}" ;;
ro) opt="ro" ;;
rootwait) wait="yes" ;;
esac
done
rootdev=`blkid -l -t PARTLABEL=APP$slotsfx | cut -d: -f1`
if [ -z "$rootdev" ]; then
if [ -n "$mayberoot" ]; then
rootdev="$mayberoot"
else
rootdev="/dev/mmcblk0p1"
fi
fi

if which bootcountcheck >/dev/null 2>&1; then
bootcountcheck
fi

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"

EXTRADEPS = ""
EXTRADEPS_tegra = "tegra-boot-tools-earlyboot"
EXTRADEPS_tegra210 = ""
RDEPENDS_${PN} += "${EXTRADEPS}"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXTRADEPS = ""
EXTRADEPS_tegra = "tegra-boot-tools"
EXTRADEPS_tegra = "tegra-boot-tools tegra-boot-tools-nvbootctrl tegra-boot-tools-lateboot"
EXTRADEPS_tegra210 = ""
RDEPENDS_${PN} += "${EXTRADEPS}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

LABELCHARS="AB"

echo "Verifying Tegra bootloader update"
curslot=`tegra-boot-control --current-slot`
cfglbl="\"RootfsPart${LABELCHARS:$curslot:1}\""
devnam=`grep -h "$cfglbl:" /etc/mender/mender.conf /var/lib/mender/mender.conf | cut -d: -f2 | cut -d, -f1 | tr -d '" '`
if [ -z "$devnam" ]; then
echo "ERR: could not determine expected mender device name for boot slot $curslot" >&2
exit 1
fi

# If the rootfs partitions are eMMC/SDcard device names, verify that
# the mender boot partition in U-Boot and the Tegra bootloader boot
# slot match. If not, the Tegra bootloader update failed, and we
# need to reset the boot slot to get the Tegra bootloader and Mender
# resynchronized.
if [ "${devnam##/dev/mmcblk}" != "${devnam}" ]; then
bootpart=`fw_printenv -n mender_boot_part`
if [ -z "$bootpart" ]; then
echo "ERR: could not retrieve mender_boot_part from U-Boot env" >&2
exit 1
fi
devnampart=`expr "${devnam##/dev/mmcblk*p}" \+ 0 2>/dev/null`
if [ -z "$devnampart" ]; then
echo "ERR: could not extract partition number from rootfs device name" >&2
exit 1
fi
if [ $bootpart -ne $devnampart ]; then
altslot=$(expr 1 - $curslot)
echo "Detected Tegra bootloader upgrade failure, resetting boot slot to $altslot" >&2
echo "*** Reboot required ***" >&2
tegra-boot-control --set-active $altslot
exit 1
fi
fi
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY_MACHINE_ID=@COPY_MACHINE_ID@

cleanup() {
[ -n "$mnt" ] || return
for d in sys proc dev run; do
for d in sys proc dev; do
if mountpoint -q "${mnt}/${d}"; then
umount "${mnt}/${d}" >/dev/null 2>&1 || true
fi
Expand All @@ -19,16 +19,11 @@ cleanup() {

echo "Installing NVIDIA bootloader update payload"

num_slots=`nvbootctrl get-number-slots`
if [ $num_slots != 2 ]; then
echo "Enabling A/B update mode using nv_update_engine"
nv_update_engine --enable-ab
if [ ! "$?" -eq 0 ]; then
echo "ERR: could not enable A/B update by using nv_update_engine" >&2
exit 1
fi
if which tegra-boot-control >/dev/null 2>&1; then
current_slot=`tegra-boot-control --current-slot`
else
current_slot=`nvbootctrl get-current-slot`
fi
current_slot=`nvbootctrl get-current-slot`
echo "Current boot slot: $current_slot"
otherslot=`expr 1 - $current_slot`
cfglbl="\"RootfsPart${LABELCHARS:$otherslot:1}\""
Expand All @@ -48,23 +43,12 @@ if [ ! -d "${mnt}/opt/ota_package" ]; then
cleanup
exit 1
fi
# nv_update_engine needs access to these filesystems,
# tegra-bootloader-update needs access to these filesystems,
# so bind-mount them into the new rootfs for the chroot
mount --bind /sys "${mnt}/sys"
mount --bind /proc "${mnt}/proc"
mount --bind /dev "${mnt}/dev"
mount -t tmpfs tmpfs "${mnt}/run"
# Run the update engine in the context of the just-installed rootfs
# to ensure that the TNSPEC in the config file it uses matches the
# TNSPEC in the update payload. But first we have to set up the
# configuration file with the TNSPEC.
if [ -L "${mnt}/etc/nv_boot_control.conf" -a -x "${mnt}/usr/bin/setup-nv-boot-control" ]; then
mkdir -p "${mnt}/run/tegra-nv-bootctrl"
if ! chroot "${mnt}" /usr/bin/setup-nv-boot-control; then
echo "ERR: could not initialize nv_boot_control.conf in new rootfs" >&2
fi
fi
if ! chroot "${mnt}" /usr/sbin/nv_update_engine --install no-reboot; then
if ! chroot "${mnt}" /usr/bin/tegra-bootloader-update /opt/ota_package/bl_update_payload; then
echo "ERR: bootloader update failed" >&2
cleanup
exit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

mnt=

cleanup() {
[ -n "$mnt" ] || return
for d in sys proc dev; do
if mountpoint -q "${mnt}/${d}"; then
umount "${mnt}/${d}" >/dev/null 2>&1 || true
fi
done
if mountpoint -q "$mnt"; then
umount "$mnt" >/dev/null 2>&1 || true
fi
rmdir "$mnt" >/dev/null 2>&1 || true
}

echo "Installing NVIDIA bootloader update payload"

new_boot_part=`fw_printenv -n mender_boot_part`
mnt=`mktemp -d -t nvbup.XXXXXX`
if [ -z "$mnt" -o ! -d "$mnt" ]; then
echo "ERR: could not create directory for mounting install partition" >&2
exit 1
fi
mount /dev/mmcblk0p${new_boot_part} "$mnt"
if [ ! -d "${mnt}/opt/ota_package" ]; then
echo "ERR: Missing /opt/ota_package directory in installed rootfs" >&2
cleanup
exit 1
fi
# tegra-bootloader-update needs access to these filesystems,
# so bind-mount them into the new rootfs for the chroot
mount --bind /sys "${mnt}/sys"
mount --bind /proc "${mnt}/proc"
mount --bind /dev "${mnt}/dev"
if ! chroot "${mnt}" /usr/bin/tegra-bootloader-update /opt/ota_package/bl_update_payload; then
echo "ERR: bootloader update failed" >&2
cleanup
exit 1
fi
echo "Successful bootloader update"
cleanup
exit 0
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI_remove = "file://redundant-boot-rollback-script-uboot"

copy_install_script() {
sed -e's,@COPY_MACHINE_ID@,${PERSIST_MACHINE_ID},' ${S}/redundant-boot-install-script > ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_80_bl-update
}

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-commit-check-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactCommit_Enter_80_bl-check-update
}

copy_other_scripts() {
:
}

do_compile_tegra210() {
cp ${S}/redundant-boot-install-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_80_bl-update
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RDEPENDS_${PN}_remove = "tegra-redundant-boot"
RDEPENDS_${PN}_append = " tegra-boot-tools-updater"