Wykres commitów

668 Commity (master)

Autor SHA1 Wiadomość Data
Damien George c1b9d2259e py/dynruntime.mk: Add basic support for armv6m architecture.
The examples/natmod features0 and features1 examples now build and run on
ARMv6-M platforms.  More complicated examples are not yet supported because
the compiler emits references to built-in functions like __aeabi_uidiv.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-23 23:01:25 +10:00
Damien George d4d53e9e11 py/emitnative: Access qstr values using indirection table qstr_table.
This changes the native emitter to access qstr values using the qstr
indirection table qstr_table, but only when generating native code that
will be saved to a .mpy file.  This makes the resulting native code fully
static, ie it does not require any fix-ups or rewriting when it is
imported.

The performance of native code is more or less unchanged.  Benchmark
results on PYBv1.0 (using --via-mpy and --emit native) are:

N=100 M=100          baseline -> this-commit     diff      diff% (error%)
bm_chaos.py            407.16 ->     411.85 :   +4.69 =  +1.152% (+/-0.01%)
bm_fannkuch.py         100.89 ->     101.20 :   +0.31 =  +0.307% (+/-0.01%)
bm_fft.py             3521.17 ->    3441.72 :  -79.45 =  -2.256% (+/-0.00%)
bm_float.py           6707.29 ->    6644.83 :  -62.46 =  -0.931% (+/-0.00%)
bm_hexiom.py            55.91 ->      55.41 :   -0.50 =  -0.894% (+/-0.00%)
bm_nqueens.py         5343.54 ->    5326.17 :  -17.37 =  -0.325% (+/-0.00%)
bm_pidigits.py         603.89 ->     632.79 :  +28.90 =  +4.786% (+/-0.33%)
core_qstr.py            64.18 ->      64.09 :   -0.09 =  -0.140% (+/-0.01%)
core_yield_from.py     313.61 ->     311.11 :   -2.50 =  -0.797% (+/-0.03%)
misc_aes.py            654.29 ->     659.75 :   +5.46 =  +0.834% (+/-0.02%)
misc_mandel.py        4205.10 ->    4272.08 :  +66.98 =  +1.593% (+/-0.01%)
misc_pystone.py       3077.79 ->    3128.39 :  +50.60 =  +1.644% (+/-0.01%)
misc_raytrace.py       388.45 ->     393.71 :   +5.26 =  +1.354% (+/-0.01%)
viper_call0.py         576.83 ->     566.76 :  -10.07 =  -1.746% (+/-0.05%)
viper_call1a.py        550.39 ->     540.12 :  -10.27 =  -1.866% (+/-0.11%)
viper_call1b.py        438.32 ->     432.09 :   -6.23 =  -1.421% (+/-0.11%)
viper_call1c.py        442.96 ->     436.11 :   -6.85 =  -1.546% (+/-0.08%)
viper_call2a.py        536.31 ->     527.37 :   -8.94 =  -1.667% (+/-0.04%)
viper_call2b.py        378.99 ->     377.50 :   -1.49 =  -0.393% (+/-0.08%)

Signed-off-by: Damien George <damien@micropython.org>
2022-05-23 15:43:06 +10:00
Damien George 1fb01bd6c5 py/emitnative: Put a pointer to the native prelude in child_table array.
Some architectures (like esp32 xtensa) cannot read byte-wise from
executable memory.  This means the prelude for native functions -- which is
usually located after the machine code for the native function -- must be
placed in separate memory that can be read byte-wise.  Prior to this commit
this was achieved by enabling N_PRELUDE_AS_BYTES_OBJ for the emitter and
MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ for the runtime.  The prelude was
then placed in a bytes object, pointed to by the module's constant table.

This behaviour is changed by this commit so that a pointer to the prelude
is stored either in mp_obj_fun_bc_t.child_table, or in
mp_obj_fun_bc_t.child_table[num_children] if num_children > 0.  The reasons
for doing this are:

1. It decouples the native emitter from runtime requirements, the emitted
   code no longer needs to know if the system it runs on can/can't read
   byte-wise from executable memory.

2. It makes all ports have the same emitter behaviour, there is no longer
   the N_PRELUDE_AS_BYTES_OBJ option.

3. The module's constant table is now used only for actual constants in the
   Python code.  This allows further optimisations to be done with the
   constants (eg constant deduplication).

Code size change for those ports that enable the native emitter:
   unix x64:   +80 +0.015%
      stm32:   +24 +0.004% PYBV10
    esp8266:   +88 +0.013% GENERIC
      esp32:   -20 -0.002% GENERIC[incl -112(data)]
        rp2:   +32 +0.005% PICO

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 16:44:49 +10:00
Damien George 8725a32f41 tools/ci.sh: For esp8266 CI install esptool 3.3.1.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 16:01:56 +10:00
Damien George f8d3956c63 tools/ci.sh: Run full test suite on stackless and settrace builds.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:25:51 +10:00
Damien George c49d5207e9 py/persistentcode: Remove unicode feature flag from .mpy file.
Prior to this commit, even with unicode disabled .py and .mpy files could
contain unicode characters, eg by entering them directly in a string as
utf-8 encoded.

The only thing the compiler disallowed (with unicode disabled) was using
\uxxxx and \Uxxxxxxxx notation to specify a character within a string with
value >= 0x100; that would give a SyntaxError.

With this change mpy-cross will now accept \u and \U notation to insert a
character with value >= 0x100 into a string (because the -mno-unicode
option is now gone, there's no way to forbid this).  The runtime will
happily work with strings with such characters, just like it already works
with strings with characters that were utf-8 encoded directly.

This change simplifies things because there are no longer any feature
flags in .mpy files, and any bytecode .mpy will now run on any target.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 12:51:54 +10:00
Damien George 2ed4f7a130 tools/mpy_ld.py: Remove obsolete QSTR_WINDOW_SIZE constant.
This was made obsolete in f2040bfc7e

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 12:51:54 +10:00
Takeo Takahashi e3c880a569 tools/autobuild: Update for ports/renesas-ra.
* Add build_renesas_ra_boards call in autobuild.sh
* Add build_renesas_ra_boards function to generate firmware.hex.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-05-06 17:15:21 +09:00
Damien George aec8db3cd1 tools/uncrustify: Make sure a space exists after a comma.
This will add a space after a comma if it doesn't have one, but will allow
more than one space if the spaces are already there.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-05 13:30:40 +10:00
Takeo Takahashi 3a941cce51 tools/ci.sh: Update for ports/renesas-ra.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-04-29 12:29:07 +09:00
Damien George 81c9219375 tools/ci.sh: Don't run uasyncio_gather test on macOS.
The timing on macOS makes this test unreliable.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-21 14:25:17 +10:00
Damien George fb10d15d47 tools/codeformat.py: Include more ports .c/.h files in formatting.
This adds a rule to cover all ports/**/*.[ch] file to the code formatting
list.  Explicit exclusions are also added for code in ports/ which is third
party, or which requires a lot of reformatting.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-20 16:02:11 +10:00
Damien George 71a64545a8 tools/codeformat.py: Remove ports/unix/*.py from exclusion list.
These .py files were removed from the .gitignore in commit
3c2aa5ff93

Signed-off-by: Damien George <damien@micropython.org>
2022-04-20 16:01:11 +10:00
Damien George 07f526067e tools/mpy-tool.py: Intern more strings when freezing.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 40d431d1bb tools/mpy-tool.py: Optimise freezing of str when str data is a qstr.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George e647966fc9 tools/mpy-tool.py: Make global qstr list a dedicated class.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George dfc6c6299c tools/mpy-tool.py: Optimise freezing of empty str and bytes objects.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 9c8a56343f tools/mpy-tool.py: Optimise freezing of ints that can fit a small int.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 68b3aeeb57 tools/mpy-tool.py: Support freezing tuples and other consts.
This also simplifies how constants are frozen.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 2a075cc8a9 tools/mpy-tool.py: Support loading tuples from .mpy files.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 42d0bd2c17 py/persistentcode: Define enum values for obj types instead of letters.
To keep the separate parts of the code that use these values in sync.  And
make it easier to add new object types.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 22:44:04 +10:00
Damien George be25e333df esp32/boards: Add test manifest to test freezing during build.
Includes tests for freezing @micropython.native and @micropython.viper
code.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 14:06:38 +10:00
Rob Knegjens d3d862769a tools/mpremote: Add option to mount cmd to allow "unsafe" symlinks.
Specifying the option `--unsafe-links` (or `-l`) to `mpremote mount` will
allow symlinks to be followed in the local directory that point outside of
the base directory path.

For the unsafe case the `path_check()` method of `PyboardCommand` still
checks for a common path but without expanding symlinks.  While this check
is currently redundant, it makes the purpose of the method clearer for
possible future uses or extensions.
2022-04-11 15:15:04 +10:00
Rob Knegjens 56978c3dde tools/mpremote: Show progress indicator when copying large files.
When copying large files (> 2048 bytes) to or from a device with
`mpremote cp` a progress bar and percentage counter are temporarily shown.
2022-04-11 15:04:20 +10:00
Damien George b59989f40e rp2/Makefile: Add mbedtls to GIT_SUBMODULES list and use it in CI func.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-11 13:05:25 +10:00
Damien George 86e6744ff5 rp2: Enable ucryptolib, using mbedtls for backend functions.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-04 23:15:01 +10:00
Andrew Leech 79c05bd522 tools/mpremote: Improve reliability of mount after soft reboot.
With the existing code problems can occur with remounting, the "if t -
t_last_activity > QUIET_TIMEOUT:" check can be triggered early before the
REPL string comes through, meaning that the remount doesn't happen.

On certain boards the "MPY: soft reboot" line comes through immediately
(getting the routine past initial timeout) but then there's a slightly
longer delay while the board restarts before it prints out the startup
header and the REPL prompt.

This commit adds some extra pattern monitoring during the timeout loop to
track the state if a soft restart is actually started.
2022-04-04 16:49:38 +10:00
Waterlens 4c252ae067 tools/mpremote: Allow running mpremote with `python -m`.
This is helpful because some scripts are likely to use mpremote with a
specific python path.
2022-03-30 15:29:26 +11:00
Damien George 35dbde163a tools/mpremote: Support any prompt string when detecting soft reset.
The prompt may be changed by sys.ps1.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-28 16:47:50 +11:00
Damien George 6d11c69983 py: Change jump-if-x-or-pop opcodes to have unsigned offset argument.
These jumps are always forwards, and it's more efficient in the VM to
decode an unsigned argument.  These opcodes are already optimised versions
of the sequence "dup-top pop-jump-if-x pop" so it doesn't hurt generality
to optimise them further.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-28 15:43:09 +11:00
Damien George 538c3c0a55 py: Change jump opcodes to emit 1-byte jump offset when possible.
This commit introduces changes:

- All jump opcodes are changed to have variable length arguments, of either
  1 or 2 bytes (previously they were fixed at 2 bytes).  In most cases only
  1 byte is needed to encode the short jump offset, saving bytecode size.

- The bytecode emitter now selects 1 byte jump arguments when the jump
  offset is guaranteed to fit in 1 byte.  This is achieved by checking if
  the code size changed during the last pass and, if it did (if it shrank),
  then requesting that the compiler make another pass to get the correct
  offsets of the now-smaller code.  This can continue multiple times until
  the code stabilises.  The code can only ever shrink so this iteration is
  guaranteed to complete.  In most cases no extra passes are needed, the
  original 4 passes are enough to get it right by the 4th pass (because the
  2nd pass computes roughly the correct labels and the 3rd pass computes
  the correct size for the jump argument).

This change to the jump opcode encoding reduces .mpy files and RAM usage
(when bytecode is in RAM) by about 2% on average.

The performance of the VM is not impacted, at least within measurment of
the performance benchmark suite.

Code size is reduced for builds that include a decent amount of frozen
bytecode.  ARM Cortex-M builds without any frozen code increase by about
350 bytes.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-28 15:41:38 +11:00
David Lechner e7f6b9f4f7 tools/gen-cpydiff: Skip Black fmt comments.
Since cpydiff is code used as documentation, there are cases where we may
want to use Black's `fmt: on/off/skip` comments to avoid automatic
formatting.  However, we don't want these comments to be distracting in the
generated documentation.

This rewrites the code to omit these comments when generating the docs.

Signed-off-by: David Lechner <david@pybricks.com>
2022-03-25 12:13:00 +11:00
Damien George e316306546 stm32/mboot: Add support for reading from SD card.
Tested on PYBV10 and PYBD_SF6, with MBOOT_FSLOAD enabled and programming
new firmware from a .dfu.gz file stored on the SD card.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Maureen Helm 474d288e55 zephyr: Upgrade to Zephyr v3.0.0.
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-03-07 16:48:35 +11:00
Damien George bf01671a96 tools/mpremote: Bump version to 0.2.0.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-07 16:02:55 +11:00
Damien George 8626dcd623 tools/ci.sh: Run performance benchmark as part of all unix test runs.
This tests that the performance benchmarks run without error.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-28 19:02:58 +11:00
robert-hh 5c46721a1c tools/mpy-tool.py: Fix frozen comment generation to escape chars.
That caused the compile of frozen_content.c to fail if characters like
backslash were in a short string.  Thanks to @hippy for identifying the
spot to change.
2022-02-28 18:47:24 +11:00
Damien George 0a217624e1 tools/upip.py: Remove unused op_basename() function.
It seems this was never used, at least not since its inclusion in this
repository.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-25 18:24:03 +11:00
Damien George d6564a3159 tools/mpremote: Add "umount" command.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-25 13:10:45 +11:00
Damien George ad1f523e7e tools/mpremote: Add "resume" and "soft-reset" commands.
This makes the auto soft-reset behaviour of mpremote more logical, and now
configurable via these new commands.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-25 13:09:28 +11:00
Damien George 66fc0f45c1 tools/ci.sh: Run urandom test scripts as part of native module tests.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:29:02 +11:00
Damien George 73a1927fce github/workflows: Add new workflow to test .mpy file format and tools.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:29:02 +11:00
Damien George f2040bfc7e py: Rework bytecode and .mpy file format to be mostly static data.
Background: .mpy files are precompiled .py files, built using mpy-cross,
that contain compiled bytecode functions (and can also contain machine
code). The benefit of using an .mpy file over a .py file is that they are
faster to import and take less memory when importing.  They are also
smaller on disk.

But the real benefit of .mpy files comes when they are frozen into the
firmware.  This is done by loading the .mpy file during compilation of the
firmware and turning it into a set of big C data structures (the job of
mpy-tool.py), which are then compiled and downloaded into the ROM of a
device.  These C data structures can be executed in-place, ie directly from
ROM.  This makes importing even faster because there is very little to do,
and also means such frozen modules take up much less RAM (because their
bytecode stays in ROM).

The downside of frozen code is that it requires recompiling and reflashing
the entire firmware.  This can be a big barrier to entry, slows down
development time, and makes it harder to do OTA updates of frozen code
(because the whole firmware must be updated).

This commit attempts to solve this problem by providing a solution that
sits between loading .mpy files into RAM and freezing them into the
firmware.  The .mpy file format has been reworked so that it consists of
data and bytecode which is mostly static and ready to run in-place.  If
these new .mpy files are located in flash/ROM which is memory addressable,
the .mpy file can be executed (mostly) in-place.

With this approach there is still a small amount of unpacking and linking
of the .mpy file that needs to be done when it's imported, but it's still
much better than loading an .mpy from disk into RAM (although not as good
as freezing .mpy files into the firmware).

The main trick to make static .mpy files is to adjust the bytecode so any
qstrs that it references now go through a lookup table to convert from
local qstr number in the module to global qstr number in the firmware.
That means the bytecode does not need linking/rewriting of qstrs when it's
loaded.  Instead only a small qstr table needs to be built (and put in RAM)
at import time.  This means the bytecode itself is static/constant and can
be used directly if it's in addressable memory.  Also the qstr string data
in the .mpy file, and some constant object data, can be used directly.
Note that the qstr table is global to the module (ie not per function).

In more detail, in the VM what used to be (schematically):

    qst = DECODE_QSTR_VALUE;

is now (schematically):

    idx = DECODE_QSTR_INDEX;
    qst = qstr_table[idx];

That allows the bytecode to be fixed at compile time and not need
relinking/rewriting of the qstr values.  Only qstr_table needs to be linked
when the .mpy is loaded.

Incidentally, this helps to reduce the size of bytecode because what used
to be 2-byte qstr values in the bytecode are now (mostly) 1-byte indices.
If the module uses the same qstr more than two times then the bytecode is
smaller than before.

The following changes are measured for this commit compared to the
previous (the baseline):
- average 7%-9% reduction in size of .mpy files
- frozen code size is reduced by about 5%-7%
- importing .py files uses about 5% less RAM in total
- importing .mpy files uses about 4% less RAM in total
- importing .py and .mpy files takes about the same time as before

The qstr indirection in the bytecode has only a small impact on VM
performance.  For stm32 on PYBv1.0 the performance change of this commit
is:

diff of scores (higher is better)
N=100 M=100             baseline -> this-commit  diff      diff% (error%)
bm_chaos.py               371.07 ->  357.39 :  -13.68 =  -3.687% (+/-0.02%)
bm_fannkuch.py             78.72 ->   77.49 :   -1.23 =  -1.563% (+/-0.01%)
bm_fft.py                2591.73 -> 2539.28 :  -52.45 =  -2.024% (+/-0.00%)
bm_float.py              6034.93 -> 5908.30 : -126.63 =  -2.098% (+/-0.01%)
bm_hexiom.py               48.96 ->   47.93 :   -1.03 =  -2.104% (+/-0.00%)
bm_nqueens.py            4510.63 -> 4459.94 :  -50.69 =  -1.124% (+/-0.00%)
bm_pidigits.py            650.28 ->  644.96 :   -5.32 =  -0.818% (+/-0.23%)
core_import_mpy_multi.py  564.77 ->  581.49 :  +16.72 =  +2.960% (+/-0.01%)
core_import_mpy_single.py  68.67 ->   67.16 :   -1.51 =  -2.199% (+/-0.01%)
core_qstr.py               64.16 ->   64.12 :   -0.04 =  -0.062% (+/-0.00%)
core_yield_from.py        362.58 ->  354.50 :   -8.08 =  -2.228% (+/-0.00%)
misc_aes.py               429.69 ->  405.59 :  -24.10 =  -5.609% (+/-0.01%)
misc_mandel.py           3485.13 -> 3416.51 :  -68.62 =  -1.969% (+/-0.00%)
misc_pystone.py          2496.53 -> 2405.56 :  -90.97 =  -3.644% (+/-0.01%)
misc_raytrace.py          381.47 ->  374.01 :   -7.46 =  -1.956% (+/-0.01%)
viper_call0.py            576.73 ->  572.49 :   -4.24 =  -0.735% (+/-0.04%)
viper_call1a.py           550.37 ->  546.21 :   -4.16 =  -0.756% (+/-0.09%)
viper_call1b.py           438.23 ->  435.68 :   -2.55 =  -0.582% (+/-0.06%)
viper_call1c.py           442.84 ->  440.04 :   -2.80 =  -0.632% (+/-0.08%)
viper_call2a.py           536.31 ->  532.35 :   -3.96 =  -0.738% (+/-0.06%)
viper_call2b.py           382.34 ->  377.07 :   -5.27 =  -1.378% (+/-0.03%)

And for unix on x64:

diff of scores (higher is better)
N=2000 M=2000        baseline -> this-commit     diff      diff% (error%)
bm_chaos.py          13594.20 ->  13073.84 :  -520.36 =  -3.828% (+/-5.44%)
bm_fannkuch.py          60.63 ->     59.58 :    -1.05 =  -1.732% (+/-3.01%)
bm_fft.py           112009.15 -> 111603.32 :  -405.83 =  -0.362% (+/-4.03%)
bm_float.py         246202.55 -> 247923.81 : +1721.26 =  +0.699% (+/-2.79%)
bm_hexiom.py           615.65 ->    617.21 :    +1.56 =  +0.253% (+/-1.64%)
bm_nqueens.py       215807.95 -> 215600.96 :  -206.99 =  -0.096% (+/-3.52%)
bm_pidigits.py        8246.74 ->   8422.82 :  +176.08 =  +2.135% (+/-3.64%)
misc_aes.py          16133.00 ->  16452.74 :  +319.74 =  +1.982% (+/-1.50%)
misc_mandel.py      128146.69 -> 130796.43 : +2649.74 =  +2.068% (+/-3.18%)
misc_pystone.py      83811.49 ->  83124.85 :  -686.64 =  -0.819% (+/-1.03%)
misc_raytrace.py     21688.02 ->  21385.10 :  -302.92 =  -1.397% (+/-3.20%)

The code size change is (firmware with a lot of frozen code benefits the
most):

       bare-arm:  +396 +0.697%
    minimal x86: +1595 +0.979% [incl +32(data)]
       unix x64: +2408 +0.470% [incl +800(data)]
    unix nanbox: +1396 +0.309% [incl -96(data)]
          stm32: -1256 -0.318% PYBV10
         cc3200:  +288 +0.157%
        esp8266:  -260 -0.037% GENERIC
          esp32:  -216 -0.014% GENERIC[incl -1072(data)]
            nrf:  +116 +0.067% pca10040
            rp2:  -664 -0.135% PICO
           samd:  +844 +0.607% ADAFRUIT_ITSYBITSY_M4_EXPRESS

As part of this change the .mpy file format version is bumped to version 6.
And mpy-tool.py has been improved to provide a good visualisation of the
contents of .mpy files.

In summary: this commit changes the bytecode to use qstr indirection, and
reworks the .mpy file format to be simpler and allow .mpy files to be
executed in-place.  Performance is not impacted too much.  Eventually it
will be possible to store such .mpy files in a linear, read-only, memory-
mappable filesystem so they can be executed from flash/ROM.  This will
essentially be able to replace frozen code for most applications.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:08:43 +11:00
Damien George b1afbe3336 tools/ci.sh: Update IDF v4.4 build to use v4.4 tag.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 15:23:32 +11:00
David Lechner 5d6408f8f9 tools/verifygitlog.py: Ignore line length in body if it's a URL.
This changes the git commit message line length check to ignore lines that
contain URLs, since these cannot be wrapped without breaking tools that
detect URLs and create a link.

Signed-off-by: David Lechner <david@pybricks.com>
2022-02-18 14:33:33 +11:00
Artyom Skrobov f46a7140f5 py/qstr: Use `const` consistently to avoid a cast.
Originally at adafruit#4707

Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
2022-02-11 22:55:02 +11:00
Artyom Skrobov 18b1ba086c py/qstr: Separate hash and len from string data.
This allows the compiler to merge strings: e.g. "update",
"difference_update" and "symmetric_difference_update" will all point to the
same memory.

No functional change.

The size reduction depends on the number of qstrs in the build.  The change
this commit brings is:

   bare-arm:    -4 -0.007%
minimal x86:  +150 +0.092% [incl +48(data)]
   unix x64:  -608 -0.118%
unix nanbox:  -572 -0.126% [incl +32(data)]
      stm32: -1392 -0.352% PYBV10
     cc3200:  -448 -0.244%
    esp8266: -1208 -0.173% GENERIC
      esp32: -1028 -0.068% GENERIC[incl -1020(data)]
        nrf:  -440 -0.252% pca10040
        rp2: -1072 -0.217% PICO
       samd:  -368 -0.264% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Performance is also improved (on bare metal at least) for the
core_import_mpy_multi.py, core_import_mpy_single.py and core_qstr.py
performance benchmarks.

Originally at adafruit#4583

Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
2022-02-11 22:52:32 +11:00
Damien George fecfd52696 tools/mpremote: Fix special handling of ctrl-D when host FS is mounted.
Changes are:
- decision to remount local filesystem on remote device is made only if
  "MPY: soft reboot" is seen in the output after sending a ctrl-D
- a nice message is printed to the user when the remount occurs
- soft reset during raw REPL is now handled correctly

Fixes issue #7731.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-07 13:21:29 +11:00
Andrew Leech 203ec8ca7f tools/mpremote: Correctly manage mounted flag during soft-reset. 2022-02-04 16:19:25 +11:00
Andrew Leech b1519845f5 tools/mpremote: Accept both --help and help to show usage. 2022-02-04 15:11:04 +11:00
Andrew Leech 5a86d8dc42 tools/mpremote: During soft reboot wait long enough for 115200 data. 2022-02-04 15:09:01 +11:00
Andrew Leech d865ca53b5 tools/mpremote: Make ConsolePosix work without .raw attribute.
When running mpremote in the vscode terminal on OSX the sys.stdout.buffer
does not have the raw attribute.  It works fine without it.
2022-02-04 15:04:02 +11:00
Andrew Leech 1f84440538 tools/mpremote: Fix "fs cp -r" on Windows.
A backslash in the directory name will end up being passed through to the
device and becoming a backslash in a filename, rather than being
interpreted as directories.  This makes "cp -r" problematic on Windows.
Changing to simply "/",join() fixes this.
2022-02-04 14:58:29 +11:00
Damien George 102cc12dbb tools/autobuild: Provide .uf2 images for esp32 builds when available.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-02 23:47:49 +11:00
Damien George 59b6099508 tools/uf2conv.py: Update to latest version.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-02 23:43:58 +11:00
stijn f3229590a9 tools/ci: Test math constants with MICROPY_OBJ_REPR_D. 2022-01-23 09:28:33 +11:00
Damien George ce4f8b49ce tools/mpremote: Use machine instead of umachine in commands.
Because bare-metal boards will have machine but not always umachine.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-20 16:35:49 +11:00
Damien George 38054a57f3 tools/mpremote: Bump version to 0.1.0.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-17 09:39:38 +11:00
Damien George 49325de475 tools/ci.sh: Build zephyr nucleo_wb55rg to test zephyr bluetooth build.
And eliminate one build to reduce CI time.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-13 13:46:03 +11:00
Maureen Helm c6d26bc524 zephyr: Upgrade to Zephyr v2.7.0.
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Maureen Helm 1469e29905 tools/ci.sh: Upgrade Zephyr docker image to v0.21.0.
As a prerequisite to upgrading to Zephyr v2.7.0, upgrade CI to use
Zephyr docker image v0.21.0. In particular, this is needed to pick up a
newer CMake version because Zephyr v2.7.0 increased the minimum CMake
version required to 3.20.0.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-01-06 14:09:39 +11:00
Damien George bfe9eba484 tools/autobuild: Build esp8266 OTA image with GENERIC_1M board.
Because the GENERIC board won't fit in the flash defined by esp8266_ota.ld.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-30 15:47:49 +11:00
Damien George a29c70c9b4 esp8266: Allow building a board to any dest directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-12-30 15:47:49 +11:00
Damien George 959e6f7da9 tools/upip.py: Skip '.frozen' entry in sys.path for install path.
Signed-off-by: Damien George <damien@micropython.org>
2021-12-29 23:55:37 +11:00
Damien George 028776d97b tools/mpremote: Add link to mpremote docs URL in help message.
Signed-off-by: Damien George <damien@micropython.org>
2021-12-29 23:35:24 +11:00
Sergei Silnov 74e995dfd2 tools/mpremote: Add help command.
Fixes issue #7480
2021-12-29 09:46:33 +01:00
Michael Bentley 7566d107d5 tools/mpremote: Add mkdir and rmdir to RemoteFS.
This allows the remote MicroPython instance to create and delete
directories from the mounted host filesystem in addition to the already
existing functionality of reading, creating, and modifying files.

Signed-off-by: Michael Bentley <mikebentley15@gmail.com>
2021-12-22 12:13:39 +11:00
Jim Mussared e0bf4611c3 py: Only search frozen modules when '.frozen' is found in sys.path.
This changes makemanifest.py & mpy-tool.py to merge string and mpy names
into the same list (now mp_frozen_names).

The various paths for loading a frozen module (mp_find_frozen_module) and
checking existence of a frozen module (mp_frozen_stat) use a common
function that searches this list.

In addition, the frozen lookup will now only take place if the path starts
with ".frozen", which needs to be added to sys.path.

This fixes issues #1804, #2322, #3509, #6419.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-18 00:01:59 +11:00
Jim Mussared f853e3e106 tools/makemanifest.py: Merge make-frozen.py.
Takes the functionality from tools/make-frozen.py, adds support for
multiple frozen directories, and moves it to tools/makemanifest.py.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-17 23:54:05 +11:00
Damien George 598618e8cf tools/makemanifest.py: Make str conversion compatible with Python 2.
Signed-off-by: Damien George <damien@micropython.org>
2021-12-15 16:51:08 +11:00
Christian Decker e9f880482c tools/upip.py: Support == to specify exact package version. 2021-12-15 12:49:14 +11:00
Damien George 3f589e2f39 tools/autobuild: Automatically build all esp32 boards.
Any board with a board.json file will be built.  ESP32-based boards will be
built using the IDF at $IDF_PATH_V42, all other MCU variants (S2, S3, C3)
will be built using the IDF at $IDF_PATH_V44.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-10 21:29:27 +11:00
Damien George 67f66795c0 tools/mpremote: Implement seek and flush in ioctl method.
Fixes issue #8058.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-09 13:35:59 +11:00
Jim Mussared 3770fab334 all: Update Python formatting to latest Black version 21.12b0.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-09 12:09:40 +11:00
Damien George bb7aae557b tools/autobuild: Automatically build all stm32 boards.
Any board with a board.json file will be built.  Additional variants for
certain pyboards will also be built by the explicit build-stm32-extra.sh
script.  Both .dfu and .hex files will be made available.

Also build boards in a sorted order, and don't stop building if a single
board fails.

Signed-off-by: Damien George <damien@micropython.org>
2021-11-22 17:12:16 +11:00
Damien George 90554d03c0 stm32/boards: Build NUCLEO_WB55 and STM32F769DISC without mboot enabled.
This is to make the builds for all nucleo/discovery boards uniform, so they
can be treated the same by the auto build scripts.

The CI script is updated to explicitly enable mboot and packing, to test
these features.

Signed-off-by: Damien George <damien@micropython.org>
2021-11-22 17:12:16 +11:00
iabdalkader 43079aaf86 drivers/ninaw10: Add ublox Nina-W10 WiFi/BT module driver.
- Add WiFi/BT drivers for ublox Nina-W10 (esp32 based) module.
- Add ublox Nina-W10 Python module in extmod.
2021-11-13 23:01:03 +11:00
Damien George 1bd47db688 tools/autobuild: Automatically build all mimxrt, rp2 and samd boards.
Any board with a board.json file will be automatically built.

Signed-off-by: Damien George <damien@micropython.org>
2021-11-05 13:50:08 +11:00
Dave Hylands cb99ca9862 tools/dfu.py: Make tool work with python3 when parsing DFU files. 2021-11-01 15:46:59 +11:00
Jim Mussared ab754d5924 tools/autobuild: Add script to generate website board metadata.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-10-27 14:04:53 +11:00
Damien George 64e4bae129 tools/ci.sh: Use a specific ESP IDF v4.4 commit.
There is no release of IDF v4.4 yet but master is now on v5.0-dev so a
specific commit must be chosen to stick to v4.4.

Signed-off-by: Damien George <damien@micropython.org>
2021-10-25 23:58:44 +11:00
robert-hh dc8be7ccad tools/autobuild: Add the MIMXRT1010_EVK board to autobuild.
Having a board now available for testing, this binary can be provided with
good confidence.
2021-10-25 23:52:23 +11:00
Damien George da4593f937 tools/ci.sh: Use IDF v4.4 as part of esp32 CI and build GENERIC_S3.
IDF v4.4 does not have an official release so for now use the latest
master.  Also remove building GENERIC with no options (all the other boards
are no-option builds), to keep CI time reasonable.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-16 22:59:05 +10:00
Jim Mussared b326edf68c all: Remove MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE.
This commit removes all parts of code associated with the existing
MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE optimisation option, including the
-mcache-lookup-bc option to mpy-cross.

This feature originally provided a significant performance boost for Unix,
but wasn't able to be enabled for MCU targets (due to frozen bytecode), and
added significant extra complexity to generating and distributing .mpy
files.

The equivalent performance gain is now provided by the combination of
MICROPY_OPT_LOAD_ATTR_FAST_PATH and MICROPY_OPT_MAP_LOOKUP_CACHE (which has
been enabled on the unix port in the previous commit).

It's hard to provide precise performance numbers, but tests have been run
on a wide variety of architectures (x86-64, ARM Cortex, Aarch64, RISC-V,
xtensa) and they all generally agree on the qualitative improvements seen
by the combination of MICROPY_OPT_LOAD_ATTR_FAST_PATH and
MICROPY_OPT_MAP_LOOKUP_CACHE.

For example, on a "quiet" Linux x64 environment (i3-5010U @ 2.10GHz) the
change from CACHE_MAP_LOOKUP_IN_BYTECODE, to LOAD_ATTR_FAST_PATH combined
with MAP_LOOKUP_CACHE is:

diff of scores (higher is better)
N=2000 M=2000       bccache -> attrmapcache      diff      diff% (error%)
bm_chaos.py        13742.56 ->   13905.67 :   +163.11 =  +1.187% (+/-3.75%)
bm_fannkuch.py        60.13 ->      61.34 :     +1.21 =  +2.012% (+/-2.11%)
bm_fft.py         113083.20 ->  114793.68 :  +1710.48 =  +1.513% (+/-1.57%)
bm_float.py       256552.80 ->  243908.29 : -12644.51 =  -4.929% (+/-1.90%)
bm_hexiom.py         521.93 ->     625.41 :   +103.48 = +19.826% (+/-0.40%)
bm_nqueens.py     197544.25 ->  217713.12 : +20168.87 = +10.210% (+/-3.01%)
bm_pidigits.py      8072.98 ->    8198.75 :   +125.77 =  +1.558% (+/-3.22%)
misc_aes.py        17283.45 ->   16480.52 :   -802.93 =  -4.646% (+/-0.82%)
misc_mandel.py     99083.99 ->  128939.84 : +29855.85 = +30.132% (+/-5.88%)
misc_pystone.py    83860.10 ->   82592.56 :  -1267.54 =  -1.511% (+/-2.27%)
misc_raytrace.py   21490.40 ->   22227.23 :   +736.83 =  +3.429% (+/-1.88%)

This shows that the new optimisations are at least as good as the existing
inline-bytecode-caching, and are sometimes much better (because the new
ones apply caching to a wider variety of map lookups).

The new optimisations can also benefit code generated by the native
emitter, because they apply to the runtime rather than the generated code.
The improvement for the native emitter when LOAD_ATTR_FAST_PATH and
MAP_LOOKUP_CACHE are enabled is (same Linux environment as above):

diff of scores (higher is better)
N=2000 M=2000        native -> nat-attrmapcache  diff      diff% (error%)
bm_chaos.py        14130.62 ->   15464.68 :  +1334.06 =  +9.441% (+/-7.11%)
bm_fannkuch.py        74.96 ->      76.16 :     +1.20 =  +1.601% (+/-1.80%)
bm_fft.py         166682.99 ->  168221.86 :  +1538.87 =  +0.923% (+/-4.20%)
bm_float.py       233415.23 ->  265524.90 : +32109.67 = +13.756% (+/-2.57%)
bm_hexiom.py         628.59 ->     734.17 :   +105.58 = +16.796% (+/-1.39%)
bm_nqueens.py     225418.44 ->  232926.45 :  +7508.01 =  +3.331% (+/-3.10%)
bm_pidigits.py      6322.00 ->    6379.52 :    +57.52 =  +0.910% (+/-5.62%)
misc_aes.py        20670.10 ->   27223.18 :  +6553.08 = +31.703% (+/-1.56%)
misc_mandel.py    138221.11 ->  152014.01 : +13792.90 =  +9.979% (+/-2.46%)
misc_pystone.py    85032.14 ->  105681.44 : +20649.30 = +24.284% (+/-2.25%)
misc_raytrace.py   19800.01 ->   23350.73 :  +3550.72 = +17.933% (+/-2.79%)

In summary, compared to MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE, the new
MICROPY_OPT_LOAD_ATTR_FAST_PATH and MICROPY_OPT_MAP_LOOKUP_CACHE options:
- are simpler;
- take less code size;
- are faster (generally);
- work with code generated by the native emitter;
- can be used on embedded targets with a small and constant RAM overhead;
- allow the same .mpy bytecode to run on all targets.

See #7680 for further discussion.  And see also #7653 for a discussion
about simplifying mpy-cross options.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-09-16 16:04:03 +10:00
Philipp Ebensberger 0d7366c912 mimxrt: Rework flash configuration.
- Moves definition of BOARD_FLASH_SIZE and other header files related to
	flash configuration into the Makefile.
- Adds board specific clock_config.h.
- Adds board.h, pin_mux.h, and peripherals.h as they are
	required by NXP MCU SDK in order to use our own clock_config.h.
- Renames board specific FlexSPI configuration files.
- Updates flash frequency of MIMXRT1020_EVK
- Creates separated flash_config files for QSPI NOR and
	QSPI Hyper flash.
- Unifies VFS start address to be @ 1M for 1010 and 1020 boards.
- Unifies 1050EVK boards
- Adds support to both NOR and HyperFlash on boards with
	both capabilities.
- Adds automatic FlexRAM initialization to start-up code based on
	linker script and NXP HAL.
- Applies code formatting to all files in mimxrt port.

With this change the flash configuration is restructured and
organized. This simplifies the configuration process and
provides a better overview of each board's settings. With the integration
of clock_config.h, board.h, pin_mux.h, and peripherals.h we gain better
control of the settings and clock configurations. Furthermore the
implementation of an explicit FlexRAM setup improves the system
performance and allows for performance tuning.

Signed-off-by: Philipp Ebensberger
2021-09-14 13:52:52 +02:00
Patrick Van Oosterwijck 0ec5052f62 tools/autobuild: Add auto build for GENERIC_C3_USB. 2021-09-10 15:41:52 +10:00
Seon Rozenblum 9a7f77bfbc esp32/boards: Add new FeatherS2-Neo board definition. 2021-09-10 15:40:32 +10:00
Damien George 89145c6aad tools/mpremote: Bump version to 0.0.6.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-01 00:49:16 +10:00
David Lechner 86371781e9 tools/uncrustify: Force 1 newline at end of file.
To keep things neat and tidy, we ensure that each file has 1 and only 1
newline at the end of each file.

Signed-off-by: David Lechner <david@pybricks.com>
2021-08-31 13:14:45 +10:00
Damien George 8c4ba575fd tests/basics: Split f-string debug printing to separate file with .exp.
This feature {x=} was introduced in Python 3.8 so needs a separate .exp
file to run on earlier Python versions.

See https://bugs.python.org/issue36817

Signed-off-by: Damien George <damien@micropython.org>
2021-08-26 23:56:02 +10:00
Jim Mussared 145fedef8d tools/pyboard.py: Make --no-soft-reset consistent with other args.
This makes it work like --no-follow and --no-exclusive using a mutex group
and dest.  Although the current implementation with BooleanOptionAction is
neater it requires Python 3.9, so don't use this feature.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25 15:47:01 +10:00
Jim Mussared 064a145097 tools/pyboard.py: Add --exclusive to match --no-exclusive.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25 15:46:38 +10:00
Jim Mussared be43164d82 tools/pyboard.py: Make --no-follow use same variable as --follow.
You can set one or the other (or neither) but not both.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25 15:46:00 +10:00
Jim Mussared 2a290bbfe1 tools/pyboard.py: Move --no-exclusive/--soft-reset out of mutex group.
The --no-exclusive flag was accidentally added to the mutex group in
178198a01d.

The --soft-reset flag was accidentally added to the mutex group in
41adf17830.

These flags can be specified independently to --[no-]follow so should not
be in that mutex group.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25 15:36:00 +10:00
Damien George ed42002c39 tools/autobuild: Don't use "-B" for make, it's already a fresh build.
And using "-B" means mpy-cross is forcefully rebuilt, sometimes with
invalid CFLAGS_EXTRA options which makes the auto-build fail.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-19 23:30:17 +10:00
Damien George 226c0341ca tools/mpremote: Remove support for pyb.USB_VCP in/out specialisation.
The sys.stdin.buffer and sys.stdout.buffer streams work just as well (and
are just as fast) as pyb.USB_VCP on stm32 devices, so there's no need to
have the USB_VCP specialisation code, which just adds complexity.

Also, on stm32 devices with both USB and UART (or other serial interface),
if something other than the USB_VCP port is used for the serial connection
then mpremote mount will not work because it will default to reading and
writing on USB_VCP instead of the other connected serial stream.

As part of this simplification, support for a second port as input is
removed (this feature was never exposed to the user).

Signed-off-by: Damien George <damien@micropython.org>
2021-08-19 18:56:11 +10:00
Jim Mussared 692d36d779 py: Implement partial PEP-498 (f-string) support.
This implements (most of) the PEP-498 spec for f-strings and is based on
https://github.com/micropython/micropython/pull/4998 by @klardotsh.

It is implemented in the lexer as a syntax translation to `str.format`:
  f"{a}" --> "{}".format(a)

It also supports:
  f"{a=}" --> "a={}".format(a)

This is done by extracting the arguments into a temporary vstr buffer,
then after the string has been tokenized, the lexer input queue is saved
and the contents of the temporary vstr buffer are injected into the lexer
instead.

There are four main limitations:
- raw f-strings (`fr` or `rf` prefixes) are not supported and will raise
  `SyntaxError: raw f-strings are not supported`.

- literal concatenation of f-strings with adjacent strings will fail
    "{}" f"{a}" --> "{}{}".format(a)    (str.format will incorrectly use
                                         the braces from the non-f-string)
    f"{a}" f"{a}" --> "{}".format(a) "{}".format(a) (cannot concatenate)

- PEP-498 requires the full parser to understand the interpolated
  argument, however because this entirely runs in the lexer it cannot
  resolve nested braces in expressions like
    f"{'}'}"

- The !r, !s, and !a conversions are not supported.

Includes tests and cpydiffs.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14 16:58:40 +10:00
Damien George 162bf3c5d8 tools/mpremote: Add "devs" shortcut for "connect list".
See issue #7480.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-14 00:13:35 +10:00
Damien George 1f48934312 tools/mpremote: Fix connect-list in case VID/PID are None.
Which can be the case on Windows and macOS for certain serial devices.

Fixes issue #7636.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-14 00:13:35 +10:00
Patrick Van Oosterwijck e49f609186 tools/autobuild: Add auto build for Silicognition wESP32. 2021-08-13 23:25:24 +10:00
Jim Mussared ee549d725a tools/gen-cpydiff.py: Don't rename foo to ufoo in diff output.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-13 23:14:08 +10:00
Glenn Ruben Bakke 85f0ce214e tools/codeformat.py: Include ports/nrf/modules/nrf in code formatting. 2021-08-08 23:17:55 +10:00
Glenn Ruben Bakke 4f76f66185 tools/ci.sh: Add mpy-cross build to nrf port. 2021-08-08 23:17:55 +10:00
Damien George 96c6b8cae3 ports: Rename USBD_VID/PID config macros to MICROPY_HW_USB_VID/PID.
For consistency with other board-level config macros that begin with
MICROPY_HW_USB.

Also allow boards in the mimxrt, nrf and samd ports to configure these
values.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-07 23:13:55 +10:00
robert-hh 4445c73b11 tools/autobuild: Add the MIMXRT1050_EVKB board to the daily builds. 2021-07-31 16:27:47 +10:00
Tobias Thyrrestrup 60e3e51753 stm32/Makefile: Update to only pull in used Bluetooth library. 2021-07-31 15:11:46 +10:00
Michel Bouwmans 92464f11b0 tools/mpremote: Raise OSError on unsupported RemoteFile.seek.
Signed-off-by: Michel Bouwmans <m.bouwmans@ep-games.eu>
2021-07-23 13:21:53 +10:00
Michel Bouwmans 7870ec0370 tools/mpremote: Add seek whence for mounted files.
Fixes issue #7534.

Signed-off-by: Michel Bouwmans <m.bouwmans@ep-games.eu>
2021-07-23 13:21:42 +10:00
Seon Rozenblum 25159129dd tools/autobuild: Add FeatherS2 and TinyS2 to esp32 auto builds. 2021-07-22 22:42:37 +10:00
Damien George 0256e1ab8b tools/autobuild: Use separate IDF version to build newer esp32 SoCs.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 22:42:37 +10:00
Damien George 9f71a11d3f tools/ci.sh: Build GENERIC_C3 board as part of esp32 CI.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George cbc8d5b61f tools/ci.sh: Build unix dev variant as part of macOS CI.
To test BTstack build on macOS.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-17 23:55:25 +10:00
Damien George 0ee256b8b1 github/workflows: Add workflow to build and test unix dev variant.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-13 15:58:39 +10:00
Damien George 136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Andrew Scheller d1decdfa93 tools/mpremote: Swap order of PID and VID in connect-list output.
Fixes issue #7481.
2021-07-02 23:27:07 +10:00
Frank Pilhofer 41adf17830 tools/pyboard.py: Add cmd-line option to make soft reset configurable.
Leaves the default as-is, but allows using --no-soft-reset to disable the
soft reset when connecting.
2021-07-01 12:37:08 +10:00
robert-hh efa97beb99 tools/autobuild: Add mimxrt port to build scripts for nightly builds.
The firmware for Teensy 4.0, Teensy 4.1 and MIMXRT1020_EVK are created.
Users of other MIMXRT10xx_EVK boards should be able to build the firmware
themselves, they might need specific DEBUG settings.

The Makefile had to be changed in order to build the .bin file as well.
2021-07-01 12:29:16 +10:00
Yonatan Goldschmidt 4ada56d4cb tools/makemanifest.py: Allow passing flags to mpy-tool.py. 2021-06-28 01:50:00 +03:00
Damien George f3e4ed82a1 github/workflows: Switch from lcov to gcov.
Coverage calculated by Codecov has the same reliability/deterministic
issues as Coveralls did, so the problem is likely to do with the output of
lcov/gcov, rather than the analysis and display of the data.

Switch from lcov to gcov for data generation to try and simplify this
process of computing coverage.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-26 21:34:37 +10:00
Damien George 2dc4f843bc github/workflows: Add workflow to build and test javascript port.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-25 11:31:00 +10:00
David Lechner 8cebd56a11 tools/ci.sh: Run apt-get update in ci_powerpc_setup.
This fixes failing builds when the GitHub CI image lags behind Ubuntu
security updates.
2021-06-25 10:34:45 +10:00
Damien George c99e4995fd tools: Remove obsolete build-stm-latest.sh script.
The tools/autobuild/ scripts replace this.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 16:59:20 +10:00
Damien George 3588d14ae6 tools/autobuild: Add scripts to build release firmware.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 16:59:20 +10:00
Damien George d2dcd05adc tools/mpremote: Use signal to capture and handle ctrl-C on Windows.
Now a ctrl-C will not stop mpremote, rather this character will be passed
through to the attached device.

The mpremote version is also increased to 0.0.5.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-15 13:52:31 +10:00
Damien George 77c529e8be tools/mpremote: Use available ports instead of auto-connect list.
Using just the list of available ports, instead of a hard-coded list of
possible ports, means that all ports will be available for auto connection.
And the order that they will be attempted in will match what's printed by
"mpremote connect list" (and will be the same as before, trying ACMx before
USBx).  Auto-connect will also now work on Mac, and will allow all COM
ports on Windows.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-15 13:52:31 +10:00
Damien George 20a8f4f7ec tests/unix: Add ffi test for integer types.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-06 22:52:25 +10:00
Maureen Helm 5cb2ade65b zephyr: Update to Zephyr v2.6.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-06-06 20:17:42 +10:00
Damien George b15e1ef5a6 github/workflows: Add workflow to build and run unix port on ARM.
Following on from ef16834887, this adds a
coverage build and running of the test suite on an ARM 32-bit Linux-based
architecture.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-05 11:03:09 +10:00
Damien George 934505ac33 tools/ci.sh: Build mpy-cross as part of ci_mimxrt_build.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-02 00:02:21 +10:00
Damien George a60ad33641 tools/mpremote: Add new CLI utility to interact with remote device.
This has been under development since April 2017.  See #3034 and #6375.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-29 17:17:22 +10:00
Damien George e4ba57c5cd tools/pyboard.py: Add "soft_reset" option to Pyboard.enter_raw_repl().
Signed-off-by: Damien George <damien@micropython.org>
2021-05-29 17:17:22 +10:00
Damien George 4982d0920e tools/pyboard.py: Track raw REPL state via in_raw_repl variable.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-29 17:17:22 +10:00
Damien George ef16834887 github/workflows: Add workflow to build and run unix port on MIPS.
This adds a coverage build and running of the test suite on a MIPS 32-bit
big endian architecture.  It uses the feature of qemu to execute foreign
code as though it were native to the system (using qemu user mode).  The
code compiled for MIPS will run under the qemu VM, but all syscalls made by
this code go to the host (Linux) system.

See related #7268 and #7273.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 16:33:18 +10:00
Damien George e7c0a8bca3 tools/ci.sh: Build Cortex-A9 sabrelite board as part of qemu-arm CI.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 16:24:00 +10:00
Damien George f5cba77e50 tools/tinytest-codegen.py: Add command-line option to exclude tests.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 16:24:00 +10:00
Damien George 2c1a6a237d tools/mpy-tool.py: Support relocating ARMv6 arch.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 16:24:00 +10:00
Philipp Ebensberger 5f68f0d08a github/workflows: Add CI workflow for mimxrt port. 2021-05-26 00:12:45 +10:00
Damien George 3b950ed295 tools/ci.sh: Use FROZEN_MANIFEST in an esp32 build to test feature.
This tests that FROZEN_MANIFEST works with cmake (on esp32 at least).

Signed-off-by: Damien George <damien@micropython.org>
2021-05-23 00:01:37 +10:00
Maureen Helm a7a9f2fe89 tools/ci.sh: Update zephyr docker image to v0.17.3.
Updates the zephyr docker image and SDK to the latest versions.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-05-21 21:55:46 +10:00
Tobias Thyrrestrup 247d7e2e8e tools/pydfu.py: Remove default VID/PID values.
As the new default behaviour, this allows PyDFU to be used with all
devices, not just the ones matching a specific set of VID/PID values.  But
it's still possible to specify VID/PID if needed to narrow down the
selection of the USB device.

Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
2021-05-21 15:39:40 +10:00
Damien George 04927dfaca tools/mpy_ld.py: Support R_X86_64_GOTPCREL reloc for x86-64 arch.
This can be treated by the linker the same as R_X86_64_REX_GOTPCRELX,
according to https://reviews.llvm.org/D18301.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-20 23:34:20 +10:00
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
Damien George 026fda605e tools/codeformat.py: Include extmod/{btstack,nimble} in code formatting.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-18 22:20:20 +10:00
David Lechner b4d0d7bf03 tools/uncrustify: Update config for v0.71.0.
This is the result of running...

    uncrustify -c tools/uncrustify.cfg --update-config-with-doc -o tools/uncrustify.cfg

...with some manual fixups to correct places where it changed things it
should not have.

Essentially it just adds new config parameters introduced in v0.71.0
with their default values.

Signed-off-by: David Lechner <david@pybricks.com>
2020-06-14 11:08:05 -05:00
David Lechner ecd7826316 tools/codeformat.py: Remove sizeof fixup.
Formatting for `* sizeof` was fixed in uncrustify v0.71, so we no longer
need the fixups for it.  Also, there was one file where the updated
uncrustify caught a problem that the regex didn't pick up, which is updated
in this commit.

Signed-off-by: David Lechner <david@pybricks.com>
2020-06-14 20:24:18 +10:00
David Lechner bd7c92e17d tools/uncrustify.cfg: Remove deprecated sp_word_brace option.
This option was removed in uncrustify v0.71.

Signed-off-by: David Lechner <david@pybricks.com>
2020-06-14 20:24:03 +10:00
David Lechner 8f642677f7 tools/codeformat.py: Add verbose option to pass to uncrustify and black.
This adds a new command line option `-v` to `tools/codeformat.py` to enable
verbose printing of all files that are scanned.

Normally `uncrustify` and `black` are called with the `-q` option so
setting verbose suppresses the `-q` option and on `black` also enables the
`-v` option which makes it print out all file names matching the filter
similar to how `uncrustify` does by default.
2020-05-29 22:59:56 +10:00
David Lechner 2d1fef7096 tools/codeformat.py: Use -q option on uncrustify to make output quiet.
This suppresses the Parsing: <file> as language C lines.  This makes
parsing run a bit faster and on CI it makes for less scrolling through logs
(and black already uses the -q option).
2020-05-28 10:08:38 +10:00
stijn 84fa3312cf all: Format code to add space after C++-style comment start.
Note: the uncrustify configuration is explicitly set to 'add' instead of
'force' in order not to alter the comments which use extra spaces after //
as a means of indenting text for clarity.
2020-04-23 11:24:25 +10:00
Damien George 6e2871df59 tools/check_code_size.sh: Remove unused script.
It's now replaced by tools/metrics.py.
2020-04-22 14:07:56 +10:00
Damien George 17dc86369f tools/metrics.py: Use OrderedDict when reading build log.
So that the output (eg of the diff command) always has the lines in the
same order.
2020-04-22 14:03:26 +10:00
Damien George 1cc24cd39a tools/metrics.py: Don't build mpy-cross if not needed by any ports.
To save build time.
2020-04-22 14:03:07 +10:00
Damien George a4423570e2 tools/metrics.py: Add option to diff to error if delta above threshold.
Useful for things like CI where the size check is automated.
2020-04-22 14:02:14 +10:00
stijn bcf01d1686 all: Fix implicit conversion from double to float.
These are found when building with -Wfloat-conversion.
2020-04-18 22:42:24 +10:00
Jim Mussared 85858e72df py/objexcept: Allow compression of exception message text.
The decompression of error-strings is only done if the string is accessed
via printing or via er.args.  Tests are added for this feature to ensure
the decompression works.
2020-04-05 15:02:06 +10:00
David Lechner 3dc324d3f1 tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py.  The basics/ subdirectory is excluded for now so we
aren't changing too much at once.

In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
2020-03-30 13:21:58 +11:00
Lars Kellogg-Stedman 3a0f64fc7a tools/pyboard.py: Add -d as an alias for --device. 2020-03-30 11:37:32 +11:00
Lars Kellogg-Stedman 1cf994c48b tools/pyboard.py: Support setting device/baudrate from shell env vars.
Allow defaults for --device and --baudrate to be set in the environment
using PYBOARD_DEVICE and PYBOARD_BAUDRATE.
2020-03-30 11:37:32 +11:00
Damien George 1a3e386c67 all: Remove spaces inside and around parenthesis.
Using new options enabled in the uncrustify configuration.
2020-03-28 23:36:44 +11:00
Damien George feb2577585 all: Remove spaces between nested paren and inside function arg paren.
Using new options enabled in the uncrustify configuration.
2020-03-25 00:39:46 +11:00
stijn 1b3e0e10b9 tools/codeformat.py: Include all msvc C code in auto-format. 2020-03-25 00:36:42 +11:00
Andrew Leech 38ccb4c643 tools/pydfu.py: Display any error strings from device/mboot. 2020-03-22 15:24:57 +11:00
Andrew Leech 2966d83a65 tools/pydfu.py: Add args for VID/PID & exit with cleaner error handling. 2020-03-22 13:33:04 +11:00
David Lechner 8a4ce6b79a tools/codeformat.py: Eliminate need for sizeof fixup.
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-11 14:34:40 +11:00
Damien George 554c01fc25 tools/metrics.py: Use check_call instead of run to error out on error. 2020-03-11 14:23:39 +11:00
MikeTeachman 8db5d2d1f1 tools/makemanifest.py: Fix build on Windows by adding .exe to mpy-cross.
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-03-05 10:26:31 +11:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George 4b23e98fb0 tools/codeformat.py: Add formatter using uncrustify for C, black for Py.
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-28 10:14:28 +11:00
Damien George a636837987 tools/makemanifest.py: Support freezing with empty list of mpy files.
Fixes issue #5655.
2020-02-20 10:41:50 +11:00
Michael Buesch 1604606238 tools/pyboard.py: Change shebang to use python3.
This script still works with Python 2 but Python 3 is recommended.
2020-02-01 00:06:26 +11:00
Michael Buesch 1cadb12d1c tools/pyboard.py: Use slice del instead of list.clear() for Py2 compat.
Python 2 does not have list.clear().
2020-02-01 00:05:29 +11:00
Michael Buesch 83afd48ad9 tools/pyboard.py: Add option --no-follow to detach after sending script.
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-02-01 00:03:37 +11:00
c0rejump 6db5cede06 tools/pydfu.py: Clean up syntax, update comments and docstrings.
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-23 13:23:12 +11:00
Damien George a11e306227 tools: Add metrics.py script to build and compute port sizes/metrics. 2020-01-23 12:48:52 +11:00
Jason Neal de78a9e317 tools/gen-cpydiff.py: Adjust subsections to sentence case. 2020-01-06 22:16:18 +11:00
David Lechner fd0ba7be07 tools/tinytest-codegen.py: Add extra newline and result message.
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-19 17:55:50 +11:00
Damien George b3b9b11596 tools/pyboard.py: Support executing .mpy files directly.
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-19 17:00:52 +11:00
Damien George 0bd7d1f7f0 py/persistentcode: Move loading of rodata/bss to before obj/raw-code.
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-17 13:22:11 +11:00
Damien George fc97d6d1b5 tools/mpy-tool.py: Raise exception if trying to freeze relocatable mpy. 2019-12-12 20:15:28 +11:00
Damien George abc642973d py/dynruntime: Add support for float API to make/get floats.
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-12 20:15:28 +11:00
Damien George aad79adab7 tools/mpy_ld.py: Add new mpy_ld.py tool and associated build files.
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-12 20:15:28 +11:00
Damien George 27879844d2 tools/mpy-tool.py: Add ability to merge multiple .mpy files into one.
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-12 20:15:28 +11:00
Damien George 360d972c16 py/nativeglue: Add new header file with native function table typedef. 2019-12-12 20:15:28 +11:00
Damien George 7f24c29778 tools/mpy-tool.py: Support qstr linking when freezing Xtensa native mpy. 2019-11-28 13:11:51 +11:00
Yonatan Goldschmidt b2dd443d92 tools/makemanifest.py: Use sys.executable when invoking Python scripts.
So the version of Python used to run makemanifest.py is also used for the
sub-scripts.
2019-11-13 13:44:19 +11:00
Andrew Leech d2e6cfd8fd tools/makemanifest.py: Skip freezing unsupported files with warning. 2019-11-07 12:34:57 +11:00
Mirko Vogt 2f71d66ef7 tools/makemanifest.py: Follow symlinks when freezing linked directories.
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-06 11:41:06 +11:00
Damien George 36c9be6f60 tools/mpy-tool.py: Use "@progbits #" attribute for native xtensa code. 2019-11-04 15:31:42 +11:00
Jim Mussared 8ba963cfa3 tools/makemanifest.py: Eval relative paths w.r.t. current manifest file.
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-21 23:01:41 +11:00
Damien George e81f538e25 tools: Add mechanism to provide a manifest of frozen files.
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-15 21:34:23 +11:00
Damien George 8e8cfa6f53 tools/make-frozen.py: Allow to run with no directory passed in.
In which case it will just emit empty frozen C definitions.
2019-10-15 21:33:49 +11:00
Damien George 23f0691fdd py/persistentcode: Make .mpy more compact with qstr directly in prelude.
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-15 16:56:27 +11:00
Damien George 9adedce42e py: Add new Xtensa-Windowed arch for native emitter.
Enabled via the configuration MICROPY_EMIT_XTENSAWIN.
2019-10-05 13:44:53 +10:00
Damien George c8c0fd4ca3 py: Rework and compress second part of bytecode prelude.
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-01 12:26:22 +10:00
Damien George b5ebfadbd6 py: Compress first part of bytecode prelude.
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-10-01 12:26:22 +10:00
Damien George 5716c5cf65 py/persistentcode: Bump .mpy version to 5.
The bytecode opcodes have changed (there are more, and they have been
reordered).
2019-09-26 16:39:37 +10:00
Josh Lloyd 7d58a197cf py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.
Fixes #5140.
2019-09-26 16:04:56 +10:00
Damien George 1f7202d122 py/bc: Replace big opcode format table with simple macro. 2019-09-26 15:27:11 +10:00
Damien George 5889cf58db py/bc0: Order opcodes into groups based on their size and format. 2019-09-26 15:27:10 +10:00
Damien George c69f58e6b9 tools/mpy-tool.py: Fix freezing of non-bytecode funcs with settrace.
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-06 23:55:15 +10:00
Damien George b29fae0c56 py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.
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-09-02 13:30:16 +10:00