Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/daplink/info.c@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 | * @file info.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief Implementation of info.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 "main.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "info.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "target_config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include "read_uid.h" |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #include "util.h" |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #include "crc.h" |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #include "daplink.h" |
Pawel Zarembski |
0:01f31e923fe2 | 30 | #include "settings.h" |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #include "target_board.h" |
Pawel Zarembski |
0:01f31e923fe2 | 32 | |
Pawel Zarembski |
0:01f31e923fe2 | 33 | static char hex_to_ascii(uint8_t x) |
Pawel Zarembski |
0:01f31e923fe2 | 34 | { |
Pawel Zarembski |
0:01f31e923fe2 | 35 | return ('0' + (x>9 ? x+0x27 : x)); |
Pawel Zarembski |
0:01f31e923fe2 | 36 | } |
Pawel Zarembski |
0:01f31e923fe2 | 37 | |
Pawel Zarembski |
0:01f31e923fe2 | 38 | // Constant variables |
Pawel Zarembski |
0:01f31e923fe2 | 39 | static const daplink_info_t *const info_bl = (daplink_info_t *)(DAPLINK_ROM_BL_START + DAPLINK_INFO_OFFSET); |
Pawel Zarembski |
0:01f31e923fe2 | 40 | static const daplink_info_t *const info_if = (daplink_info_t *)(DAPLINK_ROM_IF_START + DAPLINK_INFO_OFFSET); |
Pawel Zarembski |
0:01f31e923fe2 | 41 | |
Pawel Zarembski |
0:01f31e923fe2 | 42 | // Raw variables |
Pawel Zarembski |
0:01f31e923fe2 | 43 | static uint32_t host_id[4]; |
Pawel Zarembski |
0:01f31e923fe2 | 44 | static uint32_t target_id[4]; |
Pawel Zarembski |
0:01f31e923fe2 | 45 | static uint32_t hic_id = DAPLINK_HIC_ID; |
Pawel Zarembski |
0:01f31e923fe2 | 46 | |
Pawel Zarembski |
0:01f31e923fe2 | 47 | static uint32_t crc_bootloader; |
Pawel Zarembski |
0:01f31e923fe2 | 48 | static uint32_t crc_interface; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | static uint32_t crc_config_admin; |
Pawel Zarembski |
0:01f31e923fe2 | 50 | static uint32_t crc_config_user; |
Pawel Zarembski |
0:01f31e923fe2 | 51 | |
Pawel Zarembski |
0:01f31e923fe2 | 52 | // Strings |
Pawel Zarembski |
0:01f31e923fe2 | 53 | static char string_unique_id[48 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 54 | static char string_mac[12 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | static char string_board_id[4 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | static char string_family_id[4 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 57 | static char string_host_id[32 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 58 | static char string_target_id[32 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | static char string_hic_id[8 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 60 | static char string_version[4 + 1]; |
Pawel Zarembski |
0:01f31e923fe2 | 61 | |
Pawel Zarembski |
0:01f31e923fe2 | 62 | static char usb_desc_unique_id[2 + sizeof(string_unique_id) * 2]; |
Pawel Zarembski |
0:01f31e923fe2 | 63 | |
Pawel Zarembski |
0:01f31e923fe2 | 64 | |
Pawel Zarembski |
0:01f31e923fe2 | 65 | const char *info_get_unique_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 66 | { |
Pawel Zarembski |
0:01f31e923fe2 | 67 | return string_unique_id; |
Pawel Zarembski |
0:01f31e923fe2 | 68 | } |
Pawel Zarembski |
0:01f31e923fe2 | 69 | |
Pawel Zarembski |
0:01f31e923fe2 | 70 | const char *info_get_board_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 71 | { |
Pawel Zarembski |
0:01f31e923fe2 | 72 | return string_board_id; |
Pawel Zarembski |
0:01f31e923fe2 | 73 | } |
Pawel Zarembski |
0:01f31e923fe2 | 74 | |
Pawel Zarembski |
0:01f31e923fe2 | 75 | const char *info_get_host_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 76 | { |
Pawel Zarembski |
0:01f31e923fe2 | 77 | return string_host_id; |
Pawel Zarembski |
0:01f31e923fe2 | 78 | } |
Pawel Zarembski |
0:01f31e923fe2 | 79 | |
Pawel Zarembski |
0:01f31e923fe2 | 80 | const char *info_get_target_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 81 | { |
Pawel Zarembski |
0:01f31e923fe2 | 82 | return string_target_id; |
Pawel Zarembski |
0:01f31e923fe2 | 83 | } |
Pawel Zarembski |
0:01f31e923fe2 | 84 | |
Pawel Zarembski |
0:01f31e923fe2 | 85 | const char *info_get_hic_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 86 | { |
Pawel Zarembski |
0:01f31e923fe2 | 87 | return string_hic_id; |
Pawel Zarembski |
0:01f31e923fe2 | 88 | } |
Pawel Zarembski |
0:01f31e923fe2 | 89 | const char *info_get_version(void) |
Pawel Zarembski |
0:01f31e923fe2 | 90 | { |
Pawel Zarembski |
0:01f31e923fe2 | 91 | return string_version; |
Pawel Zarembski |
0:01f31e923fe2 | 92 | } |
Pawel Zarembski |
0:01f31e923fe2 | 93 | const char *info_get_mac(void) |
Pawel Zarembski |
0:01f31e923fe2 | 94 | { |
Pawel Zarembski |
0:01f31e923fe2 | 95 | return string_mac; |
Pawel Zarembski |
0:01f31e923fe2 | 96 | } |
Pawel Zarembski |
0:01f31e923fe2 | 97 | |
Pawel Zarembski |
0:01f31e923fe2 | 98 | const char *info_get_unique_id_string_descriptor(void) |
Pawel Zarembski |
0:01f31e923fe2 | 99 | { |
Pawel Zarembski |
0:01f31e923fe2 | 100 | return usb_desc_unique_id; |
Pawel Zarembski |
0:01f31e923fe2 | 101 | } |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | //prevent the compiler to optimize boad and family id |
Pawel Zarembski |
0:01f31e923fe2 | 104 | #if (defined(__ICCARM__)) |
Pawel Zarembski |
0:01f31e923fe2 | 105 | #pragma optimize = none |
Pawel Zarembski |
0:01f31e923fe2 | 106 | static void setup_basics(void) |
Pawel Zarembski |
0:01f31e923fe2 | 107 | #elif (defined(__CC_ARM)) |
Pawel Zarembski |
0:01f31e923fe2 | 108 | #pragma push |
Pawel Zarembski |
0:01f31e923fe2 | 109 | #pragma O0 |
Pawel Zarembski |
0:01f31e923fe2 | 110 | static void setup_basics(void) |
Pawel Zarembski |
0:01f31e923fe2 | 111 | #elif (!defined(__GNUC__)) |
Pawel Zarembski |
0:01f31e923fe2 | 112 | /* #pragma GCC push_options */ |
Pawel Zarembski |
0:01f31e923fe2 | 113 | /* #pragma GCC optimize("O0") */ |
Pawel Zarembski |
0:01f31e923fe2 | 114 | static void __attribute__((optimize("O0"))) setup_basics(void) |
Pawel Zarembski |
0:01f31e923fe2 | 115 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 116 | #error "Unknown compiler" |
Pawel Zarembski |
0:01f31e923fe2 | 117 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 118 | |
Pawel Zarembski |
0:01f31e923fe2 | 119 | { |
Pawel Zarembski |
0:01f31e923fe2 | 120 | uint8_t i = 0, idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 121 | uint16_t family_id = get_family_id(); |
Pawel Zarembski |
0:01f31e923fe2 | 122 | memset(string_board_id, 0, sizeof(string_board_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 123 | memset(string_host_id, 0, sizeof(string_host_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 124 | memset(string_target_id, 0, sizeof(string_target_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 125 | memset(string_hic_id, 0, sizeof(string_hic_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 126 | memset(string_board_id, 0, sizeof(string_board_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 127 | // Host ID |
Pawel Zarembski |
0:01f31e923fe2 | 128 | idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 129 | |
Pawel Zarembski |
0:01f31e923fe2 | 130 | for (i = 0; i < 4; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 131 | idx += util_write_hex32(string_host_id + idx, host_id[i]); |
Pawel Zarembski |
0:01f31e923fe2 | 132 | } |
Pawel Zarembski |
0:01f31e923fe2 | 133 | |
Pawel Zarembski |
0:01f31e923fe2 | 134 | string_host_id[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 135 | // Target ID |
Pawel Zarembski |
0:01f31e923fe2 | 136 | idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 137 | |
Pawel Zarembski |
0:01f31e923fe2 | 138 | for (i = 0; i < 4; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 139 | idx += util_write_hex32(string_target_id + idx, target_id[i]); |
Pawel Zarembski |
0:01f31e923fe2 | 140 | } |
Pawel Zarembski |
0:01f31e923fe2 | 141 | |
Pawel Zarembski |
0:01f31e923fe2 | 142 | string_target_id[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 143 | // HIC ID |
Pawel Zarembski |
0:01f31e923fe2 | 144 | idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 145 | idx += util_write_hex32(string_hic_id + idx, hic_id); |
Pawel Zarembski |
0:01f31e923fe2 | 146 | string_hic_id[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 147 | // Board ID |
Pawel Zarembski |
0:01f31e923fe2 | 148 | memcpy(string_board_id, get_board_id(), 4); |
Pawel Zarembski |
0:01f31e923fe2 | 149 | string_board_id[4] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 150 | idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 151 | //Family ID |
Pawel Zarembski |
0:01f31e923fe2 | 152 | string_family_id[idx++] = hex_to_ascii(((family_id >> 12) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 153 | string_family_id[idx++] = hex_to_ascii(((family_id >> 8) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 154 | #if !(defined(DAPLINK_BL)) && defined(DRAG_N_DROP_SUPPORT) //need to change the unique id when the msd is disabled |
Pawel Zarembski |
0:01f31e923fe2 | 155 | #if defined(MSC_ENDPOINT) |
Pawel Zarembski |
0:01f31e923fe2 | 156 | if (config_ram_get_disable_msd() == 1 || flash_algo_valid()==0){ |
Pawel Zarembski |
0:01f31e923fe2 | 157 | string_family_id[idx++] = hex_to_ascii((((family_id >> 4) | 0x08) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 158 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 159 | string_family_id[idx++] = hex_to_ascii(((family_id >> 4) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 160 | } |
Pawel Zarembski |
0:01f31e923fe2 | 161 | #else //no msd support always have the most significant bit set for family id 2nd byte |
Pawel Zarembski |
0:01f31e923fe2 | 162 | string_family_id[idx++] = hex_to_ascii((((family_id >> 4) | 0x08) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 163 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 164 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 165 | string_family_id[idx++] = hex_to_ascii(((family_id >> 4) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 166 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 167 | string_family_id[idx++] = hex_to_ascii(((family_id) & 0xF)); |
Pawel Zarembski |
0:01f31e923fe2 | 168 | string_family_id[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 169 | // Version |
Pawel Zarembski |
0:01f31e923fe2 | 170 | idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 171 | string_version[idx++] = '0' + (DAPLINK_VERSION / 1000) % 10; |
Pawel Zarembski |
0:01f31e923fe2 | 172 | string_version[idx++] = '0' + (DAPLINK_VERSION / 100) % 10; |
Pawel Zarembski |
0:01f31e923fe2 | 173 | string_version[idx++] = '0' + (DAPLINK_VERSION / 10) % 10; |
Pawel Zarembski |
0:01f31e923fe2 | 174 | string_version[idx++] = '0' + (DAPLINK_VERSION / 1) % 10; |
Pawel Zarembski |
0:01f31e923fe2 | 175 | string_version[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 176 | } |
Pawel Zarembski |
0:01f31e923fe2 | 177 | |
Pawel Zarembski |
0:01f31e923fe2 | 178 | static void setup_unique_id() |
Pawel Zarembski |
0:01f31e923fe2 | 179 | { |
Pawel Zarembski |
0:01f31e923fe2 | 180 | memset(string_unique_id, 0, sizeof(string_unique_id)); |
Pawel Zarembski |
0:01f31e923fe2 | 181 | strcat(string_unique_id, string_board_id); |
Pawel Zarembski |
0:01f31e923fe2 | 182 | strcat(string_unique_id, string_family_id); |
Pawel Zarembski |
0:01f31e923fe2 | 183 | strcat(string_unique_id, string_host_id); |
Pawel Zarembski |
0:01f31e923fe2 | 184 | strcat(string_unique_id, string_hic_id); |
Pawel Zarembski |
0:01f31e923fe2 | 185 | } |
Pawel Zarembski |
0:01f31e923fe2 | 186 | |
Pawel Zarembski |
0:01f31e923fe2 | 187 | static void setup_string_descriptor() |
Pawel Zarembski |
0:01f31e923fe2 | 188 | { |
Pawel Zarembski |
0:01f31e923fe2 | 189 | uint8_t i = 0, idx = 0, len = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 190 | len = strlen((const char *)string_unique_id); |
Pawel Zarembski |
0:01f31e923fe2 | 191 | // bLength |
Pawel Zarembski |
0:01f31e923fe2 | 192 | usb_desc_unique_id[idx++] = len * 2 + 2; |
Pawel Zarembski |
0:01f31e923fe2 | 193 | // bDescriptorType |
Pawel Zarembski |
0:01f31e923fe2 | 194 | usb_desc_unique_id[idx++] = 3; |
Pawel Zarembski |
0:01f31e923fe2 | 195 | |
Pawel Zarembski |
0:01f31e923fe2 | 196 | // bString |
Pawel Zarembski |
0:01f31e923fe2 | 197 | for (i = 0; i < len; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 198 | usb_desc_unique_id[idx++] = string_unique_id[i]; |
Pawel Zarembski |
0:01f31e923fe2 | 199 | usb_desc_unique_id[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 200 | } |
Pawel Zarembski |
0:01f31e923fe2 | 201 | } |
Pawel Zarembski |
0:01f31e923fe2 | 202 | |
Pawel Zarembski |
0:01f31e923fe2 | 203 | void info_init(void) |
Pawel Zarembski |
0:01f31e923fe2 | 204 | { |
Pawel Zarembski |
0:01f31e923fe2 | 205 | info_crc_compute(); |
Pawel Zarembski |
0:01f31e923fe2 | 206 | read_unique_id(host_id); |
Pawel Zarembski |
0:01f31e923fe2 | 207 | setup_basics(); |
Pawel Zarembski |
0:01f31e923fe2 | 208 | setup_unique_id(); |
Pawel Zarembski |
0:01f31e923fe2 | 209 | setup_string_descriptor(); |
Pawel Zarembski |
0:01f31e923fe2 | 210 | } |
Pawel Zarembski |
0:01f31e923fe2 | 211 | |
Pawel Zarembski |
0:01f31e923fe2 | 212 | void info_set_uuid_target(uint32_t *uuid_data) |
Pawel Zarembski |
0:01f31e923fe2 | 213 | { |
Pawel Zarembski |
0:01f31e923fe2 | 214 | uint32_t idx = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 215 | // Save the target ID |
Pawel Zarembski |
0:01f31e923fe2 | 216 | memcpy(target_id, uuid_data, 16); |
Pawel Zarembski |
0:01f31e923fe2 | 217 | // patch for MAC use. Make sure MSB bits are set correctly |
Pawel Zarembski |
0:01f31e923fe2 | 218 | uuid_data[2] |= (0x2 << 8); |
Pawel Zarembski |
0:01f31e923fe2 | 219 | uuid_data[2] &= ~(0x1 << 8); |
Pawel Zarembski |
0:01f31e923fe2 | 220 | idx += util_write_hex16(string_mac + idx, uuid_data[2] & 0xFFFF); |
Pawel Zarembski |
0:01f31e923fe2 | 221 | idx += util_write_hex32(string_mac + idx, uuid_data[3]); |
Pawel Zarembski |
0:01f31e923fe2 | 222 | string_mac[idx++] = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 223 | } |
Pawel Zarembski |
0:01f31e923fe2 | 224 | |
Pawel Zarembski |
0:01f31e923fe2 | 225 | bool info_get_bootloader_present(void) |
Pawel Zarembski |
0:01f31e923fe2 | 226 | { |
Pawel Zarembski |
0:01f31e923fe2 | 227 | bool present = true; |
Pawel Zarembski |
0:01f31e923fe2 | 228 | |
Pawel Zarembski |
0:01f31e923fe2 | 229 | if (0 == DAPLINK_ROM_BL_SIZE) { |
Pawel Zarembski |
0:01f31e923fe2 | 230 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 231 | } |
Pawel Zarembski |
0:01f31e923fe2 | 232 | |
Pawel Zarembski |
0:01f31e923fe2 | 233 | if (DAPLINK_BUILD_KEY_BL != info_bl->build_key) { |
Pawel Zarembski |
0:01f31e923fe2 | 234 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 235 | } |
Pawel Zarembski |
0:01f31e923fe2 | 236 | |
Pawel Zarembski |
0:01f31e923fe2 | 237 | if (DAPLINK_HIC_ID != info_bl->hic_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 238 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 239 | } |
Pawel Zarembski |
0:01f31e923fe2 | 240 | |
Pawel Zarembski |
0:01f31e923fe2 | 241 | return present; |
Pawel Zarembski |
0:01f31e923fe2 | 242 | } |
Pawel Zarembski |
0:01f31e923fe2 | 243 | |
Pawel Zarembski |
0:01f31e923fe2 | 244 | bool info_get_interface_present(void) |
Pawel Zarembski |
0:01f31e923fe2 | 245 | { |
Pawel Zarembski |
0:01f31e923fe2 | 246 | bool present = true; |
Pawel Zarembski |
0:01f31e923fe2 | 247 | |
Pawel Zarembski |
0:01f31e923fe2 | 248 | if (0 == DAPLINK_ROM_IF_SIZE) { |
Pawel Zarembski |
0:01f31e923fe2 | 249 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 250 | } |
Pawel Zarembski |
0:01f31e923fe2 | 251 | |
Pawel Zarembski |
0:01f31e923fe2 | 252 | if (DAPLINK_BUILD_KEY_IF != info_if->build_key) { |
Pawel Zarembski |
0:01f31e923fe2 | 253 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 254 | } |
Pawel Zarembski |
0:01f31e923fe2 | 255 | |
Pawel Zarembski |
0:01f31e923fe2 | 256 | if (DAPLINK_HIC_ID != info_if->hic_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 257 | present = false; |
Pawel Zarembski |
0:01f31e923fe2 | 258 | } |
Pawel Zarembski |
0:01f31e923fe2 | 259 | |
Pawel Zarembski |
0:01f31e923fe2 | 260 | return present; |
Pawel Zarembski |
0:01f31e923fe2 | 261 | } |
Pawel Zarembski |
0:01f31e923fe2 | 262 | |
Pawel Zarembski |
0:01f31e923fe2 | 263 | bool info_get_config_admin_present(void) |
Pawel Zarembski |
0:01f31e923fe2 | 264 | { |
Pawel Zarembski |
0:01f31e923fe2 | 265 | //TODO, c1728p9 - check if admin config has been loaded |
Pawel Zarembski |
0:01f31e923fe2 | 266 | return false; |
Pawel Zarembski |
0:01f31e923fe2 | 267 | } |
Pawel Zarembski |
0:01f31e923fe2 | 268 | |
Pawel Zarembski |
0:01f31e923fe2 | 269 | bool info_get_config_user_present(void) |
Pawel Zarembski |
0:01f31e923fe2 | 270 | { |
Pawel Zarembski |
0:01f31e923fe2 | 271 | //TODO, c1728p9 - check if user config has a valid key |
Pawel Zarembski |
0:01f31e923fe2 | 272 | return false; |
Pawel Zarembski |
0:01f31e923fe2 | 273 | } |
Pawel Zarembski |
0:01f31e923fe2 | 274 | |
Pawel Zarembski |
0:01f31e923fe2 | 275 | uint32_t info_get_crc_bootloader() |
Pawel Zarembski |
0:01f31e923fe2 | 276 | { |
Pawel Zarembski |
0:01f31e923fe2 | 277 | return crc_bootloader; |
Pawel Zarembski |
0:01f31e923fe2 | 278 | } |
Pawel Zarembski |
0:01f31e923fe2 | 279 | |
Pawel Zarembski |
0:01f31e923fe2 | 280 | uint32_t info_get_crc_interface() |
Pawel Zarembski |
0:01f31e923fe2 | 281 | { |
Pawel Zarembski |
0:01f31e923fe2 | 282 | return crc_interface; |
Pawel Zarembski |
0:01f31e923fe2 | 283 | } |
Pawel Zarembski |
0:01f31e923fe2 | 284 | |
Pawel Zarembski |
0:01f31e923fe2 | 285 | uint32_t info_get_crc_config_admin() |
Pawel Zarembski |
0:01f31e923fe2 | 286 | { |
Pawel Zarembski |
0:01f31e923fe2 | 287 | return crc_config_admin; |
Pawel Zarembski |
0:01f31e923fe2 | 288 | } |
Pawel Zarembski |
0:01f31e923fe2 | 289 | |
Pawel Zarembski |
0:01f31e923fe2 | 290 | uint32_t info_get_crc_config_user() |
Pawel Zarembski |
0:01f31e923fe2 | 291 | { |
Pawel Zarembski |
0:01f31e923fe2 | 292 | return crc_config_user; |
Pawel Zarembski |
0:01f31e923fe2 | 293 | } |
Pawel Zarembski |
0:01f31e923fe2 | 294 | |
Pawel Zarembski |
0:01f31e923fe2 | 295 | void info_crc_compute() |
Pawel Zarembski |
0:01f31e923fe2 | 296 | { |
Pawel Zarembski |
0:01f31e923fe2 | 297 | crc_bootloader = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 298 | crc_interface = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 299 | crc_config_admin = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 300 | crc_config_user = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 301 | |
Pawel Zarembski |
0:01f31e923fe2 | 302 | // Compute the CRCs of regions that exist |
Pawel Zarembski |
0:01f31e923fe2 | 303 | if (DAPLINK_ROM_BL_SIZE > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 304 | crc_bootloader = crc32((void *)DAPLINK_ROM_BL_START, DAPLINK_ROM_BL_SIZE - 4); |
Pawel Zarembski |
0:01f31e923fe2 | 305 | } |
Pawel Zarembski |
0:01f31e923fe2 | 306 | |
Pawel Zarembski |
0:01f31e923fe2 | 307 | if (DAPLINK_ROM_IF_SIZE > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 308 | crc_interface = crc32((void *)DAPLINK_ROM_IF_START, DAPLINK_ROM_IF_SIZE - 4); |
Pawel Zarembski |
0:01f31e923fe2 | 309 | } |
Pawel Zarembski |
0:01f31e923fe2 | 310 | |
Pawel Zarembski |
0:01f31e923fe2 | 311 | if (DAPLINK_ROM_CONFIG_ADMIN_SIZE > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 312 | crc_config_admin = crc32((void *)DAPLINK_ROM_CONFIG_ADMIN_START, DAPLINK_ROM_CONFIG_ADMIN_SIZE); |
Pawel Zarembski |
0:01f31e923fe2 | 313 | } |
Pawel Zarembski |
0:01f31e923fe2 | 314 | |
Pawel Zarembski |
0:01f31e923fe2 | 315 | if (DAPLINK_ROM_CONFIG_USER_SIZE > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 316 | crc_config_user = crc32((void *)DAPLINK_ROM_CONFIG_USER_START, DAPLINK_ROM_CONFIG_USER_SIZE); |
Pawel Zarembski |
0:01f31e923fe2 | 317 | } |
Pawel Zarembski |
0:01f31e923fe2 | 318 | } |
Pawel Zarembski |
0:01f31e923fe2 | 319 | |
Pawel Zarembski |
0:01f31e923fe2 | 320 | // Get version info as an integer |
Pawel Zarembski |
0:01f31e923fe2 | 321 | uint32_t info_get_bootloader_version(void) |
Pawel Zarembski |
0:01f31e923fe2 | 322 | { |
Pawel Zarembski |
0:01f31e923fe2 | 323 | // Don't read version if image is not present |
Pawel Zarembski |
0:01f31e923fe2 | 324 | if (!info_get_bootloader_present()) { |
Pawel Zarembski |
0:01f31e923fe2 | 325 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 326 | } |
Pawel Zarembski |
0:01f31e923fe2 | 327 | |
Pawel Zarembski |
0:01f31e923fe2 | 328 | return info_bl->version; |
Pawel Zarembski |
0:01f31e923fe2 | 329 | } |
Pawel Zarembski |
0:01f31e923fe2 | 330 | |
Pawel Zarembski |
0:01f31e923fe2 | 331 | uint32_t info_get_interface_version(void) |
Pawel Zarembski |
0:01f31e923fe2 | 332 | { |
Pawel Zarembski |
0:01f31e923fe2 | 333 | // Don't read version if image is not present |
Pawel Zarembski |
0:01f31e923fe2 | 334 | if (!info_get_interface_present()) { |
Pawel Zarembski |
0:01f31e923fe2 | 335 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 336 | } |
Pawel Zarembski |
0:01f31e923fe2 | 337 | |
Pawel Zarembski |
0:01f31e923fe2 | 338 | return info_if->version; |
Pawel Zarembski |
0:01f31e923fe2 | 339 | } |
Pawel Zarembski |
0:01f31e923fe2 | 340 | |
Pawel Zarembski |
0:01f31e923fe2 | 341 | #if (defined(__CC_ARM)) |
Pawel Zarembski |
0:01f31e923fe2 | 342 | #pragma pop |
Pawel Zarembski |
0:01f31e923fe2 | 343 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 344 | #if (defined(__GNUC__)) |
Pawel Zarembski |
0:01f31e923fe2 | 345 | /* #pragma GCC pop_options */ |
Pawel Zarembski |
0:01f31e923fe2 | 346 | #endif |