Skip to content

Commit

Permalink
Merge pull request #11 from rigado/release/v3.0.1
Browse files Browse the repository at this point in the history
Commit updated files for release
  • Loading branch information
estutzenberger authored Jun 16, 2017
2 parents a898d69 + 6ba481b commit e1f69e5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 21 deletions.
57 changes: 57 additions & 0 deletions image-tools/genimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Rigado DFU Image Generation Tool
================================

This tool is used to translate build output files (Intel HEX or binary formats) into
firmware update files that can then be tranferred over-the-air or via serial.

## Requirements

This tool requires Python 3.x.

## Script Usage

```
usage: genimage.py [-h] [--hexfile HEXFILE [HEXFILE ...]] [--output BIN]
[--quiet] [-f FAMILY] [--softdevice] [--bootloader]
[--application] [--softdevice-addr LOW-HIGH]
[--bootloader-addr LOW-HIGH] [--application-addr LOW-HIGH]
Generate images for RigDFU bootloader
optional arguments:
-h, --help show this help message and exit
--hexfile HEXFILE [HEXFILE ...]
Hex file(s) to load
--output BIN, -o BIN Output file
--quiet, -q Print less output
-f FAMILY, --family FAMILY
Configuration file: config/nrf52832-sd132v2.0.1.cfg
config/nrf52832-sd132v3.x.0.cfg
Images to include:
If none are specified, images are determined automatically based on the
hex file contents.
--softdevice, -s Include softdevice
--bootloader, -b Include bootloader
--application, -a Include application
Image locations in the HEX files:
If unspecified, locations are guessed heuristically. Format is LOW-HIGH,
for example 0x1000-0x16000 and 0x16000-0x3b000.
--softdevice-addr LOW-HIGH, -S LOW-HIGH
Softdevice location
--bootloader-addr LOW-HIGH, -B LOW-HIGH
Bootloader location
--application-addr LOW-HIGH, -A LOW-HIGH
Application location
```

## Notes

* At least `--family (-f)`, '--output (-o)', and `--hexfile` must be specified.

* `genimage.py` will, in most cases, figure out the addresses as necessary provided the memory map as
specified in the Rigado Bootloader documentation is used. This means that generally, `-s`, `-b`, and
`-a` are not required.
12 changes: 6 additions & 6 deletions image-tools/genimage/genimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

'''
Tool to build RigDfu firmware images from hex files
@copyright (c) Rigado, LLC. All rights reserved.
Source code licensed under BMD-200 Software License Agreement.
You should have received a copy with purchase of BMD-200 product.
If not, contact info@rigado.com for for a copy.
Source code licensed under BMD Software License Agreement.
You should have received a copy with purchase of Rigado product.
If not, contact info@rigado.com for for a copy.
'''

import sys
Expand Down Expand Up @@ -44,11 +44,11 @@ def get_all_config_files(directory):

#iterate over list of all files
for file in all_files:

#if this file matches the pattern .cfg
if fnmatch.fnmatch(file, '*.cfg'):
#split the path into the last section (short_file), and everything else (head)
head, short_file = os.path.split(file)
head, short_file = os.path.split(file)

short_file = "{0}{1}".format(directory, short_file)
#add the file to the list of config files
Expand Down
Binary file modified image-tools/signimage/signimage-w32.exe
Binary file not shown.
Binary file modified image-tools/signimage/signimage-w64.exe
Binary file not shown.
15 changes: 9 additions & 6 deletions programming/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def get_all_config_files(directory):

#iterate over list of all files
for file in all_files:

#if this file matches the pattern .cfg
if fnmatch.fnmatch(file, '*.cfg'):
#split the path into the last section (short_file), and everything else (head)
head, short_file = os.path.split(file)
head, short_file = os.path.split(file)

short_file = "{0}{1}".format(directory, short_file)
#add the file to the list of config files
Expand All @@ -67,7 +67,12 @@ def get_config_files_string(directory):

return prompt_string

def key_is_empty(key):
if key == '00000000000000000000000000000000' or \
key == 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF':
return True

return False

####################
#script entry point#
Expand Down Expand Up @@ -150,9 +155,7 @@ def get_config_files_string(directory):
elif readback_protection == False and args.disablereadback == True:
utils.log(utils.LOG_LEVEL_INFO, 'Warning: Readback protection already disabled by default. You can drop -r')

if args.enablereadback or \
(args.key != '00000000000000000000000000000000' and \
args.key != 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'):
if args.enablereadback or not key_is_empty(args.key):
readback_protection = True

if args.disablereadback:
Expand Down Expand Up @@ -286,7 +289,7 @@ def get_config_files_string(directory):
jlink.cleanup()

if cfg.device.family == 'nrf51' or cfg.device.family == 'nrf52':
if readback_protection:
if readback_protection and key_is_empty(args.key):
nrfjprog.protect(device)
nrfjprog.reset(device)

Expand Down
2 changes: 1 addition & 1 deletion update-tools/ble/dfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ commander.

// Parse MAC address
if (commander.mac) {
mac_address = parse_hex_string(commander.mac, 6);
mac_address = validate_hex_string(commander.mac, 6);
printf("Target address: " + mac_address);
}

Expand Down
61 changes: 53 additions & 8 deletions update-tools/serial/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,63 @@ def activateNresetDFU(serialPort):
InitPkt = namedtuple('InitPkt', 'iv tag')
PatchInitPkt = namedtuple('PatchInitPkt', 'len crc oldcrc')

def extractBytes(buffer, start, end=None):
result = None

if end == None:
print("{0} - end".format(start))
result = buffer[start:]
else:
print("{0} - {1}".format(start, end))
result = buffer[start:end]
return result

def has_patch_key(byte_array):

patch_key = [0xac, 0xb3, 0x37, 0xe8, 0xd0, 0xeb, 0x40, 0x90,
0xa4, 0xf3, 0xbb, 0x85, 0x7a, 0x5b, 0x2a, 0xf6]
byte_array_list = list(byte_array)

result = False

if patch_key == byte_array_list:
result = True

return result

patch_key_size = 16
start_packet_size = 12
init_packet_size = 32
patch_init_packet_size = 12

#unpack
try:

#raw binary
if(args.patch):
startBin = bindata[:12]
initBin = bindata[12:44]
patchInitBin= bindata[44:56]
imageBin = bindata[56:]
if args.patch == True or has_patch_key(bindata[:patch_key_size]):

patch_key_start = 0
start_packet_start = patch_key_start + patch_key_size
init_packet_start = start_packet_start + start_packet_size
patch_init_packet_start = init_packet_start + init_packet_size
image_bin_start = patch_init_packet_start + patch_init_packet_size

patchKeyBin = bindata[patch_key_start:start_packet_start]
startBin = bindata[start_packet_start:init_packet_start]
initBin = bindata[init_packet_start:patch_init_packet_start]
patchInitBin = bindata[patch_init_packet_start:image_bin_start]
imageBin = bindata[image_bin_start:]

args.patch = True

else:
startBin = bindata[:12]
initBin = bindata[12:44]
imageBin = bindata[44:]
start_packet_start = 0
init_packet_start = start_packet_start + start_packet_size
image_bin_start = init_packet_start + init_packet_size

startBin = bindata[start_packet_start:init_packet_start]
initBin = bindata[init_packet_start:image_bin_start]
imageBin = bindata[image_bin_start:]

#parse to struct
startPkt = StartPkt._make(unpack('<LLL', startBin))
Expand Down

0 comments on commit e1f69e5

Please sign in to comment.