Skip to content

Commit 393f256

Browse files
committed
wip: c33
1 parent 36225d1 commit 393f256

File tree

18 files changed

+2929
-2863
lines changed

18 files changed

+2929
-2863
lines changed

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ portentac33.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
484484
portentac33.menu.mode.llext=llext
485485
portentac33.menu.mode.linked=linked
486486

487-
portentac33.menu.mode.linked.build.extra_extra_ldflags=-lc -lm -lgcc -L{build.variant.path}
487+
portentac33.menu.mode.linked.build.extra_extra_ldflags=-lc -lm -lgcc -L{build.variant.path} -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
488488
portentac33.menu.mode.linked.build.llext_link_flags=
489489
portentac33.menu.mode.linked.build.suffix=_linked
490490
portentac33.menu.mode.linked.build.ldscript={runtime.platform.path}/variants/linked/linker_script.ld

cores/arduino/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "Arduino.h"
8+
#include "zephyr/kernel.h"
89
#include <cstdint>
910
#ifdef CONFIG_LLEXT
1011
#include <zephyr/llext/symbol.h>
@@ -59,7 +60,7 @@ static void __libc_init_array (void)
5960
__init_array_start[i] ();
6061
}
6162

62-
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(k_thread_stack_t* stack, size_t stack_size) {
63+
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(struct k_heap* stack, size_t stack_size) {
6364
// copy .data in the right place
6465
// .bss should already be in the right place
6566
// call constructors
@@ -68,7 +69,15 @@ extern "C" __attribute__((section(".entry_point"), used)) void entry_point(k_thr
6869
extern uintptr_t _edata;
6970
extern uintptr_t _sbss;
7071
extern uintptr_t _ebss;
72+
extern uintptr_t __heap_start;
73+
extern uintptr_t __heap_end;
7174
//__asm volatile ("cpsie i");
75+
76+
const size_t alignment = 4096;
77+
printk("Heap end: %p\n", &__heap_end);
78+
printk("Heap start: %p\n", &__heap_start);
79+
// __heap_start = (__heap_start + (alignment - 1)) & ~(alignment - 1);
80+
7281
memcpy(&_sdata, &_sidata, &_edata - &_sdata);
7382
memset(&_sbss, 0, &_ebss - &_sbss);
7483
__libc_init_array();

cores/arduino/new.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ void operator delete(void* ptr, void* place) noexcept {
132132
void operator delete[](void* ptr, void* place) noexcept {
133133
(void)ptr; (void)place; // unused
134134
// Nothing to do
135-
}
135+
}

extra/build.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ fi
3333
# Generate the provides.ld file for linked builds
3434
echo "Exporting provides.ld"
3535
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep FUNC | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' > variants/$variant/provides.ld
36-
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
37-
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE(llext_stack_size = "$3");"}' >> variants/$variant/provides.ld
36+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
37+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE(kheap_llext_heap_size = "$3");"}' >> variants/$variant/provides.ld
38+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
39+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE(kheap__system_heap_size = "$3");"}' >> variants/$variant/provides.ld
3840
cat build/zephyr/zephyr.map | grep __device_dts_ord | grep -v rodata | grep -v llext_const_symbol | awk -F' ' '{print "PROVIDE("$2" = "$1");"}' >> variants/$variant/provides.ld
3941
TEXT_START=`cat loader/boards/$variant.overlay | grep user_sketch: | cut -f2 -d"@" | cut -f1 -d"{"`
4042
echo "PROVIDE(_sketch_start = 0x$TEXT_START);" >> variants/$variant/provides.ld
43+
44+
sed -i 's/PROVIDE(malloc =/PROVIDE(__wrap_malloc =/g' variants/$variant/provides.ld
45+
sed -i 's/PROVIDE(free =/PROVIDE(__wrap_free =/g' variants/$variant/provides.ld
46+
sed -i 's/PROVIDE(realloc =/PROVIDE(__wrap_realloc =/g' variants/$variant/provides.ld
47+
sed -i 's/PROVIDE(calloc =/PROVIDE(__wrap_calloc =/g' variants/$variant/provides.ld
48+
sed -i 's/PROVIDE(random =/PROVIDE(__wrap_random =/g' variants/$variant/provides.ld

libraries/SocketWrapper/SocketHelpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class NetworkInterface {
135135
return (ret == 0);
136136
}
137137

138+
bool disconnect() {
139+
return (net_if_down(net_if_get_by_index(iface_index)) == 0);
140+
}
141+
138142
// TODO: manual functions for setting IP address, subnet mask, gateway, etc.
139143
// net_if_ipv4_set_netmask_by_addr(iface, &addr4, &nm);
140144
// net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
@@ -148,6 +152,14 @@ class NetworkInterface {
148152
}
149153
}
150154

155+
bool begin(uint8_t* mac_address, int _timeout, int _response_timeout) {
156+
return begin();
157+
}
158+
159+
bool begin(uint8_t* mac_address, IPAddress _ip, IPAddress _dns, IPAddress _gateway, IPAddress _netmask, int _timeout, int _response_timeout) {
160+
return begin();
161+
}
162+
151163
EthernetHardwareStatus hardwareStatus() {
152164
const struct device *const dev = DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ethernet_phy));
153165
if (device_is_ready(dev)) {

libraries/SocketWrapper/SocketWrapper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class ZephyrSocketWrapper {
117117
if (ca_certificate_pem != nullptr) {
118118
ret = tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
119119
ca_certificate_pem, strlen(ca_certificate_pem) + 1);
120-
Serial.println(ret);
121120
}
122121

123122
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);

libraries/SocketWrapper/ZephyrClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "SocketWrapper.h"
24
#include "api/Client.h"
35
#include "unistd.h"

libraries/SocketWrapper/ZephyrSSLClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "SocketWrapper.h"
24
#include "api/Client.h"
35
#include "unistd.h"

loader/boards/arduino_portenta_c33.conf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CONFIG_INIT_STACKS=y
4444

4545
CONFIG_NET_SOCKETS=y
4646
CONFIG_NET_SOCKETS_NET_MGMT=y
47-
#CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
47+
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
4848
CONFIG_NET_MGMT=y
4949
CONFIG_NET_MGMT_EVENT=y
5050
CONFIG_NET_L2_ETHERNET=y
@@ -58,11 +58,11 @@ CONFIG_NET_TCP=y
5858
CONFIG_NET_SOCKETS=y
5959
CONFIG_POSIX_API=y
6060

61-
#CONFIG_MBEDTLS=y
62-
#CONFIG_MBEDTLS_BUILTIN=y
63-
#CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
64-
#CONFIG_MBEDTLS_ENABLE_HEAP=y
65-
#CONFIG_MBEDTLS_HEAP_SIZE=60000
66-
#CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
67-
#CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
68-
#CONFIG_MBEDTLS_CMAC=y
61+
CONFIG_MBEDTLS=y
62+
CONFIG_MBEDTLS_BUILTIN=y
63+
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
64+
CONFIG_MBEDTLS_ENABLE_HEAP=y
65+
CONFIG_MBEDTLS_HEAP_SIZE=60000
66+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
67+
CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
68+
CONFIG_MBEDTLS_CMAC=y

loader/boards/arduino_portenta_c33.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272

7373
pwm-pin-gpios = <&ioport6 0 0>;
7474

75-
serials = <&cdc_acm_uart0>,<&uart9>;
76-
cdc-acm = <&cdc_acm_uart0>;
75+
serials = /*<&cdc_acm_uart0>,*/ <&uart9>;
76+
/* cdc-acm = <&cdc_acm_uart0>; */
7777
i2cs = <&iic1>;
7878
spis = <&spi1>;
7979
pwms = <&pwm6 1 PWM_HZ(25000000) PWM_POLARITY_NORMAL>;

loader/llext_exports.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ EXPORT_SYMBOL(z_log_msg_runtime_vcreate);
6060

6161
#if defined(CONFIG_NETWORKING)
6262
FORCE_EXPORT_SYM(net_if_foreach);
63+
FORCE_EXPORT_SYM(net_if_down);
6364
FORCE_EXPORT_SYM(net_if_get_by_iface);
6465
FORCE_EXPORT_SYM(net_if_ipv4_maddr_add);
6566
FORCE_EXPORT_SYM(net_if_ipv4_maddr_join);

loader/main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ const struct device *const usb_dev = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zep
2626

2727
static int enable_shell_usb(void);
2828

29-
K_THREAD_STACK_DEFINE(llext_stack, CONFIG_MAIN_STACK_SIZE);
30-
3129
#ifdef CONFIG_USERSPACE
30+
K_THREAD_STACK_DEFINE(llext_stack, CONFIG_MAIN_STACK_SIZE);
3231
struct k_thread llext_thread;
3332

3433
void llext_entry(void *arg0, void *arg1, void *arg2)
@@ -103,9 +102,9 @@ static int loader(const struct shell *sh)
103102
#if CONFIG_ICACHE
104103
barrier_isync_fence_full();
105104
#endif
106-
memset(llext_stack, 0, CONFIG_MAIN_STACK_SIZE);
107-
void (*entry_point)(k_thread_stack_t * stack, size_t stack_size) = (void (*)(k_thread_stack_t * stack, size_t stack_size))(offset+header_len+1);
108-
entry_point(llext_stack, K_THREAD_STACK_SIZEOF(llext_stack));
105+
extern struct k_heap llext_heap;
106+
void (*entry_point)(struct k_heap * heap, size_t heap_size) = (void (*)(struct k_heap * stack, size_t stack_size))(offset+header_len+1);
107+
entry_point(&llext_heap, llext_heap.heap.init_bytes);
109108
// should never reach here
110109
for (;;) {
111110
k_sleep(K_FOREVER);

loader/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ CONFIG_FLASH=y
4242
CONFIG_FLASH_MAP=y
4343

4444
CONFIG_CPP=y
45-
CONFIG_STD_CPP17=y
45+
CONFIG_STD_CPP17=y
46+
CONFIG_REQUIRES_FULL_LIBC=y

platform.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DARDUIN
8888
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
8989

9090
## Combine gc-sections, archives, and objects
91-
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} {build.extra_ldflags} {compiler.zephyr.ldflags} "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" {compiler.zephyr} {compiler.zephyr.extra_ldflags} {compiler.libraries.ldflags}
92-
#recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} {build.extra_ldflags} {compiler.zephyr.ldflags} "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" {compiler.zephyr} {compiler.zephyr.extra_ldflags} {compiler.libraries.ldflags}
91+
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} {build.extra_ldflags} {compiler.zephyr.ldflags} "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=picolibc.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" {compiler.zephyr} {compiler.zephyr.extra_ldflags} {compiler.libraries.ldflags}
9392

9493
## Create eeprom
9594
recipe.objcopy.eep.pattern=

variants/arduino_portenta_c33/llext-edk/include/modules/hal/renesas/drivers/ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/R7FA6M5BH.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9222,7 +9222,7 @@ typedef struct /*!< (@ 0x4009F000) R_IIC0 Structure
92229222

92239223
struct
92249224
{
9225-
__IOM uint8_t BC : 3; /*!< [2..0] Bit Counter */
9225+
__IOM uint8_t _BC : 3; /*!< [2..0] Bit Counter */
92269226
__OM uint8_t BCWP : 1; /*!< [3..3] BC Write Protect(This bit is read as 1.) */
92279227
__IOM uint8_t CKS : 3; /*!< [6..4] Internal Reference Clock (fIIC) Selection ( fIIC = PCLKB
92289228
* / 2^CKS ) */

variants/arduino_portenta_c33/llext-edk/include/zephyr/include/generated/zephyr/autoconf.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@
117117
#define CONFIG_ZEPHYR_LITTLEFS_MODULE 1
118118
#define CONFIG_ZEPHYR_LVGL_MODULE 1
119119
#define CONFIG_ZEPHYR_MBEDTLS_MODULE 1
120+
#define CONFIG_MBEDTLS 1
121+
#define CONFIG_MBEDTLS_BUILTIN 1
122+
#define CONFIG_MBEDTLS_CFG_FILE "config-tls-generic.h"
123+
#define CONFIG_MBEDTLS_TLS_VERSION_1_2 1
124+
#define CONFIG_MBEDTLS_PSK_MAX_LEN 32
125+
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 1
126+
#define CONFIG_MBEDTLS_SOME_AEAD_CIPHER_ENABLED 1
127+
#define CONFIG_MBEDTLS_SOME_CIPHER_ENABLED 1
128+
#define CONFIG_MBEDTLS_CIPHER_AES_ENABLED 1
129+
#define CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED 1
130+
#define CONFIG_MBEDTLS_CMAC 1
131+
#define CONFIG_MBEDTLS_HASH_ALL_ENABLED 1
132+
#define CONFIG_MBEDTLS_MD5 1
133+
#define CONFIG_MBEDTLS_SHA1 1
134+
#define CONFIG_MBEDTLS_SHA224 1
135+
#define CONFIG_MBEDTLS_SHA256 1
136+
#define CONFIG_MBEDTLS_SHA256_SMALLER 1
137+
#define CONFIG_MBEDTLS_SHA384 1
138+
#define CONFIG_MBEDTLS_SHA512 1
139+
#define CONFIG_MBEDTLS_POLY1305 1
140+
#define CONFIG_MBEDTLS_CTR_DRBG_ENABLED 1
141+
#define CONFIG_MBEDTLS_CIPHER 1
142+
#define CONFIG_MBEDTLS_MD 1
143+
#define CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT 1
144+
#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 7168
145+
#define CONFIG_MBEDTLS_LOG_LEVEL_DEFAULT 1
146+
#define CONFIG_MBEDTLS_LOG_LEVEL 3
147+
#define CONFIG_MBEDTLS_ENABLE_HEAP 1
148+
#define CONFIG_MBEDTLS_HEAP_SIZE 60000
149+
#define CONFIG_MBEDTLS_INIT 1
150+
#define CONFIG_APP_LINK_WITH_MBEDTLS 1
120151
#define CONFIG_ZEPHYR_MCUBOOT_MODULE 1
121152
#define CONFIG_ZEPHYR_SEGGER_MODULE 1
122153
#define CONFIG_HAS_SEGGER_RTT 1
@@ -676,8 +707,13 @@
676707
#define CONFIG_NET_SOCKETS_SERVICE 1
677708
#define CONFIG_NET_SOCKETS_SERVICE_THREAD_PRIO 15
678709
#define CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE 1200
710+
#define CONFIG_NET_SOCKETS_SOCKOPT_TLS 1
679711
#define CONFIG_NET_SOCKETS_TLS_PRIORITY 45
680712
#define CONFIG_NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH 1
713+
#define CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS 1
714+
#define CONFIG_NET_SOCKETS_TLS_MAX_CREDENTIALS 4
715+
#define CONFIG_NET_SOCKETS_TLS_MAX_CIPHERSUITES 4
716+
#define CONFIG_NET_SOCKETS_TLS_MAX_CLIENT_SESSION_COUNT 1
681717
#define CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY 40
682718
#define CONFIG_NET_SOCKETPAIR 1
683719
#define CONFIG_NET_SOCKETPAIR_BUFFER_SIZE 64
@@ -686,6 +722,11 @@
686722
#define CONFIG_NET_SOCKETS_NET_MGMT 1
687723
#define CONFIG_NET_SOCKETS_NET_MGMT_MAX_LISTENERS 1
688724
#define CONFIG_NET_SOCKETS_LOG_LEVEL 0
725+
#define CONFIG_TLS_CREDENTIALS 1
726+
#define CONFIG_TLS_CREDENTIALS_LOG_LEVEL_DEFAULT 1
727+
#define CONFIG_TLS_CREDENTIALS_LOG_LEVEL 3
728+
#define CONFIG_TLS_CREDENTIALS_BACKEND_VOLATILE 1
729+
#define CONFIG_TLS_MAX_CREDENTIALS_NUMBER 4
689730
#define CONFIG_NET_DHCPV4 1
690731
#define CONFIG_NET_DHCPV4_LOG_LEVEL 0
691732
#define CONFIG_NET_DHCPV4_INITIAL_DELAY_MAX 10

0 commit comments

Comments
 (0)