mimxrt boot automounts sd card without adding /lib to path, breaking imports
Port, board and/or hardware
mimxrt, teensy 4.1
MicroPython version
MicroPython v1.23.0 on 2024-06-02; Teensy 4.1 with MIMXRT1062DVJ6A
Reproduction
in https://github.com/micropython/micropython/blob/288a03625327b025f81bb6d4e7fb76d56343172c/ports/mimxrt/modules/_boot.py#L34 an sd card is automounted to /sdcard and then os.chdir makes this the working directory. However, /sdcard/lib is not added to the import paths so code located there will not be found by import statements.
Ran into this when using the mpr xrun tool, because the underlying mpremote commands work relative to the working directory, ended up in a state where .mpy files are copied over to /sdcard/lib but the when the program runs it can't find them.
Expected behaviour
Not sure the appropriate behavior here, but the issue would maybe have been avoided if either
- /sdcard/lib were added to the path, like /flash/lib is a few lines above, or
- if there were no
os.chdirto the automounted sd card. this would allow mpr/mpremote to continue to use /flash as working directory, per usual without breaking the handympr xruncommand. I hadn't initially expected that /sdcard would become the working directory which caused confusion in tracking down this behavior.
as a workaround I am using the functionality where creating the file /flash/SKIPSD skips the SD card auto-mount.
Observed behaviour
n/a
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
stm32/main: Add boardconfig option to enable/disable booting from sdcard
With this PR MICROPY_HW_BOOT_SDCARD can be defined to (0) in mpconfigboard.h to allow SD hardware to be enabled but not auto-mounted at boot.
Previously, if an SD card is enabled in hardware it is also used to boot from.
While booting from SD card can be disabled with a SKIPSD file on internal flash, this wont be available at first boot after flashing or if the internal flash gets corrupted.
We're working on a product that uses an SD card for bulk storage, however we don't want code to be stored or run from the card. This PR allows us to enforce this from first boot of a fresh DFU image.