[SOLVED] Error when building Micropython

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

[SOLVED] Error when building Micropython

Post by shazz » Sun May 05, 2019 3:39 pm

Hi,
I try to build MicroPython for Meowbit now that the source code is released but at the beginning of the compilation (and for any STM boards) on Ubuntu 18.10, I have this error:

Code: Select all

sudo apt-get install gcc-arm-none-eabi binutils-arm-none-eabi
git clone --recurse-submodules https://github.com/KittenBot/micropython_meowbit.git
cd micropython_meowbit/

cd ports/stm32/
make BOARD=MEOWBIT V=1
	
Python ../../py/makeversionhdr.py build-MEOWBIT/genhdr/mpversion.h
GEN build-MEOWBIT/frozen_mpy.c
python ../../tools/mpy-tool.py -f -q build-MEOWBIT/genhdr/qstrdefs.preprocessed.h  > build-MEOWBIT/frozen_mpy.c
usage: mpy-tool.py [-h] [-d] [-f] [-q QSTR_HEADER]
                   [-mlongint-impl {none,longlong,mpz}] [-mmpz-dig-size N]
                   files [files ...]
mpy-tool.py: error: too few arguments
make: *** [../../py/mkrules.mk:123: build-MEOWBIT/frozen_mpy.c] Error 2
make: *** Deleting file 'build-MEOWBIT/frozen_mpy.c'
Not sure what this mpy-tool.py is...

Looks like $(FROZEN_MPY_MPY_FILES) is empty..

Any idea ?
Last edited by shazz on Mon May 06, 2019 12:01 am, edited 2 times in total.
8bits should be enough...

quark
Posts: 4
Joined: Sun May 05, 2019 3:22 pm

Re: Error when building Micropython

Post by quark » Sun May 05, 2019 5:27 pm

The mpy-tool.py extracts static strings, precalculatestheir hashes, and generate C code that can be embedded in the main program.

It seems your python binary didn't notice the -f -q ... flags for some reason. I'd try to debug it by writing a simple python program like:

[code]
# a.py
import sys
print(sys.argv)
[/code]

and run it using python a.py foo bar to test if foo bar gets printed out. If it does not, then try to use `which python`, and read its content to get some clues.

User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

Re: Error when building Micropython

Post by shazz » Sun May 05, 2019 6:05 pm

it gives:

Code: Select all

python a.py foo bar
['a.py', 'foo', 'bar']

which python
/usr/bin/python

python --version
Python 2.7.15+
Do I need to set python3 as the default version for python ?
Could it be a problem with

Code: Select all

# make a list of all the .py files that need compiling and freezing
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)/==')
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/frozen_mpy/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
8bits should be enough...

quark
Posts: 4
Joined: Sun May 05, 2019 3:22 pm

Re: Error when building Micropython

Post by quark » Sun May 05, 2019 6:24 pm

Interesting. I'd just try running the command `make` runs:

python ../../tools/mpy-tool.py -f -q build-MEOWBIT/genhdr/qstrdefs.preprocessed.h > build-MEOWBIT/frozen_mpy.c

and see how it breaks. python2 works for me. But you can try replacing python with python3. You can also try editing mpy-tool.py directly to narrow down the cause. Maybe the argparse module is somehow broken?

User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

Re: Error when building Micropython

Post by shazz » Sun May 05, 2019 6:31 pm

Same result. With python2 and python3.

But doesn't it miss the arguments "file" before the > ?

Code: Select all

python ../../tools/mpy-tool.py -f -q build-MEOWBIT/genhdr/qstrdefs.preprocessed.h > build-MEOWBIT/frozen_mpy.c

from
usage: mpy-tool.py [-h] [-d] [-f] [-q QSTR_HEADER]
                   [-mlongint-impl {none,longlong,mpz}] [-mmpz-dig-size N]
                   files [files ...]
8bits should be enough...

User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

Re: Error when building Micropython

Post by shazz » Sun May 05, 2019 6:36 pm

Ok... I tried to compile from the https://github.com/micropython repo and here it works. So I guess something is broken in the meowbit fork.
I'll ask the devs...
8bits should be enough...

User avatar
jimmo
Posts: 885
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Error when building Micropython

Post by jimmo » Sun May 05, 2019 10:14 pm

quark wrote:
Sun May 05, 2019 5:27 pm
The mpy-tool.py extracts static strings, precalculatestheir hashes, and generate C code that can be embedded in the main program.
That's actually makeqstrdefs.py / makeqstrdata.py.

mpy-tool is the tool that takes a bunch of .mpy files (generated by the .mpy cross compiler, which are python files compiled into bytecode) and includes them into your firmware image. This is really useful for stuff like drivers that you want to be part of ROM and not have to worry about putting on the filesystem.

The usual process for an STM32 board is that python code is placed in ports/stm32/boards/BOARD/modules, you point at this by overriding FROZEN_MPY_DIR in BOARD/mpconfigboard.mk, and this generates .mpy files that are then frozen. Otherwise it uses the default directory which is ports/stm32/modules.

For some reason, the meowbit team have removed the contents of all the files in ports/stm32/modules. (i.e. the files are there just empty). This means that the Makefile step that creates the intermediate .mpy files finds them, but generates no .mpy files. This means the makefile ends up passing no files to mpy-tool to generate the frozen object.

The quick solution just to get you moving is to add a file to ports/stm32/modules (e.g. meow.py) with a single line in it like 'x = 0' (anything that will generate some actual bytecode) and run the build again. Then eventually you can continue to add drivers (but do it in boards/MEOWBIT/modules and update mpconfigboard.mk as described above)

User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

Re: Error when building Micropython

Post by shazz » Mon May 06, 2019 12:01 am

Thanks Jimmo!
Works like that!

I still wonder how it could compile for the Meowbit devs...
8bits should be enough...

User avatar
jimmo
Posts: 885
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: [SOLVED] Error when building Micropython

Post by jimmo » Mon May 06, 2019 12:10 am

My guess is that they have some Python code (e.g. drivers) somewhere else (outside of the MicroPython tree), and they set an environment variable to point to that when they make their builds, overriding the default path. Might be worth following up with them?

User avatar
shazz
Posts: 46
Joined: Tue Apr 30, 2019 6:35 pm
Contact:

Re: [SOLVED] Error when building Micropython

Post by shazz » Mon May 06, 2019 1:16 am

Yeah, I asked them the question.... (one upon a lot :D)
8bits should be enough...

Post Reply