feat: add support for gn build system

add BUILD.gn for all kernel modules

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I018446427bf64615f2596d47862b219659b58b34
This commit is contained in:
Caoruihong
2021-07-13 23:57:39 +08:00
parent 7b7d64cc87
commit a8805a65aa
114 changed files with 3993 additions and 125 deletions

48
kernel/common/BUILD.gn Normal file
View File

@@ -0,0 +1,48 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
group("common") {
deps = [
"blackbox",
"hidumper",
"patchfs",
"rootfs",
]
}
config("public") {
configs = [
"blackbox:public",
"hidumper:public",
"patchfs:public",
"rootfs:public",
]
}

View File

@@ -0,0 +1,47 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_BLACKBOX)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_blackbox_common.c",
"los_blackbox_core.c",
"los_blackbox_detector.c",
"los_blackbox_system_adapter.c",
]
include_dirs = [ "$LITEOSTOPDIR/syscall" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,147 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 0x400
#define CONSOLE_NUM 2
#define CONSOLE_CIRCBUF_SIZE 0x400
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 consoleMask;
struct Vnode *devVnode;
CHAR *name;
INT32 fd;
UINT32 refCount;
UINT32 shellEntryId;
INT32 pgrpId;
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);
#ifdef LOSCFG_KERNEL_SMP
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
extern VOID OsWakeConsoleSendTask(VOID);
#endif
extern VOID KillPgrp(VOID);
/* 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 */

View File

@@ -0,0 +1,41 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_HIDUMPER)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_hidumper.c" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -1,118 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "shcmd.h"
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
STATIC CPUP_INFO_S hwiCpupAll[OS_HWI_MAX_NUM];
STATIC CPUP_INFO_S hwiCpup10s[OS_HWI_MAX_NUM];
STATIC CPUP_INFO_S hwiCpup1s[OS_HWI_MAX_NUM];
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i;
UINT64 cycles;
size_t size = sizeof(CPUP_INFO_S) * OS_HWI_MAX_NUM;
OsIrqCpupCB *irqCpup = OsGetIrqCpupArrayBase();
(VOID)argv;
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
if (irqCpup == NULL) {
return OS_ERROR;
}
(VOID)LOS_GetAllIrqCpuUsage(CPUP_ALL_TIME, hwiCpupAll, size);
(VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_TEN_SECONDS, hwiCpup10s, size);
(VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_ONE_SECONDS, hwiCpup1s, size);
PRINTK(" InterruptNo Count ATime(us) CPUUSE CPUUSE10s CPUUSE1s Mode Name\n");
for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
UINT32 count = OsGetHwiFormCnt(i);
if (count) {
cycles = (((OsIrqCpupCB *)(&irqCpup[i]))->cpup.allTime * OS_NS_PER_CYCLE) / (count * OS_SYS_NS_PER_US);
} else {
cycles = 0;
}
/* Different cores has different hwi form implementation */
if (HWI_IS_REGISTED(i)) {
PRINTK(" %10d:%11u%11llu", i, count, cycles);
} else {
continue;
}
PRINTK("%6u.%-2u%8u.%-2u%7u.%-2u%7s %-12s\n",
hwiCpupAll[i].usage / LOS_CPUP_PRECISION_MULT,
hwiCpupAll[i].usage % LOS_CPUP_PRECISION_MULT,
hwiCpup10s[i].usage / LOS_CPUP_PRECISION_MULT,
hwiCpup10s[i].usage % LOS_CPUP_PRECISION_MULT,
hwiCpup1s[i].usage / LOS_CPUP_PRECISION_MULT,
hwiCpup1s[i].usage % LOS_CPUP_PRECISION_MULT,
(g_hwiForm[i].uwParam == IRQF_SHARED) ? "shared" : "normal",
(OsGetHwiFormName(i) != NULL) ? OsGetHwiFormName(i) : "");
}
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);
#endif /* LOSCFG_SHELL */

View File

@@ -1,105 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 */

View File

@@ -1,215 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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"
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));
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 */

View File

@@ -1,325 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "stdio.h"
#include "string.h"
#include "gic_common.h"
#include "los_atomic.h"
#include "los_exc_pri.h"
#include "los_hwi_pri.h"
#include "los_hw_tick_pri.h"
#include "los_init_pri.h"
#include "los_memory_pri.h"
#include "los_mp.h"
#include "los_mux_pri.h"
#include "los_printf.h"
#include "los_process_pri.h"
#include "los_queue_pri.h"
#include "los_sem_pri.h"
#include "los_spinlock.h"
#include "los_swtmr_pri.h"
#include "los_task_pri.h"
#include "los_tick.h"
#include "los_vm_boot.h"
STATIC SystemRebootFunc g_rebootHook = NULL;
VOID OsSetRebootHook(SystemRebootFunc func)
{
g_rebootHook = func;
}
SystemRebootFunc OsGetRebootHook(VOID)
{
return g_rebootHook;
}
extern UINT32 OsSystemInit(VOID);
extern VOID SystemInit(VOID);
#ifdef LOSCFG_KERNEL_SMP
extern VOID release_secondary_cores(VOID);
#endif
LITE_OS_SEC_TEXT_INIT STATIC UINT32 EarliestInit(VOID)
{
/* Must be placed at the beginning of the boot process */
OsSetMainTask();
OsCurrTaskSet(OsGetMainTask());
g_sysClock = OS_SYS_CLOCK;
g_tickPerSecond = LOSCFG_BASE_CORE_TICK_PER_SECOND;
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 ArchEarlyInit(VOID)
{
UINT32 ret;
/* set system counter freq */
#ifndef LOSCFG_TEE_ENABLE
HalClockFreqWrite(OS_SYS_CLOCK);
#endif
#ifdef LOSCFG_PLATFORM_HWI
OsHwiInit();
#endif
OsExcInit();
ret = OsTickInit(g_sysClock, LOSCFG_BASE_CORE_TICK_PER_SECOND);
if (ret != LOS_OK) {
PRINT_ERR("OsTickInit error!\n");
return ret;
}
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 PlatformEarlyInit(VOID)
{
#if defined(LOSCFG_PLATFORM_UART_WITHOUT_VFS) && defined(LOSCFG_DRIVERS)
uart_init();
#endif /* LOSCFG_PLATFORM_UART_WITHOUT_VFS */
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsIpcInit(VOID)
{
UINT32 ret;
#ifdef LOSCFG_BASE_IPC_SEM
ret = OsSemInit();
if (ret != LOS_OK) {
PRINT_ERR("OsSemInit error\n");
return ret;
}
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
ret = OsQueueInit();
if (ret != LOS_OK) {
PRINT_ERR("OsQueueInit error\n");
return ret;
}
#endif
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 ArchInit(VOID)
{
#ifdef LOSCFG_KERNEL_MMU
OsArchMmuInitPerCPU();
#endif
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 PlatformInit(VOID)
{
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 KModInit(VOID)
{
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
OsSwtmrInit();
#endif
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT VOID OsSystemInfo(VOID)
{
#ifdef LOSCFG_DEBUG_VERSION
const CHAR *buildType = "debug";
#else
const CHAR *buildType = "release";
#endif /* LOSCFG_DEBUG_VERSION */
PRINT_RELEASE("\n******************Welcome******************\n\n"
"Processor : %s"
#ifdef LOSCFG_KERNEL_SMP
" * %d\n"
"Run Mode : SMP\n"
#else
"\n"
"Run Mode : UP\n"
#endif
"GIC Rev : %s\n"
"build time : %s %s\n"
"Kernel : %s %d.%d.%d.%d/%s\n"
"\n*******************************************\n",
LOS_CpuInfo(),
#ifdef LOSCFG_KERNEL_SMP
LOSCFG_KERNEL_SMP_CORE_NUM,
#endif
HalIrqVersion(), __DATE__, __TIME__,\
KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, buildType);
}
LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
{
UINT32 ret;
#ifdef LOS_INIT_STATISTICS
UINT64 startNsec, endNsec, durationUsec;
#endif
ret = EarliestInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_EARLIEST);
ret = ArchEarlyInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_ARCH_EARLY);
ret = PlatformEarlyInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_PLATFORM_EARLY);
/* system and chip info */
OsSystemInfo();
PRINT_RELEASE("\nmain core booting up...\n");
#ifdef LOS_INIT_STATISTICS
startNsec = LOS_CurrNanosec();
#endif
ret = OsTaskInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_KMOD_PREVM);
ret = OsSysMemInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_VM_COMPLETE);
ret = OsIpcInit();
if (ret != LOS_OK) {
return ret;
}
ret = OsSystemProcessCreate();
if (ret != LOS_OK) {
return ret;
}
ret = ArchInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_ARCH);
ret = PlatformInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_PLATFORM);
ret = KModInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_KMOD_BASIC);
OsInitCall(LOS_INIT_LEVEL_KMOD_EXTENDED);
#ifdef LOSCFG_KERNEL_SMP
release_secondary_cores();
#endif
OsInitCall(LOS_INIT_LEVEL_KMOD_TASK);
#ifdef LOS_INIT_STATISTICS
endNsec = LOS_CurrNanosec();
durationUsec = (endNsec - startNsec) / OS_SYS_NS_PER_US;
PRINTK("The main core takes %lluus to start.\n", durationUsec);
#endif
return LOS_OK;
}
#ifndef LOSCFG_PLATFORM_ADAPT
STATIC VOID SystemInit(VOID)
{
PRINTK("dummy: *** %s ***\n", __FUNCTION__);
}
#endif
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));
#ifndef LOSCFG_ENABLE_KERNEL_TEST
sysTask.pfnTaskEntry = (TSK_ENTRY_FUNC)SystemInit;
#else
extern void TestSystemInit(void);
sysTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TestSystemInit;
#endif
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;
#ifdef LOSCFG_KERNEL_SMP
sysTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
return LOS_TaskCreate(&taskID, &sysTask);
}
UINT32 OsSystemInit(VOID)
{
UINT32 ret;
ret = OsSystemInitTaskCreate();
if (ret != LOS_OK) {
return ret;
}
return 0;
}
LOS_MODULE_INIT(OsSystemInit, LOS_INIT_LEVEL_KMOD_TASK);

View File

@@ -1,461 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "los_tick.h"
#include "los_vm_zone.h"
#include "sys_config.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 1000 /* 1ms per tick */
#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 LOSCFG_BASE_CORE_TICK_PER_SECOND
/**
* @ingroup los_config
* External configuration item for timer tailoring
*/
#ifndef LOSCFG_BASE_CORE_TICK_HW_TIME
#undef LOSCFG_BASE_CORE_TICK_HW_TIME
#endif
/****************************** Hardware interrupt module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for hardware interrupt tailoring
*/
#ifndef LOSCFG_PLATFORM_HWI
#define LOSCFG_PLATFORM_HWI
#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.
*
* 0x800 bytes, aligned on a boundary of 8.
* 0x800 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 20000 /* 20ms */
#endif
/**
* @ingroup los_config
* Configuration item for task (stack) monitoring module tailoring
*/
#ifndef LOSCFG_BASE_CORE_TSK_MONITOR
#define LOSCFG_BASE_CORE_TSK_MONITOR
#endif
/****************************** Semaphore module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for semaphore module tailoring
*/
#ifndef LOSCFG_BASE_IPC_SEM
#define LOSCFG_BASE_IPC_SEM
#endif
/**
* @ingroup los_config
* Maximum supported number of semaphores
*/
#ifndef LOSCFG_BASE_IPC_SEM_LIMIT
#define LOSCFG_BASE_IPC_SEM_LIMIT 1024
#endif
/**
* @ingroup los_config
* Maximum number of semaphores.
*/
#ifndef OS_SEM_COUNT_MAX
#define OS_SEM_COUNT_MAX 0xFFFE
#endif
/****************************** Mutex module configuration ******************************/
/**
* @ingroup los_config
* Configuration item for mutex module tailoring
*/
#ifndef LOSCFG_BASE_IPC_MUX
#define LOSCFG_BASE_IPC_MUX
#endif
/****************************** Queue module configuration ********************************/
/**
* @ingroup los_config
* Configuration item for queue module tailoring
*/
#ifndef LOSCFG_BASE_IPC_QUEUE
#define LOSCFG_BASE_IPC_QUEUE
#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 **************************/
#ifdef LOSCFG_BASE_IPC_QUEUE
/**
* @ingroup los_config
* Configuration item for software timer module tailoring
*/
#ifndef LOSCFG_BASE_CORE_SWTMR_ENABLE
#define LOSCFG_BASE_CORE_SWTMR_ENABLE
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#define LOSCFG_BASE_CORE_SWTMR 1
#else
#define LOSCFG_BASE_CORE_SWTMR 0
#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 **************************/
/**
* @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) - (((UINTPTR)&__bss_end + (64 - 1)) & ~(64 - 1)))
#endif
/****************************** SMP module configuration **************************/
#ifdef LOSCFG_KERNEL_SMP
#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)
/**
* @ingroup los_trace
* It's the total size of trace buffer. It's in the unit of char
*/
#ifdef LOSCFG_KERNEL_TRACE
#define LOS_TRACE_BUFFER_SIZE (1024 * 512)
#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 37
#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)
/****************************** Exception information configuration ******************************/
#ifdef LOSCFG_SAVE_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 INT32 OsMain(VOID);
typedef VOID (*SystemRebootFunc)(VOID);
VOID OsSetRebootHook(SystemRebootFunc func);
SystemRebootFunc OsGetRebootHook(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CONFIG_H */

View File

@@ -1,198 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_SHELL
#include "shcmd.h"
#endif
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#include "fs/fs_operation.h"
#endif
#ifdef LOSCFG_SAVE_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
}
#ifdef LOSCFG_SHELL
INT32 OsShellCmdReadExcInfo(INT32 argc, CHAR **argv)
{
UINT32 recordSpace = GetRecordSpace();
(VOID)argc;
(VOID)argv;
CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1);
if (buf == NULL) {
return LOS_NOK;
}
(void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1);
log_read_write_fn hook = GetExcInfoRW();
if (hook != NULL) {
hook(GetRecordAddr(), recordSpace, 1, buf);
}
PRINTK("%s\n", buf);
(VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf);
buf = NULL;
return LOS_OK;
}
SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)OsShellCmdReadExcInfo);
#endif
#endif

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_SAVE_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 */

View File

@@ -1,339 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_init.h"
#include "los_mp.h"
#include "los_mux.h"
#include "los_process_pri.h"
#include "los_task_pri.h"
#include "fs/file.h"
#include "fs/driver.h"
#include "los_vm_map.h"
#include "los_vm_lock.h"
#include "user_copy.h"
#define HILOG_BUFFER 4096
#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(struct file *filep);
int HiLogClose(struct file *filep);
static ssize_t HiLogWrite(struct file *filep, const char *buffer, size_t bufLen);
static ssize_t HiLogRead(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 */
};
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(struct file *filep)
{
(void)filep;
return 0;
}
int HiLogClose(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)(UINTPTR)dst, minLen) &&
LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, minLen)) {
return retval;
}
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, minLen)) {
retval = LOS_ArchCopyToUser(dst, src, minLen);
} else if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)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(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);
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));
HiLogBufferDec(header.len);
}
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
{
struct HiLogEntry header;
int retval;
LosTaskCB *runTask = (LosTaskCB *)OsCurrTaskGet();
if ((g_hiLogDev.buffer == NULL) || (OS_INT_ACTIVE) || (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK)) {
PRINTK("%s\n", buffer);
return -EAGAIN;
}
(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(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 OsHiLogDriverInit(VOID)
{
HiLogDeviceInit();
return register_driver(HILOG_DRIVER, &g_hilogFops, DRIVER_MODE, NULL);
}
LOS_MODULE_INIT(OsHiLogDriverInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 OsHiLogDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -1,127 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_init_pri.h"
#include "los_atomic.h"
#include "los_config.h"
#include "los_hw.h"
#include "los_printf.h"
#include "los_spinlock.h"
#include "los_typedef.h"
#ifdef LOS_INIT_DEBUG
#include "los_sys_pri.h"
#include "los_tick.h"
#endif
/**
* Register kernel init level labels.
*/
OS_INIT_LEVEL_REG(kernel, 10, g_kernInitLevelList);
STATIC volatile UINT32 g_initCurrentLevel = OS_INVALID_VALUE;
STATIC volatile struct ModuleInitInfo *g_initCurrentModule = 0;
STATIC Atomic g_initCount = 0;
STATIC SPIN_LOCK_INIT(g_initLock);
/**
* It is recommended that each startup framework encapsulate a layer of its own calling interface.
*/
STATIC VOID InitLevelCall(const CHAR *name, const UINT32 level, struct ModuleInitInfo *initLevelList[])
{
struct ModuleInitInfo *module = NULL;
#ifdef LOS_INIT_DEBUG
UINT64 startNsec, endNsec;
UINT64 totalTime = 0;
UINT64 singleTime = 0;
UINT32 ret = LOS_OK;
#endif
if (ArchCurrCpuid() == 0) {
#ifdef LOS_INIT_DEBUG
PRINTK("-------- %s Module Init... level = %u --------\n", name, level);
#endif
g_initCurrentLevel = level;
g_initCurrentModule = initLevelList[level];
} else {
while (g_initCurrentLevel < level) {
}
}
do {
LOS_SpinLock(&g_initLock);
if (g_initCurrentModule >= initLevelList[level + 1]) {
LOS_SpinUnlock(&g_initLock);
break;
}
module = (struct ModuleInitInfo *)g_initCurrentModule;
g_initCurrentModule++;
LOS_SpinUnlock(&g_initLock);
if (module->hook != NULL) {
#ifdef LOS_INIT_DEBUG
ret = LOS_OK;
startNsec = LOS_CurrNanosec();
ret = (UINT32)module->hook();
endNsec = LOS_CurrNanosec();
singleTime = endNsec - startNsec;
totalTime += singleTime;
PRINTK("Starting %s module consumes %llu ns. Run on cpu %u\n", module->name, singleTime, ArchCurrCpuid());
#else
module->hook();
#endif
}
#ifdef LOS_INIT_DEBUG
if (ret != LOS_OK) {
PRINT_ERR("%s initialization failed at module %s, function addr at 0x%x, ret code is %u\n",
name, module->name, module->hook, ret);
}
#endif
} while (1);
if (level >= LOS_INIT_LEVEL_KMOD_TASK) {
LOS_AtomicInc(&g_initCount);
while ((LOS_AtomicRead(&g_initCount) % LOSCFG_KERNEL_CORE_NUM) != 0) {
}
}
#ifdef LOS_INIT_DEBUG
PRINTK("%s initialization at level %u consumes %lluns on cpu %u.\n", name, level, totalTime, ArchCurrCpuid());
#endif
}
VOID OsInitCall(const UINT32 level)
{
if (level >= LOS_INIT_LEVEL_FINISH) {
return;
}
InitLevelCall("Kernel", level, g_kernInitLevelList);
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_INIT_H
#define _LOS_INIT_H
#include "los_init_info.h"
/**
* Kernel Module Init Level
*/
#define LOS_INIT_LEVEL_EARLIEST 0
#define LOS_INIT_LEVEL_ARCH_EARLY 1
#define LOS_INIT_LEVEL_PLATFORM_EARLY 2
#define LOS_INIT_LEVEL_KMOD_PREVM 3
#define LOS_INIT_LEVEL_VM_COMPLETE 4
#define LOS_INIT_LEVEL_ARCH 5
#define LOS_INIT_LEVEL_PLATFORM 6
#define LOS_INIT_LEVEL_KMOD_BASIC 7
#define LOS_INIT_LEVEL_KMOD_EXTENDED 8
#define LOS_INIT_LEVEL_KMOD_TASK 9
#define LOS_INIT_LEVEL_FINISH 10
/**
* @ingroup los_init
* @brief Register a startup module to the startup process.
*
* @par Description:
* This API is used to register a startup module to the startup process.
*
* @attention
* <ul>
* <li>Register a new module in the boot process of the kernel as part of the kernel capability component.</li>
* <li>In the startup framework, within the same _level, the startup sequence is sorted by
* the registered function name </li>
* <li>If the registration is not accompanied by the startup process after calling this interface,
* try to add -u_hook to liteos_tables_ldflags.mk </li>
* </ul>
*
* @param _hook [IN] Type #UINT32 (*)(VOID) Register function.
* @param _level [IN] Type #UINT32 Init level in the kernel.
*
* @retval None
* @par Dependency:
* <ul><li>los_init.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_MODULE_INIT(_hook, _level) OS_INIT_HOOK_REG(kernel, _hook, _level)
#endif /* _LOS_INIT_H */

View File

@@ -1,169 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_INIT_INFO_H
#define _LOS_INIT_INFO_H
#include "stdalign.h"
#include "los_toolchain.h"
#include "los_typedef.h"
/**
* @ingroup los_init_info
* Macro LOS_INIT_DEBUG needs to be defined here, used to debug the init framework.
* #define LOS_INIT_DEBUG
*/
/**
* @ingroup los_init_info
* Macro LOS_INIT_STATISTICS needs to be defined here, used to count the kernel startup time.
* @attention
* <ul>
* <li> if uses, the macro LOS_INIT_DEBUG must be undefined. </li>
* </ul>
* #define LOS_INIT_STATISTICS
*/
#if defined(LOS_INIT_STATISTICS) && defined(LOS_INIT_DEBUG)
#error "LOS_INIT_STATISTICS needs LOS_INIT_DEBUG to be undefined"
#endif
#define INIT_SECTION(_type, _level, _hook) __attribute__((section(".rodata.init."#_type"."#_level"."#_hook)))
#define INIT_ALIGN __attribute__((aligned(alignof(struct ModuleInitInfo))))
typedef UINT32 (*OsInitHook)(VOID);
struct ModuleInitInfo {
OsInitHook hook;
#ifdef LOS_INIT_DEBUG
const CHAR *name;
#endif
};
#ifdef LOS_INIT_DEBUG
#define SET_MODULE_NAME(_hook) .name = #_hook,
#else
#define SET_MODULE_NAME(_hook)
#endif
/**
* @ingroup los_init_info
* @brief Add a registration module to the specified level in a startup framework.
*
* @par Description:
* This API is used to add a registration module to the specified level in a startup framework.
* @attention
* <ul>
* <li>It is not recommended to call directly, it is recommended that each startup framework
* encapsulate a layer of interface in los_init.h.</li>
* </ul>
*
* @param _type [IN] Type name of startup framework.
* @param _hook [IN] Register function.
* @param _level [IN] At which _level do you want to register.
*
* @retval None
* @par Dependency:
* <ul><li>los_task_info.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define OS_INIT_HOOK_REG(_type, _hook, _level) \
STATIC const struct ModuleInitInfo ModuleInitInfo_##_hook \
USED INIT_SECTION(_type, _level, _hook) INIT_ALIGN = { \
.hook = (UINT32 (*)(VOID))&_hook, \
SET_MODULE_NAME(_hook) \
};
#define EXTERN_LABEL(_type, _level) extern struct ModuleInitInfo __##_type##_init_level_##_level;
#define GET_LABEL(_type, _level) &__##_type##_init_level_##_level,
#define INIT_LABEL_REG_0(_op, _type) \
_op(_type, 0)
#define INIT_LABEL_REG_1(_op, _type) \
INIT_LABEL_REG_0(_op, _type) \
_op(_type, 1)
#define INIT_LABEL_REG_2(_op, _type) \
INIT_LABEL_REG_1(_op, _type) \
_op(_type, 2)
#define INIT_LABEL_REG_3(_op, _type) \
INIT_LABEL_REG_2(_op, _type) \
_op(_type, 3)
#define INIT_LABEL_REG_4(_op, _type) \
INIT_LABEL_REG_3(_op, _type) \
_op(_type, 4)
#define INIT_LABEL_REG_5(_op, _type) \
INIT_LABEL_REG_4(_op, _type) \
_op(_type, 5)
#define INIT_LABEL_REG_6(_op, _type) \
INIT_LABEL_REG_5(_op, _type) \
_op(_type, 6)
#define INIT_LABEL_REG_7(_op, _type) \
INIT_LABEL_REG_6(_op, _type) \
_op(_type, 7)
#define INIT_LABEL_REG_8(_op, _type) \
INIT_LABEL_REG_7(_op, _type) \
_op(_type, 8)
#define INIT_LABEL_REG_9(_op, _type) \
INIT_LABEL_REG_8(_op, _type) \
_op(_type, 9)
#define INIT_LABEL_REG_10(_op, _type) \
INIT_LABEL_REG_9(_op, _type) \
_op(_type, 10)
/**
* @ingroup los_init_info
* @brief Define a set of levels and initialize the labels of each level.
*
* @par Description:
* This API is used to define a set of levels and initialize the labels of each level.
* @attention
* <ul>
* <li>This interface is used to add a new startup framework.</li>
* <li>To use this interface, you need to add a corresponding section description in
* the liteos.ld and liteos_llvm.ld files to match </li>
* </ul>
*
* @param _type [IN] Type name of startup framework.
* @param _num [IN] The maximum effective level of the startup framework, the level range is [0, _num].
* @param _list [IN] Static global array, used to manage labels at all levels.
*
* @retval None
* @par Dependency:
* <ul><li>los_task_info.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define OS_INIT_LEVEL_REG(_type, _num, _list) \
INIT_LABEL_REG_##_num(EXTERN_LABEL, _type) \
STATIC struct ModuleInitInfo* _list [] = { \
INIT_LABEL_REG_##_num(GET_LABEL, _type) \
}
#endif /* _LOS_INIT_INFO_H */

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_INIT_PRI_H
#define _LOS_INIT_PRI_H
#include "los_init.h"
#include "los_typedef.h"
VOID OsInitCall(const UINT32 level);
#endif /* _LOS_INIT_PRI_H */

View File

@@ -1,155 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "console.h"
#include "los_task_pri.h"
#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 */
};
STATIC MagicKeyOp g_magicKillPgrp = {
.opHandler = KillPgrp,
.helpMsg = "Show all magic op key(ctrl+c) ",
.magicKey = 0x03 /* ctrl + c */
};
/*
* 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 */
&g_magicKillPgrp /* ctrl + c */
};
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;
} else if (key == 0x03) { /* ctrl + c */
KillPgrp();
return 0;
}
if (magicKeySwitch != 0) {
for (i = 0; i < MAGIC_KEY_NUM; i++) {
if (g_magicOpTable[i] != NULL && key == g_magicOpTable[i]->magicKey) {
(g_magicOpTable[i])->opHandler();
return 1;
}
}
}
#endif
return 0;
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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

View File

@@ -1,279 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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"
#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif
#ifdef LOSCFG_SHELL_DMESG
#include "dmesg_pri.h"
#endif
#ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h"
#endif
#include "los_exc_pri.h"
#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
}
#ifdef LOSCFG_PLATFORM_CONSOLE
STATIC VOID ConsoleOutput(const CHAR *str, UINT32 len)
{
ssize_t writen = 0;
ssize_t cnt;
ssize_t toWrite = len;
for (;;) {
cnt = write(STDOUT_FILENO, str + writen, (size_t)toWrite);
if ((cnt < 0) || (toWrite == cnt)) {
break;
}
writen += cnt;
toWrite -= cnt;
}
}
#endif
VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
{
switch (type) {
case CONSOLE_OUTPUT:
#ifdef LOSCFG_PLATFORM_CONSOLE
if (ConsoleEnable() == TRUE) {
ConsoleOutput(str, len);
break;
}
#endif
/* fall-through */
case UART_OUTPUT:
UartOutput(str, len, UART_WITH_LOCK);
break;
case EXC_OUTPUT:
UartPuts(str, len, UART_WITH_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_SAVE_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;
if (level > PRINT_LEVEL) {
return;
}
if ((level != LOS_COMMON_LEVEL) && ((level > LOS_EMG_LEVEL) && (level <= LOS_TRACE_LEVEL))) {
dprintf("[%s]", g_logString[level]);
}
va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
va_end(ap);
}
#endif

View File

@@ -1,156 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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;
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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

View File

@@ -1,50 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 */

View File

@@ -0,0 +1,44 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_PLATFORM_PATCHFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_partition_utils.c",
"los_patchfs.c",
]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,44 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_PLATFORM_ROOTFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_bootargs.c",
"los_rootfs.c",
]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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
#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_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 */

View File

@@ -1,256 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "console.h"
#include "fs/driver.h"
#endif
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(struct file *filep, 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;
struct Vnode *vnode = NULL;
if (deviceName == NULL) {
ret = EINVAL;
goto ERROUT;
}
SerialTypeSet(deviceName);
VnodeHold();
ret = VnodeLookup(deviceName, &vnode, V_DUMMY);
if (ret != LOS_OK) {
ret = EACCES;
goto ERROUT;
}
(VOID)memset_s(&g_serialFilep, sizeof(struct file), 0, sizeof(struct file));
g_serialFilep.f_oflags = O_RDWR;
g_serialFilep.f_vnode = vnode;
g_serialFilep.ops = ((struct drv_data *)vnode->data)->ops;
if (g_serialFilep.ops->open != NULL) {
(VOID)g_serialFilep.ops->open(&g_serialFilep);
} else {
ret = EFAULT;
PRINTK("virtual_serial_init %s open is NULL\n", deviceName);
goto ERROUT;
}
(VOID)register_driver(SERIAL, &g_serialDevOps, DEFFILEMODE, &g_serialFilep);
VnodeDrop();
return ENOERR;
ERROUT:
VnodeDrop();
set_errno(ret);
return VFS_ERROR;
}
INT32 virtual_serial_deinit(VOID)
{
return unregister_driver(SERIAL);
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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"
#include "fs/file.h"
#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 */