Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit 2d8f96e

Browse files
committed
Support flashing with SEGGER JLink devices
ref #168
1 parent f62277b commit 2d8f96e

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

cement

+33-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44
import os
5+
import dbus
56
import argparse
67
import subprocess
78
import shutil
@@ -41,6 +42,25 @@ def build_runtime(root, platform):
4142
return subprocess.call(["make", "-C", os.path.join(root, "ada-runtime"), "nrf52"])
4243
return subprocess.call(["make", "-C", os.path.join(root, "ada-runtime")])
4344

45+
def find_segger_jlink():
46+
for d in os.listdir("/sys/block"):
47+
if d.startswith("sd"):
48+
with open(f"/sys/block/{d}/device/vendor") as vendor:
49+
if vendor.read().strip() == "SEGGER":
50+
return d
51+
return ""
52+
53+
def mount_segger_jlink(device):
54+
mounts = [m.strip().split(' ') for m in subprocess.check_output(["mount", "-l"]).decode('utf-8').strip().split('\n')]
55+
for m in mounts:
56+
if m[0] == device:
57+
return m[2]
58+
bus = dbus.SystemBus()
59+
obj = bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2/block_devices/' + device)
60+
iface = dbus.Interface(obj, 'org.freedesktop.UDisks2.Filesystem')
61+
return iface.get_dbus_method('Mount', dbus_interface='org.freedesktop.UDisks2.Filesystem')([])
62+
63+
4464
def build_init(root, outdir, default_args, platform, logger):
4565
args = default_args + ["-P", f"core",
4666
"-aP", root,
@@ -128,7 +148,19 @@ def gpr_compile_nrf52832(config, gneiss_root, build_dir, paths, platform, logger
128148
for step in ["prepare", "compile"]:
129149
args += ["-XCEMENT_BUILD_STEP=" + step]
130150
logger.debug("gprbuild " + " ".join(args))
131-
gprbuild(args)
151+
if gprbuild(args) != 0:
152+
logger.error("Compilation failed")
153+
return
154+
jlink = find_segger_jlink()
155+
if not jlink:
156+
logger.error("No SEGGER JLink programmer found")
157+
return
158+
target = mount_segger_jlink(jlink)
159+
logger.info(f"Programmer at {target}, flashing...")
160+
subprocess.call(["arm-eabi-objcopy", "-O", "ihex",
161+
os.path.join(project_dir, "obj/core"),
162+
os.path.join(target, "core.hex")])
163+
logger.info("Finished")
132164

133165
def gpr_compile_linux(config, gneiss_root, build_dir, root_dir, paths, platform, logger, verbose):
134166
logger.info("Compiling...")

src/core/nRF52832/flash.sh

-27
This file was deleted.

0 commit comments

Comments
 (0)