summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
Commit message (Collapse)AuthorAge
* drivers/esp-hosted: Rename Bluetooth HCI backend driver.iabdalkader8 days
| | | | | | | Rename `bthci` to `bthci_uart` for consistency with the CYW43 driver and to distinguish it from HCI backends that use a different transport. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modbluetooth: Use newer mp_map_slot_is_filled function.Andrew Leech8 days
| | | | | | Required in MICROPY_PREVIEW_VERSION_2. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/machine_usb_device: Add exception text wrappers.Andrew Leech8 days
| | | | | | Required in MICROPY_PREVIEW_VERSION_2. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/extmod.mk: Switch from drivers/cyw43/cywbt to lib/cyw43-drivers.Damien George2025-04-08
| | | | | | | | | | | | The cyw43-driver now provides the Bluetooth initialisation code, making `drivers/cyw43/cywbt.c` obsolete. To use the new code a port must enable the `CYW43_ENABLE_BLUETOOTH_OVER_UART` option. Some ports have yet to migrate to the new code, so in the meantime they can explicitly add the old source to their source list and continue to use it without change. Signed-off-by: Damien George <damien@micropython.org>
* extmod/extmod.mk: Add cyw43_spi.c to list of sources.Damien George2025-04-08
| | | | | | | This file is part of the updated cyw43-driver. It will only be used if `CYW43_USE_SPI` is enabled. Signed-off-by: Damien George <damien@micropython.org>
* rp2,esp32,extmod: Implement UPDATE_SUBMODULES in CMake.Angus Gratton2025-03-27
| | | | | | | | | | | | | | | Rather than having Make calling CMake to generate a list of submodules and then run a Make target (which is complex and prone to masking other errors), implement the submodule update logic in CMake itself. Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list, and the trigger variable name is changed from ECHO_SUBMODULES to UPDATE_SUBMODULES. The run is otherwise 100% a normal CMake run now, so most of the other special casing can be removed. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/vfs_rom: Implement minimal VfsRom.getcwd() method.Damien George2025-03-27
| | | | | | | | | | | 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>
* extmod/vfs: Return mount table from no-args vfs.mount call.Anson Mansfield2025-03-27
| | | | | | | | 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>
* extmod/vfs: Refactor mp_vfs_mount to enable no-args mount overload.Anson Mansfield2025-03-27
| | | | Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
* extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail.Damien George2025-03-27
| | | | | | | | | | | 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>
* extmod/network_cyw43: Add WPA3 security constants.Damien George2025-03-12
| | | | | | These are now supported by cyw43-driver. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Add mp_vfs_mount_romfs_protected() helper.Damien George2025-03-06
| | | | | | | 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>
* extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.Damien George2025-03-06
| | | | | | | 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>
* extmod/vfs_rom: Add bounds checking for all filesystem accesses.Damien George2025-02-26
| | | | | | | | | | | | | | | | | | | 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>
* all: Upgrade codespell to v2.4.1.Christian Clauss2025-02-25
| | | | | | | 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>
* extmod/modtls_mbedtls: Wire in support for DTLS.Keenan Johnson2025-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extmod/lwip-include: Increase number of lwIP timers when mDNS enabled.Thomas Watson2025-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extmod/vfs_rom: Remove ability to create VfsRom from an address.Damien George2025-02-11
| | | | | | | | | | 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>
* extmod/modmarshal: Add new marshal module.Damien George2025-02-11
| | | | | | | | | | | | | 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>
* extmod/mbedtls: Try GC before failing to setup socket on esp32, unix.Angus Gratton2025-02-03
| | | | | | | | | | | | | | | | | | | 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>
* extmod/lwip-include: Factor common lwIP config into lwipopts_common.h.Damien George2025-01-29
| | | | | | | | | | | 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>
* extmod/modlwip: Fix incorrect peer address for IPv6.Jared Hancock2025-01-29
| | | | | | | | | | 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>
* lib/mbedtls: Update to mbedtls v3.6.2.Glenn Strauss2025-01-17
| | | | Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
* extmod/moddeflate: Add missing size_t cast.Yoctopuce2025-01-02
| | | | | | To prevent compiler warnings. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
* extmod/modsocket: Add missing static in private function definitions.Yoctopuce2025-01-02
| | | | Signed-off-by: Yoctopuce <dev@yoctopuce.com>
* extmod/vfs_reader: Add support for opening a memory-mappable file.Damien George2024-12-23
| | | | | | | | 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>
* extmod/vfs_rom: Add VfsRom filesystem object.Damien George2024-12-23
| | | | | | | | | | | | | | | | 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>
* extmod/vfs: Guard mutating fs functions with MICROPY_VFS_WRITABLE.Damien George2024-12-20
| | | | | | | 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>
* extmod/moductypes: Fix large return values of addressof and INT_MAYBE.Damien George2024-12-18
| | | | | | | | 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>
* extmod/modplatform: Distinguish RISC-V 64 from RISC-V 32.Alessandro Gatti2024-12-10
| | | | | | | 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>
* extmod/extmod.mk: Fix libmetal build prefix.iabdalkader2024-12-10
| | | | | | | | | | | 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>
* extmod/modplatform: Add Android to the recognised platforms list.Alessandro Gatti2024-11-30
| | | | | | | | | 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>
* extmod/modplatform: Add Clang to the known compilers list.Alessandro Gatti2024-11-30
| | | | | | | | | 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>
* extmod/modplatform: Distinguish AArch64 from AArch32.Alessandro Gatti2024-11-30
| | | | | | | | 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>
* extmod/modframebuf: Fix 0 radius bug in FrameBuffer.ellipse.Corran Webster2024-11-28
| | | | | | | | | | | | | | | | | | | | 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>
* extmod/network_cyw43: Allow configuring active AP interface.Angus Gratton2024-11-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extmod/network_cyw43: Fix uninitialised variable in status('stations').Damien George2024-11-20
| | | | | | | 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>
* extmod/network_cyw43: Fix isconnected() result on AP interface.Angus Gratton2024-11-20
| | | | | | | | | | 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>
* extmod/vfs_blockdev: Support bool return from Python read/write blocks.Damien George2024-11-13
| | | | | | | | | | | | | | 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>
* extmod/network_ppp: Allow stream=None to suspend PPP.Daniël van de Giessen2024-11-13
| | | | | | | | | | | | | | | | | | | | | | | 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>
* extmod/network_ppp: Add stream config parameter.Daniël van de Giessen2024-11-13
| | | | | | | | 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>
* extmod/modlwip: Don't allow writing to a TCP socket that is connecting.Damien George2024-11-13
| | | | | | | This follows the behaviour of unix MicroPython (POSIX sockets) and the esp32 port. Signed-off-by: Damien George <damien@micropython.org>
* extmod/nimble: Remove asserts of ediv_rand_present and adjust comments.Damien George2024-11-05
| | | | | | | | | | 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>
* extmod/modlwip: Fix IGMP address type when IPv6 is enabled.Damien George2024-11-04
| | | | | | | | | | 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>
* extmod/modtls_mbedtls: Support alternate sign callbacks in Python.iabdalkader2024-10-25
| | | | | | | | | | | | | | | | 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>
* extmod/modtls_mbedtls: Add a thread-global ptr for current SSL context.iabdalkader2024-10-25
| | | | | | | 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>
* extmod/network_wiznet5k: Reset mDNS when interface is brought up.Jared Hancock2024-10-23
| | | | | | | | | | | | | 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>
* extmod/modframebuf: Fix FrameBuffer size check for stride corner-cases.Corran Webster2024-10-22
| | | | | | | | | | | | | | | | | | | | | 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>
* extmod/vfs_posix_file: Skip flush of tty handles in msvc debug builds.stijn2024-10-09
| | | | | | | | | | | | | | | 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>
* extmod/vfs_blockdev: Implement common helper for read and write.Angus Gratton2024-09-26
| | | | | | | | | | | - 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>