Commit Graph

327 Commits

Author SHA1 Message Date
Steve App 326dd7f0db tools/makemanifest.py: Show directory name if there is a FreezeError. 2021-04-29 12:36:07 +10:00
iabdalkader 0f78c36c5a tools/gen-cpydiff.py: Fix formatting of doc strings for new Black.
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see https://github.com/psf/black/pull/1740

This commit makes the Python code in this repository conform to this rule.
2021-04-27 23:41:21 +10:00
Damien George 178198a01d tools/pyboard.py: Support opening serial port in exclusive mode.
This is now the default, but can be overridden with CLI `--no-exclusive`,
or constructing `Pyboard(..., exclusive=False)`.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-23 22:41:00 +10:00
Damien George ac1d01d43e tools/upip.py: Use .errno instead of .args[0] for OSError exceptions.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-23 22:03:46 +10:00
David Michieli 5669a60954 stm32/mboot: Allow unpacking dfu without secret key.
- unpack-dfu command no longer requies a secret key to be present
- pack-dfu command raises an exception if no secret key is found
2021-04-23 11:04:37 +10:00
Damien George b74dc546fc tools/metrics.py: Add rp2 port to table of ports that can be built.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-20 21:39:53 +10:00
Damien George a9bbf7083e tools/ci.sh: Build esp32 using IDF v4.0.2 and v4.3.
To test different IDF's, and also test building the GENERIC_S2 board.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-15 10:31:06 +10:00
Damien George d35f12f5ca tools/metrics.py: Fix esp32 output filename due to move to CMake.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-06 12:50:19 +10:00
Damien George d87f42b0e5 examples/usercmodules: Simplify user C module enabling.
It's a bit of a pitfall with user C modules that including them in the
build does not automatically enable them.  This commit changes the docs and
examples for user C modules to encourage writers of user C modules to
enable them unconditionally.  This makes things simpler and covers most use
cases.

See discussion in issue #6960, and also #7086.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-01 16:27:38 +11:00
Michael O'Cleirigh 17b1f82121 tools/ci.sh: Build user C modules for esp32.
Builds the esp32 port against the example C and CXX modules.

Signed-off-by: Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
2021-04-01 15:44:10 +11:00
Phil Howard 5976ea02a5 tools/ci.sh: Add CI for CMake USER_C_MODULE support.
Builds the rp2 port against the example C and CXX modules.

Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-31 00:28:52 +11:00
Damien George 6129b8e401 tests: Rename run-tests to run-tests.py for consistency.
Signed-off-by: Damien George <damien@micropython.org>
2021-03-12 19:56:09 +11:00
Damien George cdaec0dcaf tools/pydfu.py: Support DFU files with elements of zero size.
Instead of raising a ZeroDivisionError, this tool now just skips any
elements in the DFU file that have zero size.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-23 14:33:31 +11:00
iTitou d334d781e1 tools/verifygitlog.py: Show required format regexp in error message.
Signed-off-by: iTitou <moiandme@gmail.com>
2021-02-21 15:55:44 +11:00
David Michieli 2eed9780ba stm32/mboot: Add unpack-dfu command to mboot_pack_dfu.py tool.
This command unpacks a previously packed DFU file, writing out a DFU which
should be the same as the original (before packing).
2021-02-17 11:36:44 +11:00
Maureen Helm 56a36899bd tools/ci.sh: Update zephyr docker image to v0.11.13.
Updates the zephyr docker image to the latest, v0.11.13. This updates CI
to use zephyr SDK v0.12.2 and GCC v10.2.0 for the zephyr port.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-02-16 09:01:05 -06:00
Maureen Helm f573e73bae zephyr: Build MicroPython as a cmake target.
Refactors the zephyr build infrastructure to build MicroPython as a
cmake target, using the recently introduced core cmake rules.

This change makes it possible to build the zephyr port like most other
zephyr applications using west or cmake directly. It simplifies building
with extra cmake arguments, such as specifying an alternate conf file or
adding an Arduino shield. It also enables building the zephyr port
anywhere in the host file system, which will allow regressing across
multiple boards with the zephyr twister script.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-02-16 18:49:30 +11:00
Maureen Helm 2aa57931a6 zephyr: Update to zephyr v2.5.0.
Updates the zephyr port build instructions and CI to use the latest
zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-02-16 18:38:13 +11:00
Jim Mussared 566020034f tools/makemanifest.py: Allow passing option args to include().
This allows customising which features can be enabled in a frozen library.

e.g. `include("path.py", extra_features=True)`

in path.py:

    options.defaults(standard_features=True)

    if options.standard_features:
        # freeze standard modules.
    if options.extra_features:
        # freeze extra modules.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-02-16 17:24:21 +11:00
Damien George aa3d6b6aa5 tools/ci.sh: Change esp32 CI to work with idf.py and IDF v4.0.2.
Signed-off-by: Damien George <damien@micropython.org>
2021-02-15 16:40:11 +11:00
Brianna Laugher d128999938 tools: Add filesystem action examples to pyboard.py help.
Signed-off-by: Brianna Laugher <brianna.laugher@gmail.com>
2021-02-13 14:37:28 +11:00
Damien George c9260dda23 rp2: Use local tinyusb instead of the one in pico-sdk.
So that all MicroPython ports that use tinyusb use the same version.  Also
requires fewer submodule checkouts when building rp2 along with other ports
that use tinyusb.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-12 12:56:28 +11:00
stijn c2b5bfcc0c tools: Remove obsolete upip bootstrap script.
The upip module is frozen into ports supporting it, and it is included in
the source tree, so there is no need to get it from PyPi.  Moreover the
PyPi package referred to is an out-of-date version of upip which is
basically unrelated to our upip.py because the source is taken from a fork
of micropython-lib instead of this repository.
2021-01-30 14:39:22 +11:00
Jim Mussared 2aecf378be tools/makemanifest.py: Add check that freeze path is a directory.
Avoids accidentally writing

    freeze("path/to/file.py")

and getting unexpected results.
2021-01-30 14:15:33 +11:00
stijn 37c2f507a0 github/workflows: Add workflow to verify commit message format.
Using the new tools/verifygitlog.py script.
2021-01-30 14:09:21 +11:00
stijn d48860c7dd tools/verifygitlog.py: Add script for verifying commit message format.
The main rules enforced are:
- At most 72 characters in the subject line, with a ": " in it.
- At most 75 characters per line in the body.
- No "noreply" email addresses.
2021-01-30 14:08:29 +11:00
Damien George b8f4c623f9 github/workflows: Add CI workflow for rp2 port.
Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00
Damien George fe16e785fe tools/mpy-tool.py: List frozen modules in MICROPY_FROZEN_LIST_ITEM.
Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 23:57:10 +11:00
Damien George 5d68b5e22c tools/ci.sh: For ci_code_size_setup, update apt to install gcc-multilib.
Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 23:57:10 +11:00
Damien George 203e1d2a65 tools/ci.sh: For code size build, fetch history of master branch only.
It's not necessary to fetch all branches.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-24 15:02:20 +11:00
Damien George de2374cdc6 tools/ci.sh: Pip install pyhy for stm32 builds.
Signed-off-by: Damien George <damien@micropython.org>
2021-01-18 12:43:01 +11:00
Damien George ee52f89224 tools/ci.sh: Use pip-install to get latest version of esptool.py.
Because the version included in xtensa-lx106-elf-standalone.tar.gz needs
Python 2 (and pyserial for Python 2).

Signed-off-by: Damien George <damien@micropython.org>
2020-12-14 13:09:33 +11:00
Damien George 69262a11dc tools/ci.sh: Put echo of CI path in a separate function.
Because the setup functions may print other information which should not be
added to the path.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-14 13:05:43 +11:00
Damien George cb1bb7592e stm32/Makefile: Change -O0 to -Og for DEBUG=1 builds.
The -Og optimisation level produces a more realistic build, gives a better
debugging experience, and generates smaller code than -O0, allowing debug
builds to fit in flash.

This commit also assigns variables in can.c to prevent warnings when -Og is
used, and builds a board in CI with DEBUG=1 enabled.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-07 22:27:38 +11:00
Damien George a59282b9bf tools/pyboard.py: Add fast raw-paste mode.
This commit adds support to pyboard.py for the new raw REPL paste mode.

Note that this new pyboard.py is fully backwards compatible with old
devices (it detects if the device supports the new raw REPL paste mode).

Signed-off-by: Damien George <damien@micropython.org>
2020-12-01 22:35:13 +11:00
Damien George 547e8a9fe7 tools/ci.sh: Add helper script to run CI tasks.
The aim is for this script to be used on any CI platform, as well as run
locally.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-29 22:21:28 +11:00
awachtler 56e0932485 tools/upip.py: Support explicit port number in host.
Adding a port number other then 443 to a PyPI URL may be needed if a local
server like devpi is used.
2020-10-20 12:44:30 +11:00
stijn 4b35aa5730 tools: Write msvc-compatible frozen content.
The msvc compiler doesn't accept zero-sized arrays so let the freezing
process generate compatible C code in case no modules are found and the
involved arrays are all empty.  This doesn't affect the functionality in
any way because those arrays only get accessed when mp_frozen_mpy_names
contains names, i.e.  when modules are actually found.
2020-09-11 10:51:55 +10:00
Damien George 4f2fe34623 tools/mpy-tool.py: Fix merge of multiple mpy files to POP_TOP correctly.
MP_BC_CALL_FUNCTION will leave the result on the Python stack, so that
result must be discarded by MP_BC_POP_TOP.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-09 00:11:51 +10:00
Damien George 06659077a8 all: Update Python code to conform to latest black formatting.
Updating to Black v20.8b1 there are two changes that affect the code in
this repository:

- If there is a trailing comma in a list (eg [], () or function call) then
  that list is now written out with one line per element.  So remove such
  trailing commas where the list should stay on one line.

- Spaces at the start of """ doc strings are removed.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 15:18:01 +10:00
Damien George 448319a745 tools/makemanifest.py: Use os.makedirs to make path for generated files.
The existing implementation of mkdir() in this file is not sophisticated
enough to work correctly on all operating systems (eg Mac can raise
EISDIR).  Using the standard os.makedirs() function handles all cases
correctly.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 11:18:48 +10:00
Martin Milata 492cf34fd8 tools/mpy-tool.py: Fix offset of line number info.
Signed-off-by: Martin Milata <martin@martinmilata.cz>
2020-08-21 16:17:07 +10:00
Michael Buesch 60cf2c0959 tools/pyboard.py: Replace eval() of received data with alternative.
Prior to this commit, pyboard.py used eval() to "parse" file data received
from the board.  Using eval() on received data from a device is dangerous,
because a malicious device may inject arbitrary code execution on the PC
that is doing the operation.

Consider the following scenario:

Eve may write a malicious script to Bob's board in his absence.  On return
Bob notices that something is wrong with the board, because it doesn't work
as expected anymore.  He wants to read out boot.py (or any other file) to
see what is wrong.  What he gets is a remote code execution on his PC.

Proof of concept:

Eve:

  $ cat boot.py
  _print = print
  print = lambda *x, **y: _print("os.system('ls /; echo Pwned!')", end="\r\n\x04")
  $ ./pyboard.py -f cp boot.py :
  cp boot.py :boot.py

Bob:

  $ ./pyboard.py -f cp :boot.py /tmp/foo
  cp :boot.py /tmp/foo
  bin   chroot  dev  home  lib32  media  opt   root  sbin  sys  usr
  boot  config  etc  lib   lib64  mnt    proc  run   srv   tmp  var
  Pwned!

There's also the possibility that the device is malfunctioning and sends
random and possibly dangerous data back to the PC, to be eval'd.

Fix this problem by using ast.literal_eval() to parse the received bytes,
instead of eval().

Signed-off-by: Michael Buesch <m@bues.ch>
2020-08-21 16:08:03 +10:00
Damien George b731bd0ce6 tools/makemanifest.py: Print nicely formatted errors from mpy-cross.
If mpy-cross exits with an error be sure to print that error in a way that
is readable, instead of a long bytes object.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-08 14:46:05 +10:00
Damien George 952de5cb77 tools/makemanifest.py: Use errno.EEXIST instead of number 17.
To make this code more portable, across different platforms.

Signed-off-by: Damien George <damien@micropython.org>
2020-07-26 10:56:24 +10:00
Thorsten von Eicken 3e758ef235 lib/mbedtls_errors: Add code to patch mbedtls for shortened error strs.
The file `mbedtls_errors/mp_mbedtls_errors.c` can be used instead of
`mbedtls/library/error.c` to give shorter error strings, reducing the build
size of the error strings from about 12-16kB down to about 2-5kB.
2020-07-20 23:53:27 +10:00
Andrew Leech 07f181a216 Revert "tools/pydfu.py: Respect longer timeouts requested by DFU dev..."
This reverts commit 4d6f60d428.

This implementation used the timeout as a maximum amount of time needed for
the operation, when actually the spec and other tools suggest that it's the
minumum delay needed between subsequent USB transfers.
2020-07-01 16:54:03 +10:00
Andrew Leech 4d6f60d428 tools/pydfu.py: Respect longer timeouts requested by DFU device/mboot. 2020-06-30 21:22:00 +10:00
Damien George 76faeed098 tools/makemanifest.py: Support freezing a subdirectory recursively.
This adds support for freezing an entire directory while keeping the
directory as part of the import path.  For example

    freeze("path/to/library", "module")

will recursively freeze all scripts in "path/to/library/module" and have
them importable as "from module import ...".

Signed-off-by: Damien George <damien@micropython.org>
2020-06-24 12:21:30 +10:00
David Lechner 77ed6f69ac tools/uncrustify: Enable more opts to remove space between func and '('.
With only `sp_func_proto_paren = remove` set there are some cases where
uncrustify misses removing a space between the function name and the
opening '('.  This sets all of the related options to `force` as well.
2020-06-19 22:07:32 +10:00