[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/LIBWAMR PATCH 1/1] libs/wamr: WAMR baremetal demo running on a Raspberry Pi3 B+



WAMR baremetal demo running on a Raspberry Pi3 B+

Signed-off-by: Santiago Pagani <santiagopagani@xxxxxxxxx>
---
 Makefile.uk                                 | 57 ++++++++++++++---
 patches/0005-adapt-main-c-to-unikraft.patch |  9 ---
 patches/0006-clock_gettime.patch            | 70 +++++++++++++++++++++
 patches/0007-export-gui-symbols.patch       | 17 +++++
 patches/0008-wgl_obj_wrapper.patch          | 67 ++++++++++++++++++++
 patches/0009-event.patch                    | 11 ++++
 6 files changed, 213 insertions(+), 18 deletions(-)
 create mode 100644 patches/0006-clock_gettime.patch
 create mode 100644 patches/0007-export-gui-symbols.patch
 create mode 100644 patches/0008-wgl_obj_wrapper.patch
 create mode 100644 patches/0009-event.patch

diff --git a/Makefile.uk b/Makefile.uk
index 7bbf500..8babbf0 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -65,6 +65,15 @@ CINCLUDES-$(CONFIG_LIBWAMR) += -I$(LIBWAMR_BASE)/include
                               -I$(LIBWAMR_SRC)/core/iwasm/runtime/include      
 \
                               
-I$(LIBWAMR_SRC)/core/shared-lib/platform/include \
                               -I$(LIBWAMR_SRC)/core/shared-lib/include         
 \
+                              -I$(LIBWAMR_SRC)/core/shared-lib/utils          \
+                              -I$(LIBWAMR_SRC)/core/iwasm/lib/native-interface 
\
+                              
-I$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/sensor \
+                              
-I$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui \
+                              -I$(LIBWAMR_SRC)/core/app-mgr/app-mgr-shared \
+                              -I$(LIBWAMR_SRC)/core/app-mgr/app-manager \
+                              -I$(LIBWAMR_SRC)/core/shared-lib/coap/extension \
+                              -I$(LIBWAMR_SRC)/core/shared-lib/coap/er-coap \
+                              -I$(LIBWAMR_SRC)/core/iwasm/lib/native/base
 
 
################################################################################
 # Library flags
@@ -77,10 +86,12 @@ LIBWAMR_SUPPRESS_FLAGS += 
-Wno-implicit-function-declaration \
                          -Wno-unused-label                  \
                          -Wno-unused-but-set-variable       \
                          -Wno-cast-function-type            \
-                         -Wno-implicit-fallthrough
+                         -Wno-implicit-fallthrough          \
+                         -Wno-int-to-pointer-cast           \
+                         -Wno-pointer-sign
 
-LIBWAMR_CFLAGS-y += -DNVALGRIND $(LIBWAMR_SUPPRESS_FLAGS)
-LIBWAMR_CXXFLAGS-y += -DNVALGRIND $(LIBWAMR_SUPPRESS_FLAGS)
+LIBWAMR_CFLAGS-y += -DLV_CONF_INCLUDE_SIMPLE -DNVALGRIND 
$(LIBWAMR_SUPPRESS_FLAGS)
+LIBWAMR_CXXFLAGS-y += -DLV_CONF_INCLUDE_SIMPLE -DNVALGRIND 
$(LIBWAMR_SUPPRESS_FLAGS)
 
 
################################################################################
 # Glue code
@@ -97,16 +108,44 @@ LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/runtime/vmcore-wasm/wasm_application
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/vmcore-wasm/wasm_interp.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/vmcore-wasm/wasm_loader.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/vmcore-wasm/wasm_runtime.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/bh_memory.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/utils/wasm_log.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_thread.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/utils/wasm_hashmap.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/lib/native/libc/libc_wrapper.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/runtime/utils/wasm_dlfcn.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/mem_alloc.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_platform.c
 LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/runtime/platform/zephyr/wasm_native.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/lib/native/base/base_lib_export.c
-LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/products/linux/ext_lib_export.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/lib/native/libc/libc_wrapper.c
+#LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/app-libs/base/bh_platform.c|base
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/bh_memory.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/mem_alloc.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/ems/ems_kfc.c
 LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/mem-alloc/ems/ems_alloc.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/utils/bh_queue.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_thread.c
+#LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/products/linux/ext_lib_export.c
+
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native-interface/attr_container.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/module_utils.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/app_manager.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/watchdog.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/iwasm/lib/native/base/timer_wrapper.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/utils/runtime_timer.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native-interface/restful_utils.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/message.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/event.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/app_manager_host.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/resource_reg.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/utils/bh_list.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_time.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_platform.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/shared-lib/platform/linux/bh_definition.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/module_wasm_app.c
+LIBWAMR_SRCS-y += $(LIBWAMR_SRC)/core/app-mgr/app-manager/module_wasm_lib.c
+
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/samples/gui/wasm-runtime-wgl/src/ext_lib_export.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_btn_wrapper.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_native_utils.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_obj_wrapper.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_label_wrapper.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_list_wrapper.c
+LIBWAMR_SRCS-y += 
$(LIBWAMR_SRC)/core/iwasm/lib/native/extension/gui/wgl_cb_wrapper.c
diff --git a/patches/0005-adapt-main-c-to-unikraft.patch 
b/patches/0005-adapt-main-c-to-unikraft.patch
index c8f73e5..086b7e8 100644
--- a/patches/0005-adapt-main-c-to-unikraft.patch
+++ b/patches/0005-adapt-main-c-to-unikraft.patch
@@ -9,15 +9,6 @@
  static int app_argc;
  static char **app_argv;
  
-@@ -158,7 +160,7 @@
-     return NULL;
- }
- 
--#define USE_GLOBAL_HEAP_BUF 0
-+#define USE_GLOBAL_HEAP_BUF 1
- 
- #if USE_GLOBAL_HEAP_BUF != 0
- static char global_heap_buf[10 * 1024 * 1024] = { 0 };
 @@ -177,15 +179,11 @@
      int log_verbose_level = 1;
  #endif
diff --git a/patches/0006-clock_gettime.patch b/patches/0006-clock_gettime.patch
new file mode 100644
index 0000000..087e81c
--- /dev/null
+++ b/patches/0006-clock_gettime.patch
@@ -0,0 +1,70 @@
+--- a/core/iwasm/lib/app-libs/libc/lib_base.h  2019-09-09 14:51:40.000000000 
+0200
++++ b/core/iwasm/lib/app-libs/libc/lib_base.h  2019-11-07 13:35:38.697247453 
+0100
+@@ -37,6 +37,7 @@
+ size_t strlen(const char *s);
+ int strncmp(const char * str1, const char * str2, size_t n);
+ char *strncpy(char *dest, const char *src, unsigned long n);
++int clock_gettime(clockid_t clk_id, struct timespec *tp);
+ 
+ #ifdef __cplusplus
+ }
+--- a/core/iwasm/lib/3rdparty/lv_conf.h        2019-12-16 11:31:38.000000000 
+0100
++++ b/core/iwasm/lib/3rdparty/lv_conf.h        2019-12-16 11:31:47.000000000 
+0100
+@@ -488,7 +488,7 @@
+ /*--END OF LV_CONF_H--*/
+ 
+ /*Be sure every define has a default value*/
+-#include "lvgl/src/lv_conf_checker.h"
++//#include "lvgl/src/lv_conf_checker.h"
+ 
+ #endif /*LV_CONF_H*/
+ 
+--- a/core/iwasm/lib/native/libc/libc_wrapper.c        2019-09-09 
14:51:40.000000000 +0200
++++ b/core/iwasm/lib/native/libc/libc_wrapper.c        2019-11-07 
13:35:38.697247453 +0100
+@@ -18,6 +18,10 @@
+ #include "wasm_export.h"
+ #include "wasm_log.h"
+ #include "wasm_platform_log.h"
++#include <time.h>
++#if CONFIG_PLAT_RASPI
++#include <raspi/time.h>
++#endif
+
+ void
+ wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
+@@ -908,6 +912,25 @@
+     wasm_runtime_set_exception(module_inst, buf);
+ }
+
++static int
++_clock_gettime_wrapper(clockid_t clk_id, int32 tp_offset)
++{
++       wasm_module_inst_t module_inst = get_module_inst();
++    struct timespec *tp_native;
++
++    if (!validate_app_addr(tp_offset, sizeof(struct timespec *)))
++       return -1;
++
++    tp_native = addr_app_to_native(tp_offset);
++    #if CONFIG_PLAT_RASPI
++        // When running WAMR on the Raspberry Pi, we add support to WAMR for 
clock_gettime
++        // using the Raspberry Pi's system timer. Therefore, WAMR will need 
to include the
++        // raspi/time.h header to use the get_system_timer() function.
++        tp_native->tv_sec = get_system_timer();
++    #endif
++    return 0;
++}
++
+ /*#define ENABLE_SPEC_TEST 1*/
+
+ #ifdef ENABLE_SPEC_TEST
+@@ -969,7 +992,8 @@
+     REG_NATIVE_FUNC(env, _emscripten_memcpy_big),
+     REG_NATIVE_FUNC(env, abort),
+     REG_NATIVE_FUNC(env, abortStackOverflow),
+-    REG_NATIVE_FUNC(env, nullFunc_X)
++    REG_NATIVE_FUNC(env, nullFunc_X),
++    REG_NATIVE_FUNC(env, _clock_gettime)
+ };
+
+ void*
diff --git a/patches/0007-export-gui-symbols.patch 
b/patches/0007-export-gui-symbols.patch
new file mode 100644
index 0000000..e10daee
--- /dev/null
+++ b/patches/0007-export-gui-symbols.patch
@@ -0,0 +1,17 @@
+--- a/samples/gui/wasm-runtime-wgl/src/ext_lib_export.c        2020-01-23 
15:23:26.423734785 +0100
++++ b/samples/gui/wasm-runtime-wgl/src/ext_lib_export.c        2020-01-23 
10:15:54.266465950 +0100
+@@ -4,9 +4,12 @@
+ #include "gui_api.h"
+ 
+ static NativeSymbol extended_native_symbol_defs[] = {
+-#include "runtime_sensor.inl"
+-#include "connection.inl"
++  //#include "runtime_sensor.inl"
++  //#include "connection.inl"
+ #include "wamr_gui.inl"
++EXPORT_WASM_API(wasm_create_timer),
++EXPORT_WASM_API(wasm_timer_cancel),
++EXPORT_WASM_API(wasm_timer_restart),
+ };
+ 
+ #include "ext_lib_export.h"
diff --git a/patches/0008-wgl_obj_wrapper.patch 
b/patches/0008-wgl_obj_wrapper.patch
new file mode 100644
index 0000000..aef412f
--- /dev/null
+++ b/patches/0008-wgl_obj_wrapper.patch
@@ -0,0 +1,67 @@
+--- a/core/iwasm/lib/native/extension/gui/wgl_obj_wrapper.c    2019-09-09 
14:51:40.000000000 +0200
++++ b/core/iwasm/lib/native/extension/gui/wgl_obj_wrapper.c    2020-01-29 
13:41:40.000000000 +0100
+@@ -253,6 +253,27 @@
+                 sizeof(*object_event));
+ }
+ 
++extern wasm_module_inst_t wasm_module_inst_unikraft;
++static void trigger_wasm_widget_event(object_node_t *object_node, lv_event_t 
event)
++{
++      uint32 argv[2];
++    wasm_function_inst_t func_on_object_event;
++
++      func_on_object_event = 
wasm_runtime_lookup_function(wasm_module_inst_unikraft, "on_widget_event", 
"(i32i32)");
++    if (!func_on_object_event) {
++        printf("Cannot find function _on_object_event\n");
++        return;
++    }
++
++    argv[0] = object_node->obj_id;
++    argv[1] = event;
++    if (!wasm_runtime_call_wasm(wasm_module_inst_unikraft, NULL, 
func_on_object_event, 2, argv)) {
++        printf(":Got exception running wasm code: %s\n", 
wasm_runtime_get_exception(wasm_module_inst_unikraft));
++        wasm_runtime_clear_exception(wasm_module_inst_unikraft);
++        return;
++    }
++}
++
+ static void internal_lv_obj_event_cb(lv_obj_t *obj, lv_event_t event)
+ {
+     object_node_t *elem;
+@@ -262,8 +283,8 @@
+     elem = (object_node_t *)bh_list_first_elem(&g_object_list);
+     while (elem) {
+         if (obj == elem->obj) {
+-            post_widget_msg_to_module(elem, event);
+             vm_mutex_unlock(&g_object_list_mutex);
++            trigger_wasm_widget_event(elem, event);
+             return;
+         }
+         elem = (object_node_t *) bh_list_elem_next(elem);
+@@ -288,19 +309,19 @@
+ 
+ void wgl_init(void)
+ {
+-    korp_thread tid;
++ //   korp_thread tid;
+ 
+-    lv_init();
++ //   lv_init();
+ 
+     bh_list_init(&g_object_list);
+-    vm_recursive_mutex_init(&g_object_list_mutex);
++    vm_mutex_init(&g_object_list_mutex);
+     init_object_event_callback_framework();
+ 
+     /* new a thread, call lv_task_handler periodically */
+-    vm_thread_create(&tid,
+-                     lv_task_handler_thread_routine,
+-                     NULL,
+-                     BH_APPLET_PRESERVED_STACK_SIZE);
++//    vm_thread_create(&tid,
++//                     lv_task_handler_thread_routine,
++//                     NULL,
++//                     BH_APPLET_PRESERVED_STACK_SIZE);
+ }
+ 
+ /* -------------------------------------------------------------------------
diff --git a/patches/0009-event.patch b/patches/0009-event.patch
new file mode 100644
index 0000000..36fc273
--- /dev/null
+++ b/patches/0009-event.patch
@@ -0,0 +1,11 @@
+--- a/core/app-mgr/app-manager/event.h 2019-09-09 14:51:40.000000000 +0200
++++ b/core/app-mgr/app-manager/event.h 2020-01-24 14:52:50.000000000 +0100
+@@ -33,7 +33,7 @@
+  */
+ bool
+ event_handle_event_request(uint8_t code, const char *event_url,
+-        uint32_t register);
++        uint32_t reg_client);
+ 
+ /**
+  * Test whether the event is registered
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.