Skip to content

Commit

Permalink
Add firmware merging process for nordicnrf51 // Issue #533, #500
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Aug 2, 2016
1 parent ca2adba commit a588e88
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
36 changes: 36 additions & 0 deletions platformio/builder/scripts/frameworks/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from __future__ import print_function

import json
import re
import sys
import xml.etree.ElementTree as ElementTree
Expand Down Expand Up @@ -251,6 +252,37 @@ def _mbed_whole_archive_hook(libs_):
build_flags = get_build_flags(eixdata)
variant_dir = join("$PLATFORMFW_DIR", "variant", variant)


def _find_soft_device_hex():

if not isfile(join(env.subst("$PLATFORMFW_DIR"), "targets.json")):
return None

with open(join(env.subst("$PLATFORMFW_DIR"), "targets.json")) as fp:
data = json.load(fp)

def _find_hex(target_name):
assert isinstance(data, dict)
if target_name not in data:
return None
target = data[target_name]
if "EXPECTED_SOFTDEVICES_WITH_OFFSETS" not in target:
try:
return _find_hex(target.get("inherits", [])[0])
except IndexError:
return None
else:
return target['EXPECTED_SOFTDEVICES_WITH_OFFSETS'][0]['name']

softdevice_name = _find_hex(variant)
if softdevice_name:
for root, _, files in walk(env.subst(variant_dir)):
if softdevice_name in files:
return join(root, softdevice_name)

env.Exit("Error: Cannot find SoftDevice binary file for your board!")


env.Replace(
_mbed_whole_archive_hook=_mbed_whole_archive_hook,
_LIBFLAGS="${_mbed_whole_archive_hook(%s)}" % env.get("_LIBFLAGS")[2:-1],
Expand All @@ -263,6 +295,10 @@ def _mbed_whole_archive_hook(libs_):
join(variant_dir, eixdata.get("LDSCRIPT_PATH")[0]))
)


if env.get("PLATFORM") == "nordicnrf51":
env.Append(SOFTDEVICEHEX=_find_soft_device_hex())

# restore external build flags
env.ProcessFlags(
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"))
Expand Down
29 changes: 27 additions & 2 deletions platformio/builder/scripts/nordicnrf51.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from os.path import join

from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment, SConscript)

env = DefaultEnvironment()
Expand All @@ -35,6 +35,25 @@
UPLOADERFLAGS=["-q", '"$UPLOAD_PORT"'],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
)
else:
env.Append(
BUILDERS=dict(
MergeHex=Builder(
action=" ".join([
join("$PIOPACKAGES_DIR", "tool-sreccat", "srec_cat"),
"$SOFTDEVICEHEX",
"-intel",
"$SOURCES",
"-intel",
"-o",
"$TARGET",
"-intel",
"--line-length=44"
]),
suffix=".hex"
)
)
)

#
# Target: Build executable and linkable firmware
Expand All @@ -49,7 +68,13 @@
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)
if env.subst("$BOARD") == "rfduino":
target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)
else:
target_firm = env.MergeHex(
join("$BUILD_DIR", "firmware"),
env.ElfToHex(join("$BUILD_DIR", "userfirmware"), target_elf)
)

#
# Target: Print binary size
Expand Down
3 changes: 3 additions & 0 deletions platformio/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
],
"tool-arduino101load": [
("Genuino101 uploader", "https://github.com/01org/intel-arduino-tools")
],
"tool-sreccat": [
("Merging tool", "https://github.com/marcows/SRecord")
]
}

Expand Down
4 changes: 4 additions & 0 deletions platformio/platforms/nordicnrf51.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Nordicnrf51Platform(BasePlatform):
"alias": "framework"
},

"tool-sreccat": {
"default": True
},

"tool-rfdloader": {
}
}
Expand Down

0 comments on commit a588e88

Please sign in to comment.