qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
17.77k stars 38.05k forks source link

[Bug] Large external EEPROM fails on AVR #8742

Open tzarc opened 4 years ago

tzarc commented 4 years ago

Describe the Bug

All the eeprom function signatures provided by avr-libc accept a void* address parameter for the EEPROM offset. This causes problems with AVR when attempting to address 32kB (using signed offsets) or 64kB (when using unsigned).

ChibiOS/ARM reuse the same function signatures to ensure compatibility across the rest of QMK -- these have no issue with addressing as the pointer size is 32-bit.

Suggested fix

Xelus22 commented 3 years ago

Similarly, dynamic_keymap uses uint16_t uint16_t dynamic_keymap_macro_get_buffer_size(void);

In config.h defining - which is 256kB of EEPROM: #define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 262144

results in an overflow given by the compiler: quantum/dynamic_keymap.c:72:46: error: unsigned conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} changes value from '255676' to '59068' [-Werror=overflow] 72 | # define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + 1) | ^ quantum/dynamic_keymap.c:149:62: note: in expansion of macro 'DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE' 149 | uint16_t dynamic_keymap_macro_get_buffer_size(void) { return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors [ERRORS]