Skip to content

Commit a30b208

Browse files
authored
Merge pull request #1031 from YoeDistro/kraj/master
Fix ESP partition updates in swupdate on tegra
2 parents 3c51f06 + 82a4531 commit a30b208

File tree

12 files changed

+187
-80
lines changed

12 files changed

+187
-80
lines changed

conf/site.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ require ${TOPDIR}/conf/projects/${PROJECT}/config.conf
1111
#YOE_PROFILE = "yoe-musl-systemd-wayland"
1212
#require conf/world.conf
1313

14-
IMG_VERSION = "25.04.2"
14+
IMG_VERSION = "25.04.3"
1515

1616
#INHERIT += "cve-check"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
inherit l4t_version
2+
3+
# Set to "true" to use logic which only installs the bootloader
4+
# when a change in L4T_VERSION is found between current and target rootfs
5+
TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT ?= "false"
6+
7+
8+
# The version written into the sw-versions file for the
9+
# bootloader update capsule, used to control bootloader
10+
# updates when TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT is "true"
11+
# Can be set to anything, but ideally would match the value
12+
# used for get_hex_bsp_version in tegra-uefi-capsule-signing.bbclass
13+
# to support comparisons with runtime checks of version in
14+
# /sys/firmware/efi/esrt/entries/entry0/fw_version
15+
TEGRA_SWUPDATE_BOOTLOADER_VERSION ?= "${L4T_VERSION}"
16+
17+
18+
TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH ?= "/boot/efi/EFI/UpdateCapsule/TEGRA_BL.Cap"

sources/meta-yoe/classes/bec-image.bbclass

Lines changed: 0 additions & 43 deletions
This file was deleted.

sources/meta-yoe/dynamic-layers/swupdate/recipes-core/images/files/tegra/bootloader-update.lua

Lines changed: 0 additions & 5 deletions
This file was deleted.

sources/meta-yoe/dynamic-layers/swupdate/recipes-core/images/files/tegra/sw-description

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,39 @@ software =
2828
sha256 = "$swupdate_get_sha256(@@ROOTFS_FILENAME@@)";
2929
},
3030
{
31-
filename = "@@DEPLOY_KERNEL_IMAGE@@";
32-
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_B_PARTNAME@@";
33-
},
34-
{
35-
filename = "@@DTBFILE@@";
36-
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_B_DTB_PARTNAME@@";
37-
}
31+
filename = "@@DEPLOY_KERNEL_IMAGE@@";
32+
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_B_PARTNAME@@";
33+
},
34+
{
35+
filename = "@@DTBFILE@@";
36+
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_B_DTB_PARTNAME@@";
37+
}
3838

3939
);
4040
files: (
4141
{
4242
filename = "tegra-bl.cap";
43-
path = "/boot/efi/EFI/UpdateCapsule/TEGRA_BL.Cap";
43+
path = "@@TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@@";
4444
properties = {create-destination = "true";}
45+
name = "tegra-bootloader-capsule"
46+
version = "@@TEGRA_SWUPDATE_BOOTLOADER_VERSION@@"
47+
install-if-different = @@TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@@
48+
},
49+
{
50+
filename = "@@ESP_ARCHIVE@@"
51+
type = "archive"
52+
installed-directly = "true"
53+
path = "/boot/efi"
54+
name = "tegra-bootloader-capsule"
55+
version = "@@TEGRA_SWUPDATE_BOOTLOADER_VERSION@@"
56+
install-if-different = @@TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@@
4557
}
4658
);
4759
scripts: (
4860
{
49-
filename = "bootloader-update.lua";
61+
filename = "tegra-swupdate-script.lua";
5062
type = "lua"
51-
sha256 = "$swupdate_get_sha256(bootloader-update.lua)";
63+
sha256 = "$swupdate_get_sha256(tegra-swupdate-script.lua)";
5264
}
5365
);
5466

@@ -76,26 +88,38 @@ software =
7688
sha256 = "$swupdate_get_sha256(@@ROOTFS_FILENAME@@)";
7789
},
7890
{
79-
filename = "@@DEPLOY_KERNEL_IMAGE@@";
80-
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_A_PARTNAME@@";
81-
},
82-
{
83-
filename = "@@DTBFILE@@";
84-
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_A_DTB_PARTNAME@@";
85-
}
91+
filename = "@@DEPLOY_KERNEL_IMAGE@@";
92+
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_A_PARTNAME@@";
93+
},
94+
{
95+
filename = "@@DTBFILE@@";
96+
device = "@@ROOTFS_DEVICE_PATH@@/@@KERNEL_A_DTB_PARTNAME@@";
97+
}
8698
);
8799
files: (
88100
{
89101
filename = "tegra-bl.cap";
90-
path = "/boot/efi/EFI/UpdateCapsule/TEGRA_BL.Cap";
102+
path = "@@TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@@";
91103
properties = {create-destination = "true";}
104+
name = "tegra-bootloader-capsule"
105+
version = "@@TEGRA_SWUPDATE_BOOTLOADER_VERSION@@"
106+
install-if-different = @@TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@@
107+
},
108+
{
109+
filename = "@@ESP_ARCHIVE@@"
110+
type = "archive"
111+
installed-directly = "true"
112+
path = "/boot/efi"
113+
name = "tegra-bootloader-capsule"
114+
version = "@@TEGRA_SWUPDATE_BOOTLOADER_VERSION@@"
115+
install-if-different = @@TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@@
92116
}
93117
);
94118
scripts: (
95119
{
96-
filename = "bootloader-update.lua";
120+
filename = "tegra-swupdate-script.lua";
97121
type = "lua"
98-
sha256 = "$swupdate_get_sha256(bootloader-update.lua)";
122+
sha256 = "$swupdate_get_sha256(tegra-swupdate-script.lua)";
99123
}
100124
);
101125
};

sources/meta-yoe/dynamic-layers/swupdate/recipes-core/images/yoe-swupdate-image-tegra.bb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384
66

77
SRC_URI = "\
88
file://sw-description \
9-
file://bootloader-update.lua \
109
"
1110

12-
inherit swupdate image_types_tegra
11+
inherit swupdate image_types_tegra tegra_swupdate
1312

1413
DEPLOY_KERNEL_IMAGE ?= "${@os.path.basename(tegra_kernel_image(d))}"
1514

@@ -21,18 +20,23 @@ SWUPDATE_CORE_IMAGE_NAME ?= "yoe-simple-image"
2120

2221
ROOTFS_FILENAME ?= "${SWUPDATE_CORE_IMAGE_NAME}-${MACHINE}.rootfs.tar.gz"
2322

24-
# Handle differences in redundant partition naming on t194 platforms
2523
KERNEL_A_PARTNAME = "A_kernel"
2624
KERNEL_A_DTB_PARTNAME = "A_kernel-dtb"
2725
KERNEL_B_PARTNAME = "B_kernel"
2826
KERNEL_B_DTB_PARTNAME = "B_kernel-dtb"
2927

3028
# images to build before building swupdate image
31-
IMAGE_DEPENDS = "${SWUPDATE_CORE_IMAGE_NAME} tegra-uefi-capsules"
29+
IMAGE_DEPENDS = "${SWUPDATE_CORE_IMAGE_NAME} tegra-uefi-capsules tegra-swupdate-script tegra-espimage"
30+
31+
ESP_ARCHIVE ?= "${TEGRA_ESP_IMAGE}-${MACHINE}.tar.gz"
3232

3333
# images and files that will be included in the .swu image
3434
DTBFILE_PATH = "${@'${EXTERNAL_KERNEL_DEVICETREE}/${DTBFILE}' if len(d.getVar('EXTERNAL_KERNEL_DEVICETREE')) else '${DTBFILE}'}"
35-
SWUPDATE_IMAGES = "${ROOTFS_FILENAME} tegra-bl.cap ${DEPLOY_KERNEL_IMAGE} ${DTBFILE_PATH}"
35+
SWUPDATE_IMAGES = "${ROOTFS_FILENAME} tegra-bl.cap ${DEPLOY_KERNEL_IMAGE} ${DTBFILE_PATH} tegra-swupdate-script.lua ${ESP_ARCHIVE}"
3636

3737
do_swuimage[depends] += "${DTB_EXTRA_DEPS}"
38-
do_swuimage[dirs] += "${S}"
38+
39+
# Add a link using the core image name.swu to the resulting swu image
40+
do_swuimage:append() {
41+
os.symlink(d.getVar("IMAGE_NAME") + ".swu", d.getVar("SWUPDATE_CORE_IMAGE_NAME") + "-" + d.getVar("MACHINE") + ".swu")
42+
}
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
2+
datadir=@DATADIR@
33
get_current_slot() {
44
curslot=$(nvbootctrl get-current-slot)
55
if [ $curslot -eq 1 ]; then
@@ -20,6 +20,11 @@ else
2020
fi
2121

2222
BOOTSLOT=$(get_current_slot)
23+
ALTROOTSLOT="APP"
24+
if [ "$BOOTSLOT" = "a" ]; then
25+
ALTROOTSLOT="${ALTROOTSLOT}_b"
26+
fi
27+
2328

2429
rm -f /run/swupdate/swupdate.cfg
2530

@@ -31,4 +36,18 @@ sed -e"s,@SWVERSION@,$VERSION_ID," \
3136
-e"s,@SERIALNUMBER@,$SERIALNUMBER," \
3237
-e"s,@BOOTSLOT@,$BOOTSLOT," \
3338
$extrased \
34-
/usr/share/swupdate/swupdate.cfg.in > /run/swupdate/swupdate.cfg
39+
/${datadir}/swupdate/swupdate.cfg.in > /run/swupdate/swupdate.cfg
40+
41+
rm -f /run/swupdate/sw-versions
42+
alt_rootfs_dev="/dev/disk/by-partlabel/$ALTROOTSLOT"
43+
tmp_mount=`mktemp -d`
44+
mount -o ro $alt_rootfs_dev $tmp_mount
45+
if [ -e $tmp_mount/usr/share/swupdate/sw-versions-thisslot ]; then
46+
echo "Setup sw-versions based on $ALTROOTSLOT"
47+
cp $tmp_mount/${datadir}/swupdate/sw-versions-thisslot /run/swupdate/sw-versions
48+
else
49+
echo "Alternate slot $ALTROOTSLOT does not contain sw-versions, using empty file"
50+
touch /run/swupdate/sw-versions
51+
fi
52+
umount $tmp_mount
53+
rm -rf $tmp_mount

sources/meta-yoe/dynamic-layers/swupdate/recipes-support/swupdate/swupdate-machine-config_1.0.bb renamed to sources/meta-yoe/dynamic-layers/tegra/recipes-support/swupdate/swupdate-machine-config_1.0.bb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ DESCRIPTION = "Machine-specific configuration for swupdate"
22
LICENSE = "MIT"
33
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
44

5+
inherit tegra_swupdate
6+
57
SRC_URI = "\
68
file://swupdate.cfg.in \
7-
file://swupdate-genconfig.sh \
9+
file://swupdate-genconfig.sh.in \
810
file://swupdate-mods.conf \
911
"
1012

@@ -23,7 +25,10 @@ do_compile() {
2325
rm -f ${B}/hwrevision
2426
echo "${SWUPDATE_BOARDNAME} ${SWUPDATE_HWREVISION}" > ${B}/hwrevision
2527
sed -e's,@MODEL@,${SWUPDATE_BOARDNAME},g' \
26-
${S}/swupdate.cfg.in > ${B}/swupdate.cfg.in
28+
${S}/swupdate.cfg.in > ${B}/swupdate.cfg.in
29+
sed -e's,@DATADIR@,${datadir},g' \
30+
${S}/swupdate-genconfig.sh.in > ${B}/swupdate-genconfig.sh
31+
echo "tegra-bootloader-capsule ${TEGRA_SWUPDATE_BOOTLOADER_VERSION}" > ${B}/sw-versions-thisslot
2732
}
2833

2934
do_install() {
@@ -33,16 +38,19 @@ do_install() {
3338
install -d ${D}${datadir}/swupdate
3439
install -m 0644 ${B}/swupdate.cfg.in ${D}${datadir}/swupdate/
3540
install -d ${D}${libexecdir}/swupdate
36-
install -m 0755 ${S}/swupdate-genconfig.sh ${D}${libexecdir}/swupdate/swupdate-genconfig
41+
install -m 0755 ${B}/swupdate-genconfig.sh ${D}${libexecdir}/swupdate/swupdate-genconfig
3742
install -d ${D}${sysconfdir}/systemd/system/swupdate.service.d
3843
install -m 0644 ${S}/swupdate-mods.conf ${D}${sysconfdir}/systemd/system/swupdate.service.d/
44+
install -m 0644 ${B}/sw-versions-thisslot ${D}${datadir}/swupdate/
45+
ln -s /run/swupdate/sw-versions ${D}${sysconfdir}/sw-versions
3946
}
4047

4148
do_install:append:secureboot() {
4249
install -m 0644 ${S}/swupdate.pem ${D}${datadir}/swupdate/
4350
}
4451

4552
FILES:${PN} += "${datadir}/swupdate"
53+
FILES:${PN} += "${sysconfdir}/sw-versions"
4654
PACKAGE_ARCH = "${MACHINE_ARCH}"
4755
EXTRADEPS = "tegra-redundant-boot"
4856
RDEPENDS:${PN} += "${EXTRADEPS}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local function get_current_slot()
2+
local handle = io.popen("nvbootctrl get-current-slot")
3+
if not handle then
4+
print("Failed to get-current-slot")
5+
return nil
6+
end
7+
local result = handle:read("*a")
8+
handle:close()
9+
return result:match("%d") -- Extracts the first digit found
10+
end
11+
12+
local function set_active_slot(slot)
13+
local command = "nvbootctrl set-active-boot-slot " .. slot
14+
return os.execute(command)
15+
end
16+
17+
local function switch_slots()
18+
local current_slot = get_current_slot()
19+
local success = -1
20+
if current_slot then
21+
local new_slot = current_slot == "1" and "0" or "1"
22+
print("Switching active slot to: " .. new_slot)
23+
success = set_active_slot(new_slot)
24+
else
25+
print("Failed to determine the current slot.")
26+
end
27+
return success
28+
end
29+
30+
local function file_exists(path)
31+
local file = io.open(path, "r")
32+
if file then
33+
file:close()
34+
return true
35+
else
36+
return false
37+
end
38+
end
39+
40+
function postinst()
41+
local success = -1
42+
local result = ""
43+
if file_exists("@TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@") then
44+
print("Running bootloader update script")
45+
success = os.execute("/usr/bin/oe4t-set-uefi-OSIndications")
46+
result = "oe4t-set-uefi-OSIndications completed with status: " .. tostring(success)
47+
else
48+
if @TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@ then
49+
print("Running os switch instead of bootloader update since @TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@ is missing")
50+
success = switch_slots()
51+
result = "switch_slots completed with status: " .. tostring(success)
52+
else
53+
result = "Missing @TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@, cannot complete update"
54+
end
55+
end
56+
return success, result
57+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
DESCRIPTION = "Script run as a part of swupdate install for tegra"
2+
LICENSE = "MIT"
3+
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
4+
5+
SRC_URI = "\
6+
file://tegra-swupdate-script.lua.in \
7+
"
8+
9+
S = "${WORKDIR}/sources"
10+
UNPACKDIR = "${S}"
11+
B = "${WORKDIR}/build"
12+
13+
inherit tegra_swupdate deploy
14+
15+
do_compile() {
16+
sed -e's,@TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT@,${TEGRA_SWUPDATE_BOOTLOADER_INSTALL_ONLY_IF_DIFFERENT},g' \
17+
-e's,@TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH@,${TEGRA_SWUPDATE_CAPSULE_INSTALL_PATH},g'\
18+
${S}/tegra-swupdate-script.lua.in > ${B}/tegra-swupdate-script.lua
19+
}
20+
21+
do_deploy() {
22+
cp ${B}/tegra-swupdate-script.lua ${DEPLOYDIR}/
23+
}
24+
25+
addtask deploy after do_install

0 commit comments

Comments
 (0)