pulkin / micropython

MicroPython implementation on Ai-Thinker GPRS module A9 (RDA8955)
https://micropython.org
MIT License
103 stars 30 forks source link

/t/main.py #81

Open ubaldus opened 3 years ago

ubaldus commented 3 years ago

Would it make sense to add a /t/main.py check and eventual execution by default?

I mean I think that is the spirit of boot.py and main.py so having in this case an sd card would be a pity not to implement it :)

pulkin commented 3 years ago

What kind of problem this solves?

ubaldus commented 3 years ago

The idea is that I could rewrite the main.py on the sd card without having to burn again the whole firmware nor risking to mess up with the internal storage

pulkin commented 3 years ago

Do you say you have problems rewriting /main.py as a part of internal SPI memory?

ubaldus commented 3 years ago

No, my idea is that I burn the firmware, so the device is ready and working, I can then pack it into a nice case but anytime I want to change something I will just need to rewrite the /t/main.py on the sd card without having to take the board out and burn a new firmware.

ubaldus commented 3 years ago

or having to connect via serial which is also not as easy as to connect via wifi for instance on the esp32...

pulkin commented 3 years ago

You may put /main.py with

sys.path.append("/t")
import main_from_sd_card

before packing into a nice case. Then, change to whatever you want in /t/main_from_sd_card.py.

bokolob commented 3 years ago

By the way you don't have to re-burn firmware to update main.py, you can use ampy, and upload files through UART.

ubaldus commented 3 years ago

of course Pulkin I could do it so but I would then need to connect the board to the HST pins, burn the firmware, then connect the uart, write the /main.py and disconnect which is fine if I am doing on a board but what if I am flashing hundreds?

I mean I could also easily write my own version of modules/_boot.py I was just wondering if a similar feature could be helpful to someone else and as micropython already is anyway looking for a /boot.py and a /main.py why not adding for this specific board support for a /t/main.py? :)

bokolob commented 3 years ago

Oh, I've got your point.

pulkin commented 3 years ago

but what if I am flashing hundreds?

Then you may update _boot.py with your code, rebuild the firmware and flash it hundred times.

If you provide an example of at least one other mainstream mpy firmware with this behaviour I might want to look into it. Otherwise mpy-specific features follow a simple logic: if it is present esp8266 / esp32 it is better to implement it just because people come here with this background. Otherwise fewer code is better.

ens4dz commented 3 years ago

Yesterday, I put machine.restart() line at boot.py ! It's takes me a while to reburn firmware.

From documentation: https://docs.micropython.org/en/latest/pyboard/general.html `` When the pyboard boots up, it needs to choose a filesystem to boot from. If there is no SD card, then it uses the internal filesystem /flash as the boot filesystem, otherwise, it uses the SD card /sd. After the boot, the current directory is set to one of the directories above.

If needed, you can prevent the use of the SD card by creating an empty file called /flash/SKIPSD. If this file exists when the pyboard boots up then the SD card will be skipped and the pyboard will always boot from the internal filesystem (in this case the SD card won’t be mounted but you can still mount and use it later in your program using os.mount).

``

https://github.com/micropython/micropython/issues/1915

ubaldus commented 3 years ago

Question is now, should we run /boot.py and /main.py anyway first if they are present?

    // Startup scripts
    pyexec_frozen_module("_boot.py");
    pyexec_file_if_exists("boot.py");
    if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
        pyexec_file_if_exists("/t/boot.py");
    }
    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        pyexec_file_if_exists("main.py");
        if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
            pyexec_file_if_exists("/t/main.py");
        }
    }
ens4dz commented 3 years ago

Question is now, should we run /boot.py and /main.py anyway first if they are present?

    // Startup scripts
    pyexec_frozen_module("_boot.py");
    pyexec_file_if_exists("boot.py");
    if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
        pyexec_file_if_exists("/t/boot.py");
    }
    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        pyexec_file_if_exists("main.py");
        if (mp_vfs_import_stat("/SKIPSD") == MP_IMPORT_STAT_NO_EXIST) {
            pyexec_file_if_exists("/t/main.py");
        }
    }

take a look here: https://github.com/micropython/micropython/blob/42342fa3cb30e2eac56ceb1d21b4eb60a0f406f3/ports/stm32/main.c#L624