[SOLVED] Building RP2 firmware with frozen modules.

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
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

[SOLVED] Building RP2 firmware with frozen modules.

Post by pythoncoder » Tue Feb 08, 2022 6:59 pm

I can't get this to work. I can build the firmware, but it seems to pick up the default manifest rather than mine. My build script is:

Code: Select all

cd /mnt/qnap2/data/Projects/MicroPython/micropython/ports/rp2
MANIFEST='/mnt/qnap2/Scripts/manifests/rp2_manifest.py'
make submodules
make clean
if make -j 8 BOARD=PICO FROZEN_MANIFEST=$MANIFEST
then
    echo Firmware is in build-PICO/firmware.uf2
else
    echo Build failure
fi
cd -
The manifest file is

Code: Select all

include("$(MPY_DIR)/ports/rp2/boards/manifest.py")
freeze('/mnt/qnap2/Scripts/modules/rp2_modules')
and the directory /mnt/qnap2/Scripts/modules/rp2_modules contains a couple of Python files. These are not being cross-compiled.

The above approach works with Pyboards. I can make some sense of the makefile for Pyboard but the RP2 one devolves everything to Cmake which is a closed book to me. So I'm at sea trying to figure out what's going on.
Peter Hinch
Index to my micropython libraries.

yjchun
Posts: 10
Joined: Fri Aug 27, 2021 8:04 pm

Re: Has anyone built RP2 firmware with frozen modules?

Post by yjchun » Wed Feb 09, 2022 12:25 pm

rp2 port is missing FROZEN_MANIFEST option. Just made PR request https://github.com/micropython/micropython/pull/8280 for this.
For the moment, this is part of my build script:

Code: Select all

...
# modify rp2 manifest file
# https://docs.micropython.org/en/latest/reference/manifest.html?highlight=manifest
MANIFEST_PY=$MP_SRCDIR/ports/rp2/boards/manifest.py
if ! grep -Fq "$SRCDIR" ${MANIFEST_PY}
then
	mv -f $MANIFEST_PY ${MANIFEST_PY}_orig
	cp -f ${MANIFEST_PY}_orig $MANIFEST_PY
	contents="\ninclude(\"$SRCDIR/tools/manifest.py\")\n"
	printf $contents >> $MANIFEST_PY
fi

# build firmware
make USER_C_MODULES=../../../ulab/code/micropython.cmake || exit

# clean up
mv -f ${MANIFEST_PY}_orig $MANIFEST_PY

# upload to PICO via SWD
if [[ $# -eq 1 && $1 == '-upload' ]]; then
	scp ./build-PICO/firmware.elf piw:t/ || exit
	ssh piw 'openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "program t/firmware.elf verify reset exit"'
fi
Also included how I upload firmware via SWD, connected to a pi zero w laying around.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Has anyone built RP2 firmware with frozen modules?

Post by pythoncoder » Wed Feb 09, 2022 1:16 pm

Excellent! I've patched my makefile and it works fine.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: [SOLVED] Building RP2 firmware with frozen modules.

Post by pythoncoder » Fri Feb 11, 2022 5:24 pm

Alas your PR has fallen foul of the commit message conventions. I don't know why the maintainers impose this B&D approach, but there you are ;)
Peter Hinch
Index to my micropython libraries.

Post Reply