Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers offset_update.py Source File

offset_update.py

00001 #
00002 # DAPLink Interface Firmware
00003 # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
00004 # SPDX-License-Identifier: Apache-2.0
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License"); you may
00007 # not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 # http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00014 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 #
00018 
00019 from __future__ import absolute_import
00020 
00021 from builtins import bytes
00022 
00023 import argparse
00024 
00025 
00026 def dec_or_hex(val):
00027     return int(val, 0)
00028 
00029 
00030 def create_padded_image(input_file, output_file, start,
00031                         pad_start, copy_size):
00032     pad_size = start - pad_start
00033     with open(input_file, 'rb') as file_handle:
00034         data = file_handle.read()
00035     output_data = data[0:copy_size] + bytes([0xff] * (pad_size - copy_size)) + data
00036     with open(output_file, 'wb') as file_handle:
00037         data = file_handle.write(output_data)
00038 
00039 
00040 def main():
00041     parser = argparse.ArgumentParser(description='File Padder')
00042     parser.add_argument("bin", type=str, default=None,
00043                         help="Input binary file")
00044     parser.add_argument("--start", type=dec_or_hex, default=0x8000,
00045                         help="Starting address of input binary file")
00046     parser.add_argument("--padded_start", type=dec_or_hex, default=0x5000,
00047                         help="Starting address after padding.")
00048     parser.add_argument("--output", type=str, required=True,
00049                         help="Output file")
00050     parser.add_argument("--copysize", type=str, default=0x40,
00051                         help="Size of original binary to copy")
00052     args = parser.parse_args()
00053 
00054     # Data is appened to front so padded start must be less than start
00055     assert args.start > args.padded_start
00056     create_padded_image(args.bin, args.output, args.start,
00057                         args.padded_start, args.copysize)
00058 
00059 
00060 if __name__ == "__main__":
00061     main()