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:
@@ -1,4 +1,29 @@
|
||||
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; 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();
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#![feature(const_in_array_repeat_expressions)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use core::env;
|
||||
use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState};
|
||||
use kernel::component::Component;
|
||||
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] =
|
||||
[None; NUM_PROCS];
|
||||
|
||||
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,
|
||||
},
|
||||
];
|
||||
include!(concat!(env!("OUT_DIR"), "/locations.rs"));
|
||||
|
||||
static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;
|
||||
|
||||
|
||||
18
boards/nordic/nrf52840dk_opensk_a/Cargo.toml
Normal file
18
boards/nordic/nrf52840dk_opensk_a/Cargo.toml
Normal 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" }
|
||||
31
boards/nordic/nrf52840dk_opensk_a/Makefile
Normal file
31
boards/nordic/nrf52840dk_opensk_a/Makefile
Normal 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)
|
||||
11
boards/nordic/nrf52840dk_opensk_a/README.md
Normal file
11
boards/nordic/nrf52840dk_opensk_a/README.md
Normal 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`.
|
||||
45
boards/nordic/nrf52840dk_opensk_a/build.rs
Normal file
45
boards/nordic/nrf52840dk_opensk_a/build.rs
Normal 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();
|
||||
}
|
||||
13
boards/nordic/nrf52840dk_opensk_a/layout.ld
Normal file
13
boards/nordic/nrf52840dk_opensk_a/layout.ld
Normal 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
|
||||
|
||||
18
boards/nordic/nrf52840dk_opensk_b/Cargo.toml
Normal file
18
boards/nordic/nrf52840dk_opensk_b/Cargo.toml
Normal 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" }
|
||||
31
boards/nordic/nrf52840dk_opensk_b/Makefile
Normal file
31
boards/nordic/nrf52840dk_opensk_b/Makefile
Normal 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)
|
||||
11
boards/nordic/nrf52840dk_opensk_b/README.md
Normal file
11
boards/nordic/nrf52840dk_opensk_b/README.md
Normal 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`.
|
||||
45
boards/nordic/nrf52840dk_opensk_b/build.rs
Normal file
45
boards/nordic/nrf52840dk_opensk_b/build.rs
Normal 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();
|
||||
}
|
||||
13
boards/nordic/nrf52840dk_opensk_b/layout.ld
Normal file
13
boards/nordic/nrf52840dk_opensk_b/layout.ld
Normal 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
|
||||
|
||||
2
build.rs
2
build.rs
@@ -32,6 +32,8 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed={}", UPGRADE_FILE);
|
||||
println!("cargo:rerun-if-changed=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 aaguid_bin_path = Path::new(&out_dir).join("opensk_aaguid.bin");
|
||||
|
||||
202
deploy.py
202
deploy.py
@@ -22,8 +22,11 @@ from __future__ import print_function
|
||||
import argparse
|
||||
import collections
|
||||
import copy
|
||||
import datetime
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@@ -50,12 +53,19 @@ OpenSKBoard = collections.namedtuple(
|
||||
"page_size",
|
||||
# Flash address at which the kernel will be written
|
||||
"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
|
||||
# address specified by this parameter (must match the `prog` value
|
||||
# specified on the board's `layout.ld` file) and will end at
|
||||
# `app_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
|
||||
"app_ldscript",
|
||||
# Flash address at which the app should be written
|
||||
@@ -83,14 +93,14 @@ OpenSKBoard = collections.namedtuple(
|
||||
"nordic_dfu",
|
||||
])
|
||||
|
||||
SUPPORTED_BOARDS = {
|
||||
"nrf52840dk_opensk":
|
||||
OpenSKBoard(
|
||||
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,
|
||||
@@ -102,62 +112,44 @@ SUPPORTED_BOARDS = {
|
||||
jlink_if="swd",
|
||||
jlink_device="nrf52840_xxaa",
|
||||
nordic_dfu=False,
|
||||
)
|
||||
|
||||
SUPPORTED_BOARDS = {
|
||||
"nrf52840dk_opensk":
|
||||
nrf52840dk_opensk_board,
|
||||
"nrf52840dk_opensk_a":
|
||||
nrf52840dk_opensk_board._replace(
|
||||
path=nrf52840dk_opensk_board.path + "_a",
|
||||
kernel_address=0x20000,
|
||||
padding_address=None,
|
||||
firmware_size=0x40000,
|
||||
metadata_address=0x4000,
|
||||
app_ldscript="nrf52840_layout_a.ld",
|
||||
app_address=0x40000,
|
||||
),
|
||||
"nrf52840dk_opensk_b":
|
||||
nrf52840dk_opensk_board._replace(
|
||||
path=nrf52840dk_opensk_board.path + "_b",
|
||||
kernel_address=0x60000,
|
||||
padding_address=None,
|
||||
firmware_size=0x40000,
|
||||
metadata_address=0x5000,
|
||||
app_ldscript="nrf52840_layout_b.ld",
|
||||
app_address=0x80000,
|
||||
),
|
||||
"nrf52840_dongle_opensk":
|
||||
OpenSKBoard(
|
||||
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,
|
||||
),
|
||||
nrf52840dk_opensk_board._replace(
|
||||
path="third_party/tock/boards/nordic/nrf52840_dongle_opensk",),
|
||||
"nrf52840_dongle_dfu":
|
||||
OpenSKBoard(
|
||||
nrf52840dk_opensk_board._replace(
|
||||
path="third_party/tock/boards/nordic/nrf52840_dongle_dfu",
|
||||
arch="thumbv7em-none-eabi",
|
||||
page_size=4096,
|
||||
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,
|
||||
),
|
||||
"nrf52840_mdk_dfu":
|
||||
OpenSKBoard(
|
||||
nrf52840dk_opensk_board._replace(
|
||||
path="third_party/tock/boards/nordic/nrf52840_mdk_dfu",
|
||||
arch="thumbv7em-none-eabi",
|
||||
page_size=4096,
|
||||
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,
|
||||
),
|
||||
}
|
||||
@@ -205,6 +197,18 @@ def assert_python_library(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):
|
||||
|
||||
# pylint: disable=redefined-builtin
|
||||
@@ -250,6 +254,7 @@ class OpenSKInstaller:
|
||||
self.tab_folder = os.path.join("target", "tab")
|
||||
board = SUPPORTED_BOARDS[self.args.board]
|
||||
self.tockloader_default_args = argparse.Namespace(
|
||||
app_address=board.app_address,
|
||||
arch=board.arch,
|
||||
board=self.args.board,
|
||||
bundle_apps=False,
|
||||
@@ -455,9 +460,7 @@ class OpenSKInstaller:
|
||||
def install_tab_file(self, tab_filename):
|
||||
assert 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)
|
||||
setattr(args, "app_address", board_props.app_address)
|
||||
setattr(args, "erase", self.args.clear_apps)
|
||||
setattr(args, "make", False)
|
||||
setattr(args, "no_replace", False)
|
||||
@@ -476,40 +479,72 @@ class OpenSKInstaller:
|
||||
SUPPORTED_BOARDS[self.args.board].padding_address)
|
||||
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]
|
||||
kernel_file = os.path.join("third_party", "tock", "target",
|
||||
board_props.arch, "release",
|
||||
f"{self.args.board}.bin")
|
||||
info(f"Flashing file {kernel_file}.")
|
||||
with open(kernel_file, "rb") as f:
|
||||
kernel = f.read()
|
||||
args = copy.copy(self.tockloader_default_args)
|
||||
setattr(args, "address", board_props.app_address)
|
||||
tock = loader.TockLoader(args)
|
||||
tock.open()
|
||||
try:
|
||||
tock.flash_binary(kernel, board_props.kernel_address)
|
||||
except TockLoaderException as e:
|
||||
fatal(f"Couldn't install Tock OS: {str(e)}")
|
||||
if not os.path.exists(kernel_file):
|
||||
fatal(f"File not found: {kernel_file}")
|
||||
with open(kernel_file, "rb") as firmware:
|
||||
kernel = firmware.read()
|
||||
return kernel
|
||||
|
||||
def install_tock_os(self):
|
||||
kernel = self.read_kernel()
|
||||
board_props = SUPPORTED_BOARDS[self.args.board]
|
||||
self.write_binary(kernel, board_props.kernel_address)
|
||||
|
||||
def install_padding(self):
|
||||
padding = self.get_padding()
|
||||
board_props = SUPPORTED_BOARDS[self.args.board]
|
||||
if board_props.padding_address is None:
|
||||
return
|
||||
info("Flashing padding application")
|
||||
args = copy.copy(self.tockloader_default_args)
|
||||
setattr(args, "address", board_props.padding_address)
|
||||
tock = loader.TockLoader(args)
|
||||
tock.open()
|
||||
try:
|
||||
tock.flash_binary(padding, args.address)
|
||||
except TockLoaderException as e:
|
||||
fatal(f"Couldn't install padding: {str(e)}")
|
||||
self.write_binary(self.get_padding(), board_props.padding_address)
|
||||
|
||||
def install_metadata(self):
|
||||
|
||||
def pad_to(binary, length):
|
||||
if len(binary) > length:
|
||||
fatal(f"Binary size {len(binary)} exceeds flash partition {length}.")
|
||||
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):
|
||||
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
|
||||
# at `board.app_address`. This makes sure we don't erase the padding.
|
||||
setattr(args, "force", False)
|
||||
@@ -530,12 +565,7 @@ class OpenSKInstaller:
|
||||
# Use tockloader if possible
|
||||
if self.args.programmer in ("jlink", "openocd"):
|
||||
storage = bytes([0xFF] * board_props.storage_size)
|
||||
tock = loader.TockLoader(self.tockloader_default_args)
|
||||
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)}")
|
||||
self.write_binary(storage, board_props.storage_address)
|
||||
return 0
|
||||
if self.args.programmer == "pyocd":
|
||||
self.checked_command([
|
||||
@@ -549,8 +579,7 @@ class OpenSKInstaller:
|
||||
def verify_flashed_app(self, expected_app):
|
||||
if self.args.programmer not in ("jlink", "openocd"):
|
||||
return False
|
||||
args = copy.copy(self.tockloader_default_args)
|
||||
tock = loader.TockLoader(args)
|
||||
tock = loader.TockLoader(self.tockloader_default_args)
|
||||
tock.open()
|
||||
app_found = False
|
||||
with tock._start_communication_with_board():
|
||||
@@ -568,12 +597,8 @@ class OpenSKInstaller:
|
||||
|
||||
if self.args.tockos:
|
||||
# Process kernel
|
||||
kernel_path = os.path.join("third_party", "tock", "target",
|
||||
board_props.arch, "release",
|
||||
f"{self.args.board}.bin")
|
||||
with open(kernel_path, "rb") as kernel:
|
||||
kern_hex = intelhex.IntelHex()
|
||||
kern_hex.frombytes(kernel.read(), offset=board_props.kernel_address)
|
||||
kern_hex.frombytes(self.read_kernel(), offset=board_props.kernel_address)
|
||||
final_hex.merge(kern_hex, overlap="error")
|
||||
|
||||
if self.args.application:
|
||||
@@ -669,6 +694,7 @@ class OpenSKInstaller:
|
||||
if self.args.application:
|
||||
self.install_padding()
|
||||
self.install_tab_file(f"target/tab/{self.args.application}.tab")
|
||||
self.install_metadata()
|
||||
if self.verify_flashed_app(self.args.application):
|
||||
info("You're all set!")
|
||||
return 0
|
||||
|
||||
@@ -52,8 +52,8 @@ following:
|
||||
|
||||
* rustup (can be installed with [Rustup](https://rustup.rs/))
|
||||
* 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`
|
||||
package on Debian)
|
||||
* the OpenSSL command line tool (can be installed and configured with the
|
||||
`libssl-dev` and `pkg-config` packages on Debian)
|
||||
|
||||
The scripts provided in this project have been tested under Linux and OS X. We
|
||||
haven't tested them on Windows and other platforms.
|
||||
|
||||
21
nrf52840_layout_a.ld
Normal file
21
nrf52840_layout_a.ld
Normal 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
21
nrf52840_layout_b.ld
Normal 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
|
||||
@@ -2,11 +2,13 @@ diff --git a/Cargo.toml b/Cargo.toml
|
||||
index 06acc26d2..e5db0740b 100644
|
||||
--- a/Cargo.toml
|
||||
+++ b/Cargo.toml
|
||||
@@ -20,7 +20,11 @@ members = [
|
||||
@@ -20,7 +20,13 @@ members = [
|
||||
"boards/msp_exp432p401r",
|
||||
"boards/microbit_v2",
|
||||
"boards/nordic/nrf52840dk",
|
||||
+ "boards/nordic/nrf52840dk_opensk",
|
||||
+ "boards/nordic/nrf52840dk_opensk_a",
|
||||
+ "boards/nordic/nrf52840dk_opensk_b",
|
||||
"boards/nordic/nrf52840_dongle",
|
||||
+ "boards/nordic/nrf52840_dongle_opensk",
|
||||
+ "boards/nordic/nrf52840_dongle_dfu",
|
||||
|
||||
Reference in New Issue
Block a user