You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
2 years ago
|
/*
|
||
|
* This file is part of the Trezor project, https://trezor.io/
|
||
|
*
|
||
|
* Copyright (c) SatoshiLabs
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "board_capabilities.h"
|
||
|
#include <string.h>
|
||
|
#include "common.h"
|
||
|
|
||
|
#define handle_fault(msg) \
|
||
|
(__fatal_error("Fault detected", msg, __FILE__, __LINE__, __func__))
|
||
|
|
||
2 years ago
|
static uint32_t board_name = 0;
|
||
2 years ago
|
|
||
|
static struct BoardloaderVersion boardloader_version;
|
||
|
|
||
2 years ago
|
const uint32_t get_board_name() { return board_name; }
|
||
2 years ago
|
|
||
|
const struct BoardloaderVersion *get_boardloader_version() {
|
||
|
return &boardloader_version;
|
||
|
}
|
||
|
|
||
|
void parse_boardloader_capabilities() {
|
||
|
const uint8_t *pos = (const uint8_t *)BOARD_CAPABILITIES_ADDR;
|
||
|
const uint8_t *end =
|
||
|
(const uint8_t *)(BOARD_CAPABILITIES_ADDR + BOARD_CAPABILITIES_SIZE);
|
||
|
|
||
|
if (memcmp(pos, CAPABILITIES_HEADER, 4) != 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
pos += 4;
|
||
|
|
||
|
// -2 for possible tag without any data
|
||
|
while (pos <= end - 2) {
|
||
|
enum CapabilityTag tag = pos[0];
|
||
|
uint8_t length = pos[1];
|
||
|
pos += 2;
|
||
|
|
||
|
if (pos + length > end) {
|
||
|
handle_fault("Bad capabilities format.");
|
||
|
}
|
||
|
|
||
|
switch (tag) {
|
||
1 year ago
|
case TAG_CAPABILITY:
|
||
2 years ago
|
// not used yet, just advance pointer
|
||
|
break;
|
||
1 year ago
|
case TAG_MODEL_NAME:
|
||
2 years ago
|
if (length != sizeof(uint32_t)) {
|
||
|
break;
|
||
|
}
|
||
|
memcpy((uint8_t *)&board_name, pos, sizeof(uint32_t));
|
||
2 years ago
|
break;
|
||
1 year ago
|
case TAG_BOARDLOADER_VERSION:
|
||
2 years ago
|
if (length != sizeof(boardloader_version)) {
|
||
|
break;
|
||
|
}
|
||
|
memcpy(&boardloader_version, pos, length);
|
||
|
break;
|
||
1 year ago
|
case TAG_TERMINATOR:
|
||
2 years ago
|
return;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
pos += length;
|
||
|
}
|
||
|
}
|