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
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ add_custom_target(generate_messages DEPENDS ${MSG_GENERATED_FILE})

if(NOT "${OCRE_INPUT_FILE}" STREQUAL "")
message("Using input file: ${OCRE_INPUT_FILE}")

# Extract filename without extension for use in software
get_filename_component(OCRE_INPUT_FILE_NAME ${OCRE_INPUT_FILE} NAME_WE)
message("Input file name (without extension): ${OCRE_INPUT_FILE_NAME}")
add_definitions(-DOCRE_INPUT_FILE_NAME="${OCRE_INPUT_FILE_NAME}")

add_custom_command(
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g
COMMAND xxd -n wasm_binary -i ${OCRE_INPUT_FILE} > ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g
COMMAND xxd -i ${OCRE_INPUT_FILE} | sed 's/unsigned char .*\\[/static const unsigned char wasm_binary[/' | sed 's/unsigned int .*_len/static const unsigned int wasm_binary_len/' > ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g
DEPENDS ${OCRE_INPUT_FILE}
COMMENT "Generating C header from ${OCRE_INPUT_FILE}"
)
Expand Down
7 changes: 7 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ config OCRE_WAMR_HEAP_BUFFER_SIZE
help
A static memory allocation for WAMR to use as a heap.

config OCRE_STORAGE_HEAP_BUFFER_SIZE
int "Storage heap buffer size in bytes"
default 500000
depends on MEMC
help
A static memory allocation for container storage to use as a heap.

config OCRE_CONTAINER_DEFAULT_HEAP_SIZE
int "Default value for the container heap size"
default 4096
Expand Down
3 changes: 2 additions & 1 deletion boards/b_u585i_iot02a.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CONFIG_MEMC=y

# Container defaults
CONFIG_MAX_CONTAINERS=5
CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE=8388608
CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE=6388608
CONFIG_OCRE_STORAGE_HEAP_BUFFER_SIZE=2000000

# Bus interfaces
CONFIG_GPIO=y
Expand Down
35 changes: 32 additions & 3 deletions boards/b_u585i_iot02a.overlay
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <zephyr/dt-bindings/pinctrl/stm32-pinctrl.h>

/ {
chosen {
zephyr,code-partition = &slot0_partition;
};

aliases {
rng0 = &rng_device;
led0 = &green_led_1;
Expand Down Expand Up @@ -82,12 +86,37 @@
};
};

/* Optional: flash partitions */
/* Flash partitions - 2MB total, no MCUboot */
&flash0 {
/delete-node/ partitions;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

/* Application partition - 1900KB */
slot0_partition: partition@0 {
label = "image-0";
reg = <0x00000000 DT_SIZE_K(2000)>;
};
/* Dummy slot1 partition for MCUboot compatibility (unused) */
slot1_partition: partition@1F5000 {
label = "image-1";
reg = <0x001F5000 DT_SIZE_K(44)>;
};
};
};

// 64MB external flash
&mx25lm51245 {
partitions {
user_data_partition: partition@100000 {
/delete-node/ partition;

/* Use the whole flash for the filesystem. */
user_data_partition: storage_partition: partition@0 {
label = "user_data";
reg = <0x00100000 DT_SIZE_K(256)>;
reg = <0x00000000 DT_SIZE_M(64)>;
};
};
};
Expand Down
33 changes: 16 additions & 17 deletions src/ocre/components/container_supervisor/cs_sm_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ LOG_MODULE_DECLARE(ocre_cs_component, OCRE_LOG_LEVEL);
#include "cs_sm.h"
#include "cs_sm_impl.h"

// External RAM support for WAMR heap on boards that have it
#include "ocre_psram.h"

// WAMR heap buffer - uses PSRAM when available
#if defined(CONFIG_MEMC)
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_H7)
__attribute__((section("SDRAM1"), aligned(32)))
#elif defined(CONFIG_BOARD_B_U585I_IOT02A)
__attribute__((section(".stm32_psram"), aligned(32)))
#elif defined(CONFIG_BOARD_MIMXRT1064_EVK)
__attribute__((section("SDRAM"), aligned(32)))
#endif // defined (<board>)
#endif // defined(CONFIG_MEMC)
PSRAM_SECTION_ATTR
#endif
static char wamr_heap_buf[CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE] = {0};


// Thread pool for container execution
#define CONTAINER_THREAD_POOL_SIZE 4
static core_thread_t container_threads[CONTAINER_THREAD_POOL_SIZE];
Expand Down Expand Up @@ -178,6 +175,7 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
size_t file_size = 0;
void *file_handle = NULL;
char filepath[FILE_PATH_MAX];


ret = core_construct_filepath(filepath, sizeof(filepath), container_data->sha256);
if (ret < 0) {
Expand All @@ -191,9 +189,9 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
}

container_arguments->size = file_size;
container_arguments->buffer = malloc(file_size);
container_arguments->buffer = storage_heap_alloc(file_size);
if (!container_arguments->buffer) {
LOG_ERR("Failed to allocate memory for container binary.");
LOG_ERR("Failed to allocate memory for container binary from PSRAM.");
return -ENOMEM;
}

Expand All @@ -202,22 +200,22 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
ret = core_fileopen(filepath, &file_handle);
if (ret < 0) {
LOG_ERR("Failed to open file %s: %d", filepath, ret);
free(container_arguments->buffer);
storage_heap_free(container_arguments->buffer);
return ret;
}

ret = core_fileread(file_handle, container_arguments->buffer, file_size);
if (ret < 0) {
LOG_ERR("Failed to read file %s: %d", filepath, ret);
core_fileclose(file_handle);
free(container_arguments->buffer);
storage_heap_free(container_arguments->buffer);
return ret;
}

ret = core_fileclose(file_handle);
if (ret < 0) {
LOG_ERR("Failed to close file %s: %d", filepath, ret);
free(container_arguments->buffer);
storage_heap_free(container_arguments->buffer);
return ret;
}
return 0;
Expand Down Expand Up @@ -268,6 +266,7 @@ ocre_container_runtime_status_t CS_runtime_init(ocre_cs_ctx *ctx, ocre_container
#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
ocre_messaging_init();
#endif
storage_heap_init();
return RUNTIME_STATUS_INITIALIZED;
}

Expand Down Expand Up @@ -322,7 +321,7 @@ ocre_container_status_t CS_create_container(ocre_container_t *container) {
curr_container_arguments->error_buf, sizeof(curr_container_arguments->error_buf));
if (!curr_container_arguments->module) {
LOG_ERR("Failed to load WASM module: %s", curr_container_arguments->error_buf);
free(curr_container_arguments->buffer);
storage_heap_free(curr_container_arguments->buffer);
return CONTAINER_STATUS_ERROR;
}

Expand Down Expand Up @@ -381,7 +380,7 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) {
LOG_ERR("Failed to instantiate WASM module: %s, for containerID= %d", curr_container_arguments->error_buf,
curr_container_ID);
wasm_runtime_unload(curr_container_arguments->module);
free(curr_container_arguments->buffer);
storage_heap_free(curr_container_arguments->buffer);
return CONTAINER_STATUS_ERROR;
}
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \
Expand Down Expand Up @@ -514,7 +513,7 @@ ocre_container_status_t CS_destroy_container(ocre_container_t *container, ocre_c
}

if (container->ocre_runtime_arguments.buffer) {
free(container->ocre_runtime_arguments.buffer);
storage_heap_free(container->ocre_runtime_arguments.buffer);
container->ocre_runtime_arguments.buffer = NULL;
}

Expand Down
8 changes: 6 additions & 2 deletions src/samples-mini/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ int ocre_network_init();
int main(int argc, char *argv[]) {
ocre_cs_ctx ctx;
ocre_container_init_arguments_t args;
char *container_filename = "hello";
#ifdef OCRE_INPUT_FILE_NAME
const char *container_filename = OCRE_INPUT_FILE_NAME;
#else
const char *container_filename = "hello-from-ocre";
#endif

#ifdef CONFIG_OCRE_NETWORKING
int net_status = ocre_network_init();
Expand All @@ -52,7 +56,7 @@ int main(int argc, char *argv[]) {
int container_ID;

ocre_container_data.heap_size = 0;
snprintf(ocre_container_data.name, sizeof(ocre_container_data.name), "Hello World");
snprintf(ocre_container_data.name, sizeof(ocre_container_data.name), "%s", container_filename);
snprintf(ocre_container_data.sha256, sizeof(ocre_container_data.sha256), "%s", container_filename);
ocre_container_data.timers = 0;
ocre_container_runtime_create_container(&ctx, &ocre_container_data, &container_ID, NULL);
Expand Down
31 changes: 31 additions & 0 deletions src/shared/platform/ocre_psram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef OCRE_PSRAM
#define OCRE_PSRAM

// PSRAM configuration - centralized for different platforms
#if defined(CONFIG_MEMC)
// Board-specific PSRAM section attributes
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_H7)
#define PSRAM_SECTION_ATTR __attribute__((section("SDRAM1"), aligned(32)))
#elif defined(CONFIG_BOARD_B_U585I_IOT02A)
#define PSRAM_SECTION_ATTR __attribute__((section(".stm32_psram"), aligned(32)))
#elif defined(CONFIG_BOARD_MIMXRT1064_EVK)
#define PSRAM_SECTION_ATTR __attribute__((section("SDRAM"), aligned(32)))
#else
#define PSRAM_SECTION_ATTR __attribute__((aligned(32)))
#endif

PSRAM_SECTION_ATTR
static char storage_heap_buf[CONFIG_OCRE_STORAGE_HEAP_BUFFER_SIZE] = {0};

static struct k_heap storage_heap;
#define storage_heap_init() k_heap_init(&storage_heap, storage_heap_buf, CONFIG_OCRE_STORAGE_HEAP_BUFFER_SIZE)
#define storage_heap_alloc(size) k_heap_alloc(&storage_heap, (size), K_SECONDS(1))
#define storage_heap_free(buffer) k_heap_free(&storage_heap, (void*)buffer)
#else
// No PSRAM - use system malloc
#define storage_heap_init() /* No initialization needed */
#define storage_heap_alloc(size) malloc(size)
#define storage_heap_free(buffer) free(buffer)
#endif

#endif /* OCRE_PSRAM*/