From 2f2b90535ae22c07ebaa19cc2f61cf9f0b0ee97f Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Thu, 8 Jan 2026 14:59:34 +0000 Subject: [PATCH] firmware: use C versions of memcpy and memmove for ARM Cortex-M The ARM assembly versions of memcpy and memmove try to directly modify the PC based on the number of bytes to be copied as an "optimization"; but this only works if instructions are guaranteed to be 4 bytes wide. This trick is completely broken on Cortex-M, since an instruction can be 2-4 bytes wide: for example a memcpy of 4 bytes ends up storing 32 bytes worth of garbage to the target address! Use the C memcpy/memmove implementations for Cortex-M instead; fixing the ASM version is more trouble than it's worth. Change-Id: I695587fd585ec25ef276f2dbc61e2290b7015e13 --- firmware/asm/SOURCES | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/firmware/asm/SOURCES b/firmware/asm/SOURCES index 5aa9b1c0f7..dc8d7b5dfc 100644 --- a/firmware/asm/SOURCES +++ b/firmware/asm/SOURCES @@ -1,5 +1,7 @@ #if defined(CPU_ARM) +#if defined(CPU_ARM_CLASSIC) arm/ffs.S +#endif arm/memset16.S #elif defined(CPU_MIPS) mips/ffs.S @@ -13,11 +15,17 @@ memset16.c #endif #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(HAVE_ROCKBOX_C_LIBRARY) -#if defined(CPU_ARM) +#if defined(CPU_ARM_CLASSIC) arm/memcpy.S arm/memmove.S arm/memset.S strlen.c +#elif defined(CPU_ARM_MICRO) +memcpy.c +mempcpy.c +memmove.c +arm/memset.S +strlen.c #elif defined(CPU_MIPS) mips/memcpy.S memmove.c