summaryrefslogtreecommitdiff
path: root/extmod
AgeCommit message (Collapse)Author
2025-03-27extmod/vfs_rom: Implement minimal VfsRom.getcwd() method.Damien George
This is needed if you chdir to a ROMFS and want to query your current directory. Prior to this change, using `os.getcwd()` when in a ROMFS would raise: AttributeError: 'VfsRom' object has no attribute 'getcwd' Signed-off-by: Damien George <damien@micropython.org>
2025-03-27extmod/vfs: Return mount table from no-args vfs.mount call.Anson Mansfield
This extends the existing `vfs.mount()` function to accept zero arguments, in which case it returns a list of tuples of mounted filesystem objects and their mount location. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-03-27extmod/vfs: Refactor mp_vfs_mount to enable no-args mount overload.Anson Mansfield
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-03-27extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail.Damien George
Allocation of a large compression window may fail, and in that case keep the `DeflateIO` state consistent so its other methods (such as `close()`) still work. Consistency is kept by only updating the `self->write` member if the window allocation succeeds. Thanks to @jimmo for finding the bug. Signed-off-by: Damien George <damien@micropython.org>
2025-03-12extmod/network_cyw43: Add WPA3 security constants.Damien George
These are now supported by cyw43-driver. Signed-off-by: Damien George <damien@micropython.org>
2025-03-06extmod/vfs: Add mp_vfs_mount_romfs_protected() helper.Damien George
This function will attempt to create a `VfsRom` instance and mount it at location "/rom" in the filesystem. Signed-off-by: Damien George <damien@micropython.org>
2025-03-06extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.Damien George
This is a generic interface to allow querying and modifying the read-only memory area of a device, if it has such an area. Signed-off-by: Damien George <damien@micropython.org>
2025-02-26extmod/vfs_rom: Add bounds checking for all filesystem accesses.Damien George
Testing with ROMFS shows that it is relatively easy to end up with a corrupt filesystem on the device -- eg due to the ROMFS deploy process stopping half way through -- which could lead to hard crashes. Notably, there can be boot loops trying to mount a corrupt filesystem, crashes when importing modules like `os` that first scan the filesystem for `os.py`, and crashing when deploying a new ROMFS in certain cases because the old one is removed while still mounted. The main problem is that `mp_decode_uint()` has an loop that keeps going as long as it reads 0xff byte values, which can happen in the case of erased and unwritten flash. This commit adds full bounds checking in the new `mp_decode_uint_checked()` function, and that makes all ROMFS filesystem accesses robust. Signed-off-by: Damien George <damien@micropython.org>
2025-02-25all: Upgrade codespell to v2.4.1.Christian Clauss
This commit upgrades from codespell==2.2.6 to the current codespell==2.4.1, adding emac to the ignore-words-list. Signed-off-by: Christian Clauss <cclauss@me.com>
2025-02-14extmod/modtls_mbedtls: Wire in support for DTLS.Keenan Johnson
This commit enables support for DTLS, i.e. TLS over datagram transport protocols like UDP. While support for DTLS is absent in CPython, it is worth supporting it in MicroPython because it is the basis of the ubiquitous CoAP protocol, used in many IoT projects. To select DTLS, a new set of "protocols" are added to SSLContext: - ssl.PROTOCOL_DTLS_CLIENT - ssl.PROTOCOL_DTLS_SERVER If one of these is set, the library assumes that the underlying socket is a datagram-like socket (i.e. UDP or similar). Our own timer callbacks are implemented because the out of the box implementation relies on `gettimeofday()`. This new DTLS feature is enabled on all ports that use mbedTLS. This commit is an update to a previous PR #10062. Addresses issue #5270 which requested DTLS support. Signed-off-by: Keenan Johnson <keenan.johnson@gmail.com>
2025-02-14extmod/lwip-include: Increase number of lwIP timers when mDNS enabled.Thomas Watson
Despite the code comments claiming one is sufficient, the mDNS application is capable of using up to twelve timers. Three per IP protocol are started at once in `mdns_start_multicast_timeouts_ipvX`, then another two per protocol can be started in `mdns_handle_question`. Further timers can be started for two additional callbacks. Having certain timers, such as `MDNS_MULTICAST_TIMEOUT`, fail to start due to none being free will break mDNS forever as the app will never realize it's safe to transmit a packet. Therefore, this commit goes somewhat overkill and allocates the maximal amount of timers; it's uncertain if all can run simultaneously, or how many callback timers are needed. Each timer struct is 16 bytes on standard 32 bit builds. Plus, say, 8 bytes of allocater overhead, that's 288 more bytes of RAM used which shouldn't be too horrible. Users who don't need mDNS can manually disable it to recover the RAM if necessary. This fixes mDNS on W5500_EVB_PICO (among other boards). Before, mDNS would work for a bit after connection until the host's cache expired a minute or two later. Then the board would never respond to further queries. With this patch, all works well. Signed-off-by: Thomas Watson <twatson52@icloud.com>
2025-02-11extmod/vfs_rom: Remove ability to create VfsRom from an address.Damien George
It's not necessary to support this, which allows an arbitrary memory address to be specified and potentially allows invalid memory accesses. Requiring an object with the buffer protocol is safer, and also means that the length of the region is always specified. Signed-off-by: Damien George <damien@micropython.org>
2025-02-11extmod/modmarshal: Add new marshal module.Damien George
This commit implements a small subset of the CPython `marshal` module. It implements `marshal.dumps()` and `marshal.loads()`, but only supports (un)marshalling code objects at this stage. The semantics match CPython, except that the actual marshalled bytes is not compatible with CPython's marshalled bytes. The module is enabled at the everything level (only on the unix coverage build at this stage). Signed-off-by: Damien George <damien@micropython.org>
2025-02-03extmod/mbedtls: Try GC before failing to setup socket on esp32, unix.Angus Gratton
On mbedTLS ports with non-baremetal configs (mostly esp32, technically also unix port), mbedTLS memory is allocated from the libc heap. This means an old SSL socket may be holding large SSL buffers and preventing a new SSL socket from being allocated. As a workaround, trigger a GC pass and retry before failing outright. This was originally implemented as a global mbedTLS calloc function, but there is complexity around the possibility of C user modules calling into mbedTLS without holding the GIL. It would be interesting to try making a generic version for any malloc which fails, but this would require checking for a Python thread and probably making the GIL recursive. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-29extmod/lwip-include: Factor common lwIP config into lwipopts_common.h.Damien George
This lwIP configuration file has options that are common to all ports, and the ports are updated to use this file. This change is a no-op, the lwIP configuration remains the same for the four ports using this common file. This reduces code duplication, keeps the ports in sync, and makes it easier to update the configuration for all ports at once. Signed-off-by: Damien George <damien@micropython.org>
2025-01-29extmod/modlwip: Fix incorrect peer address for IPv6.Jared Hancock
For IPv6 connections, the peer address was previously defined as only the first four bytes of the IP address. For IPv6 addresses, this resulted in an incorrect IPv4 address. For instance, receiving a packet via `::recvfrom` from `'fe80::87:e7ff:fe48:629a'` is returned as having a peer address of `'254.128.0.0'` Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
2025-01-17lib/mbedtls: Update to mbedtls v3.6.2.Glenn Strauss
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2025-01-02extmod/moddeflate: Add missing size_t cast.Yoctopuce
To prevent compiler warnings. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2025-01-02extmod/modsocket: Add missing static in private function definitions.Yoctopuce
Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2024-12-23extmod/vfs_reader: Add support for opening a memory-mappable file.Damien George
If the file can be memory mapped (because it responds to the buffer protocol) then return a memory-reader that directly references the ROM data of the file. Signed-off-by: Damien George <damien@micropython.org>
2024-12-23extmod/vfs_rom: Add VfsRom filesystem object.Damien George
This commit defines a new ROMFS filesystem for storing read-only files that can be memory mapped, and a new VfsRom driver. Files opened from this filesystem support the buffer protocol. This allows naturally getting the memory-mapped address of the file using: - memoryview(file) - uctypes.addressof(file) Furthermore, if these files are .mpy files then their content can be referenced in-place when importing. Such imports take up a lot less RAM than importing from a normal filesystem. This is essentially dynamically frozen .mpy files, building on the revamped v6 .mpy file format. Signed-off-by: Damien George <damien@micropython.org>
2024-12-20extmod/vfs: Guard mutating fs functions with MICROPY_VFS_WRITABLE.Damien George
Enabled by default. Useful for ports that need the VFS but don't have any writable filesystems. Signed-off-by: Damien George <damien@micropython.org>
2024-12-18extmod/moductypes: Fix large return values of addressof and INT_MAYBE.Damien George
So they don't return a negative number for an address (prior to this fix they would return negative addresses for values that were larger than the maximum small-int value). Signed-off-by: Damien George <damien@micropython.org>
2024-12-10extmod/modplatform: Distinguish RISC-V 64 from RISC-V 32.Alessandro Gatti
This commit lets the platform module report a more accurate architecture name when running on a RISC-V 64 bits platform. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-12-10extmod/extmod.mk: Fix libmetal build prefix.iabdalkader
libmetal source files already have the build directory prefix, because they're auto-generated inside the build directory. When they're added to `SRC_THIRDPARTY_C`, another build directory prefix is added resulting in the object files being generated in a nested build directory. This patch strips the build directory prefix before adding libmetal's source files. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-11-30extmod/modplatform: Add Android to the recognised platforms list.Alessandro Gatti
This commit adds code to distinguish between regular Linux and Android, also adding a specific entry for the platform libc. The reported libc is marked as "bionic" and its version matches the Android platform API version (there are no definitions for a specific bionic version). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-11-30extmod/modplatform: Add Clang to the known compilers list.Alessandro Gatti
This commit adds support to distinguish between GCC and Clang to report the appropriate compiler version. Usually Clang also disguises itself as GCC for compatibility reasons, but these changes look for Clang-specific definitions first to avoid that problem. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-11-30extmod/modplatform: Distinguish AArch64 from AArch32.Alessandro Gatti
This commit adds a new platform architecture name for Arm CPUs running in 64 bits mode ("aarch64"). The 32 bits name is left as "arm" to maintain compatibility with existing code. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-11-28extmod/modframebuf: Fix 0 radius bug in FrameBuffer.ellipse.Corran Webster
This fixes a bug in FrameBuffer.ellipse where it goes into an infinite loop if both radii are 0. This fixes the bug with a simple pre-check to see if both radii are 0, and in that case sets a single pixel at the center. This is consistent with the behaviour of the method when called with just one of the radii set to 0, where it will draw a horizontal or vertical line of 1 pixel width. The pixel is set with setpixel_checked so it should handle out-of-bounds drawing correctly. This fix also includes three new tests: one for the default behaviour, one for drawing out-of-bounds, and one for when the sector mask is 0. Fixes issue #16053. Signed-off-by: Corran Webster <cwebster@unital.dev>
2024-11-20extmod/network_cyw43: Allow configuring active AP interface.Angus Gratton
Configuring the AP for cyw43 writes to some buffers that are only sent to the modem when the interface is brought up. This means you can't configure the AP after calling active(True), the new settings seem to be accepted but the radio doesn't change. This is different to the WLAN behaviour on other ports. The esp8266 port requires calling active(True) on the AP before configuring, even. Fix this by bouncing the AP interface after a config change, if it's active. Configuring with active(False) still works the same as before. Adds a static variable to track interface active state, rather than relying on the LWIP interface state. This is because the interface state is updated by a driver callback and there's a race: if code calls active(True) and then config(a=b) then the driver doesn't know it's active yet and the changes aren't correctly applied. It is possible this pattern will cause the AP to come up briefly with the default "PICOabcd" SSID before being reconfigured, however (due to the aforementioned race condition) it seems like this may not happen at all before the new config is applied. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-20extmod/network_cyw43: Fix uninitialised variable in status('stations').Damien George
The `num_stas` was uninitialised and if it happened to take the value 0 then no results were returned. It now has the correct maximum value. Signed-off-by: Damien George <damien@micropython.org>
2024-11-20extmod/network_cyw43: Fix isconnected() result on AP interface.Angus Gratton
This function is documented to return True if any stations are connected to the AP. Without this fix it returns True whenever the driver has brought the AP interface up. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-13extmod/vfs_blockdev: Support bool return from Python read/write blocks.Damien George
Commit f4ab9d924790581989f2398fe30bbac5d680577f inadvertently broke some Python block devices, for example esp32 and stm32 SDCard classes. Those classes return a bool from their `readblocks` and `writeblocks` methods instead of an integer errno code. With that change, both `False` and `True` return values are now be interpreted as non-zero and hence the block device call fails. The fix in this commit is to allow a bool and explicitly convert `True` to 0 and `False` to `-MP_EIO`. Signed-off-by: Damien George <damien@micropython.org>
2024-11-13extmod/network_ppp: Allow stream=None to suspend PPP.Daniël van de Giessen
This allows the stream to be set to `None`, which essentially stops all PPP communication without disconnecting the session. This allows replacing the stream on-the-fly to suspend it, for example to send AT commands to a modem without completely disconnecting and re-establishing the PPP connection: uart = ppp.config('stream') ppp.config(stream=None) uart.write(b'+++') # do some AT commands uart.write(b'ATO\r\n') ppp.config(stream=uart) Any attempted communication by PPP while the stream is not connected will register as simple packet loss to the LwIP stack because we return 0 for any write calls, and protocols like TCP will then automatically handle retrying. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-11-13extmod/network_ppp: Add stream config parameter.Daniël van de Giessen
This makes the stream that the PPP object wraps, which is normally only set once via the constructor, accessible and configurable via the `ppp.config()` method. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-11-13extmod/modlwip: Don't allow writing to a TCP socket that is connecting.Damien George
This follows the behaviour of unix MicroPython (POSIX sockets) and the esp32 port. Signed-off-by: Damien George <damien@micropython.org>
2024-11-05extmod/nimble: Remove asserts of ediv_rand_present and adjust comments.Damien George
Recent versions of NimBLE (since release 1.6.0) removed this variable; see https://github.com/apache/mynewt-nimble/commit/7cc8c08d67d52b373eeeec6b33b113192cf2e996. We never used it except in an assert, so remove those asserts to make the code compatible with newer NimBLE versions (eg for the esp32 port). Signed-off-by: Damien George <damien@micropython.org>
2024-11-04extmod/modlwip: Fix IGMP address type when IPv6 is enabled.Damien George
This was missed in 628abf8f25a7705a2810fffe2ca6ae652c532896. The the bug was that, when IPv6 is enabled, the `sizeof(ip_addr_t)` is much larger than IPv4 size, which is what's needed for IGMP addressing. Fixes issue #16100. Signed-off-by: Damien George <damien@micropython.org>
2024-10-25extmod/modtls_mbedtls: Support alternate sign callbacks in Python.iabdalkader
This commit enables the implementation of alternative mbedTLS cryptography functions, such as ECDSA sign and verify, in pure Python. Alternative functions are implemented in Python callbacks, that get invoked from wrapper functions when needed. The callback can return None to fall back to the default mbedTLS function. A common use case for this feature is with secure elements that have drivers implemented in Python. Currently, only the ECDSA alternate sign function wrapper is implemented. Tested signing with a private EC key stored on an NXP SE05x secure element. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-25extmod/modtls_mbedtls: Add a thread-global ptr for current SSL context.iabdalkader
This is necessary for mbedTLS callbacks that do not carry any user state, so those callbacks can be customised per SSL context. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-23extmod/network_wiznet5k: Reset mDNS when interface is brought up.Jared Hancock
The LwIP interface is removed in wiznet5k_deinit() which is called as part of the init sequence. Therefore, if using mDNS, then the interface will need to be re-added when bringing the interface up. Additionally, this allows to set the hostname from MicroPython code prior to bringing the interface up and mDNS responding to the (new) hostname. This allows the hostname to be configured and saved on the flash or be based on dynamic information such as the MAC or unique_id(). Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
2024-10-22extmod/modframebuf: Fix FrameBuffer size check for stride corner-cases.Corran Webster
This is a fix for issue #15944, and handles corner cases in the FrameBuffer code when using stride values where the last line's stride may extend past the end of the underlying buffer. This commit includes extra tests for these corner cases. For example a GS8 format FrameBuffer with a width of 8, height of 2 and stride of 10 should be able to fit into a buffer of size 18 (10 bytes for the first horizontal line, and 8 bytes for the second -- the full 10 bytes are not needed). Similarly a 1 by 9 FrameBuffer in MONO_VLSB format with a stride of 10 should be able to fit into a buffer of length 11 (10 bytes for the first 8 lines, and then one byte for the 9th line. Being able to do this is particularly important when cropping the corner of an existing FrameBuffer, either to copy a sprite or to clip drawing. Signed-off-by: Corran Webster <cwebster@unital.dev>
2024-10-09extmod/vfs_posix_file: Skip flush of tty handles in msvc debug builds.stijn
In MSVC debug builds with debug error reporting set to showing a dialog (to allow attaching the debugger), any application which imports the logging module and leaves the default handlers would result in this dialog because logging.shutdown is called at exit and that flushes the default handler which has stderr as its stream. This commit fixes that by not fsync'ing stdin/out/err. Also adds a comment related to checking whether a file is stdin/out/err, which is difficult to fix properly. Signed-off-by: stijn <stijn@ignitron.net>
2024-09-26extmod/vfs_blockdev: Implement common helper for read and write.Angus Gratton
- Code size saving as all of these functions are very similar. - Resolves the "TODO" of the plain read and write functions not propagating errors. An error in the underlying block device now causes VFatFs to return EIO, for example. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-26extmod/vfs_blockdev: Check block device function positive results.Angus Gratton
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes #13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-06extmod/libmetal: Fix libmetal rules for mkdir dependencies.iabdalkader
Dependency on auto-generated libmetal should be an order only prerequisite. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-09-06extmod/modlwip: Fix compile error for lwIP with SLIP support.cajt
Fixes a compile error if STM32 port is compiled with: make BOARD=(..) MICROPY_PY_LWIP=1 MICROPY_PY_LWIP_SLIP=1 `sio_send()` and `sio_tryread()` now use `mp_get_stream`. Signed-off-by: Carl Treudler <cjt@users.sf.net>
2024-08-29extmod/network_ppp_lwip: Add network.PPP via lwIP.Damien George
This commit adds a new `network.PPP` interface which works on any port that has bare-metal lwIP, eg rp2, stm32, mimxrt. It has been tested on stm32. A board needs to enable `MICROPY_PY_NETWORK_PPP_LWIP` and then it can use it as follows: import network ppp = network.PPP(uart) ppp.connect() while not ppp.isconnected(): pass # use `socket` module as usual, etc ppp.disconnect() Usually the application must first configure the cellular/etc UART link to get it connected and in to PPP mode first (eg ATD*99#), before handing over control to `network.PPP`. The PPP interface automatically configures the UART IRQ callback to call PPP.poll() on incoming data. Signed-off-by: Damien George <damien@micropython.org>
2024-08-29extmod: Update make and cmake scripts to work with latest lwIP.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-08-26extmod/network_wiznet5k: Add support for IPv6.Jared Hancock
This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack. Additionally, if LWIP_IPV6 is disabled, the device is configured to drop all IPv6 packets to reduce load on the MCU. Signed-off-by: Jared Hancock <jared@greezybacon.me>