add OpenHarmony 1.0 baseline

This commit is contained in:
wenjun
2020-09-08 10:21:39 +08:00
parent 94f5f466b4
commit 6df931fc98
736 changed files with 111817 additions and 0 deletions

6
kernel/common/Kconfig Executable file
View File

@@ -0,0 +1,6 @@
config PLATFORM_ROOTFS
bool "Enable ROOTFS"
default y
depends on FS_JFFS || FS_FAT
help
Answer Y to enable LiteOS support rootfs.

42
kernel/common/Makefile Executable file
View File

@@ -0,0 +1,42 @@
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020, 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.
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := rootfs
LOCAL_SRCS := $(wildcard los_rootfs.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

1669
kernel/common/console.c Executable file

File diff suppressed because it is too large Load Diff

146
kernel/common/console.h Executable file
View File

@@ -0,0 +1,146 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _CONSOLE_H
#define _CONSOLE_H
#include "sys/ioctl.h"
#include "los_config.h"
#ifdef LOSCFG_FS_VFS
#include "termios.h"
#ifdef LOSCFG_NET_TELNET
#include "telnet_dev.h"
#endif
#include "virtual_serial.h"
#include "los_cir_buf_pri.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_FS_VFS
/* Define two fixed console id for Console ID. */
#define CONSOLE_SERIAL 1
#define CONSOLE_TELNET 2
#define LOSCFG_PLATFORM_CONSOLE
#define STDIN 0
#define STDOUT 1
#define STDERR 2
#define CONSOLE "/dev/console"
#define CONSOLE_NAMELEN 16
#define CONSOLE_RD_BLOCK 1
#define CONSOLE_RD_NONBLOCK 0
#define CONSOLE_SHELL_KEY_EVENT 0x112
#define CONSOLE_SHELL_EXITED 0x400
#define CONSOLE_FIFO_SIZE 1024
#define CONSOLE_NUM 2
#define TELNET_CIRBUF_SIZE 0x2000
typedef struct {
CirBuf cirBufCB; /* Circular buffer CB */
EVENT_CB_S sendEvent; /* Inform telnet send task */
} CirBufSendCB;
typedef struct {
UINT32 consoleID;
UINT32 consoleType;
UINT32 consoleSem;
UINT32 shellEntryId;
UINT32 consoleMask;
struct inode *devInode;
CHAR *name;
INT32 fd;
UINT32 refCount;
BOOL isNonBlock;
#ifdef LOSCFG_SHELL
VOID *shellHandle;
#endif
UINT32 sendTaskID;
CirBufSendCB *cirBufSendCB;
UINT8 fifo[CONSOLE_FIFO_SIZE];
UINT32 fifoOut;
UINT32 fifoIn;
UINT32 currentLen;
struct termios consoleTermios;
} CONSOLE_CB;
extern INT32 system_console_init(const CHAR *deviceName);
extern INT32 system_console_deinit(const CHAR *deviceName);
extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB);
extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB);
extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB);
extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB);
extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleID);
extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskID);
extern INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID);
extern INT32 ConsoleUpdateFd(VOID);
extern BOOL ConsoleEnable(VOID);
extern BOOL is_nonblock(const CONSOLE_CB *consoleCB);
extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB);
extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops);
extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops);
extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen);
extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen);
extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);
extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);
extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);
#if (LOSCFG_KERNEL_SMP == YES)
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
extern VOID OsWakeConsoleSendTask(VOID);
#endif
/* console ioctl */
#define CONSOLE_IOC_MAGIC 'c'
#define CONSOLE_CMD_RD_BLOCK_SERIAL _IO(CONSOLE_IOC_MAGIC, 1)
#define CONSOLE_CMD_RD_BLOCK_TELNET _IO(CONSOLE_IOC_MAGIC, 2)
#define CONSOLE_CONTROL_RIGHTS_CAPTURE _IO(CONSOLE_IOC_MAGIC, 3)
#define CONSOLE_CONTROL_RIGHTS_RELEASE _IO(CONSOLE_IOC_MAGIC, 4)
#define CONSOLE_CONTROL_CAPTURE_LINE _IO(CONSOLE_IOC_MAGIC, 5)
#define CONSOLE_CONTROL_CAPTURE_CHAR _IO(CONSOLE_IOC_MAGIC, 6)
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _CONSOLE_H */

134
kernel/common/hwi_shell.c Executable file
View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_config.h"
#ifdef LOSCFG_SHELL_CMD_DEBUG
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
#include "los_cpup_pri.h"
#endif
#include "los_hwi_pri.h"
#include "los_process_pri.h"
#include "shcmd.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
STATIC CPUP_INFO_S g_hwiCpupAll[OS_HWI_MAX_NUM];
STATIC CPUP_INFO_S g_hwiCpup10s[OS_HWI_MAX_NUM];
STATIC CPUP_INFO_S g_hwiCpup1s[OS_HWI_MAX_NUM];
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i;
UINT32 intSave;
UINT64 cycles;
size_t size = sizeof(CPUP_INFO_S) * OS_HWI_MAX_NUM;
(VOID)argv;
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
(VOID)memset_s(g_hwiCpupAll, size, 0, size);
(VOID)memset_s(g_hwiCpup10s, size, 0, size);
(VOID)memset_s(g_hwiCpup1s, size, 0, size);
intSave = LOS_IntLock();
(VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpupAll, CPUP_ALL_TIME, 0);
(VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpup10s, CPUP_LAST_TEN_SECONDS, 0);
(VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpup1s, CPUP_LAST_ONE_SECONDS, 0);
LOS_IntRestore(intSave);
PRINTK(" InterruptNo Count Name CYCLECOST CPUUSE CPUUSE10s CPUUSE1s mode\n");
for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
if (OsGetHwiFormCnt(i)) {
cycles = g_cpup[g_processMaxNum + i].allTime / OsGetHwiFormCnt(i);
} else {
cycles = 0;
}
/* Different cores has different hwi form implementation */
if (HWI_IS_REGISTED(i) && (OsGetHwiFormName(i) != NULL)) {
PRINTK(" %8d: %-10d%-12s %-10llu", i, OsGetHwiFormCnt(i), OsGetHwiFormName(i), cycles);
} else if (HWI_IS_REGISTED(i)) {
PRINTK(" %8d: %-10d%-12s %-10llu", i, OsGetHwiFormCnt(i), "", cycles);
} else {
continue;
}
PRINTK("%2d.%-7d"
"%2d.%-9d"
"%2d.%-6d"
"%s\n",
g_hwiCpupAll[i].uwUsage / LOS_CPUP_PRECISION_MULT,
g_hwiCpupAll[i].uwUsage % LOS_CPUP_PRECISION_MULT,
g_hwiCpup10s[i].uwUsage / LOS_CPUP_PRECISION_MULT,
g_hwiCpup10s[i].uwUsage % LOS_CPUP_PRECISION_MULT,
g_hwiCpup1s[i].uwUsage / LOS_CPUP_PRECISION_MULT,
g_hwiCpup1s[i].uwUsage % LOS_CPUP_PRECISION_MULT,
g_hwiForm[i].uwParam == IRQF_SHARED ? "shared" : "normal");
}
return 0;
}
#else
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i;
(VOID)argv;
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
PRINTK(" InterruptNo Count Name\n");
for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
/* Different cores has different hwi form implementation */
if (HWI_IS_REGISTED(i) && (OsGetHwiFormName(i) != NULL)) {
PRINTK(" %8d:%10d: %-s\n", i, OsGetHwiFormCnt(i), OsGetHwiFormName(i));
} else if (HWI_IS_REGISTED(i)) {
PRINTK(" %8d:%10d:\n", i, OsGetHwiFormCnt(i));
}
}
return 0;
}
#endif
SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* LOSCFG_SHELL */

105
kernel/common/los_builddef.h Executable file
View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_BUILDEF_H
#define _LOS_BUILDEF_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_LITTLE_ENDIAN 0x1234 /* Little endian */
#define OS_BIG_ENDIAN 0x4321 /* Big endian */
#ifndef OS_BYTE_ORDER
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
#endif
/* Define OS code data sections */
/* The indicator function is inline */
#ifndef LITE_OS_SEC_ALW_INLINE
#define LITE_OS_SEC_ALW_INLINE /* __attribute__((always_inline)) */
#endif
#ifndef LITE_OS_SEC_TEXT
#define LITE_OS_SEC_TEXT /* __attribute__((section(".text.sram"))) */
#endif
#ifndef LITE_OS_SEC_TEXT_MINOR
#define LITE_OS_SEC_TEXT_MINOR /* __attribute__((section(".text.ddr"))) */
#endif
#ifndef LITE_OS_SEC_TEXT_INIT
#define LITE_OS_SEC_TEXT_INIT /* __attribute__((section(".text.init"))) */
#endif
#ifndef LITE_OS_SEC_DATA
#define LITE_OS_SEC_DATA /* __attribute__((section(".data.sram"))) */
#endif
#ifndef LITE_OS_SEC_DATA_MINOR
#define LITE_OS_SEC_DATA_MINOR /* __attribute__((section(".data.ddr"))) */
#endif
#ifndef LITE_OS_SEC_DATA_INIT
#define LITE_OS_SEC_DATA_INIT /* __attribute__((section(".data.init"))) */
#endif
#ifndef LITE_OS_SEC_BSS
#define LITE_OS_SEC_BSS /* __attribute__((section(".bss.sram"))) */
#endif
#ifndef LITE_OS_SEC_BSS_MINOR
#define LITE_OS_SEC_BSS_MINOR /* __attribute__((section(".bss.ddr"))) */
#endif
#ifndef LITE_OS_SEC_BSS_INIT
#define LITE_OS_SEC_BSS_INIT /* __attribute__((section(".bss.init"))) */
#endif
#ifndef LITE_OS_SEC_ITCM
#define LITE_OS_SEC_ITCM /* __attribute__((section(".itcm "))) */
#endif
#ifndef LITE_OS_SEC_DTCM
#define LITE_OS_SEC_DTCM /* __attribute__((section(".dtcm"))) */
#endif
#define PACK1
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_BUILDEF_H */

225
kernel/common/los_cir_buf.c Executable file
View File

@@ -0,0 +1,225 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_cir_buf_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
UINT32 LOS_CirBufUsedSize(CirBuf *cirbufCB)
{
UINT32 size;
UINT32 intSave;
LOS_SpinLockSave(&cirbufCB->lock, &intSave);
size = cirbufCB->size - cirbufCB->remain;
LOS_SpinUnlockRestore(&cirbufCB->lock, intSave);
return size;
}
/*
* startIdx
* |
* 0 0 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0
* |
* endIdx
*/
STATIC UINT32 OsCirBufWriteLinear(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
{
UINT32 cpSize;
errno_t err;
cpSize = (cirbufCB->remain < size) ? cirbufCB->remain : size;
if (cpSize == 0) {
return 0;
}
err = memcpy_s(cirbufCB->fifo + cirbufCB->endIdx, cirbufCB->remain, buf, cpSize);
if (err != EOK) {
return 0;
}
cirbufCB->remain -= cpSize;
cirbufCB->endIdx += cpSize;
return cpSize;
}
STATIC UINT32 OsCirBufWriteLoop(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
{
UINT32 right, cpSize;
errno_t err;
right = cirbufCB->size - cirbufCB->endIdx;
cpSize = (right < size) ? right : size;
err = memcpy_s(cirbufCB->fifo + cirbufCB->endIdx, right, buf, cpSize);
if (err != EOK) {
return 0;
}
cirbufCB->remain -= cpSize;
cirbufCB->endIdx += cpSize;
if (cirbufCB->endIdx == cirbufCB->size) {
cirbufCB->endIdx = 0;
}
if (cpSize == size) {
return size;
} else {
cpSize += OsCirBufWriteLinear(cirbufCB, buf + cpSize, size - cpSize);
}
return cpSize;
}
UINT32 LOS_CirBufWrite(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
{
UINT32 cpSize = 0;
if ((cirbufCB == NULL) || (buf == NULL) || (size == 0)) {
return 0;
}
if ((cirbufCB->fifo == NULL) || (cirbufCB->remain == 0)) {
return 0;
}
if (cirbufCB->startIdx <= cirbufCB->endIdx) {
cpSize = OsCirBufWriteLoop(cirbufCB, buf, size);
} else {
cpSize = OsCirBufWriteLinear(cirbufCB, buf, size);
}
return cpSize;
}
STATIC UINT32 OsCirBufReadLinear(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
{
UINT32 cpSize, remain;
errno_t err;
remain = cirbufCB->endIdx - cirbufCB->startIdx;
cpSize = (remain < size) ? remain : size;
if (cpSize == 0) {
return 0;
}
err = memcpy_s(buf, size, cirbufCB->fifo + cirbufCB->startIdx, cpSize);
if (err != EOK) {
return 0;
}
cirbufCB->remain += cpSize;
cirbufCB->startIdx += cpSize;
return cpSize;
}
STATIC UINT32 OsCirBufReadLoop(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
{
UINT32 right, cpSize;
errno_t err;
right = cirbufCB->size - cirbufCB->startIdx;
cpSize = (right < size) ? right : size;
err = memcpy_s(buf, size, cirbufCB->fifo + cirbufCB->startIdx, cpSize);
if (err != EOK) {
return 0;
}
cirbufCB->remain += cpSize;
cirbufCB->startIdx += cpSize;
if (cirbufCB->startIdx == cirbufCB->size) {
cirbufCB->startIdx = 0;
}
if (cpSize < size) {
cpSize += OsCirBufReadLinear(cirbufCB, buf + cpSize, size - cpSize);
}
return cpSize;
}
UINT32 LOS_CirBufRead(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
{
UINT32 cpSize;
if ((cirbufCB == NULL) || (buf == NULL) || (size == 0)) {
return 0;
}
if ((cirbufCB->fifo == NULL) || (cirbufCB->remain == cirbufCB->size)) {
return 0;
}
if (cirbufCB->startIdx >= cirbufCB->endIdx) {
cpSize = OsCirBufReadLoop(cirbufCB, buf, size);
} else {
cpSize = OsCirBufReadLinear(cirbufCB, buf, size);
}
return cpSize;
}
UINT32 LOS_CirBufInit(CirBuf *cirbufCB, CHAR *fifo, UINT32 size)
{
if ((cirbufCB == NULL) || (fifo == NULL)) {
return LOS_NOK;
}
(VOID)memset_s(cirbufCB, sizeof(CirBuf), 0, sizeof(CirBuf));
LOS_SpinInit(&cirbufCB->lock);
cirbufCB->size = size;
cirbufCB->remain = size;
cirbufCB->status = CBUF_USED;
cirbufCB->fifo = fifo;
return LOS_OK;
}
VOID LOS_CirBufDeinit(CirBuf *cirbufCB)
{
(VOID)memset_s(cirbufCB, sizeof(CirBuf), 0, sizeof(CirBuf));
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

87
kernel/common/los_cir_buf_pri.h Executable file
View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_CIRBUF_PRI_H
#define _LOS_CIRBUF_PRI_H
#include "los_typedef.h"
#include "los_spinlock.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef enum {
CBUF_UNUSED,
CBUF_USED
} CirBufStatus;
typedef struct {
UINT32 startIdx;
UINT32 endIdx;
UINT32 size;
UINT32 remain;
SPIN_LOCK_S lock;
CirBufStatus status;
CHAR *fifo;
} CirBuf;
STATIC INLINE VOID LOS_CirBufLock(CirBuf *cirbufCB, UINT32 *intSave)
{
if (cirbufCB == NULL) {
return;
}
LOS_SpinLockSave(&cirbufCB->lock, intSave);
}
STATIC INLINE VOID LOS_CirBufUnlock(CirBuf *cirbufCB, UINT32 intSave)
{
if (cirbufCB == NULL) {
return;
}
LOS_SpinUnlockRestore(&cirbufCB->lock, intSave);
}
extern UINT32 LOS_CirBufInit(CirBuf *cirbufCB, CHAR *fifo, UINT32 size);
extern VOID LOS_CirBufDeinit(CirBuf *cirbufCB);
extern UINT32 LOS_CirBufWrite(CirBuf *cirbufCB, const CHAR *buf, UINT32 size);
extern UINT32 LOS_CirBufRead(CirBuf *cirbufCB, CHAR *buf, UINT32 size);
extern UINT32 LOS_CirBufUsedSize(CirBuf *cirbufCB);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CIRBUF_PRI_H */

449
kernel/common/los_config.c Executable file
View File

@@ -0,0 +1,449 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_config.h"
#include "string.h"
#include "stdio.h"
#include "los_oom.h"
#ifdef LOSCFG_COMPAT_LINUXKPI
#include "linux/workqueue.h"
#include "linux/module.h"
#endif
#include "los_sys.h"
#include "los_tick.h"
#include "los_task_pri.h"
#include "los_printf.h"
#include "los_swtmr.h"
#include "los_swtmr_pri.h"
#include "los_timeslice_pri.h"
#include "los_memory_pri.h"
#include "los_sem_pri.h"
#include "los_mux_pri.h"
#include "los_queue_pri.h"
#include "los_memstat_pri.h"
#include "los_hwi_pri.h"
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_atomic.h"
#include "los_exc_pri.h"
#include "gic_common.h"
#include "los_vm_boot.h"
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#include "fs/fs_operation.h"
#endif
#if (LOSCFG_KERNEL_TRACE == YES)
#include "los_trace.h"
#endif
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
#ifdef LOSCFG_COMPAT_POSIX
#include "pprivate.h"
#endif
#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
#include "console.h"
#endif
#ifdef LOSCFG_KERNEL_TICKLESS
#include "los_tickless.h"
#endif
#ifdef LOSCFG_ARCH_CORTEX_M7
#include "los_exc_pri.h"
#endif
#ifdef LOSCFG_MEM_RECORDINFO
#include "los_memrecord_pri.h"
#endif
#include "los_hw_tick_pri.h"
#include "los_hwi_pri.h"
#if defined(LOSCFG_HW_RANDOM_ENABLE) || defined (LOSCFG_DRIVERS_RANDOM)
#include "randomdev.h"
#include "yarrow.h"
#endif
#ifdef LOSCFG_SHELL_DMESG
#include "dmesg_pri.h"
#endif
#ifdef LOSCFG_SHELL_LK
#include "shell_pri.h"
#endif
#ifdef LOSCFG_KERNEL_PIPE
#include "pipe_common.h"
#endif
#include "los_process_pri.h"
#include "los_futex_pri.h"
#ifdef LOSCFG_KERNEL_VDSO
#include "los_vdso.h"
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
#include "hm_liteipc.h"
#endif
#ifdef LOSCFG_DRIVERS_HIEVENT
#include "hievent_driver.h"
#endif
#if (LOSCFG_BASE_CORE_HILOG == YES)
#include "los_hilog.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern UINT32 OsSystemInit(VOID);
extern VOID SystemInit(VOID);
LITE_OS_SEC_TEXT_INIT VOID osRegister(VOID)
{
g_sysClock = OS_SYS_CLOCK;
g_tickPerSecond = LOSCFG_BASE_CORE_TICK_PER_SECOND;
return;
}
LITE_OS_SEC_TEXT_INIT VOID OsStart(VOID)
{
LosProcessCB *runProcess = NULL;
LosTaskCB *taskCB = NULL;
UINT32 cpuid = ArchCurrCpuid();
OsTickStart();
LOS_SpinLock(&g_taskSpin);
taskCB = OsGetTopTask();
runProcess = OS_PCB_FROM_PID(taskCB->processID);
runProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
#if (LOSCFG_KERNEL_SMP == YES)
/*
* attention: current cpu needs to be set, in case first task deletion
* may fail because this flag mismatch with the real current cpu.
*/
taskCB->currCpu = cpuid;
runProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_ADD(runProcess->processStatus);
#endif
OS_SCHEDULER_SET(cpuid);
PRINTK("cpu %d entering scheduler\n", cpuid);
OsStartToRun(taskCB);
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsIpcInit(VOID)
{
UINT32 ret;
#if (LOSCFG_BASE_IPC_SEM == YES)
ret = OsSemInit();
if (ret != LOS_OK) {
return ret;
}
#endif
#if (LOSCFG_BASE_IPC_QUEUE == YES)
ret = OsQueueInit();
if (ret != LOS_OK) {
return ret;
}
#endif
return LOS_OK;
}
#ifdef LOSCFG_KERNEL_PIPE
LITE_OS_SEC_TEXT_INIT STATIC VOID OsDriverPipeInit(VOID)
{
(VOID)pipe_init();
}
#endif
#ifdef LOSCFG_DRIVERS_HIEVENT
LITE_OS_SEC_TEXT_INIT STATIC VOID OsDriverHiEventInit(VOID)
{
(VOID)HieventInit();
}
#endif
#ifdef LOSCFG_COMPAT_BSD
extern void configure (void);
LITE_OS_SEC_TEXT_INIT STATIC INT32 OsBsdInit(VOID)
{
configure();
mi_startup(SI_SUB_ARCH_INIT);
return LOS_OK;
}
#endif
LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
{
UINT32 ret;
osRegister();
#ifdef LOSCFG_SHELL_DMESG
ret = OsDmesgInit();
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_SHELL_LK
OsLkLoggerInit(NULL);
#endif
#ifdef LOSCFG_EXC_INTERACTION
#ifdef LOSCFG_ARCH_CORTEX_M7
/* 4096: 4K space for Stack */
ret = OsMemExcInteractionInit((UINT32)&__bss_end + 4096);
#else
ret = OsMemExcInteractionInit((UINTPTR)&__bss_end);
#endif
if (ret != LOS_OK) {
return ret;
}
#endif
#if (LOSCFG_PLATFORM_HWI == YES)
OsHwiInit();
#endif
OsExcInit();
ret = OsTickInit(g_sysClock, LOSCFG_BASE_CORE_TICK_PER_SECOND);
if (ret != LOS_OK) {
return ret;
}
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
#ifdef LOSCFG_DRIVERS
uart_init();
#endif
#ifdef LOSCFG_SHELL
#endif //LOSCFG_SHELL
#endif //LOSCFG_PLATFORM_UART_WITHOUT_VFS
ret = OsTaskInit();
if (ret != LOS_OK) {
PRINT_ERR("OsTaskInit error\n");
return ret;
}
#if ((LOSCFG_BASE_IPC_QUEUE == YES) || (LOSCFG_BASE_IPC_MUX == YES) || (LOSCFG_BASE_IPC_SEM == YES))
ret = OsIpcInit();
if (ret != LOS_OK) {
return ret;
}
#endif
ret = OsSysMemInit();
if (ret != LOS_OK) {
PRINT_ERR("OsSysMemInit error\n");
return ret;
}
SyscallHandleInit();
/*
* CPUP should be inited before first task creation which depends on the semaphore
* when LOSCFG_KERNEL_SMP_TASK_SYNC is enabled. So don't change this init sequence
* if not neccessary. The sequence should be like this:
* 1. OsIpcInit
* 2. OsCpupInit
* 3. other inits have task creation
*/
#ifdef LOSCFG_KERNEL_CPUP
ret = OsCpupInit();
if (ret != LOS_OK) {
PRINT_ERR("OsCpupInit error\n");
return ret;
}
#endif
ret = OsKernelInitProcess();
if (ret != LOS_OK) {
return ret;
}
#if (LOSCFG_BASE_CORE_SWTMR == YES)
ret = OsSwtmrInit();
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_KERNEL_CPUP
OsCpupGuardCreator();
#endif
#if (LOSCFG_KERNEL_SMP == YES)
(VOID)OsMpInit();
#endif
#if defined(LOSCFG_HW_RANDOM_ENABLE) || defined (LOSCFG_DRIVERS_RANDOM)
random_alg_context.ra_init_alg(NULL);
run_harvester_iterate(NULL);
#endif
#ifdef LOSCFG_COMPAT_BSD
ret = OsBsdInit();
if (ret != LOS_OK) {
PRINT_ERR("init bsd failed!\n");
return ret;
}
#endif
#ifdef LOSCFG_KERNEL_PIPE
OsDriverPipeInit();
#endif
ret = OsSystemInit();
if (ret != LOS_OK) {
return ret;
}
#if LOSCFG_DRIVERS_HIEVENT
OsDriverHiEventInit();
#endif
#if (LOSCFG_KERNEL_TRACE == YES)
LOS_TraceInit();
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
ret = LiteIpcInit();
if (ret != LOS_OK) {
return ret;
}
#endif
#if (LOSCFG_BASE_CORE_HILOG == YES)
ret = HiLogDriverInit();
if (ret != LOS_OK) {
return ret;
}
#endif
#ifdef LOSCFG_KERNEL_VDSO
ret = OsInitVdso();
if (ret != LOS_OK) {
return ret;
}
#endif
ret = OsFutexInit();
if (ret != LOS_OK) {
PRINT_ERR("Create futex failed : %d!\n", ret);
return ret;
}
ret = OomTaskInit();
if (ret != LOS_OK) {
return ret;
}
return LOS_OK;
}
STATIC UINT32 OsSystemInitTaskCreate(VOID)
{
UINT32 taskID;
TSK_INIT_PARAM_S sysTask;
(VOID)memset_s(&sysTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
sysTask.pfnTaskEntry = (TSK_ENTRY_FUNC)SystemInit;
sysTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
sysTask.pcName = "SystemInit";
sysTask.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
sysTask.uwResved = LOS_TASK_STATUS_DETACHED;
#if (LOSCFG_KERNEL_SMP == YES)
sysTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
return LOS_TaskCreate(&taskID, &sysTask);
}
#ifdef LOSCFG_MEM_RECORDINFO
STATIC UINT32 OsMemShowTaskCreate(VOID)
{
UINT32 taskID;
TSK_INIT_PARAM_S appTask;
(VOID)memset_s(&appTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
appTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OsMemRecordShowTask;
appTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
appTask.pcName = "memshow_Task";
appTask.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
appTask.uwResved = LOS_TASK_STATUS_DETACHED;
return LOS_TaskCreate(&taskID, &appTask);
}
#endif
UINT32 OsSystemInit(VOID)
{
UINT32 ret;
#ifdef LOSCFG_FS_VFS
los_vfs_init();
#endif
#ifdef LOSCFG_COMPAT_LINUXKPI
g_pstSystemWq = create_workqueue("system_wq");
#endif
ret = OsSystemInitTaskCreate();
if (ret != LOS_OK) {
return ret;
}
#ifdef LOSCFG_MEM_RECORDINFO
ret = OsMemShowTaskCreate();
if (ret != LOS_OK) {
PRINTK("create memshow_Task error %u\n", ret);
return ret;
}
PRINTK("create memshow_Task ok\n");
#endif
#ifdef LOSCFG_KERNEL_TICKLESS
LOS_TicklessEnable();
#endif
return 0;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

484
kernel/common/los_config.h Executable file
View File

@@ -0,0 +1,484 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
/**
* @defgroup los_config System configuration items
*/
#ifndef _LOS_CONFIG_H
#define _LOS_CONFIG_H
#include "platform_config.h"
#include "los_tick.h"
#include "los_vm_zone.h"
#include "sys_config.h"
#include "hisoc/clock.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_config
* int stack start addr
*/
extern CHAR __int_stack_start;
extern CHAR __rodata_start;
extern CHAR __rodata_end;
extern CHAR __bss_start;
extern CHAR __bss_end;
extern CHAR __text_start;
extern CHAR __text_end;
extern CHAR __ram_data_start;
extern CHAR __ram_data_end;
extern UINT32 __heap_start;
extern UINT32 __heap_end;
/****************************** System clock module configuration ****************************/
/**
* @ingroup los_config
* System clock (unit: HZ)
*/
#ifndef OS_SYS_CLOCK
#define OS_SYS_CLOCK (get_bus_clk())
#endif
/**
* @ingroup los_config
* time timer clock (unit: HZ)
*/
#ifndef OS_TIME_TIMER_CLOCK
#define OS_TIME_TIMER_CLOCK OS_SYS_CLOCK
#endif
/**
* @ingroup los_config
* limit addr range when search for 'func local(frame pointer)' or 'func name'
*/
#ifndef OS_SYS_FUNC_ADDR_START
#define OS_SYS_FUNC_ADDR_START ((UINTPTR)&__int_stack_start)
#endif
#ifndef OS_SYS_FUNC_ADDR_END
#define OS_SYS_FUNC_ADDR_END (KERNEL_VMM_BASE + SYS_MEM_SIZE_DEFAULT)
#endif
/**
* @ingroup los_config
* Number of Ticks in one second
*/
#ifndef LOSCFG_BASE_CORE_TICK_PER_SECOND
#define LOSCFG_BASE_CORE_TICK_PER_SECOND 100
#endif
/**
* @ingroup los_config
* Microseconds of adjtime in one second
*/
#ifndef LOSCFG_BASE_CORE_ADJ_PER_SECOND
#define LOSCFG_BASE_CORE_ADJ_PER_SECOND 500
#endif
/**
* @ingroup los_config
* Sched clck interval
*/
#define SCHED_CLOCK_INTETRVAL_TICKS 100
/**
* @ingroup los_config
* External configuration item for timer tailoring
*/
#ifndef LOSCFG_BASE_CORE_TICK_HW_TIME
#define LOSCFG_BASE_CORE_TICK_HW_TIME NO
#endif
/****************************** Hardware interrupt module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for hardware interrupt tailoring
*/
#ifndef LOSCFG_PLATFORM_HWI
#define LOSCFG_PLATFORM_HWI YES
#endif
/**
* @ingroup los_config
* Maximum number of used hardware interrupts, including Tick timer interrupts.
*/
#ifndef LOSCFG_PLATFORM_HWI_LIMIT
#define LOSCFG_PLATFORM_HWI_LIMIT 96
#endif
/**
* @ingroup los_config
* The binary point value decide the maximum preemption level.
* If preemption supported, the config value is [0, 1, 2, 3, 4, 5, 6],
* to the corresponding preemption level value is [128, 64, 32, 16, 8, 4, 2].
*/
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
#ifndef MAX_BINARY_POINT_VALUE
#define MAX_BINARY_POINT_VALUE 4
#endif
#endif
/****************************** Task module configuration ********************************/
/**
* @ingroup los_config
* Minimum stack size.
*
* 0x600 bytes, aligned on a boundary of 8.
* 0x600 bytes, aligned on a boundary of 4.
*/
#ifndef LOS_TASK_MIN_STACK_SIZE
#ifdef __LP64__
#define LOS_TASK_MIN_STACK_SIZE (ALIGN(0x800, 8))
#else
#define LOS_TASK_MIN_STACK_SIZE (ALIGN(0x800, 4))
#endif
#endif
/**
* @ingroup los_config
* Default task priority
*/
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO 10
#endif
/**
* @ingroup los_config
* Maximum supported number of tasks except the idle task rather than the number of usable tasks
*/
#ifndef LOSCFG_BASE_CORE_TSK_LIMIT
#define LOSCFG_BASE_CORE_TSK_LIMIT 128
#endif
/**
* @ingroup los_config
* Maximum supported number of process rather than the number of usable processes.
*/
#ifndef LOSCFG_BASE_CORE_PROCESS_LIMIT
#define LOSCFG_BASE_CORE_PROCESS_LIMIT 64
#endif
#if (LOSCFG_BASE_CORE_TSK_LIMIT < LOSCFG_BASE_CORE_PROCESS_LIMIT)
#error "The number of tasks must be greater than or equal to the number of processes!"
#endif
/**
* @ingroup los_config
* Size of the idle task stack
*/
#ifndef LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE SIZE(0x800)
#endif
/**
* @ingroup los_config
* Default task stack size
*/
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE SIZE(0x4000)
#endif
/**
* @ingroup los_config
* Longest execution time of tasks with the same priorities
*/
#ifndef LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 2
#endif
/**
* @ingroup los_config
* Configuration item for task (stack) monitoring module tailoring
*/
#ifndef LOSCFG_BASE_CORE_TSK_MONITOR
#define LOSCFG_BASE_CORE_TSK_MONITOR YES
#endif
/**
* @ingroup los_config
* Configuration item for task perf task filter hook
*/
#ifndef OS_PERF_TSK_FILTER
#define OS_PERF_TSK_FILTER NO
#endif
/****************************** Semaphore module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for semaphore module tailoring
*/
#ifndef LOSCFG_BASE_IPC_SEM
#define LOSCFG_BASE_IPC_SEM YES
#endif
/**
* @ingroup los_config
* Maximum supported number of semaphores
*/
#ifndef LOSCFG_BASE_IPC_SEM_LIMIT
#define LOSCFG_BASE_IPC_SEM_LIMIT 1024
#endif
/****************************** mutex module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for mutex module tailoring
*/
#ifndef LOSCFG_BASE_IPC_MUX
#define LOSCFG_BASE_IPC_MUX YES
#endif
/****************************** Queue module configuration ********************************/
/**
* @ingroup los_config
* Configuration item for queue module tailoring
*/
#ifndef LOSCFG_BASE_IPC_QUEUE
#define LOSCFG_BASE_IPC_QUEUE YES
#endif
/**
* @ingroup los_config
* Maximum supported number of queues rather than the number of usable queues
*/
#ifndef LOSCFG_BASE_IPC_QUEUE_LIMIT
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 1024
#endif
/****************************** Software timer module configuration **************************/
#if (LOSCFG_BASE_IPC_QUEUE == YES)
/**
* @ingroup los_config
* Configuration item for software timer module tailoring
*/
#ifndef LOSCFG_BASE_CORE_SWTMR
#define LOSCFG_BASE_CORE_SWTMR YES
#endif
/**
* @ingroup los_config
* Maximum supported number of software timers rather than the number of usable software timers
*/
#ifndef LOSCFG_BASE_CORE_SWTMR_LIMIT
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 1024
#endif
/**
* @ingroup los_config
* Max number of software timers ID
*
* 0xFFFF: max number of all software timers
*/
#ifndef OS_SWTMR_MAX_TIMERID
#define OS_SWTMR_MAX_TIMERID ((0xFFFF / LOSCFG_BASE_CORE_SWTMR_LIMIT) * LOSCFG_BASE_CORE_SWTMR_LIMIT)
#endif
/**
* @ingroup los_config
* Maximum size of a software timer queue
*/
#ifndef OS_SWTMR_HANDLE_QUEUE_SIZE
#define OS_SWTMR_HANDLE_QUEUE_SIZE LOSCFG_BASE_CORE_SWTMR_LIMIT
#endif
#endif
/****************************** Memory module configuration **************************/
#ifndef OS_EXC_INTERACTMEM_SIZE
#define OS_EXC_INTERACTMEM_SIZE (EXC_INTERACT_MEM_SIZE)
#endif
/**
* @ingroup los_config
* Starting address of the system memory
*/
#ifndef OS_SYS_MEM_ADDR
#define OS_SYS_MEM_ADDR (&m_aucSysMem1[0])
#endif
/**
* @ingroup los_config
* Memory size
*/
#ifndef OS_SYS_MEM_SIZE
#define OS_SYS_MEM_SIZE \
((OS_SYS_FUNC_ADDR_END) - ((OS_EXC_INTERACTMEM_SIZE + ((UINTPTR)&__bss_end) + (64 - 1)) & ~(64 - 1)))
#endif
/****************************** SMP module configuration **************************/
#ifndef LOSCFG_KERNEL_SMP
#define LOSCFG_KERNEL_SMP NO
#endif
#ifndef LOSCFG_KERNEL_SMP_LOCKDEP
#define LOSCFG_KERNEL_SMP_LOCKDEP NO
#endif
#ifndef LOSCFG_KERNEL_SMP_TASK_SYNC
#define LOSCFG_KERNEL_SMP_TASK_SYNC NO
#endif
#ifndef LOSCFG_KERNEL_SCHED_STATISTICS
#define LOSCFG_KERNEL_SCHED_STATISTICS NO
#endif
#if (LOSCFG_KERNEL_SMP == YES)
#define LOSCFG_KERNEL_CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM
#else
#define LOSCFG_KERNEL_CORE_NUM 1
#endif
#define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1)
/****************************** trace module configuration **************************/
#ifndef LOSCFG_KERNEL_TRACE
#define LOSCFG_KERNEL_TRACE NO
#endif
/**
* @ingroup los_trace
* It's the total size of trace buffer. It's in the unit of char
*/
#if (LOSCFG_KERNEL_TRACE == YES)
#define LOS_TRACE_BUFFER_SIZE 2048
#endif
/**
* @ingroup los_config
* Version number
*/
#define _T(x) x
#define KERNEL_NAME "Huawei LiteOS"
#define KERNEL_SEP " "
#define _V(v) _T(KERNEL_NAME)_T(KERNEL_SEP)_T(v)
/**
* @ingroup los_config
* The Version number of Public
*/
#define KERNEL_MAJOR 2
#define KERNEL_MINOR 0
#define KERNEL_PATCH 0
#define KERNEL_ITRE 35
#define VERSION_NUM(a, b, c, d) (((a) << 24) | ((b) << 16) | (c) << 8 | (d))
#define KERNEL_OPEN_VERSION_NUM VERSION_NUM(KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE)
/****************************** Dynamic loading module configuration **************************/
#ifndef OS_AUTOINIT_DYNLOADER
#define OS_AUTOINIT_DYNLOADER YES
#endif
/****************************** exception information configuration ******************************/
#ifdef LOSCFG_SHELL_EXCINFO
/**
* @ingroup los_config
* the size of space for recording exception information
*/
#define EXCINFO_RECORD_BUF_SIZE (16 * 1024)
/**
* @ingroup los_config
* the address of space for recording exception information
* @attention
* <ul>
* <li> if uses, the address must be valid in flash, and it should not overlap with other addresses
* used to store valid information. </li>
* </ul>
*
*/
#define EXCINFO_RECORD_ADDR (0xffffffff)
/**
* @ingroup los_config
* @brief define the type of functions for reading or writing exception information.
*
* @par Description:
* <ul>
* <li>This defination is used to declare the type of functions for reading or writing exception information</li>
* </ul>
* @attention
* <ul>
* <li> "startAddr" must be left to save the exception address space, the size of "buf" is "space" </li>
* </ul>
*
* @param startAddr [IN] Address of storage ,its must be left to save the exception address space
* @param space [IN] size of storage.its is also the size of "buf"
* @param rwFlag [IN] writer-read flag, 0 for writing,1 for reading, other number is to do nothing.
* @param buf [IN] the buffer of storing data.
*
* @retval none.
* @par Dependency:
* <ul><li>los_config.h: the header file that contains the type defination.</li></ul>
* @see
*/
typedef VOID (*log_read_write_fn)(UINT32 startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf);
/**
* @ingroup los_config
* @brief Register recording exception information function.
*
* @par Description:
* <ul>
* <li>This API is used to Register recording exception information function,
* and specify location and space and size</li>
* </ul>
* @attention
* <ul>
* <li> "startAddr" must be left to save the exception address space, the size of "buf" is "space",
* the space of "buf" is malloc or free in user's code </li>
* </ul>
*
* @param startAddr [IN] Address of storage, it must be left to save the exception address space
* @param space [IN] size of storage space, it is also the size of "buf"
* @param buf [IN] the buffer of storing exception information, the space of "buf" is malloc or free
in user's code
* @param hook [IN] the function for reading or writing exception information.
*
* @retval none.
* @par Dependency:
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see
*/
VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook);
#endif
extern VOID OsStart(VOID);
extern INT32 OsMain(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CONFIG_H */

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_exc_interaction_pri.h"
#ifdef LOSCFG_EXC_INTERACTION
#include "los_task_pri.h"
#ifdef LOSCFG_SHELL
#include "shell.h"
#include "shell_pri.h"
#endif
#include "console.h"
#include "hisoc/uart.h"
#include "hal_hwi.h"
/* Inter-module variable and function */
extern CONSOLE_CB *g_console[];
#define IS_UARTSHELL_ID(taskID) (((taskID) == shellCB->shellTaskHandle) || \
((taskID) == shellCB->shellEntryHandle))
STATIC BOOL IsIdleTask(UINT32 taskID)
{
UINT32 i;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
if (taskID == g_percpu[i].idleTaskID) {
return TRUE;
}
}
return FALSE;
}
STATIC BOOL IsSwtTask(UINT32 taskID)
{
UINT32 i;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
if (taskID == g_percpu[i].swtmrTaskID) {
return TRUE;
}
}
return FALSE;
}
UINT32 OsExcInteractionTaskCheck(const TSK_INIT_PARAM_S *initParam)
{
if (initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)OsIdleTask) {
return LOS_OK;
}
if ((initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellTask) ||
(initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellEntry)) {
return LOS_OK;
}
return LOS_NOK;
}
VOID OsExcInteractionTaskKeep(VOID)
{
LosTaskCB *taskCB = NULL;
UINT32 taskID;
UINT32 curIrqNum;
ShellCB *shellCB = NULL;
CONSOLE_CB *consoleCB = NULL;
consoleCB = g_console[CONSOLE_SERIAL - 1];
if (consoleCB == NULL) {
PRINTK("Serial Shell Uninitialized\n");
return;
}
shellCB = (ShellCB *)(consoleCB->shellHandle);
g_intCount[ArchCurrCpuid()] = 0;
for (taskID = 0; taskID < g_taskMaxNum; taskID++) {
if (taskID == OsCurrTaskGet()->taskID) {
continue;
} else if ((IsIdleTask(taskID) == TRUE) || IS_UARTSHELL_ID(taskID)) {
continue;
}
taskCB = OS_TCB_FROM_TID(taskID);
if (OsTaskIsUnused(taskCB)) {
continue;
}
if (IsSwtTask(taskID) == TRUE) {
taskCB->taskStatus &= (~OS_TASK_FLAG_SYSTEM_TASK);
}
(VOID)LOS_TaskDelete(taskID);
}
HalIrqInit();
HalIrqUnmask(NUM_HAL_INTERRUPT_UART);
curIrqNum = HalCurIrqGet();
HalIrqClear(curIrqNum);
(VOID)LOS_TaskDelete(OsCurrTaskGet()->taskID);
/* unreachable */
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_EXC_INTER_PRI_H
#define _LOS_EXC_INTER_PRI_H
#include "los_config.h"
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern UINT32 OsExcInteractionTaskCheck(const TSK_INIT_PARAM_S *initParam);
extern VOID OsExcInteractionTaskKeep(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_EXC_INTER_PRI_H */

178
kernel/common/los_excinfo.c Executable file
View File

@@ -0,0 +1,178 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_base.h"
#include "los_hwi.h"
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_SHELL_EXCINFO
STATIC log_read_write_fn g_excInfoRW = NULL; /* the hook of read-writing exception information */
STATIC CHAR *g_excInfoBuf = NULL; /* pointer to the buffer for storing the exception information */
STATIC UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */
STATIC UINT32 g_recordAddr = 0; /* the address of storing the exception information */
STATIC UINT32 g_recordSpace = 0; /* the size of storing the exception information */
VOID SetExcInfoRW(log_read_write_fn func)
{
g_excInfoRW = func;
}
log_read_write_fn GetExcInfoRW(VOID)
{
return g_excInfoRW;
}
VOID SetExcInfoBuf(CHAR *buf)
{
g_excInfoBuf = buf;
}
CHAR *GetExcInfoBuf(VOID)
{
return g_excInfoBuf;
}
VOID SetExcInfoIndex(UINT32 index)
{
g_excInfoIndex = index;
}
UINT32 GetExcInfoIndex(VOID)
{
return g_excInfoIndex;
}
VOID SetRecordAddr(UINT32 addr)
{
g_recordAddr = addr;
}
UINT32 GetRecordAddr(VOID)
{
return g_recordAddr;
}
VOID SetRecordSpace(UINT32 space)
{
g_recordSpace = space;
}
UINT32 GetRecordSpace(VOID)
{
return g_recordSpace;
}
VOID WriteExcBufVa(const CHAR *format, va_list arglist)
{
errno_t ret;
if (g_recordSpace > g_excInfoIndex) {
ret = vsnprintf_s((g_excInfoBuf + g_excInfoIndex), (g_recordSpace - g_excInfoIndex),
(g_recordSpace - g_excInfoIndex - 1), format, arglist);
if (ret == -1) {
PRINT_ERR("exc info buffer is not enough or vsnprintf_s is error.\n");
return;
}
g_excInfoIndex += ret;
}
}
VOID WriteExcInfoToBuf(const CHAR *format, ...)
{
va_list arglist;
va_start(arglist, format);
WriteExcBufVa(format, arglist);
va_end(arglist);
}
VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook)
{
if ((hook == NULL) || (buf == NULL)) {
PRINT_ERR("Buf or hook is null.\n");
return;
}
g_recordAddr = startAddr;
g_recordSpace = space;
g_excInfoBuf = buf;
g_excInfoRW = hook;
#ifdef LOSCFG_FS_VFS
los_vfs_init();
#endif
}
/* Be called in the exception. */
VOID OsReadWriteExceptionInfo(UINT32 startAddr, UINT32 space, UINT32 flag, CHAR *buf)
{
if ((buf == NULL) || (space == 0)) {
PRINT_ERR("buffer is null or space is zero\n");
return;
}
// user can write exception information to files here
}
VOID OsRecordExcInfoTime(VOID)
{
#ifdef LOSCFG_FS_VFS
#define NOW_TIME_LENGTH 24
time_t t;
struct tm *tmTime = NULL;
CHAR nowTime[NOW_TIME_LENGTH];
(VOID)time(&t);
tmTime = localtime(&t);
if (tmTime == NULL) {
return;
}
(VOID)memset_s(nowTime, sizeof(nowTime), 0, sizeof(nowTime));
(VOID)strftime(nowTime, NOW_TIME_LENGTH, "%Y-%m-%d %H:%M:%S", tmTime);
#undef NOW_TIME_LENGTH
WriteExcInfoToBuf("%s \n", nowTime);
#endif
}
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

65
kernel/common/los_excinfo_pri.h Executable file
View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_EXCINFO_PRI_H
#define _LOS_EXCINFO_PRI_H
#include "los_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_SHELL_EXCINFO
extern VOID SetExcInfoRW(log_read_write_fn func);
extern log_read_write_fn GetExcInfoRW(VOID);
extern VOID SetExcInfoBuf(CHAR *buf);
extern CHAR *GetExcInfoBuf(VOID);
extern VOID SetExcInfoIndex(UINT32 index);
extern UINT32 GetExcInfoIndex(VOID);
extern VOID SetRecordAddr(UINT32 addr);
extern UINT32 GetRecordAddr(VOID);
extern VOID SetRecordSpace(UINT32 space);
extern UINT32 GetRecordSpace(VOID);
extern VOID WriteExcBufVa(const CHAR *format, va_list arg);
extern VOID WriteExcInfoToBuf(const CHAR *format, ...);
extern VOID OsRecordExcInfoTime(VOID);
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_EXCINFO_PRI_H */

330
kernel/common/los_hilog.c Executable file
View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_hilog.h"
#include "los_mp.h"
#include "los_mux.h"
#include "los_process_pri.h"
#include "los_task_pri.h"
#include "fs/fs.h"
#include "los_vm_map.h"
#include "los_vm_lock.h"
#include "user_copy.h"
#define HILOG_BUFFER 1024
#define DRIVER_MODE 0666
#define HILOG_DRIVER "/dev/hilog"
struct HiLogEntry {
unsigned int len;
unsigned int hdrSize;
unsigned int pid : 16;
unsigned int taskId : 16;
unsigned int sec;
unsigned int nsec;
unsigned int reserved;
char msg[0];
};
ssize_t HilogRead(struct file *filep, char __user *buf, size_t count);
ssize_t HilogWrite(struct file *filep, const char __user *buf, size_t count);
int HiLogOpen(FAR struct file *filep);
int HiLogClose(FAR struct file *filep);
static ssize_t HiLogWrite(FAR struct file *filep, const char *buffer, size_t bufLen);
static ssize_t HiLogRead(FAR struct file *filep, char *buffer, size_t bufLen);
STATIC struct file_operations_vfs g_hilogFops = {
HiLogOpen, /* open */
HiLogClose, /* close */
HiLogRead, /* read */
HiLogWrite, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
FAR struct HiLogCharDevice {
int flag;
LosMux mtx;
unsigned char *buffer;
wait_queue_head_t wq;
size_t writeOffset;
size_t headOffset;
size_t size;
size_t count;
} g_hiLogDev;
static inline unsigned char *HiLogBufferHead(void)
{
return g_hiLogDev.buffer + g_hiLogDev.headOffset;
}
int HiLogOpen(FAR struct file *filep)
{
(void)filep;
return 0;
}
int HiLogClose(FAR struct file *filep)
{
(void)filep;
return 0;
}
static void HiLogBufferInc(size_t sz)
{
if (g_hiLogDev.size + sz <= HILOG_BUFFER) {
g_hiLogDev.size += sz;
g_hiLogDev.writeOffset += sz;
g_hiLogDev.writeOffset %= HILOG_BUFFER;
g_hiLogDev.count++;
}
}
static void HiLogBufferDec(size_t sz)
{
if (g_hiLogDev.size >= sz) {
g_hiLogDev.size -= sz;
g_hiLogDev.headOffset += sz;
g_hiLogDev.headOffset %= HILOG_BUFFER;
g_hiLogDev.count--;
}
}
static int HiLogBufferCopy(unsigned char *dst, unsigned dstLen, unsigned char *src, size_t srcLen)
{
int retval = -1;
size_t minLen = (dstLen > srcLen) ? srcLen : dstLen;
if (LOS_IsUserAddressRange((VADDR_T)dst, minLen) && LOS_IsUserAddressRange((VADDR_T)src, minLen)) {
return retval;
}
if (LOS_IsUserAddressRange((VADDR_T)dst, minLen)) {
retval = LOS_ArchCopyToUser(dst, src, minLen);
} else if (LOS_IsUserAddressRange((VADDR_T)src, minLen)) {
retval = LOS_ArchCopyFromUser(dst, src, minLen);
} else {
retval = memcpy_s(dst, dstLen, src, srcLen);
}
return retval;
}
static int HiLogReadRingBuffer(unsigned char *buffer, size_t bufLen)
{
size_t retval;
size_t bufLeft = HILOG_BUFFER - g_hiLogDev.headOffset;
if (bufLeft > bufLen) {
retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLen);
} else {
retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLeft);
if (retval < 0) {
return retval;
}
retval = HiLogBufferCopy(buffer + bufLeft, bufLen - bufLeft, g_hiLogDev.buffer, bufLen - bufLeft);
}
return retval;
}
static ssize_t HiLogRead(FAR struct file *filep, char *buffer, size_t bufLen)
{
size_t retval;
struct HiLogEntry header;
(void)filep;
wait_event_interruptible(g_hiLogDev.wq, (g_hiLogDev.size > 0));
(VOID)LOS_MuxAcquire(&g_hiLogDev.mtx);
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
if (retval < 0) {
retval = -EINVAL;
goto out;
}
if (bufLen < header.len + sizeof(header)) {
dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize, header.nsec);
retval = -ENOMEM;
goto out;
}
HiLogBufferDec(sizeof(header));
retval = HiLogBufferCopy((unsigned char *)buffer, bufLen, (unsigned char *)&header, sizeof(header));
if (retval < 0) {
retval = -EINVAL;
goto out;
}
retval = HiLogReadRingBuffer((unsigned char *)(buffer + sizeof(header)), header.len);
if (retval < 0) {
retval = -EINVAL;
goto out;
}
HiLogBufferDec(header.len);
retval = header.len + sizeof(header);
out:
(VOID)LOS_MuxRelease(&g_hiLogDev.mtx);
return retval;
}
static int HiLogWriteRingBuffer(unsigned char *buffer, size_t bufLen)
{
int retval;
size_t bufLeft = HILOG_BUFFER - g_hiLogDev.writeOffset;
if (bufLen > bufLeft) {
retval = HiLogBufferCopy(g_hiLogDev.buffer + g_hiLogDev.writeOffset, bufLeft, buffer, bufLeft);
if (retval) {
return -1;
}
retval = HiLogBufferCopy(g_hiLogDev.buffer, HILOG_BUFFER, buffer + bufLeft, bufLen - bufLeft);
} else {
retval = HiLogBufferCopy(g_hiLogDev.buffer + g_hiLogDev.writeOffset, bufLeft, buffer, bufLen);
}
if (retval < 0) {
return -1;
}
return 0;
}
static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
{
struct timespec now;
int ret;
ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) {
dprintf("In %s line %d,clock_gettime fail", __FUNCTION__, __LINE__);
return;
}
header->len = len;
header->pid = LOS_GetCurrProcessID();
header->taskId = LOS_CurTaskIDGet();
header->sec = now.tv_sec;
header->nsec = now.tv_nsec;
header->hdrSize = sizeof(struct HiLogEntry);
}
static void HiLogCoverOldLog(size_t bufLen)
{
int retval;
struct HiLogEntry header;
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
while (totalSize + g_hiLogDev.size >= HILOG_BUFFER) {
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
if (retval < 0) {
break;
}
HiLogBufferDec(sizeof(header) + header.len);
}
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
{
struct HiLogEntry header;
int retval;
(VOID)LOS_MuxAcquire(&g_hiLogDev.mtx);
HiLogCoverOldLog(bufLen);
HiLogHeadInit(&header, bufLen);
retval = HiLogWriteRingBuffer((unsigned char *)&header, sizeof(header));
if (retval) {
retval = -ENODATA;
goto out;
}
HiLogBufferInc(sizeof(header));
retval = HiLogWriteRingBuffer((unsigned char *)(buffer), header.len);
if (retval) {
retval = -ENODATA;
goto out;
}
HiLogBufferInc(header.len);
retval = header.len;
out:
(VOID)LOS_MuxRelease(&g_hiLogDev.mtx);
if (retval > 0) {
wake_up_interruptible(&g_hiLogDev.wq);
}
if (retval < 0) {
dprintf("write fail retval=%d\n", retval);
}
return retval;
}
static ssize_t HiLogWrite(FAR struct file *filep, const char *buffer, size_t bufLen)
{
(void)filep;
if (bufLen + sizeof(struct HiLogEntry) > HILOG_BUFFER) {
dprintf("input too large\n");
return -ENOMEM;
}
return HiLogWriteInternal(buffer, bufLen);
}
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", __FUNCTION__, __LINE__);
}
init_waitqueue_head(&g_hiLogDev.wq);
LOS_MuxInit(&g_hiLogDev.mtx, NULL);
g_hiLogDev.writeOffset = 0;
g_hiLogDev.headOffset = 0;
g_hiLogDev.size = 0;
g_hiLogDev.count = 0;
}
int HiLogDriverInit(VOID)
{
HiLogDeviceInit();
return register_driver(HILOG_DRIVER, &g_hilogFops, DRIVER_MODE, NULL);
}

53
kernel/common/los_hilog.h Executable file
View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef LOS_HILOG_H
#define LOS_HILOG_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef __user
#define __user
#endif
extern int HiLogDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

155
kernel/common/los_magickey.c Executable file
View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_magickey.h"
#include "los_task_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_ENABLE_MAGICKEY
#define MAGIC_KEY_NUM 5
STATIC VOID OsMagicHelp(VOID);
STATIC VOID OsMagicTaskShow(VOID);
STATIC VOID OsMagicPanic(VOID);
STATIC VOID OsMagicMemCheck(VOID);
STATIC MagicKeyOp g_magicMemCheckOp = {
.opHandler = OsMagicMemCheck,
.helpMsg = "Check system memory(ctrl+e) ",
.magicKey = 0x05 /* ctrl + e */
};
STATIC MagicKeyOp g_magicPanicOp = {
.opHandler = OsMagicPanic,
.helpMsg = "System panic(ctrl+p) ",
.magicKey = 0x10 /* ctrl + p */
};
STATIC MagicKeyOp g_magicTaskShowOp = {
.opHandler = OsMagicTaskShow,
.helpMsg = "Show task information(ctrl+t) ",
.magicKey = 0x14 /* ctrl + t */
};
STATIC MagicKeyOp g_magicHelpOp = {
.opHandler = OsMagicHelp,
.helpMsg = "Show all magic op key(ctrl+z) ",
.magicKey = 0x1a /* ctrl + z */
};
/*
* NOTICE:Suggest don't use
* ctrl+h/backspace=0x8,
* ctrl+i/tab=0x9,
* ctrl+m/enter=0xd,
* ctrl+n/shift out=0xe,
* ctrl+o/shift in=0xf,
* ctrl+[/esc=0x1b,
* ctrl+] used for telnet commond mode;
*/
STATIC MagicKeyOp *g_magicOpTable[MAGIC_KEY_NUM] = {
&g_magicMemCheckOp, /* ctrl + e */
&g_magicPanicOp, /* ctrl + p */
&g_magicTaskShowOp, /* ctrl + t */
&g_magicHelpOp, /* ctrl + z */
NULL /* rserved */
};
STATIC VOID OsMagicHelp(VOID)
{
INT32 i;
PRINTK("HELP: ");
for (i = 0; g_magicOpTable[i] != NULL; ++i) {
PRINTK("%s ", g_magicOpTable[i]->helpMsg);
}
PRINTK("\n");
return;
}
STATIC VOID OsMagicTaskShow(VOID)
{
const CHAR *arg = "-a";
(VOID)OsShellCmdDumpTask(1, &arg);
return;
}
STATIC VOID OsMagicPanic(VOID)
{
LOS_Panic("Magic key :\n");
return;
}
STATIC VOID OsMagicMemCheck(VOID)
{
if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) {
PRINTK("system memcheck over, all passed!\n");
}
return;
}
#endif
INT32 CheckMagicKey(CHAR key)
{
#ifdef LOSCFG_ENABLE_MAGICKEY
INT32 i;
STATIC UINT32 magicKeySwitch = 0;
if (key == 0x12) { /* ctrl + r */
magicKeySwitch = ~magicKeySwitch;
if (magicKeySwitch != 0) {
PRINTK("Magic key on\n");
} else {
PRINTK("Magic key off\n");
}
return 1;
}
if (magicKeySwitch != 0) {
for (i = 0; g_magicOpTable[i] != NULL; ++i) {
if (key == g_magicOpTable[i]->magicKey) {
(g_magicOpTable[i])->opHandler();
return 1;
}
}
}
#endif
return 0;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

57
kernel/common/los_magickey.h Executable file
View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_MAGICKEY_H
#define _LOS_MAGICKEY_H
#include "los_exc.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
VOID (*opHandler)(VOID);
CHAR *helpMsg;
CHAR magicKey;
} MagicKeyOp;
extern INT32 CheckMagicKey(CHAR key);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

270
kernel/common/los_printf.c Executable file
View File

@@ -0,0 +1,270 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_base.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#include "los_hwi.h"
#include "los_memory_pri.h"
#include "uart.h"
#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif
#ifdef LOSCFG_SHELL_DMESG
#include "dmesg_pri.h"
#endif
#ifdef LOSCFG_SHELL_EXCINFO
#include "los_excinfo_pri.h"
#endif
#include "los_exc_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SIZEBUF 256
const CHAR *g_logString[] = {
"EMG",
"COMMON",
"ERR",
"WARN",
"INFO",
"DEBUG",
"TRACE"
};
const CHAR *OsLogLvGet(INT32 level)
{
return g_logString[level];
}
STATIC VOID ErrorMsg(VOID)
{
const CHAR *p = "Output illegal string! vsnprintf_s failed!\n";
UartPuts(p, (UINT32)strlen(p), UART_WITH_LOCK);
}
STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
{
#ifdef LOSCFG_SHELL_DMESG
if (!OsCheckUartLock()) {
UartPuts(str, len, isLock);
}
if (isLock != UART_WITHOUT_LOCK) {
(VOID)OsLogMemcpyRecord(str, len);
}
#else
UartPuts(str, len, isLock);
#endif
}
VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
{
switch (type) {
case CONSOLE_OUTPUT:
#ifdef LOSCFG_PLATFORM_CONSOLE
if (ConsoleEnable() == TRUE) {
(VOID)write(STDOUT_FILENO, str, (size_t)len);
break;
}
#endif
/* fall-through */
case UART_OUTPUT:
UartOutput(str, len, UART_WITH_LOCK);
break;
case EXC_OUTPUT:
UartOutput(str, len, UART_WITHOUT_LOCK);
break;
default:
break;
}
return;
}
STATIC VOID OsVprintfFree(CHAR *buf, UINT32 bufLen)
{
if (bufLen != SIZEBUF) {
(VOID)LOS_MemFree(m_aucSysMem0, buf);
}
}
VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type)
{
INT32 len;
const CHAR *errMsgMalloc = "OsVprintf, malloc failed!\n";
const CHAR *errMsgLen = "OsVprintf, length overflow!\n";
CHAR aBuf[SIZEBUF] = {0};
CHAR *bBuf = NULL;
UINT32 bufLen = SIZEBUF;
UINT32 systemStatus;
bBuf = aBuf;
len = vsnprintf_s(bBuf, bufLen, bufLen - 1, fmt, ap);
if ((len == -1) && (*bBuf == '\0')) {
/* parameter is illegal or some features in fmt dont support */
ErrorMsg();
return;
}
while (len == -1) {
/* bBuf is not enough */
OsVprintfFree(bBuf, bufLen);
bufLen = bufLen << 1;
if ((INT32)bufLen <= 0) {
UartPuts(errMsgLen, (UINT32)strlen(errMsgLen), UART_WITH_LOCK);
return;
}
bBuf = (CHAR *)LOS_MemAlloc(m_aucSysMem0, bufLen);
if (bBuf == NULL) {
UartPuts(errMsgMalloc, (UINT32)strlen(errMsgMalloc), UART_WITH_LOCK);
return;
}
len = vsnprintf_s(bBuf, bufLen, bufLen - 1, fmt, ap);
if (*bBuf == '\0') {
/* parameter is illegal or some features in fmt dont support */
(VOID)LOS_MemFree(m_aucSysMem0, bBuf);
ErrorMsg();
return;
}
}
*(bBuf + len) = '\0';
systemStatus = OsGetSystemStatus();
if ((systemStatus == OS_SYSTEM_NORMAL) || (systemStatus == OS_SYSTEM_EXC_OTHER_CPU)) {
OutputControl(bBuf, len, type);
} else if (systemStatus == OS_SYSTEM_EXC_CURR_CPU) {
OutputControl(bBuf, len, EXC_OUTPUT);
}
OsVprintfFree(bBuf, bufLen);
}
VOID UartVprintf(const CHAR *fmt, va_list ap)
{
OsVprintf(fmt, ap, UART_OUTPUT);
}
__attribute__((noinline)) VOID UartPrintf(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
OsVprintf(fmt, ap, UART_OUTPUT);
va_end(ap);
}
__attribute__ ((noinline)) VOID dprintf(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
va_end(ap);
}
VOID LkDprintf(const CHAR *fmt, va_list ap)
{
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
}
#ifdef LOSCFG_SHELL_DMESG
VOID DmesgPrintf(const CHAR *fmt, va_list ap)
{
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
}
#endif
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
__attribute__ ((noinline)) INT32 printf(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
OsVprintf(fmt, ap, UART_OUTPUT);
va_end(ap);
return 0;
}
#endif
__attribute__((noinline)) VOID syslog(INT32 level, const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
va_end(ap);
(VOID)level;
}
__attribute__((noinline)) VOID ExcPrintf(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
/* uart output without print-spinlock */
OsVprintf(fmt, ap, EXC_OUTPUT);
va_end(ap);
}
VOID PrintExcInfo(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
/* uart output without print-spinlock */
OsVprintf(fmt, ap, EXC_OUTPUT);
#ifdef LOSCFG_SHELL_EXCINFO
WriteExcBufVa(fmt, ap);
#endif
va_end(ap);
}
#ifndef LOSCFG_SHELL_LK
VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (level > PRINT_LEVEL) {
return;
}
if ((level != LOS_COMMON_LEVEL) && ((level > LOS_EMG_LEVEL) && (level <= LOS_TRACE_LEVEL))) {
dprintf("[%s]", g_logString[level]);
}
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
va_end(ap);
}
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

504
kernel/common/los_rootfs.c Executable file
View File

@@ -0,0 +1,504 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_base.h"
#include "los_typedef.h"
#include "string.h"
#ifdef LOSCFG_PLATFORM_HI3518EV300
#include "mtd_partition.h"
#endif
#ifdef LOSCFG_DRIVERS_MMC
#include "mmc/block.h"
#include "disk.h"
#include "ff.h"
#endif
#include "sys/mount.h"
#include "inode/inode.h"
#ifdef LOSCFG_PLATFORM_ROOTFS
#include "los_rootfs.h"
#endif
#include "mtd_list.h"
#ifdef LOSCFG_PLATFORM_HI3518EV300
#define DEV_STORAGE_PATH "/dev/spinorblk2"
#define SECOND_MTD_PART_NUM 2
#define STORAGE_SIZE 0x100000
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_PLATFORM_HI3516DV300
#define STORAGE_SIZE 0x3200000
STATIC los_disk *g_emmcDisk = NULL;
#endif
#ifndef LOSCFG_SECURITY_BOOT
STATIC INT32 g_alignSize = 0;
#endif
#define VFAT_STORAGE_MOUNT_DIR_MODE 777
#define DEFAULT_STORAGE_MOUNT_DIR_MODE 755
#ifdef LOSCFG_DRIVERS_MMC
los_disk *GetMmcDisk(UINT8 type)
{
const CHAR *mmcDevHead = "/dev/mmcblk";
for (INT32 diskId = 0; diskId < SYS_MAX_DISK; diskId++) {
los_disk *disk = get_disk(diskId);
if (disk == NULL) {
continue;
} else if (disk->disk_name == NULL) {
continue;
} else if (strncmp(disk->disk_name, mmcDevHead, strlen(mmcDevHead))) {
continue;
} else {
if (disk->type == type) {
return disk;
}
}
}
PRINT_ERR("Cannot find the mmc disk!\n");
return NULL;
}
#endif
#ifdef LOSCFG_PLATFORM_HI3516DV300
STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize)
{
INT32 ret;
struct mmc_block *block = g_emmcDisk->dev->i_private;
const char *node_name = mmc_block_get_node_name(block);
if (los_disk_deinit(g_emmcDisk->disk_id) != ENOERR) {
PRINT_ERR("Failed to deinit emmc disk!\n");
return NULL;
}
struct disk_divide_info *emmc = get_emmc();
ret = add_mmc_partition(emmc, rootAddr / EMMC_SEC_SIZE, rootSize / EMMC_SEC_SIZE);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add mmc root partition!\n");
return NULL;
} else {
UINT64 storageStartCnt = (rootAddr + rootSize) / EMMC_SEC_SIZE;
UINT64 storageSizeCnt = STORAGE_SIZE / EMMC_SEC_SIZE;
UINT64 userdataStartCnt = storageStartCnt + storageSizeCnt;
UINT64 userdataSizeCnt = g_emmcDisk->sector_count - userdataStartCnt;
ret = add_mmc_partition(emmc, storageStartCnt, storageSizeCnt);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add mmc storage partition!\n");
}
ret = add_mmc_partition(emmc, userdataStartCnt, userdataSizeCnt);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add mmc userdata partition!\n");
}
LOS_Msleep(10); /* waiting for device identification */
INT32 diskId = los_alloc_diskid_byname(node_name);
if (diskId < 0) {
PRINT_ERR("Failed to alloc disk %s!\n", node_name);
return NULL;
}
if (los_disk_init(node_name, mmc_block_get_bops(block), (void *)block, diskId, emmc) != ENOERR) {
PRINT_ERR("Failed to init emmc disk!\n");
return NULL;
}
return node_name;
}
}
#endif
STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSize)
{
const CHAR *rootDev = NULL;
#ifdef LOSCFG_PLATFORM_HI3518EV300
INT32 ret;
if (strcmp(rootType, "flash") == 0) {
ret = add_mtd_partition(FLASH_TYPE, rootAddr, rootSize, 0);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add spinor root partition!\n");
} else {
rootDev = FLASH_DEV_NAME;
ret = add_mtd_partition(FLASH_TYPE, (rootAddr + rootSize), STORAGE_SIZE, SECOND_MTD_PART_NUM);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add spinor storage partition!\n");
}
}
} else
#endif
#ifdef LOSCFG_DRIVERS_USB_MASS_STORAGE
if (strcmp(rootType, "usb") == 0) {
rootDev = "/dev/sda";
} else
#endif
#ifdef LOSCFG_DRIVERS_SD
if (strcmp(rootType, "sdcard") == 0) {
los_disk *sdDisk = GetMmcDisk(OTHERS);
if (sdDisk == NULL) {
PRINT_ERR("Get sdcard failed!\n");
} else {
rootDev = sdDisk->disk_name;
}
} else
#endif
#ifdef LOSCFG_PLATFORM_HI3516DV300
if (strcmp(rootType, "emmc") == 0) {
rootDev = AddEmmcRootfsPart(rootAddr, rootSize);
} else
#endif
{
PRINT_ERR("Failed to find root dev type: %s\n", rootType);
}
return rootDev;
}
#ifndef LOSCFG_SECURITY_BOOT
STATIC INT32 GetArgs(CHAR **args)
{
INT32 ret;
INT32 i;
INT32 len = 0;
CHAR *cmdLine = NULL;
CHAR *tmp = NULL;
const CHAR *bootargName = "bootargs=";
cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
if (cmdLine == NULL) {
PRINT_ERR("Malloc cmdLine space error!\n");
return LOS_NOK;
}
#ifdef LOSCFG_PLATFORM_HI3516DV300
g_emmcDisk = GetMmcDisk(EMMC);
if (g_emmcDisk == NULL) {
PRINT_ERR("Get EMMC disk failed!\n");
goto ERROUT;
}
ret = los_disk_read(g_emmcDisk->disk_id, cmdLine, COMMAND_LINE_ADDR / EMMC_SEC_SIZE,
COMMAND_LINE_SIZE / EMMC_SEC_SIZE);
if (ret != 0) {
PRINT_ERR("Read EMMC command line failed!\n");
goto ERROUT;
}
g_alignSize = EMMC_SEC_SIZE;
#endif
#ifdef LOSCFG_PLATFORM_HI3518EV300
struct MtdDev *mtd = GetMtd(FLASH_TYPE);
if (mtd == NULL) {
PRINT_ERR("Get spinor mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, cmdLine);
if (ret != COMMAND_LINE_SIZE) {
PRINT_ERR("Read spinor command line failed!\n");
goto ERROUT;
}
#endif
for (i = 0; i < COMMAND_LINE_SIZE; i += len + 1) {
len = strlen(cmdLine + i);
tmp = strstr(cmdLine + i, bootargName);
if (tmp != NULL) {
*args = strdup(tmp + strlen(bootargName));
if (*args == NULL) {
goto ERROUT;
}
free(cmdLine);
return LOS_OK;
}
}
PRINT_ERR("Cannot find bootargs!\n");
ERROUT:
free(cmdLine);
return LOS_NOK;
}
STATIC INT32 MatchRootPos(CHAR *p, const CHAR *rootInfoName, INT32 *rootInfo)
{
UINT32 offset;
CHAR *value = NULL;
if (strncmp(p, rootInfoName, strlen(rootInfoName)) == 0) {
value = p + strlen(rootInfoName);
offset = strspn(value, DEC_NUMBER_STRING);
if (strcmp(p + strlen(p) - 1, "M") == 0) {
if ((offset < (strlen(value) - 1)) || (sscanf_s(value, "%d", rootInfo) <= 0)) {
goto ERROUT;
}
*rootInfo = *rootInfo * BYTES_PER_MBYTE;
} else if (strcmp(p + strlen(p) - 1, "K") == 0) {
if ((offset < (strlen(value) - 1)) || (sscanf_s(value, "%d", rootInfo) <= 0)) {
goto ERROUT;
}
*rootInfo = *rootInfo * BYTES_PER_KBYTE;
} else if (sscanf_s(value, "0x%x", rootInfo) > 0) {
value += strlen("0x");
if (strspn(value, HEX_NUMBER_STRING) < strlen(value)) {
goto ERROUT;
}
} else {
goto ERROUT;
}
}
if ((*rootInfo >= 0) && (g_alignSize != 0) && ((UINT32)(*rootInfo) & (UINT32)(g_alignSize - 1))) {
PRINT_ERR("The bootarg \"%s\" will be 0x%x aligned!\n", p, g_alignSize);
}
return LOS_OK;
ERROUT:
PRINT_ERR("Invalid bootarg \"%s\"!\n", p);
return LOS_NOK;
}
STATIC INT32 MatchRootInfo(CHAR *p, CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize)
{
const CHAR *rootName = "root=";
const CHAR *fsName = "fstype=";
const CHAR *rootAddrName = "rootaddr=";
const CHAR *rootSizeName = "rootsize=";
if ((*rootType == NULL) && (strncmp(p, rootName, strlen(rootName)) == 0)) {
*rootType = strdup(p + strlen(rootName));
if (*rootType == NULL) {
return LOS_NOK;
}
return LOS_OK;
}
if ((*fsType == NULL) && (strncmp(p, fsName, strlen(fsName)) == 0)) {
*fsType = strdup(p + strlen(fsName));
if (*fsType == NULL) {
return LOS_NOK;
}
return LOS_OK;
}
if (*rootAddr < 0) {
if (MatchRootPos(p, rootAddrName, rootAddr) != LOS_OK) {
return LOS_NOK;
} else if (*rootAddr >= 0) {
return LOS_OK;
}
}
if (*rootSize < 0) {
if (MatchRootPos(p, rootSizeName, rootSize) != LOS_OK) {
return LOS_NOK;
}
}
return LOS_OK;
}
STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize)
{
CHAR *args = NULL;
CHAR *argsBak = NULL;
CHAR *p = NULL;
if (GetArgs(&args) != LOS_OK) {
PRINT_ERR("Cannot get bootargs!\n");
return LOS_NOK;
}
argsBak = args;
p = strsep(&args, " ");
while (p != NULL) {
if (MatchRootInfo(p, rootType, fsType, rootAddr, rootSize) != LOS_OK) {
goto ERROUT;
}
p = strsep(&args, " ");
}
if ((*fsType != NULL) && (*rootType != NULL)) {
free(argsBak);
return LOS_OK;
}
ERROUT:
PRINT_ERR("Invalid rootfs information!\n");
if (*rootType != NULL) {
free(*rootType);
*rootType = NULL;
}
if (*fsType != NULL) {
free(*fsType);
*fsType = NULL;
}
free(argsBak);
return LOS_NOK;
}
#endif
#ifdef LOSCFG_PLATFORM_HI3516DV300
STATIC VOID OsMountUserdata(const CHAR *fsType)
{
INT32 ret;
INT32 err;
const CHAR *userdataDir = "/userdata";
ret = mkdir(userdataDir, VFAT_STORAGE_MOUNT_DIR_MODE);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to reserve inode /userdata, errno %d: %s\n", err, strerror(err));
return;
}
CHAR emmcUserdataDev[DISK_NAME] = {0};
if (snprintf_s(emmcUserdataDev, sizeof(emmcUserdataDev), sizeof(emmcUserdataDev) - 1,
"%s%s", g_emmcDisk->disk_name, "p2") < 0) {
PRINT_ERR("Failed to get emmc userdata dev name!\n");
return;
}
ret = mount(emmcUserdataDev, userdataDir, fsType, 0, "umask=000");
if (ret == LOS_OK) {
return;
}
err = get_errno();
if (err == ENOENT) {
ret = format(emmcUserdataDev, 0, FM_FAT32);
if (ret != LOS_OK) {
PRINT_ERR("Failed to format %s\n", emmcUserdataDev);
return;
}
ret = mount(emmcUserdataDev, userdataDir, fsType, 0, "umask=000");
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount /userdata, errno %d: %s\n", err, strerror(err));
}
} else {
PRINT_ERR("Failed to mount /userdata, errno %d: %s\n", err, strerror(err));
}
return;
}
#endif
STATIC INT32 OsMountRootfsAndUserfs(const CHAR *rootDev, const CHAR *fsType)
{
INT32 ret;
INT32 err;
if (strcmp(fsType, "vfat") == 0) {
ret = mount(rootDev, "/", fsType, MS_RDONLY, NULL);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount vfat rootfs, errno %d: %s\n", err, strerror(err));
return ret;
}
g_root_inode->i_mode |= S_IRWXU | S_IRWXG | S_IRWXO;
#ifdef LOSCFG_PLATFORM_HI3516DV300
ret = mkdir("/storage", VFAT_STORAGE_MOUNT_DIR_MODE);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to reserve inode /storage, errno %d: %s\n", err, strerror(err));
} else {
CHAR emmcStorageDev[DISK_NAME] = {0};
if (snprintf_s(emmcStorageDev, sizeof(emmcStorageDev), sizeof(emmcStorageDev) - 1,
"%s%s", g_emmcDisk->disk_name, "p1") < 0) {
PRINT_ERR("Failed to get emmc storage dev name!\n");
} else {
ret = mount(emmcStorageDev, "/storage", fsType, 0, "umask=000");
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount /storage, errno %d: %s\n", err, strerror(err));
}
}
}
OsMountUserdata(fsType);
#endif
} else {
ret = mount(rootDev, "/", fsType, MS_RDONLY, NULL);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount rootfs, errno %d: %s\n", err, strerror(err));
return ret;
}
#ifdef LOSCFG_PLATFORM_HI3518EV300
ret = mkdir("/storage", DEFAULT_STORAGE_MOUNT_DIR_MODE);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to reserve inode /storage, errno %d: %s\n", err, strerror(err));
} else {
ret = mount(DEV_STORAGE_PATH, "/storage", fsType, 0, NULL);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount /storage, errno %d: %s\n", err, strerror(err));
}
}
#endif
}
return LOS_OK;
}
INT32 OsMountRootfs(VOID)
{
INT32 ret = LOS_OK;
INT32 err;
INT32 rootAddr = -1;
INT32 rootSize = -1;
CHAR *rootType = NULL;
CHAR *fsType = NULL;
const CHAR *rootDev = NULL;
#ifdef LOSCFG_SECURITY_BOOT
rootType = strdup(ROOTFS_ROOT_TYPE);
fsType = strdup(ROOTFS_FS_TYPE);
rootAddr = ROOTFS_FLASH_ADDR;
rootSize = ROOTFS_FLASH_SIZE;
#else
ret = GetRootType(&rootType, &fsType, &rootAddr, &rootSize);
if (ret != LOS_OK) {
return ret;
}
rootAddr = (rootAddr >= 0) ? rootAddr : ROOTFS_FLASH_ADDR;
rootSize = (rootSize >= 0) ? rootSize : ROOTFS_FLASH_SIZE;
#endif
rootDev = GetDevName(rootType, rootAddr, rootSize);
if (rootDev != NULL) {
ret = OsMountRootfsAndUserfs(rootDev, fsType);
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount rootfs, errno %d: %s\n", err, strerror(err));
}
}
free(rootType);
free(fsType);
return ret;
}

69
kernel/common/los_rootfs.h Executable file
View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_ROOTFS_H
#define _LOS_ROOTFS_H
#define BYTES_PER_MBYTE 0x100000
#define BYTES_PER_KBYTE 0x400
#define COMMAND_LINE_ADDR 512 * BYTES_PER_KBYTE
#define COMMAND_LINE_SIZE 1024
#ifdef LOSCFG_PLATFORM_HI3518EV300
#define ROOTFS_ROOT_TYPE "flash"
#define ROOTFS_FS_TYPE "jffs2"
#endif
#ifdef LOSCFG_PLATFORM_HI3516DV300
#define ROOTFS_ROOT_TYPE "emmc"
#define ROOTFS_FS_TYPE "vfat"
#endif
#ifdef LOSCFG_TEE_ENABLE
#define ROOTFS_FLASH_ADDR 0x600000
#define ROOTFS_FLASH_SIZE 0x800000
#else
#define ROOTFS_FLASH_ADDR 0x400000
#define ROOTFS_FLASH_SIZE 0xa00000
#endif
#define FLASH_TYPE "spinor"
#define FLASH_DEV_NAME "/dev/spinorblk0"
#define EMMC_SEC_SIZE 512
#define DEC_NUMBER_STRING "0123456789"
#define HEX_NUMBER_STRING "0123456789abcdefABCDEF"
INT32 OsMountRootfs(VOID);
#endif /* _LOS_ROOTFS_H */

156
kernel/common/los_seq_buf.c Executable file
View File

@@ -0,0 +1,156 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "los_seq_buf.h"
#include <stdlib.h>
static int ExpandSeqBuf(struct SeqBuf *seqBuf, size_t oldCount)
{
char *newBuf = NULL;
int ret;
if ((seqBuf == NULL) || (seqBuf->buf == NULL)) {
return -LOS_NOK;
}
if (seqBuf->size >= SEQBUF_LIMIT_SIZE) {
goto EXPAND_FAILED;
}
newBuf = (char*)malloc(seqBuf->size <<= 1);
if (newBuf == NULL) {
goto EXPAND_FAILED;
}
(void)memset_s(newBuf + oldCount, seqBuf->size - oldCount, 0, seqBuf->size - oldCount);
ret = memcpy_s(newBuf, seqBuf->size, seqBuf->buf, oldCount);
if (ret != LOS_OK) {
free(newBuf);
goto EXPAND_FAILED;
}
seqBuf->count = oldCount;
free(seqBuf->buf);
seqBuf->buf = newBuf;
return LOS_OK;
EXPAND_FAILED:
free(seqBuf->buf);
seqBuf->buf = NULL;
seqBuf->count = 0;
seqBuf->size = 0;
return -LOS_NOK;
}
struct SeqBuf *LosBufCreat(void)
{
struct SeqBuf *seqBuf = NULL;
seqBuf = (struct SeqBuf *)malloc(sizeof(struct SeqBuf));
if (seqBuf == NULL) {
errno = -LOS_ENOMEM;
return NULL;
}
(void)memset_s(seqBuf, sizeof(struct SeqBuf), 0, sizeof(struct SeqBuf));
return seqBuf;
}
int LosBufVprintf(struct SeqBuf *seqBuf, const char *fmt, va_list argList)
{
bool needreprintf = FALSE;
int bufLen;
if (seqBuf == NULL) {
return -LOS_EPERM;
}
if (seqBuf->buf == NULL) {
seqBuf->size = SEQBUF_PAGE_SIZE;
seqBuf->buf = (char *)malloc(seqBuf->size);
if (seqBuf->buf == NULL) {
return -LOS_ENOMEM;
}
(void)memset_s(seqBuf->buf, seqBuf->size, 0, seqBuf->size);
seqBuf->count = 0;
}
do {
bufLen = vsnprintf_s(seqBuf->buf + seqBuf->count, seqBuf->size - seqBuf->count,
seqBuf->size - seqBuf->count - 1, fmt, argList);
if (bufLen >= 0) {
/* succeed write. */
seqBuf->count += bufLen;
return 0;
}
if (seqBuf->buf[seqBuf->count] == '\0') {
free(seqBuf->buf);
seqBuf->buf = NULL;
break;
}
needreprintf = TRUE;
if (ExpandSeqBuf(seqBuf, seqBuf->count) != 0) {
break;
}
} while (needreprintf);
return -LOS_NOK;
}
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt, ...)
{
va_list argList;
int ret;
va_start(argList, fmt);
ret = LosBufVprintf(seqBuf, fmt, argList);
va_end(argList);
return ret;
}
int LosBufRelease(struct SeqBuf *seqBuf)
{
if (seqBuf == NULL) {
return -LOS_EPERM;
}
if (seqBuf->buf != NULL) {
free(seqBuf->buf);
seqBuf->buf = NULL;
}
free(seqBuf);
return LOS_OK;
}

65
kernel/common/los_seq_buf.h Executable file
View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef __LOS_SEQ_BUF_H__
#define __LOS_SEQ_BUF_H__
#include "los_typedef.h"
#include "pthread.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SEQBUF_PAGE_SIZE 4096
#define SEQBUF_LIMIT_SIZE (256 * SEQBUF_PAGE_SIZE)
struct SeqBuf {
char *buf;
size_t size;
size_t count;
void *private;
};
struct SeqBuf *LosBufCreat(void);
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt, ...);
int LosBufVprintf(struct SeqBuf *seqBuf, const char *fmt, va_list argList);
int LosBufRelease(struct SeqBuf *seqBuf);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

50
kernel/common/los_timer_pri.h Executable file
View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _LOS_TIMER_PRI_H
#define _LOS_TIMER_PRI_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern VOID OsAdjTime(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_TIMER_PRI_H */

70
kernel/common/sys_config.h Executable file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _SYS_CONFIG_H
#define _SYS_CONFIG_H
#include "menuconfig.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef LOSCFG_MACRO_CONFIG
#define LOSCFG_MACRO_CONFIG
#ifdef LOSCFG_LIB_LIBC
#define CONFIG_STRERROR
#endif
#ifdef LOSCFG_NET_LWIP_SACK
#define LWIP_BSD_API 1
#endif
#ifdef LOSCFG_DEBUG_VERSION
#define LOSCFG_MEM_WATERLINE
#endif
#ifdef LOSCFG_DRIVERS_USB
#define SUPPORT_LOS_USB_NEW_DRIVER
#define USB_DEBUG_VAR 5
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _SYS_CONFIG_H */

316
kernel/common/virtual_serial.c Executable file
View File

@@ -0,0 +1,316 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#include "virtual_serial.h"
#include "fcntl.h"
#ifdef LOSCFG_FILE_MODE
#include "stdarg.h"
#endif
#ifdef LOSCFG_FS_VFS
#include "inode/inode.h"
#include "console.h"
#endif
#include "uart.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
STATIC volatile UINT32 g_serialType = 0;
STATIC struct file g_serialFilep;
UINT32 SerialTypeGet(VOID)
{
return g_serialType;
}
STATIC VOID SerialTypeSet(const CHAR *deviceName)
{
if (!strncmp(deviceName, SERIAL_UARTDEV, strlen(SERIAL_UARTDEV))) {
g_serialType = SERIAL_TYPE_UART_DEV;
} else if (!strncmp(deviceName, SERIAL_TTYGS0, strlen(SERIAL_TTYGS0))) {
g_serialType = SERIAL_TYPE_USBTTY_DEV;
}
}
STATIC INT32 SerialOpen(struct file *filep)
{
INT32 ret;
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
ret = EINVAL;
goto ERROUT;
}
ret = FilepOpen(privFilep, fileOps);
if (ret < 0) {
ret = EPERM;
goto ERROUT;
}
if (g_serialType == SERIAL_TYPE_UART_DEV) {
HalIrqUnmask(NUM_HAL_INTERRUPT_UART);
}
return ENOERR;
ERROUT:
set_errno(ret);
return VFS_ERROR;
}
STATIC INT32 SerialClose(struct file *filep)
{
(VOID)filep;
if (g_serialType == SERIAL_TYPE_UART_DEV) {
HalIrqMask(NUM_HAL_INTERRUPT_UART);
}
#if defined(LOSCFG_DRIVERS_USB_SERIAL_GADGET) || defined(LOSCFG_DRIVERS_USB_ETH_SER_GADGET)
else if (g_serialType == SERIAL_TYPE_USBTTY_DEV) {
userial_mask_set(0);
}
#endif
return ENOERR;
}
STATIC ssize_t SerialRead(struct file *filep, CHAR *buffer, size_t bufLen)
{
INT32 ret;
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
ret = -EINVAL;
goto ERROUT;
}
ret = FilepRead(privFilep, fileOps, buffer, bufLen);
if (ret < 0) {
goto ERROUT;
}
return ret;
ERROUT:
set_errno(-ret);
return VFS_ERROR;
}
/* Note: do not add print function in this module! */
STATIC ssize_t SerialWrite(FAR struct file *filep, FAR const CHAR *buffer, size_t bufLen)
{
INT32 ret;
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
ret = -EINVAL;
goto ERROUT;
}
ret = FilepWrite(privFilep, fileOps, buffer, bufLen);
if (ret < 0) {
goto ERROUT;
}
return ret;
ERROUT:
set_errno(-ret);
return VFS_ERROR;
}
STATIC INT32 SerialIoctl(struct file *filep, INT32 cmd, unsigned long arg)
{
INT32 ret;
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
ret = -EINVAL;
goto ERROUT;
}
ret = FilepIoctl(privFilep, fileOps, cmd, arg);
if (ret < 0) {
goto ERROUT;
}
return ret;
ERROUT:
set_errno(-ret);
return VFS_ERROR;
}
STATIC INT32 SerialPoll(struct file *filep, poll_table *fds)
{
INT32 ret;
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
ret = -EINVAL;
goto ERROUT;
}
ret = FilepPoll(privFilep, fileOps, fds);
if (ret < 0) {
goto ERROUT;
}
return ret;
ERROUT:
set_errno(-ret);
return VFS_ERROR;
}
STATIC const struct file_operations_vfs g_serialDevOps = {
SerialOpen, /* open */
SerialClose, /* close */
SerialRead, /* read */
SerialWrite,
NULL,
SerialIoctl,
NULL,
#ifndef CONFIG_DISABLE_POLL
SerialPoll,
#endif
NULL,
};
INT32 virtual_serial_init(const CHAR *deviceName)
{
INT32 ret;
CHAR *fullpath = NULL;
struct inode *inode = NULL;
struct inode_search_s desc;
if (deviceName == NULL) {
ret = EINVAL;
goto ERROUT;
}
SerialTypeSet(deviceName);
ret = vfs_normalize_path(NULL, deviceName, &fullpath);
if (ret < 0) {
ret = EINVAL;
goto ERROUT;
}
SETUP_SEARCH(&desc, fullpath, false);
ret = inode_find(&desc);
if (ret < 0) {
ret = EACCES;
goto ERROUT_WITH_FULLPATH;
}
inode = desc.node;
(VOID)memset_s(&g_serialFilep, sizeof(struct file), 0, sizeof(struct file));
g_serialFilep.f_oflags = O_RDWR;
g_serialFilep.f_inode = inode;
if (inode->u.i_ops->open != NULL) {
(VOID)inode->u.i_ops->open(&g_serialFilep);
} else {
ret = EFAULT;
inode_release(inode);
goto ERROUT_WITH_FULLPATH;
}
(VOID)register_driver(SERIAL, &g_serialDevOps, DEFFILEMODE, &g_serialFilep);
inode_release(inode);
free(fullpath);
return ENOERR;
ERROUT_WITH_FULLPATH:
free(fullpath);
ERROUT:
set_errno(ret);
return VFS_ERROR;
}
INT32 virtual_serial_deinit(VOID)
{
INT32 ret;
struct file *filep = NULL;
struct inode *inode = NULL;
CHAR *fullpath = NULL;
struct inode_search_s desc;
/* It's a process opposite virtual_serial_init */
ret = vfs_normalize_path(NULL, SERIAL, &fullpath);
if (ret < 0) {
ret = EINVAL;
goto ERROUT;
}
SETUP_SEARCH(&desc, fullpath, false);
ret = inode_find(&desc);
if (ret < 0) {
ret = EACCES;
goto ERROUT_WITH_FULLPATH;
}
inode = desc.node;
filep = inode->i_private;
if ((filep != NULL) && (inode->u.i_ops != NULL)) {
(VOID)inode->u.i_ops->close(filep); /* close filep */
inode->i_private = NULL;
} else {
ret = EBADF;
goto ERROUT_WITH_INODE;
}
inode_release(inode);
free(fullpath);
(VOID)unregister_driver(SERIAL);
return ENOERR;
ERROUT_WITH_INODE:
inode_release(inode);
ERROUT_WITH_FULLPATH:
free(fullpath);
ERROUT:
set_errno(ret);
return VFS_ERROR;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

75
kernel/common/virtual_serial.h Executable file
View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
#ifndef _VIRTUAL_SERIAL_H
#define _VIRTUAL_SERIAL_H
#include "los_config.h"
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#endif
#if defined(LOSCFG_DRIVERS_USB_SERIAL_GADGET) || defined(LOSCFG_DRIVERS_USB_ETH_SER_GADGET)
#include "implementation/usb_api_pri.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_FS_VFS
#define SERIAL "/dev/serial"
#define SERIAL_TTYGS0 "/dev/ttyGS0"
#define SERIAL_UARTDEV "/dev/uartdev"
#define SERIAL_TYPE_UART_DEV 1
#define SERIAL_TYPE_USBTTY_DEV 2
extern INT32 virtual_serial_init(const CHAR *deviceName);
extern INT32 virtual_serial_deinit(VOID);
extern UINT32 SerialTypeGet(VOID);
typedef struct {
struct file *filep;
UINT32 mask;
} LOS_VIRSERIAL_CB;
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VIRTUAL_SERIAL_H */