Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
tools/generate_config.py@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | # |
Pawel Zarembski |
0:01f31e923fe2 | 2 | # DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 3 | # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 4 | # SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | # |
Pawel Zarembski |
0:01f31e923fe2 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | # not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | # You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | # |
Pawel Zarembski |
0:01f31e923fe2 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | # |
Pawel Zarembski |
0:01f31e923fe2 | 12 | # Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | # See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | # limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | # |
Pawel Zarembski |
0:01f31e923fe2 | 18 | |
Pawel Zarembski |
0:01f31e923fe2 | 19 | import struct |
Pawel Zarembski |
0:01f31e923fe2 | 20 | import argparse |
Pawel Zarembski |
0:01f31e923fe2 | 21 | from intelhex import IntelHex |
Pawel Zarembski |
0:01f31e923fe2 | 22 | |
Pawel Zarembski |
0:01f31e923fe2 | 23 | CFG_KEY = 0x6b766c64 |
Pawel Zarembski |
0:01f31e923fe2 | 24 | # Must stay in sync with the structure cfg_setting |
Pawel Zarembski |
0:01f31e923fe2 | 25 | # in the header file config_settings.h: |
Pawel Zarembski |
0:01f31e923fe2 | 26 | # 32 - key |
Pawel Zarembski |
0:01f31e923fe2 | 27 | # 16 - offset_of_end |
Pawel Zarembski |
0:01f31e923fe2 | 28 | # 8 - auto_rst |
Pawel Zarembski |
0:01f31e923fe2 | 29 | # 8 - automation_allowed |
Pawel Zarembski |
0:01f31e923fe2 | 30 | # 8 - overflow_detect |
Pawel Zarembski |
0:01f31e923fe2 | 31 | # 0 - 'end' member omitted |
Pawel Zarembski |
0:01f31e923fe2 | 32 | FORMAT = '<LHBBB' |
Pawel Zarembski |
0:01f31e923fe2 | 33 | FORMAT_LENGTH = struct.calcsize(FORMAT) |
Pawel Zarembski |
0:01f31e923fe2 | 34 | MINIMUM_ALIGN = 1 << 10 # 1k aligned |
Pawel Zarembski |
0:01f31e923fe2 | 35 | |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | def create_hex(filename, addr, auto_rst, automation_allowed, |
Pawel Zarembski |
0:01f31e923fe2 | 38 | overflow_detect, pad_size): |
Pawel Zarembski |
0:01f31e923fe2 | 39 | file_format = 'hex' |
Pawel Zarembski |
0:01f31e923fe2 | 40 | intel_hex = IntelHex() |
Pawel Zarembski |
0:01f31e923fe2 | 41 | intel_hex.puts(addr, struct.pack(FORMAT, CFG_KEY, FORMAT_LENGTH, auto_rst, |
Pawel Zarembski |
0:01f31e923fe2 | 42 | automation_allowed, overflow_detect)) |
Pawel Zarembski |
0:01f31e923fe2 | 43 | pad_addr = addr + FORMAT_LENGTH |
Pawel Zarembski |
0:01f31e923fe2 | 44 | pad_byte_count = pad_size - (FORMAT_LENGTH % pad_size) |
Pawel Zarembski |
0:01f31e923fe2 | 45 | pad_data = '\xFF' * pad_byte_count |
Pawel Zarembski |
0:01f31e923fe2 | 46 | intel_hex.puts(pad_addr, pad_data) |
Pawel Zarembski |
0:01f31e923fe2 | 47 | with open(filename, 'wb') as f: |
Pawel Zarembski |
0:01f31e923fe2 | 48 | intel_hex.tofile(f, file_format) |
Pawel Zarembski |
0:01f31e923fe2 | 49 | |
Pawel Zarembski |
0:01f31e923fe2 | 50 | |
Pawel Zarembski |
0:01f31e923fe2 | 51 | def str_to_int(val): |
Pawel Zarembski |
0:01f31e923fe2 | 52 | return int(val, 0) |
Pawel Zarembski |
0:01f31e923fe2 | 53 | |
Pawel Zarembski |
0:01f31e923fe2 | 54 | |
Pawel Zarembski |
0:01f31e923fe2 | 55 | POWERS_OF_TWO = [2**num for num in range(0, 32)] |
Pawel Zarembski |
0:01f31e923fe2 | 56 | parser = argparse.ArgumentParser(description='Configuration Creator') |
Pawel Zarembski |
0:01f31e923fe2 | 57 | parser.add_argument("--addr", type=str_to_int, required=True, help="Address of configuration data") |
Pawel Zarembski |
0:01f31e923fe2 | 58 | parser.add_argument("--auto_rst", type=int, required=True, choices=[0, 1], help="Auto reset configuration value") |
Pawel Zarembski |
0:01f31e923fe2 | 59 | parser.add_argument("--automation_allowed", type=int, required=True, choices=[0,1], help="Allow automation from filesystem interaction") |
Pawel Zarembski |
0:01f31e923fe2 | 60 | parser.add_argument("--overflow_detect", type=int, required=True, choices=[0,1], help="Enable detection of UART overflow") |
Pawel Zarembski |
0:01f31e923fe2 | 61 | parser.add_argument("--pad", type=int, default=16, choices=POWERS_OF_TWO, metavar="{1, 2, 4,...}", help="Byte aligned boundary to pad region to") |
Pawel Zarembski |
0:01f31e923fe2 | 62 | parser.add_argument("--output_file", type=str, default='settings.hex', help="Name of output file") |
Pawel Zarembski |
0:01f31e923fe2 | 63 | |
Pawel Zarembski |
0:01f31e923fe2 | 64 | |
Pawel Zarembski |
0:01f31e923fe2 | 65 | def main(): |
Pawel Zarembski |
0:01f31e923fe2 | 66 | args = parser.parse_args() |
Pawel Zarembski |
0:01f31e923fe2 | 67 | print "Output file %s" % args.output_file |
Pawel Zarembski |
0:01f31e923fe2 | 68 | print "Config Offset 0x%x" % args.addr |
Pawel Zarembski |
0:01f31e923fe2 | 69 | if args.addr % MINIMUM_ALIGN != 0: |
Pawel Zarembski |
0:01f31e923fe2 | 70 | print "WARNING! Configuration is not on a 1K boundary" |
Pawel Zarembski |
0:01f31e923fe2 | 71 | if args.addr % args.pad != 0: |
Pawel Zarembski |
0:01f31e923fe2 | 72 | print "WARNING! Configuration is not aligned to pad size" |
Pawel Zarembski |
0:01f31e923fe2 | 73 | print "Settings:" |
Pawel Zarembski |
0:01f31e923fe2 | 74 | print " auto_rst: %i" % args.auto_rst |
Pawel Zarembski |
0:01f31e923fe2 | 75 | print " automation_allowed: %i" % args.automation_allowed |
Pawel Zarembski |
0:01f31e923fe2 | 76 | print " overflow_detect: %i" % args.overflow_detect |
Pawel Zarembski |
0:01f31e923fe2 | 77 | print "" |
Pawel Zarembski |
0:01f31e923fe2 | 78 | create_hex(args.output_file, args.addr, args.auto_rst, |
Pawel Zarembski |
0:01f31e923fe2 | 79 | args.automation_allowed, args.overflow_detect, args.pad) |
Pawel Zarembski |
0:01f31e923fe2 | 80 | |
Pawel Zarembski |
0:01f31e923fe2 | 81 | if __name__ == '__main__': |
Pawel Zarembski |
0:01f31e923fe2 | 82 | main() |