Clone of official tools

Committer:
theotherjimmy
Date:
Tue Oct 10 16:56:30 2017 -0500
Revision:
40:7d3fa6b99b2b
Parent:
36:96847d42f010
Update to tools release 5.6.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 36:96847d42f010 1 """
The Other Jimmy 36:96847d42f010 2 @copyright (c) 2012 ON Semiconductor. All rights reserved.
The Other Jimmy 36:96847d42f010 3 ON Semiconductor is supplying this software for use with ON Semiconductor
The Other Jimmy 36:96847d42f010 4 processor based microcontrollers only.
The Other Jimmy 36:96847d42f010 5 THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
The Other Jimmy 36:96847d42f010 6 OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
The Other Jimmy 36:96847d42f010 7 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
The Other Jimmy 36:96847d42f010 8 ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
The Other Jimmy 36:96847d42f010 9 INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
The Other Jimmy 36:96847d42f010 10 """
The Other Jimmy 36:96847d42f010 11
The Other Jimmy 36:96847d42f010 12 from __future__ import absolute_import
The Other Jimmy 36:96847d42f010 13 from __future__ import print_function
The Other Jimmy 36:96847d42f010 14
The Other Jimmy 36:96847d42f010 15 import itertools
The Other Jimmy 36:96847d42f010 16 import binascii
The Other Jimmy 36:96847d42f010 17 import intelhex
The Other Jimmy 36:96847d42f010 18 from tools.config import Config
The Other Jimmy 36:96847d42f010 19
The Other Jimmy 36:96847d42f010 20 FIB_BASE = 0x2000
theotherjimmy 40:7d3fa6b99b2b 21 TRIM_BASE = 0x2800
The Other Jimmy 36:96847d42f010 22 FLASH_BASE = 0x3000
theotherjimmy 40:7d3fa6b99b2b 23 FLASHA_SIZE = 0x52000
theotherjimmy 40:7d3fa6b99b2b 24 FLASHB_BASE = 0x00102000
theotherjimmy 40:7d3fa6b99b2b 25 FLASHB_SIZE = 0x52000
The Other Jimmy 36:96847d42f010 26 FW_REV = 0x01000100
The Other Jimmy 36:96847d42f010 27
The Other Jimmy 36:96847d42f010 28 def ranges(i):
The Other Jimmy 36:96847d42f010 29 for _, b in itertools.groupby(enumerate(i), lambda x_y: x_y[1] - x_y[0]):
The Other Jimmy 36:96847d42f010 30 b = list(b)
The Other Jimmy 36:96847d42f010 31 yield b[0][1], b[-1][1]
The Other Jimmy 36:96847d42f010 32
The Other Jimmy 36:96847d42f010 33
The Other Jimmy 36:96847d42f010 34 def add_fib_at_start(arginput):
theotherjimmy 40:7d3fa6b99b2b 35 input_file = arginput + ".hex"
theotherjimmy 40:7d3fa6b99b2b 36 file_name_hex = arginput + ".hex"
The Other Jimmy 36:96847d42f010 37 file_name_bin = arginput + ".bin"
The Other Jimmy 36:96847d42f010 38
The Other Jimmy 36:96847d42f010 39 # Read in hex file
The Other Jimmy 36:96847d42f010 40 input_hex_file = intelhex.IntelHex()
theotherjimmy 40:7d3fa6b99b2b 41 input_hex_file.loadhex(input_file)
theotherjimmy 40:7d3fa6b99b2b 42 #set padding value to be returned when reading from unspecified address
theotherjimmy 40:7d3fa6b99b2b 43 input_hex_file.padding = 0xFF
theotherjimmy 40:7d3fa6b99b2b 44 # Create new hex file
The Other Jimmy 36:96847d42f010 45 output_hex_file = intelhex.IntelHex()
The Other Jimmy 36:96847d42f010 46
The Other Jimmy 36:96847d42f010 47 # Get the starting and ending address
The Other Jimmy 36:96847d42f010 48 addresses = input_hex_file.addresses()
The Other Jimmy 36:96847d42f010 49 addresses.sort()
The Other Jimmy 36:96847d42f010 50 start_end_pairs = list(ranges(addresses))
The Other Jimmy 36:96847d42f010 51 regions = len(start_end_pairs)
The Other Jimmy 36:96847d42f010 52
The Other Jimmy 36:96847d42f010 53 if regions == 1:
theotherjimmy 40:7d3fa6b99b2b 54 #single range indicating fits within first flash block (<320K)
The Other Jimmy 36:96847d42f010 55 start, end = start_end_pairs[0]
theotherjimmy 40:7d3fa6b99b2b 56 print("Memory start 0x%08X, end 0x%08X" % (start, end))
theotherjimmy 40:7d3fa6b99b2b 57 # Compute checksum over the range (don't include data at location of crc)
theotherjimmy 40:7d3fa6b99b2b 58 size = end - start + 1
theotherjimmy 40:7d3fa6b99b2b 59 data = input_hex_file.tobinarray(start=start, size=size)
theotherjimmy 40:7d3fa6b99b2b 60 crc32 = binascii.crc32(data) & 0xFFFFFFFF
The Other Jimmy 36:96847d42f010 61 else:
theotherjimmy 40:7d3fa6b99b2b 62 #multiple ranges indicating requires both flash blocks (>320K)
theotherjimmy 40:7d3fa6b99b2b 63 start, end = start_end_pairs[0]
theotherjimmy 40:7d3fa6b99b2b 64 start2, end2 = start_end_pairs[1]
theotherjimmy 40:7d3fa6b99b2b 65 print("Region 1: memory start 0x%08X, end 0x%08X" % (start, end))
theotherjimmy 40:7d3fa6b99b2b 66 print("Region 2: memory start 0x%08X, end 0x%08X" % (start2, end2))
theotherjimmy 40:7d3fa6b99b2b 67 # Compute checksum over the range (don't include data at location of crc)
theotherjimmy 40:7d3fa6b99b2b 68 # replace end with end of flash block A
theotherjimmy 40:7d3fa6b99b2b 69 end = FLASHA_SIZE - 1
theotherjimmy 40:7d3fa6b99b2b 70 size = end - start + 1
theotherjimmy 40:7d3fa6b99b2b 71 data = input_hex_file.tobinarray(start=start, size=size)
theotherjimmy 40:7d3fa6b99b2b 72
theotherjimmy 40:7d3fa6b99b2b 73 # replace start2 with base of flash block B
theotherjimmy 40:7d3fa6b99b2b 74 start2 = FLASHB_BASE
theotherjimmy 40:7d3fa6b99b2b 75 size2 = end2 - start2 + 1
theotherjimmy 40:7d3fa6b99b2b 76 data2 = input_hex_file.tobinarray(start=start2, size=size2)
theotherjimmy 40:7d3fa6b99b2b 77
theotherjimmy 40:7d3fa6b99b2b 78 #concatenate data and data2 arrays together
theotherjimmy 40:7d3fa6b99b2b 79 data.extend(data2)
theotherjimmy 40:7d3fa6b99b2b 80 crc32 = binascii.crc32(data) & 0xFFFFFFFF
theotherjimmy 40:7d3fa6b99b2b 81
theotherjimmy 40:7d3fa6b99b2b 82 #replace size with sum of two memory region sizes
theotherjimmy 40:7d3fa6b99b2b 83 size = size + size2
The Other Jimmy 36:96847d42f010 84
The Other Jimmy 36:96847d42f010 85 assert start >= FLASH_BASE, ("Error - start 0x%x less than begining of user\
The Other Jimmy 36:96847d42f010 86 flash area" %start)
theotherjimmy 40:7d3fa6b99b2b 87
theotherjimmy 40:7d3fa6b99b2b 88 assert regions <= 2, ("Error - more than 2 memory regions found")
The Other Jimmy 36:96847d42f010 89
The Other Jimmy 36:96847d42f010 90 fw_rev = FW_REV
The Other Jimmy 36:96847d42f010 91
The Other Jimmy 36:96847d42f010 92 checksum = (start + size + crc32 + fw_rev) & 0xFFFFFFFF
The Other Jimmy 36:96847d42f010 93
The Other Jimmy 36:96847d42f010 94 print("Writing FIB: base 0x%08X, size 0x%08X, crc32 0x%08X, fw rev 0x%08X,\
The Other Jimmy 36:96847d42f010 95 checksum 0x%08X" % (start, size, crc32, fw_rev, checksum))
The Other Jimmy 36:96847d42f010 96
The Other Jimmy 36:96847d42f010 97 #expected initial values used by daplink to validate that it is a valid bin
The Other Jimmy 36:96847d42f010 98 #file added as dummy values in this file because the fib area preceeds the
The Other Jimmy 36:96847d42f010 99 #application area the bootloader will ignore these dummy values
The Other Jimmy 36:96847d42f010 100 # 00 is stack pointer (RAM address)
The Other Jimmy 36:96847d42f010 101 # 04 is Reset vector (FLASH address)
The Other Jimmy 36:96847d42f010 102 # 08 NMI_Handler (FLASH address)
The Other Jimmy 36:96847d42f010 103 # 0C HardFault_Handler(FLASH address)
The Other Jimmy 36:96847d42f010 104 # 10 dummy
The Other Jimmy 36:96847d42f010 105 dummy_sp = 0x3FFFFC00
The Other Jimmy 36:96847d42f010 106 dummy_reset_vector = 0x00003625
The Other Jimmy 36:96847d42f010 107 dummy_nmi_handler = 0x00003761
The Other Jimmy 36:96847d42f010 108 dummy_hardfault_handler = 0x00003691
The Other Jimmy 36:96847d42f010 109 dummy_blank = 0x00000000
The Other Jimmy 36:96847d42f010 110
The Other Jimmy 36:96847d42f010 111 #expected fib structure
The Other Jimmy 36:96847d42f010 112 #typedef struct fib{
The Other Jimmy 36:96847d42f010 113 #uint32_t base; /**< Base offset of firmware, indicating what flash the
The Other Jimmy 36:96847d42f010 114 # firmware is in. (will never be 0x11111111) */
The Other Jimmy 36:96847d42f010 115 #uint32_t size; /**< Size of the firmware */
The Other Jimmy 36:96847d42f010 116 #uint32_t crc; /**< CRC32 for firmware correctness check */
The Other Jimmy 36:96847d42f010 117 #uint32_t rev; /**< Revision number */
The Other Jimmy 36:96847d42f010 118 #uint32_t checksum; /**< Check-sum of information block */
The Other Jimmy 36:96847d42f010 119 #}fib_t, *fib_pt;
The Other Jimmy 36:96847d42f010 120
The Other Jimmy 36:96847d42f010 121 fib_start = FIB_BASE
The Other Jimmy 36:96847d42f010 122 dummy_fib_size = 20
The Other Jimmy 36:96847d42f010 123 fib_size = 20
The Other Jimmy 36:96847d42f010 124 trim_size = 24
The Other Jimmy 36:96847d42f010 125 user_code_start = FLASH_BASE
The Other Jimmy 36:96847d42f010 126 trim_area_start = TRIM_BASE
The Other Jimmy 36:96847d42f010 127
The Other Jimmy 36:96847d42f010 128 # Write FIB to the file in little endian
The Other Jimmy 36:96847d42f010 129 output_hex_file[fib_start + 0] = (dummy_sp >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 130 output_hex_file[fib_start + 1] = (dummy_sp >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 131 output_hex_file[fib_start + 2] = (dummy_sp >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 132 output_hex_file[fib_start + 3] = (dummy_sp >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 133
The Other Jimmy 36:96847d42f010 134 output_hex_file[fib_start + 4] = (dummy_reset_vector >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 135 output_hex_file[fib_start + 5] = (dummy_reset_vector >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 136 output_hex_file[fib_start + 6] = (dummy_reset_vector >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 137 output_hex_file[fib_start + 7] = (dummy_reset_vector >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 138
The Other Jimmy 36:96847d42f010 139 output_hex_file[fib_start + 8] = (dummy_nmi_handler >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 140 output_hex_file[fib_start + 9] = (dummy_nmi_handler >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 141 output_hex_file[fib_start + 10] = (dummy_nmi_handler >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 142 output_hex_file[fib_start + 11] = (dummy_nmi_handler >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 143
The Other Jimmy 36:96847d42f010 144 output_hex_file[fib_start + 12] = (dummy_hardfault_handler >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 145 output_hex_file[fib_start + 13] = (dummy_hardfault_handler >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 146 output_hex_file[fib_start + 14] = (dummy_hardfault_handler >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 147 output_hex_file[fib_start + 15] = (dummy_hardfault_handler >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 148
The Other Jimmy 36:96847d42f010 149 output_hex_file[fib_start + 16] = (dummy_blank >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 150 output_hex_file[fib_start + 17] = (dummy_blank >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 151 output_hex_file[fib_start + 18] = (dummy_blank >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 152 output_hex_file[fib_start + 19] = (dummy_blank >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 153
The Other Jimmy 36:96847d42f010 154 # Write FIB to the file in little endian
The Other Jimmy 36:96847d42f010 155 output_hex_file[fib_start + 20] = (start >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 156 output_hex_file[fib_start + 21] = (start >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 157 output_hex_file[fib_start + 22] = (start >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 158 output_hex_file[fib_start + 23] = (start >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 159
The Other Jimmy 36:96847d42f010 160 output_hex_file[fib_start + 24] = (size >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 161 output_hex_file[fib_start + 25] = (size >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 162 output_hex_file[fib_start + 26] = (size >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 163 output_hex_file[fib_start + 27] = (size >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 164
The Other Jimmy 36:96847d42f010 165 output_hex_file[fib_start + 28] = (crc32 >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 166 output_hex_file[fib_start + 29] = (crc32 >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 167 output_hex_file[fib_start + 30] = (crc32 >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 168 output_hex_file[fib_start + 31] = (crc32 >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 169
The Other Jimmy 36:96847d42f010 170 output_hex_file[fib_start + 32] = (fw_rev >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 171 output_hex_file[fib_start + 33] = (fw_rev >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 172 output_hex_file[fib_start + 34] = (fw_rev >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 173 output_hex_file[fib_start + 35] = (fw_rev >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 174
The Other Jimmy 36:96847d42f010 175 output_hex_file[fib_start + 36] = (checksum >> 0) & 0xFF
The Other Jimmy 36:96847d42f010 176 output_hex_file[fib_start + 37] = (checksum >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 177 output_hex_file[fib_start + 38] = (checksum >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 178 output_hex_file[fib_start + 39] = (checksum >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 179
The Other Jimmy 36:96847d42f010 180 #pad the rest of the file
The Other Jimmy 36:96847d42f010 181 for i in range(fib_start + dummy_fib_size + fib_size, trim_area_start):
The Other Jimmy 36:96847d42f010 182 output_hex_file[i] = 0xFF
The Other Jimmy 36:96847d42f010 183
The Other Jimmy 36:96847d42f010 184 # Read in configuration data from the config parameter in targets.json
The Other Jimmy 36:96847d42f010 185 configData = Config('NCS36510')
The Other Jimmy 36:96847d42f010 186 paramData = configData.get_target_config_data()
The Other Jimmy 36:96847d42f010 187 for v in paramData.values():
The Other Jimmy 36:96847d42f010 188 if (v.name == "target.mac-addr-high"):
The Other Jimmy 36:96847d42f010 189 mac_addr_high = int(v.value, 16)
The Other Jimmy 36:96847d42f010 190 elif (v.name == "target.mac-addr-low"):
The Other Jimmy 36:96847d42f010 191 mac_addr_low = int(v.value,16)
The Other Jimmy 36:96847d42f010 192 elif (v.name == "target.32KHz-clk-trim"):
The Other Jimmy 36:96847d42f010 193 clk_32k_trim = int(v.value,16)
The Other Jimmy 36:96847d42f010 194 elif (v.name == "target.32MHz-clk-trim"):
The Other Jimmy 36:96847d42f010 195 clk_32m_trim = int(v.value,16)
The Other Jimmy 36:96847d42f010 196 elif (v.name == "target.rssi-trim"):
The Other Jimmy 36:96847d42f010 197 rssi = int(v.value,16)
The Other Jimmy 36:96847d42f010 198 elif (v.name == "target.txtune-trim"):
The Other Jimmy 36:96847d42f010 199 txtune = int(v.value,16)
The Other Jimmy 36:96847d42f010 200 else:
The Other Jimmy 36:96847d42f010 201 print("Not a valid param")
The Other Jimmy 36:96847d42f010 202
The Other Jimmy 36:96847d42f010 203 output_hex_file[trim_area_start + 0] = mac_addr_low & 0xFF
The Other Jimmy 36:96847d42f010 204 output_hex_file[trim_area_start + 1] = (mac_addr_low >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 205 output_hex_file[trim_area_start + 2] = (mac_addr_low >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 206 output_hex_file[trim_area_start + 3] = (mac_addr_low >> 24) & 0xFF
theotherjimmy 40:7d3fa6b99b2b 207
The Other Jimmy 36:96847d42f010 208 output_hex_file[trim_area_start + 4] = mac_addr_high & 0xFF
The Other Jimmy 36:96847d42f010 209 output_hex_file[trim_area_start + 5] = (mac_addr_high >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 210 output_hex_file[trim_area_start + 6] = (mac_addr_high >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 211 output_hex_file[trim_area_start + 7] = (mac_addr_high >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 212
The Other Jimmy 36:96847d42f010 213 output_hex_file[trim_area_start + 8] = clk_32k_trim & 0xFF
The Other Jimmy 36:96847d42f010 214 output_hex_file[trim_area_start + 9] = (clk_32k_trim >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 215 output_hex_file[trim_area_start + 10] = (clk_32k_trim >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 216 output_hex_file[trim_area_start + 11] = (clk_32k_trim >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 217
The Other Jimmy 36:96847d42f010 218 output_hex_file[trim_area_start + 12] = clk_32m_trim & 0xFF
The Other Jimmy 36:96847d42f010 219 output_hex_file[trim_area_start + 13] = (clk_32m_trim >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 220 output_hex_file[trim_area_start + 14] = (clk_32m_trim >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 221 output_hex_file[trim_area_start + 15] = (clk_32m_trim >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 222
The Other Jimmy 36:96847d42f010 223 output_hex_file[trim_area_start + 16] = rssi & 0xFF
The Other Jimmy 36:96847d42f010 224 output_hex_file[trim_area_start + 17] = (rssi >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 225 output_hex_file[trim_area_start + 18] = (rssi >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 226 output_hex_file[trim_area_start + 19] = (rssi >> 24) & 0xFF
The Other Jimmy 36:96847d42f010 227
The Other Jimmy 36:96847d42f010 228 output_hex_file[trim_area_start + 20] = txtune & 0xFF
The Other Jimmy 36:96847d42f010 229 output_hex_file[trim_area_start + 21] = (txtune >> 8) & 0xFF
The Other Jimmy 36:96847d42f010 230 output_hex_file[trim_area_start + 22] = (txtune >> 16) & 0xFF
The Other Jimmy 36:96847d42f010 231 output_hex_file[trim_area_start + 23] = (txtune >> 24) & 0xFF
theotherjimmy 40:7d3fa6b99b2b 232
The Other Jimmy 36:96847d42f010 233 # pad the rest of the area with 0xFF
The Other Jimmy 36:96847d42f010 234 for i in range(trim_area_start + trim_size, user_code_start):
The Other Jimmy 36:96847d42f010 235 output_hex_file[i] = 0xFF
The Other Jimmy 36:96847d42f010 236
The Other Jimmy 36:96847d42f010 237 #merge two hex files
The Other Jimmy 36:96847d42f010 238 output_hex_file.merge(input_hex_file, overlap='error')
The Other Jimmy 36:96847d42f010 239
The Other Jimmy 36:96847d42f010 240 # Write out file(s)
The Other Jimmy 36:96847d42f010 241 output_hex_file.tofile(file_name_hex, 'hex')