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

Commit

Permalink
Merge pull request #4 from ElixirSeattle/upgrade-v2.0.0-rc.0
Browse files Browse the repository at this point in the history
Upgrade to upstream v2.0.0-rc.0
  • Loading branch information
vanvoljg authored Aug 6, 2020
2 parents ec66c35 + 2ff9b17 commit 1f371ce
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exec: &exec
name: build-tools/nerves-system-br
version: 1.12.0
elixir: 1.10.3-otp-23
version: 1.12.3
elixir: 1.10.4-otp-23

version: 2.1

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v2.0.0-rc.0

* New Features
* Uses `nerves_initramfs` to support pre-start checks for deciding if a
firmware should automatically be reverted before the kernel is loaded.
By default, this checks UBoot variable `nerves_fw_validated` and if the
firmware has not been validated, a revert will be triggered. This means
a user must validate the firmware on first boot via
`Nerves.Runtime.validate_firmware/0` or by writing to UBoot directly

## v1.12.1

* Fixes
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.1+keybow.2
2.0.0-rc.0+keybow.1
3 changes: 3 additions & 0 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

kernel=zImage

# Enable initramfs for auto-reverts
initramfs nerves_initramfs followkernel

# Disable the boot rainbow
disable_splash=1

Expand Down
2 changes: 2 additions & 0 deletions fwup-revert.conf
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ task revert.a {

# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "a")
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
mbr_write(mbr-a)
}
}
Expand All @@ -184,6 +185,7 @@ task revert.b {

# Switch over
uboot_setenv(uboot-env, "nerves_fw_active", "b")
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
mbr_write(mbr-b)
}
}
Expand Down
25 changes: 25 additions & 0 deletions fwup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ file-resource cmdline.txt {
file-resource zImage {
host-path = "${NERVES_SYSTEM}/images/zImage"
}
file-resource nerves_initramfs {
host-path = "${NERVES_SYSTEM}/images/nerves_initramfs_arm.xz;${NERVES_SYSTEM}/images/nerves_initramfs.conf.cpio;${NERVES_SYSTEM}/images/revert.fw.cpio"
}
file-resource bcm2708-rpi-zero-w.dtb {
host-path = "${NERVES_SYSTEM}/images/bcm2708-rpi-zero-w.dtb"
}
Expand Down Expand Up @@ -204,6 +207,8 @@ task complete {
include("${NERVES_PROVISIONING}")

uboot_setenv(uboot-env, "nerves_fw_active", "a")
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
uboot_setenv(uboot-env, "nerves_fw_devpath", ${NERVES_FW_DEVPATH})
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_devpath", ${NERVES_FW_APPLICATION_PART0_DEVPATH})
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_fstype", ${NERVES_FW_APPLICATION_PART0_FSTYPE})
Expand All @@ -225,6 +230,7 @@ task complete {
on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
Expand Down Expand Up @@ -256,6 +262,10 @@ task upgrade.a {
# This task upgrades the A partition
require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})

# Require that the running version of firmware has been validated.
# If it has not, then failing back is not guaranteed to work.
require-uboot-variable(uboot-env, "nerves_fw_validated", "1")

# Verify 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}")
Expand Down Expand Up @@ -289,6 +299,7 @@ task upgrade.a {
on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
Expand All @@ -314,6 +325,8 @@ task upgrade.a {

# Switch over to boot the new firmware
uboot_setenv(uboot-env, "nerves_fw_active", "a")
uboot_setenv(uboot-env, "nerves_fw_validated", "0")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
mbr_write(mbr-a)
}

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

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

# Switch over to boot the new firmware
uboot_setenv(uboot-env, "nerves_fw_active", "b")
uboot_setenv(uboot-env, "nerves_fw_validated", "0")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
mbr_write(mbr-b)
}

on-error {
}
}

task upgrade.unvalidated {
require-uboot-variable(uboot-env, "nerves_fw_validated", "0")

on-init {
error("Please validate the running firmware before upgrading it again.")
}
}

task upgrade.unexpected {
require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
Expand Down
5 changes: 5 additions & 0 deletions linux-4.19.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ CONFIG_NAMESPACES=y
# CONFIG_PID_NS is not set
# CONFIG_NET_NS is not set
CONFIG_SCHED_AUTOGROUP=y
CONFIG_BLK_DEV_INITRD=y
# CONFIG_RD_BZIP2 is not set
# CONFIG_RD_LZMA is not set
# CONFIG_RD_LZO is not set
# CONFIG_RD_LZ4 is not set
CONFIG_EMBEDDED=y
# CONFIG_PERF_EVENTS is not set
# CONFIG_COMPAT_BRK is not set
Expand Down
64 changes: 60 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule NervesSystemKeybow.MixProject do

@github_organization "ElixirSeattle"
@app :nerves_system_keybow
@source_url "https://github.com/#{@github_organization}/#{@app}"
@version Path.join(__DIR__, "VERSION")
|> File.read!()
|> String.trim()
Expand All @@ -18,17 +19,25 @@ defmodule NervesSystemKeybow.MixProject do
package: package(),
deps: deps(),
aliases: [loadconfig: [&bootstrap/1], docs: ["docs", &copy_images/1]],
docs: [extras: ["README.md"], main: "readme"]
docs: docs(),
preferred_cli_env: %{
docs: :docs,
"hex.build": :docs,
"hex.publish": :docs
}
]
end

def application do
check_rpi_v2_ack!()
[]
end

defp bootstrap(args) do
set_target()
Application.start(:nerves_bootstrap)
# We're compiling locally so ack v2 req
Application.put_env(:nerves, :rpi_v2_ack, true)
Mix.Task.run("loadconfig", args)
end

Expand All @@ -50,10 +59,10 @@ defmodule NervesSystemKeybow.MixProject do
defp deps do
[
{:nerves, "~> 1.5.4 or ~> 1.6.0", runtime: false},
{:nerves_system_br, "1.12.0", runtime: false},
{:nerves_system_br, "1.12.3", runtime: false},
{:nerves_toolchain_armv6_rpi_linux_gnueabi, "~> 1.3.0", runtime: false},
{:nerves_system_linter, "~> 0.4", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.18", only: [:dev, :test], runtime: false}
{:ex_doc, "~> 0.22", only: :docs, runtime: false}
]
end

Expand All @@ -63,11 +72,21 @@ defmodule NervesSystemKeybow.MixProject do
"""
end

defp docs do
[
extras: ["README.md", "CHANGELOG.md"],
main: "readme",
source_ref: "v#{@version}",
source_url: @source_url,
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
]
end

defp package do
[
files: package_files(),
licenses: ["Apache 2.0"],
links: %{"GitHub" => "https://github.com/#{@github_organization}/#{@app}"}
links: %{"GitHub" => @source_url}
]
end

Expand All @@ -84,6 +103,7 @@ defmodule NervesSystemKeybow.MixProject do
"linux-4.19.defconfig",
"mix.exs",
"nerves_defconfig",
"nerves_initramfs.conf",
"post-build.sh",
"post-createfs.sh",
"ramoops.dts",
Expand Down Expand Up @@ -112,4 +132,40 @@ defmodule NervesSystemKeybow.MixProject do
System.put_env("MIX_TARGET", "target")
end
end

defp check_rpi_v2_ack!() do
acked? = Application.get_env(:nerves, :rpi_v2_ack) || System.get_env("NERVES_RPI_V2_ACK")

unless acked? do
Mix.raise("""
You are using #{@app} >= 2.0.0 which is technically
backwards compatible, but requires one manual step if
you are attempting to update the firmware on an existing
device via ssh, upload script, NervesHub, or other remote
firmware update procedure.
You will need to validate the running firmware on the
device before installing a firmware built with this system.
Otherwise, you will get an unexpected and misleading fwup error.
To validate and avoid the fwup error, run:
Nerves.Runtime.validate_firmware()
Or if using :nerves_runtime < 0.11.2, run:
Nerves.Runtime.KV.put("nerves_fw_validated", "1")
If you are burning the firmware directly to a SD card, then
nothing needs to be done.
To allow compilation to complete, acknowledge you have read
this warning by adding this line to your `config.exs`:
config :nerves, rpi_v2_ack: true
""")
end
end
end
7 changes: 4 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
%{
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
"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"},
"earmark": {:hex, :earmark, "1.4.9", "837e4c1c5302b3135e9955f2bbf52c6c52e950c383983942b68b03909356c0d9", [:mix], [{:earmark_parser, ">= 1.4.9", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "0d72df7d13a3dc8422882bed5263fdec5a773f56f7baeb02379361cb9e5b0d8e"},
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"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"},
"makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
"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"},
"nerves_system_br": {:hex, :nerves_system_br, "1.12.0", "e86a6fc34c28b667ff2b7b614c23b7c3bc00c253165e6cb41d76bd4e3d1bbc36", [:mix], [], "hexpm", "572ff3e540677b1addb70b8fd2a6652a372a7eb1a961722c7954dffa065f267c"},
"nerves_system_br": {:hex, :nerves_system_br, "1.12.3", "ca6e51608620eeaa57aea195d4364a0d269d43c9776f9839e06f1659dfc2baee", [:mix], [], "hexpm", "df9b2926a4a6b87aef9c2a3043f33b3656e6a4a574d16672797f34cbf9cefa6f"},
"nerves_system_linter": {:hex, :nerves_system_linter, "0.4.0", "81e9a6f5018fe5fb67d7b43a04dca36156f62b55b5554eb2fa3964d3889d09cd", [:mix], [], "hexpm", "b5bd8480ce7a6317f4601ff41fd2f594bdf76aff0bdf6dcfac571c3fa1ec5f82"},
"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"},
"nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.7.2", "0683dff3b81483879a57e14d8e020314a4d1ecc6ee91952c1d7d9f1f528924a4", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm", "5d44f279705119defac7f28a70edb0273f92b38bc8ae668db4f271cd91f6eaee"},
Expand Down
1 change: 1 addition & 0 deletions nerves_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ BR2_NERVES_SYSTEM_NAME="nerves_system_rpi0"
BR2_NERVES_ADDITIONAL_IMAGE_FILES="${NERVES_DEFCONFIG_DIR}/fwup.conf ${NERVES_DEFCONFIG_DIR}/cmdline.txt ${NERVES_DEFCONFIG_DIR}/config.txt"
BR2_PACKAGE_NBTTY=y
BR2_PACKAGE_NERVES_CONFIG=y
BR2_PACKAGE_NERVES_INITRAMFS=y
31 changes: 31 additions & 0 deletions nerves_initramfs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Debug
# run_repl=true

# These need to match the definitions in fwup.conf
# in order to read the UBoot env variables from
# the correct block of memory
uboot_env.start=16 # UBOOT_ENV_OFFSET
uboot_env.count=16 # UBOOT_ENV_COUNT

loadenv()

fw_active=getenv("nerves_fw_active")
fw_validated=getenv("nerves_fw_validated")
fw_booted=getenv("nerves_fw_booted")

!fw_validated && fw_booted -> {

print("Reverting since ", fw_active, " was tried and wasn't validated\\n")

fwup_revert()

# Need to reboot to use the other kernel
reboot()
}

!fw_booted -> {
setenv("nerves_fw_booted", "1")
saveenv()
}

print("[NervesSystem] Running firmware slot: ", fw_active)
4 changes: 4 additions & 0 deletions post-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ $HOST_DIR/usr/bin/fwup -c -f $NERVES_DEFCONFIG_DIR/fwup-revert.conf -o $TARGET_D

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

# Use files-to-cpio.sh from nerves_initramfs to prep config and revert.fw
$BINARIES_DIR/file-to-cpio.sh "$NERVES_DEFCONFIG_DIR/nerves_initramfs.conf" "$BINARIES_DIR/nerves_initramfs.conf.cpio"
$BINARIES_DIR/file-to-cpio.sh "$TARGET_DIR/usr/share/fwup/revert.fw" "$BINARIES_DIR/revert.fw.cpio"
Loading

0 comments on commit 1f371ce

Please sign in to comment.