summaryrefslogtreecommitdiff
path: root/tools/pyboard.py
AgeCommit message (Collapse)Author
2021-08-25tools/pyboard.py: Make --no-soft-reset consistent with other args.Jim Mussared
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-25tools/pyboard.py: Add --exclusive to match --no-exclusive.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25tools/pyboard.py: Make --no-follow use same variable as --follow.Jim Mussared
You can set one or the other (or neither) but not both. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-25tools/pyboard.py: Move --no-exclusive/--soft-reset out of mutex group.Jim Mussared
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>
2021-07-01tools/pyboard.py: Add cmd-line option to make soft reset configurable.Frank Pilhofer
Leaves the default as-is, but allows using --no-soft-reset to disable the soft reset when connecting.
2021-05-29tools/pyboard.py: Add "soft_reset" option to Pyboard.enter_raw_repl().Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-05-29tools/pyboard.py: Track raw REPL state via in_raw_repl variable.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-23tools/pyboard.py: Support opening serial port in exclusive mode.Damien George
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-02-13tools: Add filesystem action examples to pyboard.py help.Brianna Laugher
Signed-off-by: Brianna Laugher <brianna.laugher@gmail.com>
2020-12-01tools/pyboard.py: Add fast raw-paste mode.Damien George
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-08-21tools/pyboard.py: Replace eval() of received data with alternative.Michael Buesch
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-03-30tools/pyboard.py: Add -d as an alias for --device.Lars Kellogg-Stedman
2020-03-30tools/pyboard.py: Support setting device/baudrate from shell env vars.Lars Kellogg-Stedman
Allow defaults for --device and --baudrate to be set in the environment using PYBOARD_DEVICE and PYBOARD_BAUDRATE.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-01tools/pyboard.py: Change shebang to use python3.Michael Buesch
This script still works with Python 2 but Python 3 is recommended.
2020-02-01tools/pyboard.py: Use slice del instead of list.clear() for Py2 compat.Michael Buesch
Python 2 does not have list.clear().
2020-02-01tools/pyboard.py: Add option --no-follow to detach after sending script.Michael Buesch
This option makes pyboard.py exit as soon as the script/command is successfully sent to the device, ie it does not wait for any output. This can help to avoid hangs if the board is being rebooted with --comman (for example). Example usage: $ python3 ./tools/pyboard.py --device /dev/ttyUSB0 --no-follow \ --command 'import machine; machine.reset()'
2019-12-19tools/pyboard.py: Support executing .mpy files directly.Damien George
This patch allows executing .mpy files (including native ones) directly on a target, eg a board over a serial connection. So there's no need to copy the file to its filesystem to test it. For example: $ mpy-cross foo.py $ pyboard.py foo.mpy
2019-07-25tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files.Damien George
Use "-f" to select filesystem mode, followed by the command to execute. Optionally put ":" at the start of a filename to indicate that it's on the remote device, if it would otherwise be ambiguous. Examples: $ pyboard.py -f ls $ pyboard.py -f cat main.py $ pyboard.py -f cp :main.py . # get from device $ pyboard.py -f cp main.py : # put to device $ pyboard.py -f rm main.py
2019-04-25tools/pyboard.py: Don't accumulate output data if data_consumer used.Damien George
Prior to this patch, when a lot of data was output by a running script pyboard.py would try to capture all of this output into the "data" variable, which would gradually slow down pyboard.py to the point where it would have large CPU and memory usage (on the host) and potentially lose data. This patch fixes this problem by not accumulating the data in the case that the data is not needed, which is when "data_consumer" is used.
2019-03-26tools/pyboard.py: Add missing line from example usage comments.rhubarbdog
2018-10-19tools/pyboard.py: In TelnetToSerial.close replace try/except with if.Martin Dybdal
Some Python linters don't like unconditional except clauses because they catch SystemExit and KeyboardInterrupt, which usually is not the intended behaviour.
2018-08-10tools/pyboard.py: Change base class of PyboardError to Exception.Martin Dybdal
Following standard practice for defining custom exceptions.
2018-08-04tools/pyboard: Run exec: command as a string.Ayke van Laethem
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
2017-10-08tools/pyboard: Update docstring for additional device support.Paul Sokolovsky
2017-10-05tools/pyboard: Use repr() when quoting data in error messages.Paul Sokolovsky
As it may contain newlines, etc.
2017-07-22tools/pyboard: Add license header.Paul Sokolovsky
2017-05-29various: Spelling fixesVille Skyttä
2017-04-07tools/pyboard: Provide more details when expected reply not received.Paul Sokolovsky
When trying to execute a command via raw REPL and expected "OK" reply not received, show what was received instead.
2017-04-05tools/pyboard: ProcessPtyToTerminal: Add workaround for PySerial bug.Paul Sokolovsky
When working with a "virtual" port, like PTY. The issue described in http://stackoverflow.com/questions/34831131/pyserial-does-not-play-well-with-virtual-port
2017-04-05tools/pyboard: execpty: Use shell=False to workaround some curdir issues.Paul Sokolovsky
Without this, Zephyr's port "make test" doesn't work.
2017-04-04tools/pyboard: Add "exec" and "execpty" pseudo-devices support.Paul Sokolovsky
This allows to execute a command and communicate with its stdin/stdout via pipes ("exec") or with command-created pseudo-terminal ("execpty"), to emulate serial access. Immediate usecase is controlling a QEMU process which emulates board's serial via normal console, but it could be used e.g. with helper binaries to access real board over other hadware protocols, etc. An example of device specification for these cases is: --device exec:../zephyr/qemu.sh --device execpty:../zephyr/qemu2.sh Where qemu.sh contains long-long qemu startup line, or calls another command. There's a special support in this patch for running the command in a new terminal session, to support shell wrappers like that (without new terminal session, only wrapper script would be terminated, but its child processes would continue to run).
2017-04-02tools/pyboard: Tighten up Pyboard object closure on errors.Paul Sokolovsky
Some "device" implementations may be sensitive to this.
2016-12-15tools/pyboard.py: Refactor so target is not reset between scripts/cmd.Damien George
Previous to this patch pyboard.py would open a new serial connection to the target for each script that was run, and for any command that was run. Apart from being inefficient, this meant that the board was soft-reset between scripts/commands, which precludes scripts from accessing variables set in a previous one. This patch changes the behaviour of pyboard.py so that the connection to the target is created only once, and it's not reset between scripts or any command that is sent with the -c option.
2015-12-08tools: Fix pyboard.py to work under Python 3.Damien George
2015-12-08tools: Add option to pyboard.py to wait for serial device to be ready.Peter Hinch
Also prints a nicer error message if the serial connection could not be established.
2015-12-06tools: Allow pyboard.py to work when boot.py prints things.Dave Hylands
2015-11-07tools/pyboard.py: Don't add terminating \x04 character to stdout output.Paul Sokolovsky
2015-11-07tools/pyboard.py: Make -c (inline Python code) option compatible with python2.Paul Sokolovsky
2015-10-19tools/pyboard: Add -c argument to run a program passed as a string.Tom Soulanille
2015-08-08tools: Make pyboard.py Python2 compatible.Damien George
2015-07-29tools/pyboard.py: Fix read timeout calc to work with shorter sleep.Damien George
2015-07-26tools: Add telnet support to pyboard.py.Daniel Campora
The adapter class "TelnetToSerial" is used to access the Telnet connection using the same API as with the serial connection. The function pyboard.run-test() has been removed to made the module generic and because this small test is no longer needed.
2015-07-25tools/pyboard.py: Speed up reading of chars by decreasing sleep period.Damien George
2015-07-25tools/pyboard.py: Make enter_raw_repl stricter and more reliable.Damien George
When looking for chars to indicate raw repl is active, look for the full string of chars to improve reliability of entering raw repl correctly. Previous to this patch there was the possibility that raw repl was entered in a dirty state, where not all input chars from previous invocation were drained.
2015-07-25tools/pyboard.py: Fix parsing of returned error so last chr is not lost.Damien George
2015-06-15tools/pyboard.py: Change logic for when raw ">" prompt is parsed.Damien George
In raw REPL ">" indicates the prompt. We originally read this character upon entering the raw REPL, and after reading the last bit of the output. This patch changes the logic so the ">" is read only just before trying to send the next command. To make this work (and as an added feature) the input buffer is now flushed upon entering raw REPL. The main reason for this change is so that pyboard.py recognises the EOF when sys.exit() is called on the pyboard. Ie, if you run pyboard.py with a script that calls sys.exit(), then pyboard.py will exit after the sys.exit() is called.
2015-05-27tools: Allow pyboard constructor to take a baudrate parameter.Dave Hylands
This allows pyboard.py to be used over a UART interface rather than just over a USB serial interface.
2015-05-18tools: Add exec_raw_no_follow to pyboard.py.Dave Hylands
2015-05-07tools/pyboard.py: Add "--follow" option to wait for output indefinitely.Damien George
Also flush stdout so you can see output as it comes.