diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md
deleted file mode 100644
index f09d98dd..00000000
--- a/.gitee/ISSUE_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 该问题是怎么引起的?
-
-
-
-### 重现步骤
-
-
-
-### 报错信息
-
-
-
-
diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
deleted file mode 100644
index 33948fdc..00000000
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### 相关的Issue
-
-
-### 原因(目的、解决的问题等)
-
-
-### 描述(做了什么,变更了什么)
-
-
-### 测试用例(新增、改动、可能影响的功能)
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
index cf00b530..77dbb6a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
/out
-/fs/proc
/test
/include
.config*
@@ -22,4 +21,3 @@ platform/include/menuconfig.h
platform/board.ld
apps/init/init
apps/shell/shell
-lib/libc/musl
diff --git a/BUILD.gn b/BUILD.gn
old mode 100644
new mode 100755
index a7e30ac3..ad48b121
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1,68 +1,82 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import("//build/lite/config/subsystem/lite_subsystem.gni")
-
-declare_args() {
- enable_ohos_kernel_liteos_a_ext_build = true
- LOSCFG_TEST_APPS = false
-}
-
-lite_subsystem("kernel") {
- subsystem_components = []
-
- if (enable_ohos_kernel_liteos_a_ext_build == false) {
- subsystem_components += [
- "//kernel/liteos_a/kernel",
- "//kernel/liteos_a/net",
- "//kernel/liteos_a/lib",
- "//kernel/liteos_a/compat",
- "//kernel/liteos_a/fs",
- "//kernel/liteos_a/arch:platform_cpu",
- ]
- if (LOSCFG_SHELL) {
- subsystem_components += [ "//kernel/liteos_a/shell" ]
- }
- } else {
- deps = [":make"]
- }
-}
-
-action("make") {
- script = "//build/lite/build_ext_components.py"
- outputs = [ "$target_gen_dir/liteos_a_build_log.txt" ]
- exec_path = rebase_path(rebase_path(".", root_build_dir))
- outdir = rebase_path(get_path_info(".", "out_dir"))
- command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
- args = [
- "--path=$exec_path",
- "--prebuilts=sh build.sh ${board_name} ${ohos_build_compiler} ${ohos_build_type}",
- "--command=${command}"
- ]
-}
+# 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("//build/lite/config/component/lite_component.gni")
+import("//build/lite/config/subsystem/lite_subsystem.gni")
+
+generate_notice_file("kernel_notice_file") {
+ module_name = "kernel"
+ module_source_dir_list = [
+ "//third_party/FreeBSD",
+ "//third_party/musl",
+ "//third_party/zlib",
+ "//third_party/FatFs",
+ "//third_party/Linux_Kernel",
+ "//third_party/lwip",
+ "//third_party/NuttX",
+ "//third_party/mtd-utils",
+ ]
+}
+
+declare_args() {
+ enable_ohos_kernel_liteos_a_ext_build = true
+ LOSCFG_TEST_APPS = false
+ tee_enable = ""
+}
+
+lite_subsystem("kernel") {
+ subsystem_components = []
+
+ if (enable_ohos_kernel_liteos_a_ext_build == false) {
+ subsystem_components += [
+ "//kernel/liteos_a/kernel",
+ "//kernel/liteos_a/net",
+ "//kernel/liteos_a/lib",
+ "//kernel/liteos_a/compat",
+ "//kernel/liteos_a/fs",
+ "//kernel/liteos_a/arch:platform_cpu",
+ ]
+ if (LOSCFG_SHELL) {
+ subsystem_components += [ "//kernel/liteos_a/shell" ]
+ }
+ } else {
+ deps = [ ":make" ]
+ }
+}
+
+build_ext_component("make") {
+ exec_path = rebase_path(".", root_build_dir)
+ tee_enable = "false"
+ if (board_name == "hi3516dv300" && enable_tee_ree) {
+ tee_enable = "tee"
+ }
+ prebuilts = "sh build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} ${tee_enable} \"${device_company}\" \"${product_path}\""
+ outdir = rebase_path(get_path_info(".", "out_dir"))
+ command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
+}
diff --git a/Kconfig b/Kconfig
old mode 100644
new mode 100755
index a47e793f..77380a27
--- a/Kconfig
+++ b/Kconfig
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -61,6 +61,15 @@ source "../../kernel/liteos_a/arch/Kconfig"
######################### config options of rootfs #####################
source "../../kernel/liteos_a/kernel/common/Kconfig"
+######################### config options of patchfs #####################
+source "../../kernel/liteos_a/kernel/common/patchfs/Kconfig"
+
+config QUICK_START
+ bool "Enable QUICK_START"
+ default n
+ depends on DRIVERS && FS_VFS
+ help
+ Answer Y to enable LiteOS support quick start.
endmenu
######################### config options of kernel #####################
@@ -84,6 +93,12 @@ source "../../kernel/liteos_a/fs/ramfs/Kconfig"
source "../../kernel/liteos_a/fs/nfs/Kconfig"
source "../../kernel/liteos_a/fs/proc/Kconfig"
source "../../kernel/liteos_a/fs/jffs2/Kconfig"
+source "../../kernel/liteos_a/fs/zpfs/Kconfig"
+config ENABLE_READ_BUFFER
+ bool "Enable read buffer Option"
+ default n
+ help
+ Answer Y to add enable read buffer Option.
endmenu
######################## config options of net ############################
@@ -197,6 +212,13 @@ config EXC_INTERACTION
Answer Y to enable exception interaction for LiteOS, when the system enter exception, user can also interact with system by shell
command like readreg, writereg,task,hwi.
+config SCHED_DEBUG
+ bool "Enable sched debug Feature"
+ default n
+ depends on DEBUG_VERSION
+ help
+ If you wish to build LiteOS with support for sched debug.
+
config USER_INIT_DEBUG
bool "Enable user init Debug"
default n
@@ -221,30 +243,6 @@ config MEM_DEBUG
help
Answer Y to enable LiteOS support mem debug.
-config MEM_MUL_MODULE
- bool "Enable Memory module statistics"
- default n
- depends on MEM_DEBUG
- help
- Answer Y to enable LiteOS support memory statistics depend on different module
-config MEM_MUL_POOL
- bool "Enable Memory multi-pool control"
- default y
- depends on DEBUG_VERSION && MEM_DEBUG
- help
- Answer Y to enable LiteOS support memory multi-pool control
-config MEM_HEAD_BACKUP
- bool "Enable Node Head Backup"
- default 0
- depends on DEBUG_VERSION && MEM_DEBUG
- help
- Answer Y to enable node head backup
-config MEM_RECORDINFO
- bool "Enable Mem Record"
- default n
- depends on DEBUG_VERSION && MEM_DEBUG
- help
- Answer Y to enable mem record
config MEM_LEAKCHECK
bool "Enable Function call stack of Mem operation recorded"
default n
@@ -255,14 +253,10 @@ config BASE_MEM_NODE_INTEGRITY_CHECK
bool "Enable integrity check or not "
default n
depends on DEBUG_VERSION && MEM_DEBUG
-config BASE_MEM_NODE_SIZE_CHECK
- bool "Enable size check or not"
+config MEM_WATERLINE
+ bool "Enable memory pool waterline or not"
default n
depends on DEBUG_VERSION && MEM_DEBUG
-config SLAB_INFO_STATISTIC
- bool "Enable SLAB Statistic"
- default n
- depends on DEBUG_VERSION && KERNEL_MEM_SLAB && MEM_DEBUG
config VM_OVERLAP_CHECK
bool "Enable VM overlap check or not"
@@ -278,19 +272,6 @@ config NULL_ADDRESS_PROTECT
help
Answer Y to set mem address 0~1M prohibit to access, read or write will trigger exception.
-choice
- prompt "Enable Uart"
- default DRIVERS_HDF_PLATFORM_UART
- help
- Enable simple uart (without vfs) only for litekernel.
- Enable general uart (with vfs) for full code.
-source "../../vendor/hisi/hi35xx/platform/uart/Kconfig"
-config PLATFORM_UART_WITHOUT_VFS
- bool "Simple Uart"
-config PLATFORM_NO_UART
- bool "NO Uart"
-
-endchoice
endmenu
######################## config options os drivers ########################
@@ -301,42 +282,13 @@ config DRIVERS
help
Answer Y to enable LiteOS support driver.
-source "../../vendor/hisi/hi35xx/platform/hiedmac/Kconfig"
source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
-source "../../drivers/hdf/lite/Kconfig"
+source "../../drivers/adapter/khdf/liteos/Kconfig"
-config DRIVERS_NETDEV
- bool "Enable Net Device"
- default y
- depends on DRIVERS && NET_LWIP_SACK
- help
- Answer Y to enable LiteOS support net device.
-
-choice
- depends on DRIVERS_NETDEV
- prompt "MAC"
- default n
- help
- Enable higmac for hi3516a hi3519 hi3559a_cortex-a53_aarch64.
- Enable hieth-sf for hi3516cv300 hi3516ev200 and hi3518ev200.
-source "../../vendor/hisi/hi35xx/platform/hieth-sf/Kconfig"
-endchoice
-
-source "../../drivers/liteos/mem/Kconfig"
-source "../../vendor/hisi/hi35xx/platform/mmc/Kconfig"
-
-
-config DRIVERS_MTD
- bool "Enable MTD"
- default y
- depends on DRIVERS && FS_VFS
- help
- Answer Y to enable LiteOS support jffs2 multipartion.
-
-source "../../vendor/hisi/hi35xx/platform/mtd/spi_nor/Kconfig"
-source "../../drivers/liteos/random/Kconfig"
+source "drivers/char/mem/Kconfig"
+source "drivers/char/random/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
-source "../../drivers/liteos/video/Kconfig"
+source "drivers/char/video/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"
endmenu
diff --git a/LICENSE b/LICENSE
index 61fa69e3..208b4cd3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
-Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+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:
@@ -25,4 +25,4 @@ 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.
\ No newline at end of file
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
old mode 100644
new mode 100755
index b7f3d045..27dda5e6
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -38,8 +38,6 @@ LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party
export LITEOSTOPDIR
export LITEOSTHIRDPARTY
--include $(LITEOSTOPDIR)/tools/build/config.mk
-
RM = -rm -rf
MAKE = make
__LIBS = libs
@@ -53,14 +51,33 @@ LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
LITEOS_PLATFORM_MENUCONFIG_H = $(LITEOS_PLATFORM_BASE)/include/menuconfig.h
-ifeq ($(LOSCFG_PLATFORM_HI3518EV300), y)
+export CONFIG_=LOSCFG_
+MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
+KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
+
+ifeq ($(OS), Linux)
+MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/mconf
+MENUCONFIG_CONF := $(MENUCONFIG_PATH)/conf
+else
+MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/kconfig-mconf.exe
+MENUCONFIG_CONF := $(MENUCONFIG_PATH)/kconfig-conf.exe
+endif
+
+$(shell env CONFIG_=$(CONFIG_) $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH))
+
+-include $(LITEOSTOPDIR)/tools/build/config.mk
+
+ifeq ($(LOSCFG_STORAGE_SPINOR), y)
FSTYPE = jffs2
endif
-ifeq ($(LOSCFG_PLATFORM_HI3516DV300), y)
+ifeq ($(LOSCFG_STORAGE_EMMC), y)
FSTYPE = vfat
endif
+ifeq ($(LOSCFG_STORAGE_SPINAND), y)
+FSTYPE = yaffs2
+endif
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
-FSTYPE = vfat
+FSTYPE = jffs2
endif
ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip
@@ -100,21 +117,14 @@ endif
##### make dynload #####
-include $(LITEOS_MK_PATH)/dynload.mk
-ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
-VENDOR_BOARD_INCLUDE := $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board
-else ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
-VENDOR_BOARD_INCLUDE := $(LITEOSTOPDIR)/../../device/qemu/arm/$(LITEOS_PLATFORM)/config/board
-else
-$(error "No VENDOR_BOARD_INCLUDE defined")
-endif
#-----need move when make version-----#
##### make lib #####
$(__LIBS): $(OUT) $(CXX_INCLUDE)
$(OUT): $(LITEOS_MENUCONFIG_H)
$(HIDE)mkdir -p $(OUT)/lib
- $(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(VENDOR_BOARD_INCLUDE) \
- -E $(LITEOS_PLATFORM_BASE)/board.ld.S \
+ $(HIDE)$(CC) -I$(LITEOSTOPDIR)/kernel/base/include -I$(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) \
+ -I$(LITEOS_PLATFORM_BASE)/include -E $(LITEOS_PLATFORM_BASE)/board.ld.S \
-o $(LITEOS_PLATFORM_BASE)/board.ld -P
$(BUILD):
@@ -127,14 +137,10 @@ $(LITEOS_LIBS_TARGET): $(__LIBS)
$(HIDE)echo "=============== make lib done ==============="
##### make menuconfig #####
-export CONFIG_=LOSCFG_
-MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
-KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
-
-menuconfig:$(MENUCONFIG_PATH)/mconf
+menuconfig:$(MENUCONFIG_MCONF)
$< $(KCONFIG_FILE_PATH)
-genconfig:$(MENUCONFIG_PATH)/conf
+genconfig:$(MENUCONFIG_CONF)
$(HIDE)mkdir -p include/config include/generated
$< --olddefconfig $(KCONFIG_FILE_PATH)
$< --silentoldconfig $(KCONFIG_FILE_PATH)
@@ -185,6 +191,7 @@ $(ROOTFS): $(ROOTFSDIR)
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
ifneq ($(OUT), $(LITEOS_TARGET_DIR))
+ rm -rf $(LITEOS_TARGET_DIR)rootfs
$(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs
endif
@@ -193,7 +200,7 @@ clean:
do $(MAKE) -C $$dir clean|| exit 1; \
done
$(HIDE)$(MAKE) -C apps clean
- $(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(OUT) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~
+ $(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~
$(HIDE)$(RM) $(LITEOS_PLATFORM_MENUCONFIG_H)
$(HIDE)$(RM) include
$(HIDE)$(MAKE) cleanrootfs
@@ -210,4 +217,14 @@ cleanrootfs:
$(HIDE)$(RM) $(OUT)/rootfs.zip
$(HIDE)$(RM) $(OUT)/rootfs.img
-.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help
+update_all_config:
+ $(HIDE)shopt -s globstar && for f in tools/build/config/**/*.config ; \
+ do \
+ echo updating $$f; \
+ test -f $$f && cp $$f .config && $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig $$f $(KCONFIG_FILE_PATH); \
+ done
+
+%.config:
+ $(HIDE)test -f tools/build/config/$@ && cp tools/build/config/$@ .config && $(MENUCONFIG_MCONF) $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig tools/build/config/$@ $(KCONFIG_FILE_PATH)
+
+.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..7997be41
--- /dev/null
+++ b/README.md
@@ -0,0 +1,96 @@
+# LiteOS Cortex-A
+
+- [Introduction](#section11660541593)
+- [Directory Structure](#section161941989596)
+- [Constraints](#section119744591305)
+- [Usage](#section741617511812)
+ - [Preparations](#section1579912573329)
+ - [Source Code Acquisition](#section11443189655)
+ - [Compilation and Building](#section2081013992812)
+
+- [Repositories Involved](#section1371113476307)
+
+## Introduction
+
+The OpenHarmony LiteOS Cortex-A is a new-generation kernel developed based on the Huawei LiteOS kernel. Huawei LiteOS is a lightweight operating system \(OS\) built for the Internet of Things \(IoT\) field. With the rapid development of the IoT industry, OpenHarmony LiteOS Cortex-A brings small-sized, low-power, and high-performance experience and builds a unified and open ecosystem for developers. In addition, it provides rich kernel mechanisms, more comprehensive Portable Operating System Interface \(POSIX\), and a unified driver framework, Hardware Driver Foundation \(HDF\), which offers unified access for device developers and friendly development experience for application developers. [Figure1](#fig27311582210) shows the architecture of the OpenHarmony LiteOS Cortex-A kernel.
+
+**Figure 1** Architecture of the OpenHarmony LiteOS Cortex-A kernel
+![](figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png "architecture-of-the-openharmony-liteos-cortex-a-kernel")
+
+## Directory Structure
+
+```
+/kernel/liteos_a
+├── apps # User-space init and shell application programs
+├── arch # System architecture, such as ARM
+│ └── arm # Code for ARM architecture
+├── bsd # Code of the driver and adaptation layer module related to the FreeBSD, such as the USB module
+├── compat # Kernel API compatibility
+│ └── posix # POSIX APIs
+├── drivers # Kernel driver
+│ └── char # Character device
+│ ├── mem # Driver for accessing physical input/output (I/O) devices
+│ ├── quickstart # APIs for quick start of the system
+│ ├── random # Driver for random number generators
+│ └── video # Framework of the framebuffer driver
+├── fs # File system module, which mainly derives from the NuttX open-source project
+│ ├── fat # FAT file system
+│ ├── jffs2 # JFFS2 file system
+│ ├── include # Header files exposed externally
+│ ├── nfs # NFS file system
+│ ├── proc # proc file system
+│ ├── ramfs # RAMFS file system
+│ └── vfs # VFS layer
+├── kernel # Kernel modules including the process, memory, and IPC modules
+│ ├── base # Basic kernel modules including the scheduling and memory modules
+│ ├── common # Common components used by the kernel
+│ ├── extended # Extended kernel modules including the dynamic loading, vDSO, and LiteIPC modules
+│ ├── include # Header files exposed externally
+│ └── user # Init process loading
+├── lib # Kernel library
+├── net # Network module, which mainly derives from the lwIP open-source project
+├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300
+│ ├── hw # Logic code related to clocks and interupts
+│ ├── include # Header files exposed externally
+│ └── uart # Logic code related to the serial port
+├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300
+├── security # Code related to security features, including process permission management and virtual ID mapping management
+├── syscall # System calling
+└── tools # Building tools as well as related configuration and code
+```
+
+## Constraints
+
+- Programming languages: C and C++
+- Applicable development boards: Hi3518E V300 and Hi3516D V300
+- Hi3518E V300 uses the JFFS2 file system by default, and Hi3516D V300 uses the FAT file system by default.
+
+## Usage
+
+OpenHarmony LiteOS Cortex-A supports the [Hi3518E V300](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/introduction-to-the-hi3518-development-board.md) and [Hi3516D V300](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/introduction-to-the-hi3516-development-board.md). You can develop and run your applications based on both development boards.
+
+### Preparations
+
+You need to set up the compilation environment on Linux.
+
+- For Hi3518E V300, see [Setting Up the Hi3518 Development Environment](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/setting-up-the-hi3518-development-environment.md).
+- For Hi3516D V300, see [Setting Up the Hi3516 Development Environment](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/setting-up-the-hi3516-development-environment.md).
+
+### Source Code Acquisition
+
+Download and decompress a set of source code on a Linux server to acquire the [source code](https://repo.huaweicloud.com/harmonyos/os/1.0/code-1.0.tar.gz). For more acquisition methods, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/master/docs-en/get-code/source-code-acquisition.md).
+
+### Compilation and Building
+
+For details about how to develop the first application, see:
+
+- [Developing the First Example Program Running on Hi3518](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/developing-the-first-example-program-running-on-hi3518.md)
+
+- [Developing the First Example Program Running on Hi3516](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/developing-the-first-example-program-running-on-hi3516.md)
+
+## Repositories Involved
+
+[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos)
+
+**[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a)**
+
diff --git a/README_zh.md b/README_zh.md
new file mode 100644
index 00000000..61bcf073
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,96 @@
+# LiteOS-A内核
+
+- [简介](#section11660541593)
+- [目录](#section161941989596)
+- [约束](#section119744591305)
+- [使用说明](#section741617511812)
+ - [准备](#section1579912573329)
+ - [获取源码](#section11443189655)
+ - [编译构建](#section2081013992812)
+
+- [相关仓](#section1371113476307)
+
+## 简介
+
+OpenHarmony LiteOS-A内核是基于Huawei LiteOS内核演进发展的新一代内核,Huawei LiteOS是面向IoT领域构建的轻量级物联网操作系统。在IoT产业高速发展的潮流中,OpenHarmony LiteOS-A内核能够带给用户小体积、低功耗、高性能的体验以及统一开放的生态系统能力,新增了丰富的内核机制、更加全面的POSIX标准接口以及统一驱动框架**HDF**(OpenHarmony Driver Foundation)等,为设备厂商提供了更统一的接入方式,为OpenHarmony的应用开发者提供了更友好的开发体验。图1为OpenHarmony LiteOS-A内核架构图:
+
+**图 1** OpenHarmony LiteOS-A内核架构图
+![](figures/OpenHarmony-LiteOS-A内核架构图.png "OpenHarmony-LiteOS-A内核架构图")
+
+## 目录
+
+```
+/kernel/liteos_a
+├── apps # 用户态的init和shell应用程序
+├── arch # 体系架构的目录,如arm等
+│ └── arm # arm架构代码
+├── bsd # freebsd相关的驱动和适配层模块代码引入,例如USB等
+├── compat # 内核接口兼容性目录
+│ └── posix # posix相关接口
+├── drivers # 内核驱动
+│ └── char # 字符设备
+│ ├── mem # 访问物理IO设备驱动
+│ ├── quickstart # 系统快速启动接口目录
+│ ├── random # 随机数设备驱动
+│ └── video # framebuffer驱动框架
+├── fs # 文件系统模块,主要来源于NuttX开源项目
+│ ├── fat # fat文件系统
+│ ├── jffs2 # jffs2文件系统
+│ ├── include # 对外暴露头文件存放目录
+│ ├── nfs # nfs文件系统
+│ ├── proc # proc文件系统
+│ ├── ramfs # ramfs文件系统
+│ └── vfs # vfs层
+├── kernel # 进程、内存、IPC等模块
+│ ├── base # 基础内核,包括调度、内存等模块
+│ ├── common # 内核通用组件
+│ ├── extended # 扩展内核,包括动态加载、vdso、liteipc等模块
+│ ├── include # 对外暴露头文件存放目录
+│ └── user # 加载init进程
+├── lib # 内核的lib库
+├── net # 网络模块,主要来源于lwip开源项目
+├── platform # 支持不同的芯片平台代码,如Hi3516DV300等
+│ ├── hw # 时钟与中断相关逻辑代码
+│ ├── include # 对外暴露头文件存放目录
+│ └── uart # 串口相关逻辑代码
+├── platform # 支持不同的芯片平台代码,如Hi3516DV300等
+├── security # 安全特性相关的代码,包括进程权限管理和虚拟id映射管理
+├── syscall # 系统调用
+└── tools # 构建工具及相关配置和代码
+```
+
+## 约束
+
+- 开发语言:C/C++;
+- 适用于Hi3518EV300、Hi3516DV300单板;
+- Hi3518EV300默认使用jffs2文件系统,Hi3516DV300默认使用FAT文件系统。
+
+## 使用说明
+
+OpenHarmony LiteOS-A内核支持Hi3518EV300([介绍](https://gitee.com/openharmony/docs/blob/master/quick-start/Hi3518%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))、Hi3516DV300([介绍](https://gitee.com/openharmony/docs/blob/master/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))单板,开发者可基于两种单板开发运行自己的应用程序。
+
+### 准备
+
+开发者需要在Linux上搭建编译环境:
+
+- Hi3518EV300单板:参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/quick-start/Hi3518%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md);
+- Hi3516DV300单板:参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/quick-start/Hi3516%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md)。
+
+### 获取源码
+
+在Linux服务器上下载并解压一套源代码,获取源码([下载链接](https://repo.huaweicloud.com/harmonyos/os/1.0/code-1.0.tar.gz))。更多源码获取方式,参考[源码获取](https://gitee.com/openharmony/docs/blob/master/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md)。
+
+### 编译构建
+
+开发者开发第一个应用程序可参考:
+
+- [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md);
+
+- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE%8B.md)。
+
+## 相关仓
+
+[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos)
+
+**[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a)**
+
diff --git a/apps/Makefile b/apps/Makefile
old mode 100644
new mode 100755
index e5857242..631b955c
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -38,7 +38,7 @@ all: $(APPS)
# Make
$(APPS):
ifneq ($(APP_SUBDIRS), )
- $(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir ; done
+ $(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir || exit 1; done
endif
clean:
diff --git a/apps/config.mk b/apps/config.mk
old mode 100644
new mode 100755
index 8e4c95f9..5f6efe06
--- a/apps/config.mk
+++ b/apps/config.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/apps/init/Makefile b/apps/init/Makefile
old mode 100644
new mode 100755
index 82017e7e..96eba811
--- a/apps/init/Makefile
+++ b/apps/init/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -43,6 +43,12 @@ ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses -Wnonnull $(LLVM_SYSROOT)
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
endif
+
+ifeq ($(LOSCFG_QUICK_START), y)
+LDCFLAGS += --static
+CFLAGS += -DLOSCFG_QUICK_START
+endif
+
INITNAME := init
all: $(INITNAME)
diff --git a/apps/init/src/init.c b/apps/init/src/init.c
old mode 100644
new mode 100755
index 882219df..7cab38a8
--- a/apps/init/src/init.c
+++ b/apps/init/src/init.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,11 +35,41 @@
#include
#include
+#ifdef LOSCFG_QUICK_START
+#include
+#include
+#include
+#include
+#include
+
+#define QUICKSTART_IOC_MAGIC 'T'
+#define QUICKSTART_INITSTEP2 _IO(QUICKSTART_IOC_MAGIC, 0)
+#define WAIT_FOR_SAMPLE 300000 // wait 300ms for sample
+#endif
int main(int argc, char * const *argv)
{
int ret;
const char *shellPath = "/bin/shell";
+#ifdef LOSCFG_QUICK_START
+ const char *samplePath = "/dev/shm/sample_quickstart";
+
+ ret = fork();
+ if (ret < 0) {
+ printf("Failed to fork for sample_quickstart\n");
+ } else if (ret == 0) {
+ (void)execve(samplePath, NULL, NULL);
+ exit(0);
+ }
+
+ usleep(WAIT_FOR_SAMPLE);
+
+ int fd = open("/dev/quickstart", O_RDONLY);
+ if (fd != -1) {
+ ioctl(fd, QUICKSTART_INITSTEP2);
+ close(fd);
+ }
+#endif
ret = fork();
if (ret < 0) {
printf("Failed to fork for shell\n");
diff --git a/apps/module.mk b/apps/module.mk
old mode 100644
new mode 100755
index 1cd7ae11..520f3393
--- a/apps/module.mk
+++ b/apps/module.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -38,3 +38,7 @@ endif
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
APP_SUBDIRS += init
endif
+
+ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
+APP_SUBDIRS += tftp
+endif
diff --git a/apps/shell/Makefile b/apps/shell/Makefile
old mode 100644
new mode 100755
index 857cb136..23024cac
--- a/apps/shell/Makefile
+++ b/apps/shell/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/apps/shell/builtin/cd.c b/apps/shell/builtin/cd.c
old mode 100644
new mode 100755
index 56d6897e..6fdd41d3
--- a/apps/shell/builtin/cd.c
+++ b/apps/shell/builtin/cd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shcmd.h b/apps/shell/include/shcmd.h
old mode 100644
new mode 100755
index d664a4bd..f5485a2a
--- a/apps/shell/include/shcmd.h
+++ b/apps/shell/include/shcmd.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shcmdparse.h b/apps/shell/include/shcmdparse.h
index e3206220..a6ec6197 100644
--- a/apps/shell/include/shcmdparse.h
+++ b/apps/shell/include/shcmdparse.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shell.h b/apps/shell/include/shell.h
old mode 100644
new mode 100755
index 48fa3093..d23b9e1b
--- a/apps/shell/include/shell.h
+++ b/apps/shell/include/shell.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shell_list.h b/apps/shell/include/shell_list.h
index 91b5bbd3..020c1711 100644
--- a/apps/shell/include/shell_list.h
+++ b/apps/shell/include/shell_list.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shell_pri.h b/apps/shell/include/shell_pri.h
index b8e75c1c..8e5ab6f6 100644
--- a/apps/shell/include/shell_pri.h
+++ b/apps/shell/include/shell_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/sherr.h b/apps/shell/include/sherr.h
index 6122fd2c..a560a740 100644
--- a/apps/shell/include/sherr.h
+++ b/apps/shell/include/sherr.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/shmsg.h b/apps/shell/include/shmsg.h
old mode 100644
new mode 100755
index fb683559..ee90ec6c
--- a/apps/shell/include/shmsg.h
+++ b/apps/shell/include/shmsg.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/include/show.h b/apps/shell/include/show.h
old mode 100644
new mode 100755
index 95c56b12..2bb94865
--- a/apps/shell/include/show.h
+++ b/apps/shell/include/show.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/src/main.c b/apps/shell/src/main.c
old mode 100644
new mode 100755
index 54c0bf9f..ef57ca00
--- a/apps/shell/src/main.c
+++ b/apps/shell/src/main.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -98,6 +98,8 @@ int main()
int ret = SH_NOK;
ShellCB *shellCB = NULL;
+ setbuf(stdout, NULL);
+
shellCB = (ShellCB *)malloc(sizeof(ShellCB));
if (shellCB == NULL) {
goto ERR_OUT1;
diff --git a/apps/shell/src/shcmd.c b/apps/shell/src/shcmd.c
old mode 100644
new mode 100755
index 06845ac8..a4930a90
--- a/apps/shell/src/shcmd.c
+++ b/apps/shell/src/shcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -406,7 +406,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
}
output = (char *)malloc(len + 1);
if (output == NULL) {
- printf("malloc failure in %s[%d]", __FUNCTION__, __LINE__);
+ printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
return (unsigned int)SH_ERROR;
}
diff --git a/apps/shell/src/shcmdparse.c b/apps/shell/src/shcmdparse.c
old mode 100644
new mode 100755
index 1a9bc75e..97891747
--- a/apps/shell/src/shcmdparse.c
+++ b/apps/shell/src/shcmdparse.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/apps/shell/src/shmsg.c b/apps/shell/src/shmsg.c
old mode 100644
new mode 100755
index 34b7537b..d8c17c09
--- a/apps/shell/src/shmsg.c
+++ b/apps/shell/src/shmsg.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -61,9 +61,19 @@ char *GetCmdline(ShellCB *shellCB)
}
cmdNode = SH_LIST_ENTRY(cmdkey->list.pstNext, CmdKeyLink, list);
+ if (cmdNode == NULL) {
+ (void)pthread_mutex_unlock(&shellCB->keyMutex);
+ return NULL;
+ }
+
SH_ListDelete(&(cmdNode->list));
(void)pthread_mutex_unlock(&shellCB->keyMutex);
+ if (strlen(cmdNode->cmdString) == 0) {
+ free(cmdNode);
+ return NULL;
+ }
+
return cmdNode->cmdString;
}
@@ -73,7 +83,8 @@ static void ShellSaveHistoryCmd(char *string, ShellCB *shellCB)
CmdKeyLink *cmdkey = SH_LIST_ENTRY(string, CmdKeyLink, cmdString);
CmdKeyLink *cmdNxt = NULL;
- if ((string == NULL) || (*string == '\n') || (strlen(string) == 0)) {
+ if (*string == '\n') {
+ free(cmdkey);
return;
}
@@ -87,7 +98,7 @@ static void ShellSaveHistoryCmd(char *string, ShellCB *shellCB)
}
}
- if (cmdHistory->count == CMD_HISTORY_LEN) {
+ if (cmdHistory->count >= CMD_HISTORY_LEN) {
cmdNxt = SH_LIST_ENTRY(cmdHistory->list.pstNext, CmdKeyLink, list);
SH_ListDelete(&(cmdNxt->list));
SH_ListTailInsert(&(cmdHistory->list), &(cmdkey->list));
@@ -595,10 +606,6 @@ void *ShellEntry(void *argv)
}
while (1) {
- /* is console ready for shell ? */
- if (ret != SH_OK)
- break;
-
n = read(0, &ch, 1);
if (n == 1) {
ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);
diff --git a/apps/tftp/Makefile b/apps/tftp/Makefile
new file mode 100644
index 00000000..37cf594c
--- /dev/null
+++ b/apps/tftp/Makefile
@@ -0,0 +1,77 @@
+# 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.
+
+ROOT_DIR := $(dir $(shell pwd))/tftp/
+
+ifeq ($(APPSTOPDIR), )
+APPSTOPDIR := $(shell pwd)/../
+LITEOSTOPDIR = $(APPSTOPDIR)/../
+endif
+include $(ROOT_DIR)/../config.mk
+APPS_OUT := $(OUT)/bin
+
+SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function
+
+LOCAL_SRCS = $(wildcard src/*.c)
+LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/strncpy_s.c)
+LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/memcpy_s.c)
+LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/memset_s.c)
+LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/strncat_s.c)
+LOCAL_OBJ := $(LOCAL_SRCS:.c=.o)
+
+LOCAL_INCLUDE := \
+ -I $(ROOT_DIR)/include/ \
+ -I $(SECUREC_DIR)/include/\
+
+LOCAL_FLAGS += $(CFLAGS)
+
+LDPATH := -L$(ROOT_DIR)/
+ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
+LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses $(LLVM_SYSROOT)
+LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
+endif
+
+TARGETNAME := tftp
+
+all: $(TARGETNAME)
+
+$(LOCAL_OBJ): %.o : %.c
+ $(HIDE) $(CC) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
+
+$(TARGETNAME): $(LOCAL_OBJ)
+ $(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(TARGETNAME) $^ $(LDCFLAGS)
+ $(HIDE) mkdir -p $(APPS_OUT)
+ $(HIDE) $(MV) $(TARGETNAME) $(APPS_OUT)
+ $(HIDE) $(RM) $(LOCAL_OBJ)
+
+clean:
+ $(HIDE) $(RM) $(LOCAL_OBJ)
+ $(HIDE) $(RM) $(TARGETNAME)
+
+.PHONY: all $(TARGETNAME) clean
diff --git a/net/lwip-2.1/enhancement/include/lwip/tftpc.h b/apps/tftp/include/tftpc.h
similarity index 97%
rename from net/lwip-2.1/enhancement/include/lwip/tftpc.h
rename to apps/tftp/include/tftpc.h
index 49ff2930..3d0bf568 100644
--- a/net/lwip-2.1/enhancement/include/lwip/tftpc.h
+++ b/apps/tftp/include/tftpc.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,11 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LWIP_HDR_TFTPC_H
-#define LWIP_HDR_TFTPC_H
+#ifndef TFTPC_H
+#define TFTPC_H
-#include "lwip/opt.h"
-#include "lwip/sockets.h"
+#include "types_adapt.h"
#if LWIP_TFTP /* don't build if not configured for use in lwipopts.h */
@@ -307,4 +306,4 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
#endif /* LWIP_TFTP */
-#endif /* LWIP_HDR_TFTPC_H */
+#endif /* TFTPC_H */
diff --git a/apps/tftp/include/types_adapt.h b/apps/tftp/include/types_adapt.h
new file mode 100644
index 00000000..5634495f
--- /dev/null
+++ b/apps/tftp/include/types_adapt.h
@@ -0,0 +1,88 @@
+/*
+ * 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 TYPES_ADAPT_H
+#define TYPES_ADAPT_H
+
+#include
+#include
+#include
+
+#define LWIP_TFTP 1
+#define LOSCFG_NET_LWIP_SACK_TFTP 1
+#define LOSCFG_SHELL_CMD_DEBUG 1
+
+#define u8_t uint8_t
+#define s8_t int8_t
+#define u16_t uint16_t
+#define s16_t int16_t
+#define u32_t uint32_t
+#define s32_t int32_t
+
+#define X8_F "02" PRIx8
+#define U16_F PRIu16
+#define S16_F PRId16
+#define X16_F PRIx16
+#define U32_F PRIu32
+#define S32_F PRId32
+#define X32_F PRIx32
+#define SZT_F PRIuPTR
+
+#define PRINTK(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#define LWIP_ASSERT(msg, expr) assert(expr)
+#define LWIP_DEBUGF(module, msg) PRINTK msg
+
+#define LOS_OK 0
+#define LOS_NOK 1
+#define ERR_OK 0
+#define EOK 0
+
+#define mem_malloc malloc
+#define mem_free free
+#define lwip_socket socket
+#define lwip_ioctl ioctl
+#define lwip_close close
+#define lwip_bind bind
+#define lwip_sendto sendto
+#define lwip_recvfrom recvfrom
+
+#define IPADDR_NONE INADDR_NONE
+#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
+
+#define SHELLCMD_ENTRY(l, cmdType, cmdKey, paraNum, cmdHook) \
+int main(int argc, const char **argv) \
+{ \
+ return (int)cmdHook(argc, argv); \
+}
+
+typedef u32_t (*CmdCallBackFunc)(u32_t argc, const char **argv);
+
+#endif /* TYPES_ADAPT_H */
diff --git a/apps/tftp/src/main.c b/apps/tftp/src/main.c
new file mode 100644
index 00000000..4a476c74
--- /dev/null
+++ b/apps/tftp/src/main.c
@@ -0,0 +1,160 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "tftpc.h"
+
+#ifdef LOSCFG_NET_LWIP_SACK_TFTP
+static int tcpip_init_finish = 1;
+static char *TftpError[] = {
+ "TFTP transfer finish\n",
+ "Error while creating UDP socket\n",
+ "Error while binding to the UDP socket\n",
+ "Error returned by select() system call\n",
+ "Error while receiving data from the peer\n",
+ "Error while sending data to the peer\n",
+ "Requested file is not found\n",
+ "This is the error sent by the server when hostname cannot be resolved\n",
+ "Input paramters passed to TFTP interfaces are invalid\n",
+ "Error detected in TFTP packet or the error received from the TFTP server\n",
+ "Error during packet synhronization while sending or unexpected packet is received\n",
+ "File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n",
+ "File name lenght greater than 256\n",
+ "Hostname IP is not valid\n",
+ "TFTP server returned file access error\n",
+ "TFTP server returned error signifying that the DISK is full to write\n",
+ "TFTP server returned error signifying that the file exist\n",
+ "The source file name do not exisits\n",
+ "Memory allocaion failed in TFTP client\n",
+ "File open failed\n",
+ "File read error\n",
+ "File create error\n",
+ "File write error\n",
+ "Max time expired while waiting for file to be recived\n",
+ "Error when the received packet is less than 4bytes(error lenght) or greater than 512bytes\n",
+ "Returned by TFTP server for protocol user error\n",
+ "The destination file path length greater than 256\n",
+ "Returned by TFTP server for undefined transfer ID\n",
+ "IOCTL fucntion failed at TFTP client while setting the socket to non-block\n",
+};
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+#endif
+
+u32_t osShellTftp(int argc, const char **argv)
+{
+ u32_t ulRemoteAddr = IPADDR_NONE;
+ const u16_t usTftpServPort = 69;
+ u8_t ucTftpGet = 0;
+ s8_t *szLocalFileName = NULL;
+ s8_t *szRemoteFileName = NULL;
+ u32_t ret;
+
+ int i = 1;
+ if (argc < 1 || argv == NULL) {
+ goto usage;
+ }
+
+ if (!tcpip_init_finish) {
+ PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
+ return LOS_NOK;
+ }
+
+ while (i < argc) {
+ if (strcmp(argv[i], "-p") == 0) {
+ ucTftpGet = 0;
+ i++;
+ continue;
+ }
+
+ if (strcmp(argv[i], "-g") == 0) {
+ ucTftpGet = 1;
+ i++;
+ continue;
+ }
+
+ if (strcmp(argv[i], "-l") == 0 && ((i + 1) < argc)) {
+ szLocalFileName = (s8_t *)argv[i + 1];
+ i += 2;
+ continue;
+ }
+
+ if (strcmp(argv[i], "-r") == 0 && ((i + 1) < argc)) {
+ szRemoteFileName = (s8_t *)argv[i + 1];
+ i += 2;
+ continue;
+ }
+
+ if ((i + 1) == argc) {
+ ulRemoteAddr = inet_addr(argv[i]);
+ break;
+ }
+
+ goto usage;
+ }
+
+ if (ulRemoteAddr == IPADDR_NONE || szLocalFileName == NULL || szRemoteFileName == NULL) {
+ goto usage;
+ }
+
+ if (ucTftpGet) {
+ ret = lwip_tftp_get_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
+ TRANSFER_MODE_BINARY, szRemoteFileName, szLocalFileName);
+ } else {
+ ret = lwip_tftp_put_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
+ TRANSFER_MODE_BINARY, szLocalFileName, szRemoteFileName);
+ }
+
+ LWIP_ASSERT("TFTP UNKNOW ERROR!", ret < ARRAY_SIZE(TftpError));
+ PRINTK("%s", TftpError[ret]);
+ if (ret) {
+ return LOS_NOK;
+ } else {
+ return LOS_OK;
+ }
+usage:
+ PRINTK("usage:\nTransfer a file from/to tftp server\n");
+ PRINTK("tftp <-g/-p> -l FullPathLocalFile -r RemoteFile Host\n");
+ return LOS_NOK;
+}
+
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+SHELLCMD_ENTRY(tftp_shellcmd, CMD_TYPE_EX, "tftp", XARGS, (CmdCallBackFunc)(uintptr_t)osShellTftp);
+#endif /* LOSCFG_SHELL_CMD_DEBUG */
+#endif /* LOSCFG_NET_LWIP_SACK_TFTP */
diff --git a/net/lwip-2.1/enhancement/src/tftpc.c b/apps/tftp/src/tftpc.c
similarity index 99%
rename from net/lwip-2.1/enhancement/src/tftpc.c
rename to apps/tftp/src/tftpc.c
index 16c14928..b78bd45f 100644
--- a/net/lwip-2.1/enhancement/src/tftpc.c
+++ b/apps/tftp/src/tftpc.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,29 +31,24 @@
/* TFTP Client utility */
-#include "lwip/opt.h"
+#include "tftpc.h"
#if LWIP_TFTP /* don't build if not configured for use in lwipopts.h */
-#include "lwip/tcpip.h"
-#include "lwip/netif.h"
-#include "lwip/mem.h"
-#include "lwip/err.h"
-#include "lwip/inet.h"
-#include "netif/etharp.h"
-#include "lwip/ip_addr.h"
-#include "lwip/sockets.h"
-#include "lwip/udp.h"
-#include "lwip/ip_addr.h"
-#include "lwip/netif.h"
-#include "lwip/def.h"
-#include "lwip/tftpc.h"
-#include "fcntl.h"
+#include
#include
#include
-
+#include
+#include
+#include
#include
-
+#include
+#include
+#include
+#include
+#include
+#include
+#include
/* Function Declarations */
#ifdef LOSCFG_NET_LWIP_SACK_TFTP
@@ -1088,7 +1083,6 @@ u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_
&stServerAddr, pstSendBuf);
(void)lwip_close(iSockNum);
- close(fp);
mem_free(pucBuffer);
ulErrCode = TFTPC_FILEOPEN_ERROR;
diff --git a/arch/Kconfig b/arch/Kconfig
old mode 100644
new mode 100755
diff --git a/arch/arm/arm.mk b/arch/arm/arm.mk
index 923518c9..6e765e9e 100644
--- a/arch/arm/arm.mk
+++ b/arch/arm/arm.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/arch/arm/arm/Makefile b/arch/arm/arm/Makefile
old mode 100644
new mode 100755
index 648fe5c7..d105536e
--- a/arch/arm/arm/Makefile
+++ b/arch/arm/arm/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/arch/arm/arm/include/arch_config.h b/arch/arm/arm/include/arch_config.h
old mode 100644
new mode 100755
index 09de16a4..53f09d02
--- a/arch/arm/arm/include/arch_config.h
+++ b/arch/arm/arm/include/arch_config.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/arm.h b/arch/arm/arm/include/arm.h
old mode 100644
new mode 100755
index bde38793..c8a10ade
--- a/arch/arm/arm/include/arm.h
+++ b/arch/arm/arm/include/arm.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/arm_user_copy.h b/arch/arm/arm/include/arm_user_copy.h
old mode 100644
new mode 100755
index ac82b958..b86e37c4
--- a/arch/arm/arm/include/arm_user_copy.h
+++ b/arch/arm/arm/include/arm_user_copy.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/arm_user_get.h b/arch/arm/arm/include/arm_user_get.h
old mode 100644
new mode 100755
index 53532107..43843e02
--- a/arch/arm/arm/include/arm_user_get.h
+++ b/arch/arm/arm/include/arm_user_get.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/arm_user_put.h b/arch/arm/arm/include/arm_user_put.h
old mode 100644
new mode 100755
index cacae1b2..c5c475d3
--- a/arch/arm/arm/include/arm_user_put.h
+++ b/arch/arm/arm/include/arm_user_put.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_arch_mmu.h b/arch/arm/arm/include/los_arch_mmu.h
index c501b219..93b2fd34 100644
--- a/arch/arm/arm/include/los_arch_mmu.h
+++ b/arch/arm/arm/include/los_arch_mmu.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_asid.h b/arch/arm/arm/include/los_asid.h
index eb343611..613982db 100644
--- a/arch/arm/arm/include/los_asid.h
+++ b/arch/arm/arm/include/los_asid.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_atomic.h b/arch/arm/arm/include/los_atomic.h
index d007b66e..702ea78e 100644
--- a/arch/arm/arm/include/los_atomic.h
+++ b/arch/arm/arm/include/los_atomic.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_hw_cpu.h b/arch/arm/arm/include/los_hw_cpu.h
old mode 100644
new mode 100755
index 5585eebc..45ecb23e
--- a/arch/arm/arm/include/los_hw_cpu.h
+++ b/arch/arm/arm/include/los_hw_cpu.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_mmu_descriptor_v6.h b/arch/arm/arm/include/los_mmu_descriptor_v6.h
old mode 100644
new mode 100755
index d8744100..6f93de03
--- a/arch/arm/arm/include/los_mmu_descriptor_v6.h
+++ b/arch/arm/arm/include/los_mmu_descriptor_v6.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -104,6 +104,8 @@ extern "C" {
((x) << MMU_DESCRIPTOR_L1_TEX_SHIFT) /* type extension */
#define MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED \
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE)
+#define MMU_DESCRIPTOR_L1_TYPE_NORMAL_NOCACHE \
+ (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_NON_CACHEABLE)
#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED \
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE)
#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_NON_SHARED \
@@ -141,6 +143,8 @@ extern "C" {
((x) << MMU_DESCRIPTOR_L2_TEX_SHIFT) /* type extension */
#define MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED \
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE)
+#define MMU_DESCRIPTOR_L2_TYPE_NORMAL_NOCACHE \
+ (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_NON_CACHEABLE)
#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED \
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE)
#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_NON_SHARED \
@@ -208,6 +212,12 @@ extern "C" {
MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
MMU_DESCRIPTOR_L1_AP_P_RW_U_NA)
+#define MMU_INITIAL_MAP_NORMAL_NOCACHE \
+ (MMU_DESCRIPTOR_L1_TYPE_SECTION | \
+ MMU_DESCRIPTOR_L1_TYPE_NORMAL_NOCACHE | \
+ MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
+ MMU_DESCRIPTOR_L1_AP_P_RW_U_NA)
+
#define MMU_INITIAL_MAP_DEVICE \
(MMU_DESCRIPTOR_L1_TYPE_SECTION | \
MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED | \
diff --git a/arch/arm/arm/include/los_pte_ops.h b/arch/arm/arm/include/los_pte_ops.h
index 5d6c2b74..6d1bee53 100644
--- a/arch/arm/arm/include/los_pte_ops.h
+++ b/arch/arm/arm/include/los_pte_ops.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/include/los_tlb_v6.h b/arch/arm/arm/include/los_tlb_v6.h
index 5ccacaf5..7257babe 100644
--- a/arch/arm/arm/include/los_tlb_v6.h
+++ b/arch/arm/arm/include/los_tlb_v6.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/armv7a/cache.S b/arch/arm/arm/src/armv7a/cache.S
index cdcbee06..0970d453 100644
--- a/arch/arm/arm/src/armv7a/cache.S
+++ b/arch/arm/arm/src/armv7a/cache.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/hw_user_get.S b/arch/arm/arm/src/hw_user_get.S
old mode 100644
new mode 100755
index 820d48ec..32711f60
--- a/arch/arm/arm/src/hw_user_get.S
+++ b/arch/arm/arm/src/hw_user_get.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/hw_user_put.S b/arch/arm/arm/src/hw_user_put.S
old mode 100644
new mode 100755
index 941efe7e..d79e509c
--- a/arch/arm/arm/src/hw_user_put.S
+++ b/arch/arm/arm/src/hw_user_put.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/include/asm.h b/arch/arm/arm/src/include/asm.h
old mode 100644
new mode 100755
index 796e14c0..96ea07ad
--- a/arch/arm/arm/src/include/asm.h
+++ b/arch/arm/arm/src/include/asm.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/include/los_exc_pri.h b/arch/arm/arm/src/include/los_exc_pri.h
index 4031217b..e1e9c487 100644
--- a/arch/arm/arm/src/include/los_exc_pri.h
+++ b/arch/arm/arm/src/include/los_exc_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -52,7 +52,8 @@ STATIC INLINE VOID OsSetCurrCpuSp(UINTPTR regSp)
extern UINT32 OsGetSystemStatus(VOID);
extern VOID BackTraceSub(UINTPTR regFP);
extern VOID OsExcInit(VOID);
-extern VOID OsKillUserProcess(UINTPTR sp);
+extern BOOL OsSystemExcIsReset(VOID);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/arch/arm/arm/src/include/los_hw_pri.h b/arch/arm/arm/src/include/los_hw_pri.h
old mode 100644
new mode 100755
index 5d470b34..052da990
--- a/arch/arm/arm/src/include/los_hw_pri.h
+++ b/arch/arm/arm/src/include/los_hw_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/include/los_hwi_pri.h b/arch/arm/arm/src/include/los_hwi_pri.h
index ea1726b6..ad8e589c 100644
--- a/arch/arm/arm/src/include/los_hwi_pri.h
+++ b/arch/arm/arm/src/include/los_hwi_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/jmp.S b/arch/arm/arm/src/jmp.S
index 209b4e8a..14dd05a3 100644
--- a/arch/arm/arm/src/jmp.S
+++ b/arch/arm/arm/src/jmp.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/los_arch_mmu.c b/arch/arm/arm/src/los_arch_mmu.c
old mode 100644
new mode 100755
index ec6111f7..3e046193
--- a/arch/arm/arm/src/los_arch_mmu.c
+++ b/arch/arm/arm/src/los_arch_mmu.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -91,11 +91,6 @@ STATIC INT32 OsMapParamCheck(UINT32 flags, VADDR_T vaddr, PADDR_T paddr)
}
#endif
- if (!(flags & VM_MAP_REGION_FLAG_PERM_READ)) {
- VM_ERR("miss read flag");
- return LOS_ERRNO_VM_INVALID_ARGS;
- }
-
/* paddr and vaddr must be aligned */
if (!MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(vaddr) || !MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(paddr)) {
return LOS_ERRNO_VM_INVALID_ARGS;
@@ -114,6 +109,9 @@ STATIC VOID OsCvtPte2AttsToFlags(PTE_T l1Entry, PTE_T l2Entry, UINT32 *flags)
switch (l2Entry & MMU_DESCRIPTOR_L2_TEX_TYPE_MASK) {
case MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED:
+ *flags |= VM_MAP_REGION_FLAG_STRONGLY_ORDERED;
+ break;
+ case MMU_DESCRIPTOR_L2_TYPE_NORMAL_NOCACHE:
*flags |= VM_MAP_REGION_FLAG_UNCACHED;
break;
case MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED:
@@ -208,10 +206,10 @@ STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 sca
}
}
-/* convert user level mmu flags to L1 descriptors flags */
-STATIC UINT32 OsCvtSecFlagsToAttrs(UINT32 flags)
+STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
{
- UINT32 mmuFlags = MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT;
+ UINT32 mmuFlags = 0;
+
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
case VM_MAP_REGION_FLAG_CACHED:
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
@@ -219,33 +217,63 @@ STATIC UINT32 OsCvtSecFlagsToAttrs(UINT32 flags)
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE;
#endif
break;
- case VM_MAP_REGION_FLAG_WRITE_COMBINING:
- case VM_MAP_REGION_FLAG_UNCACHED:
+ case VM_MAP_REGION_FLAG_STRONGLY_ORDERED:
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED;
break;
+ case VM_MAP_REGION_FLAG_UNCACHED:
+ mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_NOCACHE;
+ break;
case VM_MAP_REGION_FLAG_UNCACHED_DEVICE:
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED;
break;
default:
return LOS_ERRNO_VM_INVALID_ARGS;
}
+ return mmuFlags;
+}
- switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
+STATIC UINT32 OsCvtSecAccessFlagsToMMUFlags(UINT32 flags)
+{
+ UINT32 mmuFlags = 0;
+
+ switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE)) {
case 0:
+ mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_NA_U_NA;
+ break;
+ case VM_MAP_REGION_FLAG_PERM_READ:
+ case VM_MAP_REGION_FLAG_PERM_USER:
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_NA;
break;
- case VM_MAP_REGION_FLAG_PERM_WRITE:
- mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_NA;
- break;
- case VM_MAP_REGION_FLAG_PERM_USER:
+ case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ:
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_RO;
break;
+ case VM_MAP_REGION_FLAG_PERM_WRITE:
+ case VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE:
+ mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_NA;
+ break;
case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE:
+ case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE:
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_RW;
break;
default:
break;
}
+ return mmuFlags;
+}
+
+/* convert user level mmu flags to L1 descriptors flags */
+STATIC UINT32 OsCvtSecFlagsToAttrs(UINT32 flags)
+{
+ UINT32 mmuFlags;
+
+ mmuFlags = OsCvtSecCacheFlagsToMMUFlags(flags);
+ if (mmuFlags == LOS_ERRNO_VM_INVALID_ARGS) {
+ return mmuFlags;
+ }
+
+ mmuFlags |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT;
+
+ mmuFlags |= OsCvtSecAccessFlagsToMMUFlags(flags);
if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) {
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_XN;
@@ -271,6 +299,9 @@ STATIC VOID OsCvtSecAttsToFlags(PTE_T l1Entry, UINT32 *flags)
switch (l1Entry & MMU_DESCRIPTOR_L1_TEX_TYPE_MASK) {
case MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED:
+ *flags |= VM_MAP_REGION_FLAG_STRONGLY_ORDERED;
+ break;
+ case MMU_DESCRIPTOR_L1_TYPE_NORMAL_NOCACHE:
*flags |= VM_MAP_REGION_FLAG_UNCACHED;
break;
case MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED:
@@ -494,8 +525,7 @@ STATIC VOID OsMapL1PTE(LosArchMmu *archMmu, PTE_T *pte1Ptr, vaddr_t vaddr, UINT3
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, vaddr), *pte1Ptr);
}
-/* convert user level mmu flags to L2 descriptors flags */
-STATIC UINT32 OsCvtPte2FlagsToAttrs(uint32_t flags)
+STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags)
{
UINT32 mmuFlags = 0;
@@ -506,33 +536,61 @@ STATIC UINT32 OsCvtPte2FlagsToAttrs(uint32_t flags)
#endif
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
break;
- case VM_MAP_REGION_FLAG_WRITE_COMBINING:
- case VM_MAP_REGION_FLAG_UNCACHED:
+ case VM_MAP_REGION_FLAG_STRONGLY_ORDERED:
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED;
break;
+ case VM_MAP_REGION_FLAG_UNCACHED:
+ mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_NOCACHE;
+ break;
case VM_MAP_REGION_FLAG_UNCACHED_DEVICE:
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED;
break;
default:
return LOS_ERRNO_VM_INVALID_ARGS;
}
+ return mmuFlags;
+}
- switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
+STATIC UINT32 OsCvtPte2AccessFlagsToMMUFlags(UINT32 flags)
+{
+ UINT32 mmuFlags = 0;
+
+ switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE)) {
case 0:
+ mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_NA_U_NA;
+ break;
+ case VM_MAP_REGION_FLAG_PERM_READ:
+ case VM_MAP_REGION_FLAG_PERM_USER:
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_NA;
break;
- case VM_MAP_REGION_FLAG_PERM_WRITE:
- mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_NA;
- break;
- case VM_MAP_REGION_FLAG_PERM_USER:
+ case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ:
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_RO;
break;
+ case VM_MAP_REGION_FLAG_PERM_WRITE:
+ case VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE:
+ mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_NA;
+ break;
case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE:
+ case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE:
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_RW;
break;
default:
break;
}
+ return mmuFlags;
+}
+
+/* convert user level mmu flags to L2 descriptors flags */
+STATIC UINT32 OsCvtPte2FlagsToAttrs(UINT32 flags)
+{
+ UINT32 mmuFlags;
+
+ mmuFlags = OsCvtPte2CacheFlagsToMMUFlags(flags);
+ if (mmuFlags == LOS_ERRNO_VM_INVALID_ARGS) {
+ return mmuFlags;
+ }
+
+ mmuFlags |= OsCvtPte2AccessFlagsToMMUFlags(flags);
if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) {
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN;
diff --git a/arch/arm/arm/src/los_asid.c b/arch/arm/arm/src/los_asid.c
index 72b4d709..b92dae27 100644
--- a/arch/arm/arm/src/los_asid.c
+++ b/arch/arm/arm/src/los_asid.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,8 +34,8 @@
* @ingroup kernel
*/
-#include "los_typedef.h"
#include "los_asid.h"
+#include "los_bitmap.h"
#include "los_spinlock.h"
#include "los_mmu_descriptor_v6.h"
diff --git a/arch/arm/arm/src/los_dispatch.S b/arch/arm/arm/src/los_dispatch.S
old mode 100644
new mode 100755
index add17d0f..1f9c2469
--- a/arch/arm/arm/src/los_dispatch.S
+++ b/arch/arm/arm/src/los_dispatch.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,20 +32,11 @@
#include "asm.h"
#include "arch_config.h"
-#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
- .extern OsLockDepCheckOut
-#endif
- .extern g_taskSpin
- .extern g_percpu
- .global OsStartToRun
+ .extern OsSchedToUserReleaseLock
.global OsTaskSchedule
+ .global OsTaskContextLoad
.global OsIrqHandler
- .global ArchSpinUnlock
- .global OsSchedToUserSpinUnlock
- .equ OS_TASK_STATUS_RUNNING, 0x0010U
- .equ OS_PERCPU_STRUCT_SIZE, 0x28U
- .equ OS_PERCPU_TASK_LOCK_OFFSET, 0x14U
.fpu vfpv4
/* macros to align and unalign the stack on 8 byte boundary for ABI compliance */
@@ -88,26 +79,6 @@
#endif
.endm
-/* R0: new task */
-OsStartToRun:
-
- MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE)
-
- LDRH R1, [R0, #4]
- ORR R1, #OS_TASK_STATUS_RUNNING
- STRH R1, [R0, #4]
-
- /* R0 is new task, save it on tpidrprw */
- MCR p15, 0, R0, c13, c0, 4
- ISB
-
- VPUSH {S0} /* fpu */
- VPOP {S0}
- VPUSH {D0}
- VPOP {D0}
-
- B OsTaskContextLoad
-
/*
* R0: new task
* R1: run task
@@ -152,24 +123,11 @@ OsTaskContextLoad:
BNE OsKernelTaskLoad
#ifdef LOSCFG_KERNEL_SMP
-#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
/* 8 bytes stack align */
SUB SP, SP, #4
- LDR R0, =g_taskSpin
- BL OsLockDepCheckOut
+ BL OsSchedToUserReleaseLock
ADD SP, SP, #4
#endif
- /* R0 = &g_taskSpin.rawLock */
- LDR R0, =g_taskSpin
- BL ArchSpinUnlock
- LDR R2, =g_percpu
- MRC P15, 0, R3, C0, C0, 5
- UXTB R3, R3
- MOV R1, #OS_PERCPU_STRUCT_SIZE
- MLA R3, R1, R3, R2
- MOV R2, #0
- STR R2, [R3, #OS_PERCPU_TASK_LOCK_OFFSET]
-#endif
MVN R3, #CPSR_INT_DISABLE
AND R4, R4, R3
@@ -245,9 +203,7 @@ OsIrqFromKernel:
/* process pending signals */
BL OsTaskProcSignal
- /* check if needs to schedule */
- CMP R0, #0
- BLNE OsSchedPreempt
+ BL OsSchedIrqEndCheckNeedSched
MOV R0,SP
MOV R1,R7
diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c
old mode 100644
new mode 100755
index 7b431478..de57d93c
--- a/arch/arm/arm/src/los_exc.c
+++ b/arch/arm/arm/src/los_exc.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -341,7 +341,7 @@ STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
excBufAddr->SP);
}
- PrintExcInfo("fp = 0x%x\n", excBufAddr->R11);
+ PrintExcInfo("\nfp = 0x%x\n", excBufAddr->R11);
}
STATIC VOID OsExcRegsInfo(const ExcContext *excBufAddr)
@@ -422,7 +422,7 @@ STATIC VOID OsDumpExcVaddrRegion(LosVmSpace *space, LosVmMapRegion *region)
mmuFlag = FALSE;
}
PrintExcInfo(" 0x%08x 0x%08x 0x%08x\n",
- startVaddr, LOS_PaddrToKVaddr(startPaddr), pageCount << PAGE_SHIFT);
+ startVaddr, LOS_PaddrToKVaddr(startPaddr), (UINT32)pageCount << PAGE_SHIFT);
pageCount = 0;
startPaddr = 0;
}
@@ -544,6 +544,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
OsProcessExitCodeCoreDumpSet(runProcess);
#endif
OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
+
/* kill user exc process */
LOS_Exit(OS_PRO_EXIT_OK);
@@ -784,9 +785,9 @@ VOID OsBackTrace(VOID)
{
UINT32 regFP = Get_Fp();
LosTaskCB *runTask = OsCurrTaskGet();
- PRINTK("OsBackTrace fp = 0x%x\n", regFP);
- PRINTK("runTask->taskName = %s\n", runTask->taskName);
- PRINTK("runTask->taskID = %u\n", runTask->taskID);
+ PrintExcInfo("OsBackTrace fp = 0x%x\n", regFP);
+ PrintExcInfo("runTask->taskName = %s\n", runTask->taskName);
+ PrintExcInfo("runTask->taskID = %u\n", runTask->taskID);
BackTrace(regFP);
}
@@ -1005,6 +1006,35 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
#endif
}
}
+
+#if (LOSCFG_KERNEL_SMP == YES)
+#ifdef LOSCFG_FS_VFS
+ /* Wait for the end of the Console task to avoid multicore printing code */
+ OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID);
+#endif
+#endif
+}
+
+LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
+{
+#ifdef LOSCFG_DEBUG_VERSION
+ LosVmSpace *space = NULL;
+ VADDR_T vaddr;
+#endif
+
+ /* You are not allowed to add any other print information before this exception information */
+ if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
+#ifdef LOSCFG_DEBUG_VERSION
+ vaddr = ROUNDDOWN(far, PAGE_SIZE);
+ space = LOS_SpaceGet(vaddr);
+ if (space != NULL) {
+ LOS_DumpMemRegion(vaddr);
+ }
+#endif
+ PrintExcInfo("##################excFrom: User!####################\n");
+ } else {
+ PrintExcInfo("##################excFrom: kernel!###################\n");
+ }
}
/*
@@ -1021,19 +1051,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsExcPriorDisposal(excBufAddr);
-#if (LOSCFG_KERNEL_SMP == YES)
-#ifdef LOSCFG_FS_VFS
- /* Wait for the end of the Console task to avoid multicore printing code */
- OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID);
-#endif
-#endif
-
- /* You are not allowed to add any other print information before this exception information */
- if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
- PrintExcInfo("##################excFrom: User!####################\n");
- } else {
- PrintExcInfo("##################excFrom: kernel###################!\n");
- }
+ OsPrintExcHead(far);
#if (LOSCFG_KERNEL_SMP == YES)
OsAllCpuStatusOutput();
@@ -1070,6 +1088,15 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
#ifdef LOSCFG_EXC_INTERACTION
OsExcInteractionTaskKeep();
#endif
+
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+ SystemRebootFunc rebootHook = OsGetRebootHook();
+ if ((OsSystemExcIsReset() == TRUE) && (rebootHook != NULL)) {
+ LOS_Mdelay(3000); /* 3000: System dead, delay 3 seconds after system restart */
+ rebootHook();
+ }
+#endif
+
while (1) {}
}
@@ -1092,6 +1119,46 @@ VOID __stack_chk_fail(VOID)
__builtin_return_address(0));
}
+VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount)
+{
+ UINT32 count = 0;
+ UINT32 index = 0;
+ UINT32 stackStart, stackEnd;
+ LosTaskCB *taskCB = NULL;
+ UINTPTR framePtr, tmpFramePtr, linkReg;
+
+ if (LR == NULL) {
+ return;
+ }
+ /* if LR array is not enough,just record LRSize. */
+ if (LRSize < recordCount) {
+ recordCount = LRSize;
+ }
+
+ taskCB = OsCurrTaskGet();
+ stackStart = taskCB->topOfStack;
+ stackEnd = stackStart + taskCB->stackSize;
+
+ framePtr = Get_Fp();
+ while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) {
+ tmpFramePtr = framePtr;
+ linkReg = *(UINTPTR *)framePtr;
+ if (index >= jumpCount) {
+ LR[count++] = linkReg;
+ if (count == recordCount) {
+ break;
+ }
+ }
+ index++;
+ framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
+ }
+
+ /* if linkReg is not enough,clean up the last of the effective LR as the end. */
+ if (count < recordCount) {
+ LR[count] = 0;
+ }
+}
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/arch/arm/arm/src/los_hw.c b/arch/arm/arm/src/los_hw.c
old mode 100644
new mode 100755
index dbc24d2c..800bf1b9
--- a/arch/arm/arm/src/los_hw.c
+++ b/arch/arm/arm/src/los_hw.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/los_hw_exc.S b/arch/arm/arm/src/los_hw_exc.S
old mode 100644
new mode 100755
index 1dc3cf52..5dd00c78
--- a/arch/arm/arm/src/los_hw_exc.S
+++ b/arch/arm/arm/src/los_hw_exc.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/los_hw_runstop.S b/arch/arm/arm/src/los_hw_runstop.S
index 032e9af1..b8f8cf74 100644
--- a/arch/arm/arm/src/los_hw_runstop.S
+++ b/arch/arm/arm/src/los_hw_runstop.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/los_hw_tick.c b/arch/arm/arm/src/los_hw_tick.c
index b52f346c..b53bdfa2 100644
--- a/arch/arm/arm/src/los_hw_tick.c
+++ b/arch/arm/arm/src/los_hw_tick.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/los_hwi.c b/arch/arm/arm/src/los_hwi.c
index 733fc010..5bac5895 100644
--- a/arch/arm/arm/src/los_hwi.c
+++ b/arch/arm/arm/src/los_hwi.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,11 +31,11 @@
#include "los_hwi.h"
#include "los_memory.h"
-#include "los_tickless_pri.h"
#include "los_spinlock.h"
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -68,6 +68,11 @@ CHAR *OsGetHwiFormName(UINT32 index)
return g_hwiFormName[index];
}
+UINT32 LOS_GetSystemHwiMaximum(VOID)
+{
+ return OS_HWI_MAX_NUM;
+}
+
typedef VOID (*HWI_PROC_FUNC0)(VOID);
typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *);
VOID OsInterrupt(UINT32 intNum)
@@ -75,16 +80,16 @@ VOID OsInterrupt(UINT32 intNum)
HwiHandleForm *hwiForm = NULL;
UINT32 *intCnt = NULL;
+ /* Must keep the operation at the beginning of the interface */
intCnt = &g_intCount[ArchCurrCpuid()];
*intCnt = *intCnt + 1;
+ OsSchedIrqStartTime();
+
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqStart();
#endif
-#ifdef LOSCFG_KERNEL_TICKLESS
- OsTicklessUpdate(intNum);
-#endif
hwiForm = (&g_hwiForm[intNum]);
#ifndef LOSCFG_NO_SHARED_IRQ
while (hwiForm->pstNext != NULL) {
@@ -107,10 +112,13 @@ VOID OsInterrupt(UINT32 intNum)
#endif
++g_hwiFormCnt[intNum];
- *intCnt = *intCnt - 1;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqEnd(intNum);
#endif
+ OsSchedIrqUpdateUsedTime();
+
+ /* Must keep the operation at the end of the interface */
+ *intCnt = *intCnt - 1;
}
STATIC HWI_ARG_T OsHwiCpIrqParam(const HwiIrqParam *irqParam)
diff --git a/arch/arm/arm/src/startup/reset_vector_mp.S b/arch/arm/arm/src/startup/reset_vector_mp.S
old mode 100644
new mode 100755
index dc08b6dc..cec87786
--- a/arch/arm/arm/src/startup/reset_vector_mp.S
+++ b/arch/arm/arm/src/startup/reset_vector_mp.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -112,6 +112,20 @@ __exception_handlers:
/* Startup code which will get the machine into supervisor mode */
.global reset_vector
.type reset_vector,function
+
+#ifdef LOSCFG_QUICK_START
+__quickstart_args_start:
+ .fill 512,1,0
+__quickstart_args_end:
+
+.global OsGetArgsAddr
+.type OsGetArgsAddr,function
+
+OsGetArgsAddr:
+ ldr r0, =__quickstart_args_start
+ bx lr
+#endif
+
reset_vector:
/* clear register TPIDRPRW */
mov r0, #0
@@ -122,6 +136,20 @@ reset_vector:
bic r0, #(1<<2 | 1<<0)
mcr p15, 0, r0, c1, c0, 0
+ /* enable fpu+neon */
+#ifndef LOSCFG_TEE_ENABLE
+ MRC p15, 0, r0, c1, c1, 2
+ ORR r0, r0, #0xC00
+ BIC r0, r0, #0xC000
+ MCR p15, 0, r0, c1, c1, 2
+
+ LDR r0, =(0xF << 20)
+ MCR p15, 0, r0, c1, c0, 2
+ ISB
+#endif
+ MOV r3, #0x40000000
+ VMSR FPEXC, r3
+
/* r11: delta of physical address and virtual address */
adr r11, pa_va_offset
ldr r0, [r11]
@@ -156,10 +184,13 @@ reloc_img_to_bottom_loop:
reloc_img_to_bottom_done:
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
add r4, r4, r11
- bl page_table_clear
+ mov r0, r4
+ mov r1, #0
+ mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS
+ bl memset
PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
- PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
+ PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_NORMAL_NOCACHE
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
@@ -169,7 +200,6 @@ reloc_img_to_bottom_done:
add r4, r4, r11
ldr r4, [r4]
add r4, r4, r11 /* r4: jump pagetable paddr */
- bl page_table_clear
/* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */
mov r6, pc
@@ -233,20 +263,6 @@ warm_reset:
sub r0, r0, r2
mov sp, r0
- /* enable fpu+neon */
-#ifndef LOSCFG_TEE_ENABLE
- MRC p15, 0, r0, c1, c1, 2
- ORR r0, r0, #0xC00
- BIC r0, r0, #0xC000
- MCR p15, 0, r0, c1, c1, 2
-
- LDR r0, =(0xF << 20)
- MCR p15, 0, r0, c1, c0, 2
-#endif
-
- MOV r3, #0x40000000
- VMSR FPEXC, r3
-
LDR r0, =__exception_handlers
MCR p15, 0, r0, c12, c0, 0
@@ -254,14 +270,11 @@ warm_reset:
bne cpu_start
clear_bss:
- ldr r1, =__bss_start
+ ldr r0, =__bss_start
ldr r2, =__bss_end
- mov r0, #0
-
-bss_loop:
- cmp r1, r2
- strlo r0, [r1], #4
- blo bss_loop
+ mov r1, #0
+ sub r2, r2, r0
+ bl memset
#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
@@ -371,20 +384,6 @@ sp_set:
mov sp, r2
bx lr /* set sp */
-/*
- * r4: page table base address
- * r5 and r6 will be used as variable
- */
-page_table_clear:
- mov r5, #0
- mov r6, #0
-0:
- str r5, [r4, r6, lsl #2]
- add r6, #1
- cmp r6, #0x1000 /* r6 < 4096 */
- blt 0b
- bx lr
-
/*
* r4: page table base address
* r6: physical address
diff --git a/arch/arm/arm/src/startup/reset_vector_up.S b/arch/arm/arm/src/startup/reset_vector_up.S
old mode 100644
new mode 100755
index d7de4777..63ac5764
--- a/arch/arm/arm/src/startup/reset_vector_up.S
+++ b/arch/arm/arm/src/startup/reset_vector_up.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -53,7 +53,6 @@
.extern __bss_start
.extern __bss_end
.extern hal_clock_initialize_start
- .extern los_bss_init
.extern _osExceptFiqHdl
.extern _osExceptAddrAbortHdl
.extern _osExceptDataAbortHdl
@@ -119,6 +118,20 @@ reset_vector:
bic r0, #(1<<2 | 1<<0)
mcr p15, 0, r0, c1, c0, 0
+ /* enable fpu+neon */
+#ifndef LOSCFG_TEE_ENABLE
+ MRC p15, 0, r0, c1, c1, 2
+ ORR r0, r0, #0xC00
+ BIC r0, r0, #0xC000
+ MCR p15, 0, r0, c1, c1, 2
+
+ LDR r0, =(0xF << 20)
+ MCR p15, 0, r0, c1, c0, 2
+ ISB
+#endif
+ MOV r3, #0x40000000
+ VMSR FPEXC, r3
+
/* r11: delta of physical address and virtual address */
adr r11, pa_va_offset
ldr r0, [r11]
@@ -148,10 +161,14 @@ reloc_img_to_bottom_loop:
reloc_img_to_bottom_done:
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
add r4, r4, r11
- bl page_table_clear
+ mov r0, r4
+ mov r1, #0
+ mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS
+ bl memset
+
PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
- PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
+ PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_NORMAL_NOCACHE
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
@@ -161,7 +178,6 @@ reloc_img_to_bottom_done:
add r4, r4, r11
ldr r4, [r4]
add r4, r4, r11 /* r4: jump pagetable paddr */
- bl page_table_clear
/* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */
mov r6, pc
@@ -246,14 +262,11 @@ warm_reset:
bne cpu_start
clear_bss:
- ldr r1, =__bss_start
+ ldr r0, =__bss_start
ldr r2, =__bss_end
- mov r0, #0
-
-bss_loop:
- cmp r1, r2
- strlo r0, [r1], #4
- blo bss_loop
+ mov r1, #0
+ sub r2, r2, r0
+ bl memset
#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
@@ -339,20 +352,6 @@ sp_set:
mov sp, r2
bx lr /* set sp */
-/*
- * r4: page table base address
- * r5 and r6 will be used as variable
- */
-page_table_clear:
- mov r5, #0
- mov r6, #0
-0:
- str r5, [r4, r6, lsl #2]
- add r6, #1
- cmp r6, #0x1000 /* r6 < 4096 */
- blt 0b
- bx lr
-
/*
* r4: page table base address
* r6: physical address
diff --git a/arch/arm/arm/src/strncpy_from_user.c b/arch/arm/arm/src/strncpy_from_user.c
old mode 100644
new mode 100755
index 0e307f64..352b9310
--- a/arch/arm/arm/src/strncpy_from_user.c
+++ b/arch/arm/arm/src/strncpy_from_user.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/strnlen_user.c b/arch/arm/arm/src/strnlen_user.c
old mode 100644
new mode 100755
index b34d090b..4da0bf49
--- a/arch/arm/arm/src/strnlen_user.c
+++ b/arch/arm/arm/src/strnlen_user.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/arm/src/user_copy.c b/arch/arm/arm/src/user_copy.c
old mode 100644
new mode 100755
index 13e23baa..f1016f00
--- a/arch/arm/arm/src/user_copy.c
+++ b/arch/arm/arm/src/user_copy.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/in_cksum.h b/arch/arm/include/in_cksum.h
old mode 100644
new mode 100755
index 8920b1df..e86c4966
--- a/arch/arm/include/in_cksum.h
+++ b/arch/arm/include/in_cksum.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_exc.h b/arch/arm/include/los_exc.h
old mode 100644
new mode 100755
index 62cbe6ff..807bcb2f
--- a/arch/arm/include/los_exc.h
+++ b/arch/arm/include/los_exc.h
@@ -1,233 +1,251 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * @defgroup los_exc Exception handling
- * @ingroup kernel
- */
-#ifndef _LOS_EXC_H
-#define _LOS_EXC_H
-
-#include "los_typedef.h"
-#include "arch_config.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-/**
- * @ingroup los_exc
- * Register information structure
- *
- * Description: register information stored when an exception occurs on an LPC2458 platform.
- *
- * Note: The following register names without uw are the register names used in the chip manual.
- */
-#ifdef LOSCFG_ARCH_ARM_AARCH64
-#define EXC_GEN_REGS_NUM 30
-typedef struct {
- UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */
- UINT64 LR; /**< Program returning address. X30 */
- UINT64 SP;
- UINT64 regELR;
- UINT64 SPSR;
-} ExcContext;
-#else
-typedef struct {
- UINT32 USP; /**< User mode stack pointer */
- UINT32 ULR; /**< User mode program returning address */
- UINT32 regCPSR; /**< Current program status register (CPSR) */
- UINT32 R0; /**< Register R0 */
- UINT32 R1; /**< Register R1 */
- UINT32 R2; /**< Register R2 */
- UINT32 R3; /**< Register R3 */
- UINT32 R4; /**< Register R4 */
- UINT32 R5; /**< Register R5 */
- UINT32 R6; /**< Register R6 */
- UINT32 R7; /**< Register R7 */
- UINT32 R8; /**< Register R8 */
- UINT32 R9; /**< Register R9 */
- UINT32 R10; /**< Register R10 */
- UINT32 R11; /**< Register R11 */
- UINT32 R12; /**< Register R12 */
- UINT32 SP; /**< Stack pointer */
- UINT32 LR; /**< Program returning address. */
- UINT32 PC; /**< PC pointer of the exceptional function */
-} ExcContext;
-#endif
-
-/**
- * @ingroup los_exc
- * Exception information structure
- *
- * Description: exception information stored when an exception occurs on an LPC2458 platform.
- *
- */
-typedef struct {
- UINT16 phase; /**< Phase in which an exception occurs */
- UINT16 type; /**< Exception type */
- UINT16 nestCnt; /**< Count of nested exception */
- UINT16 reserved; /**< Reserved for alignment */
- ExcContext *context; /**< Hardware context when an exception occurs */
-} ExcInfo;
-
-/**
- * @ingroup los_exc
- * @brief Kernel FP Register address obtain function.
- *
- * @par Description:
- * The API is used to obtain the FP Register address.
- * @attention None.
- *
- * @param None.
- *
- * @retval #UINTPTR The FP Register address.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-STATIC INLINE UINTPTR Get_Fp(VOID)
-{
- UINTPTR regFp;
-
-#ifdef LOSCFG_ARCH_ARM_AARCH64
- __asm__ __volatile__("mov %0, X29" : "=r"(regFp));
-#else
- __asm__ __volatile__("mov %0, fp" : "=r"(regFp));
-#endif
-
- return regFp;
-}
-
-/**
- * @ingroup los_exc
- * @brief Define an exception handling function hook.
- *
- * @par Description:
- * This API is used to define the exception handling function hook based on the type of
- * the exception handling function and record exceptions.
- * @attention None.
- *
- * @param None.
- *
- * @retval None.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32);
-
-/**
- * @ingroup los_exc
- * @brief Register an exception handling hook.
- *
- * @par Description:
- * This API is used to register an exception handling hook.
- * @attention If the hook is registered for multiple times, the hook registered at the last time is effective.
- * @attention The hook can be registered as NULL, indicating that the hook registration is canceled.
- * @param excHook [IN] Type #EXC_PROC_FUNC: hook function.
- *
- * @retval #LOS_OK The exception handling hook is successfully registered.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook);
-
-/**
- * @ingroup los_exc
- * @brief Kernel panic function.
- *
- * @par Description:
- * Stack function that prints kernel panics.
- * @attention After this function is called and stack information is printed, the system will fail to respond.
- * @attention The input parameter can be NULL.
- * @param fmt [IN] Type #CHAR* : variadic argument.
- *
- * @retval #None.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-VOID LOS_Panic(const CHAR *fmt, ...);
-
-/**
- * @ingroup los_exc
- * @brief Kernel backtrace function.
- *
- * @par Description:
- * Backtrace function that prints task call stack information traced from the running task.
- * @attention None.
- *
- * @param None.
- *
- * @retval #None.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID OsBackTrace(VOID);
-
-/**
- * @ingroup los_exc
- * @brief Kernel task backtrace function.
- *
- * @par Description:
- * Backtrace function that prints task call stack information traced from the input task.
- * @attention
- *
- * The input taskID should be valid.
- *
- *
- * @param taskID [IN] Type #UINT32 Task ID.
- *
- * @retval #None.
- *
- * @par Dependency:
- * los_exc.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID OsTaskBackTrace(UINT32 taskID);
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif /* _LOS_EXC_H */
+/*
+ * 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_exc Exception handling
+ * @ingroup kernel
+ */
+#ifndef _LOS_EXC_H
+#define _LOS_EXC_H
+
+#include "los_typedef.h"
+#include "arch_config.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+/**
+ * @ingroup los_exc
+ * Register information structure
+ *
+ * Description: register information stored when an exception occurs on an LPC2458 platform.
+ *
+ * Note: The following register names without uw are the register names used in the chip manual.
+ */
+#ifdef LOSCFG_ARCH_ARM_AARCH64
+#define EXC_GEN_REGS_NUM 30
+typedef struct {
+ UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */
+ UINT64 LR; /**< Program returning address. X30 */
+ UINT64 SP;
+ UINT64 regELR;
+ UINT64 SPSR;
+} ExcContext;
+#else
+typedef struct {
+ UINT32 USP; /**< User mode stack pointer */
+ UINT32 ULR; /**< User mode program returning address */
+ UINT32 regCPSR; /**< Current program status register (CPSR) */
+ UINT32 R0; /**< Register R0 */
+ UINT32 R1; /**< Register R1 */
+ UINT32 R2; /**< Register R2 */
+ UINT32 R3; /**< Register R3 */
+ UINT32 R4; /**< Register R4 */
+ UINT32 R5; /**< Register R5 */
+ UINT32 R6; /**< Register R6 */
+ UINT32 R7; /**< Register R7 */
+ UINT32 R8; /**< Register R8 */
+ UINT32 R9; /**< Register R9 */
+ UINT32 R10; /**< Register R10 */
+ UINT32 R11; /**< Register R11 */
+ UINT32 R12; /**< Register R12 */
+ UINT32 SP; /**< Stack pointer */
+ UINT32 LR; /**< Program returning address. */
+ UINT32 PC; /**< PC pointer of the exceptional function */
+} ExcContext;
+#endif
+
+/**
+ * @ingroup los_exc
+ * Exception information structure
+ *
+ * Description: exception information stored when an exception occurs on an LPC2458 platform.
+ *
+ */
+typedef struct {
+ UINT16 phase; /**< Phase in which an exception occurs */
+ UINT16 type; /**< Exception type */
+ UINT16 nestCnt; /**< Count of nested exception */
+ UINT16 reserved; /**< Reserved for alignment */
+ ExcContext *context; /**< Hardware context when an exception occurs */
+} ExcInfo;
+
+/**
+ * @ingroup los_exc
+ * @brief Kernel FP Register address obtain function.
+ *
+ * @par Description:
+ * The API is used to obtain the FP Register address.
+ * @attention None.
+ *
+ * @param None.
+ *
+ * @retval #UINTPTR The FP Register address.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+STATIC INLINE UINTPTR Get_Fp(VOID)
+{
+ UINTPTR regFp;
+
+#ifdef LOSCFG_ARCH_ARM_AARCH64
+ __asm__ __volatile__("mov %0, X29" : "=r"(regFp));
+#else
+ __asm__ __volatile__("mov %0, fp" : "=r"(regFp));
+#endif
+
+ return regFp;
+}
+
+/**
+ * @ingroup los_exc
+ * @brief Define an exception handling function hook.
+ *
+ * @par Description:
+ * This API is used to define the exception handling function hook based on the type of
+ * the exception handling function and record exceptions.
+ * @attention None.
+ *
+ * @param None.
+ *
+ * @retval None.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32);
+
+/**
+ * @ingroup los_exc
+ * @brief Register an exception handling hook.
+ *
+ * @par Description:
+ * This API is used to register an exception handling hook.
+ * @attention If the hook is registered for multiple times, the hook registered at the last time is effective.
+ * @attention The hook can be registered as NULL, indicating that the hook registration is canceled.
+ * @param excHook [IN] Type #EXC_PROC_FUNC: hook function.
+ *
+ * @retval #LOS_OK The exception handling hook is successfully registered.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook);
+
+/**
+ * @ingroup los_exc
+ * @brief Kernel panic function.
+ *
+ * @par Description:
+ * Stack function that prints kernel panics.
+ * @attention After this function is called and stack information is printed, the system will fail to respond.
+ * @attention The input parameter can be NULL.
+ * @param fmt [IN] Type #CHAR* : variadic argument.
+ *
+ * @retval #None.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+VOID LOS_Panic(const CHAR *fmt, ...);
+
+/**
+ * @ingroup los_exc
+ * @brief record LR function.
+ *
+ * @par Description:
+ * @attention
+ * @param LR [IN] Type #UINTPTR * LR buffer.
+ * @param recordCount [IN] Type UINT32 record LR lay number.
+ * @param jumpCount [IN] Type UINT32 ignore LR lay number.
+ *
+ * @retval #None.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount);
+
+/**
+ * @ingroup los_exc
+ * @brief Kernel backtrace function.
+ *
+ * @par Description:
+ * Backtrace function that prints task call stack information traced from the running task.
+ * @attention None.
+ *
+ * @param None.
+ *
+ * @retval #None.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+extern VOID OsBackTrace(VOID);
+
+/**
+ * @ingroup los_exc
+ * @brief Kernel task backtrace function.
+ *
+ * @par Description:
+ * Backtrace function that prints task call stack information traced from the input task.
+ * @attention
+ *
+ * The input taskID should be valid.
+ *
+ *
+ * @param taskID [IN] Type #UINT32 Task ID.
+ *
+ * @retval #None.
+ *
+ * @par Dependency:
+ * los_exc.h: the header file that contains the API declaration.
+ * @see None.
+ */
+extern VOID OsTaskBackTrace(UINT32 taskID);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _LOS_EXC_H */
diff --git a/arch/arm/include/los_hw.h b/arch/arm/include/los_hw.h
old mode 100644
new mode 100755
index c9d5825c..ad30d5a1
--- a/arch/arm/include/los_hw.h
+++ b/arch/arm/include/los_hw.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_hw_arch.h b/arch/arm/include/los_hw_arch.h
index f7bd812a..3539d928 100644
--- a/arch/arm/include/los_hw_arch.h
+++ b/arch/arm/include/los_hw_arch.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_hw_tick_pri.h b/arch/arm/include/los_hw_tick_pri.h
index 98a7296b..1b893176 100644
--- a/arch/arm/include/los_hw_tick_pri.h
+++ b/arch/arm/include/los_hw_tick_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_hwi.h b/arch/arm/include/los_hwi.h
old mode 100644
new mode 100755
index b8bcadb9..cee783dc
--- a/arch/arm/include/los_hwi.h
+++ b/arch/arm/include/los_hwi.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -339,6 +339,23 @@ STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
ArchIntRestore(intSave);
}
+/**
+ * @ingroup los_hwi
+ * @brief Gets the maximum number of interrupts supported by the system.
+ *
+ * @par Description:
+ *
+ * This API is used to gets the maximum number of interrupts supported by the system.
+ *
+ *
+ * @param None.
+ *
+ * @retval None.
+ * @par Dependency:
+ * los_hwi.h: the header file that contains the API declaration.
+ */
+extern UINT32 LOS_GetSystemHwiMaximum(VOID);
+
/**
* @ingroup los_hwi
* @brief Create a hardware interrupt.
diff --git a/arch/arm/include/los_strncpy_from_user.h b/arch/arm/include/los_strncpy_from_user.h
old mode 100644
new mode 100755
index 764be8a2..58d68d9b
--- a/arch/arm/include/los_strncpy_from_user.h
+++ b/arch/arm/include/los_strncpy_from_user.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_strnlen_user.h b/arch/arm/include/los_strnlen_user.h
old mode 100644
new mode 100755
index 5c90d590..29c3e679
--- a/arch/arm/include/los_strnlen_user.h
+++ b/arch/arm/include/los_strnlen_user.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_sys_stack_pri.h b/arch/arm/include/los_sys_stack_pri.h
index 0dbc46d1..e45e4a66 100644
--- a/arch/arm/include/los_sys_stack_pri.h
+++ b/arch/arm/include/los_sys_stack_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_user_get.h b/arch/arm/include/los_user_get.h
old mode 100644
new mode 100755
index 883d299e..2ce55a01
--- a/arch/arm/include/los_user_get.h
+++ b/arch/arm/include/los_user_get.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/los_user_put.h b/arch/arm/include/los_user_put.h
old mode 100644
new mode 100755
index bec15dae..c0251623
--- a/arch/arm/include/los_user_put.h
+++ b/arch/arm/include/los_user_put.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/arm/include/user_copy.h b/arch/arm/include/user_copy.h
old mode 100644
new mode 100755
index 955634ec..293d4e34
--- a/arch/arm/include/user_copy.h
+++ b/arch/arm/include/user_copy.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/arch/cpu.mk b/arch/cpu.mk
index c1af11ac..856099ef 100644
--- a/arch/cpu.mk
+++ b/arch/cpu.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/bsd/Kconfig b/bsd/Kconfig
old mode 100644
new mode 100755
diff --git a/bsd/Makefile b/bsd/Makefile
index 9540092d..a5c0d1ff 100644
--- a/bsd/Makefile
+++ b/bsd/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/bsd/compat/linuxkpi/Makefile b/bsd/compat/linuxkpi/Makefile
old mode 100644
new mode 100755
index be7ffc70..1b270ae1
--- a/bsd/compat/linuxkpi/Makefile
+++ b/bsd/compat/linuxkpi/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/bsd/dev/usb/Kconfig b/bsd/dev/usb/Kconfig
old mode 100644
new mode 100755
diff --git a/bsd/dev/usb/Makefile b/bsd/dev/usb/Makefile
old mode 100644
new mode 100755
index 5eaa4120..a0fb6e88
--- a/bsd/dev/usb/Makefile
+++ b/bsd/dev/usb/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -28,6 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk
+include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := usb_base
@@ -120,12 +121,20 @@ ifeq ($(LOSCFG_DRIVERS_USB_MASS_STORAGE), y)
LOCAL_SRCS += $(STORAGE_SRC)/umass.c
endif
-ifeq ($(LOSCFG_DRIVERS_USB_HID_CLASS), y)
+ifeq ($(LOSCFG_DRIVERS_USB_HID_CLASS)_$(LOSCFG_DRIVERS_HDF_INPUT), y_y)
+LOCAL_FLAGS += -I$(LITEOSTOPDIR)/../../drivers/framework/model/input/driver \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/include/core \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/core/common/include/host \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/utils \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/osal \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/ability/sbuf/include \
+ -I$(LITEOSTOPDIR)/../../drivers/framework/include/osal \
+ -I$(LITEOSTOPDIR)/../../third_party/FreeBSD/sys/dev/evdev
+
LOCAL_SRCS += $(INPUT_SRC)/uhid.c \
$(CORE_SRC)/usb_hid.c
endif
LOCAL_FLAGS += $(LITEOS_GCOV_OPTS)
-include $(MODULE)
-
+include $(HDF_DRIVER)
diff --git a/build.sh b/build.sh
index bcdf9009..6ad37db5 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -30,20 +30,26 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
-echo "sh param:$1,$2,$3"
-source="tools/build/config/$1_release.config"
+echo "sh param:$1,$2,$3,$4,$5,$6,$7"
destination=".config"
+tee=""
+outdir="../..$3/test_info/gen/kernel/test"
+if [ "$5" = "tee" ]; then
+ tee="_tee"
+fi
+productName="$(basename $7)"
+source="tools/build/config/${productName}_release.config"
if [ "$2" = "clang" ]; then
- if [ "$3" = "debug" ]; then
- source="tools/build/config/debug/$1_$2.config"
+ if [ "$4" = "debug" ]; then
+ source="tools/build/config/debug/${productName}_$2$tee.config"
else
- source="tools/build/config/$1_$2_release.config"
+ source="tools/build/config/${productName}_$2_release$tee.config"
fi
elif [ "$2" = "gcc" ]; then
- if [ "$3" = "debug" ]; then
- source="tools/build/config/$1_debug_shell.config"
+ if [ "$4" = "debug" ]; then
+ source="tools/build/config/${productName}_debug_shell$tee.config"
else
- source="tools/build/config/$1_release.config"
+ source="tools/build/config/${productName}_release$tee.config"
fi
fi
if [ -d "./out" ]; then
@@ -53,3 +59,7 @@ if [ -f "$destination" ]; then
rm -rf $destination
fi
cp $source $destination
+
+mkdir -p $outdir
+cp kernel_test.sources $outdir
+
diff --git a/compat/posix/Kconfig b/compat/posix/Kconfig
old mode 100644
new mode 100755
diff --git a/compat/posix/Makefile b/compat/posix/Makefile
index 02c6cc9f..c9cd39b0 100644
--- a/compat/posix/Makefile
+++ b/compat/posix/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/compat/posix/include/mqueue.h b/compat/posix/include/mqueue.h
old mode 100644
new mode 100755
index c32b158d..eb58bd06
--- a/compat/posix/include/mqueue.h
+++ b/compat/posix/include/mqueue.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -43,6 +43,9 @@
#include "limits.h"
#include "los_typedef.h"
#include "time.h"
+#include
+#include
+#include
#include "los_queue_pri.h"
@@ -71,11 +74,23 @@ extern "C" {
/* not suppurt prio */
#define MQ_PRIO_MAX 1
+typedef union send_receive_t {
+ unsigned oth : 3;
+ unsigned grp : 6;
+ unsigned usr : 9;
+ short data;
+} mode_s;
+
/* TYPE DEFINITIONS */
struct mqarray {
UINT32 mq_id : 31;
UINT32 unlinkflag : 1;
char *mq_name;
+ UINT32 unlink_ref;
+ mode_s mode_data; /* mode data of mqueue */
+ uid_t euid; /* euid of mqueue */
+ gid_t egid; /* egid of mqueue */
+ fd_set mq_fdset; /* mqueue sysFd bit map */
LosQueueCB *mqcb;
struct mqpersonal *mq_personal;
};
@@ -84,7 +99,9 @@ struct mqpersonal {
struct mqarray *mq_posixdes;
struct mqpersonal *mq_next;
int mq_flags;
+ int mq_mode; /* Mode of mqueue */
UINT32 mq_status;
+ UINT32 mq_refcount;
};
/**
@@ -400,6 +417,8 @@ extern int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen,
extern ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen,
unsigned int *msgPrio, const struct timespec *absTimeout);
+extern void mqueue_refer(int sysFd);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/compat/posix/include/time_posix.h b/compat/posix/include/time_posix.h
old mode 100644
new mode 100755
index 0665d21b..6f8f537d
--- a/compat/posix/include/time_posix.h
+++ b/compat/posix/include/time_posix.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/map_error.c b/compat/posix/src/map_error.c
index d2cdf013..31435f7d 100644
--- a/compat/posix/src/map_error.c
+++ b/compat/posix/src/map_error.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/map_error.h b/compat/posix/src/map_error.h
index 4731a32c..935b2d5e 100644
--- a/compat/posix/src/map_error.h
+++ b/compat/posix/src/map_error.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/misc.c b/compat/posix/src/misc.c
old mode 100644
new mode 100755
index 98152931..3e623674
--- a/compat/posix/src/misc.c
+++ b/compat/posix/src/misc.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/mqueue.c b/compat/posix/src/mqueue.c
old mode 100644
new mode 100755
index 0aa2705d..588ae112
--- a/compat/posix/src/mqueue.c
+++ b/compat/posix/src/mqueue.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,6 +36,8 @@
#include "time_posix.h"
#include "los_memory.h"
#include "los_vm_map.h"
+#include "los_process_pri.h"
+#include "fs_file.h"
#include "user_copy.h"
#ifdef __cplusplus
@@ -46,9 +48,14 @@ extern "C" {
#define FNONBLOCK O_NONBLOCK
+#ifndef MAX_MQ_FD
+#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
+#endif
+
/* GLOBALS */
STATIC struct mqarray g_queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
STATIC pthread_mutex_t g_mqueueMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+STATIC struct mqpersonal *g_mqPrivBuf[MAX_MQ_FD];
/* LOCAL FUNCTIONS */
STATIC INLINE INT32 MqNameCheck(const CHAR *mqName)
@@ -100,7 +107,6 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
return &(g_queueTable[index]);
}
}
-
return NULL;
}
@@ -114,6 +120,10 @@ STATIC INT32 DoMqueueDelete(struct mqarray *mqueueCB)
}
mqueueCB->mqcb = NULL;
+ /* When mqueue-list head node needed free ,reset the mode_data */
+ mqueueCB->mode_data.data = 0;
+ mqueueCB->euid = -1;
+ mqueueCB->egid = -1;
ret = LOS_QueueDelete(mqueueCB->mq_id);
switch (ret) {
@@ -152,7 +162,7 @@ STATIC int SaveMqueueName(const CHAR *mqName, struct mqarray *mqueueCB)
return LOS_OK;
}
-STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag)
+STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag, UINT32 mode)
{
struct mqarray *mqueueCB = NULL;
UINT32 mqueueID;
@@ -191,10 +201,13 @@ STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR
}
mqueueCB->unlinkflag = FALSE;
+ mqueueCB->unlink_ref = 0;
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
mqueueCB->mq_personal->mq_next = NULL;
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
+ mqueueCB->mq_personal->mq_mode = mode;
+ mqueueCB->mq_personal->mq_refcount = 0;
return mqueueCB->mq_personal;
ERROUT:
@@ -228,6 +241,7 @@ STATIC struct mqpersonal *DoMqueueOpen(struct mqarray *mqueueCB, INT32 openFlag)
privateMqPersonal->mq_posixdes = mqueueCB;
privateMqPersonal->mq_flags = openFlag;
privateMqPersonal->mq_status = MQ_USE_MAGIC;
+ privateMqPersonal->mq_refcount = 0;
return privateMqPersonal;
@@ -235,14 +249,226 @@ ERROUT:
return (struct mqpersonal *)-1;
}
+/* Translate a sysFd into privateMqPersonal */
+STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
+{
+ INT32 sysFd = (INT32)personal;
+ INT32 id = sysFd - MQUEUE_FD_OFFSET;
+
+ /* Filter illegal id */
+ if ((id < 0) || (id >= MAX_MQ_FD)) {
+ errno = EBADF;
+ return NULL;
+ }
+ return g_mqPrivBuf[id];
+}
+
+/**
+ * Alloc sysFd, storage mq private data, set using bit.
+ *
+ * @param maxfdp: Maximum allowed application of mqueue sysFd.
+ * @param fdset: Mqueue sysFd bit map.
+ * @param privateMqPersonal: Private data.
+ * @return the index of the new fd; -1 on error
+ */
+STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
+{
+ INT32 i;
+ struct mqarray *mqueueCB = privateMqPersonal->mq_posixdes;
+ fd_set *fdset = &mqueueCB->mq_fdset;
+ for (i = 0; i < maxfdp; i++) {
+ /* sysFd: used bit setting, and get the index of swtmrID buffer */
+ if (!(fdset && FD_ISSET(i + MQUEUE_FD_OFFSET, fdset))) {
+ FD_SET(i + MQUEUE_FD_OFFSET, fdset);
+ if (!g_mqPrivBuf[i]) {
+ g_mqPrivBuf[i] = mqueueCB->mq_personal;
+ return i + MQUEUE_FD_OFFSET;
+ }
+ }
+ }
+ /* there are no more mq sysFd to use, free the personal */
+ LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal);
+ privateMqPersonal = NULL;
+ mqueueCB->mq_personal = NULL;
+ return -1;
+}
+
+STATIC VOID MqFreeSysFd(struct mqarray *mqueueCB, mqd_t personal)
+{
+ INT32 sysFd = (INT32)personal;
+ fd_set *fdset = &mqueueCB->mq_fdset;
+ if (fdset && FD_ISSET(sysFd, fdset)) {
+ FD_CLR(sysFd, fdset);
+ g_mqPrivBuf[sysFd - MQUEUE_FD_OFFSET] = NULL;
+ }
+}
+
+/* Mqueue fd reference count */
+void mqueue_refer(int sysFd)
+{
+ struct mqarray *mqueueCB = NULL;
+ struct mqpersonal *privateMqPersonal = NULL;
+
+ (VOID)pthread_mutex_lock(&g_mqueueMutex);
+ /* Get the personal sysFd and reset personal fd -1 */
+ privateMqPersonal = MqGetPrivDataBuff((mqd_t)sysFd);
+ if (privateMqPersonal == NULL) {
+ goto OUT_UNLOCK;
+ }
+ mqueueCB = privateMqPersonal->mq_posixdes;
+ if (mqueueCB == NULL) {
+ goto OUT_UNLOCK;
+ }
+ privateMqPersonal->mq_refcount++;
+ mqueueCB->unlink_ref++;
+OUT_UNLOCK:
+ (VOID)pthread_mutex_unlock(&g_mqueueMutex);
+}
+
+STATIC INT32 MqTryClose(struct mqpersonal *privateMqPersonal)
+{
+ struct mqarray *mqueueCB = NULL;
+ mqueueCB = privateMqPersonal->mq_posixdes;
+ if (mqueueCB == NULL) {
+ errno = ENFILE;
+ return false;
+ }
+
+ if (privateMqPersonal->mq_refcount == 0) {
+ return TRUE;
+ }
+ privateMqPersonal->mq_refcount--;
+ return FALSE;
+}
+
+STATIC INT32 MqTryUnlink(struct mqarray *mqueueCB)
+{
+ if (mqueueCB->unlink_ref == 0) {
+ return TRUE;
+ }
+ mqueueCB->unlink_ref--;
+ return FALSE;
+}
+
+/* Set the mode data bit,for consumer's mode comparing. */
+STATIC INT32 MqueueModeAnalysisSet(struct mqpersonal *privateMqPersonal)
+{
+ UINT32 mode;
+ UINT32 intSave;
+ User *user = NULL;
+ struct mqarray *mqueueCB = NULL;
+
+ if ((INT32)(UINTPTR)privateMqPersonal < 0) {
+ return -1;
+ }
+ /* Get mqueueCB of first time creating mqueue */
+ mqueueCB = privateMqPersonal->mq_posixdes;
+ if (mqueueCB == NULL) {
+ errno = ENFILE;
+ return -1;
+ }
+
+ mode = mqueueCB->mq_personal->mq_mode;
+ /* Set mqueue gid uid */
+ SCHEDULER_LOCK(intSave);
+ user = OsCurrUserGet();
+ mqueueCB->euid = user->effUserID;
+ mqueueCB->egid = user->effGid;
+ SCHEDULER_UNLOCK(intSave);
+
+ /* Set mode data bit */
+ if (mode & S_IRUSR) {
+ mqueueCB->mode_data.usr |= S_IRUSR;
+ }
+ if (mode & S_IWUSR) {
+ mqueueCB->mode_data.usr |= S_IWUSR;
+ }
+ if (mode & S_IRGRP) {
+ mqueueCB->mode_data.grp |= S_IRGRP;
+ }
+ if (mode & S_IWGRP) {
+ mqueueCB->mode_data.grp |= S_IWGRP;
+ }
+ if (mode & S_IROTH) {
+ mqueueCB->mode_data.oth |= S_IROTH;
+ }
+ if (mode & S_IWOTH) {
+ mqueueCB->mode_data.oth |= S_IWOTH;
+ }
+ return 0;
+}
+
+STATIC INT32 GetPermissionOfVisitor(struct mqarray *mqueueCB)
+{
+ uid_t euid;
+ gid_t egid;
+ UINT32 intSave;
+ User *user = NULL;
+
+ if (mqueueCB == NULL) {
+ errno = ENOENT;
+ return -EPERM;
+ }
+
+ /* Get the visitor process euid and egid */
+ SCHEDULER_LOCK(intSave);
+ user = OsCurrUserGet();
+ euid = user->effUserID;
+ egid = user->effGid;
+ SCHEDULER_UNLOCK(intSave);
+
+ /* root */
+ if (euid == 0) {
+ return ENOERR;
+ }
+ if (euid == mqueueCB->euid) { /* usr */
+ if (!((mqueueCB->mode_data.usr & S_IRUSR) || (mqueueCB->mode_data.usr & S_IWUSR))) {
+ errno = EACCES;
+ goto ERR_OUT;
+ }
+ } else if (egid == mqueueCB->egid) { /* grp */
+ if (!((mqueueCB->mode_data.grp & S_IRGRP) || (mqueueCB->mode_data.grp & S_IWGRP))) {
+ errno = EACCES;
+ goto ERR_OUT;
+ }
+ } else { /* oth */
+ if (!((mqueueCB->mode_data.oth & S_IROTH) || (mqueueCB->mode_data.oth & S_IWOTH))) {
+ errno = EACCES;
+ goto ERR_OUT;
+ }
+ }
+ return ENOERR;
+
+ERR_OUT:
+ return -EPERM;
+}
+
+STATIC INT32 GetMqueueAttr(struct mq_attr *defaultAttr, struct mq_attr *attr)
+{
+ if (attr != NULL) {
+ if (LOS_ArchCopyFromUser(defaultAttr, attr, sizeof(struct mq_attr))) {
+ errno = EFAULT;
+ return -1;
+ }
+ if ((defaultAttr->mq_maxmsg < 0) || (defaultAttr->mq_maxmsg > (long int)USHRT_MAX) ||
+ (defaultAttr->mq_msgsize < 0) || (defaultAttr->mq_msgsize > (long int)(USHRT_MAX - sizeof(UINT32)))) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ return 0;
+}
+
mqd_t mq_open(const char *mqName, int openFlag, ...)
{
struct mqarray *mqueueCB = NULL;
struct mqpersonal *privateMqPersonal = (struct mqpersonal *)-1;
struct mq_attr *attr = NULL;
struct mq_attr defaultAttr = { 0, MQ_MAX_MSG_NUM, MQ_MAX_MSG_LEN, 0 };
- int retVal;
va_list ap;
+ int sysFd;
+ mqd_t mqFd = -1;
+ unsigned int mode = 0;
if (MqNameCheck(mqName) == -1) {
return (mqd_t)-1;
@@ -259,56 +485,62 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag);
} else {
va_start(ap, openFlag);
- (VOID)va_arg(ap, int);
+ mode = va_arg(ap, unsigned int);
attr = va_arg(ap, struct mq_attr *);
va_end(ap);
- if (attr != NULL) {
- retVal = LOS_ArchCopyFromUser(&defaultAttr, attr, sizeof(struct mq_attr));
- if (retVal != 0) {
- errno = EFAULT;
- goto OUT;
- }
- if ((defaultAttr.mq_maxmsg < 0) || (defaultAttr.mq_maxmsg > (long int)USHRT_MAX) ||
- (defaultAttr.mq_msgsize < 0) || (defaultAttr.mq_msgsize > (long int)(USHRT_MAX - sizeof(UINT32)))) {
- errno = EINVAL;
- goto OUT;
- }
+ if (GetMqueueAttr(&defaultAttr, attr)) {
+ goto OUT;
}
- privateMqPersonal = DoMqueueCreate(&defaultAttr, mqName, openFlag);
+ privateMqPersonal = DoMqueueCreate(&defaultAttr, mqName, openFlag, mode);
+ }
+ /* Set mode data bit ,just for the first node */
+ if (MqueueModeAnalysisSet(privateMqPersonal)) {
+ goto OUT;
}
} else {
- if (mqueueCB == NULL) {
- errno = ENOENT;
+ if (GetPermissionOfVisitor(mqueueCB)) {
goto OUT;
}
privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag);
}
-
OUT:
+ if ((INT32)(UINTPTR)privateMqPersonal > 0) {
+ /* alloc sysFd */
+ sysFd = MqAllocSysFd(MAX_MQ_FD, privateMqPersonal);
+ if (sysFd == -1) {
+ errno = ENFILE;
+ }
+ mqFd = (mqd_t)sysFd;
+ }
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
- return (mqd_t)privateMqPersonal;
+ return mqFd;
}
int mq_close(mqd_t personal)
{
- INT32 ret = 0;
+ INT32 ret = -1;
struct mqarray *mqueueCB = NULL;
struct mqpersonal *privateMqPersonal = NULL;
struct mqpersonal *tmp = NULL;
- if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
- errno = EBADF;
- return -1;
+ (VOID)pthread_mutex_lock(&g_mqueueMutex);
+
+ /* Get the personal sysFd and reset personal fd -1 */
+ privateMqPersonal = MqGetPrivDataBuff(personal);
+ if (privateMqPersonal == NULL) {
+ goto OUT_UNLOCK;
}
- (VOID)pthread_mutex_lock(&g_mqueueMutex);
- privateMqPersonal = (struct mqpersonal *)personal;
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
goto OUT_UNLOCK;
}
-
+ /* there have other thread used the fd */
+ if (!MqTryClose(privateMqPersonal)) {
+ ret = 0;
+ goto OUT_UNLOCK;
+ }
mqueueCB = privateMqPersonal->mq_posixdes;
if (mqueueCB->mq_personal == NULL) {
errno = EBADF;
@@ -332,6 +564,7 @@ int mq_close(mqd_t personal)
}
/* flag no use */
privateMqPersonal->mq_status = 0;
+ MqFreeSysFd(mqueueCB, personal);
/* free the personal */
ret = LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal);
@@ -354,8 +587,8 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
struct mqarray *mqueueCB = NULL;
struct mqpersonal *privateMqPersonal = NULL;
- if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
- errno = EBADF;
+ privateMqPersonal = MqGetPrivDataBuff(personal);
+ if (privateMqPersonal == NULL) {
return -1;
}
@@ -365,7 +598,6 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
}
(VOID)pthread_mutex_lock(&g_mqueueMutex);
- privateMqPersonal = (struct mqpersonal *)personal;
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
@@ -385,8 +617,8 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
{
struct mqpersonal *privateMqPersonal = NULL;
- if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
- errno = EBADF;
+ privateMqPersonal = MqGetPrivDataBuff(personal);
+ if (privateMqPersonal == NULL) {
return -1;
}
@@ -396,7 +628,6 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
}
(VOID)pthread_mutex_lock(&g_mqueueMutex);
- privateMqPersonal = (struct mqpersonal *)personal;
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
@@ -404,7 +635,7 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
}
if (mqOldAttr != NULL) {
- (VOID)OsMqGetAttr((mqd_t)privateMqPersonal, mqOldAttr);
+ (VOID)OsMqGetAttr(personal, mqOldAttr);
}
privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags & (UINT32)(~FNONBLOCK)); /* clear */
@@ -438,10 +669,13 @@ int mq_unlink(const char *mqName)
errno = ENOENT;
goto ERROUT_UNLOCK;
}
-
+ if (!MqTryUnlink(mqueueCB)) {
+ (VOID)pthread_mutex_unlock(&g_mqueueMutex);
+ return 0;
+ }
if (mqueueCB->mq_personal != NULL) {
mqueueCB->unlinkflag = TRUE;
- } else {
+ } else if (mqueueCB->unlink_ref == 0) {
ret = DoMqueueDelete(mqueueCB);
}
@@ -476,8 +710,7 @@ STATIC INT32 ConvertTimeout(long flags, const struct timespec *absTimeout, UINT6
STATIC INLINE BOOL MqParamCheck(mqd_t personal, const char *msg, size_t msgLen)
{
- if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
- errno = EBADF;
+ if (personal < 0) {
return FALSE;
}
@@ -507,11 +740,14 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
struct mqpersonal *privateMqPersonal = NULL;
OS_MQ_GOTO_ERROUT_IF(!MqParamCheck(personal, msg, msgLen), errno);
-
OS_MQ_GOTO_ERROUT_IF(msgPrio > (MQ_PRIO_MAX - 1), EINVAL);
(VOID)pthread_mutex_lock(&g_mqueueMutex);
- privateMqPersonal = (struct mqpersonal *)personal;
+ privateMqPersonal = MqGetPrivDataBuff(personal);
+ if (privateMqPersonal == NULL) {
+ goto ERROUT_UNLOCK;
+ }
+
OS_MQ_GOTO_ERROUT_UNLOCK_IF(privateMqPersonal->mq_status != MQ_USE_MAGIC, EBADF);
mqueueCB = privateMqPersonal->mq_posixdes;
@@ -554,7 +790,10 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
}
(VOID)pthread_mutex_lock(&g_mqueueMutex);
- privateMqPersonal = (struct mqpersonal *)personal;
+ privateMqPersonal = MqGetPrivDataBuff(personal);
+ if (privateMqPersonal == NULL) {
+ goto ERROUT_UNLOCK;
+ }
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
goto ERROUT_UNLOCK;
diff --git a/compat/posix/src/posix_memalign.c b/compat/posix/src/posix_memalign.c
index 40af37dd..59e85702 100644
--- a/compat/posix/src/posix_memalign.c
+++ b/compat/posix/src/posix_memalign.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/pprivate.h b/compat/posix/src/pprivate.h
index e484c81a..85f358ef 100644
--- a/compat/posix/src/pprivate.h
+++ b/compat/posix/src/pprivate.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/pthread.c b/compat/posix/src/pthread.c
old mode 100644
new mode 100755
index 8312cbb1..4fca2c13
--- a/compat/posix/src/pthread.c
+++ b/compat/posix/src/pthread.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,6 +36,7 @@
#include "stdio.h"
#include "map_error.h"
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
diff --git a/compat/posix/src/pthread_attr.c b/compat/posix/src/pthread_attr.c
index ec3764be..736c898a 100644
--- a/compat/posix/src/pthread_attr.c
+++ b/compat/posix/src/pthread_attr.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/pthread_cond.c b/compat/posix/src/pthread_cond.c
old mode 100644
new mode 100755
index 0f824902..1b9e3203
--- a/compat/posix/src/pthread_cond.c
+++ b/compat/posix/src/pthread_cond.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/pthread_mutex.c b/compat/posix/src/pthread_mutex.c
old mode 100644
new mode 100755
index d12a3828..b4ab4015
--- a/compat/posix/src/pthread_mutex.c
+++ b/compat/posix/src/pthread_mutex.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/sched.c b/compat/posix/src/sched.c
index d4841303..feb713d8 100644
--- a/compat/posix/src/sched.c
+++ b/compat/posix/src/sched.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/semaphore.c b/compat/posix/src/semaphore.c
old mode 100644
new mode 100755
index 425259ba..63039039
--- a/compat/posix/src/semaphore.c
+++ b/compat/posix/src/semaphore.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/socket.c b/compat/posix/src/socket.c
index f29443dc..23d00cf7 100644
--- a/compat/posix/src/socket.c
+++ b/compat/posix/src/socket.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c
old mode 100644
new mode 100755
index d3a42f4e..462ea7c0
--- a/compat/posix/src/time.c
+++ b/compat/posix/src/time.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,7 +30,6 @@
*/
#include "time.h"
-#include "asm/hal_platform_ints.h"
#include "stdint.h"
#include "stdio.h"
#include "sys/times.h"
@@ -744,7 +743,7 @@ int timer_settime(timer_t timerID, int flags,
swtmr->ucMode = interval ? LOS_SWTMR_MODE_OPP : LOS_SWTMR_MODE_NO_SELFDELETE;
swtmr->uwExpiry = expiry + !!expiry; // PS: skip the first tick because it is NOT a full tick.
swtmr->uwInterval = interval;
- swtmr->ucOverrun = 0;
+ swtmr->uwOverrun = 0;
LOS_SpinUnlockRestore(&g_swtmrSpin, intSave);
if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
@@ -813,20 +812,15 @@ int timer_getoverrun(timer_t timerID)
return -1;
}
- overRun = (INT32)(swtmr->ucOverrun);
+ overRun = (INT32)(swtmr->uwOverrun);
return (overRun > DELAYTIMER_MAX) ? DELAYTIMER_MAX : overRun;
}
-STATIC INT32 DoNanoSleep(UINT64 nseconds)
+STATIC INT32 DoNanoSleep(UINT64 useconds)
{
- UINT64 tick;
UINT32 ret;
- const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
- tick = (nseconds + nsPerTick - 1) / nsPerTick; // Round up for ticks
-
- /* PS: skip the first tick because it is NOT a full tick. */
- ret = LOS_TaskDelay((tick >= UINT32_MAX) ? UINT32_MAX : (tick ? ((UINT32)tick + 1) : 0));
+ ret = LOS_TaskDelay(OsUS2Tick(useconds));
if (ret == LOS_OK || ret == LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK) {
return 0;
}
@@ -835,12 +829,12 @@ STATIC INT32 DoNanoSleep(UINT64 nseconds)
int usleep(unsigned useconds)
{
- return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US);
+ return DoNanoSleep((UINT64)useconds);
}
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
- UINT64 nseconds;
+ UINT64 useconds;
INT32 ret = -1;
(VOID)rmtp;
@@ -851,14 +845,14 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
return ret;
}
- nseconds = (UINT64)rqtp->tv_sec * OS_SYS_NS_PER_SECOND + rqtp->tv_nsec;
+ useconds = (UINT64)rqtp->tv_sec * OS_SYS_US_PER_SECOND + rqtp->tv_nsec / OS_SYS_NS_PER_US;
- return DoNanoSleep(nseconds);
+ return DoNanoSleep(useconds);
}
unsigned int sleep(unsigned int seconds)
{
- return DoNanoSleep((UINT64)seconds * OS_SYS_NS_PER_SECOND);
+ return DoNanoSleep((UINT64)seconds * OS_SYS_US_PER_SECOND);
}
double difftime(time_t time2, time_t time1)
@@ -879,15 +873,10 @@ clock_t clock(VOID)
clock_t times(struct tms *buf)
{
- clock_t clockTick;
+ clock_t clockTick = -1;
- clockTick = LOS_TickCountGet();
- if (buf != NULL) {
- buf->tms_cstime = clockTick;
- buf->tms_cutime = clockTick;
- buf->tms_stime = clockTick;
- buf->tms_utime = clockTick;
- }
+ (void)buf;
+ set_errno(ENOSYS);
return clockTick;
}
@@ -914,6 +903,12 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
}
}
LOS_TaskUnlock();
+
+ if (!ValidTimeval(&value->it_value) || !ValidTimeval(&value->it_interval)) {
+ set_errno(EINVAL);
+ return -1;
+ }
+
TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value);
TIMEVAL_TO_TIMESPEC(&value->it_interval, &spec.it_interval);
diff --git a/config.mk b/config.mk
old mode 100644
new mode 100755
index 04f95d53..50fd8877
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/drivers/char/mem/Kconfig b/drivers/char/mem/Kconfig
new file mode 100644
index 00000000..7cfed492
--- /dev/null
+++ b/drivers/char/mem/Kconfig
@@ -0,0 +1,6 @@
+config DRIVERS_MEM
+ bool "Enable MEM"
+ default y
+ depends on DRIVERS && FS_VFS
+ help
+ Answer Y to enable LiteOS support mem.
\ No newline at end of file
diff --git a/drivers/char/mem/Makefile b/drivers/char/mem/Makefile
new file mode 100644
index 00000000..4e35bd1b
--- /dev/null
+++ b/drivers/char/mem/Makefile
@@ -0,0 +1,36 @@
+# 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 $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard src/*.c)
+
+include $(MODULE)
diff --git a/kernel/extended/include/los_tickless_pri.h b/drivers/char/mem/include/los_dev_mem.h
similarity index 72%
rename from kernel/extended/include/los_tickless_pri.h
rename to drivers/char/mem/include/los_dev_mem.h
index 7116aa8e..cb5989e8 100644
--- a/kernel/extended/include/los_tickless_pri.h
+++ b/drivers/char/mem/include/los_dev_mem.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,10 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _LOS_TICKLESS_PRI_H
-#define _LOS_TICKLESS_PRI_H
+#ifndef __LOS_DEV_MEM_H__
+#define __LOS_DEV_MEM_H__
-#include "los_tickless.h"
+#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
@@ -40,15 +40,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-extern VOID OsTickTimerReload(UINT32 period);
-extern VOID OsSysTimeUpdate(UINT32 sleepTicks);
-extern VOID OsTicklessStart(VOID);
-extern BOOL OsTickIrqFlagGet(VOID);
-extern VOID OsTickIrqFlagSet(BOOL tickIrqFlag);
-extern BOOL OsTicklessFlagGet(VOID);
-extern UINT32 OsTicklessSleepTickGet(VOID);
-extern VOID OsTicklessSleepTickSet(UINT32 sleeptick);
-extern VOID OsTicklessUpdate(UINT32 irqNum);
+extern int DevMemRegister(void);
#ifdef __cplusplus
#if __cplusplus
@@ -56,4 +48,4 @@ extern VOID OsTicklessUpdate(UINT32 irqNum);
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* _LOS_TICKLESS_PRI_H */
+#endif
diff --git a/kernel/base/mem/common/memrecord/los_interto64radix.c b/drivers/char/mem/src/mem.c
similarity index 51%
rename from kernel/base/mem/common/memrecord/los_interto64radix.c
rename to drivers/char/mem/src/mem.c
index ecf91dac..df82cd07 100644
--- a/kernel/base/mem/common/memrecord/los_interto64radix.c
+++ b/drivers/char/mem/src/mem.c
@@ -1,87 +1,108 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_typedef.h"
-#include "los_printf.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-/* array used for 64 binary conversion, include 64 characters */
-const CHAR g_base64Array[] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
- 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
- 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
- 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', '~', '!'
-};
-
-#define LOGARITHM 6 /* the logarithm of 64 to base 2 */
-#define BASE64_MARK ((1U << LOGARITHM) - 1)
-
-VOID OsDecTo64F(UINT32 num, CHAR *base64, INT32 base64Len)
-{
- INT32 len = base64Len - 1;
- UINT32 tempNum = num;
- if (base64 == NULL) {
- PRINT_ERR("%s:%d input null buf\n", __FUNCTION__, __LINE__);
- return;
- }
-
- if (base64Len <= 0) {
- PRINT_ERR("%s:%d input illegal Len\n", __FUNCTION__, __LINE__);
- return;
- }
-
- while (num) {
- if (len < 0) {
- PRINT_ERR("Len[%d] is too short, input num: %u\n", base64Len, tempNum);
- break;
- }
- base64[len--] = g_base64Array[num & BASE64_MARK];
- num >>= LOGARITHM;
- }
- for (; len >= 0; len--) {
- base64[len] = '0';
- }
- base64[base64Len] = '\0';
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+/*
+ * 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 "fcntl.h"
+#include "linux/kernel.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+static int MemOpen(struct file *filep)
+{
+ return 0;
+}
+
+static int MemClose(struct file *filep)
+{
+ return 0;
+}
+
+static ssize_t MemRead(FAR struct file *filep, FAR char *buffer, size_t buflen)
+{
+ return 0;
+}
+
+static ssize_t MemWrite(FAR struct file *filep, FAR const char *buffer, size_t buflen)
+{
+ return 0;
+}
+
+static ssize_t MemMap(FAR struct file *filep, FAR LosVmMapRegion *region)
+{
+ size_t size = region->range.size;
+ PADDR_T paddr = region->pgOff << PAGE_SHIFT;
+ VADDR_T vaddr = region->range.base;
+ LosVmSpace *space = LOS_SpaceGet(vaddr);
+
+ if ((paddr >= SYS_MEM_BASE) && (paddr < SYS_MEM_END)) {
+ return -EINVAL;
+ }
+
+ /* Peripheral register memory adds strongly ordered attributes */
+ region->regionFlags |= VM_MAP_REGION_FLAG_STRONGLY_ORDERED;
+
+ if (space == NULL) {
+ return -EAGAIN;
+ }
+ if (LOS_ArchMmuMap(&space->archMmu, vaddr, paddr, size >> PAGE_SHIFT, region->regionFlags) <= 0) {
+ return -EAGAIN;
+ }
+
+ return 0;
+}
+
+static const struct file_operations_vfs g_memDevOps = {
+ MemOpen, /* open */
+ MemClose, /* close */
+ MemRead, /* read */
+ MemWrite, /* write */
+ NULL, /* seek */
+ NULL, /* ioctl */
+ MemMap, /* mmap */
+#ifndef CONFIG_DISABLE_POLL
+ NULL, /* poll */
+#endif
+ NULL, /* unlink */
+};
+
+int DevMemRegister(void)
+{
+ return register_driver("/dev/mem", &g_memDevOps, 0666, 0); /* 0666: file mode */
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/drivers/char/quickstart/Makefile b/drivers/char/quickstart/Makefile
new file mode 100644
index 00000000..4e35bd1b
--- /dev/null
+++ b/drivers/char/quickstart/Makefile
@@ -0,0 +1,36 @@
+# 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 $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard src/*.c)
+
+include $(MODULE)
diff --git a/drivers/char/quickstart/include/los_quick_start.h b/drivers/char/quickstart/include/los_quick_start.h
new file mode 100644
index 00000000..c9b97082
--- /dev/null
+++ b/drivers/char/quickstart/include/los_quick_start.h
@@ -0,0 +1,51 @@
+/*
+ * 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_QUICK_START_H__
+#define __LOS_QUICK_START_H__
+
+#include "los_typedef.h"
+
+fdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+extern int DevQuickStartRegister(void);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
diff --git a/kernel/base/include/los_timeslice_pri.h b/drivers/char/quickstart/include/los_quick_start_pri.h
similarity index 67%
rename from kernel/base/include/los_timeslice_pri.h
rename to drivers/char/quickstart/include/los_quick_start_pri.h
index 99f159ca..012b548e 100644
--- a/kernel/base/include/los_timeslice_pri.h
+++ b/drivers/char/quickstart/include/los_quick_start_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,13 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/**
- * @defgroup los_timeslice Timeslice
- * @ingroup kernel
- */
-
-#ifndef _LOS_TIMESLICE_PRI_H
-#define _LOS_TIMESLICE_PRI_H
+#ifndef __LOS_QUICK_START_PRI_H__
+#define __LOS_QUICK_START_PRI_H__
#include "los_typedef.h"
@@ -45,28 +40,8 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-/**
- * @ingroup los_timeslice
- * @brief Check time slices.
- *
- * @par Description:
- *
- * This API is used to check time slices. If the number of Ticks equals to the time for task switch,
- * tasks are switched. Otherwise, the Tick counting continues.
- *
- * @attention
- *
- *
- * @param None.
- *
- * @retval None.
- * @par Dependency:
- * los_timeslice_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID OsTimesliceCheck(VOID);
+unsigned int OsSystemInitStep2(void);
+extern VOID SystemInit2(VOID);
#ifdef __cplusplus
#if __cplusplus
@@ -74,4 +49,4 @@ extern VOID OsTimesliceCheck(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* _LOS_TIMESLICE_PRI_H */
+#endif /* __LOS_QUICK_START_PRI_H__ */
\ No newline at end of file
diff --git a/drivers/char/quickstart/src/qucikstart.c b/drivers/char/quickstart/src/qucikstart.c
new file mode 100644
index 00000000..8b4e8a57
--- /dev/null
+++ b/drivers/char/quickstart/src/qucikstart.c
@@ -0,0 +1,117 @@
+/*
+ * 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_quick_start_pri.h"
+#include "bits/ioctl.h"
+#include "fcntl.h"
+#include "linux/kernel.h"
+
+#define QUICKSTART_IOC_MAGIC 'T'
+#define QUICKSTART_INITSTEP2 _IO(QUICKSTART_IOC_MAGIC, 0)
+#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, 1)
+#define QUICKSTART_NODE "/dev/quickstart"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+static int QuickstartOpen(struct file *filep)
+{
+ return 0;
+}
+
+static int QuickstartClose(struct file *filep)
+{
+ return 0;
+}
+
+static void SystemInitStep2(void)
+{
+ static int once = 0;
+ /* Only one call is allowed */
+ if (once != 0) {
+ return;
+ }
+ once = 1;
+
+ unsigned int ret = OsSystemInitStep2();
+ if (ret != LOS_OK) {
+ PRINT_ERR("systemInitStep2 failed\n");
+ }
+}
+
+static int QuickstartDevUnregister(void)
+{
+ return unregister_driver(QUICKSTART_NODE);
+}
+
+static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
+{
+ switch (cmd) {
+ case QUICKSTART_INITSTEP2:
+ SystemInitStep2();
+ break;
+ case QUICKSTART_UNREGISTER:
+ QuickstartDevUnregister();
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
+
+static const struct file_operations_vfs g_quickstartDevOps = {
+ QuickstartOpen, /* open */
+ QuickstartClose, /* close */
+ NULL, /* read */
+ NULL, /* write */
+ NULL, /* seek */
+ QuickstartIoctl, /* ioctl */
+ NULL, /* mmap */
+#ifndef CONFIG_DISABLE_POLL
+ NULL, /* poll */
+#endif
+ NULL, /* unlink */
+};
+
+int DevQuickStartRegister(void)
+{
+ return register_driver(QUICKSTART_NODE, &g_quickstartDevOps, 0666, 0); /* 0666: file mode */
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/drivers/char/random/Kconfig b/drivers/char/random/Kconfig
new file mode 100644
index 00000000..5574bef6
--- /dev/null
+++ b/drivers/char/random/Kconfig
@@ -0,0 +1,12 @@
+config DRIVERS_RANDOM
+ bool "Enable random"
+ default y
+ depends on DRIVERS && FS_VFS && COMPAT_BSD
+ help
+ Answer Y to support random.
+config HW_RANDOM_ENABLE
+ depends on DRIVERS_RANDOM && (PLATFORM_HI3518EV300 || PLATFORM_HI3516CV300 || PLATFORM_HI3516DV300 || PLATFORM_HI3556V200)
+ bool "Select hw random"
+ default y
+ help
+ Answer Y to select hw random.
diff --git a/drivers/char/random/Makefile b/drivers/char/random/Makefile
new file mode 100644
index 00000000..edd03c4a
--- /dev/null
+++ b/drivers/char/random/Makefile
@@ -0,0 +1,45 @@
+# 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 $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard src/random.c)
+
+ifdef LOSCFG_HW_RANDOM_ENABLE
+LOCAL_SRCS += $(wildcard src/random_hw.c)
+endif
+
+LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/random/include \
+ -I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)/include
+
+LOCAL_FLAGS := $(LOCAL_INCLUDE)
+
+include $(MODULE)
diff --git a/kernel/base/include/los_memrecord_pri.h b/drivers/char/random/include/los_random.h
similarity index 63%
rename from kernel/base/include/los_memrecord_pri.h
rename to drivers/char/random/include/los_random.h
index daa102e2..298449ea 100644
--- a/kernel/base/include/los_memrecord_pri.h
+++ b/drivers/char/random/include/los_random.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,10 +29,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _LOS_MEMRECORD_PRI_H
-#define _LOS_MEMRECORD_PRI_H
+#ifndef __LOS_RANDOM_H__
+#define __LOS_RANDOM_H__
-#include "los_memory.h"
+#include "los_typedef.h"
+#include "sys/ioctl.h"
#ifdef __cplusplus
#if __cplusplus
@@ -40,40 +41,21 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#define RECORD_LEN 4000
+#define RAMDOM_IOC_MAGIC 'r'
+#define RANDOM_SET_MAX _IO(RAMDOM_IOC_MAGIC, 1)
+
+int DevRandomRegister(void);
+int DevUrandomRegister(void);
typedef struct {
- UINT32 addrID;
- UINT32 taskID;
- UINT32 reqSizeID;
- UINT32 allocatedSizeID;
- UINT32 actType;
- UINT64 sysTick;
- UINT32 linkRegID;
-} MemRecordInfo;
+ int (*support)(void); /* Whether hard random numbers are supported */
+ void (*init)(void); /* Initializing the hard random number generator */
+ void (*deinit)(void); /* Deinitializing the hard random number generator */
+ int (*read)(char *buffer, size_t buflen); /* Read hard random number */
+ int (*ioctl)(int cmd, unsigned long arg); /* Control hard random number generator */
+} RandomOperations;
-#define MEM_RECORDSHOW_TIMEOUT 6000
-
-extern VOID OsMemRecordShowSet(UINT32 value);
-extern VOID OsMemRecordMalloc(const VOID *ptr, UINT32 size);
-extern VOID OsMemRecordFree(const VOID *ptr, UINT32 size);
-extern VOID OsMemRecordShowTask(VOID);
-extern VOID OsDecTo64F(UINT32 num, CHAR *base64, INT32 base64Len);
-
-
-#ifndef LOSCFG_MEM_RECORDINFO
-INLINE VOID OsMemRecordFree(const VOID *ptr, UINT32 size)
-{
- return;
-}
-#endif
-
-#ifndef LOSCFG_MEM_RECORDINFO
-INLINE VOID OsMemRecordMalloc(const VOID *ptr, UINT32 size)
-{
- return;
-}
-#endif
+void RandomOperationsInit(const RandomOperations *r);
#ifdef __cplusplus
#if __cplusplus
@@ -81,4 +63,4 @@ INLINE VOID OsMemRecordMalloc(const VOID *ptr, UINT32 size)
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* _LOS_MEMRECORD_PRI_H */
+#endif
diff --git a/drivers/char/random/src/random.c b/drivers/char/random/src/random.c
new file mode 100644
index 00000000..9ef114d6
--- /dev/null
+++ b/drivers/char/random/src/random.c
@@ -0,0 +1,128 @@
+/*
+ * 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_random.h"
+#include "fcntl.h"
+#include "linux/kernel.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+static unsigned long g_randomMax = 0x7FFFFFFF;
+
+static long DoRand(unsigned long *value)
+{
+ long quotient, remainder, t;
+
+ quotient = *value / 127773L;
+ remainder = *value % 127773L;
+ t = 16807L * remainder - 2836L * quotient;
+ if (t <= 0) {
+ t += 0x7fffffff;
+ }
+ return ((*value = t) % (g_randomMax + 1));
+}
+
+static unsigned long g_seed = 1;
+
+int RanOpen(struct file *filep)
+{
+ g_seed = (unsigned long)(hi_sched_clock() & 0xffffffff);
+ return 0;
+}
+
+static int RanClose(struct file *filep)
+{
+ return 0;
+}
+
+int RanIoctl(struct file *filep, int cmd, unsigned long arg)
+{
+ PRINT_ERR("random ioctl is not supported\n");
+ return -ENOTSUP;
+}
+
+ssize_t RanRead(struct file *filep, char *buffer, size_t buflen)
+{
+ ssize_t len = buflen;
+ char *buf = buffer;
+ unsigned int temp;
+ int ret;
+
+ if (len % sizeof(unsigned int)) {
+ PRINT_ERR("random size not aligned by 4 bytes\n");
+ return -EINVAL;
+ }
+ while (len > 0) {
+ temp = DoRand(&g_seed);
+ ret = LOS_CopyFromKernel((void *)buf, sizeof(unsigned int), (void *)&temp, sizeof(unsigned int));
+ if (ret) {
+ break;
+ }
+ len -= sizeof(unsigned int);
+ buf += sizeof(unsigned int);
+ }
+ return (buflen - len); /* return a successful len */
+}
+
+static ssize_t RanMap(FAR struct file* filep, FAR LosVmMapRegion *region)
+{
+ PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__);
+ return 0;
+}
+
+static const struct file_operations_vfs g_ranDevOps = {
+ RanOpen, /* open */
+ RanClose, /* close */
+ RanRead, /* read */
+ NULL, /* write */
+ NULL, /* seek */
+ RanIoctl, /* ioctl */
+ RanMap, /* mmap */
+#ifndef CONFIG_DISABLE_POLL
+ NULL, /* poll */
+#endif
+ NULL, /* unlink */
+};
+
+int DevRandomRegister(void)
+{
+ return register_driver("/dev/random", &g_ranDevOps, 0666, 0); /* 0666: file mode */
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/drivers/char/random/src/random_hw.c b/drivers/char/random/src/random_hw.c
new file mode 100644
index 00000000..fe412ee6
--- /dev/null
+++ b/drivers/char/random/src/random_hw.c
@@ -0,0 +1,127 @@
+/*
+ * 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_random.h"
+#include "fcntl.h"
+#include "hisoc/random.h"
+#include "linux/kernel.h"
+
+static RandomOperations g_randomOp;
+void RandomOperationsInit(const RandomOperations *r)
+{
+ if (r != NULL) {
+ (void)memcpy_s(&g_randomOp, sizeof(RandomOperations), r, sizeof(RandomOperations));
+ } else {
+ PRINT_ERR("param is invalid\n", __FUNCTION__, __LINE__);
+ }
+ return;
+}
+static int RandomHwOpen(struct file *filep)
+{
+ if (g_randomOp.init != NULL) {
+ g_randomOp.init();
+ return ENOERR;
+ }
+ return -1;
+}
+
+static int RandomHwClose(struct file *filep)
+{
+ if (g_randomOp.deinit != NULL) {
+ g_randomOp.deinit();
+ return ENOERR;
+ }
+ return -1;
+}
+
+static int RandomHwIoctl(struct file *filep, int cmd, unsigned long arg)
+{
+ int ret;
+
+ switch (cmd) {
+ default:
+ PRINT_ERR("!!!bad command!!!\n");
+ return -EINVAL;
+ }
+ return ret;
+}
+
+static ssize_t RandomHwRead(struct file *filep, char *buffer, size_t buflen)
+{
+ int ret;
+
+ if (g_randomOp.read != NULL) {
+ ret = g_randomOp.read(buffer, buflen);
+ if (ret == ENOERR) {
+ ret = buflen;
+ }
+ } else {
+ ret = -1;
+ }
+ return ret;
+}
+
+static ssize_t RandomMap(FAR struct file *filep, FAR LosVmMapRegion *region)
+{
+ PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__);
+ return 0;
+}
+
+static const struct file_operations_vfs g_randomHwDevOps = {
+ RandomHwOpen, /* open */
+ RandomHwClose, /* close */
+ RandomHwRead, /* read */
+ NULL, /* write */
+ NULL, /* seek */
+ RandomHwIoctl, /* ioctl */
+ RandomMap, /* mmap */
+#ifndef CONFIG_DISABLE_POLL
+ NULL, /* poll */
+#endif
+ NULL, /* unlink */
+};
+
+int DevUrandomRegister(void)
+{
+ if (g_randomOp.support != NULL) {
+ int ret = g_randomOp.support();
+ if (ret) {
+ return register_driver("/dev/urandom", &g_randomHwDevOps, 0666, 0); /* 0666: file mode */
+ }
+ }
+ return -EPERM;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/drivers/char/video/Kconfig b/drivers/char/video/Kconfig
new file mode 100644
index 00000000..3fad196a
--- /dev/null
+++ b/drivers/char/video/Kconfig
@@ -0,0 +1,6 @@
+config DRIVERS_VIDEO
+ bool "Enable Video"
+ default y
+ depends on DRIVERS
+ help
+ Answer Y to enable LiteOS support video driver.
\ No newline at end of file
diff --git a/kernel/extended/tickless/Makefile b/drivers/char/video/Makefile
similarity index 83%
rename from kernel/extended/tickless/Makefile
rename to drivers/char/video/Makefile
index 813c1296..790d2e62 100644
--- a/kernel/extended/tickless/Makefile
+++ b/drivers/char/video/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -31,13 +31,10 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
-LOCAL_SRCS := $(wildcard *.c)
+LOCAL_SRCS := $(LITEOSTHIRDPARTY)/NuttX/drivers/video/fb.c
-LOCAL_INCLUDE := \
- -I $(LITEOSTOPDIR)/kernel/base/include -I $(LITEOSTOPDIR)/kernel/extended/include \
- -I $(LITEOSTOPDIR)/kernel/base/core
+LOCAL_INCLUDE := -I $(LITEOSTHIRDPARTY)/NuttX/include/nuttx/video
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)
-
diff --git a/figures/OpenHarmony-LiteOS-A内核架构图.png b/figures/OpenHarmony-LiteOS-A内核架构图.png
new file mode 100644
index 00000000..b2ff552d
Binary files /dev/null and b/figures/OpenHarmony-LiteOS-A内核架构图.png differ
diff --git a/figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png b/figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png
new file mode 100644
index 00000000..27b8a0e0
Binary files /dev/null and b/figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png differ
diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig
old mode 100644
new mode 100755
diff --git a/fs/fat/Makefile b/fs/fat/Makefile
old mode 100644
new mode 100755
index ad65ab6b..ce372490
--- a/fs/fat/Makefile
+++ b/fs/fat/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -35,8 +35,9 @@ LOCAL_SRCS := $(wildcard os_adapt/*.c)
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c)
LOCAL_INCLUDE := \
- -I $(LITEOSTHIRDPARTY)/FatFs/source \
- -I $(LITEOSTOPDIR)/fs/fat/virpart/include
+ -I $(LITEOSTHIRDPARTY)/FatFs/source \
+ -I $(LITEOSTOPDIR)/fs/fat/os_adapt \
+ -I $(LITEOSTOPDIR)/fs/fat/virpart/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
diff --git a/fs/fat/os_adapt/dirop_fat.c b/fs/fat/os_adapt/dirop_fat.c
new file mode 100755
index 00000000..0515cf15
--- /dev/null
+++ b/fs/fat/os_adapt/dirop_fat.c
@@ -0,0 +1,274 @@
+/*
+ * 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 "dirop_fat.h"
+#include "fatfs.h"
+#include "errno.h"
+#include "fs/fs.h"
+#include "inode/inode.h"
+#include "integer.h"
+#include "string.h"
+
+#ifdef LOSCFG_FS_FAT
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C"{
+#endif
+#endif /* __cplusplus */
+
+extern const struct mountpt_operations fat_operations;
+#define SECTOR_SIZE 512
+#define FIRST_MALLOC_SIZE 10
+
+static INT vfat_check_path(const char *path)
+{
+ struct inode *inode_ptr = NULL;
+ char *fullpath = NULL;
+ INT ret = vfs_normalize_path((const char *)NULL, path, &fullpath);
+ struct inode_search_s desc;
+
+ if (ret < ENOERR) {
+ ret = -ret;
+ set_errno(ret);
+ return FAT_ERROR;
+ }
+
+ SETUP_SEARCH(&desc, fullpath, false);
+ ret = inode_find(&desc);
+ if (ret < 0) {
+ PRINT_ERR("ERROR: Failed to find %s\n", fullpath);
+ ret = -ret;
+ set_errno(ret);
+ return FAT_ERROR;
+ }
+ inode_ptr = desc.node;
+
+ free(fullpath);
+
+ if (inode_ptr && (inode_ptr->u.i_mops == &fat_operations)) {
+ inode_release(inode_ptr);
+ return ENOERR;
+ }
+
+ return FAT_ERROR;
+}
+
+static DIR_FAT *initdir_fat(DIR *dp)
+{
+ DIR_FAT *dir_fat = NULL;
+
+ if (dp != NULL) {
+ dir_fat = (DIR_FAT *)malloc(sizeof(DIR_FAT) + PATH_MAX);
+ if (dir_fat != NULL) {
+ (void)memset_s(dir_fat, sizeof(DIR_FAT) + PATH_MAX, 0, sizeof(DIR_FAT) + PATH_MAX);
+
+ dir_fat->stDirStream.dd_nextloc = 0;
+ dir_fat->stDirStream.dd_size = 0;
+ dir_fat->stBuf.d_count = SECTOR_SIZE;
+ dir_fat->stBuf.d_usecount = 0;
+
+ (void)pthread_mutex_init(&(dir_fat->stDirStream.dd_lock), (const pthread_mutexattr_t *)NULL);
+ dir_fat->stDirStream.dp = dp;
+
+ return dir_fat;
+ }
+
+ (void)closedir(dp);
+ }
+
+ return NULL;
+}
+
+DIR_FAT *opendir_fat(const char *name)
+{
+ INT ret;
+ DIR *dp = NULL;
+
+ ret = vfat_check_path(name);
+ if (ret) {
+ return NULL;
+ }
+
+ dp = opendir(name);
+
+ return initdir_fat(dp);
+}
+
+int closedir_fat(DIR_FAT *dir_fat)
+{
+ INT ret;
+
+ if (dir_fat == NULL) {
+ return FAT_ERROR;
+ }
+
+ ret = closedir(dir_fat->stDirStream.dp);
+ if (ret == ENOERR) {
+ (void)pthread_mutex_destroy(&(dir_fat->stDirStream.dd_lock));
+ free(dir_fat);
+ }
+
+ return ret;
+}
+
+extern int fatfs_readdir_all(DIR_FAT *dir_fat);
+
+struct fat_direntall *readdir_fat(DIR_FAT *dir_fat)
+{
+ INT ret;
+ struct fat_direntall *de = (struct fat_direntall *)NULL;
+
+ if (dir_fat == NULL) {
+ return NULL;
+ }
+
+ if (pthread_mutex_lock(&(dir_fat->stDirStream.dd_lock)) != ENOERR) {
+ return NULL;
+ }
+
+ ret = fatfs_readdir_all(dir_fat);
+ if (!ret) {
+ de = &(dir_fat->stBuf.direntall);
+ }
+
+ if (pthread_mutex_unlock(&(dir_fat->stDirStream.dd_lock)) != ENOERR)
+ PRINT_ERR("readdir_fat mutex unlock error \n");
+ return de;
+}
+
+static struct fat_direntall **scandir_fat_remalloc_names(struct fat_direntall **names,
+ UINT *names_size, UINT pos, bool *failed)
+{
+ struct fat_direntall **new_direntall = NULL;
+ INT32 ret;
+
+ if (pos == *names_size) {
+
+ if (*names_size == 0) {
+ *names_size = FIRST_MALLOC_SIZE;
+ } else {
+ *names_size <<= 1;
+ }
+
+ new_direntall = (struct fat_direntall **)malloc(*names_size * sizeof(struct fat_direntall *));
+ if (new_direntall == NULL) {
+ *failed = 1;
+ return names;
+ }
+
+ if (names != NULL) {
+ ret = memcpy_s(new_direntall, (*names_size) * sizeof(struct fat_direntall *),
+ names, pos * sizeof(struct fat_direntall *));
+ if (ret != EOK){
+ *failed = 1;
+ free(new_direntall);
+ return names;
+ }
+ free(names);
+ }
+ return new_direntall;
+ }
+ return names;
+}
+
+int scandir_fat(const char *dir, struct fat_direntall ***namelist,
+ int (*selector) (const struct fat_direntall *),
+ int (*compar) (const struct fat_direntall **, const struct fat_direntall **))
+{
+ DIR_FAT *dp = opendir_fat(dir);
+ struct fat_direntall *current = NULL;
+ struct fat_direntall **names = NULL;
+ struct fat_direntall *vnew = NULL;
+ UINT names_size = 0;
+ UINT pos = 0;
+ UINT dsize;
+ bool failed = 0;
+ INT use_it;
+
+ if (dp == NULL) {
+ return FAT_ERROR;
+ }
+
+ current = readdir_fat(dp);
+ while (current != NULL) {
+ use_it = (selector == NULL);
+ if (!use_it) {
+ use_it = (*selector) (current);
+ }
+ if (use_it) {
+ names = scandir_fat_remalloc_names(names, &names_size, pos, &failed);
+ if (failed == 1) {
+ break;
+ }
+
+ dsize = current->d_reclen;
+ vnew = (struct fat_direntall *)malloc(dsize);
+ if (vnew == NULL) {
+ failed = 1;
+ break;
+ }
+
+ (void)memcpy_s(vnew, dsize, current, dsize);
+ names[pos++] = vnew;
+ }
+ current = readdir_fat(dp);
+ }
+
+ if (failed == 1) {
+ (void)closedir_fat(dp);
+ while (pos > 0) {
+ free(names[--pos]);
+ }
+
+ if (names != NULL) {
+ free(names);
+ }
+
+ return FAT_ERROR;
+ }
+
+ (void)closedir_fat(dp);
+
+ /* Sort the list if we have a comparison function to sort with. */
+ if (compar != NULL && names != NULL) {
+ qsort((void *)names, pos, sizeof (struct fat_direntall *), (int (*)(const void *, const void *))*compar);
+ }
+ *namelist = names;
+ return pos;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+#endif /* CONFIG_FS_FAT */
diff --git a/fs/fat/os_adapt/dirop_fat.h b/fs/fat/os_adapt/dirop_fat.h
new file mode 100755
index 00000000..2f9b9fa2
--- /dev/null
+++ b/fs/fat/os_adapt/dirop_fat.h
@@ -0,0 +1,195 @@
+/*
+ * 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 fat Fat
+ * @ingroup filesystem
+ */
+
+#ifndef _DIROP_FAT_H
+#define _DIROP_FAT_H
+
+#include "pthread.h"
+#include "dirent.h"
+#ifdef LOSCFG_FS_FAT
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C"{
+#endif
+#endif /* __cplusplus */
+
+#define TIME_LENGTH 8
+
+struct fat_direntall {
+ unsigned long d_ino;
+ unsigned long d_off;
+ unsigned char d_type;
+ unsigned int d_size;
+ char d_createtime[TIME_LENGTH];
+ unsigned short d_reclen;
+ char d_name[1];
+};
+
+struct fat_direntall_buf {
+ int d_count;
+ int d_usecount;
+ struct fat_direntall direntall;
+};
+
+struct dirstream_fat {
+ DIR *dp;
+
+ /* offset of the next dir entry in buffer */
+ unsigned int dd_nextloc;
+
+ /* bytes of valid entries in buffer */
+ unsigned int dd_size;
+
+ pthread_mutex_t dd_lock;
+};
+
+typedef struct fat_dir{
+ struct dirstream_fat stDirStream;
+ struct fat_direntall_buf stBuf;
+} DIR_FAT;
+
+/**
+ * @ingroup fat
+ * @brief open a directory
+ *
+ * @par Description:
+ * This API is used to open a directory stream corresponding to the directory name, and
+ * returns a pointer to the directory stream.
+ *
+ * @attention
+ *
+ * The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] the directory to open.
+ *
+ * @retval #NULL Open directory unsuccessfully and set errno.
+ * @retval #DIR_FAT* A pointer to the directory stream.
+ * @par Dependency:
+ * dirop_fat.h: the header file that contains the API declaration.
+ * @see closedir_fat
+ */
+DIR_FAT *opendir_fat(const char *name);
+
+/**
+ * @ingroup fat
+ * @brief close a directory
+ *
+ * @par Description:
+ * This API is used to close the directory stream associated with dirp.
+ *
+ * @attention
+ *
+ * The parameter dir_fat should be a valid pointer which opendir_fat returns.
+ *
+ *
+ * @param dir_fat [IN] Directory object structure pointer which opendir_fat returns.
+ *
+ * @retval #FAT_ERROR The directory dirp close unsuccessfully and set errno.
+ * @retval #OK The directory dirp close successfully.
+ * @par Dependency:
+ * dirop_fat.h: the header file that contains the API declaration.
+ * @see opendir_fat
+ */
+int closedir_fat(DIR_FAT *dir_fat);
+
+/**
+ * @ingroup fat
+ * @brief read a directory
+ *
+ * @par Description:
+ * This API is used to get a pointer to a dirent structure
+ * representing the next directory entry in the directory stream pointed
+ * to by dirp.
+ *
+ * @attention
+ *
+ * The parameter dir_fat should be a valid pointer which opendir_fat returns.
+ *
+ *
+ * @param dir_fat [IN] An instance of type DIR created by a previous call to opendir_fat().
+ *
+ * @retval #NULL Reaching the end of the directory stream or if an error occurred and set errno.
+ * @retval #fat_direntall* A pointer to a dirent structure.
+ * @par Dependency:
+ * dirop_fat.h: the header file that contains the API declaration.
+ * @see opendir_fat
+ */
+struct fat_direntall *readdir_fat(DIR_FAT *dir_fat);
+
+/**
+* @ingroup fat
+* @brief scan a directory for matching entries.
+*
+* @par Description:
+* The scandir_fat() function scans the directory dirp, calling selector() in
+* each directory entry. Entries for which selector() returns nonzero are
+* stored in strings allocated via malloc, sorted using qsort with
+* the comparison function compar(), and collected in array namelist
+* which is allocated via malloc. If filter is NULL, all entries are
+* selected, compare with scandir(), scandir_fat() can get the create-time of
+* file.
+*
+* @attention
+*
+*
+* @param dir [IN] Type #const char* a pointer to directory information.
+* @param namelist [OUT] Type #const struct fat_direntall*** a pointer to collected directory entries.
+* @param selector [IN] Type #int(*selector)(const struct fat_direntall*) a filter type function.
+* @param compar [IN] Type #int(*compar)(const struct fat_direntall**,const struct dirent**) a compar type function.
+*
+* @retval #int The number of directory entries selected.
+* @retval #<0 An error occurred.
+* @par Dependency:
+* dirop_fat.h: the header file that contains the API declaration.
+* @see readdir_fat
+*/
+int scandir_fat(const char *dir, struct fat_direntall ***namelist,
+ int (*selector) (const struct fat_direntall *),
+ int (*compar) (const struct fat_direntall **, const struct fat_direntall **));
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* LOSCFG_FS_FAT */
+
+#endif /* _DIROP_FAT_H */
diff --git a/fs/fat/os_adapt/fat_shellcmd.c b/fs/fat/os_adapt/fat_shellcmd.c
index 2720a2ea..0648d29c 100644
--- a/fs/fat/os_adapt/fat_shellcmd.c
+++ b/fs/fat/os_adapt/fat_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c
old mode 100644
new mode 100755
index 1d3068db..e2829109
--- a/fs/fat/os_adapt/fatfs.c
+++ b/fs/fat/os_adapt/fatfs.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -492,7 +492,7 @@ int fatfs_unbind(void *handle, struct inode **blkdriver)
result = FatFsUnbindVirPart(fat);
FatfsVirtUnlock();
if (result == FR_OK) {
- part = los_part_find(DiskDev[index]);
+ part = get_part((INT)fat->pdrv);
(void)inode_find(&desc);
inode = desc.node;
if (part == NULL || part->dev == inode) {
@@ -515,7 +515,7 @@ int fatfs_unbind(void *handle, struct inode **blkdriver)
VolToPart[index].ps = 0;
VolToPart[index].pc = 0;
- part = los_part_find(DiskDev[index]);
+ part = get_part((INT)fat->pdrv);
if (part != NULL && part->part_name) {
free(part->part_name);
part->part_name = NULL;
@@ -543,17 +543,17 @@ static BYTE FatFsGetMode(int oflags, int *accMode)
if ((UINT)oflags & O_WRONLY) {
fmode |= FA_WRITE;
- *accMode |= WRITE_OP;
+ *accMode = (unsigned int)(*accMode) | WRITE_OP;
}
if (((UINT)oflags & O_ACCMODE) & O_RDWR) {
fmode |= FA_WRITE;
- *accMode |= WRITE_OP;
+ *accMode = (unsigned int)(*accMode) | WRITE_OP;
}
/* Creates a new file if the file is not existing, otherwise, just open it. */
if ((UINT)oflags & O_CREAT) {
fmode |= FA_OPEN_ALWAYS;
- *accMode |= WRITE_OP;
+ *accMode = (unsigned int)(*accMode) | WRITE_OP;
/* Creates a new file. If the file already exists, the function shall fail. */
if ((UINT)oflags & O_EXCL)
fmode |= FA_CREATE_NEW;
@@ -561,7 +561,7 @@ static BYTE FatFsGetMode(int oflags, int *accMode)
/* Creates a new file. If the file already exists, its length shall be truncated to 0. */
if ((UINT)oflags & O_TRUNC) {
fmode |= FA_CREATE_ALWAYS;
- *accMode |= WRITE_OP;
+ *accMode = (unsigned int)(*accMode) | WRITE_OP;
}
return fmode;
@@ -598,31 +598,31 @@ static unsigned int FatFsCheckPermission(struct inode *mountpt, bool dirFlag, in
fileMode &= (READ_OP | WRITE_OP | EXEC_OP);
- if ((accMode & fileMode) == accMode) {
+ if (((unsigned int)accMode & fileMode) == (unsigned int)accMode) {
return FAT_PERM;
}
fileMode = 0;
if (S_ISDIR(mountpt->i_mode)) {
- if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_READ_SEARCH))) {
+ if (((unsigned int)accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_READ_SEARCH))) {
fileMode |= EXEC_OP;
}
} else {
- if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_EXECUTE))
+ if (((unsigned int)accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_EXECUTE))
&& (mountpt->i_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
fileMode |= EXEC_OP;
}
}
- if ((accMode & WRITE_OP) && IsCapPermit(CAP_DAC_WRITE)) {
+ if (((unsigned int)accMode & WRITE_OP) && IsCapPermit(CAP_DAC_WRITE)) {
fileMode |= WRITE_OP;
}
- if ((accMode & READ_OP) && IsCapPermit(CAP_DAC_READ_SEARCH)) {
+ if (((unsigned int)accMode & READ_OP) && IsCapPermit(CAP_DAC_READ_SEARCH)) {
fileMode |= READ_OP;
}
- if ((accMode & fileMode) == accMode) {
+ if (((unsigned int)accMode & fileMode) == (unsigned int)accMode) {
return FAT_PERM;
}
@@ -1190,7 +1190,7 @@ int fatfs_stat(struct inode *mountpt, const char *path, struct stat *buf)
get_stmtime(buf, &finfo);
}
- if (result == FR_INVALID_NAME) { /* root directoy */
+ if ((result == FR_INVALID_NAME) && (strlen(path) == 0)) { /* root directory */
buf->st_dev = 0;
buf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
S_IWUSR | S_IWGRP | S_IWOTH;
@@ -1256,7 +1256,6 @@ int fatfs_statfs(struct inode *mountpt, struct statfs *buf)
return fatfs_2_vfs(result);
}
- (void)memset_s((void *)buf, sizeof(struct statfs), 0, sizeof(struct statfs));
buf->f_type = MSDOS_SUPER_MAGIC;
buf->f_bfree = freClust;
buf->f_bavail = freClust;
@@ -1274,7 +1273,7 @@ int fatfs_statfs(struct inode *mountpt, struct statfs *buf)
/* Maximum length of filenames: 8 is the basename length, 1 is the dot, 3 is the extension length */
buf->f_namelen = (8 + 1 + 3);
#endif
-
+ buf->f_flags = mountpt->mountflags;
return 0;
#else
return -ENOSYS;
@@ -1331,9 +1330,10 @@ int fatfs_utime(struct inode *mountpt, const char *pathname, const struct tm * s
*/
/* fdate: bit[15:9] Year since 1980(0..127), bit[8:5] Month(0..11), bit[4:0] Day(1..31) */
- finfo.fdate = (WORD)(((set_tm->tm_year - 80) << 9) | (set_tm->tm_mon + 1) << 5 | set_tm->tm_mday);
+ finfo.fdate = (WORD)(((UINT)(set_tm->tm_year - 80) << 9) | ((UINT)(set_tm->tm_mon + 1) << 5) |
+ (UINT)set_tm->tm_mday);
/* ftime: bit[15:11] Hour(0..23), bit[10:5] Minute(0..59), bit[4:0] Second/2(0..29) */
- finfo.ftime = (WORD)(set_tm->tm_hour << 11 | set_tm->tm_min << 5 | set_tm->tm_sec >> 1);
+ finfo.ftime = (WORD)(((UINT)set_tm->tm_hour << 11) | ((UINT)set_tm->tm_min << 5) | ((UINT)set_tm->tm_sec >> 1));
result = f_utime(filePath, &finfo);
status = fatfs_2_vfs(result);
free(filePath);
@@ -1421,6 +1421,7 @@ int fatfs_closedir(struct inode *mountpt, struct fs_dirent_s *dir)
int fatfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
{
+ int i = 0;
#if FF_FS_MINIMIZE <= 1
DIR *fdir = NULL;
FILINFO fno;
@@ -1429,37 +1430,41 @@ int fatfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
FAT_CHECK(dir);
fdir = (DIR *)(dir->u.fs_dir);
- d = &dir->fd_dir;
- (void)memset_s(&fno, sizeof(FILINFO), 0, sizeof(FILINFO));
- result = f_readdir(fdir, &fno);
- if (result != FR_OK) {
- return fatfs_2_vfs(result);
+ while (i < dir->read_cnt) {
+ d = &(dir->fd_dir[i]);
+
+ (void)memset_s(&fno, sizeof(FILINFO), 0, sizeof(FILINFO));
+ result = f_readdir(fdir, &fno);
+ if (result != FR_OK) {
+ break;
+ }
+
+ /*
+ * 0x00:Reached end of directory.
+ * 0xFF:The directory is empty.
+ */
+ if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
+ break;
+ }
+
+ if (fno.fattrib & AM_DIR) {
+ d->d_type = DT_DIR;
+ } else {
+ d->d_type = DT_REG;
+ }
+
+ if (strncpy_s(d->d_name, sizeof(d->d_name), fno.fname, strlen(fno.fname)) != EOK) {
+ return -ENAMETOOLONG;
+ }
+
+ dir->fd_position++;
+ dir->fd_dir[i].d_off = dir->fd_position;
+ dir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent);
+ i++;
}
- /*
- * 0x00:Reached end of directory.
- * 0xFF:The directory is empty.
- */
- if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
- return -ENOENT;
- }
-
- if (fno.fattrib & AM_DIR) {
- d->d_type = DT_DIR;
- } else {
- d->d_type = DT_REG;
- }
-
- d->d_reclen = (WORD)sizeof(struct dirent);
-
- if (strncpy_s(d->d_name, sizeof(d->d_name), fno.fname, strlen(fno.fname)) != EOK) {
- return -ENAMETOOLONG;
- }
-
- d->d_off = dir->fd_position;
-
- return ENOERR;
+ return i;
#else
return -ENOSYS;
#endif
diff --git a/fs/fat/os_adapt/fatfs.h b/fs/fat/os_adapt/fatfs.h
new file mode 100755
index 00000000..cae3ec67
--- /dev/null
+++ b/fs/fat/os_adapt/fatfs.h
@@ -0,0 +1,100 @@
+/*
+ * 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 _FATFS_H
+#define _FATFS_H
+
+#include "fs/fs.h"
+#include "disk.h"
+#include "unistd.h"
+#include "string.h"
+#include "stdio.h"
+#include "stdlib.h"
+#include "time.h"
+#include "sys/stat.h"
+#include "sys/statfs.h"
+
+#include "inode/inode.h"
+#include "fs/dirent_fs.h"
+#include "fcntl.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#define MAX_LFNAME_LENTH 256
+#define LABEL_LEN 12
+#define FAT32_MAXSZIE 0x100000000
+#define FAT_ERROR (-1)
+extern char FatLabel[LABEL_LEN];
+
+#define VOLUME_CHAR_LENGTH 4
+#define FAT_CHECK(ptr) \
+ do { \
+ if ((ptr) == NULL) \
+ return -EINVAL; \
+ } while (0)
+
+int fatfs_bind (struct inode *blkdriver, const void *data, void **handle, const char *realpath);
+int fatfs_unbind (void *handle, struct inode **blkdriver);
+int fatfs_mkfs (const char *dev, int sectors, int option);
+int fatfs_statfs (struct inode *mountpt, struct statfs *buf);
+int fatfs_open (struct file *filep, const char *relpath, int oflags, mode_t mode);
+int fatfs_close (struct file *filep);
+int fatfs_ioctl (FAR struct file *filep, int cmd, unsigned long arg);
+ssize_t fatfs_read (struct file *filep, char *buffer, size_t buflen);
+ssize_t fatfs_write (struct file *filep, const char *buffer, size_t buflen);
+int fatfs_sync (struct file *filep);
+int fatfs_virstatfs_internel (struct inode *mountpt, const char *relpath, struct statfs *buf);
+int fatfs_dup (FAR const struct file *oldp, FAR struct file *newp);
+off_t fatfs_seek (struct file *filep, off_t offset, int whence);
+int fatfs_unlink (struct inode *mountpt, const char *relpath);
+int fatfs_rename (struct inode *mountpt, const char *oldpath, const char *newpath);
+int fatfs_stat (struct inode *mountpt, const char *path, struct stat *st);
+int fatfs_opendir (struct inode *mountpt, const char *relpath, struct fs_dirent_s *dir);
+int fatfs_closedir (struct inode *mountpt, struct fs_dirent_s *dir);
+int fatfs_readdir (struct inode *mountpt, struct fs_dirent_s *dir);
+int fatfs_rewinddir (struct inode *mountpt, struct fs_dirent_s *dir);
+int fatfs_mkdir (struct inode *mountpt, const char *relpath, mode_t mode);
+int fatfs_rmdir (struct inode *mountpt, const char *relpath);
+int fatfs_utime (struct inode *mountpt, const char *pathname, const struct tm *times);
+int fatfs_getlabel (void *handle, char *label);
+int fatfs_2_vfs (int result);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
diff --git a/fs/fat/os_adapt/format.c b/fs/fat/os_adapt/format.c
new file mode 100755
index 00000000..6ffbfb6a
--- /dev/null
+++ b/fs/fat/os_adapt/format.c
@@ -0,0 +1,99 @@
+/*
+ * 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 "errno.h"
+#include "fatfs.h"
+#include "unistd.h"
+#include "stdio.h"
+#include "string.h"
+#include "errcode_fat.h"
+#include "integer.h"
+#ifdef LOSCFG_FS_FAT
+
+#define DEV_NAME_SIZE 4
+int format(const char *dev, int sectors, int option)
+{
+ INT err;
+ if (dev == NULL) {
+ set_errno(EINVAL);
+ return -1;
+ }
+
+ if (strncmp(dev, "/dev", DEV_NAME_SIZE) != 0) {
+ PRINTK("Usage :\n");
+ PRINTK(" format \n");
+ PRINTK(" dev_inodename : the name of dev\n");
+ PRINTK(" sectors : Size of allocation unit in unit of byte or sector, ");
+ PRINTK("0 instead of default size\n");
+ PRINTK(" options : Index of filesystem. 1 for FAT filesystem, 2 for FAT32 filesystem, ");
+ PRINTK("7 for any, 8 for erase\n");
+ PRINTK(" label : The volume of device. It will be emptyed when this parameter is null\n");
+ PRINTK("Example:\n");
+ PRINTK(" format /dev/mmcblk0 128 2\n");
+
+ set_errno(EINVAL);
+ return -1;
+ }
+ err = fatfs_mkfs(dev, sectors, option);
+ if (err < 0) {
+ set_errno(-err);
+ return -1;
+ }
+#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
+ else if (err >= VIRERR_BASE) {
+ set_errno(err);
+ }
+#endif
+ return 0;
+}
+
+void set_label(const char *name)
+{
+ INT len;
+ INT err;
+
+ (void)memset_s(FatLabel, LABEL_LEN, 0, LABEL_LEN);
+
+ if (name == NULL || *name == '\0') {
+ return;
+ }
+
+ len = strlen(name);
+ if (len >= LABEL_LEN) {
+ len = LABEL_LEN - 1;
+ }
+
+ err = strncpy_s(FatLabel, LABEL_LEN, name, len);
+ if (err != EOK) {
+ PRINT_ERR("Fat set_label error");
+ }
+}
+#endif /* #ifdef CONFIG_FS_FAT */
diff --git a/fs/fat/virpart/Makefile b/fs/fat/virpart/Makefile
old mode 100644
new mode 100755
index f594da53..3ba118c3
--- a/fs/fat/virpart/Makefile
+++ b/fs/fat/virpart/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -34,7 +34,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
- -I $(LITEOSTOPDIR)/fs/fat/virpart/include
+ -I $(LITEOSTOPDIR)/fs/fat/virpart/include \
+ -I $(LITEOSTOPDIR)/fs/fat/os_adapt
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
diff --git a/fs/fat/virpart/include/virpart.h b/fs/fat/virpart/include/virpart.h
index 44a8dbc5..4341c829 100644
--- a/fs/fat/virpart/include/virpart.h
+++ b/fs/fat/virpart/include/virpart.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/fat/virpart/include/virpartff.h b/fs/fat/virpart/include/virpartff.h
index 323d8b8a..f1a24149 100644
--- a/fs/fat/virpart/include/virpartff.h
+++ b/fs/fat/virpart/include/virpartff.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/fat/virpart/src/virpart.c b/fs/fat/virpart/src/virpart.c
index d90848ca..dd5700c4 100644
--- a/fs/fat/virpart/src/virpart.c
+++ b/fs/fat/virpart/src/virpart.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/fat/virpart/src/virpartff.c b/fs/fat/virpart/src/virpartff.c
index 4f0e5da3..f20b6ed9 100644
--- a/fs/fat/virpart/src/virpartff.c
+++ b/fs/fat/virpart/src/virpartff.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/include/disk.h b/fs/include/disk.h
old mode 100644
new mode 100755
index 072cc432..77737dc3
--- a/fs/include/disk.h
+++ b/fs/include/disk.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -477,7 +477,7 @@ INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count);
* @see los_part_read
*
*/
-INT32 los_part_write(INT32 pt, VOID *buf, UINT64 sector, UINT32 count);
+INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count);
/**
* @ingroup disk
diff --git a/fs/include/fs/fd_table.h b/fs/include/fs/fd_table.h
index 7510de5c..ba98fee4 100644
--- a/fs/include/fs/fd_table.h
+++ b/fs/include/fs/fd_table.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -39,13 +39,12 @@
/* open file table for process fd */
struct file_table_s {
- signed short sysFd; /* system fd associate with the tg_filelist index */
+ intptr_t sysFd; /* system fd associate with the tg_filelist index */
};
struct fd_table_s {
unsigned int max_fds;
struct file_table_s *ft_fds; /* process fd array associate with system fd */
- fd_set *open_fds;
fd_set *proc_fds;
sem_t ft_sem; /* manage access to the file table */
};
@@ -77,4 +76,5 @@ void delete_files_snapshot(struct files_struct *files);
int alloc_fd(int minfd);
+void alloc_std_fd(struct fd_table_s *fdt);
#endif
diff --git a/fs/include/fs/fs_operation.h b/fs/include/fs/fs_operation.h
old mode 100644
new mode 100755
index 0403b299..e85cf5b4
--- a/fs/include/fs/fs_operation.h
+++ b/fs/include/fs/fs_operation.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/include/vfs_config.h b/fs/include/vfs_config.h
old mode 100644
new mode 100755
index f14b47b4..670f602d
--- a/fs/include/vfs_config.h
+++ b/fs/include/vfs_config.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -66,7 +66,7 @@ extern "C" {
/* config dirty ratio of bcache for fat file system */
-#define CONFIG_FS_FAT_DIRTY_RATIO 80
+#define CONFIG_FS_FAT_DIRTY_RATIO 60
/* config time interval of sync thread for fat file system, in milliseconds */
@@ -87,7 +87,11 @@ extern "C" {
#define CONFIG_STDIO_BUFFER_SIZE 0
#define CONFIG_NUNGET_CHARS 0
-#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) // total fds
+#define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS)
+#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
+#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
+#define TIMER_FD_OFFSET FD_SETSIZE
+#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)
/* net configure */
@@ -109,6 +113,14 @@ extern "C" {
#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS
+/* time configure */
+
+#define CONFIG_NTIME_DESCRIPTORS 0
+
+/* mqueue configure */
+
+#define CONFIG_NQUEUE_DESCRIPTORS 256
+
/* directory configure */
#define VFS_USING_WORKDIR // enable current working directory
diff --git a/fs/jffs2/Kconfig b/fs/jffs2/Kconfig
old mode 100644
new mode 100755
index 8107e31a..eac54f9d
--- a/fs/jffs2/Kconfig
+++ b/fs/jffs2/Kconfig
@@ -4,3 +4,10 @@ config FS_JFFS
depends on FS_VFS
help
Answer Y to enable LiteOS support jffs2 filesystem.
+
+config FS_JFFS2_SUMMARY
+ bool "Enable JFFS2 SUMMARY"
+ default n
+ depends on FS_JFFS
+ help
+ Answer Y to enable LiteOS jffs2 filesystem support Summary Patch.
diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile
index 8ddf1cfd..3ab5ddbe 100644
--- a/fs/jffs2/Makefile
+++ b/fs/jffs2/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -32,15 +32,15 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2/*.c) \
- $(wildcard $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2/*.c) \
- $(wildcard $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2/src/fs-ecos.c)
+ $(wildcard $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2/*.c) \
+ $(wildcard $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2/src/fs-ecos.c)
LOCAL_INCLUDE := \
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2 \
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs \
- -I $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2 \
- -I $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2/src \
- -I $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2/include/ \
- -I $(LITEOSTHIRDPARTY)/rt_thread/components/dfs/filesystems/jffs2/cyg/fileio
+ -I $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2 \
+ -I $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2/src \
+ -I $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2/include/ \
+ -I $(LITEOSTHIRDPARTY)/rt-thread/components/dfs/filesystems/jffs2/cyg/fileio
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index 180333e1..5b999391 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/proc/BUILD.gn b/fs/proc/BUILD.gn
new file mode 100755
index 00000000..122e956e
--- /dev/null
+++ b/fs/proc/BUILD.gn
@@ -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.
+
+static_library("fs_proc") {
+ sources = [
+ "os_adapt/proc_init.c",
+ "os_adapt/vfs_proc.c",
+ "src/proc_shellcmd.c",
+ "src/pseudofs.c",
+ "src/seq_file.c",
+ ]
+
+ include_dirs = [ "include" ]
+
+ if (LOSCFG_LLTREPORT) {
+ cflags += [
+ "-fprofile-arcs",
+ "-ftest-coverage",
+ ]
+ }
+}
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
new file mode 100644
index 00000000..1d8e320b
--- /dev/null
+++ b/fs/proc/Kconfig
@@ -0,0 +1,6 @@
+config FS_PROC
+ bool "Enable PROC"
+ default y
+ depends on FS_VFS
+ help
+ Answer Y to enable LiteOS support proc filesystem.
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
new file mode 100644
index 00000000..2b8d72e6
--- /dev/null
+++ b/fs/proc/Makefile
@@ -0,0 +1,38 @@
+# 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 $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard os_adapt/*.c) $(wildcard src/*.c)
+
+LOCAL_FLAGS := $(LITEOS_GCOV_OPTS)
+
+include $(MODULE)
\ No newline at end of file
diff --git a/kernel/base/core/los_timeslice.c b/fs/proc/include/internal.h
old mode 100644
new mode 100755
similarity index 67%
rename from kernel/base/core/los_timeslice.c
rename to fs/proc/include/internal.h
index 1e8601b4..886ab3ce
--- a/kernel/base/core/los_timeslice.c
+++ b/fs/proc/include/internal.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,8 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "los_timeslice_pri.h"
-#include "los_process_pri.h"
+#ifndef _PROC_INTERNAL_H
+#define _PROC_INTERNAL_H
+
+#include "proc_fs.h"
#ifdef __cplusplus
#if __cplusplus
@@ -38,38 +40,32 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-LITE_OS_SEC_TEXT VOID OsTimesliceCheck(VOID)
-{
- LosTaskCB *runTask = NULL;
- LosProcessCB *runProcess = OsCurrProcessGet();
- if (runProcess->policy != LOS_SCHED_RR) {
- goto SCHED_TASK;
- }
+#define MAX_NON_LFS ((1UL << 31) - 1)
- if (runProcess->timeSlice != 0) {
- runProcess->timeSlice--;
- if (runProcess->timeSlice == 0) {
- LOS_Schedule();
- }
- }
+extern spinlock_t procfsLock;
+extern bool procfsInit;
-SCHED_TASK:
- runTask = OsCurrTaskGet();
- if (runTask->policy != LOS_SCHED_RR) {
- return;
- }
+void ProcVmmInit(void);
- if (runTask->timeSlice != 0) {
- runTask->timeSlice--;
- if (runTask->timeSlice == 0) {
- LOS_Schedule();
- }
- }
-}
+void ProcProcessInit(void);
+
+void ProcKernelTraceInit(void);
+
+int ProcMatch(unsigned int len, const char *name, struct ProcDirEntry *pde);
+
+struct ProcDirEntry *ProcFindEntry(const char *path);
+
+void ProcFreeEntry(struct ProcDirEntry *pde);
+
+extern int ProcStat(const char *file, struct ProcStat *buf);
+
+extern void ProcMountsInit(void);
+
+extern void ProcUptimeInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
-
+#endif
diff --git a/fs/proc/include/proc_file.h b/fs/proc/include/proc_file.h
new file mode 100755
index 00000000..245ad39e
--- /dev/null
+++ b/fs/proc/include/proc_file.h
@@ -0,0 +1,184 @@
+/*
+ * 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 PROC_FILE_H
+#define PROC_FILE_H
+
+#include "proc_fs.h"
+
+/**
+ * @ingroup procfs
+ * @brief open a proc node
+ *
+ * @par Description:
+ * This API is used to open the node by 'fileName' and flags,
+ *
+ * @attention
+ *
+ *
+ * @param fileName [IN] Type #const char * the fileName of the node to be opened
+ * @param flags [IN] Type #int the flags of open's node
+ *
+ * @retval #NULL open failed
+ * @retval #NOT NULL open successfully
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_close
+ *
+ */
+extern struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...);
+
+/**
+ * @ingroup procfs
+ * @brief read a proc node
+ *
+ * @par Description:
+ * This API is used to read the node by pde
+ *
+ * @attention
+ *
+ *
+ * @param pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be read
+ * @param buf [IN] Type #void * user-provided to save the data
+ * @param len [IN] Type #size_t the length of want to read
+ *
+ * @retval #-1 read failed
+ * @retval #>0 Number of bytes read success
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_open
+ *
+ */
+extern int ReadProcFile(struct ProcDirEntry *pde, void *buf, size_t len);
+
+/**
+ * @ingroup procfs
+ * @brief write a proc node
+ *
+ * @par Description:
+ * This API is used to write the node by pde
+ *
+ * @attention
+ *
+ *
+ * @param pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be written
+ * @param buf [IN] Type #const void * data to write
+ * @param len [IN] Type #size_t length of data to write
+ *
+ * @retval #-1 write failed
+ * @retval #>0 Number of bytes write successfully
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_open
+ *
+ */
+extern int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len);
+
+/**
+ * @ingroup procfs
+ * @brief File migration
+ *
+ * @par Description:
+ * This API is used to set the proc file migration
+ *
+ * @attention
+ *
+ *
+ * @param pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be deviation
+ * @param offset [IN] Type #loff_t the number of deviation
+ * @param whence [IN] Type #int the begin of deviation
+ *
+ * @retval #<0 deviation failed
+ * @retval #>=0 deviation successfully
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_open
+ *
+ */
+extern loff_t LseekProcFile(struct ProcDirEntry *pde, loff_t offset, int whence);
+
+/**
+ * @ingroup procfs
+ * @brief directory migration
+ *
+ * @par Description:
+ * This API is used to set the proc directory migration
+ *
+ * @attention
+ *
+ * Only allow SEEK_SET to zero.
+ *
+ *
+ * @param pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be deviated
+ * @param pos [IN] Type #off_t * the number of deviation
+ * @param whence [IN] Type #int the begin of deviation
+ *
+ * @retval #EINVAL deviation failed
+ * @retval #ENOERR deviation successfully
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_open
+ *
+ */
+int LseekDirProcFile(struct ProcDirEntry *pde, off_t *pos, int whence);
+
+/**
+ * @ingroup procfs
+ * @brief close a proc node
+ *
+ * @par Description:
+ * This API is used to close the node by pde
+ *
+ * @attention
+ *
+ *
+ * @param pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be closed
+ *
+ * @retval #-1 close failed
+ * @retval #0 close successfully
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see proc_open
+ *
+ */
+extern int CloseProcFile(struct ProcDirEntry *pde);
+
+#endif
diff --git a/fs/proc/include/proc_fs.h b/fs/proc/include/proc_fs.h
new file mode 100755
index 00000000..3106fc5b
--- /dev/null
+++ b/fs/proc/include/proc_fs.h
@@ -0,0 +1,270 @@
+/*
+ * 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 _PROC_FS_H
+#define _PROC_FS_H
+
+#include
+#include
+
+#include "los_config.h"
+
+#ifdef LOSCFG_FS_PROC
+#include "linux/spinlock.h"
+#include "asm/atomic.h"
+#include "fs/file.h"
+#include "los_seq_buf.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+typedef unsigned short fmode_t;
+#define MAX_NAMELEN 32
+#define PROC_ERROR (-1)
+
+/* 64bit hashes as llseek() offset (for directories) */
+#define FMODE_64BITHASH ((fmode_t)0x400)
+/* 32bit hashes as llseek() offset (for directories) */
+#define FMODE_32BITHASH ((fmode_t)0x200)
+/* File is opened using open(.., 3, ..) and is writeable only for ioctls
+ * (specialy hack for floppy.c)
+ */
+#define FMODE_WRITE_IOCTL ((fmode_t)0x100)
+/* File is opened with O_EXCL (only set for block devices) */
+#define FMODE_EXCL ((fmode_t)0x80)
+/* File is opened with O_NDELAY (only set for block devices) */
+#define FMODE_NDELAY ((fmode_t)0x40)
+/* File is opened for execution with sys_execve / sys_uselib */
+#define FMODE_EXEC ((fmode_t)0x20)
+/* file can be accessed using pwrite */
+#define FMODE_PWRITE ((fmode_t)0x10)
+/* file can be accessed using pread */
+#define FMODE_PREAD ((fmode_t)0x8)
+/* file is seekable */
+#define FMODE_LSEEK ((fmode_t)0x4)
+/* file is open for writing */
+#define FMODE_WRITE ((fmode_t)0x2)
+/* file is open for reading */
+#define FMODE_READ ((fmode_t)0x1)
+
+struct ProcFile;
+
+struct ProcFileOperations {
+ char *name;
+ ssize_t (*write)(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos);
+ int (*open)(struct inode *inode, struct ProcFile *pf);
+ int (*release)(struct inode *inode, struct ProcFile *pf);
+ int (*read)(struct SeqBuf *m, void *v);
+};
+
+struct ProcDirEntry {
+ mode_t mode;
+ int flags;
+ const struct ProcFileOperations *procFileOps;
+ struct ProcFile *pf;
+ struct ProcDirEntry *next, *parent, *subdir;
+ void *data;
+ atomic_t count; /* open file count */
+ spinlock_t pdeUnloadLock;
+
+ int nameLen;
+ struct ProcDirEntry *pdirCurrent;
+ char name[MAX_NAMELEN];
+};
+
+struct ProcFile {
+ fmode_t fMode;
+ spinlock_t fLock;
+ atomic_t fCount;
+ struct SeqBuf *sbuf;
+ struct ProcDirEntry *pPDE;
+ unsigned long long fVersion;
+ loff_t fPos;
+ char name[MAX_NAMELEN];
+};
+
+struct ProcStat {
+ mode_t stMode;
+ struct ProcDirEntry *pPDE;
+ char name[MAX_NAMELEN];
+};
+
+struct ProcData {
+ ssize_t size;
+ loff_t fPos;
+ char buf[1];
+};
+
+#define PROCDATA(n) (sizeof(struct ProcData) + (n))
+
+#define S_IALLUGO (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
+
+/**
+ * Interface for modules using proc below internal proc moudule;
+ */
+/**
+ * @ingroup procfs
+ * @brief create a proc node
+ *
+ * @par Description:
+ * This API is used to create the node by 'name' and parent inode
+ *
+ * @attention
+ *
+ * This interface should be called after system initialization.
+ * The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] Type #const char * The name of the node to be created.
+ * @param mode [IN] Type #mode_t the mode of create's node.
+ * @param parent [IN] Type #struct ProcDirEntry * the parent node of the node to be created,
+ * if pass NULL, default parent node is "/proc".
+ *
+ * @retval #NULL Create failed.
+ * @retval #ProcDirEntry* Create successfully.
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see
+ *
+ */
+extern struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcDirEntry *parent);
+
+/**
+ * @ingroup procfs
+ * @brief remove a proc node
+ *
+ * @par Description:
+ * This API is used to remove the node by 'name' and parent inode
+ *
+ * @attention
+ *
+ * This interface should be called after system initialization.
+ * The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] Type #const char * The name of the node to be removed.
+ * @param parent [IN] Type #struct ProcDirEntry * the parent node of the node to be remove.
+ *
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see
+ *
+ */
+extern void RemoveProcEntry(const char *name, struct ProcDirEntry *parent);
+
+/**
+ * @ingroup procfs
+ * @brief create a proc directory node
+ *
+ * @par Description:
+ * This API is used to create the directory node by 'name' and parent inode
+ *
+ * @attention
+ *
+ * This interface should be called after system initialization.
+ * The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] Type #const char * The name of the node directory to be created.
+ * @param parent [IN] Type #struct ProcDirEntry * the parent node of the directory node to be created,
+ * if pass NULL, default parent node is "/proc".
+ *
+ * @retval #NULL Create failed.
+ * @retval #ProcDirEntry* Create successfully.
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see
+ *
+ */
+extern struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *parent);
+
+/**
+ * @ingroup procfs
+ * @brief create a proc node
+ *
+ * @par Description:
+ * This API is used to create the node by 'name' and parent inode,
+ * And assignment operation function
+ *
+ * @attention
+ *
+ * This interface should be called after system initialization.
+ * The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] Type #const char * The name of the node to be created.
+ * @param mode [IN] Type #mode_t the mode of create's node.
+ * @param parent [IN] Type #struct ProcDirEntry * the parent node of the node to be created.
+ * @param procFops [IN] Type #const struct ProcFileOperations * operation function of the node.
+ *
+ * @retval #NULL Create failed.
+ * @retval #ProcDirEntry* Create successfully.
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see
+ *
+ */
+extern struct ProcDirEntry *ProcCreate(const char *name, mode_t mode,
+ struct ProcDirEntry *parent, const struct ProcFileOperations *procFops);
+
+/**
+ * @ingroup procfs
+ * @brief init proc fs
+ *
+ * @par Description:
+ * This API is used to init proc fs.
+ *
+ * @attention
+ *
+ *
+ * @param NONE
+ *
+ * @retval NONE
+ * @par Dependency:
+ * proc_fs.h: the header file that contains the API declaration.
+ * @see ProcFsInit
+ *
+ */
+extern void ProcFsInit(void);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* LOSCFG_FS_PROC */
+#endif /* _PROC_FS_H */
diff --git a/fs/proc/os_adapt/kernel_trace_proc.c b/fs/proc/os_adapt/kernel_trace_proc.c
new file mode 100755
index 00000000..dbb77853
--- /dev/null
+++ b/fs/proc/os_adapt/kernel_trace_proc.c
@@ -0,0 +1,68 @@
+/*
+ * 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
+#include
+#include "proc_fs.h"
+#include "los_trace.h"
+
+#ifdef LOSCFG_KERNEL_TRACE
+static int KernelTraceProcFill(struct SeqBuf *m, void *v)
+{
+ (void)v;
+ if (m == NULL) {
+ return -LOS_EPERM;
+ }
+
+ if (m->buf == NULL) {
+ m->buf = (char *)LOS_TraceBufDataGet(&(m->size), &(m->count));
+ }
+ return 0;
+}
+
+static const struct ProcFileOperations KERNEL_TRACE_PROC_FOPS = {
+ .read = KernelTraceProcFill,
+};
+#endif
+
+void ProcKernelTraceInit(void)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ struct ProcDirEntry *pde = CreateProcEntry("ktrace", 0, NULL);
+ if (pde == NULL) {
+ PRINT_ERR("create /proc/ktrace error!\n");
+ return;
+ }
+
+ pde->procFileOps = &KERNEL_TRACE_PROC_FOPS;
+#endif
+}
+
diff --git a/fs/proc/os_adapt/mounts_proc.c b/fs/proc/os_adapt/mounts_proc.c
new file mode 100755
index 00000000..692511d6
--- /dev/null
+++ b/fs/proc/os_adapt/mounts_proc.c
@@ -0,0 +1,100 @@
+/*
+ * 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 "internal.h"
+#include
+#include
+#include
+#include "proc_fs.h"
+
+static int ShowType(FAR const char *mountPoint, FAR struct statfs *statBuf, FAR void *arg)
+{
+ struct SeqBuf *seqBuf = (struct SeqBuf *)arg;
+ char *type = NULL;
+ char *name = NULL;
+
+ switch (statBuf->f_type) {
+ case PROCFS_MAGIC:
+ type = "proc";
+ name = "proc";
+ break;
+ case JFFS2_SUPER_MAGIC:
+ type = "jffs";
+ name = "jffs";
+ break;
+ case NFS_SUPER_MAGIC:
+ type = "nfs";
+ name = "nfs";
+ break;
+ case TMPFS_MAGIC:
+ type = "tmpfs";
+ name = "tmpfs";
+ break;
+ case MSDOS_SUPER_MAGIC:
+ type = "vfat";
+ name = "fat";
+ break;
+ case ZPFS_MAGIC:
+ type = "zpfs";
+ name = "zpfs";
+ break;
+ default:
+ return 0;
+ }
+
+ (void)LosBufPrintf(seqBuf, "%s %s %s\n", name, mountPoint, type);
+
+ return 0;
+}
+
+static int MountsProcFill(struct SeqBuf *m, void *v)
+{
+ foreach_mountpoint_t handler = ShowType;
+ (void)foreach_mountpoint(handler, (FAR void *)m);
+
+ return 0;
+}
+
+static const struct ProcFileOperations MOUNTS_PROC_FOPS = {
+ .read = MountsProcFill,
+};
+
+void ProcMountsInit(void)
+{
+ struct ProcDirEntry *pde = CreateProcEntry("mounts", 0, NULL);
+ if (pde == NULL) {
+ PRINT_ERR("creat mounts error!\n");
+ return;
+ }
+
+ pde->procFileOps = &MOUNTS_PROC_FOPS;
+}
+
diff --git a/fs/proc/os_adapt/proc_init.c b/fs/proc/os_adapt/proc_init.c
new file mode 100755
index 00000000..5718ab94
--- /dev/null
+++ b/fs/proc/os_adapt/proc_init.c
@@ -0,0 +1,63 @@
+/*
+ * 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 "internal.h"
+#include
+#include
+#include "proc_fs.h"
+
+#ifdef LOSCFG_FS_PROC
+
+void ProcFsInit(void)
+{
+ int ret;
+
+ ret = mkdir(PROCFS_MOUNT_POINT, 0);
+ if (ret < 0) {
+ PRINT_ERR("failed to reserve inode %s\n", PROCFS_MOUNT_POINT);
+ return;
+ }
+
+ ret = mount(NULL, PROCFS_MOUNT_POINT, "procfs", 0, NULL);
+ if (ret) {
+ PRINT_ERR("mount procfs err %d\n", ret);
+ return;
+ }
+ PRINTK("Mount procfs finished.\n");
+ ProcMountsInit();
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+ ProcVmmInit();
+#endif
+ ProcProcessInit();
+ ProcUptimeInit();
+ ProcKernelTraceInit();
+}
+#endif
diff --git a/fs/proc/os_adapt/process_proc.c b/fs/proc/os_adapt/process_proc.c
new file mode 100755
index 00000000..65fe78bb
--- /dev/null
+++ b/fs/proc/os_adapt/process_proc.c
@@ -0,0 +1,58 @@
+/*
+ * 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
+#include
+#include "proc_fs.h"
+#include "los_process_pri.h"
+
+static int ProcessProcFill(struct SeqBuf *m, void *v)
+{
+ (void)v;
+ (void)OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, m, OS_PROCESS_INFO_ALL);
+ return 0;
+}
+
+static const struct ProcFileOperations PROCESS_PROC_FOPS = {
+ .read = ProcessProcFill,
+};
+
+void ProcProcessInit(void)
+{
+ struct ProcDirEntry *pde = CreateProcEntry("process", 0, NULL);
+ if (pde == NULL) {
+ PRINT_ERR("create /proc/process error!\n");
+ return;
+ }
+
+ pde->procFileOps = &PROCESS_PROC_FOPS;
+}
+
diff --git a/fs/proc/os_adapt/uptime_proc.c b/fs/proc/os_adapt/uptime_proc.c
new file mode 100755
index 00000000..d30e62c1
--- /dev/null
+++ b/fs/proc/os_adapt/uptime_proc.c
@@ -0,0 +1,87 @@
+/*
+ * 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 "proc_fs.h"
+#include "time.h"
+#include "errno.h"
+#include "los_cpup.h"
+
+#define MSEC_TO_NSEC 1000000
+#define SEC_TO_MSEC 1000
+#define DECIMAL_TO_PERCENT 100
+
+static int UptimeProcFill(struct SeqBuf *seqBuf, void *v)
+{
+ struct timespec curtime = {0, 0};
+ int ret;
+#ifdef LOSCFG_KERNEL_CPUP
+ float idleRate;
+ float idleMSec;
+ float usage;
+#endif
+ ret = clock_gettime(CLOCK_MONOTONIC, &curtime);
+ if (ret < 0) {
+ PRINT_ERR("clock_gettime error!\n");
+ return -get_errno();
+ }
+
+#ifdef LOSCFG_KERNEL_CPUP
+ usage = (float)LOS_HistorySysCpuUsage(CPUP_ALL_TIME);
+ idleRate = LOSCFG_KERNEL_CORE_NUM - usage / LOS_CPUP_PRECISION_MULT / DECIMAL_TO_PERCENT;
+ idleMSec = ((float)curtime.tv_sec * SEC_TO_MSEC + curtime.tv_nsec / MSEC_TO_NSEC) * idleRate;
+
+ (void)LosBufPrintf(seqBuf, "%llu.%03llu %llu.%03llu\n", (unsigned long long)curtime.tv_sec,
+ (unsigned long long)(curtime.tv_nsec / MSEC_TO_NSEC),
+ (unsigned long long)(idleMSec / SEC_TO_MSEC),
+ (unsigned long long)((unsigned long long)idleMSec % SEC_TO_MSEC));
+#else
+ (void)LosBufPrintf(seqBuf, "%llu.%03llu\n", (unsigned long long)curtime.tv_sec,
+ (unsigned long long)(curtime.tv_nsec / MSEC_TO_NSEC));
+
+#endif
+ return 0;
+}
+
+static const struct ProcFileOperations UPTIME_PROC_FOPS = {
+ .read = UptimeProcFill,
+};
+
+void ProcUptimeInit(void)
+{
+ struct ProcDirEntry *pde = CreateProcEntry("uptime", 0, NULL);
+ if (pde == NULL) {
+ PRINT_ERR("creat /proc/uptime error!\n");
+ return;
+ }
+
+ pde->procFileOps = &UPTIME_PROC_FOPS;
+}
+
diff --git a/fs/proc/os_adapt/vfs_proc.c b/fs/proc/os_adapt/vfs_proc.c
new file mode 100755
index 00000000..a45c980b
--- /dev/null
+++ b/fs/proc/os_adapt/vfs_proc.c
@@ -0,0 +1,432 @@
+/*
+ * 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
+#include
+#include
+#include
+#include "internal.h"
+#include "fs/dirent_fs.h"
+#include "los_tables.h"
+#include "proc_file.h"
+
+#ifdef LOSCFG_FS_PROC
+
+static char *ProcfsChangePath(const char *relpath, int namelen)
+{
+ char *path = (char *)relpath;
+
+ if (*relpath != 0) {
+ path = path - (namelen + 1); /* "/proc/xxx" need left avertence "/proc/" */
+ } else {
+ path = path - namelen;
+ }
+
+ return path;
+}
+
+int VfsProcfsOpen(struct file *filep, const char *relpath, int oflags, mode_t mode)
+{
+ struct ProcDirEntry *pde = NULL;
+ if (filep == NULL) {
+ return -EINVAL;
+ }
+ if ((unsigned int)oflags & O_DIRECTORY) {
+ return -EACCES;
+ }
+ pde = OpenProcFile(filep->f_path, oflags);
+ if (pde == NULL) {
+ if ((unsigned int)oflags & O_CREAT) {
+ return -EPERM;
+ }
+ return -ENOENT;
+ }
+ if (((unsigned int)oflags & O_CREAT) && ((unsigned int)oflags & O_EXCL)) {
+ (void)CloseProcFile(pde);
+ return -EEXIST;
+ }
+ if (S_ISDIR(pde->mode)) {
+ (void)CloseProcFile(pde);
+ return -EISDIR;
+ }
+ filep->f_priv = (void *)pde;
+ filep->f_pos = 0;
+
+ return 0;
+}
+
+int VfsProcfsClose(struct file *filep)
+{
+ if (filep == NULL) {
+ return -EINVAL;
+ }
+ return CloseProcFile((struct ProcDirEntry *)filep->f_priv);
+}
+
+ssize_t VfsProcfsRead(struct file *filep, FAR char *buffer, size_t buflen)
+{
+ ssize_t size;
+ struct ProcDirEntry *pde = NULL;
+ if ((filep == NULL) || (buffer == NULL)) {
+ return -EINVAL;
+ }
+
+ pde = (struct ProcDirEntry *)filep->f_priv;
+ size = (ssize_t)ReadProcFile(pde, (void *)buffer, buflen);
+ filep->f_pos = pde->pf->fPos;
+
+ return size;
+}
+
+ssize_t VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
+{
+ ssize_t size;
+ struct ProcDirEntry *pde = NULL;
+ if ((filep == NULL) || (buffer == NULL)) {
+ return -EINVAL;
+ }
+
+ pde = (struct ProcDirEntry *)filep->f_priv;
+ size = (ssize_t)WriteProcFile(pde, (void *)buffer, buflen);
+ filep->f_pos = pde->pf->fPos;
+
+ return size;
+}
+
+off_t VfsProcfsLseek(struct file *filep, off_t offset, int whence)
+{
+ loff_t off;
+ struct ProcDirEntry *pde = NULL;
+ if (filep == NULL) {
+ return -EINVAL;
+ }
+
+ pde = (struct ProcDirEntry *)filep->f_priv;
+ if (pde == NULL) {
+ return -EINVAL;
+ }
+
+ off = LseekProcFile(pde, (loff_t)offset, whence);
+ filep->f_pos = pde->pf->fPos;
+
+ return (off_t)off;
+}
+
+loff_t VfsProcfsLseek64(struct file *filep, loff_t offset, int whence)
+{
+ loff_t off;
+ struct ProcDirEntry *pde = NULL;
+ if (filep == NULL) {
+ return -EINVAL;
+ }
+
+ pde = (struct ProcDirEntry *)filep->f_priv;
+ if (pde == NULL) {
+ return -EINVAL;
+ }
+
+ off = LseekProcFile(pde, offset, whence);
+ filep->f_pos = pde->pf->fPos;
+
+ return off;
+}
+
+int VfsProcfsIoctl(struct file *filep, int cmd, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+int VfsProcfsSync(struct file *filep)
+{
+ return -ENOSYS;
+}
+
+int VfsProcfsDup(const struct file *oldp, struct file *newp)
+{
+ return -ENOSYS;
+}
+
+int VfsProcfsOpenDir(struct inode *mountpt, const char *relpath, struct fs_dirent_s *dir)
+{
+ struct ProcDirEntry *pde = NULL;
+ char *path = NULL;
+ int oflags = O_APPEND;
+
+ if (dir == NULL) {
+ return -EINVAL;
+ }
+
+ path = ProcfsChangePath(relpath, PROCFS_MOUNT_POINT_SIZE);
+ pde = OpenProcFile(path, oflags);
+ if (pde == NULL) {
+ return -ENOENT;
+ }
+ if (S_ISREG(pde->mode)) {
+ (void)CloseProcFile(pde);
+ return -ENOTDIR;
+ }
+
+ dir->u.fs_dir = (fs_dir_s)pde;
+
+ return 0;
+}
+
+int VfsProcfsCloseDir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ if (dir == NULL) {
+ return -EINVAL;
+ }
+
+ return CloseProcFile((struct ProcDirEntry *)dir->u.fs_dir);
+}
+
+int VfsProcfsReadDir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ int result;
+ char *buffer = NULL;
+ int buflen = MAX_NAMELEN;
+ unsigned int min_size;
+ unsigned int dst_name_size;
+ struct ProcDirEntry *pde = NULL;
+ int i = 0;
+ if (dir == NULL) {
+ return -EINVAL;
+ }
+ pde = (struct ProcDirEntry *)dir->u.fs_dir;
+
+ buffer = (char *)malloc(sizeof(char) * MAX_NAMELEN);
+ if (buffer == NULL) {
+ PRINT_ERR("malloc failed\n");
+ return -ENOMEM;
+ }
+
+ while (i < dir->read_cnt) {
+ (void)memset_s(buffer, MAX_NAMELEN, 0, MAX_NAMELEN);
+
+ result = ReadProcFile(pde, (void *)buffer, buflen);
+ if (result != ENOERR) {
+ break;
+ }
+ dst_name_size = sizeof(dir->fd_dir[i].d_name);
+ min_size = (dst_name_size < MAX_NAMELEN) ? dst_name_size : MAX_NAMELEN;
+ result = strncpy_s(dir->fd_dir[i].d_name, dst_name_size, buffer, min_size);
+ if (result != EOK) {
+ free(buffer);
+ return -ENAMETOOLONG;
+ }
+ dir->fd_dir[i].d_name[dst_name_size - 1] = '\0';
+ dir->fd_position++;
+ dir->fd_dir[i].d_off = dir->fd_position;
+ dir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent);
+ i++;
+ }
+
+ free(buffer);
+ return i;
+}
+
+int VfsProcfsRewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ int ret;
+ off_t pos = 0;
+
+ if (dir == NULL) {
+ return -EINVAL;
+ }
+
+ ret = LseekDirProcFile((struct ProcDirEntry *)dir->u.fs_dir, &pos, SEEK_SET);
+ if (ret != ENOERR) {
+ return -ret;
+ }
+
+ return 0;
+}
+
+int VfsProcfsBind(struct inode *blkdriver, const void *data, FAR void **handle, const char *relpath)
+{
+ int len, length;
+
+ if (relpath == NULL) {
+ return -EINVAL;
+ }
+
+ len = strlen(relpath) + 1;
+ length = strlen(PROCFS_MOUNT_POINT) + 1;
+ if ((len == length) && !strncmp(relpath, PROCFS_MOUNT_POINT, length)) {
+ spin_lock_init(&procfsLock);
+ procfsInit = true;
+ return ENOERR;
+ }
+
+ return -EPERM;
+}
+
+int VfsProcfsUnbind(void *handle, struct inode **blkdriver)
+{
+ return -EPERM;
+}
+
+int VfsProcfsStatfs(struct inode *mountpt, struct statfs *buf)
+{
+ if (buf == NULL) {
+ return -EINVAL;
+ }
+
+ (void)memset_s(buf, sizeof(struct statfs), 0, sizeof(struct statfs));
+ buf->f_type = PROCFS_MAGIC;
+
+ return OK;
+}
+
+int VfsProcfsUnlink(struct inode *mountpt, const char *relpath)
+{
+ struct ProcDirEntry *pde = NULL;
+ char *path = NULL;
+
+ if (relpath == NULL) {
+ return -EINVAL;
+ }
+
+ path = ProcfsChangePath(relpath, PROCFS_MOUNT_POINT_SIZE);
+ pde = ProcFindEntry(path);
+ if (pde == NULL) {
+ return -ENOENT;
+ }
+ if (S_ISDIR(pde->mode)) {
+ return -EISDIR;
+ }
+
+ return -EACCES;
+}
+
+int VfsProcfsMkdir(struct inode *mountpt, const char *relpath, mode_t mode)
+{
+ struct ProcDirEntry *pde = NULL;
+ char *path = NULL;
+
+ if (relpath == NULL) {
+ return -EINVAL;
+ }
+
+ path = ProcfsChangePath(relpath, PROCFS_MOUNT_POINT_SIZE);
+ pde = ProcFindEntry(path);
+ if (pde == NULL) {
+ return -ENOENT;
+ }
+
+ return -EEXIST;
+}
+
+int VfsProcfsRmdir(struct inode *mountpt, const char *relpath)
+{
+ struct ProcDirEntry *pde = NULL;
+ char *path = NULL;
+
+ if (relpath == NULL) {
+ return -EINVAL;
+ }
+
+ path = ProcfsChangePath(relpath, PROCFS_MOUNT_POINT_SIZE);
+ pde = ProcFindEntry(path);
+ if (pde == NULL) {
+ return -ENOENT;
+ }
+
+ return -EACCES;
+}
+
+int VfsProcfsRename(struct inode *mountpt, const char *oldrelpath, const char *newrelpath)
+{
+ return -ENOSYS;
+}
+
+int VfsProcfsStat(struct inode *mountpt, const char *relpath, struct stat *buf)
+{
+ int result;
+ struct ProcStat statbuf;
+ char *path = NULL;
+
+ if ((relpath == NULL) || (buf == NULL)) {
+ return -EINVAL;
+ }
+
+ path = ProcfsChangePath(relpath, PROCFS_MOUNT_POINT_SIZE);
+ result = ProcStat(path, &statbuf);
+ if (result != ENOERR) {
+ return -result;
+ }
+ (void)memset_s(buf, sizeof(struct stat), 0, sizeof(struct stat));
+ buf->st_mode = statbuf.stMode;
+
+ return 0;
+}
+
+const struct mountpt_operations procfs_operations = {
+ VfsProcfsOpen, /* open */
+ VfsProcfsClose, /* close */
+ VfsProcfsRead, /* read */
+ VfsProcfsWrite, /* write */
+ VfsProcfsLseek, /* seek */
+ VfsProcfsIoctl, /* ioctl */
+ NULL, /* mmap */
+ VfsProcfsSync, /* sync */
+ VfsProcfsDup, /* dup */
+ NULL, /* fstat */
+ NULL, /* truncate */
+ VfsProcfsOpenDir, /* opendir */
+ VfsProcfsCloseDir, /* closedir */
+ VfsProcfsReadDir, /* readdir */
+ VfsProcfsRewinddir, /* rewinddir */
+ VfsProcfsBind, /* bind */
+ VfsProcfsUnbind, /* unbind */
+ VfsProcfsStatfs, /* statfs */
+ NULL, /* virstatfs */
+ VfsProcfsUnlink, /* unlink */
+ VfsProcfsMkdir, /* mkdir */
+ VfsProcfsRmdir, /* rmdir */
+ VfsProcfsRename, /* rename */
+ VfsProcfsStat, /* stat */
+ NULL, /* for utime */
+ NULL, /* chattr */
+ VfsProcfsLseek64, /* seek64 */
+ NULL, /* getlabel */
+ NULL, /* fallocate */
+ NULL, /* fallocate64 */
+ NULL, /* truncate64 */
+ NULL, /* fscheck */
+ NULL, /* map_pages */
+ NULL, /* readpage */
+ NULL, /* writepage */
+};
+
+FSMAP_ENTRY(procfs_fsmap, "procfs", procfs_operations, FALSE, FALSE);
+
+#endif
diff --git a/fs/proc/os_adapt/vmm_proc.c b/fs/proc/os_adapt/vmm_proc.c
new file mode 100755
index 00000000..ff28b568
--- /dev/null
+++ b/fs/proc/os_adapt/vmm_proc.c
@@ -0,0 +1,114 @@
+/*
+ * 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
+#include
+#include "proc_fs.h"
+
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+#include "los_vm_map.h"
+#include "los_vm_dump.h"
+#include "los_vm_lock.h"
+#include "los_process_pri.h"
+
+STATIC VOID OsVmDumpSeqSpaces(struct SeqBuf *seqBuf)
+{
+ LosVmSpace *space = NULL;
+ LosVmMapRegion *region = NULL;
+ LosRbNode *pstRbNode = NULL;
+ LosRbNode *pstRbNodeNext = NULL;
+ UINT32 pssPages = 0;
+ UINT32 spacePages;
+ UINT32 regionPages;
+ LosProcessCB *pcb = NULL;
+ LOS_DL_LIST *aspaceList = LOS_GetVmSpaceList();
+ LosMux *aspaceListMux = OsGVmSpaceMuxGet();
+
+ (VOID)LOS_MuxAcquire(aspaceListMux);
+ LOS_DL_LIST_FOR_EACH_ENTRY(space, aspaceList, LosVmSpace, node) {
+ (VOID)LOS_MuxAcquire(&space->regionMux);
+ spacePages = OsCountAspacePages(space);
+ pcb = OsGetPIDByAspace(space);
+ if (pcb == NULL) {
+ (VOID)LOS_MuxRelease(&space->regionMux);
+ continue;
+ }
+ (VOID)LosBufPrintf(seqBuf, "\r\n PID aspace name base size pages \n");
+ (VOID)LosBufPrintf(seqBuf, " ---- ------ ---- ---- ----- ----\n");
+ (VOID)LosBufPrintf(seqBuf, " %-4d %#010x %-10.10s %#010x %#010x %d\n",
+ pcb->processID, space, pcb->processName, space->base, space->size, spacePages);
+ (VOID)LosBufPrintf(seqBuf,
+ "\r\n\t region name base size mmu_flags pages pg/ref\n");
+ (VOID)LosBufPrintf(seqBuf,
+ "\t ------ ---- ---- ---- --------- ----- -----\n");
+
+ RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)
+ region = (LosVmMapRegion *)pstRbNode;
+ regionPages = OsCountRegionPages(space, region, &pssPages);
+ CHAR *flagsStr = OsArchFlagsToStr(region->regionFlags);
+ if (flagsStr == NULL) {
+ break;
+ }
+ (VOID)LosBufPrintf(seqBuf, "\t %#010x %-19.19s %#010x %#010x %-15.15s %4d %4d\n",
+ region, OsGetRegionNameOrFilePath(region), region->range.base,
+ region->range.size, flagsStr, regionPages, pssPages);
+ (VOID)LOS_MemFree(m_aucSysMem0, flagsStr);
+ (VOID)OsRegionOverlapCheck(space, region);
+ RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
+ (VOID)LOS_MuxRelease(&space->regionMux);
+ }
+ (VOID)LOS_MuxRelease(aspaceListMux);
+}
+
+static int VmmProcFill(struct SeqBuf *m, void *v)
+{
+ (void)v;
+ OsVmDumpSeqSpaces(m);
+
+ return 0;
+}
+
+static const struct ProcFileOperations VMM_PROC_FOPS = {
+ .write = NULL,
+ .read = VmmProcFill,
+};
+
+void ProcVmmInit(void)
+{
+ struct ProcDirEntry *pde = CreateProcEntry("vmm", 0, NULL);
+ if (pde == NULL) {
+ PRINT_ERR("create /proc/vmm error!\n");
+ return;
+ }
+
+ pde->procFileOps = &VMM_PROC_FOPS;
+}
+#endif
diff --git a/fs/proc/src/proc_file.c b/fs/proc/src/proc_file.c
new file mode 100755
index 00000000..6acffeb3
--- /dev/null
+++ b/fs/proc/src/proc_file.c
@@ -0,0 +1,685 @@
+/*
+ * 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 "proc_fs.h"
+#include
+#include
+#include
+#include "internal.h"
+#include "user_copy.h"
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define PROC_ROOTDIR_NAMELEN 5
+#define PROC_INUSE 2
+
+DEFINE_SPINLOCK(procfsLock);
+bool procfsInit = false;
+
+static struct ProcFile g_procPf = {
+ .fPos = 0,
+};
+
+static struct ProcDirEntry g_procRootDirEntry = {
+ .nameLen = 5,
+ .mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
+ .count = ATOMIC_INIT(1),
+ .procFileOps = NULL,
+ .parent = &g_procRootDirEntry,
+ .name = "/proc",
+ .subdir = NULL,
+ .next = NULL,
+ .pf = &g_procPf,
+};
+
+int ProcMatch(unsigned int len, const char *name, struct ProcDirEntry *pn)
+{
+ if (len != pn->nameLen)
+ return 0;
+ return !strncmp(name, pn->name, len);
+}
+
+static struct ProcDirEntry *ProcFindNode(struct ProcDirEntry *parent, const char *name)
+{
+ struct ProcDirEntry *pn = NULL;
+ int length;
+
+ if ((parent == NULL) || (name == NULL)) {
+ return pn;
+ }
+ length = strlen(name);
+
+ for (pn = parent->subdir; pn != NULL; pn = pn->next) {
+ if ((length == pn->nameLen) && strcmp(pn->name, name) == 0) {
+ break;
+ }
+ }
+
+ return pn;
+}
+
+/*
+ * descrition: find the file's handle
+ * path: the file of fullpath
+ * return: the file of handle
+ * add by ll
+ */
+struct ProcDirEntry *ProcFindEntry(const char *path)
+{
+ struct ProcDirEntry *pn = NULL;
+ int isfoundsub;
+ const char *next = NULL;
+ unsigned int len;
+ int leveltotal = 0;
+ int levelcount = 0;
+ const char *p = NULL;
+ const char *name = path;
+
+ while ((p = strchr(name, '/')) != NULL) {
+ leveltotal++;
+ name = p;
+ name++;
+ }
+ if (leveltotal < 1) {
+ return pn;
+ }
+
+ spin_lock(&procfsLock);
+
+ pn = &g_procRootDirEntry;
+
+ while ((pn != NULL) && (levelcount < leveltotal)) {
+ levelcount++;
+ isfoundsub = 0;
+ while (pn != NULL) {
+ next = strchr(path, '/');
+ if (next == NULL) {
+ while (pn != NULL) {
+ if (strcmp(path, pn->name) == 0) {
+ spin_unlock(&procfsLock);
+ return pn;
+ }
+ pn = pn->next;
+ }
+ pn = NULL;
+ spin_unlock(&procfsLock);
+ return pn;
+ }
+
+ len = next - path;
+ if (pn == &g_procRootDirEntry) {
+ if (levelcount == leveltotal) {
+ spin_unlock(&procfsLock);
+ return pn;
+ }
+ len = g_procRootDirEntry.nameLen;
+ }
+ if (ProcMatch(len, path, pn)) {
+ isfoundsub = 1;
+ path += len + 1;
+ break;
+ }
+
+ pn = pn->next;
+ }
+
+ if ((isfoundsub == 1) && (pn != NULL)) {
+ pn = pn->subdir;
+ } else {
+ pn = NULL;
+ spin_unlock(&procfsLock);
+ return pn;
+ }
+ }
+ spin_unlock(&procfsLock);
+ return NULL;
+}
+
+static int CheckProcName(const char *name, struct ProcDirEntry **parent, const char **lastName)
+{
+ struct ProcDirEntry *pn = *parent;
+ const char *segment = name;
+ const char *restName = NULL;
+ int length;
+
+ if (pn == NULL) {
+ pn = &g_procRootDirEntry;
+ }
+
+ spin_lock(&procfsLock);
+
+ restName = strchr(segment, '/');
+ for (; restName != NULL; restName = strchr(segment, '/')) {
+ length = restName - segment;
+ for (pn = pn->subdir; pn != NULL; pn = pn->next) {
+ if (ProcMatch(length, segment, pn)) {
+ break;
+ }
+ }
+ if (pn == NULL) {
+ PRINT_ERR(" Error!No such name '%s'\n", name);
+ spin_unlock(&procfsLock);
+ return -ENOENT;
+ }
+ segment = restName;
+ segment++;
+ }
+ *lastName = segment;
+ *parent = pn;
+ spin_unlock(&procfsLock);
+
+ return 0;
+}
+
+static struct ProcDirEntry *ProcAllocNode(struct ProcDirEntry **parent, const char *name, mode_t mode)
+{
+ struct ProcDirEntry *pn = NULL;
+ const char *lastName = NULL;
+ int ret;
+
+ if ((name == NULL) || (strlen(name) == 0) || (procfsInit == false)) {
+ return pn;
+ }
+
+ if (CheckProcName(name, parent, &lastName) != 0) {
+ return pn;
+ }
+
+ if (strlen(lastName) > MAX_NAMELEN) {
+ return pn;
+ }
+
+ if ((S_ISDIR((*parent)->mode) == 0) || (strchr(lastName, '/'))) {
+ return pn;
+ }
+
+ pn = (struct ProcDirEntry *)malloc(sizeof(struct ProcDirEntry));
+ if (pn == NULL) {
+ return NULL;
+ }
+
+ if ((mode & S_IALLUGO) == 0) {
+ mode |= S_IRUSR | S_IRGRP | S_IROTH;
+ }
+
+ (void)memset_s(pn, sizeof(struct ProcDirEntry), 0, sizeof(struct ProcDirEntry));
+ pn->nameLen = strlen(lastName);
+ pn->mode = mode;
+ ret = memcpy_s(pn->name, sizeof(pn->name), lastName, strlen(lastName) + 1);
+ if (ret != EOK) {
+ free(pn);
+ return NULL;
+ }
+
+ pn->pf = (struct ProcFile *)malloc(sizeof(struct ProcFile));
+ if (pn->pf == NULL) {
+ free(pn);
+ return NULL;
+ }
+ (void)memset_s(pn->pf, sizeof(struct ProcFile), 0, sizeof(struct ProcFile));
+ pn->pf->pPDE = pn;
+ ret = memcpy_s(pn->pf->name, sizeof(pn->pf->name), pn->name, pn->nameLen + 1);
+ if (ret != EOK) {
+ free(pn->pf);
+ free(pn);
+ return NULL;
+ }
+
+ atomic_set(&pn->count, 1);
+ spin_lock_init(&pn->pdeUnloadLock);
+ return pn;
+}
+
+static int ProcAddNode(struct ProcDirEntry *parent, struct ProcDirEntry *pn)
+{
+ struct ProcDirEntry *temp = NULL;
+
+ if (parent == NULL) {
+ PRINT_ERR("%s(): parent is NULL", __FUNCTION__);
+ return -EINVAL;
+ }
+
+ if (pn->parent != NULL) {
+ PRINT_ERR("%s(): node already has a parent", __FUNCTION__);
+ return -EINVAL;
+ }
+
+ if (S_ISDIR(parent->mode) == 0) {
+ PRINT_ERR("%s(): parent is not a directory", __FUNCTION__);
+ return -EINVAL;
+ }
+
+ spin_lock(&procfsLock);
+
+ temp = ProcFindNode(parent, pn->name);
+ if (temp != NULL) {
+ PRINT_ERR("Error!ProcDirEntry '%s/%s' already registered\n", parent->name, pn->name);
+ spin_unlock(&procfsLock);
+ return -EEXIST;
+ }
+
+ pn->parent = parent;
+ pn->next = parent->subdir;
+ parent->subdir = pn;
+
+ spin_unlock(&procfsLock);
+
+ return 0;
+}
+
+static void ProcDetachNode(struct ProcDirEntry *pn)
+{
+ struct ProcDirEntry *parent = pn->parent;
+ struct ProcDirEntry **iter = NULL;
+
+ if (parent == NULL) {
+ PRINT_ERR("%s(): node has no parent", __FUNCTION__);
+ return;
+ }
+
+ iter = &parent->subdir;
+ while (*iter != NULL) {
+ if (*iter == pn) {
+ *iter = pn->next;
+ break;
+ }
+ iter = &(*iter)->next;
+ }
+ pn->parent = NULL;
+}
+
+static struct ProcDirEntry *ProcCreateDir(struct ProcDirEntry *parent, const char *name,
+ const struct ProcFileOperations *procFileOps, mode_t mode)
+{
+ struct ProcDirEntry *pn = NULL;
+ int ret;
+
+ pn = ProcAllocNode(&parent, name, S_IFDIR | mode);
+ if (pn == NULL) {
+ return pn;
+ }
+ pn->procFileOps = procFileOps;
+ ret = ProcAddNode(parent, pn);
+ if (ret != 0) {
+ free(pn->pf);
+ free(pn);
+ return NULL;
+ }
+
+ return pn;
+}
+
+static struct ProcDirEntry *ProcCreateFile(struct ProcDirEntry *parent, const char *name,
+ const struct ProcFileOperations *procFileOps, mode_t mode)
+{
+ struct ProcDirEntry *pn = NULL;
+ int ret;
+
+ pn = ProcAllocNode(&parent, name, S_IFREG | mode);
+ if (pn == NULL) {
+ return pn;
+ }
+
+ pn->procFileOps = procFileOps;
+ ret = ProcAddNode(parent, pn);
+ if (ret != 0) {
+ free(pn->pf);
+ free(pn);
+ return NULL;
+ }
+
+ return pn;
+}
+
+struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcDirEntry *parent)
+{
+ struct ProcDirEntry *pde = NULL;
+
+ if (S_ISDIR(mode)) {
+ pde = ProcCreateDir(parent, name, NULL, mode);
+ } else {
+ pde = ProcCreateFile(parent, name, NULL, mode);
+ }
+ return pde;
+}
+
+static void FreeProcEntry(struct ProcDirEntry *entry)
+{
+ if (entry == NULL) {
+ return;
+ }
+ if (entry->pf != NULL) {
+ free(entry->pf);
+ entry->pf = NULL;
+ }
+ free(entry);
+}
+
+void ProcFreeEntry(struct ProcDirEntry *pn)
+{
+ if (atomic_dec_and_test(&pn->count))
+ FreeProcEntry(pn);
+}
+
+static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
+{
+ if (pn == NULL) {
+ return;
+ }
+ RemoveProcEntryTravalsal(pn->next);
+ RemoveProcEntryTravalsal(pn->subdir);
+
+ ProcFreeEntry(pn);
+}
+
+void RemoveProcEntry(const char *name, struct ProcDirEntry *parent)
+{
+ struct ProcDirEntry *pn = NULL;
+ const char *lastName = name;
+
+ if ((name == NULL) || (strlen(name) == 0) || (procfsInit == false)) {
+ return;
+ }
+
+ if (CheckProcName(name, &parent, &lastName) != 0) {
+ return;
+ }
+
+ spin_lock(&procfsLock);
+
+ pn = ProcFindNode(parent, lastName);
+ if (pn == NULL) {
+ PRINT_ERR("Error:name '%s' not found!\n", name);
+ spin_unlock(&procfsLock);
+ return;
+ }
+ ProcDetachNode(pn);
+
+ spin_unlock(&procfsLock);
+
+ RemoveProcEntryTravalsal(pn->subdir);
+ ProcFreeEntry(pn);
+}
+
+struct ProcDirEntry *ProcMkdirMode(const char *name, mode_t mode, struct ProcDirEntry *parent)
+{
+ return ProcCreateDir(parent, name, NULL, mode);
+}
+
+struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *parent)
+{
+ return ProcCreateDir(parent, name, NULL, 0);
+}
+
+struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
+ const struct ProcFileOperations *procFileOps, void *data)
+{
+ struct ProcDirEntry *pde = CreateProcEntry(name, mode, parent);
+ if (pde != NULL) {
+ if (procFileOps != NULL) {
+ pde->procFileOps = procFileOps;
+ }
+ pde->data = data;
+ }
+ return pde;
+}
+
+struct ProcDirEntry *ProcCreate(const char *name, mode_t mode, struct ProcDirEntry *parent,
+ const struct ProcFileOperations *procFileOps)
+{
+ return ProcCreateData(name, mode, parent, procFileOps, NULL);
+}
+
+int ProcStat(const char *file, struct ProcStat *buf)
+{
+ struct ProcDirEntry *pn = NULL;
+ int len = sizeof(buf->name);
+ int ret;
+
+ pn = ProcFindEntry(file);
+ if (pn == NULL) {
+ return ENOENT;
+ }
+ ret = strncpy_s(buf->name, len, pn->name, len - 1);
+ if (ret != EOK) {
+ return ENAMETOOLONG;
+ }
+ buf->name[len - 1] = '\0';
+ buf->stMode = pn->mode;
+ buf->pPDE = pn;
+
+ return 0;
+}
+
+static int GetNextDir(struct ProcDirEntry *pn, void *buf, size_t len)
+{
+ char *buff = (char *)buf;
+
+ if (pn->pdirCurrent == NULL) {
+ *buff = '\0';
+ return -ENOENT;
+ }
+ int ret = memcpy_s(buff, len, pn->pdirCurrent->name, pn->pdirCurrent->nameLen);
+ if (ret != EOK) {
+ return -ENAMETOOLONG;
+ }
+
+ pn->pdirCurrent = pn->pdirCurrent->next;
+ pn->pf->fPos++;
+ return ENOERR;
+}
+
+static int ProcOpen(struct ProcFile *procFile)
+{
+ if (procFile == NULL) {
+ return PROC_ERROR;
+ }
+ if (procFile->sbuf != NULL) {
+ return OK;
+ }
+
+ struct SeqBuf *buf = LosBufCreat();
+ if (buf == NULL) {
+ return PROC_ERROR;
+ }
+ procFile->sbuf = buf;
+ return OK;
+}
+
+static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
+{
+ if (pde == NULL || pde == NULL || pde->pf == NULL) {
+ return PROC_ERROR;
+ }
+ struct ProcFile *procFile = pde->pf;
+ struct SeqBuf *sb = procFile->sbuf;
+
+ if (sb->buf == NULL) {
+ // only read once to build the storage buffer
+ if (pde->procFileOps->read(sb, NULL) != 0) {
+ return PROC_ERROR;
+ }
+ }
+
+ size_t realLen;
+ loff_t pos = procFile->fPos;
+
+ if ((pos >= sb->count) || (len == 0)) {
+ /* there's no data or at the file tail. */
+ realLen = 0;
+ } else {
+ realLen = MIN((sb->count - pos), MIN(len, INT_MAX));
+ if (LOS_CopyFromKernel(buf, len, sb->buf + pos, realLen) != 0) {
+ return PROC_ERROR;
+ }
+
+ procFile->fPos = pos + realLen;
+ }
+
+ return (ssize_t)realLen;
+}
+
+struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
+{
+ unsigned int intSave;
+ struct ProcDirEntry *pn = ProcFindEntry(fileName);
+ if (pn == NULL) {
+ return NULL;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ if (S_ISREG(pn->mode) && (pn->count != 1)) {
+ SCHEDULER_UNLOCK(intSave);
+ return NULL;
+ }
+
+ pn->flags = (unsigned int)(pn->flags) | (unsigned int)flags;
+ atomic_set(&pn->count, PROC_INUSE);
+ SCHEDULER_UNLOCK(intSave);
+ if (ProcOpen(pn->pf) != OK) {
+ return NULL;
+ }
+ if (S_ISREG(pn->mode) && (pn->procFileOps != NULL) && (pn->procFileOps->open != NULL)) {
+ (void)pn->procFileOps->open((struct inode *)pn, pn->pf);
+ }
+ if (S_ISDIR(pn->mode)) {
+ pn->pdirCurrent = pn->subdir;
+ pn->pf->fPos = 0;
+ }
+
+ return pn;
+}
+
+int ReadProcFile(struct ProcDirEntry *pde, void *buf, size_t len)
+{
+ int result = -EPERM;
+
+ if (pde == NULL) {
+ return result;
+ }
+
+ if (S_ISREG(pde->mode)) {
+ if ((pde->procFileOps != NULL) && (pde->procFileOps->read != NULL)) {
+ result = ProcRead(pde, (char *)buf, len);
+ }
+ } else if (S_ISDIR(pde->mode)) {
+ result = GetNextDir(pde, buf, len);
+ }
+
+ return result;
+}
+
+int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len)
+{
+ int result = -EPERM;
+
+ if (pde == NULL) {
+ return result;
+ }
+
+ if (S_ISDIR(pde->mode)) {
+ return -EISDIR;
+ }
+
+ spin_lock(&procfsLock);
+ if ((pde->procFileOps != NULL) && (pde->procFileOps->write != NULL)) {
+ result = pde->procFileOps->write(pde->pf, (const char *)buf, len, &(pde->pf->fPos));
+ }
+ spin_unlock(&procfsLock);
+
+ return result;
+}
+
+loff_t LseekProcFile(struct ProcDirEntry *pde, loff_t offset, int whence)
+{
+ if (pde == NULL || pde->pf == NULL) {
+ return PROC_ERROR;
+ }
+
+ struct ProcFile *procFile = pde->pf;
+
+ loff_t result = -EINVAL;
+
+ switch (whence) {
+ case SEEK_CUR:
+ result = procFile->fPos + offset;
+ break;
+
+ case SEEK_SET:
+ result = offset;
+ break;
+
+ default:
+ break;
+ }
+
+ if (result >= 0) {
+ procFile->fPos = result;
+ }
+
+ return result;
+}
+
+int LseekDirProcFile(struct ProcDirEntry *pde, off_t *pos, int whence)
+{
+ /* Only allow SEEK_SET to zero */
+ if ((whence != SEEK_SET) || (*pos != 0)) {
+ return EINVAL;
+ }
+ pde->pdirCurrent = pde->subdir;
+ pde->pf->fPos = 0;
+ return ENOERR;
+}
+
+int CloseProcFile(struct ProcDirEntry *pde)
+{
+ int result = 0;
+
+ if (pde == NULL) {
+ return -EPERM;
+ }
+ pde->pf->fPos = 0;
+ atomic_set(&pde->count, 1);
+ if (S_ISDIR(pde->mode)) {
+ pde->pdirCurrent = pde->subdir;
+ }
+
+ if ((pde->procFileOps != NULL) && (pde->procFileOps->release != NULL)) {
+ result = pde->procFileOps->release((struct inode *)pde, pde->pf);
+ }
+ LosBufRelease(pde->pf->sbuf);
+ pde->pf->sbuf = NULL;
+
+ if (pde->parent == NULL) {
+ FreeProcEntry(pde);
+ }
+ return result;
+}
+
diff --git a/fs/proc/src/proc_shellcmd.c b/fs/proc/src/proc_shellcmd.c
new file mode 100644
index 00000000..c5c894f1
--- /dev/null
+++ b/fs/proc/src/proc_shellcmd.c
@@ -0,0 +1,100 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "los_config.h"
+
+#if defined(LOSCFG_SHELL_CMD_DEBUG) && defined(LOSCFG_FS_PROC)
+#include "los_typedef.h"
+#include "shell.h"
+#include "shcmd.h"
+#include "proc_file.h"
+#include "inode/inode.h"
+#include "dirent.h"
+#include "fs/fs.h"
+#include "proc_fs.h"
+
+#define WRITEPROC_ARGC 3
+
+int OsShellCmdWriteProc(int argc, char **argv)
+{
+ int i;
+ int ret;
+ const char *path = NULL;
+ const char *value = NULL;
+ unsigned int len;
+ struct ProcDirEntry *handle = NULL;
+ char realPath[PATH_MAX] = {'\0'};
+ const char *rootProcDir = "/proc/";
+
+ if (argc == WRITEPROC_ARGC) {
+ value = argv[0];
+ path = argv[2];
+ len = strlen(value) + 1; /* +1:add the \0 */
+ if (strncmp(argv[1], ">>", strlen(">>")) == 0) {
+ if ((realpath(path, realPath) == NULL) || (strncmp(realPath, rootProcDir, strlen(rootProcDir)) != 0)) {
+ PRINT_ERR("No such file or directory\n");
+ return PROC_ERROR;
+ }
+
+ handle = OpenProcFile(realPath, O_TRUNC);
+ if (handle == NULL) {
+ PRINT_ERR("No such file or directory\n");
+ return PROC_ERROR;
+ }
+
+ ret = WriteProcFile(handle, value, len);
+ if (ret < 0) {
+ (void)CloseProcFile(handle);
+ PRINT_ERR("write error\n");
+ return PROC_ERROR;
+ }
+ for (i = 0; i < argc; i++) {
+ PRINTK("%s%s", i > 0 ? " " : "", argv[i]);
+ }
+ PRINTK("\n");
+ (void)CloseProcFile(handle);
+ return LOS_OK;
+ }
+ }
+ PRINT_ERR("writeproc [data] [>>] [path]\n");
+ return PROC_ERROR;
+}
+
+SHELLCMD_ENTRY(writeproc_shellcmd, CMD_TYPE_EX, "writeproc", XARGS, (CmdCallBackFunc)OsShellCmdWriteProc);
+#endif
diff --git a/fs/ramfs/Makefile b/fs/ramfs/Makefile
index 7dc41766..4f8e3b9f 100644
--- a/fs/ramfs/Makefile
+++ b/fs/ramfs/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/vfs/Makefile b/fs/vfs/Makefile
old mode 100644
new mode 100755
index 977e6108..1da78b0a
--- a/fs/vfs/Makefile
+++ b/fs/vfs/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/vfs/bcache/Makefile b/fs/vfs/bcache/Makefile
index 5d0d7aee..0fb1100a 100644
--- a/fs/vfs/bcache/Makefile
+++ b/fs/vfs/bcache/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/vfs/bcache/src/bcache.c b/fs/vfs/bcache/src/bcache.c
old mode 100644
new mode 100755
index a243ea7d..0676b2cb
--- a/fs/vfs/bcache/src/bcache.c
+++ b/fs/vfs/bcache/src/bcache.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -437,19 +437,6 @@ static OsBcacheBlock *GetSlowBlock(OsBcache *bc, BOOL read)
}
}
- node = bc->listHead.pstPrev;
- while (node != &bc->listHead) {
- block = LOS_DL_LIST_ENTRY(node, OsBcacheBlock, listNode);
- node = block->listNode.pstPrev;
-
- if (block->readBuff == read && read && !block->modified) {
- DelBlock(bc, block);
- block->used = TRUE;
- LOS_ListDelete(&block->listNode);
- return block; /* read only block */
- }
- }
-
node = bc->listHead.pstPrev;
while (node != &bc->listHead) {
block = LOS_DL_LIST_ENTRY(node, OsBcacheBlock, listNode);
@@ -490,6 +477,7 @@ static VOID WriteMergedBlocks(OsBcache *bc, OsBcacheBlock *begin, int blocks)
while (blocks > 0) {
next = LOS_DL_LIST_ENTRY(cur->numNode.pstNext, OsBcacheBlock, numNode);
DelBlock(bc, cur);
+ cur->modified = FALSE;
blocks--;
cur = next;
}
@@ -656,6 +644,9 @@ static INT32 BcacheGetBlock(OsBcache *bc, UINT64 num, BOOL readData, OsBcacheBlo
block = GetSlowBlock(bc, readData);
}
+ if (block == NULL) {
+ return -ENOMEM;
+ }
BlockInit(bc, block, num);
if (readData == TRUE) {
@@ -904,10 +895,9 @@ INT32 OsSdSync(INT32 id)
#ifdef LOSCFG_FS_FAT_CACHE
INT32 ret;
los_disk *disk = get_disk(id);
- if (disk == NULL) {
+ if ((disk == NULL) || (disk->disk_status == STAT_UNUSED)) {
return VFS_ERROR;
}
-
if (pthread_mutex_lock(&disk->disk_mutex) != ENOERR) {
PRINT_ERR("%s %d, mutex lock fail!\n", __FUNCTION__, __LINE__);
return VFS_ERROR;
diff --git a/fs/vfs/bch/Makefile b/fs/vfs/bch/Makefile
old mode 100644
new mode 100755
index c73a34d3..5b89f50f
--- a/fs/vfs/bch/Makefile
+++ b/fs/vfs/bch/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/vfs/disk/Makefile b/fs/vfs/disk/Makefile
index 1eed0af1..d61cb100 100644
--- a/fs/vfs/disk/Makefile
+++ b/fs/vfs/disk/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/fs/vfs/disk/disk.c b/fs/vfs/disk/disk.c
old mode 100644
new mode 100755
index 590e8327..2d6db3a7
--- a/fs/vfs/disk/disk.c
+++ b/fs/vfs/disk/disk.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -152,6 +152,8 @@ INT32 los_alloc_diskid_byname(const CHAR *diskName)
if (strncpy_s(disk->disk_name, (nameLen + 1), diskName, nameLen) != EOK) {
PRINT_ERR("The strncpy_s failed.\n");
+ LOS_MemFree(m_aucSysMem0, disk->disk_name);
+ disk->disk_name = NULL;
return VFS_ERROR;
}
@@ -261,6 +263,10 @@ static los_part *DiskPartAllocate(struct inode *dev, UINT64 start, UINT64 count)
UINT32 i;
los_part *part = get_part(0); /* traversing from the beginning of the array */
+ if (part == NULL) {
+ return NULL;
+ }
+
for (i = 0; i < SYS_MAX_PART; i++) {
if (part->dev == NULL) {
part->part_id = i;
@@ -298,7 +304,7 @@ static VOID DiskPartRelease(los_part *part)
*/
#define DEV_NAME_BUFF_SIZE (DISK_NAME + 3)
-static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount)
+static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount, BOOL IsValidPart)
{
CHAR devName[DEV_NAME_BUFF_SIZE];
struct inode *diskDev = NULL;
@@ -317,34 +323,40 @@ static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount)
return VFS_ERROR;
}
- ret = snprintf_s(devName, sizeof(devName), sizeof(devName) - 1, "%s%c%u",
- (disk->disk_name == NULL ? "null" : disk->disk_name), 'p', disk->part_count);
- if (ret < 0) {
- return VFS_ERROR;
- }
-
diskDev = disk->dev;
- if (register_blockdriver(devName, diskDev->u.i_bops, RWE_RW_RW, diskDev->i_private)) {
- PRINT_ERR("DiskAddPart : register %s fail!\n", devName);
- return VFS_ERROR;
- }
+ if (IsValidPart == TRUE) {
+ ret = snprintf_s(devName, sizeof(devName), sizeof(devName) - 1, "%s%c%u",
+ ((disk->disk_name == NULL) ? "null" : disk->disk_name), 'p', disk->part_count);
+ if (ret < 0) {
+ return VFS_ERROR;
+ }
- SETUP_SEARCH(&desc, devName, false);
- ret = inode_find(&desc);
- if (ret < 0) {
- PRINT_ERR("DiskAddPart : find %s fail!\n", devName);
- return VFS_ERROR;
- }
- partDev = desc.node;
+ if (register_blockdriver(devName, diskDev->u.i_bops, RWE_RW_RW, diskDev->i_private)) {
+ PRINT_ERR("DiskAddPart : register %s fail!\n", devName);
+ return VFS_ERROR;
+ }
- PRINTK("DiskAddPart : register %s ok!\n", devName);
+ SETUP_SEARCH(&desc, devName, false);
+ ret = inode_find(&desc);
+ if (ret < 0) {
+ PRINT_ERR("DiskAddPart : find %s fail!\n", devName);
+ return VFS_ERROR;
+ }
+ partDev = desc.node;
- part = DiskPartAllocate(partDev, sectorStart, sectorCount);
- inode_release(partDev);
+ PRINTK("DiskAddPart : register %s ok!\n", devName);
- if (part == NULL) {
- (VOID)unregister_blockdriver(devName);
- return VFS_ERROR;
+ part = DiskPartAllocate(partDev, sectorStart, sectorCount);
+ inode_release(partDev);
+ if (part == NULL) {
+ (VOID)unregister_blockdriver(devName);
+ return VFS_ERROR;
+ }
+ } else {
+ part = DiskPartAllocate(diskDev, sectorStart, sectorCount);
+ if (part == NULL) {
+ return VFS_ERROR;
+ }
}
DiskPartAddToDisk(disk, part);
@@ -371,13 +383,13 @@ static INT32 DiskDivide(los_disk *disk, struct disk_divide_info *info)
info->part[i].sector_count = info->sector_count - info->part[i].sector_start;
PRINT_ERR("Part[%u] sector_count change to %llu.\n", i, info->part[i].sector_count);
- ret = DiskAddPart(disk, info->part[i].sector_start, info->part[i].sector_count);
+ ret = DiskAddPart(disk, info->part[i].sector_start, info->part[i].sector_count, TRUE);
if (ret == VFS_ERROR) {
return VFS_ERROR;
}
break;
}
- ret = DiskAddPart(disk, info->part[i].sector_start, info->part[i].sector_count);
+ ret = DiskAddPart(disk, info->part[i].sector_start, info->part[i].sector_count, TRUE);
if (ret == VFS_ERROR) {
return VFS_ERROR;
}
@@ -410,13 +422,13 @@ static INT32 DiskPartitionMemZalloc(size_t boundary, size_t size, CHAR **gptBuf,
buffer1 = (CHAR *)memalign(boundary, size);
if (buffer1 == NULL) {
PRINT_ERR("%s buffer1 malloc %lu failed! %d\n", __FUNCTION__, size, __LINE__);
- return VFS_ERROR;
+ return -ENOMEM;
}
buffer2 = (CHAR *)memalign(boundary, size);
if (buffer2 == NULL) {
PRINT_ERR("%s buffer2 malloc %lu failed! %d\n", __FUNCTION__, size, __LINE__);
free(buffer1);
- return VFS_ERROR;
+ return -ENOMEM;
}
(VOID)memset_s(buffer1, size, 0, size);
(VOID)memset_s(buffer2, size, 0, size);
@@ -520,7 +532,7 @@ static INT32 DiskGPTPartitionRecognition(struct inode *blkDrv, struct disk_divid
ret = DiskPartitionMemZalloc(MEM_ADDR_ALIGN_BYTE, info->sector_size, &gptBuf, &partitionBuf);
if (ret != ENOERR) {
- return VFS_ERROR;
+ return ret;
}
ret = GPTInfoGet(blkDrv, gptBuf);
@@ -678,7 +690,7 @@ static INT32 DiskPartitionRecognition(struct inode *blkDrv, struct disk_divide_i
CHAR *ebrBuf = NULL;
if ((blkDrv == NULL) || (blkDrv->u.i_bops == NULL) || (blkDrv->u.i_bops->read == NULL)) {
- return VFS_ERROR;
+ return -EINVAL;
}
ret = DiskPartitionMemZalloc(MEM_ADDR_ALIGN_BYTE, info->sector_size, &mbrBuf, &ebrBuf);
@@ -733,12 +745,21 @@ INT32 DiskPartitionRegister(los_disk *disk)
parInfo.sector_size = disk->sector_size;
parInfo.sector_count = disk->sector_count;
count = DiskPartitionRecognition(disk->dev, &parInfo);
- if (count < 0) {
+ if (count == VFS_ERROR) {
+ part = get_part(DiskAddPart(disk, 0, disk->sector_count, FALSE));
+ if (part == NULL) {
+ return VFS_ERROR;
+ }
+ part->part_no_mbr = 0;
+ PRINTK("Disk %s doesn't contain a valid partition table.\n", disk->disk_name);
+ return ENOERR;
+ } else if (count < 0) {
return VFS_ERROR;
}
+
parInfo.part_count = count;
if (count == 0) {
- part = get_part(DiskAddPart(disk, 0, disk->sector_count));
+ part = get_part(DiskAddPart(disk, 0, disk->sector_count, TRUE));
if (part == NULL) {
return VFS_ERROR;
}
@@ -752,7 +773,7 @@ INT32 DiskPartitionRegister(los_disk *disk)
/* Read the disk_divide_info structure to get partition's infomation. */
if ((parInfo.part[i].type != 0) && (parInfo.part[i].type != EXTENDED_PAR) &&
(parInfo.part[i].type != EXTENDED_8G)) {
- part = get_part(DiskAddPart(disk, parInfo.part[i].sector_start, parInfo.part[i].sector_count));
+ part = get_part(DiskAddPart(disk, parInfo.part[i].sector_start, parInfo.part[i].sector_count, TRUE));
if (part == NULL) {
return VFS_ERROR;
}
@@ -989,7 +1010,7 @@ ERROR_HANDLE:
return VFS_ERROR;
}
-INT32 los_part_write(INT32 pt, VOID *buf, UINT64 sector, UINT32 count)
+INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
{
const los_part *part = get_part(pt);
los_disk *disk = NULL;
@@ -1031,7 +1052,7 @@ INT32 los_part_write(INT32 pt, VOID *buf, UINT64 sector, UINT32 count)
goto ERROR_HANDLE;
}
- ret = los_disk_write((INT32)part->disk_id, (const VOID *)buf, sector, count);
+ ret = los_disk_write((INT32)part->disk_id, buf, sector, count);
if (ret < 0) {
goto ERROR_HANDLE;
}
@@ -1195,6 +1216,8 @@ static VOID DiskStructInit(const CHAR *diskName, INT32 diskID, const struct geom
if (strncpy_s(disk->disk_name, (nameLen + 1), diskName, nameLen) != EOK) {
PRINT_ERR("DiskStructInit strncpy_s failed.\n");
+ LOS_MemFree(m_aucSysMem0, disk->disk_name);
+ disk->disk_name = NULL;
return;
}
disk->disk_name[nameLen] = '\0';
@@ -1558,7 +1581,11 @@ INT32 SetDiskPartName(los_part *part, const CHAR *src)
goto ERROR_HANDLE;
}
- (VOID)strcpy_s(part->part_name, len + 1, src);
+ if (strcpy_s(part->part_name, len + 1, src) != EOK) {
+ free(part->part_name);
+ part->part_name = NULL;
+ goto ERROR_HANDLE;
+ }
DISK_UNLOCK(&disk->disk_mutex);
return ENOERR;
diff --git a/fs/vfs/disk/disk_shellcmd.c b/fs/vfs/disk/disk_shellcmd.c
index acfabaf8..90f877ee 100644
--- a/fs/vfs/disk/disk_shellcmd.c
+++ b/fs/vfs/disk/disk_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/bcache/bcache.h b/fs/vfs/include/bcache/bcache.h
old mode 100644
new mode 100755
index 3c2d8c01..22bc1c50
--- a/fs/vfs/include/bcache/bcache.h
+++ b/fs/vfs/include/bcache/bcache.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,10 +36,6 @@
#include "linux/rbtree.h"
#include "los_list.h"
-#ifdef LOSCFG_SHELL
-#include "reset_shell.h"
-#endif
-
#include "inode/inode.h"
#ifdef __cplusplus
diff --git a/fs/vfs/include/disk/disk_pri.h b/fs/vfs/include/disk/disk_pri.h
index c174124c..eecc8667 100644
--- a/fs/vfs/include/disk/disk_pri.h
+++ b/fs/vfs/include/disk/disk_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/driver/blockproxy.h b/fs/vfs/include/driver/blockproxy.h
old mode 100644
new mode 100755
index ee4d994a..4d884e79
--- a/fs/vfs/include/driver/blockproxy.h
+++ b/fs/vfs/include/driver/blockproxy.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/driver/driver.h b/fs/vfs/include/driver/driver.h
old mode 100644
new mode 100755
index e2cb14df..274841af
--- a/fs/vfs/include/driver/driver.h
+++ b/fs/vfs/include/driver/driver.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/driver/mtd_dev.h b/fs/vfs/include/driver/mtd_dev.h
old mode 100644
new mode 100755
index bec2c9be..30f41da6
--- a/fs/vfs/include/driver/mtd_dev.h
+++ b/fs/vfs/include/driver/mtd_dev.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/driver/mtd_list.h b/fs/vfs/include/driver/mtd_list.h
old mode 100644
new mode 100755
index ca481581..cf4f7725
--- a/fs/vfs/include/driver/mtd_list.h
+++ b/fs/vfs/include/driver/mtd_list.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/multi_partition/mtd_partition.h b/fs/vfs/include/multi_partition/mtd_partition.h
old mode 100644
new mode 100755
index 58a50eb8..2fec42d7
--- a/fs/vfs/include/multi_partition/mtd_partition.h
+++ b/fs/vfs/include/multi_partition/mtd_partition.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -93,6 +93,8 @@ typedef struct par_param {
(node)->mountpoint_name = NULL; \
} while (0)
+partition_param *GetNandPartParam(VOID);
+partition_param *GetSpinorPartParam(VOID);
mtd_partition *GetSpinorPartitionHead(VOID);
/**
diff --git a/fs/vfs/include/operation/fs_file.h b/fs/vfs/include/operation/fs_file.h
old mode 100644
new mode 100755
index c29dec12..8b8f3239
--- a/fs/vfs/include/operation/fs_file.h
+++ b/fs/vfs/include/operation/fs_file.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/operation/fs_other.h b/fs/vfs/include/operation/fs_other.h
old mode 100644
new mode 100755
index 619e2487..f765a6e9
--- a/fs/vfs/include/operation/fs_other.h
+++ b/fs/vfs/include/operation/fs_other.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/include/operation/fs_poll_pri.h b/fs/vfs/include/operation/fs_poll_pri.h
index 513bd83d..4321216d 100644
--- a/fs/vfs/include/operation/fs_poll_pri.h
+++ b/fs/vfs/include/operation/fs_poll_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/multi_partition/Makefile b/fs/vfs/multi_partition/Makefile
index a7646486..ea14154d 100644
--- a/fs/vfs/multi_partition/Makefile
+++ b/fs/vfs/multi_partition/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -34,8 +34,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
- -I $(LITEOSTOPDIR)/fs/jffs2/include \
- -I $(LITEOSTOPDIR)/../../drivers/liteos/storage/mtd/common/include
+ -I $(LITEOSTOPDIR)/fs/jffs2/include \
+ -I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
diff --git a/fs/vfs/multi_partition/src/mtd_partition.c b/fs/vfs/multi_partition/src/mtd_partition.c
old mode 100644
new mode 100755
index 804865d3..1c92ab0e
--- a/fs/vfs/multi_partition/src/mtd_partition.c
+++ b/fs/vfs/multi_partition/src/mtd_partition.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,7 +38,6 @@
#include "los_mux.h"
#include "inode/inode.h"
-#if defined(LOSCFG_FS_JFFS)
#include "mtd_common.h"
#ifdef __cplusplus
@@ -50,19 +49,85 @@ extern "C" {
#define DRIVER_NAME_ADD_SIZE 3
pthread_mutex_t g_mtdPartitionLock = PTHREAD_MUTEX_INITIALIZER;
+static VOID YaffsLockInit(VOID) __attribute__((weakref("yaffsfs_OSInitialisation")));
+static VOID YaffsLockDeinit(VOID) __attribute__((weakref("yaffsfs_OsDestroy")));
static INT32 JffsLockInit(VOID) __attribute__((weakref("JffsMutexCreate")));
static VOID JffsLockDeinit(VOID) __attribute__((weakref("JffsMutexDelete")));
+partition_param *g_nandPartParam = NULL;
partition_param *g_spinorPartParam = NULL;
mtd_partition *g_spinorPartitionHead = NULL;
+mtd_partition *g_nandPartitionHead = NULL;
#define RWE_RW_RW 0755
+partition_param *GetNandPartParam(VOID)
+{
+ return g_nandPartParam;
+}
+
+partition_param *GetSpinorPartParam(VOID)
+{
+ return g_spinorPartParam;
+}
+
mtd_partition *GetSpinorPartitionHead(VOID)
{
return g_spinorPartitionHead;
}
+
+static VOID MtdNandParamAssign(partition_param *nandParam, const struct MtdDev *nandMtd)
+{
+ LOS_ListInit(&g_nandPartitionHead->node_info);
+ /*
+ * If the user do not want to use block mtd or char mtd ,
+ * you can change the NANDBLK_NAME or NANDCHR_NAME to NULL.
+ */
+ nandParam->flash_mtd = (struct MtdDev *)nandMtd;
+ nandParam->flash_ops = GetDevNandOps();
+ nandParam->char_ops = GetMtdCharFops();
+ nandParam->blockname = NANDBLK_NAME;
+ nandParam->charname = NANDCHR_NAME;
+ nandParam->partition_head = g_nandPartitionHead;
+ nandParam->block_size = nandMtd->eraseSize;
+}
+
+static VOID MtdDeinitNandParam(VOID)
+{
+ if (YaffsLockDeinit != NULL) {
+ YaffsLockDeinit();
+ }
+}
+
+static partition_param *MtdInitNandParam(partition_param *nandParam)
+{
+ struct MtdDev *nandMtd = GetMtd("nand");
+ if (nandMtd == NULL) {
+ return NULL;
+ }
+ if (nandParam == NULL) {
+ if (YaffsLockInit != NULL) {
+ YaffsLockInit();
+ }
+ nandParam = (partition_param *)zalloc(sizeof(partition_param));
+ if (nandParam == NULL) {
+ MtdDeinitNandParam();
+ return NULL;
+ }
+ g_nandPartitionHead = (mtd_partition *)zalloc(sizeof(mtd_partition));
+ if (g_nandPartitionHead == NULL) {
+ MtdDeinitNandParam();
+ free(nandParam);
+ return NULL;
+ }
+
+ MtdNandParamAssign(nandParam, nandMtd);
+ }
+
+ return nandParam;
+}
+
static VOID MtdNorParamAssign(partition_param *spinorParam, const struct MtdDev *spinorMtd)
{
LOS_ListInit(&g_spinorPartitionHead->node_info);
@@ -134,7 +199,10 @@ static partition_param *MtdInitSpinorParam(partition_param *spinorParam)
/* According the flash-type to init the param of the partition. */
static INT32 MtdInitFsparParam(const CHAR *type, partition_param **fsparParam)
{
- if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
+ if (strcmp(type, "nand") == 0) {
+ g_nandPartParam = MtdInitNandParam(g_nandPartParam);
+ *fsparParam = g_nandPartParam;
+ } else if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
g_spinorPartParam = MtdInitSpinorParam(g_spinorPartParam);
*fsparParam = g_spinorPartParam;
} else {
@@ -151,7 +219,10 @@ static INT32 MtdInitFsparParam(const CHAR *type, partition_param **fsparParam)
/* According the flash-type to deinit the param of the partition. */
static INT32 MtdDeinitFsparParam(const CHAR *type)
{
- if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
+ if (strcmp(type, "nand") == 0) {
+ MtdDeinitNandParam();
+ g_nandPartParam = NULL;
+ } else if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
MtdDeinitSpinorParam();
g_spinorPartParam = NULL;
} else {
@@ -369,7 +440,9 @@ static INT32 DeleteParamCheck(UINT32 partitionNum,
const CHAR *type,
partition_param **param)
{
- if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
+ if (strcmp(type, "nand") == 0) {
+ *param = g_nandPartParam;
+ } else if (strcmp(type, "spinor") == 0 || strcmp(type, "cfi-flash") == 0) {
*param = g_spinorPartParam;
} else {
PRINT_ERR("type error \n");
@@ -488,4 +561,3 @@ INT32 delete_mtd_partition(UINT32 partitionNum, const CHAR *type)
}
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif
diff --git a/fs/vfs/multi_partition/src/mtd_shellcmd.c b/fs/vfs/multi_partition/src/mtd_shellcmd.c
old mode 100644
new mode 100755
index 024898b8..62202f94
--- a/fs/vfs/multi_partition/src/mtd_shellcmd.c
+++ b/fs/vfs/multi_partition/src/mtd_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,13 +38,8 @@
#ifdef LOSCFG_SHELL_CMD_DEBUG
#include "shcmd.h"
-#if defined(LOSCFG_FS_JFFS)
-extern partition_param *g_spinorPartParam;
-#endif
-
INT32 osShellCmdPartitionShow(INT32 argc, const CHAR **argv)
{
-#if defined(LOSCFG_FS_JFFS)
mtd_partition *node = NULL;
const CHAR *fs = NULL;
partition_param *param = NULL;
@@ -55,19 +50,16 @@ INT32 osShellCmdPartitionShow(INT32 argc, const CHAR **argv)
} else {
fs = argv[0];
}
-#endif
-#if defined(LOSCFG_FS_JFFS)
- if (strcmp(fs, "spinor") == 0) {
- param = g_spinorPartParam;
- } else
-#endif
- {
+ if (strcmp(fs, "nand") == 0) {
+ param = GetNandPartParam();
+ } else if (strcmp(fs, "spinor") == 0) {
+ param = GetSpinorPartParam();
+ } else {
PRINT_ERR("not supported!\n");
return -EINVAL;
}
-#if defined(LOSCFG_FS_JFFS)
if ((param == NULL) || (param->flash_mtd == NULL)) {
PRINT_ERR("no partition!\n");
return -EINVAL;
@@ -80,7 +72,6 @@ INT32 osShellCmdPartitionShow(INT32 argc, const CHAR **argv)
((node->end_block - node->start_block) + 1) * param->block_size);
}
return ENOERR;
-#endif
}
SHELLCMD_ENTRY(partition_shellcmd, CMD_TYPE_EX, "partition", XARGS, (CmdCallBackFunc)osShellCmdPartitionShow);
diff --git a/fs/vfs/operation/fs_chattr.c b/fs/vfs/operation/fs_chattr.c
old mode 100644
new mode 100755
index e320e587..a3242a5c
--- a/fs/vfs/operation/fs_chattr.c
+++ b/fs/vfs/operation/fs_chattr.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_check.c b/fs/vfs/operation/fs_check.c
old mode 100644
new mode 100755
index 3cc2201b..95c5a872
--- a/fs/vfs/operation/fs_check.c
+++ b/fs/vfs/operation/fs_check.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_fallocate.c b/fs/vfs/operation/fs_fallocate.c
old mode 100644
new mode 100755
index 1c2437e7..e4eca2de
--- a/fs/vfs/operation/fs_fallocate.c
+++ b/fs/vfs/operation/fs_fallocate.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_fallocate64.c b/fs/vfs/operation/fs_fallocate64.c
old mode 100644
new mode 100755
index 8569106b..063254aa
--- a/fs/vfs/operation/fs_fallocate64.c
+++ b/fs/vfs/operation/fs_fallocate64.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_file.c b/fs/vfs/operation/fs_file.c
old mode 100644
new mode 100755
index 8007f245..228fe72f
--- a/fs/vfs/operation/fs_file.c
+++ b/fs/vfs/operation/fs_file.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -43,7 +43,7 @@ static void FileTableLock(struct fd_table_s *fdt)
* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/
- LOS_ASSERT(get_errno() == EINTR);
+ LOS_ASSERT(errno == EINTR);
}
}
diff --git a/fs/vfs/operation/fs_file_mapping.c b/fs/vfs/operation/fs_file_mapping.c
old mode 100644
new mode 100755
index df10ea95..0b85c81a
--- a/fs/vfs/operation/fs_file_mapping.c
+++ b/fs/vfs/operation/fs_file_mapping.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -235,6 +235,7 @@ int remove_mapping_nolock(const char *fullpath, const struct file *ex_filp)
fmap = LOS_DL_LIST_ENTRY(mapping,
struct file_map, mapping);
LOS_ListDelete(&fmap->head);
+ LOS_MemFree(m_aucSysMem0, fmap->owner);
LOS_MemFree(m_aucSysMem0, fmap);
out:
diff --git a/fs/vfs/operation/fs_getlabel.c b/fs/vfs/operation/fs_getlabel.c
old mode 100644
new mode 100755
index b93f4712..6c375c90
--- a/fs/vfs/operation/fs_getlabel.c
+++ b/fs/vfs/operation/fs_getlabel.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_init.c b/fs/vfs/operation/fs_init.c
old mode 100644
new mode 100755
index e3e57943..22e3ffcb
--- a/fs/vfs/operation/fs_init.c
+++ b/fs/vfs/operation/fs_init.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -53,6 +53,7 @@ void los_vfs_init(void)
spin_lock_init(&g_diskSpinlock);
spin_lock_init(&g_diskFatBlockSpinlock);
#endif
+ files_initialize();
files_initlist(&tg_filelist);
fs_initialize();
if ((err = inode_reserve("/", &g_root_inode)) < 0) {
diff --git a/fs/vfs/operation/fs_other.c b/fs/vfs/operation/fs_other.c
old mode 100644
new mode 100755
index e05b94a4..27315672
--- a/fs/vfs/operation/fs_other.c
+++ b/fs/vfs/operation/fs_other.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,6 +38,7 @@
#include "sys/select.h"
#include "sys/stat.h"
#include "sys/prctl.h"
+#include "fs/dirent_fs.h"
#include "fs/fd_table.h"
#include "fs/fs.h"
#include "linux/spinlock.h"
@@ -96,30 +97,30 @@ int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode)
tmpMode &= (READ_OP | WRITE_OP | EXEC_OP);
- if ((accMode & tmpMode) == accMode) {
+ if (((uint)accMode & tmpMode) == accMode) {
return 0;
}
tmpMode = 0;
if (S_ISDIR(fileMode)) {
- if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_READ_SEARCH))) {
+ if (((uint)accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_READ_SEARCH))) {
tmpMode |= EXEC_OP;
}
} else {
- if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_EXECUTE)) && (fileMode & MODE_IXUGO)) {
+ if (((uint)accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_EXECUTE)) && (fileMode & MODE_IXUGO)) {
tmpMode |= EXEC_OP;
}
}
- if ((accMode & WRITE_OP) && IsCapPermit(CAP_DAC_WRITE)) {
+ if (((uint)accMode & WRITE_OP) && IsCapPermit(CAP_DAC_WRITE)) {
tmpMode |= WRITE_OP;
}
- if ((accMode & READ_OP) && IsCapPermit(CAP_DAC_READ_SEARCH)) {
+ if (((uint)accMode & READ_OP) && IsCapPermit(CAP_DAC_READ_SEARCH)) {
tmpMode |= READ_OP;
}
- if ((accMode & tmpMode) == accMode) {
+ if (((uint)accMode & tmpMode) == accMode) {
return 0;
}
@@ -127,7 +128,7 @@ int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode)
}
#ifdef VFS_USING_WORKDIR
-int SetWorkDir(char *dir, size_t len)
+static int SetWorkDir(const char *dir, size_t len)
{
errno_t ret;
uint lock_flags;
@@ -303,7 +304,7 @@ static struct dirent **scandir_get_file_list(const char *dir, int *num, int(*fil
{
DIR *od = NULL;
int listSize = MAX_DIR_ENT;
- int n = *num;
+ int n = 0;
struct dirent **list = NULL;
struct dirent **newList = NULL;
struct dirent *ent = NULL;
@@ -493,7 +494,7 @@ static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
int i;
for (i = 0; i < UGO_NUMS; i++) {
- mode = stat64Info->st_mode >> (USER_MODE_SHIFT - i * UGO_NUMS);
+ mode = stat64Info->st_mode >> (uint)(USER_MODE_SHIFT - i * UGO_NUMS);
str[i][0] = (mode & READ_OP) ? 'r' : '-';
str[i][1] = (mode & WRITE_OP) ? 'w' : '-';
str[i][UGO_NUMS - 1] = (mode & EXEC_OP) ? 'x' : '-';
@@ -513,7 +514,7 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name)
int i;
for (i = 0; i < UGO_NUMS; i++) {
- mode = statInfo->st_mode >> (USER_MODE_SHIFT - i * UGO_NUMS);
+ mode = statInfo->st_mode >> (uint)(USER_MODE_SHIFT - i * UGO_NUMS);
str[i][0] = (mode & READ_OP) ? 'r' : '-';
str[i][1] = (mode & WRITE_OP) ? 'w' : '-';
str[i][UGO_NUMS - 1] = (mode & EXEC_OP) ? 'x' : '-';
@@ -584,6 +585,7 @@ void ls(const char *pathname)
}
fullpath_bak = fullpath;
+
if (stat64(fullpath, &stat64_info) == 0) {
PrintFileInfo64(&stat64_info, pdirent->d_name);
} else if (stat(fullpath, &stat_info) == 0) {
diff --git a/fs/vfs/operation/fs_preadv.c b/fs/vfs/operation/fs_preadv.c
old mode 100644
new mode 100755
index f97cc809..97f8d0c0
--- a/fs/vfs/operation/fs_preadv.c
+++ b/fs/vfs/operation/fs_preadv.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_pwritev.c b/fs/vfs/operation/fs_pwritev.c
old mode 100644
new mode 100755
index 420ed900..3b57eaab
--- a/fs/vfs/operation/fs_pwritev.c
+++ b/fs/vfs/operation/fs_pwritev.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_readv.c b/fs/vfs/operation/fs_readv.c
old mode 100644
new mode 100755
index 5ebef241..573fbf92
--- a/fs/vfs/operation/fs_readv.c
+++ b/fs/vfs/operation/fs_readv.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_utime.c b/fs/vfs/operation/fs_utime.c
old mode 100644
new mode 100755
index 8e429b8c..e30c982f
--- a/fs/vfs/operation/fs_utime.c
+++ b/fs/vfs/operation/fs_utime.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_virstatfs.c b/fs/vfs/operation/fs_virstatfs.c
old mode 100644
new mode 100755
index ade65674..8bc41dca
--- a/fs/vfs/operation/fs_virstatfs.c
+++ b/fs/vfs/operation/fs_virstatfs.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fs_writev.c b/fs/vfs/operation/fs_writev.c
old mode 100644
new mode 100755
index 6631120c..49c0b911
--- a/fs/vfs/operation/fs_writev.c
+++ b/fs/vfs/operation/fs_writev.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/operation/fullpath.c b/fs/vfs/operation/fullpath.c
old mode 100644
new mode 100755
index 230f30ba..23a7576d
--- a/fs/vfs/operation/fullpath.c
+++ b/fs/vfs/operation/fullpath.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/fs/vfs/vfs_cmd/vfs_shellcmd.c b/fs/vfs/vfs_cmd/vfs_shellcmd.c
old mode 100644
new mode 100755
index 3a056a1b..d8a4caf8
--- a/fs/vfs/vfs_cmd/vfs_shellcmd.c
+++ b/fs/vfs/vfs_cmd/vfs_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -182,19 +182,20 @@ pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER;
int osShellCmdDoCatShow(UINTPTR arg)
{
+ int ret = 0;
char buf[CAT_BUF_SIZE];
- size_t size;
- FILE *ini = NULL;
+ size_t size, writen, toWrite;
+ ssize_t cnt;
char *fullpath = (char *)arg;
+ FILE *ini = NULL;
(void)pthread_mutex_lock(&g_mutex_cat);
ini = fopen(fullpath, "r");
if (ini == NULL)
{
+ ret = -1;
perror("cat error");
- (void)pthread_mutex_unlock(&g_mutex_cat);
- free(fullpath);
- return -1;
+ goto out;
}
do
@@ -203,21 +204,38 @@ int osShellCmdDoCatShow(UINTPTR arg)
size = fread(buf, 1, CAT_BUF_SIZE, ini);
if ((int)size < 0)
{
+ ret = -1;
perror("cat error");
- (void)pthread_mutex_unlock(&g_mutex_cat);
- free(fullpath);
- (void)fclose(ini);
- return -1;
+ goto out_with_fclose;
}
- (void)write(1, buf, size);
- (void)LOS_TaskDelay(1);
- }
- while (size == CAT_BUF_SIZE);
- free(fullpath);
+ for (toWrite = size, writen = 0; toWrite > 0;)
+ {
+ cnt = write(1, buf + writen, toWrite);
+ if (cnt == 0)
+ {
+ /* avoid task-starvation */
+ (void)LOS_TaskDelay(1);
+ continue;
+ }
+ else if (cnt < 0)
+ {
+ perror("cat write error");
+ break;
+ }
+
+ writen += cnt;
+ toWrite -= cnt;
+ }
+ }
+ while (size > 0);
+
+out_with_fclose:
(void)fclose(ini);
+out:
+ free(fullpath);
(void)pthread_mutex_unlock(&g_mutex_cat);
- return 0;
+ return ret;
}
int osShellCmdCat(int argc, const char **argv)
@@ -640,7 +658,8 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
char *buf = NULL;
const char *filename = NULL;
size_t r_size, w_size;
- int src_fd, dst_fd;
+ int src_fd = -1;
+ int dst_fd = -1;
struct stat stat_buf;
mode_t src_mode;
char *shell_working_directory = OsShellGetWorkingDirtectory();
@@ -747,7 +766,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
goto errout_with_mutex;
}
- dst_fd = open(dst_fullpath, O_CREAT | O_WRONLY, src_mode);
+ dst_fd = open(dst_fullpath, O_CREAT | O_WRONLY | O_TRUNC, src_mode);
if (dst_fd < 0)
{
PRINTK("cp error: can't create %s. %s.\n", dst_fullpath, strerror(errno));
@@ -829,6 +848,12 @@ static int os_shell_cmd_do_rmdir(const char *pathname)
if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, "."))
{
size_t fullpath_buf_size = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN;
+ if (fullpath_buf_size <= 0)
+ {
+ PRINTK("buffer size is invalid!\n");
+ (void)closedir(d);
+ return -1;
+ }
fullpath = (char *)malloc(fullpath_buf_size);
if (fullpath == NULL)
{
@@ -1413,7 +1438,7 @@ int osShellCmdChmod(int argc, const char **argv)
{
if ((p[i] <= '7') && (p[i] >= '0'))
{
- mode = (mode << MODE_BIT) | (p[i] - '0');
+ mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0');
}
else
{
@@ -1541,10 +1566,8 @@ int osShellCmdChgrp(int argc, const char **argv)
#ifdef LOSCFG_SHELL_CMD_DEBUG
SHELLCMD_ENTRY(lsfd_shellcmd, CMD_TYPE_EX, "lsfd", XARGS, (CmdCallBackFunc)osShellCmdLsfd);
-#if (defined(LOSCFG_FS_FAT) || defined(LOSCFG_FS_RAMFS) || defined(LOSCFG_FS_JFFS))
SHELLCMD_ENTRY(statfs_shellcmd, CMD_TYPE_EX, "statfs", XARGS, (CmdCallBackFunc)osShellCmdStatfs);
SHELLCMD_ENTRY(touch_shellcmd, CMD_TYPE_EX, "touch", XARGS, (CmdCallBackFunc)osShellCmdTouch);
-#endif
#if (defined(LOSCFG_FS_FAT))
SHELLCMD_ENTRY(sync_shellcmd, CMD_TYPE_EX, "sync", XARGS, (CmdCallBackFunc)osShellCmdSync);
#endif
@@ -1560,11 +1583,7 @@ SHELLCMD_ENTRY(mkdir_shellcmd, CMD_TYPE_EX, "mkdir", XARGS, (CmdCallBackFunc)osS
SHELLCMD_ENTRY(chmod_shellcmd, CMD_TYPE_EX, "chmod", XARGS, (CmdCallBackFunc)osShellCmdChmod);
SHELLCMD_ENTRY(chown_shellcmd, CMD_TYPE_EX, "chown", XARGS, (CmdCallBackFunc)osShellCmdChown);
SHELLCMD_ENTRY(chgrp_shellcmd, CMD_TYPE_EX, "chgrp", XARGS, (CmdCallBackFunc)osShellCmdChgrp);
-#if (defined(LOSCFG_FS_FAT) || defined(LOSCFG_FS_RAMFS) || defined(LOSCFG_FS_JFFS))
SHELLCMD_ENTRY(mount_shellcmd, CMD_TYPE_EX, "mount", XARGS, (CmdCallBackFunc)osShellCmdMount);
SHELLCMD_ENTRY(umount_shellcmd, CMD_TYPE_EX, "umount", XARGS, (CmdCallBackFunc)osShellCmdUmount);
-#endif
-#if (defined(LOSCFG_FS_FAT) || defined(LOSCFG_FS_RAMFS) || defined(LOSCFG_FS_JFFS))
SHELLCMD_ENTRY(cp_shellcmd, CMD_TYPE_EX, "cp", XARGS, (CmdCallBackFunc)osShellCmdCp);
#endif
-#endif
diff --git a/fs/zpfs/BUILD.gn b/fs/zpfs/BUILD.gn
new file mode 100644
index 00000000..e8094f4f
--- /dev/null
+++ b/fs/zpfs/BUILD.gn
@@ -0,0 +1,42 @@
+# 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.
+
+static_library("fs_zpfs") {
+ sources = [
+ "vfs_zpfs.c",
+ "zpfs.c",
+ ]
+
+ if (LOSCFG_LLTREPORT) {
+ cflags += [
+ "-fprofile-arcs",
+ "-ftest-coverage",
+ ]
+ }
+}
diff --git a/fs/zpfs/Kconfig b/fs/zpfs/Kconfig
new file mode 100644
index 00000000..06a0d2c1
--- /dev/null
+++ b/fs/zpfs/Kconfig
@@ -0,0 +1,6 @@
+config FS_ZPFS
+ bool "Enable ZPFS"
+ default y
+ depends on FS_VFS && PLATFORM_PATCHFS
+ help
+ Answer Y to enable LiteOS support zpfs filesystem.
diff --git a/fs/zpfs/Makefile b/fs/zpfs/Makefile
new file mode 100644
index 00000000..d703d773
--- /dev/null
+++ b/fs/zpfs/Makefile
@@ -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.
+
+include $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard *.c)
+LOCAL_INCLUDE = \
+ -I $(LITEOSTOPDIR)/fs/include \
+ -I $(LITEOSTOPDIR)/fs/zpfs \
+ -I $(LITEOSTOPDIR)/../../third_party/NuttX/liteos/fs/include\
+ -I $(LITEOSTOPDIR)/../../third_party/NuttX/liteos/fs/include/inode
+
+LOCAL_FLAGS := $(LITEOS_GCOV_OPTS)
+
+include $(MODULE)
+
diff --git a/fs/zpfs/vfs_zpfs.c b/fs/zpfs/vfs_zpfs.c
new file mode 100755
index 00000000..d9ce0930
--- /dev/null
+++ b/fs/zpfs/vfs_zpfs.c
@@ -0,0 +1,458 @@
+/*
+ * 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 "vfs_zpfs.h"
+
+#include
+#include
+#include
+#include
+
+#include "fs/dirent_fs.h"
+#include "inode/inode.h"
+#include "internal.h"
+#include "los_tables.h"
+#include "los_vm_filemap.h"
+
+#ifdef LOSCFG_FS_ZPFS
+
+static int CheckEntryExist(const struct ZpfsEntry *zpfsEntry, char **fPath, struct stat *buf)
+{
+ int ret;
+ struct inode *inode = zpfsEntry->mountedInode;
+ const char *path = zpfsEntry->mountedPath;
+ const char *relPath = zpfsEntry->mountedRelpath;
+ int len = strlen(path) + strlen(relPath) + 1;
+ int fullLen = len + 1;
+ char *fullPath = (char *)malloc(fullLen);
+ if (fullPath == NULL) {
+ return -1;
+ }
+
+ ret = snprintf_s(fullPath, fullLen, len, "%s/%s", path, relPath);
+ if (ret < 0) {
+ free(fullPath);
+ return -1;
+ }
+ if (inode->u.i_mops->stat != NULL) {
+ ret = inode->u.i_mops->stat(inode, fullPath, buf);
+ } else {
+ ret = -ENOSYS;
+ }
+
+ if (fPath == NULL) {
+ free(fullPath);
+ } else {
+ *fPath = fullPath;
+ }
+
+ return ret;
+}
+
+static struct inode *GetRelInodeFromVInode(const ZpfsConfig *zpfsCfg,
+ const char* relPath, struct stat *buf, char **finalPath)
+{
+ int ret;
+ struct ZpfsEntry entry;
+
+ for (int i = 0; i < zpfsCfg->entryCount; i++) {
+ entry.mountedPath = zpfsCfg->orgEntry[i].mountedRelpath;
+ entry.mountedRelpath = (char*)relPath;
+ entry.mountedInode = zpfsCfg->orgEntry[i].mountedInode;
+ ret = CheckEntryExist(&entry, finalPath, buf);
+ if (ret == OK) {
+ return entry.mountedInode;
+ }
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: VfsZpfsRealInode
+ *
+ * Description:
+ * Get the inode which is hidden.
+ *
+ * Input Parameters:
+ * The relative path.
+ * Returned Value:
+ * finalPath the relative path of the mount point.
+ * OK
+ * NULL memory is not enough.
+ ****************************************************************************/
+static inline struct inode *VfsZpfsRealInode(const ZpfsConfig *zpfsCfg, const char *relPath, char **finalPath)
+{
+ struct stat buf;
+ struct inode *inode = GetRelInodeFromVInode(zpfsCfg, relPath, &buf, finalPath);
+ return inode;
+}
+
+static int VfsZpfsOpen(struct file *file, const char *relPath, int oflAgs, mode_t mode)
+{
+ char *finalPath = NULL;
+ struct inode *swapInode = NULL;
+ int ret;
+
+ struct inode *inode = file->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, relPath, &finalPath);
+ if ((inode == NULL) || (!inode->u.i_mops->open)) {
+ if (finalPath) {
+ free(finalPath);
+ }
+ return -ENOENT;
+ }
+
+ swapInode = file->f_inode;
+ file->f_inode = inode;
+ ret = inode->u.i_mops->open(file, finalPath, oflAgs, mode);
+ free(finalPath);
+ finalPath = NULL;
+ file->f_inode = swapInode;
+
+ return ret;
+}
+
+static int VfsZpfsClose(struct file *file)
+{
+ struct inode *swapInode = NULL;
+ int ret;
+
+ struct inode *inode = file->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, file->f_relpath, NULL);
+ if ((inode == NULL) || (!inode->u.i_mops->close)) {
+ return -ENOSYS;
+ }
+
+ swapInode = file->f_inode;
+ file->f_inode = inode;
+ ret = inode->u.i_mops->close(file);
+ file->f_inode = swapInode;
+
+ return ret;
+}
+
+static ssize_t VfsZpfsRead(struct file *file, FAR char *buffer, size_t bufLen)
+{
+ struct inode *swapInode = NULL;
+ ssize_t sret;
+
+ struct inode *inode = file->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, file->f_relpath, NULL);
+ if ((inode == NULL) || (!inode->u.i_mops->read)) {
+ return -ENOSYS;
+ }
+
+ swapInode = file->f_inode;
+ file->f_inode = inode;
+ sret = inode->u.i_mops->read(file, buffer, bufLen);
+ file->f_inode = swapInode;
+
+ return sret;
+}
+
+static off_t VfsZpfsLseek(struct file *file, off_t offset, int whence)
+{
+ off_t off;
+ struct inode *swapInode = NULL;
+
+ struct inode *inode = file->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, file->f_relpath, NULL);
+ if ((inode == NULL) || (!inode->u.i_mops->seek)) {
+ return -ENOSYS;
+ }
+
+ swapInode = file->f_inode;
+ file->f_inode = inode;
+ off = inode->u.i_mops->seek(file, offset, whence);
+ file->f_inode = swapInode;
+ return off;
+}
+
+static loff_t VfsZpfsLseek64(struct file *file, loff_t offset, int whence)
+{
+ loff_t off;
+ struct inode *swapInode = NULL;
+
+ struct inode *inode = file->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, file->f_relpath, NULL);
+ if ((inode == NULL) || (!inode->u.i_mops->seek64)) {
+ return -ENOSYS;
+ }
+
+ swapInode = file->f_inode;
+ file->f_inode = inode;
+ off = inode->u.i_mops->seek64(file, offset, whence);
+ file->f_inode = swapInode;
+ return off;
+}
+
+static int VfsZpfsDup(const struct file *oldFile, struct file *newFile)
+{
+ int ret;
+ struct inode *inode = oldFile->f_inode;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(inode);
+ inode = VfsZpfsRealInode(zpfsCfg, oldFile->f_relpath, NULL);
+ if ((inode == NULL) || (!inode->u.i_mops->dup)) {
+ return -ENOSYS;
+ }
+
+ ret = inode->u.i_mops->dup(oldFile, newFile);
+ return ret;
+}
+
+static int VfsZpfsOpenDir(struct inode *mountpt, const char *relPath, struct fs_dirent_s *dir)
+{
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(mountpt);
+ if (!VfsZpfsRealInode(zpfsCfg, relPath, NULL)) {
+ return -ENOENT;
+ }
+ struct ZpfsDir *zpfsDir = malloc(sizeof(struct ZpfsDir));
+ if (zpfsDir == NULL) {
+ return -ENOMEM;
+ }
+ zpfsDir->relPath = strdup(relPath);
+ if (zpfsDir->relPath == NULL) {
+ return -ENOMEM;
+ }
+ zpfsDir->index = zpfsCfg->entryCount;
+ zpfsDir->openEntry = -1;
+ dir->u.zpfs = (void*)zpfsDir;
+
+ return OK;
+}
+
+static void CloseEntry(const struct ZpfsConfig *zpfsCfg, struct fs_dirent_s *dir, const int index)
+{
+ struct inode *inode = zpfsCfg->orgEntry[index].mountedInode;
+ if (inode->u.i_mops->closedir != NULL) {
+ inode->u.i_mops->closedir(inode, dir);
+ }
+}
+
+static int VfsZpfsCloseDir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ struct ZpfsDir *zpfsDir = (struct ZpfsDir *)(dir->u.zpfs);
+ if (zpfsDir->relPath) {
+ free(zpfsDir->relPath);
+ zpfsDir->relPath = NULL;
+ }
+ free(zpfsDir);
+ zpfsDir = NULL;
+ return OK;
+}
+
+static int IsExistInEntries(const struct ZpfsConfig *zpfsCfg, const char* relPath, const int index)
+{
+ struct ZpfsEntry entry;
+ struct stat buf;
+ for (int i = index; i >= 0; i--) {
+ entry.mountedPath = zpfsCfg->orgEntry[i].mountedRelpath;
+ entry.mountedRelpath = (char *)relPath;
+ entry.mountedInode = zpfsCfg->orgEntry[i].mountedInode;
+ if (CheckEntryExist(&entry, NULL, &buf) == OK) {
+ return OK;
+ }
+ }
+ return -1;
+}
+
+static int OpenEntry(const struct ZpfsConfig *zpfsCfg,
+ const struct ZpfsDir *zpfsDir, struct fs_dirent_s *dir, const int index)
+{
+ int ret;
+ char *fullPath;
+ char *path = (char *)zpfsCfg->orgEntry[index].mountedRelpath;
+ char *relPath = zpfsDir->relPath;
+ struct inode *curInode = zpfsCfg->orgEntry[index].mountedInode;
+ int len = strlen(path) + strlen(relPath) + 1;
+ int fullLen = len + 1;
+ fullPath = (char *)malloc(fullLen);
+ if (fullPath == NULL) {
+ return -ENOMEM;
+ }
+ ret = snprintf_s(fullPath, fullLen, len, "%s/%s", path, relPath);
+ if (ret < 0) {
+ free(fullPath);
+ return -EINVAL;
+ }
+ ret = -ENOSYS;
+ if (curInode->u.i_mops->opendir != NULL) {
+ ret = curInode->u.i_mops->opendir(curInode, fullPath, dir);
+ }
+ free(fullPath);
+ return ret;
+}
+
+static int VfsZpfsReadDir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ int ret;
+ struct inode *oldInode = NULL;
+ struct inode *curInode = NULL;
+ struct ZpfsDir *zpfsDir = (struct ZpfsDir *)dir->u.zpfs;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(mountpt);
+
+ int index = zpfsDir->index;
+ do {
+ if (zpfsDir->openEntry == -1) {
+ zpfsDir->index--;
+ index = zpfsDir->index;
+ if (index < 0) {
+ ret = -1;
+ break;
+ }
+ ret = OpenEntry(zpfsCfg, zpfsDir, dir, index);
+ if (ret != OK) {
+ break;
+ }
+ zpfsDir->openEntry = 1;
+ }
+
+ curInode = zpfsCfg->orgEntry[index].mountedInode;
+ oldInode = dir->fd_root;
+ dir->fd_root = curInode;
+ ret = curInode->u.i_mops->readdir(curInode, dir);
+ dir->fd_root = oldInode;
+ if (ret != OK) {
+ if (index >= 0) {
+ CloseEntry(zpfsCfg, dir, index);
+ zpfsDir->openEntry = -1;
+ continue;
+ }
+ } else if (IsExistInEntries(zpfsCfg, dir->fd_dir[0].d_name, (index - 1)) == OK) {
+ continue;
+ }
+ ret = 1; // 1 means current op return one file
+ dir->fd_position++;
+ dir->fd_dir[0].d_off = dir->fd_position;
+ dir->fd_dir[0].d_reclen = (uint16_t)sizeof(struct dirent);
+ break;
+ } while (1);
+
+ return ret;
+}
+
+static int VfsZpfsRewindDir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ PRINT_DEBUG("%s NOT support!\n", __FUNCTION__);
+ return OK;
+}
+
+static int VfsZpfsBind(struct inode *blkDriver, const void *data, FAR void **handle, const char *relPath)
+{
+ if (data == NULL) {
+ return -1;
+ }
+ (*handle) = (void*)data;
+ return OK;
+}
+
+static int VfsZpfsUnbind(void *handle, struct inode **blkDriver)
+{
+ struct inode *node = NULL;
+ ZpfsConfig *zpfsCfg = NULL;
+ if (handle != NULL) {
+ zpfsCfg = (ZpfsConfig *)handle;
+ node = inode_unlink(zpfsCfg->patchTarget);
+ INODE_SET_TYPE(node, FSNODEFLAG_DELETED);
+ if (node != zpfsCfg->patchInode) {
+ return -EINVAL;
+ }
+ }
+ return OK;
+}
+
+static int VfsZpfsStatFs(struct inode *mountpt, struct statfs *buf)
+{
+ if (buf == NULL) {
+ return -EINVAL;
+ }
+ (void)memset_s(buf, sizeof(struct statfs), 0, sizeof(struct statfs));
+ buf->f_type = ZPFS_MAGIC;
+ return OK;
+}
+
+static int VfsZpfsStat(struct inode *mountpt, const char *relPath, struct stat *buf)
+{
+ struct inode *inode = NULL;
+ ZpfsConfig *zpfsCfg = GetZpfsConfig(mountpt);
+ inode = GetRelInodeFromVInode(zpfsCfg, relPath, buf, NULL);
+ if (inode == NULL) {
+ return -ENOENT;
+ }
+ return OK;
+}
+
+const struct mountpt_operations zpfsOperations = {
+ VfsZpfsOpen, /* open */
+ VfsZpfsClose, /* close */
+ VfsZpfsRead, /* read */
+ NULL, /* write */
+ VfsZpfsLseek, /* seek */
+ NULL, /* ioctl */
+ OsVfsFileMmap, /* mmap */
+ NULL, /* sync */
+ VfsZpfsDup, /* dup */
+ NULL, /* fstat */
+ NULL, /* truncate */
+ VfsZpfsOpenDir, /* opendir */
+ VfsZpfsCloseDir, /* closedir */
+ VfsZpfsReadDir, /* readdir */
+ VfsZpfsRewindDir, /* rewinddir */
+ VfsZpfsBind, /* bind */
+ VfsZpfsUnbind, /* unbind */
+ VfsZpfsStatFs, /* statfs */
+ NULL, /* virstatfs */
+ NULL, /* unlink */
+ NULL, /* mkdir */
+ NULL, /* rmdir */
+ NULL, /* rename */
+ VfsZpfsStat, /* stat */
+ NULL, /* utime */
+ NULL, /* chattr */
+ VfsZpfsLseek64, /* seek64 */
+ NULL, /* getlabel */
+ NULL, /* fallocate */
+ NULL, /* fallocate64 */
+ NULL, /* truncate64 */
+ NULL, /* fscheck */
+ NULL, /* map_pages */
+ NULL, /* readpage */
+ NULL, /* writepage */
+};
+
+FSMAP_ENTRY(zpfs_fsmap, ZPFS_NAME, zpfsOperations, FALSE, FALSE);
+
+#endif // LOSCFG_FS_ZPFS
diff --git a/fs/zpfs/vfs_zpfs.h b/fs/zpfs/vfs_zpfs.h
new file mode 100644
index 00000000..827b8d0a
--- /dev/null
+++ b/fs/zpfs/vfs_zpfs.h
@@ -0,0 +1,76 @@
+/*
+ * 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 ZPFS_VFS_ZPFS_H
+#define ZPFS_VFS_ZPFS_H
+
+#include
+
+#include "compiler.h"
+#include "los_base.h"
+#include "los_typedef.h"
+#include "menuconfig.h"
+
+#ifdef LOSCFG_FS_ZPFS
+
+#define ZPFS_NAME "zpfs"
+#define ZPFS_LEVELS 3
+
+typedef struct ZpfsDir {
+ char *relPath;
+ int index;
+ int openEntry;
+} ZpfsDir;
+
+typedef struct ZpfsEntry {
+ struct inode *mountedInode;
+ char *mountedPath;
+ char *mountedRelpath;
+} ZpfsEntry;
+
+typedef struct ZpfsConfig {
+ char *patchTarget;
+ struct inode *patchTargetInode;
+ struct inode *patchInode;
+
+ int entryCount;
+ ZpfsEntry orgEntry[ZPFS_LEVELS];
+} ZpfsConfig;
+
+ZpfsConfig *GetZpfsConfig(const struct inode *inode);
+int ZpfsPrepare(const char *source, const char *target, struct inode **inodePtr, bool force);
+void ZpfsFreeConfig(ZpfsConfig *zpfsCfg);
+void ZpfsCleanUp(const void *node, const char *target);
+bool IsZpfsFileSystem(struct inode *inode);
+
+#endif /* LOSCFG_FS_ZPFS */
+
+#endif /* ZPFS_VFS_ZPFS_H */
diff --git a/fs/zpfs/zpfs.c b/fs/zpfs/zpfs.c
new file mode 100644
index 00000000..05da2979
--- /dev/null
+++ b/fs/zpfs/zpfs.c
@@ -0,0 +1,464 @@
+/*
+ * 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 "vfs_zpfs.h"
+
+#include
+#include
+
+#include
+#include
+
+#include "fs/dirent_fs.h"
+#include "inode/inode.h"
+#include "internal.h"
+#include "los_tables.h"
+
+#ifdef LOSCFG_FS_ZPFS
+
+/****************************************************************************
+ * Name: CheckEntryExist
+ *
+ * Description:
+ * check if entry is exist or not.
+ * Input Parameters:
+ * The path
+ * Returned Value:
+ * true or false, it is true for the exist of path.
+ ****************************************************************************/
+bool CheckEntryExist(const char *entry)
+{
+ struct stat64 stat64Info;
+ struct stat statInfo;
+
+ if (stat64(entry, &stat64Info) == 0) {
+ if (S_ISDIR(stat64Info.st_mode) != 0) {
+ return true;
+ } else {
+ return false;
+ }
+ } else if (stat(entry, &statInfo) == 0) {
+ if (S_ISDIR(statInfo.st_mode) != 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ return false;
+}
+
+/****************************************************************************
+ * Name: GetZpfsConfig
+ *
+ * Description:
+ * get the zpfs configuration
+ * Input Parameters:
+ * void
+ * Returned Value:
+ * g_zpfsConfig Save the patch gobal data.
+ ****************************************************************************/
+ZpfsConfig *GetZpfsConfig(const struct inode *inode)
+{
+ ZpfsConfig *zpfsCfg = (ZpfsConfig*)(inode->i_private);
+ return zpfsCfg;
+}
+
+/****************************************************************************
+ * Name: GetSourceList
+ *
+ * Description:
+ * Get the source path list.
+ * eg: /patch/etc:/patch/etc1:/patch/etc2
+ * Input Parameters:
+ * source: /patch/etc:/patch/etc1:/patch/etc2
+ * sourcelist: output path arry
+ * num: output list num
+ *
+ * Returned Value:
+ * OK The mounted folder parameter is right.
+ * EINVAL The mounted folder parameter is wrong.
+ * ENOMEM The memory is not enough
+ ****************************************************************************/
+static int GetSourceList(const char *source, char *sourceList[ZPFS_LEVELS], int *num)
+{
+ char *subSource = NULL;
+ char *path = NULL;
+ char *subPath = NULL;
+ int index;
+ int ret;
+
+ subSource = strdup(source);
+ if (subSource == NULL) {
+ return -ENOMEM;
+ }
+
+ subPath = strtok_r(subSource, ":", &path);
+ for (*num = 0; *num < ZPFS_LEVELS && subPath != NULL; (*num)++) {
+ sourceList[*num] = strdup(subPath);
+ if (sourceList[*num] == NULL) {
+ ret = -ENOMEM;
+ goto EXIT;
+ }
+ subPath = strtok_r(NULL, ":", &path);
+ }
+
+ if (subPath != NULL || *num == 0) {
+ PRINTK("source path num %d error\n", *num);
+ ret = -EINVAL;
+ goto EXIT;
+ }
+
+ free(subSource);
+ return OK;
+
+EXIT:
+ free(subSource);
+ for (index = 0; index < *num; index++) {
+ free(sourceList[index]);
+ sourceList[index] = NULL;
+ }
+ *num = 0;
+ return ret;
+}
+
+
+/****************************************************************************
+ * Name: CheckInputParamsFormat
+ *
+ * Description:
+ * check the mounted folder format and validity. MAX three segment.
+ * eg: /patch/etc:/patch/etc1:/patch/etc2
+ * Input Parameters:
+ * check the mounted folder. eg:
+ * source: /patch/etc:/patch/etc1:/patch/etc2
+ * target: /etc
+ *
+ * Returned Value:
+ * OK The mounted folder parameter is right.
+ * EINVAL The mounted folder parameter is wrong.
+ * ENOMEM The memory is not enough
+ ****************************************************************************/
+static int CheckInputParamsFormat(const char *source, const char *target)
+{
+ char *sourceList[ZPFS_LEVELS] = {0};
+ int num = 0;
+ int ret;
+ int index;
+ bool isTargetValid = false;
+
+ if (source == NULL || target == NULL) {
+ return -EINVAL;
+ }
+
+ ret = GetSourceList(source, sourceList, &num);
+ if (ret != OK) {
+ goto EXIT;
+ }
+
+ for (index = 0; index < num; index++) {
+ if (!CheckEntryExist(sourceList[index])) {
+ ret = -ENOENT;
+ goto EXIT;
+ }
+ /* target must same with one source path */
+ if (strcmp(target, sourceList[index]) == 0) {
+ isTargetValid = true;
+ }
+ }
+
+ if (!isTargetValid) {
+ ret = -EINVAL;
+ goto EXIT;
+ }
+ ret = OK;
+EXIT:
+ for (index = 0; index < num; index++) {
+ free(sourceList[index]);
+ }
+ return ret;
+}
+
+static void ZpfsFreeEntry(ZpfsEntry *zpfsEntry)
+{
+ if (zpfsEntry->mountedPath != NULL) {
+ free(zpfsEntry->mountedPath);
+ zpfsEntry->mountedPath = NULL;
+ }
+ if (zpfsEntry->mountedRelpath != NULL) {
+ free(zpfsEntry->mountedRelpath);
+ zpfsEntry->mountedRelpath = NULL;
+ }
+ zpfsEntry->mountedInode = NULL;
+}
+
+/****************************************************************************
+ * Name: ZpfsFreeConfig
+ *
+ * Description:
+ * Umount the patch file system,
+ * Delete the global patch data and the mount pseudo point.
+ *
+ * Input Parameters:
+ * void
+ * Returned Value:
+ * void
+ ****************************************************************************/
+void ZpfsFreeConfig(ZpfsConfig *zpfsCfg)
+{
+ struct inode *pInode = NULL;
+ if (zpfsCfg == NULL) {
+ return;
+ }
+ pInode = zpfsCfg->patchInode;
+ if (pInode != NULL) {
+ INODE_SET_TYPE(pInode, FSNODEFLAG_DELETED);
+ inode_release(pInode);
+ pInode = NULL;
+ }
+
+ for (int i = 0; i < zpfsCfg->entryCount; i++) {
+ ZpfsFreeEntry(&(zpfsCfg->orgEntry[i]));
+ }
+ if (zpfsCfg->patchTarget != NULL) {
+ free(zpfsCfg->patchTarget);
+ zpfsCfg->patchTarget = NULL;
+ }
+ free(zpfsCfg);
+ zpfsCfg = NULL;
+}
+
+/****************************************************************************
+ * Name: IsTargetMounted
+ * Description:
+ * The mount patch target path must be the mounted path.
+ * Input Parameters:
+ * target: The mount point
+ * Returned Value:
+ * OK
+ * EINVAL The mount patch target path is not the mounted path.
+ ****************************************************************************/
+static int IsTargetMounted(const char *target)
+{
+ struct inode *inode = NULL;
+ char *path = NULL;
+ struct statfs buf;
+
+ if (!CheckEntryExist(target)) {
+ return -EINVAL;
+ }
+
+ inode = inode_search((FAR const char **)&target, (FAR struct inode**)NULL,
+ (FAR struct inode**)NULL, (const char **)&path);
+ if (inode == NULL || !INODE_IS_MOUNTPT(inode)) {
+ PRINT_ERR("Can't to mount to this inode %s\n", target);
+ return -EINVAL;
+ }
+ if ((inode->u.i_mops != NULL) && (inode->u.i_mops->statfs != NULL)) {
+ if (inode->u.i_mops->statfs(inode, &buf) == OK) {
+ if (buf.f_type == ZPFS_MAGIC) {
+ return -EEXIST;
+ }
+ }
+ }
+ if (path == NULL || path[0] == '\0') {
+ return -EEXIST;
+ }
+ return OK;
+}
+
+/****************************************************************************
+ * Name: SaveZpfsParameter
+ *
+ * Description:
+ * When the patch file system is mounted, the patch gobal data is built.
+ *
+ * Input Parameters:
+ * source: The mounted patch folder
+ * target: The mount point
+ * Returned Value:
+ * OK Save the patch gobal data.
+ * ENOMEM The memory is not enough.
+ * EBADMSG There is no data.
+ ****************************************************************************/
+static int SaveZpfsParameter(const char *source, const char *target, struct ZpfsConfig *zpfsCfg)
+{
+ int ret;
+ const char *path = NULL;
+ int num = 0;
+ int index;
+ char *sourceList[ZPFS_LEVELS] = {0};
+
+ /* save the mount point */
+ zpfsCfg->patchTarget = strdup(target);
+ if (zpfsCfg->patchTarget == NULL) {
+ return -ENOMEM;
+ }
+
+ /* save the mount folder inode */
+ zpfsCfg->patchTargetInode = inode_search((const char **)&target,
+ (struct inode**)NULL, (struct inode**)NULL, &path);
+ if (zpfsCfg->patchTargetInode == NULL) {
+ return -EINVAL;
+ }
+
+ ret = GetSourceList(source, sourceList, &num);
+ if (ret != OK) {
+ return ret;
+ }
+
+ zpfsCfg->entryCount = num;
+ for (index = 0; index < num; index++) {
+ zpfsCfg->orgEntry[index].mountedPath = sourceList[index];
+
+ /* save the mounted folder inode */
+ zpfsCfg->orgEntry[index].mountedInode = inode_search((const char **)&sourceList[index],
+ (struct inode**)NULL, (struct inode**)NULL, &path);
+ if (zpfsCfg->orgEntry[index].mountedInode == NULL) {
+ ret = -EINVAL;
+ goto ERROR_PROCESS;
+ }
+
+ /* save the mounted relative path */
+ zpfsCfg->orgEntry[index].mountedRelpath = (char*)path;
+ }
+
+ return OK;
+
+ERROR_PROCESS:
+ for (index = 0; index < num; index++) {
+ free(sourceList[index]);
+ sourceList[index] = NULL;
+ }
+ return ret;
+}
+
+/****************************************************************************
+ * Name: ZpfsPrepare
+ * Description:
+ * The main function of mount zpfs.
+ * Input Parameters:
+ * source: The mounted parameter
+ * target: The mount path
+ * inodePtr: the new inode info of target
+ * force: It is true for zpfs
+ * Returned Value:
+ * OK
+ * EINVAL The parameter is wrong.
+ * ENOMEM It is not enough memory.
+ ****************************************************************************/
+int ZpfsPrepare(const char *source, const char *target, struct inode **inodePtr, bool force)
+{
+ /* Check the mounted folder parameter */
+ int ret = CheckInputParamsFormat(source, target);
+ if (ret != OK) {
+ PRINT_ERR("Parameter is err source:%s target:%s.\n", source, target);
+ return ret;
+ }
+
+ /* The mount target path must be the mounted path */
+ ret = IsTargetMounted(target);
+ if (ret != OK) {
+ PRINT_ERR("Can't to mount to this inode %s\n", target);
+ return ret;
+ }
+
+ ZpfsConfig *zpfsCfg = (ZpfsConfig*) malloc(sizeof(struct ZpfsConfig));
+ if (zpfsCfg == NULL) {
+ PRINT_ERR("Memory is not enought.\n");
+ return -ENOMEM;
+ }
+ (void)memset_s(zpfsCfg, sizeof(struct ZpfsConfig), 0, sizeof(struct ZpfsConfig));
+
+ /* Save the patch global data */
+ ret = SaveZpfsParameter(source, target, zpfsCfg);
+ if (ret != OK) {
+ ZpfsFreeConfig(zpfsCfg);
+ PRINT_ERR("Memory is not enought.\n");
+ return ret;
+ }
+
+ /* Create the patch inode */
+ ret = inode_reserve_rootdir(target, inodePtr, force);
+ if (ret != OK) {
+ ZpfsFreeConfig(zpfsCfg);
+ PRINT_ERR("failed to create mounted inode.\n");
+ return ret;
+ }
+ zpfsCfg->patchInode = *inodePtr;
+ (*inodePtr)->i_private = zpfsCfg;
+ return ret;
+}
+
+/****************************************************************************
+ * Name: ZpfsCleanUp
+ * Description:
+ * Clean the configuration of zpfs.
+ * Input Parameters:
+ * target: The mount path
+ * Returned Value:
+ * void
+ ****************************************************************************/
+void ZpfsCleanUp(const void *node, const char *target)
+{
+ struct statfs buf;
+ struct inode *inode = (struct inode *)node;
+ if ((target == NULL) || (inode == NULL) ||
+ (inode->u.i_mops == NULL) ||
+ (inode->u.i_mops->statfs == NULL)) {
+ return;
+ }
+ if (inode->u.i_mops->statfs(inode, &buf) == OK) {
+ if (buf.f_type == ZPFS_MAGIC) {
+ ZpfsConfig *zpfsCfg = inode->i_private;
+ if (strcmp(zpfsCfg->patchTarget, target) == 0) {
+ ZpfsFreeConfig(zpfsCfg);
+ }
+ }
+ }
+}
+
+bool IsZpfsFileSystem(struct inode *inode)
+{
+ struct statfs buf;
+ if (inode == NULL || inode->u.i_mops == NULL ||
+ inode->u.i_mops->statfs == NULL) {
+ return false;
+ }
+ if (inode->u.i_mops->statfs(inode, &buf) == OK) {
+ if (buf.f_type == ZPFS_MAGIC) {
+ return true;
+ }
+ }
+ return false;
+}
+
+#endif // LOSCFG_FS_ZPFS
diff --git a/kernel/BUILD.gn b/kernel/BUILD.gn
old mode 100644
new mode 100755
index ddcf1f7b..34a26649
--- a/kernel/BUILD.gn
+++ b/kernel/BUILD.gn
@@ -1,59 +1,56 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# 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("//build/lite/config/component/lite_component.gni")
-
-lite_component("kernel") {
- features = [
- "base",
- "syscall",
- "user",
- ]
- if (LOSCFG_KERNEL_CPUP) {
- features += [ "extended/cpup" ]
- }
- if (LOSCFG_KERNEL_MPU) {
- features += [ "extended/mpu" ]
- }
- if (LOSCFG_KERNEL_CPPSUPPORT) {
- features += [ "extended/cppsupport" ]
- }
- if (LOSCFG_KERNEL_DYNLOAD) {
- features += [ "extended/dynload" ]
- }
- if (LOSCFG_KERNEL_TICKLESS) {
- features += [ "extended/tickless" ]
- }
- if (LOSCFG_KERNEL_TRACE) {
- features += [ "extended/trace" ]
- }
- if (LOSCFG_KERNEL_VDSO) {
- features += [ "extended/vdso" ]
- }
-}
+
+import("//build/lite/config/component/lite_component.gni")
+
+lite_component("kernel") {
+ features = [
+ "base",
+ "syscall",
+ "user",
+ ]
+ if (LOSCFG_KERNEL_CPUP) {
+ features += [ "extended/cpup" ]
+ }
+ if (LOSCFG_KERNEL_MPU) {
+ features += [ "extended/mpu" ]
+ }
+ if (LOSCFG_KERNEL_CPPSUPPORT) {
+ features += [ "extended/cppsupport" ]
+ }
+ if (LOSCFG_KERNEL_DYNLOAD) {
+ features += [ "extended/dynload" ]
+ }
+ if (LOSCFG_KERNEL_TRACE) {
+ features += [ "extended/trace" ]
+ }
+ if (LOSCFG_KERNEL_VDSO) {
+ features += [ "extended/vdso" ]
+ }
+}
diff --git a/kernel/Kconfig b/kernel/Kconfig
old mode 100644
new mode 100755
index 6c5115f5..709adc90
--- a/kernel/Kconfig
+++ b/kernel/Kconfig
@@ -83,20 +83,20 @@ config KERNEL_VDSO
help
If you wish to speed up some system calls.
-config KERNEL_TICKLESS
- bool "Enable Tickless Feature"
- default y
- depends on KERNEL_EXTKERNEL
- help
- If you wish to build LiteOS with support for tickless.
-
config KERNEL_TRACE
bool "Enable Trace Feature"
default n
- depends on KERNEL_EXTKERNEL
+ depends on KERNEL_EXTKERNEL && DEBUG_VERSION
help
If you wish to record LiteOS's task and interrupt switch trace.
+config KERNEL_SHM
+ bool "Enable Shared Memory"
+ default y
+ depends on KERNEL_EXTKERNEL
+ help
+ Answer Y to enable LiteOS support shared memory.
+
config KERNEL_LITEIPC
bool "Enable liteipc"
default y
diff --git a/kernel/base/BUILD.gn b/kernel/base/BUILD.gn
old mode 100644
new mode 100755
index 6900c4e4..67cb2543
--- a/kernel/base/BUILD.gn
+++ b/kernel/base/BUILD.gn
@@ -1,82 +1,80 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# 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.
-
-static_library("base") {
-
- sources = [
- "ipc/los_mux.c",
- "ipc/los_sem_debug.c",
- "ipc/los_queue_debug.c",
- "ipc/los_ipcdebug.c",
- "ipc/los_mux_debug.c",
- "ipc/los_sem.c",
- "ipc/los_event.c",
- "ipc/los_queue.c",
- "core/los_swtmr.c",
- "core/los_task.c",
- "core/los_timeslice.c",
- "core/los_sortlink.c",
- "core/los_bitmap.c",
- "core/los_process.c",
- "core/los_sys.c",
- "core/los_tick.c",
- "mem/bestfit/los_memory.c",
- "mem/bestfit/los_multipledlinkhead.c",
- "mem/membox/los_membox.c",
- "mem/common/los_memstat.c",
- "om/los_err.c",
- "misc/task_shellcmd.c",
- "misc/los_stackinfo.c",
- "misc/sysinfo_shellcmd.c",
- "misc/los_misc.c",
- "misc/swtmr_shellcmd.c",
- "misc/mempt_shellcmd.c",
- "misc/vm_shellcmd.c",
- "mp/los_stat.c",
- "mp/los_lockdep.c",
- "mp/los_mp.c",
- "mp/los_percpu.c",
- "sched/sched_sq/los_priqueue.c",
- "sched/sched_sq/los_sched.c",
- "vm/filemap.c",
- "vm/pmm.c",
- "vm/vm.c",
- "vm/vmm.c",
- ]
-
- include_dirs = [
- "include",
- "../extended/include",
- "../extended/vdso/include",
- "../extended/dynload/include",
- "../include",
- "mem",
- ]
-
-}
+
+static_library("base") {
+ sources = [
+ "core/los_bitmap.c",
+ "core/los_process.c",
+ "core/los_sortlink.c",
+ "core/los_swtmr.c",
+ "core/los_sys.c",
+ "core/los_task.c",
+ "core/los_tick.c",
+ "core/los_timeslice.c",
+ "ipc/los_event.c",
+ "ipc/los_ipcdebug.c",
+ "ipc/los_mux.c",
+ "ipc/los_mux_debug.c",
+ "ipc/los_queue.c",
+ "ipc/los_queue_debug.c",
+ "ipc/los_sem.c",
+ "ipc/los_sem_debug.c",
+ "mem/bestfit/los_memory.c",
+ "mem/bestfit/los_multipledlinkhead.c",
+ "mem/common/los_memstat.c",
+ "mem/membox/los_membox.c",
+ "misc/los_misc.c",
+ "misc/los_stackinfo.c",
+ "misc/mempt_shellcmd.c",
+ "misc/swtmr_shellcmd.c",
+ "misc/sysinfo_shellcmd.c",
+ "misc/task_shellcmd.c",
+ "misc/vm_shellcmd.c",
+ "mp/los_lockdep.c",
+ "mp/los_mp.c",
+ "mp/los_percpu.c",
+ "mp/los_stat.c",
+ "om/los_err.c",
+ "sched/sched_sq/los_priqueue.c",
+ "sched/sched_sq/los_sched.c",
+ "vm/filemap.c",
+ "vm/pmm.c",
+ "vm/vm.c",
+ "vm/vmm.c",
+ ]
+
+ include_dirs = [
+ "include",
+ "../extended/include",
+ "../extended/vdso/include",
+ "../extended/dynload/include",
+ "../include",
+ "mem",
+ ]
+}
diff --git a/kernel/base/Makefile b/kernel/base/Makefile
old mode 100644
new mode 100755
index 2112eaab..920c5814
--- a/kernel/base/Makefile
+++ b/kernel/base/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -28,13 +28,14 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk
+include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard ipc/*.c) $(wildcard core/*.c) $(wildcard mem/membox/*.c) $(wildcard mem/common/*.c) \
$(wildcard om/*.c)\
$(wildcard misc/*.c)\
- $(wildcard mem/bestfit/*.c) \
+ $(wildcard mem/tlsf/*.c) \
$(wildcard mp/*.c) \
$(wildcard sched/sched_sq/*.c) \
$(wildcard vm/*.c)
@@ -51,4 +52,4 @@ LOCAL_INCLUDE := \
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
-include $(MODULE)
+include $(HDF_DRIVER)
diff --git a/kernel/base/core/los_bitmap.c b/kernel/base/core/los_bitmap.c
old mode 100644
new mode 100755
index ae62a47c..36ff3f47
--- a/kernel/base/core/los_bitmap.c
+++ b/kernel/base/core/los_bitmap.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c
old mode 100644
new mode 100755
index 90cce634..7f169a68
--- a/kernel/base/core/los_process.c
+++ b/kernel/base/core/los_process.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,6 +30,7 @@
*/
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#include "los_task_pri.h"
#include "los_hw_pri.h"
#include "los_sem_pri.h"
@@ -42,9 +43,6 @@
#include "time.h"
#include "user_copy.h"
#include "los_signal.h"
-#ifdef LOSCFG_KERNEL_CPUP
-#include "los_cpup_pri.h"
-#endif
#ifdef LOSCFG_SECURITY_VID
#include "vid_api.h"
#endif
@@ -62,7 +60,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-LITE_OS_SEC_BSS LosProcessCB *g_runProcess[LOSCFG_KERNEL_CORE_NUM];
LITE_OS_SEC_BSS LosProcessCB *g_processCBArray = NULL;
LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_freeProcess;
LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_processRecyleList;
@@ -72,71 +69,6 @@ LITE_OS_SEC_BSS UINT32 g_kernelIdleProcess = OS_INVALID_VALUE;
LITE_OS_SEC_BSS UINT32 g_processMaxNum;
LITE_OS_SEC_BSS ProcessGroup *g_processGroup = NULL;
-LITE_OS_SEC_TEXT_INIT VOID OsTaskSchedQueueDequeue(LosTaskCB *taskCB, UINT16 status)
-{
- LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- OS_TASK_PRI_QUEUE_DEQUEUE(processCB, taskCB);
- taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
- }
-
- if (processCB->threadScheduleMap != 0) {
- return;
- }
-
- if (processCB->processStatus & OS_PROCESS_STATUS_READY) {
- processCB->processStatus &= ~OS_PROCESS_STATUS_READY;
- OS_PROCESS_PRI_QUEUE_DEQUEUE(processCB);
- }
-
-#if (LOSCFG_KERNEL_SMP == YES)
- if (OS_PROCESS_GET_RUNTASK_COUNT(processCB->processStatus) == 1) {
-#endif
- processCB->processStatus |= status;
-#if (LOSCFG_KERNEL_SMP == YES)
- }
-#endif
-}
-
-STATIC INLINE VOID OsSchedTaskEnqueue(LosProcessCB *processCB, LosTaskCB *taskCB)
-{
- if (((taskCB->policy == LOS_SCHED_RR) && (taskCB->timeSlice != 0)) ||
- ((taskCB->taskStatus & OS_TASK_STATUS_RUNNING) && (taskCB->policy == LOS_SCHED_FIFO))) {
- OS_TASK_PRI_QUEUE_ENQUEUE_HEAD(processCB, taskCB);
- } else {
- OS_TASK_PRI_QUEUE_ENQUEUE(processCB, taskCB);
- }
- taskCB->taskStatus |= OS_TASK_STATUS_READY;
-}
-
-LITE_OS_SEC_TEXT_INIT VOID OsTaskSchedQueueEnqueue(LosTaskCB *taskCB, UINT16 status)
-{
- LosProcessCB *processCB = NULL;
-
- LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
-
- processCB = OS_PCB_FROM_PID(taskCB->processID);
- if (!(processCB->processStatus & OS_PROCESS_STATUS_READY)) {
- if (((processCB->policy == LOS_SCHED_RR) && (processCB->timeSlice != 0)) ||
- ((processCB->processStatus & OS_PROCESS_STATUS_RUNNING) && (processCB->policy == LOS_SCHED_FIFO))) {
- OS_PROCESS_PRI_QUEUE_ENQUEUE_HEAD(processCB);
- } else {
- OS_PROCESS_PRI_QUEUE_ENQUEUE(processCB);
- }
- processCB->processStatus &= ~(status | OS_PROCESS_STATUS_PEND);
- processCB->processStatus |= OS_PROCESS_STATUS_READY;
- } else {
- LOS_ASSERT(!(processCB->processStatus & OS_PROCESS_STATUS_PEND));
- LOS_ASSERT((UINTPTR)processCB->pendList.pstNext);
- if ((processCB->timeSlice == 0) && (processCB->policy == LOS_SCHED_RR)) {
- OS_PROCESS_PRI_QUEUE_DEQUEUE(processCB);
- OS_PROCESS_PRI_QUEUE_ENQUEUE(processCB);
- }
- }
-
- OsSchedTaskEnqueue(processCB, taskCB);
-}
-
STATIC INLINE VOID OsInsertPCBToFreeList(LosProcessCB *processCB)
{
UINT32 pid = processCB->processID;
@@ -255,7 +187,7 @@ STATIC LosProcessCB *OsFindExitChildProcess(const LosProcessCB *processCB, INT32
STATIC INLINE VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
{
taskCB->waitID = wakePID;
- OsTaskWake(taskCB);
+ OsSchedTaskWake(taskCB);
#if (LOSCFG_KERNEL_SMP == YES)
LOS_MpSchedule(OS_MP_CPU_ALL);
#endif
@@ -462,15 +394,10 @@ STATIC VOID OsProcessNaturalExit(LosTaskCB *runTask, UINT32 status)
LosProcessCB *processCB = OS_PCB_FROM_PID(runTask->processID);
LosProcessCB *parentCB = NULL;
- LOS_ASSERT(!(processCB->threadScheduleMap != 0));
LOS_ASSERT(processCB->processStatus & OS_PROCESS_STATUS_RUNNING);
OsChildProcessResourcesFree(processCB);
-#ifdef LOSCFG_KERNEL_CPUP
- OsCpupClean(processCB->processID);
-#endif
-
/* is a child process */
if (processCB->parentProcessID != OS_INVALID_VALUE) {
parentCB = OS_PCB_FROM_PID(processCB->parentProcessID);
@@ -498,7 +425,7 @@ STATIC VOID OsProcessNaturalExit(LosTaskCB *runTask, UINT32 status)
return;
}
-LITE_OS_SEC_TEXT_INIT UINT32 OsProcessInit(VOID)
+STATIC UINT32 OsProcessInit(VOID)
{
UINT32 index;
UINT32 size;
@@ -521,43 +448,18 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsProcessInit(VOID)
LOS_ListTailInsert(&g_freeProcess, &g_processCBArray[index].pendList);
}
+ g_kernelIdleProcess = 0; /* 0: The idle process ID of the kernel-mode process is fixed at 0 */
+ LOS_ListDelete(&OS_PCB_FROM_PID(g_kernelIdleProcess)->pendList);
+
g_userInitProcess = 1; /* 1: The root process ID of the user-mode process is fixed at 1 */
- LOS_ListDelete(&g_processCBArray[g_userInitProcess].pendList);
+ LOS_ListDelete(&OS_PCB_FROM_PID(g_userInitProcess)->pendList);
g_kernelInitProcess = 2; /* 2: The root process ID of the kernel-mode process is fixed at 2 */
- LOS_ListDelete(&g_processCBArray[g_kernelInitProcess].pendList);
+ LOS_ListDelete(&OS_PCB_FROM_PID(g_kernelInitProcess)->pendList);
return LOS_OK;
}
-STATIC UINT32 OsCreateIdleProcess(VOID)
-{
- UINT32 ret;
- CHAR *idleName = "Idle";
- LosProcessCB *idleProcess = NULL;
- Percpu *perCpu = OsPercpuGet();
- UINT32 *idleTaskID = &perCpu->idleTaskID;
-
- ret = OsCreateResourceFreeTask();
- if (ret != LOS_OK) {
- return ret;
- }
-
- INT32 processId = LOS_Fork(CLONE_FILES, "KIdle", (TSK_ENTRY_FUNC)OsIdleTask, LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE);
- if (processId < 0) {
- return LOS_NOK;
- }
- g_kernelIdleProcess = (UINT32)processId;
-
- idleProcess = OS_PCB_FROM_PID(g_kernelIdleProcess);
- *idleTaskID = idleProcess->threadGroupID;
- OS_TCB_FROM_TID(*idleTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
-#if (LOSCFG_KERNEL_SMP == YES)
- OS_TCB_FROM_TID(*idleTaskID)->cpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
-#endif
- return (UINT32)OsSetTaskName(OS_TCB_FROM_TID(*idleTaskID), idleName, FALSE);
-}
-
LITE_OS_SEC_TEXT VOID OsProcessCBRecyleToFree(VOID)
{
UINT32 intSave;
@@ -683,20 +585,13 @@ UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
return LOS_OK;
}
-STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, UINT16 policy, const CHAR *name)
+STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, const CHAR *name)
{
- UINT32 count;
- LosVmSpace *space = NULL;
- LosVmPage *vmPage = NULL;
- status_t status;
- BOOL retVal = FALSE;
-
processCB->processMode = mode;
processCB->processStatus = OS_PROCESS_STATUS_INIT;
processCB->parentProcessID = OS_INVALID_VALUE;
processCB->threadGroupID = OS_INVALID_VALUE;
processCB->priority = priority;
- processCB->policy = policy;
processCB->umask = OS_PROCESS_DEFAULT_UMASK;
processCB->timerID = (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID;
@@ -705,40 +600,18 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
LOS_ListInit(&processCB->exitChildList);
LOS_ListInit(&(processCB->waitList));
- for (count = 0; count < OS_PRIORITY_QUEUE_NUM; ++count) {
- LOS_ListInit(&processCB->threadPriQueueList[count]);
- }
-
if (OsProcessIsUserMode(processCB)) {
- space = LOS_MemAlloc(m_aucSysMem0, sizeof(LosVmSpace));
- if (space == NULL) {
- PRINT_ERR("Init process struct, alloc space memory failed!\n");
- return LOS_ENOMEM;
- }
- VADDR_T *ttb = LOS_PhysPagesAllocContiguous(1);
- if (ttb == NULL) {
- PRINT_ERR("Init process struct, alloc ttb failed!\n");
- (VOID)LOS_MemFree(m_aucSysMem0, space);
- return LOS_ENOMEM;
- }
- (VOID)memset_s(ttb, PAGE_SIZE, 0, PAGE_SIZE);
- retVal = OsUserVmSpaceInit(space, ttb);
- vmPage = OsVmVaddrToPage(ttb);
- if ((retVal == FALSE) || (vmPage == NULL)) {
- PRINT_ERR("Init process struct, create space failed!\n");
+ processCB->vmSpace = OsCreateUserVmSapce();
+ if (processCB->vmSpace == NULL) {
processCB->processStatus = OS_PROCESS_FLAG_UNUSED;
- (VOID)LOS_MemFree(m_aucSysMem0, space);
- LOS_PhysPagesFreeContiguous(ttb, 1);
- return LOS_EAGAIN;
+ return LOS_ENOMEM;
}
- processCB->vmSpace = space;
- LOS_ListAdd(&processCB->vmSpace->archMmu.ptList, &(vmPage->node));
} else {
processCB->vmSpace = LOS_GetKVmSpace();
}
#ifdef LOSCFG_SECURITY_VID
- status = VidMapListInit(processCB);
+ status_t status = VidMapListInit(processCB);
if (status != LOS_OK) {
return LOS_ENOMEM;
}
@@ -825,7 +698,7 @@ LITE_OS_SEC_TEXT INT32 LOS_GetGroupID(VOID)
STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const CHAR *name, UINT16 priority)
{
ProcessGroup *group = NULL;
- UINT32 ret = OsInitPCB(processCB, flags, priority, LOS_SCHED_RR, name);
+ UINT32 ret = OsInitPCB(processCB, flags, priority, name);
if (ret != LOS_OK) {
goto EXIT;
}
@@ -862,10 +735,6 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
}
#endif
-#ifdef LOSCFG_KERNEL_CPUP
- OsCpupSet(processCB->processID);
-#endif
-
return LOS_OK;
EXIT:
@@ -873,65 +742,47 @@ EXIT:
return ret;
}
-LITE_OS_SEC_TEXT_INIT UINT32 OsKernelInitProcess(VOID)
+LITE_OS_SEC_TEXT_INIT UINT32 OsSystemProcessCreate(VOID)
{
- LosProcessCB *processCB = NULL;
- UINT32 ret;
-
- ret = OsProcessInit();
+ UINT32 ret = OsProcessInit();
if (ret != LOS_OK) {
return ret;
}
- processCB = OS_PCB_FROM_PID(g_kernelInitProcess);
- ret = OsProcessCreateInit(processCB, OS_KERNEL_MODE, "KProcess", 0);
+ LosProcessCB *kerInitProcess = OS_PCB_FROM_PID(g_kernelInitProcess);
+ ret = OsProcessCreateInit(kerInitProcess, OS_KERNEL_MODE, "KProcess", 0);
if (ret != LOS_OK) {
return ret;
}
- processCB->processStatus &= ~OS_PROCESS_STATUS_INIT;
- g_processGroup = processCB->group;
+ kerInitProcess->processStatus &= ~OS_PROCESS_STATUS_INIT;
+ g_processGroup = kerInitProcess->group;
LOS_ListInit(&g_processGroup->groupList);
- OsCurrProcessSet(processCB);
+ OsCurrProcessSet(kerInitProcess);
- return OsCreateIdleProcess();
-}
-
-LITE_OS_SEC_TEXT UINT32 LOS_ProcessYield(VOID)
-{
- UINT32 count;
- UINT32 intSave;
- LosProcessCB *runProcessCB = NULL;
-
- if (OS_INT_ACTIVE) {
- return LOS_ERRNO_TSK_YIELD_IN_INT;
+ ret = OsCreateResourceFreeTask();
+ if (ret != LOS_OK) {
+ return ret;
}
- if (!OsPreemptable()) {
- return LOS_ERRNO_TSK_YIELD_IN_LOCK;
+ LosProcessCB *idleProcess = OS_PCB_FROM_PID(g_kernelIdleProcess);
+ ret = OsInitPCB(idleProcess, OS_KERNEL_MODE, OS_TASK_PRIORITY_LOWEST, "KIdle");
+ if (ret != LOS_OK) {
+ return ret;
}
+ idleProcess->parentProcessID = kerInitProcess->processID;
+ LOS_ListTailInsert(&kerInitProcess->childrenList, &idleProcess->siblingList);
+ idleProcess->group = kerInitProcess->group;
+ LOS_ListTailInsert(&kerInitProcess->group->processList, &idleProcess->subordinateGroupList);
+ idleProcess->user = kerInitProcess->user;
+ idleProcess->files = kerInitProcess->files;
- SCHEDULER_LOCK(intSave);
- runProcessCB = OsCurrProcessGet();
-
- /* reset timeslice of yeilded task */
- runProcessCB->timeSlice = 0;
-
- count = OS_PROCESS_PRI_QUEUE_SIZE(runProcessCB);
- if (count > 0) {
- if (runProcessCB->processStatus & OS_PROCESS_STATUS_READY) {
- OS_PROCESS_PRI_QUEUE_DEQUEUE(runProcessCB);
- }
- OS_PROCESS_PRI_QUEUE_ENQUEUE(runProcessCB);
- runProcessCB->processStatus |= OS_PROCESS_STATUS_READY;
- OsSchedTaskEnqueue(runProcessCB, OsCurrTaskGet());
- } else {
- SCHEDULER_UNLOCK(intSave);
- return LOS_OK;
+ ret = OsIdleTaskCreate();
+ if (ret != LOS_OK) {
+ return ret;
}
+ idleProcess->threadGroupID = OsPercpuGet()->idleTaskID;
- OsSchedResched();
- SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
@@ -942,15 +793,15 @@ STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 p
}
if (which != LOS_PRIO_PROCESS) {
- return LOS_EOPNOTSUPP;
+ return LOS_EINVAL;
}
if (prio > OS_PROCESS_PRIORITY_LOWEST) {
return LOS_EINVAL;
}
- if ((policy != LOS_SCHED_FIFO) && (policy != LOS_SCHED_RR)) {
- return LOS_EOPNOTSUPP;
+ if (policy != LOS_SCHED_RR) {
+ return LOS_EINVAL;
}
return LOS_OK;
@@ -979,9 +830,10 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, UINT16 prio)
}
#endif
-LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy, BOOL policyFlag)
+LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
{
LosProcessCB *processCB = NULL;
+ BOOL needSched = FALSE;
UINT32 intSave;
INT32 ret;
@@ -1004,29 +856,11 @@ LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio
}
#endif
- if (policyFlag == TRUE) {
- if (policy == LOS_SCHED_FIFO) {
- processCB->timeSlice = 0;
- }
- processCB->policy = policy;
- }
-
- if (processCB->processStatus & OS_PROCESS_STATUS_READY) {
- OS_PROCESS_PRI_QUEUE_DEQUEUE(processCB);
- processCB->priority = prio;
- OS_PROCESS_PRI_QUEUE_ENQUEUE(processCB);
- } else {
- processCB->priority = prio;
- if (!(processCB->processStatus & OS_PROCESS_STATUS_RUNNING)) {
- ret = LOS_OK;
- goto EXIT;
- }
- }
-
+ needSched = OsSchedModifyProcessSchedParam(processCB, policy, prio);
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
- if (OS_SCHEDULER_ACTIVE) {
+ if (needSched && OS_SCHEDULER_ACTIVE) {
LOS_Schedule();
}
return LOS_OK;
@@ -1038,36 +872,32 @@ EXIT:
LITE_OS_SEC_TEXT INT32 LOS_SetProcessScheduler(INT32 pid, UINT16 policy, UINT16 prio)
{
- return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, policy, TRUE);
+ return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, policy);
}
LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid)
{
- LosProcessCB *processCB = NULL;
UINT32 intSave;
- INT32 policy;
if (OS_PID_CHECK_INVALID(pid)) {
return -LOS_EINVAL;
}
SCHEDULER_LOCK(intSave);
- processCB = OS_PCB_FROM_PID(pid);
+ LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
if (OsProcessIsUnused(processCB)) {
- policy = -LOS_ESRCH;
- goto OUT;
+ SCHEDULER_UNLOCK(intSave);
+ return -LOS_ESRCH;
}
- policy = processCB->policy;
-
-OUT:
SCHEDULER_UNLOCK(intSave);
- return policy;
+
+ return LOS_SCHED_RR;
}
LITE_OS_SEC_TEXT INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio)
{
- return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, LOS_SCHED_RR, FALSE);
+ return OsSetProcessScheduler(LOS_PRIO_PROCESS, pid, prio, LOS_GetProcessScheduler(pid));
}
LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
@@ -1082,7 +912,7 @@ LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
}
if (which != LOS_PRIO_PROCESS) {
- return -LOS_EOPNOTSUPP;
+ return -LOS_EINVAL;
}
SCHEDULER_LOCK(intSave);
@@ -1113,7 +943,7 @@ LITE_OS_SEC_TEXT VOID OsWaitSignalToWakeProcess(LosProcessCB *processCB)
}
/* only suspend process can continue */
- if (!(processCB->processStatus & OS_PROCESS_STATUS_PEND)) {
+ if (!(processCB->processStatus & OS_PROCESS_STATUS_PENDING)) {
return;
}
@@ -1131,12 +961,7 @@ STATIC VOID OsWaitInsertWaitListInOrder(LosTaskCB *runTask, LosProcessCB *proces
LOS_DL_LIST *list = head;
LosTaskCB *taskCB = NULL;
- (VOID)OsTaskWait(&processCB->waitList, LOS_WAIT_FOREVER, FALSE);
- LOS_ListDelete(&runTask->pendList);
- if (runTask->waitFlag == OS_PROCESS_WAIT_PRO) {
- LOS_ListHeadInsert(&processCB->waitList, &runTask->pendList);
- return;
- } else if (runTask->waitFlag == OS_PROCESS_WAIT_GID) {
+ if (runTask->waitFlag == OS_PROCESS_WAIT_GID) {
while (list->pstNext != head) {
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
if (taskCB->waitFlag == OS_PROCESS_WAIT_PRO) {
@@ -1145,20 +970,21 @@ STATIC VOID OsWaitInsertWaitListInOrder(LosTaskCB *runTask, LosProcessCB *proces
}
break;
}
- LOS_ListHeadInsert(list, &runTask->pendList);
- return;
- }
-
- while (list->pstNext != head) {
- taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
- if (taskCB->waitFlag != OS_PROCESS_WAIT_ANY) {
- list = list->pstNext;
- continue;
+ } else if (runTask->waitFlag == OS_PROCESS_WAIT_ANY) {
+ while (list->pstNext != head) {
+ taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(list));
+ if (taskCB->waitFlag != OS_PROCESS_WAIT_ANY) {
+ list = list->pstNext;
+ continue;
+ }
+ break;
}
- break;
}
+ /* if runTask->waitFlag == OS_PROCESS_WAIT_PRO,
+ * this node is inserted directly into the header of the waitList
+ */
- LOS_ListHeadInsert(list, &runTask->pendList);
+ (VOID)OsSchedTaskWait(list->pstNext, LOS_WAIT_FOREVER, TRUE);
return;
}
@@ -1306,8 +1132,6 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
OsWaitInsertWaitListInOrder(runTask, processCB);
- OsSchedResched();
-
runTask->waitFlag = 0;
if (runTask->waitID == OS_INVALID_VALUE) {
pid = -LOS_ECHILD;
@@ -1500,8 +1324,10 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
processCB->sigHandler = 0;
OsCurrTaskGet()->sig.sigprocmask = 0;
+ LOS_VmSpaceFree(oldSpace);
#ifdef LOSCFG_FS_VFS
delete_files(OsCurrProcessGet(), (struct files_struct *)oldFiles);
+ alloc_std_fd(OsCurrProcessGet()->files->fdt);
#endif
OsSwtmrRecycle(processCB->processID);
@@ -1518,7 +1344,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
processCB->processStatus &= ~OS_PROCESS_FLAG_EXIT;
processCB->processStatus |= OS_PROCESS_FLAG_ALREADY_EXEC;
- LOS_VmSpaceFree(oldSpace);
return LOS_OK;
}
@@ -1616,7 +1441,8 @@ STATIC UINT32 OsLoadUserInit(LosProcessCB *processCB)
}
ret = LOS_VaddrToPaddrMmap(processCB->vmSpace, (VADDR_T)(UINTPTR)userInitTextStart, LOS_PaddrQuery(userText),
initSize, VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
- VM_MAP_REGION_FLAG_PERM_EXECUTE | VM_MAP_REGION_FLAG_PERM_USER);
+ VM_MAP_REGION_FLAG_FIXED | VM_MAP_REGION_FLAG_PERM_EXECUTE |
+ VM_MAP_REGION_FLAG_PERM_USER);
if (ret < 0) {
PRINT_ERR("Mmap user init text, data and bss failed! err : %d\n", ret);
goto ERROR;
@@ -1762,8 +1588,6 @@ STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR
OsUserCloneParentStack(childTaskCB, OsCurrTaskGet());
SCHEDULER_UNLOCK(intSave);
}
- OS_TASK_PRI_QUEUE_ENQUEUE(childProcessCB, childTaskCB);
- childTaskCB->taskStatus |= OS_TASK_STATUS_READY;
return LOS_OK;
}
@@ -1775,7 +1599,6 @@ STATIC UINT32 OsCopyParent(UINT32 flags, LosProcessCB *childProcessCB, LosProces
SCHEDULER_LOCK(intSave);
childProcessCB->priority = runProcessCB->priority;
- childProcessCB->policy = runProcessCB->policy;
if (flags & CLONE_PARENT) {
parentProcessCB = OS_PCB_FROM_PID(runProcessCB->parentProcessID);
@@ -1842,7 +1665,7 @@ STATIC UINT32 OsForkInitPCB(UINT32 flags, LosProcessCB *child, const CHAR *name,
UINT32 ret;
LosProcessCB *run = OsCurrProcessGet();
- ret = OsInitPCB(child, run->processMode, OS_PROCESS_PRIORITY_LOWEST, LOS_SCHED_RR, name);
+ ret = OsInitPCB(child, run->processMode, OS_PROCESS_PRIORITY_LOWEST, name);
if (ret != LOS_OK) {
return ret;
}
@@ -1870,13 +1693,7 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
}
}
- OS_PROCESS_PRI_QUEUE_ENQUEUE(child);
- child->processStatus &= ~OS_PROCESS_STATUS_INIT;
- child->processStatus |= OS_PROCESS_STATUS_READY;
-
-#ifdef LOSCFG_KERNEL_CPUP
- OsCpupSet(child->processID);
-#endif
+ OsSchedTaskEnQueue(OS_TCB_FROM_TID(child->threadGroupID));
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem1, group);
@@ -2001,21 +1818,26 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
OsProcessExit(OsCurrTaskGet(), (UINT32)status);
}
+LITE_OS_SEC_TEXT UINT32 LOS_GetSystemProcessMaximum(VOID)
+{
+ return g_processMaxNum;
+}
+
LITE_OS_SEC_TEXT UINT32 OsGetUserInitProcessID(VOID)
{
return g_userInitProcess;
}
-LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
-{
- return g_kernelIdleProcess;
-}
-
LITE_OS_SEC_TEXT UINT32 OsGetKernelInitProcessID(VOID)
{
return g_kernelInitProcess;
}
+LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
+{
+ return g_kernelIdleProcess;
+}
+
LITE_OS_SEC_TEXT VOID OsSetSigHandler(UINTPTR addr)
{
OsCurrProcessGet()->sigHandler = addr;
diff --git a/kernel/base/core/los_sortlink.c b/kernel/base/core/los_sortlink.c
old mode 100644
new mode 100755
index 924dc1ed..d7b3fe33
--- a/kernel/base/core/los_sortlink.c
+++ b/kernel/base/core/los_sortlink.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,6 +32,9 @@
#include "los_sortlink_pri.h"
#include "los_memory.h"
#include "los_exc.h"
+#include "los_percpu_pri.h"
+#include "los_sched_pri.h"
+#include "los_mp.h"
#ifdef __cplusplus
#if __cplusplus
@@ -39,202 +42,214 @@ extern "C" {
#endif
#endif /* __cplusplus */
-LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
+UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{
- UINT32 size;
- LOS_DL_LIST *listObject = NULL;
- UINT32 index;
-
- size = sizeof(LOS_DL_LIST) << OS_TSK_SORTLINK_LOGLEN;
- listObject = (LOS_DL_LIST *)LOS_MemAlloc(m_aucSysMem0, size); /* system resident resource */
- if (listObject == NULL) {
- return LOS_NOK;
- }
-
- (VOID)memset_s(listObject, size, 0, size);
- sortLinkHeader->sortLink = listObject;
- sortLinkHeader->cursor = 0;
- for (index = 0; index < OS_TSK_SORTLINK_LEN; index++, listObject++) {
- LOS_ListInit(listObject);
- }
+ LOS_ListInit(&sortLinkHeader->sortLink);
+ sortLinkHeader->nodeNum = 0;
return LOS_OK;
}
-LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
+STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
- SortLinkList *listSorted = NULL;
- LOS_DL_LIST *listObject = NULL;
- UINT32 sortIndex;
- UINT32 rollNum;
- UINT32 timeout;
+ LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
- /*
- * huge rollnum could cause carry to invalid high bit
- * and eventually affect the calculation of sort index.
- */
- if (sortList->idxRollNum > OS_TSK_MAX_ROLLNUM) {
- SET_SORTLIST_VALUE(sortList, OS_TSK_MAX_ROLLNUM);
- }
- timeout = sortList->idxRollNum;
- sortIndex = timeout & OS_TSK_SORTLINK_MASK;
- rollNum = (timeout >> OS_TSK_SORTLINK_LOGLEN) + 1;
- if (sortIndex == 0) {
- rollNum--;
- }
- EVALUATE_L(sortList->idxRollNum, rollNum);
- sortIndex = sortIndex + sortLinkHeader->cursor;
- sortIndex = sortIndex & OS_TSK_SORTLINK_MASK;
- EVALUATE_H(sortList->idxRollNum, sortIndex);
-
- listObject = sortLinkHeader->sortLink + sortIndex;
- if (listObject->pstNext == listObject) {
- LOS_ListTailInsert(listObject, &sortList->sortLinkNode);
- } else {
- listSorted = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- do {
- if (ROLLNUM(listSorted->idxRollNum) <= ROLLNUM(sortList->idxRollNum)) {
- ROLLNUM_SUB(sortList->idxRollNum, listSorted->idxRollNum);
- } else {
- ROLLNUM_SUB(listSorted->idxRollNum, sortList->idxRollNum);
- break;
- }
-
- listSorted = LOS_DL_LIST_ENTRY(listSorted->sortLinkNode.pstNext, SortLinkList, sortLinkNode);
- } while (&listSorted->sortLinkNode != listObject);
-
- LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode);
- }
-}
-
-LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
-{
- LOS_DL_LIST *tmp = listNode->pstPrev;
-
- /* recursive check until double link round to itself */
- while (tmp != listNode) {
- if (tmp == listHead) {
- goto FOUND;
- }
- tmp = tmp->pstPrev;
- }
-
- /* delete invalid sortlink node */
- PRINT_ERR("the node is not on this sortlink!\n");
- OsBackTrace();
-
-FOUND:
- return;
-}
-
-LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
-{
- LOS_DL_LIST *listObject = NULL;
- SortLinkList *nextSortList = NULL;
- UINT32 sortIndex;
-
- sortIndex = SORT_INDEX(sortList->idxRollNum);
- listObject = sortLinkHeader->sortLink + sortIndex;
-
- /* check if pstSortList node is on the right sortlink */
- OsCheckSortLink(listObject, &sortList->sortLinkNode);
-
- if (listObject != sortList->sortLinkNode.pstNext) {
- nextSortList = LOS_DL_LIST_ENTRY(sortList->sortLinkNode.pstNext, SortLinkList, sortLinkNode);
- ROLLNUM_ADD(nextSortList->idxRollNum, sortList->idxRollNum);
- }
- LOS_ListDelete(&sortList->sortLinkNode);
-}
-
-LITE_OS_SEC_TEXT STATIC UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex)
-{
- UINT32 expireTime;
-
- if (sortIndex > curSortIndex) {
- sortIndex = sortIndex - curSortIndex;
- } else {
- sortIndex = OS_TSK_SORTLINK_LEN - curSortIndex + sortIndex;
- }
- expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex;
- return expireTime;
-}
-
-LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
-{
- UINT16 cursor;
- UINT32 minSortIndex = OS_INVALID_VALUE;
- UINT32 minRollNum = OS_TSK_LOW_BITS_MASK;
- UINT32 expireTime = OS_INVALID_VALUE;
- LOS_DL_LIST *listObject = NULL;
- SortLinkList *listSorted = NULL;
- UINT32 i;
-
- cursor = (sortLinkHeader->cursor + 1) & OS_TSK_SORTLINK_MASK;
-
- for (i = 0; i < OS_TSK_SORTLINK_LEN; i++) {
- listObject = sortLinkHeader->sortLink + ((cursor + i) & OS_TSK_SORTLINK_MASK);
- if (!LOS_ListEmpty(listObject)) {
- listSorted = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- if (minRollNum > ROLLNUM(listSorted->idxRollNum)) {
- minRollNum = ROLLNUM(listSorted->idxRollNum);
- minSortIndex = (cursor + i) & OS_TSK_SORTLINK_MASK;
- }
- }
- }
-
- if (minRollNum != OS_TSK_LOW_BITS_MASK) {
- expireTime = OsCalcExpierTime(minRollNum, minSortIndex, sortLinkHeader->cursor);
- }
-
- return expireTime;
-}
-
-LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
-{
- SortLinkList *sortList = NULL;
- LOS_DL_LIST *listObject = NULL;
- UINT32 i;
- UINT32 sortIndex;
- UINT32 rollNum;
-
- if (sleepTicks == 0) {
+ if (LOS_ListEmpty(head)) {
+ LOS_ListHeadInsert(head, &sortList->sortLinkNode);
+ sortLinkHeader->nodeNum++;
return;
}
- sortIndex = sleepTicks & OS_TSK_SORTLINK_MASK;
- rollNum = (sleepTicks >> OS_TSK_SORTLINK_LOGLEN) + 1;
- if (sortIndex == 0) {
- rollNum--;
- sortIndex = OS_TSK_SORTLINK_LEN;
+
+ SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
+ if (listSorted->responseTime >= sortList->responseTime) {
+ LOS_ListAdd(head, &sortList->sortLinkNode);
+ sortLinkHeader->nodeNum++;
+ return;
}
- for (i = 0; i < OS_TSK_SORTLINK_LEN; i++) {
- listObject = sortLinkHeader->sortLink + ((sortLinkHeader->cursor + i) & OS_TSK_SORTLINK_MASK);
- if (listObject->pstNext != listObject) {
- sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- ROLLNUM_SUB(sortList->idxRollNum, rollNum - 1);
- if ((i > 0) && (i < sortIndex)) {
- ROLLNUM_DEC(sortList->idxRollNum);
- }
+ LOS_DL_LIST *prevNode = head->pstPrev;
+ do {
+ listSorted = LOS_DL_LIST_ENTRY(prevNode, SortLinkList, sortLinkNode);
+ if (listSorted->responseTime <= sortList->responseTime) {
+ LOS_ListAdd(prevNode, &sortList->sortLinkNode);
+ sortLinkHeader->nodeNum++;
+ break;
}
- }
- sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN;
+
+ prevNode = prevNode->pstPrev;
+ } while (1);
}
-LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
- const SortLinkList *targetSortList)
+VOID OsDeleteNodeSortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
- SortLinkList *listSorted = NULL;
- LOS_DL_LIST *listObject = NULL;
- UINT32 sortIndex = SORT_INDEX(targetSortList->idxRollNum);
- UINT32 rollNum = ROLLNUM(targetSortList->idxRollNum);
+ LOS_ListDelete(&sortList->sortLinkNode);
+ SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
+ sortLinkHeader->nodeNum--;
+}
- listObject = sortLinkHeader->sortLink + sortIndex;
+STATIC INLINE UINT64 OsGetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime)
+{
+ UINT64 expirTime = 0;
+ UINT64 nextExpirTime = 0;
+ LOS_DL_LIST *head = &sortHeader->sortLink;
+ LOS_DL_LIST *list = head->pstNext;
- listSorted = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- while (listSorted != targetSortList) {
- rollNum += ROLLNUM(listSorted->idxRollNum);
- listSorted = LOS_DL_LIST_ENTRY((listSorted->sortLinkNode).pstNext, SortLinkList, sortLinkNode);
+ if (LOS_ListEmpty(head)) {
+ return (UINT64)-1;
}
- return OsCalcExpierTime(rollNum, sortIndex, sortLinkHeader->cursor);
+
+ do {
+ SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
+ if (listSorted->responseTime <= startTime) {
+ expirTime = startTime;
+ list = list->pstNext;
+ } else {
+ nextExpirTime = listSorted->responseTime;
+ break;
+ }
+ } while (list != head);
+
+ if (expirTime == 0) {
+ return nextExpirTime;
+ }
+
+ if (nextExpirTime == 0) {
+ return expirTime;
+ }
+
+ if ((nextExpirTime - expirTime) <= OS_US_PER_TICK) {
+ return nextExpirTime;
+ }
+
+ return expirTime;
+}
+
+STATIC Percpu *OsFindIdleCpu(UINT16 *ildeCpuID)
+{
+ Percpu *idleCpu = OsPercpuGetByID(0);
+ *ildeCpuID = 0;
+
+#if (LOSCFG_KERNEL_SMP == YES)
+ UINT16 cpuID = 1;
+ UINT32 nodeNum = idleCpu->taskSortLink.nodeNum + idleCpu->swtmrSortLink.nodeNum;
+
+ do {
+ Percpu *cpu = OsPercpuGetByID(cpuID);
+ UINT32 temp = cpu->taskSortLink.nodeNum + cpu->swtmrSortLink.nodeNum;
+ if (nodeNum > temp) {
+ idleCpu = cpu;
+ *ildeCpuID = cpuID;
+ }
+
+ cpuID++;
+ } while (cpuID < LOSCFG_KERNEL_CORE_NUM);
+#endif
+
+ return idleCpu;
+}
+
+VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
+{
+ UINT32 intSave;
+ Percpu *cpu = NULL;
+ SortLinkAttribute *sortLinkHeader = NULL;
+ SPIN_LOCK_S *spinLock = NULL;
+ UINT16 idleCpu;
+
+ if (OS_SCHEDULER_ACTIVE) {
+ cpu = OsFindIdleCpu(&idleCpu);
+ } else {
+ idleCpu = ArchCurrCpuid();
+ cpu = OsPercpuGet();
+ }
+
+ if (type == OS_SORT_LINK_TASK) {
+ sortLinkHeader = &cpu->taskSortLink;
+ spinLock = &cpu->taskSortLinkSpin;
+ } else if (type == OS_SORT_LINK_SWTMR) {
+ sortLinkHeader = &cpu->swtmrSortLink;
+ spinLock = &cpu->swtmrSortLinkSpin;
+ } else {
+ LOS_Panic("Sort link type error : %u\n", type);
+ }
+
+ LOS_SpinLockSave(spinLock, &intSave);
+ SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
+ OsAddNode2SortLink(sortLinkHeader, node);
+#if (LOSCFG_KERNEL_SMP == YES)
+ node->cpuid = idleCpu;
+ if (idleCpu != ArchCurrCpuid()) {
+ LOS_MpSchedule(CPUID_TO_AFFI_MASK(idleCpu));
+ }
+#endif
+ LOS_SpinUnlockRestore(spinLock, intSave);
+}
+
+VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type)
+{
+ UINT32 intSave;
+#if (LOSCFG_KERNEL_SMP == YES)
+ Percpu *cpu = OsPercpuGetByID(node->cpuid);
+#else
+ Percpu *cpu = OsPercpuGetByID(0);
+#endif
+
+ SPIN_LOCK_S *spinLock = NULL;
+ SortLinkAttribute *sortLinkHeader = NULL;
+ if (type == OS_SORT_LINK_TASK) {
+ sortLinkHeader = &cpu->taskSortLink;
+ spinLock = &cpu->taskSortLinkSpin;
+ } else if (type == OS_SORT_LINK_SWTMR) {
+ sortLinkHeader = &cpu->swtmrSortLink;
+ spinLock = &cpu->swtmrSortLinkSpin;
+ } else {
+ LOS_Panic("Sort link type error : %u\n", type);
+ }
+
+ LOS_SpinLockSave(spinLock, &intSave);
+ if (node->responseTime != OS_SORT_LINK_INVALID_TIME) {
+ OsDeleteNodeSortLink(sortLinkHeader, node);
+ }
+ LOS_SpinUnlockRestore(spinLock, intSave);
+}
+
+UINT64 OsGetNextExpireTime(UINT64 startTime)
+{
+ UINT32 intSave;
+ Percpu *cpu = OsPercpuGet();
+ SortLinkAttribute *taskHeader = &cpu->taskSortLink;
+ SortLinkAttribute *swtmrHeader = &cpu->swtmrSortLink;
+
+ LOS_SpinLockSave(&cpu->taskSortLinkSpin, &intSave);
+ UINT64 taskExpirTime = OsGetSortLinkNextExpireTime(taskHeader, startTime);
+ LOS_SpinUnlockRestore(&cpu->taskSortLinkSpin, intSave);
+
+ LOS_SpinLockSave(&cpu->swtmrSortLinkSpin, &intSave);
+ UINT64 swtmrExpirTime = OsGetSortLinkNextExpireTime(swtmrHeader, startTime);
+ LOS_SpinUnlockRestore(&cpu->swtmrSortLinkSpin, intSave);
+
+ return (taskExpirTime < swtmrExpirTime) ? taskExpirTime : swtmrExpirTime;
+}
+
+UINT32 OsSortLinkGetTargetExpireTime(const SortLinkList *targetSortList)
+{
+ UINT64 currTimes = OsGerCurrSchedTimeCycle();
+ if (currTimes >= targetSortList->responseTime) {
+ return 0;
+ }
+
+ return (UINT32)(targetSortList->responseTime - currTimes) / OS_CYCLE_PER_TICK;
+}
+
+UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
+{
+ LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
+
+ if (LOS_ListEmpty(head)) {
+ return 0;
+ }
+
+ SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
+ return OsSortLinkGetTargetExpireTime(listSorted);
}
#ifdef __cplusplus
diff --git a/kernel/base/core/los_swtmr.c b/kernel/base/core/los_swtmr.c
old mode 100644
new mode 100755
index e091d472..74db4c99
--- a/kernel/base/core/los_swtmr.c
+++ b/kernel/base/core/los_swtmr.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,6 +34,7 @@
#include "los_queue_pri.h"
#include "los_task_pri.h"
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -142,6 +143,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
if (ret != LOS_OK) {
return LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM;
}
+
+ ret = OsSchedSwtmrScanRegister((SchedScan)OsSwtmrScan);
+ if (ret != LOS_OK) {
+ return ret;
+ }
}
ret = LOS_QueueCreate(NULL, OS_SWTMR_HANDLE_QUEUE_SIZE, &g_percpu[cpuid].swtmrHandlerQueue, 0, sizeof(CHAR *));
@@ -168,22 +174,22 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
*/
LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
{
- if ((swtmr->ucOverrun == 0) && ((swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ||
+ UINT32 ticks;
+ UINT64 currTime = OsGerCurrSchedTimeCycle();
+
+ if ((swtmr->uwOverrun == 0) && ((swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ||
(swtmr->ucMode == LOS_SWTMR_MODE_OPP) ||
(swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE))) {
- SET_SORTLIST_VALUE(&(swtmr->stSortList), swtmr->uwExpiry);
+ ticks = swtmr->uwExpiry;
} else {
- SET_SORTLIST_VALUE(&(swtmr->stSortList), swtmr->uwInterval);
+ ticks = swtmr->uwInterval;
}
-
- OsAdd2SortLink(&OsPercpuGet()->swtmrSortLink, &swtmr->stSortList);
-
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
-#if (LOSCFG_KERNEL_SMP == YES)
- swtmr->uwCpuid = ArchCurrCpuid();
-#endif
-
+ OsAdd2SortLink(&swtmr->stSortList, currTime, ticks, OS_SORT_LINK_SWTMR);
+ if (OS_SCHEDULER_ACTIVE) {
+ OsSchedUpdateExpireTime(currTime);
+ }
return;
}
@@ -199,64 +205,70 @@ STATIC INLINE VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
swtmr->uwOwnerPid = 0;
}
+STATIC INLINE VOID OsWakePendTimeSwtmr(Percpu *cpu, SWTMR_CTRL_S *swtmr)
+{
+ LOS_SpinLock(&g_swtmrSpin);
+ SwtmrHandlerItemPtr swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
+ if (swtmrHandler != NULL) {
+ swtmrHandler->handler = swtmr->pfnHandler;
+ swtmrHandler->arg = swtmr->uwArg;
+
+ if (LOS_QueueWrite(cpu->swtmrHandlerQueue, swtmrHandler, sizeof(CHAR *), LOS_NO_WAIT)) {
+ (VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandler);
+ }
+ }
+
+ if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
+ OsSwtmrDelete(swtmr);
+
+ if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
+ swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
+ } else {
+ swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
+ }
+ } else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
+ swtmr->ucState = OS_SWTMR_STATUS_CREATED;
+ } else {
+ swtmr->uwOverrun++;
+ OsSwtmrStart(swtmr);
+ }
+
+ LOS_SpinUnlock(&g_swtmrSpin);
+}
+
/*
* Description: Tick interrupt interface module of software timer
* Return : LOS_OK on success or error code on failure
*/
LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
{
- SortLinkList *sortList = NULL;
- SWTMR_CTRL_S *swtmr = NULL;
- SwtmrHandlerItemPtr swtmrHandler = NULL;
- LOS_DL_LIST *listObject = NULL;
+ Percpu *cpu = OsPercpuGet();
SortLinkAttribute* swtmrSortLink = &OsPercpuGet()->swtmrSortLink;
-
- swtmrSortLink->cursor = (swtmrSortLink->cursor + 1) & OS_TSK_SORTLINK_MASK;
- listObject = swtmrSortLink->sortLink + swtmrSortLink->cursor;
+ LOS_DL_LIST *listObject = &swtmrSortLink->sortLink;
/*
* it needs to be carefully coped with, since the swtmr is in specific sortlink
* while other cores still has the chance to process it, like stop the timer.
*/
- LOS_SpinLock(&g_swtmrSpin);
+ LOS_SpinLock(&cpu->swtmrSortLinkSpin);
if (LOS_ListEmpty(listObject)) {
- LOS_SpinUnlock(&g_swtmrSpin);
+ LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
return;
}
- sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- ROLLNUM_DEC(sortList->idxRollNum);
+ SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- while (ROLLNUM(sortList->idxRollNum) == 0) {
+ UINT64 currTime = OsGerCurrSchedTimeCycle();
+ while (sortList->responseTime <= currTime) {
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- LOS_ListDelete(&sortList->sortLinkNode);
- swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
+ OsDeleteNodeSortLink(swtmrSortLink, sortList);
- swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
- if (swtmrHandler != NULL) {
- swtmrHandler->handler = swtmr->pfnHandler;
- swtmrHandler->arg = swtmr->uwArg;
+ SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
+ LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
- if (LOS_QueueWrite(OsPercpuGet()->swtmrHandlerQueue, swtmrHandler, sizeof(CHAR *), LOS_NO_WAIT)) {
- (VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandler);
- }
- }
-
- if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
- OsSwtmrDelete(swtmr);
-
- if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
- swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
- } else {
- swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
- }
- } else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
- swtmr->ucState = OS_SWTMR_STATUS_CREATED;
- } else {
- swtmr->ucOverrun++;
- OsSwtmrStart(swtmr);
- }
+ OsWakePendTimeSwtmr(cpu, swtmr);
+ LOS_SpinLock(&cpu->swtmrSortLinkSpin);
if (LOS_ListEmpty(listObject)) {
break;
}
@@ -264,7 +276,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
}
- LOS_SpinUnlock(&g_swtmrSpin);
+ LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
}
/*
@@ -282,21 +294,14 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
*/
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
{
- SortLinkAttribute *sortLinkHeader = NULL;
-
-#if (LOSCFG_KERNEL_SMP == YES)
- /*
- * the timer is running on the specific processor,
- * we need delete the timer from that processor's sortlink.
- */
- sortLinkHeader = &g_percpu[swtmr->uwCpuid].swtmrSortLink;
-#else
- sortLinkHeader = &g_percpu[0].swtmrSortLink;
-#endif
- OsDeleteSortLink(sortLinkHeader, &swtmr->stSortList);
+ OsDeleteSortLink(&swtmr->stSortList, OS_SORT_LINK_SWTMR);
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
- swtmr->ucOverrun = 0;
+ swtmr->uwOverrun = 0;
+
+ if (OS_SCHEDULER_ACTIVE) {
+ OsSchedUpdateExpireTime(OsGerCurrSchedTimeCycle());
+ }
}
/*
@@ -305,19 +310,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
*/
LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
{
- SortLinkAttribute *sortLinkHeader = NULL;
-
-#if (LOSCFG_KERNEL_SMP == YES)
- /*
- * the timer is running on the specific processor,
- * we need search the timer from that processor's sortlink.
- */
- sortLinkHeader = &g_percpu[swtmr->uwCpuid].swtmrSortLink;
-#else
- sortLinkHeader = &g_percpu[0].swtmrSortLink;
-#endif
-
- return OsSortLinkGetTargetExpireTime(sortLinkHeader, &swtmr->stSortList);
+ return OsSortLinkGetTargetExpireTime(&swtmr->stSortList);
}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
@@ -361,12 +354,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
swtmr->uwOwnerPid = OsCurrProcessGet()->processID;
swtmr->pfnHandler = handler;
swtmr->ucMode = mode;
- swtmr->ucOverrun = 0;
+ swtmr->uwOverrun = 0;
swtmr->uwInterval = interval;
swtmr->uwExpiry = interval;
swtmr->uwArg = arg;
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
- SET_SORTLIST_VALUE(&(swtmr->stSortList), 0);
+ SET_SORTLIST_VALUE(&swtmr->stSortList, OS_SORT_LINK_INVALID_TIME);
*swtmrID = swtmr->usTimerID;
return LOS_OK;
@@ -383,10 +376,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
return LOS_ERRNO_SWTMR_ID_INVALID;
}
- SWTMR_LOCK(intSave);
swtmrCBID = swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
swtmr = g_swtmrCBArray + swtmrCBID;
+ SWTMR_LOCK(intSave);
if (swtmr->usTimerID != swtmrID) {
SWTMR_UNLOCK(intSave);
return LOS_ERRNO_SWTMR_ID_INVALID;
@@ -426,9 +419,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
return LOS_ERRNO_SWTMR_ID_INVALID;
}
- SWTMR_LOCK(intSave);
swtmrCBID = swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
swtmr = g_swtmrCBArray + swtmrCBID;
+ SWTMR_LOCK(intSave);
if (swtmr->usTimerID != swtmrID) {
SWTMR_UNLOCK(intSave);
@@ -469,9 +462,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrID, UINT32 *tick)
return LOS_ERRNO_SWTMR_TICK_PTR_NULL;
}
- SWTMR_LOCK(intSave);
swtmrCBID = swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
swtmr = g_swtmrCBArray + swtmrCBID;
+ SWTMR_LOCK(intSave);
if (swtmr->usTimerID != swtmrID) {
SWTMR_UNLOCK(intSave);
@@ -506,9 +499,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
return LOS_ERRNO_SWTMR_ID_INVALID;
}
- SWTMR_LOCK(intSave);
swtmrCBID = swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
swtmr = g_swtmrCBArray + swtmrCBID;
+ SWTMR_LOCK(intSave);
if (swtmr->usTimerID != swtmrID) {
SWTMR_UNLOCK(intSave);
diff --git a/kernel/base/core/los_sys.c b/kernel/base/core/los_sys.c
old mode 100644
new mode 100755
index 69c9aeed..afee16d5
--- a/kernel/base/core/los_sys.c
+++ b/kernel/base/core/los_sys.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,7 +30,7 @@
*/
#include "los_sys_pri.h"
-#include "los_tick_pri.h"
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -38,22 +38,11 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#define OS_MAX_VALUE 0xFFFFFFFF
+#define OS_MAX_VALUE 0xFFFFFFFFUL
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
{
- UINT32 intSave;
- UINT64 tick;
-
- /*
- * use core0's tick as system's timeline,
- * the tick needs to be atomic.
- */
- TICK_LOCK(intSave);
- tick = g_tickCount[0];
- TICK_UNLOCK(intSave);
-
- return tick;
+ return OsGerCurrSchedTimeCycle() / OS_CYCLE_PER_TICK;
}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID)
@@ -75,6 +64,17 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 tick)
return ((UINT64)tick * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
}
+LITE_OS_SEC_TEXT_MINOR UINT32 OsUS2Tick(UINT64 microsec)
+{
+ const UINT32 usPerTick = OS_SYS_US_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
+
+ UINT64 ticks = (microsec + usPerTick - 1) / usPerTick;
+ if (ticks > OS_MAX_VALUE) {
+ ticks = OS_MAX_VALUE;
+ }
+ return (UINT32)ticks;
+}
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/base/core/los_task.c b/kernel/base/core/los_task.c
old mode 100644
new mode 100755
index 8c19b900..dd6bb44e
--- a/kernel/base/core/los_task.c
+++ b/kernel/base/core/los_task.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,7 +31,6 @@
#include "los_task_pri.h"
#include "los_base_pri.h"
-#include "los_priqueue_pri.h"
#include "los_sem_pri.h"
#include "los_event_pri.h"
#include "los_mux_pri.h"
@@ -41,14 +40,9 @@
#include "los_mp.h"
#include "los_spinlock.h"
#include "los_percpu_pri.h"
+#include "los_sched_pri.h"
#include "los_process_pri.h"
-#if (LOSCFG_KERNEL_TRACE == YES)
-#include "los_trace.h"
-#endif
-#ifdef LOSCFG_KERNEL_TICKLESS
-#include "los_tickless_pri.h"
-#endif
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
@@ -89,18 +83,17 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_taskSpin);
STATIC VOID OsConsoleIDSetHook(UINT32 param1,
UINT32 param2) __attribute__((weakref("OsSetConsoleID")));
-STATIC VOID OsExcStackCheckHook(VOID) __attribute__((weakref("OsExcStackCheck")));
#define OS_CHECK_TASK_BLOCK (OS_TASK_STATUS_DELAY | \
- OS_TASK_STATUS_PEND | \
- OS_TASK_STATUS_SUSPEND)
+ OS_TASK_STATUS_PENDING | \
+ OS_TASK_STATUS_SUSPENDED)
/* temp task blocks for booting procedure */
LITE_OS_SEC_BSS STATIC LosTaskCB g_mainTask[LOSCFG_KERNEL_CORE_NUM];
-VOID* OsGetMainTask()
+LosTaskCB *OsGetMainTask()
{
- return (g_mainTask + ArchCurrCpuid());
+ return (LosTaskCB *)(g_mainTask + ArchCurrCpuid());
}
VOID OsSetMainTask()
@@ -124,56 +117,10 @@ VOID OsSetMainTask()
LITE_OS_SEC_TEXT WEAK VOID OsIdleTask(VOID)
{
while (1) {
-#ifdef LOSCFG_KERNEL_TICKLESS
- if (OsTickIrqFlagGet()) {
- OsTickIrqFlagSet(0);
- OsTicklessStart();
- }
-#endif
Wfi();
}
}
-/*
- * Description : Change task priority.
- * Input : taskCB --- task control block
- * priority --- priority
- */
-LITE_OS_SEC_TEXT_MINOR VOID OsTaskPriModify(LosTaskCB *taskCB, UINT16 priority)
-{
- LosProcessCB *processCB = NULL;
-
- LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
-
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- processCB = OS_PCB_FROM_PID(taskCB->processID);
- OS_TASK_PRI_QUEUE_DEQUEUE(processCB, taskCB);
- taskCB->priority = priority;
- OS_TASK_PRI_QUEUE_ENQUEUE(processCB, taskCB);
- } else {
- taskCB->priority = priority;
- }
-}
-
-LITE_OS_SEC_TEXT STATIC INLINE VOID OsAdd2TimerList(LosTaskCB *taskCB, UINT32 timeOut)
-{
- SET_SORTLIST_VALUE(&taskCB->sortList, timeOut);
- OsAdd2SortLink(&OsPercpuGet()->taskSortLink, &taskCB->sortList);
-#if (LOSCFG_KERNEL_SMP == YES)
- taskCB->timerCpu = ArchCurrCpuid();
-#endif
-}
-
-LITE_OS_SEC_TEXT STATIC INLINE VOID OsTimerListDelete(LosTaskCB *taskCB)
-{
-#if (LOSCFG_KERNEL_SMP == YES)
- SortLinkAttribute *sortLinkHeader = &g_percpu[taskCB->timerCpu].taskSortLink;
-#else
- SortLinkAttribute *sortLinkHeader = &g_percpu[0].taskSortLink;
-#endif
- OsDeleteSortLink(sortLinkHeader, &taskCB->sortList);
-}
-
STATIC INLINE VOID OsInsertTCBToFreeList(LosTaskCB *taskCB)
{
UINT32 taskID = taskCB->taskID;
@@ -191,7 +138,8 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB)
if (taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
if (!LOS_ListEmpty(&taskCB->joinList)) {
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
- OsTaskWake(resumedTask);
+ OsTaskWakeClearPendMask(resumedTask);
+ OsSchedTaskWake(resumedTask);
}
taskCB->taskStatus &= ~OS_TASK_FLAG_PTHREAD_JOIN;
}
@@ -210,7 +158,8 @@ LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB)
}
if ((taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) && LOS_ListEmpty(&taskCB->joinList)) {
- return OsTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_JOIN, taskCB->taskID, LOS_WAIT_FOREVER);
+ return OsSchedTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER, TRUE);
} else if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) {
return LOS_OK;
}
@@ -239,78 +188,9 @@ LITE_OS_SEC_TEXT UINT32 OsTaskSetDeatchUnsafe(LosTaskCB *taskCB)
return LOS_EINVAL;
}
-LITE_OS_SEC_TEXT VOID OsTaskScan(VOID)
-{
- SortLinkList *sortList = NULL;
- LosTaskCB *taskCB = NULL;
- BOOL needSchedule = FALSE;
- UINT16 tempStatus;
- LOS_DL_LIST *listObject = NULL;
- SortLinkAttribute *taskSortLink = NULL;
-
- taskSortLink = &OsPercpuGet()->taskSortLink;
- taskSortLink->cursor = (taskSortLink->cursor + 1) & OS_TSK_SORTLINK_MASK;
- listObject = taskSortLink->sortLink + taskSortLink->cursor;
-
- /*
- * When task is pended with timeout, the task block is on the timeout sortlink
- * (per cpu) and ipc(mutex,sem and etc.)'s block at the same time, it can be waken
- * up by either timeout or corresponding ipc it's waiting.
- *
- * Now synchronize sortlink preocedure is used, therefore the whole task scan needs
- * to be protected, preventing another core from doing sortlink deletion at same time.
- */
- LOS_SpinLock(&g_taskSpin);
-
- if (LOS_ListEmpty(listObject)) {
- LOS_SpinUnlock(&g_taskSpin);
- return;
- }
- sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- ROLLNUM_DEC(sortList->idxRollNum);
-
- while (ROLLNUM(sortList->idxRollNum) == 0) {
- LOS_ListDelete(&sortList->sortLinkNode);
- taskCB = LOS_DL_LIST_ENTRY(sortList, LosTaskCB, sortList);
- taskCB->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
- tempStatus = taskCB->taskStatus;
- if (tempStatus & OS_TASK_STATUS_PEND) {
- taskCB->taskStatus &= ~OS_TASK_STATUS_PEND;
-#if (LOSCFG_KERNEL_LITEIPC == YES)
- taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
-#endif
- taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
- LOS_ListDelete(&taskCB->pendList);
- taskCB->taskSem = NULL;
- taskCB->taskMux = NULL;
- } else {
- taskCB->taskStatus &= ~OS_TASK_STATUS_DELAY;
- }
-
- if (!(tempStatus & OS_TASK_STATUS_SUSPEND)) {
- OS_TASK_SCHED_QUEUE_ENQUEUE(taskCB, OS_PROCESS_STATUS_PEND);
- needSchedule = TRUE;
- }
-
- if (LOS_ListEmpty(listObject)) {
- break;
- }
-
- sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
- }
-
- LOS_SpinUnlock(&g_taskSpin);
-
- if (needSchedule != FALSE) {
- LOS_MpSchedule(OS_MP_CPU_ALL);
- LOS_Schedule();
- }
-}
-
LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
{
UINT32 index;
- UINT32 ret;
UINT32 size;
g_taskMaxNum = LOSCFG_BASE_CORE_TSK_LIMIT;
@@ -333,19 +213,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList);
}
- ret = OsPriQueueInit();
- if (ret != LOS_OK) {
- return LOS_ERRNO_TSK_NO_MEMORY;
- }
+#if (LOSCFG_KERNEL_TRACE == YES)
+ LOS_TraceReg(LOS_TRACE_TASK, OsTaskTrace, LOS_TRACE_TASK_NAME, LOS_TRACE_ENABLE);
+#endif
- /* init sortlink for each core */
- for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
- ret = OsSortLinkInit(&g_percpu[index].taskSortLink);
- if (ret != LOS_OK) {
- return LOS_ERRNO_TSK_NO_MEMORY;
- }
- }
- return LOS_OK;
+ return OsSchedInit();
}
UINT32 OsGetIdleTaskId(VOID)
@@ -366,12 +238,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE;
taskInitParam.pcName = "Idle";
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
- taskInitParam.uwResved = OS_TASK_FLAG_IDLEFLAG;
+ taskInitParam.processID = OsGetIdleProcessID();
#if (LOSCFG_KERNEL_SMP == YES)
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
- ret = LOS_TaskCreate(idleTaskID, &taskInitParam);
- OS_TCB_FROM_TID(*idleTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
+ ret = LOS_TaskCreateOnly(idleTaskID, &taskInitParam);
+ LosTaskCB *idleTask = OS_TCB_FROM_TID(*idleTaskID);
+ idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
+ OsSchedSetIdleTaskSchedPartam(idleTask);
return ret;
}
@@ -390,39 +264,6 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
return runTask->taskID;
}
-#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
-LITE_OS_SEC_TEXT STATIC VOID OsTaskStackCheck(LosTaskCB *oldTask, LosTaskCB *newTask)
-{
- if (!OS_STACK_MAGIC_CHECK(oldTask->topOfStack)) {
- LOS_Panic("CURRENT task ID: %s:%d stack overflow!\n", oldTask->taskName, oldTask->taskID);
- }
-
- if (((UINTPTR)(newTask->stackPointer) <= newTask->topOfStack) ||
- ((UINTPTR)(newTask->stackPointer) > (newTask->topOfStack + newTask->stackSize))) {
- LOS_Panic("HIGHEST task ID: %s:%u SP error! StackPointer: %p TopOfStack: %p\n",
- newTask->taskName, newTask->taskID, newTask->stackPointer, newTask->topOfStack);
- }
-
- if (OsExcStackCheckHook != NULL) {
- OsExcStackCheckHook();
- }
-}
-
-#endif
-
-LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskSwitchCheck(LosTaskCB *oldTask, LosTaskCB *newTask)
-{
-#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
- OsTaskStackCheck(oldTask, newTask);
-#endif /* LOSCFG_BASE_CORE_TSK_MONITOR == YES */
-
-#if (LOSCFG_KERNEL_TRACE == YES)
- LOS_Trace(LOS_TRACE_SWITCH, newTask->taskID, oldTask->taskID);
-#endif
-
- return LOS_OK;
-}
-
LITE_OS_SEC_TEXT VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status)
{
UINT32 intSave;
@@ -445,7 +286,10 @@ LITE_OS_SEC_TEXT VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status)
}
if (taskCB->taskStatus & OS_TASK_FLAG_DETACHED) {
- (VOID)OsTaskDeleteUnsafe(taskCB, status, intSave);
+ UINT32 ret = OsTaskDeleteUnsafe(taskCB, status, intSave);
+ if (ret != LOS_OK) {
+ PRINT_ERR("Task exit delete failed! ERROR : 0x%x\n", ret);
+ }
}
OsTaskJoinPostUnsafe(taskCB);
@@ -710,6 +554,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
taskCB->futex.index = OS_INVALID_VALUE;
LOS_ListInit(&taskCB->lockList);
+ SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
}
STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
@@ -846,14 +691,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in
return LOS_ERRNO_TSK_YIELD_IN_INT;
}
- if (initParam->uwResved & OS_TASK_FLAG_IDLEFLAG) {
- initParam->processID = OsGetIdleProcessID();
- } else if (OsProcessIsUserMode(OsCurrProcessGet())) {
+ if (OsProcessIsUserMode(OsCurrProcessGet())) {
initParam->processID = OsGetKernelInitProcessID();
} else {
initParam->processID = OsCurrProcessGet()->processID;
}
- initParam->uwResved &= ~OS_TASK_FLAG_IDLEFLAG;
initParam->uwResved &= ~OS_TASK_FLAG_PTHREAD_JOIN;
if (initParam->uwResved & LOS_TASK_STATUS_DETACHED) {
initParam->uwResved = OS_TASK_FLAG_DETACHED;
@@ -866,8 +708,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in
taskCB = OS_TCB_FROM_TID(*taskID);
SCHEDULER_LOCK(intSave);
- taskCB->taskStatus &= ~OS_TASK_STATUS_INIT;
- OS_TASK_SCHED_QUEUE_ENQUEUE(taskCB, 0);
+ OsSchedTaskEnQueue(taskCB);
SCHEDULER_UNLOCK(intSave);
/* in case created task not running on this core,
@@ -883,7 +724,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
{
UINT32 intSave;
- UINT16 tempStatus;
UINT32 errRet;
LosTaskCB *taskCB = NULL;
BOOL needSched = FALSE;
@@ -898,27 +738,25 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
/* clear pending signal */
taskCB->signal &= ~SIGNAL_SUSPEND;
- tempStatus = taskCB->taskStatus;
- if (tempStatus & OS_TASK_STATUS_UNUSED) {
+ if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
errRet = LOS_ERRNO_TSK_NOT_CREATED;
OS_GOTO_ERREND();
- } else if (!(tempStatus & OS_TASK_STATUS_SUSPEND)) {
+ } else if (!(taskCB->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
errRet = LOS_ERRNO_TSK_NOT_SUSPENDED;
OS_GOTO_ERREND();
}
- taskCB->taskStatus &= ~OS_TASK_STATUS_SUSPEND;
+ taskCB->taskStatus &= ~OS_TASK_STATUS_SUSPENDED;
if (!(taskCB->taskStatus & OS_CHECK_TASK_BLOCK)) {
- OS_TASK_SCHED_QUEUE_ENQUEUE(taskCB, OS_PROCESS_STATUS_PEND);
+ OsSchedTaskEnQueue(taskCB);
if (OS_SCHEDULER_ACTIVE) {
needSched = TRUE;
}
}
-
SCHEDULER_UNLOCK(intSave);
+ LOS_MpSchedule(OS_MP_CPU_ALL);
if (needSched) {
- LOS_MpSchedule(OS_MP_CPU_ALL);
LOS_Schedule();
}
@@ -971,14 +809,13 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
{
UINT32 errRet;
UINT16 tempStatus;
- LosTaskCB *runTask = NULL;
tempStatus = taskCB->taskStatus;
if (tempStatus & OS_TASK_STATUS_UNUSED) {
return LOS_ERRNO_TSK_NOT_CREATED;
}
- if (tempStatus & OS_TASK_STATUS_SUSPEND) {
+ if (tempStatus & OS_TASK_STATUS_SUSPENDED) {
return LOS_ERRNO_TSK_ALREADY_SUSPENDED;
}
@@ -988,13 +825,12 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
}
if (tempStatus & OS_TASK_STATUS_READY) {
- OS_TASK_SCHED_QUEUE_DEQUEUE(taskCB, OS_PROCESS_STATUS_PEND);
+ OsSchedTaskDeQueue(taskCB);
}
- taskCB->taskStatus |= OS_TASK_STATUS_SUSPEND;
+ taskCB->taskStatus |= OS_TASK_STATUS_SUSPENDED;
- runTask = OsCurrTaskGet();
- if (taskCB == runTask) {
+ if (taskCB == OsCurrTaskGet()) {
OsSchedResched();
}
@@ -1117,23 +953,19 @@ STATIC BOOL OsRunTaskToDeleteCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
STATIC VOID OsTaskDeleteInactive(LosProcessCB *processCB, LosTaskCB *taskCB)
{
LosMux *mux = (LosMux *)taskCB->taskMux;
+ UINT16 taskStatus = taskCB->taskStatus;
- LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_RUNNING));
+ LOS_ASSERT(!(taskStatus & OS_TASK_STATUS_RUNNING));
OsTaskReleaseHoldLock(processCB, taskCB);
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- OS_TASK_SCHED_QUEUE_DEQUEUE(taskCB, 0);
- } else if (taskCB->taskStatus & OS_TASK_STATUS_PEND) {
- LOS_ListDelete(&taskCB->pendList);
+ OsSchedTaskExit(taskCB);
+ if (taskStatus & OS_TASK_STATUS_PENDING) {
if (LOS_MuxIsValid(mux) == TRUE) {
OsMuxBitmapRestore(mux, taskCB, (LosTaskCB *)mux->owner);
}
}
- if (taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)) {
- OsTimerListDelete(taskCB);
- }
OsTaskStatusUnusedSet(taskCB);
LOS_ListDelete(&taskCB->threadList);
@@ -1209,6 +1041,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
OsBackTrace();
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
}
+
processCB = OS_PCB_FROM_PID(taskCB->processID);
if (processCB->threadNumber == 1) {
if (processCB == OsCurrProcessGet()) {
@@ -1250,15 +1083,12 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
if (tick == 0) {
return LOS_TaskYield();
- } else {
- SCHEDULER_LOCK(intSave);
- OS_TASK_SCHED_QUEUE_DEQUEUE(runTask, OS_PROCESS_STATUS_PEND);
- OsAdd2TimerList(runTask, tick);
- runTask->taskStatus |= OS_TASK_STATUS_DELAY;
- OsSchedResched();
- SCHEDULER_UNLOCK(intSave);
}
+ SCHEDULER_LOCK(intSave);
+ OsSchedDelay(runTask, tick);
+ SCHEDULER_UNLOCK(intSave);
+
return LOS_OK;
}
@@ -1286,11 +1116,8 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskID)
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
{
- BOOL isReady = FALSE;
UINT32 intSave;
LosTaskCB *taskCB = NULL;
- UINT16 tempStatus;
- LosProcessCB *processCB = NULL;
if (taskPrio > OS_TASK_PRIORITY_LOWEST) {
return LOS_ERRNO_TSK_PRIOR_ERROR;
@@ -1306,30 +1133,16 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
}
SCHEDULER_LOCK(intSave);
- tempStatus = taskCB->taskStatus;
- if (tempStatus & OS_TASK_STATUS_UNUSED) {
+ if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
SCHEDULER_UNLOCK(intSave);
return LOS_ERRNO_TSK_NOT_CREATED;
}
- /* delete the task and insert with right priority into ready queue */
- isReady = tempStatus & OS_TASK_STATUS_READY;
- if (isReady) {
- processCB = OS_PCB_FROM_PID(taskCB->processID);
- OS_TASK_PRI_QUEUE_DEQUEUE(processCB, taskCB);
- taskCB->priority = taskPrio;
- OS_TASK_PRI_QUEUE_ENQUEUE(processCB, taskCB);
- } else {
- taskCB->priority = taskPrio;
- if (tempStatus & OS_TASK_STATUS_RUNNING) {
- isReady = TRUE;
- }
- }
-
+ BOOL isReady = OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, taskPrio);
SCHEDULER_UNLOCK(intSave);
- /* delete the task and insert with right priority into ready queue */
- if (isReady) {
- LOS_MpSchedule(OS_MP_CPU_ALL);
+
+ LOS_MpSchedule(OS_MP_CPU_ALL);
+ if (isReady && OS_SCHEDULER_ACTIVE) {
LOS_Schedule();
}
return LOS_OK;
@@ -1340,63 +1153,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio)
return LOS_TaskPriSet(OsCurrTaskGet()->taskID, taskPrio);
}
-/*
- * Description : pend a task in list
- * Input : list --- wait task list
- * taskStatus --- task status
- * timeOut --- Expiry time
- * Return : LOS_OK on success or LOS_NOK on failure
- */
-UINT32 OsTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched)
-{
- LosTaskCB *runTask = NULL;
- LOS_DL_LIST *pendObj = NULL;
-
- runTask = OsCurrTaskGet();
- OS_TASK_SCHED_QUEUE_DEQUEUE(runTask, OS_PROCESS_STATUS_PEND);
- pendObj = &runTask->pendList;
- runTask->taskStatus |= OS_TASK_STATUS_PEND;
- LOS_ListTailInsert(list, pendObj);
- if (timeout != LOS_WAIT_FOREVER) {
- runTask->taskStatus |= OS_TASK_STATUS_PEND_TIME;
- OsAdd2TimerList(runTask, timeout);
- }
-
- if (needSched == TRUE) {
- OsSchedResched();
- if (runTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
- runTask->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
- return LOS_ERRNO_TSK_TIMEOUT;
- }
- }
- return LOS_OK;
-}
-
-/*
- * Description : delete the task from pendlist and also add to the priqueue
- * Input : resumedTask --- resumed task
- * taskStatus --- task status
- */
-VOID OsTaskWake(LosTaskCB *resumedTask)
-{
- LOS_ListDelete(&resumedTask->pendList);
- resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND;
-
- if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
- OsTimerListDelete(resumedTask);
- resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
- }
- if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPEND)) {
- OS_TASK_SCHED_QUEUE_ENQUEUE(resumedTask, OS_PROCESS_STATUS_PEND);
- }
-}
-
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
{
- UINT32 tskCount;
UINT32 intSave;
- LosTaskCB *runTask = NULL;
- LosProcessCB *runProcess = NULL;
if (OS_INT_ACTIVE) {
return LOS_ERRNO_TSK_YIELD_IN_INT;
@@ -1406,25 +1165,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
return LOS_ERRNO_TSK_YIELD_IN_LOCK;
}
- runTask = OsCurrTaskGet();
+ LosTaskCB *runTask = OsCurrTaskGet();
if (OS_TID_CHECK_INVALID(runTask->taskID)) {
return LOS_ERRNO_TSK_ID_INVALID;
}
SCHEDULER_LOCK(intSave);
-
/* reset timeslice of yeilded task */
- runTask->timeSlice = 0;
- runProcess = OS_PCB_FROM_PID(runTask->processID);
- tskCount = OS_TASK_PRI_QUEUE_SIZE(runProcess, runTask);
- if (tskCount > 0) {
- OS_TASK_PRI_QUEUE_ENQUEUE(runProcess, runTask);
- runTask->taskStatus |= OS_TASK_STATUS_READY;
- } else {
- SCHEDULER_UNLOCK(intSave);
- return LOS_OK;
- }
- OsSchedResched();
+ OsSchedYield();
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
@@ -1432,36 +1180,15 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID)
{
UINT32 intSave;
- UINT32 *losTaskLock = NULL;
intSave = LOS_IntLock();
- losTaskLock = &OsPercpuGet()->taskLockCnt;
- (*losTaskLock)++;
+ OsCpuSchedLock(OsPercpuGet());
LOS_IntRestore(intSave);
}
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID)
{
- UINT32 intSave;
- UINT32 *losTaskLock = NULL;
- Percpu *percpu = NULL;
-
- intSave = LOS_IntLock();
-
- percpu = OsPercpuGet();
- losTaskLock = &OsPercpuGet()->taskLockCnt;
- if (*losTaskLock > 0) {
- (*losTaskLock)--;
- if ((*losTaskLock == 0) && (percpu->schedFlag == INT_PEND_RESCH) &&
- OS_SCHEDULER_ACTIVE) {
- percpu->schedFlag = INT_NO_RESCH;
- LOS_IntRestore(intSave);
- LOS_Schedule();
- return;
- }
- }
-
- LOS_IntRestore(intSave);
+ OsCpuSchedUnlock(OsPercpuGet(), LOS_IntLock());
}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo)
@@ -1496,7 +1223,6 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
taskInfo->uwTopOfStack = taskCB->topOfStack;
taskInfo->uwEventMask = taskCB->eventMask;
taskInfo->taskEvent = taskCB->taskEvent;
- taskInfo->pTaskSem = taskCB->taskSem;
taskInfo->pTaskMux = taskCB->taskMux;
taskInfo->uwTaskID = taskID;
@@ -1515,12 +1241,30 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
return LOS_OK;
}
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask)
+LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask)
{
#if (LOSCFG_KERNEL_SMP == YES)
+ LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
+
+ taskCB->cpuAffiMask = newCpuAffiMask;
+ *oldCpuAffiMask = CPUID_TO_AFFI_MASK(taskCB->currCpu);
+ if (!((*oldCpuAffiMask) & newCpuAffiMask)) {
+ taskCB->signal = SIGNAL_AFFI;
+ return TRUE;
+ }
+#else
+ (VOID)taskID;
+ (VOID)newCpuAffiMask;
+ (VOID)oldCpuAffiMask;
+#endif /* LOSCFG_KERNEL_SMP */
+ return FALSE;
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask)
+{
LosTaskCB *taskCB = NULL;
- UINT32 intSave;
BOOL needSched = FALSE;
+ UINT32 intSave;
UINT16 currCpuMask;
if (OS_TID_CHECK_INVALID(taskID)) {
@@ -1537,22 +1281,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMa
SCHEDULER_UNLOCK(intSave);
return LOS_ERRNO_TSK_NOT_CREATED;
}
+ needSched = OsTaskCpuAffiSetUnsafe(taskID, cpuAffiMask, &currCpuMask);
- taskCB->cpuAffiMask = cpuAffiMask;
- currCpuMask = CPUID_TO_AFFI_MASK(taskCB->currCpu);
- if (!(currCpuMask & cpuAffiMask)) {
- needSched = TRUE;
- taskCB->signal = SIGNAL_AFFI;
- }
SCHEDULER_UNLOCK(intSave);
-
if (needSched && OS_SCHEDULER_ACTIVE) {
LOS_MpSchedule(currCpuMask);
LOS_Schedule();
}
-#endif
- (VOID)taskID;
- (VOID)cpuAffiMask;
+
return LOS_OK;
}
@@ -1588,10 +1324,8 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
/*
* Description : Process pending signals tagged by others cores
*/
-LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskProcSignal(VOID)
+LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
{
- Percpu *percpu = NULL;
- LosTaskCB *runTask = NULL;
UINT32 intSave, ret;
/*
@@ -1599,9 +1333,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskProcSignal(VOID)
* while this task is always running when others cores see it,
* so it keeps recieving signals while follow code excuting.
*/
- runTask = OsCurrTaskGet();
+ LosTaskCB *runTask = OsCurrTaskGet();
if (runTask->signal == SIGNAL_NONE) {
- goto EXIT;
+ return;
}
if (runTask->signal & SIGNAL_KILL) {
@@ -1628,16 +1362,6 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskProcSignal(VOID)
LOS_MpSchedule((UINT32)runTask->cpuAffiMask);
#endif
}
-
-EXIT:
- /* check if needs to schedule */
- percpu = OsPercpuGet();
- if (OsPreemptable() && (percpu->schedFlag == INT_PEND_RESCH)) {
- percpu->schedFlag = INT_NO_RESCH;
- return INT_PEND_RESCH;
- }
-
- return INT_NO_RESCH;
}
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
@@ -1814,13 +1538,11 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsCreateUserTaskParamCheck(UINT32 processID,
return OS_INVALID_VALUE;
}
- if ((!userParam->userMapSize) || !LOS_IsUserAddressRange(userParam->userMapBase, userParam->userMapSize)) {
+ if (userParam->userMapBase && !LOS_IsUserAddressRange(userParam->userMapBase, userParam->userMapSize)) {
return OS_INVALID_VALUE;
}
- if (userParam->userArea &&
- ((userParam->userSP <= userParam->userMapBase) ||
- (userParam->userSP > (userParam->userMapBase + userParam->userMapSize)))) {
+ if (!LOS_IsUserAddress(userParam->userSP)) {
return OS_INVALID_VALUE;
}
@@ -1889,51 +1611,10 @@ LOS_ERREND:
return policy;
}
-LITE_OS_SEC_TEXT INT32 OsTaskSchedulerSetUnsafe(LosTaskCB *taskCB, UINT16 policy, UINT16 priority,
- BOOL policyFlag, UINT32 intSave)
-{
- BOOL needSched = TRUE;
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- OS_TASK_PRI_QUEUE_DEQUEUE(OS_PCB_FROM_PID(taskCB->processID), taskCB);
- }
-
- if (policyFlag == TRUE) {
- if (policy == LOS_SCHED_FIFO) {
- taskCB->timeSlice = 0;
- }
- taskCB->policy = policy;
- }
- taskCB->priority = priority;
-
- if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
- taskCB->taskStatus &= ~OS_TASK_STATUS_INIT;
- taskCB->taskStatus |= OS_TASK_STATUS_READY;
- }
-
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
- OS_TASK_SCHED_QUEUE_ENQUEUE(taskCB, OS_PROCESS_STATUS_INIT);
- } else if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
- goto SCHEDULE;
- } else {
- needSched = FALSE;
- }
-
-SCHEDULE:
- SCHEDULER_UNLOCK(intSave);
-
- LOS_MpSchedule(OS_MP_CPU_ALL);
- if (OS_SCHEDULER_ACTIVE && (needSched == TRUE)) {
- LOS_Schedule();
- }
-
- return LOS_OK;
-}
-
LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
{
UINT32 intSave;
- LosTaskCB *taskCB = NULL;
+ BOOL needSched = FALSE;
if (OS_TID_CHECK_INVALID(taskID)) {
return LOS_ESRCH;
@@ -1948,8 +1629,20 @@ LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16
}
SCHEDULER_LOCK(intSave);
- taskCB = OS_TCB_FROM_TID(taskID);
- return OsTaskSchedulerSetUnsafe(taskCB, policy, priority, TRUE, intSave);
+ needSched = OsSchedModifyTaskSchedParam(OS_TCB_FROM_TID(taskID), policy, priority);
+ SCHEDULER_UNLOCK(intSave);
+
+ LOS_MpSchedule(OS_MP_CPU_ALL);
+ if (needSched && OS_SCHEDULER_ACTIVE) {
+ LOS_Schedule();
+ }
+
+ return LOS_OK;
+}
+
+LITE_OS_SEC_TEXT UINT32 LOS_GetSystemTaskMaximum(VOID)
+{
+ return g_taskMaxNum;
}
LITE_OS_SEC_TEXT VOID OsWriteResourceEvent(UINT32 events)
diff --git a/kernel/base/core/los_tick.c b/kernel/base/core/los_tick.c
old mode 100644
new mode 100755
index 11cfdd3e..23f1f5ec
--- a/kernel/base/core/los_tick.c
+++ b/kernel/base/core/los_tick.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,11 +31,7 @@
#include "los_tick_pri.h"
#include "los_swtmr_pri.h"
-#include "los_task_pri.h"
-#include "los_timeslice_pri.h"
-#ifdef LOSCFG_KERNEL_TICKLESS
-#include "los_tickless_pri.h"
-#endif
+#include "los_sched_pri.h"
#ifdef LOSCFG_KERNEL_VDSO
#include "los_vdso.h"
#endif
@@ -46,7 +42,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-LITE_OS_SEC_BSS volatile UINT64 g_tickCount[LOSCFG_KERNEL_CORE_NUM] = {0};
LITE_OS_SEC_DATA_INIT UINT32 g_sysClock;
LITE_OS_SEC_DATA_INIT UINT32 g_tickPerSecond;
LITE_OS_SEC_BSS DOUBLE g_cycle2NsScale;
@@ -59,31 +54,19 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_tickSpin);
*/
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
{
- UINT32 intSave;
-
- TICK_LOCK(intSave);
- g_tickCount[ArchCurrCpuid()]++;
- TICK_UNLOCK(intSave);
+#ifdef LOSCFG_SCHED_TICK_DEBUG
+ OsSchedDebugRecordData();
+#endif
#ifdef LOSCFG_KERNEL_VDSO
OsUpdateVdsoTimeval();
#endif
-#ifdef LOSCFG_KERNEL_TICKLESS
- OsTickIrqFlagSet(OsTicklessFlagGet());
-#endif
-
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
HalClockIrqClear(); /* diff from every platform */
#endif
- OsTimesliceCheck();
-
- OsTaskScan(); /* task timeout scan */
-
-#if (LOSCFG_BASE_CORE_SWTMR == YES)
- OsSwtmrScan();
-#endif
+ OsSchedTick();
}
#ifdef __cplusplus
diff --git a/kernel/base/include/los_base_pri.h b/kernel/base/include/los_base_pri.h
index 0abb485a..24719cc7 100644
--- a/kernel/base/include/los_base_pri.h
+++ b/kernel/base/include/los_base_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_binarytree_pri.h b/kernel/base/include/los_binarytree_pri.h
index 72a9df4a..c442f605 100644
--- a/kernel/base/include/los_binarytree_pri.h
+++ b/kernel/base/include/los_binarytree_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_err_pri.h b/kernel/base/include/los_err_pri.h
index 6645645d..40a667ae 100644
--- a/kernel/base/include/los_err_pri.h
+++ b/kernel/base/include/los_err_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_event_pri.h b/kernel/base/include/los_event_pri.h
old mode 100644
new mode 100755
index 519a4d76..22d20c9e
--- a/kernel/base/include/los_event_pri.h
+++ b/kernel/base/include/los_event_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_futex_pri.h b/kernel/base/include/los_futex_pri.h
old mode 100644
new mode 100755
index f2d81831..7671115b
--- a/kernel/base/include/los_futex_pri.h
+++ b/kernel/base/include/los_futex_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -46,12 +46,12 @@
#define FUTEX_MASK 0x3U
typedef struct {
- UINTPTR key;
- UINT32 index;
- UINT32 pid;
- LOS_DL_LIST pendList;
- LOS_DL_LIST queueList;
- LOS_DL_LIST futexList;
+ UINTPTR key; /* private:uvaddr shared:paddr */
+ UINT32 index; /* hash bucket index */
+ UINT32 pid; /* private:process id shared:OS_INVALID(-1) */
+ LOS_DL_LIST pendList; /* point to pendList in TCB struct */
+ LOS_DL_LIST queueList; /* thread list blocked by this lock */
+ LOS_DL_LIST futexList; /* point to the next FutexNode */
} FutexNode;
extern UINT32 OsFutexInit(VOID);
diff --git a/kernel/base/include/los_heap_pri.h b/kernel/base/include/los_heap_pri.h
deleted file mode 100644
index 818b8f62..00000000
--- a/kernel/base/include/los_heap_pri.h
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * @defgroup los_heap Heap
- * @ingroup kernel
- */
-
-#ifndef _LOS_HEAP_PRI_H
-#define _LOS_HEAP_PRI_H
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#define ALIGNE(sz) (((sz) + HEAP_ALIGN - 1) & (~(HEAP_ALIGN - 1)))
-#define OS_MEM_ALIGN(value, align) (((UINT32)(UINTPTR)(value) + (UINT32)((align) - 1)) & \
- (~(UINT32)((align) - 1)))
-#define OS_MEM_ALIGN_FLAG 0x80000000
-#define OS_MEM_SET_ALIGN_FLAG(align) ((align) = ((align) | OS_MEM_ALIGN_FLAG))
-#define OS_MEM_GET_ALIGN_FLAG(align) ((align) & OS_MEM_ALIGN_FLAG)
-#define OS_MEM_GET_ALIGN_GAPSIZE(align) ((align) & (~OS_MEM_ALIGN_FLAG))
-
-typedef struct tagLosHeapStatus {
- UINT32 totalUsedSize;
- UINT32 totalFreeSize;
- UINT32 maxFreeNodeSize;
- UINT32 usedNodeNum;
- UINT32 freeNodeNum;
-} LosHeapStatus;
-
-struct LosHeapNode {
- struct LosHeapNode* prev;
- UINT32 size : 30;
- UINT32 used : 1;
- UINT32 align : 1;
- UINT8 data[0];
-};
-
-struct LosHeapManager {
- struct LosHeapNode *head;
- struct LosHeapNode *tail;
- UINT32 size;
-#if (LOSCFG_MEM_MUL_POOL == YES)
- VOID *nextPool;
-#endif
-};
-
-/**
- * @ingroup los_heap
- * @brief Look up the next memory node according to one memory node in the memory block list.
- *
- * @par Description:
- * This API is used to look up the next memory node according to one memory node in the memory block list.
- * @attention
- *
- * @param heapMan [IN] Type #LosHeapManager * Pointer to the manager,to distinguish heap.
- * @param node [IN] Type #LosHeapNode * Size of memory in bytes to allocate.
- *
- * @retval LosHeapNode * Pointer to next memory node.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern struct LosHeapNode* OsHeapPrvGetNext(struct LosHeapManager *heapMan, struct LosHeapNode* node);
-
-/**
- * @ingroup los_heap
- * @brief Obtain the heap information.
- *
- * @par Description:
- * This API is used to obtain the heap information.
- * @attention
- *
- * @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
- *
- * @retval None.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID OsAlarmHeapInfo(VOID *pool);
-
-/**
- * @ingroup los_heap
- * @brief Obtain the heap status.
- *
- * @par Description:
- * This API is used to obtain the heap status.
- * @attention
- *
- * @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
- * @param status [OUT] Type #LosHeapStatus * Heap status.
- *
- * @retval UINT32 Get status result.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status);
-
-/**
- * @ingroup los_heap
- * @brief Get the max free block size.
- *
- * @par Description:
- * This API is used to Get the max free block size.
- * @attention
- *
- * @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
- *
- * @retval UINT32 Max free block size.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 OsHeapGetMaxFreeBlkSize(VOID *pool);
-
-/**
- * @ingroup OsHeapInit
- * @brief Initialize the heap memory pool.
- *
- * @par Description:
- * This API is used to initialize the heap memory and get the begin address and
- * size of heap memory,then initialize LosHeapManager .
- * @attention
- *
- * @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
- * @param size [IN] Type #UINT32 Size of memory in bytes to initialized.
- *
- * @retval BOOL Get status return.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern BOOL OsHeapInit(VOID *pool, UINT32 size);
-
-/**
- * @ingroup OsHeapAlloc
- * @brief Alloc memory block from the heap.
- *
- * @par Description:
- * This API is used to alloc memory block from the heap memory pool.
- * @attention
- *
- * @param pool [IN] Type #VOID * Pointer to the manager,to distinguish heap
- * @param size [IN] Type #UINT32 Size of memory in bytes to alloc.
- *
- * @retval VOID * Get the address of the memory we alloced or NULL.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID* OsHeapAlloc(VOID *pool, UINT32 size);
-
-/**
- * @ingroup OsHeapAllocAlign
- * @brief Alloc memory block from the heap with align.
- *
- * @par Description:
- * This API is used to alloc memory block from the heap memory pool with align.
- * @attention
- *
- * @param pool [IN] Type #VOID * Pointer to the manager,to distinguish heap
- * @param size [IN] Type #UINT32 Size of memory in bytes to alloc.
- * @param boundary [IN] Type #UINT32 Boundary the heap needs align.
- *
- * @retval VOID * Get the address of the memory we alloced or NULL.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
-
-/**
- * @ingroup OsHeapFree
- * @brief Free memory block from heap memory pool.
- *
- * @par Description:
- * This API is used to To free the memory block from heap memory pool.
- * @attention
- *
- * @param pool [IN] Type #VOID * Pointer to the manager,to distinguish heap
- * @param ptr [IN] Type #VOID * Pinter of heap memory we want to free.
- *
- * @retval BOOL Get result return.
- *
- * @par Dependency:
- * los_heap_pri.h: the header file that contains the API declaration.
- * @see None.
- */
-extern BOOL OsHeapFree(VOID *pool, VOID* ptr);
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif /* _LOS_HEAP_PRI_H */
diff --git a/kernel/base/include/los_ipcdebug_pri.h b/kernel/base/include/los_ipcdebug_pri.h
index a9cd2956..c5d1c1cb 100644
--- a/kernel/base/include/los_ipcdebug_pri.h
+++ b/kernel/base/include/los_ipcdebug_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_membox_pri.h b/kernel/base/include/los_membox_pri.h
index ed904c2d..9a06ddea 100644
--- a/kernel/base/include/los_membox_pri.h
+++ b/kernel/base/include/los_membox_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_memory_pri.h b/kernel/base/include/los_memory_pri.h
old mode 100644
new mode 100755
index 64a9c639..12c6e022
--- a/kernel/base/include/los_memory_pri.h
+++ b/kernel/base/include/los_memory_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -58,10 +58,8 @@ extern UINT32 OsMemLargeNodeFree(const VOID *ptr);
extern BOOL OsMemIsHeapNode(const VOID *ptr);
extern UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]);
-/* spinlock for mem module, only available on SMP mode */
-extern SPIN_LOCK_S g_memSpin;
-#define MEM_LOCK(state) LOS_SpinLockSave(&g_memSpin, &(state))
-#define MEM_UNLOCK(state) LOS_SpinUnlockRestore(&g_memSpin, (state))
+/* memory expand size at least 1/8 of pool size if we can */
+#define MEM_EXPAND_SIZE(poolSize) (poolSize >> 3)
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/base/include/los_memstat_pri.h b/kernel/base/include/los_memstat_pri.h
index 7c093c5b..a2a9f581 100644
--- a/kernel/base/include/los_memstat_pri.h
+++ b/kernel/base/include/los_memstat_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_mux_pri.h b/kernel/base/include/los_mux_pri.h
old mode 100644
new mode 100755
index c729ab1f..129902a8
--- a/kernel/base/include/los_mux_pri.h
+++ b/kernel/base/include/los_mux_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_oom.h b/kernel/base/include/los_oom.h
old mode 100644
new mode 100755
index 3668d210..22abcb85
--- a/kernel/base/include/los_oom.h
+++ b/kernel/base/include/los_oom.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_percpu_pri.h b/kernel/base/include/los_percpu_pri.h
old mode 100644
new mode 100755
index ab0d860a..0a82c530
--- a/kernel/base/include/los_percpu_pri.h
+++ b/kernel/base/include/los_percpu_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,6 +34,7 @@
#include "los_base.h"
#include "los_hw_cpu.h"
+#include "los_spinlock.h"
#include "los_sortlink_pri.h"
#ifdef __cplusplus
@@ -51,17 +52,22 @@ typedef enum {
#endif
typedef struct {
- SortLinkAttribute taskSortLink; /* task sort link */
- SortLinkAttribute swtmrSortLink; /* swtmr sort link */
+ SortLinkAttribute taskSortLink; /* task sort link */
+ SPIN_LOCK_S taskSortLinkSpin; /* task sort link spin lock */
+ SortLinkAttribute swtmrSortLink; /* swtmr sort link */
+ SPIN_LOCK_S swtmrSortLinkSpin; /* swtmr sort link spin lock */
+ UINT64 responseTime; /* Response time for current nuclear Tick interrupts */
+ UINT32 responseID; /* The response ID of the current nuclear TICK interrupt */
+ UINTPTR runProcess; /* The address of the process control block pointer to which
+ the current kernel is running */
+ UINT32 idleTaskID; /* idle task id */
+ UINT32 taskLockCnt; /* task lock flag */
+ UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
+ UINT32 swtmrTaskID; /* software timer task id */
- UINT32 idleTaskID; /* idle task id */
- UINT32 taskLockCnt; /* task lock flag */
- UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
- UINT32 swtmrTaskID; /* software timer task id */
-
- UINT32 schedFlag; /* pending scheduler flag */
+ UINT32 schedFlag; /* pending scheduler flag */
#if (LOSCFG_KERNEL_SMP == YES)
- UINT32 excFlag; /* cpu halt or exc flag */
+ UINT32 excFlag; /* cpu halt or exc flag */
#endif
} Percpu;
diff --git a/kernel/base/include/los_pmm.h b/kernel/base/include/los_pmm.h
index 0f1b4300..2725bddd 100644
--- a/kernel/base/include/los_pmm.h
+++ b/kernel/base/include/los_pmm.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_printf_pri.h b/kernel/base/include/los_printf_pri.h
index 4ccb7777..f86aee95 100644
--- a/kernel/base/include/los_printf_pri.h
+++ b/kernel/base/include/los_printf_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_priqueue_pri.h b/kernel/base/include/los_priqueue_pri.h
deleted file mode 100644
index 67e65b71..00000000
--- a/kernel/base/include/los_priqueue_pri.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _LOS_PRIQUEUE_PRI_H
-#define _LOS_PRIQUEUE_PRI_H
-
-#include "los_config.h"
-#include "los_list.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-extern LOS_DL_LIST *g_priQueueList;
-extern UINT32 g_priQueueBitmap;
-
-#define OS_PRIORITY_QUEUE_NUM 32
-
-/**
- * @ingroup los_priqueue
- * @brief Initialize the priority queue.
- *
- * @par Description:
- * This API is used to initialize the priority queue.
- * @attention
- *
- * @param none.
- *
- * @retval #LOS_NOK Insufficient memory for priority queue initialization.
- * @retval #LOS_OK The priority queue successfully initialized.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see none.
- */
-extern UINT32 OsPriQueueInit(VOID);
-
-/**
- * @ingroup los_priqueue
- * @brief Obtain the item with highest priority.
- *
- * @par Description:
- * This API is used to obtain the item with highest priority in the priority queue.
- * @attention
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param bitMap [IN] bit map of priority queue.
- *
- * @retval NULL The priority queue is empty.
- * @retval item node The node of the item with highest priority.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see none.
- */
-extern LOS_DL_LIST *OsPriQueueTop(LOS_DL_LIST *priQueueList, UINT32 *bitMap);
-
-/**
- * @ingroup los_priqueue
- * @brief Insert a item to the head of priority queue.
- *
- * @par Description:
- * This API is used to insert a item to the head of priority queue according to the priority of this item.
- * @attention
- *
- * Param priqueueItem must point to valid memory.
- * Param priority rang is [0, OS_PRIORITY_QUEUE_NUM),included 0 and not included OS_PRIORITY_QUEUE_NUM.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param bitMap [IN] bit map of priority queue.
- * @param priqueueItem [IN] The node of item to be inserted.
- * @param priority [IN] Priority of the item be inserted.
- *
- * @retval none.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see OsPriQueueDequeue.
- */
-extern VOID OsPriQueueEnqueueHead(
- LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem, UINT32 priority);
-
-/**
- * @ingroup los_priqueue
- * @brief Insert a item to the priority queue.
- *
- * @par Description:
- * This API is used to insert a item to the priority queue according to the priority of this item.
- * @attention
- *
- * Param priqueueItem must point to valid memory.
- * Param priority rang is [0, OS_PRIORITY_QUEUE_NUM),included 0 and not included OS_PRIORITY_QUEUE_NUM.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param bitMap [IN] bit map of priority queue.
- * @param priqueueItem [IN] The node of item to be inserted.
- * @param priority [IN] Priority of the item be inserted.
- *
- * @retval none.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see OsPriQueueDequeue.
- */
-extern VOID OsPriQueueEnqueue(
- LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem, UINT32 priority);
-
-/**
- * @ingroup los_priqueue
- * @brief Delete a item from the priority queue.
- *
- * @par Description:
- * This API is used to delete a item from the priority queue.
- * @attention
- *
- * Param priqueueItem must point to valid memory.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param bitMap [IN] bit map of priority queue.
- * @param priqueueItem [IN] The node of item to be deleted.
- *
- * @retval none.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see OsPriQueueEnqueue.
- */
-extern VOID OsPriQueueDequeue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem);
-
-/**
- * @ingroup los_priqueue
- * @brief Delete a item from the priority queue.
- *
- * @par Description:
- * This API is used to delete a item from the process priority queue.
- * @attention
- *
- * Param priqueueItem must point to valid memory.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param bitMap [IN] bit map of priority queue.
- * @param priqueueItem [IN] The node of item to be deleted.
- *
- * @retval none.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see OsPriQueueProcessDequeue.
- */
-extern VOID OsPriQueueProcessDequeue(LOS_DL_LIST *priqueueItem);
-
-/**
- * @ingroup los_priqueue
- * @brief Obtain the number of items with the specified priority.
- *
- * @par Description:
- * This API is used to obtain the number of items with the specified priority.
- * @attention
- *
- * Param priority rang is [0, OS_PRIORITY_QUEUE_NUM),included 0 and not included OS_PRIORITY_QUEUE_NUM.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param priority [IN] Obtain the number of items with the specified priority.
- *
- * @retval The number of items The number of items with the specified priority.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see none.
- */
-extern UINT32 OsPriQueueSize(LOS_DL_LIST *priQueueList, UINT32 priority);
-
-/**
- * @ingroup los_priqueue
- * @brief Obtain the item with highest priority.
- *
- * @par Description:
- * This API is used to obtain the item with highest priority in the priority queue.
- * @attention
- *
- * @param none.
- *
- * @retval NULL The priority queue is empty.
- * @retval item node The node of the item with highest priority.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see none.
- */
-extern LOS_DL_LIST *OsTaskPriQueueTop(VOID);
-
-/**
- * @ingroup los_priqueue
- * @brief Obtain the number of items with the specified priority.
- *
- * @par Description:
- * This API is used to obtain the number of items with the specified process priority.
- * @attention
- *
- * Param priority rang is [0, OS_PRIORITY_QUEUE_NUM),included 0 and not included OS_PRIORITY_QUEUE_NUM.
- *
- * @param priQueueList [IN] The list of priority queue.
- * @param priority [IN] Obtain the number of items with the specified priority.
- *
- * @retval The number of items The number of items with the specified priority.
- * @par Dependency:
- * los_priqueue_pri.h: the header file that contains the API declaration.
- * @see none.
- */
-extern UINT32 OsPriQueueProcessSize(LOS_DL_LIST *priQueueList, UINT32 priority);
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif /* _LOS_PRIQUEUE_PRI_H */
diff --git a/kernel/base/include/los_process_pri.h b/kernel/base/include/los_process_pri.h
old mode 100644
new mode 100755
index ea353793..bc3dc361
--- a/kernel/base/include/los_process_pri.h
+++ b/kernel/base/include/los_process_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,8 +32,6 @@
#ifndef _LOS_PROCESS_PRI_H
#define _LOS_PROCESS_PRI_H
-#include "los_sortlink_pri.h"
-#include "los_priqueue_pri.h"
#include "los_task_pri.h"
#include "los_sem_pri.h"
#include "los_process.h"
@@ -82,10 +80,9 @@ typedef struct ProcessCB {
UINT16 processStatus; /**< [15:4] Process Status; [3:0] The number of threads currently
running in the process */
UINT16 priority; /**< Process priority */
- UINT16 policy; /**< Process policy */
- UINT16 timeSlice; /**< Remaining time slice */
UINT16 consoleID; /**< The console id of task belongs */
UINT16 processMode; /**< Kernel Mode:0; User Mode:1; */
+ UINT16 readyTaskNum; /**< The number of ready tasks in the current process */
UINT32 parentProcessID; /**< Parent process ID */
UINT32 exitCode; /**< Process exit status */
LOS_DL_LIST pendList; /**< Block list to which the process belongs */
@@ -95,11 +92,7 @@ typedef struct ProcessCB {
ProcessGroup *group; /**< Process group to which a process belongs */
LOS_DL_LIST subordinateGroupList; /**< Linkage in group list */
UINT32 threadGroupID; /**< Which thread group , is the main thread ID of the process */
- UINT32 threadScheduleMap; /**< The scheduling bitmap table for the thread group of the
- process */
LOS_DL_LIST threadSiblingList; /**< List of threads under this process */
- LOS_DL_LIST threadPriQueueList[OS_PRIORITY_QUEUE_NUM]; /**< The process's thread group schedules the
- priority hash table */
volatile UINT32 threadNumber; /**< Number of threads alive under this process */
UINT32 threadCount; /**< Total number of threads created under this process */
LOS_DL_LIST waitList; /**< The process holds the waitLits to support wait/waitpid */
@@ -109,25 +102,28 @@ typedef struct ProcessCB {
UINTPTR sigHandler; /**< Signal handler */
sigset_t sigShare; /**< Signal share bit */
#if (LOSCFG_KERNEL_LITEIPC == YES)
- ProcIpcInfo ipcInfo; /**< Memory pool for lite ipc */
+ ProcIpcInfo ipcInfo; /**< Memory pool for lite ipc */
#endif
- LosVmSpace *vmSpace; /**< VMM space for processes */
+ LosVmSpace *vmSpace; /**< VMM space for processes */
#ifdef LOSCFG_FS_VFS
- struct files_struct *files; /**< Files held by the process */
+ struct files_struct *files; /**< Files held by the process */
#endif
- timer_t timerID; /**< ITimer */
+ timer_t timerID; /**< ITimer */
#ifdef LOSCFG_SECURITY_CAPABILITY
User *user;
UINT32 capability;
#endif
#ifdef LOSCFG_SECURITY_VID
- TimerIdMap timerIdMap;
+ TimerIdMap timerIdMap;
#endif
#ifdef LOSCFG_DRIVERS_TZDRIVER
- struct file *execFile; /**< Exec bin of the process */
+ struct file *execFile; /**< Exec bin of the process */
+#endif
+ mode_t umask;
+#ifdef LOSCFG_KERNEL_CPUP
+ OsCpupBase processCpup; /**< Process cpu usage */
#endif
- mode_t umask;
} LosProcessCB;
#define CLONE_VM 0x00000100
@@ -171,9 +167,9 @@ typedef struct ProcessCB {
* @ingroup los_process
* Flag that indicates the process or process control block status.
*
- * The process is pend
+ * The process is pending
*/
-#define OS_PROCESS_STATUS_PEND 0x0080U
+#define OS_PROCESS_STATUS_PENDING 0x0080U
/**
* @ingroup los_process
@@ -267,12 +263,6 @@ STATIC INLINE BOOL OsProcessIsDead(const LosProcessCB *processCB)
return ((processCB->processStatus & (OS_PROCESS_FLAG_UNUSED | OS_PROCESS_STATUS_ZOMBIES)) != 0);
}
-/**
- * @ingroup los_process
- * Hold the time slice process
- */
-#define OS_PROCESS_SCHED_RR_INTERVAL LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
-
/**
* @ingroup los_process
* The highest priority of a kernel mode process.
@@ -324,13 +314,14 @@ STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
#define LOS_SCHED_NORMAL 0U
#define LOS_SCHED_FIFO 1U
#define LOS_SCHED_RR 2U
+#define LOS_SCHED_IDLE 3U
#define LOS_PRIO_PROCESS 0U
#define LOS_PRIO_PGRP 1U
#define LOS_PRIO_USER 2U
-#define OS_KERNEL_PROCESS_GROUP 2U
#define OS_USER_PRIVILEGE_PROCESS_GROUP 1U
+#define OS_KERNEL_PROCESS_GROUP 2U
/*
* Process exit code
@@ -365,7 +356,6 @@ STATIC INLINE VOID OsProcessExitCodeSet(LosProcessCB *processCB, UINT32 code)
}
extern LosProcessCB *g_processCBArray;
-extern LosProcessCB *g_runProcess[LOSCFG_KERNEL_CORE_NUM];
extern UINT32 g_processMaxNum;
#define OS_PID_CHECK_INVALID(pid) (((UINT32)(pid)) >= g_processMaxNum)
@@ -378,35 +368,16 @@ STATIC INLINE BOOL OsProcessIDUserCheckInvalid(UINT32 pid)
STATIC INLINE LosProcessCB *OsCurrProcessGet(VOID)
{
UINT32 intSave;
- LosProcessCB *runProcess = NULL;
intSave = LOS_IntLock();
- runProcess = g_runProcess[ArchCurrCpuid()];
+ LosProcessCB *runProcess = (LosProcessCB *)OsPercpuGet()->runProcess;
LOS_IntRestore(intSave);
return runProcess;
}
STATIC INLINE VOID OsCurrProcessSet(const LosProcessCB *process)
{
- g_runProcess[ArchCurrCpuid()] = (LosProcessCB *)process;
-}
-
-STATIC INLINE UINT32 OsCpuProcessIDGetUnsafe(UINT16 cpuID)
-{
- LosProcessCB *runProcess = g_runProcess[cpuID];
- return runProcess->processID;
-}
-
-STATIC INLINE UINT32 OsCpuProcessIDGet(UINT16 cpuID)
-{
- UINT32 pid;
- UINT32 intSave;
-
- SCHEDULER_LOCK(intSave);
- pid = OsCpuProcessIDGetUnsafe(cpuID);
- SCHEDULER_UNLOCK(intSave);
-
- return pid;
+ OsPercpuGet()->runProcess = (UINTPTR)process;
}
#ifdef LOSCFG_SECURITY_CAPABILITY
@@ -448,17 +419,17 @@ STATIC INLINE User *OsCurrUserGet(VOID)
/*
* Wait for any child process to finish
*/
-#define OS_PROCESS_WAIT_ANY (1 << 0U)
+#define OS_PROCESS_WAIT_ANY OS_TASK_WAIT_ANYPROCESS
/*
* Wait for the child process specified by the pid to finish
*/
-#define OS_PROCESS_WAIT_PRO (1 << 1U)
+#define OS_PROCESS_WAIT_PRO OS_TASK_WAIT_PROCESS
/*
* Waits for any child process in the specified process group to finish.
*/
-#define OS_PROCESS_WAIT_GID (1 << 2U)
+#define OS_PROCESS_WAIT_GID OS_TASK_WAIT_GID
#define OS_PROCESS_INFO_ALL 1
#define OS_PROCESS_DEFAULT_UMASK 0022
@@ -467,7 +438,7 @@ extern UINTPTR __user_init_entry;
extern UINTPTR __user_init_bss;
extern UINTPTR __user_init_end;
extern UINTPTR __user_init_load_addr;
-extern UINT32 OsKernelInitProcess(VOID);
+extern UINT32 OsSystemProcessCreate(VOID);
extern VOID OsProcessCBRecyleToFree(VOID);
extern VOID OsProcessResourcesToFree(LosProcessCB *processCB);
extern VOID OsProcessExit(LosTaskCB *runTask, INT32 status);
@@ -480,7 +451,7 @@ extern UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR *name,
LosVmSpace *oldAspace, UINTPTR oldFiles);
extern UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize);
extern UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name);
-extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy, BOOL policyFlag);
+extern INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy);
extern INT32 OsGetProcessPriority(INT32 which, INT32 pid);
extern VOID *OsUserStackAlloc(UINT32 processID, UINT32 *size);
extern UINT32 OsGetUserInitProcessID(VOID);
diff --git a/kernel/base/include/los_queue_debug_pri.h b/kernel/base/include/los_queue_debug_pri.h
index 5d1b7238..b7312135 100644
--- a/kernel/base/include/los_queue_debug_pri.h
+++ b/kernel/base/include/los_queue_debug_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_queue_pri.h b/kernel/base/include/los_queue_pri.h
index 746b7801..96472859 100644
--- a/kernel/base/include/los_queue_pri.h
+++ b/kernel/base/include/los_queue_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_rwlock_pri.h b/kernel/base/include/los_rwlock_pri.h
new file mode 100755
index 00000000..55681501
--- /dev/null
+++ b/kernel/base/include/los_rwlock_pri.h
@@ -0,0 +1,66 @@
+/*
+ * 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_RWLOCK_PRI_H
+#define _LOS_RWLOCK_PRI_H
+
+#include "los_rwlock.h"
+#include "los_task_pri.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#define OS_RWLOCK_MAGIC 0xBEFDCAU
+
+enum RwlockMode {
+ RWLOCK_NONE_MODE,
+ RWLOCK_READ_MODE,
+ RWLOCK_WRITE_MODE,
+ RWLOCK_READFIRST_MODE,
+ RWLOCK_WRITEFIRST_MODE
+};
+
+extern UINT32 OsRwlockRdUnsafe(LosRwlock *rwlock, UINT32 timeout);
+extern UINT32 OsRwlockTryRdUnsafe(LosRwlock *rwlock, UINT32 timeout);
+extern UINT32 OsRwlockWrUnsafe(LosRwlock *rwlock, UINT32 timeout);
+extern UINT32 OsRwlockTryWrUnsafe(LosRwlock *rwlock, UINT32 timeout);
+extern UINT32 OsRwlockUnlockUnsafe(LosRwlock *rwlock, BOOL *needSched);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _LOS_RWLOCK_PRI_H */
diff --git a/kernel/base/include/los_sched_pri.h b/kernel/base/include/los_sched_pri.h
old mode 100644
new mode 100755
index cc84e9e0..23141362
--- a/kernel/base/include/los_sched_pri.h
+++ b/kernel/base/include/los_sched_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -33,7 +33,11 @@
#define _LOS_SCHED_PRI_H
#include "los_percpu_pri.h"
+#include "los_task_pri.h"
+#include "los_sys_pri.h"
+#include "los_process_pri.h"
#include "los_hwi.h"
+#include "hal_timer.h"
#ifdef __cplusplus
#if __cplusplus
@@ -42,6 +46,30 @@ extern "C" {
#endif /* __cplusplus */
extern UINT32 g_taskScheduled;
+typedef BOOL (*SchedScan)(VOID);
+
+extern UINT64 g_sysSchedStartTime;
+
+STATIC INLINE UINT64 OsGerCurrSchedTimeCycle(VOID)
+{
+ if (g_sysSchedStartTime == 0) {
+ return g_sysSchedStartTime;
+ }
+
+ return (HalClockGetCycles() - g_sysSchedStartTime);
+}
+
+STATIC INLINE VOID OsSchedIrqUpdateUsedTime(VOID)
+{
+ LosTaskCB *runTask = OsCurrTaskGet();
+ runTask->irqUsedTime = OsGerCurrSchedTimeCycle() - runTask->irqStartTime;
+}
+
+STATIC INLINE VOID OsSchedIrqStartTime(VOID)
+{
+ LosTaskCB *runTask = OsCurrTaskGet();
+ runTask->irqStartTime = OsGerCurrSchedTimeCycle();
+}
/*
* Schedule flag, one bit represents one core.
@@ -102,6 +130,60 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
return preemptable;
}
+STATIC INLINE VOID OsCpuSchedLock(Percpu *cpu)
+{
+ cpu->taskLockCnt++;
+}
+
+STATIC INLINE VOID OsCpuSchedUnlock(Percpu *cpu, UINT32 intSave)
+{
+ if (cpu->taskLockCnt > 0) {
+ cpu->taskLockCnt--;
+ if ((cpu->taskLockCnt == 0) && (cpu->schedFlag == INT_PEND_RESCH) && OS_SCHEDULER_ACTIVE) {
+ cpu->schedFlag = INT_NO_RESCH;
+ LOS_IntRestore(intSave);
+ LOS_Schedule();
+ return;
+ }
+ }
+
+ LOS_IntRestore(intSave);
+}
+
+extern UINT32 OsSchedSetTickTimerType(UINT32 timerType);
+
+extern VOID OsSchedSetIdleTaskSchedPartam(LosTaskCB *idleTask);
+
+extern UINT32 OsSchedSwtmrScanRegister(SchedScan func);
+
+extern VOID OsSchedUpdateExpireTime(UINT64 startTime);
+
+extern VOID OsSchedToUserReleaseLock(VOID);
+
+extern VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
+
+extern VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
+
+extern UINT32 OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched);
+
+extern VOID OsSchedTaskWake(LosTaskCB *resumedTask);
+
+extern BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priority);
+
+extern BOOL OsSchedModifyProcessSchedParam(LosProcessCB *processCB, UINT16 policy, UINT16 priority);
+
+extern VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
+
+extern VOID OsSchedYield(VOID);
+
+extern VOID OsSchedTaskExit(LosTaskCB *taskCB);
+
+extern VOID OsSchedTick(VOID);
+
+extern UINT32 OsSchedInit(VOID);
+
+extern VOID OsSchedStart(VOID);
+
/*
* This function simply picks the next task and switches to it.
* Current task needs to already be in the right state or the right
@@ -109,31 +191,21 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
*/
extern VOID OsSchedResched(VOID);
-/*
- * This function put the current task back to the ready queue and
- * try to do the schedule. However, the schedule won't be definitely
- * taken place while there're no other higher priority tasks or locked.
- */
-extern VOID OsSchedPreempt(VOID);
+extern VOID OsSchedIrqEndCheckNeedSched(VOID);
/*
- * Just like OsSchedPreempt, except this function will do the OS_INT_ACTIVE
- * check, in case the schedule taken place in the middle of an interrupt.
- */
-STATIC INLINE VOID LOS_Schedule(VOID)
-{
- if (OS_INT_ACTIVE) {
- OsPercpuGet()->schedFlag = INT_PEND_RESCH;
- return;
- }
+* This function inserts the runTask to the lock pending list based on the
+* task priority.
+*/
+extern LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList);
- /*
- * trigger schedule in task will also do the slice check
- * if neccessary, it will give up the timeslice more in time.
- * otherwhise, there's no other side effects.
- */
- OsSchedPreempt();
-}
+#ifdef LOSCFG_SCHED_TICK_DEBUG
+extern VOID OsSchedDebugRecordData(VOID);
+#endif
+
+extern UINT32 OsShellShowTickRespo(VOID);
+
+extern UINT32 OsShellShowSchedParam(VOID);
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/base/include/los_sem_debug_pri.h b/kernel/base/include/los_sem_debug_pri.h
index ed156c79..e684c3dc 100644
--- a/kernel/base/include/los_sem_debug_pri.h
+++ b/kernel/base/include/los_sem_debug_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_sem_pri.h b/kernel/base/include/los_sem_pri.h
old mode 100644
new mode 100755
index 6e19ee1e..8476a1bc
--- a/kernel/base/include/los_sem_pri.h
+++ b/kernel/base/include/los_sem_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_signal.h b/kernel/base/include/los_signal.h
old mode 100644
new mode 100755
index da538a5f..86b9134f
--- a/kernel/base/include/los_signal.h
+++ b/kernel/base/include/los_signal.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_sortlink_pri.h b/kernel/base/include/los_sortlink_pri.h
old mode 100644
new mode 100755
index ce826c46..fa2edf17
--- a/kernel/base/include/los_sortlink_pri.h
+++ b/kernel/base/include/los_sortlink_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,6 +34,7 @@
#include "los_typedef.h"
#include "los_list.h"
+#include "los_sys_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -41,63 +42,34 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-/*
- * Sortlink Rollnum Structure:
- * ------------------------------------------
- * | 31 | 30 | 29 |.......| 4 | 3 | 2 | 1 | 0 |
- * ------------------------------------------
- * |<-High Bits->|<---------Low Bits--------->|
- *
- * Low Bits : circles
- * High Bits : sortlink index
- */
-#define OS_TSK_HIGH_BITS 3U
-#define OS_TSK_LOW_BITS (32U - OS_TSK_HIGH_BITS)
-#define OS_TSK_SORTLINK_LOGLEN OS_TSK_HIGH_BITS
-#define OS_TSK_SORTLINK_LEN (1U << OS_TSK_SORTLINK_LOGLEN)
-#define OS_TSK_SORTLINK_MASK (OS_TSK_SORTLINK_LEN - 1U)
-#define OS_TSK_MAX_ROLLNUM (0xFFFFFFFFU - OS_TSK_SORTLINK_LEN)
-#define OS_TSK_HIGH_BITS_MASK (OS_TSK_SORTLINK_MASK << OS_TSK_LOW_BITS)
-#define OS_TSK_LOW_BITS_MASK (~OS_TSK_HIGH_BITS_MASK)
-
-#define EVALUATE_L(NUM, VALUE) NUM = (((NUM) & OS_TSK_HIGH_BITS_MASK) | (VALUE))
-
-#define EVALUATE_H(NUM, VALUE) NUM = (((NUM) & OS_TSK_LOW_BITS_MASK) | ((VALUE) << OS_TSK_LOW_BITS))
-
-#define ROLLNUM_SUB(NUM1, NUM2) \
- NUM1 = (((NUM1) & OS_TSK_HIGH_BITS_MASK) | \
- (ROLLNUM(NUM1) - ROLLNUM(NUM2)))
-
-#define ROLLNUM_ADD(NUM1, NUM2) \
- NUM1 = (((NUM1) & OS_TSK_HIGH_BITS_MASK) | \
- (ROLLNUM(NUM1) + ROLLNUM(NUM2)))
-
-#define ROLLNUM_DEC(NUM) NUM = ((NUM) - 1)
-
-#define ROLLNUM(NUM) ((NUM) & OS_TSK_LOW_BITS_MASK)
-
-#define SORT_INDEX(NUM) ((NUM) >> OS_TSK_LOW_BITS)
-
-#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->idxRollNum = (value))
+typedef enum {
+ OS_SORT_LINK_TASK = 1,
+ OS_SORT_LINK_SWTMR = 2,
+} SortLinkType;
typedef struct {
LOS_DL_LIST sortLinkNode;
- UINT32 idxRollNum;
+ UINT64 responseTime;
+#if (LOSCFG_KERNEL_SMP == YES)
+ UINT32 cpuid;
+#endif
} SortLinkList;
typedef struct {
- LOS_DL_LIST *sortLink;
- UINT16 cursor;
- UINT16 reserved;
+ LOS_DL_LIST sortLink;
+ UINT32 nodeNum;
} SortLinkAttribute;
+#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
+#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->responseTime = (value))
+
+extern UINT64 OsGetNextExpireTime(UINT64 startTime);
extern UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
-extern VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
-extern VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
+extern VOID OsDeleteNodeSortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
+extern VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
+extern VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type);
+extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkList *targetSortList);
extern UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
-extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
- const SortLinkList *targetSortList);
-extern VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader);
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/base/include/los_stackinfo_pri.h b/kernel/base/include/los_stackinfo_pri.h
index 6540c649..2698433e 100644
--- a/kernel/base/include/los_stackinfo_pri.h
+++ b/kernel/base/include/los_stackinfo_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_stat_pri.h b/kernel/base/include/los_stat_pri.h
old mode 100644
new mode 100755
index 74754985..3ca4e9f2
--- a/kernel/base/include/los_stat_pri.h
+++ b/kernel/base/include/los_stat_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -44,10 +44,17 @@ typedef struct {
} SchedPercpu;
typedef struct {
- UINT64 startRuntime;
UINT64 allRuntime;
- UINT32 allContextSwitch;
- SchedPercpu schedPercpu[LOSCFG_KERNEL_SMP_CORE_NUM];
+ UINT64 runTime;
+ UINT64 switchCount; /* sched switch count */
+ UINT64 timeSliceRealTime; /* The actual usage time of each time slice */
+ UINT64 timeSliceTime;
+ UINT64 timeSliceCount; /* The number of time slices allocated */
+ UINT64 pendTime;
+ UINT64 pendCount;
+ UINT64 waitSchedTime; /* task status is ready to running times */
+ UINT64 waitSchedCount;
+ SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM];
} SchedStat;
#ifdef __cplusplus
@@ -56,4 +63,4 @@ typedef struct {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* __LOS_STAT_PRI_H */
\ No newline at end of file
+#endif /* __LOS_STAT_PRI_H */
diff --git a/kernel/base/include/los_swtmr_pri.h b/kernel/base/include/los_swtmr_pri.h
index 8eb0d265..bfbba009 100644
--- a/kernel/base/include/los_swtmr_pri.h
+++ b/kernel/base/include/los_swtmr_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_sys_pri.h b/kernel/base/include/los_sys_pri.h
old mode 100644
new mode 100755
index 93fd19c2..f980a1d1
--- a/kernel/base/include/los_sys_pri.h
+++ b/kernel/base/include/los_sys_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -77,6 +77,30 @@ extern "C" {
*/
#define OS_SYS_NS_PER_US 1000
+/**
+ * @ingroup los_sys
+ * Number of cycle in one tick.
+ */
+#define OS_CYCLE_PER_TICK (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND)
+
+/**
+ * @ingroup los_sys
+ * Number of nanoseconds in one cycle.
+ */
+#define OS_NS_PER_CYCLE (OS_SYS_NS_PER_SECOND / OS_SYS_CLOCK)
+
+/**
+ * @ingroup los_sys
+ * Number of microseconds in one tick.
+ */
+#define OS_US_PER_TICK (OS_SYS_US_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
+
+/**
+ * @ingroup los_sys
+ * Number of nanoseconds in one tick.
+ */
+#define OS_NS_PER_TICK (OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
+
/**
* @ingroup los_sys
* The maximum length of name.
@@ -95,6 +119,12 @@ extern "C" {
*/
#define OS_SYS_EMPTY_STACK 0xCACACACA
+/**
+ * @ingroup los_sys
+ * Convert microseconds to Ticks.
+ */
+extern UINT32 OsUS2Tick(UINT64 microsec);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/base/include/los_task_pri.h b/kernel/base/include/los_task_pri.h
old mode 100644
new mode 100755
index 88653467..d40c9511
--- a/kernel/base/include/los_task_pri.h
+++ b/kernel/base/include/los_task_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -33,15 +33,19 @@
#define _LOS_TASK_PRI_H
#include "los_task.h"
-#include "los_sched_pri.h"
-#include "los_sortlink_pri.h"
+#include "los_percpu_pri.h"
#include "los_spinlock.h"
-#if (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
+#ifdef LOSCFG_SCHED_DEBUG
#include "los_stat_pri.h"
#endif
#include "los_stackinfo_pri.h"
#include "los_futex_pri.h"
#include "los_signal.h"
+#ifdef LOSCFG_KERNEL_CPUP
+#include "los_cpup_pri.h"
+#endif
+
+#include "los_trace.h"
#ifdef __cplusplus
#if __cplusplus
@@ -121,7 +125,7 @@ extern SPIN_LOCK_S g_taskSpin;
*
* The task is suspended.
*/
-#define OS_TASK_STATUS_SUSPEND 0x0008U
+#define OS_TASK_STATUS_SUSPENDED 0x0008U
/**
* @ingroup los_task
@@ -129,7 +133,7 @@ extern SPIN_LOCK_S g_taskSpin;
*
* The task is blocked.
*/
-#define OS_TASK_STATUS_PEND 0x0010U
+#define OS_TASK_STATUS_PENDING 0x0010U
/**
* @ingroup los_task
@@ -155,6 +159,9 @@ extern SPIN_LOCK_S g_taskSpin;
*/
#define OS_TASK_STATUS_PEND_TIME 0x0080U
+#define OS_TASK_STATUS_BLOCKED (OS_TASK_STATUS_INIT | OS_TASK_STATUS_PENDING | \
+ OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)
+
/**
* @ingroup los_task
* Flag that indicates the task or task control block status.
@@ -191,17 +198,17 @@ extern SPIN_LOCK_S g_taskSpin;
* @ingroup los_task
* Flag that indicates the task property.
*
- * The task is idle task, Belong to idle process.
+ * The task is system-level task, like idle, swtmr and etc.
*/
-#define OS_TASK_FLAG_IDLEFLAG 0x1000U
+#define OS_TASK_FLAG_SYSTEM_TASK 0x1000U
/**
* @ingroup los_task
* Flag that indicates the task property.
*
- * The task is system-level task, like idle, swtmr and etc.
+ * The task is no-delete system task, like resourceTask.
*/
-#define OS_TASK_FLAG_SYSTEM_TASK 0x2000U
+#define OS_TASK_FLAG_NO_DELETE 0x2000U
/**
* @ingroup los_task
@@ -211,14 +218,6 @@ extern SPIN_LOCK_S g_taskSpin;
*/
#define OS_TASK_FLAG_SPECIFIES_PROCESS 0x4000U
-/**
- * @ingroup los_task
- * Flag that indicates the task property.
- *
- * The task is system-level task, like ResourcesTask.
- */
-#define OS_TASK_FLAG_NO_DELETE 0x8000U
-
/**
* @ingroup los_task
* Boundary on which the stack size is aligned.
@@ -304,26 +303,36 @@ extern SPIN_LOCK_S g_taskSpin;
typedef struct {
VOID *stackPointer; /**< Task stack pointer */
UINT16 taskStatus; /**< Task status */
+
+ /* The scheduling */
UINT16 priority; /**< Task priority */
UINT16 policy;
- UINT16 timeSlice; /**< Remaining time slice */
+ UINT64 startTime; /**< The start time of each phase of task */
+ UINT64 irqStartTime; /**< Interrupt start time */
+ UINT32 irqUsedTime; /**< Interrupt consumption time */
+ UINT32 initTimeSlice; /**< Task init time slice */
+ INT32 timeSlice; /**< Task remaining time slice */
+ UINT32 waitTimes; /**< Task delay time, tick number */
+ SortLinkList sortList; /**< Task sortlink node */
+
UINT32 stackSize; /**< Task stack size */
UINTPTR topOfStack; /**< Task stack top */
UINT32 taskID; /**< Task ID */
TSK_ENTRY_FUNC taskEntry; /**< Task entrance function */
VOID *joinRetval; /**< pthread adaption */
- VOID *taskSem; /**< Task-held semaphore */
VOID *taskMux; /**< Task-held mutex */
VOID *taskEvent; /**< Task-held event */
UINTPTR args[4]; /**< Parameter, of which the maximum number is 4 */
CHAR taskName[OS_TCB_NAME_LEN]; /**< Task name */
LOS_DL_LIST pendList; /**< Task pend node */
LOS_DL_LIST threadList; /**< thread list */
- SortLinkList sortList; /**< Task sortlink node */
UINT32 eventMask; /**< Event mask */
UINT32 eventMode; /**< Event mode */
UINT32 priBitMap; /**< BitMap for recording the change of task priority,
the priority can not be greater than 31 */
+#ifdef LOSCFG_KERNEL_CPUP
+ OsCpupBase taskCpup; /**< task cpu usage */
+#endif
INT32 errorNo; /**< Error Num */
UINT32 signal; /**< Task signal */
sig_cb sig;
@@ -331,16 +340,15 @@ typedef struct {
UINT16 currCpu; /**< CPU core number of this task is running on */
UINT16 lastCpu; /**< CPU core number of this task is running on last time */
UINT16 cpuAffiMask; /**< CPU affinity mask, support up to 16 cores */
- UINT32 timerCpu; /**< CPU core number of this task is delayed or pended */
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
UINT32 syncSignal; /**< Synchronization for signal handling */
#endif
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
LockDep lockDep;
#endif
-#if (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
- SchedStat schedStat; /**< Schedule statistics */
#endif
+#ifdef LOSCFG_SCHED_DEBUG
+ SchedStat schedStat; /**< Schedule statistics */
#endif
UINTPTR userArea;
UINTPTR userMapBase;
@@ -349,7 +357,7 @@ typedef struct {
FutexNode futex;
LOS_DL_LIST joinList; /**< join list */
LOS_DL_LIST lockList; /**< Hold the lock list */
- UINT32 waitID; /**< Wait for the PID or GID of the child process */
+ UINTPTR waitID; /**< Wait for the PID or GID of the child process */
UINT16 waitFlag; /**< The type of child process that is waiting, belonging to a group or parent,
a specific child process, or any child process */
#if (LOSCFG_KERNEL_LITEIPC == YES)
@@ -381,7 +389,6 @@ typedef int (*ForEachTaskCB)(LosTaskCB *tcb, void *arg);
*/
extern UINT32 g_taskMaxNum;
-
/**
* @ingroup los_task
* Starting address of a task.
@@ -451,132 +458,28 @@ STATIC INLINE BOOL OsTaskIsInactive(const LosTaskCB *taskCB)
/* get task info */
#define OS_ALL_TASK_MASK 0xFFFFFFFF
-#define OS_PROCESS_PRI_QUEUE_SIZE(processCB) OsPriQueueProcessSize(g_priQueueList, (processCB)->priority)
-
-#define OS_TASK_PRI_QUEUE_ENQUEUE(processCB, taskCB) \
- OsPriQueueEnqueue((processCB)->threadPriQueueList, &((processCB)->threadScheduleMap), \
- &((taskCB)->pendList), (taskCB)->priority)
-
-#define OS_TASK_PRI_QUEUE_ENQUEUE_HEAD(processCB, taskCB) \
- OsPriQueueEnqueueHead((processCB)->threadPriQueueList, &((processCB)->threadScheduleMap), \
- &((taskCB)->pendList), (taskCB)->priority)
-
-#define OS_TASK_PRI_QUEUE_DEQUEUE(processCB, taskCB) \
- OsPriQueueDequeue((processCB)->threadPriQueueList, &((processCB)->threadScheduleMap), &((taskCB)->pendList))
-
-
-#define OS_TASK_SCHED_QUEUE_ENQUEUE(taskCB, status) OsTaskSchedQueueEnqueue(taskCB, status)
-#define OS_TASK_SCHED_QUEUE_DEQUEUE(taskCB, status) OsTaskSchedQueueDequeue(taskCB, status)
-
-#define OS_PROCESS_PRI_QUEUE_ENQUEUE(processCB) \
- OsPriQueueEnqueue(g_priQueueList, &g_priQueueBitmap, &((processCB)->pendList), (processCB)->priority)
-#define OS_PROCESS_PRI_QUEUE_ENQUEUE_HEAD(processCB) \
- OsPriQueueEnqueueHead(g_priQueueList, &g_priQueueBitmap, &((processCB)->pendList), (processCB)->priority)
-#define OS_PROCESS_PRI_QUEUE_DEQUEUE(processCB) OsPriQueueProcessDequeue(&((processCB)->pendList))
-
-#define OS_TASK_PRI_QUEUE_SIZE(processCB, taskCB) OsPriQueueSize((processCB)->threadPriQueueList, (taskCB)->priority)
-#define OS_TASK_GET_NEW(processCB) LOS_DL_LIST_ENTRY(OsPriQueueTop((processCB)->threadPriQueueList, \
- &((processCB)->threadScheduleMap)), \
- LosTaskCB, pendList)
-
-#define OS_PROCESS_GET_NEW() \
- LOS_DL_LIST_ENTRY(OsPriQueueTop(g_priQueueList, &g_priQueueBitmap), LosProcessCB, pendList)
-
-/**
- * @ingroup los_task
- * @brief Modify the priority of task.
- *
- * @par Description:
- * This API is used to modify the priority of task.
- *
- * @attention
- *
- * The taskCB should be a correct pointer to task control block structure.
- * the priority should be in [0, OS_TASK_PRIORITY_LOWEST].
- *
- *
- * @param taskCB [IN] Type #LosTaskCB * pointer to task control block structure.
- * @param priority [IN] Type #UINT16 the priority of task.
- *
- * @retval None.
- * @par Dependency:
- * los_task_pri.h: the header file that contains the API declaration.
- * @see
- */
-extern VOID OsTaskPriModify(LosTaskCB *taskCB, UINT16 priority);
-
-/**
- * @ingroup los_task
- * @brief pend running task to pendlist
- *
- * @par Description:
- * This API is used to pend task to pendlist and add to sorted delay list.
- *
- * @attention
- *
- * The list should be a vaild pointer to pendlist.
- *
- *
- * @param list [IN] Type #LOS_DL_LIST * pointer to list which running task will be pended.
- * @param timeout [IN] Type #UINT32 Expiry time. The value range is [0,LOS_WAIT_FOREVER].
- * @param needSched [IN] Type #bool need sched
- *
- * @retval LOS_OK wait success
- * @retval LOS_NOK pend out
- * @par Dependency:
- * los_task_pri.h: the header file that contains the API declaration.
- * @see OsTaskWake
- */
-extern UINT32 OsTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched);
-
-/**
- * @ingroup los_task
- * @brief delete task from pendlist.
- *
- * @par Description:
- * This API is used to delete task from pendlist and also add to the priqueue.
- *
- * @attention
- *
- * The resumedTask should be the task which will be add to priqueue.
- *
- *
- * @param resumedTask [IN] Type #LosTaskCB * pointer to the task which will be add to priqueue.
- *
- * @retval None.
- * @par Dependency:
- * los_task_pri.h: the header file that contains the API declaration.
- * @see OsTaskWait
- */
-extern VOID OsTaskWake(LosTaskCB *resumedTask);
-
extern UINT32 OsTaskSetDeatchUnsafe(LosTaskCB *taskCB);
extern VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB);
extern UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB);
+extern BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask);
extern VOID OsTaskSchedule(LosTaskCB *, LosTaskCB *);
-extern VOID OsStartToRun(LosTaskCB *);
-extern VOID OsTaskScan(VOID);
+extern VOID OsTaskContextLoad(LosTaskCB *newTask);
extern VOID OsIdleTask(VOID);
extern UINT32 OsIdleTaskCreate(VOID);
extern UINT32 OsTaskInit(VOID);
extern UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv);
extern UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqfile, UINT16 flag);
-extern VOID* OsGetMainTask(VOID);
+extern LosTaskCB *OsGetMainTask(VOID);
extern VOID OsSetMainTask(VOID);
-extern LosTaskCB* OsGetTopTask(VOID);
extern UINT32 OsGetIdleTaskId(VOID);
extern VOID OsTaskEntry(UINT32 taskID);
extern SortLinkAttribute *OsTaskSortLinkGet(VOID);
-extern UINT32 OsTaskSwitchCheck(LosTaskCB *oldTask, LosTaskCB *newTask);
-extern UINT32 OsTaskProcSignal(VOID);
-extern VOID OsSchedStatistics(LosTaskCB *runTask, LosTaskCB *newTask);
+extern VOID OsTaskProcSignal(VOID);
extern UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UINT32 intSave);
extern VOID OsTaskResourcesToFree(LosTaskCB *taskCB);
extern VOID OsRunTaskToDelete(LosTaskCB *taskCB);
extern UINT32 OsTaskSyncWait(const LosTaskCB *taskCB);
extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
-extern INT32 OsTaskSchedulerSetUnsafe(LosTaskCB *taskCB, UINT16 policy, UINT16 priority,
- BOOL policyFlag, UINT32 intSave);
extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName);
extern VOID OsTaskCBRecyleToFree(VOID);
extern VOID OsTaskExitGroup(UINT32 status);
@@ -586,6 +489,65 @@ extern VOID OsProcessSuspendAllTask(VOID);
extern UINT32 OsUserTaskOperatePermissionsCheck(LosTaskCB *taskCB);
extern VOID OsWriteResourceEvent(UINT32 events);
extern UINT32 OsCreateResourceFreeTask(VOID);
+
+#define OS_TASK_WAIT_ANYPROCESS (1 << 0U)
+#define OS_TASK_WAIT_PROCESS (1 << 1U)
+#define OS_TASK_WAIT_GID (1 << 2U)
+#ifdef LOSCFG_DEBUG_VERSION
+#define OS_TASK_WAIT_SEM (OS_TASK_WAIT_GID + 1)
+#define OS_TASK_WAIT_QUEUE (OS_TASK_WAIT_SEM + 1)
+#define OS_TASK_WAIT_JOIN (OS_TASK_WAIT_QUEUE + 1)
+#define OS_TASK_WAIT_SIGNAL (OS_TASK_WAIT_JOIN + 1)
+#define OS_TASK_WAIT_LITEIPC (OS_TASK_WAIT_SIGNAL + 1)
+#define OS_TASK_WAIT_MUTEX (OS_TASK_WAIT_LITEIPC + 1)
+#define OS_TASK_WAIT_FUTEX (OS_TASK_WAIT_MUTEX + 1)
+#define OS_TASK_WAIT_EVENT (OS_TASK_WAIT_FUTEX + 1)
+#define OS_TASK_WAIT_COMPLETE (OS_TASK_WAIT_EVENT + 1)
+
+STATIC INLINE VOID OsTaskWaitSetPendMask(UINT16 mask, UINTPTR lockID, UINT32 timeout)
+{
+ LosTaskCB *runTask = OsCurrTaskGet();
+ runTask->waitID = lockID;
+ runTask->waitFlag = mask;
+ (VOID)timeout;
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT16 status = OS_TASK_STATUS_PENDING;
+ if (timeout != LOS_WAIT_FOREVER) {
+ status |= OS_TASK_STATUS_PEND_TIME;
+ }
+ LOS_Trace(LOS_TRACE_TASK, runTask->taskEntry, status, mask, lockID);
+#endif
+}
+
+STATIC INLINE VOID OsTaskWakeClearPendMask(LosTaskCB *resumeTask)
+{
+ resumeTask->waitID = 0;
+ resumeTask->waitFlag = 0;
+#ifdef LOSCFG_KERNEL_TRACE
+ LosTaskCB *runTask = OsCurrTaskGet();
+ LOS_Trace(LOS_TRACE_TASK, resumeTask->taskEntry, (UINT16)OS_TASK_STATUS_READY,
+ runTask->taskStatus, runTask->taskEntry);
+#endif
+}
+
+STATIC INLINE VOID OsTraceTaskSchedule(LosTaskCB *newTask, LosTaskCB *runTask)
+{
+ (VOID)newTask;
+ (VOID)runTask;
+#ifdef LOSCFG_KERNEL_TRACE
+ LOS_Trace(LOS_TRACE_TASK, newTask->taskEntry, (UINT16)OS_TASK_STATUS_RUNNING,
+ runTask->taskStatus, runTask->taskEntry);
+#endif
+}
+
+#else
+
+#define OsTaskWaitSetPendMask(mask, lockID, timeout)
+#define OsTaskWakeClearPendMask(taskCB)
+#define OsTraceTaskSchedule(newTask, runTask)
+
+#endif
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/base/include/los_tick_pri.h b/kernel/base/include/los_tick_pri.h
index d7c5c730..4621733f 100644
--- a/kernel/base/include/los_tick_pri.h
+++ b/kernel/base/include/los_tick_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -42,18 +42,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-
-/* spinlock for tick */
-extern SPIN_LOCK_S g_tickSpin;
-#define TICK_LOCK(state) LOS_SpinLockSave(&g_tickSpin, &(state))
-#define TICK_UNLOCK(state) LOS_SpinUnlockRestore(&g_tickSpin, (state))
-
-/**
- * @ingroup los_tick
- * Count of Ticks
- */
-extern volatile UINT64 g_tickCount[];
-
/**
* @ingroup los_tick
* Cycle to nanosecond scale
diff --git a/kernel/base/include/los_typedef_pri.h b/kernel/base/include/los_typedef_pri.h
index 62c2a53e..eff17a91 100644
--- a/kernel/base/include/los_typedef_pri.h
+++ b/kernel/base/include/los_typedef_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_boot.h b/kernel/base/include/los_vm_boot.h
old mode 100644
new mode 100755
index 8cb3f946..18e6b031
--- a/kernel/base/include/los_vm_boot.h
+++ b/kernel/base/include/los_vm_boot.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_common.h b/kernel/base/include/los_vm_common.h
old mode 100644
new mode 100755
index 8b2b290f..f2dd70bf
--- a/kernel/base/include/los_vm_common.h
+++ b/kernel/base/include/los_vm_common.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_dump.h b/kernel/base/include/los_vm_dump.h
index bf07a97c..e8d13a7c 100644
--- a/kernel/base/include/los_vm_dump.h
+++ b/kernel/base/include/los_vm_dump.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_fault.h b/kernel/base/include/los_vm_fault.h
index ddee3690..d3c650a2 100644
--- a/kernel/base/include/los_vm_fault.h
+++ b/kernel/base/include/los_vm_fault.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_filemap.h b/kernel/base/include/los_vm_filemap.h
old mode 100644
new mode 100755
index 16c68f19..e0d2d4ca
--- a/kernel/base/include/los_vm_filemap.h
+++ b/kernel/base/include/los_vm_filemap.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_iomap.h b/kernel/base/include/los_vm_iomap.h
old mode 100644
new mode 100755
index 1b492510..b10e3462
--- a/kernel/base/include/los_vm_iomap.h
+++ b/kernel/base/include/los_vm_iomap.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -46,8 +46,10 @@ enum DmaMemType {
DMA_NOCACHE
};
-#define IS_PERIPH_ADDR(addr) (((addr) >= U32_C(PERIPH_PMM_BASE)) && ((addr) <= U32_C(PERIPH_PMM_BASE) + U32_C(PERIPH_PMM_SIZE)))
-#define IS_MEMORY_ADDR(addr) (((addr) >= U32_C(DDR_MEM_ADDR)) && ((addr) <= U32_C(DDR_MEM_ADDR) + U32_C(DDR_MEM_SIZE)))
+#define IS_PERIPH_ADDR(addr) \
+ (((addr) >= U32_C(PERIPH_PMM_BASE)) && ((addr) <= U32_C(PERIPH_PMM_BASE) + U32_C(PERIPH_PMM_SIZE)))
+#define IS_MEMORY_ADDR(addr) \
+ (((addr) >= U32_C(DDR_MEM_ADDR)) && ((addr) <= U32_C(DDR_MEM_ADDR) + U32_C(DDR_MEM_SIZE)))
/* thread safety */
VOID *LOS_DmaMemAlloc(DMA_ADDR_T *dmaAddr, size_t size, size_t align, enum DmaMemType type);
diff --git a/kernel/base/include/los_vm_lock.h b/kernel/base/include/los_vm_lock.h
index f396225f..aa3c36fe 100644
--- a/kernel/base/include/los_vm_lock.h
+++ b/kernel/base/include/los_vm_lock.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_map.h b/kernel/base/include/los_vm_map.h
old mode 100644
new mode 100755
index da099c69..cfd9dffe
--- a/kernel/base/include/los_vm_map.h
+++ b/kernel/base/include/los_vm_map.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -50,6 +50,9 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
+/* If the kernel malloc size is less than 16k, use heap, otherwise use physical pages */
+#define KMALLOC_LARGE_SIZE (PAGE_SIZE << 2)
+
typedef struct VmMapRange {
VADDR_T base; /**< vm region base addr */
UINT32 size; /**< vm region size */
@@ -84,7 +87,6 @@ struct VmMapRegion {
VM_OFFSET_T pgOff; /**< region page offset to file */
UINT32 regionFlags; /**< region flags: cow, user_wired */
UINT32 shmid; /**< shmid about shared region */
- UINT8 protectFlags; /**< vm region protect flags: PROT_READ, PROT_WRITE, */
UINT8 forkFlags; /**< vm space fork flags: COPY, ZERO, */
UINT8 regionType; /**< vm region type: ANON, FILE, DEV */
union {
@@ -132,7 +134,7 @@ typedef struct VmSpace {
#define VM_MAP_REGION_FLAG_CACHED (0<<0)
#define VM_MAP_REGION_FLAG_UNCACHED (1<<0)
#define VM_MAP_REGION_FLAG_UNCACHED_DEVICE (2<<0) /* only exists on some arches, otherwise UNCACHED */
-#define VM_MAP_REGION_FLAG_WRITE_COMBINING (3<<0) /* only exists on some arches, otherwise UNCACHED */
+#define VM_MAP_REGION_FLAG_STRONGLY_ORDERED (3<<0) /* only exists on some arches, otherwise UNCACHED */
#define VM_MAP_REGION_FLAG_CACHE_MASK (3<<0)
#define VM_MAP_REGION_FLAG_PERM_USER (1<<2)
#define VM_MAP_REGION_FLAG_PERM_READ (1<<3)
@@ -151,7 +153,9 @@ typedef struct VmSpace {
#define VM_MAP_REGION_FLAG_VDSO (1<<14)
#define VM_MAP_REGION_FLAG_MMAP (1<<15)
#define VM_MAP_REGION_FLAG_SHM (1<<16)
-#define VM_MAP_REGION_FLAG_INVALID (1<<17) /* indicates that flags are not specified */
+#define VM_MAP_REGION_FLAG_FIXED (1<<17)
+#define VM_MAP_REGION_FLAG_FIXED_NOREPLACE (1<<18)
+#define VM_MAP_REGION_FLAG_INVALID (1<<19) /* indicates that flags are not specified */
STATIC INLINE UINT32 OsCvtProtFlagsToRegionFlags(unsigned long prot, unsigned long flags)
{
@@ -159,10 +163,12 @@ STATIC INLINE UINT32 OsCvtProtFlagsToRegionFlags(unsigned long prot, unsigned lo
regionFlags |= VM_MAP_REGION_FLAG_PERM_USER;
regionFlags |= (prot & PROT_READ) ? VM_MAP_REGION_FLAG_PERM_READ : 0;
- regionFlags |= (prot & PROT_WRITE) ? VM_MAP_REGION_FLAG_PERM_WRITE : 0;
- regionFlags |= (prot & PROT_EXEC) ? VM_MAP_REGION_FLAG_PERM_EXECUTE : 0;
+ regionFlags |= (prot & PROT_WRITE) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE) : 0;
+ regionFlags |= (prot & PROT_EXEC) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE) : 0;
regionFlags |= (flags & MAP_SHARED) ? VM_MAP_REGION_FLAG_SHARED : 0;
regionFlags |= (flags & MAP_PRIVATE) ? VM_MAP_REGION_FLAG_PRIVATE : 0;
+ regionFlags |= (flags & MAP_FIXED) ? VM_MAP_REGION_FLAG_FIXED : 0;
+ regionFlags |= (flags & MAP_FIXED_NOREPLACE) ? VM_MAP_REGION_FLAG_FIXED_NOREPLACE : 0;
return regionFlags;
}
@@ -261,10 +267,9 @@ VOID OsInitMappingStartUp(VOID);
VOID OsKSpaceInit(VOID);
BOOL LOS_IsRangeInSpace(const LosVmSpace *space, VADDR_T vaddr, size_t size);
STATUS_T LOS_VmSpaceReserve(LosVmSpace *space, size_t size, VADDR_T vaddr);
-LosVmSpace *LOS_GetKVmSpace(VOID);
INT32 OsUserHeapFree(LosVmSpace *vmSpace, VADDR_T addr, size_t len);
VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len);
-VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len);
+VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags);
LosVmMapRegion *OsCreateRegion(VADDR_T vaddr, size_t len, UINT32 regionFlags, unsigned long offset);
BOOL OsInsertRegion(LosRbTree *regionRbTree, LosVmMapRegion *region);
LosVmSpace *LOS_SpaceGet(VADDR_T vaddr);
@@ -281,6 +286,7 @@ STATUS_T LOS_RegionFree(LosVmSpace *space, LosVmMapRegion *region);
STATUS_T LOS_VmSpaceFree(LosVmSpace *space);
STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, size_t len, UINT32 flags);
BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb);
+LosVmSpace *OsCreateUserVmSapce(VOID);
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
STATUS_T LOS_UserSpaceVmAlloc(LosVmSpace *space, size_t size, VOID **ptr, UINT8 align_log2, UINT32 regionFlags);
LosMux *OsGVmSpaceMuxGet(VOID);
diff --git a/kernel/base/include/los_vm_page.h b/kernel/base/include/los_vm_page.h
index d13a190a..bb96b044 100644
--- a/kernel/base/include/los_vm_page.h
+++ b/kernel/base/include/los_vm_page.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -45,7 +45,6 @@ extern "C" {
typedef struct VmPage {
LOS_DL_LIST node; /**< vm object dl list */
- UINT32 index; /**< vm page index to vm object */
PADDR_T physAddr; /**< vm page physical addr */
Atomic refCounts; /**< vm page ref count */
UINT32 flags; /**< vm page flags */
diff --git a/kernel/base/include/los_vm_phys.h b/kernel/base/include/los_vm_phys.h
old mode 100644
new mode 100755
index d8beabe5..8d461d41
--- a/kernel/base/include/los_vm_phys.h
+++ b/kernel/base/include/los_vm_phys.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_shm_pri.h b/kernel/base/include/los_vm_shm_pri.h
index 6c2cd79f..b8a7d1f0 100644
--- a/kernel/base/include/los_vm_shm_pri.h
+++ b/kernel/base/include/los_vm_shm_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_syscall.h b/kernel/base/include/los_vm_syscall.h
index 05448c46..56e1411f 100644
--- a/kernel/base/include/los_vm_syscall.h
+++ b/kernel/base/include/los_vm_syscall.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/include/los_vm_zone.h b/kernel/base/include/los_vm_zone.h
index 0baba0a2..fd9a6b9b 100644
--- a/kernel/base/include/los_vm_zone.h
+++ b/kernel/base/include/los_vm_zone.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,7 +32,7 @@
#ifndef __VM_ZONE_H__
#define __VM_ZONE_H__
-#include "board.h"
+#include "target_config.h"
#ifdef __cplusplus
#if __cplusplus
@@ -40,6 +40,18 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
+#ifdef LOSCFG_TEE_ENABLE
+#define KERNEL_VADDR_BASE 0x41000000
+#else
+#define KERNEL_VADDR_BASE 0x40000000
+#endif
+#define KERNEL_VADDR_SIZE DDR_MEM_SIZE
+
+#define SYS_MEM_BASE DDR_MEM_ADDR
+#define SYS_MEM_END (SYS_MEM_BASE + SYS_MEM_SIZE_DEFAULT)
+
+#define EXC_INTERACT_MEM_SIZE 0x100000
+
#define _U32_C(X) X##U
#define U32_C(X) _U32_C(X)
diff --git a/kernel/base/ipc/los_event.c b/kernel/base/ipc/los_event.c
old mode 100644
new mode 100755
index 92b90d62..a17e3280
--- a/kernel/base/ipc/los_event.c
+++ b/kernel/base/ipc/los_event.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,7 +34,7 @@
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_percpu_pri.h"
-
+#include "los_sched_pri.h"
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#include "los_exc.h"
#endif
@@ -150,9 +150,9 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventM
runTask->eventMask = eventMask;
runTask->eventMode = mode;
runTask->taskEvent = eventCB;
- ret = OsTaskWait(&eventCB->stEventList, timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_EVENT, eventMask, timeout);
+ ret = OsSchedTaskWait(&eventCB->stEventList, timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
- runTask->taskEvent = NULL;
return LOS_ERRNO_EVENT_READ_TIMEOUT;
}
@@ -188,7 +188,8 @@ LITE_OS_SEC_TEXT STATIC UINT8 OsEventResume(LosTaskCB *resumedTask, const PEVENT
exitFlag = 1;
resumedTask->taskEvent = NULL;
- OsTaskWake(resumedTask);
+ OsTaskWakeClearPendMask(resumedTask);
+ OsSchedTaskWake(resumedTask);
}
return exitFlag;
diff --git a/kernel/base/ipc/los_futex.c b/kernel/base/ipc/los_futex.c
old mode 100644
new mode 100755
index 449326d2..5ce2054f
--- a/kernel/base/ipc/los_futex.c
+++ b/kernel/base/ipc/los_futex.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,6 +31,7 @@
#include "los_futex_pri.h"
#include "los_process_pri.h"
+#include "los_hash.h"
#include "los_sys_pri.h"
#include "los_sched_pri.h"
#include "los_mp.h"
@@ -49,12 +50,21 @@ extern "C" {
#define OS_FUTEX_KEY_BASE USER_ASPACE_BASE
#define OS_FUTEX_KEY_MAX (USER_ASPACE_BASE + USER_ASPACE_SIZE)
+/* private: 0~63 hash index_num
+ * shared: 64~79 hash index_num */
+#define FUTEX_INDEX_PRIVATE_MAX 64
+#define FUTEX_INDEX_SHARED_MAX 16
+#define FUTEX_INDEX_MAX (FUTEX_INDEX_PRIVATE_MAX + FUTEX_INDEX_SHARED_MAX)
+
+#define FUTEX_INDEX_SHARED_POS FUTEX_INDEX_PRIVATE_MAX
+#define FUTEX_HASH_PRIVATE_MASK (FUTEX_INDEX_PRIVATE_MAX - 1)
+#define FUTEX_HASH_SHARED_MASK (FUTEX_INDEX_SHARED_MAX - 1)
+
typedef struct {
LosMux listLock;
LOS_DL_LIST lockList;
} FutexHash;
-#define FUTEX_INDEX_MAX 128
FutexHash g_futexHash[FUTEX_INDEX_MAX];
STATIC INT32 OsFutexLock(LosMux *lock)
@@ -102,7 +112,7 @@ STATIC VOID OsFutexShowTaskNodeAttr(const LOS_DL_LIST *futexList)
LOS_DL_LIST *queueList = NULL;
tempNode = OS_FUTEX_FROM_FUTEXLIST(futexList);
- PRINTK("key : 0x%x : ->", tempNode->key);
+ PRINTK("key(pid) : 0x%x(%d) : ->", tempNode->key, tempNode->pid);
for (queueList = &tempNode->queueList; ;) {
lastNode = OS_FUTEX_FROM_QUEUELIST(queueList);
@@ -127,7 +137,7 @@ VOID OsFutexHashShow(VOID)
INT32 count;
/* The maximum number of barrels of a hash table */
INT32 hashNodeMax = FUTEX_INDEX_MAX;
- PRINTK("################los_futex_pri.hash ######################\n");
+ PRINTK("#################### los_futex_pri.hash ####################\n");
for (count = 0; count < hashNodeMax; count++) {
futexList = &(g_futexHash[count].lockList);
if (LOS_ListEmpty(futexList)) {
@@ -143,30 +153,38 @@ VOID OsFutexHashShow(VOID)
}
#endif
-STATIC UINT32 OsFutexGetTick(UINT32 absTime)
+STATIC INLINE UINTPTR OsFutexFlagsToKey(const UINT32 *userVaddr, const UINT32 flags)
{
- UINT32 interval;
+ UINTPTR futexKey;
- /* the values not less than per Millisecond */
- if (absTime < OS_SYS_MS_PER_SECOND) {
- interval = OS_SYS_MS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
+ if (flags & FUTEX_PRIVATE) {
+ futexKey = (UINTPTR)userVaddr;
} else {
- interval = absTime / OS_SYS_MS_PER_SECOND;
+ futexKey = (UINTPTR)LOS_PaddrQuery((UINT32 *)userVaddr);
}
- interval = LOS_MS2Tick(interval);
- if (interval == 0) {
- interval = 1;
- }
-
- return interval;
+ return futexKey;
}
-STATIC INLINE VOID OsFutexSetKey(UINTPTR futexKey, FutexNode *node)
+STATIC INLINE UINT32 OsFutexKeyToIndex(const UINTPTR futexKey, const UINT32 flags)
+{
+ UINT32 index = LOS_HashFNV32aBuf(&futexKey, sizeof(UINTPTR), FNV1_32A_INIT);
+
+ if (flags & FUTEX_PRIVATE) {
+ index &= FUTEX_HASH_PRIVATE_MASK;
+ } else {
+ index &= FUTEX_HASH_SHARED_MASK;
+ index += FUTEX_INDEX_SHARED_POS;
+ }
+
+ return index;
+}
+
+STATIC INLINE VOID OsFutexSetKey(UINTPTR futexKey, UINT32 flags, FutexNode *node)
{
node->key = futexKey;
- node->index = futexKey / OS_FUTEX_KEY_BASE;
- node->pid = LOS_GetCurrProcessID();
+ node->index = OsFutexKeyToIndex(futexKey, flags);
+ node->pid = (flags & FUTEX_PRIVATE) ? LOS_GetCurrProcessID() : OS_INVALID;
}
STATIC INLINE VOID OsFutexDeinitFutexNode(FutexNode *node)
@@ -225,8 +243,8 @@ EXIT:
VOID OsFutexNodeDeleteFromFutexHash(FutexNode *node, BOOL isDeleteHead, FutexNode **headNode, BOOL *queueFlags)
{
FutexHash *hashNode = NULL;
- UINT32 index = node->key / OS_FUTEX_KEY_BASE;
+ UINT32 index = OsFutexKeyToIndex(node->key, (node->pid == OS_INVALID) ? 0 : FUTEX_PRIVATE);
if (index >= FUTEX_INDEX_MAX) {
return;
}
@@ -326,6 +344,9 @@ STATIC INT32 OsFutexInsertFindFormBackToFront(LOS_DL_LIST *queueList, const LosT
for (; listHead != listTail; listTail = listTail->pstPrev) {
tempNode = OS_FUTEX_FROM_QUEUELIST(listTail);
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
+ if (tempNode == NULL) {
+ return LOS_NOK;
+ }
taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
if (runTask->priority >= taskTail->priority) {
LOS_ListHeadInsert(&(tempNode->queueList), &(node->queueList));
@@ -351,6 +372,9 @@ STATIC INT32 OsFutexInsertFindFromFrontToBack(LOS_DL_LIST *queueList, const LosT
for (; listHead != listTail; listHead = listHead->pstNext) {
tempNode = OS_FUTEX_FROM_QUEUELIST(listHead);
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
+ if (tempNode == NULL) {
+ return LOS_NOK;
+ }
taskHead = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
/* High priority comes before low priority,
* in the case of the same priority, after the current node
@@ -465,21 +489,39 @@ STATIC INT32 OsFindAndInsertToHash(FutexNode *node)
return ret;
}
+STATIC INT32 OsFutexKeyShmPermCheck(const UINT32 *userVaddr, const UINT32 flags)
+{
+ PADDR_T paddr;
+
+ /* Check whether the futexKey is a shared lock */
+ if (!(flags & FUTEX_PRIVATE)) {
+ paddr = (UINTPTR)LOS_PaddrQuery((UINT32 *)userVaddr);
+ if (paddr == 0) return LOS_NOK;
+ }
+
+ return LOS_OK;
+}
+
STATIC INT32 OsFutexWaitParamCheck(const UINT32 *userVaddr, UINT32 flags, UINT32 absTime)
{
- UINTPTR futexKey = (UINTPTR)userVaddr;
+ VADDR_T vaddr = (VADDR_T)(UINTPTR)userVaddr;
if (OS_INT_ACTIVE) {
return LOS_EINTR;
}
- if (flags) {
+ if (flags & (~FUTEX_PRIVATE)) {
PRINT_ERR("Futex wait param check failed! error flags: 0x%x\n", flags);
return LOS_EINVAL;
}
- if ((futexKey % sizeof(INT32)) || (futexKey < OS_FUTEX_KEY_BASE) || (futexKey >= OS_FUTEX_KEY_MAX)) {
- PRINT_ERR("Futex wait param check failed! error futex key: 0x%x\n", futexKey);
+ if ((vaddr % sizeof(INT32)) || (vaddr < OS_FUTEX_KEY_BASE) || (vaddr >= OS_FUTEX_KEY_MAX)) {
+ PRINT_ERR("Futex wait param check failed! error userVaddr: 0x%x\n", vaddr);
+ return LOS_EINVAL;
+ }
+
+ if (flags && (OsFutexKeyShmPermCheck(userVaddr, flags) != LOS_OK)) {
+ PRINT_ERR("Futex wait param check failed! error shared memory perm userVaddr: 0x%x\n", userVaddr);
return LOS_EINVAL;
}
@@ -514,12 +556,12 @@ STATIC INT32 OsFutexDeleteTimeoutTaskNode(FutexHash *hashNode, FutexNode *node)
return LOS_ETIMEDOUT;
}
-STATIC INT32 OsFutexInserTaskToHash(LosTaskCB **taskCB, FutexNode **node, const UINTPTR futexKey)
+STATIC INT32 OsFutexInsertTaskToHash(LosTaskCB **taskCB, FutexNode **node, const UINTPTR futexKey, const UINT32 flags)
{
INT32 ret;
*taskCB = OsCurrTaskGet();
*node = &((*taskCB)->futex);
- OsFutexSetKey(futexKey, *node);
+ OsFutexSetKey(futexKey, flags, *node);
ret = OsFindAndInsertToHash(*node);
if (ret) {
@@ -530,14 +572,14 @@ STATIC INT32 OsFutexInserTaskToHash(LosTaskCB **taskCB, FutexNode **node, const
return LOS_OK;
}
-STATIC INT32 OsFutexWaitTask(const UINT32 timeOut, const UINT32 *userVaddr, UINT32 val)
+STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const UINT32 val, const UINT32 timeOut)
{
INT32 futexRet;
UINT32 intSave, lockVal;
LosTaskCB *taskCB = NULL;
FutexNode *node = NULL;
- UINTPTR futexKey = (UINTPTR)userVaddr;
- UINT32 index = futexKey / OS_FUTEX_KEY_BASE;
+ UINTPTR futexKey = OsFutexFlagsToKey(userVaddr, flags);
+ UINT32 index = OsFutexKeyToIndex(futexKey, flags);
FutexHash *hashNode = &g_futexHash[index];
if (OsFutexLock(&hashNode->listLock)) {
@@ -555,12 +597,14 @@ STATIC INT32 OsFutexWaitTask(const UINT32 timeOut, const UINT32 *userVaddr, UINT
goto EXIT_ERR;
}
- if (OsFutexInserTaskToHash(&taskCB, &node, futexKey)) {
+ if (OsFutexInsertTaskToHash(&taskCB, &node, futexKey, flags)) {
futexRet = LOS_NOK;
goto EXIT_ERR;
}
+
SCHEDULER_LOCK(intSave);
- OsTaskWait(&(node->pendList), timeOut, FALSE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_FUTEX, futexKey, timeOut);
+ OsSchedTaskWait(&(node->pendList), timeOut, FALSE);
OsPercpuGet()->taskLockCnt++;
LOS_SpinUnlock(&g_taskSpin);
@@ -605,10 +649,32 @@ INT32 OsFutexWait(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absT
return ret;
}
if (absTime != LOS_WAIT_FOREVER) {
- timeOut = OsFutexGetTick(absTime);
+ timeOut = OsUS2Tick(absTime);
}
- return OsFutexWaitTask(timeOut, userVaddr, val);
+ return OsFutexWaitTask(userVaddr, flags, val, timeOut);
+}
+
+STATIC INT32 OsFutexWakeParamCheck(const UINT32 *userVaddr, UINT32 flags)
+{
+ VADDR_T vaddr = (VADDR_T)(UINTPTR)userVaddr;
+
+ if ((flags & (~FUTEX_PRIVATE)) != FUTEX_WAKE) {
+ PRINT_ERR("Futex wake param check failed! error flags: 0x%x\n", flags);
+ return LOS_EINVAL;
+ }
+
+ if ((vaddr % sizeof(INT32)) || (vaddr < OS_FUTEX_KEY_BASE) || (vaddr >= OS_FUTEX_KEY_MAX)) {
+ PRINT_ERR("Futex wake param check failed! error userVaddr: 0x%x\n", userVaddr);
+ return LOS_EINVAL;
+ }
+
+ if (flags && (OsFutexKeyShmPermCheck(userVaddr, flags) != LOS_OK)) {
+ PRINT_ERR("Futex wake param check failed! error shared memory perm userVaddr: 0x%x\n", userVaddr);
+ return LOS_EINVAL;
+ }
+
+ return LOS_OK;
}
/* Check to see if the task to be awakened has timed out
@@ -629,7 +695,8 @@ STATIC VOID OsFutexCheckAndWakePendTask(FutexNode *headNode, const INT32 wakeNum
}
node = *nextNode;
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(node->pendList)));
- OsTaskWake(taskCB);
+ OsTaskWakeClearPendMask(taskCB);
+ OsSchedTaskWake(taskCB);
*wakeAny = TRUE;
*nextNode = OS_FUTEX_FROM_QUEUELIST(LOS_DL_LIST_FIRST(&(node->queueList)));
if (node != headNode) {
@@ -647,17 +714,17 @@ STATIC VOID OsFutexCheckAndWakePendTask(FutexNode *headNode, const INT32 wakeNum
return;
}
-STATIC INT32 OsFutexWakeTask(UINTPTR futexKey, INT32 wakeNumber, FutexNode **newHeadNode, BOOL *wakeAny)
+STATIC INT32 OsFutexWakeTask(UINTPTR futexKey, UINT32 flags, INT32 wakeNumber, FutexNode **newHeadNode, BOOL *wakeAny)
{
UINT32 intSave;
FutexNode *node = NULL;
FutexNode *headNode = NULL;
- UINT32 index = futexKey / OS_FUTEX_KEY_BASE;
+ UINT32 index = OsFutexKeyToIndex(futexKey, flags);
FutexHash *hashNode = &g_futexHash[index];
FutexNode tempNode = {
.key = futexKey,
.index = index,
- .pid = LOS_GetCurrProcessID(),
+ .pid = (flags & FUTEX_PRIVATE) ? LOS_GetCurrProcessID() : OS_INVALID,
};
node = OsFindFutexNode(&tempNode);
@@ -684,28 +751,25 @@ STATIC INT32 OsFutexWakeTask(UINTPTR futexKey, INT32 wakeNumber, FutexNode **new
INT32 OsFutexWake(const UINT32 *userVaddr, UINT32 flags, INT32 wakeNumber)
{
INT32 ret, futexRet;
- UINTPTR futexKey = (UINTPTR)userVaddr;
+ UINTPTR futexKey;
+ UINT32 index;
FutexHash *hashNode = NULL;
- INT32 index = futexKey / OS_FUTEX_KEY_BASE;
FutexNode *headNode = NULL;
BOOL wakeAny = FALSE;
- if (!(flags & FUTEX_WAKE)) {
- PRINT_ERR("Futex wake param check failed! error flags: 0x%x\n", flags);
+ if (OsFutexWakeParamCheck(userVaddr, flags)) {
return LOS_EINVAL;
}
- if ((futexKey % sizeof(INT32)) || (futexKey < OS_FUTEX_KEY_BASE) || (futexKey >= OS_FUTEX_KEY_MAX)) {
- PRINT_ERR("Futex wake param check failed! error futex key: 0x%x\n", futexKey);
- return LOS_EINVAL;
- }
+ futexKey = OsFutexFlagsToKey(userVaddr, flags);
+ index = OsFutexKeyToIndex(futexKey, flags);
hashNode = &g_futexHash[index];
if (OsFutexLock(&hashNode->listLock)) {
return LOS_EINVAL;
}
- ret = OsFutexWakeTask(futexKey, wakeNumber, &headNode, &wakeAny);
+ ret = OsFutexWakeTask(futexKey, flags, wakeNumber, &headNode, &wakeAny);
if (ret) {
goto EXIT_ERR;
}
@@ -744,7 +808,7 @@ STATIC INT32 OsFutexRequeueInsertNewKey(UINTPTR newFutexKey, INT32 newIndex, Fut
FutexNode newTempNode = {
.key = newFutexKey,
.index = newIndex,
- .pid = LOS_GetCurrProcessID(),
+ .pid = (newIndex < FUTEX_INDEX_SHARED_POS) ? LOS_GetCurrProcessID() : OS_INVALID,
};
LOS_DL_LIST *queueList = &oldHeadNode->queueList;
FutexNode *newHeadNode = OsFindFutexNode(&newTempNode);
@@ -780,15 +844,16 @@ STATIC INT32 OsFutexRequeueInsertNewKey(UINTPTR newFutexKey, INT32 newIndex, Fut
return LOS_OK;
}
-STATIC VOID OsFutexRequeueSplitTwoLists(FutexHash *oldHashNode, FutexNode *oldHeadNode, UINTPTR futexKey, INT32 count)
+STATIC VOID OsFutexRequeueSplitTwoLists(FutexHash *oldHashNode, FutexNode *oldHeadNode,
+ UINT32 flags, UINTPTR futexKey, INT32 count)
{
LOS_DL_LIST *queueList = &oldHeadNode->queueList;
FutexNode *tailNode = OS_FUTEX_FROM_QUEUELIST(LOS_DL_LIST_LAST(queueList));
- INT32 newIndex = futexKey / OS_FUTEX_KEY_BASE;
+ INT32 newIndex = OsFutexKeyToIndex(futexKey, flags);
FutexNode *nextNode = NULL;
FutexNode *newHeadNode = NULL;
LOS_DL_LIST *futexList = NULL;
- BOOL IsAll = FALSE;
+ BOOL isAll = FALSE;
INT32 i;
for (i = 0; i < count; i++) {
@@ -796,7 +861,7 @@ STATIC VOID OsFutexRequeueSplitTwoLists(FutexHash *oldHashNode, FutexNode *oldHe
nextNode->key = futexKey;
nextNode->index = newIndex;
if (queueList->pstNext == &oldHeadNode->queueList) {
- IsAll = TRUE;
+ isAll = TRUE;
break;
}
@@ -805,7 +870,7 @@ STATIC VOID OsFutexRequeueSplitTwoLists(FutexHash *oldHashNode, FutexNode *oldHe
futexList = oldHeadNode->futexList.pstPrev;
LOS_ListDelete(&oldHeadNode->futexList);
- if (IsAll == TRUE) {
+ if (isAll == TRUE) {
return;
}
@@ -818,21 +883,21 @@ STATIC VOID OsFutexRequeueSplitTwoLists(FutexHash *oldHashNode, FutexNode *oldHe
return;
}
-STATIC FutexNode *OsFutexRequeueRemoveOldKeyAndGetHead(UINTPTR oldFutexKey, INT32 wakeNumber,
+STATIC FutexNode *OsFutexRequeueRemoveOldKeyAndGetHead(UINTPTR oldFutexKey, UINT32 flags, INT32 wakeNumber,
UINTPTR newFutexKey, INT32 requeueCount, BOOL *wakeAny)
{
INT32 ret;
+ INT32 oldIndex = OsFutexKeyToIndex(oldFutexKey, flags);
FutexNode *oldHeadNode = NULL;
- INT32 oldIndex = oldFutexKey / OS_FUTEX_KEY_BASE;
FutexHash *oldHashNode = &g_futexHash[oldIndex];
FutexNode oldTempNode = {
.key = oldFutexKey,
.index = oldIndex,
- .pid = LOS_GetCurrProcessID(),
+ .pid = (flags & FUTEX_PRIVATE) ? LOS_GetCurrProcessID() : OS_INVALID,
};
if (wakeNumber > 0) {
- ret = OsFutexWakeTask(oldFutexKey, wakeNumber, &oldHeadNode, wakeAny);
+ ret = OsFutexWakeTask(oldFutexKey, flags, wakeNumber, &oldHeadNode, wakeAny);
if ((ret != LOS_OK) || (oldHeadNode == NULL)) {
return NULL;
}
@@ -849,24 +914,32 @@ STATIC FutexNode *OsFutexRequeueRemoveOldKeyAndGetHead(UINTPTR oldFutexKey, INT3
}
}
- OsFutexRequeueSplitTwoLists(oldHashNode, oldHeadNode, newFutexKey, requeueCount);
+ OsFutexRequeueSplitTwoLists(oldHashNode, oldHeadNode, flags, newFutexKey, requeueCount);
return oldHeadNode;
}
-STATIC INT32 OsFutexRequeueParamCheck(UINTPTR oldFutexKey, UINTPTR newFutexKey)
+STATIC INT32 OsFutexRequeueParamCheck(const UINT32 *oldUserVaddr, UINT32 flags, const UINT32 *newUserVaddr)
{
- if (oldFutexKey == newFutexKey) {
+ VADDR_T oldVaddr = (VADDR_T)(UINTPTR)oldUserVaddr;
+ VADDR_T newVaddr = (VADDR_T)(UINTPTR)newUserVaddr;
+
+ if (oldVaddr == newVaddr) {
return LOS_EINVAL;
}
- if ((oldFutexKey % sizeof(INT32)) || (oldFutexKey < OS_FUTEX_KEY_BASE) || (oldFutexKey >= OS_FUTEX_KEY_MAX)) {
- PRINT_ERR("Futex requeue param check failed! error old futex key: 0x%x\n", oldFutexKey);
+ if ((flags & (~FUTEX_PRIVATE)) != FUTEX_REQUEUE) {
+ PRINT_ERR("Futex requeue param check failed! error flags: 0x%x\n", flags);
return LOS_EINVAL;
}
- if ((newFutexKey % sizeof(INT32)) || (newFutexKey < OS_FUTEX_KEY_BASE) || (newFutexKey >= OS_FUTEX_KEY_MAX)) {
- PRINT_ERR("Futex requeue param check failed! error new futex key: 0x%x\n", newFutexKey);
+ if ((oldVaddr % sizeof(INT32)) || (oldVaddr < OS_FUTEX_KEY_BASE) || (oldVaddr >= OS_FUTEX_KEY_MAX)) {
+ PRINT_ERR("Futex requeue param check failed! error old userVaddr: 0x%x\n", oldUserVaddr);
+ return LOS_EINVAL;
+ }
+
+ if ((newVaddr % sizeof(INT32)) || (newVaddr < OS_FUTEX_KEY_BASE) || (newVaddr >= OS_FUTEX_KEY_MAX)) {
+ PRINT_ERR("Futex requeue param check failed! error new userVaddr: 0x%x\n", newUserVaddr);
return LOS_EINVAL;
}
@@ -876,25 +949,30 @@ STATIC INT32 OsFutexRequeueParamCheck(UINTPTR oldFutexKey, UINTPTR newFutexKey)
INT32 OsFutexRequeue(const UINT32 *userVaddr, UINT32 flags, INT32 wakeNumber, INT32 count, const UINT32 *newUserVaddr)
{
INT32 ret;
- UINTPTR oldFutexKey = (UINTPTR)userVaddr;
- UINTPTR newFutexKey = (UINTPTR)newUserVaddr;
- INT32 oldIndex = oldFutexKey / OS_FUTEX_KEY_BASE;
- INT32 newIndex = newFutexKey / OS_FUTEX_KEY_BASE;
+ UINTPTR oldFutexKey;
+ UINTPTR newFutexKey;
+ INT32 oldIndex;
+ INT32 newIndex;
FutexHash *oldHashNode = NULL;
FutexHash *newHashNode = NULL;
FutexNode *oldHeadNode = NULL;
BOOL wakeAny = FALSE;
- if (OsFutexRequeueParamCheck(oldFutexKey, newFutexKey)) {
+ if (OsFutexRequeueParamCheck(userVaddr, flags, newUserVaddr)) {
return LOS_EINVAL;
}
+ oldFutexKey = OsFutexFlagsToKey(userVaddr, flags);
+ newFutexKey = OsFutexFlagsToKey(newUserVaddr, flags);
+ oldIndex = OsFutexKeyToIndex(oldFutexKey, flags);
+ newIndex = OsFutexKeyToIndex(newFutexKey, flags);
+
oldHashNode = &g_futexHash[oldIndex];
if (OsFutexLock(&oldHashNode->listLock)) {
return LOS_EINVAL;
}
- oldHeadNode = OsFutexRequeueRemoveOldKeyAndGetHead(oldFutexKey, wakeNumber, newFutexKey, count, &wakeAny);
+ oldHeadNode = OsFutexRequeueRemoveOldKeyAndGetHead(oldFutexKey, flags, wakeNumber, newFutexKey, count, &wakeAny);
if (oldHeadNode == NULL) {
(VOID)OsFutexUnlock(&oldHashNode->listLock);
if (wakeAny == TRUE) {
diff --git a/kernel/base/ipc/los_ipcdebug.c b/kernel/base/ipc/los_ipcdebug.c
index 64220900..1017b094 100644
--- a/kernel/base/ipc/los_ipcdebug.c
+++ b/kernel/base/ipc/los_ipcdebug.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/ipc/los_mux.c b/kernel/base/ipc/los_mux.c
old mode 100644
new mode 100755
index 2b825104..f74f2726
--- a/kernel/base/ipc/los_mux.c
+++ b/kernel/base/ipc/los_mux.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,6 +35,7 @@
#include "los_mp.h"
#include "los_task_pri.h"
#include "los_exc.h"
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -265,7 +266,7 @@ STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask, LosTas
{
if ((owner->priority > runTask->priority) && (mutex->attr.protocol == LOS_MUX_PRIO_INHERIT)) {
LOS_BitmapSet(&(owner->priBitMap), owner->priority);
- OsTaskPriModify(owner, runTask->priority);
+ (VOID)OsSchedModifyTaskSchedParam(owner, owner->policy, runTask->priority);
}
}
@@ -281,7 +282,7 @@ VOID OsMuxBitmapRestore(const LosMux *mutex, const LosTaskCB *taskCB, LosTaskCB
bitMapPri = LOS_LowBitGet(owner->priBitMap);
if (bitMapPri != LOS_INVALID_BIT_INDEX) {
LOS_BitmapClr(&(owner->priBitMap), bitMapPri);
- OsTaskPriModify(owner, bitMapPri);
+ OsSchedModifyTaskSchedParam(owner, owner->policy, bitMapPri);
}
} else {
if (LOS_HighBitGet(owner->priBitMap) != taskCB->priority) {
@@ -290,49 +291,6 @@ VOID OsMuxBitmapRestore(const LosMux *mutex, const LosTaskCB *taskCB, LosTaskCB
}
}
-STATIC LOS_DL_LIST *OsMuxPendFindPosSub(const LosTaskCB *runTask, const LosMux *mutex)
-{
- LosTaskCB *pendedTask = NULL;
- LOS_DL_LIST *node = NULL;
-
- LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, &(mutex->muxList), LosTaskCB, pendList) {
- if (pendedTask->priority < runTask->priority) {
- continue;
- } else if (pendedTask->priority > runTask->priority) {
- node = &pendedTask->pendList;
- break;
- } else {
- node = pendedTask->pendList.pstNext;
- break;
- }
- }
-
- return node;
-}
-
-STATIC LOS_DL_LIST *OsMuxPendFindPos(const LosTaskCB *runTask, LosMux *mutex)
-{
- LosTaskCB *pendedTask1 = NULL;
- LosTaskCB *pendedTask2 = NULL;
- LOS_DL_LIST *node = NULL;
-
- if (LOS_ListEmpty(&mutex->muxList)) {
- node = &mutex->muxList;
- } else {
- pendedTask1 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&mutex->muxList));
- pendedTask2 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_LAST(&mutex->muxList));
- if ((pendedTask1 != NULL) && (pendedTask1->priority > runTask->priority)) {
- node = mutex->muxList.pstNext;
- } else if ((pendedTask2 != NULL) && (pendedTask2->priority <= runTask->priority)) {
- node = &mutex->muxList;
- } else {
- node = OsMuxPendFindPosSub(runTask, mutex);
- }
- }
-
- return node;
-}
-
STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
{
UINT32 ret;
@@ -350,9 +308,9 @@ STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
mutex->muxCount++;
mutex->owner = (VOID *)runTask;
LOS_ListTailInsert(&runTask->lockList, &mutex->holdList);
- if ((runTask->priority > mutex->attr.prioceiling) && (mutex->attr.protocol == LOS_MUX_PRIO_PROTECT)) {
+ if ((mutex->attr.protocol == LOS_MUX_PRIO_PROTECT) && (runTask->priority > mutex->attr.prioceiling)) {
LOS_BitmapSet(&runTask->priBitMap, runTask->priority);
- OsTaskPriModify(runTask, mutex->attr.prioceiling);
+ (VOID)OsSchedModifyTaskSchedParam(runTask, runTask->policy, mutex->attr.prioceiling);
}
return LOS_OK;
}
@@ -374,9 +332,14 @@ STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
owner = (LosTaskCB *)mutex->owner;
runTask->taskMux = (VOID *)mutex;
- node = OsMuxPendFindPos(runTask, mutex);
+ node = OsSchedLockPendFindPos(runTask, &mutex->muxList);
+ if (node == NULL) {
+ ret = LOS_NOK;
+ return ret;
+ }
- ret = OsTaskWait(node, timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_MUTEX, (UINTPTR)mutex, timeout);
+ ret = OsSchedTaskWait(node, timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
runTask->taskMux = NULL;
ret = LOS_ETIMEDOUT;
@@ -401,7 +364,7 @@ UINT32 OsMuxLockUnsafe(LosMux *mutex, UINT32 timeout)
return LOS_EINVAL;
}
- if ((mutex->attr.type == LOS_MUX_ERRORCHECK) && (mutex->muxCount != 0) && (mutex->owner == (VOID *)runTask)) {
+ if ((mutex->attr.type == LOS_MUX_ERRORCHECK) && (mutex->owner == (VOID *)runTask)) {
return LOS_EDEADLK;
}
@@ -420,10 +383,8 @@ UINT32 OsMuxTrylockUnsafe(LosMux *mutex, UINT32 timeout)
return LOS_EINVAL;
}
- if ((mutex->owner != NULL) && ((LosTaskCB *)mutex->owner != runTask)) {
- return LOS_EBUSY;
- }
- if ((mutex->attr.type != LOS_MUX_RECURSIVE) && (mutex->muxCount != 0)) {
+ if ((mutex->owner != NULL) &&
+ (((LosTaskCB *)mutex->owner != runTask) || (mutex->attr.type != LOS_MUX_RECURSIVE))) {
return LOS_EBUSY;
}
@@ -499,7 +460,7 @@ STATIC VOID OsMuxPostOpSub(LosTaskCB *taskCB, LosMux *mutex)
}
bitMapPri = LOS_LowBitGet(taskCB->priBitMap);
LOS_BitmapClr(&taskCB->priBitMap, bitMapPri);
- OsTaskPriModify((LosTaskCB *)mutex->owner, bitMapPri);
+ (VOID)OsSchedModifyTaskSchedParam((LosTaskCB *)mutex->owner, ((LosTaskCB *)mutex->owner)->policy, bitMapPri);
}
STATIC UINT32 OsMuxPostOp(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
@@ -524,10 +485,11 @@ STATIC UINT32 OsMuxPostOp(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
}
mutex->muxCount = 1;
mutex->owner = (VOID *)resumedTask;
- resumedTask->taskMux = NULL;
LOS_ListDelete(&mutex->holdList);
LOS_ListTailInsert(&resumedTask->lockList, &mutex->holdList);
- OsTaskWake(resumedTask);
+ OsTaskWakeClearPendMask(resumedTask);
+ OsSchedTaskWake(resumedTask);
+ resumedTask->taskMux = NULL;
if (needSched != NULL) {
*needSched = TRUE;
}
@@ -547,11 +509,11 @@ UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
return LOS_EINVAL;
}
- if (mutex->muxCount == 0) {
+ if ((LosTaskCB *)mutex->owner != taskCB) {
return LOS_EPERM;
}
- if ((LosTaskCB *)mutex->owner != taskCB) {
+ if (mutex->muxCount == 0) {
return LOS_EPERM;
}
@@ -563,7 +525,7 @@ UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
bitMapPri = LOS_HighBitGet(taskCB->priBitMap);
if (bitMapPri != LOS_INVALID_BIT_INDEX) {
LOS_BitmapClr(&taskCB->priBitMap, bitMapPri);
- OsTaskPriModify(taskCB, bitMapPri);
+ (VOID)OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, bitMapPri);
}
}
diff --git a/kernel/base/ipc/los_queue.c b/kernel/base/ipc/los_queue.c
old mode 100644
new mode 100755
index fc0487b2..51e2b789
--- a/kernel/base/ipc/los_queue.c
+++ b/kernel/base/ipc/los_queue.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,6 +32,7 @@
#include "los_queue_pri.h"
#include "los_queue_debug_pri.h"
#include "los_task_pri.h"
+#include "los_sched_pri.h"
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_percpu_pri.h"
@@ -286,7 +287,8 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
goto QUEUE_END;
}
- ret = OsTaskWait(&queueCB->readWriteList[readWrite], timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_QUEUE, queueCB->queueID, timeout);
+ ret = OsSchedTaskWait(&queueCB->readWriteList[readWrite], timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
ret = LOS_ERRNO_QUEUE_TIMEOUT;
goto QUEUE_END;
@@ -299,7 +301,8 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
if (!LOS_ListEmpty(&queueCB->readWriteList[!readWrite])) {
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[!readWrite]));
- OsTaskWake(resumedTask);
+ OsTaskWakeClearPendMask(resumedTask);
+ OsSchedTaskWake(resumedTask);
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
LOS_Schedule();
diff --git a/kernel/base/ipc/los_queue_debug.c b/kernel/base/ipc/los_queue_debug.c
index 3543b006..8807ae75 100644
--- a/kernel/base/ipc/los_queue_debug.c
+++ b/kernel/base/ipc/los_queue_debug.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/ipc/los_rwlock.c b/kernel/base/ipc/los_rwlock.c
new file mode 100755
index 00000000..0cb06bda
--- /dev/null
+++ b/kernel/base/ipc/los_rwlock.c
@@ -0,0 +1,474 @@
+/*
+ * 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_rwlock_pri.h"
+#include "stdint.h"
+#include "los_spinlock.h"
+#include "los_mp.h"
+#include "los_task_pri.h"
+#include "los_exc.h"
+#include "los_sched_pri.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+#ifdef LOSCFG_BASE_IPC_RWLOCK
+#define RWLOCK_COUNT_MASK 0x00FFFFFFU
+
+BOOL LOS_RwlockIsValid(const LosRwlock *rwlock)
+{
+ if ((rwlock != NULL) && ((rwlock->magic & RWLOCK_COUNT_MASK) == OS_RWLOCK_MAGIC)) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+UINT32 LOS_RwlockInit(LosRwlock *rwlock)
+{
+ UINT32 intSave;
+
+ if (rwlock == NULL) {
+ return LOS_EINVAL;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) == OS_RWLOCK_MAGIC) {
+ SCHEDULER_UNLOCK(intSave);
+ return LOS_EPERM;
+ }
+
+ rwlock->rwCount = 0;
+ rwlock->writeOwner = NULL;
+ LOS_ListInit(&(rwlock->readList));
+ LOS_ListInit(&(rwlock->writeList));
+ rwlock->magic = OS_RWLOCK_MAGIC;
+ SCHEDULER_UNLOCK(intSave);
+ return LOS_OK;
+}
+
+UINT32 LOS_RwlockDestroy(LosRwlock *rwlock)
+{
+ UINT32 intSave;
+
+ if (rwlock == NULL) {
+ return LOS_EINVAL;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ SCHEDULER_UNLOCK(intSave);
+ return LOS_EBADF;
+ }
+
+ if (rwlock->rwCount != 0) {
+ SCHEDULER_UNLOCK(intSave);
+ return LOS_EBUSY;
+ }
+
+ (VOID)memset_s(rwlock, sizeof(LosRwlock), 0, sizeof(LosRwlock));
+ SCHEDULER_UNLOCK(intSave);
+ return LOS_OK;
+}
+
+STATIC UINT32 OsRwlockCheck(LosRwlock *rwlock)
+{
+ if (rwlock == NULL) {
+ return LOS_EINVAL;
+ }
+
+ if (OS_INT_ACTIVE) {
+ return LOS_EINTR;
+ }
+
+ /* DO NOT Call blocking API in system tasks */
+ LosTaskCB *runTask = (LosTaskCB *)OsCurrTaskGet();
+ if (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
+ return LOS_EPERM;
+ }
+
+ return LOS_OK;
+}
+
+STATIC BOOL OsRwlockPriCompare(LosTaskCB *runTask, LOS_DL_LIST *rwList)
+{
+ if (!LOS_ListEmpty(rwList)) {
+ LosTaskCB *highestTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(rwList));
+ if (runTask->priority < highestTask->priority) {
+ return TRUE;
+ }
+ return FALSE;
+ }
+ return TRUE;
+}
+
+STATIC UINT32 OsRwlockRdPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 timeout)
+{
+ UINT32 ret;
+
+ /*
+ * When the rwlock mode is read mode or free mode and the priority of the current read task
+ * is higher than the first pended write task. current read task can obtain this rwlock.
+ */
+ if (rwlock->rwCount >= 0) {
+ if (OsRwlockPriCompare(runTask, &(rwlock->writeList))) {
+ if (rwlock->rwCount == INT8_MAX) {
+ return LOS_EINVAL;
+ }
+ rwlock->rwCount++;
+ return LOS_OK;
+ }
+ }
+
+ if (!timeout) {
+ return LOS_EINVAL;
+ }
+
+ if (!OsPreemptableInSched()) {
+ return LOS_EDEADLK;
+ }
+
+ /* The current task is not allowed to obtain the write lock when it obtains the read lock. */
+ if ((LosTaskCB *)(rwlock->writeOwner) == runTask) {
+ return LOS_EINVAL;
+ }
+
+ /*
+ * When the rwlock mode is write mode or the priority of the current read task
+ * is lower than the first pended write task, current read task will be pended.
+ */
+ LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->readList));
+ ret = OsSchedTaskWait(node, timeout, TRUE);
+ if (ret == LOS_ERRNO_TSK_TIMEOUT) {
+ return LOS_ETIMEDOUT;
+ }
+
+ return ret;
+}
+
+STATIC UINT32 OsRwlockWrPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 timeout)
+{
+ UINT32 ret;
+
+ /* When the rwlock is free mode, current write task can obtain this rwlock. */
+ if (rwlock->rwCount == 0) {
+ rwlock->rwCount = -1;
+ rwlock->writeOwner = (VOID *)runTask;
+ return LOS_OK;
+ }
+
+ /* Current write task can use one rwlock once again if the rwlock owner is it. */
+ if ((rwlock->rwCount < 0) && ((LosTaskCB *)(rwlock->writeOwner) == runTask)) {
+ if (rwlock->rwCount == INT8_MIN) {
+ return LOS_EINVAL;
+ }
+ rwlock->rwCount--;
+ return LOS_OK;
+ }
+
+ if (!timeout) {
+ return LOS_EINVAL;
+ }
+
+ if (!OsPreemptableInSched()) {
+ return LOS_EDEADLK;
+ }
+
+ /*
+ * When the rwlock is read mode or other write task obtains this rwlock, current
+ * write task will be pended.
+ */
+ LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->writeList));
+ ret = OsSchedTaskWait(node, timeout, TRUE);
+ if (ret == LOS_ERRNO_TSK_TIMEOUT) {
+ ret = LOS_ETIMEDOUT;
+ }
+
+ return ret;
+}
+
+UINT32 OsRwlockRdUnsafe(LosRwlock *rwlock, UINT32 timeout)
+{
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ return LOS_EBADF;
+ }
+
+ return OsRwlockRdPendOp(OsCurrTaskGet(), rwlock, timeout);
+}
+
+UINT32 OsRwlockTryRdUnsafe(LosRwlock *rwlock, UINT32 timeout)
+{
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ return LOS_EBADF;
+ }
+
+ LosTaskCB *runTask = OsCurrTaskGet();
+ if ((LosTaskCB *)(rwlock->writeOwner) == runTask) {
+ return LOS_EINVAL;
+ }
+
+ /*
+ * When the rwlock mode is read mode or free mode and the priority of the current read task
+ * is lower than the first pended write task, current read task can not obtain the rwlock.
+ */
+ if ((rwlock->rwCount >= 0) && !OsRwlockPriCompare(runTask, &(rwlock->writeList))) {
+ return LOS_EBUSY;
+ }
+
+ /*
+ * When the rwlock mode is write mode, current read task can not obtain the rwlock.
+ */
+ if (rwlock->rwCount < 0) {
+ return LOS_EBUSY;
+ }
+
+ return OsRwlockRdPendOp(runTask, rwlock, timeout);
+}
+
+UINT32 OsRwlockWrUnsafe(LosRwlock *rwlock, UINT32 timeout)
+{
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ return LOS_EBADF;
+ }
+
+ return OsRwlockWrPendOp(OsCurrTaskGet(), rwlock, timeout);
+}
+
+UINT32 OsRwlockTryWrUnsafe(LosRwlock *rwlock, UINT32 timeout)
+{
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ return LOS_EBADF;
+ }
+
+ /* When the rwlock is read mode, current write task will be pended. */
+ if (rwlock->rwCount > 0) {
+ return LOS_EBUSY;
+ }
+
+ /* When other write task obtains this rwlock, current write task will be pended. */
+ LosTaskCB *runTask = OsCurrTaskGet();
+ if ((rwlock->rwCount < 0) && ((LosTaskCB *)(rwlock->writeOwner) != runTask)) {
+ return LOS_EBUSY;
+ }
+
+ return OsRwlockWrPendOp(runTask, rwlock, timeout);
+}
+
+UINT32 LOS_RwlockRdLock(LosRwlock *rwlock, UINT32 timeout)
+{
+ UINT32 intSave;
+
+ UINT32 ret = OsRwlockCheck(rwlock);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsRwlockRdUnsafe(rwlock, timeout);
+ SCHEDULER_UNLOCK(intSave);
+ return ret;
+}
+
+UINT32 LOS_RwlockTryRdLock(LosRwlock *rwlock)
+{
+ UINT32 intSave;
+
+ UINT32 ret = OsRwlockCheck(rwlock);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsRwlockTryRdUnsafe(rwlock, 0);
+ SCHEDULER_UNLOCK(intSave);
+ return ret;
+}
+
+UINT32 LOS_RwlockWrLock(LosRwlock *rwlock, UINT32 timeout)
+{
+ UINT32 intSave;
+
+ UINT32 ret = OsRwlockCheck(rwlock);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsRwlockWrUnsafe(rwlock, timeout);
+ SCHEDULER_UNLOCK(intSave);
+ return ret;
+}
+
+UINT32 LOS_RwlockTryWrLock(LosRwlock *rwlock)
+{
+ UINT32 intSave;
+
+ UINT32 ret = OsRwlockCheck(rwlock);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsRwlockTryWrUnsafe(rwlock, 0);
+ SCHEDULER_UNLOCK(intSave);
+ return ret;
+}
+
+STATIC UINT32 OsRwlockGetMode(LOS_DL_LIST *readList, LOS_DL_LIST *writeList)
+{
+ BOOL isReadEmpty = LOS_ListEmpty(readList);
+ BOOL isWriteEmpty = LOS_ListEmpty(writeList);
+ if (isReadEmpty && isWriteEmpty) {
+ return RWLOCK_NONE_MODE;
+ }
+ if (!isReadEmpty && isWriteEmpty) {
+ return RWLOCK_READ_MODE;
+ }
+ if (isReadEmpty && !isWriteEmpty) {
+ return RWLOCK_WRITE_MODE;
+ }
+ LosTaskCB *pendedReadTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(readList));
+ LosTaskCB *pendedWriteTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(writeList));
+ if (pendedWriteTask->priority <= pendedReadTask->priority) {
+ return RWLOCK_WRITEFIRST_MODE;
+ }
+ return RWLOCK_READFIRST_MODE;
+}
+
+STATIC UINT32 OsRwlockPostOp(LosRwlock *rwlock, BOOL *needSched)
+{
+ UINT32 rwlockMode;
+ LosTaskCB *resumedTask = NULL;
+ UINT16 pendedWriteTaskPri;
+
+ rwlock->rwCount = 0;
+ rwlock->writeOwner = NULL;
+ rwlockMode = OsRwlockGetMode(&(rwlock->readList), &(rwlock->writeList));
+ if (rwlockMode == RWLOCK_NONE_MODE) {
+ return LOS_OK;
+ }
+ /* In this case, rwlock will wake the first pended write task. */
+ if ((rwlockMode == RWLOCK_WRITE_MODE) || (rwlockMode == RWLOCK_WRITEFIRST_MODE)) {
+ resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)));
+ rwlock->rwCount = -1;
+ rwlock->writeOwner = (VOID *)resumedTask;
+ OsSchedTaskWake(resumedTask);
+ if (needSched != NULL) {
+ *needSched = TRUE;
+ }
+ return LOS_OK;
+ }
+ /* In this case, rwlock will wake the valid pended read task. */
+ if (rwlockMode == RWLOCK_READFIRST_MODE) {
+ pendedWriteTaskPri = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)))->priority;
+ }
+ resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
+ rwlock->rwCount = 1;
+ OsSchedTaskWake(resumedTask);
+ while (!LOS_ListEmpty(&(rwlock->readList))) {
+ resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
+ if ((rwlockMode == RWLOCK_READFIRST_MODE) && (resumedTask->priority >= pendedWriteTaskPri)) {
+ break;
+ }
+ if (rwlock->rwCount == INT8_MAX) {
+ return EINVAL;
+ }
+ rwlock->rwCount++;
+ OsSchedTaskWake(resumedTask);
+ }
+ if (needSched != NULL) {
+ *needSched = TRUE;
+ }
+ return LOS_OK;
+}
+
+UINT32 OsRwlockUnlockUnsafe(LosRwlock *rwlock, BOOL *needSched)
+{
+ if ((rwlock->magic & RWLOCK_COUNT_MASK) != OS_RWLOCK_MAGIC) {
+ return LOS_EBADF;
+ }
+
+ if (rwlock->rwCount == 0) {
+ return LOS_EPERM;
+ }
+
+ LosTaskCB *runTask = OsCurrTaskGet();
+ if ((rwlock->rwCount < 0) && ((LosTaskCB *)(rwlock->writeOwner) != runTask)) {
+ return LOS_EPERM;
+ }
+
+ /*
+ * When the rwCount of the rwlock more than 1 or less than -1, the rwlock mode will
+ * not changed after current unlock operation, so pended tasks can not be waken.
+ */
+ if (rwlock->rwCount > 1) {
+ rwlock->rwCount--;
+ return LOS_OK;
+ }
+
+ if (rwlock->rwCount < -1) {
+ rwlock->rwCount++;
+ return LOS_OK;
+ }
+
+ return OsRwlockPostOp(rwlock, needSched);
+}
+
+UINT32 LOS_RwlockUnLock(LosRwlock *rwlock)
+{
+ UINT32 intSave;
+ BOOL needSched = FALSE;
+
+ UINT32 ret = OsRwlockCheck(rwlock);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsRwlockUnlockUnsafe(rwlock, &needSched);
+ SCHEDULER_UNLOCK(intSave);
+ LOS_MpSchedule(OS_MP_CPU_ALL);
+ if (needSched == TRUE) {
+ LOS_Schedule();
+ }
+ return ret;
+}
+
+#endif /* LOSCFG_BASE_IPC_RWLOCK */
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
diff --git a/kernel/base/ipc/los_sem.c b/kernel/base/ipc/los_sem.c
old mode 100644
new mode 100755
index ae8131ba..ef012423
--- a/kernel/base/ipc/los_sem.c
+++ b/kernel/base/ipc/los_sem.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -34,6 +34,7 @@
#include "los_err_pri.h"
#include "los_task_pri.h"
#include "los_exc.h"
+#include "los_sched_pri.h"
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_percpu_pri.h"
@@ -115,6 +116,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *
unusedSem = LOS_DL_LIST_FIRST(&g_unusedSemList);
LOS_ListDelete(unusedSem);
+ SCHEDULER_UNLOCK(intSave);
semCreated = GET_SEM_LIST(unusedSem);
semCreated->semCount = count;
semCreated->semStat = OS_SEM_USED;
@@ -123,8 +125,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *
*semHandle = semCreated->semID;
OsSemDbgUpdateHook(semCreated->semID, OsCurrTaskGet()->taskEntry, count);
-
- SCHEDULER_UNLOCK(intSave);
return LOS_OK;
ERR_HANDLER:
@@ -227,10 +227,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
goto OUT;
}
- runTask->taskSem = (VOID *)semPended;
- retErr = OsTaskWait(&semPended->semList, timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_SEM, semPended->semID, timeout);
+ retErr = OsSchedTaskWait(&semPended->semList, timeout, TRUE);
if (retErr == LOS_ERRNO_TSK_TIMEOUT) {
- runTask->taskSem = NULL;
retErr = LOS_ERRNO_SEM_TIMEOUT;
}
@@ -244,10 +243,6 @@ LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
LosSemCB *semPosted = NULL;
LosTaskCB *resumedTask = NULL;
- if (GET_SEM_INDEX(semHandle) >= LOSCFG_BASE_IPC_SEM_LIMIT) {
- return LOS_ERRNO_SEM_INVALID;
- }
-
semPosted = GET_SEM(semHandle);
if ((semPosted->semID != semHandle) || (semPosted->semStat == OS_SEM_UNUSED)) {
return LOS_ERRNO_SEM_INVALID;
@@ -261,8 +256,8 @@ LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
}
if (!LOS_ListEmpty(&semPosted->semList)) {
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(semPosted->semList)));
- resumedTask->taskSem = NULL;
- OsTaskWake(resumedTask);
+ OsTaskWakeClearPendMask(resumedTask);
+ OsSchedTaskWake(resumedTask);
if (needSched != NULL) {
*needSched = TRUE;
}
@@ -279,6 +274,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
UINT32 ret;
BOOL needSched = FALSE;
+ if (GET_SEM_INDEX(semHandle) >= LOSCFG_BASE_IPC_SEM_LIMIT) {
+ return LOS_ERRNO_SEM_INVALID;
+ }
+
SCHEDULER_LOCK(intSave);
ret = OsSemPostUnsafe(semHandle, &needSched);
SCHEDULER_UNLOCK(intSave);
diff --git a/kernel/base/ipc/los_sem_debug.c b/kernel/base/ipc/los_sem_debug.c
old mode 100644
new mode 100755
index 148ee90a..e78c829f
--- a/kernel/base/ipc/los_sem_debug.c
+++ b/kernel/base/ipc/los_sem_debug.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c
old mode 100644
new mode 100755
index 9b7cc767..295f0fb9
--- a/kernel/base/ipc/los_signal.c
+++ b/kernel/base/ipc/los_signal.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,6 +32,7 @@
#include "los_signal.h"
#include "pthread.h"
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#include "los_hw_pri.h"
#include "user_copy.h"
#ifdef LOSCFG_SECURITY_CAPABILITY
@@ -83,7 +84,8 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
if (masked) {
/* If signal is in wait list and mask list, need unblock it */
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, info->si_signo)) {
- OsTaskWake(stcb);
+ OsTaskWakeClearPendMask(stcb);
+ OsSchedTaskWake(stcb);
OsSigEmptySet(&sigcb->sigwaitmask);
} else {
OsSigAddSet(&sigcb->sigPendFlag, info->si_signo);
@@ -92,7 +94,8 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
/* unmasked signal actions */
OsSigAddSet(&sigcb->sigFlag, info->si_signo);
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, info->si_signo)) {
- OsTaskWake(stcb);
+ OsTaskWakeClearPendMask(stcb);
+ OsSchedTaskWake(stcb);
OsSigEmptySet(&sigcb->sigwaitmask);
}
}
@@ -236,7 +239,8 @@ static int SigProcessKillSigHandler(LosTaskCB *tcb, void *arg)
if ((tcb != NULL) && (info != NULL) && (info->sigInfo != NULL)) {
sig_cb *sigcb = &tcb->sig;
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, info->sigInfo->si_signo)) {
- OsTaskWake(tcb);
+ OsTaskWakeClearPendMask(tcb);
+ OsSchedTaskWake(tcb);
OsSigEmptySet(&sigcb->sigwaitmask);
}
}
@@ -459,14 +463,15 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
/* If pendingflag & set > 0, shound clear pending flag */
sigset_t clear = sigcb->sigPendFlag & *set;
if (clear) {
+ sigcb->sigPendFlag ^= clear;
ret = FindFirstSetedBit((UINT64)clear) + 1;
- sigcb->sigPendFlag ^= SIGNO2SET(ret);
} else {
OsSigAddSet(set, SIGKILL);
OsSigAddSet(set, SIGSTOP);
sigcb->sigwaitmask |= *set;
- ret = OsTaskWait(&sigcb->waitList, timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_SIGNAL, sigcb->sigwaitmask, timeout);
+ ret = OsSchedTaskWait(&sigcb->waitList, timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
ret = -EAGAIN;
}
diff --git a/kernel/base/mem/bestfit/los_memory.c b/kernel/base/mem/bestfit/los_memory.c
deleted file mode 100644
index 239b03d8..00000000
--- a/kernel/base/mem/bestfit/los_memory.c
+++ /dev/null
@@ -1,2971 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_memory_pri.h"
-#include "los_vm_phys.h"
-#include "los_vm_boot.h"
-#include "los_vm_common.h"
-#include "los_vm_filemap.h"
-#include "asm/page.h"
-#include "los_multipledlinkhead_pri.h"
-#include "los_memstat_pri.h"
-#include "los_memrecord_pri.h"
-#include "los_task_pri.h"
-#include "los_exc.h"
-#include "los_spinlock.h"
-
-#ifdef LOSCFG_SHELL_EXCINFO
-#include "los_excinfo_pri.h"
-#endif
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#define NODEDUMPSIZE 64 /* the dump size of current broken node when memcheck error */
-#define COLUMN_NUM 8 /* column num of the output info of mem node */
-
-#define MEM_POOL_EXPAND_ENABLE 1
-#define MEM_POOL_EXPAND_DISABLE 0
-
-/* Memory pool information structure */
-typedef struct {
- VOID *pool; /* Starting address of a memory pool */
- UINT32 poolSize; /* Memory pool size */
- UINT32 flag; /* Whether the memory pool supports expansion */
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- UINT32 poolWaterLine; /* Maximum usage size in a memory pool */
- UINT32 poolCurUsedSize; /* Current usage size in a memory pool */
-#endif
-#ifdef LOSCFG_MEM_MUL_POOL
- VOID *nextPool;
-#endif
-} LosMemPoolInfo;
-
-/* Memory linked list control node structure */
-typedef struct {
- LOS_DL_LIST freeNodeInfo; /* Free memory node */
- struct tagLosMemDynNode *preNode; /* Pointer to the previous memory node */
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- UINT32 gapSize;
- UINTPTR checksum; /* magic = xor checksum */
-#endif
-
-#ifdef LOSCFG_MEM_RECORDINFO
- UINT32 originSize;
-#ifdef LOSCFG_AARCH64
- UINT32 reserve1; /* 64-bit alignment */
-#endif
-#endif
-
-#ifdef LOSCFG_MEM_LEAKCHECK
- UINTPTR linkReg[LOS_RECORD_LR_CNT];
-#endif
-
-#ifdef LOSCFG_AARCH64
- UINT32 reserve2; /* 64-bit alignment */
-#endif
- /* Size and flag of the current node (the high two bits represent a flag,and the rest bits specify the size) */
- UINT32 sizeAndFlag;
-} LosMemCtlNode;
-
-/* Memory linked list node structure */
-typedef struct tagLosMemDynNode {
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- LosMemCtlNode backupNode;
-#endif
- LosMemCtlNode selfNode;
-} LosMemDynNode;
-
-#ifdef LOSCFG_MEM_MUL_POOL
-VOID *g_poolHead = NULL;
-#endif
-
-/* spinlock for mem module, only available on SMP mode */
-LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_memSpin);
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
-/*
- * 0xffff0000U, 0xffffU
- * the taskID and moduleID multiplex the node->selfNode.freeNodeInfo.pstNext
- * the low 16 bits is the taskID and the high 16bits is the moduleID
- */
-STATIC VOID OsMemNodeSave(LosMemDynNode *node);
-#define OS_MEM_TASKID_SET(node, ID) do { \
- UINTPTR tmp_ = (UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext); \
- tmp_ &= 0xffff0000U; \
- tmp_ |= (ID); \
- ((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)tmp_; \
- OsMemNodeSave((LosMemDynNode *)(node)); \
-} while (0)
-#else
-#define OS_MEM_TASKID_SET(node, ID) do { \
- UINTPTR tmp_ = (UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext); \
- tmp_ &= 0xffff0000U; \
- tmp_ |= (ID); \
- ((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)tmp_; \
-} while (0)
-#endif
-#define OS_MEM_TASKID_GET(node) ((UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext) & 0xffffU)
-
-#ifdef LOSCFG_MEM_MUL_MODULE
-#define BITS_NUM_OF_TYPE_SHORT 16
-#ifdef LOSCFG_MEM_HEAD_BACKUP
-#define OS_MEM_MODID_SET(node, ID) do { \
- UINTPTR tmp_ = (UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext); \
- tmp_ &= 0xffffU; \
- tmp_ |= (ID) << BITS_NUM_OF_TYPE_SHORT; \
- ((LosMemDynNode *)node)->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)tmp_; \
- OsMemNodeSave((LosMemDynNode *)(node)); \
-} while (0)
-#else
-#define OS_MEM_MODID_SET(node, ID) do { \
- UINTPTR tmp_ = (UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext); \
- tmp_ &= 0xffffU; \
- tmp_ |= (ID) << BITS_NUM_OF_TYPE_SHORT; \
- ((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)tmp_; \
-} while (0)
-#endif
-#define OS_MEM_MODID_GET(node) \
- (((UINTPTR)(((LosMemDynNode *)(node))->selfNode.freeNodeInfo.pstNext) >> BITS_NUM_OF_TYPE_SHORT) & 0xffffU)
-#endif
-
-#define OS_MEM_ALIGN(p, alignSize) (((UINTPTR)(p) + (alignSize) - 1) & ~((UINTPTR)((alignSize) - 1)))
-#define OS_MEM_NODE_HEAD_SIZE sizeof(LosMemDynNode)
-#define OS_MEM_MIN_POOL_SIZE (OS_DLNK_HEAD_SIZE + (2 * OS_MEM_NODE_HEAD_SIZE) + sizeof(LosMemPoolInfo))
-#define IS_POW_TWO(value) ((((UINTPTR)(value)) & ((UINTPTR)(value) - 1)) == 0)
-#define POOL_ADDR_ALIGNSIZE 64
-#ifdef LOSCFG_AARCH64
-#define OS_MEM_ALIGN_SIZE 8
-#else
-#define OS_MEM_ALIGN_SIZE 4
-#endif
-#define OS_MEM_NODE_USED_FLAG 0x80000000U
-#define OS_MEM_NODE_ALIGNED_FLAG 0x40000000U
-#define OS_MEM_NODE_ALIGNED_AND_USED_FLAG (OS_MEM_NODE_USED_FLAG | OS_MEM_NODE_ALIGNED_FLAG)
-
-#define OS_MEM_NODE_GET_ALIGNED_FLAG(sizeAndFlag) \
- ((sizeAndFlag) & OS_MEM_NODE_ALIGNED_FLAG)
-#define OS_MEM_NODE_SET_ALIGNED_FLAG(sizeAndFlag) \
- ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_ALIGNED_FLAG))
-#define OS_MEM_NODE_GET_ALIGNED_GAPSIZE(sizeAndFlag) \
- ((sizeAndFlag) & ~OS_MEM_NODE_ALIGNED_FLAG)
-#define OS_MEM_NODE_GET_USED_FLAG(sizeAndFlag) \
- ((sizeAndFlag) & OS_MEM_NODE_USED_FLAG)
-#define OS_MEM_NODE_SET_USED_FLAG(sizeAndFlag) \
- ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_USED_FLAG))
-#define OS_MEM_NODE_GET_SIZE(sizeAndFlag) \
- ((sizeAndFlag) & ~OS_MEM_NODE_ALIGNED_AND_USED_FLAG)
-#define OS_MEM_HEAD(pool, size) \
- OsDLnkMultiHead(OS_MEM_HEAD_ADDR(pool), size)
-#define OS_MEM_HEAD_ADDR(pool) \
- ((VOID *)((UINTPTR)(pool) + sizeof(LosMemPoolInfo)))
-#define OS_MEM_NEXT_NODE(node) \
- ((LosMemDynNode *)(VOID *)((UINT8 *)(node) + OS_MEM_NODE_GET_SIZE((node)->selfNode.sizeAndFlag)))
-#define OS_MEM_FIRST_NODE(pool) \
- ((LosMemDynNode *)(VOID *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE))
-#define OS_MEM_END_NODE(pool, size) \
- ((LosMemDynNode *)(VOID *)(((UINT8 *)(pool) + (size)) - OS_MEM_NODE_HEAD_SIZE))
-#define OS_MEM_MIDDLE_ADDR_OPEN_END(startAddr, middleAddr, endAddr) \
- (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) < (UINT8 *)(endAddr)))
-#define OS_MEM_MIDDLE_ADDR(startAddr, middleAddr, endAddr) \
- (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) <= (UINT8 *)(endAddr)))
-#define OS_MEM_SET_MAGIC(value) \
- (value) = (LOS_DL_LIST *)(((UINTPTR)&(value)) ^ (UINTPTR)(-1))
-#define OS_MEM_MAGIC_VALID(value) \
- (((UINTPTR)(value) ^ ((UINTPTR)&(value))) == (UINTPTR)(-1))
-
-UINT8 *m_aucSysMem0 = NULL;
-UINT8 *m_aucSysMem1 = NULL;
-
-#ifdef LOSCFG_BASE_MEM_NODE_SIZE_CHECK
-STATIC UINT8 g_memCheckLevel = LOS_MEM_CHECK_LEVEL_DEFAULT;
-#endif
-
-#ifdef LOSCFG_MEM_MUL_MODULE
-UINT32 g_moduleMemUsedSize[MEM_MODULE_MAX + 1] = { 0 };
-#endif
-
-VOID OsMemInfoPrint(VOID *pool);
-#ifdef LOSCFG_BASE_MEM_NODE_SIZE_CHECK
-const VOID *OsMemFindNodeCtrl(const VOID *pool, const VOID *ptr);
-#endif
-#ifdef LOSCFG_MEM_HEAD_BACKUP
-#define CHECKSUM_MAGICNUM 0xDEADBEEF
-#define OS_MEM_NODE_CHECKSUN_CALCULATE(ctlNode) \
- (((UINTPTR)(ctlNode)->freeNodeInfo.pstPrev) ^ \
- ((UINTPTR)(ctlNode)->freeNodeInfo.pstNext) ^ \
- ((UINTPTR)(ctlNode)->preNode) ^ \
- (ctlNode)->gapSize ^ \
- (ctlNode)->sizeAndFlag ^ \
- CHECKSUM_MAGICNUM)
-
-STATIC INLINE VOID OsMemDispCtlNode(const LosMemCtlNode *ctlNode)
-{
- UINTPTR checksum;
-
- checksum = OS_MEM_NODE_CHECKSUN_CALCULATE(ctlNode);
-
- PRINTK("node:%p checksum=%p[%p] freeNodeInfo.pstPrev=%p "
- "freeNodeInfo.pstNext=%p preNode=%p gapSize=0x%x sizeAndFlag=0x%x\n",
- ctlNode,
- ctlNode->checksum,
- checksum,
- ctlNode->freeNodeInfo.pstPrev,
- ctlNode->freeNodeInfo.pstNext,
- ctlNode->preNode,
- ctlNode->gapSize,
- ctlNode->sizeAndFlag);
-}
-
-STATIC INLINE VOID OsMemDispMoreDetails(const LosMemDynNode *node)
-{
- UINT32 taskID;
- LosTaskCB *taskCB = NULL;
-
- PRINT_ERR("************************************************\n");
- OsMemDispCtlNode(&node->selfNode);
- PRINT_ERR("the address of node :%p\n", node);
-
- if (!OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- PRINT_ERR("this is a FREE node\n");
- PRINT_ERR("************************************************\n\n");
- return;
- }
-
- taskID = OS_MEM_TASKID_GET(node);
- if (OS_TID_CHECK_INVALID(taskID)) {
- PRINT_ERR("The task [ID: 0x%x] is ILLEGAL\n", taskID);
- if (taskID == g_taskMaxNum) {
- PRINT_ERR("PROBABLY alloc by SYSTEM INIT, NOT IN ANY TASK\n");
- }
- PRINT_ERR("************************************************\n\n");
- return;
- }
-
- taskCB = OS_TCB_FROM_TID(taskID);
- if (OsTaskIsUnused(taskCB) || (taskCB->taskEntry == NULL)) {
- PRINT_ERR("The task [ID: 0x%x] is NOT CREATED(ILLEGAL)\n", taskID);
- PRINT_ERR("************************************************\n\n");
- return;
- }
-
- PRINT_ERR("allocated by task: %s [ID = 0x%x]\n", taskCB->taskName, taskID);
-#ifdef LOSCFG_MEM_MUL_MODULE
- PRINT_ERR("allocated by moduleID: %lu\n", OS_MEM_MODID_GET(node));
-#endif
-
- PRINT_ERR("************************************************\n\n");
-}
-
-STATIC INLINE VOID OsMemDispWildPointerMsg(const LosMemDynNode *node, const VOID *ptr)
-{
- PRINT_ERR("*****************************************************\n");
- PRINT_ERR("find an control block at: %p, gap size: 0x%x, sizeof(LosMemDynNode): 0x%x\n", node,
- node->selfNode.gapSize, sizeof(LosMemDynNode));
- PRINT_ERR("the pointer should be: %p\n",
- ((UINTPTR)node + node->selfNode.gapSize + sizeof(LosMemDynNode)));
- PRINT_ERR("the pointer given is: %p\n", ptr);
- PRINT_ERR("PROBABLY A WILD POINTER\n");
- OsBackTrace();
- PRINT_ERR("*****************************************************\n\n");
-}
-
-STATIC INLINE VOID OsMemChecksumSet(LosMemCtlNode *ctlNode)
-{
- ctlNode->checksum = OS_MEM_NODE_CHECKSUN_CALCULATE(ctlNode);
-}
-
-STATIC INLINE BOOL OsMemChecksumVerify(const LosMemCtlNode *ctlNode)
-{
- return ctlNode->checksum == OS_MEM_NODE_CHECKSUN_CALCULATE(ctlNode);
-}
-
-STATIC INLINE VOID OsMemBackupSetup(const LosMemDynNode *node)
-{
- LosMemDynNode *nodePre = node->selfNode.preNode;
- if (nodePre != NULL) {
- nodePre->backupNode.freeNodeInfo.pstNext = node->selfNode.freeNodeInfo.pstNext;
- nodePre->backupNode.freeNodeInfo.pstPrev = node->selfNode.freeNodeInfo.pstPrev;
- nodePre->backupNode.preNode = node->selfNode.preNode;
- nodePre->backupNode.checksum = node->selfNode.checksum;
- nodePre->backupNode.gapSize = node->selfNode.gapSize;
-#ifdef LOSCFG_MEM_RECORDINFO
- nodePre->backupNode.originSize = node->selfNode.originSize;
-#endif
- nodePre->backupNode.sizeAndFlag = node->selfNode.sizeAndFlag;
- }
-}
-
-LosMemDynNode *OsMemNodeNextGet(const VOID *pool, const LosMemDynNode *node)
-{
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
-
- if (node == OS_MEM_END_NODE(pool, poolInfo->poolSize)) {
- return OS_MEM_FIRST_NODE(pool);
- } else {
- return OS_MEM_NEXT_NODE(node);
- }
-}
-
-STATIC INLINE UINT32 OsMemBackupSetup4Next(const VOID *pool, LosMemDynNode *node)
-{
- LosMemDynNode *nodeNext = OsMemNodeNextGet(pool, node);
-
- if (!OsMemChecksumVerify(&nodeNext->selfNode)) {
- PRINT_ERR("[%s]the next node is broken!!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodeNext->selfNode));
- PRINT_ERR("Current node details:\n");
- OsMemDispMoreDetails(node);
-
- return LOS_NOK;
- }
-
- if (!OsMemChecksumVerify(&node->backupNode)) {
- node->backupNode.freeNodeInfo.pstNext = nodeNext->selfNode.freeNodeInfo.pstNext;
- node->backupNode.freeNodeInfo.pstPrev = nodeNext->selfNode.freeNodeInfo.pstPrev;
- node->backupNode.preNode = nodeNext->selfNode.preNode;
- node->backupNode.checksum = nodeNext->selfNode.checksum;
- node->backupNode.gapSize = nodeNext->selfNode.gapSize;
-#ifdef LOSCFG_MEM_RECORDINFO
- node->backupNode.originSize = nodeNext->selfNode.originSize;
-#endif
- node->backupNode.sizeAndFlag = nodeNext->selfNode.sizeAndFlag;
- }
- return LOS_OK;
-}
-
-UINT32 OsMemBackupDoRestore(VOID *pool, const LosMemDynNode *nodePre, LosMemDynNode *node)
-{
- if (node == NULL) {
- PRINT_ERR("the node is NULL.\n");
- return LOS_NOK;
- }
- PRINT_ERR("the backup node information of current node in previous node:\n");
- OsMemDispCtlNode(&nodePre->backupNode);
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
-
- node->selfNode.freeNodeInfo.pstNext = nodePre->backupNode.freeNodeInfo.pstNext;
- node->selfNode.freeNodeInfo.pstPrev = nodePre->backupNode.freeNodeInfo.pstPrev;
- node->selfNode.preNode = nodePre->backupNode.preNode;
- node->selfNode.checksum = nodePre->backupNode.checksum;
- node->selfNode.gapSize = nodePre->backupNode.gapSize;
-#ifdef LOSCFG_MEM_RECORDINFO
- node->selfNode.originSize = nodePre->backupNode.originSize;
-#endif
- node->selfNode.sizeAndFlag = nodePre->backupNode.sizeAndFlag;
-
- /* we should re-setup next node's backup on current node */
- return OsMemBackupSetup4Next(pool, node);
-}
-
-STATIC LosMemDynNode *OsMemFirstNodePrevGet(const LosMemPoolInfo *poolInfo)
-{
- LosMemDynNode *nodePre = NULL;
-
- nodePre = OS_MEM_END_NODE(poolInfo, poolInfo->poolSize);
- if (!OsMemChecksumVerify(&(nodePre->selfNode))) {
- PRINT_ERR("the current node is THE FIRST NODE !\n");
- PRINT_ERR("[%s]: the node information of previous node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodePre->selfNode));
- return nodePre;
- }
- if (!OsMemChecksumVerify(&(nodePre->backupNode))) {
- PRINT_ERR("the current node is THE FIRST NODE !\n");
- PRINT_ERR("[%s]: the backup node information of current node in previous Node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodePre->backupNode));
- return nodePre;
- }
-
- return NULL;
-}
-
-LosMemDynNode *OsMemNodePrevGet(VOID *pool, const LosMemDynNode *node)
-{
- LosMemDynNode *nodeCur = NULL;
- LosMemDynNode *nodePre = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
-
- if (node == OS_MEM_FIRST_NODE(pool)) {
- return OsMemFirstNodePrevGet(poolInfo);
- }
-
- for (nodeCur = OS_MEM_FIRST_NODE(pool);
- nodeCur < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- nodeCur = OS_MEM_NEXT_NODE(nodeCur)) {
- if (!OsMemChecksumVerify(&(nodeCur->selfNode))) {
- PRINT_ERR("[%s]: the node information of current node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodeCur->selfNode));
-
- if (nodePre == NULL) {
- return NULL;
- }
-
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
-
- /* due to the every step's checksum verify, nodePre is trustful */
- if (OsMemBackupDoRestore(pool, nodePre, nodeCur) != LOS_OK) {
- return NULL;
- }
- }
-
- if (!OsMemChecksumVerify(&(nodeCur->backupNode))) {
- PRINT_ERR("[%s]: the backup node information in current node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodeCur->backupNode));
-
- if (nodePre != NULL) {
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
- }
-
- if (OsMemBackupSetup4Next(pool, nodeCur) != LOS_OK) {
- return NULL;
- }
- }
-
- if (OS_MEM_NEXT_NODE(nodeCur) == node) {
- return nodeCur;
- }
-
- if (OS_MEM_NEXT_NODE(nodeCur) > node) {
- break;
- }
-
- nodePre = nodeCur;
- }
-
- return NULL;
-}
-
-LosMemDynNode *OsMemNodePrevTryGet(VOID *pool, LosMemDynNode **node, const VOID *ptr)
-{
- UINTPTR nodeShoudBe = 0;
- LosMemDynNode *nodeCur = NULL;
- LosMemDynNode *nodePre = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
-
- if (ptr == OS_MEM_FIRST_NODE(pool)) {
- return OsMemFirstNodePrevGet(poolInfo);
- }
-
- for (nodeCur = OS_MEM_FIRST_NODE(pool);
- nodeCur < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- nodeCur = OS_MEM_NEXT_NODE(nodeCur)) {
- if (!OsMemChecksumVerify(&(nodeCur->selfNode))) {
- PRINT_ERR("[%s]: the node information of current node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodeCur->selfNode));
-
- if (nodePre == NULL) {
- return NULL;
- }
-
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
-
- /* due to the every step's checksum verify, nodePre is trustful */
- if (OsMemBackupDoRestore(pool, nodePre, nodeCur) != LOS_OK) {
- return NULL;
- }
- }
-
- if (!OsMemChecksumVerify(&(nodeCur->backupNode))) {
- PRINT_ERR("[%s]: the backup node information in current node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&(nodeCur->backupNode));
-
- if (nodePre != NULL) {
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
- }
-
- if (OsMemBackupSetup4Next(pool, nodeCur) != LOS_OK) {
- return NULL;
- }
- }
-
- nodeShoudBe = (UINTPTR)nodeCur + nodeCur->selfNode.gapSize + sizeof(LosMemDynNode);
- if (nodeShoudBe == (UINTPTR)ptr) {
- *node = nodeCur;
- return nodePre;
- }
-
- if (OS_MEM_NEXT_NODE(nodeCur) > (LosMemDynNode *)ptr) {
- OsMemDispWildPointerMsg(nodeCur, ptr);
- break;
- }
-
- nodePre = nodeCur;
- }
-
- return NULL;
-}
-
-STATIC INLINE UINT32 OsMemBackupTryRestore(VOID *pool, LosMemDynNode **node, const VOID *ptr)
-{
- LosMemDynNode *nodeHead = NULL;
- LosMemDynNode *nodePre = OsMemNodePrevTryGet(pool, &nodeHead, ptr);
- if (nodePre == NULL) {
- return LOS_NOK;
- }
-
- *node = nodeHead;
- return OsMemBackupDoRestore(pool, nodePre, *node);
-}
-
-STATIC INLINE UINT32 OsMemBackupRestore(VOID *pool, LosMemDynNode *node)
-{
- LosMemDynNode *nodePre = OsMemNodePrevGet(pool, node);
- if (nodePre == NULL) {
- return LOS_NOK;
- }
-
- return OsMemBackupDoRestore(pool, nodePre, node);
-}
-
-STATIC INLINE VOID OsMemSetGapSize(LosMemCtlNode *ctlNode, UINT32 gapSize)
-{
- ctlNode->gapSize = gapSize;
-}
-
-STATIC VOID OsMemNodeSave(LosMemDynNode *node)
-{
- OsMemSetGapSize(&node->selfNode, 0);
- OsMemChecksumSet(&node->selfNode);
- OsMemBackupSetup(node);
-}
-
-STATIC VOID OsMemNodeSaveWithGapSize(LosMemDynNode *node, UINT32 gapSize)
-{
- OsMemSetGapSize(&node->selfNode, gapSize);
- OsMemChecksumSet(&node->selfNode);
- OsMemBackupSetup(node);
-}
-
-STATIC VOID OsMemListDelete(LOS_DL_LIST *node, const VOID *firstNode)
-{
- LosMemDynNode *dynNode = NULL;
-
- node->pstNext->pstPrev = node->pstPrev;
- node->pstPrev->pstNext = node->pstNext;
-
- if ((VOID *)(node->pstNext) >= firstNode) {
- dynNode = LOS_DL_LIST_ENTRY(node->pstNext, LosMemDynNode, selfNode.freeNodeInfo);
- OsMemNodeSave(dynNode);
- }
-
- if ((VOID *)(node->pstPrev) >= firstNode) {
- dynNode = LOS_DL_LIST_ENTRY(node->pstPrev, LosMemDynNode, selfNode.freeNodeInfo);
- OsMemNodeSave(dynNode);
- }
-
- node->pstNext = NULL;
- node->pstPrev = NULL;
-
- dynNode = LOS_DL_LIST_ENTRY(node, LosMemDynNode, selfNode.freeNodeInfo);
- OsMemNodeSave(dynNode);
-}
-
-STATIC VOID OsMemListAdd(LOS_DL_LIST *listNode, LOS_DL_LIST *node, const VOID *firstNode)
-{
- LosMemDynNode *dynNode = NULL;
-
- node->pstNext = listNode->pstNext;
- node->pstPrev = listNode;
-
- dynNode = LOS_DL_LIST_ENTRY(node, LosMemDynNode, selfNode.freeNodeInfo);
- OsMemNodeSave(dynNode);
-
- listNode->pstNext->pstPrev = node;
- if ((VOID *)(listNode->pstNext) >= firstNode) {
- dynNode = LOS_DL_LIST_ENTRY(listNode->pstNext, LosMemDynNode, selfNode.freeNodeInfo);
- OsMemNodeSave(dynNode);
- }
-
- listNode->pstNext = node;
-}
-
-VOID LOS_MemBadNodeShow(VOID *pool)
-{
- LosMemDynNode *nodePre = NULL;
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- UINT32 intSave;
-
- if (pool == NULL) {
- return;
- }
-
- MEM_LOCK(intSave);
-
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- OsMemDispCtlNode(&tmpNode->selfNode);
-
- if (OsMemChecksumVerify(&tmpNode->selfNode)) {
- continue;
- }
-
- nodePre = OsMemNodePrevGet(pool, tmpNode);
- if (nodePre == NULL) {
- PRINT_ERR("the current node is invalid, but cannot find its previous Node\n");
- continue;
- }
-
- PRINT_ERR("the detailed information of previous node:\n");
- OsMemDispMoreDetails(nodePre);
- }
-
- MEM_UNLOCK(intSave);
- PRINTK("check finish\n");
-}
-
-#else /* without LOSCFG_MEM_HEAD_BACKUP */
-
-STATIC VOID OsMemListDelete(LOS_DL_LIST *node, const VOID *firstNode)
-{
- (VOID)firstNode;
- LOS_ListDelete(node);
-}
-
-STATIC VOID OsMemListAdd(LOS_DL_LIST *listNode, LOS_DL_LIST *node, const VOID *firstNode)
-{
- (VOID)firstNode;
- LOS_ListHeadInsert(listNode, node);
-}
-
-#endif
-
-#ifdef LOSCFG_EXC_INTERACTION
-LITE_OS_SEC_TEXT_INIT UINT32 OsMemExcInteractionInit(UINTPTR memStart)
-{
- UINT32 ret;
- UINT32 poolSize;
- m_aucSysMem0 = (UINT8 *)((memStart + (POOL_ADDR_ALIGNSIZE - 1)) & ~((UINTPTR)(POOL_ADDR_ALIGNSIZE - 1)));
- poolSize = OS_EXC_INTERACTMEM_SIZE;
- ret = LOS_MemInit(m_aucSysMem0, poolSize);
- PRINT_INFO("LiteOS kernel exc interaction memory address:%p,size:0x%x\n", m_aucSysMem0, poolSize);
- return ret;
-}
-#endif
-
-LITE_OS_SEC_TEXT_INIT UINT32 OsMemSystemInit(UINTPTR memStart)
-{
- UINT32 ret;
- UINT32 poolSize;
-
- m_aucSysMem1 = (UINT8 *)((memStart + (POOL_ADDR_ALIGNSIZE - 1)) & ~((UINTPTR)(POOL_ADDR_ALIGNSIZE - 1)));
- poolSize = OS_SYS_MEM_SIZE;
- ret = LOS_MemInit(m_aucSysMem1, poolSize);
- PRINT_INFO("LiteOS system heap memory address:%p,size:0x%x\n", m_aucSysMem1, poolSize);
-#ifndef LOSCFG_EXC_INTERACTION
- m_aucSysMem0 = m_aucSysMem1;
-#endif
- return ret;
-}
-
-#ifdef LOSCFG_MEM_LEAKCHECK
-STATIC INLINE VOID OsMemLinkRegisterRecord(LosMemDynNode *node)
-{
- UINT32 count = 0;
- UINT32 index = 0;
- UINTPTR framePtr, tmpFramePtr, linkReg;
-
- (VOID)memset_s(node->selfNode.linkReg, (LOS_RECORD_LR_CNT * sizeof(UINTPTR)), 0,
- (LOS_RECORD_LR_CNT * sizeof(UINTPTR)));
- framePtr = Get_Fp();
- while ((framePtr > OS_SYS_FUNC_ADDR_START) && (framePtr < OS_SYS_FUNC_ADDR_END)) {
- tmpFramePtr = framePtr;
-#ifdef __LP64__
- framePtr = *(UINTPTR *)framePtr;
- linkReg = *(UINTPTR *)(tmpFramePtr + sizeof(UINTPTR));
-#else
- linkReg = *(UINTPTR *)framePtr;
- framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
-#endif
- if (index >= LOS_OMIT_LR_CNT) {
- node->selfNode.linkReg[count++] = linkReg;
- if (count == LOS_RECORD_LR_CNT) {
- break;
- }
- }
- index++;
- }
-}
-#endif
-
-#define OS_CHECK_NULL_RETURN(param) do { \
- if ((param) == NULL) { \
- PRINT_ERR("%s %d\n", __FUNCTION__, __LINE__); \
- return; \
- } \
-} while (0);
-
-/*
- * Description : find suitable free block use "best fit" algorithm
- * Input : pool --- Pointer to memory pool
- * allocSize --- Size of memory in bytes which note need allocate
- * Return : NULL --- no suitable block found
- * tmpNode --- pointer a suitable free block
- */
-STATIC INLINE LosMemDynNode *OsMemFindSuitableFreeBlock(VOID *pool, UINT32 allocSize)
-{
- LOS_DL_LIST *listNodeHead = NULL;
- LosMemDynNode *tmpNode = NULL;
- UINT32 maxCount = (LOS_MemPoolSizeGet(pool) / allocSize) << 1;
- UINT32 count;
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- UINT32 ret = LOS_OK;
-#endif
- for (listNodeHead = OS_MEM_HEAD(pool, allocSize); listNodeHead != NULL;
- listNodeHead = OsDLnkNextMultiHead(OS_MEM_HEAD_ADDR(pool), listNodeHead)) {
- count = 0;
- LOS_DL_LIST_FOR_EACH_ENTRY(tmpNode, listNodeHead, LosMemDynNode, selfNode.freeNodeInfo) {
- if (count++ >= maxCount) {
- PRINT_ERR("[%s:%d]node: execute too much time\n", __FUNCTION__, __LINE__);
- break;
- }
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- if (!OsMemChecksumVerify(&tmpNode->selfNode)) {
- PRINT_ERR("[%s]: the node information of current node is bad !!\n", __FUNCTION__);
- OsMemDispCtlNode(&tmpNode->selfNode);
- ret = OsMemBackupRestore(pool, tmpNode);
- }
- if (ret != LOS_OK) {
- break;
- }
-#endif
-
- if (((UINTPTR)tmpNode & (OS_MEM_ALIGN_SIZE - 1)) != 0) {
- LOS_Panic("[%s:%d]Mem node data error:OS_MEM_HEAD_ADDR(pool)=%p, listNodeHead:%p,"
- "allocSize=%u, tmpNode=%p\n",
- __FUNCTION__, __LINE__, OS_MEM_HEAD_ADDR(pool), listNodeHead, allocSize, tmpNode);
- break;
- }
- if (tmpNode->selfNode.sizeAndFlag >= allocSize) {
- return tmpNode;
- }
- }
- }
-
- return NULL;
-}
-
-/*
- * Description : clear a mem node, set every member to NULL
- * Input : node --- Pointer to the mem node which will be cleared up
- */
-STATIC INLINE VOID OsMemClearNode(LosMemDynNode *node)
-{
- (VOID)memset_s((VOID *)node, sizeof(LosMemDynNode), 0, sizeof(LosMemDynNode));
-}
-
-/*
- * Description : merge this node and pre node, then clear this node info
- * Input : node --- Pointer to node which will be merged
- */
-STATIC INLINE VOID OsMemMergeNode(LosMemDynNode *node)
-{
- LosMemDynNode *nextNode = NULL;
-
- node->selfNode.preNode->selfNode.sizeAndFlag += node->selfNode.sizeAndFlag;
- nextNode = (LosMemDynNode *)((UINTPTR)node + node->selfNode.sizeAndFlag);
- nextNode->selfNode.preNode = node->selfNode.preNode;
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(node->selfNode.preNode);
- OsMemNodeSave(nextNode);
-#endif
- OsMemClearNode(node);
-}
-
-STATIC INLINE BOOL IsExpandPoolNode(VOID *pool, LosMemDynNode *node)
-{
- UINTPTR start = (UINTPTR)pool;
- UINTPTR end = start + ((LosMemPoolInfo *)pool)->poolSize;
- return ((UINTPTR)node < start) || ((UINTPTR)node > end);
-}
-
-/*
- * Description : split new node from allocNode, and merge remainder mem if necessary
- * Input : pool -- Pointer to memory pool
- * allocNode -- the source node which new node be spit from to.
- * After pick up it's node info, change to point the new node
- * allocSize -- the size of new node
- * Output : allocNode -- save new node addr
- */
-STATIC INLINE VOID OsMemSplitNode(VOID *pool,
- LosMemDynNode *allocNode, UINT32 allocSize)
-{
- LosMemDynNode *newFreeNode = NULL;
- LosMemDynNode *nextNode = NULL;
- LOS_DL_LIST *listNodeHead = NULL;
- const VOID *firstNode = (const VOID *)OS_MEM_FIRST_NODE(pool);
-
- newFreeNode = (LosMemDynNode *)(VOID *)((UINT8 *)allocNode + allocSize);
- newFreeNode->selfNode.preNode = allocNode;
- newFreeNode->selfNode.sizeAndFlag = allocNode->selfNode.sizeAndFlag - allocSize;
- allocNode->selfNode.sizeAndFlag = allocSize;
- nextNode = OS_MEM_NEXT_NODE(newFreeNode);
- nextNode->selfNode.preNode = newFreeNode;
- if (!OS_MEM_NODE_GET_USED_FLAG(nextNode->selfNode.sizeAndFlag)) {
- OsMemListDelete(&nextNode->selfNode.freeNodeInfo, firstNode);
- OsMemMergeNode(nextNode);
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- } else {
- OsMemNodeSave(nextNode);
-#endif
- }
- listNodeHead = OS_MEM_HEAD(pool, newFreeNode->selfNode.sizeAndFlag);
- OS_CHECK_NULL_RETURN(listNodeHead);
- /* add expand node to tail to make sure origin pool used first */
- if (IsExpandPoolNode(pool, newFreeNode)) {
- OsMemListAdd(listNodeHead->pstPrev, &newFreeNode->selfNode.freeNodeInfo, firstNode);
- } else {
- OsMemListAdd(listNodeHead, &newFreeNode->selfNode.freeNodeInfo, firstNode);
- }
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(newFreeNode);
-#endif
-}
-
-STATIC INLINE LosMemDynNode *PreSentinelNodeGet(const VOID *pool, const LosMemDynNode *node);
-STATIC INLINE BOOL OsMemIsLastSentinelNode(LosMemDynNode *node);
-
-UINT32 OsMemLargeNodeFree(const VOID *ptr)
-{
- LosVmPage *page = OsVmVaddrToPage((VOID *)ptr);
- if ((page == NULL) || (page->nPages == 0)) {
- return LOS_NOK;
- }
- LOS_PhysPagesFreeContiguous((VOID *)ptr, page->nPages);
-
- return LOS_OK;
-}
-
-STATIC INLINE BOOL TryShrinkPool(const VOID *pool, const LosMemDynNode *node)
-{
- LosMemDynNode *mySentinel = NULL;
- LosMemDynNode *preSentinel = NULL;
- size_t totalSize = (UINTPTR)node->selfNode.preNode - (UINTPTR)node;
- size_t nodeSize = OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
-
- if (nodeSize != totalSize) {
- return FALSE;
- }
-
- preSentinel = PreSentinelNodeGet(pool, node);
- if (preSentinel == NULL) {
- return FALSE;
- }
-
- mySentinel = node->selfNode.preNode;
- if (OsMemIsLastSentinelNode(mySentinel)) {
- preSentinel->selfNode.sizeAndFlag = OS_MEM_NODE_USED_FLAG;
- preSentinel->selfNode.freeNodeInfo.pstNext = NULL;
- } else {
- preSentinel->selfNode.sizeAndFlag = mySentinel->selfNode.sizeAndFlag;
- preSentinel->selfNode.freeNodeInfo.pstNext = mySentinel->selfNode.freeNodeInfo.pstNext;
- }
- if (OsMemLargeNodeFree(node) != LOS_OK) {
- PRINT_ERR("TryShrinkPool free %p failed!\n", node);
- return FALSE;
- }
-
- return TRUE;
-}
-
-/*
- * Description : free the node from memory & if there are free node beside, merger them.
- * at last update "listNodeHead' which saved all free node control head
- * Input : node -- the node which need be freed
- * pool -- Pointer to memory pool
- */
-STATIC INLINE VOID OsMemFreeNode(LosMemDynNode *node, VOID *pool)
-{
- LosMemDynNode *preNode = NULL;
- LosMemDynNode *nextNode = NULL;
- LOS_DL_LIST *listNodeHead = NULL;
- const VOID *firstNode = (const VOID *)OS_MEM_FIRST_NODE(pool);
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
-
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolInfo->poolCurUsedSize -= OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
-#endif
- if ((pool == (VOID *)OS_SYS_MEM_ADDR) || (pool == (VOID *)m_aucSysMem0)) {
- OS_MEM_REDUCE_USED(OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag), OS_MEM_TASKID_GET(node));
- }
-
- node->selfNode.sizeAndFlag = OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(node);
-#endif
-#ifdef LOSCFG_MEM_LEAKCHECK
- OsMemLinkRegisterRecord(node);
-#endif
- preNode = node->selfNode.preNode; /* merage preNode */
- if ((preNode != NULL) && !OS_MEM_NODE_GET_USED_FLAG(preNode->selfNode.sizeAndFlag)) {
- OsMemListDelete(&(preNode->selfNode.freeNodeInfo), firstNode);
- OsMemMergeNode(node);
- node = preNode;
- }
-
- nextNode = OS_MEM_NEXT_NODE(node); /* merage nextNode */
- if ((nextNode != NULL) && !OS_MEM_NODE_GET_USED_FLAG(nextNode->selfNode.sizeAndFlag)) {
- OsMemListDelete(&nextNode->selfNode.freeNodeInfo, firstNode);
- OsMemMergeNode(nextNode);
- }
-
- if (poolInfo->flag & MEM_POOL_EXPAND_ENABLE) {
- /* if this is a expand head node, and all unused, free it to pmm */
- if ((node->selfNode.preNode > node) && (node != firstNode)) {
- if (TryShrinkPool(pool, node)) {
- return;
- }
- }
- }
-
- listNodeHead = OS_MEM_HEAD(pool, node->selfNode.sizeAndFlag);
- OS_CHECK_NULL_RETURN(listNodeHead);
- /* add expand node to tail to make sure origin pool used first */
- if (IsExpandPoolNode(pool, node)) {
- OsMemListAdd(listNodeHead->pstPrev, &node->selfNode.freeNodeInfo, firstNode);
- } else {
- OsMemListAdd(listNodeHead, &node->selfNode.freeNodeInfo, firstNode);
- }
-}
-
-/*
- * Description : check the result if pointer memory node belongs to pointer memory pool
- * Input : pool -- Pointer to memory pool
- * node -- the node which need be checked
- * Return : LOS_OK or LOS_NOK
- */
-#ifdef LOS_DLNK_SAFE_CHECK
-STATIC INLINE UINT32 OsMemCheckUsedNode(const VOID *pool, const LosMemDynNode *node)
-{
- LosMemDynNode *tmpNode = OS_MEM_FIRST_NODE(pool);
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
- LosMemDynNode *endNode = (const LosMemDynNode *)OS_MEM_END_NODE(pool, poolInfo->poolSize);
-
- do {
- for (; tmpNode < endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- if ((tmpNode == node) &&
- OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
- return LOS_OK;
- }
- }
-
- if (OsMemIsLastSentinelNode(endNode) == FALSE) {
- tmpNode = OsMemSentinelNodeGet(endNode);
- endNode = OS_MEM_END_NODE(tmpNode, OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag));
- } else {
- break;
- }
- } while (1);
-
- return LOS_NOK;
-}
-
-#elif defined(LOS_DLNK_SIMPLE_CHECK)
-STATIC INLINE UINT32 OsMemCheckUsedNode(const VOID *pool, const LosMemDynNode *node)
-{
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
- const LosMemDynNode *startNode = (const LosMemDynNode *)OS_MEM_FIRST_NODE(pool);
- const LosMemDynNode *endNode = (const LosMemDynNode *)OS_MEM_END_NODE(pool, poolInfo->poolSize);
- if (!OS_MEM_MIDDLE_ADDR_OPEN_END(startNode, node, endNode)) {
- return LOS_NOK;
- }
-
- if (!OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- return LOS_NOK;
- }
-
- if (!OS_MEM_MAGIC_VALID(node->selfNode.freeNodeInfo.pstPrev)) {
- return LOS_NOK;
- }
-
- return LOS_OK;
-}
-
-#else
-STATIC LosMemDynNode *OsMemLastSentinelNodeGet(LosMemDynNode *sentinelNode)
-{
- LosMemDynNode *node = NULL;
- VOID *ptr = sentinelNode->selfNode.freeNodeInfo.pstNext;
- UINT32 size = OS_MEM_NODE_GET_SIZE(sentinelNode->selfNode.sizeAndFlag);
-
- while ((ptr != NULL) && (size != 0)) {
- node = OS_MEM_END_NODE(ptr, size);
- ptr = node->selfNode.freeNodeInfo.pstNext;
- size = OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
- }
-
- return node;
-}
-
-STATIC INLINE BOOL OsMemSentinelNodeCheck(LosMemDynNode *node)
-{
- if (!OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- return FALSE;
- }
-
- if (!OS_MEM_MAGIC_VALID(node->selfNode.freeNodeInfo.pstPrev)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-STATIC INLINE BOOL OsMemIsLastSentinelNode(LosMemDynNode *node)
-{
- if (OsMemSentinelNodeCheck(node) == FALSE) {
- PRINT_ERR("%s %d, The current sentinel node is invalid\n", __FUNCTION__, __LINE__);
- return TRUE;
- }
-
- if ((OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag) == 0) ||
- (node->selfNode.freeNodeInfo.pstNext == NULL)) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-STATIC INLINE VOID OsMemSentinelNodeSet(LosMemDynNode *sentinelNode, VOID *newNode, UINT32 size)
-{
- if (sentinelNode->selfNode.freeNodeInfo.pstNext != NULL) {
- sentinelNode = OsMemLastSentinelNodeGet(sentinelNode);
- }
-
- OS_MEM_SET_MAGIC(sentinelNode->selfNode.freeNodeInfo.pstPrev);
- sentinelNode->selfNode.sizeAndFlag = size;
- OS_MEM_NODE_SET_USED_FLAG(sentinelNode->selfNode.sizeAndFlag);
- sentinelNode->selfNode.freeNodeInfo.pstNext = newNode;
-}
-
-STATIC INLINE VOID *OsMemSentinelNodeGet(LosMemDynNode *node)
-{
- if (OsMemSentinelNodeCheck(node) == FALSE) {
- return NULL;
- }
-
- return node->selfNode.freeNodeInfo.pstNext;
-}
-
-STATIC INLINE LosMemDynNode *PreSentinelNodeGet(const VOID *pool, const LosMemDynNode *node)
-{
- UINT32 nextSize;
- LosMemDynNode *nextNode = NULL;
- LosMemDynNode *sentinelNode = NULL;
-
- sentinelNode = OS_MEM_END_NODE(pool, ((LosMemPoolInfo *)pool)->poolSize);
- while (sentinelNode != NULL) {
- if (OsMemIsLastSentinelNode(sentinelNode)) {
- PRINT_ERR("PreSentinelNodeGet can not find node %p\n", node);
- return NULL;
- }
- nextNode = OsMemSentinelNodeGet(sentinelNode);
- if (nextNode == node) {
- return sentinelNode;
- }
- nextSize = OS_MEM_NODE_GET_SIZE(sentinelNode->selfNode.sizeAndFlag);
- sentinelNode = OS_MEM_END_NODE(nextNode, nextSize);
- }
-
- return NULL;
-}
-
-BOOL OsMemIsHeapNode(const VOID *ptr)
-{
- LosMemPoolInfo *pool = (LosMemPoolInfo *)m_aucSysMem1;
- LosMemDynNode *firstNode = OS_MEM_FIRST_NODE(pool);
- LosMemDynNode *endNode = OS_MEM_END_NODE(pool, pool->poolSize);
- UINT32 intSave;
- UINT32 size;
-
- if (OS_MEM_MIDDLE_ADDR(firstNode, ptr, endNode)) {
- return TRUE;
- }
-
- MEM_LOCK(intSave);
- while (OsMemIsLastSentinelNode(endNode) == FALSE) {
- size = OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag);
- firstNode = OsMemSentinelNodeGet(endNode);
- endNode = OS_MEM_END_NODE(firstNode, size);
- if (OS_MEM_MIDDLE_ADDR(firstNode, ptr, endNode)) {
- MEM_UNLOCK(intSave);
- return TRUE;
- }
- }
- MEM_UNLOCK(intSave);
-
- return FALSE;
-}
-
-STATIC BOOL OsMemAddrValidCheck(const LosMemPoolInfo *pool, const VOID *addr)
-{
- UINT32 size;
- LosMemDynNode *node = NULL;
- LosMemDynNode *sentinel = NULL;
-
- size = ((LosMemPoolInfo *)pool)->poolSize;
- if (OS_MEM_MIDDLE_ADDR_OPEN_END(pool + 1, addr, (UINTPTR)pool + size)) {
- return TRUE;
- }
-
- sentinel = OS_MEM_END_NODE(pool, size);
- while (OsMemIsLastSentinelNode(sentinel) == FALSE) {
- size = OS_MEM_NODE_GET_SIZE(sentinel->selfNode.sizeAndFlag);
- node = OsMemSentinelNodeGet(sentinel);
- sentinel = OS_MEM_END_NODE(node, size);
- if (OS_MEM_MIDDLE_ADDR_OPEN_END(node, addr, (UINTPTR)node + size)) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-STATIC INLINE BOOL OsMemIsNodeValid(const LosMemDynNode *node, const LosMemDynNode *startNode,
- const LosMemDynNode *endNode,
- const LosMemPoolInfo *poolInfo)
-{
- if (!OS_MEM_MIDDLE_ADDR(startNode, node, endNode)) {
- return FALSE;
- }
-
- if (OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- if (!OS_MEM_MAGIC_VALID(node->selfNode.freeNodeInfo.pstPrev)) {
- return FALSE;
- }
- return TRUE;
- }
-
- if (!OsMemAddrValidCheck(poolInfo, node->selfNode.freeNodeInfo.pstPrev)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-STATIC INLINE UINT32 OsMemCheckUsedNode(const VOID *pool, const LosMemDynNode *node)
-{
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
- LosMemDynNode *startNode = (LosMemDynNode *)OS_MEM_FIRST_NODE(pool);
- LosMemDynNode *endNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, poolInfo->poolSize);
- LosMemDynNode *nextNode = NULL;
- BOOL doneFlag = FALSE;
-
- do {
- do {
- if (!OsMemIsNodeValid(node, startNode, endNode, poolInfo)) {
- break;
- }
-
- if (!OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- break;
- }
-
- nextNode = OS_MEM_NEXT_NODE(node);
- if (!OsMemIsNodeValid(nextNode, startNode, endNode, poolInfo)) {
- break;
- }
-
- if (nextNode->selfNode.preNode != node) {
- break;
- }
-
- if ((node != startNode) &&
- ((!OsMemIsNodeValid(node->selfNode.preNode, startNode, endNode, poolInfo)) ||
- (OS_MEM_NEXT_NODE(node->selfNode.preNode) != node))) {
- break;
- }
- doneFlag = TRUE;
- } while (0);
-
- if (!doneFlag) {
- if (OsMemIsLastSentinelNode(endNode) == FALSE) {
- startNode = OsMemSentinelNodeGet(endNode);
- endNode = OS_MEM_END_NODE(startNode, OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag));
- continue;
- }
- return LOS_NOK;
- }
- } while (!doneFlag);
-
- return LOS_OK;
-}
-
-#endif
-
-/*
- * Description : set magic & taskid
- * Input : node -- the node which will be set magic & taskid
- */
-STATIC INLINE VOID OsMemSetMagicNumAndTaskID(LosMemDynNode *node)
-{
- LosTaskCB *runTask = OsCurrTaskGet();
-
- OS_MEM_SET_MAGIC(node->selfNode.freeNodeInfo.pstPrev);
-
- /*
- * If the operation occured before task initialization(runTask was not assigned)
- * or in interrupt, make the value of taskid of node to 0xffffffff
- */
- if ((runTask != NULL) && OS_INT_INACTIVE) {
- OS_MEM_TASKID_SET(node, runTask->taskID);
- } else {
- /* If the task mode does not initialize, the field is the 0xffffffff */
- node->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)OS_NULL_INT;
- }
-}
-
-LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsMemPoolDlinkcheck(const LosMemPoolInfo *pool, LOS_DL_LIST listHead)
-{
- if (!OsMemAddrValidCheck(pool, listHead.pstPrev) ||
- !OsMemAddrValidCheck(pool, listHead.pstNext)) {
- return LOS_NOK;
- }
-
- if (!IS_ALIGNED(listHead.pstPrev, sizeof(VOID *)) ||
- !IS_ALIGNED(listHead.pstNext, sizeof(VOID *))) {
- return LOS_NOK;
- }
-
- return LOS_OK;
-}
-
-/*
- * Description : show mem pool header info
- * Input : pool --Pointer to memory pool
- */
-LITE_OS_SEC_TEXT_MINOR VOID OsMemPoolHeadInfoPrint(const VOID *pool)
-{
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
- UINT32 dlinkNum;
- UINT32 flag = 0;
- const LosMultipleDlinkHead *dlinkHead = NULL;
-
- if (!IS_ALIGNED(poolInfo, sizeof(VOID *))) {
- PRINT_ERR("wrong mem pool addr: %p, func:%s,line:%d\n", poolInfo, __FUNCTION__, __LINE__);
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("wrong mem pool addr: %p, func:%s,line:%d\n", poolInfo, __FUNCTION__, __LINE__);
-#endif
- return;
- }
-
- dlinkHead = (const LosMultipleDlinkHead *)(VOID *)(poolInfo + 1);
- for (dlinkNum = 0; dlinkNum < OS_MULTI_DLNK_NUM; dlinkNum++) {
- if (OsMemPoolDlinkcheck(pool, dlinkHead->listHead[dlinkNum])) {
- flag = 1;
- PRINT_ERR("DlinkHead[%u]: pstPrev:%p, pstNext:%p\n",
- dlinkNum, dlinkHead->listHead[dlinkNum].pstPrev, dlinkHead->listHead[dlinkNum].pstNext);
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("DlinkHead[%u]: pstPrev:%p, pstNext:%p\n",
- dlinkNum, dlinkHead->listHead[dlinkNum].pstPrev, dlinkHead->listHead[dlinkNum].pstNext);
-#endif
- }
- }
- if (flag) {
- PRINTK("mem pool info: poolAddr:%p, poolSize:0x%x\n", poolInfo->pool, poolInfo->poolSize);
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- PRINTK("mem pool info: poolWaterLine:0x%x, poolCurUsedSize:0x%x\n", poolInfo->poolWaterLine,
- poolInfo->poolCurUsedSize);
-#endif
-
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("mem pool info: poolAddr:%p, poolSize:0x%x\n", poolInfo->pool, poolInfo->poolSize);
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- WriteExcInfoToBuf("mem pool info: poolWaterLine:0x%x, poolCurUsedSize:0x%x\n",
- poolInfo->poolWaterLine, poolInfo->poolCurUsedSize);
-#endif
-#endif
- }
-}
-
-STATIC VOID OsMemMagicCheckPrint(LosMemDynNode **tmpNode)
-{
- PRINT_ERR("[%s], %d, memory check error!\n"
- "memory used but magic num wrong, freeNodeInfo.pstPrev(magic num):%p \n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstPrev);
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("[%s], %d, memory check error!\n"
- "memory used but magic num wrong, freeNodeInfo.pstPrev(magic num):%p \n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstPrev);
-#endif
-}
-
-STATIC UINT32 OsMemAddrValidCheckPrint(const VOID *pool, const LosMemDynNode *endPool, LosMemDynNode **tmpNode)
-{
- if (!OsMemAddrValidCheck(pool, (*tmpNode)->selfNode.freeNodeInfo.pstPrev)) {
- PRINT_ERR("[%s], %d, memory check error!\n"
- " freeNodeInfo.pstPrev:%p is out of legal mem range[%p, %p]\n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstPrev, pool, endPool);
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("[%s], %d, memory check error!\n"
- " freeNodeInfo.pstPrev:%p is out of legal mem range[%p, %p]\n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstPrev, pool, endPool);
-#endif
- return LOS_NOK;
- }
- if (!OsMemAddrValidCheck(pool, (*tmpNode)->selfNode.freeNodeInfo.pstNext)) {
- PRINT_ERR("[%s], %d, memory check error!\n"
- " freeNodeInfo.pstNext:%p is out of legal mem range[%p, %p]\n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstNext, pool, endPool);
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("[%s], %d, memory check error!\n"
- " freeNodeInfo.pstNext:%p is out of legal mem range[%p, %p]\n",
- __FUNCTION__, __LINE__, (*tmpNode)->selfNode.freeNodeInfo.pstNext, pool, endPool);
-#endif
- return LOS_NOK;
- }
- return LOS_OK;
-}
-
-STATIC UINT32 DoOsMemIntegrityCheck(LosMemDynNode **tmpNode, const VOID *pool, const LosMemDynNode *endPool)
-{
- if (OS_MEM_NODE_GET_USED_FLAG((*tmpNode)->selfNode.sizeAndFlag)) {
- if (!OS_MEM_MAGIC_VALID((*tmpNode)->selfNode.freeNodeInfo.pstPrev)) {
- OsMemMagicCheckPrint(tmpNode);
- return LOS_NOK;
- }
- } else { /* is free node, check free node range */
- if (OsMemAddrValidCheckPrint(pool, endPool, tmpNode) == LOS_NOK) {
- return LOS_NOK;
- }
- }
- return LOS_OK;
-}
-
-STATIC UINT32 OsMemIntegrityCheck(const VOID *pool, LosMemDynNode **tmpNode, LosMemDynNode **preNode)
-{
- const LosMemPoolInfo *poolInfo = (const LosMemPoolInfo *)pool;
- LosMemDynNode *endPool = (LosMemDynNode *)((UINT8 *)pool + poolInfo->poolSize - OS_MEM_NODE_HEAD_SIZE);
-
- OsMemPoolHeadInfoPrint(pool);
- *preNode = OS_MEM_FIRST_NODE(pool);
-
- do {
- for (*tmpNode = *preNode; *tmpNode < endPool; *tmpNode = OS_MEM_NEXT_NODE(*tmpNode)) {
- if (DoOsMemIntegrityCheck(tmpNode, pool, endPool) == LOS_NOK) {
- return LOS_NOK;
- }
- *preNode = *tmpNode;
- }
-
- if (OsMemIsLastSentinelNode(*tmpNode) == FALSE) {
- *preNode = OsMemSentinelNodeGet(*tmpNode);
- endPool = OS_MEM_END_NODE(*preNode, OS_MEM_NODE_GET_SIZE((*tmpNode)->selfNode.sizeAndFlag));
- } else {
- break;
- }
- } while (1);
-
- return LOS_OK;
-}
-
-#ifdef LOSCFG_MEM_LEAKCHECK
-STATIC VOID OsMemNodeBacktraceInfo(const LosMemDynNode *tmpNode,
- const LosMemDynNode *preNode)
-{
- int i;
- PRINTK("\n broken node head LR info: \n");
- for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
- PRINTK(" LR[%d]:%p\n", i, tmpNode->selfNode.linkReg[i]);
- }
- PRINTK("\n pre node head LR info: \n");
- for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
- PRINTK(" LR[%d]:%p\n", i, preNode->selfNode.linkReg[i]);
- }
-
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("\n broken node head LR info: \n");
- for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
- WriteExcInfoToBuf("LR[%d]:%p\n", i, tmpNode->selfNode.linkReg[i]);
- }
- WriteExcInfoToBuf("\n pre node head LR info: \n");
- for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
- WriteExcInfoToBuf("LR[%d]:%p\n", i, preNode->selfNode.linkReg[i]);
- }
-#endif
-}
-#endif
-
-STATIC VOID OsMemNodeInfo(const LosMemDynNode *tmpNode,
- const LosMemDynNode *preNode)
-{
- if (tmpNode == preNode) {
- PRINTK("\n the broken node is the first node\n");
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("\n the broken node is the first node\n");
-#endif
- }
- PRINTK("\n broken node head: %p %p %p 0x%x, pre node head: %p %p %p 0x%x\n",
- tmpNode->selfNode.freeNodeInfo.pstPrev, tmpNode->selfNode.freeNodeInfo.pstNext,
- tmpNode->selfNode.preNode, tmpNode->selfNode.sizeAndFlag,
- preNode->selfNode.freeNodeInfo.pstPrev, preNode->selfNode.freeNodeInfo.pstNext,
- preNode->selfNode.preNode, preNode->selfNode.sizeAndFlag);
-
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("\n broken node head: %p %p %p 0x%x, pre node head: %p %p %p 0x%x\n",
- tmpNode->selfNode.freeNodeInfo.pstPrev, tmpNode->selfNode.freeNodeInfo.pstNext,
- tmpNode->selfNode.preNode, tmpNode->selfNode.sizeAndFlag,
- preNode->selfNode.freeNodeInfo.pstPrev, preNode->selfNode.freeNodeInfo.pstNext,
- preNode->selfNode.preNode, preNode->selfNode.sizeAndFlag);
-#endif
-#ifdef LOSCFG_MEM_LEAKCHECK
- OsMemNodeBacktraceInfo(tmpNode, preNode);
-#endif
-
- PRINTK("\n---------------------------------------------\n");
- PRINTK(" dump mem tmpNode:%p ~ %p\n", tmpNode, ((UINTPTR)tmpNode + NODEDUMPSIZE));
- OsDumpMemByte(NODEDUMPSIZE, (UINTPTR)tmpNode);
- PRINTK("\n---------------------------------------------\n");
- if (preNode != tmpNode) {
- PRINTK(" dump mem :%p ~ tmpNode:%p\n", ((UINTPTR)tmpNode - NODEDUMPSIZE), tmpNode);
- OsDumpMemByte(NODEDUMPSIZE, ((UINTPTR)tmpNode - NODEDUMPSIZE));
- PRINTK("\n---------------------------------------------\n");
- }
-}
-
-STATIC VOID OsMemIntegrityCheckError(const LosMemDynNode *tmpNode,
- const LosMemDynNode *preNode,
- UINT32 intSave)
-{
- LosTaskCB *taskCB = NULL;
- UINT32 taskID;
-
- OsMemNodeInfo(tmpNode, preNode);
-
- taskID = OS_MEM_TASKID_GET(preNode);
- if (OS_TID_CHECK_INVALID(taskID)) {
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("Task ID %u in pre node is invalid!\n", taskID);
-#endif
- MEM_UNLOCK(intSave);
- LOS_Panic("Task ID %u in pre node is invalid!\n", taskID);
- return;
- }
-
- taskCB = OS_TCB_FROM_TID(taskID);
- if (OsTaskIsUnused(taskCB) || (taskCB->taskEntry == NULL)) {
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("\r\nTask ID %u in pre node is not created or deleted!\n", taskID);
-#endif
- MEM_UNLOCK(intSave);
- LOS_Panic("\r\nTask ID %u in pre node is not created!\n", taskID);
- return;
- }
-#ifdef LOSCFG_SHELL_EXCINFO
- WriteExcInfoToBuf("cur node: %p\npre node: %p\npre node was allocated by task:%s\n",
- tmpNode, preNode, taskCB->taskName);
-#endif
- MEM_UNLOCK(intSave);
- LOS_Panic("cur node: %p\npre node: %p\npre node was allocated by task:%s\n",
- tmpNode, preNode, taskCB->taskName);
- return;
-}
-
-/*
- * Description : memory pool integrity checking
- * Input : pool --Pointer to memory pool
- * Return : LOS_OK --memory pool integrate or LOS_NOK--memory pool impaired
- */
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemIntegrityCheck(const VOID *pool)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemDynNode *preNode = NULL;
- UINT32 intSave;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
- if (OsMemIntegrityCheck(pool, &tmpNode, &preNode)) {
- goto ERROR_OUT;
- }
- MEM_UNLOCK(intSave);
- return LOS_OK;
-
-ERROR_OUT:
- OsMemIntegrityCheckError(tmpNode, preNode, intSave);
- return LOS_NOK;
-}
-
-STATIC INLINE VOID OsMemNodeDebugOperate(VOID *pool, LosMemDynNode *allocNode, UINT32 size)
-{
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- poolInfo->poolCurUsedSize += OS_MEM_NODE_GET_SIZE(allocNode->selfNode.sizeAndFlag);
- if (poolInfo->poolCurUsedSize > poolInfo->poolWaterLine) {
- poolInfo->poolWaterLine = poolInfo->poolCurUsedSize;
- }
-#endif
-
-#ifdef LOSCFG_MEM_RECORDINFO
- allocNode->selfNode.originSize = size;
-#endif
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(allocNode);
-#endif
-
-#ifdef LOSCFG_MEM_LEAKCHECK
- OsMemLinkRegisterRecord(allocNode);
-#endif
-}
-
-STATIC INLINE INT32 OsMemPoolExpand(VOID *pool, UINT32 size, UINT32 intSave)
-{
- UINT32 tryCount = MAX_SHRINK_PAGECACHE_TRY;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *newNode = NULL;
- LosMemDynNode *endNode = NULL;
- LOS_DL_LIST *listNodeHead = NULL;
-
- size = ROUNDUP(size + OS_MEM_NODE_HEAD_SIZE, PAGE_SIZE);
- endNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, poolInfo->poolSize);
-
-RETRY:
- newNode = (LosMemDynNode *)LOS_PhysPagesAllocContiguous(size >> PAGE_SHIFT);
- if (newNode == NULL) {
- if (tryCount > 0) {
- tryCount--;
- MEM_UNLOCK(intSave);
- OsTryShrinkMemory(size >> PAGE_SHIFT);
- MEM_LOCK(intSave);
- goto RETRY;
- }
-
- PRINT_ERR("OsMemPoolExpand alloc failed size = %u\n", size);
- return -1;
- }
- newNode->selfNode.sizeAndFlag = (size - OS_MEM_NODE_HEAD_SIZE);
- newNode->selfNode.preNode = (LosMemDynNode *)OS_MEM_END_NODE(newNode, size);
- listNodeHead = OS_MEM_HEAD(pool, newNode->selfNode.sizeAndFlag);
- if (listNodeHead == NULL) {
- return -1;
- }
- OsMemSentinelNodeSet(endNode, newNode, size);
- LOS_ListTailInsert(listNodeHead, &(newNode->selfNode.freeNodeInfo));
-
- endNode = (LosMemDynNode *)OS_MEM_END_NODE(newNode, size);
- (VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
-
- endNode->selfNode.preNode = newNode;
- OsMemSentinelNodeSet(endNode, NULL, 0);
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolInfo->poolCurUsedSize = sizeof(LosMemPoolInfo) + OS_MULTI_DLNK_HEAD_SIZE +
- OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag);
- poolInfo->poolWaterLine = poolInfo->poolCurUsedSize;
-#endif
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(newNode);
- OsMemNodeSave(endNode);
-#endif
- return 0;
-}
-
-VOID LOS_MemExpandEnable(VOID *pool)
-{
- if (pool == NULL) {
- return;
- }
-
- ((LosMemPoolInfo *)pool)->flag = MEM_POOL_EXPAND_ENABLE;
-}
-
-#ifdef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
-
-STATIC INLINE UINT32 OsMemAllocCheck(VOID *pool, UINT32 intSave)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemDynNode *preNode = NULL;
-
- if (OsMemIntegrityCheck(pool, &tmpNode, &preNode)) {
- OsMemIntegrityCheckError(tmpNode, preNode, intSave);
- return LOS_NOK;
- }
- return LOS_OK;
-}
-#else
-STATIC INLINE UINT32 OsMemAllocCheck(VOID *pool, UINT32 intSave)
-{
- return LOS_OK;
-}
-
-#endif
-
-
-/*
- * Description : Allocate node from Memory pool
- * Input : pool --- Pointer to memory pool
- * size --- Size of memory in bytes to allocate
- * Return : Pointer to allocated memory
- */
-STATIC INLINE VOID *OsMemAllocWithCheck(VOID *pool, UINT32 size, UINT32 intSave)
-{
- LosMemDynNode *allocNode = NULL;
- UINT32 allocSize;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- const VOID *firstNode = (const VOID *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE);
- INT32 ret;
-
- if (OsMemAllocCheck(pool, intSave) == LOS_NOK) {
- return NULL;
- }
-
- allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
- if (allocSize == 0) {
- return NULL;
- }
-retry:
-
- allocNode = OsMemFindSuitableFreeBlock(pool, allocSize);
- if (allocNode == NULL) {
- if (poolInfo->flag & MEM_POOL_EXPAND_ENABLE) {
- ret = OsMemPoolExpand(pool, allocSize, intSave);
- if (ret == 0) {
- goto retry;
- }
- }
- PRINT_ERR("---------------------------------------------------"
- "--------------------------------------------------------\n");
- MEM_UNLOCK(intSave);
- OsMemInfoPrint(pool);
- MEM_LOCK(intSave);
- PRINT_ERR("[%s] No suitable free block, require free node size: 0x%x\n", __FUNCTION__, allocSize);
- PRINT_ERR("----------------------------------------------------"
- "-------------------------------------------------------\n");
- return NULL;
- }
- if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE) <= allocNode->selfNode.sizeAndFlag) {
- OsMemSplitNode(pool, allocNode, allocSize);
- }
- OsMemListDelete(&allocNode->selfNode.freeNodeInfo, firstNode);
- OsMemSetMagicNumAndTaskID(allocNode);
- OS_MEM_NODE_SET_USED_FLAG(allocNode->selfNode.sizeAndFlag);
- if ((pool == (VOID *)OS_SYS_MEM_ADDR) || (pool == (VOID *)m_aucSysMem0)) {
- OS_MEM_ADD_USED(OS_MEM_NODE_GET_SIZE(allocNode->selfNode.sizeAndFlag), OS_MEM_TASKID_GET(allocNode));
- }
- OsMemNodeDebugOperate(pool, allocNode, size);
- return (allocNode + 1);
-}
-
-/*
- * Description : reAlloc a smaller memory node
- * Input : pool --- Pointer to memory pool
- * allocSize --- the size of new node which will be alloced
- * node --- the node which wille be realloced
- * nodeSize --- the size of old node
- * Output : node --- pointer to the new node after realloc
- */
-STATIC INLINE VOID OsMemReAllocSmaller(VOID *pool, UINT32 allocSize, LosMemDynNode *node, UINT32 nodeSize)
-{
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
-#endif
- if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE) <= nodeSize) {
- node->selfNode.sizeAndFlag = nodeSize;
- OsMemSplitNode(pool, node, allocSize);
- OS_MEM_NODE_SET_USED_FLAG(node->selfNode.sizeAndFlag);
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(node);
-#endif
- if ((pool == (VOID *)OS_SYS_MEM_ADDR) || (pool == (VOID *)m_aucSysMem0)) {
- OS_MEM_REDUCE_USED(nodeSize - allocSize, OS_MEM_TASKID_GET(node));
- }
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolInfo->poolCurUsedSize -= nodeSize - allocSize;
-#endif
- }
-#ifdef LOSCFG_MEM_LEAKCHECK
- OsMemLinkRegisterRecord(node);
-#endif
-}
-
-/*
- * Description : reAlloc a Bigger memory node after merge node and nextNode
- * Input : pool --- Pointer to memory pool
- * allocSize --- the size of new node which will be alloced
- * node --- the node which wille be realloced
- * nodeSize --- the size of old node
- * nextNode --- pointer next node which will be merged
- * Output : node --- pointer to the new node after realloc
- */
-STATIC INLINE VOID OsMemMergeNodeForReAllocBigger(VOID *pool, UINT32 allocSize, LosMemDynNode *node,
- UINT32 nodeSize, LosMemDynNode *nextNode)
-{
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
-#endif
- const VOID *firstNode = (const VOID *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE);
-
- node->selfNode.sizeAndFlag = nodeSize;
- OsMemListDelete(&nextNode->selfNode.freeNodeInfo, firstNode);
- OsMemMergeNode(nextNode);
- if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE) <= node->selfNode.sizeAndFlag) {
- OsMemSplitNode(pool, node, allocSize);
- }
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolInfo->poolCurUsedSize += (node->selfNode.sizeAndFlag - nodeSize);
- if (poolInfo->poolCurUsedSize > poolInfo->poolWaterLine) {
- poolInfo->poolWaterLine = poolInfo->poolCurUsedSize;
- }
-#endif
- if ((pool == (VOID *)OS_SYS_MEM_ADDR) || (pool == (VOID *)m_aucSysMem0)) {
- OS_MEM_ADD_USED(node->selfNode.sizeAndFlag - nodeSize, OS_MEM_TASKID_GET(node));
- }
- OS_MEM_NODE_SET_USED_FLAG(node->selfNode.sizeAndFlag);
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(node);
-#endif
-#ifdef LOSCFG_MEM_LEAKCHECK
- OsMemLinkRegisterRecord(node);
-#endif
-}
-
-#ifdef LOSCFG_MEM_MUL_POOL
-STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
-{
- VOID *nextPool = g_poolHead;
- VOID *curPool = g_poolHead;
- UINTPTR poolEnd;
- while (nextPool != NULL) {
- poolEnd = (UINTPTR)nextPool + LOS_MemPoolSizeGet(nextPool);
- if (((pool <= nextPool) && (((UINTPTR)pool + size) > (UINTPTR)nextPool)) ||
- (((UINTPTR)pool < poolEnd) && (((UINTPTR)pool + size) >= poolEnd))) {
- PRINT_ERR("pool [%p, %p) conflict with pool [%p, %p)\n",
- pool, (UINTPTR)pool + size,
- nextPool, (UINTPTR)nextPool + LOS_MemPoolSizeGet(nextPool));
- return LOS_NOK;
- }
- curPool = nextPool;
- nextPool = ((LosMemPoolInfo *)nextPool)->nextPool;
- }
-
- if (g_poolHead == NULL) {
- g_poolHead = pool;
- } else {
- ((LosMemPoolInfo *)curPool)->nextPool = pool;
- }
-
- ((LosMemPoolInfo *)pool)->nextPool = NULL;
- return LOS_OK;
-}
-#endif
-
-STATIC UINT32 OsMemInit(VOID *pool, UINT32 size)
-{
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *newNode = NULL;
- LosMemDynNode *endNode = NULL;
- LOS_DL_LIST *listNodeHead = NULL;
-
- poolInfo->pool = pool;
- poolInfo->poolSize = size;
- poolInfo->flag = MEM_POOL_EXPAND_DISABLE;
- OsDLnkInitMultiHead(OS_MEM_HEAD_ADDR(pool));
- newNode = OS_MEM_FIRST_NODE(pool);
- newNode->selfNode.sizeAndFlag = (size - (UINT32)((UINTPTR)newNode - (UINTPTR)pool) - OS_MEM_NODE_HEAD_SIZE);
- newNode->selfNode.preNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, size);
- listNodeHead = OS_MEM_HEAD(pool, newNode->selfNode.sizeAndFlag);
- if (listNodeHead == NULL) {
- return LOS_NOK;
- }
-
- LOS_ListTailInsert(listNodeHead, &(newNode->selfNode.freeNodeInfo));
- endNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, size);
- (VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
-
- endNode->selfNode.preNode = newNode;
- OsMemSentinelNodeSet(endNode, NULL, 0);
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolInfo->poolCurUsedSize = sizeof(LosMemPoolInfo) + OS_MULTI_DLNK_HEAD_SIZE +
- OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag);
- poolInfo->poolWaterLine = poolInfo->poolCurUsedSize;
-#endif
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(newNode);
- OsMemNodeSave(endNode);
-#endif
-
- return LOS_OK;
-}
-
-LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemInit(VOID *pool, UINT32 size)
-{
- UINT32 intSave;
-
- if ((pool == NULL) || (size < OS_MEM_MIN_POOL_SIZE)) {
- return OS_ERROR;
- }
-
- if (!IS_ALIGNED(size, OS_MEM_ALIGN_SIZE)) {
- PRINT_WARN("pool [%p, %p) size 0x%x sholud be aligned with OS_MEM_ALIGN_SIZE\n",
- pool, (UINTPTR)pool + size, size);
- size = OS_MEM_ALIGN(size, OS_MEM_ALIGN_SIZE) - OS_MEM_ALIGN_SIZE;
- }
-
- MEM_LOCK(intSave);
-#ifdef LOSCFG_MEM_MUL_POOL
- if (OsMemPoolAdd(pool, size)) {
- MEM_UNLOCK(intSave);
- return OS_ERROR;
- }
-#endif
-
- if (OsMemInit(pool, size)) {
-#ifdef LOSCFG_MEM_MUL_POOL
- (VOID)LOS_MemDeInit(pool);
-#endif
- MEM_UNLOCK(intSave);
- return OS_ERROR;
- }
-
- MEM_UNLOCK(intSave);
- return LOS_OK;
-}
-
-#ifdef LOSCFG_MEM_MUL_POOL
-LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemDeInit(VOID *pool)
-{
- UINT32 intSave;
- UINT32 ret = LOS_NOK;
- VOID *nextPool = NULL;
- VOID *curPool = NULL;
-
- MEM_LOCK(intSave);
- do {
- if (pool == NULL) {
- break;
- }
-
- if (pool == g_poolHead) {
- g_poolHead = ((LosMemPoolInfo *)g_poolHead)->nextPool;
- ret = LOS_OK;
- break;
- }
-
- curPool = g_poolHead;
- nextPool = g_poolHead;
- while (nextPool != NULL) {
- if (pool == nextPool) {
- ((LosMemPoolInfo *)curPool)->nextPool = ((LosMemPoolInfo *)nextPool)->nextPool;
- ret = LOS_OK;
- break;
- }
- curPool = nextPool;
- nextPool = ((LosMemPoolInfo *)nextPool)->nextPool;
- }
- } while (0);
-
- MEM_UNLOCK(intSave);
- return ret;
-}
-
-LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemPoolList(VOID)
-{
- VOID *nextPool = g_poolHead;
- UINT32 index = 0;
- while (nextPool != NULL) {
- PRINTK("pool%u :\n", index);
- index++;
- OsMemInfoPrint(nextPool);
- nextPool = ((LosMemPoolInfo *)nextPool)->nextPool;
- }
- return index;
-}
-#endif
-
-LITE_OS_SEC_TEXT VOID *LOS_MemAlloc(VOID *pool, UINT32 size)
-{
- VOID *ptr = NULL;
- UINT32 intSave;
-
- if ((pool == NULL) || (size == 0)) {
- return (size > 0) ? OsVmBootMemAlloc(size) : NULL;
- }
-
- MEM_LOCK(intSave);
- do {
- if (OS_MEM_NODE_GET_USED_FLAG(size) || OS_MEM_NODE_GET_ALIGNED_FLAG(size)) {
- break;
- }
-
- ptr = OsMemAllocWithCheck(pool, size, intSave);
- } while (0);
-
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordMalloc(ptr, size);
-#endif
- MEM_UNLOCK(intSave);
-
- return ptr;
-}
-
-LITE_OS_SEC_TEXT VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
-{
- UINT32 useSize;
- UINT32 gapSize;
- VOID *ptr = NULL;
- VOID *alignedPtr = NULL;
- LosMemDynNode *allocNode = NULL;
- UINT32 intSave;
-
- if ((pool == NULL) || (size == 0) || (boundary == 0) || !IS_POW_TWO(boundary) ||
- !IS_ALIGNED(boundary, sizeof(VOID *))) {
- return NULL;
- }
-
- MEM_LOCK(intSave);
- /*
- * sizeof(gapSize) bytes stores offset between alignedPtr and ptr,
- * the ptr has been OS_MEM_ALIGN_SIZE(4 or 8) aligned, so maximum
- * offset between alignedPtr and ptr is boundary - OS_MEM_ALIGN_SIZE
- */
- if ((boundary - sizeof(gapSize)) > ((UINT32)(-1) - size)) {
- goto out;
- }
-
- useSize = (size + boundary) - sizeof(gapSize);
- if (OS_MEM_NODE_GET_USED_FLAG(useSize) || OS_MEM_NODE_GET_ALIGNED_FLAG(useSize)) {
- goto out;
- }
-
- ptr = OsMemAllocWithCheck(pool, useSize, intSave);
-
- alignedPtr = (VOID *)OS_MEM_ALIGN(ptr, boundary);
- if (ptr == alignedPtr) {
- goto out;
- }
-
- /* store gapSize in address (ptr -4), it will be checked while free */
- gapSize = (UINT32)((UINTPTR)alignedPtr - (UINTPTR)ptr);
- allocNode = (LosMemDynNode *)ptr - 1;
- OS_MEM_NODE_SET_ALIGNED_FLAG(allocNode->selfNode.sizeAndFlag);
-#ifdef LOSCFG_MEM_RECORDINFO
- allocNode->selfNode.originSize = size;
-#endif
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSaveWithGapSize(allocNode, gapSize);
-#endif
- OS_MEM_NODE_SET_ALIGNED_FLAG(gapSize);
- *(UINT32 *)((UINTPTR)alignedPtr - sizeof(gapSize)) = gapSize;
- ptr = alignedPtr;
-out:
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordMalloc(ptr, size);
-#endif
- MEM_UNLOCK(intSave);
-
- return ptr;
-}
-
-LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsDoMemFree(VOID *pool, const VOID *ptr, LosMemDynNode *node)
-{
- UINT32 ret = OsMemCheckUsedNode(pool, node);
- if (ret == LOS_OK) {
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordFree(ptr, node->selfNode.originSize);
-#endif
- OsMemFreeNode(node, pool);
- }
- return ret;
-}
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
-LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsMemBackupCheckAndRetore(VOID *pool, VOID *ptr, LosMemDynNode *node)
-{
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *startNode = OS_MEM_FIRST_NODE(pool);
- LosMemDynNode *endNode = OS_MEM_END_NODE(pool, poolInfo->poolSize);
-
- if (OS_MEM_MIDDLE_ADDR(startNode, node, endNode)) {
- /* GapSize is bad or node is broken, we need to verify & try to restore */
- if (!OsMemChecksumVerify(&(node->selfNode))) {
- node = (LosMemDynNode *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
- return OsMemBackupTryRestore(pool, &node, ptr);
- }
- }
- return LOS_OK;
-}
-#endif
-
-LITE_OS_SEC_TEXT UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
-{
- UINT32 ret = LOS_NOK;
- UINT32 gapSize;
- UINT32 intSave;
- LosMemDynNode *node = NULL;
-
- if ((pool == NULL) || (ptr == NULL) || !IS_ALIGNED(pool, sizeof(VOID *)) || !IS_ALIGNED(ptr, sizeof(VOID *))) {
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
- do {
- gapSize = *(UINT32 *)((UINTPTR)ptr - sizeof(UINT32));
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize) && OS_MEM_NODE_GET_USED_FLAG(gapSize)) {
- PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
- goto OUT;
- }
-
- node = (LosMemDynNode *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
-
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize)) {
- gapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(gapSize);
- if ((gapSize & (OS_MEM_ALIGN_SIZE - 1)) || (gapSize > ((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE))) {
- PRINT_ERR("illegal gapSize: 0x%x\n", gapSize);
- break;
- }
- node = (LosMemDynNode *)((UINTPTR)ptr - gapSize - OS_MEM_NODE_HEAD_SIZE);
- }
-#ifndef LOSCFG_MEM_HEAD_BACKUP
- ret = OsDoMemFree(pool, ptr, node);
-#endif
- } while (0);
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- ret = OsMemBackupCheckAndRetore(pool, ptr, node);
- if (!ret) {
- ret = OsDoMemFree(pool, ptr, node);
- }
-#endif
-OUT:
- if (ret == LOS_NOK) {
- OsMemRecordFree(ptr, 0);
- }
- MEM_UNLOCK(intSave);
- return ret;
-}
-
-STATIC VOID *OsGetRealPtr(const VOID *pool, VOID *ptr)
-{
- VOID *realPtr = ptr;
- UINT32 gapSize = *((UINT32 *)((UINTPTR)ptr - sizeof(UINT32)));
-
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize) && OS_MEM_NODE_GET_USED_FLAG(gapSize)) {
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordFree(ptr, 0);
-#endif
- PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
- return NULL;
- }
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize)) {
- gapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(gapSize);
- if ((gapSize & (OS_MEM_ALIGN_SIZE - 1)) ||
- (gapSize > ((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE - (UINTPTR)pool))) {
- PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordFree(ptr, 0);
-#endif
- return NULL;
- }
- realPtr = (VOID *)((UINTPTR)ptr - (UINTPTR)gapSize);
- }
- return realPtr;
-}
-
-#ifdef LOSCFG_MEM_RECORDINFO
-STATIC INLINE VOID OsMemReallocNodeRecord(LosMemDynNode *node, UINT32 size, const VOID *ptr)
-{
- node->selfNode.originSize = size;
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(node);
-#endif
- OsMemRecordMalloc(ptr, size);
-}
-#else
-STATIC INLINE VOID OsMemReallocNodeRecord(LosMemDynNode *node, UINT32 size, const VOID *ptr)
-{
- return;
-}
-#endif
-
-STATIC VOID *OsMemRealloc(VOID *pool, const VOID *ptr, LosMemDynNode *node, UINT32 size, UINT32 intSave)
-{
- LosMemDynNode *nextNode = NULL;
- UINT32 allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
- UINT32 nodeSize = OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
- VOID *tmpPtr = NULL;
- const VOID *originPtr = ptr;
-#ifdef LOSCFG_MEM_RECORDINFO
- UINT32 originSize = node->selfNode.originSize;
-#else
- UINT32 originSize = 0;
-#endif
- if (nodeSize >= allocSize) {
- OsMemRecordFree(originPtr, originSize);
- OsMemReAllocSmaller(pool, allocSize, node, nodeSize);
- OsMemReallocNodeRecord(node, size, ptr);
- return (VOID *)ptr;
- }
-
- nextNode = OS_MEM_NEXT_NODE(node);
- if (!OS_MEM_NODE_GET_USED_FLAG(nextNode->selfNode.sizeAndFlag) &&
- ((nextNode->selfNode.sizeAndFlag + nodeSize) >= allocSize)) {
- OsMemRecordFree(originPtr, originSize);
- OsMemMergeNodeForReAllocBigger(pool, allocSize, node, nodeSize, nextNode);
- OsMemReallocNodeRecord(node, size, ptr);
- return (VOID *)ptr;
- }
-
- tmpPtr = OsMemAllocWithCheck(pool, size, intSave);
- if (tmpPtr != NULL) {
- OsMemRecordMalloc(tmpPtr, size);
- if (memcpy_s(tmpPtr, size, ptr, (nodeSize - OS_MEM_NODE_HEAD_SIZE)) != EOK) {
- MEM_UNLOCK(intSave);
- (VOID)LOS_MemFree((VOID *)pool, (VOID *)tmpPtr);
- MEM_LOCK(intSave);
- return NULL;
- }
- OsMemRecordFree(originPtr, originSize);
- OsMemFreeNode(node, pool);
- }
- return tmpPtr;
-}
-
-LITE_OS_SEC_TEXT_MINOR VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
-{
- UINT32 intSave;
- VOID *newPtr = NULL;
- LosMemDynNode *node = NULL;
-#ifdef LOSCFG_MEM_RECORDINFO
- VOID *originPtr = ptr;
-#endif
-
- if (OS_MEM_NODE_GET_USED_FLAG(size) || OS_MEM_NODE_GET_ALIGNED_FLAG(size) || (pool == NULL)) {
- return NULL;
- }
-
- if (ptr == NULL) {
- newPtr = LOS_MemAlloc(pool, size);
- goto OUT;
- }
-
- if (size == 0) {
- (VOID)LOS_MemFree(pool, ptr);
- goto OUT;
- }
-
- MEM_LOCK(intSave);
-
- ptr = OsGetRealPtr(pool, ptr);
- if (ptr == NULL) {
- goto OUT_UNLOCK;
- }
-
- node = (LosMemDynNode *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
- if (OsMemCheckUsedNode(pool, node) != LOS_OK) {
-#ifdef LOSCFG_MEM_RECORDINFO
- OsMemRecordFree(originPtr, 0);
-#endif
- goto OUT_UNLOCK;
- }
-
- newPtr = OsMemRealloc(pool, ptr, node, size, intSave);
-
-OUT_UNLOCK:
- MEM_UNLOCK(intSave);
-OUT:
- return newPtr;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemTotalUsedGet(VOID *pool)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *endNode = NULL;
- UINT32 memUsed = 0;
- UINT32 size;
- UINT32 intSave;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
-
- endNode = OS_MEM_END_NODE(pool, poolInfo->poolSize);
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;) {
- if (tmpNode == endNode) {
- memUsed += OS_MEM_NODE_HEAD_SIZE;
- if (OsMemIsLastSentinelNode(endNode) == FALSE) {
- size = OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag);
- tmpNode = OsMemSentinelNodeGet(endNode);
- endNode = OS_MEM_END_NODE(tmpNode, size);
- continue;
- } else {
- break;
- }
- } else {
- if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
- memUsed += OS_MEM_NODE_GET_SIZE(tmpNode->selfNode.sizeAndFlag);
- }
- tmpNode = OS_MEM_NEXT_NODE(tmpNode);
- }
- }
-
- MEM_UNLOCK(intSave);
-
- return memUsed;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemUsedBlksGet(VOID *pool)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- UINT32 blkNums = 0;
- UINT32 intSave;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
-
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
- blkNums++;
- }
- }
-
- MEM_UNLOCK(intSave);
-
- return blkNums;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemTaskIdGet(VOID *ptr)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)(VOID *)m_aucSysMem1;
- UINT32 intSave;
-#ifdef LOSCFG_EXC_INTERACTION
- if (ptr < (VOID *)m_aucSysMem1) {
- poolInfo = (LosMemPoolInfo *)(VOID *)m_aucSysMem0;
- }
-#endif
- if ((ptr == NULL) ||
- (ptr < (VOID *)OS_MEM_FIRST_NODE(poolInfo)) ||
- (ptr > (VOID *)OS_MEM_END_NODE(poolInfo, poolInfo->poolSize))) {
- PRINT_ERR("input ptr %p is out of system memory range[%p, %p]\n", ptr, OS_MEM_FIRST_NODE(poolInfo),
- OS_MEM_END_NODE(poolInfo, poolInfo->poolSize));
- return OS_INVALID;
- }
-
- MEM_LOCK(intSave);
-
- for (tmpNode = OS_MEM_FIRST_NODE(poolInfo); tmpNode < OS_MEM_END_NODE(poolInfo, poolInfo->poolSize);
- tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- if ((UINTPTR)ptr < (UINTPTR)tmpNode) {
- if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.preNode->selfNode.sizeAndFlag)) {
- MEM_UNLOCK(intSave);
- return (UINT32)((UINTPTR)(tmpNode->selfNode.preNode->selfNode.freeNodeInfo.pstNext));
- } else {
- MEM_UNLOCK(intSave);
- PRINT_ERR("input ptr %p is belong to a free mem node\n", ptr);
- return OS_INVALID;
- }
- }
- }
-
- MEM_UNLOCK(intSave);
- return OS_INVALID;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemFreeBlksGet(VOID *pool)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- UINT32 blkNums = 0;
- UINT32 intSave;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
-
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- if (!OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
- blkNums++;
- }
- }
-
- MEM_UNLOCK(intSave);
-
- return blkNums;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINTPTR LOS_MemLastUsedGet(VOID *pool)
-{
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *node = NULL;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- node = OS_MEM_END_NODE(pool, poolInfo->poolSize)->selfNode.preNode;
- if (OS_MEM_NODE_GET_USED_FLAG(node->selfNode.sizeAndFlag)) {
- return (UINTPTR)((CHAR *)node + OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag) + sizeof(LosMemDynNode));
- } else {
- return (UINTPTR)((CHAR *)node + sizeof(LosMemDynNode));
- }
-}
-
-/*
- * Description : reset "end node"
- * Input : pool --- Pointer to memory pool
- * preAddr --- Pointer to the pre Pointer of end node
- * Output : endNode --- pointer to "end node"
- * Return : the number of free node
- */
-LITE_OS_SEC_TEXT_MINOR VOID OsMemResetEndNode(VOID *pool, UINTPTR preAddr)
-{
- LosMemDynNode *endNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, ((LosMemPoolInfo *)pool)->poolSize);
- endNode->selfNode.sizeAndFlag = OS_MEM_NODE_HEAD_SIZE;
- if (preAddr != 0) {
- endNode->selfNode.preNode = (LosMemDynNode *)(preAddr - sizeof(LosMemDynNode));
- }
- OS_MEM_NODE_SET_USED_FLAG(endNode->selfNode.sizeAndFlag);
- OsMemSetMagicNumAndTaskID(endNode);
-
-#ifdef LOSCFG_MEM_HEAD_BACKUP
- OsMemNodeSave(endNode);
-#endif
-}
-
-UINT32 LOS_MemPoolSizeGet(const VOID *pool)
-{
- UINT32 count = 0;
- UINT32 size;
- LosMemDynNode *node = NULL;
- LosMemDynNode *sentinel = NULL;
-
- if (pool == NULL) {
- return LOS_NOK;
- }
-
- count += ((LosMemPoolInfo *)pool)->poolSize;
- sentinel = OS_MEM_END_NODE(pool, count);
-
- while (OsMemIsLastSentinelNode(sentinel) == FALSE) {
- size = OS_MEM_NODE_GET_SIZE(sentinel->selfNode.sizeAndFlag);
- node = OsMemSentinelNodeGet(sentinel);
- sentinel = OS_MEM_END_NODE(node, size);
- count += size;
- }
-
- return count;
-}
-
-LITE_OS_SEC_TEXT_MINOR VOID OsMemInfoPrint(VOID *pool)
-{
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LOS_MEM_POOL_STATUS status = {0};
-
- if (LOS_MemInfoGet(pool, &status) == LOS_NOK) {
- return;
- }
-
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- PRINTK("pool addr pool size used size free size "
- "max free node size used node num free node num UsageWaterLine\n");
- PRINTK("--------------- -------- ------- -------- "
- "-------------- ------------- ------------ ------------\n");
- PRINTK("%-16p 0x%-8x 0x%-8x 0x%-8x 0x%-16x 0x%-13x 0x%-13x 0x%-13x\n",
- poolInfo->pool, LOS_MemPoolSizeGet(pool), status.uwTotalUsedSize,
- status.uwTotalFreeSize, status.uwMaxFreeNodeSize, status.uwUsedNodeNum,
- status.uwFreeNodeNum, status.uwUsageWaterLine);
-
-#else
- PRINTK("pool addr pool size used size free size "
- "max free node size used node num free node num\n");
- PRINTK("--------------- -------- ------- -------- "
- "-------------- ------------- ------------\n");
- PRINTK("%-16p 0x%-8x 0x%-8x 0x%-8x 0x%-16x 0x%-13x 0x%-13x\n",
- poolInfo->pool, LOS_MemPoolSizeGet(pool), status.uwTotalUsedSize,
- status.uwTotalFreeSize, status.uwMaxFreeNodeSize, status.uwUsedNodeNum,
- status.uwFreeNodeNum);
-#endif
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
-{
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *tmpNode = NULL;
- UINT32 totalUsedSize = 0;
- UINT32 totalFreeSize = 0;
- UINT32 maxFreeNodeSize = 0;
- UINT32 usedNodeNum = 0;
- UINT32 freeNodeNum = 0;
- UINT32 intSave;
-
- if (poolStatus == NULL) {
- PRINT_ERR("can't use NULL addr to save info\n");
- return LOS_NOK;
- }
-
- if ((poolInfo == NULL) || ((UINTPTR)pool != (UINTPTR)poolInfo->pool)) {
- PRINT_ERR("wrong mem pool addr: %p, line:%d\n", poolInfo, __LINE__);
- return LOS_NOK;
- }
-
- tmpNode = (LosMemDynNode *)OS_MEM_END_NODE(pool, poolInfo->poolSize);
- tmpNode = (LosMemDynNode *)OS_MEM_ALIGN(tmpNode, OS_MEM_ALIGN_SIZE);
-
- if (!OS_MEM_MAGIC_VALID(tmpNode->selfNode.freeNodeInfo.pstPrev)) {
- PRINT_ERR("wrong mem pool addr: %p\n, line:%d", poolInfo, __LINE__);
- return LOS_NOK;
- }
-
- MEM_LOCK(intSave);
-
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < OS_MEM_END_NODE(pool, poolInfo->poolSize);
- tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
- if (!OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
- ++freeNodeNum;
- totalFreeSize += OS_MEM_NODE_GET_SIZE(tmpNode->selfNode.sizeAndFlag);
- if (maxFreeNodeSize < OS_MEM_NODE_GET_SIZE(tmpNode->selfNode.sizeAndFlag)) {
- maxFreeNodeSize = OS_MEM_NODE_GET_SIZE(tmpNode->selfNode.sizeAndFlag);
- }
- } else {
- ++usedNodeNum;
- totalUsedSize += OS_MEM_NODE_GET_SIZE(tmpNode->selfNode.sizeAndFlag);
- }
- }
-
- MEM_UNLOCK(intSave);
-
- poolStatus->uwTotalUsedSize = totalUsedSize;
- poolStatus->uwTotalFreeSize = totalFreeSize;
- poolStatus->uwMaxFreeNodeSize = maxFreeNodeSize;
- poolStatus->uwUsedNodeNum = usedNodeNum;
- poolStatus->uwFreeNodeNum = freeNodeNum;
-#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- poolStatus->uwUsageWaterLine = poolInfo->poolWaterLine;
-#endif
- return LOS_OK;
-}
-
-STATIC INLINE VOID OsShowFreeNode(UINT32 index, UINT32 length, const UINT32 *countNum)
-{
- UINT32 count = 0;
- PRINTK("\n block size: ");
- while (count < length) {
- PRINTK("2^%-5u", (index + OS_MIN_MULTI_DLNK_LOG2 + count));
- count++;
- }
- PRINTK("\n node number: ");
- count = 0;
- while (count < length) {
- PRINTK(" %-5u", countNum[count + index]);
- count++;
- }
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemFreeNodeShow(VOID *pool)
-{
- LOS_DL_LIST *listNodeHead = NULL;
- LosMultipleDlinkHead *headAddr = (LosMultipleDlinkHead *)((UINTPTR)pool + sizeof(LosMemPoolInfo));
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- UINT32 linkHeadIndex;
- UINT32 countNum[OS_MULTI_DLNK_NUM] = { 0 };
- UINT32 intSave;
-
- if ((poolInfo == NULL) || ((UINTPTR)pool != (UINTPTR)poolInfo->pool)) {
- PRINT_ERR("wrong mem pool addr: %p, line:%d\n", poolInfo, __LINE__);
- return LOS_NOK;
- }
-
- PRINTK("\n ************************ left free node number**********************");
- MEM_LOCK(intSave);
-
- for (linkHeadIndex = 0; linkHeadIndex <= (OS_MULTI_DLNK_NUM - 1);
- linkHeadIndex++) {
- listNodeHead = headAddr->listHead[linkHeadIndex].pstNext;
- while (listNodeHead != &(headAddr->listHead[linkHeadIndex])) {
- listNodeHead = listNodeHead->pstNext;
- countNum[linkHeadIndex]++;
- }
- }
-
- linkHeadIndex = 0;
- while (linkHeadIndex < OS_MULTI_DLNK_NUM) {
- if (linkHeadIndex + COLUMN_NUM < OS_MULTI_DLNK_NUM) {
- OsShowFreeNode(linkHeadIndex, COLUMN_NUM, countNum);
- linkHeadIndex += COLUMN_NUM;
- } else {
- OsShowFreeNode(linkHeadIndex, (OS_MULTI_DLNK_NUM - 1 - linkHeadIndex), countNum);
- break;
- }
- }
-
- MEM_UNLOCK(intSave);
- PRINTK("\n ********************************************************************\n\n");
-
- return LOS_OK;
-}
-#ifdef LOSCFG_MEM_LEAKCHECK
-LITE_OS_SEC_TEXT_MINOR VOID OsMemUsedNodeShow(VOID *pool)
-{
- LosMemDynNode *tmpNode = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- LosMemDynNode *endNode = NULL;
- UINT32 size;
- UINT32 intSave;
- UINT32 count;
-
- if (pool == NULL) {
- PRINTK("input param is NULL\n");
- return;
- }
- if (LOS_MemIntegrityCheck(pool)) {
- PRINTK("LOS_MemIntegrityCheck error\n");
- return;
- }
- MEM_LOCK(intSave);
-#ifdef __LP64__
- PRINTK("\n\rnode ");
-#else
- PRINTK("\n\rnode ");
-#endif
- for (count = 0; count < LOS_RECORD_LR_CNT; count++) {
-#ifdef __LP64__
- PRINTK(" LR[%u] ", count);
-#else
- PRINTK(" LR[%u] ", count);
-#endif
- }
- PRINTK("\n");
-
- endNode = OS_MEM_END_NODE(pool, poolInfo->poolSize);
- for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;) {
- if (tmpNode == endNode) {
- if (OsMemIsLastSentinelNode(endNode) == FALSE) {
- size = OS_MEM_NODE_GET_SIZE(endNode->selfNode.sizeAndFlag);
- tmpNode = OsMemSentinelNodeGet(endNode);
- endNode = OS_MEM_END_NODE(tmpNode, size);
- continue;
- } else {
- break;
- }
- } else {
- if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->selfNode.sizeAndFlag)) {
-#ifdef __LP64__
- PRINTK("%018p: ", tmpNode);
-#else
- PRINTK("%010p: ", tmpNode);
-#endif
- for (count = 0; count < LOS_RECORD_LR_CNT; count++) {
-#ifdef __LP64__
- PRINTK(" %018p ", tmpNode->selfNode.linkReg[count]);
-#else
- PRINTK(" %010p ", tmpNode->selfNode.linkReg[count]);
-#endif
- }
- PRINTK("\n");
- }
- tmpNode = OS_MEM_NEXT_NODE(tmpNode);
- }
- }
- MEM_UNLOCK(intSave);
- return;
-}
-#endif
-
-#ifdef LOSCFG_BASE_MEM_NODE_SIZE_CHECK
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemNodeSizeCheck(VOID *pool, VOID *ptr, UINT32 *totalSize, UINT32 *availSize)
-{
- const VOID *head = NULL;
- LosMemPoolInfo *poolInfo = (LosMemPoolInfo *)pool;
- UINT8 *endPool = NULL;
-
- if (g_memCheckLevel == LOS_MEM_CHECK_LEVEL_DISABLE) {
- return LOS_ERRNO_MEMCHECK_DISABLED;
- }
-
- if ((pool == NULL) || (ptr == NULL) || (totalSize == NULL) || (availSize == NULL)) {
- return LOS_ERRNO_MEMCHECK_PARA_NULL;
- }
-
- endPool = (UINT8 *)pool + poolInfo->poolSize;
- if (!(OS_MEM_MIDDLE_ADDR_OPEN_END(pool, ptr, endPool))) {
- return LOS_ERRNO_MEMCHECK_OUTSIDE;
- }
-
- if (g_memCheckLevel == LOS_MEM_CHECK_LEVEL_HIGH) {
- head = OsMemFindNodeCtrl(pool, ptr);
- if ((head == NULL) ||
- (OS_MEM_NODE_GET_SIZE(((LosMemDynNode *)head)->selfNode.sizeAndFlag) < ((UINTPTR)ptr - (UINTPTR)head))) {
- return LOS_ERRNO_MEMCHECK_NO_HEAD;
- }
- *totalSize = OS_MEM_NODE_GET_SIZE(((LosMemDynNode *)head)->selfNode.sizeAndFlag - sizeof(LosMemDynNode));
- *availSize = OS_MEM_NODE_GET_SIZE(((LosMemDynNode *)head)->selfNode.sizeAndFlag - ((UINTPTR)ptr -
- (UINTPTR)head));
- return LOS_OK;
- }
- if (g_memCheckLevel == LOS_MEM_CHECK_LEVEL_LOW) {
- if (ptr != (VOID *)OS_MEM_ALIGN(ptr, OS_MEM_ALIGN_SIZE)) {
- return LOS_ERRNO_MEMCHECK_NO_HEAD;
- }
- head = (const VOID *)((UINTPTR)ptr - sizeof(LosMemDynNode));
- if (OS_MEM_MAGIC_VALID(((LosMemDynNode *)head)->selfNode.freeNodeInfo.pstPrev)) {
- *totalSize = OS_MEM_NODE_GET_SIZE(((LosMemDynNode *)head)->selfNode.sizeAndFlag - sizeof(LosMemDynNode));
- *availSize = OS_MEM_NODE_GET_SIZE(((LosMemDynNode *)head)->selfNode.sizeAndFlag - sizeof(LosMemDynNode));
- return LOS_OK;
- } else {
- return LOS_ERRNO_MEMCHECK_NO_HEAD;
- }
- }
-
- return LOS_ERRNO_MEMCHECK_WRONG_LEVEL;
-}
-
-/*
- * Description : get a pool's memCtrl
- * Input : ptr -- point to source ptr
- * Return : search forward for ptr's memCtrl or "NULL"
- * attention : this func couldn't ensure the return memCtrl belongs to ptr it just find forward the most nearly one
- */
-LITE_OS_SEC_TEXT_MINOR const VOID *OsMemFindNodeCtrl(const VOID *pool, const VOID *ptr)
-{
- const VOID *head = ptr;
-
- if (ptr == NULL) {
- return NULL;
- }
-
- head = (const VOID *)OS_MEM_ALIGN(head, OS_MEM_ALIGN_SIZE);
- while (!OS_MEM_MAGIC_VALID(((LosMemDynNode *)head)->selfNode.freeNodeInfo.pstPrev)) {
- head = (const VOID *)((UINT8 *)head - sizeof(CHAR *));
- if (head <= pool) {
- return NULL;
- }
- }
- return head;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemCheckLevelSet(UINT8 checkLevel)
-{
- if (checkLevel == LOS_MEM_CHECK_LEVEL_LOW) {
- PRINTK("%s: LOS_MEM_CHECK_LEVEL_LOW \n", __FUNCTION__);
- } else if (checkLevel == LOS_MEM_CHECK_LEVEL_HIGH) {
- PRINTK("%s: LOS_MEM_CHECK_LEVEL_HIGH \n", __FUNCTION__);
- } else if (checkLevel == LOS_MEM_CHECK_LEVEL_DISABLE) {
- PRINTK("%s: LOS_MEM_CHECK_LEVEL_DISABLE \n", __FUNCTION__);
- } else {
- PRINTK("%s: wrong param, setting failed !! \n", __FUNCTION__);
- return LOS_ERRNO_MEMCHECK_WRONG_LEVEL;
- }
- g_memCheckLevel = checkLevel;
- return LOS_OK;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT8 LOS_MemCheckLevelGet(VOID)
-{
- return g_memCheckLevel;
-}
-
-
-UINT32 OsMemSysNodeCheck(VOID *dstAddr, VOID *srcAddr, UINT32 nodeLength, UINT8 pos)
-{
- UINT32 ret;
- UINT32 totalSize = 0;
- UINT32 availSize = 0;
- UINT8 *pool = m_aucSysMem1;
-#ifdef LOSCFG_EXC_INTERACTION
- if ((UINTPTR)dstAddr < ((UINTPTR)m_aucSysMem0 + OS_EXC_INTERACTMEM_SIZE)) {
- pool = m_aucSysMem0;
- }
-#endif
- if (pos == 0) { /* if this func was called by memset */
- ret = LOS_MemNodeSizeCheck(pool, dstAddr, &totalSize, &availSize);
- if ((ret == LOS_OK) && (nodeLength > availSize)) {
- PRINT_ERR("---------------------------------------------\n");
- PRINT_ERR("memset: dst inode availSize is not enough"
- " availSize = 0x%x, memset length = 0x%x\n", availSize, nodeLength);
- OsBackTrace();
- PRINT_ERR("---------------------------------------------\n");
- return LOS_NOK;
- }
- } else if (pos == 1) { /* if this func was called by memcpy */
- ret = LOS_MemNodeSizeCheck(pool, dstAddr, &totalSize, &availSize);
- if ((ret == LOS_OK) && (nodeLength > availSize)) {
- PRINT_ERR("---------------------------------------------\n");
- PRINT_ERR("memcpy: dst inode availSize is not enough"
- " availSize = 0x%x, memcpy length = 0x%x\n", availSize, nodeLength);
- OsBackTrace();
- PRINT_ERR("---------------------------------------------\n");
- return LOS_NOK;
- }
-#ifdef LOSCFG_EXC_INTERACTION
- if ((UINTPTR)srcAddr < ((UINTPTR)m_aucSysMem0 + OS_EXC_INTERACTMEM_SIZE)) {
- pool = m_aucSysMem0;
- } else {
- pool = m_aucSysMem1;
- }
-#endif
- ret = LOS_MemNodeSizeCheck(pool, srcAddr, &totalSize, &availSize);
- if ((ret == LOS_OK) && (nodeLength > availSize)) {
- PRINT_ERR("---------------------------------------------\n");
- PRINT_ERR("memcpy: src inode availSize is not enough"
- " availSize = 0x%x, memcpy length = 0x%x\n",
- availSize, nodeLength);
- OsBackTrace();
- PRINT_ERR("---------------------------------------------\n");
- return LOS_NOK;
- }
- }
- return LOS_OK;
-}
-#endif /* LOSCFG_BASE_MEM_NODE_SIZE_CHECK */
-
-#ifdef LOSCFG_MEM_MUL_MODULE
-STATIC INLINE UINT32 OsMemModCheck(UINT32 moduleID)
-{
- if (moduleID > MEM_MODULE_MAX) {
- PRINT_ERR("error module ID input!\n");
- return LOS_NOK;
- }
- return LOS_OK;
-}
-
-STATIC INLINE VOID *OsMemPtrToNode(VOID *ptr)
-{
- UINT32 gapSize;
-
- if ((UINTPTR)ptr & (OS_MEM_ALIGN_SIZE - 1)) {
- PRINT_ERR("[%s:%d]ptr:%p not align by 4byte\n", __FUNCTION__, __LINE__, ptr);
- return NULL;
- }
-
- gapSize = *((UINT32 *)((UINTPTR)ptr - sizeof(UINT32)));
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize) && OS_MEM_NODE_GET_USED_FLAG(gapSize)) {
- PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
- return NULL;
- }
- if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize)) {
- gapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(gapSize);
- if ((gapSize & (OS_MEM_ALIGN_SIZE - 1)) || (gapSize > ((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE))) {
- PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
- return NULL;
- }
-
- ptr = (VOID *)((UINTPTR)ptr - gapSize);
- }
-
- return (VOID *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
-}
-
-STATIC INLINE UINT32 OsMemNodeSizeGet(VOID *ptr)
-{
- LosMemDynNode *node = (LosMemDynNode *)OsMemPtrToNode(ptr);
- if (node == NULL) {
- return 0;
- }
-
- return OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
-}
-
-VOID *LOS_MemMalloc(VOID *pool, UINT32 size, UINT32 moduleID)
-{
- UINT32 intSave;
- VOID *ptr = NULL;
- VOID *node = NULL;
- if (OsMemModCheck(moduleID) == LOS_NOK) {
- return NULL;
- }
- ptr = LOS_MemAlloc(pool, size);
- if (ptr != NULL) {
- MEM_LOCK(intSave);
- g_moduleMemUsedSize[moduleID] += OsMemNodeSizeGet(ptr);
- node = OsMemPtrToNode(ptr);
- if (node != NULL) {
- OS_MEM_MODID_SET(node, moduleID);
- }
- MEM_UNLOCK(intSave);
- }
- return ptr;
-}
-
-VOID *LOS_MemMallocAlign(VOID *pool, UINT32 size, UINT32 boundary, UINT32 moduleID)
-{
- UINT32 intSave;
- VOID *ptr = NULL;
- VOID *node = NULL;
- if (OsMemModCheck(moduleID) == LOS_NOK) {
- return NULL;
- }
- ptr = LOS_MemAllocAlign(pool, size, boundary);
- if (ptr != NULL) {
- MEM_LOCK(intSave);
- g_moduleMemUsedSize[moduleID] += OsMemNodeSizeGet(ptr);
- node = OsMemPtrToNode(ptr);
- if (node != NULL) {
- OS_MEM_MODID_SET(node, moduleID);
- }
- MEM_UNLOCK(intSave);
- }
- return ptr;
-}
-
-UINT32 LOS_MemMfree(VOID *pool, VOID *ptr, UINT32 moduleID)
-{
- UINT32 intSave;
- UINT32 ret;
- UINT32 size;
- LosMemDynNode *node = NULL;
-
- if ((OsMemModCheck(moduleID) == LOS_NOK) || (ptr == NULL) || (pool == NULL)) {
- return LOS_NOK;
- }
-
- node = (LosMemDynNode *)OsMemPtrToNode(ptr);
- if (node == NULL) {
- return LOS_NOK;
- }
-
- size = OS_MEM_NODE_GET_SIZE(node->selfNode.sizeAndFlag);
-
- if (moduleID != OS_MEM_MODID_GET(node)) {
- PRINT_ERR("node[%p] alloced in module %lu, but free in module %u\n node's taskID: 0x%x\n",
- ptr, OS_MEM_MODID_GET(node), moduleID, OS_MEM_TASKID_GET(node));
- moduleID = OS_MEM_MODID_GET(node);
- }
-
- ret = LOS_MemFree(pool, ptr);
- if (ret == LOS_OK) {
- MEM_LOCK(intSave);
- g_moduleMemUsedSize[moduleID] -= size;
- MEM_UNLOCK(intSave);
- }
- return ret;
-}
-
-VOID *LOS_MemMrealloc(VOID *pool, VOID *ptr, UINT32 size, UINT32 moduleID)
-{
- VOID *newPtr = NULL;
- UINT32 oldNodeSize;
- UINT32 intSave;
- LosMemDynNode *node = NULL;
- UINT32 oldModuleID = moduleID;
-
- if ((OsMemModCheck(moduleID) == LOS_NOK) || (pool == NULL)) {
- return NULL;
- }
-
- if (ptr == NULL) {
- return LOS_MemMalloc(pool, size, moduleID);
- }
-
- node = (LosMemDynNode *)OsMemPtrToNode(ptr);
- if (node == NULL) {
- return NULL;
- }
-
- if (moduleID != OS_MEM_MODID_GET(node)) {
- PRINT_ERR("a node[%p] alloced in module %lu, but realloc in module %u\n node's taskID: %lu\n",
- ptr, OS_MEM_MODID_GET(node), moduleID, OS_MEM_TASKID_GET(node));
- oldModuleID = OS_MEM_MODID_GET(node);
- }
-
- if (size == 0) {
- (VOID)LOS_MemMfree(pool, ptr, oldModuleID);
- return NULL;
- }
-
- oldNodeSize = OsMemNodeSizeGet(ptr);
- newPtr = LOS_MemRealloc(pool, ptr, size);
- if (newPtr != NULL) {
- MEM_LOCK(intSave);
- g_moduleMemUsedSize[moduleID] += OsMemNodeSizeGet(newPtr);
- g_moduleMemUsedSize[oldModuleID] -= oldNodeSize;
- node = (LosMemDynNode *)OsMemPtrToNode(newPtr);
- OS_MEM_MODID_SET(node, moduleID);
- MEM_UNLOCK(intSave);
- }
- return newPtr;
-}
-
-UINT32 LOS_MemMusedGet(UINT32 moduleID)
-{
- if (OsMemModCheck(moduleID) == LOS_NOK) {
- return OS_NULL_INT;
- }
- return g_moduleMemUsedSize[moduleID];
-}
-#endif
-
-STATUS_T OsKHeapInit(size_t size)
-{
- STATUS_T ret;
- VOID *ptr = NULL;
- /*
- * roundup to MB aligned in order to set kernel attributes. kernel text/code/data attributes
- * should page mapping, remaining region should section mapping. so the boundary should be
- * MB aligned.
- */
- UINTPTR end = ROUNDUP(g_vmBootMemBase + size, MB);
- size = end - g_vmBootMemBase;
-
- ptr = OsVmBootMemAlloc(size);
- if (!ptr) {
- PRINT_ERR("vmm_kheap_init boot_alloc_mem failed! %d\n", size);
- return -1;
- }
-
- m_aucSysMem0 = m_aucSysMem1 = ptr;
- ret = LOS_MemInit(m_aucSysMem0, size);
- if (ret != LOS_OK) {
- PRINT_ERR("vmm_kheap_init LOS_MemInit failed!\n");
- g_vmBootMemBase -= size;
- return ret;
- }
- LOS_MemExpandEnable(OS_SYS_MEM_ADDR);
- return LOS_OK;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
diff --git a/kernel/base/mem/bestfit_little/los_heap.c b/kernel/base/mem/bestfit_little/los_heap.c
deleted file mode 100644
index 3a3e4da4..00000000
--- a/kernel/base/mem/bestfit_little/los_heap.c
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "string.h"
-#include "securec.h"
-#include "los_hwi.h"
-#include "los_typedef.h"
-#include "los_heap_pri.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-static UINT32 g_memAllocCount = 0;
-static UINT32 g_memFreeCount = 0;
-
-#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
-static UINT32 g_memCurHeapUsed = 0;
-static UINT32 g_memMaxHeapUsed = 0;
-#endif
-
-#define HEAP_CAST(t, exp) ((t)(exp))
-#define HEAP_ALIGN 4
-#define HEAP_TAIL_NODE_SIZE_THRESHOLD 1024
-
-/*
- * Description : look up the next memory node according to one memory node in the memory block list.
- * Input : struct LosHeapManager *heapMan --- Pointer to the manager,to distinguish heap
- * struct LosHeapNode *node --- Size of memory in bytes to allocate
- * Return : Pointer to next memory node
- */
-struct LosHeapNode* OsHeapPrvGetNext(struct LosHeapManager *heapMan, struct LosHeapNode *node)
-{
- return (heapMan->tail == node) ? NULL : (struct LosHeapNode *)(UINTPTR)(node->data + node->size);
-}
-
-/*
- * Description : To initialize the heap memory and get the begin address and size of heap memory,
- * then initialize LosHeapManager.
- * Input : VOID *pool --- begin address of the heap memory pool
- * UITN32 size --- size of the heap memory pool
- * Return : 1:success 0:error
- */
-BOOL OsHeapInit(VOID *pool, UINT32 size)
-{
- struct LosHeapNode *node = NULL;
- struct LosHeapManager *heapMan = HEAP_CAST(struct LosHeapManager *, pool);
-
- if ((heapMan == NULL) || (size <= (sizeof(struct LosHeapNode) + sizeof(struct LosHeapManager)))) {
- return FALSE;
- }
-
- // Ignore the return code when matching CSEC rule 6.6(2).
- (VOID)memset_s(pool, size, 0, size);
-
- heapMan->size = size;
-
- node = heapMan->head = (struct LosHeapNode *)((UINT8*)pool + sizeof(struct LosHeapManager));
-
- heapMan->tail = node;
-
- node->used = 0;
- node->prev = NULL;
- node->size = size - sizeof(struct LosHeapNode) - sizeof(struct LosHeapManager);
-
- return TRUE;
-}
-
-/*
- * Description : update used size
- * Input : size --- alloc memory size
- * ret --- memory chunk
- */
-VOID OsHeapUpdateUsedSize(UINT32 size, VOID *ret)
-{
-#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
- g_memCurHeapUsed += (size + sizeof(struct LosHeapNode));
- if (g_memCurHeapUsed > g_memMaxHeapUsed) {
- g_memMaxHeapUsed = g_memCurHeapUsed;
- }
-#endif
-
- if (ret != NULL) {
- g_memAllocCount++;
- }
-}
-
-/*
- * Description : To alloc memory block from the heap memory poll
- * Input : VOID *pool --- Pointer to the manager,to distinguish heap
- * UINT32 size --- size of the heap memory pool
- * Return : NULL:error, other value:the address of the memory we alloced
- */
-VOID* OsHeapAlloc(VOID *pool, UINT32 size)
-{
- struct LosHeapNode *node = NULL;
- struct LosHeapNode *next = NULL;
- struct LosHeapNode *best = NULL;
- VOID *ret = NULL;
- UINT32 alignSize = ALIGNE(size);
-
- struct LosHeapManager *heapMan = HEAP_CAST(struct LosHeapManager *, pool);
- if (heapMan == NULL) {
- return NULL;
- }
-
- node = heapMan->tail;
- while (node != NULL) {
- if ((node->used == 0) && (node->size >= alignSize) &&
- ((best == NULL) || (best->size > node->size))) {
- best = node;
- if (best->size == alignSize) {
- goto SIZE_MATCH;
- }
- }
- node = node->prev;
- }
-
- /* alloc failed */
- if (best == NULL) {
- PRINT_ERR("there's not enough whole to alloc %x Bytes!\n", alignSize);
- goto OUT;
- }
-
- if ((best->size - alignSize) > sizeof(struct LosHeapNode)) {
- /* hole divide into 2 */
- node = (struct LosHeapNode*)(UINTPTR)(best->data + alignSize);
-
- node->used = 0;
- node->size = best->size - alignSize - sizeof(struct LosHeapNode);
- node->prev = best;
-
- if (best != heapMan->tail) {
- next = OsHeapPrvGetNext(heapMan, node);
- if (next != NULL) {
- next->prev = node;
- }
- } else {
- heapMan->tail = node;
- }
-
- best->size = alignSize;
- }
-
-SIZE_MATCH:
- best->align = 0;
- best->used = 1;
- ret = best->data;
-
- OsHeapUpdateUsedSize(alignSize, ret);
-OUT:
-
- return ret;
-}
-
-/*
- * Description : To alloc memory block from the heap memory poll with
- * Input : VOID *pool --- Pointer to the manager,to distinguish heap
- * UINT32 size --- size of the heap memory pool
- * UINT32 boundary --- boundary the heap needs align
- * Return : NULL:error, other value:the address of the memory we alloced
- */
-VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
-{
- UINT32 useSize;
- UINT32 gapSize;
- VOID *ret = NULL;
- VOID *alignedPtr = NULL;
-
- if ((pool == NULL) || (size == 0) || (boundary < sizeof(VOID *)) || !IS_ALIGNED(boundary, boundary)) {
- return NULL;
- }
-
- /* worst case is that the node happen to be 4 bytes ahead of the boundary */
- useSize = (size + boundary) - sizeof(VOID*);
- if (useSize < size) {
- return NULL;
- }
-
- ret = OsHeapAlloc(pool, useSize);
- if (ret != NULL) {
- alignedPtr = (VOID *)(UINTPTR)OS_MEM_ALIGN(ret, boundary);
- if (ret == alignedPtr) {
- goto OUT;
- }
-
- gapSize = (UINTPTR)alignedPtr - (UINTPTR)ret;
- OS_MEM_SET_ALIGN_FLAG(gapSize);
- *((UINT32 *)((UINTPTR)alignedPtr - (sizeof(UINTPTR) / sizeof(UINT8)))) = gapSize;
-
- ret = alignedPtr;
- }
-OUT:
- return ret;
-}
-
-STATIC VOID OsDoHeapFree(struct LosHeapManager *heapMan, struct LosHeapNode *curNode)
-{
- struct LosHeapNode *node = curNode;
- struct LosHeapNode *next = NULL;
- /* set to unused status */
- node->used = 0;
-
-#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
- if (g_memCurHeapUsed >= (node->size + sizeof(struct LosHeapNode))) {
- g_memCurHeapUsed -= (node->size + sizeof(struct LosHeapNode));
- }
-#endif
-
- /* unused region before and after combination */
- while (node->prev && !node->prev->used) {
- node = node->prev;
- }
-
- next = OsHeapPrvGetNext(heapMan, node);
- while (next != NULL) {
- if (next->used) {
- next->prev = node;
- break;
- }
- node->size += sizeof(struct LosHeapNode) + next->size;
- if (heapMan->tail == next) {
- heapMan->tail = node;
- }
- next = OsHeapPrvGetNext(heapMan, node);
- }
-}
-
-/*
- * Description : To free the memory block from heap memory poll
- * Input : VOID* pool --- Pointer to the manager,to distinguish heap
- * VOID* ptr --- the pointer of heap memory we want to free
- * Return : 1:success 0:error
- */
-BOOL OsHeapFree(VOID *pool, VOID *ptr)
-{
- struct LosHeapNode *node = NULL;
-
- UINT32 gapSize;
- BOOL ret = TRUE;
-
- struct LosHeapManager *heapMan = HEAP_CAST(struct LosHeapManager *, pool);
- if ((heapMan == NULL) || (ptr == NULL)) {
- return LOS_NOK;
- }
-
- /* find the real ptr through gap size */
- gapSize = *((UINT32 *)((UINTPTR)ptr - (sizeof(UINTPTR) / sizeof(UINT8))));
- if (OS_MEM_GET_ALIGN_FLAG(gapSize)) {
- gapSize = OS_MEM_GET_ALIGN_GAPSIZE(gapSize);
- ptr = (VOID *)((UINTPTR)ptr - gapSize);
- }
-
- if (((UINTPTR)ptr < (UINTPTR)heapMan->head) ||
- ((UINTPTR)ptr > ((UINTPTR)heapMan->tail + sizeof(struct LosHeapNode)))) {
- PRINT_ERR("0x%x out of range!\n", (UINTPTR)ptr);
- return FALSE;
- }
-
- node = ((struct LosHeapNode *)ptr) - 1;
- /* check if the address is a node of the heap memory list */
- if ((node->used == 0) || (!((UINTPTR)node == (UINTPTR)heapMan->head) &&
- (((UINTPTR)node->prev < (UINTPTR)heapMan->head) ||
- ((UINTPTR)node->prev > ((UINTPTR)heapMan->tail + sizeof(struct LosHeapNode))) ||
- ((UINTPTR)OsHeapPrvGetNext(heapMan, node->prev) != (UINTPTR)node)))) {
- ret = FALSE;
- goto OUT;
- }
-
- OsDoHeapFree(heapMan, node);
-
-OUT:
- if (ret == TRUE) {
- g_memFreeCount++;
- }
-
- return ret;
-}
-
-/*
- * Description : print heap information
- * Input : pool --- Pointer to the manager, to distinguish heap
- */
-VOID OsAlarmHeapInfo(VOID *pool)
-{
- struct LosHeapManager *heapMan = HEAP_CAST(struct LosHeapManager *, pool);
- LosHeapStatus status = {0};
- (VOID)heapMan;
-
- if (OsHeapStatisticsGet(pool, &status) == LOS_NOK) {
- return;
- }
-
- PRINT_INFO("pool addr pool size used size free size max free alloc Count free Count\n");
- PRINT_INFO("0x%-8x 0x%-8x 0x%-8x 0x%-8x 0x%-8x 0x%-8x 0x%-8x\n",
- pool, heapMan->size, status.totalUsedSize, status.totalFreeSize, status.maxFreeNodeSize,
- status.usedNodeNum, status.freeNodeNum);
-}
-
-/*
- * Description : collect heap statistics
- * Input : pool --- Pointer to the manager, to distinguish heap
- * Output : status --- heap statistics
- * Return : LOS_OK on success or error code on failure
- */
-UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status)
-{
- UINT32 heapUsed = 0;
- UINT32 maxFreeNodeSize = 0;
- UINT32 freeNodeNum = 0;
- UINT32 usedNodeNum = 0;
-
- struct LosHeapNode *node = NULL;
- struct LosHeapManager *ramHeap = HEAP_CAST(struct LosHeapManager *, pool);
-
- if (ramHeap == NULL) {
- return LOS_NOK;
- }
-
- if (status == NULL) {
- return LOS_NOK;
- }
-
- /* heap mannager header use heap space */
- heapUsed += sizeof(struct LosHeapManager);
-
- node = ramHeap->tail;
- while (node != NULL) {
- if (node->used) {
- heapUsed += (node->size + sizeof(struct LosHeapNode));
- usedNodeNum++;
- } else {
- if (node->size > maxFreeNodeSize) {
- maxFreeNodeSize = node->size;
- }
- freeNodeNum++;
- }
- node = node->prev;
- }
-
- if (ramHeap->size < heapUsed) {
- return LOS_NOK;
- }
-
- status->totalUsedSize = heapUsed;
- status->maxFreeNodeSize = maxFreeNodeSize;
- status->totalFreeSize = ramHeap->size - status->totalUsedSize;
- status->usedNodeNum = usedNodeNum;
- status->freeNodeNum = freeNodeNum;
-
- return LOS_OK;
-}
-
-#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
-UINT32 LOS_HeapGetHeapMemoryPeak(VOID)
-{
- return g_memMaxHeapUsed;
-}
-#endif
-
-/*
- * Description : get max free block size
- * Input : pool --- Pointer to the manager, to distinguish heap
- * Return : max free block size
- */
-UINT32 OsHeapGetMaxFreeBlkSize(VOID *pool)
-{
- UINT32 size = 0;
- UINT32 temp;
- struct LosHeapNode *node = NULL;
- struct LosHeapManager *ramHeap = HEAP_CAST(struct LosHeapManager *, pool);
-
- if (ramHeap == NULL) {
- return LOS_NOK;
- }
-
- node = ramHeap->tail;
- while (node != NULL) {
- if (!(node->used)) {
- temp = node->size;
- if (temp > size) {
- size = temp;
- }
- }
- node = node->prev;
- }
- return size;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
diff --git a/kernel/base/mem/common/los_memstat.c b/kernel/base/mem/common/los_memstat.c
old mode 100644
new mode 100755
index dea9dbdf..957159dd
--- a/kernel/base/mem/common/los_memstat.c
+++ b/kernel/base/mem/common/los_memstat.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -123,4 +123,4 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskSlabUsage(UINT32 taskID)
#if __cplusplus
}
#endif /* __cplusplus */
-#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/kernel/base/mem/common/memrecord/los_binarytree.c b/kernel/base/mem/common/memrecord/los_binarytree.c
deleted file mode 100644
index 425f3331..00000000
--- a/kernel/base/mem/common/memrecord/los_binarytree.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifdef LOSCFG_MEM_RECORDINFO
-#include "los_binarytree_pri.h"
-#include "los_typedef.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-UINT32 OsBinTreeInsert(const VOID *node, UINT32 nodeLen, BinNode **leaf,
- BinNode *(*GetMyBinNode)(UINT32 *nodeID),
- INT32 (*CompareNode)(const VOID *node1, const VOID *node2))
-{
- UINT32 nodeID;
- INT32 result;
- BinNode **currentNode = leaf;
-
- if (leaf == NULL) {
- return OS_INVALID;
- }
-
- do {
- if (*currentNode != NULL) {
- result = CompareNode(node, (const VOID *)(*currentNode));
- if (result == 0) {
- return (*currentNode)->nodeID;
- } else if (result < 0) {
- currentNode = (BinNode **)(&((*currentNode)->left));
- } else {
- currentNode = (BinNode **)(&((*currentNode)->right));
- }
- } else {
- (*currentNode) = GetMyBinNode(&nodeID);
- if (*currentNode == NULL) {
- return OS_INVALID;
- }
-
- (VOID)memcpy_s((*currentNode)->keyValue, (nodeLen - sizeof(BinNode)),
- ((BinNode *)node)->keyValue, (nodeLen - sizeof(BinNode)));
- (*currentNode)->nodeID = nodeID;
- /* initialize the children to NULL */
- (*currentNode)->left = NULL;
- (*currentNode)->right = NULL;
-
- return (*currentNode)->nodeID;
- }
- } while (1);
-}
-
-/* LRNODE */
-LinkRegNode g_linkRegNode[LR_COUNT];
-UINT32 g_linkRegNodeIndex = 0;
-LinkRegNode *g_linkRegRoot = NULL;
-INT32 OsCompareLRNode(const VOID *node1, const VOID *node2)
-{
- LinkRegNode *linkRegNode1 = (LinkRegNode *)node1;
- LinkRegNode *linkRegNode2 = (LinkRegNode *)node2;
- if (linkRegNode1->linkReg1 < linkRegNode2->linkReg1) {
- return -1;
- } else if ((linkRegNode1->linkReg1 == linkRegNode2->linkReg1) &&
- (linkRegNode1->linkReg2 < linkRegNode2->linkReg2)) {
- return -1;
- } else if ((linkRegNode1->linkReg1 == linkRegNode2->linkReg1) &&
- (linkRegNode1->linkReg2 == linkRegNode2->linkReg2) &&
- (linkRegNode1->linkReg3 < linkRegNode2->linkReg3)) {
- return -1;
- } else if ((linkRegNode1->linkReg1 == linkRegNode2->linkReg1) &&
- (linkRegNode1->linkReg2 == linkRegNode2->linkReg2) &&
- (linkRegNode1->linkReg3 == linkRegNode2->linkReg3)) {
- return 0;
- } else {
- return 1;
- }
-}
-
-BinNode *OsGetLRBinNode(UINT32 *nodeID)
-{
- if (g_linkRegNodeIndex < LR_COUNT) {
- *nodeID = g_linkRegNodeIndex;
- return (BinNode *)(&g_linkRegNode[g_linkRegNodeIndex++]);
- } else {
- *nodeID = (UINT32)-1;
- return NULL;
- }
-}
-
-/* ADDRNODE */
-AddrNode g_addrNode[ADDR_COUNT];
-UINT32 g_addrNodeIndex = 0;
-AddrNode *g_addrRoot = NULL;
-INT32 OsCompareAddrNode(const VOID *node1, const VOID *node2)
-{
- AddrNode *addrNode1 = (AddrNode *)node1;
- AddrNode *addrNode2 = (AddrNode *)node2;
- if (addrNode1->addr < addrNode2->addr) {
- return -1;
- } else if (addrNode1->addr == addrNode2->addr) {
- return 0;
- } else {
- return 1;
- }
-}
-
-BinNode *OsGetAddrBinNode(UINT32 *nodeID)
-{
- if (g_addrNodeIndex < ADDR_COUNT) {
- *nodeID = g_addrNodeIndex;
- return (BinNode *)(&g_addrNode[g_addrNodeIndex++]);
- } else {
- *nodeID = (UINT32)-1;
- return NULL;
- }
-}
-
-/* REQSIZENODE */
-ReqSizeNode g_reqSizeNode[REQ_SIZE_COUNT];
-UINT32 g_reqSizeNodeIndex = 0;
-ReqSizeNode *g_reqSizeRoot = NULL;
-
-INT32 OsCompareReqSizeNode(const VOID *node1, const VOID *node2)
-{
- ReqSizeNode *reqSizeNode1 = (ReqSizeNode *)node1;
- ReqSizeNode *reqSizeNode2 = (ReqSizeNode *)node2;
- if (reqSizeNode1->reqSize < reqSizeNode2->reqSize) {
- return -1;
- } else if (reqSizeNode1->reqSize == reqSizeNode2->reqSize) {
- return 0;
- } else {
- return 1;
- }
-}
-
-BinNode *OsGetReqSizeBinNode(UINT32 *nodeID)
-{
- if (g_reqSizeNodeIndex < REQ_SIZE_COUNT) {
- *nodeID = g_reqSizeNodeIndex;
- return (BinNode *)(&g_reqSizeNode[g_reqSizeNodeIndex++]);
- } else {
- *nodeID = (UINT32)-1;
- return NULL;
- }
-}
-
-/* TASKIDNODE */
-STATIC TaskIDNode g_taskIDNode[TASK_ID_COUNT];
-STATIC UINT32 g_taskIDNodeIndex = 0;
-STATIC TaskIDNode *g_taskIDRoot = NULL;
-INT32 OsCompareTaskIDNode(const VOID *node1, const VOID *node2)
-{
- TaskIDNode *taskIDNode1 = (TaskIDNode *)node1;
- TaskIDNode *taskIDNode2 = (TaskIDNode *)node2;
- if (taskIDNode1->taskID < taskIDNode2->taskID) {
- return -1;
- } else if (taskIDNode1->taskID == taskIDNode2->taskID) {
- return 0;
- } else {
- return 1;
- }
-}
-
-BinNode *OsGetTaskIDBinNode(UINT32 *nodeID)
-{
- if (g_taskIDNodeIndex < TASK_ID_COUNT) {
- *nodeID = g_taskIDNodeIndex;
- return (BinNode *)(&g_taskIDNode[g_taskIDNodeIndex++]);
- } else {
- *nodeID = (UINT32)-1;
- return NULL;
- }
-}
-#define BINARYTREE_TASKID_COUNT 11
-#define BINARYTREE_REQSIZE_COUNT 4
-STATIC const UINT32 g_binaryTreeTaskID[BINARYTREE_TASKID_COUNT] = { 33, 10, 20, 9, 42, 34, 45, 47, 46, 50, 49 };
-STATIC const UINT32 g_binaryTreeReqSize[BINARYTREE_REQSIZE_COUNT] = { 616, 136, 1708, 1580 };
-
-VOID OsBinaryTreeInit(VOID)
-{
- INT32 index;
- LinkRegNode linkRegNode;
- AddrNode node;
- TaskIDNode taskNode;
- ReqSizeNode reqNode;
- UINT32 ret;
-
- /* equal to the middle address of __text_start and __text_end */
- linkRegNode.linkReg1 = (UINTPTR)(((&__text_end - &__text_start) / 2) + &__text_start);
- linkRegNode.linkReg2 = linkRegNode.linkReg1;
- linkRegNode.linkReg3 = linkRegNode.linkReg1;
- ret = OsBinTreeInsert(&linkRegNode, sizeof(LinkRegNode), (BinNode **)&g_linkRegRoot,
- OsGetLRBinNode, OsCompareLRNode);
- if (ret == OS_INVALID) {
- PRINT_ERR("binary tree init failed\n");
- }
-
- /* equal to the middle address of __bss_end and OS_SYS_FUNC_ADDR_END */
- node.addr = ((OS_SYS_FUNC_ADDR_END - (UINTPTR)(&__bss_end)) >> 1) + (UINTPTR)(&__bss_end);
- ret = OsBinTreeInsert(&node, sizeof(AddrNode), (BinNode **)&g_addrRoot,
- OsGetAddrBinNode, OsCompareAddrNode);
- if (ret == OS_INVALID) {
- PRINT_ERR("binary tree init failed\n");
- }
-
- for (index = 0; index < BINARYTREE_TASKID_COUNT; index++) {
- taskNode.taskID = g_binaryTreeTaskID[index];
- ret = OsBinTreeInsert(&taskNode, sizeof(TaskIDNode), (BinNode **)&g_taskIDRoot,
- OsGetTaskIDBinNode, OsCompareTaskIDNode);
- if (ret == OS_INVALID) {
- PRINT_ERR("binary tree init failed\n");
- }
- }
-
- for (index = 0; index < BINARYTREE_REQSIZE_COUNT; index++) {
- reqNode.reqSize = g_binaryTreeReqSize[index];
- ret = OsBinTreeInsert(&reqNode, sizeof(ReqSizeNode), (BinNode **)&g_reqSizeRoot,
- OsGetReqSizeBinNode, OsCompareReqSizeNode);
- if (ret == OS_INVALID) {
- PRINT_ERR("binary tree init failed\n");
- }
- }
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif
diff --git a/kernel/base/mem/common/memrecord/los_memrecord.c b/kernel/base/mem/common/memrecord/los_memrecord.c
deleted file mode 100644
index ecff1f7c..00000000
--- a/kernel/base/mem/common/memrecord/los_memrecord.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_memrecord_pri.h"
-#include "stdio.h"
-#include "los_binarytree_pri.h"
-#include "los_event.h"
-#include "los_exc.h"
-#include "los_task_pri.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-enum MemActType {
- OS_MEM_VALIDFREE,
- OS_MEM_INVALIDFREE,
- OS_MEM_ALLOC
-};
-
-STATIC MemRecordInfo g_memRecord1[RECORD_LEN] = {0};
-STATIC MemRecordInfo g_memRecord2[RECORD_LEN] = {0};
-STATIC MemRecordInfo *g_saveMemRecord = g_memRecord1;
-STATIC MemRecordInfo *g_printMemRecord = NULL;
-STATIC MemRecordInfo *g_curPtr = NULL;
-
-STATIC volatile UINT32 g_memRecordIndex = 0;
-STATIC volatile UINT32 g_memLastEndIndex = 0;
-STATIC EVENT_CB_S g_memShowEvent;
-
-UINT32 g_memRecordShowEnable = 1;
-STATIC UINT32 g_lastAddrNodeIndex = 0;
-STATIC UINT32 g_lastReqSizeNodeIndex = 0;
-STATIC UINT32 g_lastlinkRegNodeIndex = 0;
-
-#define INDEX_LENGTH 2
-#define ADDR_ID_LENGTH 3
-#define REQSIZE_ID_LENGTH 2
-#define ACTTYPE_LENGTH 4
-#define TASK_ID_LENGTH 2
-#define SYS_TICK_LENGTH 6
-#define LINK_REG_ID_LENGTH 2
-#define INFO_STR_LENGTH 20
-#define PRINT_STR_LENGTH 32
-#define NODE_VALUE_LENGTH 7
-#define READ_EVENT_MASK 0xFFF
-#define WRITE_EVENT 0x112
-
-STATIC VOID OsMemRecordCompressInfo(VOID)
-{
- UINT32 count;
- CHAR infoStr[INFO_STR_LENGTH];
-
- UINT32 currentIndex = g_addrNodeIndex;
- for (count = g_lastAddrNodeIndex; count < currentIndex; count++) {
- OsDecTo64F(g_addrNode[count].leaf.nodeID, infoStr, ADDR_ID_LENGTH);
- printf("~^%s%x^~\n", infoStr, g_addrNode[count].addr);
- }
- g_lastAddrNodeIndex = currentIndex;
-
- currentIndex = g_reqSizeNodeIndex;
- for (count = g_lastReqSizeNodeIndex; count < currentIndex; count++) {
- OsDecTo64F(g_reqSizeNode[count].leaf.nodeID, infoStr, REQSIZE_ID_LENGTH);
- printf("*^%s%u^*\n", infoStr, g_reqSizeNode[count].reqSize);
- }
- g_lastReqSizeNodeIndex = currentIndex;
-
- currentIndex = g_linkRegNodeIndex;
- for (count = g_lastlinkRegNodeIndex; count < currentIndex; count++) {
- OsDecTo64F(g_linkRegNode[count].leaf.nodeID, infoStr, LINK_REG_ID_LENGTH);
- printf("$^%s%x%x%x^$\n", infoStr, g_linkRegNode[count].linkReg1, g_linkRegNode[count].linkReg2,
- g_linkRegNode[count].linkReg3);
- }
- g_lastlinkRegNodeIndex = currentIndex;
-}
-
-STATIC VOID PrintPtrAssign(CHAR *printStr, UINT32 strLen, UINT32 startIndex, UINT32 index)
-{
- CHAR nodeValue[NODE_VALUE_LENGTH];
- UINT32 tmpIndex = 0;
-
- /* 3 bytes for ending "!~" and '\0'. */
- if (strLen < (INDEX_LENGTH + ADDR_ID_LENGTH + REQSIZE_ID_LENGTH + ACTTYPE_LENGTH +
- TASK_ID_LENGTH + SYS_TICK_LENGTH + LINK_REG_ID_LENGTH + index + 3)) {
- PRINT_ERR("printStr is not big enough\n");
- return;
- }
-
- OsDecTo64F(startIndex, nodeValue, INDEX_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].addrID, nodeValue, ADDR_ID_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].reqSizeID, nodeValue, REQSIZE_ID_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].actType, nodeValue, ACTTYPE_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].taskID, nodeValue, TASK_ID_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].sysTick, nodeValue, SYS_TICK_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- tmpIndex = 0;
- OsDecTo64F(g_curPtr[startIndex].linkRegID, nodeValue, LINK_REG_ID_LENGTH);
- printStr[index++] = nodeValue[tmpIndex++];
- printStr[index++] = nodeValue[tmpIndex];
-
- printStr[index++] = '!';
- printStr[index++] = '~';
- printStr[index++] = '\0';
-
- printf("%s\n", printStr);
-}
-
-STATIC VOID OsMemRecordShow(VOID)
-{
- UINT32 index = 0;
- UINT32 startIndex = g_memLastEndIndex;
- UINT32 endIndex;
- MemRecordInfo *printMemRecord = g_printMemRecord;
- CHAR printStr[PRINT_STR_LENGTH];
-
- if (g_curPtr == NULL) {
- g_curPtr = g_printMemRecord;
- }
-
- OsMemRecordCompressInfo();
-
- if (g_curPtr != NULL) {
- printStr[index++] = '~';
- printStr[index++] = '!';
- if (g_curPtr == printMemRecord) {
- while (startIndex < RECORD_LEN) {
- PrintPtrAssign(printStr, PRINT_STR_LENGTH, startIndex, index);
- startIndex++;
- }
- g_memLastEndIndex = 0;
- }
- }
-
- startIndex = g_memLastEndIndex;
- endIndex = g_memRecordIndex;
- if ((g_curPtr == g_saveMemRecord) && (g_printMemRecord != NULL) && (startIndex >= endIndex)) {
- printf("Rec:error:the printf speed is low,Rnd\n");
- startIndex = 0;
- }
-
- g_curPtr = g_saveMemRecord;
- index = 0;
- printStr[index++] = '~';
- printStr[index++] = '!';
- while (startIndex < endIndex) {
- PrintPtrAssign(printStr, PRINT_STR_LENGTH, startIndex, index);
- startIndex++;
- }
-
- g_memLastEndIndex = endIndex;
-}
-
-STATIC VOID OsMemRecordExchange(VOID)
-{
- if (g_saveMemRecord == g_memRecord1) {
- g_saveMemRecord = g_memRecord2;
- g_printMemRecord = g_memRecord1;
- } else {
- g_saveMemRecord = g_memRecord1;
- g_printMemRecord = g_memRecord2;
- }
- g_memRecordIndex = 0;
- (VOID)LOS_EventWrite(&g_memShowEvent, WRITE_EVENT);
-}
-
-#define LINK_REG1_INDEX 1
-#define LINK_REG2_INDEX 2
-#define LINK_REG3_INDEX 3
-#define LINK_REG_NUM 3
-
-STATIC INLINE VOID OsMemRecordLR(LinkRegNode *linkRegNode)
-{
- UINTPTR framePtr, framePtrTmp;
- UINT32 index = 0;
-
- linkRegNode->linkReg1 = 0;
- linkRegNode->linkReg2 = 0;
- linkRegNode->linkReg3 = 0;
-
- framePtr = Get_Fp();
- while ((framePtr > OS_SYS_FUNC_ADDR_START) &&
- (framePtr < OS_SYS_FUNC_ADDR_END) &&
- ((framePtr % sizeof(CHAR *)) == 0)) {
- framePtrTmp = framePtr;
- if (index == LINK_REG1_INDEX) {
- linkRegNode->linkReg1 = *((UINTPTR *)(framePtrTmp));
- } else if (index == LINK_REG2_INDEX) {
- linkRegNode->linkReg2 = *((UINTPTR *)(framePtrTmp));
- } else if (index == LINK_REG3_INDEX) {
- linkRegNode->linkReg3 = *((UINTPTR *)(framePtrTmp));
- }
- framePtr = *((UINTPTR *)(framePtrTmp - sizeof(UINTPTR *)));
- index++;
- if (index == (LINK_REG_NUM + 1)) {
- break;
- }
- }
-}
-
-STATIC VOID OsMemRecordTaskID(VOID)
-{
- LosTaskCB *runTask = OsCurrTaskGet();
- if (runTask != NULL) {
- g_saveMemRecord[g_memRecordIndex].taskID = LOS_CurTaskIDGet();
- } else {
- g_saveMemRecord[g_memRecordIndex].taskID = 0;
- }
-}
-
-STATIC INLINE VOID OsMemRecord(const VOID *ptr, UINT32 size)
-{
- UINT64 tickCount = LOS_TickCountGet();
- UINT32 nodeID;
- LinkRegNode linkRegNode;
- AddrNode node;
- ReqSizeNode reqNode;
-
- OsMemRecordLR(&linkRegNode);
- nodeID = OsBinTreeInsert(&linkRegNode, sizeof(linkRegNode), (BinNode **)&g_linkRegRoot, OsGetLRBinNode,
- OsCompareLRNode);
- if (nodeID == OS_INVALID) {
- PRINT_WARN("LIST g_linkRegRoot insert linkRegNode failed!\n");
- }
- g_saveMemRecord[g_memRecordIndex].linkRegID = nodeID;
-
- node.addr = (UINTPTR)ptr;
- nodeID = OsBinTreeInsert(&node, sizeof(AddrNode), (BinNode **)&g_addrRoot, OsGetAddrBinNode,
- OsCompareAddrNode);
- if (nodeID == OS_INVALID) {
- PRINT_WARN("LIST g_addrRoot insert addrNode failed!\n");
- }
- g_saveMemRecord[g_memRecordIndex].addrID = nodeID;
- g_saveMemRecord[g_memRecordIndex].sysTick = tickCount;
-
- OsMemRecordTaskID();
-
- reqNode.reqSize = size;
- nodeID = OsBinTreeInsert(&reqNode, sizeof(ReqSizeNode), (BinNode **)&g_reqSizeRoot, OsGetReqSizeBinNode,
- OsCompareReqSizeNode);
- if (nodeID == OS_INVALID) {
- PRINT_WARN("LIST g_reqSizeRoot insert reqSizeNode failed!\n");
- }
- g_saveMemRecord[g_memRecordIndex].reqSizeID = nodeID;
-
- g_memRecordIndex++;
- if (g_memRecordIndex == RECORD_LEN) {
- OsMemRecordExchange();
- }
-}
-
-#ifdef LOSCFG_MEM_RECORDINFO
-VOID OsMemRecordMalloc(const VOID *ptr, UINT32 size)
-{
- if (g_memRecordShowEnable == 0) {
- return;
- }
-
- OsMemRecord(ptr, size);
- g_saveMemRecord[g_memRecordIndex].actType = OS_MEM_ALLOC;
-}
-#endif
-
-#ifdef LOSCFG_MEM_RECORDINFO
-VOID OsMemRecordFree(const VOID *ptr, UINT32 size)
-{
- UINT32 actType;
- if (g_memRecordShowEnable == 0) {
- return;
- }
- actType = (size == 0) ? OS_MEM_INVALIDFREE : OS_MEM_VALIDFREE;
- OsMemRecord(ptr, size);
- g_saveMemRecord[g_memRecordIndex].actType = actType;
-}
-#endif
-
-VOID OsMemRecordShowTask(VOID)
-{
- (VOID)LOS_EventInit(&g_memShowEvent);
- while (1) {
- (VOID)LOS_EventRead(&g_memShowEvent, READ_EVENT_MASK,
- LOS_WAITMODE_OR | LOS_WAITMODE_CLR, MEM_RECORDSHOW_TIMEOUT);
- if (g_memRecordShowEnable) {
- OsMemRecordShow();
- }
- }
-}
-
-VOID OsMemRecordShowSet(UINT32 value)
-{
- g_memRecordShowEnable = value;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
diff --git a/kernel/base/mem/membox/los_membox.c b/kernel/base/mem/membox/los_membox.c
index e3025a11..f8c2f0a0 100644
--- a/kernel/base/mem/membox/los_membox.c
+++ b/kernel/base/mem/membox/los_membox.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/mem/tlsf/los_memory.c b/kernel/base/mem/tlsf/los_memory.c
new file mode 100755
index 00000000..10185a4c
--- /dev/null
+++ b/kernel/base/mem/tlsf/los_memory.c
@@ -0,0 +1,1995 @@
+/*
+ * 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_memory.h"
+#include "los_memory_pri.h"
+#include "sys/param.h"
+#include "los_spinlock.h"
+#include "los_vm_phys.h"
+#include "los_vm_boot.h"
+#include "los_vm_filemap.h"
+#include "los_task_pri.h"
+#ifdef LOSCFG_KERNEL_TRACE
+#include "los_trace_frame.h"
+#include "los_trace.h"
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+/* Used to cut non-essential functions. */
+#define OS_MEM_FREE_BY_TASKID 0
+#define OS_MEM_EXPAND_ENABLE 1
+
+/* the dump size of current broken node when memcheck error */
+#define OS_MEM_NODE_DUMP_SIZE 64
+/* column num of the output info of mem node */
+#define OS_MEM_COLUMN_NUM 8
+
+UINT8 *m_aucSysMem0 = NULL;
+UINT8 *m_aucSysMem1 = NULL;
+
+#ifdef LOSCFG_MEM_MUL_POOL
+VOID *g_poolHead = NULL;
+#endif
+
+/* The following is the macro definition and interface implementation related to the TLSF. */
+
+/* Supposing a Second Level Index: SLI = 3. */
+#define OS_MEM_SLI 3
+/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */
+#define OS_MEM_SMALL_BUCKET_COUNT 31
+#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128
+/* Giving OS_MEM_FREE_LIST_NUM free lists for each large bucket. */
+#define OS_MEM_LARGE_BUCKET_COUNT 24
+#define OS_MEM_FREE_LIST_NUM (1 << OS_MEM_SLI)
+/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */
+#define OS_MEM_LARGE_START_BUCKET 7
+
+/* The count of free list. */
+#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI))
+/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */
+#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1)
+
+#define OS_MEM_BITMAP_MASK 0x1FU
+
+/* Used to find the first bit of 1 in bitmap. */
+STATIC INLINE UINT16 OsMemFFS(UINT32 bitmap)
+{
+ bitmap &= ~bitmap + 1;
+ return (OS_MEM_BITMAP_MASK - CLZ(bitmap));
+}
+
+/* Used to find the last bit of 1 in bitmap. */
+STATIC INLINE UINT16 OsMemFLS(UINT32 bitmap)
+{
+ return (OS_MEM_BITMAP_MASK - CLZ(bitmap));
+}
+
+STATIC INLINE UINT32 OsMemLog2(UINT32 size)
+{
+ return OsMemFLS(size);
+}
+
+/* Get the first level: f = log2(size). */
+STATIC INLINE UINT32 OsMemFlGet(UINT32 size)
+{
+ if (size < OS_MEM_SMALL_BUCKET_MAX_SIZE) {
+ return ((size >> 2) - 1); /* 2: The small bucket setup is 4. */
+ }
+ return OsMemLog2(size);
+}
+
+/* Get the second level: s = (size - 2^f) * 2^SLI / 2^f. */
+STATIC INLINE UINT32 OsMemSlGet(UINT32 size, UINT32 fl)
+{
+ return (((size << OS_MEM_SLI) >> fl) - OS_MEM_FREE_LIST_NUM);
+}
+
+/* The following is the memory algorithm related macro definition and interface implementation. */
+
+struct OsMemNodeHead {
+ UINT32 magic;
+ union {
+ struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */
+ struct OsMemNodeHead *next; /* The next is used for last node points to the expand node */
+ } ptr;
+#ifdef LOSCFG_MEM_LEAKCHECK
+ UINTPTR linkReg[LOS_RECORD_LR_CNT];
+#endif
+ UINT32 sizeAndFlag;
+};
+
+struct OsMemUsedNodeHead {
+ struct OsMemNodeHead header;
+#if OS_MEM_FREE_BY_TASKID
+ UINT32 taskID;
+#endif
+};
+
+struct OsMemFreeNodeHead {
+ struct OsMemNodeHead header;
+ struct OsMemFreeNodeHead *prev;
+ struct OsMemFreeNodeHead *next;
+};
+
+struct OsMemPoolInfo {
+ VOID *pool;
+ UINT32 totalSize;
+ UINT32 attr;
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ UINT32 waterLine; /* Maximum usage size in a memory pool */
+ UINT32 curUsedSize; /* Current usage size in a memory pool */
+#endif
+};
+
+struct OsMemPoolHead {
+ struct OsMemPoolInfo info;
+ UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS];
+ struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT];
+ SPIN_LOCK_S spinlock;
+#ifdef LOSCFG_MEM_MUL_POOL
+ VOID *nextPool;
+#endif
+};
+
+/* Spinlock for mem module, only available on SMP mode */
+#define MEM_LOCK(pool, state) LOS_SpinLockSave(&(pool)->spinlock, &(state))
+#define MEM_UNLOCK(pool, state) LOS_SpinUnlockRestore(&(pool)->spinlock, (state))
+
+/* The memory pool support expand. */
+#define OS_MEM_POOL_EXPAND_ENABLE 0x01
+/* The memory pool ssupport no lock. */
+#define OS_MEM_POOL_LOCK_ENABLE 0x02
+
+#define OS_MEM_NODE_MAGIC 0xABCDDCBA
+#define OS_MEM_MIN_ALLOC_SIZE (sizeof(struct OsMemFreeNodeHead) - sizeof(struct OsMemUsedNodeHead))
+
+#define OS_MEM_NODE_USED_FLAG 0x80000000U
+#define OS_MEM_NODE_ALIGNED_FLAG 0x40000000U
+#define OS_MEM_NODE_LAST_FLAG 0x20000000U /* Sentinel Node */
+#define OS_MEM_NODE_ALIGNED_AND_USED_FLAG (OS_MEM_NODE_USED_FLAG | OS_MEM_NODE_ALIGNED_FLAG | OS_MEM_NODE_LAST_FLAG)
+
+#define OS_MEM_NODE_GET_ALIGNED_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) & OS_MEM_NODE_ALIGNED_FLAG)
+#define OS_MEM_NODE_SET_ALIGNED_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_ALIGNED_FLAG))
+#define OS_MEM_NODE_GET_ALIGNED_GAPSIZE(sizeAndFlag) \
+ ((sizeAndFlag) & ~OS_MEM_NODE_ALIGNED_FLAG)
+#define OS_MEM_NODE_GET_USED_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) & OS_MEM_NODE_USED_FLAG)
+#define OS_MEM_NODE_SET_USED_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_USED_FLAG))
+#define OS_MEM_NODE_GET_SIZE(sizeAndFlag) \
+ ((sizeAndFlag) & ~OS_MEM_NODE_ALIGNED_AND_USED_FLAG)
+#define OS_MEM_NODE_SET_LAST_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_LAST_FLAG))
+#define OS_MEM_NODE_GET_LAST_FLAG(sizeAndFlag) \
+ ((sizeAndFlag) & OS_MEM_NODE_LAST_FLAG)
+
+#define OS_MEM_ALIGN_SIZE sizeof(UINTPTR)
+#define OS_MEM_IS_POW_TWO(value) ((((UINTPTR)(value)) & ((UINTPTR)(value) - 1)) == 0)
+#define OS_MEM_ALIGN(p, alignSize) (((UINTPTR)(p) + (alignSize) - 1) & ~((UINTPTR)((alignSize) - 1)))
+#define OS_MEM_IS_ALIGNED(a, b) (!(((UINTPTR)(a)) & (((UINTPTR)(b)) - 1)))
+#define OS_MEM_NODE_HEAD_SIZE sizeof(struct OsMemUsedNodeHead)
+#define OS_MEM_MIN_POOL_SIZE (OS_MEM_NODE_HEAD_SIZE + sizeof(struct OsMemPoolHead))
+#define OS_MEM_NEXT_NODE(node) \
+ ((struct OsMemNodeHead *)(VOID *)((UINT8 *)(node) + OS_MEM_NODE_GET_SIZE((node)->sizeAndFlag)))
+#define OS_MEM_FIRST_NODE(pool) \
+ (struct OsMemNodeHead *)((UINT8 *)(pool) + sizeof(struct OsMemPoolHead))
+#define OS_MEM_END_NODE(pool, size) \
+ (struct OsMemNodeHead *)((UINT8 *)(pool) + (size) - OS_MEM_NODE_HEAD_SIZE)
+#define OS_MEM_MIDDLE_ADDR_OPEN_END(startAddr, middleAddr, endAddr) \
+ (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) < (UINT8 *)(endAddr)))
+#define OS_MEM_MIDDLE_ADDR(startAddr, middleAddr, endAddr) \
+ (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) <= (UINT8 *)(endAddr)))
+#define OS_MEM_SET_MAGIC(node) ((node)->magic = OS_MEM_NODE_MAGIC)
+#define OS_MEM_MAGIC_VALID(node) ((node)->magic == OS_MEM_NODE_MAGIC)
+
+STATIC INLINE VOID OsMemFreeNodeAdd(VOID *pool, struct OsMemFreeNodeHead *node);
+STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead *node);
+STATIC VOID OsMemInfoPrint(VOID *pool);
+#ifdef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
+STATIC INLINE UINT32 OsMemAllocCheck(struct OsMemPoolHead *pool, UINT32 intSave);
+#endif
+
+#if OS_MEM_FREE_BY_TASKID
+STATIC INLINE VOID OsMemNodeSetTaskID(struct OsMemUsedNodeHead *node)
+{
+ node->taskID = LOS_CurTaskIDGet();
+}
+#endif
+
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+STATIC INLINE VOID OsMemWaterUsedRecord(struct OsMemPoolHead *pool, UINT32 size)
+{
+ pool->info.curUsedSize += size;
+ if (pool->info.curUsedSize > pool->info.waterLine) {
+ pool->info.waterLine = pool->info.curUsedSize;
+ }
+}
+#else
+STATIC INLINE VOID OsMemWaterUsedRecord(struct OsMemPoolHead *pool, UINT32 size)
+{
+ (VOID)pool;
+ (VOID)size;
+}
+#endif
+
+#if OS_MEM_EXPAND_ENABLE
+STATIC INLINE struct OsMemNodeHead *OsMemLastSentinelNodeGet(const struct OsMemNodeHead *sentinelNode)
+{
+ struct OsMemNodeHead *node = NULL;
+ VOID *ptr = sentinelNode->ptr.next;
+ UINT32 size = OS_MEM_NODE_GET_SIZE(sentinelNode->sizeAndFlag);
+
+ while ((ptr != NULL) && (size != 0)) {
+ node = OS_MEM_END_NODE(ptr, size);
+ ptr = node->ptr.next;
+ size = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+ }
+
+ return node;
+}
+
+STATIC INLINE BOOL OsMemSentinelNodeCheck(struct OsMemNodeHead *sentinelNode)
+{
+ if (!OS_MEM_NODE_GET_USED_FLAG(sentinelNode->sizeAndFlag)) {
+ return FALSE;
+ }
+
+ if (!OS_MEM_MAGIC_VALID(sentinelNode)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+STATIC INLINE BOOL OsMemIsLastSentinelNode(struct OsMemNodeHead *sentinelNode)
+{
+ if (OsMemSentinelNodeCheck(sentinelNode) == FALSE) {
+ PRINT_ERR("%s %d, The current sentinel node is invalid\n", __FUNCTION__, __LINE__);
+ return TRUE;
+ }
+
+ if ((OS_MEM_NODE_GET_SIZE(sentinelNode->sizeAndFlag) == 0) ||
+ (sentinelNode->ptr.next == NULL)) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+STATIC INLINE VOID OsMemSentinelNodeSet(struct OsMemNodeHead *sentinelNode, VOID *newNode, UINT32 size)
+{
+ if (sentinelNode->ptr.next != NULL) {
+ sentinelNode = OsMemLastSentinelNodeGet(sentinelNode);
+ }
+
+ sentinelNode->sizeAndFlag = size;
+ sentinelNode->ptr.next = newNode;
+ OS_MEM_NODE_SET_USED_FLAG(sentinelNode->sizeAndFlag);
+ OS_MEM_NODE_SET_LAST_FLAG(sentinelNode->sizeAndFlag);
+}
+
+STATIC INLINE VOID *OsMemSentinelNodeGet(struct OsMemNodeHead *node)
+{
+ return node->ptr.next;
+}
+
+STATIC INLINE struct OsMemNodeHead *PreSentinelNodeGet(const VOID *pool, const struct OsMemNodeHead *node)
+{
+ UINT32 nextSize;
+ struct OsMemNodeHead *nextNode = NULL;
+ struct OsMemNodeHead *sentinelNode = NULL;
+
+ sentinelNode = OS_MEM_END_NODE(pool, ((struct OsMemPoolHead *)pool)->info.totalSize);
+ while (sentinelNode != NULL) {
+ if (OsMemIsLastSentinelNode(sentinelNode)) {
+ PRINT_ERR("PreSentinelNodeGet can not find node %#x\n", node);
+ return NULL;
+ }
+ nextNode = OsMemSentinelNodeGet(sentinelNode);
+ if (nextNode == node) {
+ return sentinelNode;
+ }
+ nextSize = OS_MEM_NODE_GET_SIZE(sentinelNode->sizeAndFlag);
+ sentinelNode = OS_MEM_END_NODE(nextNode, nextSize);
+ }
+
+ return NULL;
+}
+
+STATIC INLINE BOOL TryShrinkPool(const VOID *pool, const struct OsMemNodeHead *node)
+{
+ struct OsMemNodeHead *mySentinel = NULL;
+ struct OsMemNodeHead *preSentinel = NULL;
+ size_t totalSize = (UINTPTR)node->ptr.prev - (UINTPTR)node;
+ size_t nodeSize = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+
+ if (nodeSize != totalSize) {
+ return FALSE;
+ }
+
+ preSentinel = PreSentinelNodeGet(pool, node);
+ if (preSentinel == NULL) {
+ return FALSE;
+ }
+
+ mySentinel = node->ptr.prev;
+ if (OsMemIsLastSentinelNode(mySentinel)) { /* prev node becomes sentinel node */
+ preSentinel->ptr.next = NULL;
+ OsMemSentinelNodeSet(preSentinel, NULL, 0);
+ } else {
+ preSentinel->sizeAndFlag = mySentinel->sizeAndFlag;
+ preSentinel->ptr.next = mySentinel->ptr.next;
+ }
+
+ if (OsMemLargeNodeFree(node) != LOS_OK) {
+ PRINT_ERR("TryShrinkPool free %#x failed!\n", node);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+STATIC INLINE INT32 OsMemPoolExpandSub(VOID *pool, UINT32 size, UINT32 intSave)
+{
+ UINT32 tryCount = MAX_SHRINK_PAGECACHE_TRY;
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *newNode = NULL;
+ struct OsMemNodeHead *endNode = NULL;
+
+ size = ROUNDUP(size + OS_MEM_NODE_HEAD_SIZE, PAGE_SIZE);
+ endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
+
+RETRY:
+ newNode = (struct OsMemNodeHead *)LOS_PhysPagesAllocContiguous(size >> PAGE_SHIFT);
+ if (newNode == NULL) {
+ if (tryCount > 0) {
+ tryCount--;
+ MEM_UNLOCK(poolInfo, intSave);
+ OsTryShrinkMemory(size >> PAGE_SHIFT);
+ MEM_LOCK(poolInfo, intSave);
+ goto RETRY;
+ }
+
+ PRINT_ERR("OsMemPoolExpand alloc failed size = %u\n", size);
+ return -1;
+ }
+ newNode->sizeAndFlag = (size - OS_MEM_NODE_HEAD_SIZE);
+ newNode->ptr.prev = OS_MEM_END_NODE(newNode, size);
+ OsMemSentinelNodeSet(endNode, newNode, size);
+ OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)newNode);
+
+ endNode = OS_MEM_END_NODE(newNode, size);
+ (VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
+ endNode->ptr.next = NULL;
+ endNode->magic = OS_MEM_NODE_MAGIC;
+ OsMemSentinelNodeSet(endNode, NULL, 0);
+ OsMemWaterUsedRecord(poolInfo, OS_MEM_NODE_HEAD_SIZE);
+
+ return 0;
+}
+
+STATIC INLINE INT32 OsMemPoolExpand(VOID *pool, UINT32 allocSize, UINT32 intSave)
+{
+ UINT32 expandDefault = MEM_EXPAND_SIZE(LOS_MemPoolSizeGet(pool));
+ UINT32 expandSize = MAX(expandDefault, allocSize);
+ UINT32 tryCount = 1;
+ UINT32 ret;
+
+ do {
+ ret = OsMemPoolExpandSub(pool, expandSize, intSave);
+ if (ret == 0) {
+ return 0;
+ }
+
+ if (allocSize > expandDefault) {
+ break;
+ }
+ expandSize = allocSize;
+ } while (tryCount--);
+
+ return -1;
+}
+
+VOID LOS_MemExpandEnable(VOID *pool)
+{
+ if (pool == NULL) {
+ return;
+ }
+
+ ((struct OsMemPoolHead *)pool)->info.attr |= OS_MEM_POOL_EXPAND_ENABLE;
+}
+#endif
+
+#ifdef LOSCFG_MEM_LEAKCHECK
+STATIC INLINE VOID OsMemLinkRegisterRecord(struct OsMemNodeHead *node)
+{
+ LOS_RecordLR(node->linkReg, LOS_RECORD_LR_CNT, LOS_RECORD_LR_CNT, LOS_OMIT_LR_CNT);
+}
+
+STATIC INLINE VOID OsMemUsedNodePrint(struct OsMemNodeHead *node)
+{
+ UINT32 count;
+
+ if (OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
+#ifdef __LP64__
+ PRINTK("0x%018x: ", node);
+#else
+ PRINTK("0x%010x: ", node);
+#endif
+ for (count = 0; count < LOS_RECORD_LR_CNT; count++) {
+#ifdef __LP64__
+ PRINTK(" 0x%018x ", node->linkReg[count]);
+#else
+ PRINTK(" 0x%010x ", node->linkReg[count]);
+#endif
+ }
+ PRINTK("\n");
+ }
+}
+
+VOID OsMemUsedNodeShow(VOID *pool)
+{
+ if (pool == NULL) {
+ PRINTK("input param is NULL\n");
+ return;
+ }
+ if (LOS_MemIntegrityCheck(pool)) {
+ PRINTK("LOS_MemIntegrityCheck error\n");
+ return;
+ }
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemNodeHead *endNode = NULL;
+ UINT32 size;
+ UINT32 intSave;
+ UINT32 count;
+
+#ifdef __LP64__
+ PRINTK("\n\rnode ");
+#else
+ PRINTK("\n\rnode ");
+#endif
+ for (count = 0; count < LOS_RECORD_LR_CNT; count++) {
+#ifdef __LP64__
+ PRINTK(" LR[%u] ", count);
+#else
+ PRINTK(" LR[%u] ", count);
+#endif
+ }
+ PRINTK("\n");
+
+ MEM_LOCK(poolInfo, intSave);
+ endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
+#if OS_MEM_EXPAND_ENABLE
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
+ if (tmpNode == endNode) {
+ if (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
+ tmpNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(tmpNode, size);
+ continue;
+ } else {
+ break;
+ }
+ } else {
+ OsMemUsedNodePrint(tmpNode);
+ }
+ }
+#else
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode;
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
+ OsMemUsedNodePrint(tmpNode);
+ }
+#endif
+ MEM_UNLOCK(poolInfo, intSave);
+}
+
+STATIC VOID OsMemNodeBacktraceInfo(const struct OsMemNodeHead *tmpNode,
+ const struct OsMemNodeHead *preNode)
+{
+ int i;
+ PRINTK("\n broken node head LR info: \n");
+ for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
+ PRINTK(" LR[%d]:%#x\n", i, tmpNode->linkReg[i]);
+ }
+
+ PRINTK("\n pre node head LR info: \n");
+ for (i = 0; i < LOS_RECORD_LR_CNT; i++) {
+ PRINTK(" LR[%d]:%#x\n", i, preNode->linkReg[i]);
+ }
+}
+#endif
+
+STATIC INLINE UINT32 OsMemFreeListIndexGet(UINT32 size)
+{
+ UINT32 fl = OsMemFlGet(size);
+ if (size < OS_MEM_SMALL_BUCKET_MAX_SIZE) {
+ return fl;
+ }
+
+ UINT32 sl = OsMemSlGet(size, fl);
+ return (OS_MEM_SMALL_BUCKET_COUNT + ((fl - OS_MEM_LARGE_START_BUCKET) << OS_MEM_SLI) + sl);
+}
+
+STATIC INLINE struct OsMemFreeNodeHead *OsMemFindCurSuitableBlock(struct OsMemPoolHead *poolHead,
+ UINT32 index, UINT32 size)
+{
+ struct OsMemFreeNodeHead *node = NULL;
+
+ for (node = poolHead->freeList[index]; node != NULL; node = node->next) {
+ if (node->header.sizeAndFlag >= size) {
+ return node;
+ }
+ }
+
+ return NULL;
+}
+
+STATIC INLINE UINT32 OsMemNotEmptyIndexGet(struct OsMemPoolHead *poolHead, UINT32 index)
+{
+ UINT32 mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
+ mask &= ~((1 << (index & OS_MEM_BITMAP_MASK)) - 1);
+ if (mask != 0) {
+ index = OsMemFFS(mask) + (index & ~OS_MEM_BITMAP_MASK);
+ return index;
+ }
+
+ return OS_MEM_FREE_LIST_COUNT;
+}
+
+STATIC INLINE struct OsMemFreeNodeHead *OsMemFindNextSuitableBlock(VOID *pool, UINT32 size, UINT32 *outIndex)
+{
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ UINT32 fl = OsMemFlGet(size);
+ UINT32 sl;
+ UINT32 index, tmp;
+ UINT32 curIndex = OS_MEM_FREE_LIST_COUNT;
+ UINT32 mask;
+
+ do {
+ if (size < OS_MEM_SMALL_BUCKET_MAX_SIZE) {
+ index = fl;
+ } else {
+ sl = OsMemSlGet(size, fl);
+ curIndex = ((fl - OS_MEM_LARGE_START_BUCKET) << OS_MEM_SLI) + sl + OS_MEM_SMALL_BUCKET_COUNT;
+ index = curIndex + 1;
+ }
+
+ tmp = OsMemNotEmptyIndexGet(poolHead, index);
+ if (tmp != OS_MEM_FREE_LIST_COUNT) {
+ index = tmp;
+ goto DONE;
+ }
+
+ for (index = LOS_Align(index + 1, 32); index < OS_MEM_FREE_LIST_COUNT; index += 32) {
+ mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
+ if (mask != 0) {
+ index = OsMemFFS(mask) + index;
+ goto DONE;
+ }
+ }
+ } while (0);
+
+ if (curIndex == OS_MEM_FREE_LIST_COUNT) {
+ return NULL;
+ }
+
+ *outIndex = curIndex;
+ return OsMemFindCurSuitableBlock(poolHead, curIndex, size);
+DONE:
+ *outIndex = index;
+ return poolHead->freeList[index];
+}
+
+STATIC INLINE VOID OsMemSetFreeListBit(struct OsMemPoolHead *head, UINT32 index)
+{
+ head->freeListBitmap[index >> 5] |= 1U << (index & 0x1f); /* 5: Divide by 32 to calculate the index of the bitmap array. */
+}
+
+STATIC INLINE VOID OsMemClearFreeListBit(struct OsMemPoolHead *head, UINT32 index)
+{
+ head->freeListBitmap[index >> 5] &= ~(1U << (index & 0x1f)); /* 5: Divide by 32 to calculate the index of the bitmap array. */
+}
+
+STATIC INLINE VOID OsMemListAdd(struct OsMemPoolHead *pool, UINT32 listIndex, struct OsMemFreeNodeHead *node)
+{
+ struct OsMemFreeNodeHead *firstNode = pool->freeList[listIndex];
+ if (firstNode != NULL) {
+ firstNode->prev = node;
+ }
+ node->prev = NULL;
+ node->next = firstNode;
+ pool->freeList[listIndex] = node;
+ OsMemSetFreeListBit(pool, listIndex);
+ node->header.magic = OS_MEM_NODE_MAGIC;
+}
+
+STATIC INLINE VOID OsMemListDelete(struct OsMemPoolHead *pool, UINT32 listIndex, struct OsMemFreeNodeHead *node)
+{
+ if (node == pool->freeList[listIndex]) {
+ pool->freeList[listIndex] = node->next;
+ if (node->next == NULL) {
+ OsMemClearFreeListBit(pool, listIndex);
+ } else {
+ node->next->prev = NULL;
+ }
+ } else {
+ node->prev->next = node->next;
+ if (node->next != NULL) {
+ node->next->prev = node->prev;
+ }
+ }
+ node->header.magic = OS_MEM_NODE_MAGIC;
+}
+
+STATIC INLINE VOID OsMemFreeNodeAdd(VOID *pool, struct OsMemFreeNodeHead *node)
+{
+ UINT32 index = OsMemFreeListIndexGet(node->header.sizeAndFlag);
+ if (index >= OS_MEM_FREE_LIST_COUNT) {
+ LOS_Panic("The index of free lists is error, index = %u\n", index);
+ return;
+ }
+ OsMemListAdd(pool, index, node);
+}
+
+STATIC INLINE VOID OsMemFreeNodeDelete(VOID *pool, struct OsMemFreeNodeHead *node)
+{
+ UINT32 index = OsMemFreeListIndexGet(node->header.sizeAndFlag);
+ if (index >= OS_MEM_FREE_LIST_COUNT) {
+ LOS_Panic("The index of free lists is error, index = %u\n", index);
+ return;
+ }
+ OsMemListDelete(pool, index, node);
+}
+
+STATIC INLINE struct OsMemNodeHead *OsMemFreeNodeGet(VOID *pool, UINT32 size)
+{
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ UINT32 index;
+ struct OsMemFreeNodeHead *firstNode = OsMemFindNextSuitableBlock(pool, size, &index);
+ if (firstNode == NULL) {
+ return NULL;
+ }
+
+ OsMemListDelete(poolHead, index, firstNode);
+
+ return &firstNode->header;
+}
+
+STATIC INLINE VOID OsMemMergeNode(struct OsMemNodeHead *node)
+{
+ struct OsMemNodeHead *nextNode = NULL;
+
+ node->ptr.prev->sizeAndFlag += node->sizeAndFlag;
+ nextNode = (struct OsMemNodeHead *)((UINTPTR)node + node->sizeAndFlag);
+ if (!OS_MEM_NODE_GET_LAST_FLAG(nextNode->sizeAndFlag)) {
+ nextNode->ptr.prev = node->ptr.prev;
+ }
+}
+
+STATIC INLINE VOID OsMemSplitNode(VOID *pool, struct OsMemNodeHead *allocNode, UINT32 allocSize)
+{
+ struct OsMemFreeNodeHead *newFreeNode = NULL;
+ struct OsMemNodeHead *nextNode = NULL;
+
+ newFreeNode = (struct OsMemFreeNodeHead *)(VOID *)((UINT8 *)allocNode + allocSize);
+ newFreeNode->header.ptr.prev = allocNode;
+ newFreeNode->header.sizeAndFlag = allocNode->sizeAndFlag - allocSize;
+ allocNode->sizeAndFlag = allocSize;
+ nextNode = OS_MEM_NEXT_NODE(&newFreeNode->header);
+ if (!OS_MEM_NODE_GET_LAST_FLAG(nextNode->sizeAndFlag)) {
+ nextNode->ptr.prev = &newFreeNode->header;
+ if (!OS_MEM_NODE_GET_USED_FLAG(nextNode->sizeAndFlag)) {
+ OsMemFreeNodeDelete(pool, (struct OsMemFreeNodeHead *)nextNode);
+ OsMemMergeNode(nextNode);
+ }
+ }
+
+ OsMemFreeNodeAdd(pool, newFreeNode);
+}
+
+STATIC INLINE VOID *OsMemCreateUsedNode(VOID *addr)
+{
+ struct OsMemUsedNodeHead *node = (struct OsMemUsedNodeHead *)addr;
+
+#if OS_MEM_FREE_BY_TASKID
+ OsMemNodeSetTaskID(node);
+#endif
+
+ return node + 1;
+}
+
+STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
+{
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *newNode = NULL;
+ struct OsMemNodeHead *endNode = NULL;
+
+ (VOID)memset_s(poolHead, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
+
+ LOS_SpinInit(&poolHead->spinlock);
+ poolHead->info.pool = pool;
+ poolHead->info.totalSize = size;
+ poolHead->info.attr = OS_MEM_POOL_LOCK_ENABLE; /* default attr: lock, not expand. */
+
+ newNode = OS_MEM_FIRST_NODE(pool);
+ newNode->sizeAndFlag = (size - sizeof(struct OsMemPoolHead) - OS_MEM_NODE_HEAD_SIZE);
+ newNode->ptr.prev = NULL;
+ newNode->magic = OS_MEM_NODE_MAGIC;
+ OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)newNode);
+
+ /* The last mem node */
+ endNode = OS_MEM_END_NODE(pool, size);
+ endNode->magic = OS_MEM_NODE_MAGIC;
+#if OS_MEM_EXPAND_ENABLE
+ endNode->ptr.next = NULL;
+ OsMemSentinelNodeSet(endNode, NULL, 0);
+#else
+ endNode->sizeAndFlag = 0;
+ endNode->ptr.prev = newNode;
+ OS_MEM_NODE_SET_USED_FLAG(endNode->sizeAndFlag);
+#endif
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ poolHead->info.curUsedSize = sizeof(struct OsMemPoolHead) + OS_MEM_NODE_HEAD_SIZE;
+ poolHead->info.waterLine = poolHead->info.curUsedSize;
+#endif
+
+ return LOS_OK;
+}
+
+#ifdef LOSCFG_MEM_MUL_POOL
+STATIC VOID OsMemPoolDeinit(VOID *pool)
+{
+ (VOID)memset_s(pool, sizeof(struct OsMemPoolHead), 0, sizeof(struct OsMemPoolHead));
+}
+
+STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
+{
+ VOID *nextPool = g_poolHead;
+ VOID *curPool = g_poolHead;
+ UINTPTR poolEnd;
+ while (nextPool != NULL) {
+ poolEnd = (UINTPTR)nextPool + LOS_MemPoolSizeGet(nextPool);
+ if (((pool <= nextPool) && (((UINTPTR)pool + size) > (UINTPTR)nextPool)) ||
+ (((UINTPTR)pool < poolEnd) && (((UINTPTR)pool + size) >= poolEnd))) {
+ PRINT_ERR("pool [%#x, %#x) conflict with pool [%#x, %#x)\n",
+ pool, (UINTPTR)pool + size,
+ nextPool, (UINTPTR)nextPool + LOS_MemPoolSizeGet(nextPool));
+ return LOS_NOK;
+ }
+ curPool = nextPool;
+ nextPool = ((struct OsMemPoolHead *)nextPool)->nextPool;
+ }
+
+ if (g_poolHead == NULL) {
+ g_poolHead = pool;
+ } else {
+ ((struct OsMemPoolHead *)curPool)->nextPool = pool;
+ }
+
+ ((struct OsMemPoolHead *)pool)->nextPool = NULL;
+ return LOS_OK;
+}
+
+STATIC UINT32 OsMemPoolDelete(VOID *pool)
+{
+ UINT32 ret = LOS_NOK;
+ VOID *nextPool = NULL;
+ VOID *curPool = NULL;
+
+ do {
+ if (pool == g_poolHead) {
+ g_poolHead = ((struct OsMemPoolHead *)g_poolHead)->nextPool;
+ ret = LOS_OK;
+ break;
+ }
+
+ curPool = g_poolHead;
+ nextPool = g_poolHead;
+ while (nextPool != NULL) {
+ if (pool == nextPool) {
+ ((struct OsMemPoolHead *)curPool)->nextPool = ((struct OsMemPoolHead *)nextPool)->nextPool;
+ ret = LOS_OK;
+ break;
+ }
+ curPool = nextPool;
+ nextPool = ((struct OsMemPoolHead *)nextPool)->nextPool;
+ }
+ } while (0);
+
+ return ret;
+}
+#endif
+
+UINT32 LOS_MemInit(VOID *pool, UINT32 size)
+{
+ if ((pool == NULL) || (size <= OS_MEM_MIN_POOL_SIZE)) {
+ return OS_ERROR;
+ }
+
+ size = OS_MEM_ALIGN(size, OS_MEM_ALIGN_SIZE);
+ if (OsMemPoolInit(pool, size)) {
+ return OS_ERROR;
+ }
+
+#ifdef LOSCFG_MEM_MUL_POOL
+ if (OsMemPoolAdd(pool, size)) {
+ (VOID)OsMemPoolDeinit(pool);
+ return OS_ERROR;
+ }
+#endif
+
+#ifdef LOSCFG_KERNEL_TRACE
+ LOS_TraceReg(LOS_TRACE_MEM_TIME, OsMemTimeTrace, LOS_TRACE_MEM_TIME_NAME, LOS_TRACE_ENABLE);
+ LOS_TraceReg(LOS_TRACE_MEM_INFO, OsMemInfoTrace, LOS_TRACE_MEM_INFO_NAME, LOS_TRACE_ENABLE);
+#endif
+
+ return LOS_OK;
+}
+
+#ifdef LOSCFG_MEM_MUL_POOL
+UINT32 LOS_MemDeInit(VOID *pool)
+{
+ if (pool == NULL) {
+ return OS_ERROR;
+ }
+
+ if (OsMemPoolDelete(pool)) {
+ return OS_ERROR;
+ }
+
+ OsMemPoolDeinit(pool);
+
+#ifdef LOSCFG_KERNEL_TRACE
+ LOS_TraceUnreg(LOS_TRACE_MEM_TIME);
+ LOS_TraceUnreg(LOS_TRACE_MEM_INFO);
+#endif
+
+ return LOS_OK;
+}
+
+UINT32 LOS_MemPoolList(VOID)
+{
+ VOID *nextPool = g_poolHead;
+ UINT32 index = 0;
+ while (nextPool != NULL) {
+ PRINTK("pool%u :\n", index);
+ index++;
+ OsMemInfoPrint(nextPool);
+ nextPool = ((struct OsMemPoolHead *)nextPool)->nextPool;
+ }
+ return index;
+}
+#endif
+
+STATIC INLINE VOID *OsMemAlloc(struct OsMemPoolHead *pool, UINT32 size, UINT32 intSave)
+{
+ struct OsMemNodeHead *allocNode = NULL;
+
+#ifdef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
+ if (OsMemAllocCheck(pool, intSave) == LOS_NOK) {
+ return NULL;
+ }
+#endif
+
+ UINT32 allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
+ if (allocSize == 0) {
+ return NULL;
+ }
+
+#if OS_MEM_EXPAND_ENABLE
+retry:
+#endif
+ allocNode = OsMemFreeNodeGet(pool, allocSize);
+ if (allocNode == NULL) {
+#if OS_MEM_EXPAND_ENABLE
+ if (pool->info.attr & OS_MEM_POOL_EXPAND_ENABLE) {
+ INT32 ret = OsMemPoolExpand(pool, allocSize, intSave);
+ if (ret == 0) {
+ goto retry;
+ }
+ }
+#endif
+ MEM_UNLOCK(pool, intSave);
+ PRINT_ERR("---------------------------------------------------"
+ "--------------------------------------------------------\n");
+ OsMemInfoPrint(pool);
+ PRINT_ERR("[%s] No suitable free block, require free node size: 0x%x\n", __FUNCTION__, allocSize);
+ PRINT_ERR("----------------------------------------------------"
+ "-------------------------------------------------------\n");
+ MEM_LOCK(pool, intSave);
+ return NULL;
+ }
+
+ if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_MIN_ALLOC_SIZE) <= allocNode->sizeAndFlag) {
+ OsMemSplitNode(pool, allocNode, allocSize);
+ }
+
+ OS_MEM_NODE_SET_USED_FLAG(allocNode->sizeAndFlag);
+ OsMemWaterUsedRecord(pool, OS_MEM_NODE_GET_SIZE(allocNode->sizeAndFlag));
+
+#ifdef LOSCFG_MEM_LEAKCHECK
+ OsMemLinkRegisterRecord(allocNode);
+#endif
+ return OsMemCreateUsedNode((VOID *)allocNode);
+}
+
+VOID *LOS_MemAlloc(VOID *pool, UINT32 size)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 start = HalClockGetCycles();
+#endif
+
+ if ((pool == NULL) || (size == 0)) {
+ return (size > 0) ? OsVmBootMemAlloc(size) : NULL;
+ }
+
+ if (size < OS_MEM_MIN_ALLOC_SIZE) {
+ size = OS_MEM_MIN_ALLOC_SIZE;
+ }
+
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ VOID *ptr = NULL;
+ UINT32 intSave;
+
+ do {
+ if (OS_MEM_NODE_GET_USED_FLAG(size) || OS_MEM_NODE_GET_ALIGNED_FLAG(size)) {
+ break;
+ }
+ MEM_LOCK(poolHead, intSave);
+ ptr = OsMemAlloc(poolHead, size, intSave);
+ MEM_UNLOCK(poolHead, intSave);
+ } while (0);
+
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 end = HalClockGetCycles();
+ UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
+ LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_MALLOC, timeUsed);
+
+ LOS_MEM_POOL_STATUS poolStatus = {0};
+ (VOID)LOS_MemInfoGet(pool, &poolStatus);
+ UINT8 fragment = 100 - poolStatus.maxFreeNodeSize * 100 / poolStatus.totalFreeSize; /* 100: percent denominator. */
+ UINT8 usage = LOS_MemTotalUsedGet(pool) * 100 / LOS_MemPoolSizeGet(pool); /* 100: percent denominator. */
+ LOS_Trace(LOS_TRACE_MEM_INFO, (UINTPTR)pool & MEM_POOL_ADDR_MASK, fragment, usage, poolStatus.totalFreeSize,
+ poolStatus.maxFreeNodeSize, poolStatus.usedNodeNum, poolStatus.freeNodeNum);
+#endif
+
+ return ptr;
+}
+
+VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 start = HalClockGetCycles();
+#endif
+
+ UINT32 gapSize;
+
+ if ((pool == NULL) || (size == 0) || (boundary == 0) || !OS_MEM_IS_POW_TWO(boundary) ||
+ !OS_MEM_IS_ALIGNED(boundary, sizeof(VOID *))) {
+ return NULL;
+ }
+
+ if (size < OS_MEM_MIN_ALLOC_SIZE) {
+ size = OS_MEM_MIN_ALLOC_SIZE;
+ }
+
+ /*
+ * sizeof(gapSize) bytes stores offset between alignedPtr and ptr,
+ * the ptr has been OS_MEM_ALIGN_SIZE(4 or 8) aligned, so maximum
+ * offset between alignedPtr and ptr is boundary - OS_MEM_ALIGN_SIZE
+ */
+ if ((boundary - sizeof(gapSize)) > ((UINT32)(-1) - size)) {
+ return NULL;
+ }
+
+ UINT32 useSize = (size + boundary) - sizeof(gapSize);
+ if (OS_MEM_NODE_GET_USED_FLAG(useSize) || OS_MEM_NODE_GET_ALIGNED_FLAG(useSize)) {
+ return NULL;
+ }
+
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ UINT32 intSave;
+ VOID *ptr = NULL;
+ VOID *alignedPtr = NULL;
+
+ do {
+ MEM_LOCK(poolHead, intSave);
+ ptr = OsMemAlloc(pool, useSize, intSave);
+ MEM_UNLOCK(poolHead, intSave);
+ alignedPtr = (VOID *)OS_MEM_ALIGN(ptr, boundary);
+ if (ptr == alignedPtr) {
+ break;
+ }
+
+ /* store gapSize in address (ptr - 4), it will be checked while free */
+ gapSize = (UINT32)((UINTPTR)alignedPtr - (UINTPTR)ptr);
+ struct OsMemUsedNodeHead *allocNode = (struct OsMemUsedNodeHead *)ptr - 1;
+ OS_MEM_NODE_SET_ALIGNED_FLAG(allocNode->header.sizeAndFlag);
+ OS_MEM_NODE_SET_ALIGNED_FLAG(gapSize);
+ *(UINT32 *)((UINTPTR)alignedPtr - sizeof(gapSize)) = gapSize;
+ ptr = alignedPtr;
+ } while (0);
+
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 end = HalClockGetCycles();
+ UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
+ LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_MEMALIGN, timeUsed);
+#endif
+
+ return ptr;
+}
+
+STATIC INLINE BOOL OsMemAddrValidCheck(const struct OsMemPoolHead *pool, const VOID *addr)
+{
+ UINT32 size;
+
+ /* First node prev is NULL */
+ if (addr == NULL) {
+ return TRUE;
+ }
+
+ size = pool->info.totalSize;
+ if (OS_MEM_MIDDLE_ADDR_OPEN_END(pool + 1, addr, (UINTPTR)pool + size)) {
+ return TRUE;
+ }
+#if OS_MEM_EXPAND_ENABLE
+ struct OsMemNodeHead *node = NULL;
+ struct OsMemNodeHead *sentinel = OS_MEM_END_NODE(pool, size);
+ while (OsMemIsLastSentinelNode(sentinel) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(sentinel->sizeAndFlag);
+ node = OsMemSentinelNodeGet(sentinel);
+ sentinel = OS_MEM_END_NODE(node, size);
+ if (OS_MEM_MIDDLE_ADDR_OPEN_END(node, addr, (UINTPTR)node + size)) {
+ return TRUE;
+ }
+ }
+#endif
+ return FALSE;
+}
+
+STATIC INLINE BOOL OsMemIsNodeValid(const struct OsMemNodeHead *node, const struct OsMemNodeHead *startNode,
+ const struct OsMemNodeHead *endNode,
+ const struct OsMemPoolHead *poolInfo)
+{
+ if (!OS_MEM_MIDDLE_ADDR(startNode, node, endNode)) {
+ return FALSE;
+ }
+
+ if (OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
+ if (!OS_MEM_MAGIC_VALID(node)) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ if (!OsMemAddrValidCheck(poolInfo, node->ptr.prev)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+STATIC UINT32 OsMemCheckUsedNode(const struct OsMemPoolHead *pool, const struct OsMemNodeHead *node)
+{
+ struct OsMemNodeHead *startNode = (struct OsMemNodeHead *)OS_MEM_FIRST_NODE(pool);
+ struct OsMemNodeHead *endNode = (struct OsMemNodeHead *)OS_MEM_END_NODE(pool, pool->info.totalSize);
+ struct OsMemNodeHead *nextNode = NULL;
+ BOOL doneFlag = FALSE;
+
+ do {
+ do {
+ if (!OsMemIsNodeValid(node, startNode, endNode, pool)) {
+ break;
+ }
+
+ if (!OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
+ break;
+ }
+
+ nextNode = OS_MEM_NEXT_NODE(node);
+ if (!OsMemIsNodeValid(nextNode, startNode, endNode, pool)) {
+ break;
+ }
+
+ if (!OS_MEM_NODE_GET_LAST_FLAG(nextNode->sizeAndFlag)) {
+ if (nextNode->ptr.prev != node) {
+ break;
+ }
+ }
+
+ if ((node != startNode) &&
+ ((!OsMemIsNodeValid(node->ptr.prev, startNode, endNode, pool)) ||
+ (OS_MEM_NEXT_NODE(node->ptr.prev) != node))) {
+ break;
+ }
+ doneFlag = TRUE;
+ } while (0);
+
+ if (!doneFlag) {
+#if OS_MEM_EXPAND_ENABLE
+ if (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ startNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(startNode, OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag));
+ continue;
+ }
+#endif
+ return LOS_NOK;
+ }
+ } while (!doneFlag);
+
+ return LOS_OK;
+}
+
+STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead *node)
+{
+ UINT32 ret = OsMemCheckUsedNode(pool, node);
+ if (ret != LOS_OK) {
+ PRINT_ERR("OsMemFree check error!\n");
+ return ret;
+ }
+
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ pool->info.curUsedSize -= OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+#endif
+
+ node->sizeAndFlag = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+#ifdef LOSCFG_MEM_LEAKCHECK
+ OsMemLinkRegisterRecord(node);
+#endif
+ struct OsMemNodeHead *preNode = node->ptr.prev; /* merage preNode */
+ if ((preNode != NULL) && !OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
+ OsMemFreeNodeDelete(pool, (struct OsMemFreeNodeHead *)preNode);
+ OsMemMergeNode(node);
+ node = preNode;
+ }
+
+ struct OsMemNodeHead *nextNode = OS_MEM_NEXT_NODE(node); /* merage nextNode */
+ if ((nextNode != NULL) && !OS_MEM_NODE_GET_USED_FLAG(nextNode->sizeAndFlag)) {
+ OsMemFreeNodeDelete(pool, (struct OsMemFreeNodeHead *)nextNode);
+ OsMemMergeNode(nextNode);
+ }
+
+#if OS_MEM_EXPAND_ENABLE
+ if (pool->info.attr & OS_MEM_POOL_EXPAND_ENABLE) {
+ /* if this is a expand head node, and all unused, free it to pmm */
+ if ((node->ptr.prev != NULL) && (node->ptr.prev > node)) {
+ if (TryShrinkPool(pool, node)) {
+ return LOS_OK;
+ }
+ }
+ }
+#endif
+ OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)node);
+
+ return ret;
+}
+
+UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 start = HalClockGetCycles();
+#endif
+
+ if ((pool == NULL) || (ptr == NULL) || !OS_MEM_IS_ALIGNED(pool, sizeof(VOID *)) ||
+ !OS_MEM_IS_ALIGNED(ptr, sizeof(VOID *))) {
+ return LOS_NOK;
+ }
+
+ UINT32 ret = LOS_NOK;
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *node = NULL;
+ UINT32 intSave;
+
+ do {
+ UINT32 gapSize = *(UINT32 *)((UINTPTR)ptr - sizeof(UINT32));
+ if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize) && OS_MEM_NODE_GET_USED_FLAG(gapSize)) {
+ PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
+ break;
+ }
+
+ node = (struct OsMemNodeHead *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
+
+ if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize)) {
+ gapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(gapSize);
+ if ((gapSize & (OS_MEM_ALIGN_SIZE - 1)) || (gapSize > ((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE))) {
+ PRINT_ERR("illegal gapSize: 0x%x\n", gapSize);
+ break;
+ }
+ node = (struct OsMemNodeHead *)((UINTPTR)ptr - gapSize - OS_MEM_NODE_HEAD_SIZE);
+ }
+ MEM_LOCK(poolHead, intSave);
+ ret = OsMemFree(poolHead, node);
+ MEM_UNLOCK(poolHead, intSave);
+ } while (0);
+
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 end = HalClockGetCycles();
+ UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
+ LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_FREE, timeUsed);
+#endif
+
+ return ret;
+}
+
+STATIC INLINE VOID OsMemReAllocSmaller(VOID *pool, UINT32 allocSize, struct OsMemNodeHead *node, UINT32 nodeSize)
+{
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+#endif
+ node->sizeAndFlag = nodeSize;
+ if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_MIN_ALLOC_SIZE) <= nodeSize) {
+ OsMemSplitNode(pool, node, allocSize);
+ OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ poolInfo->info.curUsedSize -= nodeSize - allocSize;
+#endif
+ }
+ OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
+#ifdef LOSCFG_MEM_LEAKCHECK
+ OsMemLinkRegisterRecord(node);
+#endif
+}
+
+STATIC INLINE VOID OsMemMergeNodeForReAllocBigger(VOID *pool, UINT32 allocSize, struct OsMemNodeHead *node,
+ UINT32 nodeSize, struct OsMemNodeHead *nextNode)
+{
+ node->sizeAndFlag = nodeSize;
+ OsMemFreeNodeDelete(pool, (struct OsMemFreeNodeHead *)nextNode);
+ OsMemMergeNode(nextNode);
+ if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_MIN_ALLOC_SIZE) <= node->sizeAndFlag) {
+ OsMemSplitNode(pool, node, allocSize);
+ }
+ OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
+ OsMemWaterUsedRecord((struct OsMemPoolHead *)pool, node->sizeAndFlag - nodeSize);
+#ifdef LOSCFG_MEM_LEAKCHECK
+ OsMemLinkRegisterRecord(node);
+#endif
+}
+
+STATIC INLINE VOID *OsGetRealPtr(const VOID *pool, VOID *ptr)
+{
+ VOID *realPtr = ptr;
+ UINT32 gapSize = *((UINT32 *)((UINTPTR)ptr - sizeof(UINT32)));
+
+ if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize) && OS_MEM_NODE_GET_USED_FLAG(gapSize)) {
+ PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
+ return NULL;
+ }
+ if (OS_MEM_NODE_GET_ALIGNED_FLAG(gapSize)) {
+ gapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(gapSize);
+ if ((gapSize & (OS_MEM_ALIGN_SIZE - 1)) ||
+ (gapSize > ((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE - (UINTPTR)pool))) {
+ PRINT_ERR("[%s:%d]gapSize:0x%x error\n", __FUNCTION__, __LINE__, gapSize);
+ return NULL;
+ }
+ realPtr = (VOID *)((UINTPTR)ptr - (UINTPTR)gapSize);
+ }
+ return realPtr;
+}
+
+STATIC INLINE VOID *OsMemRealloc(struct OsMemPoolHead *pool, const VOID *ptr,
+ struct OsMemNodeHead *node, UINT32 size, UINT32 intSave)
+{
+ struct OsMemNodeHead *nextNode = NULL;
+ UINT32 allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
+ UINT32 nodeSize = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+ VOID *tmpPtr = NULL;
+
+ if (nodeSize >= allocSize) {
+ OsMemReAllocSmaller(pool, allocSize, node, nodeSize);
+ return (VOID *)ptr;
+ }
+
+ nextNode = OS_MEM_NEXT_NODE(node);
+ if (!OS_MEM_NODE_GET_USED_FLAG(nextNode->sizeAndFlag) &&
+ ((nextNode->sizeAndFlag + nodeSize) >= allocSize)) {
+ OsMemMergeNodeForReAllocBigger(pool, allocSize, node, nodeSize, nextNode);
+ return (VOID *)ptr;
+ }
+
+ tmpPtr = OsMemAlloc(pool, size, intSave);
+ if (tmpPtr != NULL) {
+ if (memcpy_s(tmpPtr, size, ptr, (nodeSize - OS_MEM_NODE_HEAD_SIZE)) != EOK) {
+ MEM_UNLOCK(pool, intSave);
+ (VOID)LOS_MemFree((VOID *)pool, (VOID *)tmpPtr);
+ MEM_LOCK(pool, intSave);
+ return NULL;
+ }
+ (VOID)OsMemFree(pool, node);
+ }
+ return tmpPtr;
+}
+
+VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 start = HalClockGetCycles();
+#endif
+
+ if ((pool == NULL) || OS_MEM_NODE_GET_USED_FLAG(size) || OS_MEM_NODE_GET_ALIGNED_FLAG(size)) {
+ return NULL;
+ }
+
+ if (size < OS_MEM_MIN_ALLOC_SIZE) {
+ size = OS_MEM_MIN_ALLOC_SIZE;
+ }
+
+ if (ptr == NULL) {
+ return LOS_MemAlloc(pool, size);
+ }
+
+ if (size == 0) {
+ (VOID)LOS_MemFree(pool, ptr);
+ return NULL;
+ }
+
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *node = NULL;
+ VOID *newPtr = NULL;
+ UINT32 intSave;
+
+ MEM_LOCK(poolHead, intSave);
+ do {
+ ptr = OsGetRealPtr(pool, ptr);
+ if (ptr == NULL) {
+ break;
+ }
+
+ node = (struct OsMemNodeHead *)((UINTPTR)ptr - OS_MEM_NODE_HEAD_SIZE);
+ if (OsMemCheckUsedNode(pool, node) != LOS_OK) {
+ break;
+ }
+
+ newPtr = OsMemRealloc(pool, ptr, node, size, intSave);
+ } while (0);
+ MEM_UNLOCK(poolHead, intSave);
+
+#ifdef LOSCFG_KERNEL_TRACE
+ UINT64 end = HalClockGetCycles();
+ UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
+ LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_REALLOC, timeUsed);
+#endif
+
+ return newPtr;
+}
+
+#if OS_MEM_FREE_BY_TASKID
+UINT32 LOS_MemFreeByTaskID(VOID *pool, UINT32 taskID)
+{
+ if (pool == NULL) {
+ return OS_ERROR;
+ }
+
+ if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
+ return OS_ERROR;
+ }
+
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemUsedNodeHead *node = NULL;
+ struct OsMemNodeHead *endNode = NULL;
+ UINT32 size;
+ UINT32 intSave;
+
+ MEM_LOCK(poolHead, intSave);
+ endNode = OS_MEM_END_NODE(pool, poolHead->info.totalSize);
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;) {
+ if (tmpNode == endNode) {
+ if (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
+ tmpNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(tmpNode, size);
+ continue;
+ } else {
+ break;
+ }
+ } else {
+ if (!OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode);
+ continue;
+ }
+
+ node = (struct OsMemUsedNodeHead *)tmpNode;
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode);
+
+ if (node->taskID == taskID) {
+ OsMemFree(poolHead, &node->header);
+ }
+ }
+ }
+ MEM_UNLOCK(poolHead, intSave);
+
+ return LOS_OK;
+}
+#endif
+
+UINT32 LOS_MemPoolSizeGet(const VOID *pool)
+{
+ UINT32 count = 0;
+
+ if (pool == NULL) {
+ return LOS_NOK;
+ }
+
+ count += ((struct OsMemPoolHead *)pool)->info.totalSize;
+
+#if OS_MEM_EXPAND_ENABLE
+ UINT32 size;
+ struct OsMemNodeHead *node = NULL;
+ struct OsMemNodeHead *sentinel = OS_MEM_END_NODE(pool, count);
+
+ while (OsMemIsLastSentinelNode(sentinel) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(sentinel->sizeAndFlag);
+ node = OsMemSentinelNodeGet(sentinel);
+ sentinel = OS_MEM_END_NODE(node, size);
+ count += size;
+ }
+#endif
+ return count;
+}
+
+UINT32 LOS_MemTotalUsedGet(VOID *pool)
+{
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *endNode = NULL;
+ UINT32 memUsed = 0;
+ UINT32 intSave;
+
+ if (pool == NULL) {
+ return LOS_NOK;
+ }
+
+ MEM_LOCK(poolInfo, intSave);
+ endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
+#if OS_MEM_EXPAND_ENABLE
+ UINT32 size;
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;) {
+ if (tmpNode == endNode) {
+ memUsed += OS_MEM_NODE_HEAD_SIZE;
+ if (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
+ tmpNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(tmpNode, size);
+ continue;
+ } else {
+ break;
+ }
+ } else {
+ if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
+ memUsed += OS_MEM_NODE_GET_SIZE(tmpNode->sizeAndFlag);
+ }
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode);
+ }
+ }
+#else
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode;) {
+ if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
+ memUsed += OS_MEM_NODE_GET_SIZE(tmpNode->sizeAndFlag);
+ }
+ tmpNode = OS_MEM_NEXT_NODE(tmpNode);
+ }
+#endif
+ MEM_UNLOCK(poolInfo, intSave);
+
+ return memUsed;
+}
+
+STATIC INLINE VOID OsMemMagicCheckPrint(struct OsMemNodeHead **tmpNode)
+{
+ PRINT_ERR("[%s], %d, memory check error!\n"
+ "memory used but magic num wrong, magic num = %#x\n",
+ __FUNCTION__, __LINE__, (*tmpNode)->magic);
+}
+
+STATIC UINT32 OsMemAddrValidCheckPrint(const VOID *pool, struct OsMemFreeNodeHead **tmpNode)
+{
+ if (!OsMemAddrValidCheck(pool, (*tmpNode)->prev)) {
+ PRINT_ERR("[%s], %d, memory check error!\n"
+ " freeNode.prev:%#x is out of legal mem range\n",
+ __FUNCTION__, __LINE__, (*tmpNode)->prev);
+ return LOS_NOK;
+ }
+ if (!OsMemAddrValidCheck(pool, (*tmpNode)->next)) {
+ PRINT_ERR("[%s], %d, memory check error!\n"
+ " freeNode.next:%#x is out of legal mem range\n",
+ __FUNCTION__, __LINE__, (*tmpNode)->next);
+ return LOS_NOK;
+ }
+ return LOS_OK;
+}
+
+STATIC UINT32 OsMemIntegrityCheckSub(struct OsMemNodeHead **tmpNode, const VOID *pool,
+ const struct OsMemNodeHead *endNode)
+{
+ if (!OS_MEM_MAGIC_VALID(*tmpNode)) {
+ OsMemMagicCheckPrint(tmpNode);
+ return LOS_NOK;
+ }
+
+ if (!OS_MEM_NODE_GET_USED_FLAG((*tmpNode)->sizeAndFlag)) { /* is free node, check free node range */
+ if (OsMemAddrValidCheckPrint(pool, (struct OsMemFreeNodeHead **)tmpNode)) {
+ return LOS_NOK;
+ }
+ }
+ return LOS_OK;
+}
+
+STATIC UINT32 OsMemFreeListNodeCheck(const struct OsMemPoolHead *pool,
+ const struct OsMemFreeNodeHead *node)
+{
+ if (!OsMemAddrValidCheck(pool, node) ||
+ !OsMemAddrValidCheck(pool, node->prev) ||
+ !OsMemAddrValidCheck(pool, node->next) ||
+ !OsMemAddrValidCheck(pool, node->header.ptr.prev)) {
+ return LOS_NOK;
+ }
+
+ if (!OS_MEM_IS_ALIGNED(node, sizeof(VOID *)) ||
+ !OS_MEM_IS_ALIGNED(node->prev, sizeof(VOID *)) ||
+ !OS_MEM_IS_ALIGNED(node->next, sizeof(VOID *)) ||
+ !OS_MEM_IS_ALIGNED(node->header.ptr.prev, sizeof(VOID *))) {
+ return LOS_NOK;
+ }
+
+ return LOS_OK;
+}
+
+STATIC VOID OsMemPoolHeadCheck(const struct OsMemPoolHead *pool)
+{
+ struct OsMemFreeNodeHead *tmpNode = NULL;
+ UINT32 index;
+ UINT32 flag = 0;
+
+ if ((pool->info.pool != pool) || !OS_MEM_IS_ALIGNED(pool, sizeof(VOID *))) {
+ PRINT_ERR("wrong mem pool addr: %#x, func:%s, line:%d\n", pool, __FUNCTION__, __LINE__);
+ return;
+ }
+
+ for (index = 0; index < OS_MEM_FREE_LIST_COUNT; index++) {
+ for (tmpNode = pool->freeList[index]; tmpNode != NULL; tmpNode = tmpNode->next) {
+ if (OsMemFreeListNodeCheck(pool, tmpNode)) {
+ flag = 1;
+ PRINT_ERR("FreeListIndex: %u, node: %#x, bNode: %#x, prev: %#x, next: %#x\n",
+ index, tmpNode, tmpNode->header.ptr.prev, tmpNode->prev, tmpNode->next);
+ }
+ }
+ }
+
+ if (flag) {
+ PRINTK("mem pool info: poolAddr: %#x, poolSize: 0x%x\n", pool, pool->info.totalSize);
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ PRINTK("mem pool info: poolWaterLine: 0x%x, poolCurUsedSize: 0x%x\n", pool->info.waterLine,
+ pool->info.curUsedSize);
+#endif
+#if OS_MEM_EXPAND_ENABLE
+ UINT32 size;
+ struct OsMemNodeHead *node = NULL;
+ struct OsMemNodeHead *sentinel = OS_MEM_END_NODE(pool, pool->info.totalSize);
+ while (OsMemIsLastSentinelNode(sentinel) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(sentinel->sizeAndFlag);
+ node = OsMemSentinelNodeGet(sentinel);
+ sentinel = OS_MEM_END_NODE(node, size);
+ PRINTK("expand node info: nodeAddr: %#x, nodeSize: 0x%x\n", node, size);
+ }
+#endif
+ }
+}
+
+STATIC UINT32 OsMemIntegrityCheck(const struct OsMemPoolHead *pool, struct OsMemNodeHead **tmpNode,
+ struct OsMemNodeHead **preNode)
+{
+ struct OsMemNodeHead *endNode = OS_MEM_END_NODE(pool, pool->info.totalSize);
+
+ OsMemPoolHeadCheck(pool);
+
+ *preNode = OS_MEM_FIRST_NODE(pool);
+ do {
+ for (*tmpNode = *preNode; *tmpNode < endNode; *tmpNode = OS_MEM_NEXT_NODE(*tmpNode)) {
+ if (OsMemIntegrityCheckSub(tmpNode, pool, endNode) == LOS_NOK) {
+ return LOS_NOK;
+ }
+ *preNode = *tmpNode;
+ }
+#if OS_MEM_EXPAND_ENABLE
+ if (OsMemIsLastSentinelNode(*tmpNode) == FALSE) {
+ *preNode = OsMemSentinelNodeGet(*tmpNode);
+ endNode = OS_MEM_END_NODE(*preNode, OS_MEM_NODE_GET_SIZE((*tmpNode)->sizeAndFlag));
+ } else
+#endif
+ {
+ break;
+ }
+ } while (1);
+ return LOS_OK;
+}
+
+STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode,
+ const struct OsMemNodeHead *preNode)
+{
+ struct OsMemUsedNodeHead *usedNode = NULL;
+ struct OsMemFreeNodeHead *freeNode = NULL;
+
+ if (tmpNode == preNode) {
+ PRINTK("\n the broken node is the first node\n");
+ }
+
+ if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
+ usedNode = (struct OsMemUsedNodeHead *)tmpNode;
+ PRINTK("\n broken node head: %#x %#x %#x, ",
+ usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
+ } else {
+ freeNode = (struct OsMemFreeNodeHead *)tmpNode;
+ PRINTK("\n broken node head: %#x %#x %#x %#x, ",
+ freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
+ freeNode->header.sizeAndFlag);
+ }
+
+ if (OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
+ usedNode = (struct OsMemUsedNodeHead *)preNode;
+ PRINTK("prev node head: %#x %#x %#x\n",
+ usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
+ } else {
+ freeNode = (struct OsMemFreeNodeHead *)preNode;
+ PRINTK("prev node head: %#x %#x %#x %#x, ",
+ freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
+ freeNode->header.sizeAndFlag);
+ }
+
+#ifdef LOSCFG_MEM_LEAKCHECK
+ OsMemNodeBacktraceInfo(tmpNode, preNode);
+#endif
+
+ PRINTK("\n---------------------------------------------\n");
+ PRINTK(" dump mem tmpNode:%#x ~ %#x\n", tmpNode, ((UINTPTR)tmpNode + OS_MEM_NODE_DUMP_SIZE));
+ OsDumpMemByte(OS_MEM_NODE_DUMP_SIZE, (UINTPTR)tmpNode);
+ PRINTK("\n---------------------------------------------\n");
+ if (preNode != tmpNode) {
+ PRINTK(" dump mem :%#x ~ tmpNode:%#x\n", ((UINTPTR)tmpNode - OS_MEM_NODE_DUMP_SIZE), tmpNode);
+ OsDumpMemByte(OS_MEM_NODE_DUMP_SIZE, ((UINTPTR)tmpNode - OS_MEM_NODE_DUMP_SIZE));
+ PRINTK("\n---------------------------------------------\n");
+ }
+}
+
+STATIC VOID OsMemIntegrityCheckError(struct OsMemPoolHead *pool,
+ const struct OsMemNodeHead *tmpNode,
+ const struct OsMemNodeHead *preNode,
+ UINT32 intSave)
+{
+ OsMemNodeInfo(tmpNode, preNode);
+
+#if OS_MEM_FREE_BY_TASKID
+ LosTaskCB *taskCB = NULL;
+ if (OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
+ struct OsMemUsedNodeHead *usedNode = (struct OsMemUsedNodeHead *)preNode;
+ UINT32 taskID = usedNode->taskID;
+ if (OS_TID_CHECK_INVALID(taskID)) {
+ MEM_UNLOCK(pool, intSave);
+ LOS_Panic("Task ID %u in pre node is invalid!\n", taskID);
+ return;
+ }
+
+ taskCB = OS_TCB_FROM_TID(taskID);
+ if (OsTaskIsUnused(taskCB) || (taskCB->taskEntry == NULL)) {
+ MEM_UNLOCK(pool, intSave);
+ LOS_Panic("\r\nTask ID %u in pre node is not created!\n", taskID);
+ return;
+ }
+ } else {
+ PRINTK("The prev node is free\n");
+ }
+ MEM_UNLOCK(pool, intSave);
+ LOS_Panic("cur node: %#x\npre node: %#x\npre node was allocated by task:%s\n",
+ tmpNode, preNode, taskCB->taskName);
+#else
+ MEM_UNLOCK(pool, intSave);
+ LOS_Panic("Memory interity check error, cur node: %#x, pre node: %#x\n", tmpNode, preNode);
+#endif
+}
+
+#ifdef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
+STATIC INLINE UINT32 OsMemAllocCheck(struct OsMemPoolHead *pool, UINT32 intSave)
+{
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemNodeHead *preNode = NULL;
+
+ if (OsMemIntegrityCheck(pool, &tmpNode, &preNode)) {
+ OsMemIntegrityCheckError(pool, tmpNode, preNode, intSave);
+ return LOS_NOK;
+ }
+ return LOS_OK;
+}
+#endif
+
+UINT32 LOS_MemIntegrityCheck(const VOID *pool)
+{
+ if (pool == NULL) {
+ return LOS_NOK;
+ }
+
+ struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemNodeHead *preNode = NULL;
+ UINT32 intSave = 0;
+
+ MEM_LOCK(poolHead, intSave);
+ if (OsMemIntegrityCheck(poolHead, &tmpNode, &preNode)) {
+ goto ERROR_OUT;
+ }
+ MEM_UNLOCK(poolHead, intSave);
+ return LOS_OK;
+
+ERROR_OUT:
+ OsMemIntegrityCheckError(poolHead, tmpNode, preNode, intSave);
+ return LOS_NOK;
+}
+
+STATIC INLINE VOID OsMemInfoGet(struct OsMemPoolHead *poolInfo, struct OsMemNodeHead *node,
+ LOS_MEM_POOL_STATUS *poolStatus)
+{
+ UINT32 totalUsedSize = 0;
+ UINT32 totalFreeSize = 0;
+ UINT32 usedNodeNum = 0;
+ UINT32 freeNodeNum = 0;
+ UINT32 maxFreeSize = 0;
+ UINT32 size;
+
+ if (!OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
+ size = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+ ++freeNodeNum;
+ totalFreeSize += size;
+ if (maxFreeSize < size) {
+ maxFreeSize = size;
+ }
+ } else {
+ size = OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
+ ++usedNodeNum;
+ totalUsedSize += size;
+ }
+
+ poolStatus->totalUsedSize += totalUsedSize;
+ poolStatus->totalFreeSize += totalFreeSize;
+ poolStatus->maxFreeNodeSize = MAX(poolStatus->maxFreeNodeSize, maxFreeSize);
+ poolStatus->usedNodeNum += usedNodeNum;
+ poolStatus->freeNodeNum += freeNodeNum;
+}
+
+UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
+{
+ struct OsMemPoolHead *poolInfo = pool;
+
+ if (poolStatus == NULL) {
+ PRINT_ERR("can't use NULL addr to save info\n");
+ return LOS_NOK;
+ }
+
+ if ((pool == NULL) || (poolInfo->info.pool != pool)) {
+ PRINT_ERR("wrong mem pool addr: %#x, line:%d\n", poolInfo, __LINE__);
+ return LOS_NOK;
+ }
+
+ struct OsMemNodeHead *tmpNode = NULL;
+ struct OsMemNodeHead *endNode = NULL;
+ UINT32 intSave;
+
+ MEM_LOCK(poolInfo, intSave);
+ endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
+#if OS_MEM_EXPAND_ENABLE
+ UINT32 size;
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
+ if (tmpNode == endNode) {
+ poolStatus->totalUsedSize += OS_MEM_NODE_HEAD_SIZE;
+ poolStatus->usedNodeNum++;
+ if (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
+ tmpNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(tmpNode, size);
+ continue;
+ } else {
+ break;
+ }
+ } else {
+ OsMemInfoGet(poolInfo, tmpNode, poolStatus);
+ }
+ }
+#else
+ for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
+ OsMemInfoGet(poolInfo, tmpNode, poolStatus);
+ }
+#endif
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ poolStatus->usageWaterLine = poolInfo->info.waterLine;
+#endif
+ MEM_UNLOCK(poolInfo, intSave);
+
+ return LOS_OK;
+}
+
+STATIC VOID OsMemInfoPrint(VOID *pool)
+{
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+ LOS_MEM_POOL_STATUS status = {0};
+
+ if (LOS_MemInfoGet(pool, &status) == LOS_NOK) {
+ return;
+ }
+
+#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
+ PRINTK("pool addr pool size used size free size "
+ "max free node size used node num free node num UsageWaterLine\n");
+ PRINTK("--------------- -------- ------- -------- "
+ "-------------- ------------- ------------ ------------\n");
+ PRINTK("%-16#x 0x%-8x 0x%-8x 0x%-8x 0x%-16x 0x%-13x 0x%-13x 0x%-13x\n",
+ poolInfo->info.pool, LOS_MemPoolSizeGet(pool), status.totalUsedSize,
+ status.totalFreeSize, status.maxFreeNodeSize, status.usedNodeNum,
+ status.freeNodeNum, status.usageWaterLine);
+#else
+ PRINTK("pool addr pool size used size free size "
+ "max free node size used node num free node num\n");
+ PRINTK("--------------- -------- ------- -------- "
+ "-------------- ------------- ------------\n");
+ PRINTK("%-16#x 0x%-8x 0x%-8x 0x%-8x 0x%-16x 0x%-13x 0x%-13x\n",
+ poolInfo->info.pool, LOS_MemPoolSizeGet(pool), status.totalUsedSize,
+ status.totalFreeSize, status.maxFreeNodeSize, status.usedNodeNum,
+ status.freeNodeNum);
+#endif
+}
+
+UINT32 LOS_MemFreeNodeShow(VOID *pool)
+{
+ struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
+
+ if ((poolInfo == NULL) || ((UINTPTR)pool != (UINTPTR)poolInfo->info.pool)) {
+ PRINT_ERR("wrong mem pool addr: %#x, line:%d\n", poolInfo, __LINE__);
+ return LOS_NOK;
+ }
+
+ struct OsMemFreeNodeHead *node = NULL;
+ UINT32 countNum[OS_MEM_FREE_LIST_COUNT] = {0};
+ UINT32 index;
+ UINT32 intSave;
+
+ MEM_LOCK(poolInfo, intSave);
+ for (index = 0; index < OS_MEM_FREE_LIST_COUNT; index++) {
+ node = poolInfo->freeList[index];
+ while (node) {
+ node = node->next;
+ countNum[index]++;
+ }
+ }
+ MEM_UNLOCK(poolInfo, intSave);
+
+ PRINTK("\n ************************ left free node number**********************\n");
+ for (index = 0; index < OS_MEM_FREE_LIST_COUNT; index++) {
+ if (countNum[index] == 0) {
+ continue;
+ }
+
+ PRINTK("free index: %03u, ", index);
+ if (index < OS_MEM_SMALL_BUCKET_COUNT) {
+ PRINTK("size: [%#x], num: %u\n", (index + 1) << 2, countNum[index]); /* 2: setup is 4. */
+ } else {
+ UINT32 val = 1 << (((index - OS_MEM_SMALL_BUCKET_COUNT) >> OS_MEM_SLI) + OS_MEM_LARGE_START_BUCKET);
+ UINT32 offset = val >> OS_MEM_SLI;
+ PRINTK("size: [%#x, %#x], num: %u\n", (offset * ((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI))) + val,
+ ((offset * (((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI)) + 1)) + val - 1), countNum[index]);
+ }
+ }
+ PRINTK("\n ********************************************************************\n\n");
+
+ return LOS_OK;
+}
+
+STATUS_T OsKHeapInit(size_t size)
+{
+ STATUS_T ret;
+ VOID *ptr = NULL;
+ /*
+ * roundup to MB aligned in order to set kernel attributes. kernel text/code/data attributes
+ * should page mapping, remaining region should section mapping. so the boundary should be
+ * MB aligned.
+ */
+ UINTPTR end = ROUNDUP(g_vmBootMemBase + size, MB);
+ size = end - g_vmBootMemBase;
+
+ ptr = OsVmBootMemAlloc(size);
+ if (!ptr) {
+ PRINT_ERR("vmm_kheap_init boot_alloc_mem failed! %d\n", size);
+ return -1;
+ }
+
+ m_aucSysMem0 = m_aucSysMem1 = ptr;
+ ret = LOS_MemInit(m_aucSysMem0, size);
+ if (ret != LOS_OK) {
+ PRINT_ERR("vmm_kheap_init LOS_MemInit failed!\n");
+ g_vmBootMemBase -= size;
+ return ret;
+ }
+#if OS_MEM_EXPAND_ENABLE
+ LOS_MemExpandEnable(OS_SYS_MEM_ADDR);
+#endif
+ return LOS_OK;
+}
+
+BOOL OsMemIsHeapNode(const VOID *ptr)
+{
+ struct OsMemPoolHead *pool = (struct OsMemPoolHead *)m_aucSysMem1;
+ struct OsMemNodeHead *firstNode = OS_MEM_FIRST_NODE(pool);
+ struct OsMemNodeHead *endNode = OS_MEM_END_NODE(pool, pool->info.totalSize);
+
+ if (OS_MEM_MIDDLE_ADDR(firstNode, ptr, endNode)) {
+ return TRUE;
+ }
+
+#if OS_MEM_EXPAND_ENABLE
+ UINT32 intSave;
+ UINT32 size;
+ MEM_LOCK(pool, intSave);
+ while (OsMemIsLastSentinelNode(endNode) == FALSE) {
+ size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
+ firstNode = OsMemSentinelNodeGet(endNode);
+ endNode = OS_MEM_END_NODE(firstNode, size);
+ if (OS_MEM_MIDDLE_ADDR(firstNode, ptr, endNode)) {
+ MEM_UNLOCK(pool, intSave);
+ return TRUE;
+ }
+ }
+ MEM_UNLOCK(pool, intSave);
+#endif
+ return FALSE;
+}
+
+UINT32 OsMemLargeNodeFree(const VOID *ptr)
+{
+ LosVmPage *page = OsVmVaddrToPage((VOID *)ptr);
+ if ((page == NULL) || (page->nPages == 0)) {
+ return LOS_NOK;
+ }
+ LOS_PhysPagesFreeContiguous((VOID *)ptr, page->nPages);
+
+ return LOS_OK;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
diff --git a/kernel/base/misc/kill_shellcmd.c b/kernel/base/misc/kill_shellcmd.c
old mode 100644
new mode 100755
index c1a0231a..e21dca7d
--- a/kernel/base/misc/kill_shellcmd.c
+++ b/kernel/base/misc/kill_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -39,8 +39,8 @@
#ifdef LOSCFG_BASE_CORE_HILOG
#include "log.h"
#else
-#define HILOG_INFO(type, fmt, ...) PRINT_INFO(fmt, __VA_ARGS__)
-#define HILOG_ERROR(type, fmt, ...) PRINT_ERR(fmt, __VA_ARGS__)
+#define HILOG_INFO(type, fmt, ...) PRINT_INFO(fmt, __VA_ARGS__)
+#define HILOG_ERROR(type, fmt, ...) PRINT_ERR(fmt, __VA_ARGS__)
#endif
#ifdef LOSCFG_SHELL
@@ -64,13 +64,13 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdKill(INT32 argc, const CHAR **argv)
if (argc == ARG_NUM) {
sigNo = strtoul(argv[0], &endPtr, 0);
if (*endPtr != 0) {
- PRINTK("\nsigNo can't access %s.\n", argv[0]);
+ PRINT_ERR("\nsigNo can't access %s.\n", argv[0]);
goto ERROR;
}
endPtr = NULL;
pidNo = strtoul(argv[1], &endPtr, 0);
if (*endPtr != 0) {
- PRINTK("\npidNo can't access %s.\n", argv[1]);
+ PRINT_ERR("\npidNo can't access %s.\n", argv[1]);
goto ERROR;
}
@@ -81,11 +81,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdKill(INT32 argc, const CHAR **argv)
goto ERROR;
}
if (ret < 0) {
- PRINTK("\n Kill fail ret = %d! process not exist or sigNo is invalid\n", ret);
+ PRINT_ERR("\n Kill fail ret = %d! process not exist or sigNo is invalid\n", ret);
goto ERROR;
}
} else {
- PRINTK("\nPara number errno!\n");
+ PRINT_ERR("\nPara number errno!\n");
goto ERROR;
}
return 0;
diff --git a/kernel/base/misc/los_misc.c b/kernel/base/misc/los_misc.c
index 8e36b08a..1e76e620 100644
--- a/kernel/base/misc/los_misc.c
+++ b/kernel/base/misc/los_misc.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/misc/los_stackinfo.c b/kernel/base/misc/los_stackinfo.c
old mode 100644
new mode 100755
index 9e7c891d..5bac7160
--- a/kernel/base/misc/los_stackinfo.c
+++ b/kernel/base/misc/los_stackinfo.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -32,6 +32,7 @@
#include "los_stackinfo_pri.h"
#include "los_printf_pri.h"
#include "los_config.h"
+#include "securec.h"
#ifdef LOSCFG_SHELL
#include "shcmd.h"
#include "shell.h"
diff --git a/kernel/base/misc/mempt_shellcmd.c b/kernel/base/misc/mempt_shellcmd.c
old mode 100644
new mode 100755
index a5bea3f8..e39ba93a
--- a/kernel/base/misc/mempt_shellcmd.c
+++ b/kernel/base/misc/mempt_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -54,7 +54,6 @@ extern "C" {
#define MEM_SIZE_1K 0x400
#define MEM_SIZE_1M 0x100000
-#define MEMPT_ARG_NUM_2 2
#define MEM_SIZE_TO_KB(size) (((size) + (MEM_SIZE_1K >> 1)) / MEM_SIZE_1K)
#define MEM_SIZE_TO_MB(size) (((size) + (MEM_SIZE_1M >> 1)) / MEM_SIZE_1M)
@@ -126,46 +125,6 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[])
}
#ifdef LOSCFG_SHELL
-LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRead(INT32 argc, const CHAR *argv[])
-{
- size_t tempAddr;
- size_t length;
- CHAR *ptrlen = NULL;
- CHAR *ptrAddr = NULL;
-
- if ((argc == 0) || (argc > 2)) { /* argc is num of parameters */
- PRINTK("\nUsage: readreg [ADDRESS] [LENGTH]\n");
- return OS_ERROR;
- }
-
- if (argc == 1) {
- length = 0;
- } else {
- length = strtoul(argv[1], &ptrlen, 0);
- if ((ptrlen == NULL) || (*ptrlen != 0)) {
- PRINTK("readreg invalid length %s\n", argv[1]);
- return OS_ERROR;
- }
- }
- tempAddr = strtoul(argv[0], &ptrAddr, 0);
- if ((ptrAddr == NULL) || (*ptrAddr != 0)) {
- PRINTK("readreg invalid address %s\n", argv[0]);
- return OS_ERROR;
- }
-
- if (OsVmAddrCheck(tempAddr, length) == LOS_OK) {
- goto DONE;
- }
-
- PRINTK("readreg invalid address %s\n", argv[0]);
- return OS_ERROR;
-
-DONE:
- OsDumpMemByte(length, tempAddr);
-
- return 0;
-}
-
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR *argv[])
{
size_t textLen = &__text_end - &__text_start;
@@ -304,24 +263,6 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[])
return 0;
}
#endif
-#ifdef LOSCFG_MEM_RECORDINFO
-LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRecordEnable(INT32 argc, const CHAR *argv[])
-{
- OsMemRecordShowSet(1);
- return 0;
-}
-
-LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRecordDisable(INT32 argc, const CHAR *argv[])
-{
- OsMemRecordShowSet(0);
- return 0;
-}
-
-SHELLCMD_ENTRY(memshowenable_shellcmd, CMD_TYPE_EX, "memshowenable", 0,
- (CmdCallBackFunc)OsShellCmdMemRecordEnable);
-SHELLCMD_ENTRY(memshowdisable_shellcmd, CMD_TYPE_EX, "memshowdisable", 0,
- (CmdCallBackFunc)OsShellCmdMemRecordDisable);
-#endif
#ifdef LOSCFG_MEM_LEAKCHECK
SHELLCMD_ENTRY(memused_shellcmd, CMD_TYPE_EX, "memused", 0, (CmdCallBackFunc)OsShellCmdMemUsed);
@@ -329,7 +270,6 @@ SHELLCMD_ENTRY(memused_shellcmd, CMD_TYPE_EX, "memused", 0, (CmdCallBackFunc)OsS
#ifdef LOSCFG_SHELL_CMD_DEBUG
SHELLCMD_ENTRY(memcheck_shellcmd, CMD_TYPE_EX, "memcheck", 0, (CmdCallBackFunc)OsShellCmdMemCheck);
-SHELLCMD_ENTRY(readreg_shellcmd, CMD_TYPE_EX, "readreg", MEMPT_ARG_NUM_2, (CmdCallBackFunc)OsShellCmdMemRead);
#endif
SHELLCMD_ENTRY(free_shellcmd, CMD_TYPE_EX, "free", XARGS, (CmdCallBackFunc)OsShellCmdFree);
SHELLCMD_ENTRY(uname_shellcmd, CMD_TYPE_EX, "uname", XARGS, (CmdCallBackFunc)OsShellCmdUname);
diff --git a/kernel/base/misc/panic_shellcmd.c b/kernel/base/misc/panic_shellcmd.c
new file mode 100755
index 00000000..82be521e
--- /dev/null
+++ b/kernel/base/misc/panic_shellcmd.c
@@ -0,0 +1,131 @@
+/*
+ * 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
+#include "shcmd.h"
+#include "shell.h"
+#endif
+#include "los_swtmr_pri.h"
+#include "watchdog_if.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+STATIC BOOL systemExcReset = FALSE;
+
+#define WATCHDOG_TIMER_INTERVAL 5 // 5 seconds
+#define WATCHDOG_TIMER_INTERVAL_HALF (WATCHDOG_TIMER_INTERVAL / 2)
+
+STATIC UINT16 g_swtmrID;
+STATIC BOOL g_wdStarted = FALSE;
+STATIC DevHandle g_wdHandle;
+
+STATIC void StartWatchdog(void)
+{
+ if (g_wdStarted) {
+ return;
+ }
+
+ g_wdHandle = WatchdogOpen(0);
+ WatchdogSetTimeout(g_wdHandle, WATCHDOG_TIMER_INTERVAL);
+
+ if (LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND * WATCHDOG_TIMER_INTERVAL_HALF, LOS_SWTMR_MODE_PERIOD,
+ (SWTMR_PROC_FUNC)WatchdogFeed, &g_swtmrID, (UINTPTR)g_wdHandle) != LOS_OK) {
+ WatchdogClose(g_wdHandle);
+ g_wdHandle = NULL;
+ return;
+ }
+
+ WatchdogStart(g_wdHandle);
+ LOS_SwtmrStart(g_swtmrID);
+ g_wdStarted = TRUE;
+}
+
+STATIC void StopWatchdog(void)
+{
+ if (!g_wdStarted) {
+ return;
+ }
+
+ LOS_SwtmrStop(g_swtmrID);
+ LOS_SwtmrDelete(g_swtmrID);
+ g_swtmrID = 0;
+
+ WatchdogStop(g_wdHandle);
+ WatchdogClose(g_wdHandle);
+ g_wdHandle = NULL;
+
+ g_wdStarted = FALSE;
+}
+
+LITE_OS_SEC_TEXT_MINOR BOOL OsSystemExcIsReset(VOID)
+{
+ return systemExcReset;
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSystemExcReset(INT32 argc, const CHAR **argv)
+{
+ if (argc != 1) {
+ goto EXC_RESET_HELP;
+ }
+
+ if (strcmp(argv[0], "on") == 0) {
+ systemExcReset = TRUE;
+ StartWatchdog();
+ PRINTK("panicreset on!\n");
+ return LOS_OK;
+ }
+
+ if (strcmp(argv[0], "off") == 0) {
+ systemExcReset = FALSE;
+ StopWatchdog();
+ PRINTK("panicreset off!\n");
+ return LOS_OK;
+ }
+
+EXC_RESET_HELP:
+ PRINTK("usage: panicreset [on/off]\n");
+ return LOS_OK;
+}
+
+SHELLCMD_ENTRY(panic_reset_shellcmd, CMD_TYPE_EX, "panicreset", 1, (CmdCallBackFunc)OsShellCmdSystemExcReset);
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
diff --git a/kernel/base/misc/swtmr_shellcmd.c b/kernel/base/misc/swtmr_shellcmd.c
index 09697779..cb7a3adf 100644
--- a/kernel/base/misc/swtmr_shellcmd.c
+++ b/kernel/base/misc/swtmr_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/misc/sysinfo_shellcmd.c b/kernel/base/misc/sysinfo_shellcmd.c
index a4283210..75cac70a 100644
--- a/kernel/base/misc/sysinfo_shellcmd.c
+++ b/kernel/base/misc/sysinfo_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/misc/task_shellcmd.c b/kernel/base/misc/task_shellcmd.c
old mode 100644
new mode 100755
index 902d203f..66622feb
--- a/kernel/base/misc/task_shellcmd.c
+++ b/kernel/base/misc/task_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -51,6 +51,7 @@
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#endif
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -64,8 +65,9 @@ extern "C" {
#define OS_PROCESS_UID_INFO_LEN (g_processMaxNum * sizeof(UINT32))
#define OS_PROCESS_MEM_ALL_INFO_LEN (g_processMaxNum * PROCESS_MEMINFO_LEN)
#ifdef LOSCFG_KERNEL_CPUP
-#define OS_PROCESS_CPUP_INFO_LEN (g_processMaxNum * sizeof(CPUP_INFO_S))
-#define OS_PROCESS_CPUP_ALLINFO_LEN (OS_PROCESS_CPUP_INFO_LEN * 3)
+#define OS_PROCESS_CPUP_LEN (g_processMaxNum * sizeof(CPUP_INFO_S))
+#define OS_PROCESS_AND_TASK_CPUP_LEN ((g_processMaxNum + g_taskMaxNum) * sizeof(CPUP_INFO_S))
+#define OS_PROCESS_CPUP_ALLINFO_LEN (OS_PROCESS_AND_TASK_CPUP_LEN * 3)
#else
#define OS_PROCESS_CPUP_ALLINFO_LEN 0
#endif
@@ -73,12 +75,15 @@ extern "C" {
OS_PROCESS_CPUP_ALLINFO_LEN + OS_PROCESS_UID_INFO_LEN)
#ifdef LOSCFG_KERNEL_CPUP
-LITE_OS_SEC_BSS STATIC CPUP_INFO_S *g_processCpupAll = NULL;
-LITE_OS_SEC_BSS STATIC CPUP_INFO_S *g_processCpup10s = NULL;
-LITE_OS_SEC_BSS STATIC CPUP_INFO_S *g_processCpup1s = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpupAll = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpup10s = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpup1s = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpupAll = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpup10s = NULL;
+LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpup1s = NULL;
#endif
-STATIC UINT32 *g_taskWaterLine = NULL;
+STATIC UINT32 *taskWaterLine = NULL;
#define OS_INVALID_SEM_ID 0xFFFFFFFF
#define OS_TASK_WATER_LINE_SIZE (g_taskMaxNum * sizeof(UINT32))
#define OS_TASK_INFO_LEN (g_taskMaxNum * sizeof(LosTaskCB))
@@ -113,6 +118,8 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdSchedPolicy(UINT16 policy)
return (UINT8 *)"RR";
} else if (policy == LOS_SCHED_FIFO) {
return (UINT8 *)"FIFO";
+ } else if (policy == LOS_SCHED_IDLE) {
+ return (UINT8 *)"IDLE";
}
return (UINT8 *)"ERROR";
@@ -129,10 +136,8 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellProcessStatus(UINT16 status)
return (UINT8 *)"Running";
} else if (status & OS_PROCESS_STATUS_READY) {
return (UINT8 *)"Ready";
- } else {
- if (status & OS_PROCESS_STATUS_PEND) {
- return (UINT8 *)"Pend";
- }
+ } else if (status & OS_PROCESS_STATUS_PENDING) {
+ return (UINT8 *)"Pending";
}
return (UINT8 *)"Invalid";
@@ -145,15 +150,15 @@ STATIC VOID OsShellCmdProcessTitle(VOID *seqBuf, UINT16 flag)
PROCESS_INFO_SHOW(seqBuf, "VirtualMem ShareMem PhysicalMem ");
}
+ if (flag & OS_PROCESS_INFO_ALL) {
#ifdef LOSCFG_KERNEL_CPUP
- if (flag & OS_PROCESS_INFO_ALL) {
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
- } else {
- PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
- }
#endif /* LOSCFG_KERNEL_CPUP */
- if (flag & OS_PROCESS_INFO_ALL) {
PROCESS_INFO_SHOW(seqBuf, "Policy Priority MTID TaskTotal Mode ");
+ } else {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
+#endif /* LOSCFG_KERNEL_CPUP */
}
PROCESS_INFO_SHOW(seqBuf, " PName\n");
}
@@ -172,26 +177,26 @@ STATIC VOID OsShellCmdProcessInfoShow(const LosProcessCB *processCB, const INT32
PROCESS_INFO_SHOW(seqBuf, "%#11x%#9x%#12x", procMemUsage[PROCESS_VM_INDEX], procMemUsage[PROCESS_SM_INDEX],
procMemUsage[PROCESS_PM_INDEX]);
}
+ if (flag & OS_PROCESS_INFO_ALL) {
#ifdef LOSCFG_KERNEL_CPUP
- if (flag & OS_PROCESS_INFO_ALL) {
- PROCESS_INFO_SHOW(seqBuf, "%5u.%1u%8u.%1u%7u.%-1u ",
- g_processCpupAll[pid].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_processCpupAll[pid].uwUsage % LOS_CPUP_PRECISION_MULT,
- g_processCpup10s[pid].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_processCpup10s[pid].uwUsage % LOS_CPUP_PRECISION_MULT,
- g_processCpup1s[pid].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_processCpup1s[pid].uwUsage % LOS_CPUP_PRECISION_MULT);
- } else {
- PROCESS_INFO_SHOW(seqBuf, "%8u.%1u ",
- g_processCpup10s[pid].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_processCpup10s[pid].uwUsage % LOS_CPUP_PRECISION_MULT);
- }
+ PROCESS_INFO_SHOW(seqBuf, "%4u.%-2u%7u.%-2u%6u.%-2u ",
+ processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
+ processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT,
+ processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
+ processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT,
+ processCpup1s[pid].usage / LOS_CPUP_PRECISION_MULT,
+ processCpup1s[pid].usage % LOS_CPUP_PRECISION_MULT);
#endif /* LOSCFG_KERNEL_CPUP */
- if (flag & OS_PROCESS_INFO_ALL) {
PROCESS_INFO_SHOW(seqBuf, "%6s%9u%5d%10u%7s ",
- OsShellCmdSchedPolicy(processCB->policy), processCB->priority,
+ OsShellCmdSchedPolicy(LOS_SCHED_RR), processCB->priority,
(INT32)processCB->threadGroupID, processCB->threadNumber,
OsShellCmdProcessMode(processCB->processMode));
+ } else {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "%7u.%-2u ",
+ processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
+ processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT);
+#endif /* LOSCFG_KERNEL_CPUP */
}
PROCESS_INFO_SHOW(seqBuf, " %-32s\n", processCB->processName);
}
@@ -271,12 +276,16 @@ STATIC UINT32 OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group, UINT32 **
}
#ifdef LOSCFG_KERNEL_CPUP
- g_processCpupAll = (CPUP_INFO_S *)((UINTPTR)user + OS_PROCESS_UID_INFO_LEN);
- g_processCpup10s = (CPUP_INFO_S *)((UINTPTR)g_processCpupAll + OS_PROCESS_CPUP_INFO_LEN);
- g_processCpup1s = (CPUP_INFO_S *)((UINTPTR)g_processCpup10s + OS_PROCESS_CPUP_INFO_LEN);
- (VOID)OsAllCpuUsageUnsafe(LOSCFG_BASE_CORE_PROCESS_LIMIT, g_processCpupAll, CPUP_ALL_TIME, 1);
- (VOID)OsAllCpuUsageUnsafe(LOSCFG_BASE_CORE_PROCESS_LIMIT, g_processCpup10s, CPUP_LAST_TEN_SECONDS, 1);
- (VOID)OsAllCpuUsageUnsafe(LOSCFG_BASE_CORE_PROCESS_LIMIT, g_processCpup1s, CPUP_LAST_ONE_SECONDS, 1);
+ processCpupAll = (CPUP_INFO_S *)((UINTPTR)user + OS_PROCESS_UID_INFO_LEN);
+ taskCpupAll = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_CPUP_LEN);
+ processCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
+ taskCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_CPUP_LEN);
+ processCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
+ taskCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup1s + OS_PROCESS_CPUP_LEN);
+
+ (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_ALL_TIME, processCpupAll, OS_PROCESS_AND_TASK_CPUP_LEN);
+ (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_TEN_SECONDS, processCpup10s, OS_PROCESS_AND_TASK_CPUP_LEN);
+ (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_ONE_SECONDS, processCpup1s, OS_PROCESS_AND_TASK_CPUP_LEN);
#endif
if (flag & OS_PROCESS_MEM_INFO) {
@@ -291,6 +300,17 @@ STATIC UINT32 OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group, UINT32 **
STATIC VOID OsShellCmdProcessInfoData(const LosProcessCB *pcbArray, const INT32 *group,
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
{
+#ifdef LOSCFG_KERNEL_CPUP
+ UINT32 pid = OsGetIdleProcessID();
+ UINT32 sysUsage = LOS_CPUP_PRECISION - processCpupAll[pid].usage;
+
+ PROCESS_INFO_SHOW(seqBuf, "\n allCpu(%%): %4u.%02u sys, %4u.%02u idle\n",
+ sysUsage / LOS_CPUP_PRECISION_MULT,
+ sysUsage % LOS_CPUP_PRECISION_MULT,
+ processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
+ processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT);
+#endif
+
OsShellCmdProcessTitle(seqBuf, flag);
OsShellCmdAllProcessInfoShow(pcbArray, group, memArray, seqBuf, flag);
}
@@ -303,22 +323,18 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
return (UINT8 *)"Running";
} else if (taskStatus & OS_TASK_STATUS_READY) {
return (UINT8 *)"Ready";
- } else {
- if (taskStatus & OS_TASK_STATUS_DELAY) {
- return (UINT8 *)"Delay";
- } else if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
- if (taskStatus & OS_TASK_STATUS_SUSPEND) {
- return (UINT8 *)"SuspendTime";
- } else if (taskStatus & OS_TASK_STATUS_PEND) {
- return (UINT8 *)"PendTime";
- }
- } else if (taskStatus & OS_TASK_STATUS_PEND) {
- return (UINT8 *)"Pend";
- } else if (taskStatus & OS_TASK_STATUS_SUSPEND) {
- return (UINT8 *)"Suspend";
- } else if (taskStatus & OS_TASK_STATUS_EXIT) {
- return (UINT8 *)"Exit";
+ } else if (taskStatus & OS_TASK_STATUS_SUSPENDED) {
+ return (UINT8 *)"Suspended";
+ } else if (taskStatus & OS_TASK_STATUS_DELAY) {
+ return (UINT8 *)"Delay";
+ } else if (taskStatus & OS_TASK_STATUS_PENDING) {
+ if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
+ return (UINT8 *)"PendTime";
+ } else {
+ return (UINT8 *)"Pending";
}
+ } else if (taskStatus & OS_TASK_STATUS_EXIT) {
+ return (UINT8 *)"Exit";
}
return (UINT8 *)"Invalid";
@@ -336,10 +352,80 @@ STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray)
}
(VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
- (const UINTPTR *)taskCB->topOfStack, &g_taskWaterLine[taskCB->taskID]);
+ (const UINTPTR *)taskCB->topOfStack, &taskWaterLine[taskCB->taskID]);
}
}
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+#define OS_PEND_REASON_MAX_LEN 20
+
+STATIC CHAR *OsShellCheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
+{
+ *lockID = taskCB->waitID;
+ switch (taskCB->waitFlag) {
+ case OS_TASK_WAIT_PROCESS:
+ return "Child";
+ case OS_TASK_WAIT_GID:
+ return "PGroup";
+ case OS_TASK_WAIT_ANYPROCESS:
+ return "AnyChild";
+ case OS_TASK_WAIT_SEM:
+ return "Semaphore";
+ case OS_TASK_WAIT_QUEUE:
+ return "Queue";
+ case OS_TASK_WAIT_JOIN:
+ return "Join";
+ case OS_TASK_WAIT_SIGNAL:
+ return "Signal";
+ case OS_TASK_WAIT_LITEIPC:
+ return "LiteIPC";
+ case OS_TASK_WAIT_MUTEX:
+ return "Mutex";
+ case OS_TASK_WAIT_EVENT:
+ return "Event";
+ case OS_TASK_WAIT_FUTEX:
+ return "Futex";
+ case OS_TASK_WAIT_COMPLETE:
+ return "Complete";
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+STATIC VOID OsShellCmdCheckTaskPend(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
+{
+ CHAR *reason = NULL;
+ LosTaskCB *owner = NULL;
+
+ if (!(taskCB->taskStatus & OS_TASK_STATUS_PENDING)) {
+ reason = (CHAR *)OsShellCmdConvertTskStatus(taskCB->taskStatus);
+ goto EXIT;
+ }
+
+ reason = OsShellCheckTaskWaitFlag(taskCB, lockID);
+ if (reason == NULL) {
+ reason = "Others";
+ }
+
+ if (taskCB->taskMux != NULL) {
+ *lockID = (UINTPTR)taskCB->taskMux;
+ owner = ((LosMux *)taskCB->taskMux)->owner;
+ if (owner != NULL) {
+ if (snprintf_s(pendReason, maxLen, maxLen - 1, "Mutex-%u", owner->taskID) == EOK) {
+ return;
+ }
+ }
+ }
+
+EXIT:
+ if (strcpy_s(pendReason, maxLen, reason) != EOK) {
+ PRINT_ERR("Get pend reason copy failed !\n");
+ }
+}
+#endif
+
STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
{
PROCESS_INFO_SHOW(seqBuf, "\r\n TID PID ");
@@ -348,29 +434,27 @@ STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
#endif
PROCESS_INFO_SHOW(seqBuf, " Status StackSize WaterLine ");
if (flag & OS_PROCESS_INFO_ALL) {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
+#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_SHELL_CMD_DEBUG
- PROCESS_INFO_SHOW(seqBuf, " StackPoint TopOfStack EventMask SemID ");
+ PROCESS_INFO_SHOW(seqBuf, " StackPoint TopOfStack PendReason LockID ");
#endif
PROCESS_INFO_SHOW(seqBuf, "Policy Priority ");
+ } else {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
+#endif /* LOSCFG_KERNEL_CPUP */
}
PROCESS_INFO_SHOW(seqBuf, " MEMUSE TaskName\n");
}
-#ifdef LOSCFG_SHELL_CMD_DEBUG
-STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB)
-{
- UINT32 semID = OS_INVALID_SEM_ID;
-
- if (taskCB->taskSem != NULL) {
- semID = ((LosSemCB *)taskCB->taskSem)->semID;
- }
-
- return semID;
-}
-#endif
-
STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UINT16 flag)
{
+#ifdef LOSCFG_SHELL_CMD_DEBUG
+ UINTPTR lockID = 0;
+ CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
+#endif
PROCESS_INFO_SHOW(seqBuf, " %4u%5u", taskCB->taskID, taskCB->processID);
#if (LOSCFG_KERNEL_SMP == YES)
@@ -378,14 +462,28 @@ STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UIN
#endif
PROCESS_INFO_SHOW(seqBuf, "%12s%#10x%#10x", OsShellCmdConvertTskStatus(taskCB->taskStatus),
- taskCB->stackSize, g_taskWaterLine[taskCB->taskID]);
-
+ taskCB->stackSize, taskWaterLine[taskCB->taskID]);
if (flag & OS_PROCESS_INFO_ALL) {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "%4u.%-2u%7u.%-2u%6u.%-2u ",
+ taskCpupAll[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
+ taskCpupAll[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT,
+ taskCpup10s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
+ taskCpup10s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT,
+ taskCpup1s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
+ taskCpup1s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT);
+#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_SHELL_CMD_DEBUG
- PROCESS_INFO_SHOW(seqBuf, "%#12x%#12x%#10x%#12x", taskCB->stackPointer, taskCB->topOfStack,
- taskCB->eventMask, OsGetSemID(taskCB));
+ OsShellCmdCheckTaskPend(taskCB, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
+ PROCESS_INFO_SHOW(seqBuf, "%#12x%#12x%11s%#11x", taskCB->stackPointer, taskCB->topOfStack, pendReason, lockID);
#endif
PROCESS_INFO_SHOW(seqBuf, "%7s%9u", OsShellCmdSchedPolicy(taskCB->policy), taskCB->priority);
+ } else {
+#ifdef LOSCFG_KERNEL_CPUP
+ PROCESS_INFO_SHOW(seqBuf, "%7u.%-2u ",
+ taskCpup10s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
+ taskCpup10s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT);
+#endif /* LOSCFG_KERNEL_CPUP */
}
PROCESS_INFO_SHOW(seqBuf, "%#10x %-32s\n", OsTaskMemUsage(taskCB->taskID), taskCB->taskName);
}
@@ -429,7 +527,7 @@ STATIC VOID OsProcessAndTaskInfoGet(LosProcessCB **pcbArray, INT32 **group, LosT
processInfoLen = OsProcessInfoGet(pcbArray, group, memArray, flag);
*tcbArray = (LosTaskCB *)((UINTPTR)*pcbArray + processInfoLen);
(VOID)memcpy_s(*tcbArray, OS_TASK_INFO_LEN, g_taskCBArray, OS_TASK_INFO_LEN);
- g_taskWaterLine = (UINT32 *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
+ taskWaterLine = (UINT32 *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
OsShellCmdTaskWaterLineGet(*tcbArray);
if (lockFlag == TRUE) {
SCHEDULER_UNLOCK(intSave);
@@ -469,23 +567,34 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf,
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
{
UINT32 flag = 0;
-
flag |= OS_PROCESS_MEM_INFO;
- if (argc < 2) { /* 2:Just as number of parameters */
- if (argc == 1) {
- if (strcmp("-a", argv[0]) == 0) {
- flag |= OS_PROCESS_INFO_ALL;
- } else {
- PRINTK("Unknown option: %s\n", argv[0]);
- goto TASK_HELP;
- }
- }
-
- return OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, flag);
+ if (argc >= 2) { /* 2: The task shell name restricts the parameters */
+ goto TASK_HELP;
}
+ if (argc == 1) {
+ if (strcmp("-a", argv[0]) == 0) {
+ flag |= OS_PROCESS_INFO_ALL;
+ } else if (strcmp("-i", argv[0]) == 0) {
+ if (!OsShellShowTickRespo()) {
+ return LOS_OK;
+ }
+ goto TASK_HELP;
+ } else if (strcmp("-t", argv[0]) == 0) {
+ if (!OsShellShowSchedParam()) {
+ return LOS_OK;
+ }
+ goto TASK_HELP;
+ } else {
+ goto TASK_HELP;
+ }
+ }
+
+ return OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, flag);
+
TASK_HELP:
+ PRINTK("Unknown option: %s\n", argv[0]);
PRINTK("usage: task or task -a\n");
return LOS_NOK;
}
diff --git a/kernel/base/misc/vm_shellcmd.c b/kernel/base/misc/vm_shellcmd.c
old mode 100644
new mode 100755
index 872c49e6..c4f08d1f
--- a/kernel/base/misc/vm_shellcmd.c
+++ b/kernel/base/misc/vm_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -152,7 +152,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdV2P(INT32 argc, const CHAR *argv[])
} else if (argc == 2) {
pid_t pid = OsPid(argv[0]);
vaddr = strtoul((CHAR *)argv[1], &endPtr, 0);
- if ((endPtr == NULL) || (*endPtr != 0)) {
+ if ((endPtr == NULL) || (*endPtr != 0) || !LOS_IsUserAddress(vaddr)) {
PRINTK("vaddr %s invalid. should be in range(0x1000000~0x3e000000) \n", argv[1]);
return OS_ERROR;
} else {
diff --git a/kernel/base/mp/los_lockdep.c b/kernel/base/mp/los_lockdep.c
index f35ea96f..3f52964b 100644
--- a/kernel/base/mp/los_lockdep.c
+++ b/kernel/base/mp/los_lockdep.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -273,7 +273,7 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
depth = lockDep->lockDepth;
/* find the lock position */
- while (depth-- >= 0) {
+ while (--depth >= 0) {
if (heldlocks[depth].lockPtr == lock) {
break;
}
@@ -314,7 +314,35 @@ VOID OsLockdepClearSpinlocks(VOID)
}
}
-#endif /* LOSCFG_KERNEL_SMP_LOCKDEP */
+#else /* LOSCFG_KERNEL_SMP_LOCKDEP */
+
+VOID OsLockDepCheckIn(SPIN_LOCK_S *lock)
+{
+ (VOID)lock;
+
+ return;
+}
+
+VOID OsLockDepRecord(SPIN_LOCK_S *lock)
+{
+ (VOID)lock;
+
+ return;
+}
+
+VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
+{
+ (VOID)lock;
+
+ return;
+}
+
+VOID OsLockdepClearSpinlocks(VOID)
+{
+ return;
+}
+
+#endif
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/base/mp/los_mp.c b/kernel/base/mp/los_mp.c
index 948d3d72..9c3f7c96 100644
--- a/kernel/base/mp/los_mp.c
+++ b/kernel/base/mp/los_mp.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/mp/los_percpu.c b/kernel/base/mp/los_percpu.c
index c2e5bfb4..476c7c66 100644
--- a/kernel/base/mp/los_percpu.c
+++ b/kernel/base/mp/los_percpu.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/mp/los_spinlock.c b/kernel/base/mp/los_spinlock.c
new file mode 100644
index 00000000..02a332ab
--- /dev/null
+++ b/kernel/base/mp/los_spinlock.c
@@ -0,0 +1,115 @@
+/*
+ * 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_spinlock.h"
+#if (LOSCFG_KERNEL_SMP == YES)
+#include "los_sched_pri.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+VOID LOS_SpinInit(SPIN_LOCK_S *lock)
+{
+ lock->rawLock = 0;
+ lock->cpuid = (UINT32)-1;
+ lock->owner = SPINLOCK_OWNER_INIT;
+ lock->name = "spinlock";
+}
+
+BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
+{
+ return (lock->rawLock != 0);
+}
+
+VOID LOS_SpinLock(SPIN_LOCK_S *lock)
+{
+ UINT32 intSave = LOS_IntLock();
+ OsCpuSchedLock(OsPercpuGet());
+ LOS_IntRestore(intSave);
+
+ LOCKDEP_CHECK_IN(lock);
+ ArchSpinLock(&lock->rawLock);
+ LOCKDEP_RECORD(lock);
+}
+
+INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
+{
+ Percpu *cpu = OsPercpuGet();
+ UINT32 intSave = LOS_IntLock();
+ OsCpuSchedLock(cpu);
+ LOS_IntRestore(intSave);
+
+ INT32 ret = ArchSpinTrylock(&lock->rawLock);
+ if (ret == LOS_OK) {
+ LOCKDEP_CHECK_IN(lock);
+ LOCKDEP_RECORD(lock);
+ } else {
+ OsCpuSchedUnlock(cpu, LOS_IntLock());
+ }
+
+ return ret;
+}
+
+VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
+{
+ LOCKDEP_CHECK_OUT(lock);
+ ArchSpinUnlock(&lock->rawLock);
+
+ OsCpuSchedUnlock(OsPercpuGet(), LOS_IntLock());
+}
+
+VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave)
+{
+ *intSave = LOS_IntLock();
+ OsCpuSchedLock(OsPercpuGet());
+
+ LOCKDEP_CHECK_IN(lock);
+ ArchSpinLock(&lock->rawLock);
+ LOCKDEP_RECORD(lock);
+}
+
+VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave)
+{
+ LOCKDEP_CHECK_OUT(lock);
+ ArchSpinUnlock(&lock->rawLock);
+
+ OsCpuSchedUnlock(OsPercpuGet(), intSave);
+}
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/kernel/base/mp/los_stat.c b/kernel/base/mp/los_stat.c
old mode 100644
new mode 100755
index f556eb56..9f63716e
--- a/kernel/base/mp/los_stat.c
+++ b/kernel/base/mp/los_stat.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/om/los_err.c b/kernel/base/om/los_err.c
old mode 100644
new mode 100755
index 9b07b8d3..5c455b8f
--- a/kernel/base/om/los_err.c
+++ b/kernel/base/om/los_err.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/sched/sched_sq/los_priqueue.c b/kernel/base/sched/sched_sq/los_priqueue.c
deleted file mode 100644
index 22905273..00000000
--- a/kernel/base/sched/sched_sq/los_priqueue.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_priqueue_pri.h"
-#include "los_task_pri.h"
-#include "los_memory.h"
-#include "los_toolchain.h"
-#include "los_spinlock.h"
-#include "los_process_pri.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif
-#endif /* __cplusplus */
-
-#define PRIQUEUE_PRIOR0_BIT 0x80000000U
-
-LITE_OS_SEC_BSS LOS_DL_LIST *g_priQueueList = NULL;
-LITE_OS_SEC_BSS UINT32 g_priQueueBitmap;
-
-UINT32 OsPriQueueInit(VOID)
-{
- UINT32 priority;
-
- /* system resident resource */
- g_priQueueList = (LOS_DL_LIST *)LOS_MemAlloc(m_aucSysMem0, (OS_PRIORITY_QUEUE_NUM * sizeof(LOS_DL_LIST)));
- if (g_priQueueList == NULL) {
- return LOS_NOK;
- }
-
- for (priority = 0; priority < OS_PRIORITY_QUEUE_NUM; ++priority) {
- LOS_ListInit(&g_priQueueList[priority]);
- }
- return LOS_OK;
-}
-
-LOS_DL_LIST *OsPriQueueTop(LOS_DL_LIST *priQueueList, UINT32 *bitMap)
-{
- UINT32 priority;
-
- if (*bitMap != 0) {
- priority = CLZ(*bitMap);
- return LOS_DL_LIST_FIRST(&priQueueList[priority]);
- }
-
- return NULL;
-}
-
-VOID OsPriQueueEnqueueHead(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem, UINT32 priority)
-{
- /*
- * Task control blocks are inited as zero. And when task is deleted,
- * and at the same time would be deleted from priority queue or
- * other lists, task pend node will restored as zero.
- */
- LOS_ASSERT(priqueueItem->pstNext == NULL);
-
- if (LOS_ListEmpty(&priQueueList[priority])) {
- *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;
- }
-
- LOS_ListHeadInsert(&priQueueList[priority], priqueueItem);
-}
-
-VOID OsPriQueueEnqueue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem, UINT32 priority)
-{
- /*
- * Task control blocks are inited as zero. And when task is deleted,
- * and at the same time would be deleted from priority queue or
- * other lists, task pend node will restored as zero.
- */
- LOS_ASSERT(priqueueItem->pstNext == NULL);
-
- if (LOS_ListEmpty(&priQueueList[priority])) {
- *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;
- }
-
- LOS_ListTailInsert(&priQueueList[priority], priqueueItem);
-}
-
-VOID OsPriQueueDequeue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem)
-{
- LosTaskCB *task = NULL;
- LOS_ListDelete(priqueueItem);
-
- task = LOS_DL_LIST_ENTRY(priqueueItem, LosTaskCB, pendList);
- if (LOS_ListEmpty(&priQueueList[task->priority])) {
- *bitMap &= ~(PRIQUEUE_PRIOR0_BIT >> task->priority);
- }
-}
-
-VOID OsPriQueueProcessDequeue(LOS_DL_LIST *priqueueItem)
-{
- LosProcessCB *runProcess = NULL;
- LOS_ListDelete(priqueueItem);
-
- runProcess = LOS_DL_LIST_ENTRY(priqueueItem, LosProcessCB, pendList);
- if (LOS_ListEmpty(&g_priQueueList[runProcess->priority])) {
- g_priQueueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> runProcess->priority);
- }
-}
-
-UINT32 OsPriQueueProcessSize(LOS_DL_LIST *priQueueList, UINT32 priority)
-{
- UINT32 itemCnt = 0;
- LOS_DL_LIST *curNode = NULL;
-
- LOS_ASSERT(OsIntLocked());
- LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
-
- LOS_DL_LIST_FOR_EACH(curNode, &priQueueList[priority]) {
- ++itemCnt;
- }
-
- return itemCnt;
-}
-
-UINT32 OsPriQueueSize(LOS_DL_LIST *priQueueList, UINT32 priority)
-{
- UINT32 itemCnt = 0;
- LOS_DL_LIST *curNode = NULL;
-#if (LOSCFG_KERNEL_SMP == YES)
- LosTaskCB *task = NULL;
- UINT32 cpuID = ArchCurrCpuid();
-#endif
-
- LOS_ASSERT(OsIntLocked());
- LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
-
- LOS_DL_LIST_FOR_EACH(curNode, &priQueueList[priority]) {
-#if (LOSCFG_KERNEL_SMP == YES)
- task = OS_TCB_FROM_PENDLIST(curNode);
- if (!(task->cpuAffiMask & (1U << cpuID))) {
- continue;
- }
-#endif
- ++itemCnt;
- }
-
- return itemCnt;
-}
-
-
-LOS_DL_LIST *OsTaskPriQueueTop(VOID)
-{
- LosProcessCB *processCB = LOS_DL_LIST_ENTRY(OsPriQueueTop(g_priQueueList, &g_priQueueBitmap),
- LosProcessCB,
- pendList);
- return OsPriQueueTop(processCB->threadPriQueueList, &processCB->threadScheduleMap);
-}
-
-STATIC INLINE VOID OsDequeEmptySchedMap(LosProcessCB *processCB)
-{
- if (processCB->threadScheduleMap == 0) {
- processCB->processStatus &= ~OS_PROCESS_STATUS_READY;
- OsPriQueueProcessDequeue(&processCB->pendList);
- }
-}
-
-LITE_OS_SEC_TEXT_MINOR LosTaskCB *OsGetTopTask(VOID)
-{
- UINT32 priority, processPriority;
- UINT32 bitmap;
- UINT32 processBitmap;
- LosTaskCB *newTask = NULL;
-#if (LOSCFG_KERNEL_SMP == YES)
- UINT32 cpuid = ArchCurrCpuid();
-#endif
- LosProcessCB *processCB = NULL;
- processBitmap = g_priQueueBitmap;
- while (processBitmap) {
- processPriority = CLZ(processBitmap);
- LOS_DL_LIST_FOR_EACH_ENTRY(processCB, &g_priQueueList[processPriority], LosProcessCB, pendList) {
- bitmap = processCB->threadScheduleMap;
- while (bitmap) {
- priority = CLZ(bitmap);
- LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &processCB->threadPriQueueList[priority], LosTaskCB, pendList) {
-#if (LOSCFG_KERNEL_SMP == YES)
- if (newTask->cpuAffiMask & (1U << cpuid)) {
-#endif
- newTask->taskStatus &= ~OS_TASK_STATUS_READY;
- OsPriQueueDequeue(processCB->threadPriQueueList,
- &processCB->threadScheduleMap,
- &newTask->pendList);
- OsDequeEmptySchedMap(processCB);
- goto OUT;
-#if (LOSCFG_KERNEL_SMP == YES)
- }
-#endif
- }
- bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
- }
- }
- processBitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - processPriority - 1));
- }
-
-OUT:
- return newTask;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif
-#endif /* __cplusplus */
-
diff --git a/kernel/base/sched/sched_sq/los_sched.c b/kernel/base/sched/sched_sq/los_sched.c
old mode 100644
new mode 100755
index a3051dd1..6f082e45
--- a/kernel/base/sched/sched_sq/los_sched.c
+++ b/kernel/base/sched/sched_sq/los_sched.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,15 +29,23 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "los_base.h"
-#include "los_task_pri.h"
-#include "los_percpu_pri.h"
+#include "los_sched_pri.h"
#include "los_hw_pri.h"
-#include "los_arch_mmu.h"
+#include "los_task_pri.h"
#include "los_process_pri.h"
+#include "los_arch_mmu.h"
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
+#include "los_hw_tick_pri.h"
+#include "los_tick_pri.h"
+#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
+#include "los_stackinfo_pri.h"
+#endif
+#include "los_mp.h"
+#ifdef LOSCFG_SCHED_DEBUG
+#include "los_stat_pri.h"
+#endif
#ifdef __cplusplus
#if __cplusplus
@@ -45,123 +53,1040 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-STATIC VOID OsSchedSwitchProcess(LosProcessCB *runProcess, LosProcessCB *newProcess)
+
+#define OS_32BIT_MAX 0xFFFFFFFFUL
+#define OS_64BIT_MAX 0xFFFFFFFFFFFFFFFFULL
+#define OS_SCHED_FIFO_TIMEOUT 0x7FFFFFFF
+#define OS_PRIORITY_QUEUE_NUM 32
+#define PRIQUEUE_PRIOR0_BIT 0x80000000U
+#define OS_SCHED_TIME_SLICES_MIN ((5000 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 5ms */
+#define OS_SCHED_TIME_SLICES_MAX ((LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE)
+#define OS_SCHED_TIME_SLICES_DIFF (OS_SCHED_TIME_SLICES_MAX - OS_SCHED_TIME_SLICES_MIN)
+#define OS_SCHED_READY_MAX 30
+#define OS_TIME_SLICE_MIN ((50 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 50us */
+#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(OS_64BIT_MAX - 1U)
+
+typedef struct {
+ LOS_DL_LIST priQueueList[OS_PRIORITY_QUEUE_NUM];
+ UINT32 readyTasks[OS_PRIORITY_QUEUE_NUM];
+ UINT32 queueBitmap;
+} SchedQueue;
+
+typedef struct {
+ SchedQueue queueList[OS_PRIORITY_QUEUE_NUM];
+ UINT32 queueBitmap;
+ SchedScan taskScan;
+ SchedScan swtmrScan;
+} Sched;
+
+STATIC Sched *g_sched = NULL;
+STATIC UINT64 g_schedTickMaxResponseTime;
+UINT64 g_sysSchedStartTime = 0;
+
+#ifdef LOSCFG_SCHED_TICK_DEBUG
+#define OS_SCHED_DEBUG_DATA_NUM 1000
+typedef struct {
+ UINT32 tickResporeTime[OS_SCHED_DEBUG_DATA_NUM];
+ UINT32 index;
+ UINT32 setTickCount;
+ UINT64 oldResporeTime;
+} SchedTickDebug;
+STATIC SchedTickDebug *g_schedTickDebug = NULL;
+
+STATIC UINT32 OsSchedDebugInit(VOID)
{
- if (runProcess == newProcess) {
+ UINT32 size = sizeof(SchedTickDebug) * LOSCFG_KERNEL_CORE_NUM;
+ g_schedTickDebug = (SchedTickDebug *)LOS_MemAlloc(m_aucSysMem0, size);
+ if (g_schedTickDebug == NULL) {
+ return LOS_ERRNO_TSK_NO_MEMORY;
+ }
+
+ (VOID)memset_s(g_schedTickDebug, size, 0, size);
+ return LOS_OK;
+}
+
+VOID OsSchedDebugRecordData(VOID)
+{
+ SchedTickDebug *schedDebug = &g_schedTickDebug[ArchCurrCpuid()];
+ if (schedDebug->index < OS_SCHED_DEBUG_DATA_NUM) {
+ UINT64 currTime = OsGerCurrSchedTimeCycle();
+ schedDebug->tickResporeTime[schedDebug->index] = currTime - schedDebug->oldResporeTime;
+ schedDebug->oldResporeTime = currTime;
+ schedDebug->index++;
+ }
+}
+
+SchedTickDebug *OsSchedDebugGet(VOID)
+{
+ return g_schedTickDebug;
+}
+
+UINT32 OsShellShowTickRespo(VOID)
+{
+ UINT32 intSave;
+ UINT16 cpu;
+
+ UINT32 tickSize = sizeof(SchedTickDebug) * LOSCFG_KERNEL_CORE_NUM;
+ SchedTickDebug *schedDebug = (SchedTickDebug *)LOS_MemAlloc(m_aucSysMem1, tickSize);
+ if (schedDebug == NULL) {
+ return LOS_NOK;
+ }
+
+ UINT32 sortLinkNum[LOSCFG_KERNEL_CORE_NUM];
+ SCHEDULER_LOCK(intSave);
+ (VOID)memcpy_s((CHAR *)schedDebug, tickSize, (CHAR *)OsSchedDebugGet(), tickSize);
+ (VOID)memset_s((CHAR *)OsSchedDebugGet(), tickSize, 0, tickSize);
+ for (cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
+ sortLinkNum[cpu] = OsPercpuGetByID(cpu)->taskSortLink.nodeNum + OsPercpuGetByID(cpu)->swtmrSortLink.nodeNum;
+ }
+ SCHEDULER_UNLOCK(intSave);
+
+ for (cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
+ SchedTickDebug *schedData = &schedDebug[cpu];
+ PRINTK("cpu : %u sched data num : %u set time count : %u SortMax : %u\n",
+ cpu, schedData->index, schedData->setTickCount, sortLinkNum[cpu]);
+ UINT32 *data = schedData->tickResporeTime;
+ for (UINT32 i = 0; i < schedData->index; i++) {
+ UINT32 timeUs = (data[i] * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
+ PRINTK(" %u(%u)", timeUs, timeUs / OS_US_PER_TICK);
+ if ((i != 0) && ((i % 5) == 0)) {
+ PRINTK("\n");
+ }
+ }
+
+ PRINTK("\n");
+ }
+
+ (VOID)LOS_MemFree(m_aucSysMem1, schedDebug);
+ return LOS_OK;
+}
+
+#else
+
+UINT32 OsShellShowTickRespo(VOID)
+{
+ return LOS_NOK;
+}
+#endif
+
+#ifdef LOSCFG_SCHED_DEBUG
+UINT32 OsShellShowSchedParam(VOID)
+{
+ UINT64 averRunTime;
+ UINT64 averTimeSlice;
+ UINT64 averSchedWait;
+ UINT64 averPendTime;
+ UINT32 intSave;
+ UINT32 size = g_taskMaxNum * sizeof(LosTaskCB);
+ LosTaskCB *taskCBArray = LOS_MemAlloc(m_aucSysMem1, size);
+ if (taskCBArray == NULL) {
+ return LOS_NOK;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ (VOID)memcpy_s(taskCBArray, size, g_taskCBArray, size);
+ SCHEDULER_UNLOCK(intSave);
+ PRINTK(" Tid AverRunTime(us) SwitchCount AverTimeSlice(us) TimeSliceCount AverReadyWait(us) "
+ "AverPendTime(us) TaskName \n");
+ for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
+ LosTaskCB *taskCB = taskCBArray + tid;
+ if (OsTaskIsUnused(taskCB)) {
+ continue;
+ }
+
+ averRunTime = 0;
+ averTimeSlice = 0;
+ averPendTime = 0;
+ averSchedWait = 0;
+
+ if (taskCB->schedStat.switchCount >= 1) {
+ averRunTime = taskCB->schedStat.runTime / taskCB->schedStat.switchCount;
+ averRunTime = (averRunTime * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
+ }
+
+ if (taskCB->schedStat.timeSliceCount > 1) {
+ averTimeSlice = taskCB->schedStat.timeSliceTime / (taskCB->schedStat.timeSliceCount - 1);
+ averTimeSlice = (averTimeSlice * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
+ }
+
+ if (taskCB->schedStat.pendCount > 1) {
+ averPendTime = taskCB->schedStat.pendTime / taskCB->schedStat.pendCount;
+ averPendTime = (averPendTime * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
+ }
+
+ if (taskCB->schedStat.waitSchedCount > 0) {
+ averSchedWait = taskCB->schedStat.waitSchedTime / taskCB->schedStat.waitSchedCount;
+ averSchedWait = (averSchedWait * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
+ }
+
+ PRINTK("%5u%19llu%15llu%19llu%18llu%19llu%18llu %-32s\n", taskCB->taskID,
+ averRunTime, taskCB->schedStat.switchCount,
+ averTimeSlice, taskCB->schedStat.timeSliceCount - 1,
+ averSchedWait, averPendTime, taskCB->taskName);
+ }
+
+ (VOID)LOS_MemFree(m_aucSysMem1, taskCBArray);
+
+ return LOS_OK;
+}
+
+#else
+
+UINT32 OsShellShowSchedParam(VOID)
+{
+ return LOS_NOK;
+}
+#endif
+
+UINT32 OsSchedSetTickTimerType(UINT32 timerType)
+{
+ switch (timerType) {
+ case 32: /* 32 bit timer */
+ g_schedTickMaxResponseTime = OS_32BIT_MAX;
+ break;
+ case 64: /* 64 bit timer */
+ g_schedTickMaxResponseTime = OS_64BIT_MAX;
+ break;
+ default:
+ PRINT_ERR("Unsupported Tick Timer type, The system only supports 32 and 64 bit tick timers\n");
+ return LOS_NOK;
+ }
+
+ return LOS_OK;
+}
+
+STATIC VOID OsSchedSetStartTime(UINT64 currCycle)
+{
+ if (g_sysSchedStartTime == 0) {
+ g_sysSchedStartTime = currCycle;
+ }
+}
+
+STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
+{
+ LOS_ASSERT(currTime >= taskCB->startTime);
+
+ INT32 incTime = (currTime - taskCB->startTime - taskCB->irqUsedTime);
+
+ LOS_ASSERT(incTime >= 0);
+
+ if (taskCB->policy == LOS_SCHED_RR) {
+ taskCB->timeSlice -= incTime;
+#ifdef LOSCFG_SCHED_DEBUG
+ taskCB->schedStat.timeSliceRealTime += incTime;
+#endif
+ }
+ taskCB->irqUsedTime = 0;
+ taskCB->startTime = currTime;
+
+#ifdef LOSCFG_SCHED_DEBUG
+ taskCB->schedStat.allRuntime += incTime;
+#endif
+}
+
+STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
+ UINT64 taskEndTime, UINT32 oldResponseID)
+{
+ UINT64 nextExpireTime = OsGetNextExpireTime(startTime);
+ Percpu *currCpu = OsPercpuGet();
+ UINT64 nextResponseTime;
+ BOOL isTimeSlice = FALSE;
+
+ if (currCpu->responseID == oldResponseID) {
+ /* This time has expired, and the next time the theory has expired is infinite */
+ currCpu->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
+ }
+
+ /* The current thread's time slice has been consumed, but the current system lock task cannot
+ * trigger the schedule to release the CPU
+ */
+ if (taskEndTime < nextExpireTime) {
+ nextExpireTime = taskEndTime;
+ isTimeSlice = TRUE;
+ }
+
+ if ((currCpu->responseTime > nextExpireTime) && ((currCpu->responseTime - nextExpireTime) >= OS_CYCLE_PER_TICK)) {
+ nextResponseTime = nextExpireTime - startTime;
+ if (nextResponseTime < OS_CYCLE_PER_TICK) {
+ nextResponseTime = OS_CYCLE_PER_TICK;
+ nextExpireTime = startTime + nextResponseTime;
+ if (nextExpireTime >= currCpu->responseTime) {
+ return;
+ }
+ } else if (nextResponseTime > g_schedTickMaxResponseTime) {
+ nextResponseTime = g_schedTickMaxResponseTime;
+ nextExpireTime = startTime + nextResponseTime;
+ }
+ } else {
+ /* There is no point earlier than the current expiration date */
return;
}
+ if (isTimeSlice) {
+ /* The expiration time of the current system is the thread's slice expiration time */
+ currCpu->responseID = responseID;
+ } else {
+ currCpu->responseID = OS_INVALID_VALUE;
+ }
+
+ currCpu->responseTime = nextExpireTime;
+ HalClockTickTimerReload(nextResponseTime);
+
+#ifdef LOSCFG_SCHED_TICK_DEBUG
+ SchedTickDebug *schedDebug = &g_schedTickDebug[ArchCurrCpuid()];
+ if (schedDebug->index < OS_SCHED_DEBUG_DATA_NUM) {
+ schedDebug->setTickCount++;
+ }
+#endif
+}
+
+VOID OsSchedUpdateExpireTime(UINT64 startTime)
+{
+ UINT64 endTime;
+ LosTaskCB *runTask = OsCurrTaskGet();
+
+ if (runTask->policy == LOS_SCHED_RR) {
+ LOS_SpinLock(&g_taskSpin);
+ INT32 timeSlice = (runTask->timeSlice <= OS_TIME_SLICE_MIN) ? runTask->initTimeSlice : runTask->timeSlice;
+ LOS_SpinUnlock(&g_taskSpin);
+ endTime = startTime + timeSlice;
+ } else {
+ endTime = OS_SCHED_MAX_RESPONSE_TIME;
+ }
+
+ OsSchedSetNextExpireTime(startTime, runTask->taskID, endTime, runTask->taskID);
+}
+
+STATIC INLINE UINT32 OsSchedCalculateTimeSlice(UINT16 proPriority, UINT16 priority)
+{
+ UINT32 ratTime, readTasks;
+
+ SchedQueue *queueList = &g_sched->queueList[proPriority];
+ readTasks = queueList->readyTasks[priority];
+ if (readTasks > OS_SCHED_READY_MAX) {
+ return OS_SCHED_TIME_SLICES_MIN;
+ }
+ ratTime = ((OS_SCHED_READY_MAX - readTasks) * OS_SCHED_TIME_SLICES_DIFF) / OS_SCHED_READY_MAX;
+ return (ratTime + OS_SCHED_TIME_SLICES_MIN);
+}
+
+STATIC INLINE VOID OsSchedPriQueueEnHead(UINT32 proPriority, LOS_DL_LIST *priqueueItem, UINT32 priority)
+{
+ SchedQueue *queueList = &g_sched->queueList[proPriority];
+ LOS_DL_LIST *priQueueList = &queueList->priQueueList[0];
+ UINT32 *bitMap = &queueList->queueBitmap;
+
+ /*
+ * Task control blocks are inited as zero. And when task is deleted,
+ * and at the same time would be deleted from priority queue or
+ * other lists, task pend node will restored as zero.
+ */
+ LOS_ASSERT(priqueueItem->pstNext == NULL);
+
+ if (*bitMap == 0) {
+ g_sched->queueBitmap |= PRIQUEUE_PRIOR0_BIT >> proPriority;
+ }
+
+ if (LOS_ListEmpty(&priQueueList[priority])) {
+ *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;
+ }
+
+ LOS_ListHeadInsert(&priQueueList[priority], priqueueItem);
+ queueList->readyTasks[priority]++;
+}
+
+STATIC INLINE VOID OsSchedPriQueueEnTail(UINT32 proPriority, LOS_DL_LIST *priqueueItem, UINT32 priority)
+{
+ SchedQueue *queueList = &g_sched->queueList[proPriority];
+ LOS_DL_LIST *priQueueList = &queueList->priQueueList[0];
+ UINT32 *bitMap = &queueList->queueBitmap;
+
+ /*
+ * Task control blocks are inited as zero. And when task is deleted,
+ * and at the same time would be deleted from priority queue or
+ * other lists, task pend node will restored as zero.
+ */
+ LOS_ASSERT(priqueueItem->pstNext == NULL);
+
+ if (*bitMap == 0) {
+ g_sched->queueBitmap |= PRIQUEUE_PRIOR0_BIT >> proPriority;
+ }
+
+ if (LOS_ListEmpty(&priQueueList[priority])) {
+ *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;
+ }
+
+ LOS_ListTailInsert(&priQueueList[priority], priqueueItem);
+ queueList->readyTasks[priority]++;
+}
+
+STATIC INLINE VOID OsSchedPriQueueDelete(UINT32 proPriority, LOS_DL_LIST *priqueueItem, UINT32 priority)
+{
+ SchedQueue *queueList = &g_sched->queueList[proPriority];
+ LOS_DL_LIST *priQueueList = &queueList->priQueueList[0];
+ UINT32 *bitMap = &queueList->queueBitmap;
+
+ LOS_ListDelete(priqueueItem);
+ queueList->readyTasks[priority]--;
+ if (LOS_ListEmpty(&priQueueList[priority])) {
+ *bitMap &= ~(PRIQUEUE_PRIOR0_BIT >> priority);
+ }
+
+ if (*bitMap == 0) {
+ g_sched->queueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> proPriority);
+ }
+}
+
+STATIC INLINE VOID OsSchedWakePendTimeTask(UINT64 currTime, LosTaskCB *taskCB, BOOL *needSchedule)
+{
+#ifndef LOSCFG_SCHED_DEBUG
+ (VOID)currTime;
+#endif
+
+ LOS_SpinLock(&g_taskSpin);
+ UINT16 tempStatus = taskCB->taskStatus;
+ if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) {
+ taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
+ if (tempStatus & OS_TASK_STATUS_PENDING) {
+#if (LOSCFG_KERNEL_LITEIPC == YES)
+ taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
+#endif
+ taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
+ LOS_ListDelete(&taskCB->pendList);
+ taskCB->taskMux = NULL;
+ OsTaskWakeClearPendMask(taskCB);
+ }
+
+ if (!(tempStatus & OS_TASK_STATUS_SUSPENDED)) {
+#ifdef LOSCFG_SCHED_DEBUG
+ taskCB->schedStat.pendTime += currTime - taskCB->startTime;
+ taskCB->schedStat.pendCount++;
+#endif
+ OsSchedTaskEnQueue(taskCB);
+ *needSchedule = TRUE;
+ }
+ }
+
+ LOS_SpinUnlock(&g_taskSpin);
+}
+
+STATIC INLINE BOOL OsSchedScanTimerList(VOID)
+{
+ Percpu *cpu = OsPercpuGet();
+ BOOL needSchedule = FALSE;
+ SortLinkAttribute *taskSortLink = &OsPercpuGet()->taskSortLink;
+ LOS_DL_LIST *listObject = &taskSortLink->sortLink;
+ /*
+ * When task is pended with timeout, the task block is on the timeout sortlink
+ * (per cpu) and ipc(mutex,sem and etc.)'s block at the same time, it can be waken
+ * up by either timeout or corresponding ipc it's waiting.
+ *
+ * Now synchronize sortlink preocedure is used, therefore the whole task scan needs
+ * to be protected, preventing another core from doing sortlink deletion at same time.
+ */
+ LOS_SpinLock(&cpu->taskSortLinkSpin);
+
+ if (LOS_ListEmpty(listObject)) {
+ LOS_SpinUnlock(&cpu->taskSortLinkSpin);
+ return needSchedule;
+ }
+
+ SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
+ UINT64 currTime = OsGerCurrSchedTimeCycle();
+ while (sortList->responseTime <= currTime) {
+ LosTaskCB *taskCB = LOS_DL_LIST_ENTRY(sortList, LosTaskCB, sortList);
+ OsDeleteNodeSortLink(taskSortLink, &taskCB->sortList);
+ LOS_SpinUnlock(&cpu->taskSortLinkSpin);
+
+ OsSchedWakePendTimeTask(currTime, taskCB, &needSchedule);
+
+ LOS_SpinLock(&cpu->taskSortLinkSpin);
+ if (LOS_ListEmpty(listObject)) {
+ break;
+ }
+
+ sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
+ }
+
+ LOS_SpinUnlock(&cpu->taskSortLinkSpin);
+
+ return needSchedule;
+}
+
+STATIC INLINE VOID OsSchedEnTaskQueue(LosTaskCB *taskCB, LosProcessCB *processCB)
+{
+ LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
+
+ switch (taskCB->policy) {
+ case LOS_SCHED_RR: {
+ if (taskCB->timeSlice > OS_TIME_SLICE_MIN) {
+ OsSchedPriQueueEnHead(processCB->priority, &taskCB->pendList, taskCB->priority);
+ } else {
+ taskCB->initTimeSlice = OsSchedCalculateTimeSlice(processCB->priority, taskCB->priority);
+ taskCB->timeSlice = taskCB->initTimeSlice;
+ OsSchedPriQueueEnTail(processCB->priority, &taskCB->pendList, taskCB->priority);
+#ifdef LOSCFG_SCHED_DEBUG
+ taskCB->schedStat.timeSliceTime = taskCB->schedStat.timeSliceRealTime;
+ taskCB->schedStat.timeSliceCount++;
+#endif
+ }
+ break;
+ }
+ case LOS_SCHED_FIFO: {
+ /* The time slice of FIFO is always greater than 0 unless the yield is called */
+ if ((taskCB->timeSlice > OS_TIME_SLICE_MIN) && (taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
+ OsSchedPriQueueEnHead(processCB->priority, &taskCB->pendList, taskCB->priority);
+ } else {
+ taskCB->initTimeSlice = OS_SCHED_FIFO_TIMEOUT;
+ taskCB->timeSlice = taskCB->initTimeSlice;
+ OsSchedPriQueueEnTail(processCB->priority, &taskCB->pendList, taskCB->priority);
+ }
+ break;
+ }
+ case LOS_SCHED_IDLE:
+#ifdef LOSCFG_SCHED_DEBUG
+ taskCB->schedStat.timeSliceCount = 1;
+#endif
+ break;
+ default:
+ LOS_ASSERT(0);
+ break;
+ }
+
+ taskCB->taskStatus &= ~OS_TASK_STATUS_BLOCKED;
+ taskCB->taskStatus |= OS_TASK_STATUS_READY;
+
+ processCB->processStatus &= ~(OS_PROCESS_STATUS_INIT | OS_PROCESS_STATUS_PENDING);
+ processCB->processStatus |= OS_PROCESS_STATUS_READY;
+ processCB->readyTaskNum++;
+}
+
+STATIC INLINE VOID OsSchedDeTaskQueue(LosTaskCB *taskCB, LosProcessCB *processCB)
+{
+ if (taskCB->policy != LOS_SCHED_IDLE) {
+ OsSchedPriQueueDelete(processCB->priority, &taskCB->pendList, taskCB->priority);
+ }
+ taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
+
+ processCB->readyTaskNum--;
+ if (processCB->readyTaskNum == 0) {
+ processCB->processStatus &= ~OS_PROCESS_STATUS_READY;
+ }
+}
+
+VOID OsSchedTaskDeQueue(LosTaskCB *taskCB)
+{
+ LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
+
+ if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
+ OsSchedDeTaskQueue(taskCB, processCB);
+ }
+
+ if (processCB->processStatus & OS_PROCESS_STATUS_READY) {
+ return;
+ }
+
+ /* If the current process has only the current thread running,
+ * the process becomes blocked after the thread leaves the scheduling queue
+ */
+ if (OS_PROCESS_GET_RUNTASK_COUNT(processCB->processStatus) == 1) {
+ processCB->processStatus |= OS_PROCESS_STATUS_PENDING;
+ }
+}
+
+VOID OsSchedTaskEnQueue(LosTaskCB *taskCB)
+{
+ LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
+#ifdef LOSCFG_SCHED_DEBUG
+ if (!(taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
+ taskCB->startTime = OsGerCurrSchedTimeCycle();
+ }
+#endif
+ OsSchedEnTaskQueue(taskCB, processCB);
+}
+
+VOID OsSchedTaskExit(LosTaskCB *taskCB)
+{
+ LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
+
+ if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
+ OsSchedTaskDeQueue(taskCB);
+ processCB->processStatus &= ~OS_PROCESS_STATUS_PENDING;
+ } else if (taskCB->taskStatus & OS_TASK_STATUS_PENDING) {
+ LOS_ListDelete(&taskCB->pendList);
+ taskCB->taskStatus &= ~OS_TASK_STATUS_PENDING;
+ }
+
+ if (taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)) {
+ OsDeleteSortLink(&taskCB->sortList, OS_SORT_LINK_TASK);
+ taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
+ }
+}
+
+VOID OsSchedYield(VOID)
+{
+ LosTaskCB *runTask = OsCurrTaskGet();
+
+ runTask->timeSlice = 0;
+
+ runTask->startTime = OsGerCurrSchedTimeCycle();
+ OsSchedTaskEnQueue(runTask);
+ OsSchedResched();
+}
+
+VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick)
+{
+ OsSchedTaskDeQueue(runTask);
+ runTask->taskStatus |= OS_TASK_STATUS_DELAY;
+ runTask->waitTimes = tick;
+
+ OsSchedResched();
+}
+
+UINT32 OsSchedTaskWait(LOS_DL_LIST *list, UINT32 ticks, BOOL needSched)
+{
+ LosTaskCB *runTask = OsCurrTaskGet();
+ OsSchedTaskDeQueue(runTask);
+
+ runTask->taskStatus |= OS_TASK_STATUS_PENDING;
+ LOS_ListTailInsert(list, &runTask->pendList);
+
+ if (ticks != LOS_WAIT_FOREVER) {
+ runTask->taskStatus |= OS_TASK_STATUS_PEND_TIME;
+ runTask->waitTimes = ticks;
+ }
+
+ if (needSched == TRUE) {
+ OsSchedResched();
+ if (runTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
+ runTask->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
+ return LOS_ERRNO_TSK_TIMEOUT;
+ }
+ }
+
+ return LOS_OK;
+}
+
+VOID OsSchedTaskWake(LosTaskCB *resumedTask)
+{
+ LOS_ListDelete(&resumedTask->pendList);
+ resumedTask->taskStatus &= ~OS_TASK_STATUS_PENDING;
+
+ if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
+ OsDeleteSortLink(&resumedTask->sortList, OS_SORT_LINK_TASK);
+ resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
+ }
+
+ if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
+#ifdef LOSCFG_SCHED_DEBUG
+ resumedTask->schedStat.pendTime += OsGerCurrSchedTimeCycle() - resumedTask->startTime;
+ resumedTask->schedStat.pendCount++;
+#endif
+ OsSchedTaskEnQueue(resumedTask);
+ }
+}
+
+BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priority)
+{
+ if (taskCB->policy != policy) {
+ taskCB->policy = policy;
+ taskCB->timeSlice = 0;
+ }
+
+ if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
+ OsSchedTaskDeQueue(taskCB);
+ taskCB->priority = priority;
+ OsSchedTaskEnQueue(taskCB);
+ return TRUE;
+ }
+
+ taskCB->priority = priority;
+ if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
+ OsSchedTaskEnQueue(taskCB);
+ return TRUE;
+ }
+
+ if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+BOOL OsSchedModifyProcessSchedParam(LosProcessCB *processCB, UINT16 policy, UINT16 priority)
+{
+ LosTaskCB *taskCB = NULL;
+ BOOL needSched = FALSE;
+ (VOID)policy;
+
+ if (processCB->processStatus & OS_PROCESS_STATUS_READY) {
+ LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
+ if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
+ OsSchedPriQueueDelete(processCB->priority, &taskCB->pendList, taskCB->priority);
+ OsSchedPriQueueEnTail(priority, &taskCB->pendList, taskCB->priority);
+ needSched = TRUE;
+ }
+ }
+ }
+
+ processCB->priority = priority;
+ if (processCB->processStatus & OS_PROCESS_STATUS_RUNNING) {
+ needSched = TRUE;
+ }
+
+ return needSched;
+}
+
+VOID OsSchedTick(VOID)
+{
+ Sched *sched = g_sched;
+ Percpu *currCpu = OsPercpuGet();
+ BOOL needSched = FALSE;
+
+ if (currCpu->responseID == OS_INVALID_VALUE) {
+ if (sched->swtmrScan != NULL) {
+ (VOID)sched->swtmrScan();
+ }
+
+ needSched = sched->taskScan();
+ currCpu->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
+
+ if (needSched) {
+ LOS_MpSchedule(OS_MP_CPU_ALL);
+ currCpu->schedFlag = INT_PEND_RESCH;
+ }
+ }
+}
+
+VOID OsSchedSetIdleTaskSchedPartam(LosTaskCB *idleTask)
+{
+ idleTask->policy = LOS_SCHED_IDLE;
+ idleTask->initTimeSlice = OS_SCHED_FIFO_TIMEOUT;
+ idleTask->timeSlice = idleTask->initTimeSlice;
+ OsSchedTaskEnQueue(idleTask);
+}
+
+UINT32 OsSchedSwtmrScanRegister(SchedScan func)
+{
+ if (func == NULL) {
+ return LOS_NOK;
+ }
+
+ g_sched->swtmrScan = func;
+ return LOS_OK;
+}
+
+UINT32 OsSchedInit(VOID)
+{
+ UINT16 index, pri;
+ UINT32 ret;
+
+ g_sched = (Sched *)LOS_MemAlloc(m_aucSysMem0, sizeof(Sched));
+ if (g_sched == NULL) {
+ return LOS_ERRNO_TSK_NO_MEMORY;
+ }
+
+ (VOID)memset_s(g_sched, sizeof(Sched), 0, sizeof(Sched));
+
+ for (index = 0; index < OS_PRIORITY_QUEUE_NUM; index++) {
+ SchedQueue *queueList = &g_sched->queueList[index];
+ LOS_DL_LIST *priList = &queueList->priQueueList[0];
+ for (pri = 0; pri < OS_PRIORITY_QUEUE_NUM; pri++) {
+ LOS_ListInit(&priList[pri]);
+ }
+ }
+
+ for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
+ Percpu *cpu = OsPercpuGetByID(index);
+ ret = OsSortLinkInit(&cpu->taskSortLink);
+ if (ret != LOS_OK) {
+ return LOS_ERRNO_TSK_NO_MEMORY;
+ }
+ cpu->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
+ LOS_SpinInit(&cpu->taskSortLinkSpin);
+ LOS_SpinInit(&cpu->swtmrSortLinkSpin);
+ }
+
+ g_sched->taskScan = OsSchedScanTimerList;
+
+#ifdef LOSCFG_SCHED_TICK_DEBUG
+ ret = OsSchedDebugInit();
+ if (ret != LOS_OK) {
+ return ret;
+ }
+#endif
+ return LOS_OK;
+}
+
+STATIC LosTaskCB *OsGetTopTask(VOID)
+{
+ UINT32 priority, processPriority;
+ UINT32 bitmap;
+ LosTaskCB *newTask = NULL;
+ UINT32 processBitmap = g_sched->queueBitmap;
#if (LOSCFG_KERNEL_SMP == YES)
+ UINT32 cpuid = ArchCurrCpuid();
+#endif
+
+ while (processBitmap) {
+ processPriority = CLZ(processBitmap);
+ SchedQueue *queueList = &g_sched->queueList[processPriority];
+ bitmap = queueList->queueBitmap;
+ while (bitmap) {
+ priority = CLZ(bitmap);
+ LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueueList[priority], LosTaskCB, pendList) {
+#if (LOSCFG_KERNEL_SMP == YES)
+ if (newTask->cpuAffiMask & (1U << cpuid)) {
+#endif
+ goto FIND_TASK;
+#if (LOSCFG_KERNEL_SMP == YES)
+ }
+#endif
+ }
+ bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
+ }
+ processBitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - processPriority - 1));
+ }
+
+ newTask = OS_TCB_FROM_TID(OsPercpuGet()->idleTaskID);
+
+FIND_TASK:
+ OsSchedDeTaskQueue(newTask, OS_PCB_FROM_PID(newTask->processID));
+ return newTask;
+}
+
+VOID OsSchedStart(VOID)
+{
+ UINT32 cpuid = ArchCurrCpuid();
+ UINT32 intSave;
+
+ SCHEDULER_LOCK(intSave);
+
+ OsTickStart();
+
+ LosTaskCB *newTask = OsGetTopTask();
+ LosProcessCB *newProcess = OS_PCB_FROM_PID(newTask->processID);
+
+ newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
+ newProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
+ newProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_ADD(newProcess->processStatus);
+
+ OsSchedSetStartTime(HalClockGetCycles());
+ newTask->startTime = OsGerCurrSchedTimeCycle();
+
+#if (LOSCFG_KERNEL_SMP == YES)
+ /*
+ * attention: current cpu needs to be set, in case first task deletion
+ * may fail because this flag mismatch with the real current cpu.
+ */
+ newTask->currCpu = cpuid;
+#endif
+
+ OsCurrTaskSet((VOID *)newTask);
+
+ /* System start schedule */
+ OS_SCHEDULER_SET(cpuid);
+
+ OsPercpuGet()->responseID = OS_INVALID;
+ OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice, OS_INVALID);
+
+ PRINTK("cpu %d entering scheduler\n", cpuid);
+ OsTaskContextLoad(newTask);
+}
+
+#if (LOSCFG_KERNEL_SMP == YES)
+VOID OsSchedToUserReleaseLock(VOID)
+{
+ /* The scheduling lock needs to be released before returning to user mode */
+ LOCKDEP_CHECK_OUT(&g_taskSpin);
+ ArchSpinUnlock(&g_taskSpin.rawLock);
+
+ OsPercpuGet()->taskLockCnt--;
+}
+#endif
+
+#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
+STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
+{
+ if (!OS_STACK_MAGIC_CHECK(runTask->topOfStack)) {
+ LOS_Panic("CURRENT task ID: %s:%d stack overflow!\n", runTask->taskName, runTask->taskID);
+ }
+
+ if (((UINTPTR)(newTask->stackPointer) <= newTask->topOfStack) ||
+ ((UINTPTR)(newTask->stackPointer) > (newTask->topOfStack + newTask->stackSize))) {
+ LOS_Panic("HIGHEST task ID: %s:%u SP error! StackPointer: %p TopOfStack: %p\n",
+ newTask->taskName, newTask->taskID, newTask->stackPointer, newTask->topOfStack);
+ }
+}
+#endif
+
+STATIC INLINE VOID OsSchedSwitchCheck(LosTaskCB *runTask, LosTaskCB *newTask)
+{
+#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
+ OsTaskStackCheck(runTask, newTask);
+#endif /* LOSCFG_BASE_CORE_TSK_MONITOR == YES */
+
+ OsTraceTaskSchedule(newTask, runTask);
+}
+
+STATIC INLINE VOID OsSchedSwitchProcess(LosProcessCB *runProcess, LosProcessCB *newProcess)
+{
runProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_DEC(runProcess->processStatus);
newProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_ADD(newProcess->processStatus);
LOS_ASSERT(!(OS_PROCESS_GET_RUNTASK_COUNT(newProcess->processStatus) > LOSCFG_KERNEL_CORE_NUM));
if (OS_PROCESS_GET_RUNTASK_COUNT(runProcess->processStatus) == 0) {
-#endif
runProcess->processStatus &= ~OS_PROCESS_STATUS_RUNNING;
- if ((runProcess->threadNumber > 1) && !(runProcess->processStatus & OS_PROCESS_STATUS_READY)) {
- runProcess->processStatus |= OS_PROCESS_STATUS_PEND;
- }
-#if (LOSCFG_KERNEL_SMP == YES)
}
-#endif
- LOS_ASSERT(!(newProcess->processStatus & OS_PROCESS_STATUS_PEND));
+
+ LOS_ASSERT(!(newProcess->processStatus & OS_PROCESS_STATUS_PENDING));
newProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
if (OsProcessIsUserMode(newProcess)) {
LOS_ArchMmuContextSwitch(&newProcess->vmSpace->archMmu);
}
-#ifdef LOSCFG_KERNEL_CPUP
- OsProcessCycleEndStart(newProcess->processID, OS_PROCESS_GET_RUNTASK_COUNT(runProcess->processStatus) + 1);
-#endif /* LOSCFG_KERNEL_CPUP */
-
OsCurrProcessSet(newProcess);
-
- if ((newProcess->timeSlice == 0) && (newProcess->policy == LOS_SCHED_RR)) {
- newProcess->timeSlice = OS_PROCESS_SCHED_RR_INTERVAL;
- }
}
-VOID OsSchedResched(VOID)
+STATIC VOID OsSchedTaskSwicth(LosTaskCB *runTask, LosTaskCB *newTask)
{
- LosTaskCB *runTask = NULL;
- LosTaskCB *newTask = NULL;
- LosProcessCB *runProcess = NULL;
- LosProcessCB *newProcess = NULL;
+ UINT64 endTime;
- LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
-
- if (!OsPreemptableInSched()) {
- return;
- }
-
- runTask = OsCurrTaskGet();
- newTask = OsGetTopTask();
-
- /* always be able to get one task */
- LOS_ASSERT(newTask != NULL);
-
- if (runTask == newTask) {
- return;
- }
+ OsSchedSwitchCheck(runTask, newTask);
runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
- runProcess = OS_PCB_FROM_PID(runTask->processID);
- newProcess = OS_PCB_FROM_PID(newTask->processID);
-
- OsSchedSwitchProcess(runProcess, newProcess);
-
#if (LOSCFG_KERNEL_SMP == YES)
/* mask new running task's owner processor */
runTask->currCpu = OS_TASK_INVALID_CPUID;
newTask->currCpu = ArchCurrCpuid();
#endif
- (VOID)OsTaskSwitchCheck(runTask, newTask);
-
-#if (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
- OsSchedStatistics(runTask, newTask);
-#endif
-
- if ((newTask->timeSlice == 0) && (newTask->policy == LOS_SCHED_RR)) {
- newTask->timeSlice = LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT;
+ OsCurrTaskSet((VOID *)newTask);
+ LosProcessCB *newProcess = OS_PCB_FROM_PID(newTask->processID);
+ LosProcessCB *runProcess = OS_PCB_FROM_PID(runTask->processID);
+ if (runProcess != newProcess) {
+ OsSchedSwitchProcess(runProcess, newProcess);
}
- OsCurrTaskSet((VOID*)newTask);
-
if (OsProcessIsUserMode(newProcess)) {
OsCurrUserTaskSet(newTask->userArea);
}
- PRINT_TRACE("cpu%d run process name: (%s) pid: %d status: %x threadMap: %x task name: (%s) tid: %d status: %x ->\n"
- " new process name: (%s) pid: %d status: %x threadMap: %x task name: (%s) tid: %d status: %x!\n",
- ArchCurrCpuid(),
- runProcess->processName, runProcess->processID, runProcess->processStatus,
- runProcess->threadScheduleMap, runTask->taskName, runTask->taskID, runTask->taskStatus,
- newProcess->processName, newProcess->processID, newProcess->processStatus,
- newProcess->threadScheduleMap, newTask->taskName, newTask->taskID, newTask->taskStatus);
+#ifdef LOSCFG_KERNEL_CPUP
+ OsCpupCycleEndStart(runTask->taskID, newTask->taskID);
+#endif
+#ifdef LOSCFG_SCHED_DEBUG
+ UINT64 waitStartTime = newTask->startTime;
+#endif
+ if (runTask->taskStatus & OS_TASK_STATUS_READY) {
+ /* When a thread enters the ready queue, its slice of time is updated */
+ newTask->startTime = runTask->startTime;
+ } else {
+ /* The currently running task is blocked */
+ newTask->startTime = OsGerCurrSchedTimeCycle();
+ /* The task is in a blocking state and needs to update its time slice before pend */
+ OsTimeSliceUpdate(runTask, newTask->startTime);
+
+ if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) {
+ OsAdd2SortLink(&runTask->sortList, runTask->startTime, runTask->waitTimes, OS_SORT_LINK_TASK);
+ }
+ }
+
+ if (newTask->policy == LOS_SCHED_RR) {
+ endTime = newTask->startTime + newTask->timeSlice;
+ } else {
+ endTime = OS_SCHED_MAX_RESPONSE_TIME;
+ }
+ OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, endTime, runTask->taskID);
+
+#ifdef LOSCFG_SCHED_DEBUG
+ newTask->schedStat.waitSchedTime += newTask->startTime - waitStartTime;
+ newTask->schedStat.waitSchedCount++;
+ runTask->schedStat.runTime = runTask->schedStat.allRuntime;
+ runTask->schedStat.switchCount++;
+#endif
/* do the task context switch */
OsTaskSchedule(newTask, runTask);
}
-VOID OsSchedPreempt(VOID)
+VOID OsSchedIrqEndCheckNeedSched(VOID)
+{
+ Percpu *percpu = OsPercpuGet();
+ LosTaskCB *runTask = OsCurrTaskGet();
+
+ OsTimeSliceUpdate(runTask, OsGerCurrSchedTimeCycle());
+ if (runTask->timeSlice <= OS_TIME_SLICE_MIN) {
+ percpu->schedFlag = INT_PEND_RESCH;
+ }
+
+ if (OsPreemptable() && (percpu->schedFlag == INT_PEND_RESCH)) {
+ percpu->schedFlag = INT_NO_RESCH;
+
+ LOS_SpinLock(&g_taskSpin);
+
+ OsSchedTaskEnQueue(runTask);
+
+ LosTaskCB *newTask = OsGetTopTask();
+ if (runTask != newTask) {
+ OsSchedTaskSwicth(runTask, newTask);
+ LOS_SpinUnlock(&g_taskSpin);
+ return;
+ }
+
+ LOS_SpinUnlock(&g_taskSpin);
+ }
+
+ OsSchedUpdateExpireTime(runTask->startTime);
+}
+
+VOID OsSchedResched(VOID)
+{
+ LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
+#if (LOSCFG_KERNEL_SMP == YES)
+ LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
+#else
+ LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);
+#endif
+
+ OsPercpuGet()->schedFlag = INT_NO_RESCH;
+ LosTaskCB *runTask = OsCurrTaskGet();
+ LosTaskCB *newTask = OsGetTopTask();
+ if (runTask == newTask) {
+ return;
+ }
+
+ OsSchedTaskSwicth(runTask, newTask);
+}
+
+VOID LOS_Schedule(VOID)
{
- LosTaskCB *runTask = NULL;
UINT32 intSave;
+ LosTaskCB *runTask = OsCurrTaskGet();
+
+ if (OS_INT_ACTIVE) {
+ OsPercpuGet()->schedFlag = INT_PEND_RESCH;
+ return;
+ }
if (!OsPreemptable()) {
return;
}
+ /*
+ * trigger schedule in task will also do the slice check
+ * if neccessary, it will give up the timeslice more in time.
+ * otherwhise, there's no other side effects.
+ */
SCHEDULER_LOCK(intSave);
+ OsTimeSliceUpdate(runTask, OsGerCurrSchedTimeCycle());
+
/* add run task back to ready queue */
- runTask = OsCurrTaskGet();
- OS_TASK_SCHED_QUEUE_ENQUEUE(runTask, 0);
+ OsSchedTaskEnQueue(runTask);
/* reschedule to new thread */
OsSchedResched();
@@ -169,6 +1094,47 @@ VOID OsSchedPreempt(VOID)
SCHEDULER_UNLOCK(intSave);
}
+STATIC INLINE LOS_DL_LIST *OsSchedLockPendFindPosSub(const LosTaskCB *runTask, const LOS_DL_LIST *lockList)
+{
+ LosTaskCB *pendedTask = NULL;
+ LOS_DL_LIST *node = NULL;
+
+ LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, lockList, LosTaskCB, pendList) {
+ if (pendedTask->priority < runTask->priority) {
+ continue;
+ } else if (pendedTask->priority > runTask->priority) {
+ node = &pendedTask->pendList;
+ break;
+ } else {
+ node = pendedTask->pendList.pstNext;
+ break;
+ }
+ }
+
+ return node;
+}
+
+LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList)
+{
+ LOS_DL_LIST *node = NULL;
+
+ if (LOS_ListEmpty(lockList)) {
+ node = lockList;
+ } else {
+ LosTaskCB *pendedTask1 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(lockList));
+ LosTaskCB *pendedTask2 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_LAST(lockList));
+ if (pendedTask1->priority > runTask->priority) {
+ node = lockList->pstNext;
+ } else if (pendedTask2->priority <= runTask->priority) {
+ node = lockList;
+ } else {
+ node = OsSchedLockPendFindPosSub(runTask, lockList);
+ }
+ }
+
+ return node;
+}
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/base/vm/los_vm_boot.c b/kernel/base/vm/los_vm_boot.c
old mode 100644
new mode 100755
index 15b4f7af..b0186d73
--- a/kernel/base/vm/los_vm_boot.c
+++ b/kernel/base/vm/los_vm_boot.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -47,15 +47,6 @@ extern "C" {
UINTPTR g_vmBootMemBase = (UINTPTR)&__bss_end;
BOOL g_kHeapInited = FALSE;
-UINT32 OsVmAddrCheck(size_t tempAddr, size_t length)
-{
- if ((tempAddr >= KERNEL_VMM_BASE) && ((tempAddr + length) <= (PERIPH_UNCACHED_BASE + PERIPH_UNCACHED_SIZE))) {
- return LOS_OK;
- }
-
- return LOS_NOK;
-}
-
VOID *OsVmBootMemAlloc(size_t len)
{
UINTPTR ptr;
@@ -84,14 +75,16 @@ UINT32 OsSysMemInit(VOID)
}
OsVmPageStartup();
+ g_kHeapInited = TRUE;
OsInitMappingStartUp();
+#ifdef LOSCFG_KERNEL_SHM
ret = ShmInit();
if (ret < 0) {
VM_ERR("ShmInit fail");
return LOS_NOK;
}
-
+#endif
return LOS_OK;
}
diff --git a/kernel/base/vm/los_vm_dump.c b/kernel/base/vm/los_vm_dump.c
old mode 100644
new mode 100755
index 791c075a..4298b4f8
--- a/kernel/base/vm/los_vm_dump.c
+++ b/kernel/base/vm/los_vm_dump.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -493,6 +493,9 @@ VOID OsVmPhysDump(VOID)
UINT32 totalFreePages = 0;
UINT32 totalPages = 0;
UINT32 segIndex;
+ UINT32 intSave;
+ UINT32 flindex;
+ UINT32 listCount[VM_LIST_ORDER_MAX] = {0};
for (segIndex = 0; segIndex < g_vmPhysSegNum; segIndex++) {
seg = &g_vmPhysSeg[segIndex];
@@ -502,10 +505,19 @@ VOID OsVmPhysDump(VOID)
PRINTK("\r\n phys_seg base size free_pages \n");
PRINTK(" -------- ------- ---------- --------- \n");
#endif
- PRINTK(" %08p %08p 0x%08x %8u \n", seg, seg->start, seg->size, segFreePages);
+ PRINTK(" 0x%08x 0x%08x 0x%08x %8u \n", seg, seg->start, seg->size, segFreePages);
totalFreePages += segFreePages;
totalPages += (seg->size >> PAGE_SHIFT);
+ LOS_SpinLockSave(&seg->freeListLock, &intSave);
+ for (flindex = 0; flindex < VM_LIST_ORDER_MAX; flindex++) {
+ listCount[flindex] = seg->freeList[flindex].listCnt;
+ }
+ LOS_SpinUnlockRestore(&seg->freeListLock, intSave);
+ for (flindex = 0; flindex < VM_LIST_ORDER_MAX; flindex++) {
+ PRINTK("order = %d, free_count = %d\n", flindex, listCount[flindex]);
+ }
+
PRINTK("active anon %d\n", seg->lruSize[VM_LRU_ACTIVE_ANON]);
PRINTK("inactive anon %d\n", seg->lruSize[VM_LRU_INACTIVE_ANON]);
PRINTK("active file %d\n", seg->lruSize[VM_LRU_ACTIVE_FILE]);
diff --git a/kernel/base/vm/los_vm_fault.c b/kernel/base/vm/los_vm_fault.c
old mode 100644
new mode 100755
index 9630cf94..ccc15503
--- a/kernel/base/vm/los_vm_fault.c
+++ b/kernel/base/vm/los_vm_fault.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -56,6 +56,11 @@ extern char __exc_table_end[];
STATIC STATUS_T OsVmRegionRightCheck(LosVmMapRegion *region, UINT32 flags)
{
+ if ((region->regionFlags & VM_MAP_REGION_FLAG_PERM_READ) != VM_MAP_REGION_FLAG_PERM_READ) {
+ VM_ERR("read permission check failed operation flags %x, region flags %x", flags, region->regionFlags);
+ return LOS_NOK;
+ }
+
if ((flags & VM_MAP_PF_FLAG_WRITE) == VM_MAP_PF_FLAG_WRITE) {
if ((region->regionFlags & VM_MAP_REGION_FLAG_PERM_WRITE) != VM_MAP_REGION_FLAG_PERM_WRITE) {
VM_ERR("write permission check failed operation flags %x, region flags %x", flags, region->regionFlags);
@@ -77,10 +82,6 @@ STATIC VOID OsFaultTryFixup(ExcContext *frame, VADDR_T excVaddr, STATUS_T *statu
{
INT32 tableNum = (__exc_table_end - __exc_table_start) / sizeof(LosExcTable);
LosExcTable *excTable = (LosExcTable *)__exc_table_start;
-#ifdef LOSCFG_DEBUG_VERSION
- LosVmSpace *space = NULL;
- VADDR_T vaddr;
-#endif
if ((frame->regCPSR & CPSR_MODE_MASK) != CPSR_MODE_USR) {
for (int i = 0; i < tableNum; ++i, ++excTable) {
@@ -92,14 +93,6 @@ STATIC VOID OsFaultTryFixup(ExcContext *frame, VADDR_T excVaddr, STATUS_T *statu
}
}
}
-
-#ifdef LOSCFG_DEBUG_VERSION
- vaddr = ROUNDDOWN(excVaddr, PAGE_SIZE);
- space = LOS_SpaceGet(vaddr);
- if (space != NULL) {
- LOS_DumpMemRegion(vaddr);
- }
-#endif
}
#ifdef LOSCFG_FS_VFS
@@ -132,7 +125,7 @@ STATIC STATUS_T OsDoReadFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
ret = LOS_ArchMmuMap(&space->archMmu, vaddr, paddr, 1,
region->regionFlags & (~VM_MAP_REGION_FLAG_PERM_WRITE));
if (ret < 0) {
- VM_ERR("LOS_ArchMmuMap fial");
+ VM_ERR("LOS_ArchMmuMap failed");
OsDelMapInfo(region, vmPgFault, false);
(VOID)LOS_MuxRelease(®ion->unTypeData.rf.file->f_mapping->mux_lock);
return LOS_ERRNO_VM_NO_MEMORY;
@@ -235,7 +228,7 @@ status_t OsDoCowFault(LosVmMapRegion *region, LosVmPgFault *vmPgFault)
ret = LOS_ArchMmuMap(&space->archMmu, (VADDR_T)vmPgFault->vaddr, newPaddr, 1, region->regionFlags);
if (ret < 0) {
- VM_ERR("LOS_ArchMmuMap fial");
+ VM_ERR("LOS_ArchMmuMap failed");
ret = LOS_ERRNO_VM_NO_MEMORY;
(VOID)LOS_MuxRelease(®ion->unTypeData.rf.file->f_mapping->mux_lock);
goto ERR_OUT;
diff --git a/kernel/base/vm/los_vm_filemap.c b/kernel/base/vm/los_vm_filemap.c
old mode 100644
new mode 100755
index b4c11d81..ced2e720
--- a/kernel/base/vm/los_vm_filemap.c
+++ b/kernel/base/vm/los_vm_filemap.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -202,7 +202,7 @@ ssize_t OsMappingRead(struct file *filp, char *buf, size_t size)
readSize = MIN2((PAGE_SIZE - offInPage), readLeft);
- (VOID)memcpy_s((VOID *)buf, readLeft, (char *)kvaddr + offInPage, readSize);
+ (VOID)memcpy_s((VOID *)buf, readLeft, (char *)(UINTPTR)kvaddr + offInPage, readSize);
buf += readSize;
readLeft -= readSize;
readTotal += readSize;
@@ -488,7 +488,9 @@ VOID OsDelMapInfo(LosVmMapRegion *region, LosVmPgFault *vmf, BOOL cleanDirty)
fpage->n_maps--;
LOS_ListDelete(&info->node);
LOS_AtomicDec(&fpage->vmPage->refCounts);
+ LOS_SpinUnlockRestore(®ion->unTypeData.rf.file->f_mapping->list_lock, intSave);
LOS_MemFree(m_aucSysMem0, info);
+ return;
}
LOS_SpinUnlockRestore(®ion->unTypeData.rf.file->f_mapping->list_lock, intSave);
}
@@ -520,8 +522,8 @@ INT32 OsVmmFileFault(LosVmMapRegion *region, LosVmPgFault *vmf)
} else {
fpage = OsPageCacheAlloc(mapping, vmf->pgoff);
if (fpage == NULL) {
- VM_ERR("Failed to alloc a page frame");
LOS_SpinUnlockRestore(&mapping->list_lock, intSave);
+ VM_ERR("Failed to alloc a page frame");
return LOS_NOK;
}
newCache = true;
diff --git a/kernel/base/vm/los_vm_iomap.c b/kernel/base/vm/los_vm_iomap.c
index 5f5ffae4..62f5e34c 100644
--- a/kernel/base/vm/los_vm_iomap.c
+++ b/kernel/base/vm/los_vm_iomap.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/vm/los_vm_map.c b/kernel/base/vm/los_vm_map.c
old mode 100644
new mode 100755
index 34709c0d..dcc57acf
--- a/kernel/base/vm/los_vm_map.c
+++ b/kernel/base/vm/los_vm_map.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -43,6 +43,7 @@
#include "fs/fs.h"
#include "los_task.h"
#include "los_memory_pri.h"
+#include "los_vm_boot.h"
#ifdef __cplusplus
#if __cplusplus
@@ -96,7 +97,7 @@ VOID *OsRegionRbGetKeyFn(LosRbNode *pstNode)
return (VOID *)®ion->range;
}
-ULONG_T OsRegionRbCmpKeyFn(VOID *pNodeKeyA, VOID *pNodeKeyB)
+ULONG_T OsRegionRbCmpKeyFn(const VOID *pNodeKeyA, const VOID *pNodeKeyB)
{
LosVmMapRange rangeA = *(LosVmMapRange *)pNodeKeyA;
LosVmMapRange rangeB = *(LosVmMapRange *)pNodeKeyB;
@@ -193,6 +194,34 @@ BOOL OsUserVmSpaceInit(LosVmSpace *vmSpace, VADDR_T *virtTtb)
return OsVmSpaceInitCommon(vmSpace, virtTtb);
}
+LosVmSpace *OsCreateUserVmSapce(VOID)
+{
+ BOOL retVal = FALSE;
+
+ LosVmSpace *space = LOS_MemAlloc(m_aucSysMem0, sizeof(LosVmSpace));
+ if (space == NULL) {
+ return NULL;
+ }
+
+ VADDR_T *ttb = LOS_PhysPagesAllocContiguous(1);
+ if (ttb == NULL) {
+ (VOID)LOS_MemFree(m_aucSysMem0, space);
+ return NULL;
+ }
+
+ (VOID)memset_s(ttb, PAGE_SIZE, 0, PAGE_SIZE);
+ retVal = OsUserVmSpaceInit(space, ttb);
+ LosVmPage *vmPage = OsVmVaddrToPage(ttb);
+ if ((retVal == FALSE) || (vmPage == NULL)) {
+ (VOID)LOS_MemFree(m_aucSysMem0, space);
+ LOS_PhysPagesFreeContiguous(ttb, 1);
+ return NULL;
+ }
+ LOS_ListAdd(&space->archMmu.ptList, &(vmPage->node));
+
+ return space;
+}
+
VOID OsKSpaceInit(VOID)
{
OsVmMapInit();
@@ -270,13 +299,15 @@ STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
if (newRegion == NULL) {
VM_ERR("dup new region failed");
ret = LOS_ERRNO_VM_NO_MEMORY;
- goto ERR_CLONE_ASPACE;
+ break;
}
+#ifdef LOSCFG_KERNEL_SHM
if (oldRegion->regionFlags & VM_MAP_REGION_FLAG_SHM) {
OsShmFork(newVmSpace, oldRegion, newRegion);
continue;
}
+#endif
if (oldRegion == oldVmSpace->heap) {
newVmSpace->heap = newRegion;
@@ -312,12 +343,6 @@ STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace)
#endif
}
RB_SCAN_SAFE_END(&oldVmSpace->regionRbTree, pstRbNode, pstRbNodeNext)
- goto OUT_CLONE_ASPACE;
-ERR_CLONE_ASPACE:
- if (LOS_VmSpaceFree(newVmSpace) != LOS_OK) {
- VM_ERR("LOS_VmSpaceFree failed");
- }
-OUT_CLONE_ASPACE:
(VOID)LOS_MuxRelease(&oldVmSpace->regionMux);
return ret;
}
@@ -365,7 +390,7 @@ VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len)
if (nextStart < curEnd) {
continue;
}
- if ((curEnd + len) <= nextStart) {
+ if ((nextStart - curEnd) >= len) {
return curEnd;
} else {
curEnd = curRegion->range.base + curRegion->range.size;
@@ -379,7 +404,7 @@ VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len)
if (nextStart < curEnd) {
continue;
}
- if ((curEnd + len) <= nextStart) {
+ if ((nextStart - curEnd) >= len) {
return curEnd;
} else {
curEnd = curRegion->range.base + curRegion->range.size;
@@ -388,14 +413,14 @@ VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len)
}
nextStart = vmSpace->mapBase + vmSpace->mapSize;
- if ((curEnd + len) <= nextStart) {
+ if ((nextStart >= curEnd) && ((nextStart - curEnd) >= len)) {
return curEnd;
}
return 0;
}
-VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len)
+VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len, UINT32 regionFlags)
{
STATUS_T status;
@@ -406,10 +431,16 @@ VADDR_T OsAllocSpecificRange(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len)
if ((LOS_RegionFind(vmSpace, vaddr) != NULL) ||
(LOS_RegionFind(vmSpace, vaddr + len - 1) != NULL) ||
(LOS_RegionRangeFind(vmSpace, vaddr, len - 1) != NULL)) {
- status = LOS_UnMMap(vaddr, len);
- if (status != LOS_OK) {
- VM_ERR("unmap specific range va: %#x, len: %#x failed, status: %d", vaddr, len, status);
+ if ((regionFlags & VM_MAP_REGION_FLAG_FIXED_NOREPLACE) != 0) {
return 0;
+ } else if ((regionFlags & VM_MAP_REGION_FLAG_FIXED) != 0) {
+ status = LOS_UnMMap(vaddr, len);
+ if (status != LOS_OK) {
+ VM_ERR("unmap specific range va: %#x, len: %#x failed, status: %d", vaddr, len, status);
+ return 0;
+ }
+ } else {
+ return OsAllocRange(vmSpace, len);
}
}
@@ -499,7 +530,7 @@ LosVmMapRegion *LOS_RegionAlloc(LosVmSpace *vmSpace, VADDR_T vaddr, size_t len,
rstVaddr = OsAllocRange(vmSpace, len);
} else {
/* if it is already mmapped here, we unmmap it */
- rstVaddr = OsAllocSpecificRange(vmSpace, vaddr, len);
+ rstVaddr = OsAllocSpecificRange(vmSpace, vaddr, len, regionFlags);
if (rstVaddr == 0) {
VM_ERR("alloc specific range va: %#x, len: %#x failed", vaddr, len);
goto OUT;
@@ -608,9 +639,14 @@ STATUS_T LOS_RegionFree(LosVmSpace *space, LosVmMapRegion *region)
OsFilePagesRemove(space, region);
} else
#endif
+
+#ifdef LOSCFG_KERNEL_SHM
if (OsIsShmRegion(region)) {
OsShmRegionFree(space, region);
} else if (LOS_IsRegionTypeDev(region)) {
+#else
+ if (LOS_IsRegionTypeDev(region)) {
+#endif
OsDevPagesRemove(&space->archMmu, region->range.base, region->range.size >> PAGE_SHIFT);
} else {
OsAnonPagesRemove(&space->archMmu, region->range.base, region->range.size >> PAGE_SHIFT);
@@ -627,17 +663,27 @@ STATUS_T LOS_RegionFree(LosVmSpace *space, LosVmMapRegion *region)
LosVmMapRegion *OsVmRegionDup(LosVmSpace *space, LosVmMapRegion *oldRegion, VADDR_T vaddr, size_t size)
{
LosVmMapRegion *newRegion = NULL;
+ UINT32 regionFlags;
(VOID)LOS_MuxAcquire(&space->regionMux);
- newRegion = LOS_RegionAlloc(space, vaddr, size, oldRegion->regionFlags, oldRegion->pgOff);
+ regionFlags = oldRegion->regionFlags;
+ if (vaddr == 0) {
+ regionFlags &= ~(VM_MAP_REGION_FLAG_FIXED | VM_MAP_REGION_FLAG_FIXED_NOREPLACE);
+ } else {
+ regionFlags |= VM_MAP_REGION_FLAG_FIXED;
+ }
+ newRegion = LOS_RegionAlloc(space, vaddr, size, regionFlags, oldRegion->pgOff);
if (newRegion == NULL) {
VM_ERR("LOS_RegionAlloc failed");
goto REGIONDUPOUT;
}
newRegion->regionType = oldRegion->regionType;
+
+#ifdef LOSCFG_KERNEL_SHM
if (OsIsShmRegion(oldRegion)) {
newRegion->shmid = oldRegion->shmid;
}
+#endif
#ifdef LOSCFG_FS_VFS
if (LOS_IsRegionTypeFile(oldRegion)) {
@@ -697,6 +743,7 @@ STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T newRegionStart, size_t size
return LOS_ERRNO_VM_NO_MEMORY;
}
}
+
return LOS_OK;
}
@@ -787,7 +834,7 @@ STATUS_T OsIsRegionCanExpand(LosVmSpace *space, LosVmMapRegion *region, size_t s
nextRegion = (LosVmMapRegion *)LOS_RbSuccessorNode(&space->regionRbTree, ®ion->rbNode);
/* if the gap is larger than size, then we can expand */
- if ((nextRegion != NULL) && ((nextRegion->range.base - region->range.base ) >= size)) {
+ if ((nextRegion != NULL) && ((nextRegion->range.base - region->range.base) >= size)) {
return LOS_OK;
}
@@ -885,7 +932,7 @@ BOOL LOS_IsRangeInSpace(const LosVmSpace *space, VADDR_T vaddr, size_t size)
STATUS_T LOS_VmSpaceReserve(LosVmSpace *space, size_t size, VADDR_T vaddr)
{
- uint regionFlags;
+ UINT32 regionFlags = 0;
if ((space == NULL) || (size == 0) || (!IS_PAGE_ALIGNED(vaddr) || !IS_PAGE_ALIGNED(size))) {
return LOS_ERRNO_VM_INVALID_ARGS;
@@ -896,10 +943,10 @@ STATUS_T LOS_VmSpaceReserve(LosVmSpace *space, size_t size, VADDR_T vaddr)
}
/* lookup how it's already mapped */
- LOS_ArchMmuQuery(&space->archMmu, vaddr, NULL, ®ionFlags);
+ (VOID)LOS_ArchMmuQuery(&space->archMmu, vaddr, NULL, ®ionFlags);
/* build a new region structure */
- LosVmMapRegion *region = LOS_RegionAlloc(space, vaddr, size, regionFlags, 0);
+ LosVmMapRegion *region = LOS_RegionAlloc(space, vaddr, size, regionFlags | VM_MAP_REGION_FLAG_FIXED, 0);
return region ? LOS_OK : LOS_ERRNO_VM_NO_MEMORY;
}
@@ -935,6 +982,11 @@ STATUS_T LOS_VaddrToPaddrMmap(LosVmSpace *space, VADDR_T vaddr, PADDR_T paddr, s
while (len > 0) {
vmPage = LOS_VmPageGet(paddr);
+ if (vmPage == NULL) {
+ LOS_RegionFree(space, region);
+ VM_ERR("Page is NULL");
+ return LOS_ERRNO_VM_NOT_VALID;
+ }
LOS_AtomicInc(&vmPage->refCounts);
ret = LOS_ArchMmuMap(&space->archMmu, vaddr, paddr, 1, region->regionFlags);
@@ -1101,14 +1153,15 @@ DONE:
STATIC INLINE BOOL OsMemLargeAlloc(UINT32 size)
{
- UINT32 wasteMem;
-
- if (size < PAGE_SIZE) {
+ if (g_kHeapInited == FALSE) {
return FALSE;
}
- wasteMem = ROUNDUP(size, PAGE_SIZE) - size;
- /* that is 1K ram wasted, waste too much mem ! */
- return (wasteMem < VM_MAP_WASTE_MEM_LEVEL);
+
+ if (size < KMALLOC_LARGE_SIZE) {
+ return FALSE;
+ }
+
+ return TRUE;
}
VOID *LOS_KernelMalloc(UINT32 size)
diff --git a/kernel/base/vm/los_vm_page.c b/kernel/base/vm/los_vm_page.c
old mode 100644
new mode 100755
index 3254e87e..b612b5c2
--- a/kernel/base/vm/los_vm_page.c
+++ b/kernel/base/vm/los_vm_page.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -52,6 +52,7 @@ STATIC VOID OsVmPageInit(LosVmPage *page, paddr_t pa, UINT8 segID)
page->physAddr = pa;
page->segID = segID;
page->order = VM_LIST_ORDER_MAX;
+ page->nPages = 0;
}
STATIC INLINE VOID OsVmPageOrderListInit(LosVmPage *page, size_t nPages)
@@ -59,6 +60,12 @@ STATIC INLINE VOID OsVmPageOrderListInit(LosVmPage *page, size_t nPages)
OsVmPhysPagesFreeContiguous(page, nPages);
}
+#define VMPAGEINIT(page, pa, segID) do { \
+ OsVmPageInit(page, pa, segID); \
+ (page)++; \
+ (pa) += PAGE_SIZE; \
+} while (0)
+
VOID OsVmPageStartup(VOID)
{
struct VmPhysSeg *seg = NULL;
@@ -81,9 +88,22 @@ VOID OsVmPageStartup(VOID)
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
seg = &g_vmPhysSeg[segID];
nPage = seg->size >> PAGE_SHIFT;
- for (page = seg->pageBase, pa = seg->start; page <= seg->pageBase + nPage;
- page++, pa += PAGE_SIZE) {
- OsVmPageInit(page, pa, segID);
+ UINT32 count = nPage >> 3; /* 3: 2 ^ 3, nPage / 8, cycle count */
+ UINT32 left = nPage & 0x7; /* 0x7: nPage % 8, left page */
+
+ for (page = seg->pageBase, pa = seg->start; count > 0; count--) {
+ /* note: process large amount of data, optimize performance */
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ VMPAGEINIT(page, pa, segID);
+ }
+ for (; left > 0; left--) {
+ VMPAGEINIT(page, pa, segID);
}
OsVmPageOrderListInit(seg->pageBase, nPage);
}
diff --git a/kernel/base/vm/los_vm_phys.c b/kernel/base/vm/los_vm_phys.c
old mode 100644
new mode 100755
index 88f505a5..afb70520
--- a/kernel/base/vm/los_vm_phys.c
+++ b/kernel/base/vm/los_vm_phys.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -96,7 +96,7 @@ VOID OsVmPhysSegAdd(VOID)
{
INT32 i, ret;
- LOS_ASSERT(g_vmPhysSegNum <= VM_PHYS_SEG_MAX);
+ LOS_ASSERT(g_vmPhysSegNum < VM_PHYS_SEG_MAX);
for (i = 0; i < (sizeof(g_physArea) / sizeof(g_physArea[0])); i++) {
ret = OsVmPhysSegCreate(g_physArea[i].start, g_physArea[i].size);
@@ -280,17 +280,59 @@ LosVmPage *OsVmVaddrToPage(VOID *ptr)
return NULL;
}
-LosVmPage *OsVmPhysPagesAlloc(struct VmPhysSeg *seg, size_t nPages)
+STATIC INLINE VOID OsVmRecycleExtraPages(LosVmPage *page, size_t startPage, size_t endPage)
+{
+ if (startPage >= endPage) {
+ return;
+ }
+
+ OsVmPhysPagesFreeContiguous(page, endPage - startPage);
+}
+
+STATIC LosVmPage *OsVmPhysLargeAlloc(struct VmPhysSeg *seg, size_t nPages)
{
struct VmFreeList *list = NULL;
LosVmPage *page = NULL;
+ LosVmPage *tmp = NULL;
+ PADDR_T paStart;
+ PADDR_T paEnd;
+ size_t size = nPages << PAGE_SHIFT;
+
+ list = &seg->freeList[VM_LIST_ORDER_MAX - 1];
+ LOS_DL_LIST_FOR_EACH_ENTRY(page, &list->node, LosVmPage, node) {
+ paStart = page->physAddr;
+ paEnd = paStart + size;
+ if (paEnd > (seg->start + seg->size)) {
+ continue;
+ }
+
+ for (;;) {
+ paStart += PAGE_SIZE << (VM_LIST_ORDER_MAX - 1);
+ if ((paStart >= paEnd) || (paStart < seg->start) ||
+ (paStart >= (seg->start + seg->size))) {
+ break;
+ }
+ tmp = &seg->pageBase[(paStart - seg->start) >> PAGE_SHIFT];
+ if (tmp->order != (VM_LIST_ORDER_MAX - 1)) {
+ break;
+ }
+ }
+ if (paStart >= paEnd) {
+ return page;
+ }
+ }
+
+ return NULL;
+}
+
+STATIC LosVmPage *OsVmPhysPagesAlloc(struct VmPhysSeg *seg, size_t nPages)
+{
+ struct VmFreeList *list = NULL;
+ LosVmPage *page = NULL;
+ LosVmPage *tmp = NULL;
UINT32 order;
UINT32 newOrder;
- if ((seg == NULL) || (nPages == 0)) {
- return NULL;
- }
-
order = OsVmPagesToOrder(nPages);
if (order < VM_LIST_ORDER_MAX) {
for (newOrder = order; newOrder < VM_LIST_ORDER_MAX; newOrder++) {
@@ -301,11 +343,22 @@ LosVmPage *OsVmPhysPagesAlloc(struct VmPhysSeg *seg, size_t nPages)
page = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&list->node), LosVmPage, node);
goto DONE;
}
+ } else {
+ newOrder = VM_LIST_ORDER_MAX - 1;
+ page = OsVmPhysLargeAlloc(seg, nPages);
+ if (page != NULL) {
+ goto DONE;
+ }
}
return NULL;
DONE:
- OsVmPhysFreeListDelUnsafe(page);
+
+ for (tmp = page; tmp < &page[nPages]; tmp = &tmp[1 << newOrder]) {
+ OsVmPhysFreeListDelUnsafe(tmp);
+ }
OsVmPhysPagesSpiltUnsafe(page, order, newOrder);
+ OsVmRecycleExtraPages(&page[nPages], nPages, ROUNDUP(nPages, (1 << min(order, newOrder))));
+
return page;
}
@@ -339,7 +392,7 @@ VOID OsVmPhysPagesFree(LosVmPage *page, UINT8 order)
VOID OsVmPhysPagesFreeContiguous(LosVmPage *page, size_t nPages)
{
paddr_t pa;
- UINT32 order;
+ UINT32 order;
size_t n;
while (TRUE) {
@@ -370,10 +423,6 @@ STATIC LosVmPage *OsVmPhysPagesGet(size_t nPages)
LosVmPage *page = NULL;
UINT32 segID;
- if (nPages == 0) {
- return NULL;
- }
-
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
seg = &g_vmPhysSeg[segID];
LOS_SpinLockSave(&seg->freeListLock, &intSave);
diff --git a/kernel/base/vm/los_vm_scan.c b/kernel/base/vm/los_vm_scan.c
old mode 100644
new mode 100755
index 38277254..8855f4bf
--- a/kernel/base/vm/los_vm_scan.c
+++ b/kernel/base/vm/los_vm_scan.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/base/vm/los_vm_syscall.c b/kernel/base/vm/los_vm_syscall.c
old mode 100644
new mode 100755
index 20e90539..d79535e6
--- a/kernel/base/vm/los_vm_syscall.c
+++ b/kernel/base/vm/los_vm_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -50,20 +50,24 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-STATUS_T OsCheckMMapParams(VADDR_T vaddr, unsigned prot, unsigned long flags, size_t len, unsigned long pgoff)
+STATUS_T OsCheckMMapParams(VADDR_T *vaddr, unsigned long flags, size_t len, unsigned long pgoff)
{
- if ((vaddr != 0) && !LOS_IsUserAddressRange(vaddr, len)) {
+ if ((len == 0) || (len > USER_ASPACE_SIZE)) {
+ return -EINVAL;
+ }
+ if (len > OsCurrProcessGet()->vmSpace->mapSize) {
+ return -ENOMEM;
+ }
+
+ if (((flags & MAP_FIXED) == 0) && ((flags & MAP_FIXED_NOREPLACE) == 0)) {
+ *vaddr = ROUNDUP(*vaddr, PAGE_SIZE);
+ if ((*vaddr != 0) && (!LOS_IsUserAddressRange(*vaddr, len))) {
+ *vaddr = 0;
+ }
+ } else if ((!LOS_IsUserAddressRange(*vaddr, len)) || (!IS_ALIGNED(*vaddr, PAGE_SIZE))) {
return -EINVAL;
}
- if (len == 0) {
- return -EINVAL;
- }
-
- /* we only support some prot and flags */
- if ((prot & PROT_SUPPORT_MASK) == 0) {
- return -EINVAL;
- }
if ((flags & MAP_SUPPORT_MASK) == 0) {
return -EINVAL;
}
@@ -78,6 +82,23 @@ STATUS_T OsCheckMMapParams(VADDR_T vaddr, unsigned prot, unsigned long flags, si
return LOS_OK;
}
+STATUS_T OsNamedMmapingPermCheck(struct file *filep, unsigned long flags, unsigned prot)
+{
+ if (!((unsigned int)filep->f_oflags & O_RDWR) && (((unsigned int)filep->f_oflags & O_ACCMODE) ^ O_RDONLY)) {
+ return -EACCES;
+ }
+ if (flags & MAP_SHARED) {
+ if (((unsigned int)filep->f_oflags & O_APPEND) && (prot & PROT_WRITE)) {
+ return -EACCES;
+ }
+ if ((prot & PROT_WRITE) && !((unsigned int)filep->f_oflags & O_RDWR)) {
+ return -EACCES;
+ }
+ }
+
+ return LOS_OK;
+}
+
STATUS_T OsAnonMMap(LosVmMapRegion *region)
{
LOS_SetRegionTypeAnon(region);
@@ -93,9 +114,8 @@ VADDR_T LOS_MMap(VADDR_T vaddr, size_t len, unsigned prot, unsigned long flags,
struct file *filep = NULL;
LosVmSpace *vmSpace = OsCurrProcessGet()->vmSpace;
- vaddr = ROUNDUP(vaddr, PAGE_SIZE);
len = ROUNDUP(len, PAGE_SIZE);
- STATUS_T checkRst = OsCheckMMapParams(vaddr, prot, flags, len, pgoff);
+ STATUS_T checkRst = OsCheckMMapParams(&vaddr, flags, len, pgoff);
if (checkRst != LOS_OK) {
return checkRst;
}
@@ -105,6 +125,11 @@ VADDR_T LOS_MMap(VADDR_T vaddr, size_t len, unsigned prot, unsigned long flags,
if (status < 0) {
return -EBADF;
}
+
+ status = OsNamedMmapingPermCheck(filep, flags, prot);
+ if (status < 0) {
+ return status;
+ }
}
(VOID)LOS_MuxAcquire(&vmSpace->regionMux);
@@ -151,6 +176,33 @@ STATUS_T LOS_UnMMap(VADDR_T addr, size_t size)
return OsUnMMap(OsCurrProcessGet()->vmSpace, addr, size);
}
+STATIC INLINE BOOL OsProtMprotectPermCheck(unsigned long prot, LosVmMapRegion *region)
+{
+ UINT32 protFlags = 0;
+ UINT32 permFlags = 0;
+ UINT32 fileFlags = (((region->unTypeData).rf).file)->f_oflags;
+ permFlags |= ((fileFlags & O_ACCMODE) ^ O_RDONLY) ? 0 : VM_MAP_REGION_FLAG_PERM_READ;
+ permFlags |= (fileFlags & O_WRONLY) ? VM_MAP_REGION_FLAG_PERM_WRITE : 0;
+ permFlags |= (fileFlags & O_RDWR) ? (VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE) : 0;
+ protFlags |= (prot & PROT_READ) ? VM_MAP_REGION_FLAG_PERM_READ : 0;
+ protFlags |= (prot & PROT_WRITE) ? VM_MAP_REGION_FLAG_PERM_WRITE : 0;
+
+ return ((protFlags & permFlags) == protFlags);
+}
+
+VOID *OsShrinkHeap(VOID *addr, LosVmSpace *space)
+{
+ VADDR_T newBrk, oldBrk;
+
+ newBrk = LOS_Align((VADDR_T)(UINTPTR)addr, PAGE_SIZE);
+ oldBrk = LOS_Align(space->heapNow, PAGE_SIZE);
+ if (LOS_UnMMap(newBrk, (oldBrk - newBrk)) < 0) {
+ return (void *)(UINTPTR)space->heapNow;
+ }
+ space->heapNow = (VADDR_T)(UINTPTR)addr;
+ return addr;
+}
+
VOID *LOS_DoBrk(VOID *addr)
{
LosVmSpace *space = OsCurrProcessGet()->vmSpace;
@@ -158,7 +210,7 @@ VOID *LOS_DoBrk(VOID *addr)
VOID *ret = NULL;
LosVmMapRegion *region = NULL;
VOID *alignAddr = NULL;
- VADDR_T newBrk, oldBrk;
+ VOID *shrinkAddr = NULL;
if (addr == NULL) {
return (void *)(UINTPTR)space->heapNow;
@@ -173,26 +225,23 @@ VOID *LOS_DoBrk(VOID *addr)
alignAddr = (CHAR *)(UINTPTR)(space->heapBase) + size;
PRINT_INFO("brk addr %p , size 0x%x, alignAddr %p, align %d\n", addr, size, alignAddr, PAGE_SIZE);
+ (VOID)LOS_MuxAcquire(&space->regionMux);
if (addr < (VOID *)(UINTPTR)space->heapNow) {
- newBrk = LOS_Align((VADDR_T)(UINTPTR)addr, PAGE_SIZE);
- oldBrk = LOS_Align(space->heapNow, PAGE_SIZE);
- if (LOS_UnMMap(newBrk, (oldBrk - newBrk)) < 0) {
- return (void *)(UINTPTR)space->heapNow;
- }
- space->heapNow = (VADDR_T)(UINTPTR)alignAddr;
- return alignAddr;
+ shrinkAddr = OsShrinkHeap(addr, space);
+ (VOID)LOS_MuxRelease(&space->regionMux);
+ return shrinkAddr;
}
- (VOID)LOS_MuxAcquire(&space->regionMux);
if ((UINTPTR)alignAddr >= space->mapBase) {
VM_ERR("Process heap memory space is insufficient");
ret = (VOID *)-ENOMEM;
goto REGION_ALLOC_FAILED;
}
+
if (space->heapBase == space->heapNow) {
region = LOS_RegionAlloc(space, space->heapBase, size,
VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
- VM_MAP_REGION_FLAG_PERM_USER, 0);
+ VM_MAP_REGION_FLAG_FIXED | VM_MAP_REGION_FLAG_PERM_USER, 0);
if (region == NULL) {
ret = (VOID *)-ENOMEM;
VM_ERR("LOS_RegionAlloc failed");
@@ -231,6 +280,18 @@ int LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot)
goto OUT_MPROTECT;
}
+ if ((region->regionFlags & VM_MAP_REGION_FLAG_VDSO) || (region->regionFlags & VM_MAP_REGION_FLAG_HEAP)) {
+ ret = -EPERM;
+ goto OUT_MPROTECT;
+ }
+
+ if (LOS_IsRegionTypeFile(region) && (region->regionFlags & VM_MAP_REGION_FLAG_SHARED)) {
+ if (!OsProtMprotectPermCheck(prot, region)) {
+ ret = -EACCES;
+ goto OUT_MPROTECT;
+ }
+ }
+
len = LOS_Align(len, PAGE_SIZE);
/* can't operation cross region */
if (region->range.base + region->range.size < vaddr + len) {
diff --git a/kernel/base/vm/oom.c b/kernel/base/vm/oom.c
old mode 100644
new mode 100755
index f3e757b1..c5e5c0e3
--- a/kernel/base/vm/oom.c
+++ b/kernel/base/vm/oom.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -136,12 +136,16 @@ LITE_OS_SEC_TEXT_MINOR BOOL OomCheckProcess(VOID)
/* first we will check if we need to reclaim pagecache memory */
if (OomReclaimPageCache() == FALSE) {
+ LOS_SpinUnlock(&g_oomSpinLock);
goto NO_VICTIM_PROCESS;
}
/* get free bytes */
OsVmPhysUsedInfoGet(&usedPm, &totalPm);
isLowMemory = ((totalPm - usedPm) << PAGE_SHIFT) < g_oomCB->lowMemThreshold;
+
+ LOS_SpinUnlock(&g_oomSpinLock);
+
if (isLowMemory) {
PRINTK("[oom] OS is in low memory state\n"
"total physical memory: %#x(byte), used: %#x(byte),"
@@ -151,7 +155,6 @@ LITE_OS_SEC_TEXT_MINOR BOOL OomCheckProcess(VOID)
}
NO_VICTIM_PROCESS:
- LOS_SpinUnlock(&g_oomSpinLock);
return isLowMemory;
}
diff --git a/kernel/base/vm/shm.c b/kernel/base/vm/shm.c
old mode 100644
new mode 100755
index 4f63799c..f5c5e3a9
--- a/kernel/base/vm/shm.c
+++ b/kernel/base/vm/shm.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -45,6 +45,10 @@
#include "los_process.h"
#include "los_process_pri.h"
#include "user_copy.h"
+#ifdef LOSCFG_SHELL
+#include "shcmd.h"
+#include "shell.h"
+#endif
#ifdef __cplusplus
#if __cplusplus
@@ -52,13 +56,16 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
+#ifdef LOSCFG_KERNEL_SHM
+
STATIC LosMux g_sysvShmMux;
/* private macro */
#define SYSV_SHM_LOCK() (VOID)LOS_MuxLock(&g_sysvShmMux, LOS_WAIT_FOREVER)
#define SYSV_SHM_UNLOCK() (VOID)LOS_MuxUnlock(&g_sysvShmMux)
-#define SHM_MAX_PAGES 12800
+/* The upper limit size of total shared memory is default 16M */
+#define SHM_MAX_PAGES 4096
#define SHM_MAX (SHM_MAX_PAGES * PAGE_SIZE)
#define SHM_MIN 1
#define SHM_MNI 192
@@ -73,23 +80,28 @@ STATIC LosMux g_sysvShmMux;
#define SHM_M 010000
#endif
+#ifndef SHM_X
+#define SHM_X 0100
+#endif
+
#ifndef ACCESSPERMS
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
#endif
+#define SHM_S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
+#define SHM_S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
+#define SHM_S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
+
#define SHM_GROUPE_TO_USER 3
#define SHM_OTHER_TO_USER 6
-/* private structure */
-struct shmSegMap {
- vaddr_t vaddr;
- INT32 shmID;
-};
-
struct shmIDSource {
struct shmid_ds ds;
UINT32 status;
LOS_DL_LIST node;
+#ifdef LOSCFG_SHELL
+ CHAR ownerName[OS_PCB_NAME_LEN];
+#endif
};
/* private data */
@@ -102,6 +114,7 @@ STATIC struct shminfo g_shmInfo = {
};
STATIC struct shmIDSource *g_shmSegs = NULL;
+STATIC UINT32 g_shmUsedPageCount;
INT32 ShmInit(VOID)
{
@@ -126,6 +139,7 @@ INT32 ShmInit(VOID)
g_shmSegs[i].ds.shm_perm.seq = i + 1;
LOS_ListInit(&g_shmSegs[i].node);
}
+ g_shmUsedPageCount = 0;
return 0;
}
@@ -172,7 +186,7 @@ STATIC VOID ShmPagesRefDec(struct shmIDSource *seg)
}
}
-STATIC INT32 ShmAllocSeg(key_t key, size_t size, int shmflg)
+STATIC INT32 ShmAllocSeg(key_t key, size_t size, INT32 shmflg)
{
INT32 i;
INT32 segNum = -1;
@@ -184,6 +198,9 @@ STATIC INT32 ShmAllocSeg(key_t key, size_t size, int shmflg)
return -EINVAL;
}
size = LOS_Align(size, PAGE_SIZE);
+ if ((g_shmUsedPageCount + (size >> PAGE_SHIFT)) > g_shmInfo.shmall) {
+ return -ENOMEM;
+ }
for (i = 0; i < g_shmInfo.shmmni; i++) {
if (g_shmSegs[i].status & SHM_SEG_FREE) {
@@ -205,9 +222,10 @@ STATIC INT32 ShmAllocSeg(key_t key, size_t size, int shmflg)
return -ENOMEM;
}
ShmSetSharedFlag(seg);
+ g_shmUsedPageCount += size >> PAGE_SHIFT;
seg->status |= SHM_SEG_USED;
- seg->ds.shm_perm.mode = (unsigned int)shmflg & ACCESSPERMS;
+ seg->ds.shm_perm.mode = (UINT32)shmflg & ACCESSPERMS;
seg->ds.shm_perm.key = key;
seg->ds.shm_segsz = size;
seg->ds.shm_perm.cuid = LOS_GetUserID();
@@ -220,6 +238,9 @@ STATIC INT32 ShmAllocSeg(key_t key, size_t size, int shmflg)
seg->ds.shm_atime = 0;
seg->ds.shm_dtime = 0;
seg->ds.shm_ctime = time(NULL);
+#ifdef LOSCFG_SHELL
+ (VOID)memcpy_s(seg->ownerName, OS_PCB_NAME_LEN, OsCurrProcessGet()->processName, OS_PCB_NAME_LEN);
+#endif
return segNum;
}
@@ -234,7 +255,7 @@ STATIC INLINE VOID ShmFreeSeg(struct shmIDSource *seg)
VM_ERR("free physical pages failed, count = %d, size = %d", count, seg->ds.shm_segsz >> PAGE_SHIFT);
return;
}
-
+ g_shmUsedPageCount -= seg->ds.shm_segsz >> PAGE_SHIFT;
seg->status = SHM_SEG_FREE;
LOS_ListInit(&seg->node);
}
@@ -255,7 +276,7 @@ STATIC INT32 ShmFindSegByKey(key_t key)
return -1;
}
-STATIC INT32 ShmSegValidCheck(INT32 segNum, size_t size, int shmFalg)
+STATIC INT32 ShmSegValidCheck(INT32 segNum, size_t size, INT32 shmFlg)
{
struct shmIDSource *seg = &g_shmSegs[segNum];
@@ -263,7 +284,7 @@ STATIC INT32 ShmSegValidCheck(INT32 segNum, size_t size, int shmFalg)
return -EINVAL;
}
- if ((shmFalg & (IPC_CREAT | IPC_EXCL)) ==
+ if (((UINT32)shmFlg & (IPC_CREAT | IPC_EXCL)) ==
(IPC_CREAT | IPC_EXCL)) {
return -EEXIST;
}
@@ -344,7 +365,7 @@ VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region)
ShmFreeSeg(seg);
} else {
seg->ds.shm_dtime = time(NULL);
- seg->ds.shm_lpid = LOS_GetCurrProcessID();/* may not be the space's PID. */
+ seg->ds.shm_lpid = LOS_GetCurrProcessID(); /* may not be the space's PID. */
}
SYSV_SHM_UNLOCK();
}
@@ -396,12 +417,17 @@ STATIC INT32 ShmPermCheck(struct shmIDSource *seg, mode_t mode)
tmpMode |= SHM_W;
}
- if ((mode == SHM_M) && (tmpMode & SHM_M)) {
- return 0;
+ if (privMode & SHM_X) {
+ tmpMode |= SHM_X;
}
- tmpMode &= ~SHM_M;
- if ((tmpMode & mode) == accMode) {
+ if ((mode == SHM_M) && (tmpMode & SHM_M)) {
+ return 0;
+ } else if (mode == SHM_M) {
+ return EACCES;
+ }
+
+ if ((tmpMode & accMode) == accMode) {
return 0;
} else {
return EACCES;
@@ -414,21 +440,18 @@ INT32 ShmGet(key_t key, size_t size, INT32 shmflg)
INT32 shmid;
SYSV_SHM_LOCK();
- if ((((UINT32)shmflg & IPC_CREAT) == 0) &&
- (((UINT32)shmflg & IPC_EXCL) == 1)) {
+ if (!((UINT32)shmflg & IPC_CREAT) &&
+ ((UINT32)shmflg & IPC_EXCL)) {
ret = -EINVAL;
goto ERROR;
}
if (key == IPC_PRIVATE) {
ret = ShmAllocSeg(key, size, shmflg);
- if (ret < 0) {
- goto ERROR;
- }
} else {
ret = ShmFindSegByKey(key);
if (ret < 0) {
- if (((unsigned int)shmflg & IPC_CREAT) == 0) {
+ if (((UINT32)shmflg & IPC_CREAT) == 0) {
ret = -ENOENT;
goto ERROR;
} else {
@@ -436,7 +459,7 @@ INT32 ShmGet(key_t key, size_t size, INT32 shmflg)
}
} else {
shmid = ret;
- ret = ShmPermCheck(ShmFindSeg(shmid), (unsigned int)shmflg & ACCESSPERMS);
+ ret = ShmPermCheck(ShmFindSeg(shmid), (UINT32)shmflg & ACCESSPERMS);
if (ret != 0) {
ret = -ret;
goto ERROR;
@@ -458,14 +481,14 @@ ERROR:
return -1;
}
-INT32 ShmatParamCheck(const void *shmaddr, int shmflg)
+INT32 ShmatParamCheck(const VOID *shmaddr, INT32 shmflg)
{
- if ((shmflg & SHM_REMAP) && (shmaddr == NULL)) {
+ if (((UINT32)shmflg & SHM_REMAP) && (shmaddr == NULL)) {
return EINVAL;
}
if ((shmaddr != NULL) && !IS_PAGE_ALIGNED(shmaddr) &&
- ((shmflg & SHM_RND) == 0)) {
+ (((UINT32)shmflg & SHM_RND) == 0)) {
return EINVAL;
}
@@ -477,28 +500,32 @@ LosVmMapRegion *ShmatVmmAlloc(struct shmIDSource *seg, const VOID *shmaddr,
{
LosVmSpace *space = OsCurrProcessGet()->vmSpace;
LosVmMapRegion *region = NULL;
+ UINT32 flags = MAP_ANONYMOUS | MAP_SHARED;
+ UINT32 mapFlags = flags | MAP_FIXED;
VADDR_T vaddr;
UINT32 regionFlags;
INT32 ret;
- regionFlags = OsCvtProtFlagsToRegionFlags(prot, MAP_ANONYMOUS | MAP_SHARED);
+ if (shmaddr != NULL) {
+ flags |= MAP_FIXED_NOREPLACE;
+ }
+ regionFlags = OsCvtProtFlagsToRegionFlags(prot, flags);
(VOID)LOS_MuxAcquire(&space->regionMux);
if (shmaddr == NULL) {
region = LOS_RegionAlloc(space, 0, seg->ds.shm_segsz, regionFlags, 0);
} else {
- if (shmflg & SHM_RND) {
+ if ((UINT32)shmflg & SHM_RND) {
vaddr = ROUNDDOWN((VADDR_T)(UINTPTR)shmaddr, SHMLBA);
} else {
vaddr = (VADDR_T)(UINTPTR)shmaddr;
}
- if (!(shmflg & SHM_REMAP) && (LOS_RegionFind(space, vaddr) ||
- LOS_RegionFind(space, vaddr + seg->ds.shm_segsz - 1) ||
- LOS_RegionRangeFind(space, vaddr, seg->ds.shm_segsz - 1))) {
+ if (!((UINT32)shmflg & SHM_REMAP) && (LOS_RegionFind(space, vaddr) ||
+ LOS_RegionFind(space, vaddr + seg->ds.shm_segsz - 1) ||
+ LOS_RegionRangeFind(space, vaddr, seg->ds.shm_segsz - 1))) {
ret = EINVAL;
goto ERROR;
}
- vaddr = (VADDR_T)LOS_MMap(vaddr, seg->ds.shm_segsz, prot,
- MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+ vaddr = (VADDR_T)LOS_MMap(vaddr, seg->ds.shm_segsz, prot, mapFlags, -1, 0);
region = LOS_RegionFind(space, vaddr);
}
@@ -519,9 +546,9 @@ VOID *ShmAt(INT32 shmid, const VOID *shmaddr, INT32 shmflg)
{
INT32 ret;
UINT32 prot = PROT_READ;
+ mode_t acc_mode = SHM_S_IRUGO;
struct shmIDSource *seg = NULL;
LosVmMapRegion *r = NULL;
- mode_t mode;
ret = ShmatParamCheck(shmaddr, shmflg);
if (ret != 0) {
@@ -531,8 +558,10 @@ VOID *ShmAt(INT32 shmid, const VOID *shmaddr, INT32 shmflg)
if ((UINT32)shmflg & SHM_EXEC) {
prot |= PROT_EXEC;
+ acc_mode |= SHM_S_IXUGO;
} else if (((UINT32)shmflg & SHM_RDONLY) == 0) {
prot |= PROT_WRITE;
+ acc_mode |= SHM_S_IWUGO;
}
SYSV_SHM_LOCK();
@@ -542,8 +571,7 @@ VOID *ShmAt(INT32 shmid, const VOID *shmaddr, INT32 shmflg)
return (VOID *)-1;
}
- mode = ((unsigned int)shmflg & SHM_RDONLY) ? SHM_R : (SHM_R | SHM_W);
- ret = ShmPermCheck(seg, mode);
+ ret = ShmPermCheck(seg, acc_mode);
if (ret != 0) {
goto ERROR;
}
@@ -597,7 +625,7 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
switch (cmd) {
case IPC_STAT:
case SHM_STAT:
- ret = ShmPermCheck(seg, SHM_R);
+ ret = ShmPermCheck(seg, SHM_S_IRUGO);
if (ret != 0) {
goto ERROR;
}
@@ -628,6 +656,10 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
seg->ds.shm_perm.mode = (seg->ds.shm_perm.mode & ~ACCESSPERMS) |
(shm_perm.mode & ACCESSPERMS);
seg->ds.shm_ctime = time(NULL);
+#ifdef LOSCFG_SHELL
+ (VOID)memcpy_s(seg->ownerName, OS_PCB_NAME_LEN, OS_PCB_FROM_PID(shm_perm.uid)->processName,
+ OS_PCB_NAME_LEN);
+#endif
break;
case IPC_RMID:
ret = ShmPermCheck(seg, SHM_M);
@@ -740,6 +772,92 @@ ERROR:
return -1;
}
+#ifdef LOSCFG_SHELL
+STATIC VOID OsShmInfoCmd(VOID)
+{
+ INT32 i;
+ struct shmIDSource *seg = NULL;
+
+ PRINTK("\r\n------- Shared Memory Segments -------\n");
+ PRINTK("key shmid perms bytes nattch status owner\n");
+ SYSV_SHM_LOCK();
+ for (i = 0; i < g_shmInfo.shmmni; i++) {
+ seg = &g_shmSegs[i];
+ if (!(seg->status & SHM_SEG_USED)) {
+ continue;
+ }
+ PRINTK("%08x %-8d %-10o %-10u %-10u %-10x %s\n", seg->ds.shm_perm.key,
+ i, seg->ds.shm_perm.mode, seg->ds.shm_segsz, seg->ds.shm_nattch,
+ seg->status, seg->ownerName);
+
+ }
+ SYSV_SHM_UNLOCK();
+}
+
+STATIC VOID OsShmDeleteCmd(INT32 shmid)
+{
+ struct shmIDSource *seg = NULL;
+
+ if ((shmid < 0) || (shmid >= g_shmInfo.shmmni)) {
+ PRINT_ERR("shmid is invalid: %d\n", shmid);
+ return;
+ }
+
+ SYSV_SHM_LOCK();
+ seg = ShmFindSeg(shmid);
+ if (seg == NULL) {
+ SYSV_SHM_UNLOCK();
+ return;
+ }
+
+ if (seg->ds.shm_nattch <= 0) {
+ ShmFreeSeg(seg);
+ }
+ SYSV_SHM_UNLOCK();
+}
+
+STATIC VOID OsShmCmdUsage(VOID)
+{
+ PRINTK("\tnone option, print shm usage info\n"
+ "\t-r [shmid], Recycle the specified shared memory about shmid\n"
+ "\t-h | --help, print shm command usage\n");
+}
+
+UINT32 OsShellCmdShm(INT32 argc, const CHAR *argv[])
+{
+ INT32 shmid;
+ CHAR *endPtr = NULL;
+
+ if (argc == 0) {
+ OsShmInfoCmd();
+ } else if (argc == 1) {
+ if ((strcmp(argv[0], "-h") != 0) && (strcmp(argv[0], "--help") != 0)) {
+ PRINTK("Invalid option: %s\n", argv[0]);
+ }
+ OsShmCmdUsage();
+ } else if (argc == 2) { /* 2: two parameter */
+ if (strcmp(argv[0], "-r") != 0) {
+ PRINTK("Invalid option: %s\n", argv[0]);
+ goto DONE;
+ }
+ shmid = strtoul((CHAR *)argv[1], &endPtr, 0);
+ if ((endPtr == NULL) || (*endPtr != 0)) {
+ PRINTK("check shmid %s(us) invalid\n", argv[1]);
+ goto DONE;
+ }
+ /* try to delete shm about shmid */
+ OsShmDeleteCmd(shmid);
+ }
+ return 0;
+DONE:
+ OsShmCmdUsage();
+ return -1;
+}
+
+SHELLCMD_ENTRY(shm_shellcmd, CMD_TYPE_SHOW, "shm", 2, (CmdCallBackFunc)OsShellCmdShm);
+#endif
+#endif
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/common/Kconfig b/kernel/common/Kconfig
old mode 100644
new mode 100755
index 2e1b2e7c..66af51a1
--- a/kernel/common/Kconfig
+++ b/kernel/common/Kconfig
@@ -4,3 +4,32 @@ config PLATFORM_ROOTFS
depends on FS_JFFS || FS_FAT
help
Answer Y to enable LiteOS support rootfs.
+
+choice
+ prompt "Storage device type"
+ default STORAGE_SPINOR
+ depends on PLATFORM_ROOTFS
+ help
+ SPI_NOR or SPI_NAND or EMMC.
+
+config STORAGE_SPINOR
+ depends on PLATFORM_ROOTFS && DRIVERS_MTD_SPI_NOR
+ bool "SPI_NOR Flash"
+
+config STORAGE_SPINAND
+ depends on PLATFORM_ROOTFS && DRIVERS_MTD_NAND
+ bool "SPI_NAND Flash"
+
+config STORAGE_EMMC
+ depends on PLATFORM_ROOTFS && DRIVERS_EMMC
+ bool "EMMC"
+
+endchoice
+
+config BOOTENV_ADDR
+ int "Address of boot command line (KB)"
+ depends on PLATFORM_ROOTFS
+ range 0 1024
+ default 512
+ help
+ Boot command line addr, range from 0 to 1MB.
diff --git a/kernel/common/Makefile b/kernel/common/Makefile
old mode 100644
new mode 100755
index b7db9ad7..4e83d558
--- a/kernel/common/Makefile
+++ b/kernel/common/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/common/console.c b/kernel/common/console.c
old mode 100644
new mode 100755
index 24ad7b09..ce5a7fe3
--- a/kernel/common/console.c
+++ b/kernel/common/console.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -47,6 +47,7 @@
#endif
#include "los_exc_pri.h"
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#include "user_copy.h"
#ifdef __cplusplus
#if __cplusplus
@@ -451,7 +452,9 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
{
if ((readcount == EACH_CHAR) && (consoleCB->fifoIn <= (CONSOLE_FIFO_SIZE - 3))) {
if (ch == '\b') {
- consoleCB->fifo[--consoleCB->fifoIn] = '\0';
+ if (!ConsoleFifoEmpty(consoleCB)) {
+ consoleCB->fifo[--consoleCB->fifoIn] = '\0';
+ }
} else {
consoleCB->fifo[consoleCB->fifoIn] = (UINT8)ch;
consoleCB->fifoIn++;
@@ -685,11 +688,15 @@ STATIC ssize_t ConsoleRead(struct file *filep, CHAR *buffer, size_t bufLen)
BOOL userBuf = FALSE;
const struct file_operations_vfs *fileOps = NULL;
- if ((buffer == NULL) || (bufLen == 0) || (bufLen > CONSOLE_FIFO_SIZE)) {
+ if ((buffer == NULL) || (bufLen == 0)) {
ret = EINVAL;
goto ERROUT;
}
+ if (bufLen > CONSOLE_FIFO_SIZE) {
+ bufLen = CONSOLE_FIFO_SIZE;
+ }
+
userBuf = LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buffer, bufLen);
ret = GetFilepOps(filep, &privFilep, &fileOps);
if (ret != ENOERR) {
@@ -740,34 +747,38 @@ ERROUT:
STATIC ssize_t DoWrite(CirBufSendCB *cirBufSendCB, CHAR *buffer, size_t bufLen)
{
- INT32 cnt = 0;
+ INT32 cnt;
+ size_t writen = 0;
+ size_t toWrite = bufLen;
UINT32 intSave;
#ifdef LOSCFG_SHELL_DMESG
(VOID)OsLogMemcpyRecord(buffer, bufLen);
- if (!OsCheckConsoleLock()) {
+ if (OsCheckConsoleLock()) {
+ return 0;
+ }
#endif
LOS_CirBufLock(&cirBufSendCB->cirBufCB, &intSave);
- while (cnt < (INT32)bufLen) {
- if ((buffer[cnt] == '\n') || (buffer[cnt] == '\r')) {
+ while (writen < (INT32)bufLen) {
+ /* Transform for CR/LR mode */
+ if ((buffer[writen] == '\n') || (buffer[writen] == '\r')) {
(VOID)LOS_CirBufWrite(&cirBufSendCB->cirBufCB, "\r", 1);
- (VOID)LOS_CirBufWrite(&cirBufSendCB->cirBufCB, &buffer[cnt], 1);
- cnt++;
- continue;
}
- (VOID)LOS_CirBufWrite(&cirBufSendCB->cirBufCB, &buffer[cnt], 1);
- cnt++;
+
+ cnt = LOS_CirBufWrite(&cirBufSendCB->cirBufCB, &buffer[writen], 1);
+ if (cnt <= 0) {
+ break;
+ }
+ toWrite -= cnt;
+ writen += cnt;
}
LOS_CirBufUnlock(&cirBufSendCB->cirBufCB, intSave);
/* Log is cached but not printed when a system exception occurs */
if (OsGetSystemStatus() == OS_SYSTEM_NORMAL) {
(VOID)LOS_EventWrite(&cirBufSendCB->sendEvent, CONSOLE_CIRBUF_EVENT);
}
-#ifdef LOSCFG_SHELL_DMESG
- }
-#endif
- return cnt;
+ return writen;
}
STATIC ssize_t ConsoleWrite(struct file *filep, const CHAR *buffer, size_t bufLen)
@@ -779,11 +790,15 @@ STATIC ssize_t ConsoleWrite(struct file *filep, const CHAR *buffer, size_t bufLe
struct file *privFilep = NULL;
const struct file_operations_vfs *fileOps = NULL;
- if ((buffer == NULL) || (bufLen == 0) || (bufLen > CONSOLE_FIFO_SIZE)) {
+ if ((buffer == NULL) || (bufLen == 0)) {
ret = EINVAL;
goto ERROUT;
}
+ if (bufLen > CONSOLE_FIFO_SIZE) {
+ bufLen = CONSOLE_FIFO_SIZE;
+ }
+
userBuf = LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buffer, bufLen);
ret = GetFilepOps(filep, &privFilep, &fileOps);
@@ -1128,14 +1143,14 @@ STATIC CirBufSendCB *ConsoleCirBufCreate(VOID)
}
(VOID)memset_s(cirBufSendCB, sizeof(CirBufSendCB), 0, sizeof(CirBufSendCB));
- fifo = (CHAR *)LOS_MemAlloc(m_aucSysMem0, TELNET_CIRBUF_SIZE);
+ fifo = (CHAR *)LOS_MemAlloc(m_aucSysMem0, CONSOLE_CIRCBUF_SIZE);
if (fifo == NULL) {
goto ERROR_WITH_SENDCB;
}
- (VOID)memset_s(fifo, TELNET_CIRBUF_SIZE, 0, TELNET_CIRBUF_SIZE);
+ (VOID)memset_s(fifo, CONSOLE_CIRCBUF_SIZE, 0, CONSOLE_CIRCBUF_SIZE);
cirBufCB = &cirBufSendCB->cirBufCB;
- ret = LOS_CirBufInit(cirBufCB, fifo, TELNET_CIRBUF_SIZE);
+ ret = LOS_CirBufInit(cirBufCB, fifo, CONSOLE_CIRCBUF_SIZE);
if (ret != LOS_OK) {
goto ERROR_WITH_FIFO;
}
@@ -1519,7 +1534,7 @@ INT32 ConsoleUpdateFd(VOID)
} else if (g_console[CONSOLE_TELNET - 1] != NULL) {
consoleID = CONSOLE_TELNET;
} else {
- PRINT_ERR("No console dev used.\n");
+ PRINTK("No console dev used.\n");
return -1;
}
}
@@ -1626,7 +1641,7 @@ VOID OsWaitConsoleSendTaskPend(UINT32 taskID)
UINT32 i;
CONSOLE_CB *console = NULL;
LosTaskCB *taskCB = NULL;
- INT32 waitTime = 3000; /* 3000: 3 seconds*/
+ INT32 waitTime = 3000; /* 3000: 3 seconds */
for (i = 0; i < CONSOLE_NUM; i++) {
console = g_console[i];
diff --git a/kernel/common/console.h b/kernel/common/console.h
old mode 100644
new mode 100755
index 97c91a77..7b2a7ef4
--- a/kernel/common/console.h
+++ b/kernel/common/console.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -66,11 +66,10 @@ extern "C" {
#define CONSOLE_RD_NONBLOCK 0
#define CONSOLE_SHELL_KEY_EVENT 0x112
#define CONSOLE_SHELL_EXITED 0x400
-#define CONSOLE_FIFO_SIZE 1024
+#define CONSOLE_FIFO_SIZE 0x400
#define CONSOLE_NUM 2
-
-#define TELNET_CIRBUF_SIZE 0x2000
+#define CONSOLE_CIRCBUF_SIZE 0x400
typedef struct {
CirBuf cirBufCB; /* Circular buffer CB */
diff --git a/kernel/common/hwi_shell.c b/kernel/common/hwi_shell.c
index bccf3541..981375cb 100644
--- a/kernel/common/hwi_shell.c
+++ b/kernel/common/hwi_shell.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,7 +35,6 @@
#include "los_cpup_pri.h"
#endif
#include "los_hwi_pri.h"
-#include "los_process_pri.h"
#include "shcmd.h"
#ifdef __cplusplus
@@ -45,15 +44,15 @@ extern "C" {
#endif /* __cplusplus */
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
-STATIC CPUP_INFO_S g_hwiCpupAll[OS_HWI_MAX_NUM];
-STATIC CPUP_INFO_S g_hwiCpup10s[OS_HWI_MAX_NUM];
-STATIC CPUP_INFO_S g_hwiCpup1s[OS_HWI_MAX_NUM];
+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;
- UINT32 intSave;
UINT64 cycles;
size_t size = sizeof(CPUP_INFO_S) * OS_HWI_MAX_NUM;
+ OsIrqCpupCB *irqCpup = OsGetIrqCpupArrayBase();
(VOID)argv;
if (argc > 0) {
@@ -61,42 +60,37 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
return OS_ERROR;
}
- (VOID)memset_s(g_hwiCpupAll, size, 0, size);
- (VOID)memset_s(g_hwiCpup10s, size, 0, size);
- (VOID)memset_s(g_hwiCpup1s, size, 0, size);
+ if (irqCpup == NULL) {
+ return OS_ERROR;
+ }
- intSave = LOS_IntLock();
- (VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpupAll, CPUP_ALL_TIME, 0);
- (VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpup10s, CPUP_LAST_TEN_SECONDS, 0);
- (VOID)LOS_AllCpuUsage(OS_HWI_MAX_NUM, g_hwiCpup1s, CPUP_LAST_ONE_SECONDS, 0);
- LOS_IntRestore(intSave);
+ (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 Name CYCLECOST CPUUSE CPUUSE10s CPUUSE1s mode\n");
+ 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++) {
- if (OsGetHwiFormCnt(i)) {
- cycles = g_cpup[g_processMaxNum + i].allTime / OsGetHwiFormCnt(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) && (OsGetHwiFormName(i) != NULL)) {
- PRINTK(" %8d: %-10d%-12s %-10llu", i, OsGetHwiFormCnt(i), OsGetHwiFormName(i), cycles);
- } else if (HWI_IS_REGISTED(i)) {
- PRINTK(" %8d: %-10d%-12s %-10llu", i, OsGetHwiFormCnt(i), "", cycles);
+ if (HWI_IS_REGISTED(i)) {
+ PRINTK(" %10d:%11u%11llu", i, count, cycles);
} else {
continue;
}
- PRINTK("%2d.%-7d"
- "%2d.%-9d"
- "%2d.%-6d"
- "%s\n",
- g_hwiCpupAll[i].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_hwiCpupAll[i].uwUsage % LOS_CPUP_PRECISION_MULT,
- g_hwiCpup10s[i].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_hwiCpup10s[i].uwUsage % LOS_CPUP_PRECISION_MULT,
- g_hwiCpup1s[i].uwUsage / LOS_CPUP_PRECISION_MULT,
- g_hwiCpup1s[i].uwUsage % LOS_CPUP_PRECISION_MULT,
- g_hwiForm[i].uwParam == IRQF_SHARED ? "shared" : "normal");
+ 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;
}
diff --git a/kernel/common/los_builddef.h b/kernel/common/los_builddef.h
index 610eb11e..c00ae1f9 100644
--- a/kernel/common/los_builddef.h
+++ b/kernel/common/los_builddef.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_cir_buf.c b/kernel/common/los_cir_buf.c
index b721bc0b..3bd7b951 100644
--- a/kernel/common/los_cir_buf.c
+++ b/kernel/common/los_cir_buf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_cir_buf_pri.h b/kernel/common/los_cir_buf_pri.h
index 312fd437..9e990ec0 100644
--- a/kernel/common/los_cir_buf_pri.h
+++ b/kernel/common/los_cir_buf_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_config.c b/kernel/common/los_config.c
old mode 100644
new mode 100755
index f851a7cd..91875330
--- a/kernel/common/los_config.c
+++ b/kernel/common/los_config.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -43,10 +43,10 @@
#include "los_printf.h"
#include "los_swtmr.h"
#include "los_swtmr_pri.h"
-#include "los_timeslice_pri.h"
#include "los_memory_pri.h"
#include "los_sem_pri.h"
#include "los_mux_pri.h"
+#include "los_rwlock_pri.h"
#include "los_queue_pri.h"
#include "los_memstat_pri.h"
#include "los_hwi_pri.h"
@@ -77,9 +77,6 @@
#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
#include "console.h"
#endif
-#ifdef LOSCFG_KERNEL_TICKLESS
-#include "los_tickless.h"
-#endif
#ifdef LOSCFG_ARCH_CORTEX_M7
#include "los_exc_pri.h"
#endif
@@ -123,19 +120,31 @@
#include "los_hilog.h"
#endif
+#ifdef LOSCFG_QUICK_START
+#include "los_quick_start_pri.h"
+#endif
+
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-extern UINT32 OsSystemInit(VOID);
+STATIC SystemRebootFunc g_rebootHook = NULL;
-VOID __attribute__((weak)) SystemInit(VOID)
+VOID OsSetRebootHook(SystemRebootFunc func)
{
- PRINT_WARN("Function not implemented. Using weak reference stub\n");
+ g_rebootHook = func;
}
+SystemRebootFunc OsGetRebootHook(VOID)
+{
+ return g_rebootHook;
+}
+
+extern UINT32 OsSystemInit(VOID);
+extern VOID SystemInit(VOID);
+
LITE_OS_SEC_TEXT_INIT VOID osRegister(VOID)
{
g_sysClock = OS_SYS_CLOCK;
@@ -144,34 +153,6 @@ LITE_OS_SEC_TEXT_INIT VOID osRegister(VOID)
return;
}
-LITE_OS_SEC_TEXT_INIT VOID OsStart(VOID)
-{
- LosProcessCB *runProcess = NULL;
- LosTaskCB *taskCB = NULL;
- UINT32 cpuid = ArchCurrCpuid();
-
- OsTickStart();
-
- LOS_SpinLock(&g_taskSpin);
- taskCB = OsGetTopTask();
-
- runProcess = OS_PCB_FROM_PID(taskCB->processID);
- runProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
-#if (LOSCFG_KERNEL_SMP == YES)
- /*
- * attention: current cpu needs to be set, in case first task deletion
- * may fail because this flag mismatch with the real current cpu.
- */
- taskCB->currCpu = cpuid;
- runProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_ADD(runProcess->processStatus);
-#endif
-
- OS_SCHEDULER_SET(cpuid);
-
- PRINTK("cpu %d entering scheduler\n", cpuid);
- OsStartToRun(taskCB);
-}
-
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsIpcInit(VOID)
{
UINT32 ret;
@@ -225,7 +206,6 @@ LITE_OS_SEC_TEXT_INIT STATIC INT32 OsBsdInit(VOID)
}
#endif
-
LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
{
UINT32 ret;
@@ -243,6 +223,10 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
OsLkLoggerInit(NULL);
#endif
+#if (LOSCFG_KERNEL_TRACE == YES)
+ LOS_TraceInit();
+#endif
+
#ifdef LOSCFG_EXC_INTERACTION
#ifdef LOSCFG_ARCH_CORTEX_M7
/* 4096: 4K space for Stack */
@@ -279,7 +263,8 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
return ret;
}
-#if ((LOSCFG_BASE_IPC_QUEUE == YES) || (LOSCFG_BASE_IPC_MUX == YES) || (LOSCFG_BASE_IPC_SEM == YES))
+#if ((LOSCFG_BASE_IPC_QUEUE == YES) || (LOSCFG_BASE_IPC_MUX == YES) || \
+ (LOSCFG_BASE_IPC_SEM == YES) || (LOSCFG_BASE_IPC_RWLOCK == YES))
ret = OsIpcInit();
if (ret != LOS_OK) {
return ret;
@@ -310,7 +295,7 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
}
#endif
- ret = OsKernelInitProcess();
+ ret = OsSystemProcessCreate();
if (ret != LOS_OK) {
return ret;
}
@@ -351,24 +336,19 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
if (ret != LOS_OK) {
return ret;
}
-
-#if LOSCFG_DRIVERS_HIEVENT
- OsDriverHiEventInit();
-#endif
-
-#if (LOSCFG_KERNEL_TRACE == YES)
- LOS_TraceInit();
-#endif
-
-#if (LOSCFG_KERNEL_LITEIPC == YES)
- ret = LiteIpcInit();
+#if (LOSCFG_BASE_CORE_HILOG == YES)
+ ret = HiLogDriverInit();
if (ret != LOS_OK) {
return ret;
}
#endif
-#if (LOSCFG_BASE_CORE_HILOG == YES)
- ret = HiLogDriverInit();
+#if LOSCFG_DRIVERS_HIEVENT
+ OsDriverHiEventInit();
+#endif
+
+#if (LOSCFG_KERNEL_LITEIPC == YES)
+ ret = LiteIpcInit();
if (ret != LOS_OK) {
return ret;
}
@@ -412,6 +392,14 @@ STATIC UINT32 OsSystemInitTaskCreate(VOID)
return LOS_TaskCreate(&taskID, &sysTask);
}
+#ifdef LOSCFG_QUICK_START
+UINT32 OsSystemInitStep2(VOID)
+{
+ SystemInit2();
+ return 0;
+}
+#endif
+
#ifdef LOSCFG_MEM_RECORDINFO
STATIC UINT32 OsMemShowTaskCreate(VOID)
{
@@ -449,9 +437,6 @@ UINT32 OsSystemInit(VOID)
}
PRINTK("create memshow_Task ok\n");
#endif
-#ifdef LOSCFG_KERNEL_TICKLESS
- LOS_TicklessEnable();
-#endif
return 0;
}
diff --git a/kernel/common/los_config.h b/kernel/common/los_config.h
old mode 100644
new mode 100755
index 38b7086f..be16a712
--- a/kernel/common/los_config.h
+++ b/kernel/common/los_config.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,11 +36,9 @@
#ifndef _LOS_CONFIG_H
#define _LOS_CONFIG_H
-#include "platform_config.h"
#include "los_tick.h"
#include "los_vm_zone.h"
#include "sys_config.h"
-#include "hisoc/clock.h"
#ifdef __cplusplus
#if __cplusplus
@@ -96,7 +94,7 @@ extern UINT32 __heap_end;
* Number of Ticks in one second
*/
#ifndef LOSCFG_BASE_CORE_TICK_PER_SECOND
-#define LOSCFG_BASE_CORE_TICK_PER_SECOND 100
+#define LOSCFG_BASE_CORE_TICK_PER_SECOND 1000 /* 1ms per tick */
#endif
/**
@@ -111,7 +109,7 @@ extern UINT32 __heap_end;
* @ingroup los_config
* Sched clck interval
*/
-#define SCHED_CLOCK_INTETRVAL_TICKS 100
+#define SCHED_CLOCK_INTETRVAL_TICKS LOSCFG_BASE_CORE_TICK_PER_SECOND
/**
* @ingroup los_config
@@ -215,7 +213,7 @@ extern UINT32 __heap_end;
* Longest execution time of tasks with the same priorities
*/
#ifndef LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
-#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 2
+#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000 /* 20ms */
#endif
/**
@@ -359,17 +357,12 @@ extern UINT32 __heap_end;
#define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1)
-/****************************** trace module configuration **************************/
-#ifndef LOSCFG_KERNEL_TRACE
-#define LOSCFG_KERNEL_TRACE NO
-#endif
-
/**
* @ingroup los_trace
* It's the total size of trace buffer. It's in the unit of char
*/
-#if (LOSCFG_KERNEL_TRACE == YES)
-#define LOS_TRACE_BUFFER_SIZE 2048
+#ifdef LOSCFG_KERNEL_TRACE
+#define LOS_TRACE_BUFFER_SIZE (1024 * 512)
#endif
/**
@@ -388,7 +381,7 @@ extern UINT32 __heap_end;
#define KERNEL_MAJOR 2
#define KERNEL_MINOR 0
#define KERNEL_PATCH 0
-#define KERNEL_ITRE 35
+#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)
@@ -475,6 +468,10 @@ VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_writ
extern VOID OsStart(VOID);
extern INT32 OsMain(VOID);
+typedef VOID (*SystemRebootFunc)(VOID);
+VOID OsSetRebootHook(SystemRebootFunc func);
+SystemRebootFunc OsGetRebootHook(VOID);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/common/los_exc_interaction.c b/kernel/common/los_exc_interaction.c
index 49b6cc7b..8a282593 100644
--- a/kernel/common/los_exc_interaction.c
+++ b/kernel/common/los_exc_interaction.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_exc_interaction_pri.h b/kernel/common/los_exc_interaction_pri.h
index 0a3cc0af..dcced575 100644
--- a/kernel/common/los_exc_interaction_pri.h
+++ b/kernel/common/los_exc_interaction_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_excinfo.c b/kernel/common/los_excinfo.c
index 00d24c00..6a34fce1 100644
--- a/kernel/common/los_excinfo.c
+++ b/kernel/common/los_excinfo.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_excinfo_pri.h b/kernel/common/los_excinfo_pri.h
index ab10c401..24f0d043 100644
--- a/kernel/common/los_excinfo_pri.h
+++ b/kernel/common/los_excinfo_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_hilog.c b/kernel/common/los_hilog.c
old mode 100644
new mode 100755
index 9a259fee..e1a798dc
--- a/kernel/common/los_hilog.c
+++ b/kernel/common/los_hilog.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -127,16 +127,16 @@ static void HiLogBufferDec(size_t sz)
static int HiLogBufferCopy(unsigned char *dst, unsigned dstLen, unsigned char *src, size_t srcLen)
{
int retval = -1;
-
size_t minLen = (dstLen > srcLen) ? srcLen : dstLen;
- if (LOS_IsUserAddressRange((VADDR_T)dst, minLen) && LOS_IsUserAddressRange((VADDR_T)src, minLen)) {
+ if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, minLen) &&
+ LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, minLen)) {
return retval;
}
- if (LOS_IsUserAddressRange((VADDR_T)dst, minLen)) {
+ if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, minLen)) {
retval = LOS_ArchCopyToUser(dst, src, minLen);
- } else if (LOS_IsUserAddressRange((VADDR_T)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);
@@ -167,7 +167,6 @@ static ssize_t HiLogRead(FAR struct file *filep, char *buffer, size_t bufLen)
struct HiLogEntry header;
(void)filep;
-
wait_event_interruptible(g_hiLogDev.wq, (g_hiLogDev.size > 0));
(VOID)LOS_MuxAcquire(&g_hiLogDev.mtx);
@@ -263,6 +262,12 @@ 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);
diff --git a/kernel/common/los_hilog.h b/kernel/common/los_hilog.h
old mode 100644
new mode 100755
index 90073979..9cf10e66
--- a/kernel/common/los_hilog.h
+++ b/kernel/common/los_hilog.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_magickey.c b/kernel/common/los_magickey.c
index 6cf31323..28087066 100644
--- a/kernel/common/los_magickey.c
+++ b/kernel/common/los_magickey.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_magickey.h b/kernel/common/los_magickey.h
index 012dafca..266d49ba 100644
--- a/kernel/common/los_magickey.h
+++ b/kernel/common/los_magickey.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_printf.c b/kernel/common/los_printf.c
old mode 100644
new mode 100755
index ea00840e..40133286
--- a/kernel/common/los_printf.c
+++ b/kernel/common/los_printf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,7 +36,6 @@
#endif
#include "los_hwi.h"
#include "los_memory_pri.h"
-#include "uart.h"
#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif
@@ -91,13 +90,29 @@ STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
#endif
}
+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;
+ }
+}
+
VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
{
switch (type) {
case CONSOLE_OUTPUT:
#ifdef LOSCFG_PLATFORM_CONSOLE
if (ConsoleEnable() == TRUE) {
- (VOID)write(STDOUT_FILENO, str, (size_t)len);
+ ConsoleOutput(str, len);
break;
}
#endif
@@ -106,7 +121,7 @@ VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
UartOutput(str, len, UART_WITH_LOCK);
break;
case EXC_OUTPUT:
- UartOutput(str, len, UART_WITHOUT_LOCK);
+ UartPuts(str, len, UART_WITH_LOCK);
break;
default:
break;
@@ -250,7 +265,7 @@ VOID PrintExcInfo(const CHAR *fmt, ...)
VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...)
{
va_list ap;
- va_start(ap, fmt);
+
if (level > PRINT_LEVEL) {
return;
}
@@ -258,6 +273,8 @@ VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...
if ((level != LOS_COMMON_LEVEL) && ((level > LOS_EMG_LEVEL) && (level <= LOS_TRACE_LEVEL))) {
dprintf("[%s]", g_logString[level]);
}
+
+ va_start(ap, fmt);
OsVprintf(fmt, ap, CONSOLE_OUTPUT);
va_end(ap);
}
diff --git a/kernel/common/los_rootfs.c b/kernel/common/los_rootfs.c
old mode 100644
new mode 100755
index 934a8a8f..11a2de93
--- a/kernel/common/los_rootfs.c
+++ b/kernel/common/los_rootfs.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,7 +31,7 @@
#include "los_base.h"
#include "los_typedef.h"
#include "string.h"
-#if defined(LOSCFG_PLATFORM_HI3518EV300) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
+#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
#include "mtd_partition.h"
#endif
#ifdef LOSCFG_DRIVERS_MMC
@@ -46,10 +46,16 @@
#endif
#include "mtd_list.h"
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#ifdef LOSCFG_STORAGE_SPINOR
#define DEV_STORAGE_PATH "/dev/spinorblk2"
#define SECOND_MTD_PART_NUM 2
-#define STORAGE_SIZE 0x100000
+#define STORAGE_SIZE 0x80000
+#endif
+
+#ifdef LOSCFG_STORAGE_SPINAND
+#define DEV_STORAGE_PATH "/dev/nandblk2"
+#define SECOND_MTD_PART_NUM 2
+#define STORAGE_SIZE 0xa00000
#endif
#ifdef __cplusplus
@@ -58,7 +64,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
#define STORAGE_SIZE 0x3200000
STATIC los_disk *g_emmcDisk = NULL;
#endif
@@ -70,6 +76,18 @@ STATIC INT32 g_alignSize = 0;
#define VFAT_STORAGE_MOUNT_DIR_MODE 777
#define DEFAULT_STORAGE_MOUNT_DIR_MODE 755
+STATIC UINT64 g_cmdLineAddr = COMMAND_LINE_ADDR;
+
+VOID OsSetCmdLineAddr(UINT64 addr)
+{
+ g_cmdLineAddr = addr;
+}
+
+UINT64 OsGetCmdLineAddr(VOID)
+{
+ return g_cmdLineAddr;
+}
+
#ifdef LOSCFG_DRIVERS_MMC
los_disk *GetMmcDisk(UINT8 type)
{
@@ -94,7 +112,7 @@ los_disk *GetMmcDisk(UINT8 type)
}
#endif
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize)
{
INT32 ret;
@@ -143,17 +161,17 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi
{
const CHAR *rootDev = NULL;
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
INT32 ret;
if (strcmp(rootType, "flash") == 0) {
ret = add_mtd_partition(FLASH_TYPE, rootAddr, rootSize, 0);
if (ret != LOS_OK) {
- PRINT_ERR("Failed to add spinor root partition!\n");
+ PRINT_ERR("Failed to add spinor/spinand root partition!\n");
} else {
rootDev = FLASH_DEV_NAME;
ret = add_mtd_partition(FLASH_TYPE, (rootAddr + rootSize), STORAGE_SIZE, SECOND_MTD_PART_NUM);
if (ret != LOS_OK) {
- PRINT_ERR("Failed to add spinor storage partition!\n");
+ PRINT_ERR("Failed to add spinor/spinand storage partition!\n");
}
}
} else
@@ -176,7 +194,7 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi
} else
#endif
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
if (strcmp(rootType, "emmc") == 0) {
rootDev = AddEmmcRootfsPart(rootAddr, rootSize);
} else
@@ -184,8 +202,9 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
#define CFIFLASH_CAPACITY 64 * 1024 * 1024
- INT32 ret;
if (strcmp(rootType, "cfi-flash") == 0) {
+ INT32 ret;
+ extern INT32 add_mtd_partition(const CHAR *type, UINT32 startAddr, UINT32 length, UINT32 partitionNum);
ret = add_mtd_partition("cfi-flash", rootAddr, rootSize, 0);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add cfi-flash root partition!\n");
@@ -208,6 +227,11 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi
#ifndef LOSCFG_SECURITY_BOOT
STATIC INT32 GetArgs(CHAR **args)
{
+#ifdef LOSCFG_QUICK_START
+ *args = OsGetArgsAddr();
+ return LOS_OK;
+
+#else
INT32 ret;
INT32 i;
INT32 len = 0;
@@ -221,7 +245,7 @@ STATIC INT32 GetArgs(CHAR **args)
return LOS_NOK;
}
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
g_emmcDisk = GetMmcDisk(EMMC);
if (g_emmcDisk == NULL) {
PRINT_ERR("Get EMMC disk failed!\n");
@@ -236,7 +260,7 @@ STATIC INT32 GetArgs(CHAR **args)
g_alignSize = EMMC_SEC_SIZE;
#endif
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
struct MtdDev *mtd = GetMtd(FLASH_TYPE);
if (mtd == NULL) {
PRINT_ERR("Get spinor mtd failed!\n");
@@ -249,7 +273,6 @@ STATIC INT32 GetArgs(CHAR **args)
goto ERROUT;
}
#endif
-
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
/*
* TODO: Implement method of fetching bootargs for
@@ -277,6 +300,7 @@ STATIC INT32 GetArgs(CHAR **args)
ERROUT:
free(cmdLine);
return LOS_NOK;
+#endif
}
STATIC INT32 MatchRootPos(CHAR *p, const CHAR *rootInfoName, INT32 *rootInfo)
@@ -360,15 +384,16 @@ STATIC INT32 MatchRootInfo(CHAR *p, CHAR **rootType, CHAR **fsType, INT32 *rootA
STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize)
{
CHAR *args = NULL;
- CHAR *argsBak = NULL;
CHAR *p = NULL;
if (GetArgs(&args) != LOS_OK) {
PRINT_ERR("Cannot get bootargs!\n");
return LOS_NOK;
}
+#ifndef LOSCFG_QUICK_START
+ CHAR *argsBak = NULL;
argsBak = args;
-
+#endif
p = strsep(&args, " ");
while (p != NULL) {
if (MatchRootInfo(p, rootType, fsType, rootAddr, rootSize) != LOS_OK) {
@@ -377,7 +402,9 @@ STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32
p = strsep(&args, " ");
}
if ((*fsType != NULL) && (*rootType != NULL)) {
+#ifndef LOSCFG_QUICK_START
free(argsBak);
+#endif
return LOS_OK;
}
@@ -391,12 +418,14 @@ ERROUT:
free(*fsType);
*fsType = NULL;
}
+#ifndef LOSCFG_QUICK_START
free(argsBak);
+#endif
return LOS_NOK;
}
#endif
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
STATIC VOID OsMountUserdata(const CHAR *fsType)
{
INT32 ret;
@@ -449,7 +478,7 @@ STATIC INT32 OsMountRootfsAndUserfs(const CHAR *rootDev, const CHAR *fsType)
return ret;
}
g_root_inode->i_mode |= S_IRWXU | S_IRWXG | S_IRWXO;
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
ret = mkdir("/storage", VFAT_STORAGE_MOUNT_DIR_MODE);
if (ret != LOS_OK) {
err = get_errno();
@@ -473,10 +502,10 @@ STATIC INT32 OsMountRootfsAndUserfs(const CHAR *rootDev, const CHAR *fsType)
ret = mount(rootDev, "/", fsType, MS_RDONLY, NULL);
if (ret != LOS_OK) {
err = get_errno();
- PRINT_ERR("Failed to mount rootfs, errno %d: %s\n", err, strerror(err));
+ PRINT_ERR("Failed to mount rootfs,rootDev %s, errno %d: %s\n", rootDev, err, strerror(err));
return ret;
}
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
ret = mkdir("/storage", DEFAULT_STORAGE_MOUNT_DIR_MODE);
if (ret != LOS_OK) {
err = get_errno();
diff --git a/kernel/common/los_rootfs.h b/kernel/common/los_rootfs.h
old mode 100644
new mode 100755
index 7260f1c8..c73813b8
--- a/kernel/common/los_rootfs.h
+++ b/kernel/common/los_rootfs.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,15 +35,18 @@
#define BYTES_PER_MBYTE 0x100000
#define BYTES_PER_KBYTE 0x400
-#define COMMAND_LINE_ADDR 512 * BYTES_PER_KBYTE
+#define COMMAND_LINE_ADDR LOSCFG_BOOTENV_ADDR * BYTES_PER_KBYTE
#define COMMAND_LINE_SIZE 1024
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#ifdef LOSCFG_STORAGE_SPINOR
#define ROOTFS_ROOT_TYPE "flash"
#define ROOTFS_FS_TYPE "jffs2"
+#elif defined(LOSCFG_STORAGE_SPINAND)
+#define ROOTFS_ROOT_TYPE "nand"
+#define ROOTFS_FS_TYPE "yaffs2"
#endif
-#ifdef LOSCFG_PLATFORM_HI3516DV300
+#ifdef LOSCFG_STORAGE_EMMC
#define ROOTFS_ROOT_TYPE "emmc"
#define ROOTFS_FS_TYPE "vfat"
#endif
@@ -56,8 +59,13 @@
#define ROOTFS_FLASH_SIZE 0xa00000
#endif
+#ifdef LOSCFG_STORAGE_SPINOR
#define FLASH_TYPE "spinor"
#define FLASH_DEV_NAME "/dev/spinorblk0"
+#elif defined(LOSCFG_STORAGE_SPINAND)
+#define FLASH_TYPE "nand"
+#define FLASH_DEV_NAME "/dev/nandblk0"
+#endif
#define EMMC_SEC_SIZE 512
@@ -65,5 +73,10 @@
#define HEX_NUMBER_STRING "0123456789abcdefABCDEF"
INT32 OsMountRootfs(VOID);
+VOID OsSetCmdLineAddr(UINT64 addr);
+UINT64 OsGetCmdLineAddr(VOID);
+#ifdef LOSCFG_QUICK_START
+CHAR *OsGetArgsAddr(VOID);
+#endif
#endif /* _LOS_ROOTFS_H */
diff --git a/kernel/common/los_seq_buf.c b/kernel/common/los_seq_buf.c
old mode 100644
new mode 100755
index 826d1437..f91ffa71
--- a/kernel/common/los_seq_buf.c
+++ b/kernel/common/los_seq_buf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_seq_buf.h b/kernel/common/los_seq_buf.h
old mode 100644
new mode 100755
index d22ffc78..e048ba61
--- a/kernel/common/los_seq_buf.h
+++ b/kernel/common/los_seq_buf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/los_timer_pri.h b/kernel/common/los_timer_pri.h
index 33c19eed..6017d8b0 100644
--- a/kernel/common/los_timer_pri.h
+++ b/kernel/common/los_timer_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/common/patchfs/Kconfig b/kernel/common/patchfs/Kconfig
new file mode 100644
index 00000000..b7c11145
--- /dev/null
+++ b/kernel/common/patchfs/Kconfig
@@ -0,0 +1,6 @@
+config PLATFORM_PATCHFS
+ bool "Enable PATCHFS"
+ default n
+ depends on FS_JFFS
+ help
+ Answer Y to enable LiteOS support patchfs.
diff --git a/kernel/common/patchfs/Makefile b/kernel/common/patchfs/Makefile
new file mode 100644
index 00000000..64d68764
--- /dev/null
+++ b/kernel/common/patchfs/Makefile
@@ -0,0 +1,13 @@
+include $(LITEOSTOPDIR)/config.mk
+
+MODULE_NAME := $(notdir $(shell pwd))
+
+LOCAL_SRCS := $(wildcard *.c)
+
+LOCAL_INCLUDE := \
+ -I $(LITEOSTOPDIR)/kernel/common \
+ -I $(LITEOSTOPDIR)/kernel/common/patchfs \
+
+LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
+
+include $(MODULE)
diff --git a/kernel/common/patchfs/los_partition_utils.c b/kernel/common/patchfs/los_partition_utils.c
new file mode 100644
index 00000000..c2556011
--- /dev/null
+++ b/kernel/common/patchfs/los_partition_utils.c
@@ -0,0 +1,235 @@
+/*
+ * 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_partition_utils.h"
+#if defined(LOSCFG_STORAGE_SPINOR)
+#include "mtd_partition.h"
+#endif
+
+STATIC INT32 MatchPartPos(CHAR *p, const CHAR *partInfoName, INT32 *partInfo)
+{
+ UINT32 offset;
+ CHAR *value = NULL;
+
+ if (strncmp(p, partInfoName, strlen(partInfoName)) == 0) {
+ value = p + strlen(partInfoName);
+ offset = strspn(value, DEC_NUMBER_STRING);
+ if (strcmp(p + strlen(p) - 1, "M") == 0) {
+ if ((offset < strlen(value) - 1) || (sscanf_s(value, "%d", partInfo) <= 0)) {
+ goto ERROUT;
+ }
+ *partInfo = *partInfo * BYTES_PER_MBYTE;
+ } else if (strcmp(p + strlen(p) - 1, "K") == 0) {
+ if ((offset < (strlen(value) - 1)) || (sscanf_s(value, "%d", partInfo) <= 0)) {
+ goto ERROUT;
+ }
+ *partInfo = *partInfo * BYTES_PER_KBYTE;
+ } else if (sscanf_s(value, "0x%x", partInfo) > 0) {
+ value += strlen("0x");
+ if (strspn(value, HEX_NUMBER_STRING) < strlen(value)) {
+ goto ERROUT;
+ }
+ } else {
+ goto ERROUT;
+ }
+ }
+
+ return LOS_OK;
+
+ERROUT:
+ PRINT_ERR("Invalid format: %s\n", p + strlen(partInfoName));
+ return LOS_NOK;
+}
+
+STATIC INT32 MatchPartInfo(CHAR *p, struct PartitionInfo *partInfo)
+{
+ const CHAR *storageTypeArgName = partInfo->storageTypeArgName;
+ const CHAR *fsTypeArgName = partInfo->fsTypeArgName;
+ const CHAR *addrArgName = partInfo->addrArgName;
+ const CHAR *partSizeArgName = partInfo->partSizeArgName;
+
+ if ((partInfo->storageType == NULL) && (strncmp(p, storageTypeArgName, strlen(storageTypeArgName)) == 0)) {
+ partInfo->storageType = strdup(p + strlen(storageTypeArgName));
+ if (partInfo->storageType == NULL) {
+ return LOS_NOK;
+ }
+ return LOS_OK;
+ }
+
+ if ((partInfo->fsType == NULL) && (strncmp(p, fsTypeArgName, strlen(fsTypeArgName)) == 0)) {
+ partInfo->fsType = strdup(p + strlen(fsTypeArgName));
+ if (partInfo->fsType == NULL) {
+ return LOS_NOK;
+ }
+ return LOS_OK;
+ }
+
+ if (partInfo->startAddr < 0) {
+ if (MatchPartPos(p, addrArgName, &partInfo->startAddr) != LOS_OK) {
+ return LOS_NOK;
+ } else if (partInfo->startAddr >= 0) {
+ return LOS_OK;
+ }
+ }
+
+ if (partInfo->partSize < 0) {
+ if (MatchPartPos(p, partSizeArgName, &partInfo->partSize) != LOS_OK) {
+ return LOS_NOK;
+ }
+ }
+
+ return LOS_OK;
+}
+
+STATIC INT32 GetPartitionBootArgs(const CHAR *argName, CHAR **args)
+{
+ INT32 i;
+ INT32 len = 0;
+ CHAR *cmdLine = NULL;
+ INT32 cmdLineLen;
+ CHAR *tmp = NULL;
+
+ cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
+ if (cmdLine == NULL) {
+ PRINT_ERR("Malloc cmdLine space failed!\n");
+ return LOS_NOK;
+ }
+
+#if defined(LOSCFG_STORAGE_SPINOR)
+ struct MtdDev *mtd = GetMtd(FLASH_TYPE);
+ if (mtd == NULL) {
+ PRINT_ERR("Get spinor mtd failed!\n");
+ goto ERROUT;
+ }
+ cmdLineLen = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, cmdLine);
+ if ((cmdLineLen != COMMAND_LINE_SIZE)) {
+ PRINT_ERR("Read spinor command line failed!\n");
+ goto ERROUT;
+ }
+#else
+ cmdLineLen = 0;
+#endif
+
+ for (i = 0; i < cmdLineLen; i += len + 1) {
+ len = strlen(cmdLine + i);
+ tmp = strstr(cmdLine + i, argName);
+ if (tmp != NULL) {
+ *args = strdup(tmp + strlen(argName));
+ if (*args == NULL) {
+ goto ERROUT;
+ }
+ free(cmdLine);
+ return LOS_OK;
+ }
+ }
+
+ PRINTK("no patch partition bootargs\n");
+
+ERROUT:
+ free(cmdLine);
+ return LOS_NOK;
+}
+
+INT32 GetPartitionInfo(struct PartitionInfo *partInfo)
+{
+ CHAR *args = NULL;
+ CHAR *argsBak = NULL;
+ CHAR *p = NULL;
+
+ if (GetPartitionBootArgs(partInfo->cmdlineArgName, &args) != LOS_OK) {
+ return LOS_NOK;
+ }
+ argsBak = args;
+
+ p = strsep(&args, " ");
+ while (p != NULL) {
+ if (MatchPartInfo(p, partInfo) != LOS_OK) {
+ goto ERROUT;
+ }
+ p = strsep(&args, " ");
+ }
+ if ((partInfo->fsType != NULL) && (partInfo->storageType != NULL)) {
+ free(argsBak);
+ return LOS_OK;
+ }
+ PRINT_ERR("Cannot find %s type\n", partInfo->partName);
+
+ERROUT:
+ PRINT_ERR("Invalid %s information!\n", partInfo->partName);
+ if (partInfo->storageType != NULL) {
+ free(partInfo->storageType);
+ partInfo->storageType = NULL;
+ }
+ if (partInfo->fsType != NULL) {
+ free(partInfo->fsType);
+ partInfo->fsType = NULL;
+ }
+ free(argsBak);
+
+ return LOS_NOK;
+}
+
+const CHAR *GetDevNameOfPartition(const struct PartitionInfo *partInfo)
+{
+ const CHAR *devName = NULL;
+
+ if (strcmp(partInfo->storageType, STORAGE_TYPE) == 0) {
+#if defined(LOSCFG_STORAGE_SPINOR)
+ INT32 ret = add_mtd_partition(FLASH_TYPE, partInfo->startAddr, partInfo->partSize, partInfo->partNum);
+ if (ret != LOS_OK) {
+ PRINT_ERR("Failed to add %s partition! error = %d\n", partInfo->partName, ret);
+ } else {
+ if (partInfo->devName != NULL) {
+ devName = partInfo->devName;
+ }
+ }
+#endif
+ } else {
+ PRINT_ERR("Failed to find %s dev type: %s\n", partInfo->partName, partInfo->storageType);
+ }
+
+ return devName;
+}
+
+INT32 ResetDevNameofPartition(const struct PartitionInfo *partInfo)
+{
+ INT32 ret;
+#if defined(LOSCFG_STORAGE_SPINOR)
+ ret = delete_mtd_partition(partInfo->partNum, FLASH_TYPE);
+ if (ret != ENOERR) {
+ int err = get_errno();
+ PRINT_ERR("Failed to delete %s, errno %d: %s\n", partInfo->devName, err, strerror(err));
+ ret = LOS_NOK;
+ }
+#else
+ ret = LOS_NOK;
+#endif
+ return ret;
+}
diff --git a/kernel/base/include/los_multipledlinkhead_pri.h b/kernel/common/patchfs/los_partition_utils.h
similarity index 54%
rename from kernel/base/include/los_multipledlinkhead_pri.h
rename to kernel/common/patchfs/los_partition_utils.h
index aa34e273..8fcc1675 100644
--- a/kernel/base/include/los_multipledlinkhead_pri.h
+++ b/kernel/common/patchfs/los_partition_utils.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -28,43 +28,46 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _LOS_PARTITION_UTILS_H
+#define _LOS_PARTITION_UTILS_H
-#ifndef _LOS_MULTIPLE_DLINK_HEAD_PRI_H
-#define _LOS_MULTIPLE_DLINK_HEAD_PRI_H
-
+#include "menuconfig.h"
+#include "los_typedef.h"
#include "los_base.h"
-#include "los_list.h"
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+#define BYTES_PER_MBYTE 0x100000
+#define BYTES_PER_KBYTE 0x400
+#define DEC_NUMBER_STRING "0123456789"
+#define HEX_NUMBER_STRING "0123456789abcdefABCDEF"
-#define OS_MAX_MULTI_DLNK_LOG2 30
-#define OS_MIN_MULTI_DLNK_LOG2 4
-#define OS_MULTI_DLNK_NUM ((OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2) + 1)
-#define OS_DLNK_HEAD_SIZE OS_MULTI_DLNK_HEAD_SIZE
-#define OS_MULTI_DLNK_HEAD_SIZE sizeof(LosMultipleDlinkHead)
+#define COMMAND_LINE_ADDR LOSCFG_BOOTENV_ADDR * BYTES_PER_KBYTE
+#define COMMAND_LINE_SIZE 1024
-typedef struct {
- LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM];
-} LosMultipleDlinkHead;
+#if defined(LOSCFG_STORAGE_SPINOR)
+#define FLASH_TYPE "spinor"
+#define STORAGE_TYPE "flash"
+#define FS_TYPE "jffs2"
+#else
+#define STORAGE_TYPE "emmc"
+#endif
-STATIC INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listNodeHead)
-{
- LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
+struct PartitionInfo {
+ const CHAR *partName;
+ const CHAR *cmdlineArgName;
+ const CHAR *storageTypeArgName;
+ CHAR *storageType;
+ const CHAR *fsTypeArgName;
+ CHAR *fsType;
+ const CHAR *addrArgName;
+ INT32 startAddr;
+ const CHAR *partSizeArgName;
+ INT32 partSize;
+ CHAR *devName;
+ UINT32 partNum;
+};
- return (&head->listHead[OS_MULTI_DLNK_NUM - 1] == listNodeHead) ? NULL : (listNodeHead + 1);
-}
+INT32 GetPartitionInfo(struct PartitionInfo *partInfo);
+const CHAR *GetDevNameOfPartition(const struct PartitionInfo *partInfo);
+INT32 ResetDevNameofPartition(const struct PartitionInfo *partInfo);
-extern VOID OsDLnkInitMultiHead(VOID *headAddr);
-extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size);
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif /* _LOS_MULTIPLE_DLINK_HEAD_PRI_H */
+#endif /* _LOS_PARTITION_UTILS_H */
diff --git a/kernel/common/patchfs/los_patchfs.c b/kernel/common/patchfs/los_patchfs.c
new file mode 100755
index 00000000..fa1012c4
--- /dev/null
+++ b/kernel/common/patchfs/los_patchfs.c
@@ -0,0 +1,101 @@
+/*
+ * 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_patchfs.h"
+#include "los_partition_utils.h"
+
+#include "sys/mount.h"
+#include "inode/inode.h"
+
+#ifdef LOSCFG_PLATFORM_PATCHFS
+
+INT32 OsMountPatchFs(VOID)
+{
+ INT32 ret;
+ struct PartitionInfo partInfo = {
+ PATCHPART_NAME, PATCH_CMDLINE_ARGNAME,
+ PATCH_STORAGE_ARGNAME, NULL,
+ PATCH_FSTYPE_ARGNAME, NULL,
+ PATCH_ADDR_ARGNAME, -1,
+ PATCH_SIZE_ARGNAME, -1,
+ NULL, PATCH_PARTITIONNUM
+ };
+
+#ifdef LOSCFG_SECURITY_BOOT
+ partInfo.storageType = strdup(STORAGE_TYPE);
+ if (partInfo.storageType == NULL) {
+ return LOS_NOK;
+ }
+ partInfo.fsType = strdup(FS_TYPE);
+ if (partInfo.fsType == NULL) {
+ return LOS_NOK;
+ }
+ partInfo.startAddr = PATCHFS_FLASH_ADDR;
+ partInfo.partSize = PATCHFS_FLASH_SIZE;
+#else
+ ret = GetPartitionInfo(&partInfo);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+ partInfo.startAddr = (partInfo.startAddr >= 0) ? partInfo.startAddr : PATCHFS_FLASH_ADDR;
+ partInfo.partSize = (partInfo.partSize >= 0) ? partInfo.partSize : PATCHFS_FLASH_SIZE;
+#endif
+
+ ret = LOS_NOK;
+ partInfo.devName = strdup(PATCH_FLASH_DEV_NAME);
+ if (partInfo.devName == NULL) {
+ return LOS_NOK;
+ }
+ const CHAR *devName = GetDevNameOfPartition(&partInfo);
+ if (devName != NULL) {
+ ret = mkdir(PATCHFS_MOUNT_POINT, 0);
+ if (ret == LOS_OK) {
+ ret = mount(devName, PATCHFS_MOUNT_POINT, partInfo.fsType, MS_RDONLY, NULL);
+ if (ret != LOS_OK) {
+ int err = get_errno();
+ PRINT_ERR("Failed to mount %s, errno %d: %s\n", partInfo.partName, err, strerror(err));
+ }
+ } else {
+ int err = get_errno();
+ PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", PATCHFS_MOUNT_POINT, err, strerror(err));
+ }
+ }
+
+ if ((ret != LOS_OK) && (devName != NULL)) {
+ ResetDevNameofPartition(&partInfo);
+ }
+
+ free(partInfo.devName);
+ free(partInfo.storageType);
+ free(partInfo.fsType);
+ return ret;
+}
+
+#endif // LOSCFG_PLATFORM_PATCHFS
diff --git a/kernel/common/patchfs/los_patchfs.h b/kernel/common/patchfs/los_patchfs.h
new file mode 100644
index 00000000..72e3e876
--- /dev/null
+++ b/kernel/common/patchfs/los_patchfs.h
@@ -0,0 +1,66 @@
+/*
+ * 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_PATCHFS_H
+#define _LOS_PATCHFS_H
+
+#include "los_typedef.h"
+#include "los_base.h"
+
+#define __stringify_1(x...) #x
+#define __stringify(x...) __stringify_1(x)
+
+#define PATCH_PARTITIONNUM 1
+#ifdef TEE_ENABLE
+#define PATCHFS_FLASH_ADDR 0xC00000
+#define PATCHFS_FLASH_SIZE 0x200000
+#else
+#define PATCHFS_FLASH_ADDR 0xD00000
+#define PATCHFS_FLASH_SIZE 0x300000
+#endif
+
+#if defined(LOSCFG_STORAGE_SPINOR)
+#define PATCH_FLASH_DEV_NAME "/dev/spinorblk"__stringify(PATCH_PARTITIONNUM)
+#else
+#define PATCH_FLASH_DEV_NAME "/dev/mmcblk"__stringify(PATCH_PARTITIONNUM)
+#endif
+
+#define PATCHFS_MOUNT_POINT "/patch"
+
+#define PATCHPART_NAME "patchfs"
+#define PATCH_CMDLINE_ARGNAME "patchfs="
+#define PATCH_STORAGE_ARGNAME "patch="
+#define PATCH_FSTYPE_ARGNAME "patchfstype="
+#define PATCH_ADDR_ARGNAME "patchaddr="
+#define PATCH_SIZE_ARGNAME "patchsize="
+
+INT32 OsMountPatchFs(VOID);
+
+#endif /* _LOS_PATCHFS_H */
diff --git a/kernel/common/sys_config.h b/kernel/common/sys_config.h
old mode 100644
new mode 100755
index 184ea766..7e38fc8a
--- a/kernel/common/sys_config.h
+++ b/kernel/common/sys_config.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -51,10 +51,6 @@ extern "C" {
#define LWIP_BSD_API 1
#endif
-#ifdef LOSCFG_DEBUG_VERSION
-#define LOSCFG_MEM_WATERLINE
-#endif
-
#ifdef LOSCFG_DRIVERS_USB
#define SUPPORT_LOS_USB_NEW_DRIVER
#define USB_DEBUG_VAR 5
diff --git a/kernel/common/virtual_serial.c b/kernel/common/virtual_serial.c
old mode 100644
new mode 100755
index 9dae4ee9..d8def05d
--- a/kernel/common/virtual_serial.c
+++ b/kernel/common/virtual_serial.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,7 +38,6 @@
#include "inode/inode.h"
#include "console.h"
#endif
-#include "uart.h"
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/common/virtual_serial.h b/kernel/common/virtual_serial.h
index f7162b79..ceefe83d 100644
--- a/kernel/common/virtual_serial.h
+++ b/kernel/common/virtual_serial.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/cppsupport/Makefile b/kernel/extended/cppsupport/Makefile
index 671f9e84..826bd05a 100644
--- a/kernel/extended/cppsupport/Makefile
+++ b/kernel/extended/cppsupport/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/cppsupport/los_cppsupport.c b/kernel/extended/cppsupport/los_cppsupport.c
old mode 100644
new mode 100755
index 0ff60e0f..7c17d995
--- a/kernel/extended/cppsupport/los_cppsupport.c
+++ b/kernel/extended/cppsupport/los_cppsupport.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/cpup/Makefile b/kernel/extended/cpup/Makefile
index 3ccf9877..61b09029 100644
--- a/kernel/extended/cpup/Makefile
+++ b/kernel/extended/cpup/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/cpup/cpup_shellcmd.c b/kernel/extended/cpup/cpup_shellcmd.c
old mode 100644
new mode 100755
index 68ecfa87..cbff72cc
--- a/kernel/extended/cpup/cpup_shellcmd.c
+++ b/kernel/extended/cpup/cpup_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/cpup/los_cpup.c b/kernel/extended/cpup/los_cpup.c
old mode 100644
new mode 100755
index 9436e8a5..131e00d2
--- a/kernel/extended/cpup/los_cpup.c
+++ b/kernel/extended/cpup/los_cpup.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -42,19 +42,21 @@ extern "C" {
#ifdef LOSCFG_KERNEL_CPUP
-LITE_OS_SEC_BSS STATIC UINT16 swtmrID;
+LITE_OS_SEC_BSS STATIC UINT16 cpupSwtmrID;
LITE_OS_SEC_BSS STATIC UINT16 cpupInitFlg = 0;
-LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
+LITE_OS_SEC_BSS OsIrqCpupCB *g_irqCpup = NULL;
LITE_OS_SEC_BSS STATIC UINT16 cpupMaxNum;
-LITE_OS_SEC_BSS STATIC UINT16 hisPos = 0; /* current Sampling point of historyTime */
+LITE_OS_SEC_BSS STATIC UINT16 cpupHisPos = 0; /* current Sampling point of historyTime */
LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM + 1];
-
-LITE_OS_SEC_BSS STATIC UINT64 startCycles = 0;
+LITE_OS_SEC_BSS STATIC UINT32 runningTasks[LOSCFG_KERNEL_CORE_NUM];
+LITE_OS_SEC_BSS STATIC UINT64 cpupStartCycles = 0;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
-LITE_OS_SEC_BSS STATIC UINT64 timeInIrqPerProcessSwitch[LOSCFG_KERNEL_CORE_NUM];
-LITE_OS_SEC_BSS STATIC UINT64 intTimeStart[LOSCFG_KERNEL_CORE_NUM];
+LITE_OS_SEC_BSS UINT64 timeInIrqSwitch[LOSCFG_KERNEL_CORE_NUM];
+LITE_OS_SEC_BSS STATIC UINT64 cpupIntTimeStart[LOSCFG_KERNEL_CORE_NUM];
#endif
+#define INVALID_ID ((UINT32)-1)
+
#define OS_CPUP_UNUSED 0x0U
#define OS_CPUP_USED 0x1U
#define HIGH_BITS 32
@@ -62,33 +64,76 @@ LITE_OS_SEC_BSS STATIC UINT64 intTimeStart[LOSCFG_KERNEL_CORE_NUM];
#define CPUP_PRE_POS(pos) (((pos) == 0) ? (OS_CPUP_HISTORY_RECORD_NUM - 1) : ((pos) - 1))
#define CPUP_POST_POS(pos) (((pos) == (OS_CPUP_HISTORY_RECORD_NUM - 1)) ? 0 : ((pos) + 1))
+STATIC UINT64 OsGetCpuCycle(VOID)
+{
+ UINT32 high;
+ UINT32 low;
+ UINT64 cycles;
+
+ LOS_GetCpuCycle(&high, &low);
+ cycles = ((UINT64)high << HIGH_BITS) + low;
+ if (cpupStartCycles == 0) {
+ cpupStartCycles = cycles;
+ }
+
+ /*
+ * The cycles should keep growing, if the checking failed,
+ * it mean LOS_GetCpuCycle has the problem which should be fixed.
+ */
+ LOS_ASSERT(cycles >= cpupStartCycles);
+
+ return (cycles - cpupStartCycles);
+}
+
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
{
UINT16 prevPos;
- UINT16 loop;
- UINT32 pid;
+ UINT32 loop;
+ UINT32 runTaskID;
UINT32 intSave;
- UINT64 curCycle;
+ UINT64 cycle, cycleIncrement;
+ LosTaskCB *taskCB = NULL;
+ LosProcessCB *processCB = NULL;
SCHEDULER_LOCK(intSave);
- curCycle = OsGetCpuCycle();
- prevPos = hisPos;
- hisPos = CPUP_POST_POS(hisPos);
- cpuHistoryTime[prevPos] = curCycle;
+ cycle = OsGetCpuCycle();
+ prevPos = cpupHisPos;
+ cpupHisPos = CPUP_POST_POS(cpupHisPos);
+ cpuHistoryTime[prevPos] = cycle;
+#ifdef LOSCFG_CPUP_INCLUDE_IRQ
for (loop = 0; loop < cpupMaxNum; loop++) {
- g_cpup[loop].historyTime[prevPos] = g_cpup[loop].allTime;
+ g_irqCpup[loop].cpup.historyTime[prevPos] = g_irqCpup[loop].cpup.allTime;
+ }
+#endif
+
+ for (loop = 0; loop < g_processMaxNum; loop++) {
+ processCB = OS_PCB_FROM_PID(loop);
+ processCB->processCpup.historyTime[prevPos] = processCB->processCpup.allTime;
+ }
+
+ for (loop = 0; loop < g_taskMaxNum; loop++) {
+ taskCB = OS_TCB_FROM_TID(loop);
+ taskCB->taskCpup.historyTime[prevPos] = taskCB->taskCpup.allTime;
}
for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
- pid = OsCpuProcessIDGetUnsafe(loop);
+ runTaskID = runningTasks[loop];
+ if (runTaskID == INVALID_ID) {
+ continue;
+ }
+ taskCB = OS_TCB_FROM_TID(runTaskID);
+
/* reacquire the cycle to prevent flip */
- curCycle = OsGetCpuCycle();
- g_cpup[pid].historyTime[prevPos] += curCycle - g_cpup[pid].startTime;
+ cycle = OsGetCpuCycle();
+ cycleIncrement = cycle - taskCB->taskCpup.startTime;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- g_cpup[pid].historyTime[prevPos] -= timeInIrqPerProcessSwitch[loop];
+ cycleIncrement -= timeInIrqSwitch[loop];
#endif
+ taskCB->taskCpup.historyTime[prevPos] += cycleIncrement;
+ processCB = OS_PCB_FROM_PID(taskCB->processID);
+ processCB->processCpup.historyTime[prevPos] += cycleIncrement;
}
SCHEDULER_UNLOCK(intSave);
@@ -97,9 +142,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuardCreator(VOID)
{
(VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
- (SWTMR_PROC_FUNC)OsCpupGuard, &swtmrID, 0);
+ (SWTMR_PROC_FUNC)OsCpupGuard, &cpupSwtmrID, 0);
- (VOID)LOS_SwtmrStart(swtmrID);
+ (VOID)LOS_SwtmrStart(cpupSwtmrID);
}
/*
@@ -108,207 +153,114 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuardCreator(VOID)
*/
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit(VOID)
{
+ UINT16 loop;
+#ifdef LOSCFG_CPUP_INCLUDE_IRQ
UINT32 size;
- cpupMaxNum = LOSCFG_BASE_CORE_PROCESS_LIMIT;
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- cpupMaxNum += OS_HWI_MAX_NUM;
-#endif
+ cpupMaxNum = OS_HWI_MAX_NUM;
/* every process has only one record, and it won't operated at the same time */
- size = cpupMaxNum * sizeof(OsCpupCB);
- g_cpup = (OsCpupCB *)LOS_MemAlloc(m_aucSysMem0, size);
- if (g_cpup == NULL) {
+ size = cpupMaxNum * sizeof(OsIrqCpupCB);
+ g_irqCpup = (OsIrqCpupCB *)LOS_MemAlloc(m_aucSysMem0, size);
+ if (g_irqCpup == NULL) {
return LOS_ERRNO_CPUP_NO_MEMORY;
}
- (VOID)memset_s(g_cpup, size, 0, size);
+ (VOID)memset_s(g_irqCpup, size, 0, size);
+#endif
+
+ for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
+ runningTasks[loop] = INVALID_ID;
+ }
cpupInitFlg = 1;
return LOS_OK;
}
-LITE_OS_SEC_TEXT VOID OsCpupSet(UINT32 id)
+STATIC VOID OsResetCpup(OsCpupBase *cpup, UINT64 cycle)
{
- g_cpup[id].id = id;
- g_cpup[id].status = OS_CPUP_USED;
-}
+ UINT16 loop;
-LITE_OS_SEC_TEXT VOID OsCpupClean(UINT32 id)
-{
- (VOID)memset_s((VOID *)&g_cpup[id], sizeof(OsCpupCB), 0, sizeof(OsCpupCB));
+ cpup->startTime = cycle;
+ cpup->allTime = cycle;
+ for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) {
+ cpup->historyTime[loop] = cycle;
+ }
}
LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset(VOID)
{
- UINT32 cpupIndex;
- UINT32 maxNum = cpupMaxNum;
- UINT16 loop;
- UINT64 curCycle;
+ LosProcessCB *processCB = NULL;
+ LosTaskCB *taskCB = NULL;
+ UINT32 index;
+ UINT64 cycle;
UINT32 intSave;
- if (g_cpup == NULL) {
- return;
- }
-
cpupInitFlg = 0;
intSave = LOS_IntLock();
- (VOID)LOS_SwtmrStop(swtmrID);
- curCycle = OsGetCpuCycle();
+ (VOID)LOS_SwtmrStop(cpupSwtmrID);
+ cycle = OsGetCpuCycle();
- for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) {
- cpuHistoryTime[loop] = curCycle;
+ for (index = 0; index < (OS_CPUP_HISTORY_RECORD_NUM + 1); index++) {
+ cpuHistoryTime[index] = cycle;
}
- for (cpupIndex = 0; cpupIndex < maxNum; cpupIndex++) {
- g_cpup[cpupIndex].startTime = curCycle;
- g_cpup[cpupIndex].allTime = curCycle;
- for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) {
- g_cpup[cpupIndex].historyTime[loop] = curCycle;
- }
+ for (index = 0; index < g_processMaxNum; index++) {
+ processCB = OS_PCB_FROM_PID(index);
+ OsResetCpup(&processCB->processCpup, cycle);
+ }
+
+ for (index = 0; index < g_taskMaxNum; index++) {
+ taskCB = OS_TCB_FROM_TID(index);
+ OsResetCpup(&taskCB->taskCpup, cycle);
}
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
- timeInIrqPerProcessSwitch[loop] = 0;
+ if (g_irqCpup != NULL) {
+ for (index = 0; index < cpupMaxNum; index++) {
+ OsResetCpup(&g_irqCpup[index].cpup, cycle);
+ }
+
+ for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
+ timeInIrqSwitch[index] = 0;
+ }
}
#endif
- (VOID)LOS_SwtmrStart(swtmrID);
+ (VOID)LOS_SwtmrStart(cpupSwtmrID);
LOS_IntRestore(intSave);
cpupInitFlg = 1;
return;
}
-LITE_OS_SEC_TEXT_MINOR VOID OsSetCpuCycle(UINT64 cycles)
+VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
{
- startCycles = cycles;
- return;
-}
-
-/*
- * Description: get current cycles count
- * Return : current cycles count
- */
-LITE_OS_SEC_TEXT_MINOR UINT64 OsGetCpuCycle(VOID)
-{
- UINT32 high;
- UINT32 low;
- UINT64 cycles;
-
- LOS_GetCpuCycle(&high, &low);
- cycles = ((UINT64)high << HIGH_BITS) + low;
- if (startCycles == 0) {
- startCycles = cycles;
- }
-
- /*
- * The cycles should keep growing, if the checking failed,
- * it mean LOS_GetCpuCycle has the problem which should be fixed.
- */
- LOS_ASSERT(cycles >= startCycles);
-
- return (cycles - startCycles);
-}
-
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
-STATIC VOID OsRemoveInterTimeFromPorcess(UINT32 runPID)
-{
- UINT16 loop;
- UINT32 pid;
-
- for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
- pid = OsCpuProcessIDGetUnsafe(loop);
- if (pid != runPID) {
- continue;
- }
-
- g_cpup[runPID].allTime -= timeInIrqPerProcessSwitch[loop];
- timeInIrqPerProcessSwitch[loop] = 0;
- }
-}
-#endif
-
-/*
- * Description: start process to get cycles count in current process begining
- */
-LITE_OS_SEC_TEXT_MINOR STATIC VOID OsProcessCycleStart(VOID)
-{
- UINT32 pid;
+ /* OsCurrTaskGet and OsCurrProcessGet are not allowed to be called. */
+ LosTaskCB *runTask = OS_TCB_FROM_TID(runTaskID);
+ OsCpupBase *runTaskCpup = &runTask->taskCpup;
+ OsCpupBase *newTaskCpup = (OsCpupBase *)&(OS_TCB_FROM_TID(newTaskID)->taskCpup);
+ OsCpupBase *processCpup = (OsCpupBase *)&(OS_PCB_FROM_PID(runTask->processID)->processCpup);
+ UINT64 cpuCycle, cycleIncrement;
+ UINT16 cpuID = ArchCurrCpuid();
if (cpupInitFlg == 0) {
return;
}
- pid = LOS_GetCurrProcessID();
- g_cpup[pid].id = pid;
- g_cpup[pid].startTime = OsGetCpuCycle();
-
- return;
-}
-
-/*
- * Description: quit process and get cycle count
- */
-LITE_OS_SEC_TEXT_MINOR STATIC VOID OsProcessCycleEnd(VOID)
-{
- UINT16 runTaskCount;
- UINT32 runPID;
- UINT64 cpuCycle;
- LosProcessCB *runProcess = NULL;
-
- if (cpupInitFlg == 0) {
- return;
- }
-
- runProcess = OsCurrProcessGet();
- runPID = runProcess->processID;
- if (g_cpup[runPID].startTime == 0) {
- return;
- }
-
cpuCycle = OsGetCpuCycle();
- runTaskCount = OS_PROCESS_GET_RUNTASK_COUNT(runProcess->processStatus);
- g_cpup[runPID].allTime += (cpuCycle - g_cpup[runPID].startTime) * runTaskCount;
+ if (runTaskCpup->startTime != 0) {
+ cycleIncrement = cpuCycle - runTaskCpup->startTime;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- OsRemoveInterTimeFromPorcess(runPID);
+ cycleIncrement -= timeInIrqSwitch[cpuID];
+ timeInIrqSwitch[cpuID] = 0;
#endif
- g_cpup[runPID].startTime = 0;
-
- return;
-}
-
-/*
- * Description: start process to get cycles count in current process ending
- */
-LITE_OS_SEC_TEXT_MINOR VOID OsProcessCycleEndStart(UINT32 newID, UINT16 runTaskCount)
-{
- UINT32 runPID;
- UINT64 cpuCycle;
- OsCpupCB *cpup = NULL;
-
- if (cpupInitFlg == 0) {
- return;
+ runTaskCpup->allTime += cycleIncrement;
+ processCpup->allTime += cycleIncrement;
+ runTaskCpup->startTime = 0;
}
- LOS_ASSERT(runTaskCount != 0);
-
- cpuCycle = OsGetCpuCycle();
- runPID = LOS_GetCurrProcessID();
- cpup = &g_cpup[runPID];
- if (cpup->startTime != 0) {
- cpup->allTime += (cpuCycle - cpup->startTime) * runTaskCount;
- cpup->startTime = cpuCycle;
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- OsRemoveInterTimeFromPorcess(runPID);
-#endif
- }
-
- cpup = &g_cpup[newID];
- cpup->id = newID;
- cpup->startTime = cpuCycle;
-
- return;
+ newTaskCpup->startTime = cpuCycle;
+ runningTasks[cpuID] = newTaskID;
}
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT16 mode, UINT16 *curPosPointer, UINT16 *prePosPointer)
@@ -317,7 +269,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT16 mode, UINT16 *curPosPoint
UINT16 tmpPos;
UINT16 prePos;
- tmpPos = hisPos;
+ tmpPos = cpupHisPos;
curPos = CPUP_PRE_POS(tmpPos);
/*
@@ -344,55 +296,35 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT16 mode, UINT16 *curPosPoint
return;
}
-LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsCpuUsageParaCheck(UINT32 pid)
+STATIC INLINE UINT32 OsCalculateCpupUsage(const OsCpupBase *cpup, UINT16 pos, UINT16 prePos, UINT64 allCycle)
{
- if (cpupInitFlg == 0) {
- return LOS_ERRNO_CPUP_NO_INIT;
- }
+ UINT32 usage = 0;
+ UINT64 cpuCycle = cpup->historyTime[pos] - cpup->historyTime[prePos];
- if (OS_PID_CHECK_INVALID(pid)) {
- return LOS_ERRNO_CPUP_PID_INVALID;
+ if (allCycle) {
+ usage = (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * cpuCycle) / allCycle);
}
-
- /* weather the process is created */
- if (g_cpup[pid].id != pid) {
- return LOS_ERRNO_CPUP_PROCESS_NO_CREATED;
- }
-
- if (g_cpup[pid].status == OS_CPUP_UNUSED) {
- return LOS_ERRNO_CPUP_PROCESS_NO_CREATED;
- }
-
- return LOS_OK;
+ return usage;
}
-LITE_OS_SEC_TEXT UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
+STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
{
- UINT64 cpuCycleAll;
- UINT64 idleCycleAll;
- UINT32 cpup = 0;
+ UINT64 cpuAllCycle;
UINT16 pos;
UINT16 prePos;
- UINT32 idlePID;
+ UINT32 idleProcessID;
+ OsCpupBase *processCpup = NULL;
if (cpupInitFlg == 0) {
return LOS_ERRNO_CPUP_NO_INIT;
}
- OsProcessCycleEnd();
-
OsCpupGetPos(mode, &pos, &prePos);
- cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- idlePID = OsGetIdleProcessID();
- idleCycleAll = g_cpup[idlePID].historyTime[pos] - g_cpup[idlePID].historyTime[prePos];
-
- if (cpuCycleAll) {
- cpup = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * idleCycleAll) / cpuCycleAll));
- }
-
- OsProcessCycleStart();
- return cpup;
+ idleProcessID = OsGetIdleProcessID();
+ processCpup = (OsCpupBase *)&(OS_PCB_FROM_PID(idleProcessID)->processCpup);
+ return (LOS_CPUP_PRECISION - OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle));
}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
@@ -407,33 +339,29 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
return cpup;
}
-LITE_OS_SEC_TEXT UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode)
+STATIC UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode)
{
- UINT64 cpuCycleAll;
- UINT64 cpuCycleCurProcess;
- UINT16 pos;
- UINT16 prePos;
- UINT32 cpup = 0;
- UINT32 ret;
- OsCpupCB *processCpup = &g_cpup[pid];
+ LosProcessCB *processCB = NULL;
+ UINT64 cpuAllCycle;
+ UINT16 pos, prePos;
- ret = OsCpuUsageParaCheck(pid);
- if (ret != LOS_OK) {
- return ret;
+ if (cpupInitFlg == 0) {
+ return LOS_ERRNO_CPUP_NO_INIT;
}
- OsProcessCycleEnd();
+ if (OS_PID_CHECK_INVALID(pid)) {
+ return LOS_ERRNO_CPUP_ID_INVALID;
+ }
+
+ processCB = OS_PCB_FROM_PID(pid);
+ if (OsProcessIsUnused(processCB)) {
+ return LOS_ERRNO_CPUP_NO_CREATED;
+ }
OsCpupGetPos(mode, &pos, &prePos);
- cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- cpuCycleCurProcess = processCpup->historyTime[pos] - processCpup->historyTime[prePos];
- if (cpuCycleAll) {
- cpup = (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * cpuCycleCurProcess) / cpuCycleAll);
- }
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- OsProcessCycleStart();
-
- return cpup;
+ return OsCalculateCpupUsage(&processCB->processCpup, pos, prePos, cpuAllCycle);
}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryProcessCpuUsage(UINT32 pid, UINT16 mode)
@@ -444,81 +372,136 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryProcessCpuUsage(UINT32 pid, UINT16 mode
SCHEDULER_LOCK(intSave);
cpup = OsHistoryProcessCpuUsageUnsafe(pid, mode);
SCHEDULER_UNLOCK(intSave);
-
return cpup;
}
-LITE_OS_SEC_TEXT UINT32 OsAllCpuUsageUnsafe(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag)
+STATIC UINT32 OsHistoryTaskCpuUsageUnsafe(UINT32 tid, UINT16 mode)
{
- UINT16 loop;
- UINT16 index;
- UINT16 pos;
- UINT16 prePos;
- UINT64 cpuCycleAll;
- UINT64 cpuCycleCurProcess;
- UINT16 numTmpMax = maxNum;
- UINT16 numTmpMin = 0;
- UINT16 numMax = g_processMaxNum;
+ LosTaskCB *taskCB = NULL;
+ UINT64 cpuAllCycle;
+ UINT16 pos, prePos;
if (cpupInitFlg == 0) {
- return LOS_ERRNO_CPUP_NO_INIT;
+ return LOS_ERRNO_CPUP_NO_INIT;
}
- if (cpupInfo == NULL) {
- return LOS_ERRNO_CPUP_PROCESS_PTR_NULL;
+ if (OS_TID_CHECK_INVALID(tid)) {
+ return LOS_ERRNO_CPUP_ID_INVALID;
}
- if (maxNum == 0) {
- return LOS_ERRNO_CPUP_MAXNUM_INVALID;
+ taskCB = OS_TCB_FROM_TID(tid);
+ if (OsTaskIsUnused(taskCB)) {
+ return LOS_ERRNO_CPUP_NO_CREATED;
}
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- if (flag == 0) {
- numTmpMax += g_processMaxNum;
- numTmpMin += g_processMaxNum;
- numMax = cpupMaxNum;
- }
-#endif
-
- if (numTmpMax > numMax) {
- numTmpMax = numMax;
- }
-
- OsProcessCycleEnd();
-
OsCpupGetPos(mode, &pos, &prePos);
- cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- for (loop = numTmpMin; loop < numTmpMax; loop++) {
- if (g_cpup[loop].status == OS_CPUP_UNUSED) {
- continue;
- }
+ return OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
+}
- index = loop - numTmpMin;
- cpuCycleCurProcess = g_cpup[loop].historyTime[pos] - g_cpup[loop].historyTime[prePos];
- cpupInfo[index].usStatus = g_cpup[loop].status;
+LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 tid, UINT16 mode)
+{
+ UINT32 intSave;
+ UINT32 cpup;
- if (cpuCycleAll) {
- cpupInfo[index].uwUsage = (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * cpuCycleCurProcess) / cpuCycleAll);
- }
+ SCHEDULER_LOCK(intSave);
+ cpup = OsHistoryTaskCpuUsageUnsafe(tid, mode);
+ SCHEDULER_UNLOCK(intSave);
+ return cpup;
+}
+
+STATIC UINT32 OsCpupUsageParamCheckAndReset(CPUP_INFO_S *cpupInfo, UINT32 len, UINT32 number)
+{
+ if (cpupInitFlg == 0) {
+ return LOS_ERRNO_CPUP_NO_INIT;
}
- OsProcessCycleStart();
+ if ((cpupInfo == NULL) || (len < (sizeof(CPUP_INFO_S) * number))) {
+ return LOS_ERRNO_CPUP_PTR_ERR;
+ }
+
+ (VOID)memset_s(cpupInfo, len, 0, len);
return LOS_OK;
}
-LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag)
+LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
+{
+ LosProcessCB *processCB = NULL;
+ UINT64 cpuAllCycle;
+ UINT16 pos, prePos;
+ UINT32 processID;
+ UINT32 ret;
+
+ ret = OsCpupUsageParamCheckAndReset(cpupInfo, len, g_processMaxNum);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ OsCpupGetPos(mode, &pos, &prePos);
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+
+ for (processID = 0; processID < g_processMaxNum; processID++) {
+ processCB = OS_PCB_FROM_PID(processID);
+ if (OsProcessIsUnused(processCB)) {
+ continue;
+ }
+
+ cpupInfo[processID].usage = OsCalculateCpupUsage(&processCB->processCpup, pos, prePos, cpuAllCycle);
+ cpupInfo[processID].status = OS_CPUP_USED;
+ }
+
+ return LOS_OK;
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllProcessCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
{
UINT32 intSave;
UINT32 ret;
SCHEDULER_LOCK(intSave);
- ret = OsAllCpuUsageUnsafe(maxNum, cpupInfo, mode, flag);
+ ret = OsGetAllProcessCpuUsageUnsafe(mode, cpupInfo, len);
SCHEDULER_UNLOCK(intSave);
-
return ret;
}
+LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
+{
+ UINT64 cpuAllCycle;
+ UINT16 pos, prePos;
+ UINT32 taskID;
+ UINT32 ret;
+ LosTaskCB *taskCB = NULL;
+ OsCpupBase *processCpupBase = NULL;
+ CPUP_INFO_S *processCpup = cpupInfo;
+ CPUP_INFO_S *taskCpup = (CPUP_INFO_S *)((UINTPTR)cpupInfo + sizeof(CPUP_INFO_S) * g_processMaxNum);
+
+ ret = OsCpupUsageParamCheckAndReset(cpupInfo, len, g_taskMaxNum + g_processMaxNum);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ OsCpupGetPos(mode, &pos, &prePos);
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+
+ for (taskID = 0; taskID < g_taskMaxNum; taskID++) {
+ taskCB = OS_TCB_FROM_TID(taskID);
+ if (OsTaskIsUnused(taskCB)) {
+ continue;
+ }
+
+ taskCpup[taskID].usage = OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
+ taskCpup[taskID].status = OS_CPUP_USED;
+ if (processCpup[taskCB->processID].status == OS_CPUP_UNUSED) {
+ processCpupBase = &(OS_PCB_FROM_PID(taskCB->processID)->processCpup);
+ processCpup[taskCB->processID].usage = OsCalculateCpupUsage(processCpupBase, pos, prePos, cpuAllCycle);
+ processCpup[taskCB->processID].status = OS_CPUP_USED;
+ }
+ }
+
+ return LOS_OK;
+}
+
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(VOID)
{
@@ -526,7 +509,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(VOID)
UINT32 low;
LOS_GetCpuCycle(&high, &low);
- intTimeStart[ArchCurrCpuid()] = ((UINT64)high << HIGH_BITS) + low;
+ cpupIntTimeStart[ArchCurrCpuid()] = ((UINT64)high << HIGH_BITS) + low;
return;
}
@@ -540,13 +523,56 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum)
LOS_GetCpuCycle(&high, &low);
intTimeEnd = ((UINT64)high << HIGH_BITS) + low;
- g_cpup[g_processMaxNum + intNum].id = intNum;
- g_cpup[g_processMaxNum + intNum].status = OS_CPUP_USED;
- timeInIrqPerProcessSwitch[cpuID] += (intTimeEnd - intTimeStart[cpuID]);
- g_cpup[g_processMaxNum + intNum].allTime += (intTimeEnd - intTimeStart[cpuID]);
+ g_irqCpup[intNum].id = intNum;
+ g_irqCpup[intNum].status = OS_CPUP_USED;
+ timeInIrqSwitch[cpuID] += (intTimeEnd - cpupIntTimeStart[cpuID]);
+ g_irqCpup[intNum].cpup.allTime += (intTimeEnd - cpupIntTimeStart[cpuID]);
return;
}
+
+LITE_OS_SEC_TEXT_MINOR OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID)
+{
+ return g_irqCpup;
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllIrqCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
+{
+ UINT16 pos, prePos;
+ UINT64 cpuAllCycle;
+ UINT32 loop;
+ UINT32 ret;
+
+ ret = OsCpupUsageParamCheckAndReset(cpupInfo, len, cpupMaxNum);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ OsCpupGetPos(mode, &pos, &prePos);
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+
+ for (loop = 0; loop < cpupMaxNum; loop++) {
+ if (g_irqCpup[loop].status == OS_CPUP_UNUSED) {
+ continue;
+ }
+
+ cpupInfo[loop].usage = OsCalculateCpupUsage(&g_irqCpup[loop].cpup, pos, prePos, cpuAllCycle);
+ cpupInfo[loop].status = g_irqCpup[loop].status;
+ }
+
+ return LOS_OK;
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
+{
+ UINT32 intSave;
+ UINT32 ret;
+
+ SCHEDULER_LOCK(intSave);
+ ret = OsGetAllIrqCpuUsageUnsafe(mode, cpupInfo, len);
+ SCHEDULER_UNLOCK(intSave);
+ return ret;
+}
#endif
#endif /* LOSCFG_KERNEL_CPUP */
diff --git a/kernel/extended/dynload/Makefile b/kernel/extended/dynload/Makefile
index 4b216c0c..28d86ed1 100644
--- a/kernel/extended/dynload/Makefile
+++ b/kernel/extended/dynload/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -34,7 +34,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
- -I $(LITEOSTOPDIR)/kernel/base/include -I $(LITEOSTOPDIR)/kernel/extended/include
+ -I $(LITEOSTOPDIR)/kernel/base/include -I $(LITEOSTOPDIR)/kernel/extended/include \
+ -I $(LITEOSTOPDIR)/fs/include
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
diff --git a/kernel/extended/dynload/include/los_elf_auxvec_pri.h b/kernel/extended/dynload/include/los_elf_auxvec_pri.h
old mode 100644
new mode 100755
index b2e979a6..56a7a34c
--- a/kernel/extended/dynload/include/los_elf_auxvec_pri.h
+++ b/kernel/extended/dynload/include/los_elf_auxvec_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/dynload/include/los_exec_elf.h b/kernel/extended/dynload/include/los_exec_elf.h
old mode 100644
new mode 100755
index c0e17b84..ad8220b0
--- a/kernel/extended/dynload/include/los_exec_elf.h
+++ b/kernel/extended/dynload/include/los_exec_elf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/dynload/include/los_ld_elf_pri.h b/kernel/extended/dynload/include/los_ld_elf_pri.h
old mode 100644
new mode 100755
index 2a5d53fc..39e85949
--- a/kernel/extended/dynload/include/los_ld_elf_pri.h
+++ b/kernel/extended/dynload/include/los_ld_elf_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/dynload/include/los_load_elf.h b/kernel/extended/dynload/include/los_load_elf.h
old mode 100644
new mode 100755
index 237f291c..9912954f
--- a/kernel/extended/dynload/include/los_load_elf.h
+++ b/kernel/extended/dynload/include/los_load_elf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -86,6 +86,15 @@ extern "C" {
#define PF_X 0x1
typedef struct {
+ LD_ELF_EHDR elfEhdr;
+ LD_ELF_PHDR *elfPhdr;
+ UINT32 fileLen;
+ INT32 fd;
+} ELFInfo;
+
+typedef struct {
+ ELFInfo execInfo;
+ ELFInfo interpInfo;
const CHAR *fileName;
CHAR *execName;
INT32 argc;
@@ -100,14 +109,6 @@ typedef struct {
INT32 stackProt;
UINTPTR loadAddr;
UINTPTR elfEntry;
- LD_ELF_EHDR elfEhdr;
- LD_ELF_PHDR *elfPhdr;
- UINT32 execFileLen;
- INT32 execFD;
- LD_ELF_EHDR interpELFEhdr;
- LD_ELF_PHDR *interpELFPhdr;
- UINT32 interpFileLen;
- INT32 interpFD;
UINTPTR topOfMem;
UINTPTR oldFiles;
LosVmSpace *newSpace;
diff --git a/kernel/extended/dynload/src/los_exec_elf.c b/kernel/extended/dynload/src/los_exec_elf.c
old mode 100644
new mode 100755
index a8ef083f..f1934daf
--- a/kernel/extended/dynload/src/los_exec_elf.c
+++ b/kernel/extended/dynload/src/los_exec_elf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -123,8 +123,6 @@ INT32 LOS_DoExecveFile(const CHAR *fileName, CHAR * const *argv, CHAR * const *e
#ifdef LOSCFG_SHELL
CHAR buf[PATH_MAX + 1] = { 0 };
#endif
- VADDR_T *virtTtb = NULL;
- LosVmPage *vmPage = NULL;
if ((fileName == NULL) || ((argv != NULL) && !LOS_IsUserAddress((VADDR_T)(UINTPTR)argv)) ||
((envp != NULL) && !LOS_IsUserAddress((VADDR_T)(UINTPTR)envp))) {
@@ -144,28 +142,11 @@ INT32 LOS_DoExecveFile(const CHAR *fileName, CHAR * const *argv, CHAR * const *e
}
#endif
- loadInfo.newSpace = LOS_MemAlloc(m_aucSysMem0, sizeof(LosVmSpace));
+ loadInfo.newSpace = OsCreateUserVmSapce();
if (loadInfo.newSpace == NULL) {
PRINT_ERR("%s %d, failed to allocate new vm space\n", __FUNCTION__, __LINE__);
return -ENOMEM;
}
- virtTtb = LOS_PhysPagesAllocContiguous(1);
- if (virtTtb == NULL) {
- PRINT_ERR("%s %d, failed to allocate ttb page\n", __FUNCTION__, __LINE__);
- LOS_MemFree(m_aucSysMem0, loadInfo.newSpace);
- return -ENOMEM;
- }
-
- (VOID)memset_s(virtTtb, PAGE_SIZE, 0, PAGE_SIZE);
- ret = OsUserVmSpaceInit(loadInfo.newSpace, virtTtb);
- vmPage = OsVmVaddrToPage(virtTtb);
- if ((ret == FALSE) || (vmPage == NULL)) {
- PRINT_ERR("%s %d, create space failed, ret: %d, vmPage: %#x\n", __FUNCTION__, __LINE__, ret, vmPage);
- LOS_MemFree(m_aucSysMem0, loadInfo.newSpace);
- LOS_PhysPagesFreeContiguous(virtTtb, 1);
- return -ENOMEM;
- }
- LOS_ListAdd(&loadInfo.newSpace->archMmu.ptList, &(vmPage->node));
loadInfo.argv = argv;
loadInfo.envp = envp;
diff --git a/kernel/extended/dynload/src/los_load_elf.c b/kernel/extended/dynload/src/los_load_elf.c
old mode 100644
new mode 100755
index 8602d73a..be5c65ad
--- a/kernel/extended/dynload/src/los_load_elf.c
+++ b/kernel/extended/dynload/src/los_load_elf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,7 +30,9 @@
*/
#include "los_load_elf.h"
+#include "fcntl.h"
#include "fs/fd_table.h"
+#include "fs_file.h"
#include "los_config.h"
#include "los_vm_map.h"
#include "los_vm_syscall.h"
@@ -43,6 +45,26 @@
#include "tzdriver.h"
#endif
+static int OsELFOpen(const CHAR *fileName, INT32 oflags)
+{
+ int ret = -LOS_NOK;
+ int procFd;
+
+ procFd = AllocProcessFd();
+ if (procFd < 0) {
+ return -EMFILE;
+ }
+
+ ret = open(fileName, oflags);
+ if (ret < 0) {
+ FreeProcessFd(procFd);
+ return -get_errno();
+ }
+
+ AssociateSystemFd(procFd, ret);
+ return ret;
+}
+
STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
{
struct stat buf;
@@ -142,170 +164,103 @@ STATIC INT32 OsVerifyELFPhdr(const LD_ELF_PHDR *phdr)
return LOS_OK;
}
-STATIC INT32 OsELFLoadInit(const CHAR *fileName, ELFLoadInfo *loadInfo)
+STATIC VOID OsLoadInit(ELFLoadInfo *loadInfo)
{
- INT32 ret;
#ifdef LOSCFG_FS_VFS
const struct files_struct *oldFiles = OsCurrProcessGet()->files;
loadInfo->oldFiles = (UINTPTR)create_files_snapshot(oldFiles);
#else
loadInfo->oldFiles = NULL;
#endif
- loadInfo->execFD = INVALID_FD;
- loadInfo->interpFD = INVALID_FD;
+ loadInfo->execInfo.fd = INVALID_FD;
+ loadInfo->interpInfo.fd = INVALID_FD;
+}
- ret = OsGetFileLength(&loadInfo->execFileLen, fileName);
+STATIC INT32 OsReadEhdr(const CHAR *fileName, ELFInfo *elfInfo, BOOL isExecFile)
+{
+ INT32 ret;
+
+ ret = OsGetFileLength(&elfInfo->fileLen, fileName);
if (ret != LOS_OK) {
return -ENOENT;
}
- loadInfo->execFD = open(fileName, O_RDONLY | O_EXECVE);
- if (loadInfo->execFD < 0) {
- if (get_errno() == EACCES) {
- return -EACCES;
- }
+ ret = OsELFOpen(fileName, O_RDONLY | O_EXECVE);
+ if (ret < 0) {
PRINT_ERR("%s[%d], Failed to open ELF file: %s!\n", __FUNCTION__, __LINE__, fileName);
- return -ENOENT;
+ return ret;
}
+ elfInfo->fd = ret;
#ifdef LOSCFG_DRIVERS_TZDRIVER
- ret = fs_getfilep(loadInfo->execFD, &OsCurrProcessGet()->execFile);
- if (ret) {
- PRINT_ERR("%s[%d], Failed to get struct file %s!\n", __FUNCTION__, __LINE__, fileName);
+ if (isExecFile) {
+ ret = fs_getfilep(elfInfo->fd, &OsCurrProcessGet()->execFile);
+ if (ret) {
+ PRINT_ERR("%s[%d], Failed to get struct file %s!\n", __FUNCTION__, __LINE__, fileName);
+ }
}
#endif
- ret = OsReadELFInfo(loadInfo->execFD, (UINT8 *)&loadInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
+ ret = OsReadELFInfo(elfInfo->fd, (UINT8 *)&elfInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return -EIO;
}
- ret = OsVerifyELFEhdr(&loadInfo->elfEhdr, loadInfo->execFileLen);
+ ret = OsVerifyELFEhdr(&elfInfo->elfEhdr, elfInfo->fileLen);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
- return -ENOEXEC;
+ return isExecFile ? -ENOEXEC : -ELIBBAD;
}
return LOS_OK;
}
-STATIC INT32 OsLoadProgramHdrs(ELFLoadInfo *loadInfo)
+STATIC INT32 OsReadPhdrs(ELFInfo *elfInfo, BOOL isExecFile)
{
- LD_ELF_EHDR *elfEhdr = NULL;
- UINT32 size;
- INT32 ret;
-
- if (loadInfo->elfEhdr.elfPhNum < 1) {
- PRINT_ERR("%s[%d], No program sections in file: %s!\n", __FUNCTION__, __LINE__, loadInfo->fileName);
- return -ENOEXEC;
- }
-
- elfEhdr = &loadInfo->elfEhdr;
- if (elfEhdr->elfPhEntSize != sizeof(LD_ELF_PHDR)) {
- PRINT_ERR("%s[%d], e_phentsize is invalid, file: %s\n", __FUNCTION__, __LINE__, loadInfo->fileName);
- return -ENOEXEC;
- }
-
- size = sizeof(LD_ELF_PHDR) * elfEhdr->elfPhNum;
- if ((elfEhdr->elfPhoff + size) > loadInfo->execFileLen) {
- PRINT_ERR("%s[%d], Size for program header exceeds limit! file: %s\n", __FUNCTION__, __LINE__,
- loadInfo->fileName);
- return -ENOEXEC;
- }
-
- loadInfo->elfPhdr = LOS_MemAlloc(m_aucSysMem0, size);
- if (loadInfo->elfPhdr == NULL) {
- PRINT_ERR("%s[%d], Failed to allocate for elfPhdr! file: %s\n", __FUNCTION__, __LINE__, loadInfo->fileName);
- return -ENOMEM;
- }
-
- ret = OsReadELFInfo(loadInfo->execFD, (UINT8 *)loadInfo->elfPhdr, size, elfEhdr->elfPhoff);
- if (ret != LOS_OK) {
- (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->elfPhdr);
- loadInfo->elfPhdr = NULL;
- PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
- return -EIO;
- }
-
- return LOS_OK;
-}
-
-STATIC INT32 OsGetInterpEhdr(const CHAR *fileName, ELFLoadInfo *loadInfo)
-{
- INT32 ret;
-
- ret = OsGetFileLength(&loadInfo->interpFileLen, fileName);
- if (ret != LOS_OK) {
- return -ENOENT;
- }
-
- loadInfo->interpFD = open(fileName, O_RDONLY);
- if (loadInfo->interpFD < 0) {
- PRINT_ERR("%s[%d], Failed to open ELF file: %s!\n", __FUNCTION__, __LINE__, fileName);
- return -ENOENT;
- }
-
- ret = OsReadELFInfo(loadInfo->interpFD, (UINT8 *)&loadInfo->interpELFEhdr, sizeof(LD_ELF_EHDR), 0);
- if (ret != LOS_OK) {
- PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
- return -EIO;
- }
-
- ret = OsVerifyELFEhdr(&loadInfo->interpELFEhdr, loadInfo->interpFileLen);
- if (ret != LOS_OK) {
- PRINT_ERR("%s[%d], ELF header of file: %s is invalid!\n", __FUNCTION__, __LINE__, fileName);
- return -ELIBBAD;
- }
-
- return LOS_OK;
-}
-
-STATIC INT32 OsLoadInterpProgramHdrs(ELFLoadInfo *loadInfo)
-{
- LD_ELF_EHDR *elfEhdr = &loadInfo->interpELFEhdr;
+ LD_ELF_EHDR *elfEhdr = &elfInfo->elfEhdr;
UINT32 size;
INT32 ret;
if (elfEhdr->elfPhNum < 1) {
- PRINT_ERR("%s[%d], No program sections of interpreter!\n", __FUNCTION__, __LINE__);
- return -ELIBBAD;
+ goto OUT;
}
if (elfEhdr->elfPhEntSize != sizeof(LD_ELF_PHDR)) {
- PRINT_ERR("%s[%d], e_phentsize of interpreter is invalid!\n", __FUNCTION__, __LINE__);
- return -ELIBBAD;
+ goto OUT;
}
size = sizeof(LD_ELF_PHDR) * elfEhdr->elfPhNum;
- if ((elfEhdr->elfPhoff + size) > loadInfo->interpFileLen) {
- PRINT_ERR("%s[%d], Size for program header of interpreter exceeds limit!\n", __FUNCTION__, __LINE__);
- return -ELIBBAD;
+ if ((elfEhdr->elfPhoff + size) > elfInfo->fileLen) {
+ goto OUT;
}
- loadInfo->interpELFPhdr = LOS_MemAlloc(m_aucSysMem0, size);
- if (loadInfo->interpELFPhdr == NULL) {
- PRINT_ERR("%s[%d], Failed to allocate for elfPhdr of interpreter!\n", __FUNCTION__, __LINE__);
+ elfInfo->elfPhdr = LOS_MemAlloc(m_aucSysMem0, size);
+ if (elfInfo->elfPhdr == NULL) {
+ PRINT_ERR("%s[%d], Failed to allocate for elfPhdr!\n", __FUNCTION__, __LINE__);
return -ENOMEM;
}
- ret = OsReadELFInfo(loadInfo->interpFD, (UINT8 *)loadInfo->interpELFPhdr, size, elfEhdr->elfPhoff);
+ ret = OsReadELFInfo(elfInfo->fd, (UINT8 *)elfInfo->elfPhdr, size, elfEhdr->elfPhoff);
if (ret != LOS_OK) {
- (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->interpELFPhdr);
- loadInfo->interpELFPhdr = NULL;
- PRINT_ERR("%s[%d], Failed to read program header of interpreter!\n", __FUNCTION__, __LINE__);
+ (VOID)LOS_MemFree(m_aucSysMem0, elfInfo->elfPhdr);
+ elfInfo->elfPhdr = NULL;
+ PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return -EIO;
}
return LOS_OK;
+OUT:
+ PRINT_ERR("%s[%d], elf file is bad!\n", __FUNCTION__, __LINE__);
+ return isExecFile ? -ENOEXEC : -ELIBBAD;
}
STATIC INT32 OsReadInterpInfo(ELFLoadInfo *loadInfo)
{
- LD_ELF_PHDR *elfPhdr = loadInfo->elfPhdr;
+ LD_ELF_PHDR *elfPhdr = loadInfo->execInfo.elfPhdr;
CHAR *elfInterpName = NULL;
INT32 ret, i;
- for (i = 0; i < loadInfo->elfEhdr.elfPhNum; ++i, ++elfPhdr) {
+ for (i = 0; i < loadInfo->execInfo.elfEhdr.elfPhNum; ++i, ++elfPhdr) {
if (elfPhdr->type != LD_PT_INTERP) {
continue;
}
@@ -315,7 +270,7 @@ STATIC INT32 OsReadInterpInfo(ELFLoadInfo *loadInfo)
}
if ((elfPhdr->fileSize > FILE_PATH_MAX) || (elfPhdr->fileSize < FILE_PATH_MIN) ||
- (elfPhdr->offset + elfPhdr->fileSize > loadInfo->execFileLen)) {
+ (elfPhdr->offset + elfPhdr->fileSize > loadInfo->execInfo.fileLen)) {
PRINT_ERR("%s[%d], The size of file is out of limit!\n", __FUNCTION__, __LINE__);
return -ENOEXEC;
}
@@ -326,7 +281,7 @@ STATIC INT32 OsReadInterpInfo(ELFLoadInfo *loadInfo)
return -ENOMEM;
}
- ret = OsReadELFInfo(loadInfo->execFD, (UINT8 *)elfInterpName, elfPhdr->fileSize, elfPhdr->offset);
+ ret = OsReadELFInfo(loadInfo->execInfo.fd, (UINT8 *)elfInterpName, elfPhdr->fileSize, elfPhdr->offset);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
ret = -EIO;
@@ -339,13 +294,13 @@ STATIC INT32 OsReadInterpInfo(ELFLoadInfo *loadInfo)
goto OUT;
}
- ret = OsGetInterpEhdr(INTERP_FULL_PATH, loadInfo);
+ ret = OsReadEhdr(INTERP_FULL_PATH, &loadInfo->interpInfo, FALSE);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
goto OUT;
}
- ret = OsLoadInterpProgramHdrs(loadInfo);
+ ret = OsReadPhdrs(&loadInfo->interpInfo, FALSE);
if (ret != LOS_OK) {
goto OUT;
}
@@ -478,7 +433,7 @@ STATIC INT32 OsSetBss(const LD_ELF_PHDR *elfPhdr, INT32 fd, UINTPTR bssStart, UI
}
ret = LOS_UserSpaceVmAlloc(OsCurrProcessGet()->vmSpace, PAGE_SIZE, (VOID **)&bssPageStart,
- 0, OsCvtProtFlagsToRegionFlags(elfProt, 0));
+ 0, OsCvtProtFlagsToRegionFlags(elfProt, MAP_FIXED));
if (ret != LOS_OK) {
PRINT_ERR("%s[%d], Failed to do vmm alloc!\n", __FUNCTION__, __LINE__);
return -ENOMEM;
@@ -533,8 +488,11 @@ STATIC INT32 OsMmapELFFile(INT32 fd, const LD_ELF_PHDR *elfPhdr, const LD_ELF_EH
if ((elfProt & PROT_READ) == 0) {
return -ENOEXEC;
}
- elfFlags = MAP_PRIVATE;
+ elfFlags = MAP_PRIVATE | MAP_FIXED;
vAddr = elfPhdrTemp->vAddr;
+ if ((vAddr == 0) && (*loadBase == 0)) {
+ elfFlags &= ~MAP_FIXED;
+ }
mapAddr = OsDoMmapFile(fd, (vAddr + *loadBase), elfPhdrTemp, elfProt, elfFlags, mapSize);
if (!LOS_IsUserAddress((VADDR_T)mapAddr)) {
@@ -553,7 +511,6 @@ STATIC INT32 OsMmapELFFile(INT32 fd, const LD_ELF_PHDR *elfPhdr, const LD_ELF_EH
if ((*loadBase == 0) && (elfEhdr->elfType == LD_ET_DYN)) {
*loadBase = mapAddr;
- elfFlags |= MAP_FIXED;
}
if ((elfPhdrTemp->memSize > elfPhdrTemp->fileSize) && (elfPhdrTemp->flags & PF_W)) {
@@ -575,14 +532,14 @@ STATIC INT32 OsLoadInterpBinary(const ELFLoadInfo *loadInfo, UINTPTR *interpMapB
UINT32 mapSize;
INT32 ret;
- mapSize = OsGetAllocSize(loadInfo->interpELFPhdr, loadInfo->interpELFEhdr.elfPhNum);
+ mapSize = OsGetAllocSize(loadInfo->interpInfo.elfPhdr, loadInfo->interpInfo.elfEhdr.elfPhNum);
if (mapSize == 0) {
PRINT_ERR("%s[%d], Failed to get interp allocation size!\n", __FUNCTION__, __LINE__);
return -EINVAL;
}
- ret = OsMmapELFFile(loadInfo->interpFD, loadInfo->interpELFPhdr, &loadInfo->interpELFEhdr, interpMapBase,
- mapSize, &loadBase);
+ ret = OsMmapELFFile(loadInfo->interpInfo.fd, loadInfo->interpInfo.elfPhdr, &loadInfo->interpInfo.elfEhdr,
+ interpMapBase, mapSize, &loadBase);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return ret;
@@ -765,10 +722,10 @@ STATIC UINT32 OsGetRndOffset(const ELFLoadInfo *loadInfo)
STATIC VOID OsGetStackProt(ELFLoadInfo *loadInfo)
{
- LD_ELF_PHDR *elfPhdrTemp = loadInfo->elfPhdr;
+ LD_ELF_PHDR *elfPhdrTemp = loadInfo->execInfo.elfPhdr;
INT32 i;
- for (i = 0; i < loadInfo->elfEhdr.elfPhNum; ++i, ++elfPhdrTemp) {
+ for (i = 0; i < loadInfo->execInfo.elfEhdr.elfPhNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->type == LD_PT_GNU_STACK) {
loadInfo->stackProt = OsGetProt(elfPhdrTemp->flags);
}
@@ -796,7 +753,7 @@ STATIC INT32 OsSetArgParams(ELFLoadInfo *loadInfo, CHAR *const *argv, CHAR *cons
loadInfo->stackBase = loadInfo->stackTopMax - USER_STACK_SIZE;
loadInfo->stackSize = USER_STACK_SIZE;
loadInfo->stackParamBase = loadInfo->stackTopMax - USER_PARAM_BYTE_MAX;
- vmFlags = OsCvtProtFlagsToRegionFlags(loadInfo->stackProt, 0);
+ vmFlags = OsCvtProtFlagsToRegionFlags(loadInfo->stackProt, MAP_FIXED);
vmFlags |= VM_MAP_REGION_FLAG_STACK;
status = LOS_UserSpaceVmAlloc((VOID *)loadInfo->newSpace, USER_PARAM_BYTE_MAX,
(VOID **)&loadInfo->stackParamBase, 0, vmFlags);
@@ -888,13 +845,13 @@ STATIC INT32 OsMakeArgsStack(ELFLoadInfo *loadInfo, UINTPTR interpMapBase)
vaddr_t vdsoLoadAddr;
#endif
- AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PHDR, loadInfo->loadAddr + loadInfo->elfEhdr.elfPhoff);
+ AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PHDR, loadInfo->loadAddr + loadInfo->execInfo.elfEhdr.elfPhoff);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PHENT, sizeof(LD_ELF_PHDR));
- AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PHNUM, loadInfo->elfEhdr.elfPhNum);
+ AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PHNUM, loadInfo->execInfo.elfEhdr.elfPhNum);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_PAGESZ, PAGE_SIZE);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_BASE, interpMapBase);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_FLAGS, 0);
- AUX_VEC_ENTRY(auxVector, vecIndex, AUX_ENTRY, loadInfo->elfEhdr.elfEntry);
+ AUX_VEC_ENTRY(auxVector, vecIndex, AUX_ENTRY, loadInfo->execInfo.elfEhdr.elfEntry);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_UID, 0);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_EUID, 0);
AUX_VEC_ENTRY(auxVector, vecIndex, AUX_GID, 0);
@@ -924,16 +881,16 @@ STATIC INT32 OsMakeArgsStack(ELFLoadInfo *loadInfo, UINTPTR interpMapBase)
STATIC INT32 OsLoadELFSegment(ELFLoadInfo *loadInfo)
{
- LD_ELF_PHDR *elfPhdrTemp = loadInfo->elfPhdr;
+ LD_ELF_PHDR *elfPhdrTemp = loadInfo->execInfo.elfPhdr;
UINTPTR loadBase = 0;
UINTPTR interpMapBase = 0;
UINT32 mapSize = 0;
INT32 ret;
loadInfo->loadAddr = 0;
- if (loadInfo->elfEhdr.elfType == LD_ET_DYN) {
+ if (loadInfo->execInfo.elfEhdr.elfType == LD_ET_DYN) {
loadBase = EXEC_MMAP_BASE + OsGetRndOffset(loadInfo);
- mapSize = OsGetAllocSize(elfPhdrTemp, loadInfo->elfEhdr.elfPhNum);
+ mapSize = OsGetAllocSize(elfPhdrTemp, loadInfo->execInfo.elfEhdr.elfPhNum);
if (mapSize == 0) {
PRINT_ERR("%s[%d], Failed to get allocation size of file: %s!\n", __FUNCTION__, __LINE__,
loadInfo->fileName);
@@ -941,23 +898,23 @@ STATIC INT32 OsLoadELFSegment(ELFLoadInfo *loadInfo)
}
}
- ret = OsMmapELFFile(loadInfo->execFD, loadInfo->elfPhdr, &loadInfo->elfEhdr, &loadInfo->loadAddr, mapSize,
- &loadBase);
+ ret = OsMmapELFFile(loadInfo->execInfo.fd, loadInfo->execInfo.elfPhdr, &loadInfo->execInfo.elfEhdr,
+ &loadInfo->loadAddr, mapSize, &loadBase);
if (ret != LOS_OK) {
PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
return ret;
}
- if (loadInfo->interpFD != INVALID_FD) {
+ if (loadInfo->interpInfo.fd != INVALID_FD) {
ret = OsLoadInterpBinary(loadInfo, &interpMapBase);
if (ret != LOS_OK) {
return ret;
}
- loadInfo->elfEntry = loadInfo->interpELFEhdr.elfEntry + interpMapBase;
- loadInfo->elfEhdr.elfEntry = loadInfo->elfEhdr.elfEntry + loadBase;
+ loadInfo->elfEntry = loadInfo->interpInfo.elfEhdr.elfEntry + interpMapBase;
+ loadInfo->execInfo.elfEhdr.elfEntry = loadInfo->execInfo.elfEhdr.elfEntry + loadBase;
} else {
- loadInfo->elfEntry = loadInfo->elfEhdr.elfEntry;
+ loadInfo->elfEntry = loadInfo->execInfo.elfEhdr.elfEntry;
}
ret = OsMakeArgsStack(loadInfo, interpMapBase);
@@ -993,23 +950,23 @@ STATIC VOID OsDeInitLoadInfo(ELFLoadInfo *loadInfo)
(VOID)close(loadInfo->randomDevFD);
#endif
- if (loadInfo->elfPhdr != NULL) {
- (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->elfPhdr);
+ if (loadInfo->execInfo.elfPhdr != NULL) {
+ (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->execInfo.elfPhdr);
}
- if (loadInfo->interpELFPhdr != NULL) {
- (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->interpELFPhdr);
+ if (loadInfo->interpInfo.elfPhdr != NULL) {
+ (VOID)LOS_MemFree(m_aucSysMem0, loadInfo->interpInfo.elfPhdr);
}
}
STATIC VOID OsDeInitFiles(ELFLoadInfo *loadInfo)
{
- if (loadInfo->execFD != INVALID_FD) {
- (VOID)close(loadInfo->execFD);
+ if (loadInfo->execInfo.fd != INVALID_FD) {
+ (VOID)close(loadInfo->execInfo.fd);
}
- if (loadInfo->interpFD != INVALID_FD) {
- (VOID)close(loadInfo->interpFD);
+ if (loadInfo->interpInfo.fd != INVALID_FD) {
+ (VOID)close(loadInfo->interpInfo.fd);
}
#ifdef LOSCFG_FS_VFS
delete_files_snapshot((struct files_struct *)loadInfo->oldFiles);
@@ -1020,12 +977,14 @@ INT32 OsLoadELFFile(ELFLoadInfo *loadInfo)
{
INT32 ret;
- ret = OsELFLoadInit(loadInfo->fileName, loadInfo);
+ OsLoadInit(loadInfo);
+
+ ret = OsReadEhdr(loadInfo->fileName, &loadInfo->execInfo, TRUE);
if (ret != LOS_OK) {
goto OUT;
}
- ret = OsLoadProgramHdrs(loadInfo);
+ ret = OsReadPhdrs(&loadInfo->execInfo, TRUE);
if (ret != LOS_OK) {
goto OUT;
}
@@ -1040,7 +999,7 @@ INT32 OsLoadELFFile(ELFLoadInfo *loadInfo)
goto OUT;
}
- (VOID)OsFlushAspace(loadInfo);
+ OsFlushAspace(loadInfo);
ret = OsLoadELFSegment(loadInfo);
if (ret != LOS_OK) {
@@ -1049,7 +1008,7 @@ INT32 OsLoadELFFile(ELFLoadInfo *loadInfo)
goto OUT;
}
- (VOID)OsDeInitLoadInfo(loadInfo);
+ OsDeInitLoadInfo(loadInfo);
return LOS_OK;
diff --git a/kernel/extended/include/los_cpup_pri.h b/kernel/extended/include/los_cpup_pri.h
old mode 100644
new mode 100755
index 7b2c8d56..b19426a2
--- a/kernel/extended/include/los_cpup_pri.h
+++ b/kernel/extended/include/los_cpup_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -46,33 +46,33 @@ extern "C" {
*/
#define OS_CPUP_HISTORY_RECORD_NUM 11
+typedef struct {
+ UINT64 allTime; /**< Total running time */
+ UINT64 startTime; /**< Time before a task is invoked */
+ UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM + 1]; /**< Historical running time, the last one saves zero */
+} OsCpupBase;
+
/**
* @ingroup los_cpup
* Count the CPU usage structures of a task.
*/
typedef struct {
- UINT32 id; /**< Task ID */
- UINT16 status; /**< Task status */
- UINT64 allTime; /**< Total running time */
- UINT64 startTime; /**< Time before a task is invoked */
- UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM + 1]; /**< Historical running time, the last one saves zero */
-} OsCpupCB;
-
-extern OsCpupCB *g_cpup;
+ UINT32 id; /**< irq ID */
+ UINT16 status; /**< irq status */
+ OsCpupBase cpup; /**< irq cpup base */
+} OsIrqCpupCB;
extern UINT32 OsCpupInit(VOID);
extern VOID OsCpupGuardCreator(VOID);
-extern VOID OsSetCpuCycle(UINT64 startCycles);
-extern UINT64 OsGetCpuCycle(VOID);
-extern VOID OsProcessCycleEndStart(UINT32 newID, UINT16 runTaskCount);
-extern VOID OsCpupSet(UINT32 id);
-extern VOID OsCpupClean(UINT32 id);
-extern UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode);
-extern UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode);
-extern UINT32 OsAllCpuUsageUnsafe(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag);
+extern VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID);
+extern UINT32 OsGetAllTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
+extern UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
+extern UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
-VOID OsCpupIrqStart(VOID);
-VOID OsCpupIrqEnd(UINT32);
+extern UINT32 OsGetAllIrqCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
+extern VOID OsCpupIrqStart(VOID);
+extern VOID OsCpupIrqEnd(UINT32);
+extern OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID);
#endif
#ifdef __cplusplus
diff --git a/kernel/extended/include/los_trace_pri.h b/kernel/extended/include/los_trace_pri.h
old mode 100644
new mode 100755
index 3c988797..585ab11a
--- a/kernel/extended/include/los_trace_pri.h
+++ b/kernel/extended/include/los_trace_pri.h
@@ -1,57 +1,71 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LOS_TRACE_PRI_H
-#define LOS_TRACE_PRI_H
-
-#include "los_trace.h"
-#include "los_spinlock.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-typedef struct {
- TraceType type;
- WriteHook inputHook;
-} TraceHook;
-
-UINT32 OsTraceReg(TraceType traceType, WriteHook inHook);
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#endif /* LOS_TRACE_PRI_H */
+/*
+ * 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_TRACE_PRI_H
+#define LOS_TRACE_PRI_H
+
+#include "los_trace.h"
+#include "los_spinlock.h"
+#include "los_seq_buf.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+typedef struct {
+ TraceSwitch onOff;
+ WriteHook inputHook;
+ const CHAR *typeStr;
+} TraceHook;
+
+/*
+ * |1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0|
+ * | |
+ * readIndex writeIndex
+ */
+
+typedef struct {
+ UINT8 *dataBuf;
+ UINT32 bufLen;
+ TraceSwitch onOff;
+ UINT32 writeIndex;
+ UINT32 readIndex;
+} TraceBufferCtl;
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* LOS_TRACE_PRI_H */
diff --git a/kernel/extended/liteipc/Makefile b/kernel/extended/liteipc/Makefile
old mode 100644
new mode 100755
index 398eae4a..3af1a504
--- a/kernel/extended/liteipc/Makefile
+++ b/kernel/extended/liteipc/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/liteipc/hm_liteipc.c b/kernel/extended/liteipc/hm_liteipc.c
old mode 100644
new mode 100755
index af586ac6..c35b4bca
--- a/kernel/extended/liteipc/hm_liteipc.c
+++ b/kernel/extended/liteipc/hm_liteipc.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,10 +35,12 @@
#include "los_mp.h"
#include "los_mux.h"
#include "los_process_pri.h"
+#include "los_sched_pri.h"
#include "los_spinlock.h"
#include "los_task_pri.h"
#if (LOSCFG_KERNEL_TRACE == YES)
#include "los_trace.h"
+#include "los_trace_frame.h"
#endif
#include "los_vm_map.h"
#include "los_vm_phys.h"
@@ -104,116 +106,42 @@ STATIC const struct file_operations_vfs g_liteIpcFops = {
};
#if (LOSCFG_KERNEL_TRACE == YES)
+typedef enum {
+ WRITE,
+ WRITE_DROP,
+ TRY_READ,
+ READ,
+ READ_DROP,
+ READ_TIMEOUT,
+ OPERATION_NUM
+} IpcOpertion;
+
const char *g_operStr[OPERATION_NUM] = {"WRITE", "WRITE_DROP", "TRY_READ", "READ", "READ_DROP", "READ_TIMEOUT"};
const char *g_msgTypeStr[MT_NUM] = {"REQUEST", "REPLY", "FAILED_REPLY", "DEATH_NOTIFY"};
const char *g_ipcStatusStr[2] = {"NOT_PEND", "PEND"};
-LITE_OS_SEC_TEXT STATIC UINT16 IpcTraceHook(UINT8 *inputBuffer, UINT32 id, UINT32 msg)
-{
- IpcTraceFrame *ipcInfo = NULL;
- if (inputBuffer == NULL) {
- return 0;
- }
-
- ipcInfo = (IpcTraceFrame *)inputBuffer;
- ipcInfo->idInfo = id;
- ipcInfo->msgInfo = msg;
- ipcInfo->timestamp = LOS_CurrNanosec();
-
- return sizeof(IpcTraceFrame);
-}
-
LITE_OS_SEC_TEXT STATIC VOID IpcTrace(IpcMsg *msg, UINT32 operation, UINT32 ipcStatus, UINT32 msgType)
{
UINT32 curTid = LOS_CurTaskIDGet();
UINT32 curPid = LOS_GetCurrProcessID();
+ UINT32 srcTid;
+ UINT32 srcPid;
UINT32 dstTid;
+ UINT32 dstPid;
UINT32 ret = (msg == NULL) ? INVAILD_ID : GetTid(msg->target.handle, &dstTid);
- IdArg id = {INVAILD_ID, INVAILD_ID, INVAILD_ID, INVAILD_ID};
- MsgArg msgArg;
if (operation <= WRITE_DROP) {
- id.srcTid = curTid;
- id.srcPid = curPid;
- id.dstTid = ret ? INVAILD_ID : dstTid;
- id.dstPid = ret ? INVAILD_ID : OS_TCB_FROM_TID(dstTid)->processID;
+ srcTid = curTid;
+ srcPid = curPid;
+ dstTid = ret ? INVAILD_ID : dstTid;
+ dstPid = ret ? INVAILD_ID : OS_TCB_FROM_TID(dstTid)->processID;
} else {
- id.srcTid = (msg == NULL) ? INVAILD_ID : msg->taskID;
- id.srcPid = (msg == NULL) ? INVAILD_ID : msg->processID;
- id.dstTid = curTid;
- id.dstPid = curPid;
- }
- msgArg.msgType = msgType;
- msgArg.code = (msg == NULL) ? INVAILD_ID : msg->code;
- msgArg.operation = operation;
- msgArg.ipcStatus = ipcStatus;
-
- VOID *ptr1 = &id;
- VOID *ptr2 = &msgArg;
- LOS_Trace(LOS_TRACE_IPC, *((UINT32 *)ptr1), *((UINT32 *)ptr2));
-}
-
-UINT32 IpcInfoCheck(IpcTraceFrame *ipcInfo)
-{
- MsgArg *msgArg = NULL;
-
- if (ipcInfo == NULL) {
- return LOS_NOK;
- }
-
- msgArg = (MsgArg *)&ipcInfo->msgInfo;
- if ((msgArg->operation >= OPERATION_NUM) ||
- (msgArg->msgType >= MT_NUM)) {
- return LOS_NOK;
- }
-
- return LOS_OK;
-}
-
-LITE_OS_SEC_TEXT STATIC VOID IpcTracePrint(UINT32 cpuID, IpcTraceFrame *ipcInfo)
-{
- IdArg *idArg = (IdArg *)&ipcInfo->idInfo;
- MsgArg *msgArg = (MsgArg *)&ipcInfo->msgInfo;
-
- if (IpcInfoCheck(ipcInfo) != LOS_OK) {
- return;
- }
-
- PRINTK("[LiteIPCTrace]timestamp:%016lld", ipcInfo->timestamp);
- PRINTK(" cpuID:%02d", cpuID);
- PRINTK(" operation:%13s", g_operStr[msgArg->operation]);
- PRINTK(" msgType:%12s", g_msgTypeStr[msgArg->msgType]);
- UINT32 isPend = (msgArg->ipcStatus & IPC_THREAD_STATUS_PEND) == IPC_THREAD_STATUS_PEND;
- PRINTK(" ipcStatus:%9s", g_ipcStatusStr[isPend]);
- PRINTK(" code:%03d", msgArg->code);
- PRINTK(" srcTid:%03d", idArg->srcTid);
- PRINTK(" srcPid:%03d", idArg->srcPid);
- PRINTK(" dstTid:%03d", idArg->dstTid);
- PRINTK(" dstPid:%03d\n", idArg->dstPid);
-}
-
-VOID IpcBacktrace(VOID)
-{
- INT32 pos;
- INT32 i;
- TraceBuffer buff;
- for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
- LOS_TraceBufGet(&buff, i);
- pos = buff.tracePos;
- while (pos >= sizeof(IpcTraceFrame) + LOS_TRACE_TAG_LENGTH) {
- UINT32 *traceType = (UINT32 *)(buff.dataBuf + pos - LOS_TRACE_TAG_LENGTH);
- pos -= sizeof(IpcTraceFrame) + LOS_TRACE_TAG_LENGTH;
- switch (*traceType) {
- case LOS_TRACE_IPC: {
- IpcTraceFrame *ipcInfo = (IpcTraceFrame *)(buff.dataBuf + pos);
- IpcTracePrint(i, ipcInfo);
- break;
- }
- default:
- PRINTK("other module trace\n");
- break;
- }
- }
+ srcTid = (msg == NULL) ? INVAILD_ID : msg->taskID;
+ srcPid = (msg == NULL) ? INVAILD_ID : msg->processID;
+ dstTid = curTid;
+ dstPid = curPid;
}
+ UINT8 code = (msg == NULL) ? INVAILD_ID : (UINT8)msg->code;
+ LOS_Trace(LOS_TRACE_IPC, srcTid, srcPid, dstTid, dstPid, msgType, code, operation, ipcStatus);
}
#endif
@@ -229,7 +157,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LiteIpcInit(VOID)
if (ret != LOS_OK) {
return ret;
}
- ret = (UINT32)register_driver(LITEIPC_DRIVER, &g_liteIpcFops, DRIVER_MODE, NULL);
+ ret = (UINT32)register_driver(LITEIPC_DRIVER, &g_liteIpcFops, LITEIPC_DRIVER_MODE, NULL);
if (ret != LOS_OK) {
PRINT_ERR("register lite_ipc driver failed:%d\n", ret);
}
@@ -238,9 +166,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 LiteIpcInit(VOID)
LOS_ListInit(&(g_ipcUsedNodelist[i]));
}
#if (LOSCFG_KERNEL_TRACE == YES)
- ret = LOS_TraceUserReg(LOS_TRACE_IPC, IpcTraceHook, sizeof(IpcTraceFrame));
+ ret = LOS_TraceReg(LOS_TRACE_IPC, OsIpcTrace, LOS_TRACE_IPC_NAME, LOS_TRACE_ENABLE);
if (ret != LOS_OK) {
- PRINT_ERR("liteipc LOS_TraceUserReg failed:%d\n", ret);
+ PRINT_ERR("liteipc LOS_TraceReg failed:%d\n", ret);
}
#endif
return ret;
@@ -294,7 +222,6 @@ LITE_OS_SEC_TEXT STATIC INT32 DoIpcMmap(LosProcessCB *pcb, LosVmMapRegion *regio
PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
break;
}
- LOS_AtomicInc(&vmPage->refCounts);
}
/* if any failure happened, rollback */
if (i != (region->range.size >> PAGE_SHIFT)) {
@@ -990,7 +917,6 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid)
if (now > msg->timestamp + LITEIPC_TIMEOUT_NS) {
#if (LOSCFG_KERNEL_TRACE == YES)
IpcTrace(msg, WRITE_DROP, 0, msg->type);
- IpcBacktrace();
#endif
PRINT_ERR("A timeout reply, request timestamp:%lld, now:%lld\n", msg->timestamp, now);
return -ETIME;
@@ -1052,7 +978,8 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content)
#endif
if (tcb->ipcStatus & IPC_THREAD_STATUS_PEND) {
tcb->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
- OsTaskWake(tcb);
+ OsTaskWakeClearPendMask(tcb);
+ OsSchedTaskWake(tcb);
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
LOS_Schedule();
@@ -1138,7 +1065,8 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcRead(IpcContent *content)
IpcTrace(NULL, TRY_READ, tcb->ipcStatus, syncFlag ? MT_REPLY : MT_REQUEST);
#endif
tcb->ipcStatus |= IPC_THREAD_STATUS_PEND;
- ret = OsTaskWait(&g_ipcPendlist, timeout, TRUE);
+ OsTaskWaitSetPendMask(OS_TASK_WAIT_LITEIPC, OS_INVALID_VALUE, timeout);
+ ret = OsSchedTaskWait(&g_ipcPendlist, timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
#if (LOSCFG_KERNEL_TRACE == YES)
IpcTrace(NULL, READ_TIMEOUT, tcb->ipcStatus, syncFlag ? MT_REPLY : MT_REQUEST);
diff --git a/kernel/extended/liteipc/hm_liteipc.h b/kernel/extended/liteipc/hm_liteipc.h
old mode 100644
new mode 100755
index 2f02e391..dc9806af
--- a/kernel/extended/liteipc/hm_liteipc.h
+++ b/kernel/extended/liteipc/hm_liteipc.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -45,7 +45,7 @@ extern "C" {
#endif /* __cplusplus */
#define LITEIPC_DRIVER "/dev/lite_ipc"
-#define DRIVER_MODE 0666
+#define LITEIPC_DRIVER_MODE 0644
#define MAX_SERVICE_NUM LOSCFG_BASE_CORE_TSK_LIMIT
#define USE_TIMESTAMP YES
@@ -174,41 +174,6 @@ typedef struct {
#define IPC_THREAD_STATUS_PEND 0x0004U
#define IPC_THREAD_STATUS_STOP 0x0008U
-#if (LOSCFG_KERNEL_TRACE == YES)
-#define LOS_TRACE_IPC 3
-
-typedef enum {
- WRITE,
- WRITE_DROP,
- TRY_READ,
- READ,
- READ_DROP,
- READ_TIMEOUT,
- OPERATION_NUM
-} IpcOpertion;
-
-typedef struct {
- UINT32 srcTid : 8;
- UINT32 srcPid : 8;
- UINT32 dstTid : 8;
- UINT32 dstPid : 8;
-} IdArg;
-
-typedef struct {
- UINT32 msgType : 8;
- UINT32 code : 8;
- UINT32 operation : 8;
- UINT32 ipcStatus : 8;
-} MsgArg;
-
-typedef struct {
- UINT32 idInfo;
- UINT32 msgInfo;
- UINT64 timestamp;
-} IpcTraceFrame;
-#endif
-
-
/* init liteipc driver */
extern UINT32 LiteIpcInit(VOID);
diff --git a/kernel/extended/pipe b/kernel/extended/pipes
similarity index 100%
rename from kernel/extended/pipe
rename to kernel/extended/pipes
diff --git a/kernel/extended/tickless/los_tickless.c b/kernel/extended/tickless/los_tickless.c
deleted file mode 100644
index 48b0d4f8..00000000
--- a/kernel/extended/tickless/los_tickless.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_tickless_pri.h"
-#include "los_hwi.h"
-#include "los_tick_pri.h"
-#include "los_sortlink_pri.h"
-#include "los_swtmr_pri.h"
-#include "los_task_pri.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-STATIC BOOL g_ticklessFlag = FALSE;
-STATIC BOOL g_tickIrqFlag[LOSCFG_KERNEL_CORE_NUM] = {FALSE};
-STATIC volatile UINT32 g_sleepTicks[LOSCFG_KERNEL_CORE_NUM] = {0};
-
-#define OS_GET_CYCLECOMPENSATE(cyclesPre,cyclesCur) (((cyclesPre) > (cyclesCur)) ? \
- ((g_sysClock / g_tickPerSecond) - (cyclesCur)) : (((g_sysClock / g_tickPerSecond) << 1) - (cyclesCur)))
-
-LITE_OS_SEC_TEXT VOID LOS_TicklessEnable(VOID)
-{
- g_ticklessFlag = TRUE;
-}
-
-LITE_OS_SEC_TEXT VOID LOS_TicklessDisable(VOID)
-{
- g_ticklessFlag = FALSE;
-}
-
-LITE_OS_SEC_TEXT BOOL OsTicklessFlagGet(VOID)
-{
- return g_ticklessFlag;
-}
-
-LITE_OS_SEC_TEXT BOOL OsTickIrqFlagGet(VOID)
-{
- return g_tickIrqFlag[ArchCurrCpuid()];
-}
-
-LITE_OS_SEC_TEXT VOID OsTickIrqFlagSet(BOOL tickIrqFlag)
-{
- g_tickIrqFlag[ArchCurrCpuid()] = tickIrqFlag;
-}
-
-LITE_OS_SEC_TEXT UINT32 OsTicklessSleepTickGet(VOID)
-{
- return g_sleepTicks[ArchCurrCpuid()];
-}
-
-LITE_OS_SEC_TEXT VOID OsTicklessSleepTickSet(UINT32 sleeptick)
-{
- g_sleepTicks[ArchCurrCpuid()] = sleeptick;
-}
-
-STATIC INLINE UINT32 OsSleepTicksGet(VOID)
-{
- UINT32 tskSortLinkTicks, swtmrSortLinkTicks, sleepTicks;
-
- UINT32 intSave = LOS_IntLock();
- LOS_SpinLock(&g_taskSpin);
- tskSortLinkTicks = OsSortLinkGetNextExpireTime(&OsPercpuGet()->taskSortLink);
- LOS_SpinUnlock(&g_taskSpin);
- LOS_SpinLock(&g_swtmrSpin);
- swtmrSortLinkTicks = OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink);
- LOS_SpinUnlock(&g_swtmrSpin);
- sleepTicks = (tskSortLinkTicks < swtmrSortLinkTicks) ? tskSortLinkTicks : swtmrSortLinkTicks;
- LOS_IntRestore(intSave);
- return sleepTicks;
-}
-
-LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks)
-{
- UINT32 intSave;
-
- if (sleepTicks == 0) {
- return;
- }
-
- intSave = LOS_IntLock();
- g_tickCount[ArchCurrCpuid()] += (sleepTicks - 1);
- LOS_SpinLock(&g_taskSpin);
- OsSortLinkUpdateExpireTime(sleepTicks, &OsPercpuGet()->taskSortLink);
- LOS_SpinUnlock(&g_taskSpin);
- LOS_SpinLock(&g_swtmrSpin);
- OsSortLinkUpdateExpireTime(sleepTicks, &OsPercpuGet()->swtmrSortLink);
- LOS_SpinUnlock(&g_swtmrSpin);
- LOS_IntRestore(intSave);
-}
-
-VOID OsTicklessUpdate(UINT32 irqnum)
-{
- UINT32 cycles, ticks;
- UINT32 cyclesPertick;
- UINT32 sleepTicks;
- UINT32 intSave = LOS_IntLock();
-
- sleepTicks = OsTicklessSleepTickGet();
- if (sleepTicks == 0) {
- LOS_IntRestore(intSave);
- return;
- }
-
- cyclesPertick = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND;
- if (irqnum == OS_TICK_INT_NUM) {
- OsSysTimeUpdate(sleepTicks);
- } else {
- cycles = HalClockGetTickTimerCycles();
- cycles = (sleepTicks * cyclesPertick) - cycles;
- ticks = cycles / cyclesPertick;
- if (ticks < sleepTicks) {
- cycles = cycles % cyclesPertick;
- OsSysTimeUpdate(ticks + 1);
- HalClockTickTimerReload(cyclesPertick - cycles);
- } else {
- /*
- * If ticks is greater or equal to sleepTicks, it means the tick has already
- * arrived, it should compensate with the sleepTicks just as that will be done
- * in tick handler.
- */
- OsSysTimeUpdate(sleepTicks);
- }
- }
- OsTicklessSleepTickSet(0);
-
- LOS_IntRestore(intSave);
-}
-
-VOID OsTicklessStart(VOID)
-{
- UINT32 intSave;
- /*
- * The system has already started, the g_sysClock is non-zero and greater or equal to
- * LOSCFG_BASE_CORE_TICK_PER_SECOND (see OsTickInit). So the cyclesPerTick won't be zero.
- */
- UINT32 cyclesPerTick = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND;
- UINT32 maxTicks = OS_NULL_INT / cyclesPerTick;
- UINT32 sleepTicks;
- UINT32 cycles, cyclesPre, cyclesCur, cycleCompensate;
-
- intSave = LOS_IntLock();
- /*
- * The sleep tick may be changed afterwards, cause interrupt has been disabled, the sleep tick
- * may increase but cannot decrease. Thus there's no need to spin here.
- */
- sleepTicks = OsSleepTicksGet();
- cyclesPre = HalClockGetTickTimerCycles();
-
- if (sleepTicks > 1) {
- if (sleepTicks >= maxTicks) {
- sleepTicks = maxTicks;
- }
- cycles = sleepTicks * cyclesPerTick;
- cyclesCur = HalClockGetTickTimerCycles();
- cycleCompensate = OS_GET_CYCLECOMPENSATE(cyclesPre, cyclesCur);
- HalClockTickTimerReload(cycles - cycleCompensate);
- OsTicklessSleepTickSet(sleepTicks);
- LOS_IntRestore(intSave);
-
- return;
- }
- LOS_IntRestore(intSave);
- return;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
diff --git a/kernel/extended/trace/Makefile b/kernel/extended/trace/Makefile
old mode 100644
new mode 100755
index 80e6829f..c6ceffcd
--- a/kernel/extended/trace/Makefile
+++ b/kernel/extended/trace/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/trace/los_trace.c b/kernel/extended/trace/los_trace.c
old mode 100644
new mode 100755
index 2628a435..ad63323a
--- a/kernel/extended/trace/los_trace.c
+++ b/kernel/extended/trace/los_trace.c
@@ -1,250 +1,522 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_trace_pri.h"
-#include "securec.h"
-#include "los_typedef.h"
-#include "los_task_pri.h"
-#include "los_memory.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#if (LOSCFG_KERNEL_TRACE == YES)
-LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_traceSpin);
-#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state))
-#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state))
-
-STATIC SPIN_LOCK_S g_traceCpuSpin[LOSCFG_KERNEL_CORE_NUM];
-#define TRACE_CPU_LOCK(state, cpuID) LOS_SpinLockSave(&g_traceCpuSpin[(cpuID)], &(state))
-#define TRACE_CPU_UNLOCK(state, cpuID) LOS_SpinUnlockRestore(&g_traceCpuSpin[(cpuID)], (state))
-
-STATIC TraceBuffer g_traceBuf[LOSCFG_KERNEL_CORE_NUM];
-STATIC TraceHook *g_traceInfo[LOS_TRACE_TYPE_NUM];
-STATIC UINT16 g_frameSize[LOS_TRACE_TYPE_NUM];
-
-STATIC VOID OsTracePosAdj(UINT16 bufferSize)
-{
- UINT32 cpu = ArchCurrCpuid();
- if ((g_traceBuf[cpu].tracePos == LOS_TRACE_BUFFER_SIZE) ||
- ((g_traceBuf[cpu].tracePos + bufferSize + LOS_TRACE_TAG_LENGTH) > LOS_TRACE_BUFFER_SIZE)) {
- /* When wrap happened, record the postion before wrap */
- g_traceBuf[cpu].traceWrapPos = g_traceBuf[cpu].tracePos;
- g_traceBuf[cpu].tracePos = 0;
- }
-}
-
-STATIC UINT16 OsTaskTrace(UINT8 *inputBuffer, UINT32 newTaskID, UINT32 oldTaskID)
-{
- TaskTraceFrame *taskInfo = NULL;
-
- if (inputBuffer == NULL) {
- return 0;
- }
-
- taskInfo = (TaskTraceFrame *)inputBuffer;
- taskInfo->currentTick = LOS_TickCountGet();
- taskInfo->srcTaskId = oldTaskID;
- taskInfo->destTaskId = newTaskID;
-
- return sizeof(TaskTraceFrame);
-}
-
-STATIC UINT16 OsIntTrace(UINT8 *inputBuffer, UINT32 newIrqNum, UINT32 direFlag)
-{
- IntTraceFrame *interruptInfo = NULL;
- UINT16 useSize = 0;
-
- if (inputBuffer == NULL) {
- return 0;
- }
-
- /* ignore tick and uart interrupts */
- if ((newIrqNum != OS_TICK_INT_NUM) && (newIrqNum != NUM_HAL_INTERRUPT_UART)) {
- useSize = sizeof(IntTraceFrame);
- interruptInfo = (IntTraceFrame *)inputBuffer;
- interruptInfo->currentTick = LOS_TickCountGet();
- interruptInfo->irqNum = newIrqNum;
- interruptInfo->irqDirection = direFlag;
- }
-
- return useSize;
-}
-
-UINT32 OsTraceReg(TraceType traceType, WriteHook inHook)
-{
- TraceHook *traceInfo = NULL;
-
- if (g_traceInfo[traceType]) {
- /* The Buffer has been alocated before */
- traceInfo = g_traceInfo[traceType];
- } else {
- /* First time allocate */
- traceInfo = (TraceHook *)LOS_MemAlloc(m_aucSysMem0, sizeof(TraceHook));
- if (traceInfo == NULL) {
- return LOS_ERRNO_TRACE_NO_MEMORY;
- }
-
- g_traceInfo[traceType] = traceInfo;
- }
-
- traceInfo->type = traceType;
- traceInfo->inputHook = inHook;
-
- return LOS_OK;
-}
-
-UINT32 LOS_TraceInit(VOID)
-{
- UINT32 ret;
- INT32 cpuID;
- UINT32 intSave;
-
- /* Initialize the global variable */
- (VOID)memset_s((VOID *)g_traceInfo, sizeof(g_traceInfo), 0, sizeof(g_traceInfo));
- (VOID)memset_s((VOID *)g_traceBuf, sizeof(g_traceBuf), 0, sizeof(g_traceBuf));
- (VOID)memset_s((VOID *)g_frameSize, sizeof(g_frameSize), 0, sizeof(g_frameSize));
-
- TRACE_LOCK(intSave);
- for (cpuID = 0; cpuID < LOSCFG_KERNEL_CORE_NUM; cpuID++) {
- LOS_SpinInit(&g_traceCpuSpin[cpuID]); /* initialize all buffer spin lock */
- }
-
- g_frameSize[LOS_TRACE_SWITCH] = sizeof(TaskTraceFrame);
- ret = OsTraceReg(LOS_TRACE_SWITCH, OsTaskTrace);
- if (ret != LOS_OK) {
- TRACE_UNLOCK(intSave);
- return ret;
- }
-
- g_frameSize[LOS_TRACE_INTERRUPT] = sizeof(IntTraceFrame);
- ret = OsTraceReg(LOS_TRACE_INTERRUPT, OsIntTrace);
- if (ret != LOS_OK) {
- TRACE_UNLOCK(intSave);
- return ret;
- }
- TRACE_UNLOCK(intSave);
-
- return LOS_OK;
-}
-
-UINT32 LOS_TraceUserReg(TraceType traceType, WriteHook inHook, UINT16 useSize)
-{
- UINT32 intSave;
- UINT32 ret;
-
- if ((traceType <= LOS_TRACE_INTERRUPT) || (traceType >= LOS_TRACE_TYPE_NUM)) {
- return LOS_ERRNO_TRACE_TYPE_INVALID;
- }
-
- if (inHook == NULL) {
- return LOS_ERRNO_TRACE_FUNCTION_NULL;
- }
-
- if ((useSize == 0) || (((UINT32)useSize + LOS_TRACE_TAG_LENGTH) > LOS_TRACE_BUFFER_SIZE)) {
- return LOS_ERRNO_TRACE_MAX_SIZE_INVALID;
- }
-
- TRACE_LOCK(intSave);
- g_frameSize[traceType] = useSize;
- ret = OsTraceReg(traceType, inHook);
- TRACE_UNLOCK(intSave);
-
- return ret;
-}
-
-VOID LOS_Trace(TraceType traceType, UINT32 newID, UINT32 oldID)
-{
- TraceHook *traceInfo = NULL;
- UINT32 intSave, intSaveCpu;
- UINT32 cpu;
- UINT16 useSize;
-
- intSaveCpu = LOS_IntLock();
- cpu = ArchCurrCpuid();
-
- if (traceType < LOS_TRACE_TYPE_NUM) {
- TRACE_CPU_LOCK(intSave, cpu);
- traceInfo = g_traceInfo[traceType];
- if ((traceInfo != NULL) && (traceInfo->inputHook != NULL)) {
- useSize = g_frameSize[traceType];
- OsTracePosAdj(useSize);
- useSize = traceInfo->inputHook(&g_traceBuf[cpu].dataBuf[g_traceBuf[cpu].tracePos], newID, oldID);
- if (useSize) {
- g_traceBuf[cpu].tracePos += useSize;
-
- /* Add tag by trace system, to avoid the user's misuse */
- *(UINTPTR *)&(g_traceBuf[cpu].dataBuf[g_traceBuf[cpu].tracePos]) = (UINTPTR)traceType;
- g_traceBuf[cpu].tracePos += LOS_TRACE_TAG_LENGTH;
- }
- }
- TRACE_CPU_UNLOCK(intSave, cpu);
- }
-
- LOS_IntRestore(intSaveCpu);
-}
-
-INT32 LOS_TraceFrameSizeGet(TraceType traceType)
-{
- if ((traceType < LOS_TRACE_SWITCH) || (traceType >= LOS_TRACE_TYPE_NUM)) {
- return -1;
- }
- return g_frameSize[traceType];
-}
-
-UINT32 LOS_TraceBufGet(TraceBuffer *outputBuf, UINT32 cpuID)
-{
- UINT32 intSave;
-
- if ((outputBuf == NULL) || (cpuID >= LOSCFG_KERNEL_CORE_NUM)) {
- return LOS_NOK;
- }
-
- TRACE_CPU_LOCK(intSave, cpuID);
- if (memcpy_s(outputBuf, sizeof(TraceBuffer), &g_traceBuf[cpuID], sizeof(TraceBuffer)) != EOK) {
- TRACE_CPU_UNLOCK(intSave, cpuID);
- return LOS_NOK;
- }
- TRACE_CPU_UNLOCK(intSave, cpuID);
-
- return LOS_OK;
-}
-
-#endif
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+/*
+ * Copyright (c) 2013-2020, 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_trace_pri.h"
+#include "securec.h"
+#include "los_typedef.h"
+#include "los_task_pri.h"
+#include "ctype.h"
+
+#ifdef LOSCFG_SHELL
+#include "shcmd.h"
+#include "shell.h"
+#include "unistd.h"
+#include "stdlib.h"
+#include "inode/inode.h"
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#ifndef LOSCFG_KERNEL_TRACE
+VOID LOS_TraceInit(VOID)
+{
+ return;
+}
+
+UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff)
+{
+ (VOID)traceType;
+ (VOID)inHook;
+ (VOID)onOff;
+ (VOID)typeStr;
+ return LOS_OK;
+}
+
+UINT32 LOS_TraceUnreg(TraceType traceType)
+{
+ (VOID)traceType;
+ return LOS_OK;
+}
+
+VOID LOS_Trace(TraceType traceType, ...)
+{
+ (VOID)traceType;
+ return;
+}
+
+VOID LOS_TraceSwitch(TraceSwitch onOff)
+{
+ (VOID)onOff;
+}
+
+UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff)
+{
+ (VOID)traceType;
+ (VOID)onOff;
+ return LOS_OK;
+}
+
+VOID LOS_TracePrint(VOID)
+{
+ return;
+}
+
+INT32 LOS_Trace2File(const CHAR *filename)
+{
+ (VOID)filename;
+ return 0;
+}
+
+UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen)
+{
+ (VOID)desLen;
+ (VOID)relLen;
+ return NULL;
+}
+
+#else
+
+SPIN_LOCK_INIT(g_traceSpin);
+#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state))
+#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state))
+
+#define TMP_DATALEN 128
+
+STATIC UINT8 traceBufArray[LOS_TRACE_BUFFER_SIZE];
+STATIC TraceBufferCtl traceBufCtl;
+STATIC TraceHook traceFunc[LOS_TRACE_TYPE_MAX + 1];
+
+VOID LOS_TraceInit(VOID)
+{
+ UINT32 intSave;
+
+ /* Initialize the global variable. */
+ (VOID)memset_s((VOID *)traceBufArray, LOS_TRACE_BUFFER_SIZE, 0, LOS_TRACE_BUFFER_SIZE);
+ (VOID)memset_s(&traceBufCtl, sizeof(traceBufCtl), 0, sizeof(traceBufCtl));
+ (VOID)memset_s((VOID *)traceFunc, sizeof(traceFunc), 0, sizeof(traceFunc));
+
+ TRACE_LOCK(intSave);
+
+ /* Initialize trace contrl. */
+ traceBufCtl.bufLen = LOS_TRACE_BUFFER_SIZE;
+ traceBufCtl.dataBuf = traceBufArray;
+ traceBufCtl.onOff = LOS_TRACE_ENABLE;
+
+ TRACE_UNLOCK(intSave);
+}
+
+UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff)
+{
+ UINT32 intSave;
+ INT32 i;
+
+ if ((traceType < LOS_TRACE_TYPE_MIN) || (traceType > LOS_TRACE_TYPE_MAX)) {
+ return LOS_ERRNO_TRACE_TYPE_INVALID;
+ }
+
+ if (inHook == NULL) {
+ return LOS_ERRNO_TRACE_FUNCTION_NULL;
+ }
+
+ TRACE_LOCK(intSave);
+ /* if inputHook is NULL,return failed. */
+ if (traceFunc[traceType].inputHook != NULL) {
+ PRINT_ERR("Registered Failed!\n");
+ for (i = 0; i <= LOS_TRACE_TYPE_MAX; i++) {
+ if (traceFunc[i].inputHook == NULL) {
+ PRINTK("type:%d ", i);
+ }
+ }
+ PRINTK("could be registered\n");
+ TRACE_UNLOCK(intSave);
+ return LOS_ERRNO_TRACE_TYPE_EXISTED;
+ } else {
+ traceFunc[traceType].inputHook = inHook;
+ traceFunc[traceType].onOff = onOff;
+ traceFunc[traceType].typeStr = typeStr;
+ }
+ TRACE_UNLOCK(intSave);
+ return LOS_OK;
+}
+
+UINT32 LOS_TraceUnreg(TraceType traceType)
+{
+ UINT32 intSave;
+
+ if ((traceType < LOS_TRACE_TYPE_MIN) || (traceType > LOS_TRACE_TYPE_MAX)) {
+ return LOS_ERRNO_TRACE_TYPE_INVALID;
+ }
+
+ TRACE_LOCK(intSave);
+ /* if inputHook is NULL,return failed. */
+ if (traceFunc[traceType].inputHook == NULL) {
+ PRINT_ERR("Trace not exist!\n");
+ TRACE_UNLOCK(intSave);
+ return LOS_ERRNO_TRACE_TYPE_NOT_EXISTED;
+ } else {
+ traceFunc[traceType].inputHook = NULL;
+ traceFunc[traceType].onOff = LOS_TRACE_DISABLE;
+ traceFunc[traceType].typeStr = NULL;
+ }
+ TRACE_UNLOCK(intSave);
+ return LOS_OK;
+}
+
+
+VOID LOS_TraceSwitch(TraceSwitch onOff)
+{
+ traceBufCtl.onOff = onOff;
+}
+
+UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff)
+{
+ UINT32 intSave;
+ if (traceType < LOS_TRACE_TYPE_MIN || traceType > LOS_TRACE_TYPE_MAX) {
+ return LOS_ERRNO_TRACE_TYPE_INVALID;
+ }
+ TRACE_LOCK(intSave);
+ if (traceFunc[traceType].inputHook != NULL) {
+ traceFunc[traceType].onOff = onOff;
+ TRACE_UNLOCK(intSave);
+ return LOS_OK;
+ }
+ TRACE_UNLOCK(intSave);
+ return LOS_ERRNO_TRACE_TYPE_NOT_EXISTED;
+}
+
+STATIC UINT32 OsFindReadFrameHead(UINT32 readIndex, UINT32 dataSize)
+{
+ UINT32 historySize = 0;
+ UINT32 index = readIndex;
+ while (historySize < dataSize) {
+ historySize += ((FrameHead *)&(traceBufCtl.dataBuf[index]))->frameSize;
+ index = readIndex + historySize;
+ if (index >= traceBufCtl.bufLen) {
+ index = index - traceBufCtl.bufLen;
+ }
+ }
+ return index;
+}
+
+STATIC VOID OsAddData2Buf(UINT8 *buf, UINT32 dataSize)
+{
+ UINT32 intSave;
+ UINT32 ret;
+
+ TRACE_LOCK(intSave);
+
+ UINT32 desLen = traceBufCtl.bufLen;
+ UINT32 writeIndex = traceBufCtl.writeIndex;
+ UINT32 readIndex = traceBufCtl.readIndex;
+ UINT32 writeRange = writeIndex + dataSize;
+ UINT8 *des = traceBufCtl.dataBuf + writeIndex;
+
+ /* update readIndex */
+ if ((readIndex > writeIndex) && (writeRange > readIndex)) {
+ traceBufCtl.readIndex = OsFindReadFrameHead(readIndex, writeRange - readIndex);
+ } else if ((readIndex <= writeIndex) && (writeRange > desLen + readIndex)) {
+ traceBufCtl.readIndex = OsFindReadFrameHead(readIndex, writeRange - readIndex - desLen);
+ }
+
+ /* copy the data and update writeIndex */
+ UINT32 tmpLen = desLen - writeIndex;
+ if (tmpLen >= dataSize) {
+ ret = (UINT32)memcpy_s(des, tmpLen, buf, dataSize);
+ if (ret != 0) {
+ goto EXIT;
+ }
+ traceBufCtl.writeIndex = writeIndex + dataSize;
+ } else {
+ ret = (UINT32)memcpy_s(des, tmpLen, buf, tmpLen); /* tmpLen: The length of ringbuf that can be written */
+ if (ret != 0) {
+ goto EXIT;
+ }
+ ret = (UINT32)memcpy_s(traceBufCtl.dataBuf, desLen, buf + tmpLen, dataSize - tmpLen);
+ if (ret != 0) {
+ goto EXIT;
+ }
+ traceBufCtl.writeIndex = dataSize - tmpLen;
+ }
+
+EXIT:
+ TRACE_UNLOCK(intSave);
+}
+
+VOID LOS_Trace(TraceType traceType, ...)
+{
+ va_list ap;
+ if ((traceType > LOS_TRACE_TYPE_MAX) || (traceType < LOS_TRACE_TYPE_MIN) ||
+ (traceFunc[traceType].inputHook == NULL)) {
+ return;
+ }
+ if ((traceBufCtl.onOff == LOS_TRACE_DISABLE) || (traceFunc[traceType].onOff == LOS_TRACE_DISABLE)) {
+ return;
+ }
+ /* Set the trace frame head */
+ UINT8 buf[TMP_DATALEN];
+ FrameHead *frameHead = (FrameHead *)buf;
+ frameHead->type = traceType;
+ frameHead->cpuID = ArchCurrCpuid();
+ frameHead->taskID = LOS_CurTaskIDGet();
+ frameHead->timestamp = HalClockGetCycles();
+
+#ifdef LOSCFG_TRACE_LR
+ /* Get the linkreg from stack fp and storage to frameHead */
+ LOS_RecordLR(frameHead->linkReg, LOSCFG_TRACE_LR_RECORD, LOSCFG_TRACE_LR_RECORD, LOSCFG_TRACE_LR_IGNOR);
+#endif
+
+ /* Get the trace message */
+ va_start(ap, traceType);
+ INT32 dataSize = (traceFunc[traceType].inputHook)(buf + sizeof(FrameHead), TMP_DATALEN - sizeof(FrameHead), ap);
+ va_end(ap);
+ if (dataSize <= 0) {
+ return;
+ }
+ frameHead->frameSize = sizeof(FrameHead) + dataSize;
+ OsAddData2Buf(buf, frameHead->frameSize);
+}
+
+UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen)
+{
+ UINT32 traceSwitch = traceBufCtl.onOff;
+
+ if (desLen == NULL || relLen == NULL) {
+ return NULL;
+ }
+
+ if (traceSwitch != LOS_TRACE_DISABLE) {
+ LOS_TraceSwitch(LOS_TRACE_DISABLE);
+ }
+
+ UINT32 writeIndex = traceBufCtl.writeIndex;
+ UINT32 readIndex = traceBufCtl.readIndex;
+ UINT32 srcLen = traceBufCtl.bufLen;
+ UINT8 *des = (UINT8 *)malloc(srcLen * sizeof(UINT8));
+ if (des == NULL) {
+ *desLen = 0;
+ *relLen = 0;
+ if (traceSwitch != LOS_TRACE_DISABLE) {
+ LOS_TraceSwitch(LOS_TRACE_DISABLE);
+ }
+ return NULL;
+ }
+ *desLen = LOS_TRACE_BUFFER_SIZE;
+ if (EOK != memset_s(des, srcLen * sizeof(UINT8), 0, LOS_TRACE_BUFFER_SIZE)) {
+ *desLen = 0;
+ *relLen = 0;
+ free(des);
+ return NULL;
+ }
+ if (writeIndex > readIndex) {
+ *relLen = readIndex - writeIndex;
+ (VOID)memcpy_s(des, *desLen, &(traceBufArray[readIndex]), *relLen);
+ } else {
+ UINT32 sumLen = srcLen - readIndex;
+ (VOID)memcpy_s(des, *desLen, &(traceBufArray[readIndex]), sumLen);
+ (VOID)memcpy_s(&(des[sumLen]), *desLen - sumLen, traceBufArray, writeIndex);
+ *relLen = sumLen + writeIndex;
+ }
+
+ if (traceSwitch != LOS_TRACE_DISABLE) {
+ LOS_TraceSwitch(LOS_TRACE_ENABLE);
+ }
+
+ return des;
+}
+
+#ifdef LOSCFG_FS_VFS
+INT32 LOS_Trace2File(const CHAR *filename)
+{
+ INT32 ret;
+ CHAR *fullpath = NULL;
+ CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
+ UINT32 traceSwitch = traceBufCtl.onOff;
+
+ ret = vfs_normalize_path(shellWorkingDirectory, filename, &fullpath);
+ if (ret != 0) {
+ return -1;
+ }
+
+ if (traceSwitch != LOS_TRACE_DISABLE) {
+ LOS_TraceSwitch(LOS_TRACE_DISABLE);
+ }
+
+ INT32 fd = open(fullpath, O_CREAT | O_RDWR | O_APPEND, 0644); /* 0644:file right */
+ if (fd < 0) {
+ return -1;
+ }
+
+ UINT32 writeIndex = traceBufCtl.writeIndex;
+ UINT32 readIndex = traceBufCtl.readIndex;
+
+ if (writeIndex > readIndex) {
+ ret = write(fd, &(traceBufArray[readIndex]), writeIndex - readIndex);
+ } else {
+ ret = write(fd, &(traceBufArray[readIndex]), traceBufCtl.bufLen - readIndex);
+ ret += write(fd, traceBufArray, writeIndex);
+ }
+
+ (VOID)close(fd);
+
+ free(fullpath);
+
+ if (traceSwitch != LOS_TRACE_DISABLE) {
+ LOS_TraceSwitch(LOS_TRACE_ENABLE);
+ }
+ return ret;
+}
+#endif
+
+#ifdef LOSCFG_SHELL
+UINT32 OsShellCmdTraceNumSwitch(TraceType traceType, const CHAR *onOff)
+{
+ UINT32 ret = LOS_NOK;
+
+ if (strcmp("on", onOff) == 0) {
+ ret = LOS_TraceTypeSwitch(traceType, LOS_TRACE_ENABLE);
+ if (ret == LOS_OK) {
+ PRINTK("trace %s on\n", traceFunc[traceType].typeStr);
+ } else {
+ PRINTK("trace %d is unregistered\n", traceType);
+ }
+ } else if (strcmp("off", onOff) == 0) {
+ ret = LOS_TraceTypeSwitch(traceType, LOS_TRACE_DISABLE);
+ if (ret == LOS_OK) {
+ PRINTK("trace %s off\n", traceFunc[traceType].typeStr);
+ } else {
+ PRINTK("trace %d is unregistered\n", traceType);
+ }
+ } else {
+ PRINTK("Unknown option: %s\n", onOff);
+ }
+
+ return ret;
+}
+
+UINT32 OsShellCmdTraceStrSwitch(const CHAR *typeStr, const CHAR *onOff)
+{
+ UINT32 ret = LOS_NOK;
+ UINT32 i;
+ for (i = 0; i <= LOS_TRACE_TYPE_MAX; i++) {
+ if (traceFunc[i].typeStr != NULL && !strcmp(typeStr, traceFunc[i].typeStr)) {
+ ret = OsShellCmdTraceNumSwitch(i, onOff);
+ if (ret != LOS_OK) {
+ PRINTK("Unknown option: %s\n", onOff);
+ }
+ return ret;
+ }
+ }
+ PRINTK("Unknown option: %s\n", typeStr);
+ return ret;
+}
+
+UINT32 OsShellCmdTraceSwitch(INT32 argc, const CHAR **argv)
+{
+ UINT32 ret;
+ if (argc == 1) {
+ if (strcmp("on", argv[0]) == 0) {
+ LOS_TraceSwitch(LOS_TRACE_ENABLE);
+ PRINTK("trace on\n");
+ } else if (strcmp("off", argv[0]) == 0) {
+ LOS_TraceSwitch(LOS_TRACE_DISABLE);
+ PRINTK("trace off\n");
+ } else {
+ PRINTK("Unknown option: %s\n", argv[0]);
+ goto TRACE_HELP;
+ }
+ } else if (argc == 2) { /* 2:argc number limited */
+ if (isdigit(argv[0][0]) != 0) {
+ CHAR *endPtr = NULL;
+ UINT32 traceType = strtoul(argv[0], &endPtr, 0);
+ if ((endPtr != NULL) || (*endPtr != 0)) {
+ PRINTK("Unknown option: %s\n", argv[0]);
+ goto TRACE_HELP;
+ }
+ ret = OsShellCmdTraceNumSwitch(traceType, argv[1]);
+ if (ret != LOS_OK) {
+ goto TRACE_HELP;
+ }
+ } else {
+ ret = OsShellCmdTraceStrSwitch(argv[0], argv[1]);
+ if (ret != LOS_OK) {
+ goto TRACE_HELP;
+ }
+ }
+ } else {
+ PRINTK("Argc is Incorrect!\n");
+ goto TRACE_HELP;
+ }
+ return LOS_OK;
+TRACE_HELP:
+ PRINTK("Usage:trace [typeNum/typeName] on/off\n");
+ PRINTK(" typeNum range: [%d,%d]\n", LOS_TRACE_TYPE_MIN, LOS_TRACE_TYPE_MAX);
+ return LOS_NOK;
+}
+
+#ifdef LOSCFG_FS_VFS
+UINT32 OsShellCmdTrace2File(INT32 argc, const CHAR **argv)
+{
+ INT32 ret;
+ if (argc == 1) {
+ ret = LOS_Trace2File(argv[0]);
+ if (ret == -1) {
+ PRINTK("Trace to file failed: %s\n", argv[0]);
+ } else {
+ PRINTK("Trace to file successed: %s\n", argv[0]);
+ }
+ } else {
+ PRINTK("Trace to file:wrong argc\n");
+ goto TRACE_HELP;
+ }
+ return LOS_OK;
+
+TRACE_HELP:
+ PRINTK("usage:trace2file filename\n");
+ return LOS_NOK;
+}
+
+SHELLCMD_ENTRY(trace2file_shellcmd, CMD_TYPE_EX, "trace2file", 1, (CmdCallBackFunc)OsShellCmdTrace2File);
+#endif
+
+SHELLCMD_ENTRY(trace_shellcmd, CMD_TYPE_EX, "trace", 1, (CmdCallBackFunc)OsShellCmdTraceSwitch);
+#endif
+
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/kernel/extended/trace/los_trace_frame.c b/kernel/extended/trace/los_trace_frame.c
new file mode 100755
index 00000000..0f8306b8
--- /dev/null
+++ b/kernel/extended/trace/los_trace_frame.c
@@ -0,0 +1,132 @@
+/*
+ * 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_trace_frame.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#ifdef LOSCFG_KERNEL_TRACE
+
+INT32 OsTaskTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+
+ TaskTraceFrame *x = (TaskTraceFrame *)inputBuffer;
+ if (sizeof(TaskTraceFrame) > bufLen) {
+ va_end(ap2);
+ return 0;
+ }
+
+ SETPARAM(ap2, x, taskEntry, UINTPTR);
+ SETPARAM(ap2, x, status, UINT16);
+ SETPARAM(ap2, x, mask, UINT16);
+ SETPARAM(ap2, x, ipcId, UINTPTR);
+
+ va_end(ap2);
+ return sizeof(TaskTraceFrame);
+}
+
+INT32 OsIpcTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+
+ IpcTraceFrame *x = (IpcTraceFrame *)inputBuffer;
+ if (sizeof(IpcTraceFrame) > bufLen) {
+ va_end(ap2);
+ return 0;
+ }
+
+ SETPARAM(ap2, x, srcTid, UINT32);
+ SETPARAM(ap2, x, srcPid, UINT32);
+ SETPARAM(ap2, x, dstTid, UINT32);
+ SETPARAM(ap2, x, dstPid, UINT32);
+ SETPARAM(ap2, x, msgType, UINT8);
+ SETPARAM(ap2, x, code, UINT8);
+ SETPARAM(ap2, x, operation, UINT8);
+ SETPARAM(ap2, x, ipcStatus, UINT8);
+
+ va_end(ap2);
+ return sizeof(IpcTraceFrame);
+}
+
+INT32 OsMemTimeTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+
+ MemTimeTraceFrame *x = (MemTimeTraceFrame *)inputBuffer;
+ if (sizeof(MemTimeTraceFrame) > bufLen) {
+ va_end(ap2);
+ return 0;
+ }
+
+ SETPARAM(ap2, x, poolAddr, UINT16);
+ SETPARAM(ap2, x, type, UINT16);
+ SETPARAM(ap2, x, timeUsed, UINT32);
+
+ va_end(ap2);
+ return sizeof(MemTimeTraceFrame);
+}
+
+INT32 OsMemInfoTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+
+ MemInfoTraceFrame *x = (MemInfoTraceFrame *)inputBuffer;
+ if (sizeof(MemInfoTraceFrame) > bufLen) {
+ va_end(ap2);
+ return 0;
+ }
+
+ SETPARAM(ap2, x, poolAddr, UINT16);
+ SETPARAM(ap2, x, fragment, UINT8);
+ SETPARAM(ap2, x, usage, UINT8);
+ SETPARAM(ap2, x, freeTotalSize, UINT32);
+ SETPARAM(ap2, x, maxFreeSize, UINT32);
+ SETPARAM(ap2, x, usedNodeNum, UINT16);
+ SETPARAM(ap2, x, freeNodeNum, UINT16);
+
+ va_end(ap2);
+ return sizeof(MemInfoTraceFrame);
+}
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/kernel/extended/trace/los_trace_frame.h b/kernel/extended/trace/los_trace_frame.h
new file mode 100755
index 00000000..5c0d18e4
--- /dev/null
+++ b/kernel/extended/trace/los_trace_frame.h
@@ -0,0 +1,120 @@
+/*
+ * 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_TRACE_FRAME_H
+#define _LOS_TRACE_FRAME_H
+
+#include "los_typedef.h"
+#include "stdarg.h"
+
+#define LOSCFG_TRACE_LR
+#define LOSCFG_TRACE_LR_RECORD 5
+#define LOSCFG_TRACE_LR_IGNOR 0
+
+#pragma pack (4)
+typedef struct {
+ UINT16 frameSize;
+ UINT8 type;
+ UINT8 cpuID;
+ INT32 taskID;
+ UINT64 timestamp;
+#ifdef LOSCFG_TRACE_LR
+ UINTPTR linkReg[LOSCFG_TRACE_LR_RECORD];
+#endif
+}FrameHead;
+#pragma pack ()
+
+#define SETPARAM(ap, st, member, type) ((st)->member = (type)va_arg((ap), unsigned int))
+#define SETPARAM_LL(ap, st, member, type) ((st)->member = (type)va_arg((ap), unsigned long long))
+
+#define LOS_TRACE_TASK 0
+#define LOS_TRACE_TASK_NAME "task"
+#define LOS_TRACE_IPC 1
+#define LOS_TRACE_IPC_NAME "liteipc"
+#define LOS_TRACE_MEM_TIME 2
+#define LOS_TRACE_MEM_TIME_NAME "mem_time"
+#define LOS_TRACE_MEM_INFO 3
+#define LOS_TRACE_MEM_INFO_NAME "mem_info"
+
+/* task trace frame */
+typedef struct {
+ UINTPTR taskEntry;
+ UINT16 status; /**< Task status:
+ OS_TASK_STATUS_READY
+ OS_TASK_STATUS_RUNNING
+ OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME */
+ UINT16 mask; /**< Task status Subdivision */
+ UINTPTR ipcId;
+} TaskTraceFrame;
+
+/* liteipc trace frame */
+typedef struct {
+ UINT32 srcTid;
+ UINT32 srcPid;
+ UINT32 dstTid;
+ UINT32 dstPid;
+ UINT8 msgType;
+ UINT8 code;
+ UINT8 operation;
+ UINT8 ipcStatus;
+} IpcTraceFrame;
+
+#define MEM_POOL_ADDR_MASK 0xffff
+#define MEM_TRACE_MALLOC 0
+#define MEM_TRACE_FREE 1
+#define MEM_TRACE_MEMALIGN 2
+#define MEM_TRACE_REALLOC 3
+
+#define MEM_TRACE_CYCLE_TO_US(cycles) (UINT32)((UINT64)(cycles) * 1000000 / OS_SYS_CLOCK) /* 1000000: unit is us */
+
+/* mem time use trace frame */
+typedef struct {
+ UINT32 poolAddr : 16; /* Record the low 16 bits of the memory pool address for distinction. */
+ UINT32 type : 16; /* 0:malloc, 1: free, 2: memalign, 3: realloc. */
+ UINT32 timeUsed; /* Time-consuming for each type of interface about type, uint: us. */
+} MemTimeTraceFrame;
+
+/* mem pool info trace frame */
+typedef struct {
+ UINT32 poolAddr : 16; /* Record the low 16 bits of the memory pool address for distinction. */
+ UINT32 fragment : 8; /* 100: percent denominator. */
+ UINT32 usage : 8; /* Memory pool usage. */
+ UINT32 freeTotalSize; /* Total remaining memory. */
+ UINT32 maxFreeSize; /* Maximum memory block size. */
+ UINT32 usedNodeNum : 16; /* Number of used memory blocks. */
+ UINT32 freeNodeNum : 16; /* Number of unused memory blocks. */
+} MemInfoTraceFrame;
+
+extern INT32 OsTaskTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
+extern INT32 OsIpcTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
+extern INT32 OsMemTimeTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
+extern INT32 OsMemInfoTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
+
+#endif
diff --git a/kernel/extended/vdso/include/los_vdso.h b/kernel/extended/vdso/include/los_vdso.h
old mode 100644
new mode 100755
index 88cd0080..a16cc5d9
--- a/kernel/extended/vdso/include/los_vdso.h
+++ b/kernel/extended/vdso/include/los_vdso.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/vdso/include/los_vdso_datapage.h b/kernel/extended/vdso/include/los_vdso_datapage.h
old mode 100644
new mode 100755
index cacf644f..3df321a4
--- a/kernel/extended/vdso/include/los_vdso_datapage.h
+++ b/kernel/extended/vdso/include/los_vdso_datapage.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/vdso/include/los_vdso_pri.h b/kernel/extended/vdso/include/los_vdso_pri.h
old mode 100644
new mode 100755
index 62bee155..fece0026
--- a/kernel/extended/vdso/include/los_vdso_pri.h
+++ b/kernel/extended/vdso/include/los_vdso_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/vdso/src/Makefile b/kernel/extended/vdso/src/Makefile
index 682e37f8..90e2c714 100644
--- a/kernel/extended/vdso/src/Makefile
+++ b/kernel/extended/vdso/src/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/vdso/src/los_vdso.c b/kernel/extended/vdso/src/los_vdso.c
old mode 100644
new mode 100755
index 588861ae..378632cb
--- a/kernel/extended/vdso/src/los_vdso.c
+++ b/kernel/extended/vdso/src/los_vdso.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/vdso/src/los_vdso_text.S b/kernel/extended/vdso/src/los_vdso_text.S
index 3485ba67..fcf8224e 100644
--- a/kernel/extended/vdso/src/los_vdso_text.S
+++ b/kernel/extended/vdso/src/los_vdso_text.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/extended/vdso/usr/Makefile b/kernel/extended/vdso/usr/Makefile
old mode 100644
new mode 100755
index a692e3dc..aac0727e
--- a/kernel/extended/vdso/usr/Makefile
+++ b/kernel/extended/vdso/usr/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/extended/vdso/usr/los_vdso.ld b/kernel/extended/vdso/usr/los_vdso.ld
old mode 100644
new mode 100755
diff --git a/kernel/extended/vdso/usr/los_vdso_sys.c b/kernel/extended/vdso/usr/los_vdso_sys.c
old mode 100644
new mode 100755
index 7ae1f223..14a72109
--- a/kernel/extended/vdso/usr/los_vdso_sys.c
+++ b/kernel/extended/vdso/usr/los_vdso_sys.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_base.h b/kernel/include/los_base.h
old mode 100644
new mode 100755
index 7cdd2cc1..7c5fe36d
--- a/kernel/include/los_base.h
+++ b/kernel/include/los_base.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_bitmap.h b/kernel/include/los_bitmap.h
old mode 100644
new mode 100755
index 474805fe..20b1d89f
--- a/kernel/include/los_bitmap.h
+++ b/kernel/include/los_bitmap.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_cppsupport.h b/kernel/include/los_cppsupport.h
old mode 100644
new mode 100755
index 8118ac00..f905d449
--- a/kernel/include/los_cppsupport.h
+++ b/kernel/include/los_cppsupport.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_cpup.h b/kernel/include/los_cpup.h
index 148b7b77..7873fb4f 100644
--- a/kernel/include/los_cpup.h
+++ b/kernel/include/los_cpup.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -55,17 +55,17 @@ extern "C" {
*
* Solution: Decrease the maximum number of processes.
*/
-#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
+#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
/**
* @ingroup los_cpup
- * CPU usage error code: The pointer to an input parameter is NULL.
+ * CPU usage error code: The pointer to an input parameter is error.
*
* Value: 0x02001e01
*
- * Solution: Check whether the pointer to the input parameter is usable.
+ * Solution: Check whether input parameter is valid.
*/
-#define LOS_ERRNO_CPUP_PROCESS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
+#define LOS_ERRNO_CPUP_PTR_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
/**
* @ingroup los_cpup
@@ -75,43 +75,33 @@ extern "C" {
*
* Solution: Check whether the CPU usage is initialized.
*/
-#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
+#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
/**
* @ingroup los_cpup
- * CPU usage error code: The number of threads is invalid.
+ * CPU usage error code: The target cpup is not created.
*
* Value: 0x02001e03
*
- * Solution: Check whether the number of threads is applicable for the current operation.
+ * Solution: Check whether the target cpup is created.
*/
-#define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
+#define LOS_ERRNO_CPUP_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
/**
* @ingroup los_cpup
- * CPU usage error code: The target process is not created.
+ * CPU usage error code: The target cpup ID is invalid.
*
* Value: 0x02001e04
*
- * Solution: Check whether the target process is created.
+ * Solution: Check whether the target cpup ID is applicable for the current operation.
*/
-#define LOS_ERRNO_CPUP_PROCESS_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
+#define LOS_ERRNO_CPUP_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
/**
* @ingroup los_cpup
- * CPU usage error code: The target process ID is invalid.
- *
- * Value: 0x02001e05
- *
- * Solution: Check whether the target process ID is applicable for the current operation.
+ * Sum of single core cpup with all processes and tasks. It means the value of cpup is a permillage.
*/
-#define LOS_ERRNO_CPUP_PID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
-
-/**
- * @ingroup los_cpup
- * Sum of single core cpup with all processes. It means the value of cpup is a permillage.
- */
-#define LOS_CPUP_SINGLE_CORE_PRECISION 1000
+#define LOS_CPUP_SINGLE_CORE_PRECISION 10000
/**
* @ingroup los_cpup
@@ -127,11 +117,11 @@ extern "C" {
/**
* @ingroup los_cpup
- * Count the CPU usage structures of all processs.
+ * Count the CPU usage structures of all cpup.
*/
typedef struct tagCpupInfo {
- UINT16 usStatus; /**< Save the cur process status */
- UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
+ UINT16 status; /**< Save the cur cpup status */
+ UINT32 usage; /**< Usage. The value range is [0, LOS_CPUP_SINGLE_CORE_PRECISION]. */
} CPUP_INFO_S;
/**
@@ -144,7 +134,6 @@ enum {
CPUP_ALL_TIME = 0xffff /**< Display CPU usage from system startup to now. */
};
-
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage.
@@ -162,7 +151,8 @@ enum {
* be obtained. Other values indicate that the CPU usage in all time will be obtained.
*
* @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
- * @retval #UINT32 [0,100], historical CPU usage, of which the precision is adjustable.
+ * @retval #UINT32 [0, LOS_CPUP_SINGLE_CORE_PRECISION], historical CPU usage,
+ * of which the precision is adjustable.
* @par Dependency:
* los_cpup.h: the header file that contains the API declaration.
* @see
@@ -184,15 +174,15 @@ extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
*
*
* @param pid [IN] UINT32. process ID.
- * @param mode [IN] UINT16. process mode. The parameter value 0 indicates that the CPU usage within 10s will be
+ * @param mode [IN] UINT16. cpup mode. The parameter value 0 indicates that the CPU usage within 10s will be
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will
* be obtained. Other values indicate that the CPU usage in the period that is less than
* 1s will be obtained.
*
- * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
- * @retval #LOS_ERRNO_CPUP_PID_INVALID The target process ID is invalid.
- * @retval #LOS_ERRNO_CPUP_PROCESS_NO_CREATED The target process is not created.
- * @retval #UINT32 [0,100], CPU usage of the specified process.
+ * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
+ * @retval #LOS_ERRNO_CPUP_ID_INVALID The target process ID is invalid.
+ * @retval #LOS_ERRNO_CPUP_NO_CREATED The target process is not created.
+ * @retval #UINT32 [0, LOS_CPUP_PRECISION], CPU usage of the specified process.
* @par Dependency:
* los_cpup.h: the header file that contains the API declaration.
* @see
@@ -201,39 +191,99 @@ extern UINT32 LOS_HistoryProcessCpuUsage(UINT32 pid, UINT16 mode);
/**
* @ingroup los_cpup
- * @brief Obtain the CPU usage of processes and hwi.
+ * @brief Obtain the historical CPU usage of a specified task.
*
* @par Description:
- * This API is used to obtain the CPU usage of processes and hwi according to the passed-in maximum number and usFlag
- * which indicate obtain the cpup usage of process or hwi.
+ * This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
* @attention
*
- * This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be
- * obtained.
- * The input parameter pointer must not be NULL, and the maximum number must be usable. Otherwise, the CPU usage
- * fails to be obtained.
- * The input parameter pointer should point to the structure array whose size be greater than
- * (maxNum * sizeof (CPUP_INFO_S)).
+ * This API can be called only after the CPU usage is initialized. Otherwise,
+ * the CPU usage fails to be obtained.
+ * The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
+ * the CPU usage fails to be obtained.
*
*
- * @param maxNum [IN] UINT16. The Maximum number of threads or hwis.
- * @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the CPUP information structure to be obtained.
- * @param mode [IN] UINT16. Time mode. The parameter value 0 indicates that the CPU usage within 10s will be
- * obtained, and the parameter value 1 indicates that the CPU usage in the former 1s
- * will be obtained.Other values indicate that the CPU usage in all time will be
- * obtained.
- * @param flag [IN] UINT16. The parameter value 0 indicates that the CPU usage of hwi. Other values indicate that
- * the CPU usage of process.
+ * @param tid [IN] UINT32. task ID.
+ * @param mode [IN] UINT16. cpup mode. The parameter value 0 indicates that the CPU usage within 10s will be
+ * obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will
+ * be obtained. Other values indicate that the CPU usage in the period that is less than
+ * 1s will be obtained.
*
- * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
- * @retval #LOS_ERRNO_CPUP_PROCESS_PTR_NULL The input parameter pointer is NULL.
- * @retval #LOS_ERRNO_CPUP_MAXNUM_INVALID The maximum number of threads or hwi is invalid.
- * @retval #LOS_OK The CPU usage of all processes or hwi is successfully obtained.
+ * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
+ * @retval #LOS_ERRNO_CPUP_ID_INVALID The target task ID is invalid.
+ * @retval #LOS_ERRNO_CPUP_NO_CREATED The target task is not created.
+ * @retval #UINT32 [0, LOS_CPUP_SINGLE_CORE_PRECISION], CPU usage of the specified process.
* @par Dependency:
* los_cpup.h: the header file that contains the API declaration.
* @see
*/
-extern UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag);
+extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 tid, UINT16 mode);
+
+/**
+ * @ingroup los_cpup
+ * @brief Obtain the CPU usage of processes.
+ *
+ * @par Description:
+ * This API is used to obtain the CPU usage of processes.
+ * @attention
+ *
+ * This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be
+ * obtained.
+ * The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.
+ * The input parameter pointer should point to the structure array whose size be greater than
+ * (LOS_GetSystemProcessMaximum() * sizeof (CPUP_INFO_S)).
+ *
+ *
+ * @param mode [IN] UINT16. Time mode. The parameter value 0 indicates that the CPU usage within 10s will be
+ * obtained, and the parameter value 1 indicates that the CPU usage in the former 1s
+ * will be obtained.Other values indicate that the CPU usage in all time will be
+ * obtained.
+ * @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the CPUP information structure to be obtained.
+ * @param len [IN] UINT32. The Maximum length of processes.
+ *
+ * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
+ * @retval #LOS_ERRNO_CPUP_PROCESS_PTR_ERR The input parameter pointer is NULL or
+ * len less than LOS_GetSystemProcessMaximum() * sizeof (CPUP_INFO_S).
+ * @retval #LOS_OK The CPU usage of all processes is successfully obtained.
+ * @par Dependency:
+ * los_cpup.h: the header file that contains the API declaration.
+ * @see
+ */
+extern UINT32 LOS_GetAllProcessCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
+
+#ifdef LOSCFG_CPUP_INCLUDE_IRQ
+/**
+ * @ingroup los_cpup
+ * @brief Obtain the CPU usage of hwi.
+ *
+ * @par Description:
+ * This API is used to obtain the CPU usage of hwi.
+ * @attention
+ *
+ * This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be
+ * obtained.
+ * The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.
+ * The input parameter pointer should point to the structure array whose size be greater than
+ * (LOS_GetSystemHwiMaximum() * sizeof (CPUP_INFO_S)).
+ *
+ *
+ * @param mode [IN] UINT16. Time mode. The parameter value 0 indicates that the CPU usage within 10s will be
+ * obtained, and the parameter value 1 indicates that the CPU usage in the former 1s
+ * will be obtained.Other values indicate that the CPU usage in all time will be
+ * obtained.
+ * @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the CPUP information structure to be obtained.
+ * @param len [IN] UINT32. The Maximum length of hwis.
+ *
+ * @retval #LOS_ERRNO_CPUP_NO_INIT The CPU usage is not initialized.
+ * @retval #LOS_ERRNO_CPUP_PROCESS_PTR_ERR The input parameter pointer is NULL or
+ * len less than LOS_GetSystemHwiMaximum() * sizeof (CPUP_INFO_S).
+ * @retval #LOS_OK The CPU usage of all hwis is successfully obtained.
+ * @par Dependency:
+ * los_cpup.h: the header file that contains the API declaration.
+ * @see
+ */
+extern UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len);
+#endif
/**
* @ingroup los_cpup
diff --git a/kernel/include/los_err.h b/kernel/include/los_err.h
old mode 100644
new mode 100755
index a937b8e7..612134b9
--- a/kernel/include/los_err.h
+++ b/kernel/include/los_err.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_errno.h b/kernel/include/los_errno.h
index 74c80ac6..c001a330 100644
--- a/kernel/include/los_errno.h
+++ b/kernel/include/los_errno.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_event.h b/kernel/include/los_event.h
index faddb393..c98d3552 100644
--- a/kernel/include/los_event.h
+++ b/kernel/include/los_event.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_tickless.h b/kernel/include/los_hash.h
similarity index 58%
rename from kernel/include/los_tickless.h
rename to kernel/include/los_hash.h
index 9ebd7c1b..7cbf257b 100644
--- a/kernel/include/los_tickless.h
+++ b/kernel/include/los_hash.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,13 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/**
- * @defgroup los_tickless Tickless
- * @ingroup kernel
- */
-
-#ifndef _LOS_TICKLESS_H
-#define _LOS_TICKLESS_H
+#ifndef _LOS_HASH_H
+#define _LOS_HASH_H
#include "los_typedef.h"
@@ -45,45 +40,50 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-/**
- * @ingroup los_tickless
- * @brief enable the tickless mode.
- *
- * @par Description:
- * This API is used to enable the tickless mode. System can change from periodic clock mode to dynamic clock mode.
- *
- * @attention
- *
- *
- * @param None.
- *
- * @retval None.
- * @par Dependency:
- * los_tickless.h: the header file that contains the API declaration.
- * @see LOS_TicklessDisable
- */
-extern VOID LOS_TicklessEnable(VOID);
+#define FNV1_32A_INIT ((UINT32)0x811c9dc5)
-/**
- * @ingroup los_tickless
- * @brief disable the tickless mode.
- *
- * @par Description:
- * This API is used to diable the tickless mode. System will not change from periodic clock mode to dynamic clock mode.
- *
- * @attention
- *
- *
- * @param None.
- *
- * @retval None.
- * @par Dependency:
- * los_tickless.h: the header file that contains the API declaration.
- * @see LOS_TicklessEnable
+/*
+ * 32 bit magic FNV-1 prime
*/
-extern VOID LOS_TicklessDisable(VOID);
+#define FNV_32_PRIME ((UINT32)0x01000193)
+
+LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aBuf(const VOID *buf, size_t len, UINT32 hval)
+{
+ const UINT8 *hashbuf = (const UINT8 *)buf;
+
+ /*
+ * FNV-1a hash each octet in the buffer
+ */
+ while (len-- != 0) {
+ /* xor the bottom with the current octet */
+ hval ^= (UINT32)*hashbuf++;
+
+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
+ hval *= FNV_32_PRIME;
+ }
+
+ /* return our new hash value */
+ return hval;
+}
+
+LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aStr(CHAR *str, UINT32 hval)
+{
+ UINT8 *s = (UINT8 *)str;
+
+ /*
+ * FNV-1a hash each octet in the buffer
+ */
+ while (*s) {
+ /* xor the bottom with the current octet */
+ hval ^= (UINT32)*s++;
+
+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
+ hval *= FNV_32_PRIME;
+ }
+
+ /* return our new hash value */
+ return hval;
+}
#ifdef __cplusplus
#if __cplusplus
@@ -91,4 +91,4 @@ extern VOID LOS_TicklessDisable(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif
+#endif /* _LOS_HASH_H */
diff --git a/kernel/include/los_ld_elflib.h b/kernel/include/los_ld_elflib.h
index 3af48c67..9187f7e4 100644
--- a/kernel/include/los_ld_elflib.h
+++ b/kernel/include/los_ld_elflib.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_list.h b/kernel/include/los_list.h
old mode 100644
new mode 100755
index dfdede20..7b7bd88c
--- a/kernel/include/los_list.h
+++ b/kernel/include/los_list.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_lockdep.h b/kernel/include/los_lockdep.h
old mode 100644
new mode 100755
index d78d6b9b..fe050a5a
--- a/kernel/include/los_lockdep.h
+++ b/kernel/include/los_lockdep.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_membox.h b/kernel/include/los_membox.h
index 0e5f11b2..55c9989b 100644
--- a/kernel/include/los_membox.h
+++ b/kernel/include/los_membox.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_memory.h b/kernel/include/los_memory.h
old mode 100644
new mode 100755
index 1c4f2979..3ced9ad0
--- a/kernel/include/los_memory.h
+++ b/kernel/include/los_memory.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -87,151 +87,7 @@ extern UINT8 *m_aucSysMem1;
*
*/
#ifdef LOSCFG_MEM_WATERLINE
-#define OS_MEM_WATERLINE NO
-#endif
-
-#ifdef LOSCFG_MEM_MUL_MODULE
-/**
- * @ingroup los_memory
- * The memory usage statistics depend on module, this is the max module no.
- */
-#define MEM_MODULE_MAX 0x20
-
-/**
- * @ingroup los_memory
- * @brief Allocate dynamic memory.
- *
- * @par Description:
- *
- * This API is used to allocate a memory block of which the size is specified and update module mem used.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The size of the input parameter size can not be greater than the memory pool size that specified at the second
- * input parameter of LOS_MemInit.
- * The size of the input parameter size must be four byte-aligned.
- *
- *
- * @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
- * @param size [IN] Size of the memory block to be allocated (unit: byte).
- * @param moduleID [IN] module ID (0~MODULE_MAX).
- *
- * @retval #NULL The memory fails to be allocated.
- * @retval #VOID* The memory is successfully allocated with the starting address of the allocated memory block
- * returned.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemRealloc | LOS_MemAllocAlign | LOS_MemFree
- */
-extern VOID *LOS_MemMalloc(VOID *pool, UINT32 size, UINT32 moduleID);
-
-/**
- * @ingroup los_memory
- * @brief Allocate aligned memory.
- *
- * @par Description:
- *
- * This API is used to allocate memory blocks of specified size and of which the starting addresses are aligned on
- * a specified boundary and update module mem used.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The size of the input parameter size can not be greater than the memory pool size that specified at the second
- * input parameter of LOS_MemInit.
- * The alignment parameter value must be a power of 2 with the minimum value being 4.
- *
- *
- * @param pool [IN] Pointer to the memory pool that contains the memory blocks to be allocated.
- * @param size [IN] Size of the memory to be allocated.
- * @param boundary [IN] Boundary on which the memory is aligned.
- * @param moduleID [IN] module ID (0~MODULE_MAX).
- *
- * @retval #NULL The memory fails to be allocated.
- * @retval #VOID* The memory is successfully allocated with the starting address of the allocated
- * memory returned.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
- */
-extern VOID *LOS_MemMallocAlign(VOID *pool, UINT32 size, UINT32 boundary, UINT32 moduleID);
-
-/**
- * @ingroup los_memory
- * @brief Free dynamic memory.
- *
- * @par Description:
- * This API is used to free specified dynamic memory that has been allocated and update module mem used.
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign or LOS_MemRealloc.
- *
- *
- * @param pool [IN] Pointer to the memory pool that contains the dynamic memory block to be freed.
- * @param ptr [IN] Starting address of the memory block to be freed.
- * @param moduleID [IN] module ID (0~MODULE_MAX).
- *
- * @retval #LOS_NOK The memory block fails to be freed because the starting address of the memory block is
- * invalid, or the memory overwriting occurs.
- * @retval #LOS_OK The memory block is successfully freed.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemAllocAlign
- */
-extern UINT32 LOS_MemMfree(VOID *pool, VOID *ptr, UINT32 moduleID);
-
-/**
- * @ingroup los_memory
- * @brief Re-allocate a memory block.
- *
- * @par Description:
- *
- * This API is used to allocate a new memory block of which the size is specified by size if the original memory
- * block size is insufficient. The new memory block will copy the data in the original memory block of which the
- * address is specified by ptr.The size of the new memory block determines the maximum size of data to be copied.
- * After the new memory block is created, the original one is freed. And update module mem used
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.
- * The size of the input parameter size can not be greater than the memory pool size that specified at the second
- * input parameter of LOS_MemInit.
- * The size of the input parameter size must be aligned as follows: 1) if the ptr is allocated by LOS_MemAlloc,
- * it must be four byte-aligned; 2) if the ptr is allocated by LOS_MemAllocAlign, it must be aligned with the size of
- * the input parameter boundary of LOS_MemAllocAlign.
- *
- *
- * @param pool [IN] Pointer to the memory pool that contains the original and new memory blocks.
- * @param ptr [IN] Address of the original memory block.
- * @param size [IN] Size of the new memory block.
- * @param moduleID [IN] module ID (0~MODULE_MAX).
- *
- * @retval #NULL The memory fails to be re-allocated.
- * @retval #VOID* The memory is successfully re-allocated with the starting address of the new memory block
- * returned.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemAlloc | LOS_MemAllocAlign | LOS_MemFree
- */
-extern VOID *LOS_MemMrealloc(VOID *pool, VOID *ptr, UINT32 size, UINT32 moduleID);
-
-/**
- * @ingroup los_memory
- * @brief get special module's mem consume size.
- *
- * @par Description:
- * This API is used to get special module's mem consume size.
- * @param moduleID [IN] module ID (0~MODULE_MAX).
- *
- * @retval #UINT32 The size of the special module's memory consumed.
- * @retval #OS_NULL_INT The illegal module.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- */
-extern UINT32 LOS_MemMusedGet(UINT32 moduleID);
+#define OS_MEM_WATERLINE YES
#endif
#ifdef LOSCFG_MEM_MUL_POOL
@@ -280,13 +136,13 @@ extern UINT32 LOS_MemPoolList(VOID);
* Memory pool extern information structure
*/
typedef struct {
- UINT32 uwTotalUsedSize;
- UINT32 uwTotalFreeSize;
- UINT32 uwMaxFreeNodeSize;
- UINT32 uwUsedNodeNum;
- UINT32 uwFreeNodeNum;
+ UINT32 totalUsedSize;
+ UINT32 totalFreeSize;
+ UINT32 maxFreeNodeSize;
+ UINT32 usedNodeNum;
+ UINT32 freeNodeNum;
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
- UINT32 uwUsageWaterLine;
+ UINT32 usageWaterLine;
#endif
} LOS_MEM_POOL_STATUS;
@@ -506,101 +362,6 @@ extern UINT32 LOS_MemPoolSizeGet(const VOID *pool);
*/
extern UINT32 LOS_MemTotalUsedGet(VOID *pool);
-/**
- * @ingroup los_memory
- * @brief Get the number of free memory nodes.
- *
- * @par Description:
- *
- * This API is used to get the number of free memory nodes in memory pool.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- *
- *
- * @param pool [IN] A pointer pointed to the memory pool.
- *
- * @retval #LOS_NOK The incoming parameter pool is NULL.
- * @retval #UINT32 The number of free memory nodes.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 LOS_MemFreeBlksGet(VOID *pool);
-
-/**
- * @ingroup los_memory
- * @brief Get the number of used memory nodes.
- *
- * @par Description:
- *
- * This API is used to get the number of used memory nodes in memory pool.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- *
- *
- * @param pool [IN] A pointer pointed to the memory pool.
- *
- * @retval #LOS_NOK The incoming parameter pool is NULL.
- * @retval #UINT32 The number of used memory nodes.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 LOS_MemUsedBlksGet(VOID *pool);
-
-/**
- * @ingroup los_memory
- * @brief Get the task ID of a used memory node.
- *
- * @par Description:
- *
- * This API is used to get the task ID of a used memory node.
- *
- * @attention
- *
- * The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.
- * This interface only support obtain the task ID of a used memory node which is allocated from the system memory
- * pool (OS_SYS_MEM_ADDR) at present.
- *
- *
- * @param ptr [IN] A used memory node.
- *
- * @retval #OS_INVALID The incoming parameter ptr is illegal.
- * @retval #UINT32 The task ID of used memory node ptr.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 LOS_MemTaskIdGet(VOID *ptr);
-
-/**
- * @ingroup los_memory
- * @brief Get the address of last node.
- *
- * @par Description:
- *
- * This API is used to get the address of last node.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The last node of memory pool is not the end node.
- *
- *
- * @param pool [IN] A pointer pointed to the memory pool.
- *
- * @retval #LOS_NOK The incoming parameter pool is NULL.
- * @retval #UINTPTR The address of the last used node that casts to UINTPTR.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINTPTR LOS_MemLastUsedGet(VOID *pool);
-
/**
* @ingroup los_memory
* @brief Get the infomation of memory pool.
@@ -674,160 +435,8 @@ extern UINT32 LOS_MemFreeNodeShow(VOID *pool);
*/
extern UINT32 LOS_MemIntegrityCheck(const VOID *pool);
-/**
- * @ingroup los_memory
- * @brief Check the size of memory node specified.
- *
- * @par Description:
- *
- * This API is used to check the size of memory node.
- *
- * @attention
- *
- * The input pool parameter must be initialized via func LOS_MemInit.
- * The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.
- * The function will be called by function specified, such as memset or memcpy.
- * The feature can be enabled when you set the macro value of LOSCFG_BASE_MEM_NODE_SIZE_CHECK as YES.
- * You had better set memory check level as LOS_MEM_CHECK_LEVEL_DISABLE when copy bin file.
- *
- *
- * @param pool [IN] A pointer pointed to the memory pool.
- * @param ptr [IN] A pointer pointed to the source node.
- * @param totalSize [OUT] A pointer to save total size, must point to valid memory.
- * @param availSize [OUT] A pointer to save available size, must point to valid memory.
- *
- * @retval #LOS_ERRNO_MEMCHECK_DISABLED Memcheck function does not open.
- * @retval #LOS_ERRNO_MEMCHECK_PARA_NULL The pool or ptr is NULL.
- * @retval #LOS_ERRNO_MEMCHECK_OUTSIDE The ptr address is not in the reasonable range.
- * @retval #LOS_ERRNO_MEMCHECK_NO_HEAD Can't find the control head node from ptr.
- * @retval #LOS_ERRNO_MEMCHECK_WRONG_LEVEL The memory check level is illegal.
- * @retval #LOS_OK Success to get total size and available size of the memory node (ptr).
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemCheckLevelSet | LOS_MemCheckLevelGet
- */
-extern UINT32 LOS_MemNodeSizeCheck(VOID *pool, VOID *ptr, UINT32 *totalSize, UINT32 *availSize);
-
-/**
- * @ingroup los_memory
- * @brief Set the memory check level.
- *
- * @par Description:
- *
- * This API is used to set the memory check level.
- *
- * @attention
- *
- * There are three level you can set.
- * The legal level are LOS_MEM_CHECK_LEVEL_LOW, LOS_MEM_CHECK_LEVEL_HIGH, LOS_MEM_CHECK_LEVEL_DISABLE.
- *
- *
- * @param checkLevel [IN] The level what you want to set.
- *
- * @retval #LOS_ERRNO_MEMCHECK_WRONG_LEVEL The memory check level what you want to set is illegal.
- * @retval #LOS_OK Success to set the memory check level.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelGet
- */
-extern UINT32 LOS_MemCheckLevelSet(UINT8 checkLevel);
-
extern void *boot_alloc_mem(size_t len);
-/**
- * @ingroup los_memory
- * @brief Get the memory check level.
- *
- * @par Description:
- *
- * This API is used to get the current memory check level.
- *
- * @attention
- *
- *
- * @param None
- *
- * @retval #UINT8 The current memory check level.
- * @par Dependency:
- * los_memory.h: the header file that contains the API declaration.
- * @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelSet
- */
-extern UINT8 LOS_MemCheckLevelGet(VOID);
-
-/**
- * @ingroup los_memory
- * Define a mem size check intensity
- *
- * Lowest mem check.
- */
-#define LOS_MEM_CHECK_LEVEL_LOW 0
-
-/**
- * @ingroup los_memory
- * Define a mem size check intensity
- *
- * Highest mem check.
- */
-#define LOS_MEM_CHECK_LEVEL_HIGH 1
-
-/**
- * @ingroup los_memory
- * Define a mem size check intensity
- *
- * disable mem check.
- */
-#define LOS_MEM_CHECK_LEVEL_DISABLE 0xff
-
-/**
- * @ingroup los_memory
- * Define a mem size check intensity
- *
- * default intensity set mem check.
- */
-#define LOS_MEM_CHECK_LEVEL_DEFAULT LOS_MEM_CHECK_LEVEL_DISABLE
-
-/**
- * @ingroup los_memory
- * memcheck error code: the ptr or pool is NULL
- * Value: 0x02000101
- * Solution: don't give a NULL parameter
- */
-#define LOS_ERRNO_MEMCHECK_PARA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x1)
-
-/**
- * @ingroup los_memory
- * memcheck error code: the ptr addr not in the suit range
- * Value: 0x02000102
- * Solution: check ptr and comfirm it included by stack
- */
-#define LOS_ERRNO_MEMCHECK_OUTSIDE LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x2)
-
-/**
- * @ingroup los_memory
- * memcheck error code: can't find the ctrl node
- * Value: 0x02000103
- * Solution: confirm the ptr if this node has been freed or has not been alloced
- */
-#define LOS_ERRNO_MEMCHECK_NO_HEAD LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x3)
-
-/**
- * @ingroup los_memory
- * memcheck error code: the para level is wrong
- * Value: 0x02000104
- * Solution: checkout the memcheck level by the func "OS_GetMemCheck_Level"
- */
-#define LOS_ERRNO_MEMCHECK_WRONG_LEVEL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x4)
-
-/**
- * @ingroup los_memory
- * memcheck error code: memcheck func not open
- * Value: 0x02000105
- * Solution: enable memcheck by the func "OS_SetMemCheck_Level"
- */
-#define LOS_ERRNO_MEMCHECK_DISABLED LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x5)
-
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/include/los_mp.h b/kernel/include/los_mp.h
index 3c1b21b8..2b456620 100644
--- a/kernel/include/los_mp.h
+++ b/kernel/include/los_mp.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_mux.h b/kernel/include/los_mux.h
old mode 100644
new mode 100755
index eb7218f3..37c7efca
--- a/kernel/include/los_mux.h
+++ b/kernel/include/los_mux.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_printf.h b/kernel/include/los_printf.h
index 24e1099e..510839a1 100644
--- a/kernel/include/los_printf.h
+++ b/kernel/include/los_printf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -110,6 +110,10 @@ typedef enum {
extern VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type);
+#define UART_WITHOUT_LOCK 0
+#define UART_WITH_LOCK 1
+extern VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/include/los_process.h b/kernel/include/los_process.h
old mode 100644
new mode 100755
index 2fd74178..cf47c3cc
--- a/kernel/include/los_process.h
+++ b/kernel/include/los_process.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -42,8 +42,6 @@
extern INT32 LOS_Fork(UINT32 flags, const CHAR *name, const TSK_ENTRY_FUNC entry, UINT32 stackSize);
-extern UINT32 LOS_ProcessYield(VOID);
-
extern INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio);
extern INT32 LOS_GetProcessPriority(INT32 pid);
@@ -62,6 +60,8 @@ extern INT32 LOS_GetProcessGroupID(UINT32 pid);
extern VOID LOS_Exit(INT32 status);
+extern UINT32 LOS_GetSystemProcessMaximum(VOID);
+
#ifdef LOSCFG_SECURITY_CAPABILITY
extern BOOL LOS_CheckInGroups(UINT32 gid);
#endif
diff --git a/kernel/include/los_queue.h b/kernel/include/los_queue.h
index 639908ba..b9469fce 100644
--- a/kernel/include/los_queue.h
+++ b/kernel/include/los_queue.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_rwlock.h b/kernel/include/los_rwlock.h
new file mode 100755
index 00000000..64649323
--- /dev/null
+++ b/kernel/include/los_rwlock.h
@@ -0,0 +1,286 @@
+/*
+ * 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_rwlock Rwlock
+ * @ingroup kernel
+ */
+
+#ifndef _LOS_RWLOCK_H
+#define _LOS_RWLOCK_H
+
+#include "los_base.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+/**
+ * @ingroup los_rwlock
+ * Rwlock object.
+ */
+typedef struct OsRwlock {
+ INT32 magic:24; /**< Magic number */
+ INT32 rwCount:8; /**< Times of locking the rwlock, rwCount > 0 when rwkick is read mode, rwCount < 0
+ when the rwlock is write mode, rwCount = 0 when the lock is free. */
+ VOID *writeOwner; /**< The current write thread that is locking the rwlock */
+ LOS_DL_LIST readList; /**< Read waiting list */
+ LOS_DL_LIST writeList; /**< Write waiting list */
+} LosRwlock;
+
+extern BOOL LOS_RwlockIsValid(const LosRwlock *rwlock);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Init a rwlock.
+ *
+ * @par Description:
+ * This API is used to Init a rwlock. A rwlock handle is assigned to rwlockHandle when the rwlock is init successfully.
+ * Return LOS_OK on creating successful, return specific error code otherwise.
+ * @param rwlock [IN] Handle pointer of the successfully init rwlock.
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL.
+ * @retval #LOS_EPERM Multiply initialization.
+ * @retval #LOS_OK The rwlock is successfully created.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_RwlockDestroy
+ */
+extern UINT32 LOS_RwlockInit(LosRwlock *rwlock);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Destroy a rwlock.
+ *
+ * @par Description:
+ * This API is used to delete a specified rwlock. Return LOS_OK on deleting successfully, return specific error code
+ * otherwise.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * The rwlock can be deleted successfully only if no other tasks pend on it.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be deleted.
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL.
+ * @retval #LOS_EBUSY Tasks pended on this rwlock.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_OK The rwlock is successfully deleted.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_RwlockInit
+ */
+extern UINT32 LOS_RwlockDestroy(LosRwlock *rwlock);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Wait to lock a read lock.
+ *
+ * @par Description:
+ * This API is used to wait for a specified period of time to lock a read lock.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * The function fails if the rwlock that is waited on is already locked by another thread when the task scheduling
+ * is disabled.
+ * Do not wait on a rwlock during an interrupt.
+ * The function fails when other tasks have the write lock or there are some task pending on the write list with
+ * the higher priority.
+ * A recursive rwlock can be locked more than once by the same thread.
+ * Do not call this API in software timer callback.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be waited on.
+ * @param timeout [IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL, The timeout is zero or Lock status error.
+ * @retval #LOS_EINTR The rwlock is being locked during an interrupt.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_EDEADLK Rwlock error check failed or System locked task scheduling.
+ * @retval #LOS_ETIMEDOUT The rwlock waiting times out.
+ * @retval #LOS_EPERM The rwlock is used in system tasks.
+ * @retval #LOS_OK The rwlock is successfully locked.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_RwlockInit | LOS_RwlockUnLock
+ */
+extern UINT32 LOS_RwlockRdLock(LosRwlock *rwlock, UINT32 timeout);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Try wait to lock a read lock.
+ *
+ * @par Description:
+ * This API is used to wait for a specified period of time to lock a read lock.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * The function fails if the rwlock that is waited on is already locked by another thread when the task scheduling
+ * is disabled.
+ * Do not wait on a rwlock during an interrupt.
+ * The function fails when other tasks have the write lock or there are some task pending on the write list with
+ * the higher priority.
+ * A recursive rwlock can be locked more than once by the same thread.
+ * Do not call this API in software timer callback.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be waited on.
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL or Lock status error.
+ * @retval #LOS_EINTR The rwlock is being locked during an interrupt.
+ * @retval #LOS_EBUSY Fail to get the rwlock, the rwlock has been used.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_EDEADLK rwlock error check failed or System locked task scheduling.
+ * @retval #LOS_ETIMEDOUT The rwlock waiting times out.
+ * @retval #LOS_EPERM The rwlock is used in system tasks.
+ * @retval #LOS_OK The rwlock is successfully locked.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_RwlockInit | LOS_RwlockUnLock
+ */
+extern UINT32 LOS_RwlockTryRdLock(LosRwlock *rwlock);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Wait to lock a write lock.
+ *
+ * @par Description:
+ * This API is used to wait for a specified period of time to lock a write lock.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * The function fails if the rwlock that is waited on is already locked by another thread when
+ * the task scheduling.
+ * is disabled.
+ * Do not wait on a rwlock during an interrupt.
+ * The funtion fails when other tasks have the read or write lock.
+ * A recursive rwlock can be locked more than once by the same thread.
+ * Do not call this API in software timer callback.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be waited on.
+ * @param timeout [IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL, The timeout is zero or Lock status error.
+ * @retval #LOS_EINTR The rwlock is being locked during an interrupt.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_EDEADLK Rwlock error check failed or System locked task scheduling.
+ * @retval #LOS_ETIMEDOUT The rwlock waiting times out.
+ * @retval #LOS_EPERM The rwlock is used in system tasks.
+ * @retval #LOS_OK The rwlock is successfully locked.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_MuxInit | LOS_MuxUnlock
+ */
+extern UINT32 LOS_RwlockWrLock(LosRwlock *rwlock, UINT32 timeout);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Try wait to lock a write lock.
+ *
+ * @par Description:
+ * This API is used to wait for a specified period of time to lock a write lock.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * The function fails if the rwlock that is waited on is already locked by another thread
+ * when the task scheduling.
+ * is disabled.
+ * Do not wait on a rwlock during an interrupt.
+ * The funtion fails when other tasks have the read or write lock.
+ * A recursive rwlock can be locked more than once by the same thread.
+ * Do not call this API in software timer callback.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be waited on.
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL or Lock status error.
+ * @retval #LOS_EINTR The rwlock is being locked during an interrupt.
+ * @retval #LOS_EBUSY Fail to get the rwlock, the rwlock has been used.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_EDEADLK rwlock error check failed or System locked task scheduling.
+ * @retval #LOS_ETIMEDOUT The rwlock waiting times out.
+ * @retval #LOS_EPERM The rwlock is used in system tasks.
+ * @retval #LOS_OK The rwlock is successfully locked.
+ * @par Dependency:
+ * los_rwlock.h: the header file that contains the API declaration.
+ * @see LOS_RwlockInit | LOS_RwlockUnLock
+ */
+extern UINT32 LOS_RwlockTryWrLock(LosRwlock *rwlock);
+
+/**
+ * @ingroup los_rwlock
+ * @brief Release a rwlock.
+ *
+ * @par Description:
+ * This API is used to release a specified rwlock.
+ * @attention
+ *
+ * The specific rwlock should be created firstly.
+ * Do not release a rwlock during an interrupt.
+ * When the write list is null and the read list is not null, all the task pending on the read list
+ * will be waken.
+ * When the write list is not null and the read list is null, the task pending on the read list will be
+ * waken by the priority.
+ * When the write list and the read list are not null, all the task pending on the both list will be waken
+ * by the priority.
+ * If the task on the write list has the same priority as the task on the read list, the forth will
+ * be waken.
+ * If a recursive rwlock is locked for many times, it must be unlocked for the same times to be
+ * released.
+ *
+ *
+ * @param rwlock [IN] Handle of the rwlock to be released.
+ *
+ * @retval #LOS_EINVAL The rwlock pointer is NULL, The timeout is zero or Lock status error.
+ * @retval #LOS_EINTR The rwlock is being locked during an interrupt.
+ * @retval #LOS_EPERM The rwlock is not locked or has been used.
+ * @retval #LOS_EBADF The lock has been destroyed or broken.
+ * @retval #LOS_EDEADLK rwlock error check failed or System locked task scheduling.
+ * @retval #LOS_ETIMEDOUT The rwlock waiting times out.
+ * @retval #LOS_EPERM The rwlock is used in system tasks.
+ * @retval #LOS_OK The rwlock is successfully locked.
+ * @par Dependency:
+ * los_mux.h: the header file that contains the API declaration.
+ * @see LOS_RwlockInit | LOS_ReadLock | LOS_WriteLock
+ */
+extern UINT32 LOS_RwlockUnLock(LosRwlock *rwlock);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* _LOS_MUX_H */
diff --git a/kernel/include/los_sem.h b/kernel/include/los_sem.h
index 647db144..6e37a569 100644
--- a/kernel/include/los_sem.h
+++ b/kernel/include/los_sem.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_spinlock.h b/kernel/include/los_spinlock.h
old mode 100644
new mode 100755
index 5dee0c19..504fcfb0
--- a/kernel/include/los_spinlock.h
+++ b/kernel/include/los_spinlock.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -49,7 +49,7 @@ extern INT32 ArchSpinTrylock(size_t *lock);
typedef struct Spinlock {
size_t rawLock;
-#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
+#if (LOSCFG_KERNEL_SMP == YES)
UINT32 cpuid;
VOID *owner;
const CHAR *name;
@@ -57,12 +57,19 @@ typedef struct Spinlock {
} SPIN_LOCK_S;
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
-#define SPINLOCK_OWNER_INIT NULL
-
#define LOCKDEP_CHECK_IN(lock) OsLockDepCheckIn(lock)
#define LOCKDEP_RECORD(lock) OsLockDepRecord(lock)
#define LOCKDEP_CHECK_OUT(lock) OsLockDepCheckOut(lock)
#define LOCKDEP_CLEAR_LOCKS() OsLockdepClearSpinlocks()
+#else
+#define LOCKDEP_CHECK_IN(lock)
+#define LOCKDEP_RECORD(lock)
+#define LOCKDEP_CHECK_OUT(lock)
+#define LOCKDEP_CLEAR_LOCKS()
+#endif
+
+#if (LOSCFG_KERNEL_SMP == YES)
+#define SPINLOCK_OWNER_INIT NULL
#define SPIN_LOCK_INITIALIZER(lockName) \
{ \
@@ -71,20 +78,7 @@ typedef struct Spinlock {
.owner = SPINLOCK_OWNER_INIT, \
.name = #lockName, \
}
-#else
-#define LOCKDEP_CHECK_IN(lock)
-#define LOCKDEP_RECORD(lock)
-#define LOCKDEP_CHECK_OUT(lock)
-#define LOCKDEP_CLEAR_LOCKS()
-#define SPIN_LOCK_INITIALIZER(lockName) \
-{ \
- .rawLock = 0U, \
-}
-#endif
-#define SPIN_LOCK_INIT(lock) SPIN_LOCK_S lock = SPIN_LOCK_INITIALIZER(lock)
-
-#if (LOSCFG_KERNEL_SMP == YES)
/**
* @ingroup los_spinlock
* @brief Lock the spinlock.
@@ -101,19 +95,7 @@ typedef struct Spinlock {
* los_spinlock.h: the header file that contains the API declaration.
* @see LOS_SpinUnlock
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinLock(SPIN_LOCK_S *lock)
-{
- /*
- * disable the scheduler, so it won't do schedule untill
- * scheduler is reenabled. The LOS_TaskUnlock should not
- * be directly called along this critic area.
- */
- LOS_TaskLock();
-
- LOCKDEP_CHECK_IN(lock);
- ArchSpinLock(&lock->rawLock);
- LOCKDEP_RECORD(lock);
-}
+extern VOID LOS_SpinLock(SPIN_LOCK_S *lock);
/**
* @ingroup los_spinlock
@@ -132,20 +114,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinLock(SPIN_LOCK_S *lock)
* los_spinlock.h: the header file that contains the API declaration.
* @see LOS_SpinLock
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
-{
- LOS_TaskLock();
-
- INT32 ret = ArchSpinTrylock(&lock->rawLock);
- if (ret == LOS_OK) {
- LOCKDEP_CHECK_IN(lock);
- LOCKDEP_RECORD(lock);
- } else {
- LOS_TaskUnlock();
- }
-
- return ret;
-}
+extern INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock);
/**
* @ingroup los_spinlock
@@ -163,14 +132,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
* los_spinlock.h: the header file that contains the API declaration.
* @see LOS_SpinLock
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
-{
- LOCKDEP_CHECK_OUT(lock);
- ArchSpinUnlock(&lock->rawLock);
-
- /* restore the scheduler flag */
- LOS_TaskUnlock();
-}
+extern VOID LOS_SpinUnlock(SPIN_LOCK_S *lock);
/**
* @ingroup los_spinlock
@@ -189,11 +151,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
* los_spinlock.h: the header file that contains the API declaration.
* @see LOS_SpinLock
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave)
-{
- *intSave = LOS_IntLock();
- LOS_SpinLock(lock);
-}
+extern VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave);
/**
* @ingroup los_spinlock
@@ -212,11 +170,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UI
* los_spinlock.h: the header file that contains the API declaration.
* @see LOS_SpinUnlock
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave)
-{
- LOS_SpinUnlock(lock);
- LOS_IntRestore(intSave);
-}
+extern VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave);
/**
* @ingroup los_spinlock
@@ -234,10 +188,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *loc
* @par Dependency:
* los_spinlock.h: the header file that contains the API declaration.
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
-{
- return (lock->rawLock != 0);
-}
+extern BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock);
/**
* @ingroup los_spinlock
@@ -255,17 +206,13 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
* @par Dependency:
* los_spinlock.h: the header file that contains the API declaration.
*/
-LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinInit(SPIN_LOCK_S *lock)
-{
- lock->rawLock = 0;
-#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
- lock->cpuid = (UINT32)-1;
- lock->owner = SPINLOCK_OWNER_INIT;
- lock->name = "spinlock";
-#endif
-}
+extern VOID LOS_SpinInit(SPIN_LOCK_S *lock);
#else
+#define SPIN_LOCK_INITIALIZER(lockName) \
+{ \
+ .rawLock = 0U, \
+}
/*
* For Non-SMP system, these apis does not handle with spinlocks,
@@ -312,6 +259,8 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_SpinInit(SPIN_LOCK_S *lock)
#endif
+#define SPIN_LOCK_INIT(lock) SPIN_LOCK_S lock = SPIN_LOCK_INITIALIZER(lock)
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/include/los_swtmr.h b/kernel/include/los_swtmr.h
old mode 100644
new mode 100755
index 205539f0..68b77c0c
--- a/kernel/include/los_swtmr.h
+++ b/kernel/include/los_swtmr.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -267,14 +267,11 @@ typedef struct tagSwTmrCtrl {
SortLinkList stSortList;
UINT8 ucState; /**< Software timer state */
UINT8 ucMode; /**< Software timer mode */
- UINT8 ucOverrun; /**< Times that a software timer repeats timing */
UINT16 usTimerID; /**< Software timer ID */
+ UINT32 uwOverrun; /**< Times that a software timer repeats timing */
UINT32 uwCount; /**< Times that a software timer works */
UINT32 uwInterval; /**< Timeout interval of a periodic software timer */
UINT32 uwExpiry; /**< Timeout interval of an one-off software timer */
-#if (LOSCFG_KERNEL_SMP == YES)
- UINT32 uwCpuid; /**< The cpu where the timer running on */
-#endif
UINTPTR uwArg; /**< Parameter passed in when the callback function
that handles software timer timeout is called */
SWTMR_PROC_FUNC pfnHandler; /**< Callback function that handles software timer timeout */
diff --git a/kernel/include/los_sys.h b/kernel/include/los_sys.h
index 82747253..26475697 100644
--- a/kernel/include/los_sys.h
+++ b/kernel/include/los_sys.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_tables.h b/kernel/include/los_tables.h
old mode 100644
new mode 100755
index fc66f23e..5b67ac88
--- a/kernel/include/los_tables.h
+++ b/kernel/include/los_tables.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h
old mode 100644
new mode 100755
index afae40ca..49df83b3
--- a/kernel/include/los_task.h
+++ b/kernel/include/los_task.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -914,6 +914,25 @@ extern UINT16 LOS_TaskPriGet(UINT32 taskID);
*/
extern UINT32 LOS_CurTaskIDGet(VOID);
+/**
+ * @ingroup los_task
+ * @brief Gets the maximum number of threads supported by the system.
+ *
+ * @par Description:
+ * This API is used to gets the maximum number of threads supported by the system.
+ *
+ * @attention
+ *
+ * This interface should not be called before system initialized.
+ *
+ *
+ * @retval None.
+ * @par Dependency:
+ * los_task.h: the header file that contains the API declaration.
+ * @see
+ */
+extern UINT32 LOS_GetSystemTaskMaximum(VOID);
+
/**
* @ingroup los_task
* @brief Obtain a task information structure.
@@ -1029,6 +1048,23 @@ extern INT32 LOS_GetTaskScheduler(INT32 taskID);
*/
extern INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority);
+/**
+ * @ingroup los_task
+ * @brief Trigger active task scheduling.
+ *
+ * @par Description:
+ * This API is used to trigger active task scheduling.
+ *
+ * @attention None.
+ *
+ * @param None
+ *
+ * @retval Nobe
+ * @par Dependency:
+ * los_task.h: the header file that contains the API declaration.
+ */
+extern VOID LOS_Schedule(VOID);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/kernel/include/los_tick.h b/kernel/include/los_tick.h
index 54597e60..80b3006d 100644
--- a/kernel/include/los_tick.h
+++ b/kernel/include/los_tick.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_toolchain.h b/kernel/include/los_toolchain.h
index c9d2302f..f118498c 100644
--- a/kernel/include/los_toolchain.h
+++ b/kernel/include/los_toolchain.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/include/los_trace.h b/kernel/include/los_trace.h
old mode 100644
new mode 100755
index df88b090..6a97f1a6
--- a/kernel/include/los_trace.h
+++ b/kernel/include/los_trace.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,9 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef RECORD_TRACE_H
-#define RECORD_TRACE_H
+#ifndef _LOS_TRACE_H
+#define _LOS_TRACE_H
+#include "los_trace_frame.h"
#include "los_base.h"
#ifdef __cplusplus
@@ -40,62 +41,49 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-/**
- * @ingroup los_trace
- * Task error code: Insufficient memory for trace struct.
- *
- * Value: 0x02001400
- *
- * Solution: Decrease the maximum number of tasks.
+/* Provide a mechanism for kernel tracking. Record the data to global buffer,
+ * and you can get the data from /proc/ktrace.
*/
-#define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
/**
* @ingroup los_trace
* Task error code: User type is invalid when register new trace.
*
- * Value: 0x02001401
+ * Value: 0x02001400
*
* Solution: Use valid type to regeister the new trace.
*/
-#define LOS_ERRNO_TRACE_TYPE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
+#define LOS_ERRNO_TRACE_TYPE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
/**
* @ingroup los_trace
* Task error code: The callback function is null when register new trace.
*
- * Value: 0x02001402
+ * Value: 0x02001401
*
* Solution: Use valid callback function to regeister the new trace.
*/
-#define LOS_ERRNO_TRACE_FUNCTION_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
+#define LOS_ERRNO_TRACE_FUNCTION_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
/**
* @ingroup los_trace
- * Task error code: The filled size is 0 when register new trace.
+ * Task error code: The type is already registered.
+ *
+ * Value: 0x02001402
+ *
+ * Solution: Use valid type to regeister the new trace.
+ */
+#define LOS_ERRNO_TRACE_TYPE_EXISTED LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
+
+/**
+ * @ingroup los_trace
+ * Task error code: The type is not registered.
*
* Value: 0x02001403
*
- * Solution: Use valid filled size to regeister the new trace.
+ * Solution: Use valid type to regeister the new trace.
*/
-#define LOS_ERRNO_TRACE_MAX_SIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03)
-
-/**
- * @ingroup los_trace
- * Interrupt direction: enter the new interrupt
- */
-#define IRQ_DIRECT_IN 1
-/**
- * @ingroup los_trace
- * Interrupt direction: leave the old interrupt
- */
-#define IRQ_DIRECT_OUT 0
-
-/**
- * @ingroup los_trace
- * It's the length of tag, filled by los_trace system
- */
-#define LOS_TRACE_TAG_LENGTH sizeof(UINTPTR)
+#define LOS_ERRNO_TRACE_TYPE_NOT_EXISTED LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03)
/**
* @ingroup los_trace
@@ -105,57 +93,30 @@ extern "C" {
* This API is used to define the type of a recording trace function and call it after task or interrupt switch.
* @attention None.
*
-* @param inBuf [IN] Type #UINT8 * The buffer saved trace information.
-* @param newID [IN] Type #UINT32 The destination.
-* @param oldID [IN] Type #UINT32 The source ID for task or the direction for interrupt.
+* @param inBuf [IN] Type #UINT8 * The buffer saved trace information.
+* @param bufLen [IN] Type #UINT32 The buffer len.
+* @param ap [IN] Type #va_list The trace data list.
*
-* @retval None.
+* @retval trace frame length.
* @par Dependency:
* los_trace.h: the header file that contains the API declaration.
* @see
*/
-typedef UINT16 (*WriteHook)(UINT8 *inBuf, UINT32 newID, UINT32 oldID);
+typedef INT32 (*WriteHook)(UINT8 *inBuf, UINT32 bufLen, va_list ap);
/**
* @ingroup los_trace
* Stands for the trace type can be registered.
*/
typedef enum {
- LOS_TRACE_SWITCH = 0, /**< trace for task switch, 0 is reserved for taskswitch */
- LOS_TRACE_INTERRUPT = 1, /**< trace for Interrrupt, 1 is reserved for interrupt */
- LOS_TRACE_TYPE_NUM = 5, /**< num for the register type, user can use 2~ LOS_TRACE_TYPE_NUM-1 */
+ LOS_TRACE_TYPE_MIN = 0,
+ LOS_TRACE_TYPE_MAX = 15,
} TraceType;
-/**
- * @ingroup los_trace
- * struct to store the trace infomation
- */
-typedef struct {
- UINTPTR tracePos; /**< Data buffer current index position */
- UINTPTR traceWrapPos; /**< Data buffer last loop end position */
- UINT8 dataBuf[LOS_TRACE_BUFFER_SIZE]; /**< Data buffer */
-} TraceBuffer;
-
-/**
- * @ingroup los_trace
- * struct to store the task switch infomation
- */
-typedef struct {
- UINT32 srcTaskId; /**< source taskid */
- UINT32 destTaskId; /**< destination taskid */
- UINT64 currentTick; /**< Time at which the task switch happens */
-} TaskTraceFrame;
-
-/**
- * @ingroup los_trace
- * struct to store the interrupt infomation
- */
-typedef struct {
- UINT32 irqDirection; /**< IRQ_DIRECT_IN stands for entering the irq handler */
- /**< IRQ_DIRECT_OUT stands for leaving the previous irq handler */
- UINT32 irqNum; /**< IRQ number which trigger the interrupt */
- UINT64 currentTick; /**< Time at which the the trace is called */
-} IntTraceFrame;
+typedef enum {
+ LOS_TRACE_DISABLE = 0,
+ LOS_TRACE_ENABLE = 1,
+} TraceSwitch;
/**
* @ingroup los_trace
@@ -168,17 +129,16 @@ typedef struct {
* This API can be called only after trace type is intialized. Otherwise, the trace will be failed.
*
*
- * @param traceType [IN] TraceType. Type of trace information.
- * @param newID [IN] UINT32. It stands for the new direction of trace
- * @param oldID [IN] UINT32. It stands for the previous source of trace
+ * @param traceType [IN] TraceType Type of trace information.
+ * @param ... [IN] The trace data.
*
- * @retval NONE.
+ * @retval None.
*
* @par Dependency:
* los_trace.h: the header file that contains the API declaration.
* @see LOS_Trace
*/
-VOID LOS_Trace(TraceType traceType, UINT32 newID, UINT32 oldID);
+VOID LOS_Trace(TraceType traceType, ...);
/**
* @ingroup los_trace
@@ -193,13 +153,12 @@ VOID LOS_Trace(TraceType traceType, UINT32 newID, UINT32 oldID);
*
* @param None.
*
- * @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize.
- * @retval #LOS_OK 0x00000000: The intialization is successful.
+ * @retval None.
* @par Dependency:
* los_trace.h: the header file that contains the API declaration.
* @see LOS_TraceInit
*/
-UINT32 LOS_TraceInit(VOID);
+VOID LOS_TraceInit(VOID);
/**
* @ingroup los_trace
@@ -213,14 +172,14 @@ UINT32 LOS_TraceInit(VOID);
* Otherwise, the trace will be failed.
*
*
- * @param traceType [IN] TraceType. Type of trace information.
- * @param inhook [IN] WriteHook. It's a callback function to store the useful trace
- * information
- * @param useSize [IN] UINT16. The maximum size the trace will use for the specific trace type.
+ * @param traceType [IN] TraceType. Type of trace information.
+ * @param inhook [IN] WriteHook. It's a callback function to store the useful trace information.
+ * @param typeStr [IN] const CHAR *. The trace name of trace type.
+ * @param onOff [IN] TraceSwitch. It only can be LOS_TRACE_DISABLE or LOS_TRACE_ENABLE.
*
* @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize.
* @retval #LOS_ERRNO_TRACE_TYPE_INVALID 0x02001401: The trace type is invalid. Valid type is from
- * LOS_TRACE_TYPE_NUM-1
+ * LOS_TRACE_TYPE_MAX
* @retval #LOS_ERRNO_TRACE_FUNCTION_NULL 0x02001402: The input callback function is NULL
* @retval #LOS_ERRNO_TRACE_MAX_SIZE_INVALID 0x02001403: The information maxmum size is 0 to store.
* @retval #LOS_OK 0x00000000: The registeration is successful.
@@ -229,52 +188,19 @@ UINT32 LOS_TraceInit(VOID);
* los_trace.h: the header file that contains the API declaration.
* @see LOS_TraceUserReg
*/
-UINT32 LOS_TraceUserReg(TraceType traceType, WriteHook inHook, UINT16 useSize);
+UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff);
-/**
- * @ingroup los_trace
- * @brief the function to get certain type trace information frame size.
- *
- * @par Description:
- * This API is used to get certain type trace information frame size.
- * @attention
- *
- * This API can be called to get frame size.
- * Otherwise, the trace will be failed.
- *
- *
- * @param traceType [IN] TraceType. Type of trace information, it must belong to the defined enumeration type.
- *
- * @retval #UINT16 The certain type trace information frame size.
- *
- * @par Dependency:
- * los_trace.h: the header file that contains the API declaration.
- * @see LOS_TraceFrameSizeGet
- */
-INT32 LOS_TraceFrameSizeGet(TraceType traceType);
+UINT32 LOS_TraceUnreg(TraceType traceType);
-/**
- * @ingroup los_trace
- * @brief copy trace buffer of certain cpu to user-defined buffer.
- *
- * @par Description:
- * This API is used to copy system trace buffer of certain cpu to user-defined buffer.
- * @attention
- *
- * This API can be called only after that trace buffer has been established.
- * Otherwise, the trace will be failed.
- *
- *
- * @param cpuID [IN] UINT32. Current cpu ID.
- * @param outputBuf [IN] TraceBuffer. The type of user-defined buffer must be TraceBuffer structure type.
- *
- * @retval #TraceBuffer The point to trace buffer of certain cpuID.
- *
- * @par Dependency:
- * los_trace.h: the header file that contains the API declaration.
- * @see LOS_TraceBufGet
- */
-UINT32 LOS_TraceBufGet(TraceBuffer *outputBuf, UINT32 cpuID);
+UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen);
+
+VOID LOS_TraceSwitch(TraceSwitch onOff);
+
+UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff);
+
+#ifdef LOSCFG_FS_VFS
+INT32 LOS_Trace2File(const CHAR *filename);
+#endif
#ifdef __cplusplus
#if __cplusplus
diff --git a/kernel/include/los_typedef.h b/kernel/include/los_typedef.h
old mode 100644
new mode 100755
index 62001837..b2f5e4ca
--- a/kernel/include/los_typedef.h
+++ b/kernel/include/los_typedef.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/user/Makefile b/kernel/user/Makefile
old mode 100644
new mode 100755
index e5a3d455..6dc3fc56
--- a/kernel/user/Makefile
+++ b/kernel/user/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/kernel/user/include/los_user_init.h b/kernel/user/include/los_user_init.h
old mode 100644
new mode 100755
index 9dadcc8d..225ccbe3
--- a/kernel/user/include/los_user_init.h
+++ b/kernel/user/include/los_user_init.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/kernel/user/src/los_user_init.c b/kernel/user/src/los_user_init.c
old mode 100644
new mode 100755
index d8434323..b16c6634
--- a/kernel/user/src/los_user_init.c
+++ b/kernel/user/src/los_user_init.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,7 +36,11 @@
#define SYS_CALL_VALUE 0x900001
+#ifdef LOSCFG_QUICK_START
+LITE_USER_SEC_RODATA STATIC CHAR *g_initPath = "/dev/shm/init";
+#else
LITE_USER_SEC_RODATA STATIC CHAR *g_initPath = "/bin/init";
+#endif
LITE_USER_SEC_TEXT STATIC UINT32 sys_call3(UINT32 nbr, UINT32 parm1, UINT32 parm2, UINT32 parm3)
{
diff --git a/kernel_test.sources b/kernel_test.sources
new file mode 100755
index 00000000..cab52bfd
--- /dev/null
+++ b/kernel_test.sources
@@ -0,0 +1 @@
+../../kernel/liteos_a/test/apps/src/osTest.c
diff --git a/lib/Kconfig b/lib/Kconfig
old mode 100644
new mode 100755
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
old mode 100644
new mode 100755
index a355a1ed..66a4146b
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -2,40 +2,73 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := c
-$(shell ln -snf $(LITEOSTHIRDPARTY)/musl/kernel/ musl)
+LOCAL_MODULES = \
+ musl/src/ctype \
+ musl/src/env \
+ musl/src/errno \
+ musl/src/exit \
+ musl/src/internal \
+ musl/src/linux \
+ musl/src/locale \
+ musl/src/malloc \
+ musl/src/multibyte \
+ musl/src/network \
+ musl/src/prng \
+ musl/src/sched \
+ musl/src/stdio \
+ musl/src/stdlib \
+ musl/src/string \
+ musl/src/math \
+ musl/src/time
LOCAL_SRCS = $(wildcard musl/src/ctype/*.c) \
- $(wildcard musl/src/env/*.c) \
- $(wildcard musl/src/errno/*.c) \
- $(wildcard musl/src/exit/*.c) \
- $(wildcard musl/src/internal/*.c) \
- $(wildcard musl/src/linux/*.c) \
- $(wildcard musl/src/locale/*.c) \
- $(wildcard musl/src/malloc/*.c) \
- $(wildcard musl/src/math/*.c) \
- $(wildcard musl/src/multibyte/*.c) \
- $(wildcard musl/src/network/*.c) \
- $(wildcard musl/src/prng/*.c) \
- $(wildcard musl/src/sched/*.c) \
- $(wildcard musl/src/stdio/*.c) \
- $(wildcard musl/src/stdlib/*.c) \
- $(wildcard musl/src/string/*.c) \
- $(wildcard musl/src/time/*.c)
+ $(wildcard musl/src/env/*.c) \
+ $(wildcard musl/src/errno/*.c) \
+ $(wildcard musl/src/exit/*.c) \
+ $(wildcard musl/src/linux/*.c) \
+ $(wildcard musl/src/locale/*.c) \
+ $(wildcard musl/src/malloc/*.c) \
+ $(wildcard musl/src/multibyte/*.c) \
+ $(wildcard musl/src/network/*.c) \
+ $(wildcard musl/src/prng/*.c) \
+ $(wildcard musl/src/sched/*.c) \
+ $(wildcard musl/src/stdlib/*.c)
+
+ifeq ($(LOSCFG_ARCH_ARM_VER), "armv7-a")
+LOCAL_SRCS += \
+ optimization/arm/memchr.S \
+ optimization/arm/memcpy.S \
+ optimization/arm/strcmp.S \
+ optimization/arm/strcpy.c \
+ optimization/arm/strlen.S
+endif
+
+LOCAL_SRCS_MATH = $(wildcard musl/src/math/*.c)
+LOCAL_SRCS_INTERNAL = $(wildcard musl/src/internal/*.c)
+LOCAL_SRCS_STDIO = $(wildcard musl/src/stdio/*.c)
+LOCAL_SRCS_STRING = $(wildcard musl/src/string/*.c)
+LOCAL_SRCS_TIME = $(wildcard musl/src/time/*.c)
+
+ifeq ($(LOSCFG_ARCH_ARM_VER), "armv7-a")
+LOCAL_FILTER_SRCS_STRING = memchr.c memcpy.c strcmp.c strcpy.c strlen.c
+LOCAL_SRCS_STRING := $(filter-out $(LOCAL_FILTER_SRCS_STRING),$(wildcard musl/src/string/*.c))
+endif
LOCAL_INCLUDE := \
- -I $(LITEOSTOPDIR)/lib/libc/musl/include \
- -I $(LITEOSTOPDIR)/lib/libc/musl/arch/arm \
- -I $(LITEOSTOPDIR)/lib/libc/musl/arch/generic \
- -I $(LITEOSTOPDIR)/lib/libc/musl/obj/include \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/include \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/dirent \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/errno \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/internal \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/multibyte \
- -I $(LITEOSTOPDIR)/lib/libc/musl/src/time \
- -I $(LITEOSTOPDIR)/syscall \
- -I $(LITEOSTOPDIR)/bsd/dev/random \
- -I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
+ -I $(LITEOSTOPDIR)/lib/libc/musl/include \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/arch/arm \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/arch/generic \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/obj/include \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/include \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/dirent \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/errno \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/internal \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/multibyte \
+ -I $(LITEOSTOPDIR)/lib/libc/musl/src/time \
+ -I $(LITEOSTOPDIR)/syscall \
+ -I $(LITEOSTOPDIR)/bsd/dev/random \
+ -I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
+
ifeq ($(LOSCFG_LLTSER), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/tools/gcov_ser
endif
@@ -47,4 +80,110 @@ else
LOCAL_FLAGS += -frounding-math -Wno-unused-but-set-variable -Wno-unknown-pragmas
endif
-include $(MODULE)
+ifeq ($(OS), Linux)
+OBJOUT := $(BUILD)$(dir $(subst $(LITEOSTOPDIR),,$(shell pwd)))$(MODULE_NAME)
+LOCAL_PWD := $(shell pwd)
+else
+TEMPLITEOSTOPDIR:=$(shell cygpath -u $(LITEOSTOPDIR))
+OBJOUT := $(BUILD)$(dir $(subst $(TEMPLITEOSTOPDIR),,$(shell pwd)))$(MODULE_NAME)
+LOCAL_PWD := $(shell cygpath -m $(shell pwd))
+endif
+
+ifeq ($(LOCAL_SO), y)
+LIBSO := $(OUT)/lib/lib$(MODULE_NAME).so
+LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
+else
+LIBSO :=
+LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
+endif
+LIB := $(LIBA) $(LIBSO)
+
+# create a separate list of objects per source type
+
+LOCAL_CSRCS := $(filter %.c,$(LOCAL_SRCS))
+LOCAL_CSRCS_MATH := $(filter %.c,$(LOCAL_SRCS_MATH))
+LOCAL_CSRCS_INTERNAL := $(filter %.c,$(LOCAL_SRCS_INTERNAL))
+LOCAL_CSRCS_STDIO := $(filter %.c,$(LOCAL_SRCS_STDIO))
+LOCAL_CSRCS_STRING := $(filter %.c,$(LOCAL_SRCS_STRING))
+LOCAL_CSRCS_TIME := $(filter %.c,$(LOCAL_SRCS_TIME))
+
+LOCAL_ASMSRCS := $(filter %.S,$(LOCAL_SRCS))
+
+LOCAL_COBJS := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS))
+LOCAL_COBJS_MATH := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS_MATH))
+LOCAL_COBJS_INTERNAL := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS_INTERNAL))
+LOCAL_COBJS_STDIO := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS_STDIO))
+LOCAL_COBJS_STRING := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS_STRING))
+LOCAL_COBJS_TIME := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS_TIME))
+
+LOCAL_ASMOBJS := $(patsubst %.S,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS))
+
+LOCAL_OBJS := $(LOCAL_COBJS) $(LOCAL_ASMOBJS) $(LOCAL_COBJS_MATH) $(LOCAL_COBJS_INTERNAL) $(LOCAL_COBJS_STDIO) $(LOCAL_COBJS_STRING) $(LOCAL_COBJS_TIME)
+LOCAL_CGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CHS))
+LOCAL_CPPGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CPPHS))
+
+all : $(LIB)
+
+$(LOCAL_COBJS): $(OBJOUT)/%.o: %.c sub_math
+ $(HIDE)$(OBJ_MKDIR)
+ $(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) -c $< -o $@
+
+$(LOCAL_ASMOBJS): $(OBJOUT)/%.o: %.S
+ $(HIDE)$(OBJ_MKDIR)
+ $(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) -c $< -o $@
+
+sub_math:
+ $(HIDE)$(MAKE) -C musl/src/math all LOCAL_COBJS_MATH="$(LOCAL_COBJS_MATH)" OBJOUT="$(OBJOUT)" LOCAL_FLAGS="$(LOCAL_FLAGS)"
+
+sub_internal: sub_math
+ $(HIDE)$(MAKE) -C musl/src/internal all LOCAL_COBJS_INTERNAL="$(LOCAL_COBJS_INTERNAL)" OBJOUT="$(OBJOUT)" LOCAL_FLAGS="$(LOCAL_FLAGS)"
+
+sub_stdio: sub_math
+ $(HIDE)$(MAKE) -C musl/src/stdio all LOCAL_COBJS_STDIO="$(LOCAL_COBJS_STDIO)" OBJOUT="$(OBJOUT)" LOCAL_FLAGS="$(LOCAL_FLAGS)"
+
+sub_string: sub_math
+ $(HIDE)$(MAKE) -C musl/src/string all LOCAL_COBJS_STRING="$(LOCAL_COBJS_STRING)" OBJOUT="$(OBJOUT)" LOCAL_FLAGS="$(LOCAL_FLAGS)"
+
+sub_time: sub_math
+ $(HIDE)$(MAKE) -C musl/src/time all LOCAL_COBJS_TIME="$(LOCAL_COBJS_TIME)" OBJOUT="$(OBJOUT)" LOCAL_FLAGS="$(LOCAL_FLAGS)"
+
+$(LOCAL_CGCH): %.h.gch : %.h
+ $(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) $> $^
+
+$(LOCAL_CPPGCH): %.h.gch : %.h
+ $(HIDE)$(GPP) $(LITEOS_CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -x c++-header $> $^
+
+LOCAL_GCH := $(LOCAL_CGCH) $(LOCAL_CPPGCH)
+
+$(LOCAL_OBJS): $(LOCAL_GCH)
+$(LIBA): $(LOCAL_OBJS) sub_math sub_internal sub_stdio sub_string sub_time
+ $(HIDE)$(OBJ_MKDIR)
+
+ifeq ($(OS), Linux)
+ $(HIDE)$(AR) $(ARFLAGS) $@ $(LOCAL_OBJS)
+else
+ifeq ($(LOCAL_MODULES),)
+ $(HIDE)$(AR) $(ARFLAGS) $@ $(LOCAL_OBJS)
+else
+ $(HIDE)for i in $(LOCAL_MODULES); do \
+ pushd $(OBJOUT)/$$i 1>/dev/null; \
+ $(AR) $(ARFLAGS) $@ *.o;\
+ popd 1>/dev/null;\
+ done
+endif
+endif
+
+ifeq ($(LOCAL_SO), y)
+$(LIBSO): $(LOCAL_OBJS)
+ $(HIDE)$(CC) $(LITEOS_CFLAGS) -fPIC -shared $^ -o $@
+endif
+
+clean:
+ $(HIDE)$(RM) $(LIB) $(OBJOUT) $(LOCAL_GCH) *.bak *~
+
+.PHONY: all clean sub_math sub_internal sub_stdio sub_string sub_time
+
+# clear some variables we set here
+LOCAL_CSRCS :=
+LOCAL_COBJS :=
+
diff --git a/lib/libc/musl b/lib/libc/musl
new file mode 120000
index 00000000..939d63a1
--- /dev/null
+++ b/lib/libc/musl
@@ -0,0 +1 @@
+../../../../third_party/musl/kernel
\ No newline at end of file
diff --git a/lib/libc/optimization/arm/memchr.S b/lib/libc/optimization/arm/memchr.S
new file mode 120000
index 00000000..eda33c21
--- /dev/null
+++ b/lib/libc/optimization/arm/memchr.S
@@ -0,0 +1 @@
+../../../../../../third_party/optimized-routines/string/arm/memchr.S
\ No newline at end of file
diff --git a/lib/libc/optimization/arm/memcpy.S b/lib/libc/optimization/arm/memcpy.S
new file mode 120000
index 00000000..2c97f410
--- /dev/null
+++ b/lib/libc/optimization/arm/memcpy.S
@@ -0,0 +1 @@
+../../../../../../third_party/optimized-routines/string/arm/memcpy.S
\ No newline at end of file
diff --git a/lib/libc/optimization/arm/strcmp.S b/lib/libc/optimization/arm/strcmp.S
new file mode 120000
index 00000000..921ebe90
--- /dev/null
+++ b/lib/libc/optimization/arm/strcmp.S
@@ -0,0 +1 @@
+../../../../../../third_party/optimized-routines/string/arm/strcmp.S
\ No newline at end of file
diff --git a/lib/libc/optimization/arm/strcpy.c b/lib/libc/optimization/arm/strcpy.c
new file mode 120000
index 00000000..ab07c4d1
--- /dev/null
+++ b/lib/libc/optimization/arm/strcpy.c
@@ -0,0 +1 @@
+../../../../../../third_party/optimized-routines/string/arm/strcpy.c
\ No newline at end of file
diff --git a/lib/libc/optimization/arm/strlen.S b/lib/libc/optimization/arm/strlen.S
new file mode 120000
index 00000000..eecf51cc
--- /dev/null
+++ b/lib/libc/optimization/arm/strlen.S
@@ -0,0 +1 @@
+../../../../../../third_party/optimized-routines/string/arm/strlen-armv6t2.S
\ No newline at end of file
diff --git a/lib/libc/optimization/asmdefs.h b/lib/libc/optimization/asmdefs.h
new file mode 120000
index 00000000..1cb01634
--- /dev/null
+++ b/lib/libc/optimization/asmdefs.h
@@ -0,0 +1 @@
+../../../../../third_party/optimized-routines/string/asmdefs.h
\ No newline at end of file
diff --git a/lib/libscrew/include/los_crc32.h b/lib/libscrew/include/los_crc32.h
index ef89f30d..7101e2d1 100644
--- a/lib/libscrew/include/los_crc32.h
+++ b/lib/libscrew/include/los_crc32.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/lib/libscrew/include/los_rbtree.h b/lib/libscrew/include/los_rbtree.h
index d21bccaf..7919f689 100644
--- a/lib/libscrew/include/los_rbtree.h
+++ b/lib/libscrew/include/los_rbtree.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -55,7 +55,7 @@ typedef struct TagRbNode {
ULONG_T lColor;
} LosRbNode;
-typedef ULONG_T (*pfRBCmpKeyFn)(VOID *, VOID *);
+typedef ULONG_T (*pfRBCmpKeyFn)(const VOID *, const VOID *);
typedef ULONG_T (*pfRBFreeFn)(LosRbNode *);
typedef VOID *(*pfRBGetKeyFn)(LosRbNode *);
diff --git a/lib/libscrew/src/los_crc32.c b/lib/libscrew/src/los_crc32.c
index 81b66a8d..ad6ea030 100644
--- a/lib/libscrew/src/los_crc32.c
+++ b/lib/libscrew/src/los_crc32.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/lib/libscrew/src/los_rbtree.c b/lib/libscrew/src/los_rbtree.c
old mode 100644
new mode 100755
index b9466e78..bcd02dda
--- a/lib/libscrew/src/los_rbtree.c
+++ b/lib/libscrew/src/los_rbtree.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -296,9 +296,6 @@ STATIC VOID OsRbDeleteNode(LosRbTree *pstTree, VOID *pstData)
return;
}
- if (pstTree == NULL) {
- return;
- }
(pstTree->ulNodes)--;
if (!LOS_ListEmpty(&pstTree->stWalkHead)) {
diff --git a/lib/libsec/Makefile b/lib/libsec/Makefile
old mode 100644
new mode 100755
diff --git a/net/Kconfig b/net/Kconfig
index 4e1e47d7..36a9e16b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -25,6 +25,10 @@ config NET_LWIP_SACK_2_1
bool "Enable Lwipsack (2.1)"
depends on NET_LWIP_SACK
+config NET_LWIP_SACK_2_0
+ bool "Enable Lwipsack (2.0)"
+ depends on NET_LWIP_SACK
+
endchoice
endmenu
diff --git a/net/lwip-2.1/Makefile b/net/lwip-2.1/Makefile
index 5194ad9e..c38e9119 100644
--- a/net/lwip-2.1/Makefile
+++ b/net/lwip-2.1/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/net/lwip-2.1/enhancement/include/lwip/api_shell.h b/net/lwip-2.1/enhancement/include/lwip/api_shell.h
old mode 100644
new mode 100755
index 4575c6e6..7b212301
--- a/net/lwip-2.1/enhancement/include/lwip/api_shell.h
+++ b/net/lwip-2.1/enhancement/include/lwip/api_shell.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/enhancement/include/lwip/dhcps.h b/net/lwip-2.1/enhancement/include/lwip/dhcps.h
index 261938ee..bab711a4 100644
--- a/net/lwip-2.1/enhancement/include/lwip/dhcps.h
+++ b/net/lwip-2.1/enhancement/include/lwip/dhcps.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/enhancement/include/lwip/fixme.h b/net/lwip-2.1/enhancement/include/lwip/fixme.h
index 75687417..49bec93d 100644
--- a/net/lwip-2.1/enhancement/include/lwip/fixme.h
+++ b/net/lwip-2.1/enhancement/include/lwip/fixme.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -47,7 +47,6 @@
#define ip_tx_bytes cachehit
#define DUP_ARP_DETECT_TIME 2000 /* 2 seconds period */
-#define SOF_BINDNONUNICAST 0x0800U /* socket has bind to a non unicast */
#define NETCONN_PKT_RAW 0x80
#define SYS_ARCH_ERROR 0x7fffffffUL
diff --git a/net/lwip-2.1/enhancement/src/api_shell.c b/net/lwip-2.1/enhancement/src/api_shell.c
index 24df1b48..28921cd4 100644
--- a/net/lwip-2.1/enhancement/src/api_shell.c
+++ b/net/lwip-2.1/enhancement/src/api_shell.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -63,7 +63,6 @@
#include
#include "lwip/api_shell.h"
-#include "lwip/tftpc.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
@@ -276,6 +275,9 @@ int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
char *addr = NULL;
#endif
+ if (buf_len < 1) {
+ goto out;
+ }
if (netif->link_layer_type == LOOPBACK_IF) {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%.2s\t", netif->name);
} else {
@@ -1173,6 +1175,9 @@ void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int
u8_t state, i;
int ret;
char *tmp = printf_buf;
+ if (buf_len < 1) {
+ return;
+ }
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%-24s%-24s%-12s%-12s\n", "Address", "HWaddress", "Iface", "Type");
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
return;
@@ -1874,7 +1879,7 @@ u32_t osShellPing(int argc, const char **argv)
#endif /* LWIP_DNS */
if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) {
- PRINTK("Invalid dest ipaddr: %s\n", argv[i]);
+ PRINTK("Invalid dest ipaddr: NONE or ANY\n");
return LOS_NOK;
}
@@ -1971,7 +1976,7 @@ u32_t osShellPing(int argc, const char **argv)
to.sin_port = 0;
if (to.sin_addr.s_addr == IPADDR_NONE || to.sin_addr.s_addr == IPADDR_ANY) {
- PRINTK("ping : invalid ip address : %s\n", argv[0]);
+ PRINTK("ping : invalid ip address : NONE or ANY\n");
return LOS_NOK;
}
@@ -2627,126 +2632,6 @@ SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc
#endif /* LWIP_SNTP*/
-
-#ifdef LOSCFG_NET_LWIP_SACK_TFTP
-static char *TftpError[] = {
- "TFTP transfer finish\n",
- "Error while creating UDP socket\n",
- "Error while binding to the UDP socket\n",
- "Error returned by select() system call\n",
- "Error while receiving data from the peer\n",
- "Error while sending data to the peer\n",
- "Requested file is not found\n",
- "This is the error sent by the server when hostname cannot be resolved\n",
- "Input paramters passed to TFTP interfaces are invalid\n",
- "Error detected in TFTP packet or the error received from the TFTP server\n",
- "Error during packet synhronization while sending or unexpected packet is received\n",
- "File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n",
- "File name lenght greater than 256\n",
- "Hostname IP is not valid\n",
- "TFTP server returned file access error\n",
- "TFTP server returned error signifying that the DISK is full to write\n",
- "TFTP server returned error signifying that the file exist\n",
- "The source file name do not exisits\n",
- "Memory allocaion failed in TFTP client\n",
- "File open failed\n",
- "File read error\n",
- "File create error\n",
- "File write error\n",
- "Max time expired while waiting for file to be recived\n",
- "Error when the received packet is less than 4bytes(error lenght) or greater than 512bytes\n",
- "Returned by TFTP server for protocol user error\n",
- "The destination file path length greater than 256\n",
- "Returned by TFTP server for undefined transfer ID\n",
- "IOCTL fucntion failed at TFTP client while setting the socket to non-block\n",
-};
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-#endif
-
-u32_t osShellTftp(int argc, const char **argv)
-{
- u32_t ulRemoteAddr = IPADDR_NONE;
- const u16_t usTftpServPort = 69;
- u8_t ucTftpGet = 0;
- s8_t *szLocalFileName = NULL;
- s8_t *szRemoteFileName = NULL;
- u32_t ret;
-
- int i = 0;
- if (argc < 1 || argv == NULL) {
- goto usage;
- }
-
- if (!tcpip_init_finish) {
- PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
- return LOS_NOK;
- }
-
- while (i < argc) {
- if (strcmp(argv[i], "-p") == 0) {
- ucTftpGet = 0;
- i++;
- continue;
- }
-
- if (strcmp(argv[i], "-g") == 0) {
- ucTftpGet = 1;
- i++;
- continue;
- }
-
- if (strcmp(argv[i], "-l") == 0 && ((i + 1) < argc)) {
- szLocalFileName = (s8_t *)argv[i + 1];
- i += 2;
- continue;
- }
-
- if (strcmp(argv[i], "-r") == 0 && ((i + 1) < argc)) {
- szRemoteFileName = (s8_t *)argv[i + 1];
- i += 2;
- continue;
- }
-
- if ((i + 1) == argc) {
- ulRemoteAddr = inet_addr(argv[i]);
- break;
- }
-
- goto usage;
- }
-
- if (ulRemoteAddr == IPADDR_NONE || szLocalFileName == NULL || szRemoteFileName == NULL) {
- goto usage;
- }
-
- if (ucTftpGet) {
- ret = lwip_tftp_get_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
- TRANSFER_MODE_BINARY, szRemoteFileName, szLocalFileName);
- } else {
- ret = lwip_tftp_put_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
- TRANSFER_MODE_BINARY, szLocalFileName, szRemoteFileName);
- }
-
- LWIP_ASSERT("TFTP UNKNOW ERROR!", ret < ARRAY_SIZE(TftpError));
- PRINTK("%s", TftpError[ret]);
- if (ret) {
- return LOS_NOK;
- } else {
- return LOS_OK;
- }
-usage:
- PRINTK("usage:\nTransfer a file from/to tftp server\n");
- PRINTK("tftp <-g/-p> -l FullPathLocalFile -r RemoteFile Host\n");
- return LOS_NOK;
-}
-#ifdef LOSCFG_SHELL_CMD_DEBUG
-SHELLCMD_ENTRY(tftp_shellcmd, CMD_TYPE_EX, "tftp", XARGS, (CmdCallBackFunc)osShellTftp);
-#endif /* LOSCFG_SHELL_CMD_DEBUG */
-#endif /* LOSCFG_NET_LWIP_SACK_TFTP */
-
-
#if LWIP_DNS
u32_t osShellDns(int argc, const char **argv)
{
@@ -2841,7 +2726,6 @@ int netstat_get_udp_sendQLen6(struct udp_pcb *udppcb, struct pbuf *udpbuf)
if (!(ip6_addr_cmp(&iphdr->dest, ip_2_ip6(&udppcb->remote_ip)) &&
(ip_addr_isany(&udppcb->local_ip) ||
- ip_get_option(udppcb, SOF_BINDNONUNICAST) ||
ip6_addr_cmp(&iphdr->src, ip_2_ip6(&udppcb->local_ip))))) {
goto FUNC_OUT;
}
@@ -2930,7 +2814,6 @@ int netstat_get_udp_sendQLen(struct udp_pcb *udppcb, struct pbuf *udpbuf)
if (!(ip4_addr_cmp(&iphdr->dest, ip_2_ip4(&udppcb->remote_ip)) &&
(ip_addr_isany(&udppcb->local_ip) ||
- ip_get_option(udppcb, SOF_BINDNONUNICAST) ||
ip4_addr_cmp(&iphdr->src, ip_2_ip4(&udppcb->local_ip))))) {
goto FUNC_OUT;
}
@@ -3883,7 +3766,7 @@ u32_t osShellIpDebug(int argc, const char **argv)
for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) {
if (prefix_list[i].netif != NULL && prefix_list[i].invalidation_timer > 0) {
atleastOneEntry = 1;
- (void)ip6addr_ntoa_r((const ip6_addr_t *)(prefix_list[i].prefix.addr), (acIPv6Addr), INET6_ADDRSTRLEN);
+ (void)ip6addr_ntoa_r((const ip6_addr_t *)(prefix_list[i].prefix.addr), (acIPv6Addr), sizeof(acIPv6Addr));
PRINTK("%-50s ", acIPv6Addr);
PRINTK("%-16s ", netif_get_name(prefix_list[i].netif));
PRINTK("%-20u\n", prefix_list[i].invalidation_timer);
@@ -3910,7 +3793,7 @@ u32_t osShellIpDebug(int argc, const char **argv)
if (neighbor_cache[i].state != ND6_NO_ENTRY) {
atleastOneEntry = 1;
(void)ip6addr_ntoa_r((const ip6_addr_t *)(neighbor_cache[i].next_hop_address.addr), (acIPv6Addr),
- INET6_ADDRSTRLEN);
+ sizeof(acIPv6Addr));
PRINTK("%-50s ", acIPv6Addr);
if (snprintf_s(aclladdr, sizeof(aclladdr), sizeof(aclladdr) - 1, "%02X:%02X:%02X:%02X:%02X:%02X",
@@ -3944,10 +3827,10 @@ u32_t osShellIpDebug(int argc, const char **argv)
if (!ip6_addr_isany(&(destination_cache[i].destination_addr))) {
atleastOneEntry = 1;
(void)ip6addr_ntoa_r((const ip6_addr_t *)(destination_cache[i].destination_addr.addr), (acIPv6Addr),
- INET6_ADDRSTRLEN);
+ sizeof(acIPv6Addr));
PRINTK("%-50s ", acIPv6Addr);
(void)ip6addr_ntoa_r((const ip6_addr_t *)(destination_cache[i].next_hop_addr.addr), (acIPv6Addr),
- INET6_ADDRSTRLEN);
+ sizeof(acIPv6Addr));
PRINTK("%-50s ", acIPv6Addr);
PRINTK("%-10u ", destination_cache[i].pmtu);
PRINTK("%-10u\n", destination_cache[i].age);
@@ -3971,7 +3854,7 @@ u32_t osShellIpDebug(int argc, const char **argv)
if (default_router_list[i].neighbor_entry) {
atleastOneEntry = 1;
(void)ip6addr_ntoa_r((const ip6_addr_t *)((default_router_list[i].neighbor_entry)->next_hop_address.addr),
- (acIPv6Addr), INET6_ADDRSTRLEN);
+ (acIPv6Addr), sizeof(acIPv6Addr));
PRINTK("%-50s ", acIPv6Addr);
PRINTK("%-20u ", default_router_list[i].invalidation_timer);
PRINTK("%-10u\n", default_router_list[i].flags);
diff --git a/net/lwip-2.1/enhancement/src/dhcps.c b/net/lwip-2.1/enhancement/src/dhcps.c
index 0d386468..e31a4794 100644
--- a/net/lwip-2.1/enhancement/src/dhcps.c
+++ b/net/lwip-2.1/enhancement/src/dhcps.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -487,7 +487,6 @@ LWIP_STATIC ip4_addr_t validate_request_message(struct netif *netif, struct dhcp
if (client_lease == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
("validate_request_message: No Configuration found corresponding to request message\n"));
- requested_ip.addr = 1;
return requested_ip;
}
diff --git a/net/lwip-2.1/enhancement/src/fixme.c b/net/lwip-2.1/enhancement/src/fixme.c
index 3f473f3c..5bb6c3f7 100644
--- a/net/lwip-2.1/enhancement/src/fixme.c
+++ b/net/lwip-2.1/enhancement/src/fixme.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -438,7 +438,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
current_block_value = 0;
} else if (lwip_isxdigit(*s) && (s - ss) < 5) { // 4 hex-digits at most
current_block_value = (current_block_value << 4) +
- (*s | ('a' - 'A')) - '0' - ('a' - '9' - 1) * (*s >= 'A');
+ ((u8_t)(*s) | ('a' - 'A')) - '0' - ('a' - '9' - 1) * (*s >= 'A');
#if LWIP_IPV4
} else if (*s == '.' && current_block_index < ipv6_blocks - 1) {
ip4_addr_t ip4;
diff --git a/net/lwip-2.1/porting/include/arch/cc.h b/net/lwip-2.1/porting/include/arch/cc.h
index 44846c7d..9dd49830 100644
--- a/net/lwip-2.1/porting/include/arch/cc.h
+++ b/net/lwip-2.1/porting/include/arch/cc.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/arch/perf.h b/net/lwip-2.1/porting/include/arch/perf.h
index 4c510336..dea6a694 100644
--- a/net/lwip-2.1/porting/include/arch/perf.h
+++ b/net/lwip-2.1/porting/include/arch/perf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/arch/sys_arch.h b/net/lwip-2.1/porting/include/arch/sys_arch.h
index 798fdecd..19e76bee 100644
--- a/net/lwip-2.1/porting/include/arch/sys_arch.h
+++ b/net/lwip-2.1/porting/include/arch/sys_arch.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/dhcp.h b/net/lwip-2.1/porting/include/lwip/dhcp.h
index b6b37ad7..59b52e70 100644
--- a/net/lwip-2.1/porting/include/lwip/dhcp.h
+++ b/net/lwip-2.1/porting/include/lwip/dhcp.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/inet.h b/net/lwip-2.1/porting/include/lwip/inet.h
index 0f833f7b..414b6bc6 100644
--- a/net/lwip-2.1/porting/include/lwip/inet.h
+++ b/net/lwip-2.1/porting/include/lwip/inet.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/lwipopts.h b/net/lwip-2.1/porting/include/lwip/lwipopts.h
old mode 100644
new mode 100755
index d172aa87..3656f696
--- a/net/lwip-2.1/porting/include/lwip/lwipopts.h
+++ b/net/lwip-2.1/porting/include/lwip/lwipopts.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -218,7 +218,6 @@
// Options for enhancement code, same for old lwipopts.h
#define LWIP_NETIF_PROMISC 1
-#define LWIP_TFTP LOSCFG_NET_LWIP_SACK_TFTP
#define LWIP_DHCPS 1
#define LWIP_ENABLE_NET_CAPABILITY 1
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
diff --git a/net/lwip-2.1/porting/include/lwip/netif.h b/net/lwip-2.1/porting/include/lwip/netif.h
index 06774ddf..2633cd71 100644
--- a/net/lwip-2.1/porting/include/lwip/netif.h
+++ b/net/lwip-2.1/porting/include/lwip/netif.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/netifapi.h b/net/lwip-2.1/porting/include/lwip/netifapi.h
index c6a35e74..4bfcc835 100644
--- a/net/lwip-2.1/porting/include/lwip/netifapi.h
+++ b/net/lwip-2.1/porting/include/lwip/netifapi.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/pbuf.h b/net/lwip-2.1/porting/include/lwip/pbuf.h
index c7915a35..79968178 100644
--- a/net/lwip-2.1/porting/include/lwip/pbuf.h
+++ b/net/lwip-2.1/porting/include/lwip/pbuf.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/priv/api_msg.h b/net/lwip-2.1/porting/include/lwip/priv/api_msg.h
index 3492b046..573aac6b 100644
--- a/net/lwip-2.1/porting/include/lwip/priv/api_msg.h
+++ b/net/lwip-2.1/porting/include/lwip/priv/api_msg.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/priv/sockets_priv.h b/net/lwip-2.1/porting/include/lwip/priv/sockets_priv.h
index e96bd935..dfab001e 100644
--- a/net/lwip-2.1/porting/include/lwip/priv/sockets_priv.h
+++ b/net/lwip-2.1/porting/include/lwip/priv/sockets_priv.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwip/sockets.h b/net/lwip-2.1/porting/include/lwip/sockets.h
index 30a5a7d8..af3dcb25 100644
--- a/net/lwip-2.1/porting/include/lwip/sockets.h
+++ b/net/lwip-2.1/porting/include/lwip/sockets.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/include/lwipopts.h b/net/lwip-2.1/porting/include/lwipopts.h
index 2e24ce6e..5a2d3545 100644
--- a/net/lwip-2.1/porting/include/lwipopts.h
+++ b/net/lwip-2.1/porting/include/lwipopts.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/src/driverif.c b/net/lwip-2.1/porting/src/driverif.c
index a4441015..ed233838 100644
--- a/net/lwip-2.1/porting/src/driverif.c
+++ b/net/lwip-2.1/porting/src/driverif.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/src/sockets.c b/net/lwip-2.1/porting/src/sockets.c
old mode 100644
new mode 100755
index 8e4740e3..95cfa0bf
--- a/net/lwip-2.1/porting/src/sockets.c
+++ b/net/lwip-2.1/porting/src/sockets.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/lwip-2.1/porting/src/sys_arch.c b/net/lwip-2.1/porting/src/sys_arch.c
index e591e8c2..9826fba7 100644
--- a/net/lwip-2.1/porting/src/sys_arch.c
+++ b/net/lwip-2.1/porting/src/sys_arch.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/mac/los_mac.h b/net/mac/los_mac.h
index c42ea628..88d36a14 100644
--- a/net/mac/los_mac.h
+++ b/net/mac/los_mac.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/telnet/Makefile b/net/telnet/Makefile
index 8143998f..aa2f3b8d 100644
--- a/net/telnet/Makefile
+++ b/net/telnet/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/net/telnet/include/telnet_dev.h b/net/telnet/include/telnet_dev.h
old mode 100644
new mode 100755
index 77815488..23d56fc8
--- a/net/telnet/include/telnet_dev.h
+++ b/net/telnet/include/telnet_dev.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/telnet/include/telnet_loop.h b/net/telnet/include/telnet_loop.h
old mode 100644
new mode 100755
index 7388a77e..c8ef2f1f
--- a/net/telnet/include/telnet_loop.h
+++ b/net/telnet/include/telnet_loop.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/telnet/include/telnet_pri.h b/net/telnet/include/telnet_pri.h
index a1d24e8b..e710c910 100644
--- a/net/telnet/include/telnet_pri.h
+++ b/net/telnet/include/telnet_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/net/telnet/src/telnet_dev.c b/net/telnet/src/telnet_dev.c
old mode 100644
new mode 100755
index e921aa9a..77fbca07
--- a/net/telnet/src/telnet_dev.c
+++ b/net/telnet/src/telnet_dev.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -41,6 +41,7 @@
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#include "los_swtmr_pri.h"
#endif
+#include "los_sched_pri.h"
#include "console.h"
#include "lwip/opt.h"
#include "lwip/sockets.h"
diff --git a/net/telnet/src/telnet_loop.c b/net/telnet/src/telnet_loop.c
index 8f69c7b7..87747b18 100644
--- a/net/telnet/src/telnet_loop.c
+++ b/net/telnet/src/telnet_loop.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/Kconfig b/platform/Kconfig
old mode 100644
new mode 100755
index db1af3f9..a9886b3c
--- a/platform/Kconfig
+++ b/platform/Kconfig
@@ -4,8 +4,22 @@ config PLATFORM
default "hi3518ev300" if PLATFORM_HI3518EV300
default "virt" if PLATFORM_QEMU_ARM_VIRT_CA7
+config PRODUCT_NAME
+ string
+ default "ipcamera_hi3516dv300_liteos" if PRODUCT_IPCAMERA_HI3516DV300_LITEOS
+ default "ipcamera_hi3518ev300_liteos" if PRODUCT_IPCAMERA_HI3518EV300_LITEOS
+ default "hispark_taurus" if PRODUCT_HISPARK_TAURUS
+ default "hispark_aries" if PRODUCT_HISPARK_ARIES
+ default "arm_virt" if PRODUCT_QEMU_ARM
+
+config DEVICE_COMPANY
+ string
+ default "hisilicon" if PLATFORM_HI3516DV300
+ default "hisilicon" if PLATFORM_HI3518EV300
+ default "qemu" if PLATFORM_QEMU_ARM_VIRT_CA7
+
choice
- prompt "Board"
+ prompt "Chip"
default PLATFORM_HI3516DV300
help
IPC has several chips:
@@ -30,6 +44,29 @@ config PLATFORM_QEMU_ARM_VIRT_CA7
endchoice
+choice
+ prompt "Porduct"
+ help
+ Select your target board.
+
+config PRODUCT_IPCAMERA_HI3516DV300_LITEOS
+ bool "ipcamera_hi3516dv300_liteos" if PLATFORM_HI3516DV300
+config PRODUCT_HISPARK_TAURUS
+ bool "hispark_taurus" if PLATFORM_HI3516DV300
+
+config PRODUCT_IPCAMERA_HI3518EV300_LITEOS
+ bool "ipcamera_hi3518ev300_liteos" if PLATFORM_HI3518EV300
+config PRODUCT_HISPARK_ARIES
+ bool "hispark_aries" if PLATFORM_HI3518EV300
+
+config PRODUCT_QEMU_ARM
+ bool "arm_virt" if PLATFORM_QEMU_ARM_VIRT_CA7
+endchoice
+
+config BOARD_CONFIG_PATH
+ string "BOARD CONFIG PATH"
+ default "config/board"
+
config TEE_ENABLE
bool "ENABLE TEE"
default n
diff --git a/platform/Makefile b/platform/Makefile
old mode 100644
new mode 100755
index 34ab7750..33e81e1a
--- a/platform/Makefile
+++ b/platform/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -60,10 +60,6 @@ LOCAL_SRCS += $(wildcard ../kernel/common/los_config.c)
LOCAL_SRCS += $(wildcard ../kernel/common/los_printf.c)
endif
-ifeq ($(LOSCFG_DRIVERS_USB), y)
-LOCAL_SRCS += $(wildcard $(USB_SRC)/*.c)
-endif
-
ifeq ($(LOSCFG_KERNEL_TICKLESS), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/include
endif
diff --git a/platform/board.ld.S b/platform/board.ld.S
index ef3d8171..92788d04 100644
--- a/platform/board.ld.S
+++ b/platform/board.ld.S
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,7 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "include/board.h"
+#include "los_vm_zone.h"
#define TEXT_BASE KERNEL_VADDR_BASE
diff --git a/platform/bsp.mk b/platform/bsp.mk
old mode 100644
new mode 100755
index 9deee827..b2dc9216
--- a/platform/bsp.mk
+++ b/platform/bsp.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -79,20 +79,21 @@ LITEOS_PLATFORM := $(subst $\",,$(LOSCFG_PLATFORM))
PLATFORM_BSP_BASE := $(LITEOSTOPDIR)/platform
-PLATFORM_INCLUDE := -I $(PLATFORM_BSP_BASE)/../kernel/common \
+PLATFORM_INCLUDE := -I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) \
+ -I $(PLATFORM_BSP_BASE)/../kernel/common \
-I $(PLATFORM_BSP_BASE)/../../../drivers/liteos/platform/pm \
-I $(PLATFORM_BSP_BASE)/hw/include \
-I $(PLATFORM_BSP_BASE)/include \
-I $(PLATFORM_BSP_BASE)/$(UART_SRC)
-ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
- PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board/include
- PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board/include/hisoc
-else ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
- PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm/$(LITEOS_PLATFORM)/config/board/include
- # TODO: remove hisoc dependency in the code to avoid using hisoc here
- PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm/$(LITEOS_PLATFORM)/config/board/include/hisoc
+ifeq ($(LOSCFG_PLATFORM_PATCHFS), y)
+ PLATFORM_INCLUDE += -I $(PLATFORM_BSP_BASE)/../kernel/common/patchfs
endif
+
+ifeq ($(LOSCFG_FS_ZPFS), y)
+ PLATFORM_INCLUDE += -I $(PLATFORM_BSP_BASE)/../fs/zpfs
+endif
+
#
#-include $(LITEOSTOPDIR)/platform/bsp/board/$(LITEOS_PLATFORM)/board.mk
#
diff --git a/platform/hw/arm/interrupt/gic/gic_v2.c b/platform/hw/arm/interrupt/gic/gic_v2.c
old mode 100644
new mode 100755
index 87226902..463d20de
--- a/platform/hw/arm/interrupt/gic/gic_v2.c
+++ b/platform/hw/arm/interrupt/gic/gic_v2.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/hw/arm/interrupt/gic/gic_v3.c b/platform/hw/arm/interrupt/gic/gic_v3.c
old mode 100644
new mode 100755
index 3e20c60c..8451f108
--- a/platform/hw/arm/interrupt/gic/gic_v3.c
+++ b/platform/hw/arm/interrupt/gic/gic_v3.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/hw/arm/timer/arm_generic/arm_generic_timer.c b/platform/hw/arm/timer/arm_generic/arm_generic_timer.c
old mode 100644
new mode 100755
index f203699b..f7d0a9bc
--- a/platform/hw/arm/timer/arm_generic/arm_generic_timer.c
+++ b/platform/hw/arm/timer/arm_generic/arm_generic_timer.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,6 +31,7 @@
#include "los_hw_pri.h"
#include "los_tick_pri.h"
+#include "los_sched_pri.h"
#include "los_sys_pri.h"
#include "gic_common.h"
@@ -87,8 +88,6 @@
#endif
-#define OS_CYCLE_PER_TICK (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND)
-
UINT32 HalClockFreqRead(VOID)
{
return READ_TIMER_REG32(TIMER_REG_CNTFRQ);
@@ -127,27 +126,12 @@ UINT64 HalClockGetCycles(VOID)
return cntpct;
}
-LITE_OS_SEC_TEXT VOID OsTickEntry(VOID)
-{
- TimerCtlWrite(0);
-
- OsTickHandler();
-
- /*
- * use last cval to generate the next tick's timing is
- * absolute and accurate. DO NOT use tval to drive the
- * generic time in which case tick will be slower.
- */
- TimerCvalWrite(TimerCvalRead() + OS_CYCLE_PER_TICK);
- TimerCtlWrite(1);
-}
-
LITE_OS_SEC_TEXT_INIT VOID HalClockInit(VOID)
{
UINT32 ret;
g_sysClock = HalClockFreqRead();
- ret = LOS_HwiCreate(OS_TICK_INT_NUM, MIN_INTERRUPT_PRIORITY, 0, OsTickEntry, 0);
+ ret = LOS_HwiCreate(OS_TICK_INT_NUM, MIN_INTERRUPT_PRIORITY, 0, OsTickHandler, 0);
if (ret != LOS_OK) {
PRINT_ERR("%s, %d create tick irq failed, ret:0x%x\n", __FUNCTION__, __LINE__, ret);
}
@@ -155,6 +139,11 @@ LITE_OS_SEC_TEXT_INIT VOID HalClockInit(VOID)
LITE_OS_SEC_TEXT_INIT VOID HalClockStart(VOID)
{
+ UINT32 ret = OsSchedSetTickTimerType(64); /* 64 bit tick timer */
+ if (ret != LOS_OK) {
+ return;
+ }
+
HalIrqUnmask(OS_TICK_INT_NUM);
/* triggle the first tick */
@@ -165,7 +154,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalClockStart(VOID)
VOID HalDelayUs(UINT32 usecs)
{
- UINT64 cycles = (UINT64)usecs * HalClockFreqRead() / OS_SYS_US_PER_SECOND;
+ UINT64 cycles = (UINT64)usecs * g_sysClock / OS_SYS_US_PER_SECOND;
UINT64 deadline = HalClockGetCycles() + cycles;
while (HalClockGetCycles() < deadline) {
@@ -186,7 +175,7 @@ UINT32 HalClockGetTickTimerCycles(VOID)
return (UINT32)((cval > cycles) ? (cval - cycles) : 0);
}
-VOID HalClockTickTimerReload(UINT32 cycles)
+VOID HalClockTickTimerReload(UINT64 cycles)
{
HalIrqMask(OS_TICK_INT_NUM);
HalIrqClear(OS_TICK_INT_NUM);
diff --git a/platform/hw/arm/timer/arm_private/arm_private_timer.c b/platform/hw/arm/timer/arm_private/arm_private_timer.c
index 1e94d022..c21dff1f 100644
--- a/platform/hw/arm/timer/arm_private/arm_private_timer.c
+++ b/platform/hw/arm/timer/arm_private/arm_private_timer.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,6 +31,7 @@
#include "asm/platform.h"
#include "los_hwi.h"
+#include "los_sched_pri.h"
#include "los_tick_pri.h"
#define OS_CYCLE_PER_TICK (TIMER_FREQ / LOSCFG_BASE_CORE_TICK_PER_SECOND)
@@ -67,6 +68,11 @@ VOID HalClockFreqWrite(UINT32 freq)
VOID HalClockStart(VOID)
{
+ UINT32 ret = OsSchedSetTickTimerType(32); /* 32 bit tick timer */
+ if (ret != LOS_OK) {
+ return;
+ }
+
HalIrqUnmask(PRVTIMER_INT_NUM);
g_privateTimer->load = OS_CYCLE_PER_TICK;
@@ -124,12 +130,12 @@ UINT32 HalClockGetTickTimerCycles(VOID)
return g_privateTimer->count;
}
-VOID HalClockTickTimerReload(UINT32 period)
+VOID HalClockTickTimerReload(UINT64 period)
{
HalIrqUnmask(PRVTIMER_INT_NUM);
/* set control counter regs to defaults */
- g_privateTimer->load = period;
+ g_privateTimer->load = (UINT32)period;
g_privateTimer->control = 0x06; /* IAE bits = 110, not eanbled yet */
g_privateTimer->control |= 0x01; /* reenable private timer */
}
diff --git a/platform/hw/hisoc/hrtimer/hrtimer.c b/platform/hw/hisoc/hrtimer/hrtimer.c
index 947573b0..c85b5980 100644
--- a/platform/hw/hisoc/hrtimer/hrtimer.c
+++ b/platform/hw/hisoc/hrtimer/hrtimer.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,7 +30,6 @@
*/
#include "los_hwi.h"
-#include "hisoc/sys_ctrl.h"
#ifdef __cplusplus
#if __cplusplus
diff --git a/platform/hw/hisoc/timer/timer.c b/platform/hw/hisoc/timer/timer.c
index 81b2bd4e..f78882fc 100644
--- a/platform/hw/hisoc/timer/timer.c
+++ b/platform/hw/hisoc/timer/timer.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,9 +31,9 @@
#include "los_timer_pri.h"
#include "los_tick_pri.h"
+#include "los_sched_pri.h"
#include "los_sys_pri.h"
#include "los_hwi.h"
-#include "hisoc/sys_ctrl.h"
#include "los_swtmr.h"
#ifdef __cplusplus
@@ -64,19 +64,15 @@ STATIC volatile UINT64 g_schedClockCycle = 0;
STATIC volatile UINT32 g_timeClkLast = 0;
STATIC UINT16 g_swtmrID;
-#ifdef LOSCFG_KERNEL_TICKLESS
-VOID HalClockTickTimerReload(UINT32 period)
+VOID HalClockTickTimerReload(UINT64 period)
{
- UINT32 cyclesPerTick;
- cyclesPerTick = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND;
-
- WRITE_UINT32(period, TIMER_TICK_REG_BASE + TIMER_LOAD);
- WRITE_UINT32(cyclesPerTick, TIMER_TICK_REG_BASE + TIMER_BGLOAD);
+ UINT32 cycle = (UINT32)period;
+ WRITE_UINT32(cycle, TIMER_TICK_REG_BASE + TIMER_LOAD);
+ WRITE_UINT32(cycle, TIMER_TICK_REG_BASE + TIMER_BGLOAD);
HalClockIrqClear();
HalIrqClear(NUM_HAL_INTERRUPT_TIMER);
}
-#endif
VOID ResetTimerMasked(VOID)
{
@@ -348,6 +344,11 @@ VOID SchedClockSwtmr(VOID)
LITE_OS_SEC_TEXT_INIT VOID HalClockStart(VOID)
{
+ UINT32 ret = OsSchedSetTickTimerType(32); /* 32 bit tick timer */
+ if (ret != LOS_OK) {
+ return;
+ }
+
HalIrqUnmask(NUM_HAL_INTERRUPT_TIMER);
HalClockEnable();
diff --git a/platform/hw/include/gic_common.h b/platform/hw/include/gic_common.h
index 239b003a..3a72a9c8 100644
--- a/platform/hw/include/gic_common.h
+++ b/platform/hw/include/gic_common.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -33,7 +33,7 @@
#define _GIC_COMMON_H
#include "stdint.h"
-#include "asm/platform.h"
+#include "target_config.h"
#include "los_config.h"
/* gic arch revision */
diff --git a/platform/hw/include/gic_v3.h b/platform/hw/include/gic_v3.h
old mode 100644
new mode 100755
index 2781f51a..7f846732
--- a/platform/hw/include/gic_v3.h
+++ b/platform/hw/include/gic_v3.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -33,7 +33,7 @@
#define _GIC_V3_H_
#include "stdint.h"
-#include "asm/platform.h"
+#include "target_config.h"
#include "los_hw_cpu.h"
#define BIT_32(bit) (1u << bit)
diff --git a/platform/include/hal_hwi.h b/platform/include/hal_hwi.h
index 211c23f3..9d08589a 100644
--- a/platform/include/hal_hwi.h
+++ b/platform/include/hal_hwi.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/include/hal_timer.h b/platform/include/hal_timer.h
index 780e46f6..380b3621 100644
--- a/platform/include/hal_timer.h
+++ b/platform/include/hal_timer.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -47,7 +47,7 @@ extern UINT64 HalClockGetCycles(VOID);
extern VOID HalDelayUs(UINT32 usecs);
extern UINT64 hi_sched_clock(VOID);
extern UINT32 HalClockGetTickTimerCycles(VOID);
-extern VOID HalClockTickTimerReload(UINT32 cycles);
+extern VOID HalClockTickTimerReload(UINT64 cycles);
extern UINT32 HrtimersInit(VOID);
extern VOID HrtimerClockIrqClear(VOID);
diff --git a/platform/main.c b/platform/main.c
index 1074dd47..921ca047 100644
--- a/platform/main.c
+++ b/platform/main.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,14 +30,14 @@
*/
#include "los_config.h"
-#include "los_task_pri.h"
-#include "los_swtmr_pri.h"
#include "los_printf.h"
#include "los_atomic.h"
-#include "gic_common.h"
-#include "uart.h"
#include "los_process_pri.h"
+#include "los_task_pri.h"
+#include "los_swtmr_pri.h"
+#include "los_sched_pri.h"
#include "los_arch_mmu.h"
+#include "gic_common.h"
#if (LOSCFG_KERNEL_SMP == YES)
STATIC Atomic g_ncpu = 1;
@@ -91,7 +91,7 @@ LITE_OS_SEC_TEXT_INIT VOID secondary_cpu_start(VOID)
OsCurrProcessSet(OS_PCB_FROM_PID(OsGetKernelInitProcessID()));
OsSwtmrInit();
OsIdleTaskCreate();
- OsStart();
+ OsSchedStart();
while (1) {
__asm volatile("wfi");
}
@@ -134,7 +134,7 @@ LITE_OS_SEC_TEXT_INIT VOID release_secondary_cores(VOID)
{
UINT32 regval;
- /* clear the slave cpu reset */
+ /* clear the second cpu reset status */
READ_UINT32(regval, PERI_CRG30_BASE);
CLEAR_RESET_REG_STATUS(regval);
WRITE_UINT32(regval, PERI_CRG30_BASE);
@@ -178,7 +178,7 @@ LITE_OS_SEC_TEXT_INIT INT32 main(VOID)
CPU_MAP_SET(0, OsHwIDGet());
- OsStart();
+ OsSchedStart();
while (1) {
__asm volatile("wfi");
diff --git a/platform/uart/amba-pl011-lagacy/uart.c b/platform/uart/amba-pl011-lagacy/uart.c
index 788ee2b8..25adc557 100644
--- a/platform/uart/amba-pl011-lagacy/uart.c
+++ b/platform/uart/amba-pl011-lagacy/uart.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/uart/amba_pl011/amba_pl011.c b/platform/uart/amba_pl011/amba_pl011.c
old mode 100644
new mode 100755
index 3d60b0b5..7978ec14
--- a/platform/uart/amba_pl011/amba_pl011.c
+++ b/platform/uart/amba_pl011/amba_pl011.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -30,10 +30,6 @@
*/
#include "amba_pl011.h"
-#include "asm/platform.h"
-#include "uart.h"
-#include "los_hwi.h"
-#include "los_spinlock.h"
#include "los_event.h"
#include "los_task_pri.h"
@@ -41,7 +37,11 @@ EVENT_CB_S g_stShellEvent;
CHAR g_inputCmd[CMD_LENGTH];
INT32 g_inputIdx = 0;
+#ifdef LOSCFG_QUICK_START
+__attribute__ ((section(".data"))) UINT32 g_uart_fputc_en = 0;
+#else
__attribute__ ((section(".data"))) UINT32 g_uart_fputc_en = 1;
+#endif
#define REG32(addr) ((volatile UINT32 *)(UINTPTR)(addr))
#define UARTREG(base, reg) (*REG32((base) + (reg)))
diff --git a/platform/uart/amba_pl011/amba_pl011.h b/platform/uart/amba_pl011/amba_pl011.h
index 1de43758..6de19dec 100644
--- a/platform/uart/amba_pl011/amba_pl011.h
+++ b/platform/uart/amba_pl011/amba_pl011.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/uart/dw-3.0.8a/uart.c b/platform/uart/dw-3.0.8a/uart.c
index 2b2fb2b8..bd03df9e 100644
--- a/platform/uart/dw-3.0.8a/uart.c
+++ b/platform/uart/dw-3.0.8a/uart.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/platform/usb/usb3.0_hi3516dv300/usb_board.c b/platform/usb/usb3.0_hi3516dv300/usb_board.c
deleted file mode 100644
index 03e1093d..00000000
--- a/platform/usb/usb3.0_hi3516dv300/usb_board.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "hisoc/usb3.h"
-#include "los_atomic.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-#define USB3_CTRL_REG_BASE IO_DEVICE_ADDR(CONFIG_HIUSB_XHCI_IOBASE)
-#define REG_USB2_CTRL 0x0140
-
-/* offset 0x140 */
-#define USB2_UTMI_PCTRL (0x1U << 15)
-#define USB2_PHY_TEST_SRST_REQ (0x1U << 14)
-#define USB2_UTMI_CKSEL (0x1U << 13)
-#define USB2_UTMI_CKEN (0x1U << 12)
-#define USB2_REF_CKEN (0x1U << 9)
-#define USB2_BUS_CKEN (0x1U << 8)
-#define USB2_VCC_SRST_REQ (0x1U << 3)
-#define USB2_PHY_CKEN (0x1U << 2)
-#define USB2_PHY_PORT_TREQ (0x1U << 1)
-#define USB2_PHY_REQ (0x1U << 0)
-
-#define REG_GUSB3PIPECTL0 0xC2C0
-#define PCS_SSP_SOFT_RESET (0x1U << 31)
-#define PORT_DISABLE_SUSPEND (0x1U << 17)
-
-#define REG_GCTL 0xC110
-#define PORT_CAP_DIR (0x3U << 12)
-#define PORT_SET_HOST (0x1U << 12)
-#define PORT_SET_DEVICE (0x1U << 13)
-
-#define GTXTHRCFG 0xC108
-#define USB2_G_TXTHRCFG IO_DEVICE_ADDR(0x23100000)
-
-#define GRXTHRCFG 0xC10C
-#define USB2_G_RXTHRCFG IO_DEVICE_ADDR(0x23100000)
-
-#define USB2_INNO_PHY_BASE_REG IO_DEVICE_ADDR(0x10110000)
-#define USB2_PHY_CLK_OUTPUT_REG 0x18
-#define USB2_PHY_CLK_OUTPUT_VAL 0x0C
-
-#define USB2_VBUS_IO_BASE_REG IO_DEVICE_ADDR(0x10FF0000)
-#define USB2_VBUS_IO_OFFSET 0x40
-#define USB2_VBUS_IO_VAL 0x431
-
-#define HS_HIGH_HEIGHT_TUNING_OFFSET 0x8
-#define HS_HIGH_HEIGHT_TUNING_MASK (0x7U << 4)
-#define HS_HIGH_HEIGHT_TUNING_VAL (0x5U << 4)
-
-#define PRE_EMPHASIS_TUNING_OFFSET 0x0
-#define PRE_EMPHASIS_TUNING_MASK (0x7U << 0)
-#define PRE_EMPHASIS_TUNING_VAL (0x7U << 0)
-
-#define PRE_EMPHASIS_STRENGTH_OFFSET 0x14
-#define PRE_EMPHASIS_STRENGTH_MASK (0x7U << 2)
-#define PRE_EMPHASIS_STRENGTH_VAL (0x3U << 2)
-
-#define HS_SLEW_RATE_TUNING_OFFSET 0x74
-#define HS_SLEW_RATE_TUNING_MASK (0x7U << 1)
-#define HS_SLEW_RATE_TUNING_VAL (0x7U << 1)
-
-#define DISCONNECT_TRIGGER_OFFSET 0x10
-#define DISCONNECT_TRIGGER_MASK (0xfU << 4)
-#define DISCONNECT_TRIGGER_VAL (0xdU << 4)
-
-STATIC BOOL g_otgUsbdevStat = FALSE;
-STATIC Atomic g_devOpenCnt = 0;
-
-STATIC VOID OpenUtmi(VOID)
-{
- UINT32 reg;
-
- /* open utmi pctrl */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_UTMI_PCTRL;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(10); /* Delay 10us */
-
- /* open utmi cksel */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_UTMI_CKSEL;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(10); /* Delay 10us */
-
- /* open utmi cken */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_UTMI_CKEN;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(10); /* Delay 10us */
-}
-
-STATIC VOID CancelReset(VOID)
-{
- UINT32 reg;
-
- /* cancel POR reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_PHY_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
-
- /* cancel TPOR reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_PHY_PORT_TREQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
-
- /* cancel vcc reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_VCC_SRST_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
-}
-
-STATIC VOID Usb2ControllerConfig(VOID)
-{
- UINT32 reg;
-
- reg = GET_UINT32(USB3_CTRL_REG_BASE + REG_GUSB3PIPECTL0);
- reg |= PCS_SSP_SOFT_RESET;
- WRITE_UINT32(reg, USB3_CTRL_REG_BASE + REG_GUSB3PIPECTL0);
- LOS_Udelay(20); /* Delay 20us */
-
- reg = GET_UINT32(USB3_CTRL_REG_BASE + REG_GCTL);
- reg &= ~PORT_CAP_DIR;
- reg |= PORT_SET_HOST; /* [13:12] 01: Host; 10: Device; 11: OTG */
- WRITE_UINT32(reg, USB3_CTRL_REG_BASE + REG_GCTL);
- LOS_Udelay(20); /* Delay 20us */
-
- reg = GET_UINT32(USB3_CTRL_REG_BASE + REG_GUSB3PIPECTL0);
- reg &= ~PCS_SSP_SOFT_RESET;
- reg &= ~PORT_DISABLE_SUSPEND; /* disable suspend */
- WRITE_UINT32(reg, USB3_CTRL_REG_BASE + REG_GUSB3PIPECTL0);
- LOS_Udelay(20); /* Delay 20us */
-
- WRITE_UINT32(USB2_G_TXTHRCFG, USB3_CTRL_REG_BASE + GTXTHRCFG);
- WRITE_UINT32(USB2_G_RXTHRCFG, USB3_CTRL_REG_BASE + GRXTHRCFG);
- LOS_Udelay(20); /* Delay 20us */
-}
-
-VOID Usb2EyeConfig(VOID)
-{
- UINT32 reg;
-
- /* HS eye height tuning */
- reg = GET_UINT32(USB2_INNO_PHY_BASE_REG + HS_HIGH_HEIGHT_TUNING_OFFSET);
- reg &= ~HS_HIGH_HEIGHT_TUNING_MASK;
- reg |= HS_HIGH_HEIGHT_TUNING_VAL;
- WRITE_UINT32(reg, USB2_INNO_PHY_BASE_REG + HS_HIGH_HEIGHT_TUNING_OFFSET);
-
- /* Pre-emphasis tuning */
- reg = GET_UINT32(USB2_INNO_PHY_BASE_REG + PRE_EMPHASIS_TUNING_OFFSET);
- reg &= ~PRE_EMPHASIS_TUNING_MASK;
- reg |= PRE_EMPHASIS_TUNING_VAL;
- WRITE_UINT32(reg, USB2_INNO_PHY_BASE_REG + PRE_EMPHASIS_TUNING_OFFSET);
-
- /* Pre-emphasis strength */
- reg = GET_UINT32(USB2_INNO_PHY_BASE_REG + PRE_EMPHASIS_STRENGTH_OFFSET);
- reg &= ~PRE_EMPHASIS_STRENGTH_MASK;
- reg |= PRE_EMPHASIS_STRENGTH_VAL;
- WRITE_UINT32(reg, USB2_INNO_PHY_BASE_REG + PRE_EMPHASIS_STRENGTH_OFFSET);
-
- /* HS driver slew rate tunning */
- reg = GET_UINT32(USB2_INNO_PHY_BASE_REG + HS_SLEW_RATE_TUNING_OFFSET);
- reg &= ~HS_SLEW_RATE_TUNING_MASK;
- reg |= HS_SLEW_RATE_TUNING_VAL;
- WRITE_UINT32(reg, USB2_INNO_PHY_BASE_REG + HS_SLEW_RATE_TUNING_OFFSET);
-
- /* HOST disconnects detection trigger point */
- reg = GET_UINT32(USB2_INNO_PHY_BASE_REG + DISCONNECT_TRIGGER_OFFSET);
- reg &= ~DISCONNECT_TRIGGER_MASK;
- reg |= DISCONNECT_TRIGGER_VAL;
- WRITE_UINT32(reg, USB2_INNO_PHY_BASE_REG + DISCONNECT_TRIGGER_OFFSET);
-}
-
-STATIC VOID HisiUsb3PhyPowerOn(VOID)
-{
- UINT32 reg;
-
- if (LOS_AtomicIncRet(&g_devOpenCnt) == 1) {
- /* usb phy reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_PHY_TEST_SRST_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(100); /* Delay 100us */
-
- /* cancel usb phy srst */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg &= ~USB2_PHY_TEST_SRST_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(20); /* Delay 20us */
-
- /* usb2 vcc reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_VCC_SRST_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
-
- /* set inno phy output clock */
- WRITE_UINT32(USB2_PHY_CLK_OUTPUT_VAL, USB2_INNO_PHY_BASE_REG +
- USB2_PHY_CLK_OUTPUT_REG);
- LOS_Udelay(10); /* Delay 10us */
-
- /* open phy ref cken */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_PHY_CKEN;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(10); /* Delay 10us */
-
- /* open utmi */
- OpenUtmi();
-
- /* open controller ref cken */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_REF_CKEN;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(10); /* Delay 10us */
-
- /* open bus cken */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_BUS_CKEN;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
-
- /* cancel reset */
- CancelReset();
-
- /* usb2 test vbus using gpio */
- WRITE_UINT32(USB2_VBUS_IO_VAL, USB2_VBUS_IO_BASE_REG + USB2_VBUS_IO_OFFSET);
- LOS_Udelay(20); /* Delay 20us */
-
- /* USB2 Controller configs */
- Usb2ControllerConfig();
-
- /* USB2 eye config */
- Usb2EyeConfig();
- }
-}
-
-STATIC VOID HisiUsb3PhyPowerOff(VOID)
-{
- UINT32 reg;
-
- if (LOS_AtomicDecRet(&g_devOpenCnt) == 0) {
- /* usb2 vcc reset */
- reg = GET_UINT32(CRG_REG_BASE + REG_USB2_CTRL);
- reg |= USB2_VCC_SRST_REQ;
- WRITE_UINT32(reg, CRG_REG_BASE + REG_USB2_CTRL);
- LOS_Udelay(200); /* Delay 200us */
- }
-}
-
-VOID HiUsb3StartHcd(VOID)
-{
- HisiUsb3PhyPowerOn();
-}
-VOID HiUsb3StopHcd(VOID)
-{
- HisiUsb3PhyPowerOff();
-}
-
-VOID HiUsb3Host2Device(VOID)
-{
- UINT32 reg;
-
- reg = GET_UINT32(USB3_CTRL_REG_BASE + REG_GCTL);
- reg &= ~PORT_CAP_DIR;
- reg |= PORT_SET_DEVICE; /* [13:12] 01: Host; 10: Device; 11: OTG */
- WRITE_UINT32(reg, USB3_CTRL_REG_BASE + REG_GCTL);
- LOS_Udelay(20); /* Delay 20us */
-}
-
-BOOL HiUsbIsDeviceMode(VOID)
-{
- return g_otgUsbdevStat;
-}
-
-VOID UsbOtgSwSetDeviceState(VOID)
-{
- g_otgUsbdevStat = TRUE;
-}
-
-VOID UsbOtgSwClearDeviceState(VOID)
-{
- g_otgUsbdevStat = FALSE;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif
-#endif
diff --git a/platform/usb/usb3.0_hi3518ev300/usb_board.c b/platform/usb/usb3.0_hi3518ev300/usb_board.c
deleted file mode 100644
index 1302e921..00000000
--- a/platform/usb/usb3.0_hi3518ev300/usb_board.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "hisoc/usb3.h"
-#include "linux/delay.h"
-#include "board.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-/* offset 0x140 */
-#define USB2_CTRL IO_ADDRESS(CRG_REG_BASE + 0x140)
-#define USB2_CRG_DEFAULT_VAL 0x3B2F
-#define USB2_UTMI_CKEN (0x1U << 12)
-#define USB2_PHY_APB_CKEN (0x1U << 11)
-#define USB2_REF_CKEN (0x1U << 9)
-#define USB2_BUS_CKEN (0x1U << 8)
-#define USB2_PHY_PLL_CKEN (0x1U << 4)
-#define USB2_PHY_XTAL_CKEN (0x1U << 2)
-#define USB2_FREECLK_CKSEL (0x1U << 13)
-#define USB2_PHY_APB_RST (0x1U << 10)
-#define USB2_VCC_SRST_REQ (0x1U << 3)
-#define USB2_PHY_REQ (0x1U << 0)
-#define USB2_PHY_PORT_TREQ (0x1U << 1)
-
-#define CTRL_BASE_REG IO_DEVICE_ADDR(0x10030000)
-#define GTXTHRCFG IO_ADDRESS(CTRL_BASE_REG + 0xC108)
-#define GRXTHRCFG IO_ADDRESS(CTRL_BASE_REG + 0xC10C)
-#define REG_GCTL IO_ADDRESS(CTRL_BASE_REG + 0xC110)
-#define REG_GUSB3PIPECTL0 IO_ADDRESS(CTRL_BASE_REG + 0xC2C0)
-#define PCS_SSP_SOFT_RESET (0x1U << 31)
-
-#define PORT_CAP_DIR (0x3U << 12)
-#define PORT_SET_HOST (0x1U << 12)
-#define PORT_SET_DEVICE (0x1U << 13)
-#define PORT_DISABLE_SUSPEND (0x1U << 17)
-
-#define USB2_G_TXTHRCFG 0x23100000
-#define USB2_G_RXTHRCFG 0x23100000
-
-/* PHY base register */
-#define USB2_PHY_BASE_REG IO_DEVICE_ADDR(0x100D0000)
-#define RG_PLL_EN_MASK 0x0003U
-#define RG_PLL_EN_VAL 0x0003U
-#define RG_PLL_OFFSET 0x0014
-
-#define USB2_VBUS_IO_BASE_REG IO_DEVICE_ADDR(0x100C0000)
-#define USB2_VBUS_IO_OFFSET 0x7C
-#define USB_VBUS_IO_CONFIG_VAL 0x0531
-
-#define USB_PWREN_CONFIG_REG IO_DEVICE_ADDR(0x100C0080)
-#define USB_PWREN_CONFIG_VAL 0x1
-
-/* PHY eye config */
-#define HIXVP_PHY_ANA_CFG_0_OFFSET 0x00
-#define HIXVP_PHY_PRE_DRIVE_MASK (0xFU << 24)
-#define HIXVP_PHY_PRE_DRIVE_VAL (0x4U << 24)
-#define HIXVP_PHY_ANA_CFG_2_OFFSET 0x08
-#define HIXVP_PHY_TX_TEST_BIT (0x1U << 20)
-#define HIXVP_PHY_DISCONNECT_REFERENCE_MASK (0x7U << 16)
-#define HIXVP_PHY_DISCONNECT_REFERENCE_VAL (0x2U << 16)
-#define HIXVP_PHY_ANA_CFG_4_OFFSET 0x10
-#define HIXVP_PHY_TX_REFERENCE_MASK (0x7U << 4)
-#define HIXVP_PHY_TX_REFERENCE_VAL (0x5U << 4)
-#define HIXVP_PHY_SQUELCH_MASK (0x7U << 0)
-#define HIXVP_PHY_SQUELCH_VAL (0x5U << 0)
-
-/* PHY trim config */
-#define USB_TRIM_BASE_REG IO_DEVICE_ADDR(0x12028004)
-#define USB_TRIM_VAL_MASK 0x001FU
-#define USB_TRIM_VAL_MIN 0x0009
-#define USB_TRIM_VAL_MAX 0x001D
-#define USB2_TRIM_OFFSET 0x0008
-#define USB2_TRIM_MASK 0x1F00U
-#define USB2_TRIM_VAL(a) (((a) << 8) & USB2_TRIM_MASK)
-#define USB2_TRIM_DEFAULT_VAL 0x000EU
-
-/* PHY svb config */
-#define USB_SVB_BASE_REG IO_DEVICE_ADDR(0x12020158)
-#define USB_SVB_OFFSET 0x00
-#define USB_SVB_MASK (0x0FU << 24)
-#define USB_SVB_PREDEV_5_MIN 0x2BC
-#define USB_SVB_PREDEV_5_MAX_4_MIN 0x32A
-#define USB_SVB_PREDEV_4_MAX_3_MIN 0x398
-#define USB_SVB_PREDEV_3_MAX_2_MIN 0x3CA
-#define USB_SVB_PREDEV_2_MAX 0x44C
-#define USB_SVB_PREDEV_5_PHY_VAL (0x05U << 24)
-#define USB_SVB_PREDEV_4_PHY_VAL (0x04U << 24)
-#define USB_SVB_PREDEV_3_PHY_VAL (0x03U << 24)
-#define USB_SVB_PREDEV_2_PHY_VAL (0x02U << 24)
-
-#define VBUS_CONFIG_WAIT_TIME 20
-#define CTRL_CONFIG_WAIT_TIME 20
-#define MODE_SWITCH_WAIT_TIME 20
-#define USB_PHY_OFF_WAIT_TIME 2000
-#define PLL_CONFIG_WAIT_TIME 2000
-#define USB2_CTRL_CONFIG_WAIT_TIME 200
-
-STATIC BOOL g_otgUsbdevStat = FALSE;
-
-STATIC VOID UsbEyeConfig(VOID)
-{
- UINT32 reg;
- /* HSTX pre-drive strength */
- reg = GET_UINT32(USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_0_OFFSET);
- reg &= ~HIXVP_PHY_PRE_DRIVE_MASK;
- reg |= HIXVP_PHY_PRE_DRIVE_VAL;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_0_OFFSET);
-
- /* TX test bit */
- reg = GET_UINT32(USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_2_OFFSET);
- reg |= HIXVP_PHY_TX_TEST_BIT;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_2_OFFSET);
-
- /* Disconnect reference voltage sel */
- reg = GET_UINT32(USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_2_OFFSET);
- reg &= ~HIXVP_PHY_DISCONNECT_REFERENCE_MASK;
- reg |= HIXVP_PHY_DISCONNECT_REFERENCE_VAL;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_2_OFFSET);
-
- /* TX reference voltage sel */
- reg = GET_UINT32(USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_4_OFFSET);
- reg &= ~HIXVP_PHY_TX_REFERENCE_MASK;
- reg |= HIXVP_PHY_TX_REFERENCE_VAL;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_4_OFFSET);
-
- /* Squelch voltage config */
- reg = GET_UINT32(USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_4_OFFSET);
- reg &= ~HIXVP_PHY_SQUELCH_MASK;
- reg |= HIXVP_PHY_SQUELCH_VAL;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + HIXVP_PHY_ANA_CFG_4_OFFSET);
-}
-
-VOID UsbTrimConfig(VOID)
-{
- UINT32 ret, reg, trimVal;
-
- ret = GET_UINT32(USB_TRIM_BASE_REG);
- trimVal = ret & USB_TRIM_VAL_MASK; /* get usb trim value */
- reg = GET_UINT32(USB2_PHY_BASE_REG + USB2_TRIM_OFFSET);
- reg &= ~USB2_TRIM_MASK;
- /* set trim value to HiXVPV100 phy */
- if ((trimVal >= USB_TRIM_VAL_MIN) && (trimVal <= USB_TRIM_VAL_MAX)) {
- reg |= USB2_TRIM_VAL(trimVal);
- } else {
- reg |= USB2_TRIM_VAL(USB2_TRIM_DEFAULT_VAL);
- }
-
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + USB2_TRIM_OFFSET);
-}
-
-VOID UsbSvbConfig(VOID)
-{
- UINT32 ret, reg;
-
- ret = GET_UINT32(USB_SVB_BASE_REG);
- reg = GET_UINT32(USB2_PHY_BASE_REG + USB_SVB_OFFSET);
- reg &= ~USB_SVB_MASK;
- /* set svb value to HiXVPV100 phy */
- if ((ret >= USB_SVB_PREDEV_5_MIN) && (ret < USB_SVB_PREDEV_5_MAX_4_MIN)) {
- reg |= USB_SVB_PREDEV_5_PHY_VAL;
- } else if ((ret >= USB_SVB_PREDEV_5_MAX_4_MIN) && (ret < USB_SVB_PREDEV_4_MAX_3_MIN)) {
- reg |= USB_SVB_PREDEV_4_PHY_VAL;
- } else if ((ret >= USB_SVB_PREDEV_4_MAX_3_MIN) && (ret <= USB_SVB_PREDEV_3_MAX_2_MIN)) {
- reg |= USB_SVB_PREDEV_3_PHY_VAL;
- } else if ((ret > USB_SVB_PREDEV_3_MAX_2_MIN) && (ret <= USB_SVB_PREDEV_2_MAX)) {
- reg |= USB_SVB_PREDEV_2_PHY_VAL;
- } else {
- reg |= USB_SVB_PREDEV_4_PHY_VAL;
- }
-
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + USB_SVB_OFFSET);
-}
-
-STATIC VOID UsbVbusConfig(VOID)
-{
- WRITE_UINT32(USB_VBUS_IO_CONFIG_VAL, USB2_VBUS_IO_BASE_REG + USB2_VBUS_IO_OFFSET);
- udelay(VBUS_CONFIG_WAIT_TIME);
-}
-
-STATIC VOID UsbCrgC(VOID)
-{
- UINT32 reg;
-
- reg = USB_PWREN_CONFIG_VAL;
- WRITE_UINT32(reg, USB_PWREN_CONFIG_REG);
-
- /* set usb2 CRG default val */
- reg = USB2_CRG_DEFAULT_VAL;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB2_CTRL_CONFIG_WAIT_TIME);
-
- /* open UTMI clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_UTMI_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* open phy apb clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_PHY_APB_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* open ctrl ref clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_REF_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* open bus clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_BUS_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* open phy pll clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_PHY_PLL_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* open phy xtal clk */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_PHY_XTAL_CKEN;
- WRITE_UINT32(reg, USB2_CTRL);
-
- /* freeclk_cksel_free */
- reg = GET_UINT32(USB2_CTRL);
- reg |= USB2_FREECLK_CKSEL;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB2_CTRL_CONFIG_WAIT_TIME);
-
- /* release phy apb */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_PHY_APB_RST;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB2_CTRL_CONFIG_WAIT_TIME);
-
- /* por noreset */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_PHY_REQ;
- WRITE_UINT32(reg, USB2_CTRL);
-
- reg = GET_UINT32(USB2_PHY_BASE_REG + RG_PLL_OFFSET);
- reg &= ~RG_PLL_EN_MASK;
- reg |= RG_PLL_EN_VAL;
- WRITE_UINT32(reg, USB2_PHY_BASE_REG + RG_PLL_OFFSET);
- udelay(PLL_CONFIG_WAIT_TIME);
-
- /* cancel TPOR */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_PHY_PORT_TREQ;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB2_CTRL_CONFIG_WAIT_TIME);
-
- /* vcc reset */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_VCC_SRST_REQ;
- WRITE_UINT32(reg, USB2_CTRL);
-}
-
-STATIC VOID UsbCtrlC(VOID)
-{
- UINT32 reg;
-
- reg = GET_UINT32(REG_GUSB3PIPECTL0);
- reg |= PCS_SSP_SOFT_RESET;
- WRITE_UINT32(reg, REG_GUSB3PIPECTL0);
- udelay(CTRL_CONFIG_WAIT_TIME);
-
- reg = GET_UINT32(REG_GCTL);
- reg &= ~PORT_CAP_DIR;
- reg |= PORT_SET_HOST; /* [13:12] 01: Host; 10: Device; 11: OTG */
- WRITE_UINT32(reg, REG_GCTL);
- udelay(CTRL_CONFIG_WAIT_TIME);
-
- reg = GET_UINT32(REG_GUSB3PIPECTL0);
- reg &= ~PCS_SSP_SOFT_RESET;
- reg &= ~PORT_DISABLE_SUSPEND; /* disable suspend */
- WRITE_UINT32(reg, REG_GUSB3PIPECTL0);
- udelay(CTRL_CONFIG_WAIT_TIME);
-
- WRITE_UINT32(USB2_G_TXTHRCFG, GTXTHRCFG);
- WRITE_UINT32(USB2_G_RXTHRCFG, GRXTHRCFG);
- udelay(CTRL_CONFIG_WAIT_TIME);
-}
-
-VOID HisiUsbPhyOn(VOID)
-{
- UsbVbusConfig();
- UsbCrgC();
- UsbCtrlC();
-
- /* USB2 eye config */
- UsbEyeConfig();
-
- /* USB2 trim config */
- UsbTrimConfig();
-
- /* USB2 svb config */
- UsbSvbConfig();
-}
-
-VOID HisiUsbPhyOff(VOID)
-{
- UINT32 reg;
-
- /* por noreset */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_PHY_REQ;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB_PHY_OFF_WAIT_TIME);
- /* cancel TPOR */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_PHY_PORT_TREQ;
- WRITE_UINT32(reg, USB2_CTRL);
- udelay(USB_PHY_OFF_WAIT_TIME);
- /* vcc reset */
- reg = GET_UINT32(USB2_CTRL);
- reg &= ~USB2_VCC_SRST_REQ;
- WRITE_UINT32(reg, USB2_CTRL);
-}
-
-VOID HiUsb3StartHcd(VOID)
-{
- HisiUsbPhyOn();
-}
-
-VOID HiUsb3StopHcd(VOID)
-{
- HisiUsbPhyOff();
-}
-
-VOID HiUsb3Host2Device(VOID)
-{
- UINT32 reg;
-
- reg = GET_UINT32(REG_GCTL);
- reg &= ~PORT_CAP_DIR; /* [13:12] Clear Mode Bits */
- reg |= PORT_SET_DEVICE; /* [13:12] 01: Host; 10: Device; 11: OTG */
- WRITE_UINT32(reg, REG_GCTL);
- udelay(MODE_SWITCH_WAIT_TIME);
-}
-
-BOOL HiUsbIsDeviceMode(VOID)
-{
- return g_otgUsbdevStat;
-}
-
-VOID UsbOtgSwSetDeviceState(VOID)
-{
- g_otgUsbdevStat = TRUE;
-}
-
-VOID UsbOtgSwClearDeviceState(VOID)
-{
- g_otgUsbdevStat = FALSE;
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif
-#endif
diff --git a/readme.md b/readme.md
deleted file mode 100644
index b3784e47..00000000
--- a/readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-详见:https://gitee.com/openharmony/docs/blob/master/readme/内核子系统README.md
-
-see: https://gitee.com/openharmony/docs/blob/master/docs-en/readme/kernel-subsystem.md
\ No newline at end of file
diff --git a/security/Makefile b/security/Makefile
old mode 100644
new mode 100755
index b557bd93..a300fb89
--- a/security/Makefile
+++ b/security/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/security/cap/Makefile b/security/cap/Makefile
old mode 100644
new mode 100755
index 7a63cb75..a32f48af
--- a/security/cap/Makefile
+++ b/security/cap/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/security/cap/capability.c b/security/cap/capability.c
old mode 100644
new mode 100755
index 23363f7f..00eb4a42
--- a/security/cap/capability.c
+++ b/security/cap/capability.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,6 +38,7 @@
#define CAPABILITY_INIT_STAT 0xffffffff
#define CAPABILITY_GET_CAP_MASK(x) (1 << ((x) & 31))
#define CAPABILITY_MAX 31
+#define VALID_CAPS(a, b) (((a) & (~(b))) != 0)
BOOL IsCapPermit(UINT32 capIndex)
{
@@ -68,23 +69,45 @@ UINT32 SysCapSet(UINT32 caps)
{
UINT32 intSave;
+ SCHEDULER_LOCK(intSave);
if (!IsCapPermit(CAP_CAPSET)) {
+ SCHEDULER_UNLOCK(intSave);
+ return -EPERM;
+ }
+
+ if (VALID_CAPS(caps, OsCurrProcessGet()->capability)) {
+ SCHEDULER_UNLOCK(intSave);
return -EPERM;
}
- SCHEDULER_LOCK(intSave);
OsCurrProcessGet()->capability = caps;
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
-UINT32 SysCapGet(UINT32 *caps)
+UINT32 SysCapGet(pid_t pid, UINT32 *caps)
{
UINT32 intSave;
UINT32 kCaps;
+ LosProcessCB *processCB = NULL;
+
+ if ((OS_PID_CHECK_INVALID((UINT32)pid))) {
+ return -EINVAL;
+ }
+
+ if (pid == 0) {
+ processCB = OsCurrProcessGet();
+ } else {
+ processCB = OS_PCB_FROM_PID(pid);
+ }
SCHEDULER_LOCK(intSave);
- kCaps = OsCurrProcessGet()->capability;
+ if (OsProcessIsInactive(processCB)) {
+ SCHEDULER_UNLOCK(intSave);
+ return -ESRCH;
+ }
+
+ kCaps = processCB->capability;
SCHEDULER_UNLOCK(intSave);
if (LOS_ArchCopyToUser(caps, &kCaps, sizeof(UINT32)) != LOS_OK) {
diff --git a/security/cap/capability_api.h b/security/cap/capability_api.h
old mode 100644
new mode 100755
index a8851eb5..51e7233d
--- a/security/cap/capability_api.h
+++ b/security/cap/capability_api.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -37,5 +37,5 @@ BOOL IsCapPermit(UINT32 capIndex);
VOID OsInitCapability(LosProcessCB *processCB);
VOID OsCopyCapability(LosProcessCB *from, LosProcessCB *to);
UINT32 SysCapSet(UINT32 caps);
-UINT32 SysCapGet(UINT32 *caps);
+UINT32 SysCapGet(pid_t pid, UINT32 *caps);
#endif
diff --git a/security/cap/capability_type.h b/security/cap/capability_type.h
old mode 100644
new mode 100755
index 4f541484..b5163325
--- a/security/cap/capability_type.h
+++ b/security/cap/capability_type.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/security/vid/vid.c b/security/vid/vid.c
old mode 100644
new mode 100755
index f494e6fd..f460c6c7
--- a/security/vid/vid.c
+++ b/security/vid/vid.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/security/vid/vid_api.h b/security/vid/vid_api.h
old mode 100644
new mode 100755
index 67ca6d69..12a7c75d
--- a/security/vid/vid_api.h
+++ b/security/vid/vid_api.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/security/vid/vid_type.h b/security/vid/vid_type.h
old mode 100644
new mode 100755
index 6bd0f36e..835e4716
--- a/security/vid/vid_type.h
+++ b/security/vid/vid_type.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/BUILD.gn b/shell/BUILD.gn
old mode 100644
new mode 100755
index 1ae5e4f9..6e8dc0bb
--- a/shell/BUILD.gn
+++ b/shell/BUILD.gn
@@ -1,43 +1,43 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# 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("//build/lite/config/component/lite_component.gni")
-
-lite_component("shell") {
- version = "1.0.0"
- dependences = [
- "fs:^1.0.0",
- "kernel:^1.0.0"
- ]
- features = []
-
- if (LOSCFG_SHELL) {
- features += [ "full:shell_full" ]
- }
-}
+
+import("//build/lite/config/component/lite_component.gni")
+
+lite_component("shell") {
+ version = "1.0.0"
+ dependences = [
+ "fs:^1.0.0",
+ "kernel:^1.0.0",
+ ]
+ features = []
+
+ if (LOSCFG_SHELL) {
+ features += [ "full:shell_full" ]
+ }
+}
diff --git a/shell/Makefile b/shell/Makefile
old mode 100644
new mode 100755
index 91fc0e2a..d49850a1
--- a/shell/Makefile
+++ b/shell/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/shell/full/include/dmesg.h b/shell/full/include/dmesg.h
old mode 100644
new mode 100755
index 6a3f939b..15cde687
--- a/shell/full/include/dmesg.h
+++ b/shell/full/include/dmesg.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -74,7 +74,7 @@ extern "C" {
* dmesg.h: the header file that contains the API declaration.
* @see LOS_DmesgMemSet
*/
-extern UINT32 LOS_DmesgMemSet(VOID *addr, UINT32 size);
+extern UINT32 LOS_DmesgMemSet(const VOID *addr, UINT32 size);
/**
* @ingroup dmesg
diff --git a/shell/full/include/dmesg_pri.h b/shell/full/include/dmesg_pri.h
index dd48e266..6f73ca19 100644
--- a/shell/full/include/dmesg_pri.h
+++ b/shell/full/include/dmesg_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shcmd.h b/shell/full/include/shcmd.h
old mode 100644
new mode 100755
index 999f9d4b..754f30dc
--- a/shell/full/include/shcmd.h
+++ b/shell/full/include/shcmd.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shcmdparse.h b/shell/full/include/shcmdparse.h
index c337d0e9..d4a7111c 100644
--- a/shell/full/include/shcmdparse.h
+++ b/shell/full/include/shcmdparse.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shell.h b/shell/full/include/shell.h
index 6f03dee5..c2899d4f 100644
--- a/shell/full/include/shell.h
+++ b/shell/full/include/shell.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shell_lk.h b/shell/full/include/shell_lk.h
index b825c883..7cd58762 100644
--- a/shell/full/include/shell_lk.h
+++ b/shell/full/include/shell_lk.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shell_pri.h b/shell/full/include/shell_pri.h
index 278636be..022ae145 100644
--- a/shell/full/include/shell_pri.h
+++ b/shell/full/include/shell_pri.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/shmsg.h b/shell/full/include/shmsg.h
old mode 100644
new mode 100755
index 0b0d3b55..9159dd38
--- a/shell/full/include/shmsg.h
+++ b/shell/full/include/shmsg.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/include/show.h b/shell/full/include/show.h
old mode 100644
new mode 100755
index e6c8d1ab..27bb369f
--- a/shell/full/include/show.h
+++ b/shell/full/include/show.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/base/shcmd.c b/shell/full/src/base/shcmd.c
old mode 100644
new mode 100755
index 5dbc73e2..34e11ce5
--- a/shell/full/src/base/shcmd.c
+++ b/shell/full/src/base/shcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -38,7 +38,6 @@
#include "securec.h"
#include "los_mux.h"
#include "los_memory.h"
-#include "hisoc/uart.h"
#ifdef __cplusplus
#if __cplusplus
diff --git a/shell/full/src/base/shcmdparse.c b/shell/full/src/base/shcmdparse.c
old mode 100644
new mode 100755
index 2238a8ed..b7a71854
--- a/shell/full/src/base/shcmdparse.c
+++ b/shell/full/src/base/shcmdparse.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/base/shell_lk.c b/shell/full/src/base/shell_lk.c
old mode 100644
new mode 100755
index 0a5ab5bd..c7630443
--- a/shell/full/src/base/shell_lk.c
+++ b/shell/full/src/base/shell_lk.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/base/shmsg.c b/shell/full/src/base/shmsg.c
old mode 100644
new mode 100755
index 8f1f94a5..6ffe776d
--- a/shell/full/src/base/shmsg.c
+++ b/shell/full/src/base/shmsg.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -41,7 +41,6 @@
#include "los_event.h"
#include "los_list.h"
#include "los_printf.h"
-#include "hisoc/uart.h"
#ifdef LOSCFG_FS_VFS
#include "console.h"
diff --git a/shell/full/src/base/show.c b/shell/full/src/base/show.c
old mode 100644
new mode 100755
index 13ea0874..178778b9
--- a/shell/full/src/base/show.c
+++ b/shell/full/src/base/show.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -33,10 +33,6 @@
#include "shmsg.h"
#include "shcmd.h"
#include "console.h"
-#include "asm/hal_platform_ints.h"
-#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
-#include "hisoc/uart.h"
-#endif
#ifdef __cplusplus
#if __cplusplus
@@ -130,7 +126,6 @@ ERR_OUT1:
return ret;
}
-
UINT32 OsShellInit(INT32 consoleId)
{
if (g_shellSourceFlag == FALSE) {
diff --git a/shell/full/src/cmds/date_shell.c b/shell/full/src/cmds/date_shell.c
old mode 100644
new mode 100755
index b5fe826e..2c594b3a
--- a/shell/full/src/cmds/date_shell.c
+++ b/shell/full/src/cmds/date_shell.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/cmds/dmesg.c b/shell/full/src/cmds/dmesg.c
old mode 100644
new mode 100755
index f64a61ac..961d39d7
--- a/shell/full/src/cmds/dmesg.c
+++ b/shell/full/src/cmds/dmesg.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -59,7 +59,6 @@ Case B:
#include "unistd.h"
#include "stdlib.h"
#include "los_task.h"
-#include "hisoc/uart.h"
#include "inode/inode.h"
#ifdef __cplusplus
@@ -607,7 +606,7 @@ VOID LOS_DmesgClear(VOID)
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
}
-UINT32 LOS_DmesgMemSet(VOID *addr, UINT32 size)
+UINT32 LOS_DmesgMemSet(const VOID *addr, UINT32 size)
{
UINT32 ret = 0;
diff --git a/shell/full/src/cmds/excinfo_shell.c b/shell/full/src/cmds/excinfo_shell.c
old mode 100644
new mode 100755
index 213c6e46..06a484ce
--- a/shell/full/src/cmds/excinfo_shell.c
+++ b/shell/full/src/cmds/excinfo_shell.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/cmds/shell_shellcmd.c b/shell/full/src/cmds/shell_shellcmd.c
index 12ab0183..38124666 100644
--- a/shell/full/src/cmds/shell_shellcmd.c
+++ b/shell/full/src/cmds/shell_shellcmd.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/shell/full/src/cmds/watch_shell.c b/shell/full/src/cmds/watch_shell.c
old mode 100644
new mode 100755
index 8141be80..33f88592
--- a/shell/full/src/cmds/watch_shell.c
+++ b/shell/full/src/cmds/watch_shell.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/syscall/Makefile b/syscall/Makefile
old mode 100644
new mode 100755
index bb32fe6e..d4dc0c72
--- a/syscall/Makefile
+++ b/syscall/Makefile
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -43,5 +43,4 @@ LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/compat/posix/include \
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include \
-I $(LITEOSTOPDIR)/../../third_party/musl/kernel/include
-
include $(MODULE)
diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c
old mode 100644
new mode 100755
index fc582f2a..c1b8c790
--- a/syscall/fs_syscall.c
+++ b/syscall/fs_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -55,6 +55,8 @@
#include "capability_type.h"
#include "capability_api.h"
+#define HIGH_SHIFT_BIT 32
+
static int UserPathCopy(const char *userPath, char **pathBuf)
{
int ret;
@@ -66,11 +68,11 @@ static int UserPathCopy(const char *userPath, char **pathBuf)
ret = LOS_StrncpyFromUser(*pathBuf, userPath, PATH_MAX + 1);
if (ret < 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *pathBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *pathBuf);
*pathBuf = NULL;
return ret;
} else if (ret > PATH_MAX) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *pathBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *pathBuf);
*pathBuf = NULL;
return -ENAMETOOLONG;
}
@@ -108,13 +110,13 @@ static int UserIovCopy(struct iovec **iovBuf, const struct iovec *iov, const int
}
if (LOS_ArchCopyFromUser(*iovBuf, iov, bufLen) != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *iovBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *iovBuf);
return -EFAULT;
}
ret = UserIovItemCheck(*iovBuf, iovcnt);
if (ret == 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *iovBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *iovBuf);
return -EFAULT;
}
@@ -190,7 +192,7 @@ static int FcntlDupFd(int fd, void *arg, int (*fcntl)(int, int, ...))
if (procFd < 0) {
return -EMFILE;
}
- arg = (void *)minFd;
+ arg = (void *)(UINTPTR)minFd;
ret = fcntl(fd, F_DUPFD, arg);
if (ret < 0) {
@@ -308,7 +310,7 @@ int SysOpen(const char *path, int oflags, ...)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
if (ret >= 0) {
AssociateSystemFd(procFd, ret);
@@ -349,7 +351,7 @@ int SysCreat(const char *pathname, mode_t mode)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -373,7 +375,7 @@ int SysUnlink(const char *pathname)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -402,7 +404,7 @@ int SysChdir(const char *path)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -454,7 +456,7 @@ off64_t SysLseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int w
off64_t ret;
int retVal;
struct file *filep = NULL;
- off64_t offset = ((off64_t)offsetHigh << 32) + (uint)offsetLow; /* 32: offsetHigh is high 32 bits */
+ off64_t offset = ((off64_t)((UINT64)offsetHigh << 32)) + (uint)offsetLow; /* 32: offsetHigh is high 32 bits */
/* Process fd convert to system global fd */
fd = GetAssociatedSystemFd(fd);
@@ -569,10 +571,10 @@ int SysMount(const char *source, const char *target, const char *filesystemtype,
OUT:
if (sourceRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, sourceRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, sourceRet);
}
if (targetRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, targetRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, targetRet);
}
return ret;
}
@@ -600,7 +602,7 @@ int SysUmount(const char *target)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -609,6 +611,7 @@ int SysAccess(const char *path, int amode)
{
int ret;
struct stat buf;
+ struct statfs fsBuf;
char *pathRet = NULL;
if (path != NULL) {
@@ -618,9 +621,21 @@ int SysAccess(const char *path, int amode)
}
}
+ ret = statfs((path ? pathRet : NULL), &fsBuf);
+ if (ret != 0) {
+ ret = -get_errno();
+ goto OUT;
+ }
+
+ if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
+ ret = -EROFS;
+ goto OUT;
+ }
+
ret = stat((path ? pathRet : NULL), &buf);
if (ret != 0) {
ret = -get_errno();
+ goto OUT;
}
if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
@@ -629,7 +644,7 @@ int SysAccess(const char *path, int amode)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
@@ -663,10 +678,10 @@ int SysRename(const char *oldpath, const char *newpath)
OUT:
if (pathOldRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
}
if (pathNewRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
}
return ret;
}
@@ -690,7 +705,7 @@ int SysMkdir(const char *pathname, mode_t mode)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -714,7 +729,7 @@ int SysRmdir(const char *pathname)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -750,7 +765,7 @@ void SysSync(void)
int SysUmount2(const char *target, int flags)
{
if (flags != 0) {
- return -ENOSYS;
+ return -EINVAL;
}
return SysUmount(target);
}
@@ -799,6 +814,7 @@ int SysFcntl(int fd, int cmd, void *arg)
return ret;
}
+#ifdef LOSCFG_KERNEL_PIPE
int SysPipe(int pipefd[2]) /* 2 : pipe fds for read and write */
{
int ret;
@@ -839,6 +855,7 @@ int SysPipe(int pipefd[2]) /* 2 : pipe fds for read and write */
}
return ret;
}
+#endif
int SysDup2(int fd1, int fd2)
{
@@ -892,21 +909,21 @@ static int SelectParamCheckCopy(fd_set *readfds, fd_set *writefds, fd_set *excep
if (readfds != NULL) {
if (LOS_ArchCopyFromUser(readfdsRet, readfds, sizeof(fd_set)) != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
return -EFAULT;
}
}
if (writefds != NULL) {
if (LOS_ArchCopyFromUser(writefdsRet, writefds, sizeof(fd_set)) != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
return -EFAULT;
}
}
if (exceptfds != NULL) {
if (LOS_ArchCopyFromUser(exceptfdsRet, exceptfds, sizeof(fd_set)) != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, *fdsBuf);
return -EFAULT;
}
}
@@ -941,7 +958,7 @@ int SysSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
ret = do_select(nfds, (readfds ? readfdsRet : NULL), (writefds ? writefdsRet : NULL),
(exceptfds ? exceptfdsRet : NULL), (timeout ? (&timeoutRet) : NULL), UserPoll);
if (ret < 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
return -get_errno();
}
@@ -963,18 +980,18 @@ int SysSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
}
}
- LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
return ret;
ERROUT:
- LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
return -EFAULT;
}
int SysTruncate(const char *path, off_t length)
{
int ret;
- int fd = 0;
+ int fd = -1;
char *pathRet = NULL;
if (path != NULL) {
@@ -999,7 +1016,7 @@ int SysTruncate(const char *path, off_t length)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1007,7 +1024,7 @@ OUT:
int SysTruncate64(const char *path, off64_t length)
{
int ret;
- int fd = 0;
+ int fd = -1;
char *pathRet = NULL;
if (path != NULL) {
@@ -1032,7 +1049,7 @@ int SysTruncate64(const char *path, off64_t length)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1077,7 +1094,7 @@ int SysStatfs(const char *path, struct statfs *buf)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1113,7 +1130,7 @@ int SysStatfs64(const char *path, size_t sz, struct statfs *buf)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1144,7 +1161,7 @@ int SysStat(const char *path, struct stat *buf)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1175,7 +1192,7 @@ int SysLstat(const char *path, struct stat *buffer)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1410,17 +1427,17 @@ ssize_t SysPread64(int fd, void *buf, size_t nbytes, off64_t offset)
ret = pread64(fd, (buf ? bufRet : NULL), nbytes, offset);
if (ret < 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return -get_errno();
}
retVal = LOS_ArchCopyToUser(buf, bufRet, ret);
if (retVal != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return -EFAULT;
}
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return ret;
}
@@ -1448,18 +1465,18 @@ ssize_t SysPwrite64(int fd, const void *buf, size_t nbytes, off64_t offset)
if (buf != NULL) {
ret = LOS_ArchCopyFromUser(bufRet, buf, nbytes);
if (ret != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return -EFAULT;
}
}
ret = pwrite64(fd, (buf ? bufRet : NULL), nbytes, offset);
if (ret < 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return -get_errno();
}
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return ret;
}
@@ -1477,18 +1494,18 @@ char *SysGetcwd(char *buf, size_t n)
ret = getcwd((buf ? bufRet : NULL), n);
if (ret == NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return (char *)(intptr_t)-get_errno();
}
retVal = LOS_ArchCopyToUser(buf, bufRet, n);
if (retVal != 0) {
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return (char *)(intptr_t)-EFAULT;
}
ret = buf;
- LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
return ret;
}
@@ -1567,7 +1584,7 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1596,7 +1613,7 @@ int SysMkdirat(int dirfd, const char *pathname, mode_t mode)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1625,7 +1642,7 @@ int SysUnlinkat(int dirfd, const char *pathname, int flag)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1666,10 +1683,10 @@ int SysRenameat(int oldfd, const char *oldpath, int newdfd, const char *newpath)
OUT:
if (pathOldRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
}
if (pathNewRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
}
return ret;
}
@@ -1702,8 +1719,11 @@ int SysFallocate64(int fd, int mode, off64_t offset, off64_t len)
return ret;
}
-ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
+ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
{
+ off_t offsetflag;
+ offsetflag = (off_t)((unsigned long long)loffset | (((unsigned long long)hoffset) << HIGH_SHIFT_BIT));
+
int ret;
int valid_iovcnt = -1;
struct iovec *iovRet = NULL;
@@ -1711,7 +1731,7 @@ ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
/* Process fd convert to system global fd */
fd = GetAssociatedSystemFd(fd);
if ((iov == NULL) || (iovcnt <= 0) || (iovcnt > IOV_MAX)) {
- ret = preadv(fd, iov, iovcnt, offset);
+ ret = preadv(fd, iov, iovcnt, offsetflag);
return -get_errno();
}
@@ -1725,18 +1745,20 @@ ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
goto OUT_FREE;
}
- ret = preadv(fd, iovRet, valid_iovcnt, offset);
+ ret = preadv(fd, iovRet, valid_iovcnt, offsetflag);
if (ret < 0) {
ret = -get_errno();
}
OUT_FREE:
- (void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
+ (void)(void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
return ret;
}
-ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
+ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
{
+ off_t offsetflag;
+ offsetflag = (off_t)((unsigned long long)loffset | (((unsigned long long)hoffset) << HIGH_SHIFT_BIT));
int ret;
int valid_iovcnt = -1;
struct iovec *iovRet = NULL;
@@ -1744,7 +1766,7 @@ ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
/* Process fd convert to system global fd */
fd = GetAssociatedSystemFd(fd);
if ((iov == NULL) || (iovcnt <= 0) || (iovcnt > IOV_MAX)) {
- ret = pwritev(fd, iov, iovcnt, offset);
+ ret = pwritev(fd, iov, iovcnt, offsetflag);
return -get_errno();
}
@@ -1758,7 +1780,7 @@ ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
goto OUT_FREE;
}
- ret = pwritev(fd, iovRet, valid_iovcnt, offset);
+ ret = pwritev(fd, iovRet, valid_iovcnt, offsetflag);
if (ret < 0) {
ret = -get_errno();
}
@@ -1792,7 +1814,7 @@ int SysFormat(const char *dev, int sectors, int option)
OUT:
if (devRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, devRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, devRet);
}
return ret;
}
@@ -1836,7 +1858,7 @@ int SysFcntl64(int fd, int cmd, void *arg)
int SysGetdents64(int fd, struct dirent *de_user, unsigned int count)
{
- if (!LOS_IsUserAddressRange((VADDR_T)de_user, count)) {
+ if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)de_user, count)) {
return -EFAULT;
}
@@ -1850,7 +1872,7 @@ int SysGetdents64(int fd, struct dirent *de_user, unsigned int count)
return ret;
}
if (de_knl != NULL) {
- int cpy_ret = LOS_ArchCopyToUser(de_user, de_knl, sizeof(*de_knl));
+ int cpy_ret = LOS_ArchCopyToUser(de_user, de_knl, ret);
if (cpy_ret != 0)
{
return -EFAULT;
@@ -1893,17 +1915,17 @@ char *SysRealpath(const char *path, char *resolved_path)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
if (resolved_pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, resolved_pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, resolved_pathRet);
}
return result;
}
int SysChmod(const char *pathname, mode_t mode)
{
- struct IATTR attr;
+ struct IATTR attr = {0};
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
int ret;
@@ -1923,7 +1945,7 @@ int SysChmod(const char *pathname, mode_t mode)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
@@ -1957,7 +1979,7 @@ int SysChown(const char *pathname, uid_t owner, gid_t group)
OUT:
if (pathRet != NULL) {
- LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
diff --git a/syscall/ipc_syscall.c b/syscall/ipc_syscall.c
old mode 100644
new mode 100755
index a1890ed1..551f4984
--- a/syscall/ipc_syscall.c
+++ b/syscall/ipc_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -37,6 +37,24 @@
#include "user_copy.h"
#include "los_signal.h"
#include "los_strncpy_from_user.h"
+#include "fs_file.h"
+
+#define MQUEUE_FD_U2K(id) \
+ do { \
+ int sysFd = GetAssociatedSystemFd((INTPTR)(id)); \
+ (id) = (mqd_t)sysFd; \
+ } while (0)
+#define MQUEUE_FD_K2U(id) \
+ do { \
+ int procFd = AllocAndAssocProcessFd((INTPTR)(id), MIN_START_FD); \
+ if (procFd == -1) { \
+ mq_close(id); \
+ set_errno(EMFILE); \
+ (id) = (mqd_t)(-EMFILE); \
+ } else { \
+ (id) = (mqd_t)procFd; \
+ } \
+ } while (0)
mqd_t SysMqOpen(const char *mqName, int openFlag, mode_t mode, struct mq_attr *attr)
{
@@ -52,6 +70,8 @@ mqd_t SysMqOpen(const char *mqName, int openFlag, mode_t mode, struct mq_attr *a
if (ret == -1) {
return (mqd_t)-get_errno();
}
+ /* SysFd to procFd */
+ MQUEUE_FD_K2U(ret);
return ret;
}
@@ -59,6 +79,7 @@ int SysMqClose(mqd_t personal)
{
int ret;
+ MQUEUE_FD_U2K(personal);
ret = mq_close(personal);
if (ret < 0) {
return -get_errno();
@@ -77,6 +98,7 @@ int SysMqGetSetAttr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
return -EFAULT;
}
}
+ MQUEUE_FD_U2K(mqd);
ret = mq_getsetattr(mqd, new ? &knew : NULL, old ? &kold : NULL);
if (ret < 0) {
return -get_errno();
@@ -133,6 +155,7 @@ int SysMqTimedSend(mqd_t personal, const char *msg, size_t msgLen, unsigned int
free(msgIntr);
return -EFAULT;
}
+ MQUEUE_FD_U2K(personal);
ret = mq_timedsend(personal, msgIntr, msgLen, msgPrio, absTimeout ? &timeout : NULL);
free(msgIntr);
if (ret < 0) {
@@ -162,6 +185,7 @@ ssize_t SysMqTimedReceive(mqd_t personal, char *msg, size_t msgLen, unsigned int
if (msgIntr == NULL) {
return -ENOMEM;
}
+ MQUEUE_FD_U2K(personal);
receiveLen = mq_timedreceive(personal, msgIntr, msgLen, &kMsgPrio, absTimeout ? &timeout : NULL);
if (receiveLen < 0) {
free(msgIntr);
@@ -281,6 +305,7 @@ int SysSigSuspend(sigset_t_l *setl)
return OsSigSuspend(&set);
}
+#ifdef LOSCFG_KERNEL_PIPE
int SysMkFifo(const char *pathName, mode_t mode)
{
int retValue;
@@ -292,4 +317,4 @@ int SysMkFifo(const char *pathName, mode_t mode)
}
return mkfifo(kPathName, mode);
}
-
+#endif
diff --git a/syscall/los_syscall.c b/syscall/los_syscall.c
old mode 100644
new mode 100755
index 04bd3784..bd3c464d
--- a/syscall/los_syscall.c
+++ b/syscall/los_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h
old mode 100644
new mode 100755
index e4614771..0827b0a6
--- a/syscall/los_syscall.h
+++ b/syscall/los_syscall.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -35,6 +35,7 @@
#include "los_typedef.h"
#include "los_task.h"
#include "los_mux.h"
+#include "fs/fs.h"
#include "syscall.h"
#ifdef LOSCFG_KERNEL_DYNLOAD
#include "los_exec_elf.h"
@@ -97,6 +98,8 @@ extern void SysUserExitGroup(int status);
extern void SysThreadExit(int status);
extern int SysFutex(const unsigned int *uAddr, unsigned int flags, int val,
unsigned int absTime, const unsigned int *newUserAddr);
+extern int SysSchedGetAffinity(int id, unsigned int *cpuset, int flag);
+extern int SysSchedSetAffinity(int id, const unsigned short cpuset, int flag);
extern mqd_t SysMqOpen(const char *mqName, int openFlag, mode_t mode, struct mq_attr *attr);
extern int SysMqClose(mqd_t personal);
extern int SysMqGetSetAttr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old);
@@ -250,13 +253,14 @@ extern int SysUnlinkat(int dirfd, const char *pathname, int flag);
extern int SysRenameat(int oldfd, const char *oldpath, int newdfd, const char *newpath);
extern int SysFallocate(int fd, int mode, off_t offset, off_t len);
extern int SysFallocate64(int fd, int mode, off64_t offset, off64_t len);
-extern ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
-extern ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
+extern ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset);
+extern ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset);
extern void SysSync(void);
extern int SysGetdents64(int fd, struct dirent *de_user, unsigned int count);
extern int do_opendir(const char *path, int oflags);
extern char *SysRealpath(const char *path, char *resolvedPath);
extern int SysUmask(int mask);
extern int SysShellExec(const char *msgName, const char *cmdString);
+extern int SysReboot(int magic, int magic2, int type);
#endif
#endif /* _LOS_SYSCALL_H */
diff --git a/syscall/misc_syscall.c b/syscall/misc_syscall.c
old mode 100644
new mode 100755
index 5e185b01..c048dc1c
--- a/syscall/misc_syscall.c
+++ b/syscall/misc_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -36,6 +36,7 @@
#include "shmsg.h"
#endif
#include "sys/utsname.h"
+#include "sys/reboot.h"
#include "user_copy.h"
#include "los_strncpy_from_user.h"
#include "capability_type.h"
@@ -66,6 +67,21 @@ int SysUname(struct utsname *name)
return ret;
}
+int SysReboot(int magic, int magic2, int type)
+{
+ (void)magic;
+ (void)magic2;
+ if (!IsCapPermit(CAP_REBOOT)) {
+ return -EPERM;
+ }
+ SystemRebootFunc rebootHook = OsGetRebootHook();
+ if ((type == RB_AUTOBOOT) && (rebootHook != NULL)) {
+ rebootHook();
+ return 0;
+ }
+ return -EFAULT;
+}
+
#ifdef LOSCFG_SHELL
int SysShellExec(const char *msgName, const char *cmdString)
{
diff --git a/syscall/net_syscall.c b/syscall/net_syscall.c
old mode 100644
new mode 100755
index da948df5..1532eb12
--- a/syscall/net_syscall.c
+++ b/syscall/net_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -29,16 +29,28 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "los_process_pri.h"
-#include "lwip/sockets.h"
-#include
-#include "los_vm_map.h"
-#include "user_copy.h"
+#include "syscall_pub.h"
+#include "stdlib.h"
#include "fs_file.h"
+#include "fs/fs.h"
+#include "los_process_pri.h"
+#include "los_signal.h"
+#include "los_syscall.h"
+#include "los_vm_map.h"
+#include "lwip/sockets.h"
+#include "user_copy.h"
#ifdef LOSCFG_NET_LWIP_SACK
-#define SOCKET_U2K(s) do { s = GetAssociatedSystemFd(s); } while (0)
+#define SOCKET_U2K(s) \
+ do { \
+ s = GetAssociatedSystemFd(s); \
+ if (s == VFS_ERROR) { \
+ set_errno(EBADF); \
+ return -get_errno(); \
+ } \
+ } while (0)
+
#define SOCKET_K2U(s) \
do { \
int fd = AllocAndAssocProcessFd(s, MIN_START_FD); \
@@ -51,214 +63,6 @@
} \
} while (0)
-#define CHECK_ASPACE(ptr, len, ...) \
- do { \
- if (ptr != NULL && len != 0) { \
- if (!LOS_IsUserAddressRange((VADDR_T)ptr, len)) { \
- set_errno(EFAULT); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- if (CheckRegion(OsCurrProcessGet()->vmSpace, (VADDR_T)ptr, len) == -1) { \
- set_errno(EFAULT); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- } \
- } while (0)
-
-static int CheckRegion(const LosVmSpace *space, VADDR_T ptr, size_t len)
-{
- LosVmMapRegion *region = LOS_RegionFind((LosVmSpace *)space, ptr);
- if (region == NULL) {
- return -1;
- }
- if (ptr + len <= region->range.base + region->range.size) {
- return 0;
- }
- return CheckRegion(space, region->range.base + region->range.size,
- (ptr + len) - (region->range.base + region->range.size));
-}
-
-static void *DupUserMem(const void *ptr, size_t len, int needCopy)
-{
- void *p = malloc(len);
- if (p == NULL) {
- set_errno(ENOMEM);
- return NULL;
- }
- if (needCopy && LOS_ArchCopyFromUser(p, ptr, len) != 0) {
- free(p);
- set_errno(EFAULT);
- return NULL;
- }
- return p;
-}
-
-#define LEN(ptr) ((ptr) ? *(ptr) : 0)
-
-#define DUP_FROM_USER_(ptr, size, copy, ...) \
- __typeof(ptr) ptr##bak = ptr; \
- if (ptr != NULL && (size) != 0) { \
- ptr = DupUserMem(ptr, size, copy); \
- if (ptr == NULL) { \
- ptr = ptr##bak; \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-#define DUP_FROM_USER(ptr, size, ...) \
- DUP_FROM_USER_(ptr, size, 1, ##__VA_ARGS__)
-
-#define DUP_FROM_USER_NOCOPY(ptr, size, ...) \
- DUP_FROM_USER_(ptr, size, 0, ##__VA_ARGS__)
-
-#define DUP_TO_USER(ptr, size, ...) \
- if (ptr != NULL && (size) != 0) { \
- if (LOS_ArchCopyToUser(ptr##bak, ptr, size) != 0) { \
- set_errno(EFAULT); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-#define FREE_DUP(ptr) \
- if (ptr != ptr##bak) { \
- free((void*)ptr); \
- ptr = ptr##bak; \
- }
-
-#define CPY_FROM_USER(ptr) \
- __typeof(*ptr) ptr##cpy = {0}, *ptr##bak = ptr; \
- if (ptr != NULL) { \
- if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr, sizeof(*ptr)) != 0) { \
- set_errno(EFAULT); \
- return -get_errno(); \
- } \
- ptr = &ptr##cpy; \
- }
-
-#define CPY_TO_USER(ptr, ...) \
- if (ptr != NULL) { \
- if (LOS_ArchCopyToUser(ptr##bak, ptr, sizeof(*ptr)) != 0) { \
- set_errno(EFAULT); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-/** Macros for sendmsg and recvmsg */
-
-#define CONST_CAST(ptr) ((__typeof(ptr##_NONCONST))ptr)
-
-#define CHECK_FIELD_ASPACE(ptr, field, len) \
- do { \
- if (ptr != NULL) { \
- CHECK_ASPACE(ptr->field, len); \
- } \
- } while (0)
-
-#define CHECK_ARRAY_FIELD_ASPACE(ptr, arr, arrlen, field, len, ...) \
- do { \
- if (ptr != NULL && ptr->arr != NULL) { \
- for (size_t i = 0; i < arrlen; i++) { \
- CHECK_ASPACE(ptr->arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
- } \
- } \
- } while (0)
-
-#define DUP_FIELD_FROM_USER_(ptr, field, size, copy, ...) \
- if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
- CONST_CAST(ptr)->field = DupUserMem(ptr->field, size, copy); \
- if (ptr->field == NULL) { \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-#define DUP_FIELD_FROM_USER(ptr, field, size, ...) \
- DUP_FIELD_FROM_USER_(ptr, field, size, 1, ##__VA_ARGS__)
-
-#define DUP_FIELD_FROM_USER_NOCOPY(ptr, field, size, ...) \
- DUP_FIELD_FROM_USER_(ptr, field, size, 0, ##__VA_ARGS__)
-
-#define DUP_ARRAY_FIELD_FROM_USER_(ext, ptr, arr, arrlen, field, len, ...) \
- /* backup the arr to ptr##arr */ \
- __typeof(*ptr##_NONCONST) ptr##arr##cpy = ptr##cpybak, ptr##arr##cpybak = ptr##cpybak; \
- __typeof(ptr##_NONCONST) ptr##arr = ptr ? &ptr##arr##cpy : NULL, ptr##arr##_NONCONST = NULL; \
- DUP_FIELD_FROM_USER(ptr##arr, arr, arrlen * sizeof(ptr->arr[0]), ##__VA_ARGS__); \
- if (ptr != NULL && ptr->arr != NULL) { \
- size_t i = 0; \
- for (; i < arrlen; i++) { \
- DUP_FIELD_FROM_USER##ext(ptr, arr[i].field, ptr->arr[i].len, break); \
- } \
- if (i != arrlen) { \
- FREE_DUP_ARRAY_FIELD(ptr, arr, i, field); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-#define DUP_ARRAY_FIELD_FROM_USER(ptr, arr, arrlen, field, len, ...) \
- DUP_ARRAY_FIELD_FROM_USER_(, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
-
-#define DUP_ARRAY_FIELD_FROM_USER_NOCOPY(ptr, arr, arrlen, field, len, ...) \
- DUP_ARRAY_FIELD_FROM_USER_(_NOCOPY, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
-
-#define FREE_DUP_FIELD(ptr, field) \
- if (ptr != NULL && ptr->field != ptr##cpybak.field) { \
- free((void*)ptr->field); \
- CONST_CAST(ptr)->field = ptr##cpybak.field; \
- }
-
-#define FREE_DUP_ARRAY_FIELD(ptr, arr, arrlen, field) \
- /* use and free the backuped arr in ptr##arr */ \
- if (ptr != NULL && ptr->arr != NULL && arrlen != 0) { \
- __typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
- ptr##cpybak.arr = ptr##arr->arr; \
- for (size_t j = 0; j < arrlen; j++) { \
- FREE_DUP_FIELD(ptr, arr[j].field); \
- } \
- ptr##cpybak.arr = tmp; \
- } \
- FREE_DUP_FIELD(ptr##arr, arr);
-
-#define CPY_FROM_CONST_USER(NonConstType, ptr) \
- CPY_FROM_USER(ptr); \
- NonConstType *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy; \
- (void)ptr##bak;
-
-#define CPY_FROM_NONCONST_USER(ptr) \
- CPY_FROM_USER(ptr); \
- __typeof(*ptr) *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy;
-
-#define DUP_FIELD_TO_USER(ptr, field, size, ...) \
- if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
- if (LOS_ArchCopyToUser(ptr##cpybak.field, ptr->field, size) != 0 || \
- LOS_ArchCopyToUser(&ptr##bak->field, &ptr##cpybak.field, sizeof(ptr##cpybak.field)) != 0) { \
- set_errno(EFAULT); \
- __VA_ARGS__; \
- return -get_errno(); \
- } \
- }
-
-#define DUP_ARRAY_FIELD_TO_USER(ptr, arr, arrlen, field, len, ...) \
- /* use the backuped arr from ptr##arr */ \
- if (ptr != NULL && ptr->arr != NULL) { \
- __typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
- __typeof(ptr##bak) tmp2 = ptr##bak; \
- ptr##cpybak.arr = ptr##arr->arr; \
- ptr##arr->arr = tmp; \
- ptr##bak = ptr##arr; \
- for (size_t i = 0; i < arrlen; i++) { \
- DUP_FIELD_TO_USER(ptr, arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
- } \
- ptr##bak = tmp2; \
- ptr##arr->arr = ptr##cpybak.arr; \
- ptr##cpybak.arr = tmp; \
- }
-
int SysSocket(int domain, int type, int protocol)
{
int ret;
@@ -280,7 +84,13 @@ int SysBind(int s, const struct sockaddr *name, socklen_t namelen)
CHECK_ASPACE(name, namelen);
DUP_FROM_USER(name, namelen);
- ret = bind(s, name, namelen);
+
+ if (name == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = bind(s, name, namelen);
+ }
FREE_DUP(name);
if (ret == -1) {
return -get_errno();
@@ -297,7 +107,13 @@ int SysConnect(int s, const struct sockaddr *name, socklen_t namelen)
CHECK_ASPACE(name, namelen);
DUP_FROM_USER(name, namelen);
- ret = connect(s, name, namelen);
+
+ if (name == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = connect(s, name, namelen);
+ }
FREE_DUP(name);
if (ret == -1) {
return -get_errno();
@@ -346,7 +162,7 @@ int SysAccept(int socket, struct sockaddr *address,
return ret;
}
-int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen)
+int SysGetSockName(int s, struct sockaddr *name, socklen_t *namelen)
{
int ret;
@@ -358,7 +174,12 @@ int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen)
CHECK_ASPACE(name, LEN(namelen));
DUP_FROM_USER_NOCOPY(name, LEN(namelen));
- ret = getsockname(s, name, namelen);
+ if (name == NULL || namelen == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = getsockname(s, name, namelen);
+ }
if (ret == -1) {
FREE_DUP(name);
return -get_errno();
@@ -370,7 +191,7 @@ int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen)
return ret;
}
-int SysGetPeerName (int s, struct sockaddr *name, socklen_t *namelen)
+int SysGetPeerName(int s, struct sockaddr *name, socklen_t *namelen)
{
int ret;
@@ -382,7 +203,12 @@ int SysGetPeerName (int s, struct sockaddr *name, socklen_t *namelen)
CHECK_ASPACE(name, LEN(namelen));
DUP_FROM_USER_NOCOPY(name, LEN(namelen));
- ret = getpeername(s, name, namelen);
+ if (name == NULL || namelen == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = getpeername(s, name, namelen);
+ }
if (ret == -1) {
FREE_DUP(name);
return -get_errno();
@@ -402,7 +228,13 @@ ssize_t SysSend(int s, const void *dataptr, size_t size, int flags)
CHECK_ASPACE(dataptr, size);
DUP_FROM_USER(dataptr, size);
- ret = send(s, dataptr, size, flags);
+
+ if (dataptr == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = send(s, dataptr, size, flags);
+ }
FREE_DUP(dataptr);
if (ret == -1) {
return -get_errno();
@@ -421,8 +253,14 @@ ssize_t SysSendTo(int s, const void *dataptr, size_t size, int flags,
CHECK_ASPACE(to, tolen);
DUP_FROM_USER(dataptr, size);
- DUP_FROM_USER(to, tolen, FREE_DUP(dataptr););
- ret = sendto(s, dataptr, size, flags, to, tolen);
+ DUP_FROM_USER(to, tolen, FREE_DUP(dataptr));
+
+ if (dataptr == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = sendto(s, dataptr, size, flags, to, tolen);
+ }
FREE_DUP(dataptr);
FREE_DUP(to);
if (ret == -1) {
@@ -440,7 +278,13 @@ ssize_t SysRecv(int socket, void *buffer, size_t length, int flags)
CHECK_ASPACE(buffer, length);
DUP_FROM_USER_NOCOPY(buffer, length);
- ret = recv(socket, buffer, length, flags);
+
+ if (buffer == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = recv(socket, buffer, length, flags);
+ }
if (ret == -1) {
FREE_DUP(buffer);
return -get_errno();
@@ -467,7 +311,13 @@ ssize_t SysRecvFrom(int socket, void *buffer, size_t length,
DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
DUP_FROM_USER_NOCOPY(buffer, length, FREE_DUP(address));
- ret = recvfrom(socket, buffer, length, flags, address, addressLen);
+
+ if (buffer == NULL || (address != NULL && addressLen == NULL)) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = recvfrom(socket, buffer, length, flags, address, addressLen);
+ }
if (ret == -1) {
FREE_DUP(address);
FREE_DUP(buffer);
@@ -526,7 +376,12 @@ int SysGetSockOpt(int sockfd, int level, int optName,
CHECK_ASPACE(optValue, LEN(optLen));
DUP_FROM_USER_NOCOPY(optValue, LEN(optLen));
- ret = getsockopt(sockfd, level, optName, optValue, optLen);
+ if (optLen == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = getsockopt(sockfd, level, optName, optValue, optLen);
+ }
if (ret == -1) {
FREE_DUP(optValue);
return -get_errno();
@@ -558,17 +413,23 @@ ssize_t SysSendMsg(int s, const struct msghdr *message, int flags)
DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
- FREE_DUP_FIELD(message, msg_iov));
+ FREE_DUP_FIELD(message, msg_iov));
DUP_FIELD_FROM_USER(message, msg_name, message->msg_namelen,
- FREE_DUP_FIELD(message, msg_iov));
+ FREE_DUP_FIELD(message, msg_iov));
DUP_FIELD_FROM_USER(message, msg_control, message->msg_controllen,
- FREE_DUP_FIELD(message, msg_iov);
- FREE_DUP_FIELD(message, msg_name));
+ FREE_DUP_FIELD(message, msg_iov);
+ FREE_DUP_FIELD(message, msg_name));
DUP_ARRAY_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
- FREE_DUP_FIELD(message, msg_control);
- FREE_DUP_FIELD(message, msg_iov);
- FREE_DUP_FIELD(message, msg_name));
- ret = sendmsg(s, message, flags);
+ FREE_DUP_FIELD(message, msg_control);
+ FREE_DUP_FIELD(message, msg_iov);
+ FREE_DUP_FIELD(message, msg_name));
+
+ if (message == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = sendmsg(s, message, flags);
+ }
FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
FREE_DUP_FIELD(message, msg_control);
FREE_DUP_FIELD(message, msg_iov);
@@ -600,17 +461,23 @@ ssize_t SysRecvMsg(int s, struct msghdr *message, int flags)
DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
- FREE_DUP_FIELD(message, msg_iov));
+ FREE_DUP_FIELD(message, msg_iov));
DUP_FIELD_FROM_USER_NOCOPY(message, msg_name, message->msg_namelen,
- FREE_DUP_FIELD(message, msg_iov));
+ FREE_DUP_FIELD(message, msg_iov));
DUP_FIELD_FROM_USER_NOCOPY(message, msg_control, message->msg_controllen,
- FREE_DUP_FIELD(message, msg_iov);
- FREE_DUP_FIELD(message, msg_name));
+ FREE_DUP_FIELD(message, msg_iov);
+ FREE_DUP_FIELD(message, msg_name));
DUP_ARRAY_FIELD_FROM_USER_NOCOPY(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
- FREE_DUP_FIELD(message, msg_control);
- FREE_DUP_FIELD(message, msg_iov);
- FREE_DUP_FIELD(message, msg_name));
- ret = recvmsg(s, message, flags);
+ FREE_DUP_FIELD(message, msg_control);
+ FREE_DUP_FIELD(message, msg_iov);
+ FREE_DUP_FIELD(message, msg_name));
+
+ if (message == NULL) {
+ set_errno(EFAULT);
+ ret = -1;
+ } else {
+ ret = recvmsg(s, message, flags);
+ }
if (ret == -1) {
goto OUT;
}
diff --git a/syscall/process_syscall.c b/syscall/process_syscall.c
old mode 100644
new mode 100755
index 7bb1ec90..b54f8bb8
--- a/syscall/process_syscall.c
+++ b/syscall/process_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -31,9 +31,11 @@
#include "los_process_pri.h"
#include "los_task_pri.h"
+#include "los_sched_pri.h"
#include "los_hw_pri.h"
#include "los_sys_pri.h"
#include "los_futex_pri.h"
+#include "los_mp.h"
#include "user_copy.h"
#include "time.h"
#ifdef LOSCFG_SECURITY_CAPABILITY
@@ -66,7 +68,7 @@ static int OsUserTaskSchedulerSet(unsigned int tid, unsigned short policy, unsig
{
int ret;
unsigned int intSave;
- LosTaskCB *taskCB = NULL;
+ bool needSched = false;
if (OS_TID_CHECK_INVALID(tid)) {
return EINVAL;
@@ -81,24 +83,28 @@ static int OsUserTaskSchedulerSet(unsigned int tid, unsigned short policy, unsig
}
SCHEDULER_LOCK(intSave);
- taskCB = OS_TCB_FROM_TID(tid);
+ LosTaskCB *taskCB = OS_TCB_FROM_TID(tid);
ret = OsUserTaskOperatePermissionsCheck(taskCB);
if (ret != LOS_OK) {
SCHEDULER_UNLOCK(intSave);
return ret;
}
- return OsTaskSchedulerSetUnsafe(taskCB, policy, priority, policyFlag, intSave);
+ policy = (policyFlag == true) ? policy : taskCB->policy;
+ needSched = OsSchedModifyTaskSchedParam(taskCB, policy, priority);
+ SCHEDULER_UNLOCK(intSave);
+
+ LOS_MpSchedule(OS_MP_CPU_ALL);
+ if (needSched && OS_SCHEDULER_ACTIVE) {
+ LOS_Schedule();
+ }
+
+ return LOS_OK;
}
void SysSchedYield(int type)
{
- if (type < 0) {
- (void)LOS_TaskYield();
- return;
- }
-
- (void)LOS_ProcessYield();
+ (void)LOS_TaskYield();
return;
}
@@ -127,10 +133,6 @@ int SysSchedGetScheduler(int id, int flag)
return policy;
}
- if (id == 0) {
- id = (int)LOS_GetCurrProcessID();
- }
-
return LOS_GetProcessScheduler(id);
}
@@ -139,18 +141,13 @@ int SysSchedSetScheduler(int id, int policy, int prio, int flag)
int ret;
if (flag < 0) {
- return -OsUserTaskSchedulerSet(id, policy, prio, TRUE);
+ return -OsUserTaskSchedulerSet(id, policy, prio, true);
}
if (prio < OS_USER_PROCESS_PRIORITY_HIGHEST) {
return -EINVAL;
}
- /* Temporarily not support linux policy: SCHED_BATCH 3U, SCHED_RESET_ON_FORK 4U, SCHED_IDLE 5U, SCHED_DEADLINE 6U */
- if ((policy == 0) || (policy == 3) || (policy == 4) || (policy == 5) || (policy == 6)) {
- return -ENOSYS;
- }
-
if (id == 0) {
id = (int)LOS_GetCurrProcessID();
}
@@ -160,7 +157,7 @@ int SysSchedSetScheduler(int id, int policy, int prio, int flag)
return ret;
}
- return OsSetProcessScheduler(LOS_PRIO_PROCESS, id, prio, policy, TRUE);
+ return OsSetProcessScheduler(LOS_PRIO_PROCESS, id, prio, policy);
}
int SysSchedGetParam(int id, int flag)
@@ -198,30 +195,6 @@ int SysSchedGetParam(int id, int flag)
return OsGetProcessPriority(LOS_PRIO_PROCESS, id);
}
-int SysSchedSetParam(int id, unsigned int prio, int flag)
-{
- int ret;
-
- if (flag < 0) {
- return -OsUserTaskSchedulerSet(id, LOS_SCHED_RR, prio, FALSE);
- }
-
- if (prio < OS_USER_PROCESS_PRIORITY_HIGHEST) {
- return -EINVAL;
- }
-
- if (id == 0) {
- id = (int)LOS_GetCurrProcessID();
- }
-
- ret = OsPermissionToCheck(id, LOS_GetCurrProcessID());
- if (ret < 0) {
- return ret;
- }
-
- return OsSetProcessScheduler(LOS_PRIO_PROCESS, id, prio, LOS_SCHED_RR, FALSE);
-}
-
int SysSetProcessPriority(int which, int who, unsigned int prio)
{
int ret;
@@ -239,7 +212,16 @@ int SysSetProcessPriority(int which, int who, unsigned int prio)
return ret;
}
- return OsSetProcessScheduler(which, who, prio, LOS_SCHED_RR, FALSE);
+ return OsSetProcessScheduler(which, who, prio, LOS_GetProcessScheduler(who));
+}
+
+int SysSchedSetParam(int id, unsigned int prio, int flag)
+{
+ if (flag < 0) {
+ return -OsUserTaskSchedulerSet(id, LOS_SCHED_RR, prio, false);
+ }
+
+ return SysSetProcessPriority(LOS_PRIO_PROCESS, id, prio);
}
int SysGetProcessPriority(int which, int who)
@@ -253,11 +235,7 @@ int SysGetProcessPriority(int which, int who)
int SysSchedGetPriorityMin(int policy)
{
- /* Temporarily not support linux policy: SCHED_BATCH 3U, SCHED_RESET_ON_FORK 4U, SCHED_IDLE 5U, SCHED_DEADLINE 6U */
- if ((policy == 0) || (policy == 3) || (policy == 4) || (policy == 5) || (policy == 6)) {
- return -ENOSYS;
- }
- if ((policy != LOS_SCHED_RR) && (policy != LOS_SCHED_FIFO)) {
+ if (policy != LOS_SCHED_RR) {
return -EINVAL;
}
@@ -266,11 +244,7 @@ int SysSchedGetPriorityMin(int policy)
int SysSchedGetPriorityMax(int policy)
{
- /* Temporarily not support linux policy: SCHED_BATCH 3U, SCHED_RESET_ON_FORK 4U, SCHED_IDLE 5U, SCHED_DEADLINE 6U */
- if ((policy == 0) || (policy == 3) || (policy == 4) || (policy == 5) || (policy == 6)) {
- return -ENOSYS;
- }
- if ((policy != LOS_SCHED_RR) && (policy != LOS_SCHED_FIFO)) {
+ if (policy != LOS_SCHED_RR) {
return -EINVAL;
}
@@ -279,10 +253,12 @@ int SysSchedGetPriorityMax(int policy)
int SysSchedRRGetInterval(int pid, struct timespec *tp)
{
+ unsigned int intSave;
int ret;
- time_t msec;
+ time_t timeSlice = 0;
struct timespec tv;
- LosProcessCB *pcb = NULL;
+ LosTaskCB *taskCB = NULL;
+ LosProcessCB *processCB = NULL;
if (tp == NULL) {
return -EINVAL;
@@ -292,15 +268,30 @@ int SysSchedRRGetInterval(int pid, struct timespec *tp)
return -EINVAL;
}
+ if (pid == 0) {
+ processCB = OsCurrProcessGet();
+ } else {
+ processCB = OS_PCB_FROM_PID(pid);
+ }
+
+ SCHEDULER_LOCK(intSave);
/* if can not find process by pid return ESRCH */
- pcb = OS_PCB_FROM_PID(pid);
- if (OsProcessIsInactive(pcb)) {
+ if (OsProcessIsInactive(processCB)) {
+ SCHEDULER_UNLOCK(intSave);
return -ESRCH;
}
- msec = LOS_Tick2MS(OS_PROCESS_SCHED_RR_INTERVAL);
- tv.tv_sec = msec / OS_SYS_MS_PER_SECOND;
- tv.tv_nsec = (msec % OS_SYS_MS_PER_SECOND) * OS_SYS_NS_PER_MS;
+ LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
+ if (!OsTaskIsInactive(taskCB) && (taskCB->policy == LOS_SCHED_RR)) {
+ timeSlice += taskCB->initTimeSlice;
+ }
+ }
+
+ SCHEDULER_UNLOCK(intSave);
+
+ timeSlice = timeSlice * OS_NS_PER_CYCLE;
+ tv.tv_sec = timeSlice / OS_SYS_NS_PER_SECOND;
+ tv.tv_nsec = timeSlice % OS_SYS_NS_PER_SECOND;
ret = LOS_ArchCopyToUser(tp, &tv, sizeof(struct timespec));
if (ret != 0) {
return -EFAULT;
@@ -786,7 +777,7 @@ int SysGetGroups(int size, int list[])
#endif
}
-int SysSetGroups(int size, int list[])
+int SysSetGroups(int size, const int list[])
{
#ifdef LOSCFG_SECURITY_CAPABILITY
int ret;
@@ -996,6 +987,122 @@ unsigned int SysGetTid(void)
return OsCurrTaskGet()->taskID;
}
+/* If flag >= 0, the process mode is used. If flag < 0, the thread mode is used. */
+static int SchedAffinityParameterPreprocess(int id, int flag, unsigned int *taskID, unsigned int *processID)
+{
+ if (flag >= 0) {
+ if (OS_PID_CHECK_INVALID(id)) {
+ return -ESRCH;
+ }
+ *taskID = (id == 0) ? (OsCurrTaskGet()->taskID) : (OS_PCB_FROM_PID((UINT32)id)->threadGroupID);
+ *processID = (id == 0) ? (OS_TCB_FROM_TID(*taskID)->processID) : id;
+ } else {
+ if (OS_TID_CHECK_INVALID(id)) {
+ return -ESRCH;
+ }
+ *taskID = id;
+ *processID = OS_INVALID_VALUE;
+ }
+ return LOS_OK;
+}
+
+/* If flag >= 0, the process mode is used. If flag < 0, the thread mode is used. */
+int SysSchedGetAffinity(int id, unsigned int *cpuset, int flag)
+{
+ int ret;
+ unsigned int processID;
+ unsigned int taskID;
+ unsigned int intSave;
+ unsigned int cpuAffiMask;
+
+ ret = SchedAffinityParameterPreprocess(id, flag, &taskID, &processID);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ SCHEDULER_LOCK(intSave);
+ if (flag >= 0) {
+ if (OsProcessIsInactive(OS_PCB_FROM_PID(processID))) {
+ SCHEDULER_UNLOCK(intSave);
+ return -ESRCH;
+ }
+ } else {
+ ret = OsUserTaskOperatePermissionsCheck(OS_TCB_FROM_TID(taskID));
+ if (ret != LOS_OK) {
+ SCHEDULER_UNLOCK(intSave);
+ if (ret == EINVAL) {
+ return -ESRCH;
+ }
+ return -ret;
+ }
+ }
+
+#if (LOSCFG_KERNEL_SMP == YES)
+ cpuAffiMask = (unsigned int)OS_TCB_FROM_TID(taskID)->cpuAffiMask;
+#else
+ cpuAffiMask = 1;
+#endif /* LOSCFG_KERNEL_SMP */
+
+ SCHEDULER_UNLOCK(intSave);
+ ret = LOS_ArchCopyToUser(cpuset, &cpuAffiMask, sizeof(unsigned int));
+ if (ret != LOS_OK) {
+ return -EFAULT;
+ }
+
+ return LOS_OK;
+}
+
+/* If flag >= 0, the process mode is used. If flag < 0, the thread mode is used. */
+int SysSchedSetAffinity(int id, const unsigned short cpuset, int flag)
+{
+ int ret;
+ unsigned int processID;
+ unsigned int taskID;
+ unsigned int intSave;
+ unsigned short currCpuMask;
+ bool needSched = FALSE;
+
+ if (cpuset > LOSCFG_KERNEL_CPU_MASK) {
+ return -EINVAL;
+ }
+
+ ret = SchedAffinityParameterPreprocess(id, flag, &taskID, &processID);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ if (flag >= 0) {
+ ret = OsPermissionToCheck(processID, LOS_GetCurrProcessID());
+ if (ret != LOS_OK) {
+ return ret;
+ }
+ SCHEDULER_LOCK(intSave);
+ if (OsProcessIsInactive(OS_PCB_FROM_PID(processID))) {
+ SCHEDULER_UNLOCK(intSave);
+ return -ESRCH;
+ }
+ } else {
+ SCHEDULER_LOCK(intSave);
+ ret = OsUserTaskOperatePermissionsCheck(OS_TCB_FROM_TID(taskID));
+ if (ret != LOS_OK) {
+ SCHEDULER_UNLOCK(intSave);
+ if (ret == EINVAL) {
+ return -ESRCH;
+ }
+ return -ret;
+ }
+ }
+
+ needSched = OsTaskCpuAffiSetUnsafe(taskID, cpuset, &currCpuMask);
+ SCHEDULER_UNLOCK(intSave);
+ if (needSched && OS_SCHEDULER_ACTIVE) {
+ LOS_MpSchedule(currCpuMask);
+ LOS_Schedule();
+ }
+
+ return LOS_OK;
+}
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h
old mode 100644
new mode 100755
index a35b3acd..bb72f2b8
--- a/syscall/syscall_lookup.h
+++ b/syscall/syscall_lookup.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -54,12 +54,13 @@ SYSCALL_HAND_DEF(__NR_rename, SysRename, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_mkdir, SysMkdir, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_rmdir, SysRmdir, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_dup, SysDup, int, ARG_NUM_1)
+#ifdef LOSCFG_KERNEL_PIPE
SYSCALL_HAND_DEF(__NR_pipe, SysPipe, int, ARG_NUM_1)
+#endif
SYSCALL_HAND_DEF(__NR_umount2, SysUmount2, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_ioctl, SysIoctl, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_fcntl, SysFcntl, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_dup2, SysDup2, int, ARG_NUM_2)
-SYSCALL_HAND_DEF(82, SysSelect, int, ARG_NUM_5)
SYSCALL_HAND_DEF(__NR_truncate, SysTruncate, int, ARG_NUM_7)
SYSCALL_HAND_DEF(__NR_ftruncate, SysFtruncate, int, ARG_NUM_7)
SYSCALL_HAND_DEF(__NR_statfs, SysStatfs, int, ARG_NUM_2)
@@ -101,25 +102,25 @@ SYSCALL_HAND_DEF(__NR_statfs64, SysStatfs64, int, ARG_NUM_3)
#ifdef LOSCFG_DEBUG_VERSION
SYSCALL_HAND_DEF(__NR_dumpmemory, LOS_DumpMemRegion, void, ARG_NUM_1)
#endif
+#ifdef LOSCFG_KERNEL_PIPE
SYSCALL_HAND_DEF(__NR_mkfifo, SysMkFifo, int, ARG_NUM_2)
+#endif
SYSCALL_HAND_DEF(__NR_mqclose, SysMqClose, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_realpath, SysRealpath, char *, ARG_NUM_2)
#ifdef LOSCFG_SHELL
SYSCALL_HAND_DEF(__NR_shellexec, SysShellExec, UINT32, ARG_NUM_2)
#endif
-
-SYSCALL_HAND_DEF(30, SysUtime, int, ARG_NUM_2)
#endif
SYSCALL_HAND_DEF(__NR_exit, SysThreadExit, void, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_fork, SysFork, int, ARG_NUM_0)
-SYSCALL_HAND_DEF(13, SysTime, time_t, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_getpid, SysGetPID, unsigned int, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_pause, SysPause, int, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_kill, SysKill, int, ARG_NUM_2)
+SYSCALL_HAND_DEF(__NR_reboot, SysReboot, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_times, SysTimes, clock_t, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_brk, SysBrk, void *, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_setgid, SysSetGroupID, int, ARG_NUM_1)
@@ -143,6 +144,8 @@ SYSCALL_HAND_DEF(__NR_sched_getscheduler, SysSchedGetScheduler, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_sched_yield, SysSchedYield, void, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_sched_get_priority_max, SysSchedGetPriorityMax, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_sched_get_priority_min, SysSchedGetPriorityMin, int, ARG_NUM_1)
+SYSCALL_HAND_DEF(__NR_sched_setaffinity, SysSchedSetAffinity, int, ARG_NUM_3)
+SYSCALL_HAND_DEF(__NR_sched_getaffinity, SysSchedGetAffinity, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_sched_rr_get_interval, SysSchedRRGetInterval, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_nanosleep, SysNanoSleep, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_mremap, SysMremap, void *, ARG_NUM_5)
@@ -157,7 +160,7 @@ SYSCALL_HAND_DEF(__NR_rt_sigsuspend, SysSigSuspend, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_chown, SysChown, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_chown32, SysChown, int, ARG_NUM_3)
#ifdef LOSCFG_SECURITY_CAPABILITY
-SYSCALL_HAND_DEF(__NR_ohoscapget, SysCapGet, UINT32, ARG_NUM_1)
+SYSCALL_HAND_DEF(__NR_ohoscapget, SysCapGet, UINT32, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_ohoscapset, SysCapSet, UINT32, ARG_NUM_1)
#endif
@@ -183,8 +186,8 @@ SYSCALL_HAND_DEF(__NR_tkill, SysPthreadKill, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_futex, SysFutex, int, ARG_NUM_4)
SYSCALL_HAND_DEF(__NR_exit_group, SysUserExitGroup, void, ARG_NUM_1)
-SYSCALL_HAND_DEF(254, SysSetThreadArea, int, ARG_NUM_1)
-SYSCALL_HAND_DEF(255, SysGetThreadArea, char *, ARG_NUM_0)
+SYSCALL_HAND_DEF(__NR_set_thread_area, SysSetThreadArea, int, ARG_NUM_1)
+SYSCALL_HAND_DEF(__NR_get_thread_area, SysGetThreadArea, char *, ARG_NUM_0)
SYSCALL_HAND_DEF(__NR_timer_create, SysTimerCreate, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_timer_settime32, SysTimerSettime, int, ARG_NUM_4)
SYSCALL_HAND_DEF(__NR_timer_gettime32, SysTimerGettime, int, ARG_NUM_2)
@@ -219,18 +222,14 @@ SYSCALL_HAND_DEF(__NR_sendmsg, SysSendMsg, ssize_t, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_recvmsg, SysRecvMsg, ssize_t, ARG_NUM_3)
#endif
+#ifdef LOSCFG_KERNEL_SHM
SYSCALL_HAND_DEF(__NR_shmat, SysShmAt, void *, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_shmdt, SysShmDt, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_shmget, SysShmGet, int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_shmctl, SysShmCtl, int, ARG_NUM_3)
+#endif
SYSCALL_HAND_DEF(__NR_statx, SysStatx, int, ARG_NUM_5)
-SYSCALL_HAND_DEF(403, SysClockGettime64, int, ARG_NUM_2)
-SYSCALL_HAND_DEF(404, SysClockSettime64, int, ARG_NUM_2)
-SYSCALL_HAND_DEF(406, SysClockGetres64, int, ARG_NUM_2)
-SYSCALL_HAND_DEF(407, SysClockNanoSleep64, int, ARG_NUM_4)
-SYSCALL_HAND_DEF(408, SysTimerGettime64, int, ARG_NUM_2)
-SYSCALL_HAND_DEF(409, SysTimerSettime64, int, ARG_NUM_4)
/* LiteOS customized syscalls, not compatible with ARM EABI */
SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDeatch, int, ARG_NUM_1)
diff --git a/kernel/base/mem/bestfit/los_multipledlinkhead.c b/syscall/syscall_pub.c
similarity index 56%
rename from kernel/base/mem/bestfit/los_multipledlinkhead.c
rename to syscall/syscall_pub.c
index 641947dc..dbfd0f5a 100644
--- a/kernel/base/mem/bestfit/los_multipledlinkhead.c
+++ b/syscall/syscall_pub.c
@@ -1,74 +1,62 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "los_multipledlinkhead_pri.h"
-#include "los_bitmap.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#endif /* __cplusplus */
-
-STATIC INLINE UINT32 OsLog2(UINT32 size)
-{
- return (size > 0) ? (UINT32)LOS_HighBitGet(size) : 0;
-}
-
-LITE_OS_SEC_TEXT_INIT VOID OsDLnkInitMultiHead(VOID *headAddr)
-{
- LosMultipleDlinkHead *dlinkHead = (LosMultipleDlinkHead *)headAddr;
- LOS_DL_LIST *listNodeHead = dlinkHead->listHead;
- UINT32 index;
-
- for (index = 0; index < OS_MULTI_DLNK_NUM; ++index, ++listNodeHead) {
- LOS_ListInit(listNodeHead);
- }
-}
-
-LITE_OS_SEC_TEXT_MINOR LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size)
-{
- LosMultipleDlinkHead *dlinkHead = (LosMultipleDlinkHead *)headAddr;
- UINT32 index = OsLog2(size);
- if (index > OS_MAX_MULTI_DLNK_LOG2) {
- return NULL;
- } else if (index <= OS_MIN_MULTI_DLNK_LOG2) {
- index = OS_MIN_MULTI_DLNK_LOG2;
- }
-
- return dlinkHead->listHead + (index - OS_MIN_MULTI_DLNK_LOG2);
-}
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+/*
+ * 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 "syscall_pub.h"
+
+int CheckRegion(const LosVmSpace *space, VADDR_T ptr, size_t len)
+{
+ LosVmMapRegion *region = LOS_RegionFind((LosVmSpace *)space, ptr);
+ if (region == NULL) {
+ return -1;
+ }
+ if (ptr + len <= region->range.base + region->range.size) {
+ return 0;
+ }
+ return CheckRegion(space, region->range.base + region->range.size,
+ (ptr + len) - (region->range.base + region->range.size));
+}
+
+void *DupUserMem(const void *ptr, size_t len, int needCopy)
+{
+ void *p = LOS_MemAlloc(OS_SYS_MEM_ADDR, len);
+
+ if (p == NULL) {
+ set_errno(ENOMEM);
+ return NULL;
+ }
+
+ if (needCopy && LOS_ArchCopyFromUser(p, ptr, len) != 0) {
+ LOS_MemFree(OS_SYS_MEM_ADDR, p);
+ set_errno(EFAULT);
+ return NULL;
+ }
+
+ return p;
+}
diff --git a/syscall/syscall_pub.h b/syscall/syscall_pub.h
new file mode 100644
index 00000000..6c9015f0
--- /dev/null
+++ b/syscall/syscall_pub.h
@@ -0,0 +1,242 @@
+/*
+ * 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 _SYSCALL_PUB_H
+#define _SYSCALL_PUB_H
+
+#include
+#include "los_memory.h"
+#include "los_vm_map.h"
+#include "user_copy.h"
+
+extern int CheckRegion(const LosVmSpace *space, VADDR_T ptr, size_t len);
+extern void *DupUserMem(const void *ptr, size_t len, int needCopy);
+
+#define CHECK_ASPACE(ptr, len, ...) \
+ do { \
+ if (ptr != NULL && len != 0) { \
+ if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)ptr, len)) { \
+ set_errno(EFAULT); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ if (CheckRegion(OsCurrProcessGet()->vmSpace, (VADDR_T)(UINTPTR)ptr, len) == -1) { \
+ set_errno(EFAULT); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ } \
+ } while (0)
+
+#define LEN(ptr) ((ptr) ? *(ptr) : 0)
+
+#define DUP_FROM_USER_(ptr, size, copy, ...) \
+ __typeof(ptr) ptr##bak = ptr; \
+ if (ptr != NULL && (size) != 0) { \
+ ptr = DupUserMem(ptr, size, copy); \
+ if (ptr == NULL) { \
+ ptr = ptr##bak; \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ }
+
+/*
+DUP_FROM_USER(ptr, size, ...) can not deal with "char *";
+Please deal with the "char *" by function:UserPathCopy.
+*/
+#define DUP_FROM_USER(ptr, size, ...) \
+ DUP_FROM_USER_(ptr, size, 1, ##__VA_ARGS__)
+
+#define DUP_FROM_USER_NOCOPY(ptr, size, ...) \
+ DUP_FROM_USER_(ptr, size, 0, ##__VA_ARGS__)
+
+#define DUP_TO_USER(ptr, size, ...) \
+ do { \
+ if (ptr != NULL && (size) != 0) { \
+ if (LOS_ArchCopyToUser(ptr##bak, ptr, size) != 0) { \
+ set_errno(EFAULT); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ } \
+ } while (0)
+
+#define FREE_DUP(ptr) \
+ do { \
+ if (ptr != ptr##bak) { \
+ LOS_MemFree(OS_SYS_MEM_ADDR, (void*)ptr); \
+ ptr = ptr##bak; \
+ } \
+ } while (0)
+
+#define CPY_FROM_USER(ptr) \
+ __typeof(*ptr) ptr##cpy = {0}, *ptr##bak = ptr; \
+ if (ptr != NULL) { \
+ if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr, sizeof(*ptr)) != 0) { \
+ set_errno(EFAULT); \
+ return -get_errno(); \
+ } \
+ ptr = &ptr##cpy; \
+ }
+
+#define CPY_TO_USER(ptr, ...) \
+ if (ptr != NULL) { \
+ if (LOS_ArchCopyToUser(ptr##bak, ptr, sizeof(*ptr)) != 0) { \
+ set_errno(EFAULT); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ }
+
+/** Macros for sendmsg and recvmsg */
+
+#define CONST_CAST(ptr) ((__typeof(ptr##_NONCONST))ptr)
+
+#define CHECK_FIELD_ASPACE(ptr, field, len) \
+ do { \
+ if (ptr != NULL) { \
+ CHECK_ASPACE(ptr->field, len); \
+ } \
+ } while (0)
+
+#define CHECK_ARRAY_FIELD_ASPACE(ptr, arr, arrlen, field, len, ...) \
+ do { \
+ if (ptr != NULL && ptr->arr != NULL) { \
+ for (size_t i = 0; i < arrlen; i++) { \
+ CHECK_ASPACE(ptr->arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
+ } \
+ } \
+ } while (0)
+
+#define DUP_FIELD_FROM_USER_(ptr, field, size, copy, ...) \
+ do { \
+ if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
+ CONST_CAST(ptr)->field = DupUserMem(ptr->field, size, copy); \
+ if (ptr->field == NULL) { \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ } \
+ } while (0)
+
+#define DUP_FIELD_FROM_USER(ptr, field, size, ...) \
+ DUP_FIELD_FROM_USER_(ptr, field, size, 1, ##__VA_ARGS__)
+
+#define DUP_FIELD_FROM_USER_NOCOPY(ptr, field, size, ...) \
+ DUP_FIELD_FROM_USER_(ptr, field, size, 0, ##__VA_ARGS__)
+
+/* backup the arr to ptr##arr */
+#define DUP_ARRAY_FIELD_FROM_USER_(ext, ptr, arr, arrlen, field, len, ...) \
+ __typeof(*ptr##_NONCONST) ptr##arr##cpy = ptr##cpybak, ptr##arr##cpybak = ptr##cpybak; \
+ __typeof(ptr##_NONCONST) ptr##arr = ptr ? &ptr##arr##cpy : NULL, ptr##arr##_NONCONST = NULL; \
+ DUP_FIELD_FROM_USER(ptr##arr, arr, arrlen * sizeof(ptr->arr[0]), ##__VA_ARGS__); \
+ if (ptr != NULL && ptr->arr != NULL) { \
+ size_t i = 0; \
+ for (; i < arrlen; i++) { \
+ DUP_FIELD_FROM_USER##ext(ptr, arr[i].field, ptr->arr[i].len, break); \
+ } \
+ if (i != arrlen) { \
+ FREE_DUP_ARRAY_FIELD(ptr, arr, i, field); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ }
+
+#define DUP_ARRAY_FIELD_FROM_USER(ptr, arr, arrlen, field, len, ...) \
+ DUP_ARRAY_FIELD_FROM_USER_(, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
+
+#define DUP_ARRAY_FIELD_FROM_USER_NOCOPY(ptr, arr, arrlen, field, len, ...) \
+ DUP_ARRAY_FIELD_FROM_USER_(_NOCOPY, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
+
+#define FREE_DUP_FIELD(ptr, field) \
+ do { \
+ if (ptr != NULL && ptr->field != ptr##cpybak.field) { \
+ LOS_MemFree(OS_SYS_MEM_ADDR, (void*)ptr->field); \
+ CONST_CAST(ptr)->field = ptr##cpybak.field; \
+ } \
+ } while (0)
+
+/* use and free the backuped arr in ptr##arr */
+#define FREE_DUP_ARRAY_FIELD(ptr, arr, arrlen, field) \
+ if (ptr != NULL && ptr->arr != NULL && arrlen != 0) { \
+ __typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
+ ptr##cpybak.arr = ptr##arr->arr; \
+ for (size_t j = 0; j < arrlen; j++) { \
+ FREE_DUP_FIELD(ptr, arr[j].field); \
+ } \
+ ptr##cpybak.arr = tmp; \
+ } \
+ FREE_DUP_FIELD(ptr##arr, arr);
+
+#define CPY_FROM_CONST_USER(NonConstType, ptr) \
+ CPY_FROM_USER(ptr); \
+ NonConstType *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy; \
+ (void)ptr##bak;
+
+#define CPY_FROM_NONCONST_USER(ptr) \
+ CPY_FROM_USER(ptr); \
+ __typeof(*ptr) *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy;
+
+#define DUP_FIELD_TO_USER(ptr, field, size, ...) \
+ do { \
+ if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
+ if (LOS_ArchCopyToUser(ptr##cpybak.field, ptr->field, size) != 0 || \
+ LOS_ArchCopyToUser(&ptr##bak->field, &ptr##cpybak.field, sizeof(__typeof(ptr##cpybak.field))) != 0) { \
+ set_errno(EFAULT); \
+ __VA_ARGS__; \
+ return -get_errno(); \
+ } \
+ } \
+ } while (0)
+
+/* use the backuped arr from ptr##arr */
+#define DUP_ARRAY_FIELD_TO_USER(ptr, arr, arrlen, field, len, ...) \
+ if (ptr != NULL && ptr->arr != NULL) { \
+ __typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
+ __typeof(ptr##bak) tmp2 = ptr##bak; \
+ ptr##cpybak.arr = ptr##arr->arr; \
+ ptr##arr->arr = tmp; \
+ ptr##bak = ptr##arr; \
+ for (size_t i = 0; i < arrlen; i++) { \
+ DUP_FIELD_TO_USER(ptr, arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
+ } \
+ ptr##bak = tmp2; \
+ ptr##arr->arr = ptr##cpybak.arr; \
+ ptr##cpybak.arr = tmp; \
+ }
+
+#define PointerFree(ptr) \
+ do { \
+ if (ptr != NULL) { \
+ LOS_MemFree(OS_SYS_MEM_ADDR, (void*)ptr); \
+ } \
+ } while (0)
+#endif
diff --git a/syscall/time_syscall.c b/syscall/time_syscall.c
old mode 100644
new mode 100755
index ab1c4278..10ef483c
--- a/syscall/time_syscall.c
+++ b/syscall/time_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -331,7 +331,7 @@ int SysClockNanoSleep(clockid_t clk, int flags, const struct timespec *req, stru
{
int ret;
struct timespec sreq;
- struct timespec srem = {0};
+ struct timespec srem = { 0 };
if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec))) {
errno = EFAULT;
@@ -355,7 +355,7 @@ int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp)
{
int ret;
struct timespec srqtp;
- struct timespec srmtp = {0};
+ struct timespec srmtp = { 0 };
if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
errno = EFAULT;
@@ -380,9 +380,15 @@ clock_t SysTimes(struct tms *buf)
clock_t ret;
struct tms sbuf;
- ret = times(buf ? &sbuf : NULL);
-
- if (buf && LOS_ArchCopyToUser(buf, &sbuf, sizeof(struct tms))) {
+ if (buf == NULL) {
+ errno = EFAULT;
+ return -EFAULT;
+ }
+ ret = times(&sbuf);
+ if (ret == -1) {
+ return -get_errno();
+ }
+ if (LOS_ArchCopyToUser(buf, &sbuf, sizeof(struct tms))) {
errno = EFAULT;
return -EFAULT;
}
@@ -478,9 +484,9 @@ int SysClockNanoSleep64(clockid_t clk, int flags, const struct timespec64 *req,
{
int ret;
struct timespec rq;
- struct timespec rm = {0};
+ struct timespec rm = { 0 };
struct timespec64 sreq;
- struct timespec64 srem;
+ struct timespec64 srem = { 0 };
if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec64))) {
errno = EFAULT;
diff --git a/syscall/vm_syscall.c b/syscall/vm_syscall.c
old mode 100644
new mode 100755
index 6afe3b1e..c1344ea1
--- a/syscall/vm_syscall.c
+++ b/syscall/vm_syscall.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * 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:
@@ -70,6 +70,7 @@ void *SysBrk(void *addr)
return LOS_DoBrk(addr);
}
+#ifdef LOSCFG_KERNEL_SHM
int SysShmGet(key_t key, size_t size, int shmflg)
{
int ret;
@@ -117,6 +118,7 @@ int SysShmDt(const void *shmaddr)
return ret;
}
+#endif
#ifdef __cplusplus
#if __cplusplus
diff --git a/tools/build/config.mk b/tools/build/config.mk
index 4d06aea7..6b468487 100644
--- a/tools/build/config.mk
+++ b/tools/build/config.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/build/config/debug/hi3516dv300.config b/tools/build/config/debug/hi3516dv300.config
deleted file mode 100644
index fb17d09f..00000000
--- a/tools/build/config/debug/hi3516dv300.config
+++ /dev/null
@@ -1,190 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3516dv300"
-LOSCFG_PLATFORM_HI3516DV300=y
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-# LOSCFG_TEE_ENABLE is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-LOSCFG_KERNEL_SMP=y
-LOSCFG_KERNEL_SMP_CORE_NUM=2
-LOSCFG_KERNEL_SMP_LOCKDEP=y
-LOSCFG_KERNEL_SMP_TASK_SYNC=y
-# LOSCFG_KERNEL_SCHED_STATISTICS is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-# LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-LOSCFG_USER_INIT_DEBUG=y
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-# LOSCFG_NULL_ADDRESS_PROTECT is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-LOSCFG_DRIVERS_HDF_INPUT=y
-LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
-LOSCFG_DRIVERS_HDF_LCD=y
-LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-LOSCFG_DRIVERS_SD=y
-LOSCFG_DRIVERS_EMMC=y
-LOSCFG_DRIVERS_EMMC_HS200=y
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/debug/hi3516dv300_clang.config b/tools/build/config/debug/hi3516dv300_clang.config
deleted file mode 100644
index 111ba398..00000000
--- a/tools/build/config/debug/hi3516dv300_clang.config
+++ /dev/null
@@ -1,192 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-# LOSCFG_COMPILER_HIMIX_32 is not set
-LOSCFG_COMPILER_CLANG_LLVM=y
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3516dv300"
-LOSCFG_PLATFORM_HI3516DV300=y
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-# LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 is not set
-# LOSCFG_TEE_ENABLE is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_HRTIMER_ENABLE=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-LOSCFG_KERNEL_SMP=y
-LOSCFG_KERNEL_SMP_CORE_NUM=2
-LOSCFG_KERNEL_SMP_LOCKDEP=y
-LOSCFG_KERNEL_SMP_TASK_SYNC=y
-# LOSCFG_KERNEL_SCHED_STATISTICS is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-# LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-LOSCFG_USER_INIT_DEBUG=y
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-# LOSCFG_NULL_ADDRESS_PROTECT is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-LOSCFG_DRIVERS_HDF_INPUT=y
-LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
-LOSCFG_DRIVERS_HDF_LCD=y
-LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-LOSCFG_DRIVERS_SD=y
-LOSCFG_DRIVERS_EMMC=y
-LOSCFG_DRIVERS_EMMC_HS200=y
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/debug/hi3518ev300.config b/tools/build/config/debug/hi3518ev300.config
deleted file mode 100644
index 57654ae2..00000000
--- a/tools/build/config/debug/hi3518ev300.config
+++ /dev/null
@@ -1,183 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3518ev300"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-LOSCFG_PLATFORM_HI3518EV300=y
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-LOSCFG_KERNEL_TICKLESS=y
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-LOSCFG_USER_INIT_DEBUG=y
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-LOSCFG_NULL_ADDRESS_PROTECT=y
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-# LOSCFG_DRIVERS_SD_DETECT_BY_SW is not set
-LOSCFG_DRIVERS_SD=y
-# LOSCFG_DRIVERS_EMMC is not set
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/debug/hi3518ev300_clang.config b/tools/build/config/debug/hi3518ev300_clang.config
deleted file mode 100644
index 339674a9..00000000
--- a/tools/build/config/debug/hi3518ev300_clang.config
+++ /dev/null
@@ -1,185 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-# LOSCFG_COMPILER_HIMIX_32 is not set
-LOSCFG_COMPILER_CLANG_LLVM=y
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3518ev300"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-LOSCFG_PLATFORM_HI3518EV300=y
-# LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_HRTIMER_ENABLE=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-LOSCFG_KERNEL_TICKLESS=y
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-LOSCFG_USER_INIT_DEBUG=y
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-LOSCFG_NULL_ADDRESS_PROTECT=y
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-# LOSCFG_DRIVERS_SD_DETECT_BY_SW is not set
-LOSCFG_DRIVERS_SD=y
-# LOSCFG_DRIVERS_EMMC is not set
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/debug/hispark_aries.config b/tools/build/config/debug/hispark_aries.config
new file mode 100755
index 00000000..772b3f04
--- /dev/null
+++ b/tools/build/config/debug/hispark_aries.config
@@ -0,0 +1,33 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_PRODUCT_HISPARK_ARIES=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_aries/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/hispark_aries_clang.config b/tools/build/config/debug/hispark_aries_clang.config
new file mode 100755
index 00000000..ad900b69
--- /dev/null
+++ b/tools/build/config/debug/hispark_aries_clang.config
@@ -0,0 +1,33 @@
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_PRODUCT_HISPARK_ARIES=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_aries/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/hispark_taurus.config b/tools/build/config/debug/hispark_taurus.config
new file mode 100755
index 00000000..4bee1095
--- /dev/null
+++ b/tools/build/config/debug/hispark_taurus.config
@@ -0,0 +1,43 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/hispark_taurus_clang.config b/tools/build/config/debug/hispark_taurus_clang.config
new file mode 100755
index 00000000..8cd85850
--- /dev/null
+++ b/tools/build/config/debug/hispark_taurus_clang.config
@@ -0,0 +1,43 @@
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/hispark_taurus_clang_tee.config b/tools/build/config/debug/hispark_taurus_clang_tee.config
new file mode 100755
index 00000000..03dff370
--- /dev/null
+++ b/tools/build/config/debug/hispark_taurus_clang_tee.config
@@ -0,0 +1,44 @@
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/ipcamera_hi3516dv300_liteos.config b/tools/build/config/debug/ipcamera_hi3516dv300_liteos.config
new file mode 100755
index 00000000..eb1feba5
--- /dev/null
+++ b/tools/build/config/debug/ipcamera_hi3516dv300_liteos.config
@@ -0,0 +1,41 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang.config b/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang.config
new file mode 100755
index 00000000..05e8c829
--- /dev/null
+++ b/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang.config
@@ -0,0 +1,39 @@
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang_tee.config b/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang_tee.config
new file mode 100755
index 00000000..d7c5566f
--- /dev/null
+++ b/tools/build/config/debug/ipcamera_hi3516dv300_liteos_clang_tee.config
@@ -0,0 +1,41 @@
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/ipcamera_hi3518ev300_liteos.config b/tools/build/config/debug/ipcamera_hi3518ev300_liteos.config
new file mode 100755
index 00000000..655891d1
--- /dev/null
+++ b/tools/build/config/debug/ipcamera_hi3518ev300_liteos.config
@@ -0,0 +1,33 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3518ev300/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/ipcamera_hi3518ev300_liteos_clang.config b/tools/build/config/debug/ipcamera_hi3518ev300_liteos_clang.config
new file mode 100755
index 00000000..5c9f4535
--- /dev/null
+++ b/tools/build/config/debug/ipcamera_hi3518ev300_liteos_clang.config
@@ -0,0 +1,31 @@
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3518ev300/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/debug/qemu_arm_virt_ca7_clang.config b/tools/build/config/debug/qemu_arm_virt_ca7_clang.config
deleted file mode 100644
index 0ea33d91..00000000
--- a/tools/build/config/debug/qemu_arm_virt_ca7_clang.config
+++ /dev/null
@@ -1,148 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-# LOSCFG_COMPILER_HIMIX_32 is not set
-LOSCFG_COMPILER_CLANG_LLVM=y
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="virt"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7=y
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-# LOSCFG_HRTIMER_ENABLE is not set
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-# LOSCFG_KERNEL_CPPSUPPORT is not set
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-# LOSCFG_KERNEL_VDSO is not set
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-# LOSCFG_BASE_CORE_HILOG is not set
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-# LOSCFG_FS_VFS_BLOCK_DEVICE is not set
-LOSCFG_FILE_MODE=y
-# LOSCFG_FS_FAT is not set
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-# LOSCFG_NET_LWIP_SACK is not set
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-# LOSCFG_PLATFORM_ADAPT is not set
-# LOSCFG_ENABLE_OOM_LOOP_TASK is not set
-# LOSCFG_ENABLE_MAGICKEY is not set
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-# LOSCFG_SHELL_LK is not set
-# LOSCFG_SHELL_EXCINFO is not set
-# LOSCFG_EXC_INTERACTION is not set
-LOSCFG_USER_INIT_DEBUG=y
-# LOSCFG_SHELL_CMD_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-# LOSCFG_NULL_ADDRESS_PROTECT is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-# LOSCFG_DRIVERS_USB is not set
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-# LOSCFG_DRIVERS_HDF_PLATFORM_I2C is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_SPI is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_GPIO is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_SDIO is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_RTC is not set
-# LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK is not set
-# LOSCFG_DRIVERS_HDF_WIFI is not set
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-# LOSCFG_DRIVERS_HDF_USB is not set
-LOSCFG_DRIVERS_MEM=y
-# LOSCFG_DRIVERS_MMC is not set
-LOSCFG_DRIVERS_MTD=y
-# LOSCFG_DRIVERS_RANDOM is not set
-# LOSCFG_DRIVERS_VIDEO is not set
-# LOSCFG_DRIVERS_HIEVENT is not set
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR_STRONG is not set
-LOSCFG_CC_STACKPROTECTOR_ALL=y
diff --git a/tools/build/config/hi3516dv300_clang_release.config b/tools/build/config/hi3516dv300_clang_release.config
deleted file mode 100644
index 4476fd70..00000000
--- a/tools/build/config/hi3516dv300_clang_release.config
+++ /dev/null
@@ -1,175 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-# LOSCFG_COMPILER_HIMIX_32 is not set
-LOSCFG_COMPILER_CLANG_LLVM=y
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3516dv300"
-LOSCFG_PLATFORM_HI3516DV300=y
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-# LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 is not set
-# LOSCFG_TEE_ENABLE is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_HRTIMER_ENABLE=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-LOSCFG_KERNEL_SMP=y
-LOSCFG_KERNEL_SMP_CORE_NUM=2
-LOSCFG_KERNEL_SMP_LOCKDEP=y
-LOSCFG_KERNEL_SMP_TASK_SYNC=y
-# LOSCFG_KERNEL_SCHED_STATISTICS is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-# LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-# LOSCFG_DEBUG_VERSION is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-LOSCFG_DRIVERS_HDF_INPUT=y
-LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
-LOSCFG_DRIVERS_HDF_LCD=y
-LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-LOSCFG_DRIVERS_SD=y
-LOSCFG_DRIVERS_EMMC=y
-LOSCFG_DRIVERS_EMMC_HS200=y
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hi3516dv300_debug_shell.config b/tools/build/config/hi3516dv300_debug_shell.config
deleted file mode 100644
index a3b4d5c0..00000000
--- a/tools/build/config/hi3516dv300_debug_shell.config
+++ /dev/null
@@ -1,190 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3516dv300"
-LOSCFG_PLATFORM_HI3516DV300=y
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-# LOSCFG_TEE_ENABLE is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-LOSCFG_KERNEL_SMP=y
-LOSCFG_KERNEL_SMP_CORE_NUM=2
-LOSCFG_KERNEL_SMP_LOCKDEP=y
-LOSCFG_KERNEL_SMP_TASK_SYNC=y
-# LOSCFG_KERNEL_SCHED_STATISTICS is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-# LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-# LOSCFG_USER_INIT_DEBUG is not set
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-# LOSCFG_NULL_ADDRESS_PROTECT is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-LOSCFG_DRIVERS_HDF_INPUT=y
-LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
-LOSCFG_DRIVERS_HDF_LCD=y
-LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-LOSCFG_DRIVERS_SD=y
-LOSCFG_DRIVERS_EMMC=y
-LOSCFG_DRIVERS_EMMC_HS200=y
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hi3516dv300_release.config b/tools/build/config/hi3516dv300_release.config
deleted file mode 100644
index 28dc1d19..00000000
--- a/tools/build/config/hi3516dv300_release.config
+++ /dev/null
@@ -1,173 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3516dv300"
-LOSCFG_PLATFORM_HI3516DV300=y
-# LOSCFG_PLATFORM_HI3518EV300 is not set
-# LOSCFG_TEE_ENABLE is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-LOSCFG_KERNEL_SMP=y
-LOSCFG_KERNEL_SMP_CORE_NUM=2
-LOSCFG_KERNEL_SMP_LOCKDEP=y
-LOSCFG_KERNEL_SMP_TASK_SYNC=y
-# LOSCFG_KERNEL_SCHED_STATISTICS is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-# LOSCFG_KERNEL_TICKLESS is not set
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-# LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-# LOSCFG_ENABLE_MAGICKEY is not set
-# LOSCFG_THUMB is not set
-# LOSCFG_DEBUG_VERSION is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-LOSCFG_DRIVERS_HDF_INPUT=y
-LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
-LOSCFG_DRIVERS_HDF_LCD=y
-LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-LOSCFG_DRIVERS_SD=y
-LOSCFG_DRIVERS_EMMC=y
-LOSCFG_DRIVERS_EMMC_HS200=y
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hi3518ev300_clang_release.config b/tools/build/config/hi3518ev300_clang_release.config
deleted file mode 100644
index 0d2da7ee..00000000
--- a/tools/build/config/hi3518ev300_clang_release.config
+++ /dev/null
@@ -1,168 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-# LOSCFG_COMPILER_HIMIX_32 is not set
-LOSCFG_COMPILER_CLANG_LLVM=y
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3518ev300"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-LOSCFG_PLATFORM_HI3518EV300=y
-# LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 is not set
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_HRTIMER_ENABLE=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-LOSCFG_KERNEL_TICKLESS=y
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-# LOSCFG_DEBUG_VERSION is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-# LOSCFG_DRIVERS_SD_DETECT_BY_SW is not set
-LOSCFG_DRIVERS_SD=y
-# LOSCFG_DRIVERS_EMMC is not set
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hi3518ev300_debug_shell.config b/tools/build/config/hi3518ev300_debug_shell.config
deleted file mode 100644
index 41716002..00000000
--- a/tools/build/config/hi3518ev300_debug_shell.config
+++ /dev/null
@@ -1,183 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3518ev300"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-LOSCFG_PLATFORM_HI3518EV300=y
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-LOSCFG_KERNEL_TICKLESS=y
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-LOSCFG_ENABLE_MAGICKEY=y
-# LOSCFG_THUMB is not set
-LOSCFG_DEBUG_VERSION=y
-# LOSCFG_DEBUG_KERNEL is not set
-LOSCFG_SHELL=y
-
-#
-# Functionality of Shell
-#
-LOSCFG_SHELL_LK=y
-LOSCFG_SHELL_DMESG=y
-# LOSCFG_SHELL_EXCINFO is not set
-LOSCFG_NET_LWIP_SACK_TFTP=y
-LOSCFG_NET_TELNET=y
-# LOSCFG_EXC_INTERACTION is not set
-# LOSCFG_USER_INIT_DEBUG is not set
-LOSCFG_SHELL_CMD_DEBUG=y
-# LOSCFG_USB_DEBUG is not set
-# LOSCFG_MEM_DEBUG is not set
-LOSCFG_NULL_ADDRESS_PROTECT=y
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-# LOSCFG_DRIVERS_SD_DETECT_BY_SW is not set
-LOSCFG_DRIVERS_SD=y
-# LOSCFG_DRIVERS_EMMC is not set
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hi3518ev300_release.config b/tools/build/config/hi3518ev300_release.config
deleted file mode 100644
index f21be7b2..00000000
--- a/tools/build/config/hi3518ev300_release.config
+++ /dev/null
@@ -1,166 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# Huawei LiteOS Configuration
-#
-
-#
-# Compiler
-#
-LOSCFG_COMPILER_HIMIX_32=y
-# LOSCFG_COMPILER_CLANG_LLVM is not set
-
-#
-# Platform
-#
-LOSCFG_PLATFORM="hi3518ev300"
-# LOSCFG_PLATFORM_HI3516DV300 is not set
-LOSCFG_PLATFORM_HI3518EV300=y
-LOSCFG_PLATFORM_BSP_GIC_V2=y
-LOSCFG_ARCH_ARM=y
-LOSCFG_ARCH_ARM_AARCH32=y
-LOSCFG_ARCH_ARM_V7A=y
-LOSCFG_ARCH_ARM_VER="armv7-a"
-LOSCFG_ARCH_FPU_VFP_V4=y
-LOSCFG_ARCH_FPU_VFP_D32=y
-LOSCFG_ARCH_FPU_VFP_NEON=y
-LOSCFG_ARCH_FPU="neon-vfpv4"
-LOSCFG_ARCH_CORTEX_A7=y
-LOSCFG_ARCH_CPU="cortex-a7"
-
-#
-# Extra Configurations
-#
-# LOSCFG_ARCH_FPU_DISABLE is not set
-LOSCFG_IRQ_USE_STANDALONE_STACK=y
-LOSCFG_PLATFORM_ROOTFS=y
-
-#
-# Kernel
-#
-# LOSCFG_KERNEL_SMP is not set
-LOSCFG_KERNEL_EXTKERNEL=y
-LOSCFG_KERNEL_CPPSUPPORT=y
-LOSCFG_KERNEL_CPUP=y
-LOSCFG_CPUP_INCLUDE_IRQ=y
-LOSCFG_KERNEL_DYNLOAD=y
-LOSCFG_ASLR=y
-LOSCFG_KERNEL_VDSO=y
-LOSCFG_KERNEL_TICKLESS=y
-# LOSCFG_KERNEL_TRACE is not set
-LOSCFG_KERNEL_LITEIPC=y
-LOSCFG_KERNEL_PIPE=y
-LOSCFG_BASE_CORE_HILOG=y
-
-#
-# Lib
-#
-LOSCFG_LIB_LIBC=y
-LOSCFG_LIB_ZLIB=y
-
-#
-# Compat
-#
-LOSCFG_COMPAT_POSIX=y
-LOSCFG_COMPAT_BSD=y
-
-#
-# FileSystem
-#
-LOSCFG_FS_VFS=y
-LOSCFG_FS_VFS_BLOCK_DEVICE=y
-LOSCFG_FILE_MODE=y
-LOSCFG_FS_FAT=y
-LOSCFG_FS_FAT_CACHE=y
-LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
-LOSCFG_FS_FAT_CHINESE=y
-LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
-LOSCFG_FS_FAT_VOLUMES=16
-LOSCFG_FS_FAT_DISK=y
-LOSCFG_FS_RAMFS=y
-LOSCFG_FS_NFS=y
-LOSCFG_FS_PROC=y
-LOSCFG_FS_JFFS=y
-
-#
-# Net
-#
-LOSCFG_NET_LWIP_SACK=y
-LOSCFG_NET_LWIP_SACK_2_1=y
-
-#
-# Debug
-#
-# LOSCFG_COMPILE_DEBUG is not set
-LOSCFG_PLATFORM_ADAPT=y
-LOSCFG_ENABLE_OOM_LOOP_TASK=y
-# LOSCFG_ENABLE_MAGICKEY is not set
-# LOSCFG_THUMB is not set
-# LOSCFG_DEBUG_VERSION is not set
-LOSCFG_DRIVERS_HDF_PLATFORM_UART=y
-# LOSCFG_PLATFORM_UART_WITHOUT_VFS is not set
-# LOSCFG_PLATFORM_NO_UART is not set
-
-#
-# Driver
-#
-LOSCFG_DRIVERS=y
-LOSCFG_DRIVERS_USB=y
-LOSCFG_DRIVERS_USB_HOST_DRIVER=y
-# LOSCFG_DRIVERS_USB_HOST_EHCI is not set
-LOSCFG_DRIVERS_USB_HOST_XHCI=y
-LOSCFG_DRIVERS_USB_DEVICE_CLASS_DRIVERS=y
-
-#
-# USB Device Class Drivers
-#
-LOSCFG_DRIVERS_USB_MASS_STORAGE=y
-LOSCFG_DRIVERS_USB_RNDIS_HOST=y
-LOSCFG_DRIVERS_USB_4G_MODEM=y
-LOSCFG_DRIVERS_USB_SERIAL=y
-LOSCFG_DRIVERS_USB_ETHERNET=y
-LOSCFG_DRIVERS_USB_WIRELESS=y
-LOSCFG_DRIVERS_USB_HID_CLASS=y
-LOSCFG_DRIVERS_HDF=y
-LOSCFG_DRIVERS_HDF_PLATFORM=y
-LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
-LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
-LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
-LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
-LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
-LOSCFG_DRIVERS_HDF_WIFI=y
-LOSCFG_DRIVERS_HI3881=y
-# LOSCFG_DRIVERS_HDF_INPUT is not set
-# LOSCFG_DRIVERS_HDF_LCD is not set
-LOSCFG_DRIVERS_HDF_USB=y
-LOSCFG_DRIVERS_NETDEV=y
-LOSCFG_DRIVERS_HIETH_SF=y
-LOSCFG_DRIVERS_MEM=y
-LOSCFG_DRIVERS_MMC=y
-# LOSCFG_DRIVERS_SD_DETECT_BY_SW is not set
-LOSCFG_DRIVERS_SD=y
-# LOSCFG_DRIVERS_EMMC is not set
-LOSCFG_DRIVERS_MTD=y
-LOSCFG_DRIVERS_MTD_SPI_NOR=y
-LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100=y
-LOSCFG_DRIVERS_RANDOM=y
-LOSCFG_HW_RANDOM_ENABLE=y
-LOSCFG_DRIVERS_VIDEO=y
-LOSCFG_DRIVERS_HIEVENT=y
-
-#
-# Security
-#
-LOSCFG_SECURITY=y
-LOSCFG_SECURITY_CAPABILITY=y
-LOSCFG_SECURITY_VID=y
-# LOSCFG_SECURITY_BOOT is not set
-
-#
-# Stack Smashing Protector (SSP) Compiler Feature
-#
-# LOSCFG_CC_NO_STACKPROTECTOR is not set
-# LOSCFG_CC_STACKPROTECTOR is not set
-LOSCFG_CC_STACKPROTECTOR_STRONG=y
-# LOSCFG_CC_STACKPROTECTOR_ALL is not set
diff --git a/tools/build/config/hispark_aries_clang_release.config b/tools/build/config/hispark_aries_clang_release.config
new file mode 100755
index 00000000..53d622bf
--- /dev/null
+++ b/tools/build/config/hispark_aries_clang_release.config
@@ -0,0 +1,30 @@
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_PRODUCT_HISPARK_ARIES=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_aries/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+# LOSCFG_SHELL is not set
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_aries_debug_shell.config b/tools/build/config/hispark_aries_debug_shell.config
new file mode 100755
index 00000000..772b3f04
--- /dev/null
+++ b/tools/build/config/hispark_aries_debug_shell.config
@@ -0,0 +1,33 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_PRODUCT_HISPARK_ARIES=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_aries/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_aries_release.config b/tools/build/config/hispark_aries_release.config
new file mode 100755
index 00000000..e7c564cb
--- /dev/null
+++ b/tools/build/config/hispark_aries_release.config
@@ -0,0 +1,29 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_PRODUCT_HISPARK_ARIES=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_aries/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_clang_release.config b/tools/build/config/hispark_taurus_clang_release.config
new file mode 100755
index 00000000..4f0f51ea
--- /dev/null
+++ b/tools/build/config/hispark_taurus_clang_release.config
@@ -0,0 +1,40 @@
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+# LOSCFG_SHELL is not set
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_clang_release_tee.config b/tools/build/config/hispark_taurus_clang_release_tee.config
new file mode 100755
index 00000000..d920789e
--- /dev/null
+++ b/tools/build/config/hispark_taurus_clang_release_tee.config
@@ -0,0 +1,42 @@
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+# LOSCFG_SHELL is not set
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_debug_shell.config b/tools/build/config/hispark_taurus_debug_shell.config
new file mode 100755
index 00000000..b0965c3c
--- /dev/null
+++ b/tools/build/config/hispark_taurus_debug_shell.config
@@ -0,0 +1,43 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_debug_shell_tee.config b/tools/build/config/hispark_taurus_debug_shell_tee.config
new file mode 100755
index 00000000..a3ee089a
--- /dev/null
+++ b/tools/build/config/hispark_taurus_debug_shell_tee.config
@@ -0,0 +1,45 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_release.config b/tools/build/config/hispark_taurus_release.config
new file mode 100755
index 00000000..c7a42fa0
--- /dev/null
+++ b/tools/build/config/hispark_taurus_release.config
@@ -0,0 +1,39 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/hispark_taurus_release_tee.config b/tools/build/config/hispark_taurus_release_tee.config
new file mode 100755
index 00000000..df3a8e52
--- /dev/null
+++ b/tools/build/config/hispark_taurus_release_tee.config
@@ -0,0 +1,41 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PRODUCT_HISPARK_TAURUS=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hispark_taurus/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_STORAGE_EMMC=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release.config b/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release.config
new file mode 100755
index 00000000..18ed73cc
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release.config
@@ -0,0 +1,34 @@
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release_tee.config b/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release_tee.config
new file mode 100755
index 00000000..df2abca4
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_clang_release_tee.config
@@ -0,0 +1,36 @@
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell.config b/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell.config
new file mode 100755
index 00000000..6c2b9e47
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell.config
@@ -0,0 +1,42 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_HDF_SENSOR=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell_tee.config b/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell_tee.config
new file mode 100755
index 00000000..52d48e03
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_debug_shell_tee.config
@@ -0,0 +1,43 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_TEE_ENABLE=y
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_TZDRIVER=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_release.config b/tools/build/config/ipcamera_hi3516dv300_liteos_release.config
new file mode 100755
index 00000000..a0ab25a3
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_release.config
@@ -0,0 +1,38 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3516dv300_liteos_release_tee.config b/tools/build/config/ipcamera_hi3516dv300_liteos_release_tee.config
new file mode 100755
index 00000000..a0ab25a3
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3516dv300_liteos_release_tee.config
@@ -0,0 +1,38 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3516dv300/sdk_liteos/config/board"
+LOSCFG_KERNEL_SMP=y
+LOSCFG_KERNEL_SMP_LOCKDEP=y
+LOSCFG_KERNEL_SMP_TASK_SYNC=y
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_PWM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_EMMC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_DISP=y
+LOSCFG_DRIVERS_HDF_LCD_ICN9700=y
+LOSCFG_DRIVERS_HDF_INPUT=y
+LOSCFG_DRIVERS_HDF_TP_5P5_GT911=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_EMMC=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3518ev300_liteos_clang_release.config b/tools/build/config/ipcamera_hi3518ev300_liteos_clang_release.config
new file mode 100755
index 00000000..015e238e
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3518ev300_liteos_clang_release.config
@@ -0,0 +1,26 @@
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3518ev300/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3518ev300_liteos_debug_shell.config b/tools/build/config/ipcamera_hi3518ev300_liteos_debug_shell.config
new file mode 100755
index 00000000..6c0ea04f
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3518ev300_liteos_debug_shell.config
@@ -0,0 +1,34 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3518ev300/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+LOSCFG_DEBUG_VERSION=y
+LOSCFG_SHELL_DMESG=y
+LOSCFG_USER_INIT_DEBUG=y
+LOSCFG_SHELL_CMD_DEBUG=y
+LOSCFG_NULL_ADDRESS_PROTECT=y
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_HDF_TEST=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/ipcamera_hi3518ev300_liteos_release.config b/tools/build/config/ipcamera_hi3518ev300_liteos_release.config
new file mode 100755
index 00000000..326021a5
--- /dev/null
+++ b/tools/build/config/ipcamera_hi3518ev300_liteos_release.config
@@ -0,0 +1,29 @@
+LOSCFG_COMPILER_HIMIX_32=y
+LOSCFG_PLATFORM_HI3518EV300=y
+LOSCFG_BOARD_CONFIG_PATH="device/hisilicon/hi3518ev300/sdk_liteos/config/board"
+LOSCFG_ASLR=y
+LOSCFG_KERNEL_VDSO=y
+LOSCFG_FS_VFS_BLOCK_DEVICE=y
+LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y
+LOSCFG_FS_FAT_VIRTUAL_PARTITION=y
+LOSCFG_NET_LWIP_SACK_2_0=y
+LOSCFG_ENABLE_OOM_LOOP_TASK=y
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DRIVERS_USB_HOST_XHCI=y
+LOSCFG_DRIVERS_USB_ETHERNET=y
+LOSCFG_DRIVERS_USB_WIRELESS=y
+LOSCFG_DRIVERS_USB_HID_CLASS=y
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_I2C=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+LOSCFG_DRIVERS_HDF_PLATFORM_GPIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SDIO=y
+LOSCFG_DRIVERS_HDF_PLATFORM_RTC=y
+LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK=y
+LOSCFG_DRIVERS_HDF_WIFI=y
+LOSCFG_DRIVERS_HI3881=y
+LOSCFG_DRIVERS_HDF_USB=y
+LOSCFG_DRIVERS_SD=y
+LOSCFG_DRIVERS_HIEVENT=y
diff --git a/tools/build/config/qemu_arm_virt_debug_shell.config b/tools/build/config/qemu_arm_virt_debug_shell.config
new file mode 100755
index 00000000..88da9ef9
--- /dev/null
+++ b/tools/build/config/qemu_arm_virt_debug_shell.config
@@ -0,0 +1,18 @@
+LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7=y
+LOSCFG_BOARD_CONFIG_PATH="device/qemu/arm_virt/liteos_a/config/board"
+# LOSCFG_HRTIMER_ENABLE is not set
+# LOSCFG_KERNEL_CPPSUPPORT is not set
+# LOSCFG_FS_FAT is not set
+# LOSCFG_ENABLE_MAGICKEY is not set
+LOSCFG_DEBUG_VERSION=y
+# LOSCFG_SHELL_LK is not set
+LOSCFG_USER_INIT_DEBUG=y
+# LOSCFG_DRIVERS_USB is not set
+LOSCFG_DRIVERS_HDF=y
+LOSCFG_DRIVERS_HDF_PLATFORM=y
+LOSCFG_DRIVERS_HDF_PLATFORM_SPI=y
+# LOSCFG_DRIVERS_MMC is not set
+# LOSCFG_DRIVERS_MTD_SPI_NOR is not set
+# LOSCFG_DRIVERS_RANDOM is not set
+# LOSCFG_DRIVERS_VIDEO is not set
+LOSCFG_CC_STACKPROTECTOR_ALL=y
diff --git a/tools/build/liteos.ld b/tools/build/liteos.ld
old mode 100644
new mode 100755
diff --git a/tools/build/liteos_llvm.ld b/tools/build/liteos_llvm.ld
old mode 100644
new mode 100755
diff --git a/tools/build/mk/bepbuildtime.conf b/tools/build/mk/bepbuildtime.conf
old mode 100644
new mode 100755
diff --git a/tools/build/mk/dynload.mk b/tools/build/mk/dynload.mk
old mode 100644
new mode 100755
index 0cc4bb12..5b802f30
--- a/tools/build/mk/dynload.mk
+++ b/tools/build/mk/dynload.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/build/mk/get_compiler_path.sh b/tools/build/mk/get_compiler_path.sh
new file mode 100755
index 00000000..191e9046
--- /dev/null
+++ b/tools/build/mk/get_compiler_path.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+# 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.
+
+set -e
+declare CROSS_COMPILER="$1"
+declare HMOS_TOP_DIR="$2"
+declare gcc_path=${HMOS_TOP_DIR}/../../prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc
+declare windows_gcc_path=${HMOS_TOP_DIR}/../../prebuilts/gcc/win-x86/arm/arm-linux-ohoseabi-gcc
+function get_compiler_path()
+{
+ local system=$(uname -s)
+ local user_gcc="${CROSS_COMPILER}"gcc
+ local gcc_install_path=$(which "${user_gcc}")
+
+ if [ "$system" != "Linux" ] ; then
+ if [ -e "${windows_gcc_path}" ] ; then
+ gcc_install_path=$windows_gcc_path
+ else
+ gcc_install_path=$(dirname $gcc_install_path)/../
+ fi
+ else
+ if [ -e "${gcc_path}" ] ; then
+ gcc_install_path=$gcc_path
+ else
+ gcc_install_path=$(dirname $gcc_install_path)/../
+ fi
+ fi
+
+ echo "$gcc_install_path"
+}
+get_compiler_path
diff --git a/tools/build/mk/get_llvm_compiler_path.sh b/tools/build/mk/get_llvm_compiler_path.sh
index 1fa12631..243c984b 100755
--- a/tools/build/mk/get_llvm_compiler_path.sh
+++ b/tools/build/mk/get_llvm_compiler_path.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -30,20 +30,28 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
+declare TEMP="$1"
+declare TEMP2="$2"
+declare llvm_path_linux=${TEMP2}/../../prebuilts/clang/ohos/linux-x86_64/llvm
+declare llvm_path_windows=${TEMP2}/../../prebuilts/clang/ohos/windows-x86_64/llvm
function get_compiler_path()
{
local system=$(uname -s)
local user_clang=clang
local clang_install_path=$(which "${user_clang}")
if [ "$system" == "Linux" ] ; then
- if [ -n "${clang_install_path}" ] ; then
+ if [ -e "${llvm_path_linux}" ] ; then
+ echo "${llvm_path_linux}"
+ elif [ -n "${clang_install_path}" ] ; then
clang_install_path=$(dirname ${clang_install_path})/../
echo "${clang_install_path}"
else
echo "WARNING:Set llvm/bin path in PATH."
fi
else
- if [ -n "${clang_install_path}" ] ; then
+ if [ -e "${llvm_path_windows}" ] ; then
+ echo "${llvm_path_windows}"
+ elif [ -n "${clang_install_path}" ] ; then
clang_install_path=$(dirname ${clang_install_path})/../
echo "${clang_install_path}"
else
diff --git a/tools/build/mk/liteos_tables_ldflags.mk b/tools/build/mk/liteos_tables_ldflags.mk
old mode 100644
new mode 100755
index 5e8f9e13..07d50a02
--- a/tools/build/mk/liteos_tables_ldflags.mk
+++ b/tools/build/mk/liteos_tables_ldflags.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -31,7 +31,7 @@
#task_shellcmd.c -utask_shellcmd
#cpup_shellcmd.c -ucpup_shellcmd
#shell_shellcmd.c -uhelp_shellcmd
-#mempt_shellcmd.c -ufree_shellcmd -umemcheck_shellcmd -uuname_shellcmd -ureadreg_shellcmd -uwritereg_shellcmd
+#mempt_shellcmd.c -ufree_shellcmd -umemcheck_shellcmd -uuname_shellcmd -uwritereg_shellcmd
#sem_shellcmd.c -usem_shellcmd
#sysinfo_shellcmd.c -usysteminfo_shellcmd
#swtmr_shellcmd.c -uswtmr_shellcmd
@@ -58,8 +58,9 @@ LITEOS_TABLES_KERNEL_LDFLAGS := \
-uwatch_shellcmd \
-udeadlock_shellcmd \
-ukill_shellcmd \
- -upmm_shellcmd
-
+ -upmm_shellcmd \
+ -upanic_reset_shellcmd \
+ -ushm_shellcmd
####Net command####
#api_shell.c -uarp_shellcmd -uifconfig_shellcmd -uping_shellcmd -utftp_shellcmd -unetstat_shellcmd -udns_shellcmd -untpdate_shellcmd
@@ -151,6 +152,10 @@ LITEOS_TABLES_FSMAP_LDFLAGS := \
-uprocfs_fsmap \
-ug_fsmap
+#ifdef LOSCFG_FS_ZPFS
+LITEOS_TABLES_FSMAP_LDFLAGS += -uzpfs_fsmap
+#endif
+
LITEOS_TABLES_LDFLAGS := \
$(LITEOS_TABLES_KERNEL_LDFLAGS)\
$(LITEOS_TABLES_NET_LDFLAGS) \
diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk
old mode 100644
new mode 100755
index 2fc434d2..66e2be84
--- a/tools/build/mk/los_config.mk
+++ b/tools/build/mk/los_config.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -101,7 +101,6 @@ LITEOS_COMPILER_CXXLIB_PATH :=
LITEOS_COMPILER_GCCLIB_PATH :=
LITEOS_COMPILER_GCC_INCLUDE :=
LITEOS_DRIVERS_BASE_PATH :=
-LITEOS_VENDOR_DRIVERS_BASE_PATH :=
## variable define ##
ifeq ($(LITEOSTHIRDPARTY),)
@@ -128,8 +127,6 @@ ifeq ($(LOSCFG_COMPILER_HIMIX_32), y)
LITEOS_CMACRO += -D__COMPILER_HUAWEILITEOS__
else ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LITEOS_CMACRO += -D__COMPILER_HUAWEILITEOS__
-else ifeq ($(LOSCFG_COMPILER_HIMIX100_64), y)
-LITEOS_CMACRO += -D__COMPILER_HUAWEILITEOS__
else ifeq ($(LOSCFG_COMPILER_HCC_64), y)
LITEOS_CMACRO += -D__COMPILER_HUAWEILITEOS__
endif
@@ -143,7 +140,11 @@ LITEOS_BASELIB += -lgcc_eh
endif
AS_OBJS_LIBC_FLAGS = -D__ASSEMBLY__
+ifeq ($(LOSCFG_QUICK_START), y)
+WARNING_AS_ERROR := -Wall
+else
WARNING_AS_ERROR := -Wall -Werror
+endif
####################################### CPU Option Begin #########################################
include $(LITEOSTOPDIR)/arch/cpu.mk
@@ -156,6 +157,11 @@ ifeq ($(LOSCFG_PLATFORM_ROOTFS), y)
LITEOS_BASELIB += -lrootfs
LIB_SUBDIRS += $(LITEOSTOPDIR)/kernel/common
endif
+
+ifeq ($(LOSCFG_PLATFORM_PATCHFS), y)
+ LITEOS_BASELIB += -lpatchfs
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/kernel/common/patchfs
+endif
############################# Platform Option End #################################
####################################### Kernel Option Begin ###########################################
@@ -163,9 +169,11 @@ LITEOS_BASELIB += -lbase
LIB_SUBDIRS += kernel/base
LITEOS_KERNEL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/include
-ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
-LITEOS_BASELIB += -lhi35xx_bsp
-LIB_SUBDIRS += $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board/
+LITEOS_BASELIB += -lbsp_config
+LIB_SUBDIRS += $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)
+
+ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
+LITEOS_PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)/include/
endif
ifeq ($(LOSCFG_KERNEL_CPUP), y)
@@ -193,17 +201,9 @@ ifeq ($(LOSCFG_KERNEL_VDSO), y)
LITEOS_VDSO_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/vdso/include
endif
-ifeq ($(LOSCFG_KERNEL_TICKLESS), y)
- LITEOS_BASELIB += -ltickless
- LIB_SUBDIRS += kernel/extended/tickless
- LITEOS_TICKLESS_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/tickless
-endif
-
-ifeq ($(LOSCFG_KERNEL_TRACE), y)
LITEOS_BASELIB += -ltrace
LIB_SUBDIRS += kernel/extended/trace
LITEOS_TRACE_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/trace
-endif
ifeq ($(LOSCFG_KERNEL_LITEIPC), y)
LITEOS_BASELIB += -lliteipc
@@ -213,8 +213,8 @@ endif
ifeq ($(LOSCFG_KERNEL_PIPE), y)
LITEOS_BASELIB += -lpipes
- LIB_SUBDIRS += kernel/extended/pipe
- LITEOS_PIPE_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/pipe
+ LIB_SUBDIRS += kernel/extended/pipes
+ LITEOS_PIPE_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/pipes
endif
################################### Kernel Option End ################################
@@ -338,6 +338,11 @@ ifeq ($(LOSCFG_FS_JFFS), y)
LITEOS_BASELIB += -ljffs2
LIB_SUBDIRS += fs/jffs2
endif
+
+ifeq ($(LOSCFG_FS_ZPFS), y)
+ LITEOS_BASELIB += -lzpfs
+ LIB_SUBDIRS += fs/zpfs
+endif
#################################### FS Option End ##################################
@@ -352,6 +357,15 @@ ifeq ($(LOSCFG_NET_LWIP_SACK_2_1), y)
-I $(LWIPDIR)/include \
-I $(LITEOSTOPDIR)/net/mac
+ LITEOS_CMACRO += $(LWIP_MACROS)
+else ifeq ($(LOSCFG_NET_LWIP_SACK_2_0), y)
+ LWIPDIR := $(LITEOSTHIRDPARTY)/lwip_enhanced
+ LITEOS_BASELIB += -llwip
+ LIB_SUBDIRS += $(LWIPDIR)
+ LITEOS_LWIP_SACK_INCLUDE += \
+ -I $(LWIPDIR)/include \
+ -I $(LITEOSTOPDIR)/net/mac
+ LWIP_MACROS += -DLWIP_CONFIG_FILE=\"lwip/lwipopts.h\"
LITEOS_CMACRO += $(LWIP_MACROS)
else
$(error "unknown lwip version")
@@ -360,14 +374,9 @@ endif
#################################### Net Option End####################################
LITEOS_DRIVERS_BASE_PATH := $(LITEOSTOPDIR)/../../drivers/liteos
-ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
-LITEOS_VENDOR_DRIVERS_BASE_PATH := $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/platform
-else ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
-LITEOS_VENDOR_DRIVERS_BASE_PATH := $(LITEOSTOPDIR)/../../device/qemu/arm/platform
-endif
################################## Driver Option Begin #################################
ifeq ($(LOSCFG_DRIVERS_HDF), y)
-include $(LITEOSTOPDIR)/../../drivers/hdf/lite/hdf_lite.mk
+include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/hdf_lite.mk
endif
ifeq ($(LOSCFG_DRIVERS_HIEVENT), y)
@@ -376,16 +385,6 @@ ifeq ($(LOSCFG_DRIVERS_HIEVENT), y)
LITEOS_HIEVENT_INCLUDE += -I $(LITEOS_DRIVERS_BASE_PATH)/hievent/include
endif
-ifeq ($(LOSCFG_DRIVERS_HIEDMAC), y)
- LITEOS_BASELIB += -lhiedmac
- LITEOS_HIDMAC_INCLUDE += -I $(LITEOS_VENDOR_DRIVERS_BASE_PATH)/hiedmac/include
-endif
-
-ifeq ($(LOSCFG_DRIVERS_HIETH_SF), y)
- LITEOS_BASELIB += -lhieth-sf
- LITEOS_HIETH_SF_INCLUDE += -I $(LITEOS_VENDOR_DRIVERS_BASE_PATH)/hieth-sf/include
-endif
-
ifeq ($(LOSCFG_DRIVERS_TZDRIVER), y)
LITEOS_BASELIB += -ltzdriver -lmbedtls
LIB_SUBDIRS += $(LITEOS_DRIVERS_BASE_PATH)/tzdriver $(LITEOSTOPDIR)/lib/libmbedtls
@@ -394,36 +393,20 @@ endif
ifeq ($(LOSCFG_DRIVERS_MEM), y)
LITEOS_BASELIB += -lmem
- LIB_SUBDIRS += $(LITEOS_DRIVERS_BASE_PATH)/mem
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/mem
+ LITEOS_DEV_MEM_INCLUDE = -I $(LITEOSTOPDIR)/drivers/char/mem/include
endif
-ifeq ($(LOSCFG_DRIVERS_MMC), y)
- MMC_HOST_DIR := himci
- LITEOS_BASELIB += -lmmc
- LITEOS_MMC_INCLUDE += -I $(LITEOS_VENDOR_DRIVERS_BASE_PATH)/mmc/include
-endif
-
-ifeq ($(LOSCFG_DRIVERS_MTD), y)
- LITEOS_BASELIB += -lmtd_common
- LITEOS_MTD_SPI_NOR_INCLUDE += -I $(LITEOS_VENDOR_DRIVERS_BASE_PATH)/mtd/common/include
-
- ifeq ($(LOSCFG_DRIVERS_MTD_SPI_NOR), y)
- ifeq ($(LOSCFG_DRIVERS_MTD_SPI_NOR_HISFC350), y)
- NOR_DRIVER_DIR := hisfc350
- else ifeq ($(LOSCFG_DRIVERS_MTD_SPI_NOR_HIFMC100), y)
- NOR_DRIVER_DIR := hifmc100
- endif
-
- LITEOS_BASELIB += -lspinor_flash
- LITEOS_MTD_SPI_NOR_INCLUDE += -I $(LITEOS_VENDOR_DRIVERS_BASE_PATH)/mtd/spi_nor/include
-
- endif
+ifeq ($(LOSCFG_QUICK_START), y)
+ LITEOS_BASELIB += -lquickstart
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/quickstart
+ LITEOS_QUICK_START_INCLUDE = -I $(LITEOSTOPDIR)/drivers/char/quickstart/include
endif
ifeq ($(LOSCFG_DRIVERS_RANDOM), y)
LITEOS_BASELIB += -lrandom
- LIB_SUBDIRS += $(LITEOS_DRIVERS_BASE_PATH)/random
- LITEOS_RANDOM_INCLUDE += -I $(LITEOS_DRIVERS_BASE_PATH)/random/include
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/random
+ LITEOS_RANDOM_INCLUDE += -I $(LITEOSTOPDIR)/drivers/char/random/include
endif
ifeq ($(LOSCFG_DRIVERS_USB), y)
@@ -437,7 +420,7 @@ endif
ifeq ($(LOSCFG_DRIVERS_VIDEO), y)
LITEOS_BASELIB += -lvideo
- LIB_SUBDIRS += $(LITEOS_DRIVERS_BASE_PATH)/video
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/video
LITEOS_VIDEO_INCLUDE += -I $(LITEOSTOPDIR)/../../third_party/NuttX/include/nuttx/video
endif
@@ -446,8 +429,9 @@ endif
############################## Dfx Option Begin#######################################
ifeq ($(LOSCFG_BASE_CORE_HILOG), y)
LITEOS_BASELIB += -lhilog
- LIB_SUBDIRS += $(LITEOSTOPDIR)/../../base/hiviewdfx/frameworks/hilog_lite/featured
- LITEOS_HILOG_INCLUDE += -I $(LITEOSTOPDIR)/../../base/hiviewdfx/interfaces/kits/hilog
+ LIB_SUBDIRS += $(LITEOSTOPDIR)/../../base/hiviewdfx/hilog_lite/frameworks/featured
+ LITEOS_HILOG_INCLUDE += -I $(LITEOSTOPDIR)/../../base/hiviewdfx/hilog_lite/interfaces/native/kits
+ LITEOS_HILOG_INCLUDE += -I $(LITEOSTOPDIR)/../../base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog
LITEOS_CMACRO += -DLOSCFG_BASE_CORE_HILOG
endif
############################## Dfx Option End #######################################
@@ -539,7 +523,7 @@ endif
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
ifeq ($(LITEOS_COMPILER_PATH),)
-LITEOS_COMPILER_PATH := $(shell $(LITEOSTOPDIR)/tools/build/mk/get_llvm_compiler_path.sh $(CROSS_COMPILE) $(LITEOSTOPDIR))
+LITEOS_COMPILER_PATH := $(shell $(LITEOSTOPDIR)/tools/build/mk/get_llvm_compiler_path.sh "$(CROSS_COMPILE)" "$(LITEOSTOPDIR)")
export LITEOS_COMPILER_PATH
endif
CC = $(LITEOS_COMPILER_PATH)/bin/clang
@@ -561,7 +545,7 @@ LLVM_EXTRA_OPTS := -target $(LLVM_TARGET) -fms-extensions -Wno-address-of-packed
LLVM_EXTRA_LD_OPTS := -fuse-ld=lld --rtlib=compiler-rt
else
ifeq ($(LITEOS_COMPILER_PATH),)
-LITEOS_COMPILER_PATH := $(shell $(LITEOSTOPDIR)/tools/build/mk/get_compiler_path.sh $(CROSS_COMPILE) $(LITEOSTOPDIR))
+LITEOS_COMPILER_PATH := $(shell $(LITEOSTOPDIR)/tools/build/mk/get_compiler_path.sh "$(CROSS_COMPILE)" "$(LITEOSTOPDIR)")
export LITEOS_COMPILER_PATH
endif
CC = $(LITEOS_COMPILER_PATH)/bin/$(CROSS_COMPILE)gcc
@@ -591,10 +575,6 @@ else ifeq ($(LOSCFG_COMPILER_HIMIX_32), y)
LITEOS_COMPILER_CXXLIB_PATH = $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib
LITEOS_COMPILER_GCCLIB_PATH = $(LITEOS_COMPILER_PATH)/lib/gcc/$(COMPILE_NAME)/$(VERSION_NUM)
LITEOS_COMPILER_GCC_INCLUDE = -I $(LITEOS_COMPILER_PATH)/lib/gcc/arm-linux-ohoseabi/$(VERSION_NUM)/include
-else ifeq ($(LOSCFG_COMPILER_HIMIX100_64), y)
-LITEOS_COMPILER_CXXLIB_PATH = $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib64
-LITEOS_COMPILER_GCCLIB_PATH = $(LITEOS_COMPILER_PATH)/lib/gcc/$(COMPILE_NAME)/$(VERSION_NUM)
-LITEOS_COMPILER_GCC_INCLUDE = -I $(LITEOS_COMPILER_PATH)/lib/gcc/aarch64-linux-android/$(VERSION_NUM)/include
else ifeq ($(LOSCFG_COMPILER_HCC_64), y)
LITEOS_COMPILER_CXXLIB_PATH = $(LITEOS_COMPILER_PATH)/$(COMPILE_NAME)/lib64
LITEOS_COMPILER_GCCLIB_PATH = $(LITEOS_COMPILER_PATH)/lib64/gcc/$(COMPILE_NAME)/$(VERSION_NUM)
@@ -620,11 +600,6 @@ ifeq ($(LOSCFG_COMPILER_HIMIX_32), y)
-I $(LITEOS_COMPILER_CXX_PATH)/c++/$(VERSION_NUM)/arm-linux-ohoseabi
LITEOS_CXXMACRO += -DLOSCFG_KERNEL_CPP_EXCEPTIONS_SUPPORT
LITEOS_CMACRO += -DLOSCFG_KERNEL_CPP_EXCEPTIONS_SUPPORT
-else ifeq ($(LOSCFG_COMPILER_HIMIX100_64), y)
- LITEOS_CXXINCLUDE += \
- -I $(LITEOS_COMPILER_CXX_PATH)/c++/$(VERSION_NUM)/aarch64-linux-android
- LITEOS_CXXMACRO += -DLOSCFG_KERNEL_CPP_EXCEPTIONS_SUPPORT
- LITEOS_CMACRO += -DLOSCFG_KERNEL_CPP_EXCEPTIONS_SUPPORT
else ifeq ($(LOSCFG_COMPILER_HCC_64), y)
LITEOS_CXXINCLUDE += \
-I $(LITEOS_COMPILER_CXX_PATH)/c++/$(VERSION_NUM)/aarch64-linux-gnu
@@ -656,14 +631,15 @@ LITEOS_DRIVERS_INCLUDE := $(LITEOS_CELLWISE_INCLUDE) $(LITEOS_GPIO_INCLUDE
$(LITEOS_HIDMAC_INCLUDE) $(LITEOS_HIETH_SF_INCLUDE) \
$(LITEOS_HIGMAC_INCLUDE) $(LITEOS_I2C_INCLUDE) \
$(LITEOS_LCD_INCLUDE) $(LITEOS_MMC_INCLUDE) \
- $(LITEOS_MTD_SPI_NOR_INCLUDE) \
+ $(LITEOS_MTD_SPI_NOR_INCLUDE) $(LITEOS_MTD_NAND_INCLUDE) \
$(LITEOS_RANDOM_INCLUDE) $(LITEOS_RTC_INCLUDE) \
$(LITEOS_SPI_INCLUDE) $(LITEOS_USB_INCLUDE) \
$(LITEOS_WTDG_INCLUDE) $(LITEOS_DBASE_INCLUDE) \
$(LITEOS_CPUFREQ_INCLUDE) $(LITEOS_DEVFREQ_INCLUDE) \
$(LITEOS_REGULATOR_INCLUDE) $(LITEOS_VIDEO_INCLUDE) \
$(LITEOS_DRIVERS_HDF_INCLUDE) $(LITEOS_TZDRIVER_INCLUDE) \
- $(LITEOS_HIEVENT_INCLUDE)
+ $(LITEOS_HIEVENT_INCLUDE) $(LITEOS_DEV_MEM_INCLUDE) \
+ $(LITEOS_QUICK_START_INCLUDE)
LITEOS_DFX_INCLUDE := $(LITEOS_HILOG_INCLUDE)
LITEOS_SECURITY_INCLUDE := $(LITEOS_SECURITY_CAP_INC) $(LITEOS_SECURITY_VID_INC)
@@ -686,7 +662,7 @@ endif
endif
LITEOS_COPTS_EXTRA += -fno-short-enums
ifeq ($(LOSCFG_THUMB), y)
-LITEOS_COPTS_EXTRA_INTERWORK := $(LITEOS_COPTS_EXTRA) -mthumb
+LITEOS_COPTS_EXTRA_INTERWORK := $(LITEOS_COPTS_EXTRA) -mthumb -Wa,-mimplicit-it=thumb
LITEOS_CMACRO += -DLOSCFG_INTERWORK_THUMB
else
LITEOS_COPTS_EXTRA_INTERWORK := $(LITEOS_COPTS_EXTRA)
@@ -713,7 +689,9 @@ endif
# temporary
LITEOS_PLATFORM_INCLUDE += \
- -I $(LITEOSTOPDIR)/kernel/base/include
+ -I $(LITEOSTOPDIR)/kernel/base/include \
+ -I $(LITEOSTOPDIR)/kernel/extended/include
+
LITEOS_CXXINCLUDE += \
$(LITEOS_NET_INCLUDE) \
-I $(LITEOSTOPDIR)/kernel/base/include
diff --git a/tools/build/mk/module.mk b/tools/build/mk/module.mk
old mode 100644
new mode 100755
index e8916568..5152c6a6
--- a/tools/build/mk/module.mk
+++ b/tools/build/mk/module.mk
@@ -1,5 +1,5 @@
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/fsimage/MakeVersion.sh b/tools/fsimage/MakeVersion.sh
index 97302ca9..712d1a11 100755
--- a/tools/fsimage/MakeVersion.sh
+++ b/tools/fsimage/MakeVersion.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/fsimage/win-x86/cygz.dll b/tools/fsimage/win-x86/cygz.dll
new file mode 100755
index 00000000..038e660c
Binary files /dev/null and b/tools/fsimage/win-x86/cygz.dll differ
diff --git a/tools/fsimage/win-x86/doc_loadbios.exe b/tools/fsimage/win-x86/doc_loadbios.exe
new file mode 100755
index 00000000..958619ea
Binary files /dev/null and b/tools/fsimage/win-x86/doc_loadbios.exe differ
diff --git a/tools/fsimage/win-x86/docfdisk.exe b/tools/fsimage/win-x86/docfdisk.exe
new file mode 100755
index 00000000..d161fd00
Binary files /dev/null and b/tools/fsimage/win-x86/docfdisk.exe differ
diff --git a/tools/fsimage/win-x86/flash_erase.exe b/tools/fsimage/win-x86/flash_erase.exe
new file mode 100755
index 00000000..b6e4241a
Binary files /dev/null and b/tools/fsimage/win-x86/flash_erase.exe differ
diff --git a/tools/fsimage/win-x86/flash_eraseall b/tools/fsimage/win-x86/flash_eraseall
new file mode 100755
index 00000000..c5539b3a
--- /dev/null
+++ b/tools/fsimage/win-x86/flash_eraseall
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
diff --git a/tools/fsimage/win-x86/flash_lock.exe b/tools/fsimage/win-x86/flash_lock.exe
new file mode 100755
index 00000000..9b1735d5
Binary files /dev/null and b/tools/fsimage/win-x86/flash_lock.exe differ
diff --git a/tools/fsimage/win-x86/flash_otp_dump.exe b/tools/fsimage/win-x86/flash_otp_dump.exe
new file mode 100755
index 00000000..d9f2ce5a
Binary files /dev/null and b/tools/fsimage/win-x86/flash_otp_dump.exe differ
diff --git a/tools/fsimage/win-x86/flash_otp_info.exe b/tools/fsimage/win-x86/flash_otp_info.exe
new file mode 100755
index 00000000..2288b2bf
Binary files /dev/null and b/tools/fsimage/win-x86/flash_otp_info.exe differ
diff --git a/tools/fsimage/win-x86/flash_otp_lock.exe b/tools/fsimage/win-x86/flash_otp_lock.exe
new file mode 100755
index 00000000..91389cd2
Binary files /dev/null and b/tools/fsimage/win-x86/flash_otp_lock.exe differ
diff --git a/tools/fsimage/win-x86/flash_otp_write.exe b/tools/fsimage/win-x86/flash_otp_write.exe
new file mode 100755
index 00000000..9b71e60f
Binary files /dev/null and b/tools/fsimage/win-x86/flash_otp_write.exe differ
diff --git a/tools/fsimage/win-x86/flash_unlock.exe b/tools/fsimage/win-x86/flash_unlock.exe
new file mode 100755
index 00000000..ec4095ad
Binary files /dev/null and b/tools/fsimage/win-x86/flash_unlock.exe differ
diff --git a/tools/fsimage/win-x86/flashcp.exe b/tools/fsimage/win-x86/flashcp.exe
new file mode 100755
index 00000000..936e6cab
Binary files /dev/null and b/tools/fsimage/win-x86/flashcp.exe differ
diff --git a/tools/fsimage/win-x86/ftl_check.exe b/tools/fsimage/win-x86/ftl_check.exe
new file mode 100755
index 00000000..ce6008de
Binary files /dev/null and b/tools/fsimage/win-x86/ftl_check.exe differ
diff --git a/tools/fsimage/win-x86/ftl_format.exe b/tools/fsimage/win-x86/ftl_format.exe
new file mode 100755
index 00000000..964da5fb
Binary files /dev/null and b/tools/fsimage/win-x86/ftl_format.exe differ
diff --git a/tools/fsimage/win-x86/jffs2dump.exe b/tools/fsimage/win-x86/jffs2dump.exe
new file mode 100755
index 00000000..fedd81fe
Binary files /dev/null and b/tools/fsimage/win-x86/jffs2dump.exe differ
diff --git a/tools/fsimage/win-x86/jffs2reader.exe b/tools/fsimage/win-x86/jffs2reader.exe
new file mode 100755
index 00000000..ecd15f9d
Binary files /dev/null and b/tools/fsimage/win-x86/jffs2reader.exe differ
diff --git a/tools/fsimage/win-x86/lsmtd.exe b/tools/fsimage/win-x86/lsmtd.exe
new file mode 100755
index 00000000..b5fc9219
Binary files /dev/null and b/tools/fsimage/win-x86/lsmtd.exe differ
diff --git a/tools/fsimage/win-x86/mkfs.jffs2.exe b/tools/fsimage/win-x86/mkfs.jffs2.exe
new file mode 100755
index 00000000..70c466be
Binary files /dev/null and b/tools/fsimage/win-x86/mkfs.jffs2.exe differ
diff --git a/tools/fsimage/win-x86/mtd_debug.exe b/tools/fsimage/win-x86/mtd_debug.exe
new file mode 100755
index 00000000..8e2054dd
Binary files /dev/null and b/tools/fsimage/win-x86/mtd_debug.exe differ
diff --git a/tools/fsimage/win-x86/mtdinfo.exe b/tools/fsimage/win-x86/mtdinfo.exe
new file mode 100755
index 00000000..67b5af4b
Binary files /dev/null and b/tools/fsimage/win-x86/mtdinfo.exe differ
diff --git a/tools/fsimage/win-x86/mtdpart.exe b/tools/fsimage/win-x86/mtdpart.exe
new file mode 100755
index 00000000..a5ea67e8
Binary files /dev/null and b/tools/fsimage/win-x86/mtdpart.exe differ
diff --git a/tools/fsimage/win-x86/nanddump.exe b/tools/fsimage/win-x86/nanddump.exe
new file mode 100755
index 00000000..dc1f1a30
Binary files /dev/null and b/tools/fsimage/win-x86/nanddump.exe differ
diff --git a/tools/fsimage/win-x86/nandtest.exe b/tools/fsimage/win-x86/nandtest.exe
new file mode 100755
index 00000000..7278aee4
Binary files /dev/null and b/tools/fsimage/win-x86/nandtest.exe differ
diff --git a/tools/fsimage/win-x86/nandwrite.exe b/tools/fsimage/win-x86/nandwrite.exe
new file mode 100755
index 00000000..8a47b582
Binary files /dev/null and b/tools/fsimage/win-x86/nandwrite.exe differ
diff --git a/tools/fsimage/win-x86/nftl_format.exe b/tools/fsimage/win-x86/nftl_format.exe
new file mode 100755
index 00000000..b35e83c9
Binary files /dev/null and b/tools/fsimage/win-x86/nftl_format.exe differ
diff --git a/tools/fsimage/win-x86/nftldump.exe b/tools/fsimage/win-x86/nftldump.exe
new file mode 100755
index 00000000..4d5acd08
Binary files /dev/null and b/tools/fsimage/win-x86/nftldump.exe differ
diff --git a/tools/fsimage/win-x86/recv_image.exe b/tools/fsimage/win-x86/recv_image.exe
new file mode 100755
index 00000000..d52fdbd7
Binary files /dev/null and b/tools/fsimage/win-x86/recv_image.exe differ
diff --git a/tools/fsimage/win-x86/rfddump.exe b/tools/fsimage/win-x86/rfddump.exe
new file mode 100755
index 00000000..85e784c9
Binary files /dev/null and b/tools/fsimage/win-x86/rfddump.exe differ
diff --git a/tools/fsimage/win-x86/rfdformat.exe b/tools/fsimage/win-x86/rfdformat.exe
new file mode 100755
index 00000000..99ddbc8c
Binary files /dev/null and b/tools/fsimage/win-x86/rfdformat.exe differ
diff --git a/tools/fsimage/win-x86/serve_image.exe b/tools/fsimage/win-x86/serve_image.exe
new file mode 100755
index 00000000..7b978f69
Binary files /dev/null and b/tools/fsimage/win-x86/serve_image.exe differ
diff --git a/tools/fsimage/win-x86/sumtool.exe b/tools/fsimage/win-x86/sumtool.exe
new file mode 100755
index 00000000..8e0be798
Binary files /dev/null and b/tools/fsimage/win-x86/sumtool.exe differ
diff --git a/tools/fsimage/win-x86/ubiattach.exe b/tools/fsimage/win-x86/ubiattach.exe
new file mode 100755
index 00000000..a58d7acd
Binary files /dev/null and b/tools/fsimage/win-x86/ubiattach.exe differ
diff --git a/tools/fsimage/win-x86/ubiblock.exe b/tools/fsimage/win-x86/ubiblock.exe
new file mode 100755
index 00000000..aa1e0671
Binary files /dev/null and b/tools/fsimage/win-x86/ubiblock.exe differ
diff --git a/tools/fsimage/win-x86/ubicrc32.exe b/tools/fsimage/win-x86/ubicrc32.exe
new file mode 100755
index 00000000..b3411090
Binary files /dev/null and b/tools/fsimage/win-x86/ubicrc32.exe differ
diff --git a/tools/fsimage/win-x86/ubidetach.exe b/tools/fsimage/win-x86/ubidetach.exe
new file mode 100755
index 00000000..d6e28b65
Binary files /dev/null and b/tools/fsimage/win-x86/ubidetach.exe differ
diff --git a/tools/fsimage/win-x86/ubiformat.exe b/tools/fsimage/win-x86/ubiformat.exe
new file mode 100755
index 00000000..c016684f
Binary files /dev/null and b/tools/fsimage/win-x86/ubiformat.exe differ
diff --git a/tools/fsimage/win-x86/ubimkvol.exe b/tools/fsimage/win-x86/ubimkvol.exe
new file mode 100755
index 00000000..28bf595c
Binary files /dev/null and b/tools/fsimage/win-x86/ubimkvol.exe differ
diff --git a/tools/fsimage/win-x86/ubinfo.exe b/tools/fsimage/win-x86/ubinfo.exe
new file mode 100755
index 00000000..563158ed
Binary files /dev/null and b/tools/fsimage/win-x86/ubinfo.exe differ
diff --git a/tools/fsimage/win-x86/ubinize.exe b/tools/fsimage/win-x86/ubinize.exe
new file mode 100755
index 00000000..c56a7d6d
Binary files /dev/null and b/tools/fsimage/win-x86/ubinize.exe differ
diff --git a/tools/fsimage/win-x86/ubirename.exe b/tools/fsimage/win-x86/ubirename.exe
new file mode 100755
index 00000000..d783cf47
Binary files /dev/null and b/tools/fsimage/win-x86/ubirename.exe differ
diff --git a/tools/fsimage/win-x86/ubirmvol.exe b/tools/fsimage/win-x86/ubirmvol.exe
new file mode 100755
index 00000000..9610c987
Binary files /dev/null and b/tools/fsimage/win-x86/ubirmvol.exe differ
diff --git a/tools/fsimage/win-x86/ubirsvol.exe b/tools/fsimage/win-x86/ubirsvol.exe
new file mode 100755
index 00000000..c3d8febc
Binary files /dev/null and b/tools/fsimage/win-x86/ubirsvol.exe differ
diff --git a/tools/fsimage/win-x86/ubiupdatevol.exe b/tools/fsimage/win-x86/ubiupdatevol.exe
new file mode 100755
index 00000000..993123f0
Binary files /dev/null and b/tools/fsimage/win-x86/ubiupdatevol.exe differ
diff --git a/tools/scripts/make_rootfs/releaseinfo.sh b/tools/scripts/make_rootfs/releaseinfo.sh
index 1aab55d7..65c0cdd8 100755
--- a/tools/scripts/make_rootfs/releaseinfo.sh
+++ b/tools/scripts/make_rootfs/releaseinfo.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/scripts/make_rootfs/rootfs.sh b/tools/scripts/make_rootfs/rootfs.sh
index cae9c03c..e1c46223 100755
--- a/tools/scripts/make_rootfs/rootfs.sh
+++ b/tools/scripts/make_rootfs/rootfs.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/scripts/make_rootfs/rootfsdir.sh b/tools/scripts/make_rootfs/rootfsdir.sh
index 13f81320..fe46c91f 100755
--- a/tools/scripts/make_rootfs/rootfsdir.sh
+++ b/tools/scripts/make_rootfs/rootfsdir.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
diff --git a/tools/scripts/make_rootfs/rootfsimg.sh b/tools/scripts/make_rootfs/rootfsimg.sh
index a733d6bb..25b25daf 100755
--- a/tools/scripts/make_rootfs/rootfsimg.sh
+++ b/tools/scripts/make_rootfs/rootfsimg.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
-# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+# 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:
@@ -33,9 +33,10 @@ set -e
system=$(uname -s)
ROOTFS_DIR=$1
FSTYPE=$2
-ROOTFS_IMG=${ROOTFS_DIR}".img"
+ROOTFS_IMG=${ROOTFS_DIR}"_"${FSTYPE}".img"
JFFS2_TOOL=mkfs.jffs2
WIN_JFFS2_TOOL=mkfs.jffs2.exe
+YAFFS2_TOOL=mkyaffs2image100
VFAT_TOOL=mkfs.vfat
MCOPY_TOOL=mcopy
@@ -43,7 +44,7 @@ tool_check() {
local ret='0'
command -v "$1" >/dev/null 2>&1 || { local ret='1'; }
if [ "$ret" -ne 0 ]; then
- echo "$1 tool is not exist, please install it" >&2
+ echo "$1 tool is not exit, please install it" >&2
fi
return 0
}
@@ -64,6 +65,9 @@ if [ "${FSTYPE}" = "jffs2" ]; then
tool_check ${JFFS2_TOOL}
${JFFS2_TOOL} -q -o ${ROOTFS_IMG} -d ${ROOTFS_DIR} --pagesize=4096
fi
+elif [ "${FSTYPE}" = "yaffs2" ]; then
+ tool_check ${YAFFS2_TOOL}
+ ${YAFFS2_TOOL} ${ROOTFS_DIR} ${ROOTFS_IMG} 2k 24bit
elif [ "${FSTYPE}" = "vfat" ]; then
if [ "${system}" != "Linux" ] ; then
echo "Unsupported fs type!" >&2