Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #64 from NordicSemiconductor/feature/sd-id
Browse files Browse the repository at this point in the history
--sd-id param added to *pkg generate*
  • Loading branch information
bencefr authored Jun 29, 2017
2 parents 1704d94 + fb2cc7e commit ddc480e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ SoftDevice | FWID (sd-req)
`s132_nrf52_4.0.0` | 0x95
`s132_nrf52_4.0.2` | 0x98
`s132_nrf52_4.0.3` | 0x99
`s132_nrf52_5.0.0` | 0x9D

**Note**: The Thread stack doesn't use a SoftDevice but --sd-req option is required for compatibility reasons. You can provide any value for the option as it is ignored during DFU.

Expand All @@ -158,12 +159,16 @@ The following conventions are used on the table:
Combination | Supported | Notes
--------------| ----------|-------
BL | Yes |
SD | Yes | **SD must be of the same Major Version**
SD | Yes | **See notes 1 and 2 below**
APP | Yes |
BL + SD | Yes |
BL + APP | No | Create two .zip packages instead
BL + SD + APP | Yes |
SD + APP | Yes | **SD must be of the same Major Version**
BL + SD + APP | Yes | **See note 1 below**
SD + APP | Yes | **See notes 1 and 2 below**

**Note 1:** SD must be of the same Major Version as the old BL may not be compatible with the new SD.

**Note 2:** When updating BL + SD + APP the update is done in 2 following connections, unless a custom bootloader is used. First the BL + SD is updated, then the bootloader will disconnect and the new BL will start advertising. Second connection to the new bootloader will update the APP. However, the two SDs may have different IDs. The first update requires --sd-req to be set to the ID of the old SD while update of the APP requires the ID of the new SD. In that case the new ID can be set using ```--sd-id``` parameter.

##### display
Use this option to display the contents of a DFU package in a .zip file.
Expand Down
32 changes: 31 additions & 1 deletion nordicsemi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,13 @@ def pkg():
'\n|s132_nrf52_3.1.0|0x91|'
'\n|s132_nrf52_4.0.0|0x95|'
'\n|s132_nrf52_4.0.2|0x98|'
'\n|s132_nrf52_4.0.3|0x99|',
'\n|s132_nrf52_4.0.3|0x99|'
'\n|s132_nrf52_5.0.0|0x9D|',
type=click.STRING,
multiple=True)
@click.option('--sd-id',
help='The new SoftDevice ID to be used as --sd-req for the Application update in case the ZIP '
'contains a SoftDevice and an Application.',
type=click.STRING,
multiple=True)
@click.option('--softdevice',
Expand All @@ -408,6 +414,7 @@ def generate(zipfile,
bootloader_version,
hw_version,
sd_req,
sd_id,
softdevice,
key_file):
"""
Expand Down Expand Up @@ -470,6 +477,16 @@ def generate(zipfile,
if sd_req == 'none':
sd_req = None

if len(sd_id) > 1:
click.echo("Please specify SoftDevice requirements as a comma-separated list: --sd-id 0xXXXX,0xYYYY,...")
return
elif len(sd_id) == 0:
sd_id = None
else:
sd_id = sd_id[0]
if sd_id == 'none':
sd_id = None

# Initial consistency checks
if application_version_internal is not None and application is None:
click.echo("Error: Application version with no image.")
Expand Down Expand Up @@ -520,6 +537,18 @@ def generate(zipfile,
raise NordicSemiException("Could not parse value for --sd-req. "
"Hex values should be prefixed with 0x.")

sd_id_list = []
if sd_id is not None:
try:
# This will parse any string starting with 0x as base 16.
sd_id_list = sd_id.split(',')
sd_id_list = map(int_as_text_to_int, sd_id_list)
except ValueError:
raise NordicSemiException("Could not parse value for --sd-id. "
"Hex values should be prefixed with 0x.")
else:
sd_id_list = sd_req_list

signer = Signing()
default_key = signer.load_key(key_file)
if default_key:
Expand All @@ -530,6 +559,7 @@ def generate(zipfile,
application_version_internal,
bootloader_version,
sd_req_list,
sd_id_list,
application,
bootloader,
softdevice,
Expand Down
10 changes: 8 additions & 2 deletions nordicsemi/dfu/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Package(object):
DEFAULT_APP_VERSION = 0xFFFFFFFF
DEFAULT_BL_VERSION = 0xFFFFFFFF
DEFAULT_SD_REQ = [0xFFFE]
DEFAULT_SD_ID = [0xFFFE]
DEFAULT_DFU_VER = 0.5
MANIFEST_FILENAME = "manifest.json"

Expand All @@ -115,6 +116,7 @@ def __init__(self,
app_version=DEFAULT_APP_VERSION,
bl_version=DEFAULT_BL_VERSION,
sd_req=DEFAULT_SD_REQ,
sd_id=DEFAULT_SD_ID,
app_fw=None,
bootloader_fw=None,
softdevice_fw=None,
Expand All @@ -127,6 +129,7 @@ def __init__(self,
:param int app_version: App version init-packet field
:param int bl_version: Bootloader version init-packet field
:param list sd_req: Softdevice Requirement init-packet field
:param list sd_id: Softdevice Requirement init-packet field for the Application if softdevice_fw is set
:param str app_fw: Path to application firmware file
:param str bootloader_fw: Path to bootloader firmware file
:param str softdevice_fw: Path to softdevice firmware file
Expand All @@ -141,8 +144,8 @@ def __init__(self,
if hw_version is not None:
init_packet_vars[PacketField.HW_VERSION] = hw_version

if sd_req is not None:
init_packet_vars[PacketField.REQUIRED_SOFTDEVICES_ARRAY] = sd_req
if sd_id is not None:
init_packet_vars[PacketField.REQUIRED_SOFTDEVICES_ARRAY] = sd_id

self.firmwares_data = {}

Expand All @@ -152,6 +155,9 @@ def __init__(self,
filename=app_fw,
init_packet_data=init_packet_vars)

if sd_req is not None:
init_packet_vars[PacketField.REQUIRED_SOFTDEVICES_ARRAY] = sd_req

if bootloader_fw:
self.__add_firmware_info(firmware_type=HexType.BOOTLOADER,
firmware_version=bl_version,
Expand Down
2 changes: 1 addition & 1 deletion nordicsemi/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@

""" Version definition for nrfutil. """

NRFUTIL_VERSION = "3.0.0"
NRFUTIL_VERSION = "3.1.0"

0 comments on commit ddc480e

Please sign in to comment.