Skip to content

Commit 2934d54

Browse files
jjcarstensfhunleth
authored andcommitted
Upgrade fwup-revert.conf to more capable fwup-ops.conf
1 parent 18b7ab1 commit 2934d54

File tree

3 files changed

+109
-21
lines changed

3 files changed

+109
-21
lines changed

fwup-revert.conf fwup-ops.conf

+103-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
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`)
211
#
312
# 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`.
1119
#
1220
# It is critical that this is kept in sync with the main fwup.conf.
1321

@@ -36,28 +44,37 @@ define(NERVES_FW_AUTHOR, "The Nerves Team")
3644
# +----------------------------+
3745
# | MBR |
3846
# +----------------------------+
39-
# | boot0 |
40-
# +----------------------------+
41-
# | boot0 copy (unused) |
47+
# | SPL and U-Boot |
4248
# +----------------------------+
4349
# | U-Boot environment |
4450
# +----------------------------+
45-
# | U-Boot |
46-
# +----------------------------+
47-
# | U-Boot copy (unused) |
48-
# +----------------------------+
4951
# | p1: Rootfs A (squashfs) |
5052
# +----------------------------+
5153
# | p2: Rootfs B (squashfs) |
5254
# +----------------------------+
5355
# | p3: Application (f2fs) |
5456
# +----------------------------+
5557

58+
define(UBOOT_OFFSET, 16)
59+
define(UBOOT_COUNT, 8176)
60+
5661
# The U-Boot environment is written directly to the SDCard/eMMC. It is not
5762
# in any partition
58-
define(UBOOT_ENV_OFFSET, 1792)
63+
define(UBOOT_ENV_OFFSET, 8192)
5964
define(UBOOT_ENV_COUNT, 256) # 128 KB
6065

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+
6178
# Firmware archive metadata
6279
meta-product = ${NERVES_FW_PRODUCT}
6380
meta-description = ${NERVES_FW_DESCRIPTION}
@@ -74,6 +91,59 @@ uboot-environment uboot-env {
7491
block-count = ${UBOOT_ENV_COUNT}
7592
}
7693

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+
##
77147
task revert.a {
78148
# This task reverts to the A partition, so check that we're running on B
79149
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
@@ -131,7 +201,11 @@ task revert.wrongplatform {
131201
}
132202
}
133203

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+
##
135209
task status.aa {
136210
require-path-on-device("/", "/dev/mmcblk0p2")
137211
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
@@ -155,3 +229,15 @@ task status.ba {
155229
task status.fail {
156230
on-init { error("fail") }
157231
}
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+
}

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ defmodule NervesSystemMangopiMQPro.MixProject do
103103
"rootfs_overlay",
104104
"uboot",
105105
"CHANGELOG.md",
106-
"fwup-revert.conf",
106+
"fwup-ops.conf",
107107
"fwup.conf",
108108
"LICENSE",
109109
"mix.exs",

post-build.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
set -e
44

5-
# Create the revert script for manually switching back to the previously
6-
# active firmware.
5+
# Create the fwup ops script to handling MicroSD/eMMC operations at runtime
6+
# NOTE: revert.fw is the previous, more limited version of this. ops.fw is
7+
# backwards compatible.
78
mkdir -p $TARGET_DIR/usr/share/fwup
8-
$HOST_DIR/usr/bin/fwup -c -f $NERVES_DEFCONFIG_DIR/fwup-revert.conf -o $TARGET_DIR/usr/share/fwup/revert.fw
9+
$HOST_DIR/usr/bin/fwup -c -f $NERVES_DEFCONFIG_DIR/fwup-ops.conf -o $TARGET_DIR/usr/share/fwup/ops.fw
10+
ln -sf ops.fw $TARGET_DIR/usr/share/fwup/revert.fw
911

1012
# Copy the fwup includes to the images dir
1113
cp -rf $NERVES_DEFCONFIG_DIR/fwup_include $BINARIES_DIR

0 commit comments

Comments
 (0)