@@ -20,6 +20,8 @@ LOG_MODULE_REGISTER(app);
20
20
#include <zephyr/drivers/uart.h>
21
21
#include <zephyr/usb/usb_device.h>
22
22
23
+ #define HEADER_LEN 16
24
+
23
25
#if DT_NODE_HAS_PROP (DT_PATH (zephyr_user ), cdc_acm )
24
26
const struct device * const usb_dev = DEVICE_DT_GET (DT_PHANDLE_BY_IDX (DT_PATH (zephyr_user ), cdc_acm , 0 ));
25
27
#endif
@@ -49,9 +51,10 @@ static int loader(const struct shell *sh)
49
51
return rc ;
50
52
}
51
53
52
- uint32_t offset = DT_REG_ADDR (DT_GPARENT (DT_NODELABEL (user_sketch ))) + DT_REG_ADDR (DT_NODELABEL (user_sketch ));
54
+ uintptr_t base_addr = DT_REG_ADDR (DT_GPARENT (DT_NODELABEL (user_sketch ))) +
55
+ DT_REG_ADDR (DT_NODELABEL (user_sketch ));
53
56
54
- char header [16 ];
57
+ char header [HEADER_LEN ];
55
58
rc = flash_area_read (fa , 0 , header , sizeof (header ));
56
59
if (rc ) {
57
60
printk ("Failed to read header, rc %d\n" , rc );
@@ -89,10 +92,9 @@ static int loader(const struct shell *sh)
89
92
}
90
93
#endif
91
94
92
- int header_len = 16 ;
93
-
94
95
uint8_t linked = endptr [2 ];
95
96
if (linked ) {
97
+ #ifdef CONFIG_BOARD_ARDUINO_PORTENTA_C33
96
98
#if CONFIG_MPU
97
99
barrier_dmem_fence_full ();
98
100
#endif
@@ -102,8 +104,11 @@ static int loader(const struct shell *sh)
102
104
#if CONFIG_ICACHE
103
105
barrier_isync_fence_full ();
104
106
#endif
107
+ #endif
108
+
105
109
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 );
110
+ typedef void (* entry_point_t )(struct k_heap * heap , size_t heap_size );
111
+ entry_point_t entry_point = (entry_point_t )(base_addr + HEADER_LEN + 1 );
107
112
entry_point (& llext_heap , llext_heap .heap .init_bytes );
108
113
// should never reach here
109
114
for (;;) {
@@ -125,7 +130,7 @@ static int loader(const struct shell *sh)
125
130
}
126
131
#else
127
132
// Assuming the sketch is stored in the same flash device as the loader
128
- uint8_t * sketch_buf = (uint8_t * )(offset + header_len );
133
+ uint8_t * sketch_buf = (uint8_t * )(base_addr + HEADER_LEN );
129
134
#endif
130
135
131
136
#ifdef CONFIG_LLEXT
@@ -219,4 +224,4 @@ int main(void)
219
224
{
220
225
loader (NULL );
221
226
return 0 ;
222
- }
227
+ }
0 commit comments