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 * @file error.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief Implementation of error.h
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #include "error.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "util.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "compiler.h"
Pawel Zarembski 0:01f31e923fe2 25
Pawel Zarembski 0:01f31e923fe2 26 static const char *const error_message[] = {
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 /* Shared errors */
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30 // ERROR_SUCCESS
Pawel Zarembski 0:01f31e923fe2 31 "Operation was successful",
Pawel Zarembski 0:01f31e923fe2 32 // ERROR_FAILURE
Pawel Zarembski 0:01f31e923fe2 33 "An error has occurred",
Pawel Zarembski 0:01f31e923fe2 34 // ERROR_INTERNAL
Pawel Zarembski 0:01f31e923fe2 35 "An internal error has occurred",
Pawel Zarembski 0:01f31e923fe2 36
Pawel Zarembski 0:01f31e923fe2 37 /* VFS user errors */
Pawel Zarembski 0:01f31e923fe2 38
Pawel Zarembski 0:01f31e923fe2 39 // ERROR_ERROR_DURING_TRANSFER
Pawel Zarembski 0:01f31e923fe2 40 "An error occurred during the transfer",
Pawel Zarembski 0:01f31e923fe2 41 // ERROR_TRANSFER_TIMEOUT
Pawel Zarembski 0:01f31e923fe2 42 "The transfer timed out.",
Pawel Zarembski 0:01f31e923fe2 43 // ERROR_FILE_BOUNDS
Pawel Zarembski 0:01f31e923fe2 44 "Possible mismatch between file size and size programmed",
Pawel Zarembski 0:01f31e923fe2 45 // ERROR_OOO_SECTOR
Pawel Zarembski 0:01f31e923fe2 46 "File sent out of order by PC. Target might not be programmed correctly.",
Pawel Zarembski 0:01f31e923fe2 47
Pawel Zarembski 0:01f31e923fe2 48 /* Target flash errors */
Pawel Zarembski 0:01f31e923fe2 49
Pawel Zarembski 0:01f31e923fe2 50 // ERROR_RESET
Pawel Zarembski 0:01f31e923fe2 51 "The interface firmware FAILED to reset/halt the target MCU",
Pawel Zarembski 0:01f31e923fe2 52 // ERROR_ALGO_DL
Pawel Zarembski 0:01f31e923fe2 53 "The interface firmware FAILED to download the flash programming algorithms to the target MCU",
Pawel Zarembski 0:01f31e923fe2 54 //ERROR_ALGO_MISSING
Pawel Zarembski 0:01f31e923fe2 55 "The flash algo missing for a region",
Pawel Zarembski 0:01f31e923fe2 56 // ERROR_ALGO_DATA_SEQ
Pawel Zarembski 0:01f31e923fe2 57 "The interface firmware FAILED to download the flash data contents to be programmed",
Pawel Zarembski 0:01f31e923fe2 58 // ERROR_INIT
Pawel Zarembski 0:01f31e923fe2 59 "The interface firmware FAILED to initialize the target MCU",
Pawel Zarembski 0:01f31e923fe2 60 // ERROR_UNINIT
Pawel Zarembski 0:01f31e923fe2 61 "The interface firmware FAILED to uninitialize the target MCU",
Pawel Zarembski 0:01f31e923fe2 62 // ERROR_SECURITY_BITS
Pawel Zarembski 0:01f31e923fe2 63 "The interface firmware ABORTED programming. Image is trying to set security bits",
Pawel Zarembski 0:01f31e923fe2 64 // ERROR_UNLOCK
Pawel Zarembski 0:01f31e923fe2 65 "The interface firmware FAILED to unlock the target for programming",
Pawel Zarembski 0:01f31e923fe2 66 // ERROR_ERASE_SECTOR
Pawel Zarembski 0:01f31e923fe2 67 "Flash algorithm erase sector command FAILURE",
Pawel Zarembski 0:01f31e923fe2 68 // ERROR_ERASE_ALL
Pawel Zarembski 0:01f31e923fe2 69 "Flash algorithm erase all command FAILURE",
Pawel Zarembski 0:01f31e923fe2 70 // ERROR_WRITE
Pawel Zarembski 0:01f31e923fe2 71 "Flash algorithm write command FAILURE",
Pawel Zarembski 0:01f31e923fe2 72 // ERROR_WRITE_VERIFY
Pawel Zarembski 0:01f31e923fe2 73 "Flash algorithm write verify command FAILURE",
Pawel Zarembski 0:01f31e923fe2 74
Pawel Zarembski 0:01f31e923fe2 75 /* File stream errors */
Pawel Zarembski 0:01f31e923fe2 76
Pawel Zarembski 0:01f31e923fe2 77 // ERROR_SUCCESS_DONE
Pawel Zarembski 0:01f31e923fe2 78 "End of stream has been reached",
Pawel Zarembski 0:01f31e923fe2 79 // ERROR_SUCCESS_DONE_OR_CONTINUE
Pawel Zarembski 0:01f31e923fe2 80 "End of stream is unknown",
Pawel Zarembski 0:01f31e923fe2 81 // ERROR_HEX_CKSUM
Pawel Zarembski 0:01f31e923fe2 82 "The hex file cannot be decoded. Checksum calculation failure occurred.",
Pawel Zarembski 0:01f31e923fe2 83 // ERROR_HEX_PARSER
Pawel Zarembski 0:01f31e923fe2 84 "The hex file cannot be decoded. Parser logic failure occurred.",
Pawel Zarembski 0:01f31e923fe2 85 // ERROR_HEX_PROGRAM
Pawel Zarembski 0:01f31e923fe2 86 "The hex file cannot be programmed. Logic failure occurred.",
Pawel Zarembski 0:01f31e923fe2 87 // ERROR_HEX_INVALID_ADDRESS
Pawel Zarembski 0:01f31e923fe2 88 "The hex file you dropped isn't compatible with this mode or device. Are you in MAINTENANCE mode? See HELP FAQ.HTM",
Pawel Zarembski 0:01f31e923fe2 89 // ERROR_HEX_INVALID_APP_OFFSET
Pawel Zarembski 0:01f31e923fe2 90 "The hex file offset load address is not correct.",
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 /* Flash decoder errors */
Pawel Zarembski 0:01f31e923fe2 93
Pawel Zarembski 0:01f31e923fe2 94 // ERROR_FD_BL_UPDT_ADDR_WRONG
Pawel Zarembski 0:01f31e923fe2 95 "The starting address for the bootloader update is wrong.",
Pawel Zarembski 0:01f31e923fe2 96 // ERROR_FD_INTF_UPDT_ADDR_WRONG
Pawel Zarembski 0:01f31e923fe2 97 "The starting address for the interface update is wrong.",
Pawel Zarembski 0:01f31e923fe2 98 // ERROR_FD_UNSUPPORTED_UPDATE
Pawel Zarembski 0:01f31e923fe2 99 "The application file format is unknown and cannot be parsed and/or processed.",
Pawel Zarembski 0:01f31e923fe2 100
Pawel Zarembski 0:01f31e923fe2 101 /* Flash IAP interface */
Pawel Zarembski 0:01f31e923fe2 102
Pawel Zarembski 0:01f31e923fe2 103 // ERROR_IAP_INIT
Pawel Zarembski 0:01f31e923fe2 104 "In application programming initialization failed.",
Pawel Zarembski 0:01f31e923fe2 105 // ERROR_IAP_UNINIT
Pawel Zarembski 0:01f31e923fe2 106 "In application programming uninit failed.",
Pawel Zarembski 0:01f31e923fe2 107 // ERROR_IAP_WRITE
Pawel Zarembski 0:01f31e923fe2 108 "In application programming write failed.",
Pawel Zarembski 0:01f31e923fe2 109 // ERROR_IAP_ERASE_SECTOR
Pawel Zarembski 0:01f31e923fe2 110 "In application programming sector erase failed.",
Pawel Zarembski 0:01f31e923fe2 111 // ERROR_IAP_ERASE_ALL
Pawel Zarembski 0:01f31e923fe2 112 "In application programming mass erase failed.",
Pawel Zarembski 0:01f31e923fe2 113 // ERROR_IAP_OUT_OF_BOUNDS
Pawel Zarembski 0:01f31e923fe2 114 "In application programming aborted due to an out of bounds address.",
Pawel Zarembski 0:01f31e923fe2 115 // ERROR_IAP_UPDT_NOT_SUPPORTED
Pawel Zarembski 0:01f31e923fe2 116 "In application programming not supported on this device.",
Pawel Zarembski 0:01f31e923fe2 117 // ERROR_IAP_UPDT_INCOMPLETE
Pawel Zarembski 0:01f31e923fe2 118 "In application programming failed because the update sent was incomplete.",
Pawel Zarembski 0:01f31e923fe2 119 // ERROR_IAP_NO_INTERCEPT
Pawel Zarembski 0:01f31e923fe2 120 "",
Pawel Zarembski 0:01f31e923fe2 121 // ERROR_BL_UPDT_BAD_CRC
Pawel Zarembski 0:01f31e923fe2 122 "The bootloader CRC did not pass.",
Pawel Zarembski 0:01f31e923fe2 123
Pawel Zarembski 0:01f31e923fe2 124 };
Pawel Zarembski 0:01f31e923fe2 125
Pawel Zarembski 0:01f31e923fe2 126 static error_type_t error_type[] = {
Pawel Zarembski 0:01f31e923fe2 127
Pawel Zarembski 0:01f31e923fe2 128 /* These should always stay the same for each error type. */
Pawel Zarembski 0:01f31e923fe2 129
Pawel Zarembski 0:01f31e923fe2 130 // ERROR_SUCCESS
Pawel Zarembski 0:01f31e923fe2 131 0,
Pawel Zarembski 0:01f31e923fe2 132 // ERROR_FAILURE
Pawel Zarembski 0:01f31e923fe2 133 ERROR_TYPE_INTERNAL,
Pawel Zarembski 0:01f31e923fe2 134 // ERROR_INTERNAL
Pawel Zarembski 0:01f31e923fe2 135 ERROR_TYPE_INTERNAL,
Pawel Zarembski 0:01f31e923fe2 136
Pawel Zarembski 0:01f31e923fe2 137 /* VFS user errors */
Pawel Zarembski 0:01f31e923fe2 138
Pawel Zarembski 0:01f31e923fe2 139 // ERROR_ERROR_DURING_TRANSFER
Pawel Zarembski 0:01f31e923fe2 140 ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 141 // ERROR_TRANSFER_TIMEOUT
Pawel Zarembski 0:01f31e923fe2 142 ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 143 // ERROR_FILE_BOUNDS
Pawel Zarembski 0:01f31e923fe2 144 ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 145 // ERROR_OOO_SECTOR
Pawel Zarembski 0:01f31e923fe2 146 ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 147
Pawel Zarembski 0:01f31e923fe2 148 /* Target flash errors */
Pawel Zarembski 0:01f31e923fe2 149
Pawel Zarembski 0:01f31e923fe2 150 // ERROR_RESET
Pawel Zarembski 0:01f31e923fe2 151 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 152 // ERROR_ALGO_DL
Pawel Zarembski 0:01f31e923fe2 153 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 154 //ERROR_ALGO_MISSING
Pawel Zarembski 0:01f31e923fe2 155 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 156 // ERROR_ALGO_DATA_SEQ
Pawel Zarembski 0:01f31e923fe2 157 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 158 // ERROR_INIT
Pawel Zarembski 0:01f31e923fe2 159 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 160 // ERROR_UNINIT
Pawel Zarembski 0:01f31e923fe2 161 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 162 // ERROR_SECURITY_BITS
Pawel Zarembski 0:01f31e923fe2 163 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 164 // ERROR_UNLOCK
Pawel Zarembski 0:01f31e923fe2 165 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 166 // ERROR_ERASE_SECTOR
Pawel Zarembski 0:01f31e923fe2 167 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 168 // ERROR_ERASE_ALL
Pawel Zarembski 0:01f31e923fe2 169 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 170 // ERROR_WRITE
Pawel Zarembski 0:01f31e923fe2 171 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 172 // ERROR_WRITE_VERIFY
Pawel Zarembski 0:01f31e923fe2 173 ERROR_TYPE_TARGET,
Pawel Zarembski 0:01f31e923fe2 174
Pawel Zarembski 0:01f31e923fe2 175 /* File stream errors */
Pawel Zarembski 0:01f31e923fe2 176
Pawel Zarembski 0:01f31e923fe2 177 // ERROR_SUCCESS_DONE
Pawel Zarembski 0:01f31e923fe2 178 ERROR_TYPE_INTERNAL,
Pawel Zarembski 0:01f31e923fe2 179 // ERROR_SUCCESS_DONE_OR_CONTINUE
Pawel Zarembski 0:01f31e923fe2 180 ERROR_TYPE_INTERNAL,
Pawel Zarembski 0:01f31e923fe2 181 // ERROR_HEX_CKSUM
Pawel Zarembski 0:01f31e923fe2 182 ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 183 // ERROR_HEX_PARSER
Pawel Zarembski 0:01f31e923fe2 184 ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 185 // ERROR_HEX_PROGRAM
Pawel Zarembski 0:01f31e923fe2 186 ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
Pawel Zarembski 0:01f31e923fe2 187 // ERROR_HEX_INVALID_ADDRESS
Pawel Zarembski 0:01f31e923fe2 188 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 189 // ERROR_HEX_INVALID_APP_OFFSET
Pawel Zarembski 0:01f31e923fe2 190 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 191
Pawel Zarembski 0:01f31e923fe2 192 /* Flash decoder errors */
Pawel Zarembski 0:01f31e923fe2 193
Pawel Zarembski 0:01f31e923fe2 194 // ERROR_FD_BL_UPDT_ADDR_WRONG
Pawel Zarembski 0:01f31e923fe2 195 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 196 // ERROR_FD_INTF_UPDT_ADDR_WRONG
Pawel Zarembski 0:01f31e923fe2 197 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 198 // ERROR_FD_UNSUPPORTED_UPDATE
Pawel Zarembski 0:01f31e923fe2 199 ERROR_TYPE_USER,
Pawel Zarembski 0:01f31e923fe2 200
Pawel Zarembski 0:01f31e923fe2 201 /* Flash IAP interface */
Pawel Zarembski 0:01f31e923fe2 202
Pawel Zarembski 0:01f31e923fe2 203 // ERROR_IAP_INIT
Pawel Zarembski 0:01f31e923fe2 204 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 205 // ERROR_IAP_UNINIT
Pawel Zarembski 0:01f31e923fe2 206 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 207 // ERROR_IAP_WRITE
Pawel Zarembski 0:01f31e923fe2 208 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 209 // ERROR_IAP_ERASE_SECTOR
Pawel Zarembski 0:01f31e923fe2 210 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 211 // ERROR_IAP_ERASE_ALL
Pawel Zarembski 0:01f31e923fe2 212 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 213 // ERROR_IAP_OUT_OF_BOUNDS
Pawel Zarembski 0:01f31e923fe2 214 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 215 // ERROR_IAP_UPDT_NOT_SUPPORTED
Pawel Zarembski 0:01f31e923fe2 216 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 217 // ERROR_IAP_UPDT_INCOMPLETE
Pawel Zarembski 0:01f31e923fe2 218 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 219 // ERROR_IAP_NO_INTERCEPT
Pawel Zarembski 0:01f31e923fe2 220 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 221 // ERROR_BL_UPDT_BAD_CRC
Pawel Zarembski 0:01f31e923fe2 222 ERROR_TYPE_INTERFACE,
Pawel Zarembski 0:01f31e923fe2 223 };
Pawel Zarembski 0:01f31e923fe2 224
Pawel Zarembski 0:01f31e923fe2 225 COMPILER_ASSERT(ERROR_COUNT == ARRAY_SIZE(error_message));
Pawel Zarembski 0:01f31e923fe2 226
Pawel Zarembski 0:01f31e923fe2 227 const char *error_get_string(error_t error)
Pawel Zarembski 0:01f31e923fe2 228 {
Pawel Zarembski 0:01f31e923fe2 229 const char *msg = 0;
Pawel Zarembski 0:01f31e923fe2 230
Pawel Zarembski 0:01f31e923fe2 231 if (error < ERROR_COUNT) {
Pawel Zarembski 0:01f31e923fe2 232 msg = error_message[error];
Pawel Zarembski 0:01f31e923fe2 233 }
Pawel Zarembski 0:01f31e923fe2 234
Pawel Zarembski 0:01f31e923fe2 235 if (0 == msg) {
Pawel Zarembski 0:01f31e923fe2 236 util_assert(0);
Pawel Zarembski 0:01f31e923fe2 237 msg = "";
Pawel Zarembski 0:01f31e923fe2 238 }
Pawel Zarembski 0:01f31e923fe2 239
Pawel Zarembski 0:01f31e923fe2 240 return msg;
Pawel Zarembski 0:01f31e923fe2 241 }
Pawel Zarembski 0:01f31e923fe2 242
Pawel Zarembski 0:01f31e923fe2 243 error_type_t error_get_type(error_t error)
Pawel Zarembski 0:01f31e923fe2 244 {
Pawel Zarembski 0:01f31e923fe2 245 error_type_t type = ERROR_TYPE_INTERNAL;
Pawel Zarembski 0:01f31e923fe2 246
Pawel Zarembski 0:01f31e923fe2 247 if (error < ERROR_COUNT) {
Pawel Zarembski 0:01f31e923fe2 248 type = error_type[error];
Pawel Zarembski 0:01f31e923fe2 249 }
Pawel Zarembski 0:01f31e923fe2 250
Pawel Zarembski 0:01f31e923fe2 251 return type;
Pawel Zarembski 0:01f31e923fe2 252 }