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

Nvidia Jestson JetPack 5.x rootfs slot A/B update #352

Closed
Closed
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
4 changes: 4 additions & 0 deletions meta-mender-tegra/classes/tegra-mender-setup.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ PREFERRED_PROVIDER_u-boot-fw-utils = "u-boot-fw-utils-tegra"
PREFERRED_PROVIDER_libubootenv:tegra = "${@'libubootenv-fake' if d.getVar('PREFERRED_PROVIDER_virtual/bootloader').startswith('cboot') else 'libubootenv'}"
PREFERRED_RPROVIDER_u-boot-fw-utils = "u-boot-fw-utils-tegra"
PREFERRED_RPROVIDER_libubootenv-bin:tegra = "${@'libubootenv-fake' if d.getVar('PREFERRED_PROVIDER_virtual/bootloader').startswith('cboot') else 'libubootenv-bin'}"
PREFERRED_PROVIDER_libubootenv:tegra234 = "libubootenv-fake"

# Note: this isn't really a boot file, just put it here to keep the mender build from
# complaining about empty IMAGE_BOOT_FILES. We won't use the full image anyway, just the mender file
IMAGE_BOOT_FILES = "u-boot-dtb.bin"
Expand All @@ -48,12 +50,14 @@ MENDER_DATA_PART_NUMBER_DEFAULT:tegra194 = "43"
MENDER_DATA_PART_NUMBER_DEFAULT:tegra210 = "${@'16' if (d.getVar('TEGRA_SPIFLASH_BOOT') or '') == '1' else '23'}"
MENDER_DATA_PART_NUMBER_DEFAULT:jetson-nano-emmc = "19"
MENDER_DATA_PART_NUMBER_DEFAULT:xavier-nx = "12"
MENDER_DATA_PART_NUMBER_DEFAULT:tegra234 = "16"
MENDER_ROOTFS_PART_A_NUMBER_DEFAULT = "1"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:tegra186 = "33"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:tegra194 = "42"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:tegra210 = "${@'15' if (d.getVar('TEGRA_SPIFLASH_BOOT') or '') == '1' else '22'}"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:jetson-nano-emmc = "18"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:xavier-nx = "11"
MENDER_ROOTFS_PART_B_NUMBER_DEFAULT:tegra234 = "2"

# Machine name and flash layout changed for SDcard Nanos in L4T R32.5.x
MENDER_DATA_PART_NUMBER_DEFAULT:jetson-nano-devkit = "3"
Expand Down
7 changes: 7 additions & 0 deletions meta-mender-tegra/conf/layer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ BBFILE_PRIORITY_meta-mender-tegra = "10"
LAYERVERSION_meta-mender-tegra = "1"
LAYERSERIES_COMPAT_meta-mender-tegra = "kirkstone"
LAYERDEPENDS_meta-mender-tegra = "tegra"

BBMASK:tegra234:append = " \
recipes-bsp/cboot/ \
recipes-bsp/u-boot/patches \
recipes-bsp/u-boot/libubootenv_.* \
recipes-bsp/u-boot/u-boot.* \
"

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
RDEPENDS:${PN} += "tegra-redundant-boot-nvbootctrl"
# RDEPENDS:${PN} += "tegra-redundant-boot-nvbootctrl"
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXTRADEPS = "redundant-boot-overrides"
EXTRADEPS:tegra210 = ""
EXTRADEPS:tegra234 = ""
RDEPENDS:${PN} += "${EXTRADEPS}"

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
RDEPENDS:${PN}:remove = "tegra-redundant-boot"
RDEPENDS:${PN}:append = " tegra-boot-tools-updater"
# RDEPENDS:${PN}:append = " tegra-boot-tools-updater"
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ PACKAGE_ARCH = "${MACHINE_ARCH}"

RPROVIDES:${PN} += "libubootenv-bin u-boot-fw-utils"
RDEPENDS:${PN} = "tegra-boot-tools"
RDEPENDS:${PN}:tegra234 = ""
RCONFLICTS:${PN} = "libubootenv-bin"
RREPLACES:${PN} = "libubootenv-bin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRC_URI += "file://0007-runtime-access-for-KernelCommandLine-efivar.patch;patchdir=.."
SRC_URI += "file://0008-enable-rootfs-redundancy.patch;patchdir=.."


Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigDxe.c edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigDxe.c
index 90e515ae..a00efb6c 100644
--- edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigDxe.c
+++ edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigDxe.c
@@ -133,7 +133,7 @@ InitializeSettings (
if (KernelCmdLineLen < sizeof (CmdLine)) {
KernelCmdLineLen = sizeof (CmdLine);
ZeroMem (&CmdLine, KernelCmdLineLen);
- Status = gRT->SetVariable (L"KernelCommandLine", &gNVIDIAPublicVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, KernelCmdLineLen, (VOID *)&CmdLine);
+ Status = gRT->SetVariable (L"KernelCommandLine", &gNVIDIAPublicVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, KernelCmdLineLen, (VOID *)&CmdLine);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Error setting command line variable %r\r\n", __FUNCTION__, Status));
}
diff --git edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigHii.vfr edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigHii.vfr
index dbc26647..58c9aa91 100644
--- edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigHii.vfr
+++ edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Drivers/NvidiaConfigDxe/NvidiaConfigHii.vfr
@@ -58,7 +58,7 @@ formset
guid = NVIDIA_TOKEN_SPACE_GUID;

efivarstore NVIDIA_KERNEL_COMMAND_LINE,
- attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, // EFI variable attributes
+ attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS, // EFI variable attributes
name = KernelCommandLine,
guid = NVIDIA_PUBLIC_VARIABLE_GUID;

diff --git edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Library/PlatformBootManagerLib/PlatformBm.c edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Library/PlatformBootManagerLib/PlatformBm.c
index a3fb49d6..f642b433 100644
--- edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Library/PlatformBootManagerLib/PlatformBm.c
+++ edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Library/PlatformBootManagerLib/PlatformBm.c
@@ -1023,7 +1023,7 @@ IsPlatformConfigurationNeeded (
AddlCmdLen = sizeof (AddlCmdLine);
Status = gRT->GetVariable (L"KernelCommandLine", &gNVIDIAPublicVariableGuid, &AddlCmdLineAttributes, &AddlCmdLen, &AddlCmdLine);
if (EFI_ERROR (Status)) {
- AddlCmdLineAttributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+ AddlCmdLineAttributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
ZeroMem (&AddlCmdLine, sizeof (AddlCmdLine));
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Tegra/DeviceTree/L4TConfiguration.dts edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Tegra/DeviceTree/L4TConfiguration.dts
index 2c619e21..b254ae76 100644
--- edk2-tegra.a/edk2-nvidia/Silicon/NVIDIA/Tegra/DeviceTree/L4TConfiguration.dts
+++ edk2-tegra.b/edk2-nvidia/Silicon/NVIDIA/Tegra/DeviceTree/L4TConfiguration.dts
@@ -37,7 +37,7 @@
locked;
};
RootfsRedundancyLevel {
- data = [00 00 00 00];
+ data = [01 00 00 00];
runtime;
locked;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
EXTRADEPS = ""
EXTRADEPS:tegra = "tegra-boot-tools-earlyboot"
EXTRADEPS:tegra210 = ""
EXTRADEPS:tegra234 = ""
RDEPENDS:${PN} += "${EXTRADEPS}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh

function to_unicode() {
local in="$1"
local out

for (( i=0; i<${#in}; i++)); do
char=${in:i:1}
out+="$char"
out+="\x00"
done
echo -n "$out"
}


function fill_to_size() {
local size="$2"
local out="$1"
local fill_size=$(( $size - (${#out}*2/5) ))

for i in $(seq $fill_size)
do
out+="\x00"
done

echo -n "$out"
}


function write_efivar() {
local readonly varname="781e084c-a330-417c-b678-38e696380cb9-KernelCommandLine"
local readonly total_size=514
local readonly attr_size=4
local readonly data_size=$(( $total_size - $attr_size))
local in="$1"

#printf "\nin=$in\n"
local out="$(to_unicode "$in")"
out="$(fill_to_size "$out" $data_size)"

local f=$(mktemp)
printf "$out" > $f
efivar -n $varname -f $f -w
rm ${f}
}

function read_efivar() {
local readonly varname="/sys/firmware/efi/efivars/KernelCommandLine-781e084c-a330-417c-b678-38e696380cb9"
local var=$(cat $varname | tail -c +4 | tr -d '[\000]')

echo -n "$var"
}


function read_efi_machine_id() {
local var=$(read_efivar)
local id

for i in $var; do
case $i in
systemd.machine_id=*)
id="${i#*=}"
;;
*)
;;
esac
done
echo -n "$id"
}


function write_efi_machine_id() {
local id="$1"
local var=$(read_efivar)
local out_var
local sep=""
local id_mod=false

for i in $var; do
out_var+="$sep"
case $i in
systemd.machine_id=*)
out_var+="systemd.machine_id=$id"
id_mod=true
;;
*)
out_var+="$i"
;;
esac
sep=" "
done

if [ "$id_mod" = false ] ; then
out_var+="${sep}systemd.machine_id=$id"
fi

write_efivar "$out_var"
}


usage="Usage: efi_systemd_machine_id.sh [-r] [-w val]"

while getopts "rw:" opt; do
case ${opt} in
r )
printf "$(read_efi_machine_id)\n"
;;
w )
write_efi_machine_id $OPTARG
;;
\? )
echo "$usage";exit 2
;;
esac
done


if [ $OPTIND -eq 1 ]; then
echo "$usage"; exit 1
fi








Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -eu

BOOTENV_PRINT="efi_systemd_machine_id.sh -r"
BOOTENV_SET="efi_systemd_machine_id.sh -w"

CURRENT_BOOTLOADER_ID=$($BOOTENV_PRINT 2>/dev/null | cut -d= -f2)
CURRENT_SYSTEMD_ID=$(cat /etc/machine-id)

rc=0
if [ -z "${CURRENT_BOOTLOADER_ID}" ] && [ ! -z "${CURRENT_SYSTEMD_ID}" ]; then
$BOOTENV_SET "${CURRENT_SYSTEMD_ID}"
rc=$?
elif [ "${CURRENT_BOOTLOADER_ID}" != "${CURRENT_SYSTEMD_ID}" ]; then
echo "Error; bootloader and systemd disagree on machine-id." >&2
rc=1
fi

exit $rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
EXTRADEPS = ""
EXTRADEPS:tegra = "tegra-bup-payload tegra-boot-tools tegra-boot-tools-nvbootctrl tegra-boot-tools-lateboot${@' libubootenv-fake' if d.getVar('PREFERRED_PROVIDER_virtual/bootloader').startswith('cboot') else ''}"
EXTRADEPS:tegra210 = "tegra-bup-payload tegra-boot-tools"
EXTRADEPS:jetson-agx-orin-devkit = "tegra-bup-payload libubootenv-fake"
RDEPENDS:${PN} += "${EXTRADEPS}"

FILESEXTRAPATHS:prepend:tegra234 := "${THISDIR}/files/tegra234:"

SRC_URI:remove:mender-persist-systemd-machine-id = " \
file://mender-client-set-systemd-machine-id.sh \
"
SRC_URI:append:tegra234:mender-persist-systemd-machine-id = " \
file://tegra234-mender-client-set-systemd-machine-id.sh \
file://efi_systemd_machine_id.sh \
"

do_install:prepend:tegra234:class-target:mender-persist-systemd-machine-id() {
install -d -m 755 ${D}${bindir}
install -m 755 ${WORKDIR}/efi_systemd_machine_id.sh ${D}${bindir}/
cp ${WORKDIR}/tegra234-mender-client-set-systemd-machine-id.sh ${WORKDIR}/mender-client-set-systemd-machine-id.sh
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
echo "$(mender show-artifact): $(basename "$0") was called!" >&2

get_bootpart() {
local current_slot=`nvbootctrl get-current-slot 2>/dev/null`
if [ -z "$current_slot" ]; then
echo "ERR: could not identify current boot slot" >&2
echo "UNKNOWN"
return
fi
echo "$current_slot"
}

current_slot=`get_bootpart`
echo "current_slot=$current_slot" >&2

next_slot=
if [ $current_slot = "0" ]; then
next_slot="1"
else
next_slot="0"
fi

echo "next_slot=$next_slot" >&2
nvbootctrl set-active-boot-slot $next_slot
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SRC_URI = " \
file://redundant-boot-commit-check-script-uboot \
file://redundant-boot-install-script \
file://redundant-boot-install-script-uboot \
file://switch-rootfs \
"

LICENSE = "Apache-2.0"
Expand Down Expand Up @@ -43,6 +44,10 @@ do_compile:tegra210() {
cp ${S}/redundant-boot-install-script-uboot ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_80_bl-update
}

do_compile:tegra234() {
cp ${S}/switch-rootfs ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_50_switch-rootfs
}

# Make sure scripts aren't left around from old builds
do_deploy:prepend() {
rm -rf ${DEPLOYDIR}/mender-state-scripts
Expand Down