/
updatehub-runtime.bbclass
177 lines (149 loc) · 9.37 KB
/
updatehub-runtime.bbclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Handle updatehub agent runtime configuration
#
# This class is not intended to be used directly but through the
# updatehub-image class.
#
# The supported variables as well as their usage are documented on the
# updatehub-image class.
#
# Copyright 2016-2020 (C) O.S. Systems Software LTDA.
UPDATEHUB_PACKAGE_VERSION ?= "${@sanitise_version(d.getVar('DISTRO_VERSION'))}"
UPDATEHUB_SERVER_URL ?= "https://api.updatehub.io"
UPDATEHUB_UHUPKG_PUBLIC_KEY ?= ""
UPDATEHUB_UHUPKG_PRIVATE_KEY ?= ""
UPDATEHUB_IMAGE_TYPE[type] = "list"
UPDATEHUB_IMAGE_TYPE[validitems] += "initramfs active/inactive"
UPDATEHUB_INSTALL_MODE ?= ""
UPDATEHUB_INSTALL_MODE[type] = "list"
UPDATEHUB_INSTALL_MODE[validitems] += "copy flash raw tarball ubifs imxkobs"
UPDATEHUB_FILESYSTEM_SUPPORT ?= ""
UPDATEHUB_FILESYSTEM_SUPPORT[type] = "list"
UPDATEHUB_FILESYSTEM_SUPPORT[validitems] += "btrfs ext2 ext3 ext4 f2fs jffs2 ubifs vfat xfs"
UPDATEHUB_ACTIVE_INACTIVE_BACKEND ?= ""
UPDATEHUB_ACTIVE_INACTIVE_BACKEND[type] = "list"
UPDATEHUB_ACTIVE_INACTIVE_BACKEND[validitems] += "u-boot grub grub-efi"
UPDATEHUB_DEVICE_IDENTITY ?= ""
UPDATEHUB_DEVICE_IDENTITY[type] = "list"
UPDATEHUB_DEVICE_IDENTITY[validitems] += "primary-iface cpuinfo-serial custom"
UPDATEHUB_DEVICE_ATTRIBUTE ?= ""
UPDATEHUB_DEVICE_ATTRIBUTE[type] = "list"
UPDATEHUB_DEVICE_ATTRIBUTE[validitems] += "kernel cpu-model mem-total ipinfo-io"
UPDATEHUB_RUNTIME_PACKAGES = ""
UPDATEHUB_COMPATIBLE_MACHINE ?= "${MACHINE}"
# Change tar format argument to use gnu instead of posix. OE-Core
# 07a1771c9b2066c2003f285493d9720008b7412b changed tar format from gnu to posix.
# When we have an rootfs running that was built using the gnu format and then
# update to a rootfs that was built using posix format libarchive fails to
# unpack and raise the error:
#
# level=warning msg="transient error: Pathname can't be converted from UTF-8 to current locale.
#
# This happens because the LC_ALL variable is not set to use UTF-8, e.g. en_US.UTF-8 and libarchive
# can't extract files uses UTF-8 format, e.g. ca-certificate NetLock_Arany_=Class_Gold=_Főtanúsítvány.pem
# file.
IMAGE_CMD:tar = "${IMAGE_CMD_TAR} --sort=name --format=gnu --numeric-owner -cf ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar -C ${IMAGE_ROOTFS} . || [ $? -eq 1 ]"
python () {
if bb.data.inherits_class('image', d):
### Ensures product uid is set
product_uid = d.getVar("UPDATEHUB_PRODUCT_UID", False)
if not product_uid:
raise bb.parse.SkipRecipe("To enable updatehub support, the 'UPDATEHUB_PRODUCT_UID' variable must be set.")
### Ensure a version is set
version = d.getVar("UPDATEHUB_PACKAGE_VERSION", False)
### Handle image type selection
image_type = d.getVar("UPDATEHUB_IMAGE_TYPE", False)
valid_image_types = d.getVarFlag('UPDATEHUB_IMAGE_TYPE', 'validitems', False).split()
active_inactive_backend = d.getVar('UPDATEHUB_ACTIVE_INACTIVE_BACKEND', False)
valid_active_inactive_backends = d.getVarFlag('UPDATEHUB_ACTIVE_INACTIVE_BACKEND', 'validitems', False).split()
if not image_type:
raise bb.parse.SkipRecipe("To enable updatehub support, the 'UPDATEHUB_IMAGE_TYPE' variable must be set. Valid image types are: %s" % ' '.join(valid_image_types))
elif not image_type in valid_image_types:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_IMAGE_TYPE is not a valid image type. Valid image types are: %s" % (image_type, ' '.join(valid_image_types)))
elif image_type in ['active/inactive']:
if not active_inactive_backend:
raise bb.parse.SkipRecipe("To enable updatehub with Active/Inactive image schema support, the 'UPDATEHUB_ACTIVE_INACTIVE_BACKEND' variable must be set. Valid backends are: %s" % ' '.join(valid_active_inactive_backends))
d.appendVar('IMAGE_INSTALL', ' packagegroup-updatehub-active-inactive-runtime')
elif image_type in ['initramfs']:
if active_inactive_backend:
raise bb.parse.SkipRecipe("To enable updatehub with initramfs image schema support, the 'UPDATEHUB_ACTIVE_INACTIVE_BACKEND' variable must NOT be set.")
d.appendVar('IMAGE_INSTALL', ' packagegroup-updatehub-initramfs-support')
### Handle device identity selection
device_identities = (d.getVar('UPDATEHUB_DEVICE_IDENTITY', True) or "").split()
valid_device_identities = d.getVarFlag('UPDATEHUB_DEVICE_IDENTITY', 'validitems', False).split()
if not device_identities:
raise bb.parse.SkipRecipe("To enable updatehub the 'UPDATEHUB_DEVICE_IDENTITY' variable must be set. Valid device identities are: %s" % ' '.join(valid_device_identities))
for device_identity in device_identities:
if device_identity == "custom":
continue
d.appendVar('UPDATEHUB_RUNTIME_PACKAGES', ' updatehub-device-identity-%s' % device_identity)
if not device_identity in valid_device_identities:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_DEVICE_IDENTITY is not valid. Valid device identities are: %s" % (device_identity, ' '.join(valid_device_identities)))
### Handle device attribute selection
device_attributes = (d.getVar('UPDATEHUB_DEVICE_ATTRIBUTE', True) or "").split()
valid_device_attributes = d.getVarFlag('UPDATEHUB_DEVICE_ATTRIBUTE', 'validitems', False).split()
for device_attribute in device_attributes:
d.appendVar('UPDATEHUB_RUNTIME_PACKAGES', ' updatehub-device-attribute-%s' % device_attribute)
if not device_attribute in valid_device_attributes:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_DEVICE_ATTRIBUTE is not valid. Valid device attributes are: %s" % (device_attribute, ' '.join(valid_device_attributes)))
### Handle install mode selection
modes = (d.getVar('UPDATEHUB_INSTALL_MODE', True) or "").split()
valid_modes = d.getVarFlag('UPDATEHUB_INSTALL_MODE', 'validitems', False).split()
mode_rdepends_map = {
'copy' : '',
'flash' : 'mtd-utils',
'imxkobs' : 'imx-kobs',
'raw' : '',
'tarball' : '',
'ubifs' : 'mtd-utils-ubifs',
}
if any(map(lambda x: x not in mode_rdepends_map.keys(), valid_modes)):
raise bb.parse.SkipRecipe("Not all valid modes has the runtime dependencies mapped. Please check.")
if not modes:
raise bb.parse.SkipRecipe("To enable updatehub support, the 'UPDATEHUB_INSTALL_MODE' variable must be set. Valid modes are: %s" % ' '.join(valid_modes))
else:
for mode in modes:
d.appendVar('UPDATEHUB_RUNTIME_PACKAGES', ' %s' % mode_rdepends_map[mode])
if not mode in valid_modes:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_INSTALL_MODE is not a valid install mode. Valid install modes are: %s" % (mode, ' '.join(valid_modes)))
### Handle filesystem support selection
filesystems = (d.getVar('UPDATEHUB_FILESYSTEM_SUPPORT', True) or "").split()
valid_filesystems = d.getVarFlag('UPDATEHUB_FILESYSTEM_SUPPORT', 'validitems', False).split()
filesystem_rdepends_map = {
'btrfs': 'btrfs-tools',
'ext2' : 'e2fsprogs-mke2fs',
'ext3' : 'e2fsprogs-mke2fs',
'ext4' : 'e2fsprogs-mke2fs',
'f2fs' : 'f2fs-tools',
'jffs2': 'mtd-utils-jffs2',
'ubifs': 'mtd-utils-ubifs',
'vfat' : 'dosfstools',
'xfs' : 'xfsprogs-mkfs',
}
# Ensure if we enable 'ubifs' we add both the mode and the filesystem
# support.
if 'ubifs' in modes and not 'ubifs' in filesystems or \
not 'ubifs' in modes and 'ubifs' in filesystems:
raise bb.parse.SkipRecipe("To use 'ubifs' it must be enabled on the UPDATEHUB_FILESYSTEM_SUPPORT and UPDATEHUB_INSTALL_MODE variables. Please check.")
if any(map(lambda x: x not in filesystem_rdepends_map.keys(), valid_filesystems)):
raise bb.parse.SkipRecipe("Not all valid filesystems has the runtime dependencies mapped. Please check.")
for filesystem in filesystems:
if not filesystem in valid_filesystems:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_FILESYSTEM_SUPPORT is not a valid filesystem support. Valid filesystem supports are: %s" % (filesystem, ' '.join(valid_filesystems)))
if any(mode in modes for mode in ['copy', 'tarball']):
d.appendVar('UPDATEHUB_RUNTIME_PACKAGES', ' %s' % filesystem_rdepends_map[filesystem])
else:
bb.debug(1, "UPDATEHUB_FILESYSTEM_SUPPORT is set but there is no mode in use which makes use of it. Ignoring it.")
### Handle the Active/Inactive backend selection
active_inactive_backend = d.getVar('UPDATEHUB_ACTIVE_INACTIVE_BACKEND', False)
valid_active_inactive_backends = (d.getVarFlag('UPDATEHUB_ACTIVE_INACTIVE_BACKEND', 'validitems', False) or "").split()
if active_inactive_backend and active_inactive_backend not in valid_active_inactive_backends:
raise bb.parse.SkipRecipe("'%s' in UPDATEHUB_ACTIVE_INACTIVE_BACKEND is not a valid active/inactive backend. Valid active/inactive backends are: %s" % (active_inactive_backend, ' '.join(valid_active_inactive_backends)))
elif active_inactive_backend:
d.appendVar('UPDATEHUB_RUNTIME_PACKAGES', ' updatehub-active-inactive-backend-%s' % active_inactive_backend)
}
def sanitise_version(ver):
# VERSION_ID should be (from os-release(5)):
# lower-case string (mostly numeric, no spaces or other characters
# outside of 0-9, a-z, ".", "_" and "-")
ret = ver.replace('+', '-').replace(' ','_')
return ret.lower()