diff --git a/BUILD.gn b/BUILD.gn
index 9cd2131e..6f4c713d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -35,6 +35,7 @@ declare_args() {
tee_enable = false
liteos_name = "OHOS_Image"
liteos_skip_make = false
+ liteos_is_mini = false
}
tee = ""
@@ -129,7 +130,9 @@ config("stdinc_config") {
"-isystem",
std_include,
]
- cflags += [ "-nostdinc" ]
+ if (!defined(LOSCFG_LIBC_NEWLIB)) {
+ cflags += [ "-nostdinc" ]
+ }
asmflags = cflags
}
@@ -316,14 +319,16 @@ group("kernel") {
}
group("liteos_a") {
- deps = [
- ":apps",
- ":kernel",
- ":tests",
- "//prebuilts/lite/sysroot/build:strip",
- ]
- if (liteos_skip_make == false) {
- deps += [ ":make" ]
+ deps = [ ":kernel" ]
+ if (!liteos_is_mini) {
+ deps += [
+ ":apps",
+ ":tests",
+ "//prebuilts/lite/sysroot/build:strip",
+ ]
+ if (liteos_skip_make == false) {
+ deps += [ ":make" ]
+ }
}
}
@@ -340,6 +345,17 @@ executable("liteos") {
"-Wl,--no-eh-frame-hdr",
]
+ if (defined(LOSCFG_LIBC_NEWLIB)) {
+ ldflags += [
+ "-Wl,--wrap=_free_r",
+ "-Wl,--wrap,_malloc_usable_size_r",
+ "-Wl,--wrap,_malloc_r",
+ "-Wl,--wrap,_memalign_r",
+ "-Wl,--wrap,_realloc_r",
+ "-Wl,--wrap,_fseeko_r",
+ ]
+ ldflags -= [ "-nostdlib" ]
+ }
libgcc = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-libgcc-file-name" ],
"trim string")
@@ -351,7 +367,7 @@ executable("liteos") {
} else {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
- ldflags += [ "-Wl,-nostartfiles" ]
+ ldflags += [ "-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c
index 3c8514c8..f51ac52a 100644
--- a/arch/arm/arm/src/los_exc.c
+++ b/arch/arm/arm/src/los_exc.c
@@ -88,6 +88,7 @@ STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
#define OS_MAX_BACKTRACE 15U
#define DUMPSIZE 128U
#define DUMPREGS 12U
+#define COM_REGS 4U
#define INSTR_SET_MASK 0x01000020U
#define THUMB_INSTR_LEN 2U
#define ARM_INSTR_LEN 4U
@@ -516,13 +517,22 @@ VOID OsDumpContextMem(const ExcContext *excBufAddr)
return;
}
- for (excReg = &(excBufAddr->R0); count <= DUMPREGS; excReg++, count++) {
+ for (excReg = &(excBufAddr->R0); count < COM_REGS; excReg++, count++) {
if (IS_VALID_ADDR(*excReg)) {
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
}
}
-
+ for (excReg = &(excBufAddr->R4); count < DUMPREGS; excReg++, count++) {
+ if (IS_VALID_ADDR(*excReg)) {
+ PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
+ OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
+ }
+ }
+ if (IS_VALID_ADDR(excBufAddr->R12)) {
+ PrintExcInfo("\ndump mem around R12:%p", excBufAddr->R12);
+ OsDumpMemByte(DUMPSIZE, (excBufAddr->R12 - (DUMPSIZE >> 1)));
+ }
if (IS_VALID_ADDR(excBufAddr->SP)) {
PrintExcInfo("\ndump mem around SP:%p", excBufAddr->SP);
OsDumpMemByte(DUMPSIZE, (excBufAddr->SP - (DUMPSIZE >> 1)));
@@ -645,6 +655,7 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
const StackInfo *stack = NULL;
vaddr_t kvaddr;
+#ifdef LOSCFG_KERNEL_VM
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
taskCB = OsCurrTaskGet();
stackStart = taskCB->userMapBase;
@@ -655,6 +666,7 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
}
return found;
}
+#endif
/* Search in the task stacks */
for (index = 0; index < g_taskMaxNum; index++) {
diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c
index 8803b586..d49c5c54 100644
--- a/compat/posix/src/time.c
+++ b/compat/posix/src/time.c
@@ -387,9 +387,16 @@ int gettimeofday64(struct timeval64 *tv, struct timezone *tz)
}
#endif
+#ifdef LOSCFG_LIBC_NEWLIB
+int gettimeofday(struct timeval *tv, void *_tz)
+#else
int gettimeofday(struct timeval *tv, struct timezone *tz)
+#endif
{
struct timeval64 stTimeVal64 = {0};
+#ifdef LOSCFG_LIBC_NEWLIB
+ struct timezone *tz = (struct timezone *)_tz;
+#endif
if (tv == NULL) {
TIME_RETURN(EINVAL);
@@ -718,6 +725,7 @@ typedef struct {
static VOID SwtmrProc(UINTPTR tmrArg)
{
+#ifdef LOSCFG_KERNEL_VM
INT32 sig, ret;
UINT32 intSave;
pid_t pid;
@@ -761,9 +769,47 @@ static VOID SwtmrProc(UINTPTR tmrArg)
return;
EXIT:
PRINT_ERR("Dispatch signals failed!, ret: %d\r\n", ret);
+#endif
return;
}
+int timer_create(clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID)
+{
+ UINT32 ret;
+ UINT16 swtmrID;
+#ifdef LOSCFG_SECURITY_VID
+ UINT16 vid;
+#endif
+
+ if (!timerID || (clockID != CLOCK_REALTIME) || !evp) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if ((evp->sigev_notify != SIGEV_THREAD) || evp->sigev_notify_attributes) {
+ errno = ENOTSUP;
+ return -1;
+ }
+
+ ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, (SWTMR_PROC_FUNC)evp->sigev_notify_function,
+ &swtmrID, (UINTPTR)evp->sigev_value.sival_ptr);
+ if (ret != LOS_OK) {
+ errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
+ return -1;
+ }
+
+#ifdef LOSCFG_SECURITY_VID
+ vid = AddNodeByRid(swtmrID);
+ if (vid == MAX_INVALID_TIMER_VID) {
+ (VOID)LOS_SwtmrDelete(swtmrID);
+ return -1;
+ }
+ swtmrID = vid;
+#endif
+ *timerID = (timer_t)(UINTPTR)swtmrID;
+ return 0;
+}
+
int OsTimerCreate(clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
{
UINT32 ret;
@@ -823,6 +869,7 @@ int timer_delete(timer_t timerID)
{
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
VOID *arg = NULL;
+ UINTPTR swtmrProc;
#ifdef LOSCFG_SECURITY_VID
swtmrID = GetRidByVid(swtmrID);
@@ -832,10 +879,11 @@ int timer_delete(timer_t timerID)
}
arg = (VOID *)OS_SWT_FROM_SID(swtmrID)->uwArg;
+ swtmrProc = (UINTPTR)OS_SWT_FROM_SID(swtmrID)->pfnHandler;
if (LOS_SwtmrDelete(swtmrID)) {
goto ERROUT;
}
- if (arg != NULL) {
+ if ((swtmrProc == (UINTPTR)SwtmrProc) && (arg != NULL)) {
free(arg);
}
@@ -979,7 +1027,11 @@ STATIC INT32 DoNanoSleep(UINT64 nanoseconds)
return -1;
}
+#ifdef LOSCFG_LIBC_NEWLIB
+int usleep(unsigned long useconds)
+#else
int usleep(unsigned useconds)
+#endif
{
return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US);
}
diff --git a/drivers/block/disk/include/disk.h b/drivers/block/disk/include/disk.h
index 8f79cea3..46c55ee1 100644
--- a/drivers/block/disk/include/disk.h
+++ b/drivers/block/disk/include/disk.h
@@ -163,7 +163,7 @@ extern "C" {
#define DISK_ATA_GET_MODEL 21 /* Get model name */
#define DISK_ATA_GET_SN 22 /* Get serial number */
-#ifdef LOSCFG_FS_FAT_CACHE
+#ifndef LOSCFG_FS_FAT_CACHE
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
#endif
diff --git a/kernel/base/core/los_task.c b/kernel/base/core/los_task.c
index bcddc312..23e6a18e 100644
--- a/kernel/base/core/los_task.c
+++ b/kernel/base/core/los_task.c
@@ -226,6 +226,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
ret = LOS_TaskCreateOnly(&idleTaskID, &taskInitParam);
+ if (ret != LOS_OK) {
+ return ret;
+ }
LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
OsSchedRunqueueIdleInit(idleTaskID);
diff --git a/kernel/base/include/los_sched_pri.h b/kernel/base/include/los_sched_pri.h
index a8dfe1a0..979c4822 100644
--- a/kernel/base/include/los_sched_pri.h
+++ b/kernel/base/include/los_sched_pri.h
@@ -41,7 +41,9 @@
#endif
#include "los_stackinfo_pri.h"
#include "los_futex_pri.h"
+#ifdef LOSCFG_KERNEL_PM
#include "los_pm_pri.h"
+#endif
#include "los_signal.h"
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
@@ -555,9 +557,11 @@ STATIC INLINE VOID SchedTaskFreeze(LosTaskCB *taskCB)
{
UINT64 responseTime;
+#ifdef LOSCFG_KERNEL_PM
if (!OsIsPmMode()) {
return;
}
+#endif
if (!(taskCB->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY))) {
return;
diff --git a/kernel/common/los_printf.c b/kernel/common/los_printf.c
index 25f7c193..e0126544 100644
--- a/kernel/common/los_printf.c
+++ b/kernel/common/los_printf.c
@@ -198,6 +198,7 @@ __attribute__((noinline)) VOID UartPrintf(const CHAR *fmt, ...)
va_end(ap);
}
+#ifndef LOSCFG_LIBC_NEWLIB
__attribute__((noinline)) VOID dprintf(const CHAR *fmt, ...)
{
va_list ap;
@@ -210,6 +211,7 @@ __attribute__((noinline)) VOID dprintf(const CHAR *fmt, ...)
#endif
va_end(ap);
}
+#endif
VOID LkDprintf(const CHAR *fmt, va_list ap)
{
@@ -279,7 +281,7 @@ VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...
}
if ((level != LOS_COMMON_LEVEL) && ((level > LOS_EMG_LEVEL) && (level <= LOS_TRACE_LEVEL))) {
- dprintf("[%s][%s:%s]", g_logString[level],
+ PRINTK("[%s][%s:%s]", g_logString[level],
((OsCurrProcessGet() == NULL) ? "NULL" : OsCurrProcessGet()->processName),
((OsCurrTaskGet() == NULL) ? "NULL" : OsCurrTaskGet()->taskName));
}
diff --git a/kernel/extended/hilog/los_hilog.c b/kernel/extended/hilog/los_hilog.c
index dd7c7c6f..3758f9a2 100644
--- a/kernel/extended/hilog/los_hilog.c
+++ b/kernel/extended/hilog/los_hilog.c
@@ -179,7 +179,7 @@ static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen)
}
if (bufLen < header.len + sizeof(header)) {
- dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize);
+ PRINTK("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize);
retval = -ENOMEM;
goto out;
}
@@ -238,7 +238,7 @@ static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) {
- dprintf("In %s line %d,clock_gettime fail\n", __FUNCTION__, __LINE__);
+ PRINTK("In %s line %d,clock_gettime fail\n", __FUNCTION__, __LINE__);
return;
}
@@ -274,7 +274,7 @@ static void HiLogCoverOldLog(size_t bufLen)
if (isLastTimeFull == 1 && isThisTimeFull == 0) {
/* so we can only print one log if hilog ring buffer is full in a short time */
if (dropLogLines > 0) {
- dprintf("hilog ringbuffer full, drop %d line(s) log\n", dropLogLines);
+ PRINTK("hilog ringbuffer full, drop %d line(s) log\n", dropLogLines);
}
isLastTimeFull = 0;
dropLogLines = 0;
@@ -319,7 +319,7 @@ out:
wake_up_interruptible(&g_hiLogDev.wq);
}
if (retval < 0) {
- dprintf("write fail retval=%d\n", retval);
+ PRINTK("write fail retval=%d\n", retval);
}
return retval;
}
@@ -328,7 +328,7 @@ static ssize_t HiLogWrite(struct file *filep, const char *buffer, size_t bufLen)
{
(void)filep;
if (bufLen + sizeof(struct HiLogEntry) > HILOG_BUFFER) {
- dprintf("input too large\n");
+ PRINTK("input too large\n");
return -ENOMEM;
}
@@ -339,7 +339,7 @@ static void HiLogDeviceInit(void)
{
g_hiLogDev.buffer = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, HILOG_BUFFER);
if (g_hiLogDev.buffer == NULL) {
- dprintf("In %s line %d,LOS_MemAlloc fail\n", __FUNCTION__, __LINE__);
+ PRINTK("In %s line %d,LOS_MemAlloc fail\n", __FUNCTION__, __LINE__);
}
init_waitqueue_head(&g_hiLogDev.wq);
diff --git a/kernel/include/los_printf.h b/kernel/include/los_printf.h
index ae4e4949..69f759e6 100644
--- a/kernel/include/los_printf.h
+++ b/kernel/include/los_printf.h
@@ -87,9 +87,9 @@ typedef VOID (*pf_OUTPUT)(const CHAR *fmt, ...);
*
- los_printf.h: the header file that contains the API declaration.
* @see printf
*/
+#ifndef LOSCFG_LIBC_NEWLIB
extern void dprintf(const char *fmt, ...);
-
-#define diag_printf dprintf
+#endif
#define PRINT_DEBUG(fmt, args...) LOS_LkPrint(LOS_DEBUG_LEVEL, __FUNCTION__, __LINE__, fmt, ##args)
#define PRINT_INFO(fmt, args...) LOS_LkPrint(LOS_INFO_LEVEL, __FUNCTION__, __LINE__, fmt, ##args)
diff --git a/lib/Kconfig b/lib/Kconfig
index 6bc561e8..d9f3b54e 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -5,6 +5,20 @@ config LIB_LIBC
help
Answer Y to enable libc for full code.
+choice
+ prompt "choose libc"
+ default LIBC_MUSL
+ depends on LIB_LIBC
+ help
+ Choose libc.
+
+config LIBC_NEWLIB
+ bool "newlibc"
+
+config LIBC_MUSL
+ bool "musl libc"
+endchoice
+
config LIB_ZLIB
bool "Enable Zlib"
default y
diff --git a/lib/libc/BUILD.gn b/lib/libc/BUILD.gn
index 32949c4e..d61e4185 100644
--- a/lib/libc/BUILD.gn
+++ b/lib/libc/BUILD.gn
@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -29,93 +29,16 @@
import("//kernel/liteos_a/liteos.gni")
-MUSLDIR = "$LITEOSTHIRDPARTY/musl"
-
-import("//third_party/optimized-routines/optimized-routines.gni")
-import("$MUSLDIR/porting/liteos_a/kernel/musl.gni")
-
-module_switch = defined(LOSCFG_LIB_LIBC)
-module_name = get_path_info(rebase_path("."), "name")
-kernel_module(module_name) {
- sources = MUSL_SRC_COMMON
-
- if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
- sources += MUSL_SRC_ARM
- foreach(f, MUSL_SRC_ARM) {
- sources -= [ string_replace(f, "/arm/", "/") ]
- }
- }
-
- if (LOSCFG_ARCH_ARM_VER == "armv7-a") {
- sources -= [
- "$MUSLPORTINGDIR/src/string/memchr.c",
- "$MUSLPORTINGDIR/src/string/memcpy.c",
- "$MUSLPORTINGDIR/src/string/strcmp.c",
- "$MUSLPORTINGDIR/src/string/strcpy.c",
- "$MUSLPORTINGDIR/src/string/strlen.c",
- ]
- sources += [
- "src/arch/arm/memcmp.S",
- "src/arch/arm/memset.S",
- ]
- sources += OPTRT_STRING_ARM_SRC_FILES_FOR_ARMV7_A
- asmflags = [
- "-D__strlen_armv6t2=strlen",
- "-D__strcmp_arm=strcmp",
- "-D__memchr_arm=memchr",
- ]
- if (defined(LOSCFG_KERNEL_LMS)) {
- asmflags += [
- "-D__memcpy_arm=__memcpy",
- "-D__strcpy_arm=__strcpy",
- ]
- } else {
- asmflags += [
- "-D__memcpy_arm=memcpy",
- "-D__strcpy_arm=strcpy",
- ]
- }
- } else {
- # arch is not armv7-a
- sources += [
- "src/memcmp.c",
- "src/memset.c",
- ]
- }
-
- include_dirs = [
- "$MUSLPORTINGDIR/src/include",
- "$MUSLPORTINGDIR/src/internal",
+group("libc") {
+ deps = [
+ "musl",
+ "newlib",
]
-
- public_configs = [ ":public" ]
- configs += [ ":private" ]
}
config("public") {
- cflags = [
- "-isystem",
- rebase_path("$MUSLPORTINGDIR/include"),
- ]
-}
-
-config("private") {
- if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
- cflags = [
- "-Wno-char-subscripts",
- "-Wno-unknown-pragmas",
- ]
- } else {
- cflags = [
- "-frounding-math",
- "-Wno-unused-but-set-variable",
- "-Wno-unknown-pragmas",
- ]
- }
-
- cflags += [
- "-Wno-shift-op-parentheses",
- "-Wno-logical-op-parentheses",
- "-Wno-bitwise-op-parentheses",
+ configs = [
+ "musl:public",
+ "newlib:public",
]
}
diff --git a/lib/libc/musl/BUILD.gn b/lib/libc/musl/BUILD.gn
new file mode 100644
index 00000000..2b5bbbe0
--- /dev/null
+++ b/lib/libc/musl/BUILD.gn
@@ -0,0 +1,121 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//kernel/liteos_a/liteos.gni")
+
+MUSLDIR = "$LITEOSTHIRDPARTY/musl"
+
+import("//third_party/optimized-routines/optimized-routines.gni")
+import("$MUSLDIR/porting/liteos_a/kernel/musl.gni")
+
+module_switch = defined(LOSCFG_LIBC_MUSL)
+module_name = get_path_info(rebase_path("."), "name")
+kernel_module(module_name) {
+ sources = MUSL_SRC_COMMON
+
+ if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
+ sources += MUSL_SRC_ARM
+ foreach(f, MUSL_SRC_ARM) {
+ sources -= [ string_replace(f, "/arm/", "/") ]
+ }
+ }
+
+ if (LOSCFG_ARCH_ARM_VER == "armv7-a") {
+ sources -= [
+ "$MUSLPORTINGDIR/src/string/memchr.c",
+ "$MUSLPORTINGDIR/src/string/memcpy.c",
+ "$MUSLPORTINGDIR/src/string/strcmp.c",
+ "$MUSLPORTINGDIR/src/string/strcpy.c",
+ "$MUSLPORTINGDIR/src/string/strlen.c",
+ ]
+ sources += [
+ "src/arch/arm/memcmp.S",
+ "src/arch/arm/memset.S",
+ ]
+ sources += OPTRT_STRING_ARM_SRC_FILES_FOR_ARMV7_A
+ asmflags = [
+ "-D__strlen_armv6t2=strlen",
+ "-D__strcmp_arm=strcmp",
+ "-D__memchr_arm=memchr",
+ ]
+ if (defined(LOSCFG_KERNEL_LMS)) {
+ asmflags += [
+ "-D__memcpy_arm=__memcpy",
+ "-D__strcpy_arm=__strcpy",
+ ]
+ } else {
+ asmflags += [
+ "-D__memcpy_arm=memcpy",
+ "-D__strcpy_arm=strcpy",
+ ]
+ }
+ } else {
+ # arch is not armv7-a
+ sources += [
+ "src/memcmp.c",
+ "src/memset.c",
+ ]
+ }
+
+ include_dirs = [
+ "$MUSLPORTINGDIR/src/include",
+ "$MUSLPORTINGDIR/src/internal",
+ ]
+
+ public_configs = [ ":public" ]
+ configs += [ ":private" ]
+}
+
+config("public") {
+ cflags = [
+ "-isystem",
+ rebase_path("$MUSLPORTINGDIR/include"),
+ ]
+}
+
+config("private") {
+ if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
+ cflags = [
+ "-Wno-char-subscripts",
+ "-Wno-unknown-pragmas",
+ ]
+ } else {
+ cflags = [
+ "-frounding-math",
+ "-Wno-unused-but-set-variable",
+ "-Wno-unknown-pragmas",
+ ]
+ }
+
+ cflags += [
+ "-Wno-shift-op-parentheses",
+ "-Wno-logical-op-parentheses",
+ "-Wno-bitwise-op-parentheses",
+ ]
+}
diff --git a/lib/libc/Makefile b/lib/libc/musl/Makefile
similarity index 100%
rename from lib/libc/Makefile
rename to lib/libc/musl/Makefile
diff --git a/lib/libc/src/arch/arm/memcmp.S b/lib/libc/musl/src/arch/arm/memcmp.S
similarity index 100%
rename from lib/libc/src/arch/arm/memcmp.S
rename to lib/libc/musl/src/arch/arm/memcmp.S
diff --git a/lib/libc/src/arch/arm/memset.S b/lib/libc/musl/src/arch/arm/memset.S
similarity index 100%
rename from lib/libc/src/arch/arm/memset.S
rename to lib/libc/musl/src/arch/arm/memset.S
diff --git a/lib/libc/src/memcmp.c b/lib/libc/musl/src/memcmp.c
similarity index 100%
rename from lib/libc/src/memcmp.c
rename to lib/libc/musl/src/memcmp.c
diff --git a/lib/libc/src/memset.c b/lib/libc/musl/src/memset.c
similarity index 100%
rename from lib/libc/src/memset.c
rename to lib/libc/musl/src/memset.c
diff --git a/lib/libc/newlib/BUILD.gn b/lib/libc/newlib/BUILD.gn
new file mode 100644
index 00000000..f78432c4
--- /dev/null
+++ b/lib/libc/newlib/BUILD.gn
@@ -0,0 +1,58 @@
+# Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//kernel/liteos_a/liteos.gni")
+import("//third_party/musl/porting/liteos_a_newlib/kernel/newlib.gni")
+
+module_switch = defined(LOSCFG_LIBC_NEWLIB)
+module_name = get_path_info(rebase_path("."), "name")
+kernel_module(module_name) {
+ sources = NEWLIB_ADAPT_SRC_COMMON
+ configs += [ "$LITEOSTOPDIR:warn_config" ]
+
+ configs += [ ":private" ]
+}
+
+config("public") {
+ include_dirs = [ "porting/include" ]
+ include_dirs += NEWLIB_ADAPT_INCLUDE_DIRS
+}
+
+config("private") {
+ cflags = [
+ "-frounding-math",
+ "-Wno-unused-but-set-variable",
+ "-Wno-unknown-pragmas",
+ ]
+
+ cflags += [
+ "-Wno-shift-op-parentheses",
+ "-Wno-logical-op-parentheses",
+ "-Wno-bitwise-op-parentheses",
+ ]
+}
diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk
index 81c6fbb7..d1ceb848 100644
--- a/tools/build/mk/los_config.mk
+++ b/tools/build/mk/los_config.mk
@@ -204,7 +204,7 @@ LIB_SUBDIRS += lib/libscrew
LITEOS_LIBSCREW_INCLUDE += -I $(LITEOSTOPDIR)/lib/libscrew/include
ifeq ($(LOSCFG_LIB_LIBC), y)
- LIB_SUBDIRS += lib/libc
+ LIB_SUBDIRS += lib/libc/musl
LITEOS_BASELIB += -lc
LITEOS_LIBC_INCLUDE += \
-isystem $(LITEOSTHIRDPARTY)/musl/porting/liteos_a/kernel/include