summaryrefslogtreecommitdiff
path: root/tools
AgeCommit message (Collapse)Author
2020-03-11tools/codeformat.py: Eliminate need for sizeof fixup.David Lechner
This eliminates the need for the sizeof regex fixup by rearranging things a bit. All other bitfields already use the parentheses around expressions with sizeof, so one case is fixed by following this convention. VM_MAX_STATE_ON_STACK is the only remaining problem and it can be worked around by changing the order of the operands.
2020-03-11tools/metrics.py: Use check_call instead of run to error out on error.Damien George
2020-03-05tools/makemanifest.py: Fix build on Windows by adding .exe to mpy-cross.MikeTeachman
When using a manifest on Windows the reference to mpy-cross compiler was missing the .exe file extension, so add it when appropriate. Also allow the default path to mpy-cross to be overridden by the (optional) MICROPY_MPYCROSS environment variable, to allow full flexibility on any OS.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28tools/codeformat.py: Add formatter using uncrustify for C, black for Py.Damien George
This commit adds a tool, codeformat.py, which will reformat C and Python code to fit a certain style. By default the tool will reformat (almost) all the original (ie not 3rd-party) .c, .h and .py files in this repository. Passing filenames on the command-line to codeformat.py will reformat only those. Reformatting is done in-place. uncrustify is used for C reformatting, which is available for many platforms and can be easily built from source, see https://github.com/uncrustify/uncrustify. The configuration for uncrustify is also added in this commit and values are chosen to best match the existing code style. A small post-processing stage on .c and .h files is done by codeformat.py (after running uncrustify) to fix up some minor items: - space inserted after * when used as multiplication with sizeof - #if/ifdef/ifndef/elif/else/endif are dedented by one level when they are configuring if-blocks and case-blocks. For Python code, the formatter used is black, which can be pip-installed; see https://github.com/psf/black. The defaults are used, except for line- length which is set at 99 characters to match the "about 100" line-length limit used in C code. The formatting tools used and their configuration were chosen to strike a balance between keeping existing style and not changing too many lines of code, and enforcing a relatively strict style (especially for Python code). This should help to keep the code consistent across everything, and reduce cognitive load when writing new code to match the style.
2020-02-20tools/makemanifest.py: Support freezing with empty list of mpy files.Damien George
Fixes issue #5655.
2020-02-01tools/pyboard.py: Change shebang to use python3.Michael Buesch
This script still works with Python 2 but Python 3 is recommended.
2020-02-01tools/pyboard.py: Use slice del instead of list.clear() for Py2 compat.Michael Buesch
Python 2 does not have list.clear().
2020-02-01tools/pyboard.py: Add option --no-follow to detach after sending script.Michael Buesch
This option makes pyboard.py exit as soon as the script/command is successfully sent to the device, ie it does not wait for any output. This can help to avoid hangs if the board is being rebooted with --comman (for example). Example usage: $ python3 ./tools/pyboard.py --device /dev/ttyUSB0 --no-follow \ --command 'import machine; machine.reset()'
2020-01-23tools/pydfu.py: Clean up syntax, update comments and docstrings.c0rejump
Some parts of code have been aligned to increase readability. In general '' instead of "" were used wherever possible to keep the same convention for entire file. Import inspect line has been moved to the top according to hints reported by pep8 tools. A few extra spaces were removed, a few missing spaces were added. Comments have been updated, mostly in "read_dfu_file" function. Some other comments have been capitalized and/or slightly updated. A few docstrings were fixed as well. No real code changes intended.
2020-01-23tools: Add metrics.py script to build and compute port sizes/metrics.Damien George
2020-01-06tools/gen-cpydiff.py: Adjust subsections to sentence case.Jason Neal
2019-12-19tools/tinytest-codegen.py: Add extra newline and result message.David Lechner
This is an alternative to f4ed2df that adds a newline so that the output of the test starts on a new line and the result of the test is prefixed with "result: " to distinguish it from the test output. Suggested-by: @dpgeorge
2019-12-19tools/pyboard.py: Support executing .mpy files directly.Damien George
This patch allows executing .mpy files (including native ones) directly on a target, eg a board over a serial connection. So there's no need to copy the file to its filesystem to test it. For example: $ mpy-cross foo.py $ pyboard.py foo.mpy
2019-12-17py/persistentcode: Move loading of rodata/bss to before obj/raw-code.Damien George
This makes the loading of viper-code-with-relocations a bit neater and easier to understand, by treating the rodata/bss like a special object to be loaded into the constant table (which is how it behaves).
2019-12-12tools/mpy-tool.py: Raise exception if trying to freeze relocatable mpy.Damien George
2019-12-12py/dynruntime: Add support for float API to make/get floats.Damien George
We don't want to add a feature flag to .mpy files that indicate float support because it will get complex and difficult to use. Instead the .mpy is built using whatever precision it chooses (float or double) and the native glue API will convert between this choice and what the host runtime actually uses.
2019-12-12tools/mpy_ld.py: Add new mpy_ld.py tool and associated build files.Damien George
This commit adds a new tool called mpy_ld.py which is essentially a linker that builds .mpy files directly from .o files. A new header file (dynruntime.h) and makefile fragment (dynruntime.mk) are also included which allow building .mpy files from C source code. Such .mpy files can then be dynamically imported as though they were a normal Python module, even though they are implemented in C. Converting .o files directly (rather than pre-linked .elf files) allows the resulting .mpy to be more efficient because it has more control over the relocations; for example it can skip PLT indirection. Doing it this way also allows supporting more architectures, such as Xtensa which has specific needs for position-independent code and the GOT. The tool supports targets of x86, x86-64, ARM Thumb and Xtensa (windowed and non-windowed). BSS, text and rodata sections are supported, with relocations to all internal sections and symbols, as well as relocations to some external symbols (defined by dynruntime.h), and linking of qstrs.
2019-12-12tools/mpy-tool.py: Add ability to merge multiple .mpy files into one.Damien George
Usage: mpy-tool.py -o merged.mpy --merge mod1.mpy mod2.mpy The constituent .mpy files are executed sequentially when the merged file is imported, and they all use the same global namespace.
2019-12-12py/nativeglue: Add new header file with native function table typedef.Damien George
2019-11-28tools/mpy-tool.py: Support qstr linking when freezing Xtensa native mpy.Damien George
2019-11-13tools/makemanifest.py: Use sys.executable when invoking Python scripts.Yonatan Goldschmidt
So the version of Python used to run makemanifest.py is also used for the sub-scripts.
2019-11-07tools/makemanifest.py: Skip freezing unsupported files with warning.Andrew Leech
2019-11-06tools/makemanifest.py: Follow symlinks when freezing linked directories.Mirko Vogt
While the new manifest.py style got introduced for freezing python code into the resulting binary, the old way - where files and modules within ports/*/modules where baked into the resulting binary - was still supported via `freeze('$(PORT_DIR)/modules')` within manifest.py. However behaviour changed for symlinked directories (=modules), as those links weren't followed anymore. This commit restores the original behaviour by explicitly following symlinks within a modules/ directory
2019-11-04tools/mpy-tool.py: Use "@progbits #" attribute for native xtensa code.Damien George
2019-10-21tools/makemanifest.py: Eval relative paths w.r.t. current manifest file.Jim Mussared
When loading a manifest file, e.g. by include(), it will chdir first to the directory of that manifest. This means that all file operations within a manifest are relative to that manifest's location. As a consequence of this, additional environment variables are needed to find absolute paths, so the following are added: $(MPY_LIB_DIR), $(PORT_DIR), $(BOARD_DIR). And rename $(MPY) to $(MPY_DIR) to be consistent. Existing manifests are updated to match.
2019-10-15tools: Add mechanism to provide a manifest of frozen files.Damien George
This introduces a new build variable FROZEN_MANIFEST which can be set to a manifest listing (written in Python) that describes the set of files to be frozen in to the firmware.
2019-10-15tools/make-frozen.py: Allow to run with no directory passed in.Damien George
In which case it will just emit empty frozen C definitions.
2019-10-15py/persistentcode: Make .mpy more compact with qstr directly in prelude.Damien George
Instead of encoding 4 zero bytes as placeholders for the simple_name and source_file qstrs, and storing the qstrs after the bytecode, store the qstrs at the location of these 4 bytes. This saves 4 bytes per bytecode function stored in a .mpy file (for example lcd160cr.mpy drops by 232 bytes, 4x 58 functions). And resulting code size is slightly reduced on ports that use this feature.
2019-10-05py: Add new Xtensa-Windowed arch for native emitter.Damien George
Enabled via the configuration MICROPY_EMIT_XTENSAWIN.
2019-10-01py: Rework and compress second part of bytecode prelude.Damien George
This patch compresses the second part of the bytecode prelude which contains the source file name, function name, source-line-number mapping and cell closure information. This part of the prelude now begins with a single varible length unsigned integer which encodes 2 numbers, being the byte-size of the following 2 sections in the header: the "source info section" and the "closure section". After decoding this variable unsigned integer it's possible to skip over one or both of these sections very easily. This scheme saves about 2 bytes for most functions compared to the original format: one in the case that there are no closure cells, and one because padding was eliminated.
2019-10-01py: Compress first part of bytecode prelude.Damien George
The start of the bytecode prelude contains 6 numbers telling the amount of stack needed for the Python values and exceptions, and the signature of the function. Prior to this patch these numbers were all encoded one after the other (2x variable unsigned integers, then 4x bytes), but using so many bytes is unnecessary. An entropy analysis of around 150,000 bytecode functions from the CPython standard library showed that the optimal Shannon coding would need about 7.1 bits on average to encode these 6 numbers, compared to the existing 48 bits. This patch attempts to get close to this optimal value by packing the 6 numbers into a single, varible-length unsigned integer via bit-wise interleaving. The interleaving scheme is chosen to minimise the average number of bytes needed, and at the same time keep the scheme simple enough so it can be implemented without too much overhead in code size or speed. The scheme requires about 10.5 bits on average to store the 6 numbers. As a result most functions which originally took 6 bytes to encode these 6 numbers now need only 1 byte (in 80% of cases).
2019-09-26py/persistentcode: Bump .mpy version to 5.Damien George
The bytecode opcodes have changed (there are more, and they have been reordered).
2019-09-26py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.Josh Lloyd
Fixes #5140.
2019-09-26py/bc: Replace big opcode format table with simple macro.Damien George
2019-09-26py/bc0: Order opcodes into groups based on their size and format.Damien George
2019-09-06tools/mpy-tool.py: Fix freezing of non-bytecode funcs with settrace.Damien George
Only bytecode functions can be profiled at this stage. Native functions (eg inline assembler) may not even have a valid prelude. Fixes issue #5075.
2019-09-02py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.Damien George
Prior to this patch mp_opcode_format would calculate the incorrect size of the MP_BC_UNWIND_JUMP opcode, missing the additional byte. But, because opcodes below 0x10 are unused and treated as bytes in the .mpy load/save and freezing code, this bug did not show any symptoms, since nested unwind jumps would rarely (if ever) reach a depth of 16 (so the extra byte of this opcode would be between 0x01 and 0x0f and be correctly loaded/saved/frozen simply as an undefined opcode). This patch fixes this bug by correctly accounting for the additional byte. .
2019-08-30tools/mpy-tool.py: Add initial support for frozen with settrace.Damien George
2019-08-30tests: Add tests for sys.settrace feature.Milan Rossa
2019-08-20qemu-arm: Add testing of frozen native modules.Jim Mussared
- Split 'qemu-arm' from 'unix' for generating tests. - Add frozen module to the qemu-arm test build. - Add test that reproduces the requirement to half-word align native function data.
2019-08-20tools/mpy-tool.py: Force native func alignment to halfword/word on ARM.Jim Mussared
This is necessary for ARMV6 and V7. Without this change, calling a frozen native/viper function that is misaligned will crash.
2019-07-25tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files.Damien George
Use "-f" to select filesystem mode, followed by the command to execute. Optionally put ":" at the start of a filename to indicate that it's on the remote device, if it would otherwise be ambiguous. Examples: $ pyboard.py -f ls $ pyboard.py -f cat main.py $ pyboard.py -f cp :main.py . # get from device $ pyboard.py -f cp main.py : # put to device $ pyboard.py -f rm main.py
2019-07-01tools: Add uf2conv.py from Microsoft/uf2 repository.Damien George
Repository https://github.com/Microsoft/uf2 commit 19615407727073e36d81bf239c52108ba92e7660
2019-06-28py: Define EMIT_MACHINE_CODE as EMIT_NATIVE || EMIT_INLINE_ASM.Jun Wu
The combination MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM is used in many places, so define a new macro for it.
2019-06-11tools/mpy-tool.py: Fix linking of qstr objects in native ARM Thumb code.Damien George
Previously, when linking qstr objects in native code for ARM Thumb, the index into the machine code was being incremented by 4, not 8. It should be 8 to account for the size of the two machine instructions movw and movt. This patch makes sure the index into the machine code is incremented by the correct amount for all variations of qstr linking. See issue #4829.
2019-06-04tools/mpy-tool.py: Fix linking qstrs in native code, and multiple files.Damien George
Fixes errors in the tool when 1) linking qstrs in native ARM-M code; 2) freezing multiple files some of which use native code and some which don't. Fixes issue #4829.
2019-05-15tools/upip.py: Add support for multiple index URLs with custom default.Damien George
The user can now select their own package index by either passing the "-i" command line option, or setting the upip.index_urls variable (before doing an install). The https://micropython.org/pi package index hosts packages from micropython-lib and will be searched first when installing a package. If a package is not found here then it will fallback to PyPI.
2019-04-25tools/pyboard.py: Don't accumulate output data if data_consumer used.Damien George
Prior to this patch, when a lot of data was output by a running script pyboard.py would try to capture all of this output into the "data" variable, which would gradually slow down pyboard.py to the point where it would have large CPU and memory usage (on the host) and potentially lose data. This patch fixes this problem by not accumulating the data in the case that the data is not needed, which is when "data_consumer" is used.
2019-04-08tools/mpy-tool.py: Fix init of QStrWindow, and remove unused variable.Damien George
The qstr window size is not log-2 encoded, it's just the actual number (but in mpy-tool.py this didn't lead to an error because the size is just used to truncate the window so it doesn't grow arbitrarily large in memory). Addresses issue #4635.