From 64971f1a65aed54e6a1c041d069c2cb75f2dd64b Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Tue, 23 Sep 2025 22:52:44 +0200 Subject: py/persistentcode: Add architecture flags check for RV32 platforms. This commit introduces the MPY architecture flags checking code specific for the RV32 target, currently checking for the only additional extension that is supported by the runtime: Zba. The warnings inside "mpy-cross" have also been removed since now there is a way to reject incompatible MPY files at runtime. Signed-off-by: Alessandro Gatti --- py/persistentcode.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'py/persistentcode.c') diff --git a/py/persistentcode.c b/py/persistentcode.c index 7d71cfd98..b12c10074 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -63,6 +63,10 @@ typedef struct _bytecode_prelude_t { uint code_info_size; } bytecode_prelude_t; +#if MICROPY_EMIT_RV32 +#include "py/asmrv32.h" +#endif + #endif // MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE #if MICROPY_PERSISTENT_CODE_LOAD @@ -485,8 +489,19 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) { size_t arch_flags = 0; if (MPY_FEATURE_ARCH_FLAGS_TEST(header[2])) { - (void)arch_flags; - mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file")); + #if MICROPY_EMIT_RV32 + arch_flags = read_uint(reader); + + if (MPY_FEATURE_ARCH_TEST(MP_NATIVE_ARCH_RV32IMC)) { + if ((arch_flags & (size_t)asm_rv32_allowed_extensions()) != arch_flags) { + mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file")); + } + } else + #endif + { + (void)arch_flags; + mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file")); + } } size_t n_qstr = read_uint(reader); -- cgit v1.2.3