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 validation.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief Implementation of validation.h
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-2019, 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 <string.h>
Pawel Zarembski 0:01f31e923fe2 23 #include "validation.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "target_config.h"
Pawel Zarembski 0:01f31e923fe2 25 #include "target_family.h"
Pawel Zarembski 0:01f31e923fe2 26 #include "target_board.h"
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 static inline uint32_t test_range(const uint32_t test, const uint32_t min, const uint32_t max)
Pawel Zarembski 0:01f31e923fe2 29 {
Pawel Zarembski 0:01f31e923fe2 30 return ((test < min) || (test > max)) ? 0 : 1;
Pawel Zarembski 0:01f31e923fe2 31 }
Pawel Zarembski 0:01f31e923fe2 32
Pawel Zarembski 0:01f31e923fe2 33 uint8_t validate_bin_nvic(const uint8_t *buf)
Pawel Zarembski 0:01f31e923fe2 34 {
Pawel Zarembski 0:01f31e923fe2 35 if (g_target_family && g_target_family->validate_bin_nvic) {
Pawel Zarembski 0:01f31e923fe2 36 return g_target_family && g_target_family->validate_bin_nvic(buf);
Pawel Zarembski 0:01f31e923fe2 37 } else if (g_board_info.target_cfg) {
Pawel Zarembski 0:01f31e923fe2 38 uint32_t i = 4, nvic_val = 0;
Pawel Zarembski 0:01f31e923fe2 39 uint8_t in_range = 0;
Pawel Zarembski 0:01f31e923fe2 40 // test the initial SP value
Pawel Zarembski 0:01f31e923fe2 41 memcpy(&nvic_val, buf + 0, sizeof(nvic_val));
Pawel Zarembski 0:01f31e923fe2 42
Pawel Zarembski 0:01f31e923fe2 43 region_info_t * region = g_board_info.target_cfg->ram_regions;
Pawel Zarembski 0:01f31e923fe2 44 for (; region->start != 0 || region->end != 0; ++region) {
Pawel Zarembski 0:01f31e923fe2 45 if (1 == test_range(nvic_val, region->start, region->end)) {
Pawel Zarembski 0:01f31e923fe2 46 in_range = 1;
Pawel Zarembski 0:01f31e923fe2 47 break;
Pawel Zarembski 0:01f31e923fe2 48 }
Pawel Zarembski 0:01f31e923fe2 49 }
Pawel Zarembski 0:01f31e923fe2 50
Pawel Zarembski 0:01f31e923fe2 51 if (in_range == 0) {
Pawel Zarembski 0:01f31e923fe2 52 return 0;
Pawel Zarembski 0:01f31e923fe2 53 }
Pawel Zarembski 0:01f31e923fe2 54
Pawel Zarembski 0:01f31e923fe2 55 // Reset_Handler
Pawel Zarembski 0:01f31e923fe2 56 // NMI_Handler
Pawel Zarembski 0:01f31e923fe2 57 // HardFault_Handler
Pawel Zarembski 0:01f31e923fe2 58 for (; i <= 12; i += 4) {
Pawel Zarembski 0:01f31e923fe2 59 in_range = 0;
Pawel Zarembski 0:01f31e923fe2 60 memcpy(&nvic_val, buf + i, sizeof(nvic_val));
Pawel Zarembski 0:01f31e923fe2 61 region_info_t * region = g_board_info.target_cfg->flash_regions;
Pawel Zarembski 0:01f31e923fe2 62 for (; region->start != 0 || region->end != 0; ++region) {
Pawel Zarembski 0:01f31e923fe2 63 if (1 == test_range(nvic_val, region->start, region->end)) {
Pawel Zarembski 0:01f31e923fe2 64 in_range = 1;
Pawel Zarembski 0:01f31e923fe2 65 break;
Pawel Zarembski 0:01f31e923fe2 66 }
Pawel Zarembski 0:01f31e923fe2 67 }
Pawel Zarembski 0:01f31e923fe2 68 if (in_range == 0) {
Pawel Zarembski 0:01f31e923fe2 69 return 0;
Pawel Zarembski 0:01f31e923fe2 70 }
Pawel Zarembski 0:01f31e923fe2 71 }
Pawel Zarembski 0:01f31e923fe2 72
Pawel Zarembski 0:01f31e923fe2 73 return 1;
Pawel Zarembski 0:01f31e923fe2 74
Pawel Zarembski 0:01f31e923fe2 75 } else {
Pawel Zarembski 0:01f31e923fe2 76 return 0;
Pawel Zarembski 0:01f31e923fe2 77 }
Pawel Zarembski 0:01f31e923fe2 78 }
Pawel Zarembski 0:01f31e923fe2 79
Pawel Zarembski 0:01f31e923fe2 80 uint8_t validate_hexfile(const uint8_t *buf)
Pawel Zarembski 0:01f31e923fe2 81 {
Pawel Zarembski 0:01f31e923fe2 82 if (g_target_family && g_target_family->validate_hexfile) {
Pawel Zarembski 0:01f31e923fe2 83 return g_target_family->validate_hexfile(buf);
Pawel Zarembski 0:01f31e923fe2 84 } else {
Pawel Zarembski 0:01f31e923fe2 85 // look here for known hex records
Pawel Zarembski 0:01f31e923fe2 86 // add hex identifier b[0] == ':' && b[8] == {'0', '2', '3', '4', '5'}
Pawel Zarembski 0:01f31e923fe2 87 return ((buf[0] == ':') && ((buf[8] == '0') || (buf[8] == '2') || (buf[8] == '3') || (buf[8] == '4') || (buf[8] == '5'))) ? 1 : 0;
Pawel Zarembski 0:01f31e923fe2 88 }
Pawel Zarembski 0:01f31e923fe2 89 }