New logging and more (#446)

- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>`
- Changed default timezone to Europe/Amsterdam
- Fix for logic bug in unPhone hardware
- Fix for init/deinit in DRV2605 driver
- Other fixes
- Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
+12 -11
View File
@@ -1,7 +1,7 @@
#include "Tactility/crypt/Crypt.h"
#include <Tactility/crypt/Crypt.h>
#include "Tactility/Check.h"
#include "Tactility/Log.h"
#include <Tactility/Check.h>
#include <Tactility/Logger.h>
#include <mbedtls/aes.h>
#include <cstring>
@@ -15,7 +15,8 @@
namespace tt::crypt {
#define TAG "secure"
static const auto LOGGER = Logger("Crypt");
#define TT_NVS_NAMESPACE "tt_secure"
#ifdef ESP_PLATFORM
@@ -27,7 +28,7 @@ static void get_hardware_key(uint8_t key[32]) {
uint8_t mac[8];
// MAC can be 6 or 8 bytes
size_t mac_length = esp_mac_addr_len_get(ESP_MAC_EFUSE_FACTORY);
TT_LOG_I(TAG, "Using MAC with length %u", mac_length);
LOGGER.info("Using MAC with length {}", mac_length);
tt_check(mac_length <= 8);
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
@@ -66,13 +67,13 @@ static void get_nvs_key(uint8_t key[32]) {
esp_err_t result = nvs_open(TT_NVS_NAMESPACE, NVS_READWRITE, &handle);
if (result != ESP_OK) {
TT_LOG_E(TAG, "Failed to get key from NVS (%s)", esp_err_to_name(result));
LOGGER.error("Failed to get key from NVS ({})", esp_err_to_name(result));
tt_crash("NVS error");
}
size_t length = 32;
if (nvs_get_blob(handle, "key", key, &length) == ESP_OK) {
TT_LOG_I(TAG, "Fetched key from NVS (%d bytes)", length);
LOGGER.info("Fetched key from NVS ({} bytes)", length);
tt_check(length == 32);
} else {
// TODO: Improved randomness
@@ -83,7 +84,7 @@ static void get_nvs_key(uint8_t key[32]) {
key[i] = (uint8_t)(rand());
}
ESP_ERROR_CHECK(nvs_set_blob(handle, "key", key, 32));
TT_LOG_I(TAG, "Stored new key in NVS");
LOGGER.info("Stored new key in NVS");
}
nvs_close(handle);
@@ -109,8 +110,8 @@ static void xorKey(const uint8_t* inLeft, const uint8_t* inRight, uint8_t* out,
*/
static void getKey(uint8_t key[32]) {
#if !defined(CONFIG_SECURE_BOOT) || !defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
TT_LOG_W(TAG, "Using tt_secure_* code with secure boot and/or flash encryption disabled.");
TT_LOG_W(TAG, "An attacker with physical access to your ESP32 can decrypt your secure data.");
LOGGER.warn("Using tt_secure_* code with secure boot and/or flash encryption disabled.");
LOGGER.warn("An attacker with physical access to your ESP32 can decrypt your secure data.");
#endif
#ifdef ESP_PLATFORM
@@ -121,7 +122,7 @@ static void getKey(uint8_t key[32]) {
get_nvs_key(nvs_key);
xorKey(hardware_key, nvs_key, key, 32);
#else
TT_LOG_W(TAG, "Using unsafe key for debugging purposes.");
LOGGER.warn("Using unsafe key for debugging purposes.");
memset(key, 0, 32);
#endif
}