Improve deploy script.
- Check that JLinkExe in properly installed - Verify that the app is installed - Always report failures in the exit code - Add vscode settings for Python code formatting using Google style - Fix issue #42 regarding tockloader version and sticky parameter
This commit is contained in:
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@@ -1,7 +1,20 @@
|
|||||||
{
|
{
|
||||||
|
"editor.detectIndentation": true,
|
||||||
|
"editor.formatOnPaste": false,
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
|
"editor.formatOnType": true,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"editor.tabSize": 4,
|
||||||
"rust-client.channel": "nightly",
|
"rust-client.channel": "nightly",
|
||||||
// The toolchain is updated from time to time so let's make sure that RLS is updated too
|
// The toolchain is updated from time to time so let's make sure that RLS is updated too
|
||||||
"rust-client.updateOnStartup": true,
|
"rust-client.updateOnStartup": true,
|
||||||
"rust.clippy_preference": "on"
|
"rust.clippy_preference": "on",
|
||||||
|
// Try to make VSCode formating as close as possible to the Google style.
|
||||||
|
"python.formatting.provider": "yapf",
|
||||||
|
"python.formatting.yapfArgs": [
|
||||||
|
"--style=chromium"
|
||||||
|
],
|
||||||
|
"[python]": {
|
||||||
|
"editor.tabSize": 2
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
141
deploy.py
141
deploy.py
@@ -27,7 +27,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from tockloader import tab, tbfh, tockloader
|
from tockloader import tab, tbfh, tockloader
|
||||||
|
|
||||||
|
|
||||||
# This structure allows us in the future to also support out-of-tree boards.
|
# This structure allows us in the future to also support out-of-tree boards.
|
||||||
SUPPORTED_BOARDS = {
|
SUPPORTED_BOARDS = {
|
||||||
"nrf52840_dk": "third_party/tock/boards/nordic/nrf52840dk",
|
"nrf52840_dk": "third_party/tock/boards/nordic/nrf52840dk",
|
||||||
@@ -76,6 +75,7 @@ def info(msg):
|
|||||||
|
|
||||||
|
|
||||||
class RemoveConstAction(argparse.Action):
|
class RemoveConstAction(argparse.Action):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
option_strings,
|
option_strings,
|
||||||
dest,
|
dest,
|
||||||
@@ -109,6 +109,7 @@ class RemoveConstAction(argparse.Action):
|
|||||||
|
|
||||||
|
|
||||||
class OpenSKInstaller(object):
|
class OpenSKInstaller(object):
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
colorama.init()
|
colorama.init()
|
||||||
self.args = args
|
self.args = args
|
||||||
@@ -116,8 +117,7 @@ class OpenSKInstaller(object):
|
|||||||
self.tab_folder = os.path.join("target", "tab")
|
self.tab_folder = os.path.join("target", "tab")
|
||||||
# This is the filename that elf2tab command expects in order
|
# This is the filename that elf2tab command expects in order
|
||||||
# to create a working TAB file.
|
# to create a working TAB file.
|
||||||
self.target_elf_filename = os.path.join(
|
self.target_elf_filename = os.path.join(self.tab_folder, "cortex-m4.elf")
|
||||||
self.tab_folder, "cortex-m4.elf")
|
|
||||||
self.tockloader_default_args = argparse.Namespace(
|
self.tockloader_default_args = argparse.Namespace(
|
||||||
arch="cortex-m4",
|
arch="cortex-m4",
|
||||||
board=getattr(self.args, "board", "nrf52840"),
|
board=getattr(self.args, "board", "nrf52840"),
|
||||||
@@ -154,11 +154,9 @@ class OpenSKInstaller(object):
|
|||||||
# empty value.
|
# empty value.
|
||||||
target_toolchain.append('')
|
target_toolchain.append('')
|
||||||
current_version = self.checked_command_output(["rustc", "--version"])
|
current_version = self.checked_command_output(["rustc", "--version"])
|
||||||
if not all(
|
if not all((target_toolchain[0] in current_version,
|
||||||
(target_toolchain[0] in current_version,
|
|
||||||
target_toolchain[1] in current_version)):
|
target_toolchain[1] in current_version)):
|
||||||
info("Updating rust toolchain to {}".format(
|
info("Updating rust toolchain to {}".format("-".join(target_toolchain)))
|
||||||
"-".join(target_toolchain)))
|
|
||||||
# Need to update
|
# Need to update
|
||||||
self.checked_command_output(
|
self.checked_command_output(
|
||||||
["rustup", "install", target_toolchain_fullstring])
|
["rustup", "install", target_toolchain_fullstring])
|
||||||
@@ -168,26 +166,21 @@ class OpenSKInstaller(object):
|
|||||||
|
|
||||||
def build_and_install_tockos(self):
|
def build_and_install_tockos(self):
|
||||||
self.checked_command_output(
|
self.checked_command_output(
|
||||||
["make", "-C", SUPPORTED_BOARDS[self.args.board], "flash"]
|
["make", "-C", SUPPORTED_BOARDS[self.args.board], "flash"])
|
||||||
)
|
|
||||||
|
|
||||||
def build_and_install_example(self):
|
def build_and_install_example(self):
|
||||||
assert(self.args.application)
|
assert (self.args.application)
|
||||||
self.checked_command_output([
|
self.checked_command_output([
|
||||||
"cargo",
|
"cargo", "build", "--release", "--target=thumbv7em-none-eabi",
|
||||||
"build",
|
"--features={}".format(",".join(self.args.features)), "--example",
|
||||||
"--release",
|
|
||||||
"--target=thumbv7em-none-eabi",
|
|
||||||
"--features={}".format(",".join(self.args.features)),
|
|
||||||
"--example",
|
|
||||||
self.args.application
|
self.args.application
|
||||||
])
|
])
|
||||||
self.install_elf_file(os.path.join(
|
self.install_elf_file(
|
||||||
"target/thumbv7em-none-eabi/release/examples",
|
os.path.join("target/thumbv7em-none-eabi/release/examples",
|
||||||
self.args.application))
|
self.args.application))
|
||||||
|
|
||||||
def build_and_install_opensk(self):
|
def build_and_install_opensk(self):
|
||||||
assert(self.args.application)
|
assert (self.args.application)
|
||||||
info("Building OpenSK application")
|
info("Building OpenSK application")
|
||||||
self.checked_command_output([
|
self.checked_command_output([
|
||||||
"cargo",
|
"cargo",
|
||||||
@@ -196,8 +189,9 @@ class OpenSKInstaller(object):
|
|||||||
"--target=thumbv7em-none-eabi",
|
"--target=thumbv7em-none-eabi",
|
||||||
"--features={}".format(",".join(self.args.features)),
|
"--features={}".format(",".join(self.args.features)),
|
||||||
])
|
])
|
||||||
self.install_elf_file(os.path.join(
|
self.install_elf_file(
|
||||||
"target/thumbv7em-none-eabi/release", self.args.application))
|
os.path.join("target/thumbv7em-none-eabi/release",
|
||||||
|
self.args.application))
|
||||||
|
|
||||||
def generate_crypto_materials(self, force_regenerate):
|
def generate_crypto_materials(self, force_regenerate):
|
||||||
has_error = subprocess.call([
|
has_error = subprocess.call([
|
||||||
@@ -205,35 +199,27 @@ class OpenSKInstaller(object):
|
|||||||
"Y" if force_regenerate else "N",
|
"Y" if force_regenerate else "N",
|
||||||
])
|
])
|
||||||
if has_error:
|
if has_error:
|
||||||
error((
|
error(("Something went wrong while trying to generate ECC "
|
||||||
"Something went wrong while trying to generate ECC "
|
|
||||||
"key and/or certificate for OpenSK"))
|
"key and/or certificate for OpenSK"))
|
||||||
|
|
||||||
def install_elf_file(self, elf_path):
|
def install_elf_file(self, elf_path):
|
||||||
assert(self.args.application)
|
assert (self.args.application)
|
||||||
package_parameter = "-n"
|
package_parameter = "-n"
|
||||||
elf2tab_ver = self.checked_command_output(
|
elf2tab_ver = self.checked_command_output(["elf2tab", "--version"]).split(
|
||||||
["elf2tab", "--version"]).split(' ', maxsplit=1)[1]
|
' ', maxsplit=1)[1]
|
||||||
# Starting from v0.5.0-dev the parameter changed.
|
# Starting from v0.5.0-dev the parameter changed.
|
||||||
# Current pyblished crate is 0.4.0 but we don't want developers
|
# Current pyblished crate is 0.4.0 but we don't want developers
|
||||||
# running the HEAD from github to be stuck
|
# running the HEAD from github to be stuck
|
||||||
if "0.5.0-dev" in elf2tab_ver:
|
if "0.5.0-dev" in elf2tab_ver:
|
||||||
package_parameter = "--package-name"
|
package_parameter = "--package-name"
|
||||||
os.makedirs(self.tab_folder, exist_ok=True)
|
os.makedirs(self.tab_folder, exist_ok=True)
|
||||||
tab_filename = os.path.join(
|
tab_filename = os.path.join(self.tab_folder,
|
||||||
self.tab_folder,
|
|
||||||
"{}.tab".format(self.args.application))
|
"{}.tab".format(self.args.application))
|
||||||
shutil.copyfile(elf_path, self.target_elf_filename)
|
shutil.copyfile(elf_path, self.target_elf_filename)
|
||||||
self.checked_command_output([
|
self.checked_command_output([
|
||||||
"elf2tab",
|
"elf2tab", package_parameter, self.args.application, "-o", tab_filename,
|
||||||
package_parameter,
|
self.target_elf_filename, "--stack={}".format(STACK_SIZE),
|
||||||
self.args.application,
|
"--app-heap={}".format(APP_HEAP_SIZE), "--kernel-heap=1024",
|
||||||
"-o",
|
|
||||||
tab_filename,
|
|
||||||
self.target_elf_filename,
|
|
||||||
"--stack={}".format(STACK_SIZE),
|
|
||||||
"--app-heap={}".format(APP_HEAP_SIZE),
|
|
||||||
"--kernel-heap=1024",
|
|
||||||
"--protected-region-size=64"
|
"--protected-region-size=64"
|
||||||
])
|
])
|
||||||
self.install_padding()
|
self.install_padding()
|
||||||
@@ -243,13 +229,11 @@ class OpenSKInstaller(object):
|
|||||||
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)
|
||||||
setattr(args, "sticky", False)
|
|
||||||
tock = tockloader.TockLoader(args)
|
tock = tockloader.TockLoader(args)
|
||||||
tock.open(args)
|
tock.open(args)
|
||||||
tabs = [tab.TAB(tab_filename)]
|
tabs = [tab.TAB(tab_filename)]
|
||||||
try:
|
try:
|
||||||
tock.install(tabs, replace="yes",
|
tock.install(tabs, replace="yes", erase=args.erase)
|
||||||
erase=args.erase, sticky=args.sticky)
|
|
||||||
except tockloader.exceptions.TockLoaderException as e:
|
except tockloader.exceptions.TockLoaderException as e:
|
||||||
fatal("Couldn't install Tock application {}: {}".format(
|
fatal("Couldn't install Tock application {}: {}".format(
|
||||||
self.args.application, str(e)))
|
self.args.application, str(e)))
|
||||||
@@ -284,16 +268,26 @@ class OpenSKInstaller(object):
|
|||||||
info(("A non-critical error occured while erasing "
|
info(("A non-critical error occured while erasing "
|
||||||
"apps: {}".format(str(e))))
|
"apps: {}".format(str(e))))
|
||||||
|
|
||||||
|
def verify_flashed_app(self, expected_app):
|
||||||
|
args = copy.copy(self.tockloader_default_args)
|
||||||
|
tock = tockloader.TockLoader(args)
|
||||||
|
app_found = False
|
||||||
|
with tock._start_communication_with_board():
|
||||||
|
apps = [app.name for app in tock._extract_all_app_headers()]
|
||||||
|
app_found = expected_app in apps
|
||||||
|
return app_found
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.args.action is None:
|
if self.args.action is None:
|
||||||
# Nothing to do
|
# Nothing to do
|
||||||
return
|
return 0
|
||||||
|
|
||||||
self.update_rustc_if_needed()
|
self.update_rustc_if_needed()
|
||||||
|
|
||||||
if self.args.action == "os":
|
if self.args.action == "os":
|
||||||
info("Installing Tock on board {}".format(self.args.board))
|
info("Installing Tock on board {}".format(self.args.board))
|
||||||
self.build_and_install_tockos()
|
self.build_and_install_tockos()
|
||||||
|
return 0
|
||||||
|
|
||||||
if self.args.action == "app":
|
if self.args.action == "app":
|
||||||
if self.args.application is None:
|
if self.args.application is None:
|
||||||
@@ -305,6 +299,12 @@ class OpenSKInstaller(object):
|
|||||||
self.build_and_install_opensk()
|
self.build_and_install_opensk()
|
||||||
else:
|
else:
|
||||||
self.build_and_install_example()
|
self.build_and_install_example()
|
||||||
|
if self.verify_flashed_app(self.args.application):
|
||||||
|
info("You're all set!")
|
||||||
|
return 0
|
||||||
|
error(("It seems that something went wrong. "
|
||||||
|
"App/example not found on your board."))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
@@ -325,28 +325,21 @@ if __name__ == '__main__':
|
|||||||
action="store_false",
|
action="store_false",
|
||||||
default=True,
|
default=True,
|
||||||
dest="clear_apps",
|
dest="clear_apps",
|
||||||
help=(
|
help=("When installing an application, previously installed "
|
||||||
"When installing an application, previously installed "
|
"applications won't be erased from the board."),
|
||||||
"applications won't be erased from the board."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
commands = parser.add_subparsers(
|
commands = parser.add_subparsers(
|
||||||
dest="action",
|
dest="action",
|
||||||
help=(
|
help=("Indicates which part of the firmware should be compiled and "
|
||||||
"Indicates which part of the firmware should be compiled and "
|
"flashed to the connected board."))
|
||||||
"flashed to the connected board."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
os_commands = commands.add_parser(
|
os_commands = commands.add_parser(
|
||||||
"os",
|
"os",
|
||||||
parents=[shared_parser],
|
parents=[shared_parser],
|
||||||
help=(
|
help=("Compiles and installs Tock OS. The target board must be "
|
||||||
"Compiles and installs Tock OS. The target board must be "
|
"specified by setting the --board argument."),
|
||||||
"specified by setting the --board argument."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
os_commands.add_argument(
|
os_commands.add_argument(
|
||||||
"--board",
|
"--board",
|
||||||
@@ -354,57 +347,47 @@ if __name__ == '__main__':
|
|||||||
dest="board",
|
dest="board",
|
||||||
choices=get_supported_boards(),
|
choices=get_supported_boards(),
|
||||||
help="Indicates which board Tock OS will be compiled for.",
|
help="Indicates which board Tock OS will be compiled for.",
|
||||||
required=True
|
required=True)
|
||||||
)
|
|
||||||
|
|
||||||
app_commands = commands.add_parser(
|
app_commands = commands.add_parser(
|
||||||
"app",
|
"app",
|
||||||
parents=[shared_parser],
|
parents=[shared_parser],
|
||||||
help="compiles and installs an application."
|
help="compiles and installs an application.")
|
||||||
)
|
|
||||||
app_commands.add_argument(
|
app_commands.add_argument(
|
||||||
"--panic-console",
|
"--panic-console",
|
||||||
action="append_const",
|
action="append_const",
|
||||||
const="panic_console",
|
const="panic_console",
|
||||||
dest="features",
|
dest="features",
|
||||||
help=(
|
help=("In case of application panic, the console will be used to "
|
||||||
"In case of application panic, the console will be used to "
|
|
||||||
"output messages before starting blinking the LEDs on the "
|
"output messages before starting blinking the LEDs on the "
|
||||||
"board."
|
"board."),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
app_commands.add_argument(
|
app_commands.add_argument(
|
||||||
"--no-u2f",
|
"--no-u2f",
|
||||||
action=RemoveConstAction,
|
action=RemoveConstAction,
|
||||||
const="with_ctap1",
|
const="with_ctap1",
|
||||||
dest="features",
|
dest="features",
|
||||||
help=(
|
help=("Compiles the OpenSK application without backward compatible "
|
||||||
"Compiles the OpenSK application without backward compatible "
|
"support for U2F/CTAP1 protocol."),
|
||||||
"support for U2F/CTAP1 protocol."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
app_commands.add_argument(
|
app_commands.add_argument(
|
||||||
"--regen-keys",
|
"--regen-keys",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
dest="regenerate_keys",
|
dest="regenerate_keys",
|
||||||
help=(
|
help=("Forces the generation of files (certificates and private keys) "
|
||||||
"Forces the generation of files (certificates and private keys) "
|
|
||||||
"under the crypto_data/ directory. "
|
"under the crypto_data/ directory. "
|
||||||
"This is useful to allow flashing multiple OpenSK authenticators "
|
"This is useful to allow flashing multiple OpenSK authenticators "
|
||||||
"in a row without them being considered clones."
|
"in a row without them being considered clones."),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
app_commands.add_argument(
|
app_commands.add_argument(
|
||||||
"--debug",
|
"--debug",
|
||||||
action="append_const",
|
action="append_const",
|
||||||
const="debug_ctap",
|
const="debug_ctap",
|
||||||
dest="features",
|
dest="features",
|
||||||
help=(
|
help=("Compiles and installs the OpenSK application in debug mode "
|
||||||
"Compiles and installs the OpenSK application in debug mode "
|
|
||||||
"(i.e. more debug messages will be sent over the console port "
|
"(i.e. more debug messages will be sent over the console port "
|
||||||
"such as hexdumps of packets)."
|
"such as hexdumps of packets)."),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
apps = app_commands.add_mutually_exclusive_group()
|
apps = app_commands.add_mutually_exclusive_group()
|
||||||
apps.add_argument(
|
apps.add_argument(
|
||||||
@@ -412,18 +395,14 @@ if __name__ == '__main__':
|
|||||||
dest="application",
|
dest="application",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="ctap2",
|
const="ctap2",
|
||||||
help="Compiles and installs the OpenSK application."
|
help="Compiles and installs the OpenSK application.")
|
||||||
)
|
|
||||||
apps.add_argument(
|
apps.add_argument(
|
||||||
"--crypto_bench",
|
"--crypto_bench",
|
||||||
dest="application",
|
dest="application",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="crypto_bench",
|
const="crypto_bench",
|
||||||
help=(
|
help=("Compiles and installs the crypto_bench example that tests "
|
||||||
"Compiles and installs the crypto_bench example that tests "
|
"the performance of the cryptographic algorithms on the board."))
|
||||||
"the performance of the cryptographic algorithms on the board."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
app_commands.set_defaults(features=["with_ctap1"])
|
app_commands.set_defaults(features=["with_ctap1"])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user