summaryrefslogtreecommitdiff
path: root/extmod
AgeCommit message (Collapse)Author
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>
2024-08-26extmod/modtls_mbedtls: Optimise the DER certificate parsing fix.Angus Gratton
Small code size and binary size optimisation for the fix merged in 4d6d84983f370e48e81fb05fe31802e0a13fb369. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-14py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton
Currently the stack limit margin is hard-coded in each port's call to `mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to bugs (such as incorrect thread stack margin on esp32). This commit provides a new API to initialise the C Stack in one function call, with a config macro to set the margin. Where possible the new call is inlined to reduce code size in thread-free ports. Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32. The previous `stackctrl.h` API is still present and unmodified apart from a deprecation comment. However it's not available when the `MICROPY_PREVIEW_VERSION_2` macro is set. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-13extmod/modtls_mbedtls: Fix DER parsing and calculation of key/cert len.Peter Züger
`mbedtls_pk_parse_key()` expects `key_len` to include the NULL terminator for PEM data but not for DER encoded data. This also applies to `mbedtls_x509_crt_parse()` and `cert_len`. Since all PEM data contains "-----BEGIN" this is used to check if the data is PEM (as per mbedtls code). This can be done for both v2 and v3 of mbedtls since the fundamental behaviour/expectation did not change. What changed is that in v3 the PKCS#8 DER parser now checks that the passed key buffer is fully utilized and no bytes are remaining (all other DER formats still do not check this). Signed-off-by: Peter Züger <zueger.peter@icloud.com>
2024-08-08extmod/modopenamp: Use mp_event_* functions for poll/wait.iabdalkader
These are the new helper functions to use for polling/waiting. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-08extmod/modopenamp: Fix Endpoint callback required arg.iabdalkader
The callback arg is not actually required. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-08extmod/modopenamp: Add support for building Open-AMP on device side.iabdalkader
Tested with two VMs each running on a different core. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-08extmod/modopenamp_remoteproc: Fix entry point address int overflow.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-08extmod/libmetal: Remove source file listed twice in sources.iabdalkader
This causes multiple definition of symbols on some builds. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-07-23extmod/vfs: Fix buffer overflow of string comparison in umount.Junwha
The comparison between the given unmount string and existing mount strings were made by the given string, which leads to buffer overflow. Fixes issue #13006. Signed-off-by: Junwha <qbit@unist.ac.kr>
2024-07-23extmod/vfs_fat: Set default volume label on mkfs if it's defined.Terence Stenvold
Using mkfs doesn't set a volume label for FAT filesystems. This commit will set the volume label if `MICROPY_HW_FLASH_FS_LABEL` is defined.
2024-07-22extmod/moductypes: Validate the descriptor tuple.stijn
Fixes various null dereferencing, out-of-bounds memory accesses and `assert(0)` failures in the case of an invalid `uctypes` descriptor. By design `uctypes` can crash because it accesses arbitrary memory, but at least describing the descriptor layout should be forced to be correct and not crash. Fixes issue #12702. Signed-off-by: stijn <stijn@ignitron.net>
2024-07-22extmod/modbtree: Add checks for already-closed database.Michael Vornovitsky
Fixes use-after-free when accessing the database after it is closed with `btree_close`. `btree_close` always succeeds when called with an already-closed database. The new test checks that operations that access the underlying database (get, set, flush, seq) fail with a `ValueError` when the btree is already closed. It also checks that closing and printing the btree succeed when the btree is already closed. Fixes issue #12543. Signed-off-by: Michael Vornovitsky <michaelvornovitskiy@outlook.com>
2024-07-20extmod/modos: Include os.sep entry if MICROPY_VFS is enabled.Damien George
This simplifies configuration by removing the `MICROPY_PY_OS_SEP` option and instead including `os.sep` if `MICROPY_VFS` is enabled. That matches the configuration of all existing ports that enabled `os.sep` (they also had `MICROPY_VFS` enabled), and brings consistency to other ports. Fixes issue #15116. Signed-off-by: Damien George <damien@micropython.org>
2024-07-20extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.Damien George
It does the same thing, raising `SystemExit`. Signed-off-by: Damien George <damien@micropython.org>
2024-07-20shared/runtime/pyexec: Make a raised SystemExit always do a forced exit.Damien George
The current situation with SystemExit and soft reset is the following: - `sys.exit()` follows CPython and just raises `SystemExit`. - On the unix port, raising `SystemExit` quits the application/MicroPython, whether at the REPL or in code (this follows CPython behaviour). - On bare-metal ports, raising `SystemExit` at the REPL does nothing, raising it in code will stop the code and drop into the REPL. - `machine.soft_reset()` raises `SystemExit` but with a special flag set, and bare-metal targets check this flag when it propagates to the top-level and do a soft reset when they receive it. The original idea here was that a bare-metal target can't "quit" like the unix port can, and so dropping to the REPL was considered the same as "quit". But this bare-metal behaviour is arguably inconsistent with unix, and "quit" should mean terminate everything, including REPL access. This commit changes the behaviour to the following, which is more consistent: - Raising `SystemExit` on a bare-metal port will do a soft reset (unless the exception is caught by the application). - `machine.soft_reset()` is now equivalent to `sys.exit()`. - unix port behaviour remains unchanged. Tested running the test suite on an stm32 board and everything still passes, in particular tests that skip by raising `SystemExit` still correctly skip. Signed-off-by: Damien George <damien@micropython.org>
2024-07-15extmod/modre: Rename re_exec to re_exec_helper to avoid clash on BSD.Owen
The `re_exec` symbol is the name of a FreeBSD regex function, so needs to be renamed to avoid a clash when building on FreeBSD. (This clash was fixed once before but then accidentally reintroduced by the u-module renaming in 7f5d5c72718af773db751269c6ae14037b9c0727.) Fixes issue #15430. clarify as helper function
2024-07-12extmod/machine_spi: Support firstbit=LSB for machine.SoftSPI.robert-hh
Being able to send data out in LSB format can be useful, and having support in the low-level driver is much better than requiring Python code to reorder the bits before sending them / after receiving them. In particular if the hardware does not support the LSB format (eg RP2040) then one needs to use the SoftSPI in LSB mode. For this change a default definition of `MICROPY_PY_MACHINE_SPI_MSB/_LSB` was added to `py/mpconfig.h`, making them available to all ports. The identical defines in `esp32/mpconfigport.h` were deleted. Resolves issues #5340, #11404. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-12extmod/network_nina: Fix the AP security mode constants.iabdalkader
The only AP security mode supported is actually WPA/WPA2 not WEP. The firmware command `0x19` starts the AP using `WIFI_AUTH_WPA_WPA2_PSK` mode. There are no functional changes in this commit, it just fixes the constant names and removes the useless sanity checks for WEP. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-07-11extmod/modmachine: Allow more than one argument to machine.freq().robert-hh
The limit is set by a `MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX` define, which defaults to 1 and is set for stm32 to 4. For stm32 this fixes a regression introduced in commit e1ec6af654b1c5c4a973b6c6b029ee68bb92eb89 where the maximum number of arguments was changed from 4 to 1. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-04all: Use new mp_obj_new_str_from_cstr() function.Jon Foster
Use new function mp_obj_new_str_from_cstr() where appropriate. It simplifies the code, and makes it smaller too. Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
2024-07-02extmod/mbedtls: Enable GCM and ECDHE-RSA in common mbedtls config.Sylvain Zimmer
Enable support for cipher suites like TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, as suggested in https://github.com/micropython/micropython/issues/14204#issuecomment-2024366349 and https://github.com/micropython/micropython/issues/10485#issuecomment-1396426824 Tests have been run on the top 500 domains from moz.com. Without this patch, 155 out of 500 fail to connect because of TLS issues. This patch fixes them all. And it seems all existing mbedtls flags are needed to get good coverage of those top 500 domains. The `ssl_poll.py` test has the cipher bits increased from 512 to 1024 in its test key/cert so that it can work with ECDHE-RSA which is now the chosen cipher. Signed-off-by: Sylvain Zimmer <sylvain@sylvainzimmer.com> Signed-off-by: Damien George <damien@micropython.org>
2024-07-02extmod/machine_usb_device: Add USBDevice.remote_wakeup method.Felix Dörre
This simply exposes the TinyUSB function. Signed-off-by: Felix Dörre <felix@dogcraft.de>