Clone of official tools
Diff: targets/NCS.py
- Revision:
- 40:7d3fa6b99b2b
- Parent:
- 36:96847d42f010
--- a/targets/NCS.py Wed Jul 19 16:44:30 2017 -0500 +++ b/targets/NCS.py Tue Oct 10 16:56:30 2017 -0500 @@ -18,9 +18,12 @@ from tools.config import Config FIB_BASE = 0x2000 +TRIM_BASE = 0x2800 FLASH_BASE = 0x3000 +FLASHA_SIZE = 0x52000 +FLASHB_BASE = 0x00102000 +FLASHB_SIZE = 0x52000 FW_REV = 0x01000100 -TRIM_BASE = 0x2800 def ranges(i): for _, b in itertools.groupby(enumerate(i), lambda x_y: x_y[1] - x_y[0]): @@ -29,17 +32,17 @@ def add_fib_at_start(arginput): - input_file = arginput + ".bin" - file_name_hex = arginput + "_fib.hex" + input_file = arginput + ".hex" + file_name_hex = arginput + ".hex" file_name_bin = arginput + ".bin" # Read in hex file input_hex_file = intelhex.IntelHex() - input_hex_file.padding = 0x00 - input_hex_file.loadbin(input_file, offset=FLASH_BASE) - + input_hex_file.loadhex(input_file) + #set padding value to be returned when reading from unspecified address + input_hex_file.padding = 0xFF + # Create new hex file output_hex_file = intelhex.IntelHex() - output_hex_file.padding = 0x00 # Get the starting and ending address addresses = input_hex_file.addresses() @@ -48,17 +51,41 @@ regions = len(start_end_pairs) if regions == 1: + #single range indicating fits within first flash block (<320K) start, end = start_end_pairs[0] + print("Memory start 0x%08X, end 0x%08X" % (start, end)) + # Compute checksum over the range (don't include data at location of crc) + size = end - start + 1 + data = input_hex_file.tobinarray(start=start, size=size) + crc32 = binascii.crc32(data) & 0xFFFFFFFF else: - start = min(min(start_end_pairs)) - end = max(max(start_end_pairs)) + #multiple ranges indicating requires both flash blocks (>320K) + start, end = start_end_pairs[0] + start2, end2 = start_end_pairs[1] + print("Region 1: memory start 0x%08X, end 0x%08X" % (start, end)) + print("Region 2: memory start 0x%08X, end 0x%08X" % (start2, end2)) + # Compute checksum over the range (don't include data at location of crc) + # replace end with end of flash block A + end = FLASHA_SIZE - 1 + size = end - start + 1 + data = input_hex_file.tobinarray(start=start, size=size) + + # replace start2 with base of flash block B + start2 = FLASHB_BASE + size2 = end2 - start2 + 1 + data2 = input_hex_file.tobinarray(start=start2, size=size2) + + #concatenate data and data2 arrays together + data.extend(data2) + crc32 = binascii.crc32(data) & 0xFFFFFFFF + + #replace size with sum of two memory region sizes + size = size + size2 assert start >= FLASH_BASE, ("Error - start 0x%x less than begining of user\ flash area" %start) - # Compute checksum over the range (don't include data at location of crc) - size = end - start + 1 - data = input_hex_file.tobinarray(start=start, size=size) - crc32 = binascii.crc32(data) & 0xFFFFFFFF + + assert regions <= 2, ("Error - more than 2 memory regions found") fw_rev = FW_REV @@ -177,7 +204,7 @@ output_hex_file[trim_area_start + 1] = (mac_addr_low >> 8) & 0xFF output_hex_file[trim_area_start + 2] = (mac_addr_low >> 16) & 0xFF output_hex_file[trim_area_start + 3] = (mac_addr_low >> 24) & 0xFF - + output_hex_file[trim_area_start + 4] = mac_addr_high & 0xFF output_hex_file[trim_area_start + 5] = (mac_addr_high >> 8) & 0xFF output_hex_file[trim_area_start + 6] = (mac_addr_high >> 16) & 0xFF @@ -202,7 +229,7 @@ output_hex_file[trim_area_start + 21] = (txtune >> 8) & 0xFF output_hex_file[trim_area_start + 22] = (txtune >> 16) & 0xFF output_hex_file[trim_area_start + 23] = (txtune >> 24) & 0xFF - + # pad the rest of the area with 0xFF for i in range(trim_area_start + trim_size, user_code_start): output_hex_file[i] = 0xFF @@ -212,4 +239,3 @@ # Write out file(s) output_hex_file.tofile(file_name_hex, 'hex') - output_hex_file.tofile(file_name_bin, 'bin')