summaryrefslogtreecommitdiffstatshomepage
path: root/tools/pyboard.py
Commit message (Collapse)AuthorAge
* tools: Only issue a single Ctrl-C when entering raw REPL.Damien George2024-10-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | A long time ago when there was only the `stm` port, Ctrl-C would trigger a preemptive NLR jump to break out of running code. Then in commit 124df6f8d07b53542b6960dbeea9b63bff469a67 a more general approach to asynchronous `KeyboardInterrupt` exceptions was implemented, and `stmhal` supported both approaches, with the general (soft) interrupt taking priority. Then in commit bc1488a05f509cd5be8bfab9574babfcb993806f `pyboard.py` was updated with a corresponding change to make it issue a double Ctrl-C to break out of any existing code when entering the raw REPL (two Ctrl-C characters were sent in order to more reliably trigger the preemptive NLR jump). No other port has preemptive NLR jumps and so a double Ctrl-C doesn't really behave any differently to a single Ctrl-C: with USB CDC the double Ctrl-C would most likely be in the same USB packet and so processed in the same low-level USB callback, so it's just setting the keyboard interrupt flag twice in a row. The VM/runtime then just sees one keyboard interrupt and acts as though only one Ctrl-C was sent. This commit changes the double Ctrl-C to a single Ctrl-C in `pyboard.py` and `mpremote`. That keeps things as simple as they need to be. Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Capture stdout for pts line.Damien George2024-08-28
| | | | | | | | The pts line printed by qemu-system-arm goes to stdout, not stderr. Redirect stderr to stdout in case other tools do print to stderr. Signed-off-by: Damien George <damien@micropython.org>
* all: Update Python formatting to ruff-format.Jim Mussared2023-11-03
| | | | | | | | | This updates a small number of files that change with ruff-format's (vs black's) rules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Replace all uses of umodule in Python code.Jim Mussared2023-06-08
| | | | | | | | Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/mpremote: Handle `cp` without destination.Jim Mussared2023-06-02
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Import errno to fix undefined name in PyboardError.Christian Clauss2023-05-09
| | | | | | This will keep line 96 from raising a NameError. Signed-off-by: Christian Clauss <cclauss@me.com>
* tools/pyboard.py: Import serial.tools.list_ports.Damien George2023-05-04
| | | | | | This import is needed by newer versions of pyserial. Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Rename ProcessPtyToTerminal member "ser" to "serial".Damien George2023-04-27
| | | | | | So that this file doesn't need to be excluded from codespell. Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Fix ESPxx boards hanging in bootloader after reset.Jos Verlinde2023-04-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a follow up to d263438a6e365d3199494498a9b734cda29dde52, which solved one problem (reset on disconnect) but introduced a second one (hang in bootloader). To solve both probles, False/False is needed for DTR/RTS for ESPxx, but that would then block stm32 and others. Any unconditional combination of DTR/RTS ends up blocking normal operation on some type of board or another. A simple overview (for windows only): DTR CTS ESP8266/ESP32 STM32/SAMD51/RP2040 unspecified unspecified Reset on disconnect OK True False Hang in bootloader OK False False OK No Repl True True Reset on disconnect No Repl False True Reset on disconnect No Repl serial.manufacturer: wch.cn/Silicon Labs Microsoft serial.description: USB-SERIAL CH340 / USB Serial Device CP210x USB to UART Bridge The updated logic will only set the DTR/RTS signals for boards that do not use standard Microsoft drivers (based on the manufacturer). It would also be possible to check against a list of known driver manufactures (like wch.cn or Silicon Labs) but this would require a list of known drivers for all ports. Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
* tools/pyboard.py: Fix joining of path in filesystem_command.Damien George2023-03-22
| | | | | | This was broken by 5327cd1021dc92cad428ff44cb114c4a94c0bc45 Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Use '/' exclusively when dealing with paths.Damien George2023-02-24
| | | | | | | | | | | | | | | | | | | | | Currently, certain mpremote filesystem operations can fail on Windows due to a mixing of '/' and '\' for path separators. Eg if filesystem_command() is called with a destination that ends in / then dest.endswith(os.path.sep) will return False, which gives the wrong behaviour (it does end in a path separator). For similar reasons to 7e9a15966acf80ff50fdf5c52553dd56de164bb3, it's best to use '/' everywhere in pyboard.py and mpremote, because the target device understands only '/'. mpremote already does this, so the remaining place to fix it is in pyboard.y, to convert all incoming paths to use '/' instead of '\'. This effectively reverts 57fd66b80f8352e4859e6b71536b6083f9d7279c which tried to fix the problem in a different way. See also related 1f84440538a017e463aaad9686831ce9527122b5. Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Set DTR on Windows to avoid ESPxx hard reset.Jos Verlinde2023-01-13
| | | | | | Fixes issue #9659. Signed-off-by: Jos Verlinde <Jos.Verlinde@Microsoft.com>
* tools/pyboard.py: Add fs_{listdir,readfile,writefile,stat}.Jim Mussared2023-01-13
| | | | | | | | | | | | | | | | | | | These are for working with the filesystem when using pyboard.py as a library, rather than at the command line. - fs_listdir returns a list of tuples, in the same format as os.ilistdir(). - fs_readfile returns the contents of a file as a bytes object. - fs_writefile allows writing a bytes object to a file. - fs_stat returns an os.statresult. All raise FileNotFoundError (or OSError(ENOENT) on Python 2) if the file is not found (or PyboardError on other errors). Updated fs_cp and fs_get to use fs_stat to compute file size. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Add parse kwarg to eval.Jim Mussared2023-01-13
| | | | | | | | | | | | | | | | | This is useful when using pyboard.py as a library rather than at the command line. pyb.eval("1+1") --> b"2" pyb.eval("{'a': '\x00'}") --> b"{'a': '\\x00'}" Now you can also do pyb.eval("1+1", parse=True) --> 2 pyb.eval("{'a': '\x00'}", parse=True) --> {'a': '\x00'} This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Fix Python 2 compatibility.Jim Mussared2023-01-13
| | | | | | | In Python 2, serial.read()[0] a string, not int. Use struct.unpack to do this instead. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Handle unsupported fs command.Jim Mussared2022-10-01
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/mpremote: Add `mpremote mip install` to install packages.Jim Mussared2022-10-01
| | | | | | | | | | | | | | | This supports the same package sources as the new `mip` tool. - micropython-lib (by name) - http(s) & github packages with json description - directly downloading a .py/.mpy file The version is specified with an optional `@version` on the end of the package name. The target dir, index, and mpy/no-mpy can be set through command line args. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Support Windows pathname separators.Wind-stormger2022-09-13
| | | | Addresses issue #9132.
* tools/pyboard.py: Add fs_cp function for direct device-to-device copy.Damien George2022-08-26
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Remove implicit fs_put if source starts with ./.Damien George2022-08-26
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Add "touch" filesystem command.Jim Mussared2022-08-18
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Add verbose option to filesystem_command.Damien George2022-07-08
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tools/mpremote: Show progress indicator when copying large files.Rob Knegjens2022-04-11
| | | | | When copying large files (> 2048 bytes) to or from a device with `mpremote cp` a progress bar and percentage counter are temporarily shown.
* tools/pyboard.py: Make --no-soft-reset consistent with other args.Jim Mussared2021-08-25
| | | | | | | | 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>
* tools/pyboard.py: Add --exclusive to match --no-exclusive.Jim Mussared2021-08-25
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Make --no-follow use same variable as --follow.Jim Mussared2021-08-25
| | | | | | You can set one or the other (or neither) but not both. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tools/pyboard.py: Move --no-exclusive/--soft-reset out of mutex group.Jim Mussared2021-08-25
| | | | | | | | | | | | | The --no-exclusive flag was accidentally added to the mutex group in 178198a01df51b5f4c5ef9f38ab2fb8f6269d5f4. The --soft-reset flag was accidentally added to the mutex group in 41adf178309759d5965c15972f04987a2635314c. 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>
* tools/pyboard.py: Add cmd-line option to make soft reset configurable.Frank Pilhofer2021-07-01
| | | | | Leaves the default as-is, but allows using --no-soft-reset to disable the soft reset when connecting.
* tools/pyboard.py: Add "soft_reset" option to Pyboard.enter_raw_repl().Damien George2021-05-29
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Track raw REPL state via in_raw_repl variable.Damien George2021-05-29
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tools/pyboard.py: Support opening serial port in exclusive mode.Damien George2021-04-23
| | | | | | | 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>
* tools: Add filesystem action examples to pyboard.py help.Brianna Laugher2021-02-13
| | | | Signed-off-by: Brianna Laugher <brianna.laugher@gmail.com>
* tools/pyboard.py: Add fast raw-paste mode.Damien George2020-12-01
| | | | | | | | | 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>
* tools/pyboard.py: Replace eval() of received data with alternative.Michael Buesch2020-08-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* tools/pyboard.py: Add -d as an alias for --device.Lars Kellogg-Stedman2020-03-30
|
* tools/pyboard.py: Support setting device/baudrate from shell env vars.Lars Kellogg-Stedman2020-03-30
| | | | | Allow defaults for --device and --baudrate to be set in the environment using PYBOARD_DEVICE and PYBOARD_BAUDRATE.
* all: Reformat C and Python source code with tools/codeformat.py.Damien George2020-02-28
| | | | This is run with uncrustify 0.70.1, and black 19.10b0.
* tools/pyboard.py: Change shebang to use python3.Michael Buesch2020-02-01
| | | | This script still works with Python 2 but Python 3 is recommended.
* tools/pyboard.py: Use slice del instead of list.clear() for Py2 compat.Michael Buesch2020-02-01
| | | | Python 2 does not have list.clear().
* tools/pyboard.py: Add option --no-follow to detach after sending script.Michael Buesch2020-02-01
| | | | | | | | | | | | 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()'
* tools/pyboard.py: Support executing .mpy files directly.Damien George2019-12-19
| | | | | | | | | | | 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
* tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files.Damien George2019-07-25
| | | | | | | | | | | | | | Use "-f" to select filesystem mode, followed by the command to execute. Optionally put ":" at the start of a filename to indicate that it's on the remote device, if it would otherwise be ambiguous. Examples: $ pyboard.py -f ls $ pyboard.py -f cat main.py $ pyboard.py -f cp :main.py . # get from device $ pyboard.py -f cp main.py : # put to device $ pyboard.py -f rm main.py
* tools/pyboard.py: Don't accumulate output data if data_consumer used.Damien George2019-04-25
| | | | | | | | | | | Prior to this patch, when a lot of data was output by a running script pyboard.py would try to capture all of this output into the "data" variable, which would gradually slow down pyboard.py to the point where it would have large CPU and memory usage (on the host) and potentially lose data. This patch fixes this problem by not accumulating the data in the case that the data is not needed, which is when "data_consumer" is used.
* tools/pyboard.py: Add missing line from example usage comments.rhubarbdog2019-03-26
|
* tools/pyboard.py: In TelnetToSerial.close replace try/except with if.Martin Dybdal2018-10-19
| | | | | | Some Python linters don't like unconditional except clauses because they catch SystemExit and KeyboardInterrupt, which usually is not the intended behaviour.
* tools/pyboard.py: Change base class of PyboardError to Exception.Martin Dybdal2018-08-10
| | | | Following standard practice for defining custom exceptions.
* tools/pyboard: Run exec: command as a string.Ayke van Laethem2018-08-04
| | | | | | | | | The Python documentation recommends to pass the command as a string when using Popen(..., shell=True). This is because "sh -c <string>" is used to execute the command and additional arguments after the command string are passed to the shell itself (not the executing command). https://docs.python.org/3.5/library/subprocess.html#subprocess.Popen
* tools/pyboard: Update docstring for additional device support.Paul Sokolovsky2017-10-08
|
* tools/pyboard: Use repr() when quoting data in error messages.Paul Sokolovsky2017-10-05
| | | | As it may contain newlines, etc.
* tools/pyboard: Add license header.Paul Sokolovsky2017-07-22
|