Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit 1f371ce

Browse files
authored
Merge pull request #4 from ElixirSeattle/upgrade-v2.0.0-rc.0
Upgrade to upstream v2.0.0-rc.0
2 parents ec66c35 + 2ff9b17 commit 1f371ce

File tree

13 files changed

+153
-15
lines changed

13 files changed

+153
-15
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exec: &exec
22
name: build-tools/nerves-system-br
3-
version: 1.12.0
4-
elixir: 1.10.3-otp-23
3+
version: 1.12.3
4+
elixir: 1.10.4-otp-23
55

66
version: 2.1
77

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## v2.0.0-rc.0
4+
5+
* New Features
6+
* Uses `nerves_initramfs` to support pre-start checks for deciding if a
7+
firmware should automatically be reverted before the kernel is loaded.
8+
By default, this checks UBoot variable `nerves_fw_validated` and if the
9+
firmware has not been validated, a revert will be triggered. This means
10+
a user must validate the firmware on first boot via
11+
`Nerves.Runtime.validate_firmware/0` or by writing to UBoot directly
12+
313
## v1.12.1
414

515
* Fixes

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.1+keybow.2
1+
2.0.0-rc.0+keybow.1

config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
kernel=zImage
1313

14+
# Enable initramfs for auto-reverts
15+
initramfs nerves_initramfs followkernel
16+
1417
# Disable the boot rainbow
1518
disable_splash=1
1619

fwup-revert.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ task revert.a {
165165

166166
# Switch over
167167
uboot_setenv(uboot-env, "nerves_fw_active", "a")
168+
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
168169
mbr_write(mbr-a)
169170
}
170171
}
@@ -184,6 +185,7 @@ task revert.b {
184185

185186
# Switch over
186187
uboot_setenv(uboot-env, "nerves_fw_active", "b")
188+
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
187189
mbr_write(mbr-b)
188190
}
189191
}

fwup.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ file-resource cmdline.txt {
111111
file-resource zImage {
112112
host-path = "${NERVES_SYSTEM}/images/zImage"
113113
}
114+
file-resource nerves_initramfs {
115+
host-path = "${NERVES_SYSTEM}/images/nerves_initramfs_arm.xz;${NERVES_SYSTEM}/images/nerves_initramfs.conf.cpio;${NERVES_SYSTEM}/images/revert.fw.cpio"
116+
}
114117
file-resource bcm2708-rpi-zero-w.dtb {
115118
host-path = "${NERVES_SYSTEM}/images/bcm2708-rpi-zero-w.dtb"
116119
}
@@ -204,6 +207,8 @@ task complete {
204207
include("${NERVES_PROVISIONING}")
205208

206209
uboot_setenv(uboot-env, "nerves_fw_active", "a")
210+
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
211+
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
207212
uboot_setenv(uboot-env, "nerves_fw_devpath", ${NERVES_FW_DEVPATH})
208213
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_devpath", ${NERVES_FW_APPLICATION_PART0_DEVPATH})
209214
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_fstype", ${NERVES_FW_APPLICATION_PART0_FSTYPE})
@@ -225,6 +230,7 @@ task complete {
225230
on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
226231
on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
227232
on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
233+
on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
228234
on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
229235
on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
230236
on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -256,6 +262,10 @@ task upgrade.a {
256262
# This task upgrades the A partition
257263
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
258264

265+
# Require that the running version of firmware has been validated.
266+
# If it has not, then failing back is not guaranteed to work.
267+
require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
268+
259269
# Verify the expected platform/architecture
260270
require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
261271
require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
@@ -289,6 +299,7 @@ task upgrade.a {
289299
on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
290300
on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
291301
on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
302+
on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
292303
on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
293304
on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
294305
on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -314,6 +325,8 @@ task upgrade.a {
314325

315326
# Switch over to boot the new firmware
316327
uboot_setenv(uboot-env, "nerves_fw_active", "a")
328+
uboot_setenv(uboot-env, "nerves_fw_validated", "0")
329+
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
317330
mbr_write(mbr-a)
318331
}
319332

@@ -324,6 +337,7 @@ task upgrade.a {
324337
task upgrade.b {
325338
# This task upgrades the B partition
326339
require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
340+
require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
327341

328342
# Verify the expected platform/architecture
329343
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
@@ -356,6 +370,7 @@ task upgrade.b {
356370
on-resource start.elf { fat_write(${BOOT_B_PART_OFFSET}, "start.elf") }
357371
on-resource fixup.dat { fat_write(${BOOT_B_PART_OFFSET}, "fixup.dat") }
358372
on-resource zImage { fat_write(${BOOT_B_PART_OFFSET}, "zImage") }
373+
on-resource nerves_initramfs { fat_write(${BOOT_B_PART_OFFSET}, "nerves_initramfs") }
359374
on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_B_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
360375
on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_B_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
361376
on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_B_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -381,13 +396,23 @@ task upgrade.b {
381396

382397
# Switch over to boot the new firmware
383398
uboot_setenv(uboot-env, "nerves_fw_active", "b")
399+
uboot_setenv(uboot-env, "nerves_fw_validated", "0")
400+
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
384401
mbr_write(mbr-b)
385402
}
386403

387404
on-error {
388405
}
389406
}
390407

408+
task upgrade.unvalidated {
409+
require-uboot-variable(uboot-env, "nerves_fw_validated", "0")
410+
411+
on-init {
412+
error("Please validate the running firmware before upgrading it again.")
413+
}
414+
}
415+
391416
task upgrade.unexpected {
392417
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
393418
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")

linux-4.19.defconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ CONFIG_NAMESPACES=y
1818
# CONFIG_PID_NS is not set
1919
# CONFIG_NET_NS is not set
2020
CONFIG_SCHED_AUTOGROUP=y
21+
CONFIG_BLK_DEV_INITRD=y
22+
# CONFIG_RD_BZIP2 is not set
23+
# CONFIG_RD_LZMA is not set
24+
# CONFIG_RD_LZO is not set
25+
# CONFIG_RD_LZ4 is not set
2126
CONFIG_EMBEDDED=y
2227
# CONFIG_PERF_EVENTS is not set
2328
# CONFIG_COMPAT_BRK is not set

mix.exs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule NervesSystemKeybow.MixProject do
33

44
@github_organization "ElixirSeattle"
55
@app :nerves_system_keybow
6+
@source_url "https://github.com/#{@github_organization}/#{@app}"
67
@version Path.join(__DIR__, "VERSION")
78
|> File.read!()
89
|> String.trim()
@@ -18,17 +19,25 @@ defmodule NervesSystemKeybow.MixProject do
1819
package: package(),
1920
deps: deps(),
2021
aliases: [loadconfig: [&bootstrap/1], docs: ["docs", &copy_images/1]],
21-
docs: [extras: ["README.md"], main: "readme"]
22+
docs: docs(),
23+
preferred_cli_env: %{
24+
docs: :docs,
25+
"hex.build": :docs,
26+
"hex.publish": :docs
27+
}
2228
]
2329
end
2430

2531
def application do
32+
check_rpi_v2_ack!()
2633
[]
2734
end
2835

2936
defp bootstrap(args) do
3037
set_target()
3138
Application.start(:nerves_bootstrap)
39+
# We're compiling locally so ack v2 req
40+
Application.put_env(:nerves, :rpi_v2_ack, true)
3241
Mix.Task.run("loadconfig", args)
3342
end
3443

@@ -50,10 +59,10 @@ defmodule NervesSystemKeybow.MixProject do
5059
defp deps do
5160
[
5261
{:nerves, "~> 1.5.4 or ~> 1.6.0", runtime: false},
53-
{:nerves_system_br, "1.12.0", runtime: false},
62+
{:nerves_system_br, "1.12.3", runtime: false},
5463
{:nerves_toolchain_armv6_rpi_linux_gnueabi, "~> 1.3.0", runtime: false},
5564
{:nerves_system_linter, "~> 0.4", only: [:dev, :test], runtime: false},
56-
{:ex_doc, "~> 0.18", only: [:dev, :test], runtime: false}
65+
{:ex_doc, "~> 0.22", only: :docs, runtime: false}
5766
]
5867
end
5968

@@ -63,11 +72,21 @@ defmodule NervesSystemKeybow.MixProject do
6372
"""
6473
end
6574

75+
defp docs do
76+
[
77+
extras: ["README.md", "CHANGELOG.md"],
78+
main: "readme",
79+
source_ref: "v#{@version}",
80+
source_url: @source_url,
81+
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
82+
]
83+
end
84+
6685
defp package do
6786
[
6887
files: package_files(),
6988
licenses: ["Apache 2.0"],
70-
links: %{"GitHub" => "https://github.com/#{@github_organization}/#{@app}"}
89+
links: %{"GitHub" => @source_url}
7190
]
7291
end
7392

@@ -84,6 +103,7 @@ defmodule NervesSystemKeybow.MixProject do
84103
"linux-4.19.defconfig",
85104
"mix.exs",
86105
"nerves_defconfig",
106+
"nerves_initramfs.conf",
87107
"post-build.sh",
88108
"post-createfs.sh",
89109
"ramoops.dts",
@@ -112,4 +132,40 @@ defmodule NervesSystemKeybow.MixProject do
112132
System.put_env("MIX_TARGET", "target")
113133
end
114134
end
135+
136+
defp check_rpi_v2_ack!() do
137+
acked? = Application.get_env(:nerves, :rpi_v2_ack) || System.get_env("NERVES_RPI_V2_ACK")
138+
139+
unless acked? do
140+
Mix.raise("""
141+
142+
143+
You are using #{@app} >= 2.0.0 which is technically
144+
backwards compatible, but requires one manual step if
145+
you are attempting to update the firmware on an existing
146+
device via ssh, upload script, NervesHub, or other remote
147+
firmware update procedure.
148+
149+
You will need to validate the running firmware on the
150+
device before installing a firmware built with this system.
151+
Otherwise, you will get an unexpected and misleading fwup error.
152+
153+
To validate and avoid the fwup error, run:
154+
155+
Nerves.Runtime.validate_firmware()
156+
157+
Or if using :nerves_runtime < 0.11.2, run:
158+
159+
Nerves.Runtime.KV.put("nerves_fw_validated", "1")
160+
161+
If you are burning the firmware directly to a SD card, then
162+
nothing needs to be done.
163+
164+
To allow compilation to complete, acknowledge you have read
165+
this warning by adding this line to your `config.exs`:
166+
167+
config :nerves, rpi_v2_ack: true
168+
""")
169+
end
170+
end
115171
end

mix.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
%{
2-
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
3-
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
2+
"earmark": {:hex, :earmark, "1.4.9", "837e4c1c5302b3135e9955f2bbf52c6c52e950c383983942b68b03909356c0d9", [:mix], [{:earmark_parser, ">= 1.4.9", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "0d72df7d13a3dc8422882bed5263fdec5a773f56f7baeb02379361cb9e5b0d8e"},
3+
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
4+
"ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"},
45
"makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
56
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
67
"nerves": {:hex, :nerves, "1.6.3", "ac0155508a6eb0e3c8e92a6c7c0524dbe38dcc289e89cf0ef129df673a89f2ea", [:mix], [{:distillery, "~> 2.1", [hex: :distillery, repo: "hexpm", optional: true]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ce150c9aaf2ccffb2cf2fbfe1da462f363ceb322ee515c0a23394235346f71fc"},
7-
"nerves_system_br": {:hex, :nerves_system_br, "1.12.0", "e86a6fc34c28b667ff2b7b614c23b7c3bc00c253165e6cb41d76bd4e3d1bbc36", [:mix], [], "hexpm", "572ff3e540677b1addb70b8fd2a6652a372a7eb1a961722c7954dffa065f267c"},
8+
"nerves_system_br": {:hex, :nerves_system_br, "1.12.3", "ca6e51608620eeaa57aea195d4364a0d269d43c9776f9839e06f1659dfc2baee", [:mix], [], "hexpm", "df9b2926a4a6b87aef9c2a3043f33b3656e6a4a574d16672797f34cbf9cefa6f"},
89
"nerves_system_linter": {:hex, :nerves_system_linter, "0.4.0", "81e9a6f5018fe5fb67d7b43a04dca36156f62b55b5554eb2fa3964d3889d09cd", [:mix], [], "hexpm", "b5bd8480ce7a6317f4601ff41fd2f594bdf76aff0bdf6dcfac571c3fa1ec5f82"},
910
"nerves_toolchain_armv6_rpi_linux_gnueabi": {:hex, :nerves_toolchain_armv6_rpi_linux_gnueabi, "1.3.2", "beb0f97d6f432406af6c4fdcee02d2ab750298845834f869a0b98239362783ae", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.7.2", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm", "ef93b7d678241be2d4520dceecf6a2116bb87640576211dad3b618ce79b85e39"},
1011
"nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.7.2", "0683dff3b81483879a57e14d8e020314a4d1ecc6ee91952c1d7d9f1f528924a4", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm", "5d44f279705119defac7f28a70edb0273f92b38bc8ae668db4f271cd91f6eaee"},

nerves_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ BR2_NERVES_SYSTEM_NAME="nerves_system_rpi0"
6363
BR2_NERVES_ADDITIONAL_IMAGE_FILES="${NERVES_DEFCONFIG_DIR}/fwup.conf ${NERVES_DEFCONFIG_DIR}/cmdline.txt ${NERVES_DEFCONFIG_DIR}/config.txt"
6464
BR2_PACKAGE_NBTTY=y
6565
BR2_PACKAGE_NERVES_CONFIG=y
66+
BR2_PACKAGE_NERVES_INITRAMFS=y

0 commit comments

Comments
 (0)