1
- # Revert firmware for the Raspberry Pi 3
1
+ # Post-installation firmware operations for the Raspberry Pi 3
2
+ #
3
+ # Tasks include:
4
+ #
5
+ # * `factory-reset` - Clear out the writable filesystem and any other writable
6
+ # areas so that they can be re-initialized on the next boot.
7
+ # * `prevent-revert` - Prevent `revert` from working until the next firmware
8
+ # * `revert` - Revert to the previous firmware if it's still available
9
+ # * `validate` - Mark this firmware as a good update.
10
+ # * `status` - Print out which partition is active (`a` or `b`)
2
11
#
3
12
# To use:
4
- # 1. Run `fwup -c -f fwup-revert.conf -o revert.fw` and copy revert.fw to
5
- # the device. This is done automatically as part of the Nerves system
6
- # build process. The file is stored in `/usr/share/fwup/revert.fw`.
7
- # 2. On the device, run `fwup -t revert revert.fw -d $NERVES_FW_DEVPATH`. If
8
- # it succeeds, reboot. If not, then it's possible that there isn't a previous
9
- # firmware or the metadata about what's stored where is corrupt or out of
10
- # sync.
13
+ #
14
+ # 1. Run `fwup -c -f fwup-ops.conf -o ops.fw` and copy ops.fw to
15
+ # the device. This is done automatically as part of the Nerves system
16
+ # build process. The file is stored in `/usr/share/fwup/ops.fw`.
17
+ # 2. On the device, run `fwup -t <task> -d /dev/rootdisk0 --enable-trim /usr/share/fwup/ops.fw`.
18
+ # 3. Reboot after running `revert` or `factory-reset`.
11
19
#
12
20
# It is critical that this is kept in sync with the main fwup.conf.
13
21
14
- require-fwup-version="0.19 .0"
22
+ require-fwup-version="1.0 .0"
15
23
16
24
#
17
25
# Firmware metadata
@@ -30,16 +38,8 @@ define(NERVES_FW_PLATFORM, "rpi3")
30
38
define(NERVES_FW_ARCHITECTURE, "arm")
31
39
define(NERVES_FW_AUTHOR, "The Farmbot Team")
32
40
33
- define(NERVES_FW_DEVPATH, "/dev/mmcblk0")
34
- define(NERVES_FW_APPLICATION_PART0_DEVPATH, "/dev/mmcblk0p3") # Linux part number is 1-based
35
- define(NERVES_FW_APPLICATION_PART0_FSTYPE, "ext4")
36
- define(NERVES_FW_APPLICATION_PART0_TARGET, "/root")
37
-
38
- # Default paths if not specified via the commandline
39
- define(ROOTFS, "${NERVES_SYSTEM}/images/rootfs.squashfs")
40
-
41
- # This configuration file will create an image that has an MBR and the
42
- # following 3 partitions:
41
+ # This configuration file will create an image that
42
+ # has an MBR and the following layout:
43
43
#
44
44
# +----------------------------+
45
45
# | MBR |
@@ -150,6 +150,65 @@ uboot-environment uboot-env {
150
150
block-count = ${UBOOT_ENV_COUNT}
151
151
}
152
152
153
+ ##
154
+ # factory-reset
155
+ ##
156
+ task factory-reset {
157
+ on-init {
158
+ info("Erasing all writable data")
159
+ # This requires --enable-trim
160
+ # Trim may not work on MicroSD card, so don't rely on it
161
+ trim(${APP_PART_OFFSET}, ${APP_PART_COUNT})
162
+ raw_memset(${APP_PART_OFFSET}, 256, 0xff)
163
+ }
164
+ }
165
+
166
+ ##
167
+ # prevent-revert
168
+ #
169
+ # Pass `--enable-trim` to also clear out the partition that no longer should be used.
170
+ ##
171
+ task prevent-revert.a {
172
+ # Check that we're running on B
173
+ require-partition-offset(0, ${BOOT_B_PART_OFFSET})
174
+ require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
175
+ require-uboot-variable(uboot-env, "nerves_fw_active", "b")
176
+
177
+ on-init {
178
+ info("Preventing reverts to partition A")
179
+ # Remove U-Boot variables that fwup uses to allow reverting images
180
+ uboot_unsetenv(uboot-env, "a.nerves_fw_platform")
181
+ uboot_unsetenv(uboot-env, "a.nerves_fw_architecture")
182
+ # Clear out the old image using TRIM. This requires --enable-trim
183
+ trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
184
+ trim(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
185
+ }
186
+ }
187
+ task prevent-revert.b {
188
+ # Check that we're running on A
189
+ require-partition-offset(0, ${BOOT_A_PART_OFFSET})
190
+ require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
191
+ require-uboot-variable(uboot-env, "nerves_fw_active", "a")
192
+
193
+ on-init {
194
+ info("Preventing reverts to partition B")
195
+ # Remove U-Boot variables that fwup uses to allow reverting images
196
+ uboot_unsetenv(uboot-env, "b.nerves_fw_platform")
197
+ uboot_unsetenv(uboot-env, "b.nerves_fw_architecture")
198
+ # Clear out the image using TRIM. This requires --enable-trim
199
+ trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
200
+ trim(${BOOT_B_PART_OFFSET}, ${BOOT_B_PART_COUNT})
201
+ }
202
+ }
203
+ task prevent-revert.fail {
204
+ on-init {
205
+ error("Error detecting active partition")
206
+ }
207
+ }
208
+
209
+ ##
210
+ # revert
211
+ ##
153
212
task revert.a {
154
213
# This task reverts to the A partition, so check that we're running on B
155
214
require-partition-offset(0, ${BOOT_B_PART_OFFSET})
@@ -211,7 +270,11 @@ task revert.wrongplatform {
211
270
}
212
271
}
213
272
214
- # Run "fwup /usr/share/fwup/revert.fw -t status -d /dev/mmcblk0 -q -U" to check the status.
273
+ ##
274
+ # status
275
+ #
276
+ # Run "fwup /usr/share/fwup/ops.fw -t status -d /dev/rootdisk0 -q -U" to check the status.
277
+ ##
215
278
task status.aa {
216
279
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
217
280
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
@@ -235,3 +298,15 @@ task status.ba {
235
298
task status.fail {
236
299
on-init { error("fail") }
237
300
}
301
+
302
+ ##
303
+ # validate
304
+ #
305
+ # The fwup configuration for this device always validates, so this doesn't do anything.
306
+ ##
307
+ task validate {
308
+ on-init {
309
+ info("Validate")
310
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
311
+ }
312
+ }
0 commit comments