1
- # Revert firmware on the MangoPi MQ Pro
1
+ # Post-installation firmware operations for the MangoPi MQ Pro
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
@@ -36,28 +44,37 @@ define(NERVES_FW_AUTHOR, "The Nerves Team")
36
44
# +----------------------------+
37
45
# | MBR |
38
46
# +----------------------------+
39
- # | boot0 |
40
- # +----------------------------+
41
- # | boot0 copy (unused) |
47
+ # | SPL and U-Boot |
42
48
# +----------------------------+
43
49
# | U-Boot environment |
44
50
# +----------------------------+
45
- # | U-Boot |
46
- # +----------------------------+
47
- # | U-Boot copy (unused) |
48
- # +----------------------------+
49
51
# | p1: Rootfs A (squashfs) |
50
52
# +----------------------------+
51
53
# | p2: Rootfs B (squashfs) |
52
54
# +----------------------------+
53
55
# | p3: Application (f2fs) |
54
56
# +----------------------------+
55
57
58
+ define(UBOOT_OFFSET, 16)
59
+ define(UBOOT_COUNT, 8176)
60
+
56
61
# The U-Boot environment is written directly to the SDCard/eMMC. It is not
57
62
# in any partition
58
- define(UBOOT_ENV_OFFSET, 1792 )
63
+ define(UBOOT_ENV_OFFSET, 8192 )
59
64
define(UBOOT_ENV_COUNT, 256) # 128 KB
60
65
66
+ # Let the rootfs have room to grow up to 140 MiB and align it to the nearest 1
67
+ # MB boundary
68
+ define(ROOTFS_A_PART_OFFSET, 43008)
69
+ define(ROOTFS_A_PART_COUNT, 286720)
70
+ define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}")
71
+ define(ROOTFS_B_PART_COUNT, ${ROOTFS_A_PART_COUNT})
72
+
73
+ # Application partition. This partition can occupy all of the remaining space.
74
+ # Size it to fit the destination.
75
+ define-eval(APP_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}")
76
+ define(APP_PART_COUNT, 1048576)
77
+
61
78
# Firmware archive metadata
62
79
meta-product = ${NERVES_FW_PRODUCT}
63
80
meta-description = ${NERVES_FW_DESCRIPTION}
@@ -74,6 +91,59 @@ uboot-environment uboot-env {
74
91
block-count = ${UBOOT_ENV_COUNT}
75
92
}
76
93
94
+ ##
95
+ # factory-reset
96
+ ##
97
+ task factory-reset {
98
+ on-init {
99
+ info("Erasing all writable data")
100
+ # This requires --enable-trim
101
+ # Trim may not work on MicroSD card, so don't rely on it
102
+ trim(${APP_PART_OFFSET}, ${APP_PART_COUNT})
103
+ raw_memset(${APP_PART_OFFSET}, 256, 0xff)
104
+ }
105
+ }
106
+
107
+ ##
108
+ # prevent-revert
109
+ #
110
+ # Pass `--enable-trim` to also clear out the partition that no longer should be used.
111
+ ##
112
+ task prevent-revert.a {
113
+ # Check that we're running on B
114
+ require-uboot-variable(uboot-env, "nerves_fw_active", "b")
115
+
116
+ on-init {
117
+ info("Preventing reverts to partition A")
118
+ # Remove U-Boot variables that fwup uses to allow reverting images
119
+ uboot_unsetenv(uboot-env, "a.nerves_fw_platform")
120
+ uboot_unsetenv(uboot-env, "a.nerves_fw_architecture")
121
+ # Clear out the old image using TRIM. This requires --enable-trim
122
+ trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
123
+ }
124
+ }
125
+ task prevent-revert.b {
126
+ # Check that we're running on A
127
+ require-uboot-variable(uboot-env, "nerves_fw_active", "a")
128
+
129
+ on-init {
130
+ info("Preventing reverts to partition B")
131
+ # Remove U-Boot variables that fwup uses to allow reverting images
132
+ uboot_unsetenv(uboot-env, "b.nerves_fw_platform")
133
+ uboot_unsetenv(uboot-env, "b.nerves_fw_architecture")
134
+ # Clear out the image using TRIM. This requires --enable-trim
135
+ trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
136
+ }
137
+ }
138
+ task prevent-revert.fail {
139
+ on-init {
140
+ error("Error detecting active partition")
141
+ }
142
+ }
143
+
144
+ ##
145
+ # revert
146
+ ##
77
147
task revert.a {
78
148
# This task reverts to the A partition, so check that we're running on B
79
149
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
@@ -131,7 +201,11 @@ task revert.wrongplatform {
131
201
}
132
202
}
133
203
134
- # Run "fwup /usr/share/fwup/revert.fw -t status -d /dev/mmcblk0 -q -U" to check the status.
204
+ ##
205
+ # status
206
+ #
207
+ # Run "fwup /usr/share/fwup/ops.fw -t status -d /dev/rootdisk0 -q -U" to check the status.
208
+ ##
135
209
task status.aa {
136
210
require-path-on-device("/", "/dev/mmcblk0p2")
137
211
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
@@ -155,3 +229,15 @@ task status.ba {
155
229
task status.fail {
156
230
on-init { error("fail") }
157
231
}
232
+
233
+ ##
234
+ # validate
235
+ ##
236
+ task validate {
237
+ on-init {
238
+ info("Validate")
239
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
240
+ uboot_setenv(uboot-env, "upgrade_available", "0")
241
+ uboot_setenv(uboot-env, "bootcount", "1")
242
+ }
243
+ }
0 commit comments