Skip to content

Commit a33048c

Browse files
dwalkesmadisongh
authored andcommitted
swupdate-image-tegra: Add swupdate demo
Building off the work at [1] (based on the original implementation referenced in [2]) and the proposal for meta-swupdate-boards discussed at [3], add the swupdate example to tegra-demo-distro instead as discussed in [4]. 1: Trellis-Logic/meta-swupdate-boards#1 2: https://github.com/madisongh/tegra-test-distro/wiki/swupdate-integration-notes 3: https://groups.google.com/g/swupdate/c/Kh2XlA5rwzE/m/x5W88vDEAwAJ 4: https://github.com/OE4T/meta-tegra/wiki/OE4T-Meeting-Notes-2024-02-08 Signed-off-by: Dan Walkes <danwalkes@trellis-logic.com>
1 parent 82f9553 commit a33048c

File tree

16 files changed

+342
-0
lines changed

16 files changed

+342
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ demo applications.
8282
| demo-image-weston | Wayland with Weston compositor |
8383
| demo-image-full | Sato image plus nvidia-docker, openCV, multimedia API samples |
8484

85+
### Update image demo
86+
87+
A [swupdate](https://sbabic.github.io/swupdate/) demo image is also available which supports
88+
A/B rootfs updates to any of the supported images. For details refer to
89+
[layers/meta-tegrademo/dynamic-layers/meta-swupdate/README.md](layers/meta-tegrademo/dynamic-layers/meta-swupdate/README.md).
90+
8591
# Contributing
8692

8793
Please see the contributor wiki page at [this link](https://github.com/OE4T/meta-tegra/wiki/OE4T-Contributor-Guide).

layers/meta-tegrademo/conf/layer.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
BBPATH =. "${LAYERDIR}:"
22
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
3+
BBFILES_DYNAMIC += "swupdate:${LAYERDIR}/dynamic-layers/meta-swupdate/recipes-*/*/*.bb \
4+
swupdate:${LAYERDIR}/dynamic-layers/meta-swupdate/recipes-*/*/*.bbappend"
35

46
BBFILE_COLLECTIONS += "tegrademo"
57
BBFILE_PATTERN_tegrademo = "^${LAYERDIR}/"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Swupdate for NVIDIA Tegra (Jetson) platforms
2+
3+
This dynamic layer provides an example implementation for
4+
Nvidia Jetson and [swupdate](https://sbabic.github.io/swupdate).
5+
6+
The simplest way to use on tegra is to add to a forked copy of
7+
[tegra-demo-distro](https://github.com/OE4T/tegra-demo-distro) which
8+
also contains relevant images and submodules used to build tegra images.
9+
However, this is not strictly required. The only dependency required
10+
is the [meta-tegra](https://github.com/OE4T/meta-tegra) layer.
11+
12+
## Build with tegra-demo-distro
13+
14+
Use these instructions to add to tegra-demo-distro on whatever
15+
branch you'd like to target (kirkstone and later are supported).
16+
17+
```
18+
cd repos
19+
git submodule add https://github.com/sbabic/meta-swupdate
20+
cd ../layers
21+
ln -s ../repos/meta-swupdate
22+
```
23+
24+
Then use the `setup-env` script to start a bitbake shell, and add
25+
this layer to your build
26+
```
27+
bitbake-layers add-layer ../layers/meta-swupdate
28+
```
29+
30+
In your local.conf (or distro/machine configuration) add
31+
these lines:
32+
```
33+
IMAGE_INSTALL:append = " swupdate"
34+
USE_REDUNDANT_FLASH_LAYOUT = "1"
35+
IMAGE_FSTYPES:append = " tar.gz"
36+
```
37+
If you desire an image other than demo-image-base as your base image,
38+
you may add a definition for `SWUPDATE_CORE_IMAGE_NAME` with the
39+
desired base image.
40+
41+
Finally, build the update image using:
42+
```
43+
bitbake swupdate-image-tegra
44+
```
45+
46+
## Deploy and Test
47+
* Tegraflash the inital image (demo-image-base or, whatever
48+
image you've set as `SWUPDATE_CORE_IMAGE_NAME`
49+
* Deploy the .swu file built with swupdate-image-tegra
50+
to the target
51+
* Run the update with:
52+
```
53+
swupdate -i </path/to/swu/file>
54+
```
55+
* Reboot to apply the update.
56+
* The root partition should change
57+
* The `nvbootctrl dump-slots-info` output should show boot
58+
from the alternate boot slot with `Capsule update status:1`.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SUMMARY = "Tegra swupdate update image"
2+
DESCRIPTION = "A swupdate image for demonstrating tegra updates"
3+
4+
LICENSE = "MIT"
5+
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
6+
7+
SRC_URI = "\
8+
file://sw-description \
9+
file://bootloader-update.lua \
10+
"
11+
12+
inherit swupdate image_types_tegra
13+
14+
DEPLOY_KERNEL_IMAGE ?= "${@os.path.basename(tegra_kernel_image(d))}"
15+
16+
ROOTFS_DEVICE_PATH ?= "/dev/disk/by-partlabel"
17+
18+
# By default, use demo-image-base as the base image.
19+
# Redefine in local.conf if you'd like to use a different base image.
20+
SWUPDATE_CORE_IMAGE_NAME ?= "demo-image-base"
21+
22+
ROOTFS_FILENAME ?= "${SWUPDATE_CORE_IMAGE_NAME}-${MACHINE}.rootfs.tar.gz"
23+
24+
# Handle differences in redundant partition naming on t194 platforms
25+
KERNEL_A_PARTNAME = "A_kernel"
26+
KERNEL_A_PARTNAME:tegra194 = "kernel"
27+
KERNEL_A_DTB_PARTNAME = "A_kernel-dtb"
28+
KERNEL_A_DTB_PARTNAME:tegra194 = "kernel-dtb"
29+
KERNEL_B_PARTNAME = "B_kernel"
30+
KERNEL_B_PARTNAME:tegra194 = "kernel_b"
31+
KERNEL_B_DTB_PARTNAME = "B_kernel-dtb"
32+
KERNEL_B_DTB_PARTNAME:tegra194 = "kernel-dtb_b"
33+
34+
# images to build before building swupdate image
35+
IMAGE_DEPENDS = "${SWUPDATE_CORE_IMAGE_NAME} tegra-uefi-capsules"
36+
37+
# images and files that will be included in the .swu image
38+
SWUPDATE_IMAGES = "${ROOTFS_FILENAME} tegra-bl.cap ${DEPLOY_KERNEL_IMAGE} ${DTBFILE}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function postinst()
2+
local success = os.execute("/usr/bin/oe4t-set-uefi-OSIndications")
3+
local result = "oe4t-set-uefi-OSIndications completed with success: " .. tostring(success)
4+
return success, result
5+
end
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
software =
2+
{
3+
version = "@@DISTRO_VERSION@@";
4+
5+
@@MACHINE@@ = {
6+
hardware-compatibility: [ "1.0" ]
7+
system = {
8+
slot_a : {
9+
partitions: (
10+
{
11+
type = "diskformat";
12+
device = "@@ROOTFS_DEVICE_PATH@@/APP_b";
13+
properties: {
14+
fstype = "ext4";
15+
force = "true";
16+
}
17+
}
18+
);
19+
images: (
20+
{
21+
filename = "@@ROOTFS_FILENAME@@";
22+
type = "archive";
23+
device = "@@ROOTFS_DEVICE_PATH@@/APP_b";
24+
filesystem = "ext4";
25+
path = "/";
26+
installed-directly = true;
27+
preserve-attributes = true;
28+
sha256 = "$swupdate_get_sha256(@@ROOTFS_FILENAME@@)";
29+
},
30+
{
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+
}
38+
39+
);
40+
files: (
41+
{
42+
filename = "tegra-bl.cap";
43+
path = "/opt/nvidia/esp/EFI/UpdateCapsule/TEGRA_BL.Cap";
44+
properties = {create-destination = "true";}
45+
}
46+
);
47+
scripts: (
48+
{
49+
filename = "bootloader-update.lua";
50+
type = "lua"
51+
sha256 = "$swupdate_get_sha256(bootloader-update.lua)";
52+
}
53+
);
54+
55+
};
56+
slot_b : {
57+
partitions: (
58+
{
59+
type = "diskformat";
60+
device = "@@ROOTFS_DEVICE_PATH@@/APP";
61+
properties: {
62+
fstype = "ext4";
63+
force = "true";
64+
}
65+
}
66+
);
67+
images: (
68+
{
69+
filename = "@@ROOTFS_FILENAME@@";
70+
type = "archive";
71+
device = "@@ROOTFS_DEVICE_PATH@@/APP";
72+
filesystem = "ext4";
73+
path = "/";
74+
installed-directly = true;
75+
preserve-attributes = true;
76+
sha256 = "$swupdate_get_sha256(@@ROOTFS_FILENAME@@)";
77+
},
78+
{
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+
}
86+
);
87+
files: (
88+
{
89+
filename = "tegra-bl.cap";
90+
path = "/opt/nvidia/esp/EFI/UpdateCapsule/TEGRA_BL.Cap";
91+
properties = {create-destination = "true";}
92+
}
93+
);
94+
scripts: (
95+
{
96+
filename = "bootloader-update.lua";
97+
type = "lua"
98+
sha256 = "$swupdate_get_sha256(bootloader-update.lua)";
99+
}
100+
);
101+
};
102+
};
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
get_current_slot() {
4+
curslot=$(nvbootctrl get-current-slot)
5+
if [ $curslot -eq 1 ]; then
6+
echo "b"
7+
else
8+
echo "a"
9+
fi
10+
}
11+
12+
. /etc/os-release
13+
14+
if [ -e /run/mfgdata/serial-number ]; then
15+
SERIALNUMBER=$(cat /run/mfgdata/serial-number)
16+
elif [ -e /sys/module/fuse_burn/parameters/tegra_chip_uid ]; then
17+
SERIALNUMBER=$(cat /sys/module/fuse_burn/parameters/tegra_chip_uid)
18+
else
19+
SERIALNUMBER="unknown"
20+
fi
21+
22+
BOOTSLOT=$(get_current_slot)
23+
24+
rm -f /run/swupdate/swupdate.cfg
25+
26+
extrased=
27+
if [ ! -e /usr/share/swupdate/swupdate.pem ]; then
28+
extrased="-e /public-key-file/d"
29+
fi
30+
sed -e"s,@SWVERSION@,$VERSION_ID," \
31+
-e"s,@SERIALNUMBER@,$SERIALNUMBER," \
32+
-e"s,@BOOTSLOT@,$BOOTSLOT," \
33+
$extrased \
34+
/usr/share/swupdate/swupdate.cfg.in > /run/swupdate/swupdate.cfg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Service]
2+
ExecStartPre=/usr/libexec/swupdate/swupdate-genconfig
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
globals:
2+
{
3+
verbose = false;
4+
loglevel = 3;
5+
select = "system,slot_@BOOTSLOT@";
6+
};
7+
8+
identify : (
9+
{ name = "swversion"; value = "@SWVERSION@" },
10+
{ name = "serialnumber"; value = "@SERIALNUMBER@" },
11+
{ name = "model"; value = "@MODEL@" }
12+
);
13+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
DESCRIPTION = "Machine-specific configuration for swupdate"
2+
LICENSE = "MIT"
3+
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
4+
5+
SRC_URI = "\
6+
file://swupdate.cfg.in \
7+
file://swupdate-genconfig.sh \
8+
file://swupdate-mods.conf \
9+
"
10+
11+
SRC_URI:append:secureboot = " \
12+
file://swupdate.pem \
13+
"
14+
15+
SWUPDATE_BOARDNAME ??= "${MACHINE}"
16+
SWUPDATE_HWREVISION ??= "1.0"
17+
18+
S = "${WORKDIR}"
19+
B = "${WORKDIR}/build"
20+
21+
do_compile() {
22+
rm -f ${B}/hwrevision
23+
echo "${SWUPDATE_BOARDNAME} ${SWUPDATE_HWREVISION}" > ${B}/hwrevision
24+
sed -e's,@MODEL@,${SWUPDATE_BOARDNAME},g' \
25+
${S}/swupdate.cfg.in > ${B}/swupdate.cfg.in
26+
}
27+
28+
do_install() {
29+
install -d ${D}${sysconfdir}
30+
install -m 0644 ${B}/hwrevision ${D}${sysconfdir}/
31+
ln -s /run/swupdate/swupdate.cfg ${D}${sysconfdir}/swupdate.cfg
32+
install -d ${D}${datadir}/swupdate
33+
install -m 0644 ${B}/swupdate.cfg.in ${D}${datadir}/swupdate/
34+
install -d ${D}${libexecdir}/swupdate
35+
install -m 0755 ${S}/swupdate-genconfig.sh ${D}${libexecdir}/swupdate/swupdate-genconfig
36+
install -d ${D}${sysconfdir}/systemd/system/swupdate.service.d
37+
install -m 0644 ${S}/swupdate-mods.conf ${D}${sysconfdir}/systemd/system/swupdate.service.d/
38+
}
39+
40+
do_install:append:secureboot() {
41+
install -m 0644 ${S}/swupdate.pem ${D}${datadir}/swupdate/
42+
}
43+
44+
FILES:${PN} += "${datadir}/swupdate"
45+
PACKAGE_ARCH = "${MACHINE_ARCH}"
46+
EXTRADEPS = "tegra-redundant-boot"
47+
RDEPENDS:${PN} += "${EXTRADEPS}"

0 commit comments

Comments
 (0)