MCPcopy Create free account
hub / github.com/ARMmbed/DAPLink / post_build_script

Function post_build_script

tools/post_build_script.py:44–251  ·  view source on GitHub ↗
(input_file, output_file, board_id=None, family_id=None, bin_offset=None, flash_algo_file=None, target_ram_start=None, target_ram_end=None, flash_blob_entry="0x20000000")

Source from the content-addressed store, hash-verified

42 yield b[0][1], b[-1][1]
43
44def post_build_script(input_file, output_file, board_id=None, family_id=None, bin_offset=None, flash_algo_file=None, target_ram_start=None, target_ram_end=None, flash_blob_entry="0x20000000"):
45 output_format_file = '-'.join(filter(None, (output_file, board_id, family_id, bin_offset)))
46 print(output_format_file)
47 output_file_hex = output_format_file + ".hex"
48 output_file_binary = output_format_file + ".bin"
49 output_file_txt = output_format_file + ".txt"
50 output_file_c = output_format_file + ".c"
51 output_file_c_generic = join(dirname(output_file), "bootloader_image.c")
52 output_file_legacy = output_format_file + "_legacy_0x8000.bin"
53 output_file_legacy_5000 = output_format_file + "_legacy_0x5000.bin"
54 output_file_legacy_txt = output_format_file + "_legacy.txt"
55
56 # Read in hex file
57 new_hex_file = intelhex.IntelHex()
58 new_hex_file.padding = 0xFF
59
60 if input_file.lower().endswith('.bin'):
61 if bin_offset is not None:
62 new_hex_file.loadbin(input_file, offset=int(bin_offset, 16))
63 else:
64 new_hex_file.loadbin(input_file)
65 else: #always assume hex format
66 new_hex_file.fromfile(input_file, format='hex')
67
68
69 # Get the starting and ending address
70 addresses = new_hex_file.addresses()
71 addresses.sort()
72 start_end_pairs = list(ranges(addresses))
73 regions = len(start_end_pairs)
74 if regions > 1:
75 print("Error - only 1 region allowed in hex file %i found." % regions)
76 print("Regions:")
77 for i, se in enumerate(start_end_pairs):
78 s, e = se
79 print(" %d: 0x%08x - 0x%08x" % (i, s, e))
80 exit(1)
81 start, end = start_end_pairs[0]
82
83 pack_flash_algo = None
84 if flash_algo_file is not None:
85 with open(flash_algo_file, "rb") as file_handle:
86 pack_flash_algo = PackFlashAlgo(file_handle.read())
87
88 # Checksum the vector table
89 #
90 # Note this is only required for NXP devices but
91 # it doesn't hurt to checksum all builds
92
93 # Compute a checksum on the first 7 vector nvic vectors
94 vector_size = struct.calcsize(VECTOR_FMT)
95 vector_data = new_hex_file.tobinarray(start=start, size=vector_size)
96 vectors = struct.unpack(VECTOR_FMT, vector_data)
97 assert len(vectors) == 7, "Incorrect size of %i" % len(vectors)
98 checksum = 0
99 for vector in vectors:
100 checksum += vector
101 checksum = (~checksum + 1) & 0xFFFFFFFF # Two's compliment

Callers 6

progen_compile.pyFile · 0.90
mainFunction · 0.90

Calls 5

PackFlashAlgoClass · 0.90
rangesFunction · 0.70
readMethod · 0.45
packMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected