need help to recompile firmware

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
rikun99
Posts: 5
Joined: Wed Oct 06, 2021 11:19 am

need help to recompile firmware

Post by rikun99 » Wed Oct 06, 2021 11:30 am

Hi all, i just joined now for suggestions.
I have a pico and i'm using the micropython port for rp2 board, trying to use uhashlib.sha1(), but it gives error: module object has no attribute sha1.
It seems that the official firmware has only sha256 implemented.

I'm trying to compile micropython from source, editing the file /micropython/ports/rp2/mpconfigport.h By default only #define MICROPY_PY_UHASHLIB (1) is present; i tried to add #define MICROPY_PY_UHASHLIB_SHA1 (1) but the compiling process results in this error:

Code: Select all

Building C object CMakeFiles/firmware.dir/pico/micropython/extmod/moduhashlib.c.obj
In file included from /pico/micropython/py/mpstate.h:35:0,
from /pico/micropython/py/runtime.h:29,
from /pico/micropython/extmod/moduhashlib.c:30:
/pico/micropython/extmod/moduhashlib.c:249:60: error: 'uhashlib_sha1_digest' undeclared here (not in a function); did you mean 'uhashlib_sha256_digest'?
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha1_digest_obj, uhashlib_sha1_digest);
^
/pico/micropython/py/obj.h:337:42: note: in definition of macro 'MP_DEFINE_CONST_FUN_OBJ_1'
{{&mp_type_fun_builtin_1}, .fun._1 = fun_name}
^~~~~~~~
/pico/micropython/extmod/moduhashlib.c:260:17: error: 'uhashlib_sha1_make_new' undeclared here (not in a function); did you mean 'uhashlib_sha256_make_new'?
.make_new = uhashlib_sha1_make_new,
^~~~~~~~~~~~~~~~~~~~~~
uhashlib_sha256_make_new
/pico/micropython/extmod/moduhashlib.c:171:17: error: 'uhashlib_sha1_update' used but never defined [-Werror]
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [CMakeFiles/firmware.dir/build.make:2219: CMakeFiles/firmware.dir/pico/micropython/extmod/moduhashlib.c.obj] Error 1
What else should i modify to have the micropython compiled with sha1 support?
Adding external libraries?

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: need help to recompile firmware

Post by hippy » Wed Oct 06, 2021 5:09 pm

Looking at '/micropython/extmod/moduhashlib.c' the SHA1 stuff is wrapped in "#if MICROPY_SSL_AXTLS".

You could try adding "#define MICROPY_SSL_AXTLS (1)" to 'mpconfigport.h' though I don't know what other affect that will have. Or just comment out the "#if" and "#endif" to continue until there's a definitive answer forthcoming.

I got compilation completing but it failed at linking. I didn't pursue it further.

rikun99
Posts: 5
Joined: Wed Oct 06, 2021 11:19 am

Re: need help to recompile firmware

Post by rikun99 » Fri Oct 08, 2021 8:09 am

Thanks for the tip, i added #define MICROPY_SSL_AXTLS (1) and did git submodule update --init lib/axtls
The compilation works but as you said, it errors out at linking

Code: Select all

Linking CXX executable firmware.elf
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/firmware.dir/pico/micropython/extmod/moduhashlib.c.obj: in function `uhashlib_sha1_digest':
moduhashlib.c:(.text.uhashlib_sha1_digest+0x1c): undefined reference to `SHA1_Final'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/firmware.dir/pico/micropython/extmod/moduhashlib.c.obj: in function `uhashlib_sha1_update':
moduhashlib.c:(.text.uhashlib_sha1_update+0x20): undefined reference to `SHA1_Update'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/firmware.dir/pico/micropython/extmod/moduhashlib.c.obj: in function `uhashlib_sha1_make_new':
moduhashlib.c:(.text.uhashlib_sha1_make_new+0x22): undefined reference to `SHA1_Init'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/firmware.dir/build.make:4426: firmware.elf] Error 1
make[2]: *** [CMakeFiles/Makefile2:1511: CMakeFiles/firmware.dir/all] Error 2
make[1]: *** [Makefile:84: all] Error 2
make: *** [Makefile:19: all] Error 2
should i modify a CMake file too?

Post Reply