-
Notifications
You must be signed in to change notification settings - Fork 0
/
fwup-revert.conf
327 lines (292 loc) · 11.2 KB
/
fwup-revert.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
# Revert firmware configuration file for the ODYSSEY - STM32MP157C
#
# To use:
# 1. Run `fwup -c -f fwup-revert.conf -o revert.fw` and copy revert.fw to
# the device. This is done automatically as part of the Nerves system
# build process. The file is stored in `/usr/share/fwup/revert.fw`.
# 2. On the device, run `fwup -t revert revert.fw -d $NERVES_FW_DEVPATH`. If
# it succeeds, reboot. If not, then it's possible that there isn't a previous
# firmware or the metadata about what's stored where is corrupt or out of
# sync.
#
# It is critical that this is kept in sync with the main fwup.conf.
require-fwup-version="1.7.0" # For `boot` option of gpt
#
# 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, "stm32mp157c_odyssey")
define(NERVES_FW_ARCHITECTURE, "arm")
define(NERVES_FW_AUTHOR, "5G & Beyond with Elixir")
define(NERVES_FW_DEVPATH, "/dev/mmcblk0")
define(NERVES_FW_APPLICATION_PART0_DEVPATH, "/dev/mmcblk0p6") # Linux part number is 1-based
define(NERVES_FW_APPLICATION_PART0_FSTYPE, "f2fs")
define(NERVES_FW_APPLICATION_PART0_TARGET, "/root")
# Default paths if not specified via the commandline
define(ROOTFS, "${NERVES_SYSTEM}/images/rootfs.squashfs")
define(UNAME_R, "5.10.83-armv7-lpae-x58")
# This configuration file will create an image that has an MBR and the
# following layout:
#
# +--------------------------+
# | MBR LBA 0 |
# +--------------------------+
# | GPT header LBA 1 |
# | GPT entries LBA 2-33 |
# +--------------------------+
# | Firmware configuration |
# | (formatted as uboot env) |
# +--------------------------+
# | p0: FSBL 1 |
# | for u-boot-spl.stm32 |
# +--------------------------+
# | p1: FSBL 2 |
# | for u-boot-spl.stm32 |
# +--------------------------+
# | p2: SSBL for u-boot.img |
# +--------------------------+
# | p3*: BOOT A (FAT16) |
# | vmlinuz |
# | uEnv.txt |
# | *.dtb |
# +--------------------------+
# | p3*: BOOT B (FAT16) |
# +--------------------------+
# | p4*: Rootfs A (squashfs) |
# +--------------------------+
# | p4*: Rootfs B (squashfs) |
# +--------------------------+
# | p5: Application (f2fs) |
# +--------------------------+
define(GPT_PART_START_OFFSET, 34)
define(UBOOT_ENV_OFFSET, ${GPT_PART_START_OFFSET})
define(UBOOT_ENV_COUNT, 16) # 16 * 512 / 1024 = 8 KiB
# The First Stage Boot Loader 1
define-eval(FSBL1_PART_OFFSET, "${UBOOT_ENV_OFFSET} + ${UBOOT_ENV_COUNT}")
define(FSBL1_PART_COUNT, 512) # 512 * 512 / 1024 = 256 KiB
# The First Stage Boot Loader 2
define-eval(FSBL2_PART_OFFSET, "${FSBL1_PART_OFFSET} + ${FSBL1_PART_COUNT}")
define(FSBL2_PART_COUNT, ${FSBL1_PART_COUNT}) # same size as FSBL 1
# The Second Stage Boot Loader 2
define-eval(SSBL_PART_OFFSET, "${FSBL2_PART_OFFSET} + ${FSBL2_PART_COUNT}")
define(SSBL_PART_COUNT, 4096) # 4096 * 512 / 1024 / 1024 = 2 MiB
# The boot partition has room for a kernel, a uEnv.txt, and a dtb.
define-eval(BOOT_A_PART_OFFSET, "${SSBL_PART_OFFSET} + ${SSBL_PART_COUNT}")
define(BOOT_A_PART_COUNT, 131072) # 131072 * 512 / 1024 / 1024 = 64 MiB
define-eval(BOOT_B_PART_OFFSET, "${BOOT_A_PART_OFFSET} + ${BOOT_A_PART_COUNT}")
define(BOOT_B_PART_COUNT, ${BOOT_A_PART_COUNT}) # same size as BOOT A
# Let the rootfs have room to grow up to 128 MiB (256K 512-byte blocks)
define-eval(ROOTFS_A_PART_OFFSET, "${BOOT_B_PART_OFFSET} + ${BOOT_B_PART_COUNT}")
define(ROOTFS_A_PART_COUNT, 262144) # 262144 * 512 / 1024 / 1024 = 128 MiB
define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}")
define(ROOTFS_B_PART_COUNT, ${ROOTFS_A_PART_COUNT}) # same size as ROOTFS A
# 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}
# gpt definitions
define(ENTIRE_DISK_UUID, "691f1be3-ec37-4dd2-b695-fe9901a93d63") # generated by uuidgen
define(LINUX_FS_UUID, "0fc63daf-8483-4772-8e79-3d69d8477de4")
define(PART_0_UUID, "9ecd363c-6af5-4648-b975-5b4cebef0f68") # generated by uuidgen
define(PART_1_UUID, "f13c7240-fcdc-4b84-aecc-fd57dc6c27ed") # generated by uuidgen
define(PART_2_UUID, "3b122046-ac67-4174-8ee8-0d2e9842fad4") # generated by uuidgen
define(PART_3_UUID, "bfc7baa5-8afb-4220-b03d-88d378e16e77") # generated by uuidgen
define(PART_4_UUID, "5c58aef9-cc84-4d5e-a11f-4d18571ee5bb") # generated by uuidgen
define(PART_5_UUID, "e0a92ca3-86d3-44bb-8237-a7aea464b8c9") # generated by uuidgen
define(PART_0_NAME, "fsbl1")
define(PART_1_NAME, "fsbl2")
define(PART_2_NAME, "ssbl")
define(PART_3_NAME, "boot")
define(PART_4_NAME, "rootfs")
define(PART_5_NAME, "app")
gpt gpt-a {
guid = ${ENTIRE_DISK_UUID}
partition 0 {
block-offset = ${FSBL1_PART_OFFSET}
block-count = ${FSBL1_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_0_UUID}
name = ${PART_0_NAME}
}
partition 1 {
block-offset = ${FSBL2_PART_OFFSET}
block-count = ${FSBL2_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_1_UUID}
name = ${PART_1_NAME}
}
partition 2 {
block-offset = ${SSBL_PART_OFFSET}
block-count = ${SSBL_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_2_UUID}
name = ${PART_2_NAME}
}
partition 3 {
block-offset = ${BOOT_A_PART_OFFSET}
block-count = ${BOOT_A_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_3_UUID}
name = ${PART_3_NAME}
boot = true
}
partition 4 {
block-offset = ${ROOTFS_A_PART_OFFSET}
block-count = ${ROOTFS_A_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_4_UUID}
name = ${PART_4_NAME}
}
partition 5 {
block-offset = ${APP_PART_OFFSET}
block-count = ${APP_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_5_UUID}
name = ${PART_5_NAME}
}
}
gpt gpt-b {
guid = ${ENTIRE_DISK_UUID}
partition 0 {
block-offset = ${FSBL1_PART_OFFSET}
block-count = ${FSBL1_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_0_UUID}
name = ${PART_0_NAME}
}
partition 1 {
block-offset = ${FSBL2_PART_OFFSET}
block-count = ${FSBL2_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_1_UUID}
name = ${PART_1_NAME}
}
partition 2 {
block-offset = ${SSBL_PART_OFFSET}
block-count = ${SSBL_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_2_UUID}
name = ${PART_2_NAME}
}
partition 3 {
block-offset = ${BOOT_B_PART_OFFSET}
block-count = ${BOOT_B_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_3_UUID}
name = ${PART_3_NAME}
boot = true
}
partition 4 {
block-offset = ${ROOTFS_B_PART_OFFSET}
block-count = ${ROOTFS_B_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_4_UUID}
name = ${PART_4_NAME}
}
partition 5 {
block-offset = ${APP_PART_OFFSET}
block-count = ${APP_PART_COUNT}
type = ${LINUX_FS_UUID}
guid = ${PART_5_UUID}
name = ${PART_5_NAME}
}
}
# 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}
}
task revert.a {
# This task reverts to the A partition, so check that we're running on B
# require-partition-offset(3, ${BOOT_B_PART_OFFSET}) # not supported for gpt
# require-partition-offset(4, ${ROOTFS_B_PART_OFFSET}) # not supported for gpt
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}")
on-init {
info("Reverting to partition A")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "a")
gpt_write(gpt-a)
}
}
task revert.b {
# This task reverts to the B partition, so check that we're running on A
# require-partition-offset(3, ${BOOT_A_PART_OFFSET}) # not supported for gpt
# require-partition-offset(4, ${ROOTFS_A_PART_OFFSET}) # not supported for gpt
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}")
on-init {
info("Reverting to partition B")
# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "b")
gpt_write(gpt-b)
}
}
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}")
}
}
# Run "fwup /usr/share/fwup/revert.fw -t status -d /dev/mmcblk0 -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") }
}