From e83d9835953e4835dba6ef08b2a19cc4bed88322 Mon Sep 17 00:00:00 2001 From: highlander Date: Fri, 24 Apr 2026 21:40:18 -0500 Subject: [PATCH 1/3] =?UTF-8?q?fix(ci):=20unbreak=20alpha=20=E2=80=94=20fo?= =?UTF-8?q?rmat,=20TOKENS=5FCOUNT=20collision,=20const=20pointer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three pre-existing breakages on alpha that block every PR's CI: 1. lint-format failed on include/keepkey/emulator/{setup.h,libkkemu.h} — newly-merged libkkemu support landed without clang-format applied. Run: clang-format -i ... 2. build-arm-firmware-btc-only failed with TOKENS_COUNT redefined. coins.h:51 defines TOKENS_COUNT=0 in BITCOIN_ONLY builds (because the comment claims ethereum_tokens.h isn't included), but ethereum.c actually does include ethereum_tokens.h, which redefines it. Guard ethereum_tokens.h's #define with #ifndef so coins.h's BTC-only fallback wins when both are included. 3. static-analysis (cppcheck) failed on lib/emulator/libkkemu.c:167 — Canvas *c is read-only, declare as const Canvas *. --- include/keepkey/emulator/libkkemu.h | 19 ++++++++++--------- include/keepkey/emulator/setup.h | 2 +- include/keepkey/firmware/ethereum_tokens.h | 5 +++++ lib/emulator/libkkemu.c | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/keepkey/emulator/libkkemu.h b/include/keepkey/emulator/libkkemu.h index d0ef6db54..9ec93bd7d 100644 --- a/include/keepkey/emulator/libkkemu.h +++ b/include/keepkey/emulator/libkkemu.h @@ -15,24 +15,25 @@ extern "C" { #endif -#define KKEMU_FLASH_SIZE (1024 * 1024) /* 1 MB */ -#define KKEMU_PACKET_SIZE 64 /* HID report size */ -#define KKEMU_IFACE_MAIN 0 -#define KKEMU_IFACE_DEBUG 1 +#define KKEMU_FLASH_SIZE (1024 * 1024) /* 1 MB */ +#define KKEMU_PACKET_SIZE 64 /* HID report size */ +#define KKEMU_IFACE_MAIN 0 +#define KKEMU_IFACE_DEBUG 1 /** * Initialize the emulator with a host-provided flash buffer. * * @param flash_buf Pointer to 1MB buffer (host-owned, must remain valid). * If contents are all 0xFF, treated as fresh/erased device. - * If contents are from a previous session, device state is restored. + * If contents are from a previous session, device state is + * restored. * @param flash_len Must be KKEMU_FLASH_SIZE (1048576). * @return 0 on success, -1 on error. * * After this call, the emulator is ready to process messages via * kkemu_write() + kkemu_poll() + kkemu_read(). */ -int kkemu_init(uint8_t *flash_buf, size_t flash_len); +int kkemu_init(uint8_t* flash_buf, size_t flash_len); /** * Shut down the emulator. Flushes pending storage writes to the @@ -49,7 +50,7 @@ void kkemu_shutdown(void); * @param iface KKEMU_IFACE_MAIN (0) or KKEMU_IFACE_DEBUG (1). * @return 0 on success, -1 if queue is full. */ -int kkemu_write(const uint8_t *data, size_t len, int iface); +int kkemu_write(const uint8_t* data, size_t len, int iface); /** * Read a 64-byte HID report from the emulator's output queue. @@ -61,7 +62,7 @@ int kkemu_write(const uint8_t *data, size_t len, int iface); * @param iface KKEMU_IFACE_MAIN (0) or KKEMU_IFACE_DEBUG (1). * @return Number of bytes read (64), or 0 if queue is empty. */ -int kkemu_read(uint8_t *buf, size_t len, int iface); +int kkemu_read(uint8_t* buf, size_t len, int iface); /** * Run one iteration of the firmware event loop. @@ -83,7 +84,7 @@ int kkemu_poll(void); * @return Pointer to framebuffer (valid until next kkemu_poll). * Returns NULL if emulator is not initialized. */ -const uint8_t *kkemu_get_display(int *width, int *height); +const uint8_t* kkemu_get_display(int* width, int* height); /** * Check if the emulator has been initialized. diff --git a/include/keepkey/emulator/setup.h b/include/keepkey/emulator/setup.h index 683a13256..fadd9843c 100644 --- a/include/keepkey/emulator/setup.h +++ b/include/keepkey/emulator/setup.h @@ -2,6 +2,6 @@ #define KEEPKEY_EMULATOR_SETUP_H void setup(void); -void setup_urandom_only(void); /* For libkkemu: init RNG without flash mmap */ +void setup_urandom_only(void); /* For libkkemu: init RNG without flash mmap */ #endif diff --git a/include/keepkey/firmware/ethereum_tokens.h b/include/keepkey/firmware/ethereum_tokens.h index 7e26bd164..a8a19116a 100644 --- a/include/keepkey/firmware/ethereum_tokens.h +++ b/include/keepkey/firmware/ethereum_tokens.h @@ -34,7 +34,12 @@ enum { TokenIndexFirst = 0 }; +/* coins.h pre-defines TOKENS_COUNT=0 in BITCOIN_ONLY builds, where this + * header is still pulled in transitively via ethereum.c. Guard so the two + * defs don't collide. */ +#ifndef TOKENS_COUNT #define TOKENS_COUNT ((int)TokenIndexLast - (int)TokenIndexFirst) +#endif typedef struct _TokenType { const char* const address; diff --git a/lib/emulator/libkkemu.c b/lib/emulator/libkkemu.c index 03bf8b4b9..59115cf33 100644 --- a/lib/emulator/libkkemu.c +++ b/lib/emulator/libkkemu.c @@ -164,7 +164,7 @@ const uint8_t *kkemu_get_display(int *width, int *height) { if (!libkkemu_initialized) { if (width) *width = 0; if (height) *height = 0; return NULL; } - Canvas *c = display_canvas(); + const Canvas *c = display_canvas(); if (!c || !c->buffer) { if (width) *width = 0; if (height) *height = 0; return NULL; } memset(packed, 0, sizeof(packed)); From fc8f6bcf7f758b04b690d5ee98de519acc789123 Mon Sep 17 00:00:00 2001 From: highlander Date: Fri, 24 Apr 2026 21:45:53 -0500 Subject: [PATCH 2/3] fix(ci): drop coins.h's stale BTC-only TOKENS_COUNT override ethereum_tokens.h IS included in BTC-only builds (transitively via ethereum.c and ethereum_tokens.c), so the override in coins.h that forces TOKENS_COUNT=0 collides with the real definition. Single source of truth: ethereum_tokens.h owns TOKENS_COUNT. Reverts the #ifndef guard from the previous commit since coins.h no longer fights it. --- include/keepkey/firmware/coins.h | 11 +++++------ include/keepkey/firmware/ethereum_tokens.h | 5 ----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/include/keepkey/firmware/coins.h b/include/keepkey/firmware/coins.h index 0efe39229..10c8fc4a5 100644 --- a/include/keepkey/firmware/coins.h +++ b/include/keepkey/firmware/coins.h @@ -44,16 +44,15 @@ enum { CONCAT(CoinIndex, __COUNTER__), #include "keepkey/firmware/coins.def" -#ifdef BITCOIN_ONLY -// For full-featured keepkey, this is defined in ethereum_tokens.h. For bitcoin -// only keepkey, need to define it here because ethereum_tokens.h is not -// included in any file -#define TOKENS_COUNT 0 -#else +#ifndef BITCOIN_ONLY #define X(INDEX, NAME, SYMBOL, DECIMALS, CONTRACT_ADDRESS) \ CONCAT(CoinIndex, __COUNTER__), #include "keepkey/firmware/tokens.def" #endif +/* TOKENS_COUNT is owned by ethereum_tokens.h. The BTC-only override that + * used to live here was based on a stale invariant — ethereum_tokens.h is + * actually pulled in transitively in BTC-only builds, so the override + * collided with the real define. */ CoinIndexLast, CoinIndexFirst = 0 }; diff --git a/include/keepkey/firmware/ethereum_tokens.h b/include/keepkey/firmware/ethereum_tokens.h index a8a19116a..7e26bd164 100644 --- a/include/keepkey/firmware/ethereum_tokens.h +++ b/include/keepkey/firmware/ethereum_tokens.h @@ -34,12 +34,7 @@ enum { TokenIndexFirst = 0 }; -/* coins.h pre-defines TOKENS_COUNT=0 in BITCOIN_ONLY builds, where this - * header is still pulled in transitively via ethereum.c. Guard so the two - * defs don't collide. */ -#ifndef TOKENS_COUNT #define TOKENS_COUNT ((int)TokenIndexLast - (int)TokenIndexFirst) -#endif typedef struct _TokenType { const char* const address; From d93f54b00f5114d2f07812baf2a737ed8dc56b71 Mon Sep 17 00:00:00 2001 From: highlander Date: Fri, 24 Apr 2026 21:55:14 -0500 Subject: [PATCH 3/3] style: clang-format coins.h after TOKENS_COUNT cleanup --- include/keepkey/firmware/coins.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/keepkey/firmware/coins.h b/include/keepkey/firmware/coins.h index 10c8fc4a5..e04f6dc85 100644 --- a/include/keepkey/firmware/coins.h +++ b/include/keepkey/firmware/coins.h @@ -49,10 +49,10 @@ enum { CONCAT(CoinIndex, __COUNTER__), #include "keepkey/firmware/tokens.def" #endif -/* TOKENS_COUNT is owned by ethereum_tokens.h. The BTC-only override that - * used to live here was based on a stale invariant — ethereum_tokens.h is - * actually pulled in transitively in BTC-only builds, so the override - * collided with the real define. */ + /* TOKENS_COUNT is owned by ethereum_tokens.h. The BTC-only override that + * used to live here was based on a stale invariant — ethereum_tokens.h is + * actually pulled in transitively in BTC-only builds, so the override + * collided with the real define. */ CoinIndexLast, CoinIndexFirst = 0 };