Browse Source

配合mlibc,内核修改部分

林振兴 3 years ago
parent
commit
5c16af13c5

+ 4 - 1
components/dfs/include/dfs_poll.h

@@ -13,8 +13,11 @@
 #include <rtthread.h>
 #include <rtthread.h>
 
 
 #ifdef RT_USING_POSIX
 #ifdef RT_USING_POSIX
+#if defined(RT_USING_MLIB)
+#include <time.h>
+#else
 #include <sys/time.h> /* for struct timeval */
 #include <sys/time.h> /* for struct timeval */
-
+#endif
 #if !defined(POLLIN) && !defined(POLLOUT)
 #if !defined(POLLIN) && !defined(POLLOUT)
 #define POLLIN          (0x01)
 #define POLLIN          (0x01)
 #define POLLRDNORM      (0x01)
 #define POLLRDNORM      (0x01)

+ 6 - 0
components/libc/Kconfig

@@ -19,6 +19,12 @@ if RT_USING_LIBC && RT_USING_LWP
 
 
     endchoice
     endchoice
 endif
 endif
+            
+if RT_USING_MUSL
+    config RT_USING_MLIB
+    bool "Use libc: mlib"
+    default n 
+endif
 
 
 config RT_USING_PTHREADS
 config RT_USING_PTHREADS
     bool "Enable pthreads APIs"
     bool "Enable pthreads APIs"

+ 14 - 12
components/libc/compilers/musl/SConscript

@@ -7,19 +7,21 @@ cwd = GetCurrentDir()
 group = []
 group = []
 
 
 if rtconfig.PLATFORM == 'gcc' and GetDepend('RT_USING_MUSL'):
 if rtconfig.PLATFORM == 'gcc' and GetDepend('RT_USING_MUSL'):
-    CPPDEFINES = ['__STDC_ISO_10646__=201206L', '_STDC_PREDEF_H']
-    LIBS       = ['c', 'gcc']
+    if GetDepend('RT_USING_MLIB') == False:
+        CPPDEFINES = ['__STDC_ISO_10646__=201206L', '_STDC_PREDEF_H']
+        LIBS       = ['c', 'gcc']
 
 
-    if os.path.exists(os.path.join(cwd, 'libc', 'lib', 'libc.a')):
-        CFLAGS     = ' -nostdinc'
-        CPPPATH    = [cwd, cwd + '/libc/include']
-        LIBPATH    = [cwd + '/libc/lib']
+        if os.path.exists(os.path.join(cwd, 'libc', 'lib', 'libc.a')):
+            CFLAGS     = '-nostdinc'
+            CPPPATH    = [cwd, cwd + '/libc/include']
+            LIBPATH    = [cwd + '/libc/lib']
 
 
-        group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], CFLAGS = CFLAGS, 
-            CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS, LIBPATH = LIBPATH)
-    else:
-        LINKFLAGS = ' --specs=kernel.specs'
-        group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], LINKFLAGS = LINKFLAGS, 
-            CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+            group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], CFLAGS = CFLAGS, 
+                CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS, LIBPATH = LIBPATH)
+        else:
+            CPPPATH    = [cwd]
+            LINKFLAGS = ' --specs=kernel.specs'
+            group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], CPPPATH = CPPPATH, LINKFLAGS = LINKFLAGS, 
+                CPPDEFINES = CPPDEFINES, LIBS = LIBS)
 
 
 Return('group')
 Return('group')

+ 3 - 4
components/libc/compilers/newlib/SConscript

@@ -5,7 +5,6 @@ src = Glob('*.c')
 cwd = GetCurrentDir()
 cwd = GetCurrentDir()
 group = []
 group = []
 
 
-CPPPATH = [cwd]
 CPPDEFINES = []
 CPPDEFINES = []
 
 
 # link with libc and libm:
 # link with libc and libm:
@@ -21,9 +20,9 @@ if rtconfig.PLATFORM == 'gcc' and GetDepend('RT_USING_LIBC'):
         LIBS = []
         LIBS = []
     elif not GetDepend('RT_USING_NEWLIB'):
     elif not GetDepend('RT_USING_NEWLIB'):
         # RT_USING_NEWLIB is defined already
         # RT_USING_NEWLIB is defined already
+        CPPPATH = [cwd]
         CPPDEFINES = ['RT_USING_NEWLIB']
         CPPDEFINES = ['RT_USING_NEWLIB']
-
-    group = DefineGroup('newlib', src, depend = ['RT_USING_LIBC'], 
-        CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+        group = DefineGroup('newlib', src, depend = ['RT_USING_LIBC'], 
+            CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
 
 
 Return('group')
 Return('group')

+ 2 - 2
components/libc/time/clock_time.c

@@ -10,7 +10,7 @@
  */
  */
 
 
 #include <rtthread.h>
 #include <rtthread.h>
-#include <pthread.h>
+//#include <pthread.h>
 
 
 #include "clock_time.h"
 #include "clock_time.h"
 
 
@@ -48,7 +48,7 @@ int clock_time_to_tick(const struct timespec *time)
     RT_ASSERT(time != RT_NULL);
     RT_ASSERT(time != RT_NULL);
 
 
     tick = RT_WAITING_FOREVER;
     tick = RT_WAITING_FOREVER;
-    if (time != NULL)
+    if (time != RT_NULL)
     {
     {
         /* get current tp */
         /* get current tp */
         clock_gettime(CLOCK_REALTIME, &tp);
         clock_gettime(CLOCK_REALTIME, &tp);

+ 1 - 1
components/lwp/arch/arm/common/reloc.c

@@ -1,7 +1,7 @@
 #include <rtthread.h>
 #include <rtthread.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <string.h>
 #include <string.h>
-#include <elf.h>
+#include <lwp_elf.h>
 #ifdef RT_USING_USERSPACE
 #ifdef RT_USING_USERSPACE
 #include <mmu.h>
 #include <mmu.h>
 #include <page.h>
 #include <page.h>

+ 2 - 2
components/lwp/arch/arm/cortex-a/lwp_arch.c

@@ -32,8 +32,8 @@ int arch_user_space_init(struct rt_lwp *lwp)
     }
     }
 
 
     lwp->end_heap = USER_HEAP_VADDR;
     lwp->end_heap = USER_HEAP_VADDR;
-    memcpy(mmu_table + (KERNEL_VADDR_START >> ARCH_SECTION_SHIFT), MMUTable + (KERNEL_VADDR_START >> ARCH_SECTION_SHIFT), ARCH_PAGE_SIZE);
-    memset(mmu_table, 0, 3 * ARCH_PAGE_SIZE);
+    rt_memcpy(mmu_table + (KERNEL_VADDR_START >> ARCH_SECTION_SHIFT), MMUTable + (KERNEL_VADDR_START >> ARCH_SECTION_SHIFT), ARCH_PAGE_SIZE);
+    rt_memset(mmu_table, 0, 3 * ARCH_PAGE_SIZE);
     rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, mmu_table, 4 * ARCH_PAGE_SIZE);
     rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, mmu_table, 4 * ARCH_PAGE_SIZE);
     rt_hw_mmu_map_init(&lwp->mmu_info, (void*)USER_VADDR_START, USER_VADDR_TOP - USER_VADDR_START, mmu_table, PV_OFFSET);
     rt_hw_mmu_map_init(&lwp->mmu_info, (void*)USER_VADDR_START, USER_VADDR_TOP - USER_VADDR_START, mmu_table, PV_OFFSET);
 
 

+ 4 - 0
components/lwp/lwp.h

@@ -36,6 +36,10 @@
 #include "lwp_arch.h"
 #include "lwp_arch.h"
 #endif
 #endif
 
 
+#if defined(RT_USING_MLIB)
+#include <locale.h>
+#endif
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif

+ 4 - 0
components/lwp/lwp_syscall.h

@@ -15,7 +15,11 @@
 #include <rtthread.h>
 #include <rtthread.h>
 #include <dfs_posix.h>
 #include <dfs_posix.h>
 #include <dfs_poll.h>
 #include <dfs_poll.h>
+#if defined(RT_USING_MLIB)
+#include <time.h>
+#else
 #include <sys/time.h>
 #include <sys/time.h>
+#endif
 #include <sys/types.h>
 #include <sys/types.h>
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus

+ 5 - 0
components/net/lwip-2.1.2/src/arch/include/arch/cc.h

@@ -46,7 +46,12 @@
 #define X32_F "lx"
 #define X32_F "lx"
 
 
 #if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
 #if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
+#if defined(RT_USING_MLIB)
+#include <time.h>
+#else
 #include <sys/time.h>
 #include <sys/time.h>
+#endif
+
 #define LWIP_TIMEVAL_PRIVATE	   0
 #define LWIP_TIMEVAL_PRIVATE	   0
 #else
 #else
 #define LWIP_TIMEVAL_PRIVATE	   1
 #define LWIP_TIMEVAL_PRIVATE	   1

+ 4 - 1
components/net/sal_socket/src/sal_socket.c

@@ -11,8 +11,11 @@
 
 
 #include <rtthread.h>
 #include <rtthread.h>
 #include <rthw.h>
 #include <rthw.h>
+#if defined(RT_USING_MLIB)
+#include <time.h>
+#else 
 #include <sys/time.h>
 #include <sys/time.h>
-
+#endif
 #include <sal_socket.h>
 #include <sal_socket.h>
 #include <sal_netdb.h>
 #include <sal_netdb.h>
 #ifdef SAL_USING_TLS
 #ifdef SAL_USING_TLS

+ 2 - 0
components/utilities/ulog/ulog_def.h

@@ -135,7 +135,9 @@ extern "C" {
 #undef ELOG_LVL_INFO
 #undef ELOG_LVL_INFO
 #undef ELOG_LVL_DEBUG
 #undef ELOG_LVL_DEBUG
 #undef ELOG_LVL_VERBOSE
 #undef ELOG_LVL_VERBOSE
+#if !defined(RT_USING_MLIB)
 #define assert                         ASSERT
 #define assert                         ASSERT
+#endif
 #define log_e                          LOG_E
 #define log_e                          LOG_E
 #define log_w                          LOG_W
 #define log_w                          LOG_W
 #define log_i                          LOG_I
 #define log_i                          LOG_I

+ 2 - 5
src/kservice.c

@@ -121,16 +121,13 @@ int *_rt_errno(void)
 RTM_EXPORT(_rt_errno);
 RTM_EXPORT(_rt_errno);
 
 
 #ifdef RT_USING_MUSL
 #ifdef RT_USING_MUSL
-int *__errno_location(void)
-{
-    return _rt_errno();
-}
-
+#if !defined(RT_USING_MLIB)
 int *___errno_location(void)
 int *___errno_location(void)
 {
 {
     return _rt_errno();
     return _rt_errno();
 }
 }
 #endif
 #endif
+#endif
 
 
 /**
 /**
  * This function will set the content of memory to specified value
  * This function will set the content of memory to specified value