@@ -21,48 +21,6 @@ require-fwup-version="1.0.0"
21
21
22
22
include("${NERVES_SDK_IMAGES:-.}/fwup_include/fwup-common.conf")
23
23
24
- mbr mbr-a {
25
- partition 0 {
26
- block-offset = ${BOOT_A_PART_OFFSET}
27
- block-count = ${BOOT_A_PART_COUNT}
28
- type = 0xc # FAT32
29
- boot = true
30
- }
31
- partition 1 {
32
- block-offset = ${ROOTFS_A_PART_OFFSET}
33
- block-count = ${ROOTFS_A_PART_COUNT}
34
- type = 0x83 # Linux
35
- }
36
- partition 2 {
37
- block-offset = ${APP_PART_OFFSET}
38
- block-count = ${APP_PART_COUNT}
39
- type = 0x83 # Linux
40
- expand = true
41
- }
42
- # partition 3 is unused
43
- }
44
-
45
- mbr mbr-b {
46
- partition 0 {
47
- block-offset = ${BOOT_B_PART_OFFSET}
48
- block-count = ${BOOT_B_PART_COUNT}
49
- type = 0xc # FAT32
50
- boot = true
51
- }
52
- partition 1 {
53
- block-offset = ${ROOTFS_B_PART_OFFSET}
54
- block-count = ${ROOTFS_B_PART_COUNT}
55
- type = 0x83 # Linux
56
- }
57
- partition 2 {
58
- block-offset = ${APP_PART_OFFSET}
59
- block-count = ${APP_PART_COUNT}
60
- type = 0x83 # Linux
61
- expand = true
62
- }
63
- # partition 3 is unused
64
- }
65
-
66
24
# Location where installed firmware information is stored.
67
25
# While this is called "u-boot", u-boot isn't involved in this
68
26
# setup. It just provides a convenient key/value store format.
@@ -90,28 +48,31 @@ task factory-reset {
90
48
##
91
49
task prevent-revert.a {
92
50
# Check that we're running on B
93
- require-partition-offset(0, ${BOOT_B_PART_OFFSET})
94
- require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
95
51
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
96
52
97
- on-init {
53
+ on-resource autoboot-b.txt {
98
54
info("Preventing reverts to partition A")
55
+ # Ensure that autoboot is booting the B partition
56
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
57
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
99
58
# Remove U-Boot variables that fwup uses to allow reverting images
100
59
uboot_unsetenv(uboot-env, "a.nerves_fw_platform")
101
60
uboot_unsetenv(uboot-env, "a.nerves_fw_architecture")
61
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
102
62
# Clear out the old image using TRIM. This requires --enable-trim
103
63
trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
104
64
trim(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
105
65
}
106
66
}
107
67
task prevent-revert.b {
108
68
# Check that we're running on A
109
- require-partition-offset(0, ${BOOT_A_PART_OFFSET})
110
- require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
111
69
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
112
70
113
- on-init {
71
+ on-resource autoboot-a.txt {
114
72
info("Preventing reverts to partition B")
73
+ # Ensure that autoboot is booting the A partition
74
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
75
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
115
76
# Remove U-Boot variables that fwup uses to allow reverting images
116
77
uboot_unsetenv(uboot-env, "b.nerves_fw_platform")
117
78
uboot_unsetenv(uboot-env, "b.nerves_fw_architecture")
@@ -131,39 +92,37 @@ task prevent-revert.fail {
131
92
##
132
93
task revert.a {
133
94
# This task reverts to the A partition, so check that we're running on B
134
- require-partition-offset(0, ${BOOT_B_PART_OFFSET})
135
95
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
136
96
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
137
97
138
98
# Verify that partition A has the expected platform/architecture
139
99
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
140
100
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
141
101
142
- on-init {
102
+ on-resource autoboot-a.txt {
143
103
info("Reverting to partition A")
144
-
145
- # Switch over
104
+ # Update the autoboot first and then the tracking U-Boot variables
105
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
146
106
uboot_setenv(uboot-env, "nerves_fw_active", "a")
147
- mbr_write(mbr-a )
107
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1" )
148
108
}
149
109
}
150
110
151
111
task revert.b {
152
112
# This task reverts to the B partition, so check that we're running on A
153
- require-partition-offset(0, ${BOOT_A_PART_OFFSET})
154
- require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
113
+ require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
155
114
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
156
115
157
116
# Verify that partition B has the expected platform/architecture
158
117
require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
159
118
require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
160
119
161
- on-init {
120
+ on-resource autoboot-b.txt {
162
121
info("Reverting to partition B")
163
-
164
- # Switch over
122
+ # Update the autoboot first and then the tracking U-Boot variables
123
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
165
124
uboot_setenv(uboot-env, "nerves_fw_active", "b")
166
- mbr_write(mbr-b )
125
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1" )
167
126
}
168
127
}
169
128
@@ -222,11 +181,28 @@ task status.fail {
222
181
##
223
182
# validate
224
183
#
225
- # The fwup configuration for this device always validates, so this doesn't do anything .
184
+ # Update the autoboot.txt file to unconditionally boot the active partition .
226
185
##
227
- task validate {
228
- on-init {
229
- info("Validate")
186
+ task validate.a {
187
+ require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
188
+ require-uboot-variable(uboot-env, "nerves_fw_active", "a")
189
+
190
+ on-resource autoboot-a.txt {
191
+ info("Validate A")
192
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
193
+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
194
+ }
195
+ }
196
+ task validate.b {
197
+ require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
198
+ require-uboot-variable(uboot-env, "nerves_fw_active", "b")
199
+
200
+ on-resource autoboot-b.txt {
201
+ info("Validate B")
202
+ fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
230
203
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
231
204
}
232
205
}
206
+ task validate.fail {
207
+ on-init { error("Can't validate unless running from active partition") }
208
+ }
0 commit comments