Skip to content

ports/unix: Add raw REPL support. #16141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

glenn20
Copy link
Contributor

@glenn20 glenn20 commented Nov 3, 2024

Summary

Add raw REPL support to the unix port. This make it possible to connect to a unix micropython instance using mpremote and utilise the functionality of the raw REPL. This is useful for debugging and CI tests of mpremote and related tools.

For example, one can run micropython behind a PTY with socat and connect to the slave pty (as if it were a serial port) with mpremote:

socat PTY,link=$HOME/.upy-pty,rawer EXEC:./build-standard/micropython,pty,stderr,onlcr=0 &
mpremote resume connect ~/.upy-pty ls

(The resume argument is required since micropython v1.24 as a soft reset terminates the micropython process).

or, using the micropython docker image (thanks to @mattytrentini ):

socat PTY,link=$HOME/.upy-pty,rawer EXEC:"docker run -ti --rm micropython/unix\:v1.23.0",pty,stderr,onlcr=0

Testing

This has been tested using private CI workflows adapted from those in the mpremote-path tool (which uses mpremote as a library).

Trade-offs and Alternatives

The changes impact only the unix port (adding pyexec.c to the build) and present a user-visible change through behaviour when a ctrl-A character is entered at the repl. However, this reflects expected behaviour on other ports and should not impact on expected or supported usage.

Copy link

codecov bot commented Nov 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (0e490b7) to head (7904157).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16141   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21345           
=======================================
  Hits        21040    21040           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Nov 3, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64: +1484 +0.176% standard[incl +8(bss)]
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Add raw REPL support to the unix port. This make it possible to
connect to a unix micropython instance using mpremote and
utilise the functionality of the raw REPL. This is useful for
debugging and CI tests of mpremote and related tools.

Eg:
```
socat PTY,link=$HOME/.upy-pty,rawer |
      EXEC:./build-standard/micropython,pty,stderr,onlcr=0 &
mpremote resume connect ~/.upy-pty ls
```

Requires the inclusion of `#include "extmod/modplatform.h"` in
`pyexec.c` so that `MICROPY_BANNER_MACHINE` is fully resolved.

Changes are wrapped in `#ifdef linux` to ensure no impact on
the windows port.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
@glenn20 glenn20 force-pushed the feature-unix-port-rawrepl branch from 75567d5 to 7904157 Compare November 3, 2024 03:24
@glenn20
Copy link
Contributor Author

glenn20 commented Nov 3, 2024

Pushed a commit to wrap the changes to ports/unix/main.c in #ifdef __linux__ to ensure no impact on the windows port (which re-uses code in the unix port).

@dpgeorge
Copy link
Member

dpgeorge commented Nov 4, 2024

Thanks for this, I do think this is a good feature to enable on the unix port.

There are previous attempts to do similar things, which aim to unify unix and bare-metal REPL code: #12802 and #6008.

@glenn20
Copy link
Contributor Author

glenn20 commented Nov 4, 2024

Thanks for this, I do think this is a good feature to enable on the unix port.

There are previous attempts to do similar things, which aim to unify unix and bare-metal REPL code: #12802 and #6008.

Ah. Thanks for pointing out those PRs. I completely overlooked them when scanning for PRs. I see the value in a more unified approach to the repl - I was just chasing a particular feature and so a much more limited change. I'm happy to close this PR in favour of #12802 or #6008.

@dpgeorge
Copy link
Member

dpgeorge commented Nov 4, 2024

This PR is nice and simple, and may still be needed. Let's keep it open until the other ones are merged/closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants