New boards with layouts for dual partition setups (#387)

* upgradable boards

* updates the install manual for proper SSL config

* storage locations from build script

* deploy script improvements

* UTC time
This commit is contained in:
kaczmarczyck
2021-10-06 18:33:40 +02:00
committed by GitHub
parent d085d54878
commit 9b780ef7d7
18 changed files with 441 additions and 119 deletions

View File

@@ -1,4 +1,29 @@
use std::env;
use std::fs;
use std::path::Path;
fn main() { fn main() {
println!("cargo:rerun-if-changed=layout.ld"); println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=../../kernel_layout.ld"); println!("cargo:rerun-if-changed=../../kernel_layout.ld");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("locations.rs");
fs::write(
&dest_path,
"
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [
// We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
kernel::StorageLocation {
address: 0xC0000,
size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
];
"
).unwrap();
} }

View File

@@ -67,6 +67,7 @@
#![feature(const_in_array_repeat_expressions)] #![feature(const_in_array_repeat_expressions)]
#![deny(missing_docs)] #![deny(missing_docs)]
use core::env;
use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState}; use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState};
use kernel::component::Component; use kernel::component::Component;
use kernel::hil::led::LedLow; use kernel::hil::led::LedLow;
@@ -128,19 +129,7 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS]; [None; NUM_PROCS];
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [ include!(concat!(env!("OUT_DIR"), "/locations.rs"));
// We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
kernel::StorageLocation {
address: 0xC0000,
size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
];
static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None; static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;

View File

@@ -0,0 +1,18 @@
[package]
name = "nrf52840dk_opensk_a"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"
[[bin]]
path = "../nrf52840dk_opensk/src/main.rs"
name = "nrf52840dk_opensk_a"
[dependencies]
components = { path = "../../components" }
cortexm4 = { path = "../../../arch/cortex-m4" }
capsules = { path = "../../../capsules" }
kernel = { path = "../../../kernel" }
nrf52840 = { path = "../../../chips/nrf52840" }
nrf52_components = { path = "../nrf52_components" }

View File

@@ -0,0 +1,31 @@
# Makefile for building the tock kernel for the nRF development kit
TARGET=thumbv7em-none-eabi
PLATFORM=nrf52840dk_opensk_a
include ../../Makefile.common
TOCKLOADER=tockloader
# Where in the SAM4L flash to load the kernel with `tockloader`
KERNEL_ADDRESS=0x20000
# Upload programs over uart with tockloader
ifdef PORT
TOCKLOADER_GENERAL_FLAGS += --port $(PORT)
endif
# Upload the kernel over JTAG
.PHONY: flash
flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --jlink $<
# Upload the kernel over JTAG using OpenOCD
.PHONY: flash-openocd
flash-openocd: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --openocd $<
# Upload the kernel over serial/bootloader
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).hex
$(error Cannot program nRF52840DK over USB. Use \`make flash\` and JTAG)

View File

@@ -0,0 +1,11 @@
Platform-Specific Instructions: nRF52840-DK, partition A
===================================
This is an upgrade partition for the adapted nrf52840dk in `../nrf52840dk_opensk`.
Compared to our regular board definition for the nrf52840dk, changes are:
- a `layout.ld` with 128 kB for kernel and app
- the matching kernel address in the `Makefile`
- different `StorageLocation`s in `build.rs`
For everything else, please check the README in `../nrf52840dk_opensk`.

View File

@@ -0,0 +1,45 @@
use std::env;
use std::fs;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=../../kernel_layout.ld");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("locations.rs");
fs::write(
&dest_path,
"
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 5] = [
// We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
kernel::StorageLocation {
address: 0xC0000,
size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
// Partitions can also be split to maximize MPU happiness.
kernel::StorageLocation {
address: 0x60000,
size: 0x20000,
storage_type: kernel::StorageType::PARTITION,
},
kernel::StorageLocation {
address: 0x80000,
size: 0x20000,
storage_type: kernel::StorageType::PARTITION,
},
kernel::StorageLocation {
address: 0x5000,
size: 0x1000,
storage_type: kernel::StorageType::METADATA,
},
];
"
).unwrap();
}

View File

@@ -0,0 +1,13 @@
/* Memory Space Definitions, 1M flash, 256K ram */
MEMORY
{
rom (rx) : ORIGIN = 0x00020000, LENGTH = 128K
prog (rx) : ORIGIN = 0x00040000, LENGTH = 128K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}
MPU_MIN_ALIGN = 8K;
PAGE_SIZE = 4K;
INCLUDE ../../kernel_layout.ld

View File

@@ -0,0 +1,18 @@
[package]
name = "nrf52840dk_opensk_b"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"
[[bin]]
path = "../nrf52840dk_opensk/src/main.rs"
name = "nrf52840dk_opensk_b"
[dependencies]
components = { path = "../../components" }
cortexm4 = { path = "../../../arch/cortex-m4" }
capsules = { path = "../../../capsules" }
kernel = { path = "../../../kernel" }
nrf52840 = { path = "../../../chips/nrf52840" }
nrf52_components = { path = "../nrf52_components" }

View File

@@ -0,0 +1,31 @@
# Makefile for building the tock kernel for the nRF development kit
TARGET=thumbv7em-none-eabi
PLATFORM=nrf52840dk_opensk_b
include ../../Makefile.common
TOCKLOADER=tockloader
# Where in the SAM4L flash to load the kernel with `tockloader`
KERNEL_ADDRESS=0x60000
# Upload programs over uart with tockloader
ifdef PORT
TOCKLOADER_GENERAL_FLAGS += --port $(PORT)
endif
# Upload the kernel over JTAG
.PHONY: flash
flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --jlink $<
# Upload the kernel over JTAG using OpenOCD
.PHONY: flash-openocd
flash-openocd: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --openocd $<
# Upload the kernel over serial/bootloader
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).hex
$(error Cannot program nRF52840DK over USB. Use \`make flash\` and JTAG)

View File

@@ -0,0 +1,11 @@
Platform-Specific Instructions: nRF52840-DK, partition B
===================================
This is an upgrade partition for the adapted nrf52840dk in `../nrf52840dk_opensk`.
Compared to our regular board definition for the nrf52840dk, changes are:
- a `layout.ld` with 128 kB for kernel and app
- the matching kernel address in the `Makefile`
- different `StorageLocation`s in `build.rs`
For everything else, please check the README in `../nrf52840dk_opensk`.

View File

@@ -0,0 +1,45 @@
use std::env;
use std::fs;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=../../kernel_layout.ld");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("locations.rs");
fs::write(
&dest_path,
"
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 5] = [
// We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
kernel::StorageLocation {
address: 0xC0000,
size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
// Partitions can also be split to maximize MPU happiness.
kernel::StorageLocation {
address: 0x20000,
size: 0x20000,
storage_type: kernel::StorageType::PARTITION,
},
kernel::StorageLocation {
address: 0x40000,
size: 0x20000,
storage_type: kernel::StorageType::PARTITION,
},
kernel::StorageLocation {
address: 0x4000,
size: 0x1000,
storage_type: kernel::StorageType::METADATA,
},
];
"
).unwrap();
}

View File

@@ -0,0 +1,13 @@
/* Memory Space Definitions, 1M flash, 256K ram */
MEMORY
{
rom (rx) : ORIGIN = 0x00060000, LENGTH = 128K
prog (rx) : ORIGIN = 0x00080000, LENGTH = 128K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}
MPU_MIN_ALIGN = 8K;
PAGE_SIZE = 4K;
INCLUDE ../../kernel_layout.ld

View File

@@ -32,6 +32,8 @@ fn main() {
println!("cargo:rerun-if-changed={}", UPGRADE_FILE); println!("cargo:rerun-if-changed={}", UPGRADE_FILE);
println!("cargo:rerun-if-changed=layout.ld"); println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=nrf52840_layout.ld"); println!("cargo:rerun-if-changed=nrf52840_layout.ld");
println!("cargo:rerun-if-changed=nrf52840_layout_a.ld");
println!("cargo:rerun-if-changed=nrf52840_layout_b.ld");
let out_dir = env::var_os("OUT_DIR").unwrap(); let out_dir = env::var_os("OUT_DIR").unwrap();
let aaguid_bin_path = Path::new(&out_dir).join("opensk_aaguid.bin"); let aaguid_bin_path = Path::new(&out_dir).join("opensk_aaguid.bin");

232
deploy.py
View File

@@ -22,8 +22,11 @@ from __future__ import print_function
import argparse import argparse
import collections import collections
import copy import copy
import datetime
import hashlib
import os import os
import shutil import shutil
import struct
import subprocess import subprocess
import sys import sys
@@ -50,12 +53,19 @@ OpenSKBoard = collections.namedtuple(
"page_size", "page_size",
# Flash address at which the kernel will be written # Flash address at which the kernel will be written
"kernel_address", "kernel_address",
# Set to None is padding is not required for the board. # Set to None if padding is not required for the board.
# This creates a fake Tock OS application that starts at the # This creates a fake Tock OS application that starts at the
# address specified by this parameter (must match the `prog` value # address specified by this parameter (must match the `prog` value
# specified on the board's `layout.ld` file) and will end at # specified on the board's `layout.ld` file) and will end at
# `app_address`. # `app_address`.
"padding_address", "padding_address",
# If present, enforce that the firmware image equals this value,
# padding it with 0xFF bytes.
"firmware_size",
# Set to None if metadata is not required for the board.
# Writes the metadata that is checked by the custom bootloader for
# upgradable board.
"metadata_address",
# Linker script to produce a working app for this board # Linker script to produce a working app for this board
"app_ldscript", "app_ldscript",
# Flash address at which the app should be written # Flash address at which the app should be written
@@ -83,81 +93,63 @@ OpenSKBoard = collections.namedtuple(
"nordic_dfu", "nordic_dfu",
]) ])
nrf52840dk_opensk_board = OpenSKBoard(
path="third_party/tock/boards/nordic/nrf52840dk_opensk",
arch="thumbv7em-none-eabi",
page_size=4096,
kernel_address=0,
padding_address=0x30000,
firmware_size=None,
metadata_address=None,
app_ldscript="nrf52840_layout.ld",
app_address=0x40000,
storage_address=0xC0000,
storage_size=0x14000,
pyocd_target="nrf52840",
openocd_board="nordic_nrf52840_dongle.cfg",
openocd_options=[],
openocd_commands={},
jlink_if="swd",
jlink_device="nrf52840_xxaa",
nordic_dfu=False,
)
SUPPORTED_BOARDS = { SUPPORTED_BOARDS = {
"nrf52840dk_opensk": "nrf52840dk_opensk":
OpenSKBoard( nrf52840dk_opensk_board,
path="third_party/tock/boards/nordic/nrf52840dk_opensk", "nrf52840dk_opensk_a":
arch="thumbv7em-none-eabi", nrf52840dk_opensk_board._replace(
page_size=4096, path=nrf52840dk_opensk_board.path + "_a",
kernel_address=0, kernel_address=0x20000,
padding_address=0x30000, padding_address=None,
app_ldscript="nrf52840_layout.ld", firmware_size=0x40000,
metadata_address=0x4000,
app_ldscript="nrf52840_layout_a.ld",
app_address=0x40000, app_address=0x40000,
storage_address=0xC0000, ),
storage_size=0x14000, "nrf52840dk_opensk_b":
pyocd_target="nrf52840", nrf52840dk_opensk_board._replace(
openocd_board="nordic_nrf52840_dongle.cfg", path=nrf52840dk_opensk_board.path + "_b",
openocd_options=[], kernel_address=0x60000,
openocd_commands={}, padding_address=None,
jlink_if="swd", firmware_size=0x40000,
jlink_device="nrf52840_xxaa", metadata_address=0x5000,
nordic_dfu=False, app_ldscript="nrf52840_layout_b.ld",
app_address=0x80000,
), ),
"nrf52840_dongle_opensk": "nrf52840_dongle_opensk":
OpenSKBoard( nrf52840dk_opensk_board._replace(
path="third_party/tock/boards/nordic/nrf52840_dongle_opensk", path="third_party/tock/boards/nordic/nrf52840_dongle_opensk",),
arch="thumbv7em-none-eabi",
page_size=4096,
kernel_address=0,
padding_address=0x30000,
app_ldscript="nrf52840_layout.ld",
app_address=0x40000,
storage_address=0xC0000,
storage_size=0x14000,
pyocd_target="nrf52840",
openocd_board="nordic_nrf52840_dongle.cfg",
openocd_options=[],
openocd_commands={},
jlink_if="swd",
jlink_device="nrf52840_xxaa",
nordic_dfu=False,
),
"nrf52840_dongle_dfu": "nrf52840_dongle_dfu":
OpenSKBoard( nrf52840dk_opensk_board._replace(
path="third_party/tock/boards/nordic/nrf52840_dongle_dfu", path="third_party/tock/boards/nordic/nrf52840_dongle_dfu",
arch="thumbv7em-none-eabi",
page_size=4096,
kernel_address=0x1000, kernel_address=0x1000,
padding_address=0x30000,
app_ldscript="nrf52840_layout.ld",
app_address=0x40000,
storage_address=0xC0000,
storage_size=0x14000,
pyocd_target="nrf52840",
openocd_board="nordic_nrf52840_dongle.cfg",
openocd_options=[],
openocd_commands={},
jlink_if="swd",
jlink_device="nrf52840_xxaa",
nordic_dfu=True, nordic_dfu=True,
), ),
"nrf52840_mdk_dfu": "nrf52840_mdk_dfu":
OpenSKBoard( nrf52840dk_opensk_board._replace(
path="third_party/tock/boards/nordic/nrf52840_mdk_dfu", path="third_party/tock/boards/nordic/nrf52840_mdk_dfu",
arch="thumbv7em-none-eabi",
page_size=4096,
kernel_address=0x1000, kernel_address=0x1000,
padding_address=0x30000,
app_ldscript="nrf52840_layout.ld",
app_address=0x40000,
storage_address=0xC0000,
storage_size=0x14000,
pyocd_target="nrf52840",
openocd_board="nordic_nrf52840_dongle.cfg",
openocd_options=[],
openocd_commands={},
jlink_if="swd",
jlink_device="nrf52840_xxaa",
nordic_dfu=True, nordic_dfu=True,
), ),
} }
@@ -205,6 +197,18 @@ def assert_python_library(module):
f"Try to run: pip3 install {module}")) f"Try to run: pip3 install {module}"))
def create_metadata(firmware_image, partition_address):
t = datetime.datetime.utcnow().timestamp()
timestamp = struct.pack("<I", int(t))
partition_start = struct.pack("<I", partition_address)
sha256_hash = hashlib.sha256()
sha256_hash.update(firmware_image)
sha256_hash.update(timestamp)
sha256_hash.update(partition_start)
checksum = sha256_hash.digest()
return checksum + timestamp + partition_start
class RemoveConstAction(argparse.Action): class RemoveConstAction(argparse.Action):
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
@@ -250,6 +254,7 @@ class OpenSKInstaller:
self.tab_folder = os.path.join("target", "tab") self.tab_folder = os.path.join("target", "tab")
board = SUPPORTED_BOARDS[self.args.board] board = SUPPORTED_BOARDS[self.args.board]
self.tockloader_default_args = argparse.Namespace( self.tockloader_default_args = argparse.Namespace(
app_address=board.app_address,
arch=board.arch, arch=board.arch,
board=self.args.board, board=self.args.board,
bundle_apps=False, bundle_apps=False,
@@ -455,9 +460,7 @@ class OpenSKInstaller:
def install_tab_file(self, tab_filename): def install_tab_file(self, tab_filename):
assert self.args.application assert self.args.application
info(f"Installing Tock application {self.args.application}") info(f"Installing Tock application {self.args.application}")
board_props = SUPPORTED_BOARDS[self.args.board]
args = copy.copy(self.tockloader_default_args) args = copy.copy(self.tockloader_default_args)
setattr(args, "app_address", board_props.app_address)
setattr(args, "erase", self.args.clear_apps) setattr(args, "erase", self.args.clear_apps)
setattr(args, "make", False) setattr(args, "make", False)
setattr(args, "no_replace", False) setattr(args, "no_replace", False)
@@ -476,40 +479,72 @@ class OpenSKInstaller:
SUPPORTED_BOARDS[self.args.board].padding_address) SUPPORTED_BOARDS[self.args.board].padding_address)
return padding.get_binary() return padding.get_binary()
def install_tock_os(self): def write_binary(self, binary, address):
tock = loader.TockLoader(self.tockloader_default_args)
tock.open()
try:
tock.flash_binary(binary, address)
except TockLoaderException as e:
fatal(f"Couldn't write binary: {str(e)}")
def read_kernel(self):
board_props = SUPPORTED_BOARDS[self.args.board] board_props = SUPPORTED_BOARDS[self.args.board]
kernel_file = os.path.join("third_party", "tock", "target", kernel_file = os.path.join("third_party", "tock", "target",
board_props.arch, "release", board_props.arch, "release",
f"{self.args.board}.bin") f"{self.args.board}.bin")
info(f"Flashing file {kernel_file}.") if not os.path.exists(kernel_file):
with open(kernel_file, "rb") as f: fatal(f"File not found: {kernel_file}")
kernel = f.read() with open(kernel_file, "rb") as firmware:
args = copy.copy(self.tockloader_default_args) kernel = firmware.read()
setattr(args, "address", board_props.app_address) return kernel
tock = loader.TockLoader(args)
tock.open() def install_tock_os(self):
try: kernel = self.read_kernel()
tock.flash_binary(kernel, board_props.kernel_address) board_props = SUPPORTED_BOARDS[self.args.board]
except TockLoaderException as e: self.write_binary(kernel, board_props.kernel_address)
fatal(f"Couldn't install Tock OS: {str(e)}")
def install_padding(self): def install_padding(self):
padding = self.get_padding()
board_props = SUPPORTED_BOARDS[self.args.board] board_props = SUPPORTED_BOARDS[self.args.board]
if board_props.padding_address is None:
return
info("Flashing padding application") info("Flashing padding application")
args = copy.copy(self.tockloader_default_args) self.write_binary(self.get_padding(), board_props.padding_address)
setattr(args, "address", board_props.padding_address)
tock = loader.TockLoader(args) def install_metadata(self):
tock.open()
try: def pad_to(binary, length):
tock.flash_binary(padding, args.address) if len(binary) > length:
except TockLoaderException as e: fatal(f"Binary size {len(binary)} exceeds flash partition {length}.")
fatal(f"Couldn't install padding: {str(e)}") padding = bytes([0xFF] * (length - len(binary)))
return binary + padding
board_props = SUPPORTED_BOARDS[self.args.board]
if board_props.metadata_address is None:
return
kernel = self.read_kernel()
app_tab_path = "target/tab/ctap2.tab"
if not os.path.exists(app_tab_path):
fatal(f"File not found: {app_tab_path}")
app_tab = tab.TAB(app_tab_path)
arch = board_props.arch
if arch not in app_tab.get_supported_architectures():
fatal(f"Architecture not found: {arch}")
app = app_tab.extract_app(arch).get_binary(board_props.app_address)
kernel_size = board_props.app_address - board_props.kernel_address
app_size = board_props.firmware_size - kernel_size
firmware_image = pad_to(kernel, kernel_size) + pad_to(app, app_size)
metadata = create_metadata(firmware_image, board_props.kernel_address)
if self.args.verbose_build:
info(f"Metadata bytes: {metadata}")
info("Flashing metadata application")
self.write_binary(metadata, board_props.metadata_address)
def clear_apps(self): def clear_apps(self):
args = copy.copy(self.tockloader_default_args) args = copy.copy(self.tockloader_default_args)
board_props = SUPPORTED_BOARDS[self.args.board]
setattr(args, "app_address", board_props.app_address)
# Ensure we don't force erase all apps but only the apps starting # Ensure we don't force erase all apps but only the apps starting
# at `board.app_address`. This makes sure we don't erase the padding. # at `board.app_address`. This makes sure we don't erase the padding.
setattr(args, "force", False) setattr(args, "force", False)
@@ -530,12 +565,7 @@ class OpenSKInstaller:
# Use tockloader if possible # Use tockloader if possible
if self.args.programmer in ("jlink", "openocd"): if self.args.programmer in ("jlink", "openocd"):
storage = bytes([0xFF] * board_props.storage_size) storage = bytes([0xFF] * board_props.storage_size)
tock = loader.TockLoader(self.tockloader_default_args) self.write_binary(storage, board_props.storage_address)
tock.open()
try:
tock.flash_binary(storage, board_props.storage_address)
except TockLoaderException as e:
fatal(f"Couldn't erase the persistent storage: {str(e)}")
return 0 return 0
if self.args.programmer == "pyocd": if self.args.programmer == "pyocd":
self.checked_command([ self.checked_command([
@@ -549,8 +579,7 @@ class OpenSKInstaller:
def verify_flashed_app(self, expected_app): def verify_flashed_app(self, expected_app):
if self.args.programmer not in ("jlink", "openocd"): if self.args.programmer not in ("jlink", "openocd"):
return False return False
args = copy.copy(self.tockloader_default_args) tock = loader.TockLoader(self.tockloader_default_args)
tock = loader.TockLoader(args)
tock.open() tock.open()
app_found = False app_found = False
with tock._start_communication_with_board(): with tock._start_communication_with_board():
@@ -568,13 +597,9 @@ class OpenSKInstaller:
if self.args.tockos: if self.args.tockos:
# Process kernel # Process kernel
kernel_path = os.path.join("third_party", "tock", "target", kern_hex = intelhex.IntelHex()
board_props.arch, "release", kern_hex.frombytes(self.read_kernel(), offset=board_props.kernel_address)
f"{self.args.board}.bin") final_hex.merge(kern_hex, overlap="error")
with open(kernel_path, "rb") as kernel:
kern_hex = intelhex.IntelHex()
kern_hex.frombytes(kernel.read(), offset=board_props.kernel_address)
final_hex.merge(kern_hex, overlap="error")
if self.args.application: if self.args.application:
# Add padding # Add padding
@@ -669,6 +694,7 @@ class OpenSKInstaller:
if self.args.application: if self.args.application:
self.install_padding() self.install_padding()
self.install_tab_file(f"target/tab/{self.args.application}.tab") self.install_tab_file(f"target/tab/{self.args.application}.tab")
self.install_metadata()
if self.verify_flashed_app(self.args.application): if self.verify_flashed_app(self.args.application):
info("You're all set!") info("You're all set!")
return 0 return 0

View File

@@ -52,8 +52,8 @@ following:
* rustup (can be installed with [Rustup](https://rustup.rs/)) * rustup (can be installed with [Rustup](https://rustup.rs/))
* python3 and pip (can be installed with the `python3-pip` package on Debian) * python3 and pip (can be installed with the `python3-pip` package on Debian)
* the OpenSSL command line tool (can be installed with the `libssl-dev` * the OpenSSL command line tool (can be installed and configured with the
package on Debian) `libssl-dev` and `pkg-config` packages on Debian)
The scripts provided in this project have been tested under Linux and OS X. We The scripts provided in this project have been tested under Linux and OS X. We
haven't tested them on Windows and other platforms. haven't tested them on Windows and other platforms.

21
nrf52840_layout_a.ld Normal file
View File

@@ -0,0 +1,21 @@
/* Layout for the nRF52840-DK and nRF52840 dongle, used by the
* app in this repository.
*/
MEMORY {
/* The application region is 64 bytes (0x40) and we reserve 0x40000 at the end
* of the flash for the persistent storage.
*/
FLASH (rx) : ORIGIN = 0x00040040, LENGTH = 0x0001FFC0
SRAM (rwx) : ORIGIN = 0x20020000, LENGTH = 128K
}
/*
* Any change to STACK_SIZE should be accompanied by a corresponding change to
* `elf2tab`'s `--stack` option
*/
STACK_SIZE = 16384;
MPU_MIN_ALIGN = 8K;
INCLUDE layout.ld

21
nrf52840_layout_b.ld Normal file
View File

@@ -0,0 +1,21 @@
/* Layout for the nRF52840-DK and nRF52840 dongle, used by the
* app in this repository.
*/
MEMORY {
/* The application region is 64 bytes (0x40) and we reserve 0x40000 at the end
* of the flash for the persistent storage.
*/
FLASH (rx) : ORIGIN = 0x00080040, LENGTH = 0x0001FFC0
SRAM (rwx) : ORIGIN = 0x20020000, LENGTH = 128K
}
/*
* Any change to STACK_SIZE should be accompanied by a corresponding change to
* `elf2tab`'s `--stack` option
*/
STACK_SIZE = 16384;
MPU_MIN_ALIGN = 8K;
INCLUDE layout.ld

View File

@@ -2,11 +2,13 @@ diff --git a/Cargo.toml b/Cargo.toml
index 06acc26d2..e5db0740b 100644 index 06acc26d2..e5db0740b 100644
--- a/Cargo.toml --- a/Cargo.toml
+++ b/Cargo.toml +++ b/Cargo.toml
@@ -20,7 +20,11 @@ members = [ @@ -20,7 +20,13 @@ members = [
"boards/msp_exp432p401r", "boards/msp_exp432p401r",
"boards/microbit_v2", "boards/microbit_v2",
"boards/nordic/nrf52840dk", "boards/nordic/nrf52840dk",
+ "boards/nordic/nrf52840dk_opensk", + "boards/nordic/nrf52840dk_opensk",
+ "boards/nordic/nrf52840dk_opensk_a",
+ "boards/nordic/nrf52840dk_opensk_b",
"boards/nordic/nrf52840_dongle", "boards/nordic/nrf52840_dongle",
+ "boards/nordic/nrf52840_dongle_opensk", + "boards/nordic/nrf52840_dongle_opensk",
+ "boards/nordic/nrf52840_dongle_dfu", + "boards/nordic/nrf52840_dongle_dfu",