Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

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?

UserRevisionLine numberNew 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 """
Pawel Zarembski 0:01f31e923fe2 20
Pawel Zarembski 0:01f31e923fe2 21 Usage example:
Pawel Zarembski 0:01f31e923fe2 22
Pawel Zarembski 0:01f31e923fe2 23 python mbedapi.py --repo http://developer.mbed.org/users/dan/code/pubtest/
Pawel Zarembski 0:01f31e923fe2 24 --user dan --api http://developer.mbed.org --platform mbed-LPC1768
Pawel Zarembski 0:01f31e923fe2 25 --destdir /tmp/ --debug 2
Pawel Zarembski 0:01f31e923fe2 26
Pawel Zarembski 0:01f31e923fe2 27 This will compile http://developer.mbed.org/users/dan/code/pubtest/
Pawel Zarembski 0:01f31e923fe2 28 for the 1768 and download the result.
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30 Examples of options:
Pawel Zarembski 0:01f31e923fe2 31 --extra_symbols "foo=bar,x=y"
Pawel Zarembski 0:01f31e923fe2 32
Pawel Zarembski 0:01f31e923fe2 33 --replace_file "main.cpp:/tmp/replace_main.cpp"
Pawel Zarembski 0:01f31e923fe2 34 (can be repeated)
Pawel Zarembski 0:01f31e923fe2 35
Pawel Zarembski 0:01f31e923fe2 36 """
Pawel Zarembski 0:01f31e923fe2 37 import os
Pawel Zarembski 0:01f31e923fe2 38 import getpass
Pawel Zarembski 0:01f31e923fe2 39 import json
Pawel Zarembski 0:01f31e923fe2 40 import time
Pawel Zarembski 0:01f31e923fe2 41 import requests
Pawel Zarembski 0:01f31e923fe2 42 import logging
Pawel Zarembski 0:01f31e923fe2 43
Pawel Zarembski 0:01f31e923fe2 44 MBED_API_SERVER = 'https://os.mbed.com/'
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46
Pawel Zarembski 0:01f31e923fe2 47 def build_repo(user, password, repo, platform, destdir,
Pawel Zarembski 0:01f31e923fe2 48 replace='', symbols='', clean=False, api=MBED_API_SERVER):
Pawel Zarembski 0:01f31e923fe2 49
Pawel Zarembski 0:01f31e923fe2 50 payload = {
Pawel Zarembski 0:01f31e923fe2 51 'clean': clean,
Pawel Zarembski 0:01f31e923fe2 52 'platform': platform,
Pawel Zarembski 0:01f31e923fe2 53 'repo': repo,
Pawel Zarembski 0:01f31e923fe2 54 'extra_symbols': symbols
Pawel Zarembski 0:01f31e923fe2 55 }
Pawel Zarembski 0:01f31e923fe2 56
Pawel Zarembski 0:01f31e923fe2 57 if replace:
Pawel Zarembski 0:01f31e923fe2 58 replace = []
Pawel Zarembski 0:01f31e923fe2 59 for pair in replace:
Pawel Zarembski 0:01f31e923fe2 60 dest = pair.split(':')[0]
Pawel Zarembski 0:01f31e923fe2 61 src = pair.split(':')[1]
Pawel Zarembski 0:01f31e923fe2 62 print(dest)
Pawel Zarembski 0:01f31e923fe2 63 cwd = os.getcwd()
Pawel Zarembski 0:01f31e923fe2 64 srcfile = open(os.path.join(cwd, src), 'r')
Pawel Zarembski 0:01f31e923fe2 65 replace.append({dest: srcfile.read()})
Pawel Zarembski 0:01f31e923fe2 66
Pawel Zarembski 0:01f31e923fe2 67 payload['replace'] = json.dumps(replace)
Pawel Zarembski 0:01f31e923fe2 68 logging.debug("Payload is: %s" % payload)
Pawel Zarembski 0:01f31e923fe2 69
Pawel Zarembski 0:01f31e923fe2 70 auth = (user, password,)
Pawel Zarembski 0:01f31e923fe2 71
Pawel Zarembski 0:01f31e923fe2 72 # send task to api
Pawel Zarembski 0:01f31e923fe2 73 logging.debug(api + "/api/v2/tasks/compiler/start/" + "| data: " +
Pawel Zarembski 0:01f31e923fe2 74 str(payload))
Pawel Zarembski 0:01f31e923fe2 75 r = requests.post(api + "/api/v2/tasks/compiler/start/",
Pawel Zarembski 0:01f31e923fe2 76 data=payload, auth=auth)
Pawel Zarembski 0:01f31e923fe2 77
Pawel Zarembski 0:01f31e923fe2 78 logging.debug(r.content)
Pawel Zarembski 0:01f31e923fe2 79
Pawel Zarembski 0:01f31e923fe2 80 if r.status_code != 200:
Pawel Zarembski 0:01f31e923fe2 81 raise Exception("Error while talking to the mbed API")
Pawel Zarembski 0:01f31e923fe2 82
Pawel Zarembski 0:01f31e923fe2 83 uuid = json.loads(r.content)['result']['data']['task_id']
Pawel Zarembski 0:01f31e923fe2 84 logging.debug("Task accepted and given ID: %s" % uuid)
Pawel Zarembski 0:01f31e923fe2 85 success = False
Pawel Zarembski 0:01f31e923fe2 86
Pawel Zarembski 0:01f31e923fe2 87 # poll for output
Pawel Zarembski 0:01f31e923fe2 88 for check in range(0, 40):
Pawel Zarembski 0:01f31e923fe2 89 logging.debug("Checking for output: cycle %s of %s" % (check, 10))
Pawel Zarembski 0:01f31e923fe2 90 time.sleep(2)
Pawel Zarembski 0:01f31e923fe2 91 r = requests.get(api + "/api/v2/tasks/compiler/output/%s" %
Pawel Zarembski 0:01f31e923fe2 92 uuid, auth=auth)
Pawel Zarembski 0:01f31e923fe2 93 logging.debug(r.content)
Pawel Zarembski 0:01f31e923fe2 94 response = json.loads(r.content)
Pawel Zarembski 0:01f31e923fe2 95 messages = response['result']['data']['new_messages']
Pawel Zarembski 0:01f31e923fe2 96 percent = 0
Pawel Zarembski 0:01f31e923fe2 97 for message in messages:
Pawel Zarembski 0:01f31e923fe2 98 if message.get('message'):
Pawel Zarembski 0:01f31e923fe2 99 if message.get('type') != 'debug':
Pawel Zarembski 0:01f31e923fe2 100 logging.info("[%s] %s" % (message['type'],
Pawel Zarembski 0:01f31e923fe2 101 message['message']))
Pawel Zarembski 0:01f31e923fe2 102 if message.get('action'):
Pawel Zarembski 0:01f31e923fe2 103 if message.get('percent'):
Pawel Zarembski 0:01f31e923fe2 104 percent = message['percent']
Pawel Zarembski 0:01f31e923fe2 105 logging.info("[%s%% - %s] %s " % (percent, message['action'],
Pawel Zarembski 0:01f31e923fe2 106 message.get('file', '')))
Pawel Zarembski 0:01f31e923fe2 107
Pawel Zarembski 0:01f31e923fe2 108 if response['result']['data']['task_complete']:
Pawel Zarembski 0:01f31e923fe2 109 logging.info("Task completed.")
Pawel Zarembski 0:01f31e923fe2 110 success = response['result']['data']['compilation_success']
Pawel Zarembski 0:01f31e923fe2 111 logging.info("Compile success: %s" % (success))
Pawel Zarembski 0:01f31e923fe2 112 break
Pawel Zarembski 0:01f31e923fe2 113
Pawel Zarembski 0:01f31e923fe2 114 # now download
Pawel Zarembski 0:01f31e923fe2 115 if success:
Pawel Zarembski 0:01f31e923fe2 116 logging.info("Downloading your binary")
Pawel Zarembski 0:01f31e923fe2 117 params = {
Pawel Zarembski 0:01f31e923fe2 118 'repomode': True,
Pawel Zarembski 0:01f31e923fe2 119 'program': response['result']['data']['program'],
Pawel Zarembski 0:01f31e923fe2 120 'binary': response['result']['data']['binary'],
Pawel Zarembski 0:01f31e923fe2 121 'task_id': uuid
Pawel Zarembski 0:01f31e923fe2 122 }
Pawel Zarembski 0:01f31e923fe2 123 r = requests.get(api + "/api/v2/tasks/compiler/bin/",
Pawel Zarembski 0:01f31e923fe2 124 params=params, auth=auth)
Pawel Zarembski 0:01f31e923fe2 125 destination = os.path.join(destdir,
Pawel Zarembski 0:01f31e923fe2 126 response['result']['data']['binary'])
Pawel Zarembski 0:01f31e923fe2 127
Pawel Zarembski 0:01f31e923fe2 128 with open(destination, 'wb') as fd:
Pawel Zarembski 0:01f31e923fe2 129 for chunk in r.iter_content(1024):
Pawel Zarembski 0:01f31e923fe2 130 fd.write(chunk)
Pawel Zarembski 0:01f31e923fe2 131
Pawel Zarembski 0:01f31e923fe2 132 logging.info("Finished!")
Pawel Zarembski 0:01f31e923fe2 133 else:
Pawel Zarembski 0:01f31e923fe2 134 raise Exception("Failed to build platform %s" % platform)
Pawel Zarembski 0:01f31e923fe2 135 return destination
Pawel Zarembski 0:01f31e923fe2 136
Pawel Zarembski 0:01f31e923fe2 137 if __name__ == "__main__":
Pawel Zarembski 0:01f31e923fe2 138 import argparse
Pawel Zarembski 0:01f31e923fe2 139 parser = argparse.ArgumentParser(description='Build an mbed repository.')
Pawel Zarembski 0:01f31e923fe2 140 parser.add_argument('--user', type=str, help='Your username on mbed.', required=True)
Pawel Zarembski 0:01f31e923fe2 141 parser.add_argument('--password', type=str, help='Your password on mbed.', default=None, required=False)
Pawel Zarembski 0:01f31e923fe2 142 parser.add_argument('--api', type=str, help='URL to API server', required=False, default=MBED_API_SERVER)
Pawel Zarembski 0:01f31e923fe2 143 parser.add_argument('--repo', type=str, help='URL of repository to build.', required=True)
Pawel Zarembski 0:01f31e923fe2 144 parser.add_argument('--platform', type=str, help='Platform name', required=True)
Pawel Zarembski 0:01f31e923fe2 145 parser.add_argument('--destdir', type=str, help='Binary destination directory', required=True)
Pawel Zarembski 0:01f31e923fe2 146 parser.add_argument('--replace_file', type=str, help='Replace file and build. Can be repeated. Syntax: remotepath:localpath', required=False, action='append')
Pawel Zarembski 0:01f31e923fe2 147 parser.add_argument('--extra_symbols', type=str, help='Provide extra symbols to build system', required=False, action='append')
Pawel Zarembski 0:01f31e923fe2 148 parser.add_argument('--clean', action='store_true', help='Force clean build')
Pawel Zarembski 0:01f31e923fe2 149 parser.add_argument('--debug', help='Show debugging info', required=False)
Pawel Zarembski 0:01f31e923fe2 150
Pawel Zarembski 0:01f31e923fe2 151 args = parser.parse_args()
Pawel Zarembski 0:01f31e923fe2 152 if args.debug:
Pawel Zarembski 0:01f31e923fe2 153 logging.basicConfig(level=logging.DEBUG)
Pawel Zarembski 0:01f31e923fe2 154 else:
Pawel Zarembski 0:01f31e923fe2 155 logging.basicConfig(level=logging.INFO)
Pawel Zarembski 0:01f31e923fe2 156 if args.password is None:
Pawel Zarembski 0:01f31e923fe2 157 args.password = getpass.getpass('mbed password: ')
Pawel Zarembski 0:01f31e923fe2 158 build_repo(args.user, args.password, args.repo, args.platform,
Pawel Zarembski 0:01f31e923fe2 159 args.destdir, args.replace_file, args.extra_symbols,
Pawel Zarembski 0:01f31e923fe2 160 args.clean, args.api)