Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AnimatedGIF/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//
#include "AnimatedGIF_circuitpy.h"

#ifdef HAL_ESP32_HAL_H_
#ifndef memcpy_P
#define memcpy_P memcpy
#endif

Expand Down
9 changes: 9 additions & 0 deletions lib/mbedtls_config/crt_bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,32 @@ static int crt_check_signature(mbedtls_x509_crt *child, const uint8_t *pub_key_b
}


#if MBEDTLS_VERSION_MAJOR < 4
// Fast check to avoid expensive computations when not necessary
if (!mbedtls_pk_can_do(&parent.pk, child->MBEDTLS_PRIVATE(sig_pk))) {
LOGE(TAG, "Simple compare failed");
ret = -1;
goto cleanup;
}
#endif

md_info = mbedtls_md_info_from_type(child->MBEDTLS_PRIVATE(sig_md));
if ((ret = mbedtls_md(md_info, child->tbs.p, child->tbs.len, hash)) != 0) {
LOGE(TAG, "Internal mbedTLS error %X", ret);
goto cleanup;
}

#if MBEDTLS_VERSION_MAJOR >= 4
if ((ret = mbedtls_pk_verify_ext(
child->MBEDTLS_PRIVATE(sig_pk), &parent.pk,
child->MBEDTLS_PRIVATE(sig_md), hash, mbedtls_md_get_size(md_info),
child->MBEDTLS_PRIVATE(sig).p, child->MBEDTLS_PRIVATE(sig).len)) != 0) {
#else
if ((ret = mbedtls_pk_verify_ext(
child->MBEDTLS_PRIVATE(sig_pk), child->MBEDTLS_PRIVATE(sig_opts), &parent.pk,
child->MBEDTLS_PRIVATE(sig_md), hash, mbedtls_md_get_size(md_info),
child->MBEDTLS_PRIVATE(sig).p, child->MBEDTLS_PRIVATE(sig).len)) != 0) {
#endif

LOGE(TAG, "PK verify failed with error %X", ret);
goto cleanup;
Expand Down
3 changes: 3 additions & 0 deletions ports/zephyr-cp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ endif

.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash recover debug debug-jlink debugserver attach run run-sim clean menuconfig all clean-all sim clean-sim test fetch-port-submodules

export BSIM_COMPONENTS_PATH := $(CURDIR)/tools/bsim/components
export BSIM_OUT_PATH := $(CURDIR)/tools/bsim

$(BUILD)/zephyr-cp/zephyr/zephyr.elf:
python cptools/pre_zephyr_build_prep.py $(BOARD)
west build -b $(BOARD) -d $(BUILD) $(WEST_SHIELD_ARGS) --sysbuild -- $(WEST_CMAKE_ARGS)
Expand Down
7 changes: 1 addition & 6 deletions ports/zephyr-cp/boards/frdm_rw612.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ CONFIG_NET_HOSTNAME="circuitpython"

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_PKCS1_V15=y
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y
CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y
CONFIG_MBEDTLS_ENTROPY_C=y
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_CTR_DRBG_C=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_USE_PSA_CRYPTO=n

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sharpdisplay = true # Zephyr board has busio
socketpool = true # Zephyr networking enabled
spitarget = false
ssl = false
storage = true # Zephyr board has flash
storage = true
struct = true
supervisor = true
synthio = true # Zephyr board has audiobusio
Expand Down
4 changes: 2 additions & 2 deletions ports/zephyr-cp/boards/native_sim.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_NET_LOG=y

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_SHA256=y
CONFIG_PSA_WANT_ALG_SHA_1=y
CONFIG_PSA_WANT_ALG_SHA_256=y
1 change: 0 additions & 1 deletion ports/zephyr-cp/boards/nrf7002dk_nrf5340_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CONFIG_NETWORKING=y
CONFIG_WIFI=y

CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
CONFIG_MBEDTLS_USE_PSA_CRYPTO=n

CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
Expand Down
7 changes: 1 addition & 6 deletions ports/zephyr-cp/boards/rpi_pico2_rp2350a_m33_w.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ CONFIG_NET_HOSTNAME="circuitpython"

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_PKCS1_V15=y
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y
CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y
CONFIG_MBEDTLS_ENTROPY_C=y
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_CTR_DRBG_C=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_USE_PSA_CRYPTO=n
7 changes: 1 addition & 6 deletions ports/zephyr-cp/boards/rpi_pico_rp2040_w.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ CONFIG_NET_HOSTNAME="circuitpython"

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_PKCS1_V15=y
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y
CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y
CONFIG_MBEDTLS_ENTROPY_C=y
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_CTR_DRBG_C=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_USE_PSA_CRYPTO=n

CONFIG_TEST_RANDOM_GENERATOR=y
4 changes: 4 additions & 0 deletions ports/zephyr-cp/common-hal/busio/UART.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ mp_obj_t common_hal_busio_uart_construct_from_device(busio_uart_obj_t *self, con

// Internal helper for clearing buffer
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self);

// Zephyr-port-specific write-timeout accessors, used by usb_cdc/Serial.c.
mp_float_t common_hal_busio_uart_get_write_timeout(busio_uart_obj_t *self);
void common_hal_busio_uart_set_write_timeout(busio_uart_obj_t *self, mp_float_t write_timeout);
1 change: 1 addition & 0 deletions ports/zephyr-cp/common-hal/usb_cdc/Serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "shared/runtime/interrupt_char.h"
#include "shared-bindings/usb_cdc/Serial.h"
#include "shared-bindings/busio/UART.h"
#include "common-hal/busio/UART.h"
#include "supervisor/shared/tick.h"

mp_obj_t common_hal_usb_cdc_serial_construct_from_device(usb_cdc_serial_obj_t *self, const struct device *uart_device, uint16_t receiver_buffer_size, byte *receiver_buffer) {
Expand Down
1 change: 1 addition & 0 deletions ports/zephyr-cp/common-hal/wifi/ScannedNetworks.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/Radio.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
#include "bindings/zephyr_kernel/__init__.h"

#include <zephyr/kernel.h>
#include <zephyr/net/wifi_mgmt.h>
Expand Down
14 changes: 13 additions & 1 deletion ports/zephyr-cp/cptools/build_circuitpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,19 @@ async def build_circuitpython():
("-isystem", portdir / "modules" / "crypto" / "mbedtls" / "configs")
)
circuitpython_flags.extend(
("-isystem", portdir / "modules" / "crypto" / "mbedtls" / "include")
("-isystem", portdir / "modules" / "crypto" / "tf-psa-crypto" / "include")
)
circuitpython_flags.extend(
(
"-isystem",
portdir
/ "modules"
/ "crypto"
/ "tf-psa-crypto"
/ "drivers"
/ "builtin"
/ "include",
)
)
circuitpython_flags.extend(("-isystem", zephyrdir / "modules" / "mbedtls" / "configs"))
if "ssl" in enabled_modules:
Expand Down
19 changes: 19 additions & 0 deletions ports/zephyr-cp/cptools/zephyr2cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,25 @@ def find_flash_devices(device_tree):
)
continue

# Skip soc-nv-flash nodes whose parent is itself a flash device — the
# parent is the real Zephyr device (e.g. nxp,imx-flexspi-nor) and the
# child has no driver-instantiated symbol.
if "soc-nv-flash" in compatible and node.parent is not None:
parent_compat = []
if "compatible" in node.parent.props:
parent_compat = node.parent.props["compatible"].to_strings()
parent_drivers = []
for c in parent_compat:
underscored = c.replace(",", "_").replace("-", "_")
d = COMPAT_TO_DRIVER.get(underscored) or MANUAL_COMPAT_TO_DRIVER.get(underscored)
if d:
parent_drivers.append(d)
if "flash" in parent_drivers:
logger.debug(
f" skipping flash {node.labels[0] if node.labels else node.name} (parent is flash device)"
)
continue

if node.labels:
flashes.append(node.labels[0])

Expand Down
6 changes: 4 additions & 2 deletions ports/zephyr-cp/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CONFIG_FLASH_MAP_LABELS=y
CONFIG_MAIN_STACK_SIZE=24288

CONFIG_THREAD_STACK_INFO=y
CONFIG_ARCH_POSIX_UPDATE_STACK_INFO=y
CONFIG_STACK_SENTINEL=n
CONFIG_DEBUG_THREAD_INFO=n
CONFIG_EXCEPTION_STACK_TRACE=n
Expand Down Expand Up @@ -52,5 +53,6 @@ CONFIG_DYNAMIC_THREAD_PREFER_ALLOC=y

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_SHA256=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_PSA_WANT_ALG_SHA_1=y
CONFIG_PSA_WANT_ALG_SHA_256=y
3 changes: 2 additions & 1 deletion ports/zephyr-cp/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#include "common-hal/audiobusio/I2SOut.h"
#endif

#include <stdlib.h>

#include <zephyr/autoconf.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/sys/util.h>

#if defined(CONFIG_ARCH_POSIX)
#include <limits.h>
#include <stdlib.h>

#include "cmdline.h"
#include "posix_board_if.h"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ports/zephyr-cp/zephyr-config/west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ manifest:
path: modules/bsim_hw_models/nrf_hw_models
- name: zephyr
url: https://github.com/adafruit/zephyr
revision: d991bfc190507849d510326b24ba7b7a6c51a0e6
revision: e1dc85052bc8928572fdb972997c65eeb96f555b
clone-depth: 100
import: true
8 changes: 6 additions & 2 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
#define MICROPY_INCLUDED_PY_MPCONFIG_H

#include <stddef.h>
#include <stdint.h>

#if defined(__cplusplus) // Required on at least one compiler to get ULLONG_MAX
Expand Down Expand Up @@ -204,10 +205,13 @@

#if MP_INT_TYPE == MP_INT_TYPE_INTPTR
typedef intptr_t mp_int_t;
typedef uintptr_t mp_uint_t;
// Use size_t so kw-function signatures and other size-typed APIs match without
// triggering -Wincompatible-pointer-types under newer GCCs where size_t and
// uintptr_t are distinct types of the same width (e.g. picolibc on 32-bit ARM).
typedef size_t mp_uint_t;
#define MP_INT_MAX INTPTR_MAX
#define MP_INT_MIN INTPTR_MIN
#define MP_UINT_MAX INTPTR_UMAX
#define MP_UINT_MAX SIZE_MAX
#elif MP_INT_TYPE == MP_INT_TYPE_INT64
typedef int64_t mp_int_t;
typedef uint64_t mp_uint_t;
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/_bleio/CharacteristicBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static mp_uint_t bleio_characteristic_buffer_write(mp_obj_t self_in, const void
return 0;
}

static mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
raise_error_if_not_connected(self);
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static mp_uint_t busio_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_
return common_hal_busio_uart_write(self, buf, size, errcode);
}

static mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
busio_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);
mp_uint_t ret;
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/jpegio/JpegDecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(jpegio_jpegdecoder_open_obj, jpegio_jpegdecoder_open);
//| """
//|
//|
static mp_obj_t jpegio_jpegdecoder_decode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static mp_obj_t jpegio_jpegdecoder_decode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
jpegio_jpegdecoder_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);

enum { ARG_bitmap, ARG_scale, ARG_x, ARG_y, ARGS_X1_Y1_X2_Y2, ARG_skip_source_index, ARG_skip_dest_index };
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/socketpool/Socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
return ret;
}

static mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/ssl/SSLSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static mp_uint_t sslsocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si
return readwrite_common(self_in, common_hal_ssl_sslsocket_send, buf, size, errorcode);
}

static mp_uint_t sslsocket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t sslsocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
ssl_sslsocket_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(terminalio_terminal_get_cursor_y_obj, terminalio_termi
MP_PROPERTY_GETTER(terminalio_terminal_cursor_y_obj,
(mp_obj_t)&terminalio_terminal_get_cursor_y_obj);

static mp_uint_t terminalio_terminal_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t terminalio_terminal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
terminalio_terminal_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/usb_cdc/Serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static mp_uint_t usb_cdc_serial_write_stream(mp_obj_t self_in, const void *buf_i
return common_hal_usb_cdc_serial_write(self, buf, size, errcode);
}

static mp_uint_t usb_cdc_serial_ioctl_stream(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t usb_cdc_serial_ioctl_stream(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
usb_cdc_serial_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret = 0;
switch (request) {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/usb_midi/PortIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static mp_uint_t usb_midi_portin_read(mp_obj_t self_in, void *buf_in, mp_uint_t
return common_hal_usb_midi_portin_read(self, buf, size, errcode);
}

static mp_uint_t usb_midi_portin_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t usb_midi_portin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
usb_midi_portin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/usb_midi/PortOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static mp_uint_t usb_midi_portout_write(mp_obj_t self_in, const void *buf_in, mp
return common_hal_usb_midi_portout_write(self, buf, size, errcode);
}

static mp_uint_t usb_midi_portout_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
static mp_uint_t usb_midi_portout_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
usb_midi_portout_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
Expand Down
8 changes: 5 additions & 3 deletions supervisor/shared/workflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#endif
#endif

#if CIRCUITPY_TINYUSB || CIRCUITPY_USB_KEYBOARD_WORKFLOW
#if CIRCUITPY_USB_DEVICE || CIRCUITPY_USB_KEYBOARD_WORKFLOW
#include "supervisor/usb.h"
#endif
#if CIRCUITPY_TINYUSB
#include "tusb.h"
#endif

Expand Down Expand Up @@ -70,8 +72,8 @@ void supervisor_workflow_request_background(void) {
bool supervisor_workflow_active(void) {
#if CIRCUITPY_USB_DEVICE
// Eventually there might be other non-USB workflows, such as BLE.
// tud_ready() checks for usb mounted and not suspended.
if (tud_ready()) {
// usb_connected() checks for usb mounted and not suspended.
if (usb_connected()) {
return true;
}
#endif
Expand Down
Loading