SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (ModusToolbox)
Loading...
Searching...
No Matches
fw_hash.h
Go to the documentation of this file.
1/*******************************************************************************
2 * File Name: fw_hash.h
3 *
4 * Description: Boot-time SHA-256 of the active firmware image. Used by the
5 * Bento Desktop Buddy firmware-update flow so the
6 * desktop can compare the running image against a reference and
7 * so the on-device Y/N physical-ack prompt can
8 * display a stable hash prefix.
9 *
10 * Implementation strategy:
11 *
12 * We do NOT pre-bake the hash into the hex at link time — that
13 * requires a circular reservation + post-link patch step and
14 * adds a fragile tool dependency to the build pipeline. Instead
15 * the firmware computes SHA-256 over a known flash region at
16 * boot and caches the hex string in RAM. The trade-off is a
17 * one-time ~80 ms CPU hit on boot in exchange for no build-
18 * pipeline complexity.
19 *
20 * Boundaries:
21 * Hash window covers the CM33_NS application code region only
22 * (start/end derived from symbols exported by the linker
23 * script). Bootloader + HSM regions are excluded because they
24 * sit on a different flash bank and are not part of the image
25 * the desktop can patch via OpenOCD.
26 *
27 * Call fw_hash_compute_at_boot() ONCE early in main() before the
28 * Bento Buddy UI comes up. Safe to call multiple times — second
29 * call is a no-op.
30 *
31 ******************************************************************************/
32
33#ifndef FW_HASH_H
34#define FW_HASH_H
35
36#include <stddef.h>
37#include <stdint.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* SHA-256 hex string length (64 lowercase hex digits + trailing NUL). */
44#define FW_HASH_HEX_LEN (65)
45
46/* Compute SHA-256 over the CM33_NS code region and cache the result.
47 * Idempotent. Falls back to the sentinel "unknown" if mbedtls is unavailable
48 * or the linker symbols cannot be resolved at boot. */
50
51/* Return a pointer to the cached 64-char lowercase hex digest + trailing NUL.
52 * Always non-NULL — returns "unknown" before fw_hash_compute_at_boot(). */
53const char *fw_hash_hex(void);
54
55/* Return the first 8 hex chars of the cached digest as a NUL-terminated
56 * C string into `out8` (MUST be at least 9 bytes). Useful for the LCD
57 * physical-ack prompt, which only displays a short prefix. */
58void fw_hash_prefix8(char *out9);
59
60/* Diagnostic snapshot exposed via `bento.fw.query`'s `_diag` block.
61 * Populated each time fw_hash_compute_at_boot() runs. Lets the desktop
62 * verify the SHA-256 is deterministic across boots (production support
63 * for F2.5 — surfaced after a real-hardware session showed two
64 * different hashes for one binary across two power-cycles). */
65typedef struct {
66 uint32_t compute_count; /* total times compute_at_boot() executed */
67 uintptr_t vtor_addr; /* VTOR register value seen on last compute */
68 uint8_t window_head[8]; /* first 8 bytes of the hashed flash window */
70
72
73#ifdef __cplusplus
74}
75#endif
76
77#endif /* FW_HASH_H */
void fw_hash_get_diagnostics(fw_hash_diag_t *out)
เติม snapshot ข้อมูลวินิจฉัยของ hash ที่ผู้เรียกเป็นเจ้าของ สำหรับบล็อก _diag ของ bento....
void fw_hash_prefix8(char *out9)
เขียน hex 8 อักขระแรก + NUL ลงใน out9 (ต้องมีอย่างน้อย 9 ไบต์) ไม่มีผู้เรียกที่ใดเลย
void fw_hash_compute_at_boot(void)
คำนวณและแคช digest อัตลักษณ์แบบ SHA-256 ไว้ (ราว 80 ms หนึ่งครั้ง) เป็น idempotent
const char * fw_hash_hex(void)
digest 64 อักขระที่แคชไว้ ไม่เป็น NULL เสมอ — ได้ "unknown" ก่อนการคำนวณ ห้าม free ค่านี้
Definition fw_hash.h:65
uint32_t compute_count
Definition fw_hash.h:66
uintptr_t vtor_addr
Definition fw_hash.h:67
uint8_t window_head[8]
Definition fw_hash.h:68