REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
hashflash.h
Go to the documentation of this file.
1#ifndef UTILS_HASH_FLASH_H
2#define UTILS_HASH_FLASH_H
3
4#include "utils/dcp.h" // utils::hash_sha256
5#include <ArduinoJson.h>
6#include <array>
7#include <cstdio> // sprintf
8#include <string>
9
10// defined in the Teensy default linker script imxrt1062_t41.ld
11extern unsigned long _flashimagelen;
12// typically hardcoded everywhere, but see also the linker script.
13constexpr unsigned long flash_origin = 0x60000000;
14
15namespace loader {
16
17struct flashimage {
28 static uint32_t len() { return (uint32_t)&_flashimagelen; };
29
41 auto *flash = (const uint8_t *)flash_origin;
42 return utils::sha256(flash, len());
43 // sha256_t checksum;
44 // utils::hash_sha256(flash, flashimagelen(), checksum.data());
45 // return checksum;
46 };
47
48 static void toJson(JsonVariant target) {
49 target["size"] = len();
50 target["sha256sum"] = sha256sum().to_string();
51 }
52};
53
54inline void convertToJson(const flashimage &src, JsonVariant info) { src.toJson(info); }
55
56} // namespace loader
57
58#endif /* UTILS_HASH_FLASH_H */
uint32_t
Definition flasher.cpp:195
uint32_t src
Definition flasher.cpp:63
constexpr unsigned long flash_origin
Definition hashflash.h:13
unsigned long _flashimagelen
void convertToJson(const GlobalPluginLoader &src, JsonVariant dst)
Definition plugin.cpp:99
static utils::sha256 sha256sum()
Computes a SHA256 hash of the program image stored on Flash.
Definition hashflash.h:40
static uint32_t len()
Returns the number of bytes of the flash image.
Definition hashflash.h:28
static void toJson(JsonVariant target)
Definition hashflash.h:48
std::string to_string() const
Definition dcp.h:67