diff --git a/image-tools/genimage/README.md b/image-tools/genimage/README.md new file mode 100644 index 0000000..c6b5a59 --- /dev/null +++ b/image-tools/genimage/README.md @@ -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. diff --git a/image-tools/genimage/genimage.py b/image-tools/genimage/genimage.py index 5d12852..cf643ba 100644 --- a/image-tools/genimage/genimage.py +++ b/image-tools/genimage/genimage.py @@ -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 @@ -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 diff --git a/image-tools/signimage/signimage-w32.exe b/image-tools/signimage/signimage-w32.exe index 89ffa10..6ce9fb2 100755 Binary files a/image-tools/signimage/signimage-w32.exe and b/image-tools/signimage/signimage-w32.exe differ diff --git a/image-tools/signimage/signimage-w64.exe b/image-tools/signimage/signimage-w64.exe index c8d4f58..9255ffb 100755 Binary files a/image-tools/signimage/signimage-w64.exe and b/image-tools/signimage/signimage-w64.exe differ diff --git a/programming/program.py b/programming/program.py index 291380f..5d52a52 100644 --- a/programming/program.py +++ b/programming/program.py @@ -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 @@ -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# @@ -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: @@ -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) diff --git a/update-tools/ble/dfu.js b/update-tools/ble/dfu.js index 7fb33ad..de63248 100644 --- a/update-tools/ble/dfu.js +++ b/update-tools/ble/dfu.js @@ -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); } diff --git a/update-tools/serial/dfu.py b/update-tools/serial/dfu.py index 0ce8992..5a67cfe 100644 --- a/update-tools/serial/dfu.py +++ b/update-tools/serial/dfu.py @@ -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('