/
updatehub-image-tasks.bbclass
204 lines (169 loc) · 6.79 KB
/
updatehub-image-tasks.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Handle updatehub image integration tasks
#
# This class is not intended to be used directly but through the
# updatehub-image class.
#
# For more information about its usage, is available in
# 'updatehub-image' class documentation.
#
# Copyright 2017-2020 (C) O.S. Systems Software LTDA.
inherit terminal python3native updatehub-runtime
UHUPKG_FILES ?= "${IMAGE_BASENAME}.${MACHINE}.uhupkg.config ${IMAGE_BASENAME}.uhupkg.config ${MACHINE}.uhupkg.config"
UHUPKG_SEARCH_PATH ?= "${THISDIR}:${@':'.join('%s/uhu' % p for p in '${BBPATH}'.split(':'))}"
UHUPKG_FULL_PATH = "${@uhupkg_search(d.getVar('UHUPKG_FILES', True).split(), d.getVar('UHUPKG_SEARCH_PATH', True)) or ''}"
def uhupkg_search(files, search_path):
for f in files:
if os.path.isabs(f):
if os.path.exists(f):
return f
else:
searched = bb.utils.which(search_path, f)
if searched:
return searched
python () {
### Queue initramfs image build
image_type = d.getVar("UPDATEHUB_IMAGE_TYPE", False)
if image_type in ['initramfs']:
d.appendVarFlag('do_generate_updatehub_dependencies',
'depends',
'updatehub-initramfs-image:do_rootfs')
}
addtask generate_updatehub_dependencies before do_image_complete
do_generate_updatehub_dependencies() {
:
}
UHUPKG = "${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}.${MACHINE}.uhupkg.config"
UPDATEHUB_ACCESS_ID ?= ""
UPDATEHUB_ACCESS_SECRET ?= ""
uhu_setup() {
need_key=$1
# Remove any leftover from previous run
if [ -e ".uhu" ] || [ -e "${UHUPKG}" ]; then
rm -f ".uhu" "${UHUPKG}"
bbdebug 1 "Removed a leftover uhu configuration files from previous run"
fi
if [ -n "${UHUPKG_FULL_PATH}" ]; then
cp ${UHUPKG_FULL_PATH} .uhu
bbdebug 1 "Copied ${UHUPKG_FULL_PATH} as .uhu"
else
bbwarn "No uhupkg.config files from UHUPKG_FILES were found: ${UHUPKG_FILES}. Please set UHUPKG_FILE or UHUPKG_FILES appropriately."
fi
if [ -n "${UPDATEHUB_SERVER_URL}" ]; then
export UHU_SERVER_URL="${UPDATEHUB_SERVER_URL}"
fi
if [ -n "${UPDATEHUB_CUSTOM_CA_CERTS}" ]; then
export UHU_CUSTOM_CA_CERTS="${UPDATEHUB_CUSTOM_CA_CERTS}"
fi
export UHU_PRIVATE_KEY="${UPDATEHUB_UHUPKG_PRIVATE_KEY}"
uhu hardware reset
if [ -n "${UPDATEHUB_COMPATIBLE_MACHINE}" ]; then
machine_list='${UPDATEHUB_COMPATIBLE_MACHINE}'
for machine in $machine_list; do
uhu hardware add "$machine"
done
else
bberror "UPDATEHUB_COMPATIBLE_MACHINE is not set. Aborting."
fi
uhu product use "${UPDATEHUB_PRODUCT_UID}"
uhu package version "${UPDATEHUB_PACKAGE_VERSION}"
# Replace few commonly used variables
sed -e "s,\$IMAGE_BASENAME,${IMAGE_BASENAME},g" \
-e "s,\$MACHINE,${MACHINE},g" \
-e "s,\$UBOOT_BINARY,${UBOOT_BINARY},g" \
-e "s,\$SPL_BINARY,${SPL_BINARY},g" \
-e "s,\$SDIMG_KERNELIMAGE,${SDIMG_KERNELIMAGE},g" \
-e "s,\$BOOTFILES_DIR_NAME,${BOOTFILES_DIR_NAME},g" \
-i .uhu
}
uhu_setup[dirs] ?= "${DEPLOY_DIR_IMAGE}"
uhushell_finish() {
uhu package export ${UHUPKG}
uhu cleanup
# Replace few commonly used variables
sed -e "s,${IMAGE_BASENAME},\$IMAGE_BASENAME,g" \
-e "s,${MACHINE},\$MACHINE,g" \
-e "s,${UBOOT_BINARY},\$UBOOT_BINARY,g" \
-e "s,\$SPL_BINARY,${SPL_BINARY},g" \
-i ${UHUPKG}
}
uhushell_finish[dirs] ?= "${DEPLOY_DIR_IMAGE}"
python do_uhushell () {
bb.build.exec_func('uhu_setup', d)
# We need to know when the command completes we therefore write
# the pid to a file using a wrapper script, then monitor the pid
# until it exits.
import tempfile
pidfile = tempfile.NamedTemporaryFile(delete = False).name
try:
oe_terminal("${SHELL} -c 'echo $$ > %s ; UHU_ACCESS_ID=\"%s\" UHU_ACCESS_SECRET=\"%s\" UHU_PRIVATE_KEY=\"%s\" uhu'" % (
pidfile,
d.getVar('UPDATEHUB_ACCESS_ID'),
d.getVar('UPDATEHUB_ACCESS_SECRET'),
d.getVar('UPDATEHUB_UHUPKG_PRIVATE_KEY')
), "updatehub Shell", d)
while os.stat(pidfile).st_size <= 0:
continue
with open(pidfile, "r") as f:
pid = int(f.readline())
finally:
os.unlink(pidfile)
import time
while True:
try:
os.kill(pid, 0)
except OSError:
break
time.sleep(0.1)
bb.build.exec_func('uhushell_finish', d)
uhupkg = d.getVar('UHUPKG', True)
bb.plain("updatehub package exported in '%s'. Please add it to your image directory." % uhupkg)
}
addtask uhushell after do_image_complete do_unpack
do_uhushell[depends] += "uhu-native:do_populate_sysroot"
do_uhushell[dirs] ?= "${DEPLOY_DIR_IMAGE}"
do_uhushell[nostamp] = "1"
do_uhuarchive() {
uhu_setup
uhu package archive --output ${IMAGE_NAME}.uhupkg
uhu cleanup
ln -sf ${IMAGE_NAME}.uhupkg ${IMAGE_LINK_NAME}.uhupkg
}
addtask uhuarchive after do_image_complete do_unpack
do_uhuarchive[dirs] ?= "${DEPLOY_DIR_IMAGE}"
do_uhuarchive[depends] += "uhu-native:do_populate_sysroot"
do_uhuarchive[progress] = "percent"
do_uhuarchive[nostamp] = "1"
do_uhuarchive[recrdeptask] += "do_deploy"
do_uhupush() {
uhu_setup
if [ -z "${UPDATEHUB_ACCESS_ID}" ] || [ -z "${UPDATEHUB_ACCESS_SECRET}" ]; then
bberror "Both UPDATEHUB_ACCESS_ID and UPDATEHUB_ACCESS_SECRET must be set. Aborting."
fi
if [ -n "${UPDATEHUB_ACCESS_ID}" ] && [ -n "${UPDATEHUB_ACCESS_SECRET}" ]; then
export UHU_ACCESS_ID="${UPDATEHUB_ACCESS_ID}"
export UHU_ACCESS_SECRET="${UPDATEHUB_ACCESS_SECRET}"
fi
uhu package push
uhu cleanup
}
addtask uhupush after do_image_complete do_unpack
do_uhupush[dirs] ?= "${DEPLOY_DIR_IMAGE}"
do_uhupush[depends] += "uhu-native:do_populate_sysroot"
do_uhupush[progress] = "percent"
do_uhupush[nostamp] = "1"
do_uhupush[recrdeptask] += "do_deploy"
do_uhupush[network] = "1"
addtask validate_updatehub_settings before do_uhupush
addtask validate_updatehub_settings before do_uhuarchive
do_validate_updatehub_settings[nostamp] = "1"
python do_validate_updatehub_settings() {
### Ensures product uid is set
product_uid = d.getVar("UPDATEHUB_PRODUCT_UID", False)
if product_uid == '0000000000000000000000000000000000000000000000000000000000000000':
bb.warn("'UPDATEHUB_PRODUCT_UID' is set to a generic id")
### Ensure a valid public and private keys are provided
uhupkg_public_key = d.getVar('UPDATEHUB_UHUPKG_PUBLIC_KEY', True)
uhupkg_private_key = d.getVar('UPDATEHUB_UHUPKG_PRIVATE_KEY', True)
if not uhupkg_public_key or not uhupkg_private_key:
bb.warn("'UPDATEHUB_UHUPKG_PUBLIC_KEY' and 'UPDATEHUB_UHUPKG_PRIVATE_KEY' variables must be set to allow image authenticity verification. The image authenticity will not be verified in the system.")
}