Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
tools/offset_update.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 | from __future__ import absolute_import |
Pawel Zarembski |
0:01f31e923fe2 | 20 | |
Pawel Zarembski |
0:01f31e923fe2 | 21 | from builtins import bytes |
Pawel Zarembski |
0:01f31e923fe2 | 22 | |
Pawel Zarembski |
0:01f31e923fe2 | 23 | import argparse |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | |
Pawel Zarembski |
0:01f31e923fe2 | 26 | def dec_or_hex(val): |
Pawel Zarembski |
0:01f31e923fe2 | 27 | return int(val, 0) |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | |
Pawel Zarembski |
0:01f31e923fe2 | 30 | def create_padded_image(input_file, output_file, start, |
Pawel Zarembski |
0:01f31e923fe2 | 31 | pad_start, copy_size): |
Pawel Zarembski |
0:01f31e923fe2 | 32 | pad_size = start - pad_start |
Pawel Zarembski |
0:01f31e923fe2 | 33 | with open(input_file, 'rb') as file_handle: |
Pawel Zarembski |
0:01f31e923fe2 | 34 | data = file_handle.read() |
Pawel Zarembski |
0:01f31e923fe2 | 35 | output_data = data[0:copy_size] + bytes([0xff] * (pad_size - copy_size)) + data |
Pawel Zarembski |
0:01f31e923fe2 | 36 | with open(output_file, 'wb') as file_handle: |
Pawel Zarembski |
0:01f31e923fe2 | 37 | data = file_handle.write(output_data) |
Pawel Zarembski |
0:01f31e923fe2 | 38 | |
Pawel Zarembski |
0:01f31e923fe2 | 39 | |
Pawel Zarembski |
0:01f31e923fe2 | 40 | def main(): |
Pawel Zarembski |
0:01f31e923fe2 | 41 | parser = argparse.ArgumentParser(description='File Padder') |
Pawel Zarembski |
0:01f31e923fe2 | 42 | parser.add_argument("bin", type=str, default=None, |
Pawel Zarembski |
0:01f31e923fe2 | 43 | help="Input binary file") |
Pawel Zarembski |
0:01f31e923fe2 | 44 | parser.add_argument("--start", type=dec_or_hex, default=0x8000, |
Pawel Zarembski |
0:01f31e923fe2 | 45 | help="Starting address of input binary file") |
Pawel Zarembski |
0:01f31e923fe2 | 46 | parser.add_argument("--padded_start", type=dec_or_hex, default=0x5000, |
Pawel Zarembski |
0:01f31e923fe2 | 47 | help="Starting address after padding.") |
Pawel Zarembski |
0:01f31e923fe2 | 48 | parser.add_argument("--output", type=str, required=True, |
Pawel Zarembski |
0:01f31e923fe2 | 49 | help="Output file") |
Pawel Zarembski |
0:01f31e923fe2 | 50 | parser.add_argument("--copysize", type=str, default=0x40, |
Pawel Zarembski |
0:01f31e923fe2 | 51 | help="Size of original binary to copy") |
Pawel Zarembski |
0:01f31e923fe2 | 52 | args = parser.parse_args() |
Pawel Zarembski |
0:01f31e923fe2 | 53 | |
Pawel Zarembski |
0:01f31e923fe2 | 54 | # Data is appened to front so padded start must be less than start |
Pawel Zarembski |
0:01f31e923fe2 | 55 | assert args.start > args.padded_start |
Pawel Zarembski |
0:01f31e923fe2 | 56 | create_padded_image(args.bin, args.output, args.start, |
Pawel Zarembski |
0:01f31e923fe2 | 57 | args.padded_start, args.copysize) |
Pawel Zarembski |
0:01f31e923fe2 | 58 | |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | if __name__ == "__main__": |
Pawel Zarembski |
0:01f31e923fe2 | 61 | main() |