-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathfwup-ops.conf
More file actions
182 lines (167 loc) · 5.96 KB
/
fwup-ops.conf
File metadata and controls
182 lines (167 loc) · 5.96 KB
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
# Post-installation firmware operations for the Raspberry Pi 3
#
# 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`.
require-fwup-version="1.0.0"
include("${NERVES_SDK_IMAGES:-.}/fwup_include/fwup-common.conf")
##
# factory-reset
##
task factory-reset {
on-init {
info("Erasing all writable data")
# This works better with --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-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-resource autoboot-b.txt {
info("Preventing reverts to partition A")
# Ensure that autoboot is booting the B partition
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "1")
# 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")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "0")
# 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-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-resource autoboot-a.txt {
info("Preventing reverts to partition B")
# Ensure that autoboot is booting the A partition
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "1")
# 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")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "0")
# 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
# and A is valid.
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "1")
on-resource autoboot-a.txt {
info("Reverting to partition A")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
}
}
task revert.b {
# This task reverts to the B partition, so check that we're running on A
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "1")
on-resource autoboot-b.txt {
info("Reverting to partition B")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
}
}
task revert.unexpected.a {
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "1")
on-init {
# Case where A is good, and the desire is to go to B.
error("It doesn't look like there's valid firmware to revert to in partition B.")
}
}
task revert.unexpected.b {
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "1")
on-init {
# Case where B is good, and the desire is to go to A.
error("It doesn't look like there's valid firmware to revert to in partition A.")
}
}
task revert.fail {
on-init { error("Failed") }
}
##
# status
#
# Run "fwup /usr/share/fwup/ops.fw -t status -d /dev/rootdisk0 -q -U" to check the status.
##
task status.ab {
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "0")
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-init { info("a->b") }
}
task status.ba {
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "0")
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-init { info("b->a") }
}
task status.aa {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-init { info("a") }
}
task status.bb {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-init { info("b") }
}
task status.fail {
on-init { error("fail") }
}
##
# validate
#
# Update the autoboot.txt file to unconditionally boot the active partition.
##
task validate.a {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-resource autoboot-a.txt {
info("Validate A")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "1")
uboot_unsetenv(uboot-env, "nerves_fw_active") # Ensure not used to avoid confusion
}
}
task validate.b {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-resource autoboot-b.txt {
info("Validate B")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "1")
uboot_unsetenv(uboot-env, "nerves_fw_active") # Ensure not used to avoid confusion
}
}
task validate.fail {
on-init { error("Failed") }
}