Why do `rshell` and `ampy` run boot.py and main.py for every command?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
zachmoshe
Posts: 6
Joined: Fri Jun 24, 2022 8:28 am

Why do `rshell` and `ampy` run boot.py and main.py for every command?

Post by zachmoshe » Thu Aug 11, 2022 4:14 pm

Hi,
I'm new to MicroPython, so definitely could be missing something, but it seems that whenever I'm running `ampy` or `rshell` they constantly keep running `boot.py` and `main.py`.
I see that for every `ampy` command, even just `ls`, and with `rshell` I notice that when it starts, it tries to initialize different variables from the board itself (name, chip_type, even the list of files under '/'), and it seems that for every such command, it runs boot+main.

This causes me several problems:
1. This is slow. I'm initializing network, sdcard and other peripherals in boot.py and main.py, so it does so repeatedly, even without I need that for the command itself.
2. If I have a bug in main.py it could make these stuck and sometimes I even need to erase flash and copy a "commented-out" main.

[*] Do `ampy` and `rshell` really need to run the init scripts?
[*] Is there a flag to turn that off?
[*] If not - what should be my best practice? On one hand - my app needs the initializations (network, sdcard,...), but on the other hand I don't need them just for copying files, or testing another new module. Can I have 2 "modes" for boot?

Thanks!
Zach

MicroRichard
Posts: 15
Joined: Tue Aug 09, 2022 11:32 am

Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?

Post by MicroRichard » Fri Aug 12, 2022 7:51 am

I am not sure if i understand you correctly but this is what i use to run the main.py on the pyboard.
Download the following micropython github repo.
https://github.com/micropython/micropython
From this github repo there is a folder tools which has pyboard.py. You can use this to start main.py or any other python file on your device.
The command i use is:

Code: Select all

python pyboard.py --device COM10 h:\main.py

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?

Post by jimmo » Sat Aug 13, 2022 2:16 pm

zachmoshe wrote:
Thu Aug 11, 2022 4:14 pm
[*] If not - what should be my best practice? On one hand - my app needs the initializations (network, sdcard,...), but on the other hand I don't need them just for copying files, or testing another new module. Can I have 2 "modes" for boot?
I don't know much about ampy or rshell, but what you're describing definitely doesn't happen with mpremote (or pyboard.py).

I would definitely recommend mpremote -- see https://docs.micropython.org/en/latest/ ... emote.html

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?

Post by dhylands » Tue Aug 23, 2022 6:09 pm

rshell does whatever pyboard.py does (since it uses pyboard.py to do all of the low level stuff).

When micropython boots up it runs boot.py and then if it's running the raw REPL it will skip running main.py
https://github.com/micropython/micropyt ... #L223-L247

rshell, pyboard.py and mpremote all use the raw repl, so for all of these you should see that boot.py gets run but main.py doesn't.

The intention of boot.py is do very limited hardware setup (mount SD card, configure USB), and these are the types of things that rshell/pyboard.py/mpremote would want setup. Additional setup that takes a long time, should happen in main.py and then it won't happen once rshell/pyboard.py/mpremote is connected.

Post Reply