forked from nerves-project/nerves_system_rpi4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fwup-ops.conf
416 lines (372 loc) · 13.8 KB
/
fwup-ops.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# # Post-installation firmware operations for the Raspberry Pi 4
#
# Tasks include:
#
# * `factory-reset` - Clear out the writable filesystem and any other writable
# areas so that they can be re-initialized on the next boot.
# * `prevent-revert` - Prevent `revert` from working until the next firmware
# * `revert` - Revert to the previous firmware if it's still available
# * `validate` - Mark this firmware as a good update.
# * `status` - Print out which partition is active (`a` or `b`)
#
# To use:
#
# 1. Run `fwup -c -f fwup-ops.conf -o ops.fw` and copy ops.fw to
# the device. This is done automatically as part of the Nerves system
# build process. The file is stored in `/usr/share/fwup/ops.fw`.
# 2. On the device, run `fwup -t <task> -d /dev/rootdisk0 --enable-trim /usr/share/fwup/ops.fw`.
# 3. Reboot after running `revert` or `factory-reset`.
#
# It is critical that this is kept in sync with the main fwup.conf.
require-fwup-version="1.0.0"
#
# Firmware metadata
#
# All of these can be overriden using environment variables of the same name.
#
# Run 'fwup -m' to query values in a .fw file.
# Use 'fw_printenv' to query values on the target.
#
# These are used by Nerves libraries to introspect.
define(NERVES_FW_PRODUCT, "Nerves Firmware")
define(NERVES_FW_DESCRIPTION, "")
define(NERVES_FW_VERSION, "${NERVES_SDK_VERSION}")
define(NERVES_FW_PLATFORM, "ly11_rpi4")
define(NERVES_FW_ARCHITECTURE, "arm")
define(NERVES_FW_AUTHOR, "Blue Clover Devices")
define(NERVES_FW_DEVPATH, "/dev/mmcblk0")
define(NERVES_FW_APPLICATION_PART0_DEVPATH, "tmpfs") # Linux part number is 1-based
define(NERVES_FW_APPLICATION_PART0_FSTYPE, "tmpfs")
define(NERVES_FW_APPLICATION_PART0_TARGET, "/root")
define(NERVES_FW_PARTITION_SCHEME, "1.1GB root")
define(OLD_NERVES_FW_PARTITION_SCHEME, "141MB root")
# Default paths if not specified via the commandline
define(ROOTFS, "${NERVES_SYSTEM}/images/rootfs.squashfs")
# This configuration file will create an image that
# has an MBR and the following layout:
#
# +----------------------------+
# | MBR |
# +----------------------------+
# | Firmware configuration data|
# | (formatted as uboot env) |
# +----------------------------+
# | p0*: Boot A (FAT32) |
# | kernel8.img, start4.elf, |
# | config.txt, etc. |
# +----------------------------+
# | p0*: Boot B (FAT32) |
# +----------------------------+
# | p1*: Rootfs A (squashfs) |
# +----------------------------+
# | p1*: Rootfs B (squashfs) |
# +----------------------------+
# | p2: Application (f2fs) |
# +----------------------------+
#
# The p0/p1 partition points to whichever of configurations A or B that is
# active.
#
# The image is sized to be less than 1 GB so that it fits on nearly any SDCard
# around. If you have a larger SDCard and need more space, feel free to bump
# the partition sizes below.
# The Raspberry Pi is incredibly picky on the partition sizes and in ways that
# I don't understand. Test changes one at a time to make sure that they boot.
# (Sizes are in 512 byte blocks)
define(UBOOT_ENV_OFFSET, 16)
define(UBOOT_ENV_COUNT, 16) # 8 KB
define(BOOT_A_PART_OFFSET, 63)
define(BOOT_A_PART_COUNT, 38630)
define-eval(BOOT_B_PART_OFFSET, "${BOOT_A_PART_OFFSET} + ${BOOT_A_PART_COUNT}")
define(BOOT_B_PART_COUNT, ${BOOT_A_PART_COUNT})
# Previous used partition values
define(OLD_ROOTFS_A_PART_OFFSET, 77324)
define(OLD_ROOTFS_A_PART_COUNT, 289044)
define-eval(OLD_ROOTFS_B_PART_OFFSET, "${OLD_ROOTFS_A_PART_OFFSET} + ${OLD_ROOTFS_A_PART_COUNT}")
define(OLD_ROOTFS_B_PART_COUNT, ${OLD_ROOTFS_A_PART_COUNT})
define-eval(OLD_APP_PART_OFFSET, "${OLD_ROOTFS_B_PART_OFFSET} + ${OLD_ROOTFS_B_PART_COUNT}")
# Let the rootfs have room to grow up to 1 GiB and align it to the nearest 1
# MB boundary
define-eval(ROOTFS_A_PART_OFFSET, "${OLD_ROOTFS_B_PART_OFFSET} + ${OLD_ROOTFS_B_PART_COUNT}")
define(ROOTFS_A_PART_COUNT, 2312352)
define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}")
define(ROOTFS_B_PART_COUNT, ${ROOTFS_A_PART_COUNT})
# Application partition. This partition can occupy all of the remaining space.
# Size it to fit the destination.
define-eval(APP_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}")
define(APP_PART_COUNT, 1048576)
# Firmware archive metadata
meta-product = ${NERVES_FW_PRODUCT}
meta-description = ${NERVES_FW_DESCRIPTION}
meta-version = ${NERVES_FW_VERSION}
meta-platform = ${NERVES_FW_PLATFORM}
meta-architecture = ${NERVES_FW_ARCHITECTURE}
meta-author = ${NERVES_FW_AUTHOR}
meta-vcs-identifier = ${NERVES_FW_VCS_IDENTIFIER}
meta-misc = ${NERVES_FW_MISC}
mbr mbr-a {
partition 0 {
block-offset = ${BOOT_A_PART_OFFSET}
block-count = ${BOOT_A_PART_COUNT}
type = 0xc # FAT32
boot = true
}
partition 1 {
block-offset = ${ROOTFS_A_PART_OFFSET}
block-count = ${ROOTFS_A_PART_COUNT}
type = 0x83 # Linux
}
# partition 2 {
# block-offset = ${app_part_offset}
# block-count = ${app_part_count}
# type = 0x83 # linux
# expand = true
# }
# partition 3 is unused
}
mbr mbr-a-old {
partition 0 {
block-offset = ${BOOT_A_PART_OFFSET}
block-count = ${BOOT_A_PART_COUNT}
type = 0xc # FAT32
boot = true
}
partition 1 {
block-offset = ${OLD_ROOTFS_A_PART_OFFSET}
block-count = ${OLD_ROOTFS_A_PART_COUNT}
type = 0x83 # Linux
}
# partition 2 {
# block-offset = ${app_part_offset}
# block-count = ${app_part_count}
# type = 0x83 # linux
# expand = true
# }
# partition 3 is unused
}
mbr mbr-b {
partition 0 {
block-offset = ${BOOT_B_PART_OFFSET}
block-count = ${BOOT_B_PART_COUNT}
type = 0xc # FAT32
boot = true
}
partition 1 {
block-offset = ${ROOTFS_B_PART_OFFSET}
block-count = ${ROOTFS_B_PART_COUNT}
type = 0x83 # Linux
}
# partition 2 {
# block-offset = ${APP_PART_OFFSET}
# block-count = ${APP_PART_COUNT}
# type = 0x83 # Linux
# expand = true
# }
# partition 3 is unused
}
mbr mbr-b-old {
partition 0 {
block-offset = ${BOOT_B_PART_OFFSET}
block-count = ${BOOT_B_PART_COUNT}
type = 0xc # FAT32
boot = true
}
partition 1 {
block-offset = ${OLD_ROOTFS_B_PART_OFFSET}
block-count = ${OLD_ROOTFS_B_PART_COUNT}
type = 0x83 # Linux
}
# partition 2 {
# block-offset = ${APP_PART_OFFSET}
# block-count = ${APP_PART_COUNT}
# type = 0x83 # Linux
# expand = true
# }
# partition 3 is unused
}
# 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}
}
##
# factory-reset
##
task factory-reset {
on-init {
info("Erasing all writable data")
# This requires --enable-trim
# Trim may not work on MicroSD card, so don't rely on it
trim(${APP_PART_OFFSET}, ${APP_PART_COUNT})
raw_memset(${APP_PART_OFFSET}, 256, 0xff)
}
}
##
# prevent-revert
#
# Pass `--enable-trim` to also clear out the partition that no longer should be used.
##
task prevent-revert.a {
# Check that we're running on B
require-partition-offset(0, ${BOOT_B_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
on-init {
info("Preventing reverts to partition A")
# Remove U-Boot variables that fwup uses to allow reverting images
uboot_unsetenv(uboot-env, "a.nerves_fw_platform")
uboot_unsetenv(uboot-env, "a.nerves_fw_architecture")
# Clear out the old image using TRIM. This requires --enable-trim
trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
trim(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
}
}
task prevent-revert.b {
# Check that we're running on A
require-partition-offset(0, ${BOOT_A_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
on-init {
info("Preventing reverts to partition B")
# Remove U-Boot variables that fwup uses to allow reverting images
uboot_unsetenv(uboot-env, "b.nerves_fw_platform")
uboot_unsetenv(uboot-env, "b.nerves_fw_architecture")
# Clear out the image using TRIM. This requires --enable-trim
trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
trim(${BOOT_B_PART_OFFSET}, ${BOOT_B_PART_COUNT})
}
}
task prevent-revert.fail {
on-init {
error("Error detecting active partition")
}
}
##
# revert
##
task revert.a {
# This task reverts to the A partition, so check that we're running on B
require-partition-offset(0, ${BOOT_B_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
# Verify that partition A has the expected platform/architecture
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
require-uboot-variable(uboot-env, "a.nerves_fw_partition_scheme", "${NERVES_FW_PARTITION_SCHEME}")
on-init {
info("Reverting to partition A")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "a")
mbr_write(mbr-a)
}
}
task revert.a-old {
# This task reverts to the A partition, so check that we're running on B
require-partition-offset(0, ${BOOT_B_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
# Verify that partition A has the expected platform/architecture
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
require-uboot-variable(uboot-env, "a.nerves_fw_partition_scheme", "${OLD_NERVES_FW_PARTITION_SCHEME}")
on-init {
info("Reverting to OLD partition A")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "a")
mbr_write(mbr-a-old)
}
}
task revert.b {
# This task reverts to the B partition, so check that we're running on A
require-partition-offset(0, ${BOOT_A_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
# Verify that partition B has the expected platform/architecture
require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
require-uboot-variable(uboot-env, "b.nerves_fw_partition_scheme", "${NERVES_FW_PARTITION_SCHEME}")
on-init {
info("Reverting to partition B")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "b")
mbr_write(mbr-b)
}
}
task revert.b-old {
# This task reverts to the B partition, so check that we're running on A
require-partition-offset(0, ${BOOT_A_PART_OFFSET})
require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
# Verify that partition B has the expected platform/architecture
require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
require-uboot-variable(uboot-env, "b.nerves_fw_partition_scheme", "${OLD_NERVES_FW_PARTITION_SCHEME}")
on-init {
info("Reverting to partition OLD B")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "b")
mbr_write(mbr-b-old)
}
}
task revert.unexpected.a {
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
on-init {
# Case where A is good, and the desire is to go to B.
error("It doesn't look like there's anything to revert to in partition B.")
}
}
task revert.unexpected.b {
require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
on-init {
# Case where B is good, and the desire is to go to A.
error("It doesn't look like there's anything to revert to in partition A.")
}
}
task revert.wrongplatform {
on-init {
error("Expecting platform=${NERVES_FW_PLATFORM} and architecture=${NERVES_FW_ARCHITECTURE}")
}
}
##
# status
#
# Run "fwup /usr/share/fwup/ops.fw -t status -d /dev/rootdisk0 -q -U" to check the status.
##
task status.aa {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
on-init { info("a") }
}
task status.ab {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
on-init { info("a->b") }
}
task status.bb {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
on-init { info("b") }
}
task status.ba {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
on-init { info("b->a") }
}
task status.fail {
on-init { error("fail") }
}
##
# validate
#
# The fwup configuration for this device always validates, so this doesn't do anything.
##
task validate {
on-init {
info("Validate")
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
}
}