diff --git a/BUILD.gn b/BUILD.gn index 043b0c87d7d6a8fe5cb5b81d07fb1faa9feeee50..5c112eba3177283a14870d2892376ecd77682c2c 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 = "" @@ -128,7 +129,9 @@ config("stdinc_config") { "-isystem", std_include, ] - cflags += [ "-nostdinc" ] + if (!defined(LOSCFG_LIBC_NEWLIB)) { + cflags += [ "-nostdinc" ] + } asmflags = cflags } @@ -315,14 +318,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" ] + } } } @@ -339,6 +344,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") @@ -350,7 +366,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 3c8514c81b53c424200546463d8568aef441fa14..f51ac52a9f598bf2e5a3241c008f9073bb85d2cb 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 8803b5862ddc088d1dc2d382a604aebb32e662b3..d49c5c5477520262fc24fc72c7a1dc794246dcf2 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 8f79cea39279e0cbeec47a21a12ce73b1221f876..46c55ee1f890067052734f55d6ce5070cc883dd3 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 bcddc312d860619cf17725659c97b1502d65314c..23e6a18e3f091892928dc1bb6730948a1527916b 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 a8dfe1a05891f05f63988a5102f9affb189f0a5d..979c4822a9910f44eaa28d83e2bce18351e31bbd 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 25f7c193cf6c230afabbf7afbc244184349bdb1f..e0126544996290a95d158eb528f636f47f47ecdb 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 dd7c7c6f3238fd87346646de4931692a33f4936b..3758f9a2a80f40736cd0bf32dfdc7a79e6c38bf0 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 ae4e4949297e690a3a135cb54e80d4083fa1df12..69f759e6997e0c7bf542ae6c0d3e6eb61233ac7c 100644 --- a/kernel/include/los_printf.h +++ b/kernel/include/los_printf.h @@ -87,9 +87,9 @@ typedef VOID (*pf_OUTPUT)(const CHAR *fmt, ...); *