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/coins.h b/include/keepkey/firmware/coins.h index 0efe39229..e04f6dc85 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/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));