-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu.fwup.conf
302 lines (262 loc) · 13.1 KB
/
qemu.fwup.conf
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# Firmware configuration file for qemuarm64-secureboot system
require-fwup-version="1.4.0"
define(UBOOT_ENV_OFFSET, "${PERIDIO_UBOOT_ENV_OFFSET}")
define(UBOOT_ENV_COUNT, "${PERIDIO_UBOOT_ENV_COUNT}")
define-eval(UBOOT_ENV_REDUND_OFFSET, "${PERIDIO_UBOOT_ENV_OFFSET} + ${UBOOT_ENV_COUNT} * 2")
# Boot
define(BOOT_A_PART_OFFSET, "${PERIDIO_BOOTFS_OFFSET_BLOCKS}")
define-eval(BOOT_A_PART_COUNT, "${PERIDIO_BOOTFS_SIZE_MB} * 1024 * 1024 / ${PERIDIO_DISK_BLOCK_SIZE}")
define-eval(BOOT_B_PART_OFFSET, "${BOOT_A_PART_OFFSET} + ${BOOT_A_PART_COUNT}")
define(BOOT_B_PART_COUNT, ${BOOT_A_PART_COUNT})
# RootFS
define-eval(ROOTFS_A_PART_OFFSET, "${BOOT_B_PART_OFFSET} + ${BOOT_B_PART_COUNT}")
define-eval(ROOTFS_A_PART_COUNT, "${PERIDIO_ROOTFS_SIZE_MB} * 1024 * 1024 / ${PERIDIO_DISK_BLOCK_SIZE}")
define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}")
define(ROOTFS_B_PART_COUNT, ${ROOTFS_A_PART_COUNT})
# Data
define-eval(DATA_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}")
define-eval(DATA_PART_COUNT, "${PERIDIO_DATAFS_SIZE_MB} * 1024 * 1024 / ${PERIDIO_DISK_BLOCK_SIZE}")
define(PERIDIO_DISK_UUID, "2fbebe4d-0b70-4121-a2a3-5d2cc58d46e2")
define(PERIDIO_DISK_UBOOT_ENV_UUID, "ba5cc62e-6f1f-4321-9ee4-907e9f8b6a94")
define(PERIDIO_DISK_BOOT_A_UUID, "ef8cbeb1-eac7-4f6e-87d9-d4c106cd50ea")
define(PERIDIO_DISK_BOOT_B_UUID, "90940628-add3-4b05-a0cd-5e900c9472ad")
define(PERIDIO_DISK_ROOTFS_A_UUID, "894cdc22-d192-47f5-961b-f5d7f6196803")
define(PERIDIO_DISK_ROOTFS_B_UUID, "83539304-93ab-4092-ad71-db21d3ac7253")
define(PERIDIO_DISK_DATA_UUID, "62fc6879-3d47-4895-9b53-105cc57fe3ac")
define(GPT_DISK_BOOT_DATA_TYPE, "21686148-6449-6E6F-744E-656564454649")
define(GPT_DISK_LINUX_DATA_TYPE, "0fc63daf-8483-4772-8e79-3d69d8477de4")
# Firmware archive metadata
meta-product = ${PERIDIO_META_PRODUCT}
meta-description = ${PERIDIO_META_DESCRIPTION}
meta-version = ${PERIDIO_META_VERSION}
meta-platform = ${PERIDIO_META_PLATFORM}
meta-architecture = ${PERIDIO_META_ARCHITECTURE}
meta-author = ${PERIDIO_META_AUTHOR}
meta-vcs-identifier = ${PERIDIO_META_VCS_IDENTIFIER}
meta-misc = ${PERIDIO_META_MISC}
gpt gpt {
guid = ${PERIDIO_DISK_UUID}
partition 0 {
block-offset = ${UBOOT_ENV_OFFSET}
block-count = ${UBOOT_ENV_COUNT}
type = ${GPT_DISK_LINUX_DATA_TYPE}
guid = ${PERIDIO_DISK_UBOOT_ENV_UUID}
name = "ubootenv"
}
partition 1 {
block-offset = ${BOOT_A_PART_OFFSET}
block-count = ${BOOT_A_PART_COUNT}
type = ${GPT_DISK_BOOT_DATA_TYPE}
guid = ${PERIDIO_DISK_BOOT_A_UUID}
name = "boot-a"
}
partition 2 {
block-offset = ${BOOT_B_PART_OFFSET}
block-count = ${BOOT_B_PART_COUNT}
type = ${GPT_DISK_BOOT_DATA_TYPE}
guid = ${PERIDIO_DISK_BOOT_B_UUID}
name = "boot-b"
}
partition 3 {
block-offset = ${ROOTFS_A_PART_OFFSET}
block-count = ${ROOTFS_A_PART_COUNT}
type = ${GPT_DISK_LINUX_DATA_TYPE}
guid = ${PERIDIO_DISK_ROOTFS_A_UUID}
name = "rootfs-a"
}
partition 4 {
block-offset = ${ROOTFS_B_PART_OFFSET}
block-count = ${ROOTFS_B_PART_COUNT}
type = ${GPT_DISK_LINUX_DATA_TYPE}
guid = ${PERIDIO_DISK_ROOTFS_B_UUID}
name = "rootfs-b"
}
partition 5 {
block-offset = ${DATA_PART_OFFSET}
block-count = ${DATA_PART_COUNT}
type = ${GPT_DISK_LINUX_DATA_TYPE}
guid = ${PERIDIO_DISK_DATA_UUID}
name = "data"
}
}
# Location where installed firmware information is stored.
# While this is called "u-boot", u-boot isn't involved in this
# setup. It just provides a convenient key/value store format.
uboot-environment uboot-env {
block-offset = ${UBOOT_ENV_OFFSET}
block-count = ${UBOOT_ENV_COUNT}
block-offset-redund = ${UBOOT_ENV_REDUND_OFFSET}
}
file-resource uboot.env {
host-path = "${PERIDIO_HOST_IMAGE_DIR}/uboot.env"
}
file-resource Image {
host-path = "${PERIDIO_HOST_IMAGE_DIR}/Image"
}
file-resource avocado-initramfs {
host-path = "${PERIDIO_HOST_IMAGE_DIR}/avocado-image-initramfs-${MACHINE}.cpio.gz"
}
file-resource rootfs.img {
host-path = "${PERIDIO_HOST_ROOTFS_DIR}/${PERIDIO_ROOTFS_FILE}"
# Error out if the rootfs size exceeds the partition size
assert-size-lte = ${ROOTFS_A_PART_COUNT}
}
# This firmware task writes everything to the destination media.
# This should only be run for the first installation.
task complete {
# Only match if not mounted
require-unmounted-destination = true
on-init {
gpt_write(gpt)
fat_mkfs(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
fat_setlabel(${BOOT_A_PART_OFFSET}, "BOOT-A")
}
on-resource uboot.env {
raw_write(${UBOOT_ENV_OFFSET})
uboot_setenv(uboot-env, "peridio_key", "\${PERIDIO_PRIVATE_KEY}")
uboot_setenv(uboot-env, "peridio_certificate", "\${PERIDIO_CERTIFICATE}")
uboot_setenv(uboot-env, "peridio_active", "a")
uboot_setenv(uboot-env, "peridio_validated", "1")
uboot_setenv(uboot-env, "peridio_autovalidate", "1")
uboot_setenv(uboot-env, "peridio_booted", "0")
uboot_setenv(uboot-env, "peridio_initramfs_shell", "0")
uboot_setenv(uboot-env, "peridio_disk_devpath", ${PERIDIO_DISK_DEVPATH})
uboot_setenv(uboot-env, "a.peridio_rootfs_part_devpath", ${PERIDIO_ROOTFS_A_PART_DEVPATH})
uboot_setenv(uboot-env, "a.peridio_rootfs_part_type", ${PERIDIO_ROOTFS_A_PART_TYPE})
uboot_setenv(uboot-env, "a.peridio_datafs_part_devpath", ${PERIDIO_DATAFS_PART_DEVPATH})
uboot_setenv(uboot-env, "a.peridio_datafs_part_type", ${PERIDIO_DATAFS_PART_TYPE})
uboot_setenv(uboot-env, "a.peridio_datafs_part_mountpoint", ${PERIDIO_DATAFS_PART_MOUNTPOINT})
uboot_setenv(uboot-env, "a.peridio_product", ${PERIDIO_META_PRODUCT})
uboot_setenv(uboot-env, "a.peridio_description", ${PERIDIO_META_DESCRIPTION})
uboot_setenv(uboot-env, "a.peridio_version", ${PERIDIO_META_VERSION})
uboot_setenv(uboot-env, "a.peridio_platform", ${PERIDIO_META_PLATFORM})
uboot_setenv(uboot-env, "a.peridio_architecture", ${PERIDIO_META_ARCHITECTURE})
uboot_setenv(uboot-env, "a.peridio_author", ${PERIDIO_META_AUTHOR})
uboot_setenv(uboot-env, "a.peridio_vcs_identifier", ${PERIDIO_META_VCS_IDENTIFIER})
uboot_setenv(uboot-env, "a.peridio_misc", ${PERIDIO_META_MISC})
uboot_setenv(uboot-env, "a.peridio_uuid", "\${FWUP_META_UUID}")
}
on-resource Image { fat_write(${BOOT_A_PART_OFFSET}, "Image") }
on-resource avocado-initramfs { fat_write(${BOOT_A_PART_OFFSET}, "avocado-initramfs") }
on-resource rootfs.img { raw_write(${ROOTFS_A_PART_OFFSET}) }
on-finish {
# Clear out any old data in the B partition that might be mistaken for
# a file system. This is mostly to avoid confusion in humans when
# reprogramming SDCards with unknown contents.
raw_memset(${ROOTFS_B_PART_OFFSET}, 256, 0xff)
# Invalidate the application data partition so that it is guaranteed to
# trigger the corrupt filesystem detection code on first boot and get
# formatted.
raw_memset(${DATA_PART_OFFSET}, 256, 0xff)
}
}
task upgrade.a {
# This task upgrades the A partition, so make sure we're running
# on B.
require-uboot-variable(uboot-env, "peridio_active", "b")
# Verify the expected platform/architecture
require-uboot-variable(uboot-env, "b.peridio_platform", "${PERIDIO_META_PLATFORM}")
require-uboot-variable(uboot-env, "b.peridio_architecture", "${PERIDIO_META_ARCHITECTURE}")
on-init {
info("Upgrading partition A")
# Clear some firmware information just in case this update gets
# interrupted midway. If this partition was bootable, it's not going to
# be soon.
uboot_unsetenv(uboot-env, "a.peridio_version")
uboot_unsetenv(uboot-env, "a.peridio_platform")
uboot_unsetenv(uboot-env, "a.peridio_architecture")
uboot_unsetenv(uboot-env, "a.peridio_uuid")
trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
fat_mkfs(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
fat_setlabel(${BOOT_A_PART_OFFSET}, "BOOT-A")
}
on-resource Image { fat_write(${BOOT_A_PART_OFFSET}, "Image") }
on-resource avocado-initramfs { fat_write(${BOOT_A_PART_OFFSET}, "avocado-initramfs") }
on-resource rootfs.img {
delta-source-raw-offset=${ROOTFS_B_PART_OFFSET}
delta-source-raw-count=${ROOTFS_B_PART_COUNT}
raw_write(${ROOTFS_A_PART_OFFSET})
}
on-finish {
# Update firmware metedata
uboot_setenv(uboot-env, "peridio_validated", "0")
uboot_setenv(uboot-env, "peridio_booted", "0")
uboot_setenv(uboot-env, "a.peridio_rootfs_part_devpath", ${PERIDIO_ROOTFS_A_PART_DEVPATH})
uboot_setenv(uboot-env, "a.peridio_rootfs_part_type", ${PERIDIO_ROOTFS_A_PART_TYPE})
uboot_setenv(uboot-env, "a.peridio_datafs_part_devpath", ${PERIDIO_DATAFS_PART_DEVPATH})
uboot_setenv(uboot-env, "a.peridio_datafs_part_type", ${PERIDIO_DATAFS_PART_TYPE})
uboot_setenv(uboot-env, "a.peridio_datafs_part_mountpoint", ${PERIDIO_DATAFS_PART_MOUNTPOINT})
uboot_setenv(uboot-env, "a.peridio_product", ${PERIDIO_META_PRODUCT})
uboot_setenv(uboot-env, "a.peridio_description", ${PERIDIO_META_DESCRIPTION})
uboot_setenv(uboot-env, "a.peridio_version", ${PERIDIO_META_VERSION})
uboot_setenv(uboot-env, "a.peridio_platform", ${PERIDIO_META_PLATFORM})
uboot_setenv(uboot-env, "a.peridio_architecture", ${PERIDIO_META_ARCHITECTURE})
uboot_setenv(uboot-env, "a.peridio_author", ${PERIDIO_META_AUTHOR})
uboot_setenv(uboot-env, "a.peridio_vcs_identifier", ${PERIDIO_META_VCS_IDENTIFIER})
uboot_setenv(uboot-env, "a.peridio_misc", ${PERIDIO_META_MISC})
uboot_setenv(uboot-env, "a.peridio_uuid", "\${FWUP_META_UUID}")
# Reset the validation status and boot to A
# next time.
uboot_setenv(uboot-env, "peridio_active", "a")
}
}
task upgrade.b {
# This task upgrades the B partition, so make sure we're running
# on A.
require-uboot-variable(uboot-env, "peridio_active", "a")
# Verify the expected platform/architecture
require-uboot-variable(uboot-env, "a.peridio_platform", "${PERIDIO_META_PLATFORM}")
require-uboot-variable(uboot-env, "a.peridio_architecture", "${PERIDIO_META_ARCHITECTURE}")
on-init {
info("Upgrading partition B")
# Clear some firmware information just in case this update gets
# interrupted midway.
uboot_unsetenv(uboot-env, "b.peridio_version")
uboot_unsetenv(uboot-env, "b.peridio_platform")
uboot_unsetenv(uboot-env, "b.peridio_architecture")
uboot_unsetenv(uboot-env, "b.peridio_uuid")
trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
fat_mkfs(${BOOT_B_PART_OFFSET}, ${BOOT_B_PART_COUNT})
fat_setlabel(${BOOT_B_PART_OFFSET}, "BOOT-B")
}
on-resource Image { fat_write(${BOOT_B_PART_OFFSET}, "Image") }
on-resource avocado-initramfs { fat_write(${BOOT_B_PART_OFFSET}, "avocado-initramfs") }
on-resource rootfs.img {
delta-source-raw-offset=${ROOTFS_A_PART_OFFSET}
delta-source-raw-count=${ROOTFS_A_PART_COUNT}
raw_write(${ROOTFS_B_PART_OFFSET})
}
on-finish {
# Update firmware metadata
uboot_setenv(uboot-env, "peridio_validated", "0")
uboot_setenv(uboot-env, "peridio_booted", "0")
uboot_setenv(uboot-env, "b.peridio_rootfs_part_devpath", ${PERIDIO_ROOTFS_B_PART_DEVPATH})
uboot_setenv(uboot-env, "b.peridio_rootfs_part_type", ${PERIDIO_ROOTFS_B_PART_TYPE})
uboot_setenv(uboot-env, "b.peridio_datafs_part_devpath", ${PERIDIO_DATAFS_PART_DEVPATH})
uboot_setenv(uboot-env, "b.peridio_datafs_part_type", ${PERIDIO_DATAFS_PART_TYPE})
uboot_setenv(uboot-env, "b.peridio_datafs_part_mountpoint", ${PERIDIO_DATAFS_PART_MOUNTPOINT})
uboot_setenv(uboot-env, "b.peridio_product", ${PERIDIO_META_PRODUCT})
uboot_setenv(uboot-env, "b.peridio_description", ${PERIDIO_META_DESCRIPTION})
uboot_setenv(uboot-env, "b.peridio_version", ${PERIDIO_META_VERSION})
uboot_setenv(uboot-env, "b.peridio_platform", ${PERIDIO_META_PLATFORM})
uboot_setenv(uboot-env, "b.peridio_architecture", ${PERIDIO_META_ARCHITECTURE})
uboot_setenv(uboot-env, "b.peridio_author", ${PERIDIO_META_AUTHOR})
uboot_setenv(uboot-env, "b.peridio_vcs_identifier", ${PERIDIO_META_VCS_IDENTIFIER})
uboot_setenv(uboot-env, "b.peridio_misc", ${PERIDIO_META_MISC})
uboot_setenv(uboot-env, "b.peridio_uuid", "\${FWUP_META_UUID}")
# Reset the validation status and boot to B next time.
uboot_setenv(uboot-env, "peridio_active", "b")
}
}
task upgrade.wrong {
require-uboot-variable(uboot-env, "a.peridio_platform", "${PERIDIO_META_PLATFORM}")
require-uboot-variable(uboot-env, "a.peridio_architecture", "${PERIDIO_META_ARCHITECTURE}")
on-init {
error("Please check the media being upgraded. It doesn't look like either the A or B partitions are active.")
}
}
task upgrade.wrongplatform {
on-init {
error("Expecting platform=${PERIDIO_META_PLATFORM} and architecture=${PERIDIO_META_ARCHITECTURE}")
}
}