diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md
deleted file mode 100755
index f09d98dde9597de75ffcdb237c2b580b8fffa3f9..0000000000000000000000000000000000000000
--- 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 100755
index 33948fdcb51264545ce5ae797f5310a1c06f871d..0000000000000000000000000000000000000000
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### 相关的Issue
-
-
-### 原因(目的、解决的问题等)
-
-
-### 描述(做了什么,变更了什么)
-
-
-### 测试用例(新增、改动、可能影响的功能)
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
old mode 100755
new mode 100644
index cf00b53065085c1ce9fa1f91f6c0a2ace9803e7f..77dbb6a9907fa0834c076ac8e7b081d22840a628
--- 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
index a7e30ac37004b50e47234bcd37a57aba6947243d..ad48b1216bade8fa5935fb363c0606b81d9edee5 100755
--- 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
index 522800bd2e11be2a7ba428734b7e985dac8c886a..77380a272b92b7590b88f3e7cfb5aaa49fd84cc3 100755
--- 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:
@@ -42,11 +42,11 @@ choice
config COMPILER_HIMIX_32
bool "arm-linux-ohoseabi"
- depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300
+ depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7
config COMPILER_CLANG_LLVM
bool "clang-llvm"
- depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300
+ depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7
endchoice
endmenu
@@ -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"
@@ -274,23 +268,10 @@ config VM_OVERLAP_CHECK
config NULL_ADDRESS_PROTECT
bool "Enable NULL Address protect"
default n
- depends on (PLATFORM_HI3518EV200 || PLATFORM_HI3516CV300 || PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300) && DEBUG_VERSION
+ depends on (PLATFORM_HI3518EV200 || PLATFORM_HI3516CV300 || PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7) && DEBUG_VERSION
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"
-
-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 "../../drivers/adapter/khdf/liteos/Kconfig"
-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 61fa69e3906c43870779e2c98903e447c8d86f73..208b4cd3556ada5a8fa98bcf0fade1795fa982c6 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
index 673c0988207dcafe01280a0ca7e87bf50c8b5cc0..27dda5e627e6ae98464894eacaf9e1ccd2cf86ae 100755
--- 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,12 +51,34 @@ 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 = jffs2
+endif
ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip
VERSION =
@@ -103,8 +123,8 @@ $(__LIBS): $(OUT) $(CXX_INCLUDE)
$(OUT): $(LITEOS_MENUCONFIG_H)
$(HIDE)mkdir -p $(OUT)/lib
- $(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board \
- -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):
@@ -117,15 +137,12 @@ $(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)
-mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H)
##### menuconfig end #######
@@ -165,15 +182,16 @@ endif
$(ROOTFSDIR): prepare $(APPS)
$(HIDE)$(MAKE) clean -C apps
- $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR))
+ $(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR)
ifneq ($(VERSION),)
- $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR))
+ $(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR)
endif
$(ROOTFS): $(ROOTFSDIR)
- $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE))
+ $(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
@@ -182,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
@@ -199,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 0000000000000000000000000000000000000000..7997be41716882bbd690bb0de8f7bc51f41735f5
--- /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 0000000000000000000000000000000000000000..61bcf07307d427506fa6c622e9413b2ffd740020
--- /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
index e5857242c98fd1487eb44350bc36c1ad427094f0..631b955cf9701268b5048c7dc123629296263c63 100755
--- 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
index 8e4c95f9508efe3bcf374ae634377380c9c86a60..5f6efe06d4d1f2c572a05a9c4fb578f781c107b0 100755
--- 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
index 82017e7e6cad05beb8bd124c21c795757f33adeb..96eba811382793af81db1ebad894e6b0877440e1 100755
--- 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
index 882219df6f2f58210942b61e5cc4a55d94426804..7cab38a83105451745031a4b2e9446aea53b0c24 100755
--- 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
index 1cd7ae1164c004b2db132b9777eab6631d6feca7..520f339354222e8a2d52632fb78b249aa9e0ee40 100755
--- 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
index 857cb1367216a2927e0a44b62692d2ce2686c0df..23024cac865c6f7d453e7169569c006879fa3ff9 100755
--- 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
index 56d6897e3df557dec7456374a0db53acd864b046..6fdd41d36c99730306c6b965bd4b2f8d8c04203e 100755
--- 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
index d664a4bd8ff4d3060aec0799257a2779b0bc59b2..f5485a2a9278c3624ca2c64f01eb30d66b1130fd 100755
--- 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
old mode 100755
new mode 100644
index e3206220497e6c6fb41fe1be81847f1b878cd8ba..a6ec619732885be889efd3fbddad34933dbcd30d
--- 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
index 48fa3093b772b2c16da350dec6f7d008909447af..d23b9e1b056584ad54e29e5cb7de257e8c7ba5de 100755
--- 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
old mode 100755
new mode 100644
index 91b5bbd33f2119d11fb5210129c8a0d8709b8b24..020c1711d8063a129970fd34b69fa287e2567276
--- 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
old mode 100755
new mode 100644
index b8e75c1c641856c55b7d9699b812ff9e4b0bc481..8e5ab6f6458a49b5c1f1b909385c3a47fa98aac4
--- 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
old mode 100755
new mode 100644
index 6122fd2c4efb3f4ab575b22cf3768878601b8e74..a560a740721eacc0e928eca02c55056ab903e5af
--- 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
index fb683559799550cf088b331a18b0c316d93fc04b..ee90ec6c858f7f2995351cfa4b8d0dd1b5023b41 100755
--- 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
index 95c56b125e0967065c07fb865bf553719bbce44f..2bb9486576fafd7ddfa35c212d379799a0ddedca 100755
--- 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
index 54c0bf9fdc10cfae4582608e1ce9b23adbd176b7..ef57ca00b1fef7321dc3a278c055f725a79aee72 100755
--- 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
index 06845ac8e3c409d9a2b9decaf083594a4a6918b0..a4930a902a9abac2277a21a67b8d920e426b2f68 100755
--- 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
index 1a9bc75e1b96e435dcd6d70976fb240bbb9ff3eb..978917475d4c7e992d5fe78f6951030adbc46b98 100755
--- 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
index a10b4c8058024a3b8e2d543696ab260892ca97bb..d8c17c09a7f08847f63e3746f69f863598226f67 100755
--- 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));
diff --git a/apps/tftp/Makefile b/apps/tftp/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..37cf594c1123840299d5eabc0bdb9f121c02236b
--- /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/apps/tftp/include/tftpc.h b/apps/tftp/include/tftpc.h
new file mode 100644
index 0000000000000000000000000000000000000000..3d0bf568ced68334ff1fd33f8f6d55bf5bbc7074
--- /dev/null
+++ b/apps/tftp/include/tftpc.h
@@ -0,0 +1,309 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 TFTPC_H
+#define TFTPC_H
+
+#include "types_adapt.h"
+
+#if LWIP_TFTP /* don't build if not configured for use in lwipopts.h */
+
+#if defined (__cplusplus) && __cplusplus
+extern "C" {
+#endif
+
+#define TFTP_NULL_UINT32 ((u32_t)0xffffffffUL)
+
+#define TFTP_NULL_INT32 -1
+
+/** @cond liteos
+* @defgroup TFTP_Interfaces
+* @ingroup Enums
+* * This section contains the TFTP enums.
+*/
+/**
+*
+* This Enum is used to specify the transfer mode of the file to be handled by TFTP client.
+*/
+typedef enum tagTFTPC_TransferMode {
+ TRANSFER_MODE_ASCII = 0, /**< Indicates that the mode of transfer is ASCII. */
+ TRANSFER_MODE_BINARY, /**< Indicates that the mode of transfer is Binary */
+ TRANSFER_MODE_BUTT /**< Indicates invalid transfer mode.*/
+} TFTPC_TRANSFER_MODE_E;
+
+/**
+* This Enum is used to specify the transfer mode to be handled by TFTP client
+* This Enum indicates the TFTP client transfer mode of the file
+
+*/
+typedef enum tagTFTPC_ErrCode {
+ TFTPC_SOCKET_FAILURE = 1, /**< Error while creating UDP socket. */
+ TFTPC_BIND_FAILURE = 2, /**< Error while binding to the UDP socket. */
+ TFTPC_SELECT_ERROR = 3, /**< Error returned by select() system call. */
+ TFTPC_RECVFROM_ERROR = 4, /**< Error while receiving data from the peer. */
+ TFTPC_SENDTO_ERROR = 5, /**< Error while sending data to the peer. */
+ TFTPC_FILE_NOT_FOUND = 6, /**< Requested file is not found. */
+
+ /**< This is the error sent by the server when host name cannot be resolved. */
+ TFTPC_CANNOT_RESOLVE_HOSTNAME = 7,
+ TFTPC_INVALID_PARAVALUE = 8, /**< Input parameters passed to TFTP interfaces are invalid. */
+
+ /**< Error detected in TFTP packet or the error received from the TFTP server. */
+ TFTPC_PROTO_ERROR = 9,
+ /**< Error during packet synchronization while sending or unexpected packet is received. */
+ TFTPC_SYNC_FAILURE = 10,
+ /**< File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes. */
+ TFTPC_FILE_TOO_BIG = 11,
+ TFTPC_SRC_FILENAME_LENGTH_ERROR = 12, /**< File name length greater than 256. */
+ TFTPC_IP_NOT_WITHIN_RANGE = 13, /**< Host name IP is not valid. */
+ TFTPC_ACCESS_ERROR = 14, /**< TFTP server returned file access error. */
+
+ /**< TFTP server returned error signifying that the DISK is full to write. */
+ TFTPC_DISK_FULL = 15,
+ TFTPC_FILE_EXISTS = 16, /**< TFTP server returned error signifying that the file exists. */
+
+ /**< tftp_put_file_by_filename returned error signifying that the source file name do not exist. */
+ TFTPC_FILE_NOT_EXIST = 17,
+ TFTPC_MEMALLOC_ERROR = 18, /**< Memory allocation failed in TFTP client. */
+ TFTPC_FILEOPEN_ERROR = 19, /**< File open failed. */
+ TFTPC_FILEREAD_ERROR = 20, /**< File read error. */
+ TFTPC_FILECREATE_ERROR = 21, /**< File create error. */
+ TFTPC_FILEWRITE_ERROR = 22, /**< File write error. */
+ TFTPC_TIMEOUT_ERROR = 23, /**< Max time expired while waiting for file to be received. */
+
+ /**< Error when the received packet is less than 4 bytes (error length) or greater than 512 bytes. */
+ TFTPC_PKT_SIZE_ERROR = 24,
+ TFTPC_ERROR_NOT_DEFINED = 25, /**< Returned by TFTP server for protocol user error. */
+ TFTPC_DEST_PATH_LENGTH_ERROR = 26, /**< If the destination file path length is greater than 256. */
+ TFTPC_UNKNOWN_TRANSFER_ID = 27, /**< Returned by TFTP server for undefined transfer ID. */
+
+ /**< IOCTL function failed at TFTP client while setting the socket to non-block. */
+ TFTPC_IOCTLSOCKET_FAILURE = 28,
+ TFTPC_MEMCPY_FAILURE = 29 /**< TFTP memcpy failure. */
+} TFTPC_ERR_CODE_E;
+
+typedef enum tagTFTPC_OpCode {
+ TFTPC_OP_RRQ = 1, /* read request */
+ TFTPC_OP_WRQ, /* write request */
+ TFTPC_OP_DATA, /* data packet */
+ TFTPC_OP_ACK, /* acknowledgement */
+ TFTPC_OP_ERROR, /* error code */
+ TFTPC_OP_OPT /* option code */
+} TFTPC_OPCODE_E;
+
+typedef enum tagTFTPC_PROTOCOL_ErrCode {
+ TFTPC_PROTOCOL_USER_DEFINED = 0,
+ TFTPC_PROTOCOL_FILE_NOT_FOUND,
+ TFTPC_PROTOCOL_ACCESS_ERROR,
+ TFTPC_PROTOCOL_DISK_FULL,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ TFTPC_PROTOCOL_UNKNOWN_TRANSFER_ID,
+ TFTPC_PROTOCOL_FILE_EXISTS,
+ TFTPC_PROTOCOL_CANNOT_RESOLVE_HOSTNAME
+} TFTPC_PROT_ERRCODE_E;
+
+
+#ifndef TFTPC_MAX_SEND_REQ_ATTEMPTS
+#define TFTPC_MAX_SEND_REQ_ATTEMPTS 5 /* tftp max attempts */
+#endif
+
+#ifndef TFTPC_TIMEOUT_PERIOD
+#define TFTPC_TIMEOUT_PERIOD 5 /* tftp timeout period,unit :s */
+#endif
+
+#define TFTPC_SERVER_PORT 69 /* tftp server well known port no. */
+
+/* MAX file size in TFTP is 32 MB.
+ Reason for keeping 75 here , is ((75*512=38400bytes)/1024) = 37MB. So the recv/Send Loop can
+ receive the complete MAX message from the network
+*/
+#define TFTPC_MAX_WAIT_IN_LOOP 75
+
+#define TFTP_BLKSIZE 512 /* data block size (IEN-133) */
+#define TFTP_HDRSIZE 4 /* TFTP header size */
+#define TFTP_PKTSIZE (TFTP_BLKSIZE + TFTP_HDRSIZE) /* Packet size */
+#define TFTP_MAX_MODE_SIZE 9 /* max size of mode string */
+#define TFTP_MAXERRSTRSIZE 100 /* max size of error message string */
+#define TFTP_MAX_PATH_LENGTH 256 /* Max path or filename length */
+#define TFTP_MAX_BLK_NUM (0xFFFFL) /* MAximum block number */
+
+/* IP address not including reserved IPs(0 and 127) and multicast addresses(Class D) */
+#define TFTPC_IP_ADDR_MIN 0x01000000
+#define TFTPC_IP_ADDR_EX_RESV 0x7effffff
+#define TFTPC_IP_ADDR_CLASS_B 0x80000000
+#define TFTPC_IP_ADDR_EX_CLASS_DE 0xdfffffff
+
+#define TFTPC_FOUR 4 /* minimum packet size */
+
+/****************************************************************************/
+/* Structure definitions */
+/****************************************************************************/
+/* Tftp data packet */
+typedef struct tagTFTPC_DATA {
+ u16_t usBlknum; /* block number */
+ u8_t ucDataBuf[TFTP_BLKSIZE]; /* Actual data */
+} TFTPC_DATA_S;
+
+
+/* TFTP error packet */
+typedef struct tagTFTPC_ERROR {
+ u16_t usErrNum; /* error number */
+ u8_t ucErrMesg[TFTP_MAXERRSTRSIZE]; /* error message */
+} TFTPC_ERROR_S;
+
+
+/* TFTP packet format */
+typedef struct tagTFTPC_PACKET {
+ u16_t usOpcode; /* Opcode value */
+ union {
+ /* it contains mode and filename */
+ s8_t ucName_Mode[TFTP_MAX_PATH_LENGTH + TFTP_MAX_MODE_SIZE];
+ u16_t usBlknum; /* Block Number */
+ TFTPC_DATA_S stTFTP_Data; /* Data Packet */
+ TFTPC_ERROR_S stTFTP_Err; /* Error Packet */
+ } u;
+} TFTPC_PACKET_S;
+
+
+/** @defgroup TFTP_Interfaces
+* This section contains the TFTP Interfaces
+*/
+/*
+Func Name: lwip_tftp_get_file_by_filename
+*/
+/**
+* @ingroup TFTP_Interfaces
+* @brief
+* This API gets the source file from the server. It then stores the received file in the destination path
+* on the client system.
+*
+* @param[in] ulHostAddr IP address of Host. This is the TFTP server IP. [NA]
+* @param[in] usTftpServPort TFTP server port. If the value is passed as 0 then the default TFTP
+* PORT 69 is used. [NA]
+* @param[in] ucTftpTransMode File transfer mode, either TRANSFER_MODE_BINARY or TRANSFER_MODE_ASCII. [NA]
+* @param[in] szSrcFileName Source file in the tftp server. [NA]
+* @param[in] szDestDirPath Destination file path in the in the client. [NA]
+* @param[out] [N/A]
+*
+* @return
+* ERR_OK: On success \n
+* TFTPC_ERR_CODE_E: On failure
+*
+* @note
+* \n
+* The behavior of this API is such that if the destination file already exists, it will be overwritten.
+*/
+u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
+ u16_t usTftpServPort,
+ u8_t ucTftpTransMode,
+ s8_t *szSrcFileName,
+ s8_t *szDestDirPath);
+
+
+/* @defgroup TFTP_Interfaces
+* This section contains the TFTP Interfaces
+*/
+/*
+Func Name: lwip_tftp_put_file_by_filename
+*/
+/**
+* @ingroup TFTP_Interfaces
+
+* @brief
+* This API reads the contents of the source file on the client system and sends it to the server and
+* server then receives the data and stores it in the specified destination path.
+*
+* @param[in] ulHostAddr Indicates the IP address of Host. This is the TFTP server IP.
+* @param[in] usTftpServPort Indicates the TFTP server port. If the value is passed as 0 then the default TFTP
+* PORT 69 is used.
+* @param[in] ucTftpTransMode Indicates the file transfer mode, either TRANSFER_MODE_BINARY or TRANSFER_MODE_ASCII.
+* @param[in] szSrcFileName Indicates the source file in the client.
+* @param[in] szDestDirPath Indicates the destination file path on the tftp server.
+*
+* @return
+* ERR_OK: On success \n
+* TFTPC_ERR_CODE_E: On failure
+*
+*/
+u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr,
+ u16_t usTftpServPort,
+ u8_t cTftpTransMode,
+ s8_t *szSrcFileName,
+ s8_t *szDestDirPath);
+
+#ifdef TFTP_TO_RAWMEM
+/* @defgroup TFTP_Interfaces
+* This section contains the TFTP Interfaces
+*/
+/*
+Func Name: lwip_tftp_get_file_by_filename_to_rawmem
+*/
+/**
+* @ingroup TFTP_Interfaces
+
+* @brief
+* This API gets the source file from the server. It then stores the received file in the target memory
+* on the client system.
+*
+* @param[in] ulHostAddr Indicates the IP address of the Host. This is the TFTP server IP.
+* @param[in] usTftpServPort Indicates the TFTP server port. If the value is passed as 0 then the default TFTP
+* PORT 69 is used.
+* @param[in] ucTftpTransMode Indicates the File transfer mode, either TRANSFER_MODE_BINARY or TRANSFER_MODE_ASCII.
+* @param[in] szSrcFileName Indicates the Source file in the TFTP server.
+* @param[in] szDestMemAddr Indicates the target memory address in the client.
+* @param[in/out] ulFileLength Indicates the target memory address can cache the size of the content,
+ and The real size of the Source file.
+*
+* @return
+* ERR_OK: On success \n
+* TFTPC_ERR_CODE_E: On failure
+* @note
+
+* 1.You must define TFTP_TO_RAWMEM when using this API. \n
+* 2.The behavior of this API is such that if the destination file already exists, it will be overwritten.
+* @endcond
+*/
+
+u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
+ u16_t usTftpServPort,
+ u8_t ucTftpTransMode,
+ s8_t *szSrcFileName,
+ s8_t *szDestMemAddr,
+ u32_t *ulFileLength);
+#endif
+
+#if defined (__cplusplus) && __cplusplus
+}
+#endif
+
+#endif /* LWIP_TFTP */
+
+#endif /* TFTPC_H */
diff --git a/apps/tftp/include/types_adapt.h b/apps/tftp/include/types_adapt.h
new file mode 100644
index 0000000000000000000000000000000000000000..5634495f6046970cb535b99de3f0906753dd6a2d
--- /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 0000000000000000000000000000000000000000..4a476c746395d8ff7ca51c4fb78c6db280799090
--- /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/apps/tftp/src/tftpc.c b/apps/tftp/src/tftpc.c
new file mode 100644
index 0000000000000000000000000000000000000000..b78bd45fb7c1ef3d16a8efe89b850feece419f16
--- /dev/null
+++ b/apps/tftp/src/tftpc.c
@@ -0,0 +1,1720 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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.
+ */
+
+/* TFTP Client utility */
+
+#include "tftpc.h"
+
+#if LWIP_TFTP /* don't build if not configured for use in lwipopts.h */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* Function Declarations */
+#ifdef LOSCFG_NET_LWIP_SACK_TFTP
+static u32_t lwip_tftp_create_bind_socket(s32_t *piSocketID);
+
+static s32_t lwip_tftp_make_tftp_packet(u16_t usOpcode, s8_t *szFileName,
+ u32_t ulMode, TFTPC_PACKET_S *pstPacket);
+
+static u32_t lwip_tftp_recv_from_server(s32_t iSockNum,
+ u32_t *pulSize,
+ TFTPC_PACKET_S *pstRecvBuf,
+ u32_t *pulIgnorePkt,
+ struct sockaddr_in *pstServerAddr,
+ TFTPC_PACKET_S *pstSendBuf);
+
+static u32_t lwip_tftp_send_to_server(s32_t iSockNum, u32_t ulSize,
+ TFTPC_PACKET_S *pstSendBuf,
+ struct sockaddr_in *pstServerAddr);
+
+static u32_t lwip_tftp_validate_data_pkt(s32_t iSockNum,
+ u32_t *pulSize,
+ TFTPC_PACKET_S *pstRecvBuf,
+ u16_t usCurrBlk, u32_t *pulResendPkt,
+ struct sockaddr_in *pstServerAddr);
+
+static u32_t lwip_tftp_inner_put_file(s32_t iSockNum, TFTPC_PACKET_S *pstSendBuf,
+ u32_t ulSendSize, u16_t usCurrBlk,
+ struct sockaddr_in *pstServerAddr);
+
+static void lwip_tftp_send_error(s32_t iSockNum, u32_t ulError, const char *szErrMsg,
+ struct sockaddr_in *pstServerAddr, TFTPC_PACKET_S *pstSendBuf);
+
+
+/* Create and bind a UDP socket. */
+u32_t lwip_tftp_create_bind_socket(s32_t *piSocketID)
+{
+ int retval;
+ struct sockaddr_in stClientAddr;
+ u32_t ulTempClientIp;
+ u32_t set_non_block_socket = 1;
+
+ /* create a socket */
+ *piSocketID = lwip_socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (*piSocketID == -1) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_create_bind_socket : lwip_socket create socket failed\n"));
+ return TFTPC_SOCKET_FAILURE;
+ }
+
+ /* Make the socket as NON-BLOCKING. */
+ retval = lwip_ioctl(*piSocketID, (long)FIONBIO, &set_non_block_socket);
+ if (retval != 0) {
+ (void)lwip_close(*piSocketID);
+ *piSocketID = TFTP_NULL_INT32;
+ return TFTPC_IOCTLSOCKET_FAILURE;
+ }
+
+ ulTempClientIp = INADDR_ANY;
+
+ /* specify a local address for this socket */
+ (void)memset_s(&stClientAddr, sizeof(stClientAddr), 0, sizeof(stClientAddr));
+ stClientAddr.sin_family = AF_INET;
+ stClientAddr.sin_port = 0;
+ stClientAddr.sin_addr.s_addr = htonl(ulTempClientIp);
+
+ retval = lwip_bind(*piSocketID, (struct sockaddr *)&stClientAddr, sizeof(stClientAddr));
+ if (retval != 0) {
+ (void)lwip_close(*piSocketID);
+ *piSocketID = TFTP_NULL_INT32;
+
+ return TFTPC_BIND_FAILURE;
+ }
+
+ return ERR_OK;
+}
+
+
+/* Function to create TFTP packet.
+ usOpcode - indiacting the nature of the operation
+ pFileName -filename on which the operation needs to done
+ ulMode -mode in which the operation needs to done
+ pstPacket - packet generated
+ Returns packet address on success
+*/
+static s32_t lwip_tftp_make_tftp_packet(u16_t usOpcode, s8_t *szFileName, u32_t ulMode, TFTPC_PACKET_S *pstPacket)
+{
+ s8_t *pcCp = NULL;
+
+ pstPacket->usOpcode = htons(usOpcode);
+ pcCp = pstPacket->u.ucName_Mode;
+
+ /* Request packet format is:
+ | Opcode | Filename | 0 | Mode | 0 |
+ */
+ (void)strncpy_s((char *)pcCp, TFTP_MAX_PATH_LENGTH, (char *)szFileName, (TFTP_MAX_PATH_LENGTH - 1));
+ pcCp[(TFTP_MAX_PATH_LENGTH - 1)] = '\0';
+
+ pcCp += (strlen((char *)szFileName) + 1);
+ if (ulMode == TRANSFER_MODE_BINARY) {
+ (void)strncpy_s((char *)pcCp, TFTP_MAX_MODE_SIZE, "octet", (TFTP_MAX_MODE_SIZE - 1));
+ pcCp[(TFTP_MAX_MODE_SIZE - 1)] = '\0';
+ } else if (ulMode == TRANSFER_MODE_ASCII) {
+ (void)strncpy_s((char *)pcCp, TFTP_MAX_MODE_SIZE, "netascii", (TFTP_MAX_MODE_SIZE - 1));
+ pcCp[(TFTP_MAX_MODE_SIZE - 1)] = '\0';
+ }
+
+ pcCp += (strlen((char *)pcCp) + 1);
+
+ return (pcCp - (s8_t *)pstPacket);
+}
+
+/* Function to recv a packet from server
+ iSockNum - Socket Number
+ pstServerAddr - Server address
+ pulIgnorePkt - Ignore packet flag
+ pstRecvBuf - received packet
+ pulSize - Size of the packet
+*/
+u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S *pstRecvBuf, u32_t *pulIgnorePkt,
+ struct sockaddr_in *pstServerAddr, TFTPC_PACKET_S *pstSendBuf)
+{
+ u32_t ulError;
+ socklen_t slFromAddrLen;
+ struct sockaddr_in stFromAddr;
+ fd_set stReadfds;
+ struct timeval stTimeout;
+ u16_t usOpcode; /* Opcode value */
+ s32_t iRet;
+
+ slFromAddrLen = sizeof(stFromAddr);
+ stTimeout.tv_sec = TFTPC_TIMEOUT_PERIOD;
+ stTimeout.tv_usec = 0;
+
+ /* wait for DATA packet */
+ FD_ZERO(&stReadfds);
+ FD_SET(iSockNum, &stReadfds);
+
+ iRet = select((s32_t)(iSockNum + 1), &stReadfds, 0, 0, &stTimeout);
+ if (iRet == -1) {
+ return TFTPC_SELECT_ERROR;
+ } else if (iRet == 0) {
+ return TFTPC_TIMEOUT_ERROR; /* Select timeout occured */
+ }
+
+ if (!FD_ISSET(iSockNum, &stReadfds)) {
+ return TFTPC_TIMEOUT_ERROR; /* FD not set*/
+ }
+
+ /* receive a packet from server */
+ iRet = lwip_recvfrom(iSockNum, (s8_t *)pstRecvBuf, TFTP_PKTSIZE, 0,
+ (struct sockaddr *)&stFromAddr, &slFromAddrLen);
+ if (iRet <= 0) {
+ return TFTPC_RECVFROM_ERROR;
+ }
+
+ /* If received packet size < minimum packet size */
+ if (iRet < TFTPC_FOUR) {
+ /* Send Error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Packet size < min size",
+ pstServerAddr, pstSendBuf);
+
+ return TFTPC_PKT_SIZE_ERROR;
+ }
+
+ /* convert network opcode to host format after receive. */
+ usOpcode = ntohs(pstRecvBuf->usOpcode);
+ /* if this packet is ERROR packet */
+ if (usOpcode == TFTPC_OP_ERROR) {
+ ulError = ntohs (pstRecvBuf->u.stTFTP_Err.usErrNum);
+
+ /*If the error is according to RFC,then convert to lwip error codes.
+ Constant values are used in the cases as these error codes are as per
+ the RFC, these are constant values returned by many standard TFTP
+ serevrs.*/
+ switch (ulError) {
+ case TFTPC_PROTOCOL_USER_DEFINED:
+ ulError = TFTPC_ERROR_NOT_DEFINED;
+ break;
+ case TFTPC_PROTOCOL_FILE_NOT_FOUND:
+ ulError = TFTPC_FILE_NOT_FOUND;
+ break;
+ case TFTPC_PROTOCOL_ACCESS_ERROR:
+ ulError = TFTPC_ACCESS_ERROR;
+ break;
+ case TFTPC_PROTOCOL_DISK_FULL:
+ ulError = TFTPC_DISK_FULL;
+ break;
+ case TFTPC_PROTOCOL_PROTO_ERROR:
+ ulError = TFTPC_PROTO_ERROR;
+ break;
+ case TFTPC_PROTOCOL_UNKNOWN_TRANSFER_ID:
+ ulError = TFTPC_UNKNOWN_TRANSFER_ID;
+ break;
+ case TFTPC_PROTOCOL_FILE_EXISTS:
+ ulError = TFTPC_FILE_EXISTS;
+ break;
+ case TFTPC_PROTOCOL_CANNOT_RESOLVE_HOSTNAME:
+ ulError = TFTPC_CANNOT_RESOLVE_HOSTNAME;
+ break;
+ default:
+ ulError = TFTPC_ERROR_NOT_DEFINED;
+ break;
+ }
+
+ /* If length of error msg > 100 chars */
+ pstRecvBuf->u.stTFTP_Err.ucErrMesg[TFTP_MAXERRSTRSIZE - 1] = '\0';
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_recv_from_server : ERROR pkt received: %s\n",
+ pstRecvBuf->u.stTFTP_Err.ucErrMesg));
+
+ /* Now we get error block, so return. */
+ return ulError;
+ }
+
+ /* Store the size of received block */
+ *pulSize = (u32_t)iRet;
+
+ /* If received packet is first block of data(for get operation) or if
+ received packet is acknowledgement for write request (put operation)
+ store the received port number */
+ if (((usOpcode == TFTPC_OP_DATA) &&
+ (ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum) == 1)) ||
+ ((usOpcode == TFTPC_OP_ACK) &&
+ (ntohs(pstRecvBuf->u.usBlknum) == 0))) {
+ /* If received packet from correct server */
+ if (stFromAddr.sin_addr.s_addr == pstServerAddr->sin_addr.s_addr) {
+ /* set the server port to received port */
+ pstServerAddr->sin_port = stFromAddr.sin_port;
+ } else {
+ /* Received packet form wrong server. */
+ LWIP_DEBUGF(TFTP_DEBUG,
+ ("lwip_tftp_recv_from_server : Received 1st packet from wrong Server or unknown server\n"));
+
+ /* Set ignore packet flag */
+ *pulIgnorePkt = 1;
+ }
+ } else {
+ /* If not first packet, check if the received packet is from correct
+ server and from correct port */
+ if ((stFromAddr.sin_addr.s_addr != pstServerAddr->sin_addr.s_addr) ||
+ (pstServerAddr->sin_port != stFromAddr.sin_port)) {
+ /* Received packet form wrong server or wrong port.Ignore packet. */
+ LWIP_DEBUGF(TFTP_DEBUG,
+ ("lwip_tftp_recv_from_server : Received a packet from wrong Server or unknown server\n"));
+
+ /* Set ignore packet flag */
+ *pulIgnorePkt = 1;
+ }
+ }
+
+ return ERR_OK;
+}
+
+/* Function to send a packet to server
+ iSockNum: Socket Number
+ ulSize: Size of the packet
+ pstSendBuf: Packet to send
+ pstServerAddr: Server address
+*/
+u32_t lwip_tftp_send_to_server(s32_t iSockNum,
+ u32_t ulSize,
+ TFTPC_PACKET_S *pstSendBuf,
+ struct sockaddr_in *pstServerAddr)
+{
+ s32_t iRet;
+
+ /* Send packet to server */
+ iRet = lwip_sendto(iSockNum, (s8_t *)pstSendBuf,
+ (size_t)ulSize, 0,
+ (struct sockaddr *)pstServerAddr,
+ sizeof(struct sockaddr_in));
+ /* Size of data sent not equal to size of packet */
+ if ((iRet == TFTP_NULL_INT32) || ((u32_t)iRet != ulSize)) {
+ return TFTPC_SENDTO_ERROR;
+ }
+
+ return ERR_OK;
+}
+
+/* lwip_tftp_validate_data_pkt
+* Get the data block from the received packet
+* @param Input iSockNum Socket Number
+* pulSize: Size of received packet,
+ pstRecvBuf - received packet
+ usCurrBlk - Current block number
+ * @param Output pulResendPkt - Resend packet flag
+ * @return VOS_OK on success.else error code*/
+
+u32_t lwip_tftp_validate_data_pkt(s32_t iSockNum,
+ u32_t *pulSize,
+ TFTPC_PACKET_S *pstRecvBuf,
+ u16_t usCurrBlk,
+ u32_t *pulResendPkt,
+ struct sockaddr_in *pstServerAddr)
+{
+ fd_set stReadfds;
+ struct timeval stTimeout;
+ struct sockaddr_in stFromAddr;
+ socklen_t ulFromAddrLen;
+ s32_t iRecvLen = (s32_t)*pulSize;
+ s32_t iError;
+ u16_t usBlknum;
+ u32_t ulLoopCnt = 0;
+
+ ulFromAddrLen = sizeof(stFromAddr);
+
+ /* Initialize from address to the server address at first */
+ if (memcpy_s((void *)&stFromAddr, sizeof(struct sockaddr_in), (void *)pstServerAddr, sizeof(stFromAddr)) != 0) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_validate_data_pkt : memcpy_s error\n"));
+ return TFTPC_MEMCPY_FAILURE;
+ }
+
+ /* Get Block Number */
+ usBlknum = ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum);
+ /* Now data blocks are not in sync. */
+ if (usBlknum != usCurrBlk) {
+ /* Set timeout value */
+ stTimeout.tv_sec = 1;
+ stTimeout.tv_usec = 0;
+
+ /* Reset any stored packets. */
+ FD_ZERO(&stReadfds);
+ FD_SET(iSockNum, &stReadfds);
+
+ iError = select((s32_t)(iSockNum + 1),
+ &stReadfds, 0, 0, &stTimeout);
+
+ /* Loop to get the last data packet from the receive buffer */
+ while ((iError != TFTP_NULL_INT32) && (iError != 0)) {
+ ulLoopCnt++;
+
+ /* MAX file size in TFTP is 32 MB.
+ Reason for keeping 75 here , is ((75*512=38400bytes)/1024) = 37MB. So the recv/Send
+ Loop can receive the complete MAX message from the network.
+ */
+ if (ulLoopCnt > TFTPC_MAX_WAIT_IN_LOOP) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_validate_data_pkt : unexpected packets are received repeatedly\n"));
+ *pulSize = TFTP_NULL_UINT32;
+ return TFTPC_PKT_SIZE_ERROR;
+ }
+
+ FD_ZERO(&stReadfds);
+ FD_SET(iSockNum, &stReadfds);
+
+ iRecvLen = lwip_recvfrom(iSockNum,
+ (s8_t *)pstRecvBuf,
+ TFTP_PKTSIZE, 0,
+ (struct sockaddr *)&stFromAddr,
+ &ulFromAddrLen);
+ if (iRecvLen == -1) {
+ *pulSize = TFTP_NULL_UINT32;
+
+ /* return from the function, recvfrom operation failed */
+ return TFTPC_RECVFROM_ERROR;
+ }
+
+ stTimeout.tv_sec = 1;
+ stTimeout.tv_usec = 0;
+ iError = select((s32_t)(iSockNum + 1), &stReadfds, 0, 0, &stTimeout);
+ }
+
+ /* If received packet size < minimum packet size */
+ if (iRecvLen < TFTPC_FOUR) {
+ return TFTPC_PKT_SIZE_ERROR;
+ }
+
+ /* Check if the received packet is from correct server and from
+ correct port
+ */
+ if ((stFromAddr.sin_addr.s_addr != pstServerAddr->sin_addr.s_addr) ||
+ (pstServerAddr->sin_port != stFromAddr.sin_port)) {
+ /* resend ack packet */
+ *pulResendPkt = 1;
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_validate_data_pkt : Received pkt from unknown server\n"));
+
+ return ERR_OK;
+ }
+
+ /* if this packet is not DATA packet */
+ if (TFTPC_OP_DATA != ntohs(pstRecvBuf->usOpcode)) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_validate_data_pkt : Received pkt not a DATA pkt\n"));
+
+ /* return from the function, incorrect packet received,
+ expected packet is data packet */
+ return TFTPC_PROTO_ERROR;
+ }
+
+ usBlknum = ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum);
+ /* if we now have the earlier data packet, then the host probably
+ never got our acknowledge packet, now we will send it again. */
+ if (usBlknum == (usCurrBlk - 1)) {
+ /* resend ack packet */
+ *pulResendPkt = 1;
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_validate_data_pkt : Received previous DATA pkt\n"));
+
+ return ERR_OK;
+ }
+
+ /* If the block of data received is not current block or also
+ previous block, then it is abnormal case. */
+ if (usBlknum != usCurrBlk) {
+ LWIP_DEBUGF(TFTP_DEBUG,
+ ("lwip_tftp_validate_data_pkt : Received DATA pkt no. %"S32_F" instead of pkt no.%"S32_F"\n",
+ usBlknum, usCurrBlk));
+
+ return TFTPC_SYNC_FAILURE;
+ }
+ }
+
+ *pulSize = (u32_t)iRecvLen;
+ return ERR_OK;
+}
+
+/* Send an error packet to the server
+ iSockNum : Socket Number
+ ulError: Error code
+ szErrMsg - Error message
+ pstServerAddr - Server address
+*/
+static void lwip_tftp_send_error(s32_t iSockNum, u32_t ulError, const char *szErrMsg,
+ struct sockaddr_in *pstServerAddr, TFTPC_PACKET_S *pstSendBuf)
+{
+ u16_t usOpCode = TFTPC_OP_ERROR;
+
+ if (memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S)) != 0) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_send_error : memset_s error\n"));
+ return;
+ }
+
+ /* Set up the send buffer */
+ pstSendBuf->usOpcode = htons(usOpCode);
+ pstSendBuf->u.stTFTP_Err.usErrNum = htons((u16_t)ulError);
+
+ if (strncpy_s((char *)(pstSendBuf->u.stTFTP_Err.ucErrMesg), TFTP_MAXERRSTRSIZE,
+ (char *)szErrMsg, (TFTP_MAXERRSTRSIZE - 1)) != EOK) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_send_error : strncpy_s error\n"));
+ return;
+ }
+ pstSendBuf->u.stTFTP_Err.ucErrMesg[(TFTP_MAXERRSTRSIZE - 1)] = '\0';
+
+ /* Send to server */
+ if (lwip_tftp_send_to_server(iSockNum,
+ sizeof(TFTPC_PACKET_S),
+ pstSendBuf,
+ pstServerAddr) != ERR_OK) {
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_send_to_server error."));
+ return;
+ }
+}
+
+/* INTEFACE to get a file using filename
+ ulHostAddr - IP address of Host
+ szSrcFileName - Source file
+ szDestDirPath - Destination file path
+*/
+u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
+ u16_t usTftpServPort,
+ u8_t ucTftpTransMode,
+ s8_t *szSrcFileName,
+ s8_t *szDestDirPath)
+{
+ s32_t iSockNum = TFTP_NULL_INT32;
+ u32_t ulSrcStrLen;
+ u32_t ulDestStrLen;
+ u32_t ulSize;
+ u32_t ulRecvSize = TFTP_NULL_UINT32;
+ s32_t iErrCode;
+ u32_t ulErrCode;
+ u16_t usReadReq;
+ u16_t usTempServPort;
+ s8_t *pszTempDestName = NULL;
+ s8_t *szTempSrcName = NULL;
+ u32_t ulCurrBlk = 1;
+ u32_t ulResendPkt = 0; /*Resend the previous packet*/
+ u32_t ulIgnorePkt = 0; /*Ignore received packet*/
+ u32_t ulTotalTime = 0;
+ u32_t isLocalFileOpened = false;
+
+ TFTPC_PACKET_S *pstSendBuf = NULL;
+ TFTPC_PACKET_S *pstRecvBuf = NULL;
+ struct sockaddr_in stServerAddr;
+ struct stat sb;
+ u32_t IsDirExist = 0;
+ s32_t fp = -1;
+
+ /*Validate the parameters*/
+ if ((szSrcFileName == NULL) || (szDestDirPath == NULL)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ if ((ucTftpTransMode != TRANSFER_MODE_BINARY) && (ucTftpTransMode != TRANSFER_MODE_ASCII)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ /*check IP address not within ( 1.0.0.0 - 126.255.255.255 )
+ and ( 128.0.0.0 - 223.255.255.255 ) range.*/
+ if (!(((ulHostAddr >= TFTPC_IP_ADDR_MIN) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_RESV)) ||
+ ((ulHostAddr >= TFTPC_IP_ADDR_CLASS_B) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_CLASS_DE)))) {
+ return TFTPC_IP_NOT_WITHIN_RANGE;
+ }
+
+ /*Check validity of source filename*/
+ ulSrcStrLen = strlen((char *)szSrcFileName);
+ if ((ulSrcStrLen == 0) || (ulSrcStrLen >= TFTP_MAX_PATH_LENGTH)) {
+ return TFTPC_SRC_FILENAME_LENGTH_ERROR;
+ }
+
+ /*Check validity of destination path*/
+ ulDestStrLen = strlen((char *)szDestDirPath);
+ if ((ulDestStrLen >= TFTP_MAX_PATH_LENGTH) || (ulDestStrLen == 0)) {
+ return TFTPC_DEST_PATH_LENGTH_ERROR;
+ }
+
+ pstSendBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstSendBuf == NULL) {
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ pstRecvBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstRecvBuf == NULL) {
+ mem_free(pstSendBuf);
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ pszTempDestName = (s8_t *)mem_malloc(TFTP_MAX_PATH_LENGTH);
+ if (pszTempDestName == NULL) {
+ mem_free(pstSendBuf);
+ mem_free(pstRecvBuf);
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ /* First time initialize the buffers */
+ (void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+ (void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+
+ /*If given src filename is a relative path extract
+ the file name from the path*/
+ if ((0 != strchr((char *)szSrcFileName, '/')) || (0 != strchr((char *)szSrcFileName, '\\'))) {
+ /*Move to the end of the src file path*/
+ szTempSrcName = szSrcFileName + (ulSrcStrLen - 1);
+
+ while (((*(szTempSrcName - 1) != '/') &&
+ (*(szTempSrcName - 1) != '\\')) &&
+ (szTempSrcName != szSrcFileName)) {
+ szTempSrcName--;
+ }
+
+ /*Get length of the extracted src filename*/
+ ulSrcStrLen = strlen((char *)szTempSrcName);
+ } else {
+ /*If not a relative src path use the given src filename*/
+ szTempSrcName = szSrcFileName;
+ }
+
+ (void)memset_s(pszTempDestName, TFTP_MAX_PATH_LENGTH, 0, TFTP_MAX_PATH_LENGTH);
+ if (strncpy_s((char *)pszTempDestName, TFTP_MAX_PATH_LENGTH, (char *)szDestDirPath, TFTP_MAX_PATH_LENGTH - 1) !=
+ 0) {
+ ulErrCode = TFTPC_MEMCPY_FAILURE;
+ goto err_handler;
+ }
+ pszTempDestName[TFTP_MAX_PATH_LENGTH - 1] = '\0';
+
+ if (stat((char *)pszTempDestName, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+ IsDirExist = 1;
+ }
+
+ if (IsDirExist == 1) {
+ /*The filename is not present concat source filename and try*/
+ if ((ulDestStrLen + ulSrcStrLen) >= TFTP_MAX_PATH_LENGTH) {
+ /*If concatenating src filename exceeds 256 bytes*/
+ ulErrCode = TFTPC_DEST_PATH_LENGTH_ERROR;
+ goto err_handler;
+ }
+
+ /*Check if / present at end of string*/
+ if ((pszTempDestName[ulDestStrLen - 1] != '/') &&
+ (pszTempDestName[ulDestStrLen - 1] != '\\')) {
+ if ((ulDestStrLen + ulSrcStrLen + 1) >= TFTP_MAX_PATH_LENGTH) {
+ /*If concatenating src filename exceeds 256 bytes*/
+ ulErrCode = TFTPC_DEST_PATH_LENGTH_ERROR;
+ goto err_handler;
+ }
+
+ /*If not present concat / to the path*/
+ if (strncat_s((char *)pszTempDestName, (TFTP_MAX_PATH_LENGTH - strlen((char *)pszTempDestName)),
+ "/", TFTP_MAX_PATH_LENGTH - strlen((char *)pszTempDestName) - 1) != 0) {
+ ulErrCode = TFTPC_ERROR_NOT_DEFINED;
+ goto err_handler;
+ }
+ }
+
+ /*Concatenate src filename to destination path*/
+ if (strncat_s((char *)pszTempDestName, (TFTP_MAX_PATH_LENGTH - strlen((char *)pszTempDestName)),
+ (char *)szTempSrcName, TFTP_MAX_PATH_LENGTH - strlen((char *)pszTempDestName) - 1) != 0) {
+ ulErrCode = TFTPC_ERROR_NOT_DEFINED;
+ goto err_handler;
+ }
+ }
+
+ ulErrCode = lwip_tftp_create_bind_socket(&iSockNum);
+ if (ulErrCode != ERR_OK) {
+ goto err_handler;
+ }
+
+ if (usTftpServPort == 0) {
+ usTftpServPort = TFTPC_SERVER_PORT;
+ }
+
+ usTempServPort = usTftpServPort;
+
+ /* set server IP address */
+ (void)memset_s(&stServerAddr, sizeof(stServerAddr), 0, sizeof(stServerAddr));
+ stServerAddr.sin_family = AF_INET;
+ stServerAddr.sin_port = htons(usTempServPort);
+ stServerAddr.sin_addr.s_addr = htonl(ulHostAddr);
+
+ /* Make a request packet - TFTPC_OP_RRQ */
+ ulSize = (u32_t)lwip_tftp_make_tftp_packet(TFTPC_OP_RRQ, szSrcFileName,
+ (u32_t)ucTftpTransMode,
+ pstSendBuf);
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* send to server failed */
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+
+ for (;;) {
+ if (ulIgnorePkt > 0) {
+ ulIgnorePkt = 0;
+ }
+
+ ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf,
+ &ulIgnorePkt, &stServerAddr, pstSendBuf);
+ /* If select timeout occured */
+ if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
+ ulTotalTime++;
+ if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
+ /* Max attempts not reached. Resend packet */
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+ goto err_handler;
+ }
+
+ continue;
+ } else {
+ /* return from the function, max attempts limit reached */
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+ ulErrCode = TFTPC_TIMEOUT_ERROR;
+ goto err_handler;
+ }
+ } else if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+ goto err_handler;
+ }
+
+ /* Now we have receive block from different server. */
+ if (ulIgnorePkt > 0) {
+ /*Continue without processing this block. */
+ continue;
+ }
+
+ /* if this packet is unkonwn or incorrect packet */
+ if (ntohs (pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
+ /* Send error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Protocol error.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Received pkt not DATA pkt\n"));
+
+ ulErrCode = TFTPC_PROTO_ERROR;
+ goto err_handler;
+ }
+
+ /* Now the number of tries will be reset. */
+ ulTotalTime = 0;
+
+ /* Validate received DATA packet. */
+ ulErrCode = lwip_tftp_validate_data_pkt(iSockNum, &ulRecvSize,
+ pstRecvBuf, (u16_t)ulCurrBlk,
+ &ulResendPkt,
+ &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* Send Error packet to server */
+ if (ulErrCode != TFTPC_RECVFROM_ERROR) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Received unexpected packet",
+ &stServerAddr, pstSendBuf);
+ }
+
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+
+ goto err_handler;
+ }
+
+ /* Received previous data block again. Resend last packet */
+ if (ulResendPkt > 0) {
+ /* Now set ulResendPkt to 0 to send the last packet. */
+ ulResendPkt = 0;
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+
+ goto err_handler;
+ }
+
+ /* Continue in loop to send last packet again. */
+ continue;
+ }
+
+ /* Get the size of the data block received */
+ ulRecvSize -= TFTP_HDRSIZE;
+
+ /* Check if the size of the received data block > max size */
+ if (ulRecvSize > TFTP_BLKSIZE) {
+ /* Send Error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Packet size > max size",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ if (isLocalFileOpened == true) {
+ close(fp);
+ }
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Packet size > max size\n"));
+
+ ulErrCode = TFTPC_PKT_SIZE_ERROR;
+ goto err_handler;
+ }
+
+ usReadReq = (u16_t)TFTPC_OP_ACK;
+ pstSendBuf->usOpcode = htons(usReadReq);
+ pstSendBuf->u.usBlknum = htons((u16_t)ulCurrBlk);
+ ulSize = TFTP_HDRSIZE;
+
+ if (isLocalFileOpened == false) {
+ fp = open((char *)pszTempDestName, (O_WRONLY | O_CREAT | O_TRUNC), DEFFILEMODE);
+ if (fp == TFTP_NULL_INT32) {
+ ulErrCode = TFTPC_FILECREATE_ERROR;
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+ isLocalFileOpened = true;
+ }
+
+ if (ulRecvSize != TFTP_BLKSIZE) {
+ (void)lwip_tftp_send_to_server(iSockNum, ulSize, pstSendBuf, &stServerAddr);
+
+ /* If the received packet has only header and do not have payload, the return failure */
+ if (ulRecvSize != 0) {
+ /* Write the last packet to the file */
+ iErrCode = write(fp, (void *)pstRecvBuf->u.stTFTP_Data.ucDataBuf, (size_t)ulRecvSize);
+ if (ulRecvSize != (u32_t)iErrCode) {
+ /* Write to file failed. */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "Write to file failed",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+
+ /* return from the function, file write failed */
+ ulErrCode = TFTPC_FILEWRITE_ERROR;
+ goto err_handler;
+ }
+ }
+
+ /* Now free allocated resourdes and return,
+ data block receiving is already completed */
+ (void)lwip_close(iSockNum);
+ close(fp);
+ ulErrCode = ERR_OK;
+ goto err_handler;
+ }
+
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ close(fp);
+ goto err_handler;
+ }
+
+ iErrCode = write(fp, (void *)pstRecvBuf->u.stTFTP_Data.ucDataBuf, (size_t)ulRecvSize);
+ if (ulRecvSize != (u32_t)iErrCode) {
+ /* Write to file failed. */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "Write to file failed",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+
+ /* return from the function, file write failed */
+ ulErrCode = TFTPC_FILEWRITE_ERROR;
+ goto err_handler;
+ }
+
+ /* form the ACK packet for the DATA packet received */
+ /* Go to the next packet no. */
+ ulCurrBlk++;
+
+ /* if the file is too big, exit */
+ if (ulCurrBlk > TFTP_MAX_BLK_NUM) {
+ /* Send error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "File is too big.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Data block number exceeded max value\n"));
+
+ ulErrCode = TFTPC_FILE_TOO_BIG;
+ goto err_handler;
+ }
+ }
+
+err_handler:
+ mem_free(pstSendBuf);
+ mem_free(pstRecvBuf);
+ mem_free(pszTempDestName);
+ return ulErrCode;
+}
+
+
+/* INTERFACE Function to put a file using filename
+ ulHostAddr: IP address of Host
+ szSrcFileName: Source file
+ szDestDirPath: Destination file path
+*/
+u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_t ucTftpTransMode,
+ s8_t *szSrcFileName, s8_t *szDestDirPath)
+{
+ u32_t ulSrcStrLen;
+ u32_t ulDestStrLen;
+ s32_t iSockNum = TFTP_NULL_INT32;
+ s32_t iErrCode;
+ u32_t ulErrCode;
+ u16_t usTempServPort;
+ TFTPC_PACKET_S *pstSendBuf = NULL;
+ u16_t usReadReq;
+ u32_t ulSize;
+ s8_t *pucBuffer = 0;
+ s8_t *szTempDestName = NULL;
+
+ /*Initialize the block number*/
+ u16_t usCurrBlk = 0;
+ struct sockaddr_in stServerAddr;
+ struct stat buffer;
+ s32_t fp = -1;
+
+ /* Validate parameters */
+ if ((szSrcFileName == NULL) || (szDestDirPath == NULL)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ if ((ucTftpTransMode != TRANSFER_MODE_BINARY) && (ucTftpTransMode != TRANSFER_MODE_ASCII)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ /*check IP address not within ( 1.0.0.0 - 126.255.255.255 )
+ and ( 128.0.0.0 - 223.255.255.255 ) range.*/
+ if (!(((ulHostAddr >= TFTPC_IP_ADDR_MIN) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_RESV)) ||
+ ((ulHostAddr >= TFTPC_IP_ADDR_CLASS_B) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_CLASS_DE)))) {
+ return TFTPC_IP_NOT_WITHIN_RANGE;
+ }
+
+ /* If Src filename is empty or exceeded max length */
+ ulSrcStrLen = strlen((char *)szSrcFileName);
+ if ((ulSrcStrLen == 0) || (ulSrcStrLen >= TFTP_MAX_PATH_LENGTH)) {
+ return TFTPC_SRC_FILENAME_LENGTH_ERROR;
+ }
+
+ /* Check if source file exists */
+ if (stat((char *)szSrcFileName, &buffer) != 0) {
+ return TFTPC_FILE_NOT_EXIST;
+ }
+
+ /* Check if the file is too big */
+ if (buffer.st_size >= (off_t)(TFTP_MAX_BLK_NUM * TFTP_BLKSIZE)) {
+ return TFTPC_FILE_TOO_BIG;
+ }
+
+ /* Check validity of destination path */
+ ulDestStrLen = strlen((char *)szDestDirPath);
+ /* If dest path length exceeded max value */
+ if (ulDestStrLen >= TFTP_MAX_PATH_LENGTH) {
+ return TFTPC_DEST_PATH_LENGTH_ERROR;
+ }
+
+ pstSendBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstSendBuf == NULL) {
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ /* First time intialize the buffer */
+ (void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+
+ /* The destination path can only be one of the following:
+ 1. Only filename
+ 2. Relative path WITH filename
+ 3. Empty string
+ */
+ if (ulDestStrLen != 0) {
+ /* If not empty string use the Destination path name */
+ szTempDestName = szDestDirPath;
+ } else {
+ /* If destination directory is empty string use source filename
+ If given src filename is a relative path extract the file name
+ from the path */
+ if ((strchr((char *)szSrcFileName, '/') != 0) ||
+ (strchr((char *)szSrcFileName, '\\') != 0)) {
+ /* Move to the end of the src file path */
+ szTempDestName = szSrcFileName + (ulSrcStrLen - 1);
+
+ while (((*(szTempDestName - 1) != '/') && (*(szTempDestName - 1) != '\\')) &&
+ (szTempDestName != szSrcFileName)) {
+ szTempDestName--;
+ }
+ } else {
+ /* If not a relative src path use the given src filename */
+ szTempDestName = szSrcFileName;
+ }
+ }
+
+ /* Create a socket and bind it to an available port number */
+ ulErrCode = lwip_tftp_create_bind_socket(&iSockNum);
+ if (ulErrCode != EOK) {
+ /* Create and Bind socket failed */
+ goto err_handler;
+ }
+
+ if (usTftpServPort == 0) {
+ usTftpServPort = TFTPC_SERVER_PORT;
+ }
+
+ usTempServPort = usTftpServPort;
+
+ /* set server internet address */
+ (void)memset_s(&stServerAddr, sizeof(stServerAddr), 0, sizeof(stServerAddr));
+ stServerAddr.sin_family = AF_INET;
+ stServerAddr.sin_port = htons(usTempServPort);
+ stServerAddr.sin_addr.s_addr = htonl(ulHostAddr);
+
+ /* Make request packet - TFTPC_OP_WRQ */
+ ulSize = (u32_t)lwip_tftp_make_tftp_packet(TFTPC_OP_WRQ,
+ szTempDestName,
+ ucTftpTransMode,
+ pstSendBuf);
+
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* Send to server error */
+ (void)lwip_close(iSockNum);
+
+ goto err_handler;
+ }
+
+ /* Send the request packet */
+ ulErrCode = lwip_tftp_inner_put_file(iSockNum, pstSendBuf, ulSize,
+ usCurrBlk, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* Send request packet failed */
+ (void)lwip_close(iSockNum);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_put_file_by_filename : Failed to send request packet\n"));
+
+ goto err_handler;
+ }
+
+ /* Create buffer block size */
+ pucBuffer = mem_malloc(TFTP_BLKSIZE);
+ if (pucBuffer == NULL) {
+ /* Memory allocation failed */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "Memory allocation failed.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ ulErrCode = TFTPC_MEMALLOC_ERROR;
+ goto err_handler;
+ }
+
+ (void)memset_s((void *)pucBuffer, TFTP_BLKSIZE, 0, TFTP_BLKSIZE);
+
+ fp = open((char *)szSrcFileName, O_RDONLY);
+ if (TFTP_NULL_INT32 == fp) {
+ /* If file could not be opened send error to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "File open error.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ mem_free(pucBuffer);
+
+ ulErrCode = TFTPC_FILEOPEN_ERROR;
+ goto err_handler;
+ }
+
+ iErrCode = read(fp, pucBuffer, TFTP_BLKSIZE);
+ if (iErrCode < 0) {
+ /* If failed to read from file */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "File read error.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+
+ ulErrCode = TFTPC_FILEREAD_ERROR;
+ goto err_handler;
+ }
+
+ /* Read from source file and send to server */
+ /* To send empty packet to server when file is a 0 byte file */
+ do {
+ if (((u32_t)usCurrBlk + 1) > TFTP_MAX_BLK_NUM) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "File is too big.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_put_file_by_filename : Data block number exceeded max value\n"));
+
+ ulErrCode = TFTPC_FILE_TOO_BIG;
+ goto err_handler;
+ }
+
+ /* Increment block number */
+ usCurrBlk++;
+
+ ulSize = (u32_t)iErrCode + TFTP_HDRSIZE;
+
+ /* Form the DATA packet */
+ usReadReq = (u16_t)TFTPC_OP_DATA;
+ pstSendBuf->usOpcode = htons(usReadReq);
+ pstSendBuf->u.stTFTP_Data.usBlknum = htons(usCurrBlk);
+ if (memcpy_s((void *)pstSendBuf->u.stTFTP_Data.ucDataBuf, TFTP_BLKSIZE,
+ (void *)pucBuffer, (u32_t)iErrCode) != EOK) {
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+ goto err_handler;
+ }
+
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if ((ulErrCode != ERR_OK) || (memset_s((void *)pucBuffer, TFTP_BLKSIZE, 0, TFTP_BLKSIZE) != 0)) {
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+ goto err_handler;
+ }
+
+ /* Read a block from the file to buffer */
+ iErrCode = read(fp, pucBuffer, TFTP_BLKSIZE);
+ if (iErrCode < 0) {
+ /*If failed to read from file*/
+ lwip_tftp_send_error(iSockNum, TFTPC_PROTOCOL_USER_DEFINED, "File read error.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+ ulErrCode = TFTPC_FILEREAD_ERROR;
+ goto err_handler;
+ }
+
+ /* Send the request packet */
+ ulErrCode = lwip_tftp_inner_put_file(iSockNum, pstSendBuf, ulSize,
+ usCurrBlk, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* Sending buffer contents failed */
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_put_file_by_filename : Sending file to server failed\n"));
+ goto err_handler;
+ }
+ } while (ulSize == (TFTP_BLKSIZE + TFTP_HDRSIZE));
+
+ /* Transfer of data is finished */
+ (void)lwip_close(iSockNum);
+ close(fp);
+ mem_free(pucBuffer);
+
+ ulErrCode = ERR_OK;
+err_handler:
+ mem_free(pstSendBuf);
+ return ulErrCode;
+}
+
+/* Put file function
+ iSockNum: Socket ID
+ pstSendBuf: Packet to send to server
+ ulSendSize: Packet length
+ usCurrBlk: Current block number
+ pstServerAddr: Server address
+*/
+u32_t lwip_tftp_inner_put_file(s32_t iSockNum,
+ TFTPC_PACKET_S *pstSendBuf,
+ u32_t ulSendSize,
+ u16_t usCurrBlk,
+ struct sockaddr_in *pstServerAddr)
+{
+ u32_t ulPktSize;
+ u32_t ulError;
+ s32_t iError;
+ int iRecvLen = 0;
+ socklen_t iFromAddrLen;
+ u32_t ulTotalTime = 0;
+ fd_set stReadfds;
+ struct sockaddr_in stFromAddr;
+ struct timeval stTimeout;
+ TFTPC_PACKET_S *pstRecvBuf = NULL;
+ u32_t ulIgnorePkt = 0;
+ u16_t usBlknum;
+ u32_t ulLoopCnt = 0;
+
+ iFromAddrLen = sizeof(stFromAddr);
+
+ pstRecvBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstRecvBuf == NULL) {
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ /* First time intialize the buffer */
+ (void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+
+ /* Initialize from address to the server address at first */
+ if (memcpy_s((void *)&stFromAddr, sizeof(struct sockaddr_in),
+ (void *)pstServerAddr, sizeof(stFromAddr)) != EOK) {
+ ulError = TFTPC_MEMCPY_FAILURE;
+ goto err_handler;
+ }
+
+ for (;;) {
+ ulError = lwip_tftp_recv_from_server(iSockNum, &ulPktSize,
+ pstRecvBuf, &ulIgnorePkt,
+ pstServerAddr, pstSendBuf);
+ /* If select timeout occured */
+ if (ulError == TFTPC_TIMEOUT_ERROR) {
+ ulTotalTime++;
+ if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
+ /*Max attempts not reached. Resend packet*/
+ ulError = lwip_tftp_send_to_server(iSockNum, ulSendSize,
+ pstSendBuf, pstServerAddr);
+ if (ulError != ERR_OK) {
+ goto err_handler;
+ }
+
+ continue;
+ } else {
+ /* return from the function, max attempts limit reached */
+ ulError = TFTPC_TIMEOUT_ERROR;
+ goto err_handler;
+ }
+ } else if (ulError != ERR_OK) {
+ /* return from the function, RecvFromServer failed */
+ goto err_handler;
+ }
+
+ /* If Received packet from another server */
+ if (ulIgnorePkt > 0) {
+ /* The packet that is received is to be ignored.
+ So continue without processing it. */
+ ulIgnorePkt = 0;
+ continue;
+ }
+
+ /* if this packet is unknown or incorrect packet */
+ if (TFTPC_OP_ACK != ntohs(pstRecvBuf->usOpcode)) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Protocol error.",
+ pstServerAddr, pstSendBuf);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_inner_put_file : Received pkt not Ack pkt\n"));
+
+ ulError = TFTPC_PROTO_ERROR;
+ goto err_handler;
+ }
+
+ ulTotalTime = 0;
+
+ /* if the packet is acknowledge packet */
+ usBlknum = ntohs(pstRecvBuf->u.usBlknum);
+ iRecvLen = (int)ulPktSize;
+
+ /* If not correct block no. */
+ if (usBlknum != usCurrBlk) {
+ /* we are not in sync now */
+ /* reset any collected packets. */
+ stTimeout.tv_sec = 1;
+ stTimeout.tv_usec = 0;
+
+ FD_ZERO(&stReadfds);
+ FD_SET(iSockNum, &stReadfds);
+
+ /*
+ Need to take care of timeout scenario in Select call.
+ Since the socket used is blocking, if select timeout occurs,
+ the following recvfrom will block indefinitely.
+ */
+ iError = select((s32_t)(iSockNum + 1), &stReadfds, 0, 0, &stTimeout);
+
+ /* Loop to get the last data packet from the receive buffer */
+ while ((iError != -1) && (iError != 0)) {
+ ulLoopCnt++;
+
+ /* MAX file size in TFTP is 32 MB.
+ Reason for keeping 75 here , is ((75*512=38400bytes)/1024) = 37MB. So the recv/Snd
+ Loop can receive the complete MAX message from the network.
+ */
+ if (ulLoopCnt > TFTPC_MAX_WAIT_IN_LOOP) {
+ LWIP_DEBUGF(TFTP_DEBUG,
+ ("lwip_tftp_inner_put_file : unexpected packets are received repeatedly\n"));
+ ulError = TFTPC_PKT_SIZE_ERROR;
+ goto err_handler;
+ }
+
+ FD_ZERO(&stReadfds);
+ FD_SET(iSockNum, &stReadfds);
+ iRecvLen = lwip_recvfrom(iSockNum,
+ (s8_t *)pstRecvBuf,
+ TFTP_PKTSIZE, 0,
+ (struct sockaddr *)&stFromAddr,
+ &iFromAddrLen);
+ if (TFTP_NULL_INT32 == iRecvLen) {
+ ulError = TFTPC_RECVFROM_ERROR;
+ goto err_handler;
+ }
+
+ stTimeout.tv_sec = 1;
+ stTimeout.tv_usec = 0;
+ iError = select((s32_t)(iSockNum + 1),
+ &stReadfds, 0, 0, &stTimeout);
+ }
+
+ /* If a new packet is not received then donot change the byte order
+ * as it has already been done
+ */
+ /* If received packet size < minimum packet size */
+ if (iRecvLen < TFTPC_FOUR) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Packet size < min packet size",
+ pstServerAddr, pstSendBuf);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_inner_put_file : Received pkt not Ack pkt\n"));
+
+ ulError = TFTPC_PKT_SIZE_ERROR;
+ goto err_handler;
+ }
+
+ /* Check if the received packet is from correct server and from
+ correct port
+ */
+ if ((stFromAddr.sin_addr.s_addr != pstServerAddr->sin_addr.s_addr) ||
+ (pstServerAddr->sin_port != stFromAddr.sin_port)) {
+ /* This ACK packet is invalid. Just ignore it. */
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_inner_put_file : Received pkt from unknown server\n"));
+ continue;
+ }
+
+ /* if this packet is not ACK packet */
+ if (TFTPC_OP_ACK != ntohs(pstRecvBuf->usOpcode)) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Protocol error.",
+ pstServerAddr, pstSendBuf);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_inner_put_file : Received pkt not Ack pkt\n"));
+
+ ulError = TFTPC_PROTO_ERROR;
+ goto err_handler;
+ }
+
+ usBlknum = ntohs(pstRecvBuf->u.usBlknum);
+ /*
+ * In this case we have received a duplicate ACK for data block.
+ * (ACK for this data block was aready received earlier)
+ * In this case we have usRecvBlkNum == (usNextBlkNum - 1).
+ * This could mean that:
+ * (i) last data packet that was sent was not received at server side
+ * (ii) Acknowledgement of peer side is delayed.
+ *
+ * In this case, this duplicate ACK will be ignored and return to the
+ * state machine to initiate a receive of this data packet.
+ */
+ if ((usCurrBlk - 1) == usBlknum) {
+ /* This ACK packet is invalid. Just ignore it. */
+ continue;
+ }
+
+ /* Now check the block number with current block.
+ * If it is not the previous block and the current block,
+ * then it is an unexpected packet.
+ */
+ if (usBlknum != usCurrBlk) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Received unexpected packet",
+ pstServerAddr, pstSendBuf);
+
+ LWIP_DEBUGF(TFTP_DEBUG,
+ ("lwip_tftp_inner_put_file : Received DATA pkt no. %"S32_F"instead of pkt no. %"S32_F"\n",
+ usBlknum, usCurrBlk));
+
+ ulError = TFTPC_SYNC_FAILURE;
+ goto err_handler;
+ }
+ }
+
+ ulError = ERR_OK;
+ goto err_handler;
+ }
+
+err_handler:
+ mem_free(pstRecvBuf);
+ return ulError;
+}
+
+#ifdef TFTP_TO_RAWMEM
+/* INTEFACE to get a file using filename
+ ulHostAddr - IP address of Host
+ szSrcFileName - Source file
+ szDestMemAddr - The target memory address in the client
+
+ Example :
+ ulHostAddr = ntohl(inet_addr ("192.168.1.3"));
+ lwip_tftp_get_file_by_filename_to_rawmem(ulHostAddr, "/ramfs/vs_server.bin", memaddr, &filelen);
+*/
+u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
+ u16_t usTftpServPort,
+ u8_t ucTftpTransMode,
+ s8_t *szSrcFileName,
+ s8_t *szDestMemAddr,
+ u32_t *ulFileLength)
+{
+ s32_t iSockNum = TFTP_NULL_INT32;
+ u32_t ulSrcStrLen;
+ u32_t lDestStrLen;
+ u32_t ulSize;
+ u32_t ulRecvSize = TFTP_NULL_UINT32;
+ s32_t iErrCode;
+ u32_t ulErrCode;
+ u16_t usReadReq;
+ u16_t usTempServPort;
+ u32_t ulCurrBlk = 1;
+ u32_t ulResendPkt = 0; /* Resend the previous packet */
+ u32_t ulIgnorePkt = 0; /* Ignore received packet */
+ u32_t ulTotalTime = 0;
+
+ TFTPC_PACKET_S *pstSendBuf = NULL;
+ TFTPC_PACKET_S *pstRecvBuf = NULL;
+ struct sockaddr_in stServerAddr;
+ u32_t ulMemOffset = 0;
+
+ /* Validate the parameters */
+ if ((szSrcFileName == NULL) || (szDestMemAddr == NULL) || (*ulFileLength == 0)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ if ((ucTftpTransMode != TRANSFER_MODE_BINARY) && (ucTftpTransMode != TRANSFER_MODE_ASCII)) {
+ return TFTPC_INVALID_PARAVALUE;
+ }
+
+ /* check IP address not within ( 1.0.0.0 - 126.255.255.255 )
+ and ( 128.0.0.0 - 223.255.255.255 ) range. */
+ if (!(((ulHostAddr >= TFTPC_IP_ADDR_MIN) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_RESV)) ||
+ ((ulHostAddr >= TFTPC_IP_ADDR_CLASS_B) &&
+ (ulHostAddr <= TFTPC_IP_ADDR_EX_CLASS_DE)))) {
+ return TFTPC_IP_NOT_WITHIN_RANGE;
+ }
+
+ /*Check validity of source filename*/
+ ulSrcStrLen = strlen(szSrcFileName);
+ if ((ulSrcStrLen == 0) || (ulSrcStrLen >= TFTP_MAX_PATH_LENGTH)) {
+ return TFTPC_SRC_FILENAME_LENGTH_ERROR;
+ }
+
+ pstSendBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstSendBuf == NULL) {
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ pstRecvBuf = (TFTPC_PACKET_S *)mem_malloc(sizeof(TFTPC_PACKET_S));
+ if (pstRecvBuf == NULL) {
+ mem_free(pstSendBuf);
+ return TFTPC_MEMALLOC_ERROR;
+ }
+
+ /* First time initialize the buffers */
+ (void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+ (void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
+
+ ulErrCode = lwip_tftp_create_bind_socket(&iSockNum);
+ if (ulErrCode != EOK) {
+ goto err_handler;
+ }
+
+ if (usTftpServPort == 0) {
+ usTftpServPort = TFTPC_SERVER_PORT;
+ }
+
+ usTempServPort = usTftpServPort;
+
+ /* set server IP address */
+ (void)memset_s(&stServerAddr, sizeof(stServerAddr), 0, sizeof(stServerAddr));
+ stServerAddr.sin_family = AF_INET;
+ stServerAddr.sin_port = htons(usTempServPort);
+ stServerAddr.sin_addr.s_addr = htonl(ulHostAddr);
+
+ /* Make a request packet - TFTPC_OP_RRQ */
+ ulSize = (u32_t)lwip_tftp_make_tftp_packet(TFTPC_OP_RRQ, szSrcFileName, (u32_t)ucTftpTransMode, pstSendBuf);
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize, pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* send to server failed */
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+
+ for (;;) {
+ if (ulIgnorePkt > 0) {
+ ulIgnorePkt = 0;
+ }
+
+ ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf, &ulIgnorePkt,
+ &stServerAddr, pstSendBuf);
+ /* If select timeout occured */
+ if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
+ ulTotalTime++;
+ if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
+ /* Max attempts not reached. Resend packet */
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+
+ continue;
+ } else {
+ /* return from the function, max attempts limit reached */
+ (void)lwip_close(iSockNum);
+ ulErrCode = TFTPC_TIMEOUT_ERROR;
+ goto err_handler;
+ }
+ } else if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+
+ /* Now we have receive block from different server. */
+ if (ulIgnorePkt > 0) {
+ /*Continue without processing this block. */
+ continue;
+ }
+
+ /* if this packet is unkonwn or incorrect packet */
+ if (ntohs (pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
+ /* Send error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Protocol error.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Received pkt not DATA pkt\n"));
+
+ ulErrCode = TFTPC_PROTO_ERROR;
+ goto err_handler;
+ }
+
+ /* Now the number of tries will be reset. */
+ ulTotalTime = 0;
+
+ /* Validate received DATA packet. */
+ ulErrCode = lwip_tftp_validate_data_pkt(iSockNum, &ulRecvSize,
+ pstRecvBuf, (u16_t)ulCurrBlk,
+ &ulResendPkt,
+ &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ /* Send Error packet to server */
+ if (ulErrCode != TFTPC_RECVFROM_ERROR) {
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Received unexpected packet",
+ &stServerAddr, pstSendBuf);
+ }
+
+ (void)lwip_close(iSockNum);
+
+ goto err_handler;
+ }
+
+ /* Received previous data block again. Resend last packet */
+ if (ulResendPkt > 0) {
+ /* Now set ulResendPkt to 0 to send the last packet. */
+ ulResendPkt = 0;
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+
+ goto err_handler;
+ }
+
+ /* Continue in loop to send last packet again. */
+ continue;
+ }
+
+ /* Get the size of the data block received */
+ ulRecvSize -= TFTP_HDRSIZE;
+
+ /* Check if the size of the received data block > max size */
+ if (ulRecvSize > TFTP_BLKSIZE) {
+ /* Send Error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_PROTO_ERROR,
+ "Packet size > max size",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Packet size > max size\n"));
+
+ ulErrCode = TFTPC_PKT_SIZE_ERROR;
+ goto err_handler;
+ }
+
+ usReadReq = (u16_t)TFTPC_OP_ACK;
+ pstSendBuf->usOpcode = htons(usReadReq);
+ pstSendBuf->u.usBlknum = htons((u16_t)ulCurrBlk);
+ ulSize = TFTP_HDRSIZE;
+
+ if (ulRecvSize != TFTP_BLKSIZE) {
+ (void)lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+
+ /* If the received packet has only header and do not have payload, the return failure */
+ if (ulRecvSize != 0) {
+ /* memcopy filed */
+ if (*ulFileLength < (ulMemOffset + ulRecvSize)) {
+ ulErrCode = TFTPC_MEMCPY_FAILURE;
+ (void)lwip_close(iSockNum);
+ *ulFileLength = ulMemOffset;
+ goto err_handler;
+ }
+ /* copy the last packet to the memory */
+ if (memcpy_s(szDestMemAddr + ulMemOffset, TFTP_MAX_BLK_NUM * TFTP_BLKSIZE,
+ (void *)pstRecvBuf->u.stTFTP_Data.ucDataBuf, (size_t)ulRecvSize) != EOK) {
+ ulErrCode = TFTPC_MEMCPY_FAILURE;
+ (void)lwip_close(iSockNum);
+ *ulFileLength = ulMemOffset;
+ goto err_handler;
+ }
+ ulMemOffset += ulRecvSize;
+ }
+
+ /* Now free allocated resourdes and return,
+ data block receiving is already completed */
+ (void)lwip_close(iSockNum);
+ ulErrCode = ERR_OK;
+ *ulFileLength = ulMemOffset;
+ goto err_handler;
+ }
+
+ ulErrCode = lwip_tftp_send_to_server(iSockNum, ulSize,
+ pstSendBuf, &stServerAddr);
+ if (ulErrCode != ERR_OK) {
+ (void)lwip_close(iSockNum);
+ goto err_handler;
+ }
+
+ /* memcopy filed */
+ if (*ulFileLength < ulRecvSize * ulCurrBlk) {
+ ulErrCode = TFTPC_MEMCPY_FAILURE;
+ (void)lwip_close(iSockNum);
+ *ulFileLength = ulMemOffset;
+ goto err_handler;
+ }
+ if (memcpy_s(szDestMemAddr + ulMemOffset, TFTP_MAX_BLK_NUM * TFTP_BLKSIZE,
+ (void *)pstRecvBuf->u.stTFTP_Data.ucDataBuf, (size_t)ulRecvSize) != EOK) {
+ ulErrCode = TFTPC_MEMCPY_FAILURE;
+ (void)lwip_close(iSockNum);
+ *ulFileLength = ulMemOffset;
+ goto err_handler;
+ }
+
+ ulMemOffset += ulRecvSize;
+ /* form the ACK packet for the DATA packet received */
+ /* Go to the next packet no. */
+ ulCurrBlk++;
+ /* if the file is too big, exit */
+ if (ulCurrBlk > TFTP_MAX_BLK_NUM) {
+ /* Send error packet to server */
+ lwip_tftp_send_error(iSockNum,
+ TFTPC_PROTOCOL_USER_DEFINED,
+ "File is too big.",
+ &stServerAddr, pstSendBuf);
+
+ (void)lwip_close(iSockNum);
+
+ LWIP_DEBUGF(TFTP_DEBUG, ("lwip_tftp_get_file_by_filename : Data block number exceeded max value\n"));
+
+ ulErrCode = TFTPC_FILE_TOO_BIG;
+ goto err_handler;
+ }
+ }
+
+err_handler:
+ mem_free(pstSendBuf);
+ mem_free(pstRecvBuf);
+ return ulErrCode;
+}
+#endif
+
+#endif /* LOSCFG_NET_LWIP_SACK_TFTP */
+#endif /* LWIP_TFTP */
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
old mode 100755
new mode 100644
diff --git a/arch/arm/arm.mk b/arch/arm/arm.mk
old mode 100755
new mode 100644
index 923518c91e643b282871a9dde97bd1f5c66e255e..6e765e9e973eb09ea9c64407a0050d1a79a43083
--- 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
index 24d47056b11cad0e784abdec6555fa99029695ad..d105536e72600dacc78a6e741e48f75cd5867d50 100755
--- 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:
@@ -35,6 +35,7 @@ LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/kernel/extended/include \
+ -I $(LITEOSTOPDIR)/kernel/extended/dynload/include \
-I $(LITEOSTOPDIR)/arch/arm/arm/include \
ifeq ($(LITEOS_ARM_ARCH), -march=armv7-a)
diff --git a/arch/arm/arm/include/arch_config.h b/arch/arm/arm/include/arch_config.h
index 09de16a48e0ff13eca9a39c2a318c82a66e051bc..53f09d0245303b432b7cc98842dd25da92b9cbdd 100755
--- 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
index bde3879349678e556111eba4b187ca43ebff9b11..c8a10adef555a4f71ce3cc3e6b48cc7f2578164f 100755
--- 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
index ac82b958744d3e9473d23804f7f69621349f6978..b86e37c47229c00f11db66ee19149cf92e3b03c6 100755
--- 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
index 53532107dd3f6a9a9942ac95a03d67096a570d06..43843e02804943f887ad441dca0a06cf5685d6c7 100755
--- 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
index cacae1b26b4551516a194f23d5d81f29830827a8..c5c475d35980fefa33b3fc1cee07ee2938bc9d4f 100755
--- 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
old mode 100755
new mode 100644
index c501b219702ddaafffba9ca5dd94a140b7a86ed2..93b2fd34495fbd9fbe00134f3467aa07d5ce65d0
--- 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
old mode 100755
new mode 100644
index eb343611a9dab70ec4f3a65f116dfc63d670259e..613982db08c127ff03a4af9dd293ef618a485466
--- 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
old mode 100755
new mode 100644
index d007b66e7a60d3e37f031dab423121c486bae811..702ea78ef5165db43dee44b947ad4132c3f4f3d1
--- 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
index 5585eebc7fe2118c7db0eb2a28cffd07b61f0f2c..45ecb23ee70463bda078db92f4a3b258a9bfc87b 100755
--- 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
index 1eb04229ea3bf412033e8acf19e741979920ab9b..6f93de03a91948aee39afc414b94b0d99450d7d2 100755
--- 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 \
@@ -158,7 +162,7 @@ extern "C" {
#define MMU_DESCRIPTOR_L2_AP01_0 (MMU_DESCRIPTOR_L2_AP01(0))
#define MMU_DESCRIPTOR_L2_AP01_1 (MMU_DESCRIPTOR_L2_AP01(1))
#define MMU_DESCRIPTOR_L2_AP01_3 (MMU_DESCRIPTOR_L2_AP01(3))
-#define MMU_DESCRIPTOR_L2_AP_P_NA_U_NA (MMUDESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_0)
+#define MMU_DESCRIPTOR_L2_AP_P_NA_U_NA (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_0)
#define MMU_DESCRIPTOR_L2_AP_P_RW_U_RW (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_3)
#define MMU_DESCRIPTOR_L2_AP_P_RW_U_NA (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_1)
#define MMU_DESCRIPTOR_L2_AP_P_RO_U_RO (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_3)
@@ -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
old mode 100755
new mode 100644
index 5d6c2b74cd87119472f96717e8eb3029f110f083..6d1bee534dacc27ce7e5e9b28320ee02f703100f
--- 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
old mode 100755
new mode 100644
index 5ccacaf58f1a09a27a316772fe3134efadc33dce..7257babeb20977286716ea201583fcb81a049912
--- 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
old mode 100755
new mode 100644
index cdcbee06603bbeed76053828ccaef3cd9ef5e445..0970d4538e66f39281d0d52d2c37bada7c966ca1
--- 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
index 820d48ecefc224ea2b440dc9f46cca1210c061e2..32711f605be53f3e8c49dc1062bf725ea389b012 100755
--- 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
index 941efe7ed4d0f2b6f04dca9aa6388ad0a30ca75b..d79e509c0c78544b0d4f4525e957c840cfb4c11c 100755
--- 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
index 796e14c0559eefe6cacdb3477a1138e514d817fb..96ea07addb849edcc4b33c5c4e73a2b78819a5dc 100755
--- 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
old mode 100755
new mode 100644
index 4031217b4c725583fd6ea4df40cf1faf87ee3944..e1e9c4873a37e5fab943fb77ed694fe41642e7b2
--- 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
index 5d470b348abc3f0c6a94978d13b43cbcc2e505cd..052da990a59ae488b59246c6592c4a51e6c39eeb 100755
--- 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
old mode 100755
new mode 100644
index ea1726b629e363ac2eaf7091e73399684d80726b..ad8e589c9c1210c8c1d0f699e7449b84e1f20ab7
--- 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
old mode 100755
new mode 100644
index 209b4e8a9e7bea72270f4c56b4b24a1f3001f8c6..14dd05a39256be9e5693b7cb6a1942f7acd40f48
--- 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
index 7d7cf935c162f659acc4593966b383da29d05bee..3e046193ddd4fc6a493bf48102f7cc8969ad0b8b 100755
--- 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;
+}
+
+STATIC UINT32 OsCvtSecAccessFlagsToMMUFlags(UINT32 flags)
+{
+ UINT32 mmuFlags = 0;
- switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
+ 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_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:
- mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_RO;
- 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;
+}
+
+STATIC UINT32 OsCvtPte2AccessFlagsToMMUFlags(UINT32 flags)
+{
+ UINT32 mmuFlags = 0;
- switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
+ 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_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:
- mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_RO;
- 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;
@@ -624,8 +682,7 @@ STATUS_T LOS_ArchMmuChangeProt(LosArchMmu *archMmu, VADDR_T vaddr, size_t count,
status = LOS_ArchMmuUnmap(archMmu, vaddr, 1);
if (status < 0) {
- VM_ERR("invalid args:aspace %p, vaddr %p, count %d",
- __FUNCTION__, __LINE__, archMmu, vaddr, count);
+ VM_ERR("invalid args:aspace %p, vaddr %p, count %d", archMmu, vaddr, count);
return LOS_NOK;
}
@@ -832,7 +889,7 @@ STATIC VOID OsSetKSectionAttr(VOID)
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE);
if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
- VM_ERR("unmap failed, status: %d", status);
+ VM_ERR("mmap failed, status: %d", status);
return;
}
LOS_VmSpaceReserve(kSpace, kmallocLength, bssEndBoundary);
diff --git a/arch/arm/arm/src/los_asid.c b/arch/arm/arm/src/los_asid.c
old mode 100755
new mode 100644
index 72b4d7097f1f9359a3a3cc43c22d700bc56b052b..b92dae2708b07ac486d72dbd163c1e81015bc851
--- 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
index add17d0ffcda8efe93dfc7769e8effd700cc103b..1f9c24697564c51472c7ba8e09a671918b8a262e 100755
--- 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
index 989cf2e32498c569524c2f4f08fa9e9c3d2664a2..de57d93cfc9d6a79c523b016c9879c6b13a3ef27 100755
--- 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:
@@ -55,6 +55,7 @@
#include "los_vm_phys.h"
#include "los_vm_fault.h"
#include "los_vm_common.h"
+#include "los_load_elf.h"
#include "arm.h"
#include "los_bitmap.h"
#include "los_process_pri.h"
@@ -255,6 +256,39 @@ STATIC const CHAR *g_excTypeString[] = {
"irq"
};
+STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess)
+{
+ struct file *curFilep = NULL;
+ struct file *lastFilep = NULL;
+ LosVmMapRegion *curRegion = NULL;
+ LosVmMapRegion *lastRegion = NULL;
+
+ if ((region == NULL) || (runProcess == NULL)) {
+ return 0;
+ }
+
+ if (!LOS_IsRegionFileValid(region)) {
+ return region->range.base;
+ }
+
+ lastRegion = region;
+ do {
+ curRegion = lastRegion;
+ lastRegion = LOS_RegionFind(runProcess->vmSpace, curRegion->range.base - 1);
+ if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) {
+ goto DONE;
+ }
+ curFilep = curRegion->unTypeData.rf.file;
+ lastFilep = lastRegion->unTypeData.rf.file;
+ } while (!strcmp(curFilep->f_path, lastFilep->f_path));
+
+DONE:
+ if (curRegion->range.base == EXEC_MMAP_BASE) {
+ return 0;
+ }
+ return curRegion->range.base;
+}
+
STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
{
LosTaskCB *runTask = OsCurrTaskGet();
@@ -289,7 +323,7 @@ STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->PC);
if (region != NULL) {
PrintExcInfo("in %s ---> 0x%x", OsGetRegionNameOrFilePath(region),
- (VADDR_T)excBufAddr->PC - region->range.base);
+ (VADDR_T)excBufAddr->PC - OsGetTextRegionBase(region, runProcess));
}
}
@@ -297,7 +331,7 @@ STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->ULR);
if (region != NULL) {
PrintExcInfo("in %s ---> 0x%x", OsGetRegionNameOrFilePath(region),
- (VADDR_T)excBufAddr->ULR - region->range.base);
+ (VADDR_T)excBufAddr->ULR - OsGetTextRegionBase(region, runProcess));
}
PrintExcInfo("\nusp = 0x%x", excBufAddr->USP);
} else {
@@ -307,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)
@@ -388,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;
}
@@ -510,6 +544,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
OsProcessExitCodeCoreDumpSet(runProcess);
#endif
OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
+
/* kill user exc process */
LOS_Exit(OS_PRO_EXIT_OK);
@@ -750,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);
}
@@ -971,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");
+ }
}
/*
@@ -987,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();
@@ -1036,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) {}
}
@@ -1058,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
index dbc24d2cbf52b87eefbc083a3969a982f963397b..800bf1b99b06430b5df4ee680a2dfa894d0e1e39 100755
--- 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
index 25d8639c3b8768fde0031cb1b8baf6c9af5d2c51..5dd00c78c1fbfe6453f0395fca6f9411e56526d4 100755
--- 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:
@@ -57,7 +57,11 @@
.global _osExceptPrefetchAbortHdl
.global _osExceptSwiHdl
.global _osExceptUndefInstrHdl
+#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
+ defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
+ defined(LOSCFG_CC_STACKPROTECTOR)
.global __stack_chk_guard_setup
+#endif
.fpu vfpv4
@@ -147,15 +151,22 @@
.endm
#endif
+#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
+ defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
+ defined(LOSCFG_CC_STACKPROTECTOR)
@ Description: Stack-Protector Init
__stack_chk_guard_setup:
PUSH {FP, LR}
+#if defined(LOSCFG_PLATFORM_HI3516DV300) || defined(LOSCFG_PLATFORM_HI3518EV300)
+ /* Randomize __stack_chk_quard using platform-specific function. */
BL OsRandomStackGuard
LDR R1, =__stack_chk_guard
MOV R3, R0
ORR R2, R3, #0X80000000
STR R2, [R1]
+#endif
POP {FP, PC}
+#endif
@ Description: Undefined instruction exception handler
_osExceptUndefInstrHdl:
diff --git a/arch/arm/arm/src/los_hw_runstop.S b/arch/arm/arm/src/los_hw_runstop.S
old mode 100755
new mode 100644
index 032e9af12e99c72e098f33c30f2758ef0f8da845..b8f8cf7455463bd23a8e11b4d5a25f2c6bd694c5
--- 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
old mode 100755
new mode 100644
index b52f346c29d0a67105eb3f643beff1b71f0484d9..b53bdfa265023fef35844de9e021bf65e000bbf4
--- 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
old mode 100755
new mode 100644
index 733fc0103402b531c9e3ca5cf83e15d05b68d7fe..5bac58950c85137f560ca9e019956c78d70d4b65
--- 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
index dc08b6dc55f3008e43723a48944771d579322ad1..cec87786964d26a9641127c128fc4568df01c83f 100755
--- 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
index d7de47773eed9519c6fca4563f2a50bcbf9b33e1..63ac57641ba8c2205b91bdab6a535c966ecc9b86 100755
--- 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
index 0e307f64480f898c28013eb05f41b67ff1d08173..352b9310220038eb17433de9113aecba2b607942 100755
--- 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
index b34d090b5176e52679977bbcca53edf70a742f22..4da0bf4906704a2f32b3251e0ed2c17b51d32414 100755
--- 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
index 13e23baadd2b39734da7f03114d2c1b31124ac5e..f1016f00807f302e38bf28493d62c91d9e4e8994 100755
--- 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
index 8920b1df150dcbac070021c3b101ac3bef804f57..e86c496654aef768b2ac1bb746f279703523a5ed 100755
--- 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
index 62cbe6ff70482f22c9a078eef1d7bddda0bb6a18..807bcb2fad1db91571b8a0951118c9cd9e910440 100755
--- 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
index c9d5825c38d09f8d04a506559d1432d79197aa98..ad30d5a1836c9c8003e306fe2011cd7ce4c84eab 100755
--- 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
old mode 100755
new mode 100644
index f7bd812ad8a80ad680aa4f3f33d55e4c7d7bc020..3539d928fad82eaefa502f487c687f32eadcdda5
--- 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
old mode 100755
new mode 100644
index 98a7296b3b52dc688b089e22bc71ebb06a41f272..1b8931762e938ce12175b1da81cc15371d6361a5
--- 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
index b8bcadb970dadde2d568bf6131d3f2b5f7e8cf8e..cee783dcccde3626b032c214bae96c5e9e40528c 100755
--- 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
index 764be8a22b27fa7b13157d1b121ee3592e885006..58d68d9be6a1e9e702ccc90ecc9f57edb3bde69a 100755
--- 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
index 5c90d5906e244d2d13c36d9296af8b930ef29370..29c3e67980322dabe24ff0741d279b2c9311626f 100755
--- 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
old mode 100755
new mode 100644
index 0dbc46d10879a121060981026ca0144832f76344..e45e4a66f50ec1ec2777663b0ff64daca6a1b580
--- 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
index 883d299ea564d42ee0b3205c2eb59ac8b36ab969..2ce55a0106f28866dbcd502bc3e1c895716bd658 100755
--- 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
index bec15dae7c490c3e9be4f5af5551597e9af25a0d..c0251623a4db5cdb17f40b934205a6dc04c03b2c 100755
--- 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
index 955634ec5e9b80c70e4e441b612f0de72a81d423..293d4e34d80af75d58a674e143edfd3012933d75 100755
--- 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
old mode 100755
new mode 100644
index c1af11ac57b6eec47e6e01500fb8a1fcf76cf387..856099ef7462fd3f3aa6e37f6cac0266b5121ca8
--- 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/Makefile b/bsd/Makefile
old mode 100755
new mode 100644
index 9540092d36a62b13d7540a54f44bf0a624692800..a5c0d1ffe3edc391e03bfd89252f77ded4b6c323
--- 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
index 5244c46976b5a48ebec3cd1be89205deb7d1aa3c..1b270ae19c4a62c192b1d01833f4063f9b3f9ada 100755
--- 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:
@@ -33,6 +33,10 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
+ifneq ($(LOSCFG_HRTIMER_ENABLE), y)
+LOCAL_SRCS := $(filter-out src/linux_hrtimer.c, $(LOCAL_SRCS))
+endif
+
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
diff --git a/bsd/dev/usb/Makefile b/bsd/dev/usb/Makefile
index 5eaa4120d32bac7eb84cae7e622c98d54ca733ff..a0fb6e8837bebed2867c8adeb42fec65dc6c68f5 100755
--- 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 bcdf9009c6a35c8b1d9478186827acf5eefb5cd9..6ad37db5d67823d6908ef8f90c564bb5325044b4 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/Makefile b/compat/posix/Makefile
old mode 100755
new mode 100644
index 02c6cc9f84a573eea26e964f403d6dd65458149b..c9cd39b06a8344b4d37337898cd1e113750b2c52
--- 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
index c32b158d10dd96336e66d1ce2baeb1039ee3a67f..eb58bd0669684d477979b833300c8a8f48569fbc 100755
--- 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
index 0665d21b64097537c97e364b9ad467db2b1792cf..6f8f537d131f9f9aad55d45f7430635f74da1505 100755
--- 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
old mode 100755
new mode 100644
index d2cdf013a465c0d719d4a401ebc7254254ac3851..31435f7d8ff1ee75a88d17e76f775689d1decb12
--- 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
old mode 100755
new mode 100644
index 4731a32cdf5e1f460e6f96bd73c771db648df425..935b2d5e8124885dc61ed015d5631405f4e78def
--- 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
index 98152931202be05e95c2d00721f1735a65eabda0..3e623674e5699e037f7e6f805a4e4e291ae8f1e2 100755
--- 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
index 0aa2705db3d1b69905cbd16e67d8a4cd0c0a7186..588ae11293b57bcf62ca3c11d0be2b4b38fd84bc 100755
--- 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
old mode 100755
new mode 100644
index 40af37dd67af6fd85f07835033450b8269af2aba..59e85702f9c8663653852c63762cc2e0fba56c07
--- 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
old mode 100755
new mode 100644
index e484c81ad140f908052f32883f9cd9c51860ec1f..85f358ef800288e1e71dca73cb24a55eef4bd538
--- 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
index 372fbe56165fe38ffe05a1edee2f55924daa1d5e..4fca2c13dd579fe78c77220ea6e5d82a86ff6e78 100755
--- 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
@@ -203,10 +204,9 @@ STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr,
return LOS_NOK;
}
userAttr->stacksize = taskCB->stackSize;
- err = memcpy_s(taskCB->taskName, OS_TCB_NAME_LEN, created->name, strlen(created->name));
- if (err != EOK) {
+ err = OsSetTaskName(taskCB, created->name, FALSE);
+ if (err != LOS_OK) {
PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err);
- taskCB->taskName[0] = '\0';
return LOS_NOK;
}
#if (LOSCFG_KERNEL_SMP == YES)
@@ -224,7 +224,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
{
pthread_attr_t userAttr;
UINT32 ret;
- CHAR name[PTHREAD_DATA_NAME_MAX];
+ CHAR name[PTHREAD_DATA_NAME_MAX] = {0};
STATIC UINT16 pthreadNumber = 1;
TSK_INIT_PARAM_S taskInitParam = {0};
UINT32 taskHandle;
@@ -236,7 +236,6 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
SetPthreadAttr(self, attr, &userAttr);
- (VOID)memset_s(name, sizeof(name), 0, sizeof(name));
(VOID)snprintf_s(name, sizeof(name), sizeof(name) - 1, "pth%02d", pthreadNumber);
pthreadNumber++;
diff --git a/compat/posix/src/pthread_attr.c b/compat/posix/src/pthread_attr.c
old mode 100755
new mode 100644
index ec3764be65933f56deefcfb232ec5b3be741c122..736c898a5924dd706c076a303e3ad2e990ff1725
--- 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
index 0f824902b3d98ba3de81a864a72d7cea8021af17..1b9e320341164f69c200ec3d081dff80ac9c79e9 100755
--- 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
index d12a3828aa74c0b321eeb97a598b183104ab6408..b4ab40150612a42c8326f69c63b056a0d7bc13f5 100755
--- 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
old mode 100755
new mode 100644
index d48413034b4bb1d9a2532490c5b9bdde262ca8f1..feb713d8f127f0443c3824e3a33233d61ee31b61
--- 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
index 425259ba952c82965241b927fb6e054697345f3a..63039039c871ee59944a42bd20da7a110b0fb3b2 100755
--- 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
old mode 100755
new mode 100644
index f29443dc168896a15e07eea178e558688d62b932..23d00cf701a89ef52582364b100b448fad6c73df
--- 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
index d3a42f4eb7f912e73b5b65f0e4bcac30c47a7e06..462ea7c0d8c354b9f5f1028292bc5446435e6ad5 100755
--- 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
index 04f95d535855202b78ff4d1d525d9c182e657177..50fd88773a8fb7708f37f42a1fd763f977102e18 100755
--- 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 0000000000000000000000000000000000000000..7cfed49266d613441198dea7dfb6d9a1d087033d
--- /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 0000000000000000000000000000000000000000..4e35bd1bdebf88811cf46eb8f46c35775c811aaf
--- /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/net/lwip-2.1/porting/src/fixme.c b/drivers/char/mem/include/los_dev_mem.h
old mode 100755
new mode 100644
similarity index 73%
rename from net/lwip-2.1/porting/src/fixme.c
rename to drivers/char/mem/include/los_dev_mem.h
index e7b1268faa2af677c0c2172e7b6d3eacee66e036..cb5989e8ae145cb2eb51c526c644c6db7a3fcfb3
--- a/net/lwip-2.1/porting/src/fixme.c
+++ 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,18 +29,23 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include
-#include
+#ifndef __LOS_DEV_MEM_H__
+#define __LOS_DEV_MEM_H__
-err_t dhcp_is_bound(struct netif *netif)
-{
- return (netif_dhcp_data(netif) ? (netif_dhcp_data(netif)->state == DHCP_STATE_BOUND) ? ERR_OK : ERR_INPROGRESS : ERR_ARG);
-}
+#include "los_typedef.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
-#if (LWIP_CHKSUM_ALGORITHM == 4) /* version #4, asm based */
-#include "in_cksum.h"
-u16_t lwip_standard_chksum(const void *dataptr, int len)
-{
- return ~(u16_t)(in_cksum(dataptr, len));
+extern int DevMemRegister(void);
+
+#ifdef __cplusplus
+#if __cplusplus
}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
#endif
diff --git a/kernel/base/mem/common/memrecord/los_interto64radix.c b/drivers/char/mem/src/mem.c
old mode 100755
new mode 100644
similarity index 51%
rename from kernel/base/mem/common/memrecord/los_interto64radix.c
rename to drivers/char/mem/src/mem.c
index ecf91dac07092faa0e2e708312a4650268991167..df82cd07895854449b14ce793aa2e57e7d04b6fe
--- 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 0000000000000000000000000000000000000000..4e35bd1bdebf88811cf46eb8f46c35775c811aaf
--- /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/kernel/base/include/los_timeslice_pri.h b/drivers/char/quickstart/include/los_quick_start.h
old mode 100755
new mode 100644
similarity index 66%
rename from kernel/base/include/los_timeslice_pri.h
rename to drivers/char/quickstart/include/los_quick_start.h
index 99f159ca0d4a4c854b6ff33a5f81471d1bab128d..c9b970826c1064ef1bbb4aae0a26845431a83b84
--- a/kernel/base/include/los_timeslice_pri.h
+++ b/drivers/char/quickstart/include/los_quick_start.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,44 +29,18 @@
* 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_H__
+#define __LOS_QUICK_START_H__
#include "los_typedef.h"
-#ifdef __cplusplus
+fdef __cplusplus
#if __cplusplus
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);
+extern int DevQuickStartRegister(void);
#ifdef __cplusplus
#if __cplusplus
@@ -74,4 +48,4 @@ extern VOID OsTimesliceCheck(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* _LOS_TIMESLICE_PRI_H */
+#endif
diff --git a/kernel/extended/include/los_tickless_pri.h b/drivers/char/quickstart/include/los_quick_start_pri.h
old mode 100755
new mode 100644
similarity index 72%
rename from kernel/extended/include/los_tickless_pri.h
rename to drivers/char/quickstart/include/los_quick_start_pri.h
index 7116aa8eec03bec16c399c606616d2f4453830b3..012b548e4db602e8331ebb2b4260e740c7812d53
--- a/kernel/extended/include/los_tickless_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,10 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _LOS_TICKLESS_PRI_H
-#define _LOS_TICKLESS_PRI_H
+#ifndef __LOS_QUICK_START_PRI_H__
+#define __LOS_QUICK_START_PRI_H__
-#include "los_tickless.h"
+#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
@@ -40,15 +40,8 @@ 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);
+unsigned int OsSystemInitStep2(void);
+extern VOID SystemInit2(VOID);
#ifdef __cplusplus
#if __cplusplus
@@ -56,4 +49,4 @@ extern VOID OsTicklessUpdate(UINT32 irqNum);
#endif /* __cplusplus */
#endif /* __cplusplus */
-#endif /* _LOS_TICKLESS_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 0000000000000000000000000000000000000000..8b4e8a57a6a0e90f7eabe6fe9577dd9c9a90bcbc
--- /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 0000000000000000000000000000000000000000..5574bef6b45f431f57b7f587880cfb4565aa7cf9
--- /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 0000000000000000000000000000000000000000..edd03c4a4df96215cfd33a35a405ef53d9e57f5f
--- /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
old mode 100755
new mode 100644
similarity index 63%
rename from kernel/base/include/los_memrecord_pri.h
rename to drivers/char/random/include/los_random.h
index daa102e25426f6028aa6537714483140031dd268..298449ea78b86b07f4aeb046e65ac12569734036
--- 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)
-typedef struct {
- UINT32 addrID;
- UINT32 taskID;
- UINT32 reqSizeID;
- UINT32 allocatedSizeID;
- UINT32 actType;
- UINT64 sysTick;
- UINT32 linkRegID;
-} MemRecordInfo;
-
-#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);
+int DevRandomRegister(void);
+int DevUrandomRegister(void);
+typedef struct {
+ 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;
-#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 0000000000000000000000000000000000000000..9ef114d6cf8c59e709445d9175a21e2b2140c33e
--- /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 0000000000000000000000000000000000000000..fe412ee6fa414b2444037f61aaf3bca72caf73e7
--- /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 0000000000000000000000000000000000000000..3fad196adbb2919427acd9c07af545b610849e38
--- /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
old mode 100755
new mode 100644
similarity index 83%
rename from kernel/extended/tickless/Makefile
rename to drivers/char/video/Makefile
index 813c1296f5b32558e5d81c4d631adcc697593b8c..790d2e6247b5d8ff9eecbc89af0ac88f66fbf0c3
--- 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\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" "b/figures/OpenHarmony-LiteOS-A\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png"
new file mode 100644
index 0000000000000000000000000000000000000000..b2ff552d12a62fb207505772fc4c8cad29262022
Binary files /dev/null and "b/figures/OpenHarmony-LiteOS-A\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.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 0000000000000000000000000000000000000000..27b8a0e059ea26e2eb4e53c27afd76f722761550
Binary files /dev/null and b/figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png differ
diff --git a/fs/fat/Makefile b/fs/fat/Makefile
index ad65ab6ba5931e1cab60a579ac80663be2c625f8..ce37249085bdc7e56722284eb15f75f2ecfda7ab 100755
--- 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 0000000000000000000000000000000000000000..0515cf15324dd4b32307c8731ff9c3c73772a130
--- /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 0000000000000000000000000000000000000000..2f9b9fa2f77af4430f7bfa32c8a53150024999f5
--- /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
old mode 100755
new mode 100644
index 2720a2ea2a91b8a3323b4b6afbbd8db09fae1e4f..0648d29c7e96103a84c1258de30fc4b9493a6bd3
--- 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
index 1bf4173ab93478a1d2ccf9017f69698317b62acf..e282910950334ab8c06ef81e7e42938e64d56b75 100755
--- 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:
@@ -348,8 +348,6 @@ int fatfs_bind(struct inode *blkdriver, const void *data, void **handle, const c
los_part *part = NULL;
char drive[DRIVER_NAME_LEN];
struct FatfsMountOpts opts = {0};
- struct inode_search_s desc;
- FAR struct inode *inode;
FatParseOptions((char *)data, &opts);
@@ -424,6 +422,8 @@ int fatfs_bind(struct inode *blkdriver, const void *data, void **handle, const c
free(dir);
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
/* Parent Partition Mount Success, then process virtual partition mount operation */
+ struct inode_search_s desc;
+ FAR struct inode *inode;
if (result == FR_OK) {
if (fat->fs_type != FS_FAT32)
return VIRERR_NOTFIT;
@@ -472,8 +472,6 @@ int fatfs_unbind(void *handle, struct inode **blkdriver)
INT result;
los_part *part = NULL;
char drive[DRIVER_NAME_LEN];
- struct inode_search_s desc;
- FAR struct inode *inode;
fat = (FATFS *)handle;
if (fat == NULL)
@@ -487,12 +485,14 @@ int fatfs_unbind(void *handle, struct inode **blkdriver)
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
/* Release virtual partition objects before unbind real partition */
+ struct inode_search_s desc;
+ FAR struct inode *inode;
SETUP_SEARCH(&desc, g_fatVirPart.virtualinfo.devpartpath, false);
FatfsVirtLock();
result = FatFsUnbindVirPart(fat);
- FatfsVirtLock();
+ 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]);
- /*
- * 0x00:Reached end of directory.
- * 0xFF:The directory is empty.
- */
- if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
- return -ENOENT;
- }
+ (void)memset_s(&fno, sizeof(FILINFO), 0, sizeof(FILINFO));
+ result = f_readdir(fdir, &fno);
+ if (result != FR_OK) {
+ break;
+ }
- if (fno.fattrib & AM_DIR) {
- d->d_type = DT_DIR;
- } else {
- d->d_type = DT_REG;
- }
+ /*
+ * 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;
+ }
- 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;
+ }
- 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++;
}
- 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 0000000000000000000000000000000000000000..cae3ec676a9f95108d27b33a9e73618b554cd3c2
--- /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 0000000000000000000000000000000000000000..6ffbfb6ac27d78072841e2543477cab40620a0c1
--- /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
index f594da53b22d43899800715acda8c94fbe145b71..3ba118c31c7904e25a370fb072c6858df475c903 100755
--- 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
old mode 100755
new mode 100644
index 44a8dbc5cd37fbc6b400efb6453930ba53182788..4341c8290a3590b68d2162660c3eb6a525b1b12a
--- 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
old mode 100755
new mode 100644
index 323d8b8a28e9db3a467728fb46b0abe13a57fb13..f1a24149417a3e6d4f9cdc432adcadaf6719ce52
--- 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
old mode 100755
new mode 100644
index d90848ca08a361c08cb04689525f8ccc8bffd752..dd5700c45bcea6409db24ca3ea69c7080eb78751
--- 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
old mode 100755
new mode 100644
index 1bed9afc3c4722d286efbc73171f44fb44b4582a..f20b6ed99ed71a881b9241e2941bc72619a60c69
--- 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:
@@ -96,95 +96,95 @@ extern FATFS *FatFs[FF_VOLUMES];
*/
FRESULT follow_virentry(FFOBJID *obj, const TCHAR *path)
{
-TCHAR keyword[FF_MAX_LFN + 1] = {0};
-FATFS *fs = obj->fs;
-INT len;
-UINT i;
-
-(void)memset_s(keyword, sizeof(keyword), 0, sizeof(keyword));
-/* Search and copy the first segment in path */
-for (len = 0; *path != '/' && *path != '\\' && *path != '\0' && len < FF_MAX_LFN; path++, len++) {
-keyword[len] = *path;
-}
+ TCHAR keyword[FF_MAX_LFN + 1] = {0};
+ FATFS *fs = obj->fs;
+ INT len;
+ UINT i;
+
+ (void)memset_s(keyword, sizeof(keyword), 0, sizeof(keyword));
+ /* Search and copy the first segment in path */
+ for (len = 0; *path != '/' && *path != '\\' && *path != '\0' && len < FF_MAX_LFN; path++, len++) {
+ keyword[len] = *path;
+ }
-if (len == 0 || len > _MAX_ENTRYLENGTH) {
-return FR_DENIED;
-}
+ if (len == 0 || len > _MAX_ENTRYLENGTH) {
+ return FR_DENIED;
+ }
-/*
-* Compare the segment does match one for virtual partitions' entry or not,
-* replace the FATFS if the result is positive
-*/
-for (i = 0; i < fs->vir_amount; i++) {
-if (!CHILDFS(fs, i)) {
- return FR_INT_ERR;
-}
-if (memcmp((CHILDFS(fs, i))->namelabel, keyword, _MAX_ENTRYLENGTH + 1) == 0) {
- obj->fs = CHILDFS(fs, i);
- return FR_OK;
-}
-}
+ /*
+ * Compare the segment does match one for virtual partitions' entry or not,
+ * replace the FATFS if the result is positive
+ */
+ for (i = 0; i < fs->vir_amount; i++) {
+ if (!CHILDFS(fs, i)) {
+ return FR_INT_ERR;
+ }
+ if (memcmp((CHILDFS(fs, i))->namelabel, keyword, _MAX_ENTRYLENGTH + 1) == 0) {
+ obj->fs = CHILDFS(fs, i);
+ return FR_OK;
+ }
+ }
-return FR_DENIED;
+ return FR_DENIED;
}
FRESULT f_checkname(const TCHAR *path)
{
-FRESULT res;
-DIR dj;
-FATFS fs;
-TCHAR *label = (TCHAR *)path;
-DEF_NAMBUF
-
-(void)memset_s(&fs, sizeof(fs), 0, sizeof(fs));
-dj.obj.fs = &fs;
-INIT_NAMBUF(&fs);
-res = create_name(&dj, &path);
-/* the last byte of file name can't be a space */
-if (res == FR_OK && dj.fn[11] == 0x20) {
-res = FR_INVALID_NAME;
-return res;
-}
+ FRESULT res;
+ DIR dj;
+ FATFS fs;
+ TCHAR *label = (TCHAR *)path;
+ DEF_NAMBUF
+
+ (void)memset_s(&fs, sizeof(fs), 0, sizeof(fs));
+ dj.obj.fs = &fs;
+ INIT_NAMBUF(&fs);
+ res = create_name(&dj, &path);
+ /* the last byte of file name can't be a space */
+ if (res == FR_OK && dj.fn[11] == 0x20) {
+ res = FR_INVALID_NAME;
+ return res;
+ }
-FREE_NAMBUF();
+ FREE_NAMBUF();
-for (; *label != '\0'; label++) {
-if (label - path > _MAX_ENTRYLENGTH) {
- res = FR_INVALID_NAME;
- return res;
-}
-if (*label == '/' || *label == '\\') {
- res = FR_INVALID_NAME;
+ for (; *label != '\0'; label++) {
+ if (label - path > _MAX_ENTRYLENGTH) {
+ res = FR_INVALID_NAME;
+ return res;
+ }
+ if (*label == '/' || *label == '\\') {
+ res = FR_INVALID_NAME;
+ return res;
+ }
+ }
return res;
}
-}
-return res;
-}
FATFS *f_getfatfs(int vol)
{
-FATFS *fs = NULL;
-if (vol < 0 || vol >= FF_VOLUMES) {
-fs = NULL;
-} else {
-fs = FatFs[vol];
-}
-return fs;
+ FATFS *fs = NULL;
+ if (vol < 0 || vol >= FF_VOLUMES) {
+ fs = NULL;
+ } else {
+ fs = FatFs[vol];
+ }
+ return fs;
}
static FRESULT FatfsCheckBoundParam(FATFS *fs, DWORD clust)
{
-if (fs->st_clst <= 2 || (fs->st_clst + fs->ct_clst) > fs->n_fatent) {
-return FR_INT_ERR;
-}
-if (clust < 2 || clust > fs->n_fatent) {
-return FR_INT_ERR;
-}
-if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
-return FR_CHAIN_ERR;
-}
+ if (fs->st_clst <= 2 || (fs->st_clst + fs->ct_clst) > fs->n_fatent) {
+ return FR_INT_ERR;
+ }
+ if (clust < 2 || clust > fs->n_fatent) {
+ return FR_INT_ERR;
+ }
+ if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
+ return FR_CHAIN_ERR;
+ }
-return FR_OK;
+ return FR_OK;
}
/*
@@ -197,38 +197,38 @@ return FR_OK;
*/
FRESULT f_boundary(FATFS *fs, DWORD clust)
{
-FFOBJID obj;
-FRESULT res;
-obj.fs = fs;
-if (fs == NULL) {
-return FR_INT_ERR;
-}
-if (fs->fs_type != FS_FAT32) {
-return FR_INVAILD_FATFS;
-}
-ENTER_FF(fs);
+ FFOBJID obj;
+ FRESULT res;
+ obj.fs = fs;
+ if (fs == NULL) {
+ return FR_INT_ERR;
+ }
+ if (fs->fs_type != FS_FAT32) {
+ return FR_INVAILD_FATFS;
+ }
+ ENTER_FF(fs);
-res = FatfsCheckBoundParam(fs, clust);
-if (res != FR_OK) {
-LEAVE_FF(fs, res);
-}
-for (; ;) {
-clust = get_fat(&obj, clust);
-if (clust == 0xFFFFFFFF) {
- LEAVE_FF(fs, FR_DISK_ERR);
-}
-if (clust == 0x0FFFFFFF) {
- break;
-}
-if (clust < 2 || clust >= fs->n_fatent) {
- LEAVE_FF(fs, FR_INT_ERR);
-}
-if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
- LEAVE_FF(fs, FR_CHAIN_ERR);
-}
-}
+ res = FatfsCheckBoundParam(fs, clust);
+ if (res != FR_OK) {
+ LEAVE_FF(fs, res);
+ }
+ for (;;) {
+ clust = get_fat(&obj, clust);
+ if (clust == 0xFFFFFFFF) {
+ LEAVE_FF(fs, FR_DISK_ERR);
+ }
+ if (clust == 0x0FFFFFFF) {
+ break;
+ }
+ if (clust < 2 || clust >= fs->n_fatent) {
+ LEAVE_FF(fs, FR_INT_ERR);
+ }
+ if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
+ LEAVE_FF(fs, FR_CHAIN_ERR);
+ }
+ }
-LEAVE_FF(fs, FR_OK);
+ LEAVE_FF(fs, FR_OK);
}
/*
@@ -240,76 +240,76 @@ LEAVE_FF(fs, FR_OK);
*/
FRESULT f_disvirfs(FATFS *fs)
{
-if (ISCHILD(fs)) {
-return FR_INVAILD_FATFS;
-}
+ if (ISCHILD(fs)) {
+ return FR_INVAILD_FATFS;
+ }
-if (fs->vir_amount > _MAX_VIRVOLUMES) {
-return FR_INT_ERR;
-}
+ if (fs->vir_amount > _MAX_VIRVOLUMES) {
+ return FR_INT_ERR;
+ }
-ENTER_FF(fs);
+ ENTER_FF(fs);
-(void)f_unregvirfs(fs);
-LEAVE_FF(fs, FR_OK);
+ (void)f_unregvirfs(fs);
+ LEAVE_FF(fs, FR_OK);
}
FRESULT f_unregvirfs(FATFS *fs)
{
-UINT i;
+ UINT i;
-if (fs == NULL || ISCHILD(fs)) {
-return FR_INVAILD_FATFS;
-}
+ if (fs == NULL || ISCHILD(fs)) {
+ return FR_INVAILD_FATFS;
+ }
-fs->vir_avail = FS_VIRDISABLE;
-/* PARENT FATFS has linked to CHILD FATFS already */
-if (fs->child_fs != NULL) {
-/* Followed the CHILD FATFS and free the memory */
-for (i = 0; i < fs->vir_amount; i++) {
- if (CHILDFS(fs, i) != NULL) {
- ff_memfree(CHILDFS(fs, i));
+ fs->vir_avail = FS_VIRDISABLE;
+ /* PARENT FATFS has linked to CHILD FATFS already */
+ if (fs->child_fs != NULL) {
+ /* Followed the CHILD FATFS and free the memory */
+ for (i = 0; i < fs->vir_amount; i++) {
+ if (CHILDFS(fs, i) != NULL) {
+ ff_memfree(CHILDFS(fs, i));
+ }
+ }
+ /* Free the 'child_fs' feild */
+ ff_memfree(fs->child_fs);
+ fs->child_fs = NULL;
+ fs->vir_amount = 0xFFFFFFFF;
}
-}
-/* Free the 'child_fs' feild */
-ff_memfree(fs->child_fs);
-fs->child_fs = NULL;
-fs->vir_amount = 0xFFFFFFFF;
-}
-return FR_OK;
+ return FR_OK;
}
static void FatfsSetParentFs(FATFS *pfs, FATFS *fs)
{
-pfs->fs_type = fs->fs_type; /* Copy the feild info from PARENT FATFS object */
-pfs->pdrv = fs->pdrv;
-pfs->n_fats = fs->n_fats;
-pfs->id = fs->id;
-pfs->n_rootdir = fs->n_rootdir;
-pfs->csize = fs->csize;
+ pfs->fs_type = fs->fs_type; /* Copy the feild info from PARENT FATFS object */
+ pfs->pdrv = fs->pdrv;
+ pfs->n_fats = fs->n_fats;
+ pfs->id = fs->id;
+ pfs->n_rootdir = fs->n_rootdir;
+ pfs->csize = fs->csize;
#if FF_MAX_SS != FF_MIN_SS
-pfs->ssize = fs->ssize;
+ pfs->ssize = fs->ssize;
#endif
-pfs->sobj = fs->sobj;
+ pfs->sobj = fs->sobj;
#if FF_FS_RPATH != 0
-pfs->cdir = 0;
+ pfs->cdir = 0;
#endif
-pfs->n_fatent = fs->n_fatent;
-pfs->fsize = fs->fsize;
-pfs->volbase = fs->volbase;
-pfs->fatbase = fs->fatbase;
-pfs->dirbase = fs->dirbase;
-pfs->database = fs->database;
-pfs->last_clst = 0xFFFFFFFF; /* Mark the 'last_clst' and 'free_clst' in CHILD FATFS is not been updated for now */
-pfs->free_clst = 0xFFFFFFFF;
-pfs->st_clst = 0xFFFFFFFF; /* Mark the 'st_clst' and 'ct_clst' in CHILD FATFS is not been update for now. */
-pfs->ct_clst = 0xFFFFFFFF;
-pfs->vir_flag = FS_CHILD; /* Mark the FATFS object is a CHILD */
-pfs->vir_avail = FS_VIRENABLE; /* Mark the CHILD object is enable for now */
-pfs->parent_fs = (void *)fs; /* Link to the PARENT object */
-pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */
+ pfs->n_fatent = fs->n_fatent;
+ pfs->fsize = fs->fsize;
+ pfs->volbase = fs->volbase;
+ pfs->fatbase = fs->fatbase;
+ pfs->dirbase = fs->dirbase;
+ pfs->database = fs->database;
+ pfs->last_clst = 0xFFFFFFFF; /* Mark the 'last_clst' and 'free_clst' in CHILD FATFS is not been updated for now */
+ pfs->free_clst = 0xFFFFFFFF;
+ pfs->st_clst = 0xFFFFFFFF; /* Mark the 'st_clst' and 'ct_clst' in CHILD FATFS is not been update for now. */
+ pfs->ct_clst = 0xFFFFFFFF;
+ pfs->vir_flag = FS_CHILD; /* Mark the FATFS object is a CHILD */
+ pfs->vir_avail = FS_VIRENABLE; /* Mark the CHILD object is enable for now */
+ pfs->parent_fs = (void *)fs; /* Link to the PARENT object */
+ pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */
}
/*
@@ -328,77 +328,77 @@ pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */
*/
FRESULT f_regvirfs(FATFS *fs)
{
-UINT i;
-FATFS *pfs = NULL;
+ UINT i;
+ FATFS *pfs = NULL;
-if (fs == NULL || ISCHILD(fs)) {
-return FR_INVAILD_FATFS;
-}
+ if (fs == NULL || ISCHILD(fs)) {
+ return FR_INVAILD_FATFS;
+ }
-if (fs->vir_amount > _MAX_VIRVOLUMES) {
-return FR_INT_ERR;
-}
+ if (fs->vir_amount > _MAX_VIRVOLUMES) {
+ return FR_INT_ERR;
+ }
-fs->parent_fs = (void *)fs; /* Relink to itself */
-/* Mark the FATFS object is PARENT */
-fs->st_clst = 0xFFFFFFFF;
-fs->ct_clst = 0xFFFFFFFF;
-/* Allocate a space for linking to the child FATFS */
-fs->child_fs = (void **)ff_memalloc(fs->vir_amount * sizeof(void *));
-if (fs->child_fs == NULL) {
-return FR_NOT_ENOUGH_CORE;
-}
-fs->vir_avail = FS_VIRENABLE; /* Mark the PARENT object is enable for now */
+ fs->parent_fs = (void *)fs; /* Relink to itself */
+ /* Mark the FATFS object is PARENT */
+ fs->st_clst = 0xFFFFFFFF;
+ fs->ct_clst = 0xFFFFFFFF;
+ /* Allocate a space for linking to the child FATFS */
+ fs->child_fs = (void **)ff_memalloc(fs->vir_amount * sizeof(void *));
+ if (fs->child_fs == NULL) {
+ return FR_NOT_ENOUGH_CORE;
+ }
+ fs->vir_avail = FS_VIRENABLE; /* Mark the PARENT object is enable for now */
-/* Set the CHILD object field */
-for (i = 0; i < fs->vir_amount; i++) {
-pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memeory for current child FATFS object */
-if (pfs == NULL) { /* If allocate failed, must call 'f_unregvirfs' to free the previous FATFS object memory */
- goto ERROUT;
-}
-FatfsSetParentFs(pfs, fs);
-*(fs->child_fs + i) = (void *)pfs;
-}
+ /* Set the CHILD object field */
+ for (i = 0; i < fs->vir_amount; i++) {
+ pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memeory for current child FATFS object */
+ if (pfs == NULL) { /* If allocate failed, must call 'f_unregvirfs' to free the previous FATFS object memory */
+ goto ERROUT;
+ }
+ FatfsSetParentFs(pfs, fs);
+ *(fs->child_fs + i) = (void *)pfs;
+ }
-return FR_OK;
+ return FR_OK;
ERROUT:
-while (i > 0) {
---i;
-ff_memfree(*(fs->child_fs + i));
-}
-ff_memfree(fs->child_fs);
-fs->child_fs = NULL;
+ while (i > 0) {
+ --i;
+ ff_memfree(*(fs->child_fs + i));
+ }
+ ff_memfree(fs->child_fs);
+ fs->child_fs = NULL;
-return FR_NOT_ENOUGH_CORE;
+ return FR_NOT_ENOUGH_CORE;
}
static FRESULT FatfsCheckScanFatParam(FATFS *fs)
{
-if (fs == NULL) {
-return FR_INVAILD_FATFS;
-}
+ if (fs == NULL) {
+ return FR_INVAILD_FATFS;
+ }
-if (ISNORMAL(fs)) {
-return FR_DENIED;
-}
+ if (ISNORMAL(fs)) {
+ return FR_DENIED;
+ }
-if (fs->fs_type != FS_FAT32 || ISPARENT(fs)) {
-return FR_INVAILD_FATFS;
-}
+ if (fs->fs_type != FS_FAT32 || ISPARENT(fs)) {
+ return FR_INVAILD_FATFS;
+ }
-if (fs->st_clst < 3 || fs->st_clst >= fs->n_fatent) {
-return FR_INVAILD_FATFS;
-}
+ if (fs->st_clst < 3 || fs->st_clst >= fs->n_fatent) {
+ return FR_INVAILD_FATFS;
+ }
-if (fs->ct_clst == 0 || fs->ct_clst > (fs->n_fatent - 3)) {
-return FR_INVAILD_FATFS;
-}
+ if (fs->ct_clst == 0 || fs->ct_clst > (fs->n_fatent - 3)) {
+ return FR_INVAILD_FATFS;
+ }
-if ((fs->st_clst + fs->ct_clst) > fs->n_fatent || (fs->st_clst + fs->ct_clst) < 3) {
-return FR_INVAILD_FATFS;
-}
+ if ((fs->st_clst + fs->ct_clst) > fs->n_fatent || (fs->st_clst + fs->ct_clst) < 3) {
+ return FR_INVAILD_FATFS;
+ }
-return FR_OK;
+ return FR_OK;
}
/*
@@ -415,114 +415,114 @@ return FR_OK;
*/
FRESULT f_scanfat(FATFS *fs)
{
-FRESULT res;
-DWORD clst;
-DWORD link;
-FFOBJID obj;
-
-res = FatfsCheckScanFatParam(fs);
-if (res != FR_OK) {
-return res;
-}
+ FRESULT res;
+ DWORD clst;
+ DWORD link;
+ FFOBJID obj;
-ENTER_FF(fs);
-res = FR_OK;
-obj.fs = fs;
+ res = FatfsCheckScanFatParam(fs);
+ if (res != FR_OK) {
+ return res;
+ }
-fs->free_clst = fs->ct_clst;
-for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
-link = get_fat(&obj, clst);
-if (link == 0xFFFFFFFF) {
- LEAVE_FF(fs, FR_DISK_ERR);
-}
-if (link == 0) {
- continue;
-}
-fs->free_clst--;
-}
-fs->last_clst = fs->st_clst - 1;
+ ENTER_FF(fs);
+ res = FR_OK;
+ obj.fs = fs;
-LEAVE_FF(fs, res);
+ fs->free_clst = fs->ct_clst;
+ for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
+ link = get_fat(&obj, clst);
+ if (link == 0xFFFFFFFF) {
+ LEAVE_FF(fs, FR_DISK_ERR);
+ }
+ if (link == 0) {
+ continue;
+ }
+ fs->free_clst--;
+ }
+ fs->last_clst = fs->st_clst - 1;
+
+ LEAVE_FF(fs, res);
}
static FRESULT FatfsCheckStart(BYTE *work, FATFS *fs, BYTE vol)
{
-DWORD startBaseSect, countBaseSect;
+ DWORD startBaseSect, countBaseSect;
-countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */
-startBaseSect = LD2PS(vol); /* Volume Base Start Sector */
+ countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */
+ startBaseSect = LD2PS(vol); /* Volume Base Start Sector */
-/* Check ASCII for Keyword "LITE" */
-if (ld_dword(work + VR_VertifyString) != 0x4C495445) {
-return FR_NOVIRPART;
-}
-/* Check whether filesystem has been changed or not */
-if (work[VR_PartitionFSType] != fs->fs_type) {
-return FR_MODIFIED;
-}
-/* Check whether volume base sector has benn changed or not */
-if (ld_dword(work + VR_PartitionStSec) != startBaseSect) {
-return FR_MODIFIED;
-}
-/* Check whether volume base size hase been changed or not */
-if (ld_dword(work + VR_PartitionCtSec) != countBaseSect) {
-return FR_MODIFIED;
-}
-/* Check whether volume cluster size has been changed or not */
-if (ld_word(work + VR_PartitionClstSz) != fs->csize) {
-return FR_MODIFIED;
-}
-/* Check whether volume start cluster is cluster #3 or not */
-if (ld_dword(work + VR_PartitionCtClst) != fs->n_fatent) {
-return FR_MODIFIED;
-}
-/* Check whether virtual partition overlimit */
-if (work[VR_PartitionCnt] > _MAX_VIRVOLUMES) {
-return FR_MODIFIED;
-}
+ /* Check ASCII for Keyword "LITE" */
+ if (ld_dword(work + VR_VertifyString) != 0x4C495445) {
+ return FR_NOVIRPART;
+ }
+ /* Check whether filesystem has been changed or not */
+ if (work[VR_PartitionFSType] != fs->fs_type) {
+ return FR_MODIFIED;
+ }
+ /* Check whether volume base sector has benn changed or not */
+ if (ld_dword(work + VR_PartitionStSec) != startBaseSect) {
+ return FR_MODIFIED;
+ }
+ /* Check whether volume base size hase been changed or not */
+ if (ld_dword(work + VR_PartitionCtSec) != countBaseSect) {
+ return FR_MODIFIED;
+ }
+ /* Check whether volume cluster size has been changed or not */
+ if (ld_word(work + VR_PartitionClstSz) != fs->csize) {
+ return FR_MODIFIED;
+ }
+ /* Check whether volume start cluster is cluster #3 or not */
+ if (ld_dword(work + VR_PartitionCtClst) != fs->n_fatent) {
+ return FR_MODIFIED;
+ }
+ /* Check whether virtual partition overlimit */
+ if (work[VR_PartitionCnt] > _MAX_VIRVOLUMES) {
+ return FR_MODIFIED;
+ }
-return FR_OK;
+ return FR_OK;
}
static FRESULT FatfsCheckPercent(FATFS *fs, WORD i)
{
-if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst < fs->n_fatent) {
-fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
-fs->ct_clst = fs->n_fatent - ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst);
-} else if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst == fs->n_fatent) {
-fs->st_clst = 0xFFFFFFFF;
-fs->ct_clst = 0xFFFFFFFF;
-} else {
-(void)f_unregvirfs(fs);
-return FR_MODIFIED;
-}
+ if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst < fs->n_fatent) {
+ fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
+ fs->ct_clst = fs->n_fatent - ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst);
+ } else if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst == fs->n_fatent) {
+ fs->st_clst = 0xFFFFFFFF;
+ fs->ct_clst = 0xFFFFFFFF;
+ } else {
+ (void)f_unregvirfs(fs);
+ return FR_MODIFIED;
+ }
-return FR_OK;
+ return FR_OK;
}
static FRESULT FatfsCheckPartClst(FATFS *fs, WORD i)
{
-if (i == 0) {
-/* First virtual partition must start at cluster #3 */
-if ((CHILDFS(fs, i))->st_clst != 3) {
- (void)f_unregvirfs(fs);
- return FR_MODIFIED;
-}
-} else {
-/* Check whether the current virtual partition is closely next to the previous virtual partition */
-if ((CHILDFS(fs, i))->st_clst != (CHILDFS(fs, (i - 1))->st_clst + CHILDFS(fs, (i - 1))->ct_clst)) {
- (void)f_unregvirfs(fs);
- return FR_MODIFIED;
-}
-}
+ if (i == 0) {
+ /* First virtual partition must start at cluster #3 */
+ if ((CHILDFS(fs, i))->st_clst != 3) {
+ (void)f_unregvirfs(fs);
+ return FR_MODIFIED;
+ }
+ } else {
+ /* Check whether the current virtual partition is closely next to the previous virtual partition */
+ if ((CHILDFS(fs, i))->st_clst != (CHILDFS(fs, (i - 1))->st_clst + CHILDFS(fs, (i - 1))->ct_clst)) {
+ (void)f_unregvirfs(fs);
+ return FR_MODIFIED;
+ }
+ }
-return FR_OK;
+ return FR_OK;
}
static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
{
-(CHILDFS(fs, i))->st_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust);
-(CHILDFS(fs, i))->ct_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust);
+ (CHILDFS(fs, i))->st_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust);
+ (CHILDFS(fs, i))->ct_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust);
}
/*
@@ -544,144 +544,144 @@ static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
*/
FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
{
-FRESULT res;
-WORD i;
-DWORD virSect;
-DWORD tmp;
-BYTE pdrv;
-BYTE *work = NULL;
-CHAR label[_MAX_ENTRYLENGTH + 1];
-DWORD *labelTmp = NULL; /* to clear the compilation warning */
-
-if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
-return FR_INVAILD_FATFS; /* The object is invalid */
-}
+ FRESULT res;
+ WORD i;
+ DWORD virSect;
+ DWORD tmp;
+ BYTE pdrv;
+ BYTE *work = NULL;
+ CHAR label[_MAX_ENTRYLENGTH + 1];
+ DWORD *labelTmp = NULL; /* to clear the compilation warning */
+
+ if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
+ return FR_INVAILD_FATFS; /* The object is invalid */
+ }
-/* Lock the filesystem object */
-res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
-if (res != FR_OK) {
-LEAVE_FF(fs, res);
-}
+ /* Lock the filesystem object */
+ res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
+ if (res != FR_OK) {
+ LEAVE_FF(fs, res);
+ }
-if (ISCHILD(fs)) {
-LEAVE_FF(fs, FR_INT_ERR);
-}
-/* Data will be save at the last reserve sector ,which is the front one of the fat base sector */
-virSect = fs->fatbase - 1;
+ if (ISCHILD(fs)) {
+ LEAVE_FF(fs, FR_INT_ERR);
+ }
+ /* Data will be save at the last reserve sector ,which is the front one of the fat base sector */
+ virSect = fs->fatbase - 1;
-pdrv = LD2PD(vol); /* Driver index */
+ pdrv = LD2PD(vol); /* Driver index */
-work = (BYTE *)ff_memalloc(SS(fs));
-if (work == NULL) {
-LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
-}
-/* Check and vertify partition information */
-if (disk_read(pdrv, work, virSect, 1) != RES_OK) {
-res = FR_DISK_ERR;
-goto EXIT;
-} /* Load VBR */
-
-res = FatfsCheckStart(work, fs, vol);
-if (res != FR_OK) {
-goto EXIT;
-}
-/* Check the virtual parition amount if matched current setting or not */
-fs->vir_amount = work[VR_PartitionCnt];
-res = f_regvirfs(fs);
-if (res != FR_OK) {
-goto EXIT;
-}
+ work = (BYTE *)ff_memalloc(SS(fs));
+ if (work == NULL) {
+ LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
+ }
+ /* Check and vertify partition information */
+ if (disk_read(pdrv, work, virSect, 1) != RES_OK) {
+ res = FR_DISK_ERR;
+ goto EXIT;
+ } /* Load VBR */
-for (i = 0; i < _MAX_VIRVOLUMES; i++) {
-if (i < work[VR_PartitionCnt]) {
- if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x80) {
- (void)f_unregvirfs(fs);
- res = FR_MODIFIED;
+ res = FatfsCheckStart(work, fs, vol);
+ if (res != FR_OK) {
goto EXIT;
}
-} else {
- if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x00) {
- (void)f_unregvirfs(fs);
- res = FR_MODIFIED;
+ /* Check the virtual parition amount if matched current setting or not */
+ fs->vir_amount = work[VR_PartitionCnt];
+ res = f_regvirfs(fs);
+ if (res != FR_OK) {
goto EXIT;
}
- break;
-}
-
-(void)memset_s(label, sizeof(label), 0, sizeof(label));
-tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0);
-labelTmp = (DWORD *)label;
-*labelTmp = tmp;
-tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4);
-*((DWORD *)(label + 4)) = tmp;
-tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8);
-*((DWORD *)(label + 8)) = tmp;
-tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12);
-*((DWORD *)(label + 12)) = tmp;
+ for (i = 0; i < _MAX_VIRVOLUMES; i++) {
+ if (i < work[VR_PartitionCnt]) {
+ if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x80) {
+ (void)f_unregvirfs(fs);
+ res = FR_MODIFIED;
+ goto EXIT;
+ }
+ } else {
+ if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x00) {
+ (void)f_unregvirfs(fs);
+ res = FR_MODIFIED;
+ goto EXIT;
+ }
+ break;
+ }
-if (f_checkname(label) != FR_OK) {
- (void)f_unregvirfs(fs);
- res = FR_MODIFIED;
- goto EXIT;
-}
-(void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, label, _MAX_ENTRYLENGTH + 1);
+ (void)memset_s(label, sizeof(label), 0, sizeof(label));
+
+ tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0);
+ labelTmp = (DWORD *)label;
+ *labelTmp = tmp;
+ tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4);
+ *((DWORD * )(label + 4)) = tmp;
+ tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8);
+ *((DWORD * )(label + 8)) = tmp;
+ tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12);
+ *((DWORD * )(label + 12)) = tmp;
+
+ if (f_checkname(label) != FR_OK) {
+ (void)f_unregvirfs(fs);
+ res = FR_MODIFIED;
+ goto EXIT;
+ }
+ (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, label, _MAX_ENTRYLENGTH + 1);
-FatfsSetChildClst(work, fs, i);
+ FatfsSetChildClst(work, fs, i);
-/* External SD setting has overlimit the whole partition cluster amount */
-if ((QWORD)(CHILDFS(fs, i))->st_clst + (QWORD)((CHILDFS(fs, i))->ct_clst) > (QWORD)fs->n_fatent) {
- (void)f_unregvirfs(fs);
- res = FR_MODIFIED;
- goto EXIT;
-}
+ /* External SD setting has overlimit the whole partition cluster amount */
+ if ((QWORD)(CHILDFS(fs, i))->st_clst + (QWORD)((CHILDFS(fs, i))->ct_clst) > (QWORD)fs->n_fatent) {
+ (void)f_unregvirfs(fs);
+ res = FR_MODIFIED;
+ goto EXIT;
+ }
-res = FatfsCheckPartClst(fs, i);
-if (res != FR_OK) {
- goto EXIT;
-}
-if (i == (work[VR_PartitionCnt] - 1)) {
- /*
- * If the external SD virtual partition percent exceeds the error tolerance based on current virtual
- * partition percent setting
- */
- res = FatfsCheckPercent(fs, i);
- if (res != FR_OK) {
- goto EXIT;
+ res = FatfsCheckPartClst(fs, i);
+ if (res != FR_OK) {
+ goto EXIT;
+ }
+ if (i == (work[VR_PartitionCnt] - 1)) {
+ /*
+ * If the external SD virtual partition percent exceeds the error tolerance based on current virtual
+ * partition percent setting
+ */
+ res = FatfsCheckPercent(fs, i);
+ if (res != FR_OK) {
+ goto EXIT;
+ }
+ }
}
-}
-}
EXIT:
-ff_memfree(work);
-LEAVE_FF(fs, res);
+ ff_memfree(work);
+ LEAVE_FF(fs, res);
}
static void FatfsClacPartInfo(FATFS *fs, DOUBLE virpartper, UINT i)
{
-if (i == 0) {
-(CHILDFS(fs, i))->st_clst = 3;
-(CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
- g_fatVirPart.virtualinfo.virpartpercent[i]);
-
-fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
-fs->ct_clst = fs->n_fatent - fs->st_clst;
-} else if (i != (fs->vir_amount - 1)) {
-(CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
-(CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
- g_fatVirPart.virtualinfo.virpartpercent[i]);
-} else {
-(CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
-if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) {
- (CHILDFS(fs, i))->ct_clst = fs->n_fatent - (CHILDFS(fs, i))->st_clst;
- fs->st_clst = 0xFFFFFFFF;
- fs->ct_clst = 0xFFFFFFFF;
-} else {
- (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
- g_fatVirPart.virtualinfo.virpartpercent[i]);
- fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
- fs->ct_clst = fs->n_fatent - fs->st_clst;
-}
-}
+ if (i == 0) {
+ (CHILDFS(fs, i))->st_clst = 3;
+ (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
+ g_fatVirPart.virtualinfo.virpartpercent[i]);
+
+ fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
+ fs->ct_clst = fs->n_fatent - fs->st_clst;
+ } else if (i != (fs->vir_amount - 1)) {
+ (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
+ (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
+ g_fatVirPart.virtualinfo.virpartpercent[i]);
+ } else {
+ (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
+ if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) {
+ (CHILDFS(fs, i))->ct_clst = fs->n_fatent - (CHILDFS(fs, i))->st_clst;
+ fs->st_clst = 0xFFFFFFFF;
+ fs->ct_clst = 0xFFFFFFFF;
+ } else {
+ (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
+ g_fatVirPart.virtualinfo.virpartpercent[i]);
+ fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
+ fs->ct_clst = fs->n_fatent - fs->st_clst;
+ }
+ }
}
/*
@@ -700,173 +700,173 @@ if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) {
*/
FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
{
-FRESULT res;
-DWORD virSect;
-DWORD startBaseSect, countBaseSect;
-DWORD tmp;
-CHAR label[_MAX_ENTRYLENGTH + 1];
-DWORD *labelTmp = NULL; /* to clear the compilation warning */
-UINT i;
-BYTE pdrv;
-BYTE *work = NULL;
-DOUBLE virpartper = 0.0;
-
-if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
-return FR_INVAILD_FATFS; /* The object is invalid */
-}
+ FRESULT res;
+ DWORD virSect;
+ DWORD startBaseSect, countBaseSect;
+ DWORD tmp;
+ CHAR label[_MAX_ENTRYLENGTH + 1];
+ DWORD *labelTmp = NULL; /* to clear the compilation warning */
+ UINT i;
+ BYTE pdrv;
+ BYTE *work = NULL;
+ DOUBLE virpartper = 0.0;
+
+ if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
+ return FR_INVAILD_FATFS; /* The object is invalid */
+ }
-/* Lock the filesystem object */
-res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
-if (res != FR_OK) {
-LEAVE_FF(fs, res);
-}
+ /* Lock the filesystem object */
+ res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
+ if (res != FR_OK) {
+ LEAVE_FF(fs, res);
+ }
-/* Only available in FAT32 filesystem */
-if (ISCHILD(fs)) {
-LEAVE_FF(fs, FR_INVAILD_FATFS);
-}
-/* Data will be save at the last reserve sector,which is the front one of the fat base sector */
-virSect = fs->fatbase - 1;
-/* Search the fs index, which same as the volume index */
-pdrv = LD2PD(vol); /* Driver index */
-countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */
-startBaseSect = LD2PS(vol); /* Volume Base Start Sector */
-
-fs->vir_amount = g_fatVirPart.virtualinfo.virpartnum;
-res = f_regvirfs(fs);
-if (res != FR_OK) {
-LEAVE_FF(fs, res);
-}
+ /* Only available in FAT32 filesystem */
+ if (ISCHILD(fs)) {
+ LEAVE_FF(fs, FR_INVAILD_FATFS);
+ }
+ /* Data will be save at the last reserve sector,which is the front one of the fat base sector */
+ virSect = fs->fatbase - 1;
+ /* Search the fs index, which same as the volume index */
+ pdrv = LD2PD(vol); /* Driver index */
+ countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */
+ startBaseSect = LD2PS(vol); /* Volume Base Start Sector */
+
+ fs->vir_amount = g_fatVirPart.virtualinfo.virpartnum;
+ res = f_regvirfs(fs);
+ if (res != FR_OK) {
+ LEAVE_FF(fs, res);
+ }
-work = (BYTE *)ff_memalloc(SS(fs));
-if (work == NULL) {
-LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
-}
-/* Data Cluster is begin from the Cluster #3 to the last cluster */
-/* Cluster #0 #1 is for VBR, reserve sectors and fat */
-/* Cluster #2 is for root directory */
-(void)memset_s(work, SS(fs), 0, SS(fs));
-
-for (i = 0; i < fs->vir_amount; i++) {
-/* Copy the Entry label and write to work sector's buffer */
-(void)memset_s(label, sizeof(label), 0, sizeof(label));
-(void)memcpy_s(label, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], _MAX_ENTRYLENGTH + 1);
-labelTmp = (DWORD *)label;
-tmp = *labelTmp;
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0, tmp);
-tmp = *((DWORD *)(label + 4));
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4, tmp);
-tmp = *((DWORD *)(label + 8));
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8, tmp);
-tmp = *((DWORD *)(label + 12));
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12, tmp);
-
-virpartper += g_fatVirPart.virtualinfo.virpartpercent[i];
-
-(void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i],
- _MAX_ENTRYLENGTH + 1);
-FatfsClacPartInfo(fs, virpartper, i);
-(CHILDFS(fs, i))->last_clst = (CHILDFS(fs, i))->st_clst - 1;
-work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] = 0x80;
-}
+ work = (BYTE *)ff_memalloc(SS(fs));
+ if (work == NULL) {
+ LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
+ }
+ /* Data Cluster is begin from the Cluster #3 to the last cluster */
+ /* Cluster #0 #1 is for VBR, reserve sectors and fat */
+ /* Cluster #2 is for root directory */
+ (void)memset_s(work, SS(fs), 0, SS(fs));
+
+ for (i = 0; i < fs->vir_amount; i++) {
+ /* Copy the Entry label and write to work sector's buffer */
+ (void)memset_s(label, sizeof(label), 0, sizeof(label));
+ (void)memcpy_s(label, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], _MAX_ENTRYLENGTH + 1);
+ labelTmp = (DWORD *)label;
+ tmp = *labelTmp;
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0, tmp);
+ tmp = *((DWORD * )(label + 4));
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4, tmp);
+ tmp = *((DWORD * )(label + 8));
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8, tmp);
+ tmp = *((DWORD * )(label + 12));
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12, tmp);
+
+ virpartper += g_fatVirPart.virtualinfo.virpartpercent[i];
+
+ (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i],
+ _MAX_ENTRYLENGTH + 1);
+ FatfsClacPartInfo(fs, virpartper, i);
+ (CHILDFS(fs, i))->last_clst = (CHILDFS(fs, i))->st_clst - 1;
+ work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] = 0x80;
+ }
-/* Set the data to sector */
-work[VR_PartitionCnt] = fs->vir_amount;
-work[VR_PartitionFSType] = fs->fs_type;
-st_dword(work + VR_PartitionStSec, startBaseSect);
-st_dword(work + VR_PartitionCtSec, countBaseSect);
-st_word(work + VR_PartitionClstSz, fs->csize);
-st_dword(work + VR_PartitionCtClst, fs->n_fatent);
-for (i = 0; i < fs->vir_amount; i++) {
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust,
- (CHILDFS(fs, i))->st_clst);
-st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust,
- (CHILDFS(fs, i))->ct_clst);
-}
+ /* Set the data to sector */
+ work[VR_PartitionCnt] = fs->vir_amount;
+ work[VR_PartitionFSType] = fs->fs_type;
+ st_dword(work + VR_PartitionStSec, startBaseSect);
+ st_dword(work + VR_PartitionCtSec, countBaseSect);
+ st_word(work + VR_PartitionClstSz, fs->csize);
+ st_dword(work + VR_PartitionCtClst, fs->n_fatent);
+ for (i = 0; i < fs->vir_amount; i++) {
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust,
+ (CHILDFS(fs, i))->st_clst);
+ st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust,
+ (CHILDFS(fs, i))->ct_clst);
+ }
-/* ASCII for Keyword "LITE" */
-st_dword(work + VR_VertifyString, 0x4C495445);
+ /* ASCII for Keyword "LITE" */
+ st_dword(work + VR_VertifyString, 0x4C495445);
-/* Write into the data area */
-if (disk_write(pdrv, work, virSect, 1) != RES_OK) {
-(void)f_unregvirfs(fs);
-res = FR_DISK_ERR;
-}
+ /* Write into the data area */
+ if (disk_write(pdrv, work, virSect, 1) != RES_OK) {
+ (void)f_unregvirfs(fs);
+ res = FR_DISK_ERR;
+ }
-ff_memfree(work);
-LEAVE_FF(fs, res);
+ ff_memfree(work);
+ LEAVE_FF(fs, res);
}
FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
{
-FATFS *fs = NULL;
-FRESULT res;
-DWORD clst, link;
-DWORD nfree;
-UINT i;
-DIR dj;
-
-/* Find volume to Update the global FSINFO */
-res = find_volume(&path, &fs, 0);
-if (res != FR_OK) {
-LEAVE_FF(fs, res);
-}
-
-/* Following the entry keyword, decide to replace the PARENT FATFS to CHILD FATFS or not */
-dj.obj.fs = fs;
-if (ISVIRPART(fs)) {
-/* Check the virtual partition top directory, and match the virtual fs */
-res = follow_virentry(&dj.obj, path);
-if (res == FR_INT_ERR) {
- LEAVE_FF(fs, res);
-}
-if (res == FR_OK) {
- fs = dj.obj.fs;
-}
-} else {
-/* Virtual Partition Feature was off, deny this operation */
-LEAVE_FF(fs, FR_DENIED);
-}
+ FATFS *fs = NULL;
+ FRESULT res;
+ DWORD clst, link;
+ DWORD nfree;
+ UINT i;
+ DIR dj;
+
+ /* Find volume to Update the global FSINFO */
+ res = find_volume(&path, &fs, 0);
+ if (res != FR_OK) {
+ LEAVE_FF(fs, res);
+ }
-/* If current FATFS is a CHILD FATFS */
-if (ISCHILD(fs)) {
-/* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */
-if (fs->free_clst > fs->ct_clst) {
+ /* Following the entry keyword, decide to replace the PARENT FATFS to CHILD FATFS or not */
dj.obj.fs = fs;
- fs->free_clst = fs->ct_clst;
- for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
- link = get_fat(&dj.obj, clst);
- if (link == 0) {
- continue;
+ if (ISVIRPART(fs)) {
+ /* Check the virtual partition top directory, and match the virtual fs */
+ res = follow_virentry(&dj.obj, path);
+ if (res == FR_INT_ERR) {
+ LEAVE_FF(fs, res);
}
- fs->free_clst--;
+ if (res == FR_OK) {
+ fs = dj.obj.fs;
+ }
+ } else {
+ /* Virtual Partition Feature was off, deny this operation */
+ LEAVE_FF(fs, FR_DENIED);
}
-}
-*nclst = fs->free_clst;
-*cclst = fs->ct_clst;
-LEAVE_FF(fs, FR_OK);
-} else {
-nfree = 0;
-if (fs->ct_clst == 0xFFFFFFFF) {
- LEAVE_FF(fs, FR_DENIED);
-}
-for (i = 0; i < fs->vir_amount; i++) {
- if (CHILDFS(fs, i)->free_clst > CHILDFS(fs, i)->ct_clst) {
- dj.obj.fs = CHILDFS(fs, i);
- CHILDFS(fs, i)->free_clst = CHILDFS(fs, i)->ct_clst;
- for (clst = CHILDFS(fs, i)->st_clst; clst < CHILDFS(fs, i)->st_clst + CHILDFS(fs, i)->ct_clst; clst++) {
- link = get_fat(&dj.obj, clst);
- if (link == 0) {
- continue;
+
+ /* If current FATFS is a CHILD FATFS */
+ if (ISCHILD(fs)) {
+ /* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */
+ if (fs->free_clst > fs->ct_clst) {
+ dj.obj.fs = fs;
+ fs->free_clst = fs->ct_clst;
+ for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
+ link = get_fat(&dj.obj, clst);
+ if (link == 0) {
+ continue;
+ }
+ fs->free_clst--;
+ }
+ }
+ *nclst = fs->free_clst;
+ *cclst = fs->ct_clst;
+ LEAVE_FF(fs, FR_OK);
+ } else {
+ nfree = 0;
+ if (fs->ct_clst == 0xFFFFFFFF) {
+ LEAVE_FF(fs, FR_DENIED);
+ }
+ for (i = 0; i < fs->vir_amount; i++) {
+ if (CHILDFS(fs, i)->free_clst > CHILDFS(fs, i)->ct_clst) {
+ dj.obj.fs = CHILDFS(fs, i);
+ CHILDFS(fs, i)->free_clst = CHILDFS(fs, i)->ct_clst;
+ for (clst = CHILDFS(fs, i)->st_clst; clst < CHILDFS(fs, i)->st_clst + CHILDFS(fs, i)->ct_clst; clst++) {
+ link = get_fat(&dj.obj, clst);
+ if (link == 0) {
+ continue;
+ }
+ CHILDFS(fs, i)->free_clst--;
+ }
}
- CHILDFS(fs, i)->free_clst--;
+ nfree += CHILDFS(fs, i)->free_clst;
}
+ *nclst = fs->free_clst - nfree;
+ *cclst = fs->ct_clst;
+ LEAVE_FF(fs, FR_OK);
}
- nfree += CHILDFS(fs, i)->free_clst;
-}
-*nclst = fs->free_clst - nfree;
-*cclst = fs->ct_clst;
-LEAVE_FF(fs, FR_OK);
-}
}
#endif
diff --git a/fs/include/disk.h b/fs/include/disk.h
index 569c0e586b59daee0049ce08775faab9e6a93eae..77737dc34216b52a64762b95a63090084d6c1f6c 100755
--- 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:
@@ -47,6 +47,8 @@
#endif
+#include "pthread.h"
+
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@@ -475,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
old mode 100755
new mode 100644
index 7510de5c4668d5a497fa12e109e1786a67892cc7..ba98fee4600fc45e7e052985e40f562ae06d53db
--- 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
index 0403b299cc9d1a882454f26ac5b7a38a40723962..e85cf5b489bb364d00c9e89b771b113a1f20f283 100755
--- 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
index f14b47b4036eefe48644f676fa63c2148a161010..670f602d05bd08733ce128bae86c0f087cb5b7db 100755
--- 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
index 8107e31ac8f98855d5fa81d6df450a3bd38da495..eac54f9d0c8341f7ae0764e6d8a1978d57399e70 100755
--- 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
old mode 100755
new mode 100644
index 8ddf1cfd396d47002c49c87679651351fb2dab11..3ab5ddbe14a9248e998f8aeea28d3c77394d0ba9
--- 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/Kconfig b/fs/nfs/Kconfig
old mode 100755
new mode 100644
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
old mode 100755
new mode 100644
index 180333e1164b0957c5df30df3b3a26cead0a1ec5..5b999391e351e3e3cb626bfd688067601bec440f
--- 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 0000000000000000000000000000000000000000..122e956e6b074fd7886faf05431eadc51a33ac4e
--- /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 0000000000000000000000000000000000000000..1d8e320b7cbbac03c639c8b094cb3ddfa4873a46
--- /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 0000000000000000000000000000000000000000..2b8d72e6f58258c74898c7238ce359ae0499db82
--- /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
similarity index 67%
rename from kernel/base/core/los_timeslice.c
rename to fs/proc/include/internal.h
index 1e8601b4ecdc978f226c7d19e7e4b74075849171..886ab3ced4805e979e9310e9b03eb47397fc7713 100755
--- 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 0000000000000000000000000000000000000000..245ad39efde52f99dce656659d89c00ac289286d
--- /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 0000000000000000000000000000000000000000..3106fc5b28952f447de66b69b83bf4c0c74d8c06
--- /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 0000000000000000000000000000000000000000..dbb7785308eda4aba5a583bac3cccd73e2651ff6
--- /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 0000000000000000000000000000000000000000..692511d68173aaea1947a39844277cbd083c10be
--- /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 0000000000000000000000000000000000000000..5718ab94521f5cab80d38ffe0a07d3247c4c1108
--- /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 0000000000000000000000000000000000000000..65fe78bba0476893dfc7e408b24832f45ade8091
--- /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 0000000000000000000000000000000000000000..d30e62c14ae2a611c86c78514a1d59a9aa25016c
--- /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 0000000000000000000000000000000000000000..a45c980baac64972c9357dd4d37f1a82f3ea89d2
--- /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 0000000000000000000000000000000000000000..ff28b5680587ded1eb161a6bbac9333714e3c69b
--- /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 0000000000000000000000000000000000000000..6acffeb37f5f952c68fc7392ab6107d75128ee7d
--- /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 0000000000000000000000000000000000000000..c5c894f14a6eb58d07f43aaaf873b352eddf988c
--- /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/Kconfig b/fs/ramfs/Kconfig
old mode 100755
new mode 100644
diff --git a/fs/ramfs/Makefile b/fs/ramfs/Makefile
old mode 100755
new mode 100644
index 7dc41766bebfddf908e341e1a2c31ed6cf36fedf..4f8e3b9fc99d3dfe5f833bfb45babace680f56ce
--- 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/Kconfig b/fs/vfs/Kconfig
old mode 100755
new mode 100644
diff --git a/fs/vfs/Makefile b/fs/vfs/Makefile
index 977e61082fd363ac507329a68e856641115763a9..1da78b0aba130e3f0d847b5e500d782746caec91 100755
--- 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
old mode 100755
new mode 100644
index 5d0d7aeecee91e4a75e0182194bc709241f6a399..0fb1100adee8b57addcd0c043f04abbde0224b82
--- 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
index a243ea7dd3d6efd398881822a08a52267ef1ef52..0676b2cb1da0e846cadf007669506ff83d8351fb 100755
--- 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
index c73a34d3f5486f50c516699210e5e4b7656d4883..5b89f50f226aa6dd05ee2b9e6e456063e9292fe0 100755
--- 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
old mode 100755
new mode 100644
index 1eed0af1b22abd62d32ad0472f91eb3f2190e6a7..d61cb10026fa656cd62ae358bc20a7cf89cadb50
--- 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
index 99bd612ca90e0be299a4d633b74ed69e508db392..2d6db3a70cadea9ae650fb943d6829b3100ca768 100755
--- 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:
@@ -34,7 +34,6 @@
#include "stdlib.h"
#include "unistd.h"
#include "sys/mount.h"
-#include "pthread.h"
#include "linux/spinlock.h"
#include "inode/inode.h"
@@ -153,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;
}
@@ -262,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;
@@ -299,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;
@@ -318,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);
@@ -372,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;
}
@@ -411,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);
@@ -521,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);
@@ -679,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);
@@ -734,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;
}
@@ -753,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;
}
@@ -990,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;
@@ -1032,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;
}
@@ -1196,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';
@@ -1559,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
old mode 100755
new mode 100644
index acfabaf8e04c22d18eb1b97e99c53d1b424b6670..90f877eeee3b082f72a60b662a1a7453e85bae19
--- 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
index 3c2d8c0181225d5bcac72fb2ea49f7c4da9f1f03..22bc1c50b81f542b08e6e1fff385eb8cdad0cb3e 100755
--- 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
old mode 100755
new mode 100644
index c174124ce5737bc797e7ec3be4380cab63c06259..eecc8667efc88657ead0ce9917fa9a8057f24e95
--- 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
index ee4d994a4df58eae5e764118a8da15c82c4aec9c..4d884e79dc897c6353a5b5762bb4d67a1c3257a6 100755
--- 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
index e2cb14df4a4e06d0d82bbb50e514387e605fc50e..274841af6f90db00c83bc0e4ed1f40b6c2c4f4f2 100755
--- 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
index bec2c9bec014760b0c2e582f1dd7373ae9f6c677..30f41da6fe069192d2ca544ab705259f28dbc892 100755
--- 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
index ca4815815005beb1951302f5d8a1d09363a67068..cf4f7725a6f519c49d0a6a33a1c76e4397d98aca 100755
--- 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
index 58a50eb857f19d82ef4fe10a9d0ef42687316226..2fec42d75dfeec34cc54486a7efcd921b83fb707 100755
--- 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
index c29dec126590c2f6f682e96bff51d4fc25c92f72..8b8f32390e708eb9af5bbdeffde1c645b9c2c2cb 100755
--- 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
index 619e2487299e5cf5227ef48c55f4f83533070ee9..f765a6e9e5a79125b31ba7027c209f72cd7a92d7 100755
--- 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
old mode 100755
new mode 100644
index 513bd83d46135a6875460e29a9c54b95cecfa482..4321216db3a903d465cbd9641ab5d02cd771713d
--- 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
old mode 100755
new mode 100644
index a764648683449ffd6fcc08c4203c3f5a871d68bc..ea14154d183f7fbe74f7da4651f1fc881b3e9fb2
--- 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
index d11adb2e8845b8aa592bdc8b18e554164559d836..1c92ab0e51de65a7e7527578c41f5c083041aaae 100755
--- 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);
@@ -71,10 +136,18 @@ static VOID MtdNorParamAssign(partition_param *spinorParam, const struct MtdDev
* you can change the SPIBLK_NAME or SPICHR_NAME to NULL.
*/
spinorParam->flash_mtd = (struct MtdDev *)spinorMtd;
+#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
spinorParam->flash_ops = GetDevSpinorOps();
spinorParam->char_ops = GetMtdCharFops();
spinorParam->blockname = SPIBLK_NAME;
spinorParam->charname = SPICHR_NAME;
+#else
+ extern struct block_operations *GetCfiBlkOps(void);
+ spinorParam->flash_ops = GetCfiBlkOps();
+ spinorParam->char_ops = NULL;
+ spinorParam->blockname = "/dev/cfiflash";
+ spinorParam->charname = NULL;
+#endif
spinorParam->partition_head = g_spinorPartitionHead;
spinorParam->block_size = spinorMtd->eraseSize;
}
@@ -88,7 +161,12 @@ static VOID MtdDeinitSpinorParam(VOID)
static partition_param *MtdInitSpinorParam(partition_param *spinorParam)
{
+#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
struct MtdDev *spinorMtd = GetMtd("spinor");
+#else
+ extern struct MtdDev *GetCfiMtdDev(void);
+ struct MtdDev *spinorMtd = GetCfiMtdDev();
+#endif
if (spinorMtd == NULL) {
return NULL;
}
@@ -121,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) {
+ 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 {
@@ -138,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) {
+ 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 {
@@ -356,7 +440,9 @@ static INT32 DeleteParamCheck(UINT32 partitionNum,
const CHAR *type,
partition_param **param)
{
- if (strcmp(type, "spinor") == 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");
@@ -475,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
index 024898b83cf68d1318e5d9ca574155082ebf2193..62202f945bd854d24cd0763d65cd3ab6447d64b6 100755
--- 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
index e320e587b5cd89450d25934e364996f69ee58cc4..a3242a5c834a4252401980402e55a14b9fe2a544 100755
--- 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
index 3cc2201b5d370a054db82cceb15f15dd1db813c5..95c5a87226543642e48fc0bce06b1f0e03219aea 100755
--- 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
index 1c2437e704e39228c2fa64e2ce33689223bf0cbb..e4eca2de9ca04c664a0a5e6267758d225c2e085e 100755
--- 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
index 8569106b4a94b871aeaae3bb5452c97335d365bc..063254aa5fbf7640bfded96b2fb27a6375368e93 100755
--- 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
index 8007f2451551b1b338806771e5c0a47bfeeb3bdf..228fe72fec398058951f786e11fd0d3bb4d4fd53 100755
--- 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
index df10ea95b17e37be4cd079f43c251a76ad6988f9..0b85c81a03864c169a1c79c1aa56da7e712939eb 100755
--- 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
index b93f47129ac42afd0e3f1335af45fca767acbcee..6c375c9031891817c346cd4fa83e2e49f668d35d 100755
--- 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
index e30bc5223bb262bcf864f540ba1a51e1d33f4e74..22e3ffcb3a9d312d44579e46483fea0708505b08 100755
--- 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:
@@ -49,8 +49,11 @@ void los_vfs_init(void)
return;
}
+#ifdef LOSCFG_FS_FAT_DISK
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
index e05b94a417fd746e5d8f71162d60d121f70147ec..27315672f70ba83609f4516b70ec0437f31696ff 100755
--- 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
index f97cc80935ce0dc51a9e6ce954b488dae2a9ffc2..97f8d0c050398d57ee9ad8b6532cda1ffbdb8c14 100755
--- 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
index 420ed90037bc2da255530271cc431f44cdfc42d0..3b57eaab7b26239a71a9c19a4456bf0830aaf1f3 100755
--- 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
index 5ebef241474f2caf700cc5632ce39e1b8d0ea8d6..573fbf92f692e192803d01c551e5cda81e3dd5bf 100755
--- 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
index 8e429b8c900828f3393dbaf52cf4dc332852f624..e30c982f2131d0ebcb205e9d093887eeb13a4be9 100755
--- 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
index ade656742442cea5380caa00971fc7ef270aec1d..8bc41dcaa8b0220ea185035ff7160fb07b74a804 100755
--- 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
index 6631120c3133bcc39a12d82e0747665061536396..49c0b91108ef830660050dc1cf773b73d634ffeb 100755
--- 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
index 230f30badd92ebb2f63d43e8c7ee89797d6e6f8b..23a7576d9f8cbf5524e2225e2182cf0be4d2ac5f 100755
--- 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
index 3a056a1b0b99920b16454eb396d9424960743c53..d8a4caf83675292de3c7a9d81dae750368c10755 100755
--- 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;
+ }
+
+ 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;
}
- (void)write(1, buf, size);
- (void)LOS_TaskDelay(1);
}
- while (size == CAT_BUF_SIZE);
+ while (size > 0);
- free(fullpath);
+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 0000000000000000000000000000000000000000..e8094f4fed79317a79bf70faa8dd835b075601f4
--- /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 0000000000000000000000000000000000000000..06a0d2c1b9f5c4bd5fd31ab5f3ded4d31fd79acc
--- /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 0000000000000000000000000000000000000000..d703d77315c0c058eb44760cadadfcaae28ce076
--- /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 0000000000000000000000000000000000000000..d9ce09309638a5f766ba573cac05fff999d223a0
--- /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 0000000000000000000000000000000000000000..827b8d0ab5a11bc810aeb569c889cf6e56bdae84
--- /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 0000000000000000000000000000000000000000..05da29797fcdf312a0a19477c0b35b6cb029130f
--- /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
index ddcf1f7bce44a6569722a00363a9011efa54f9b9..34a2664982bfe4b070725eec436af40bab696f07 100755
--- 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
index 6c5115f5272f039ff84d7d751a1c9991e011f78d..709adc90a4eb460b61be5751cc72119a85d7b2b5 100755
--- 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
index 6900c4e4cfc8f2bdd84ba0779b85ac4981b874d9..67cb2543af7e22c602b2e1517174d0803a5f2de7 100755
--- 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
index 2112eaab467fcb8d8a848d3106f0524592a47f8e..920c581436fbf85da3b9148a246686aa13b864f1 100755
--- 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
index 937084cd63d1829010fb72b7ce70f77a8a5ce50a..36ff3f47bd8451c4b7929452a604205894c33a87 100755
--- 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:
@@ -92,7 +92,7 @@ VOID LOS_BitmapSetNBits(UINTPTR *bitmap, UINT32 start, UINT32 numsSet)
UINTPTR maskToSet = BITMAP_FIRST_WORD_MASK(start);
while (numsSet > bitsToSet) {
- *p |= bitsToSet;
+ *p |= maskToSet;
numsSet -= bitsToSet;
bitsToSet = BITMAP_BITS_PER_WORD;
maskToSet = OS_BITMAP_WORD_MASK;
diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c
index ae384c6b2e561194f4b4e5a16f2f4fb512e63d4b..7f169a68e289e829811b93466f7782ef00e83a50 100755
--- 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,45 +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;
- }
-
- ret = LOS_Fork(CLONE_FILES, "KIdle", (TSK_ENTRY_FUNC)OsIdleTask, LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE);
- if (ret < 0) {
- return LOS_NOK;
- }
- g_kernelIdleProcess = (UINT32)ret;
-
- 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
- (VOID)memset_s(OS_TCB_FROM_TID(*idleTaskID)->taskName, OS_TCB_NAME_LEN, 0, OS_TCB_NAME_LEN);
- (VOID)memcpy_s(OS_TCB_FROM_TID(*idleTaskID)->taskName, OS_TCB_NAME_LEN, idleName, strlen(idleName));
- return LOS_OK;
-}
-
LITE_OS_SEC_TEXT VOID OsProcessCBRecyleToFree(VOID)
{
UINT32 intSave;
@@ -653,53 +553,45 @@ STATIC VOID OsDeInitPCB(LosProcessCB *processCB)
return;
}
-STATIC UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
+UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
{
errno_t errRet;
- UINT32 len;
+
+ if (processCB == NULL) {
+ return LOS_EINVAL;
+ }
if (name != NULL) {
- len = strlen(name);
- if (len >= OS_PCB_NAME_LEN) {
- len = OS_PCB_NAME_LEN - 1; /* 1: Truncate, reserving the termination operator for character turns */
- }
- errRet = memcpy_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN, name, len);
- if (errRet != EOK) {
- processCB->processName[0] = '\0';
- return LOS_NOK;
+ errRet = strncpy_s(processCB->processName, OS_PCB_NAME_LEN, name, OS_PCB_NAME_LEN - 1);
+ if (errRet == EOK) {
+ return LOS_OK;
}
- processCB->processName[len] = '\0';
- return LOS_OK;
}
- (VOID)memset_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN, 0, sizeof(CHAR) * OS_PCB_NAME_LEN);
switch (processCB->processMode) {
case OS_KERNEL_MODE:
- (VOID)snprintf_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN,
- (sizeof(CHAR) * OS_PCB_NAME_LEN) - 1, "KerProcess%u", processCB->processID);
+ errRet = snprintf_s(processCB->processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
+ "KerProcess%u", processCB->processID);
break;
default:
- (VOID)snprintf_s(processCB->processName, sizeof(CHAR) * OS_PCB_NAME_LEN,
- (sizeof(CHAR) * OS_PCB_NAME_LEN) - 1, "UserProcess%u", processCB->processID);
+ errRet = snprintf_s(processCB->processName, OS_PCB_NAME_LEN, OS_PCB_NAME_LEN - 1,
+ "UserProcess%u", processCB->processID);
break;
}
+
+ if (errRet < 0) {
+ return LOS_NOK;
+ }
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;
@@ -708,42 +600,19 @@ 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("%s %d, alloc space failed\n", __FUNCTION__, __LINE__);
- return LOS_ENOMEM;
- }
- VADDR_T *ttb = LOS_PhysPagesAllocContiguous(1);
- if (ttb == NULL) {
- PRINT_ERR("%s %d, alloc ttb or space failed\n", __FUNCTION__, __LINE__);
- (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("create space failed! ret: %d, vmPage: %#x\n", retVal, vmPage);
+ 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) {
- PRINT_ERR("VidMapListInit failed!\n");
return LOS_ENOMEM;
}
#endif
@@ -829,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;
}
@@ -839,7 +708,6 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
if (ret != LOS_OK) {
ret = LOS_ENOMEM;
- PRINT_ERR("LiteIpcPoolInit failed!\n");
goto EXIT;
}
}
@@ -867,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:
@@ -878,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);
-
- return OsCreateIdleProcess();
-}
-
-LITE_OS_SEC_TEXT UINT32 LOS_ProcessYield(VOID)
-{
- UINT32 count;
- UINT32 intSave;
- LosProcessCB *runProcessCB = NULL;
+ OsCurrProcessSet(kerInitProcess);
- 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;
}
@@ -947,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;
@@ -984,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;
@@ -1009,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;
@@ -1043,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)
@@ -1087,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);
@@ -1118,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;
}
@@ -1136,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) {
@@ -1150,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;
}
@@ -1224,7 +1045,7 @@ WAIT_BACK:
return LOS_OK;
}
-STATIC INT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSave, INT32 *status)
+STATIC UINT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSave, INT32 *status)
{
ProcessGroup *group = NULL;
UINT32 pid = childCB->processID;
@@ -1246,7 +1067,7 @@ STATIC INT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSa
return pid;
}
-STATIC INT32 OsWaitChildProcessCheck(LosProcessCB *processCB, INT32 pid, LosProcessCB **childCB)
+STATIC UINT32 OsWaitChildProcessCheck(LosProcessCB *processCB, INT32 pid, LosProcessCB **childCB)
{
if (LOS_ListEmpty(&(processCB->childrenList)) && LOS_ListEmpty(&(processCB->exitChildList))) {
return LOS_ECHILD;
@@ -1300,7 +1121,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
}
if (childCB != NULL) {
- return OsWaitRecycleChildPorcess(childCB, intSave, status);
+ return (INT32)OsWaitRecycleChildPorcess(childCB, intSave, status);
}
if ((options & LOS_WAIT_WNOHANG) != 0) {
@@ -1311,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;
@@ -1325,7 +1144,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
goto ERROR;
}
- return OsWaitRecycleChildPorcess(childCB, intSave, status);
+ return (INT32)OsWaitRecycleChildPorcess(childCB, intSave, status);
ERROR:
SCHEDULER_UNLOCK(intSave);
@@ -1372,7 +1191,7 @@ STATIC UINT32 OsSetProcessGroupIDUnsafe(UINT32 pid, UINT32 gid, ProcessGroup **g
ProcessGroup *oldGroup = NULL;
ProcessGroup *newGroup = NULL;
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
- INT32 ret = OsSetProcessGroupCheck(processCB, gid);
+ UINT32 ret = OsSetProcessGroupCheck(processCB, gid);
if (ret != LOS_OK) {
return ret;
}
@@ -1445,7 +1264,7 @@ LITE_OS_SEC_TEXT INT32 LOS_GetProcessGroupID(UINT32 pid)
goto EXIT;
}
- gid = processCB->group->groupID;
+ gid = (INT32)processCB->group->groupID;
EXIT:
SCHEDULER_UNLOCK(intSave);
@@ -1457,10 +1276,9 @@ LITE_OS_SEC_TEXT INT32 LOS_GetCurrProcessGroupID(VOID)
return LOS_GetProcessGroupID(OsCurrProcessGet()->processID);
}
-STATIC VOID *OsUserInitStackAlloc(UINT32 processID, UINT32 *size)
+STATIC VOID *OsUserInitStackAlloc(LosProcessCB *processCB, UINT32 *size)
{
LosVmMapRegion *region = NULL;
- LosProcessCB *processCB = OS_PCB_FROM_PID(processID);
UINT32 stackSize = ALIGN(OS_USER_TASK_STACK_SIZE, PAGE_SIZE);
region = LOS_RegionAlloc(processCB->vmSpace, 0, stackSize,
@@ -1482,7 +1300,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
LosVmSpace *oldSpace, UINTPTR oldFiles)
{
UINT32 ret;
- errno_t errRet;
const CHAR *processName = NULL;
if ((processCB == NULL) || (name == NULL)) {
@@ -1492,20 +1309,14 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
processName = strrchr(name, '/');
processName = (processName == NULL) ? name : (processName + 1); /* 1: Do not include '/' */
- ret = OsSetProcessName(processCB, processName);
+ ret = (UINT32)OsSetTaskName(OsCurrTaskGet(), processName, TRUE);
if (ret != LOS_OK) {
return ret;
}
- errRet = memcpy_s(OsCurrTaskGet()->taskName, OS_TCB_NAME_LEN, processCB->processName, OS_PCB_NAME_LEN);
- if (errRet != EOK) {
- OsCurrTaskGet()->taskName[0] = '\0';
- return LOS_NOK;
- }
#if (LOSCFG_KERNEL_LITEIPC == YES)
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
if (ret != LOS_OK) {
- PRINT_ERR("LiteIpcPoolInit failed!\n");
return LOS_NOK;
}
#endif
@@ -1513,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);
@@ -1524,7 +1337,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
VidMapDestroy(processCB);
ret = VidMapListInit(processCB);
if (ret != LOS_OK) {
- PRINT_ERR("VidMapListInit failed!\n");
return LOS_NOK;
}
#endif
@@ -1532,13 +1344,11 @@ 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;
}
LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINTPTR mapBase, UINT32 mapSize)
{
- LosProcessCB *processCB = NULL;
LosTaskCB *taskCB = NULL;
TaskContext *taskContext = NULL;
UINT32 intSave;
@@ -1556,10 +1366,8 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
}
SCHEDULER_LOCK(intSave);
- processCB = OsCurrProcessGet();
taskCB = OsCurrTaskGet();
- processCB->threadGroupID = taskCB->taskID;
taskCB->userMapBase = mapBase;
taskCB->userMapSize = mapSize;
taskCB->taskEntry = (TSK_ENTRY_FUNC)entry;
@@ -1573,68 +1381,115 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
STATIC UINT32 OsUserInitProcessStart(UINT32 processID, TSK_INIT_PARAM_S *param)
{
UINT32 intSave;
- INT32 taskID;
+ UINT32 taskID;
INT32 ret;
taskID = OsCreateUserTask(processID, param);
- if (taskID < 0) {
+ if (taskID == OS_INVALID_VALUE) {
return LOS_NOK;
}
ret = LOS_SetTaskScheduler(taskID, LOS_SCHED_RR, OS_TASK_PRIORITY_LOWEST);
- if (ret < 0) {
+ if (ret != LOS_OK) {
PRINT_ERR("User init process set scheduler failed! ERROR:%d \n", ret);
SCHEDULER_LOCK(intSave);
(VOID)OsTaskDeleteUnsafe(OS_TCB_FROM_TID(taskID), OS_PRO_EXIT_OK, intSave);
- return -ret;
+ return LOS_NOK;
}
return LOS_OK;
}
-LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
+STATIC UINT32 OsLoadUserInit(LosProcessCB *processCB)
{
+ /* userInitTextStart -----
+ * | user text |
+ *
+ * | user data | initSize
+ * userInitBssStart ---
+ * | user bss | initBssSize
+ * userInitEnd --- -----
+ */
+ errno_t errRet;
INT32 ret;
- UINT32 size;
- TSK_INIT_PARAM_S param = { 0 };
- VOID *stack = NULL;
- VOID *userText = NULL;
CHAR *userInitTextStart = (CHAR *)&__user_init_entry;
CHAR *userInitBssStart = (CHAR *)&__user_init_bss;
CHAR *userInitEnd = (CHAR *)&__user_init_end;
UINT32 initBssSize = userInitEnd - userInitBssStart;
UINT32 initSize = userInitEnd - userInitTextStart;
+ VOID *userBss = NULL;
+ VOID *userText = NULL;
- LosProcessCB *processCB = OS_PCB_FROM_PID(g_userInitProcess);
- ret = OsProcessCreateInit(processCB, OS_USER_MODE, "Init", OS_PROCESS_USERINIT_PRIORITY);
- if (ret != LOS_OK) {
- return ret;
+ if ((LOS_Align((UINTPTR)userInitTextStart, PAGE_SIZE) != (UINTPTR)userInitTextStart) ||
+ (LOS_Align((UINTPTR)userInitEnd, PAGE_SIZE) != (UINTPTR)userInitEnd)) {
+ return LOS_EINVAL;
+ }
+
+ if ((initSize == 0) || (initSize <= initBssSize)) {
+ return LOS_EINVAL;
}
userText = LOS_PhysPagesAllocContiguous(initSize >> PAGE_SHIFT);
if (userText == NULL) {
- ret = LOS_NOK;
- goto ERROR;
+ return LOS_NOK;
}
- (VOID)memcpy_s(userText, initSize, (VOID *)&__user_init_load_addr, initSize);
+ errRet = memcpy_s(userText, initSize, (VOID *)&__user_init_load_addr, initSize - initBssSize);
+ if (errRet != EOK) {
+ PRINT_ERR("Load user init text, data and bss failed! err : %d\n", errRet);
+ goto ERROR;
+ }
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;
}
- (VOID)memset_s((VOID *)((UINTPTR)userText + userInitBssStart - userInitTextStart), initBssSize, 0, initBssSize);
+ /* The User init boot segment may not actually exist */
+ if (initBssSize != 0) {
+ userBss = (VOID *)((UINTPTR)userText + userInitBssStart - userInitTextStart);
+ errRet = memset_s(userBss, initBssSize, 0, initBssSize);
+ if (errRet != EOK) {
+ PRINT_ERR("memset user init bss failed! err : %d\n", errRet);
+ goto ERROR;
+ }
+ }
+
+ return LOS_OK;
- stack = OsUserInitStackAlloc(g_userInitProcess, &size);
+ERROR:
+ (VOID)LOS_PhysPagesFreeContiguous(userText, initSize >> PAGE_SHIFT);
+ return LOS_NOK;
+}
+
+LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
+{
+ UINT32 ret;
+ UINT32 size;
+ TSK_INIT_PARAM_S param = { 0 };
+ VOID *stack = NULL;
+
+ LosProcessCB *processCB = OS_PCB_FROM_PID(g_userInitProcess);
+ ret = OsProcessCreateInit(processCB, OS_USER_MODE, "Init", OS_PROCESS_USERINIT_PRIORITY);
+ if (ret != LOS_OK) {
+ return ret;
+ }
+
+ ret = OsLoadUserInit(processCB);
+ if (ret != LOS_OK) {
+ goto ERROR;
+ }
+
+ stack = OsUserInitStackAlloc(processCB, &size);
if (stack == NULL) {
- PRINTK("user init process malloc user stack failed!\n");
- ret = LOS_NOK;
+ PRINT_ERR("Alloc user init process user stack failed!\n");
goto ERROR;
}
- param.pfnTaskEntry = (TSK_ENTRY_FUNC)userInitTextStart;
+ param.pfnTaskEntry = (TSK_ENTRY_FUNC)(CHAR *)&__user_init_entry;
param.userParam.userSP = (UINTPTR)stack + size;
param.userParam.userMapBase = (UINTPTR)stack;
param.userParam.userMapSize = size;
@@ -1648,7 +1503,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
return LOS_OK;
ERROR:
- (VOID)LOS_PhysPagesFreeContiguous(userText, initSize >> PAGE_SHIFT);
OsDeInitPCB(processCB);
return ret;
}
@@ -1734,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;
}
@@ -1747,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);
@@ -1814,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;
}
@@ -1842,20 +1693,14 @@ 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);
return LOS_OK;
}
-STATIC INT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProcessCB *run)
+STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProcessCB *run)
{
UINT32 ret;
@@ -1973,14 +1818,14 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
OsProcessExit(OsCurrTaskGet(), (UINT32)status);
}
-LITE_OS_SEC_TEXT UINT32 OsGetUserInitProcessID(VOID)
+LITE_OS_SEC_TEXT UINT32 LOS_GetSystemProcessMaximum(VOID)
{
- return g_userInitProcess;
+ return g_processMaxNum;
}
-LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
+LITE_OS_SEC_TEXT UINT32 OsGetUserInitProcessID(VOID)
{
- return g_kernelIdleProcess;
+ return g_userInitProcess;
}
LITE_OS_SEC_TEXT UINT32 OsGetKernelInitProcessID(VOID)
@@ -1988,6 +1833,11 @@ 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
index 924dc1ed13738a2bc7d63c32b20d170eab682dd4..d7b3fe333e743ad2500ad1f6122b729b4a4abfff 100755
--- 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;
-
- /*
- * 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--;
+ LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
+
+ if (LOS_ListEmpty(head)) {
+ LOS_ListHeadInsert(head, &sortList->sortLinkNode);
+ sortLinkHeader->nodeNum++;
+ return;
}
- 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);
+
+ SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
+ if (listSorted->responseTime >= sortList->responseTime) {
+ LOS_ListAdd(head, &sortList->sortLinkNode);
+ sortLinkHeader->nodeNum++;
+ return;
}
+
+ 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;
+ }
+
+ prevNode = prevNode->pstPrev;
+ } while (1);
}
-LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
+VOID OsDeleteNodeSortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
- LOS_DL_LIST *tmp = listNode->pstPrev;
+ LOS_ListDelete(&sortList->sortLinkNode);
+ SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
+ sortLinkHeader->nodeNum--;
+}
+
+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;
+
+ if (LOS_ListEmpty(head)) {
+ return (UINT64)-1;
+ }
- /* recursive check until double link round to itself */
- while (tmp != listNode) {
- if (tmp == listHead) {
- goto FOUND;
+ do {
+ SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
+ if (listSorted->responseTime <= startTime) {
+ expirTime = startTime;
+ list = list->pstNext;
+ } else {
+ nextExpirTime = listSorted->responseTime;
+ break;
}
- tmp = tmp->pstPrev;
+ } while (list != head);
+
+ if (expirTime == 0) {
+ return nextExpirTime;
+ }
+
+ if (nextExpirTime == 0) {
+ return expirTime;
}
- /* delete invalid sortlink node */
- PRINT_ERR("the node is not on this sortlink!\n");
- OsBackTrace();
+ if ((nextExpirTime - expirTime) <= OS_US_PER_TICK) {
+ return nextExpirTime;
+ }
-FOUND:
- return;
+ return expirTime;
}
-LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
+STATIC Percpu *OsFindIdleCpu(UINT16 *ildeCpuID)
{
- LOS_DL_LIST *listObject = NULL;
- SortLinkList *nextSortList = NULL;
- UINT32 sortIndex;
-
- sortIndex = SORT_INDEX(sortList->idxRollNum);
- listObject = sortLinkHeader->sortLink + sortIndex;
+ 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;
+ }
- /* check if pstSortList node is on the right sortlink */
- OsCheckSortLink(listObject, &sortList->sortLinkNode);
+ cpuID++;
+ } while (cpuID < LOSCFG_KERNEL_CORE_NUM);
+#endif
- 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);
+ return idleCpu;
}
-LITE_OS_SEC_TEXT STATIC UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex)
+VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
{
- UINT32 expireTime;
+ 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 (sortIndex > curSortIndex) {
- sortIndex = sortIndex - curSortIndex;
+ 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 {
- sortIndex = OS_TSK_SORTLINK_LEN - curSortIndex + sortIndex;
+ 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));
}
- expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex;
- return expireTime;
+#endif
+ LOS_SpinUnlockRestore(spinLock, intSave);
}
-LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
+VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type)
{
- 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;
- }
- }
- }
+ UINT32 intSave;
+#if (LOSCFG_KERNEL_SMP == YES)
+ Percpu *cpu = OsPercpuGetByID(node->cpuid);
+#else
+ Percpu *cpu = OsPercpuGetByID(0);
+#endif
- if (minRollNum != OS_TSK_LOW_BITS_MASK) {
- expireTime = OsCalcExpierTime(minRollNum, minSortIndex, sortLinkHeader->cursor);
+ 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);
}
- return expireTime;
+ LOS_SpinLockSave(spinLock, &intSave);
+ if (node->responseTime != OS_SORT_LINK_INVALID_TIME) {
+ OsDeleteNodeSortLink(sortLinkHeader, node);
+ }
+ LOS_SpinUnlockRestore(spinLock, intSave);
}
-LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
+UINT64 OsGetNextExpireTime(UINT64 startTime)
{
- SortLinkList *sortList = NULL;
- LOS_DL_LIST *listObject = NULL;
- UINT32 i;
- UINT32 sortIndex;
- UINT32 rollNum;
+ UINT32 intSave;
+ Percpu *cpu = OsPercpuGet();
+ SortLinkAttribute *taskHeader = &cpu->taskSortLink;
+ SortLinkAttribute *swtmrHeader = &cpu->swtmrSortLink;
- if (sleepTicks == 0) {
- return;
- }
- sortIndex = sleepTicks & OS_TSK_SORTLINK_MASK;
- rollNum = (sleepTicks >> OS_TSK_SORTLINK_LOGLEN) + 1;
- if (sortIndex == 0) {
- rollNum--;
- sortIndex = OS_TSK_SORTLINK_LEN;
- }
+ LOS_SpinLockSave(&cpu->taskSortLinkSpin, &intSave);
+ UINT64 taskExpirTime = OsGetSortLinkNextExpireTime(taskHeader, startTime);
+ LOS_SpinUnlockRestore(&cpu->taskSortLinkSpin, intSave);
- 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);
- }
- }
- }
- sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN;
+ LOS_SpinLockSave(&cpu->swtmrSortLinkSpin, &intSave);
+ UINT64 swtmrExpirTime = OsGetSortLinkNextExpireTime(swtmrHeader, startTime);
+ LOS_SpinUnlockRestore(&cpu->swtmrSortLinkSpin, intSave);
+
+ return (taskExpirTime < swtmrExpirTime) ? taskExpirTime : swtmrExpirTime;
}
-LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
- const SortLinkList *targetSortList)
+UINT32 OsSortLinkGetTargetExpireTime(const SortLinkList *targetSortList)
{
- SortLinkList *listSorted = NULL;
- LOS_DL_LIST *listObject = NULL;
- UINT32 sortIndex = SORT_INDEX(targetSortList->idxRollNum);
- UINT32 rollNum = ROLLNUM(targetSortList->idxRollNum);
+ UINT64 currTimes = OsGerCurrSchedTimeCycle();
+ if (currTimes >= targetSortList->responseTime) {
+ return 0;
+ }
+
+ return (UINT32)(targetSortList->responseTime - currTimes) / OS_CYCLE_PER_TICK;
+}
- listObject = sortLinkHeader->sortLink + sortIndex;
+UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
+{
+ LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
- 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 0;
}
- return OsCalcExpierTime(rollNum, sortIndex, sortLinkHeader->cursor);
+
+ 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
index e091d472fd2db0855a6d128fa4a85ec9df52ec6c..74db4c998de4fe169bb87556633dd4ea47d21228 100755
--- 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);
-
- swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
- if (swtmrHandler != NULL) {
- swtmrHandler->handler = swtmr->pfnHandler;
- swtmrHandler->arg = swtmr->uwArg;
+ OsDeleteNodeSortLink(swtmrSortLink, sortList);
- 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);
+ SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
+ LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
- 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
index 69c9aeed14af120005754885e4651902788fee1e..afee16d56cacbd79b3c7b3caea9e1e8ae7a16802 100755
--- 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
index 751aa4f900587158e7ed41f6196f800ac8d41616..dd6bb44e917aef5f0f0adb6e232fbbfeef2df50e 100755
--- 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
@@ -61,7 +55,7 @@
#if (LOSCFG_KERNEL_LITEIPC == YES)
#include "hm_liteipc.h"
#endif
-#include "user_copy.h"
+#include "los_strncpy_from_user.h"
#include "los_vm_syscall.h"
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
#include "los_oom.h"
@@ -89,25 +83,23 @@ 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()
{
UINT32 i;
CHAR *name = "osMain";
- errno_t ret;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
@@ -117,10 +109,7 @@ VOID OsSetMainTask()
g_mainTask[i].lockDep.lockDepth = 0;
g_mainTask[i].lockDep.waitLock = NULL;
#endif
- ret = memcpy_s(g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, strlen(name));
- if (ret != EOK) {
- g_mainTask[i].taskName[0] = '\0';
- }
+ (VOID)strncpy_s(g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, OS_TCB_NAME_LEN - 1);
LOS_ListInit(&g_mainTask[i].lockList);
}
}
@@ -128,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;
@@ -195,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;
}
@@ -214,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;
}
@@ -243,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;
@@ -337,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)
@@ -370,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;
}
@@ -394,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;
@@ -449,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);
@@ -702,7 +542,6 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
LOS_ListInit(&(taskCB->msgListHead));
- (VOID)memset_s(taskCB->accessMap, sizeof(taskCB->accessMap), 0, sizeof(taskCB->accessMap));
#endif
taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;
taskCB->taskStatus = OS_TASK_STATUS_INIT;
@@ -715,10 +554,11 @@ 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);
}
-LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
- const VOID *stackPtr, const VOID *topStack)
+STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
+ const VOID *stackPtr, const VOID *topStack)
{
UINT32 intSave;
UINT32 ret;
@@ -749,20 +589,16 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_IN
processCB->threadCount++;
SCHEDULER_UNLOCK(intSave);
- if (initParam->pcName == NULL) {
- (VOID)memset_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN, 0, sizeof(CHAR) * OS_TCB_NAME_LEN);
- (VOID)snprintf_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN,
- (sizeof(CHAR) * OS_TCB_NAME_LEN) - 1, "thread%u", numCount);
- return LOS_OK;
- }
-
- if (mode == OS_KERNEL_MODE) {
- ret = memcpy_s(taskCB->taskName, sizeof(CHAR) * OS_TCB_NAME_LEN, initParam->pcName, strlen(initParam->pcName));
- if (ret != EOK) {
- taskCB->taskName[0] = '\0';
+ if (initParam->pcName != NULL) {
+ ret = (UINT32)OsSetTaskName(taskCB, initParam->pcName, FALSE);
+ if (ret == LOS_OK) {
+ return LOS_OK;
}
}
+ if (snprintf_s(taskCB->taskName, OS_TCB_NAME_LEN, OS_TCB_NAME_LEN - 1, "thread%u", numCount) < 0) {
+ return LOS_NOK;
+ }
return LOS_OK;
}
@@ -855,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;
@@ -875,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,
@@ -892,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;
@@ -907,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();
}
@@ -980,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;
}
@@ -997,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();
}
@@ -1126,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);
@@ -1213,6 +1036,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
OS_GOTO_ERREND();
}
+ if (taskCB->taskStatus & (OS_TASK_FLAG_SYSTEM_TASK | OS_TASK_FLAG_NO_DELETE)) {
+ SCHEDULER_UNLOCK(intSave);
+ OsBackTrace();
+ return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
+ }
+
processCB = OS_PCB_FROM_PID(taskCB->processID);
if (processCB->threadNumber == 1) {
if (processCB == OsCurrProcessGet()) {
@@ -1254,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;
}
@@ -1290,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;
@@ -1310,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;
@@ -1344,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;
@@ -1410,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;
}
@@ -1436,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)
@@ -1500,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;
@@ -1519,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)) {
@@ -1541,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;
}
@@ -1592,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;
/*
@@ -1603,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) {
@@ -1632,66 +1362,48 @@ 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 OsSetCurrTaskName(const CHAR *name)
+LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
{
UINT32 intSave;
- UINT32 strLen;
errno_t err;
- LosTaskCB *runTask = NULL;
- LosProcessCB *runProcess = NULL;
+ LosProcessCB *processCB = NULL;
const CHAR *namePtr = NULL;
CHAR nameBuff[OS_TCB_NAME_LEN] = { 0 };
- runTask = OsCurrTaskGet();
- runProcess = OS_PCB_FROM_PID(runTask->processID);
- if (runProcess->processMode == OS_USER_MODE) {
- (VOID)LOS_ArchCopyFromUser(nameBuff, (const VOID *)name, OS_TCB_NAME_LEN);
- strLen = strnlen(nameBuff, OS_TCB_NAME_LEN);
+ if ((taskCB == NULL) || (name == NULL)) {
+ return EINVAL;
+ }
+
+ if (LOS_IsUserAddress((VADDR_T)(UINTPTR)name)) {
+ err = LOS_StrncpyFromUser(nameBuff, (const CHAR *)name, OS_TCB_NAME_LEN);
+ if (err < 0) {
+ return -err;
+ }
namePtr = nameBuff;
} else {
- strLen = strnlen(name, OS_TCB_NAME_LEN);
namePtr = name;
}
- if (strLen == 0) {
- err = EINVAL;
- PRINT_ERR("set task(%u) name failed! %d\n", OsCurrTaskGet()->taskID, err);
- return err;
- } else if (strLen == OS_TCB_NAME_LEN) {
- strLen = strLen - 1;
- }
-
SCHEDULER_LOCK(intSave);
- err = memcpy_s(runTask->taskName, OS_TCB_NAME_LEN, (VOID *)namePtr, strLen);
+ err = strncpy_s(taskCB->taskName, OS_TCB_NAME_LEN, (VOID *)namePtr, OS_TCB_NAME_LEN - 1);
if (err != EOK) {
- runTask->taskName[0] = '\0';
err = EINVAL;
goto EXIT;
}
- runTask->taskName[strLen] = '\0';
-
+ err = LOS_OK;
+ processCB = OS_PCB_FROM_PID(taskCB->processID);
/* if thread is main thread, then set processName as taskName */
- if (runTask->taskID == runProcess->threadGroupID) {
- (VOID)memcpy_s(runProcess->processName, OS_PCB_NAME_LEN, (VOID *)runTask->taskName, OS_TCB_NAME_LEN);
+ if ((taskCB->taskID == processCB->threadGroupID) && (setPName == TRUE)) {
+ err = (INT32)OsSetProcessName(processCB, (const CHAR *)taskCB->taskName);
+ if (err != LOS_OK) {
+ err = EINVAL;
+ }
}
- SCHEDULER_UNLOCK(intSave);
- return LOS_OK;
-
EXIT:
SCHEDULER_UNLOCK(intSave);
return err;
@@ -1747,6 +1459,7 @@ LITE_OS_SEC_TEXT VOID OsTaskExitGroup(UINT32 status)
(VOID)OsTaskSyncWait(runTask[cpu]);
}
#endif
+ processCB->threadGroupID = OsCurrTaskGet()->taskID;
SCHEDULER_UNLOCK(intSave);
LOS_ASSERT(processCB->threadNumber == 1);
@@ -1825,20 +1538,18 @@ 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;
}
return LOS_OK;
}
-LITE_OS_SEC_TEXT_INIT INT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
+LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
{
LosProcessCB *processCB = NULL;
UINT32 taskID;
@@ -1900,67 +1611,38 @@ LOS_ERREND:
return policy;
}
-LITE_OS_SEC_TEXT INT32 OsTaskSchedulerSetUnsafe(LosTaskCB *taskCB, UINT16 policy, UINT16 priority,
- BOOL policyFlag, UINT32 intSave)
+LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
{
- BOOL needSched = TRUE;
- if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
- OS_TASK_PRI_QUEUE_DEQUEUE(OS_PCB_FROM_PID(taskCB->processID), taskCB);
- }
+ UINT32 intSave;
+ BOOL needSched = FALSE;
- if (policyFlag == TRUE) {
- if (policy == LOS_SCHED_FIFO) {
- taskCB->timeSlice = 0;
- }
- taskCB->policy = policy;
+ if (OS_TID_CHECK_INVALID(taskID)) {
+ return LOS_ESRCH;
}
- taskCB->priority = priority;
- if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
- taskCB->taskStatus &= ~OS_TASK_STATUS_INIT;
- taskCB->taskStatus |= OS_TASK_STATUS_READY;
+ if (priority > OS_TASK_PRIORITY_LOWEST) {
+ return LOS_EINVAL;
}
- 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;
+ if ((policy != LOS_SCHED_FIFO) && (policy != LOS_SCHED_RR)) {
+ return LOS_EINVAL;
}
-SCHEDULE:
+ SCHEDULER_LOCK(intSave);
+ needSched = OsSchedModifyTaskSchedParam(OS_TCB_FROM_TID(taskID), policy, priority);
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
- if (OS_SCHEDULER_ACTIVE && (needSched == TRUE)) {
+ if (needSched && OS_SCHEDULER_ACTIVE) {
LOS_Schedule();
}
return LOS_OK;
}
-LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
+LITE_OS_SEC_TEXT UINT32 LOS_GetSystemTaskMaximum(VOID)
{
- UINT32 intSave;
- LosTaskCB *taskCB = NULL;
-
- if (OS_TID_CHECK_INVALID(taskID)) {
- return LOS_ESRCH;
- }
-
- if (priority > OS_TASK_PRIORITY_LOWEST) {
- return LOS_EINVAL;
- }
-
- if ((policy != LOS_SCHED_FIFO) && (policy != LOS_SCHED_RR)) {
- return LOS_EINVAL;
- }
-
- SCHEDULER_LOCK(intSave);
- taskCB = OS_TCB_FROM_TID(taskID);
- return OsTaskSchedulerSetUnsafe(taskCB, policy, priority, TRUE, intSave);
+ return g_taskMaxNum;
}
LITE_OS_SEC_TEXT VOID OsWriteResourceEvent(UINT32 events)
@@ -2005,7 +1687,11 @@ LITE_OS_SEC_TEXT UINT32 OsCreateResourceFreeTask(VOID)
taskInitParam.uwStackSize = OS_TASK_RESOURCE_STATCI_SIZE;
taskInitParam.pcName = "ResourcesTask";
taskInitParam.usTaskPrio = OS_TASK_RESOURCE_FREE_PRIORITY;
- return LOS_TaskCreate(&taskID, &taskInitParam);
+ ret = LOS_TaskCreate(&taskID, &taskInitParam);
+ if (ret == LOS_OK) {
+ OS_TCB_FROM_TID(taskID)->taskStatus |= OS_TASK_FLAG_NO_DELETE;
+ }
+ return ret;
}
#ifdef __cplusplus
diff --git a/kernel/base/core/los_tick.c b/kernel/base/core/los_tick.c
index 11cfdd3e64f301f624ad001abf3085ea37a7f95f..23f1f5ec3ebe9c46da49292bbe9f46744c0bf956 100755
--- 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
old mode 100755
new mode 100644
index 0abb485afd246647cf7c135eb632a4ddad52c548..24719cc7f76384e23f12621fa0673d1b43f61053
--- 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
old mode 100755
new mode 100644
index 72a9df4ae4437ed64e97355d293ad8b3a41790bb..c442f605479b6831d70fd29a24bc1ad6015481ad
--- 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
old mode 100755
new mode 100644
index 6645645dcf024d918db1608b21099e5d8d7cdf8e..40a667ae2f35ea217e9d4ac23d01ed5fbc0ee6d7
--- 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
index 519a4d761d89496b5f50153b2068fff43bf6a965..22d20c9ebfd932cc8ca7afe83ca4f2f39dbe3bfe 100755
--- 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
index f2d81831b1d0e1f9dac4016543148070d9f7804c..7671115b9a4a9ffc27badd05fa1c2619690eb267 100755
--- 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 100755
index 818b8f62fdeabb263b5c041e845488d508b17ea3..0000000000000000000000000000000000000000
--- 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
old mode 100755
new mode 100644
index a9cd29569ef8b4e4a1449831d5ebea19bcf8d1a9..c5d1c1cbab9b4532c2509bec8fede58d5ab689f4
--- 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
old mode 100755
new mode 100644
index ed904c2d876a834f46a3c95c8d282550e69975e4..9a06ddeaf24ecb8fa225c8e7e59ad5fec6eb019c
--- 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
index 64a9c6396bd3c4b422bbba561d86721cd622b50d..12c6e0229f8463fc8d36077db1a8edab0b6c4840 100755
--- 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
old mode 100755
new mode 100644
index 7c093c5b21ad004576921cad315631b5bdd2f887..a2a9f581085e2cac7150eea70c168c62be86235d
--- 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
index c729ab1fc05910fb32f1c3221d60df88de3d10bd..129902a8692b2bfcc1109228b54c01171a607161 100755
--- 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
index 3668d2108c59c3179725a46cc26ce2743860ed7a..22abcb85865d586efbab504d2508cc462d77cd41 100755
--- 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
index ab0d860a5f5f320f4207262fbad8cb55f5bbb9bf..0a82c5303dd22d7411d7867d005974d92c20d530 100755
--- 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
old mode 100755
new mode 100644
index 0f1b4300cd873e64785b820b6529038d0bac171f..2725bddd6a5ddef1e0e7039c867c0a77a00980f7
--- 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
old mode 100755
new mode 100644
index 4ccb7777164ad7844ef704ae17d7400757963bde..f86aee95a73015d8ee69d51ae9ad4733bbb328e2
--- 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 100755
index 67e65b71f6302d427df9d5e624324281f457ba35..0000000000000000000000000000000000000000
--- 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
index 81639c86226a1607ec13e70aa801d9fc825badd7..bc3dc36181462dcb41df0455209fdac2c2bb883f 100755
--- 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"
@@ -78,56 +76,54 @@ typedef struct {
typedef struct ProcessCB {
CHAR processName[OS_PCB_NAME_LEN]; /**< Process name */
- UINT32 processID; /**< process ID = leader thread ID */
- UINT16 processStatus; /**< [15:4] process Status; [3:0] The number of threads currently
+ UINT32 processID; /**< Process ID */
+ 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 priority; /**< Process priority */
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 */
+ UINT32 exitCode; /**< Process exit status */
LOS_DL_LIST pendList; /**< Block list to which the process belongs */
- LOS_DL_LIST childrenList; /**< my children process list */
- LOS_DL_LIST exitChildList; /**< my exit children process list */
- LOS_DL_LIST siblingList; /**< linkage in my parent's children list */
+ LOS_DL_LIST childrenList; /**< Children process list */
+ LOS_DL_LIST exitChildList; /**< Exit children process list */
+ LOS_DL_LIST siblingList; /**< Linkage in parent's children list */
ProcessGroup *group; /**< Process group to which a process belongs */
- LOS_DL_LIST subordinateGroupList; /**< linkage in my group list */
+ 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 */
#if (LOSCFG_KERNEL_SMP == YES)
UINT32 timerCpu; /**< CPU core number of this task is delayed or pended */
#endif
- UINTPTR sigHandler; /**< signal handler */
- sigset_t sigShare; /**< signal share bit */
+ 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);
@@ -479,7 +450,8 @@ extern VOID OsWaitSignalToWakeProcess(LosProcessCB *processCB);
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 INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy, BOOL policyFlag);
+extern UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name);
+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
old mode 100755
new mode 100644
index 5d1b7238e391d18e64391397535e4d8ecab13b3a..b731213522f43fc458962c8727a89808137e0446
--- 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
old mode 100755
new mode 100644
index 746b78012d9f5f9c85e94cc693fdca067c845a83..964728597fef8dfdb2170c2e797f62bb2f8c62d8
--- 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 0000000000000000000000000000000000000000..55681501682fe9f84fb7b3385943f11bf64d39c1
--- /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
index cc84e9e018f3873a910191a9fb2373aed46ae73f..23141362a0c2f5a65cdd0070be4dd03177cf0364 100755
--- 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
old mode 100755
new mode 100644
index ed156c79d0e61457cb27f39d717f24c6a514963f..e684c3dc5b5017991f7f21bd89a856feb4c8e124
--- 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
index 6e19ee1eea88692e265a702ead2872710b6ea6d6..8476a1bc645017b68674ec9ac8d2d0c76cb61e23 100755
--- 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
index da538a5f43b65031e058cc5f7d13b03d1be9e1c1..86b9134f094e0b3e43f04cbe766176ef7232deed 100755
--- 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
index ce826c46e0b43d50c0c876efa60ae7dc04799a73..fa2edf17accde62bdb3e0d2c82c1fd7b40e22a11 100755
--- 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
old mode 100755
new mode 100644
index 6540c64944f5f16c5e10695b8e41ca3adb24a728..2698433e68d4ea8347ab8d6ff33a6fe56fd8e5ed
--- 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
index 74754985c2986fdc574f2744f6178b6b2d1eb61f..3ca4e9f273f7738b0e4d919887d45c21859f7ddc 100755
--- 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
old mode 100755
new mode 100644
index 8eb0d2650bd60eab0b1c349b082b3ee0b25736b9..bfbba009f96e7ae561ded52cc1aada6a96afa787
--- 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
index 93fd19c250bf10a6572091ef40cb244a7c1ab648..f980a1d16e2910a3b13975434cf36aef3bdfac42 100755
--- 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
index 6ddd274ac7ff8aa1a9e17330d20f73c58e1f8963..d40c9511997ab08f56e0b31acacd67143ea80b77 100755
--- 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
@@ -296,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;
@@ -323,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;
@@ -341,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)
@@ -373,7 +389,6 @@ typedef int (*ForEachTaskCB)(LosTaskCB *tcb, void *arg);
*/
extern UINT32 g_taskMaxNum;
-
/**
* @ingroup los_task
* Starting address of a task.
@@ -443,133 +458,29 @@ 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 INT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
-extern INT32 OsTaskSchedulerSetUnsafe(LosTaskCB *taskCB, UINT16 policy, UINT16 priority,
- BOOL policyFlag, UINT32 intSave);
-extern INT32 OsSetCurrTaskName(const CHAR *name);
+extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
+extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName);
extern VOID OsTaskCBRecyleToFree(VOID);
extern VOID OsTaskExitGroup(UINT32 status);
extern VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status);
@@ -578,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
old mode 100755
new mode 100644
index d7c5c730754998fd6aaceae6b635938f184a3303..4621733f9c1885626a8d859739aabd274195b074
--- 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
old mode 100755
new mode 100644
index 62c2a53ed9093b20f3e423aa012a00e6cbeeab4a..eff17a91f837ff459e6076e94ec0ef4462156467
--- 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
index 8cb3f9469422858069aed8acb500e8c76c7c3774..18e6b031793ffccc8a73e1ae93567f1e284ae236 100755
--- 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
index 8b2b290fa5a61a34aba6348334c911b5424cb029..f2dd70bf676072eb4f23515724293addc8b33b4f 100755
--- 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
old mode 100755
new mode 100644
index bf07a97c9bc0abf8727fba3341637d9bc0355958..e8d13a7ceae809cf18e0591d47f9122287fb5828
--- 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
old mode 100755
new mode 100644
index ddee36901f5c7f342e003f9fe093bae76e061173..d3c650a208af83212c3e6c00c459bafa02315cb7
--- 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
index 16c68f196b0d1b6ebbbbaeb81b14365060a097b7..e0d2d4ca88ab540e5345c78ca4f20961b61f623f 100755
--- 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
index f73aa89a9f5959269057843b3dfe12c15a24ba6e..b10e3462eb3fe0f7f61f9de6fa8e00753ff24d6b 100755
--- 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 >= PERIPH_PMM_BASE) && (addr <= PERIPH_PMM_BASE + PERIPH_PMM_SIZE))
-#define IS_MEMORY_ADDR(addr) ((addr >= DDR_MEM_ADDR) && (addr <= DDR_MEM_ADDR + 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
old mode 100755
new mode 100644
index f396225f8329a56e8b7ea75dd1a5ea1b8007c33d..aa3c36fe65ae5902e461039a24c5007b7a4e7055
--- 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
index 3ebd7570f51322d8065116f78fcd7adc02f6305d..cfd9dffe27cd8591e0b788aaa04c987d9b45c022 100755
--- 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;
}
@@ -240,7 +246,6 @@ STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
return (vaddr + len > vaddr) && LOS_IsUserAddress(vaddr) && (LOS_IsUserAddress(vaddr + len - 1));
}
-
STATIC INLINE BOOL LOS_IsVmallocAddress(VADDR_T vaddr)
{
return ((vaddr >= VMALLOC_START) &&
@@ -262,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);
@@ -282,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
old mode 100755
new mode 100644
index d13a190ada1f74d1732504b86953f250f4ed818d..bb96b044cc0bc3951e826b27e89dd1de20035a89
--- 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
index d8beabe56b542fc712d7b54fac6f6ad26e25600e..8d461d418608014d902b639dcf04940ee029f27b 100755
--- 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
old mode 100755
new mode 100644
index 6c2cd79fd75fb0f5e7f36b469de5bd2cdfad1a61..b8a7d1f06baccfcb870e8f95954d0280c52f1783
--- 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
old mode 100755
new mode 100644
index 05448c463621131595333da529f0ee589816876c..56e1411fbe4670a75026e4450e30c37b35c1bdb4
--- 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
old mode 100755
new mode 100644
index 0292effd8a4a31023dede17f848cc92e7c3b0d70..fd9a6b9bf387bd41384e4a60d20c9e0dbfba8092
--- 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,11 +40,23 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#define DEFINE_(X) X##U
-#define DEFINE(X) DEFINE_(X)
+#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)
-#define KERNEL_VMM_BASE DEFINE(KERNEL_VADDR_BASE)
-#define KERNEL_VMM_SIZE DEFINE(KERNEL_VADDR_SIZE)
+#define KERNEL_VMM_BASE U32_C(KERNEL_VADDR_BASE)
+#define KERNEL_VMM_SIZE U32_C(KERNEL_VADDR_SIZE)
#define KERNEL_ASPACE_BASE KERNEL_VMM_BASE
#define KERNEL_ASPACE_SIZE KERNEL_VMM_SIZE
@@ -57,11 +69,11 @@ extern "C" {
#define VMALLOC_SIZE 0x08000000
#define PERIPH_DEVICE_BASE (VMALLOC_START + VMALLOC_SIZE)
-#define PERIPH_DEVICE_SIZE PERIPH_PMM_SIZE
+#define PERIPH_DEVICE_SIZE U32_C(PERIPH_PMM_SIZE)
#define PERIPH_CACHED_BASE (PERIPH_DEVICE_BASE + PERIPH_DEVICE_SIZE)
-#define PERIPH_CACHED_SIZE PERIPH_PMM_SIZE
+#define PERIPH_CACHED_SIZE U32_C(PERIPH_PMM_SIZE)
#define PERIPH_UNCACHED_BASE (PERIPH_CACHED_BASE + PERIPH_CACHED_SIZE)
-#define PERIPH_UNCACHED_SIZE PERIPH_PMM_SIZE
+#define PERIPH_UNCACHED_SIZE U32_C(PERIPH_PMM_SIZE)
#define IO_DEVICE_ADDR(paddr) (paddr - PERIPH_PMM_BASE + PERIPH_DEVICE_BASE)
#define IO_CACHED_ADDR(paddr) (paddr - PERIPH_PMM_BASE + PERIPH_CACHED_BASE)
diff --git a/kernel/base/ipc/los_event.c b/kernel/base/ipc/los_event.c
index 92b90d623708c73264bffb2472ac106ef944835a..a17e3280d13cfbf4222ac61acaa6bf1677a58ee2 100755
--- 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
index bcce88093ade9458b32574874a1fabd64750c8da..5ce2054f3807e3c5888174c66f2773b31bef493c 100755
--- 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 futexKey;
+}
+
+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 interval;
+ return index;
}
-STATIC INLINE VOID OsFutexSetKey(UINTPTR futexKey, FutexNode *node)
+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,41 +489,47 @@ STATIC INT32 OsFindAndInsertToHash(FutexNode *node)
return ret;
}
-STATIC INT32 OsFutexWaitParmaCheck(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absTime)
+STATIC INT32 OsFutexKeyShmPermCheck(const UINT32 *userVaddr, const UINT32 flags)
{
- UINTPTR futexKey = (UINTPTR)userVaddr;
- UINT32 lockVal;
- INT32 ret;
+ 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)
+{
+ VADDR_T vaddr = (VADDR_T)(UINTPTR)userVaddr;
if (OS_INT_ACTIVE) {
return LOS_EINTR;
}
- if (flags) {
- PRINT_ERR("Futex wait parma check failed! error flags: 0x%x\n", 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 parma 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 (!absTime) {
- PRINT_ERR("Futex wait parma check failed! error absTime: %u\n", absTime);
+ 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;
}
- ret = LOS_ArchCopyFromUser(&lockVal, userVaddr, sizeof(UINT32));
- if (ret) {
- PRINT_ERR("Futex wait parma check failed! copy from user failed!\n");
+ if (!absTime) {
+ PRINT_ERR("Futex wait param check failed! error absTime: %u\n", absTime);
return LOS_EINVAL;
}
- if (lockVal != val) {
- return LOS_EBADF;
- }
-
return LOS_OK;
}
@@ -526,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) {
@@ -542,32 +572,42 @@ STATIC INT32 OsFutexInserTaskToHash(LosTaskCB **taskCB, FutexNode **node, const
return LOS_OK;
}
-STATIC INT32 OsFutexWaitTask(const UINT32 timeOut, const UINT32 *userVaddr)
+STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const UINT32 val, const UINT32 timeOut)
{
INT32 futexRet;
- UINT32 intSave;
+ 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)) {
return LOS_EINVAL;
}
- if (OsFutexInserTaskToHash(&taskCB, &node, futexKey)) {
+ if (LOS_ArchCopyFromUser(&lockVal, userVaddr, sizeof(UINT32))) {
+ PRINT_ERR("Futex wait param check failed! copy from user failed!\n");
+ futexRet = LOS_EINVAL;
goto EXIT_ERR;
}
+
+ if (lockVal != val) {
+ futexRet = LOS_EBADF;
+ goto EXIT_ERR;
+ }
+
+ 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);
-#ifdef LOS_FUTEX_DEBUG
- OsFutexHashShow();
-#endif
-
futexRet = OsFutexUnlock(&hashNode->listLock);
if (futexRet) {
OsPercpuGet()->taskLockCnt--;
@@ -594,12 +634,9 @@ STATIC INT32 OsFutexWaitTask(const UINT32 timeOut, const UINT32 *userVaddr)
return LOS_OK;
EXIT_ERR:
- futexRet = OsFutexUnlock(&hashNode->listLock);
+ (VOID)OsFutexUnlock(&hashNode->listLock);
EXIT_UNLOCK_ERR:
- if (futexRet) {
- return futexRet;
- }
- return LOS_NOK;
+ return futexRet;
}
INT32 OsFutexWait(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absTime)
@@ -607,15 +644,37 @@ INT32 OsFutexWait(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absT
INT32 ret;
UINT32 timeOut = LOS_WAIT_FOREVER;
- ret = OsFutexWaitParmaCheck(userVaddr, flags, val, absTime);
+ ret = OsFutexWaitParamCheck(userVaddr, flags, absTime);
if (ret) {
return ret;
}
if (absTime != LOS_WAIT_FOREVER) {
- timeOut = OsFutexGetTick(absTime);
+ timeOut = OsUS2Tick(absTime);
+ }
+
+ 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;
}
- return OsFutexWaitTask(timeOut, userVaddr);
+ 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
@@ -636,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) {
@@ -654,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);
@@ -691,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;
}
@@ -751,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);
@@ -787,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++) {
@@ -803,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;
}
@@ -812,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;
}
@@ -825,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;
}
@@ -856,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;
}
@@ -883,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
old mode 100755
new mode 100644
index 64220900d2314e695caae9b963cb6c8967b7a706..1017b094dbc4adaf45674ec29a534b35ff6e3fd8
--- 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
index 2b8251047055460c306ce06a2c70e3f7086cd1b3..f74f2726653a4601319263b23a03854798547d2f 100755
--- 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
index fc0487b2d26a0ce3039686725f1bc5fb8dc275ca..51e2b789fe93be4adc43dbcfc1c275ea8e5eccbd 100755
--- 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
old mode 100755
new mode 100644
index 3543b0061fcf3b08326252cd9649908c5bdff044..8807ae759fc6b972358aaf444d860fd212934dcf
--- 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 0000000000000000000000000000000000000000..0cb06bda2c6b67ec455f1ffd79b269de630cbdbc
--- /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
index ae8131ba6443d5e96633d2bff252635c36f10bc6..ef012423afa94eaff745b87ade515cf1b2b33bce 100755
--- 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
index 73a6f2d86b488838154fb977b651bc5925e91e14..e78c829f6835dbb66e78e52342d50a5ddc0579d8 100755
--- 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:
@@ -71,7 +71,7 @@ STATIC VOID OsSemPendedTaskNamePrint(LosSemCB *semNode)
PRINTK("Pended task list : ");
for (i = 0; i < num; i++) {
if (i == 0) {
- PRINTK("%s\n", nameArr[i]);
+ PRINTK("\n%s", nameArr[i]);
} else {
PRINTK(", %s", nameArr[i]);
}
diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c
index c5057968c0379854228923c5a52f51018304619f..295f0fb9099cfd2f39eb51acba1f8af90c8d63f4 100755
--- 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);
}
}
@@ -466,7 +470,8 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
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 100755
index 239b03d85c123e328f9dbdf2ce00970dcb31b3a4..0000000000000000000000000000000000000000
--- 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 100755
index 3a3e4da452ad85b9b58010259f8804eba203dca1..0000000000000000000000000000000000000000
--- 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
index 5140d45240243827a5806bf068ed3b0b5991ff69..957159ddeb7e777b0350c23ca0ae0a19b7683e50 100755
--- 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:
@@ -83,7 +83,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemClear(UINT32 taskID)
}
if (g_tskMemUsedInfo[taskID].memUsed != 0) {
PRINT_WARN("mem used of task '%s' is:0x%x, not zero when task being deleted\n",
- OsCurrTaskGet()->taskName, g_tskMemUsedInfo[taskID].memUsed);
+ OS_TCB_FROM_TID(taskID)->taskName, g_tskMemUsedInfo[taskID].memUsed);
}
g_tskMemUsedInfo[taskID].memUsed = 0;
}
diff --git a/kernel/base/mem/common/memrecord/los_binarytree.c b/kernel/base/mem/common/memrecord/los_binarytree.c
deleted file mode 100755
index 425f3331e41be6b907ad9ccc662179ee930d5cb3..0000000000000000000000000000000000000000
--- 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 100755
index ecff1f7c3c140ef038a5f62afbdbf254e3187ee5..0000000000000000000000000000000000000000
--- 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
old mode 100755
new mode 100644
index e3025a117953aac54eea7efac59a2a6b453e0d69..f8c2f0a096b59b12bd03b5485f77aa548eda6990
--- 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 0000000000000000000000000000000000000000..10185a4cd31da2829c5bc5d43a88ab4f3ab46275
--- /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
index 96b3d7e044c0947539034f10ce7fe6117f565c0a..e21dca7d6c4421be9d343b2ef4ca527cdee49769 100755
--- 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:
@@ -35,7 +35,14 @@
#include "los_printf.h"
#include "los_task_pri.h"
#include "los_process_pri.h"
+
+#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__)
+#endif
+
#ifdef LOSCFG_SHELL
#include "shcmd.h"
#include "shell.h"
@@ -57,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;
}
@@ -74,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
old mode 100755
new mode 100644
index 8e36b08a5068d39bc51933ace81e04872aba37ae..1e76e62081b4f349b21d1c2426c13455d2fc63f6
--- 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
index 9e7c891d1e5340c8a203f948b3ae6d81f016d1ab..5bac7160abb8ff6ccdb41a4a55bb37980c72e14e 100755
--- 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
index a5bea3f84a3d20fe5f2717560cf002cbaa43302b..e39ba93abfe34dab91594f71b091372999bd383f 100755
--- 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 0000000000000000000000000000000000000000..82be521e74d3e73e96c98dba733b6362227a6982
--- /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
old mode 100755
new mode 100644
index 096977796c6df972579a9a9cf25920b456317e23..cb7a3adfb16b5824fe02d8447a258851295ea7c5
--- 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
old mode 100755
new mode 100644
index a4283210b785003a08d6629eb6655ca95e518aa4..75cac70a405046e9b8b8f48652448bb7cba0f65d
--- 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
index 902d203f640a2c04c3e0e3d954587f4c6cd2d890..66622feb2c7bc90215d85a69b1ad973aceff167e 100755
--- 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 ");
}
-#ifdef LOSCFG_KERNEL_CPUP
if (flag & OS_PROCESS_INFO_ALL) {
+#ifdef LOSCFG_KERNEL_CPUP
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
+#endif /* LOSCFG_KERNEL_CPUP */
+ PROCESS_INFO_SHOW(seqBuf, "Policy Priority MTID TaskTotal Mode ");
} else {
+#ifdef LOSCFG_KERNEL_CPUP
PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
- }
#endif /* LOSCFG_KERNEL_CPUP */
- if (flag & OS_PROCESS_INFO_ALL) {
- PROCESS_INFO_SHOW(seqBuf, "Policy Priority MTID TaskTotal Mode ");
}
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]);
}
-#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);
- }
+#ifdef LOSCFG_KERNEL_CPUP
+ 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;
+ 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);
}
+ 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
index 872c49e6747a02ed5a925e798146546b6f4507d5..c4f08d1fc7e0d22820f519d39172ce6eab18e2e0 100755
--- 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
old mode 100755
new mode 100644
index f35ea96f66eaaf882fd2e5faba1f07344701eba2..3f52964bed7cc57e3ecb011b5acb3b6c4b083562
--- 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
old mode 100755
new mode 100644
index 948d3d72b2217eb30e16ac5f1fcae001e712a80d..9c3f7c96beb0a9807f92a6a0d1ecfd91e1d169fb
--- 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
old mode 100755
new mode 100644
index c2e5bfb464419ca45566449b06ab72bc910ce6b6..476c7c664c2b38ee6e89fe0f981751f30ae8ee87
--- 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/mem/bestfit/los_multipledlinkhead.c b/kernel/base/mp/los_spinlock.c
old mode 100755
new mode 100644
similarity index 51%
rename from kernel/base/mem/bestfit/los_multipledlinkhead.c
rename to kernel/base/mp/los_spinlock.c
index 641947dc1473d038e580b6f98a85085eaa66add0..02a332ab22ab517561965a1bb3eefe800f76c274
--- a/kernel/base/mem/bestfit/los_multipledlinkhead.c
+++ b/kernel/base/mp/los_spinlock.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,8 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "los_multipledlinkhead_pri.h"
-#include "los_bitmap.h"
+#include "los_spinlock.h"
+#if (LOSCFG_KERNEL_SMP == YES)
+#include "los_sched_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -38,34 +39,74 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-STATIC INLINE UINT32 OsLog2(UINT32 size)
+VOID LOS_SpinInit(SPIN_LOCK_S *lock)
{
- return (size > 0) ? (UINT32)LOS_HighBitGet(size) : 0;
+ lock->rawLock = 0;
+ lock->cpuid = (UINT32)-1;
+ lock->owner = SPINLOCK_OWNER_INIT;
+ lock->name = "spinlock";
}
-LITE_OS_SEC_TEXT_INIT VOID OsDLnkInitMultiHead(VOID *headAddr)
+BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
{
- LosMultipleDlinkHead *dlinkHead = (LosMultipleDlinkHead *)headAddr;
- LOS_DL_LIST *listNodeHead = dlinkHead->listHead;
- UINT32 index;
+ return (lock->rawLock != 0);
+}
- for (index = 0; index < OS_MULTI_DLNK_NUM; ++index, ++listNodeHead) {
- LOS_ListInit(listNodeHead);
- }
+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);
}
-LITE_OS_SEC_TEXT_MINOR LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size)
+INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
{
- 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;
+ 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 dlinkHead->listHead + (index - OS_MIN_MULTI_DLNK_LOG2);
+ 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
diff --git a/kernel/base/mp/los_stat.c b/kernel/base/mp/los_stat.c
index f556eb56c6d27e7c65d97529991ddaf3727eaa40..9f63716ecb21a701c43c75318c1afe9a2f2d5703 100755
--- 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
index 9b07b8d37c861b6bb46f0fe89213879c34014aaa..5c455b8f901bbf1b3317e84905a42b90941099a1 100755
--- 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 100755
index 229052730b083b8a0dba8028fc5914ff33b84e65..0000000000000000000000000000000000000000
--- 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
index a3051dd1f76ee2b991fa40707e682a0dbbcf843c..6f082e450cd39e9ebca5757d5006d672df16202a 100755
--- 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) {
- return;
+ 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;
}
-#if (LOSCFG_KERNEL_SMP == YES)
- runProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_DEC(runProcess->processStatus);
- newProcess->processStatus = OS_PROCESS_RUNTASK_COUNT_ADD(newProcess->processStatus);
+ (VOID)memset_s(g_schedTickDebug, size, 0, size);
+ return LOS_OK;
+}
- LOS_ASSERT(!(OS_PROCESS_GET_RUNTASK_COUNT(newProcess->processStatus) > LOSCFG_KERNEL_CORE_NUM));
- if (OS_PROCESS_GET_RUNTASK_COUNT(runProcess->processStatus) == 0) {
+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
- runProcess->processStatus &= ~OS_PROCESS_STATUS_RUNNING;
- if ((runProcess->threadNumber > 1) && !(runProcess->processStatus & OS_PROCESS_STATUS_READY)) {
- runProcess->processStatus |= OS_PROCESS_STATUS_PEND;
+
+#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;
}
-#if (LOSCFG_KERNEL_SMP == YES)
+
+ 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
- LOS_ASSERT(!(newProcess->processStatus & OS_PROCESS_STATUS_PEND));
- newProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
- if (OsProcessIsUserMode(newProcess)) {
- LOS_ArchMmuContextSwitch(&newProcess->vmSpace->archMmu);
+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;
}
-#ifdef LOSCFG_KERNEL_CPUP
- OsProcessCycleEndStart(newProcess->processID, OS_PROCESS_GET_RUNTASK_COUNT(runProcess->processStatus) + 1);
-#endif /* LOSCFG_KERNEL_CPUP */
+ return LOS_OK;
+}
- OsCurrProcessSet(newProcess);
+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 ((newProcess->timeSlice == 0) && (newProcess->policy == LOS_SCHED_RR)) {
- newProcess->timeSlice = OS_PROCESS_SCHED_RR_INTERVAL;
+ 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
}
-VOID OsSchedResched(VOID)
+STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
+ UINT64 taskEndTime, UINT32 oldResponseID)
{
- LosTaskCB *runTask = NULL;
- LosTaskCB *newTask = NULL;
- LosProcessCB *runProcess = NULL;
- LosProcessCB *newProcess = NULL;
+ UINT64 nextExpireTime = OsGetNextExpireTime(startTime);
+ Percpu *currCpu = OsPercpuGet();
+ UINT64 nextResponseTime;
+ BOOL isTimeSlice = FALSE;
- LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
+ 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 (!OsPreemptableInSched()) {
+ 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;
}
- runTask = OsCurrTaskGet();
- newTask = OsGetTopTask();
+ 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;
+ }
- /* always be able to get one task */
- LOS_ASSERT(newTask != NULL);
+ currCpu->responseTime = nextExpireTime;
+ HalClockTickTimerReload(nextResponseTime);
- if (runTask == newTask) {
+#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;
}
- runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
+ /* 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);
- runProcess = OS_PCB_FROM_PID(runTask->processID);
- newProcess = OS_PCB_FROM_PID(newTask->processID);
+ OsSchedSetStartTime(HalClockGetCycles());
+ newTask->startTime = OsGerCurrSchedTimeCycle();
- OsSchedSwitchProcess(runProcess, newProcess);
+#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)
- /* mask new running task's owner processor */
- runTask->currCpu = OS_TASK_INVALID_CPUID;
- newTask->currCpu = ArchCurrCpuid();
+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
- (VOID)OsTaskSwitchCheck(runTask, newTask);
+#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 (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
- OsSchedStatistics(runTask, newTask);
+ 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
- if ((newTask->timeSlice == 0) && (newTask->policy == LOS_SCHED_RR)) {
- newTask->timeSlice = LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT;
+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) {
+ runProcess->processStatus &= ~OS_PROCESS_STATUS_RUNNING;
}
- OsCurrTaskSet((VOID*)newTask);
+ LOS_ASSERT(!(newProcess->processStatus & OS_PROCESS_STATUS_PENDING));
+ newProcess->processStatus |= OS_PROCESS_STATUS_RUNNING;
+
+ if (OsProcessIsUserMode(newProcess)) {
+ LOS_ArchMmuContextSwitch(&newProcess->vmSpace->archMmu);
+ }
+
+ OsCurrProcessSet(newProcess);
+}
+
+STATIC VOID OsSchedTaskSwicth(LosTaskCB *runTask, LosTaskCB *newTask)
+{
+ UINT64 endTime;
+
+ OsSchedSwitchCheck(runTask, newTask);
+
+ runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
+ newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
+
+#if (LOSCFG_KERNEL_SMP == YES)
+ /* mask new running task's owner processor */
+ runTask->currCpu = OS_TASK_INVALID_CPUID;
+ newTask->currCpu = ArchCurrCpuid();
+#endif
+
+ 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);
+ }
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
index 15b4f7af220d66d71f5a992db148019e83b0a908..b0186d73d901585483333fde4ffbe738769efcbf 100755
--- 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
index 791c075a5fc03451526f69bd6bbe5cde3bd3f19c..4298b4f8ccfe7b1a11f2ac3aabc46173cbd1e8bf 100755
--- 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
index 9630cf94b938ff382b5d5a9715836d0dbd8e60e1..ccc1550336d34cc11acd675ebbe8d67c120de262 100755
--- 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
index e5f6483e00aa643e992d2c3cdd7ecc1fdea31ee7..ced2e7204bda4b0969971e9e1f5c41c44f5e2ca1 100755
--- 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;
@@ -661,7 +663,7 @@ STATUS_T OsNamedMMap(struct file *filep, LosVmMapRegion *region)
return LOS_ERRNO_VM_MAP_FAILED;
}
} else if (INODE_IS_DRIVER(inodePtr)) {
- if (inodePtr->u.i_ops->mmap) {
+ if (inodePtr->u.i_ops && inodePtr->u.i_ops->mmap) {
LOS_SetRegionTypeDev(region);
return inodePtr->u.i_ops->mmap(filep, region);
} else {
@@ -751,6 +753,7 @@ VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB)
space = processCB->vmSpace;
if (space != NULL) {
+ (VOID)LOS_MuxAcquire(&space->regionMux);
/* free the regions associated with filep */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeTmp)
region = (LosVmMapRegion *)pstRbNode;
@@ -764,6 +767,7 @@ VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB)
}
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeTmp)
+ (VOID)LOS_MuxRelease(&space->regionMux);
}
}
#endif
diff --git a/kernel/base/vm/los_vm_iomap.c b/kernel/base/vm/los_vm_iomap.c
old mode 100755
new mode 100644
index 5f5ffae4b69089d67b22ab0f947d53d7befe49ef..62f5e34ca31e5e1aff0632709b8faf3b6d05548b
--- 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
index 244bf8772989ada66c7b99c0a91b78b25e0cd6da..dcc57acf1f416c306142e42d4c8fb108816c562e 100755
--- 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;
}
@@ -388,14 +413,14 @@ VADDR_T OsAllocRange(LosVmSpace *vmSpace, size_t len)
}
nextStart = vmSpace->mapBase + vmSpace->mapSize;
- if ((nextStart - curEnd) >= len) {
+ 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;
@@ -561,7 +592,7 @@ STATIC VOID OsDevPagesRemove(LosArchMmu *archMmu, VADDR_T vaddr, UINT32 count)
status_t status;
if ((archMmu == NULL) || (vaddr == 0) || (count == 0)) {
- VM_ERR("OsAnonPagesRemove invalid args, archMmu %p, vaddr %p, count %d", archMmu, vaddr, count);
+ VM_ERR("OsDevPagesRemove invalid args, archMmu %p, vaddr %p, count %d", archMmu, vaddr, count);
return;
}
@@ -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)) {
@@ -658,10 +704,9 @@ STATIC LosVmMapRegion *OsVmRegionSplit(LosVmMapRegion *oldRegion, VADDR_T newReg
LosVmSpace *space = oldRegion->space;
size_t size = LOS_RegionSize(newRegionStart, LOS_RegionEndAddr(oldRegion));
- LOS_RbDelNode(&space->regionRbTree, &oldRegion->rbNode);
oldRegion->range.size = LOS_RegionSize(oldRegion->range.base, newRegionStart - 1);
- if (oldRegion->range.size != 0) {
- LOS_RbAddNode(&space->regionRbTree, &oldRegion->rbNode);
+ if (oldRegion->range.size == 0) {
+ LOS_RbDelNode(&space->regionRbTree, &oldRegion->rbNode);
}
newRegion = OsVmRegionDup(oldRegion->space, oldRegion, newRegionStart, size);
@@ -682,15 +727,7 @@ STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T newRegionStart, size_t size
LosVmMapRegion *newRegion = NULL;
region = LOS_RegionFind(space, newRegionStart);
- if ((region == NULL) || (region->range.base >= nextRegionBase)) {
- return LOS_ERRNO_VM_NOT_FOUND;
- }
-
- if ((region->range.base == newRegionStart) && (region->range.size == size)) {
- return LOS_OK;
- }
-
- if (newRegionStart > region->range.base) {
+ if ((region != NULL) && (newRegionStart > region->range.base)) {
newRegion = OsVmRegionSplit(region, newRegionStart);
if (newRegion == NULL) {
VM_ERR("region split fail");
@@ -698,7 +735,7 @@ STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T newRegionStart, size_t size
}
}
- region = LOS_RegionFind(space, nextRegionBase);
+ region = LOS_RegionFind(space, nextRegionBase - 1);
if ((region != NULL) && (nextRegionBase < LOS_RegionEndAddr(region))) {
newRegion = OsVmRegionSplit(region, nextRegionBase);
if (newRegion == NULL) {
@@ -706,6 +743,7 @@ STATUS_T OsVmRegionAdjust(LosVmSpace *space, VADDR_T newRegionStart, size_t size
return LOS_ERRNO_VM_NO_MEMORY;
}
}
+
return LOS_OK;
}
@@ -726,6 +764,9 @@ STATUS_T OsRegionsRemove(LosVmSpace *space, VADDR_T regionBase, size_t size)
RB_SCAN_SAFE(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext)
regionTemp = (LosVmMapRegion *)pstRbNodeTemp;
+ if (regionTemp->range.base > regionEnd) {
+ break;
+ }
if (regionBase <= regionTemp->range.base && regionEnd >= LOS_RegionEndAddr(regionTemp)) {
status = LOS_RegionFree(space, regionTemp);
if (status != LOS_OK) {
@@ -734,9 +775,6 @@ STATUS_T OsRegionsRemove(LosVmSpace *space, VADDR_T regionBase, size_t size)
}
}
- if (regionTemp->range.base > regionEnd) {
- break;
- }
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext)
ERR_REGION_SPLIT:
@@ -796,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 - region->range.size) > size)) {
+ if ((nextRegion != NULL) && ((nextRegion->range.base - region->range.base) >= size)) {
return LOS_OK;
}
@@ -894,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;
@@ -905,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;
}
@@ -944,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);
@@ -1110,14 +1153,15 @@ DONE:
STATIC INLINE BOOL OsMemLargeAlloc(UINT32 size)
{
- UINT32 wasteMem;
+ if (g_kHeapInited == FALSE) {
+ return FALSE;
+ }
- if (size < PAGE_SIZE) {
+ if (size < KMALLOC_LARGE_SIZE) {
return FALSE;
}
- wasteMem = ROUNDUP(size, PAGE_SIZE) - size;
- /* that is 1K ram wasted, waste too much mem ! */
- return (wasteMem < VM_MAP_WASTE_MEM_LEVEL);
+
+ 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
index 3254e87ef6df88d7271f537a79ffc57d7362b4a3..b612b5c2a2b40c2ef06599df210f7291729e4d10 100755
--- 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
index 0ee98d05a892fed537c75159bc37331355c04026..afb70520588e6736500411f20ec1898747735858 100755
--- 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;
- UINT32 order;
- UINT32 newOrder;
+ 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;
+ }
- if ((seg == NULL) || (nPages == 0)) {
- return NULL;
+ 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;
+
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;
}
@@ -340,7 +393,6 @@ VOID OsVmPhysPagesFreeContiguous(LosVmPage *page, size_t nPages)
{
paddr_t pa;
UINT32 order;
- size_t count;
size_t n;
while (TRUE) {
@@ -355,10 +407,11 @@ VOID OsVmPhysPagesFreeContiguous(LosVmPage *page, size_t nPages)
page += n;
}
- for (count = 0; count < nPages; count += n) {
+ while (nPages > 0) {
order = LOS_HighBitGet(nPages);
n = VM_ORDER_TO_PAGES(order);
OsVmPhysPagesFree(page, order);
+ nPages -= n;
page += n;
}
}
@@ -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
index 13d20de373a57af283eb96cdc4ac12e1cce49e15..8855f4bf46e8839ae9a0c817a3df58858b36c640 100755
--- 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:
@@ -337,7 +337,7 @@ int OsTryShrinkMemory(size_t nPage)
return nReclaimed;
}
#else
-int TryShrinkMemory(size_t nPage)
+int OsTryShrinkMemory(size_t nPage)
{
return 0;
}
diff --git a/kernel/base/vm/los_vm_syscall.c b/kernel/base/vm/los_vm_syscall.c
index 1a3b8194a3f998c1c7747191af849d015d7dfb91..d79535e6a7a0a3b563c0b67851f2d8ababacaba8 100755
--- 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 == 0) {
- return -EINVAL;
+ if (len > OsCurrProcessGet()->vmSpace->mapSize) {
+ return -ENOMEM;
}
- /* we only support some prot and flags */
- if ((prot & PROT_SUPPORT_MASK) == 0) {
+ 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 ((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,21 +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)addr;
- return addr;
+ shrinkAddr = OsShrinkHeap(addr, space);
+ (VOID)LOS_MuxRelease(&space->regionMux);
+ return shrinkAddr;
+ }
+
+ if ((UINTPTR)alignAddr >= space->mapBase) {
+ VM_ERR("Process heap memory space is insufficient");
+ ret = (VOID *)-ENOMEM;
+ goto REGION_ALLOC_FAILED;
}
- (VOID)LOS_MuxAcquire(&space->regionMux);
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");
@@ -197,11 +251,6 @@ VOID *LOS_DoBrk(VOID *addr)
space->heap = region;
}
- if ((UINTPTR)alignAddr >= space->mapBase) {
- VM_ERR("Process heap memory space is insufficient");
- goto REGION_ALLOC_FAILED;
- }
-
space->heapNow = (VADDR_T)(UINTPTR)alignAddr;
space->heap->range.size = size;
ret = (VOID *)(UINTPTR)space->heapNow;
@@ -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) {
@@ -360,7 +421,9 @@ VADDR_T LOS_DoMremap(VADDR_T oldAddress, size_t oldSize, size_t newSize, int fla
ret = -ENOMEM;
goto OUT_MREMAP;
}
- status = LOS_ArchMmuMove(&space->archMmu, oldAddress, newAddr, newSize >> PAGE_SHIFT, regionOld->regionFlags);
+ status = LOS_ArchMmuMove(&space->archMmu, oldAddress, newAddr,
+ ((newSize < regionOld->range.size) ? newSize : regionOld->range.size) >> PAGE_SHIFT,
+ regionOld->regionFlags);
if (status) {
LOS_RegionFree(space, regionNew);
ret = -ENOMEM;
@@ -390,8 +453,8 @@ VADDR_T LOS_DoMremap(VADDR_T oldAddress, size_t oldSize, size_t newSize, int fla
ret = -ENOMEM;
goto OUT_MREMAP;
}
- status = LOS_ArchMmuMove(&space->archMmu, oldAddress, regionNew->range.base, newSize >> PAGE_SHIFT,
- regionOld->regionFlags);
+ status = LOS_ArchMmuMove(&space->archMmu, oldAddress, regionNew->range.base,
+ regionOld->range.size >> PAGE_SHIFT, regionOld->regionFlags);
if (status) {
LOS_RegionFree(space, regionNew);
ret = -ENOMEM;
diff --git a/kernel/base/vm/oom.c b/kernel/base/vm/oom.c
index f3e757b1e2869b39ee3020a344b5e9df35c0842a..c5e5c0e3d677c5580adbf5577726165af471c699 100755
--- 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
index 129fd4d07a359305ac7838b260b92a1ac45cbb52..f5c5e3a98b023604cf5a0d5d7f0d167bcb6b2fdf 100755
--- 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;
}
@@ -337,10 +358,14 @@ VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region)
return;
}
+ LOS_ArchMmuUnmap(&space->archMmu, region->range.base, region->range.size >> PAGE_SHIFT);
ShmPagesRefDec(seg);
seg->ds.shm_nattch--;
- if (seg->ds.shm_nattch <= 0) {
+ if (seg->ds.shm_nattch <= 0 && (seg->status & SHM_SEG_REMOVE)) {
ShmFreeSeg(seg);
+ } else {
+ seg->ds.shm_dtime = time(NULL);
+ seg->ds.shm_lpid = LOS_GetCurrProcessID(); /* may not be the space's PID. */
}
SYSV_SHM_UNLOCK();
}
@@ -392,12 +417,17 @@ STATIC INT32 ShmPermCheck(struct shmIDSource *seg, mode_t mode)
tmpMode |= SHM_W;
}
+ if (privMode & SHM_X) {
+ tmpMode |= SHM_X;
+ }
+
if ((mode == SHM_M) && (tmpMode & SHM_M)) {
return 0;
+ } else if (mode == SHM_M) {
+ return EACCES;
}
- tmpMode &= ~SHM_M;
- if ((tmpMode & mode) == accMode) {
+ if ((tmpMode & accMode) == accMode) {
return 0;
} else {
return EACCES;
@@ -410,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) == 0)) {
+ 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 {
@@ -432,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;
@@ -454,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;
}
@@ -473,27 +500,33 @@ 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)) {
- vaddr = (VADDR_T)LOS_MMap(vaddr, seg->ds.shm_segsz, prot,
- MAP_ANONYMOUS | MAP_SHARED, -1, 0);
- region = LOS_RegionFind(space, vaddr);
- } else {
- region = LOS_RegionAlloc(space, vaddr, seg->ds.shm_segsz, regionFlags, 0);
+ 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, mapFlags, -1, 0);
+ region = LOS_RegionFind(space, vaddr);
}
if (region == NULL) {
@@ -513,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) {
@@ -525,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();
@@ -536,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;
}
@@ -591,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;
}
@@ -622,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);
@@ -718,10 +756,10 @@ INT32 ShmDt(const VOID *shmaddr)
if ((seg->ds.shm_nattch <= 0) &&
(seg->status & SHM_SEG_REMOVE)) {
ShmFreeSeg(seg);
+ } else {
+ seg->ds.shm_dtime = time(NULL);
+ seg->ds.shm_lpid = LOS_GetCurrProcessID();
}
-
- seg->ds.shm_dtime = time(NULL);
- seg->ds.shm_lpid = LOS_GetCurrProcessID();
SYSV_SHM_UNLOCK();
(VOID)LOS_MuxRelease(&space->regionMux);
return 0;
@@ -734,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
index 2e1b2e7cc0c7bb6b1e4e7d5033d96985afcf52dd..66af51a10954d51e0e65b14bc2a1930e1b1d6da7 100755
--- 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
index b7db9ad7d445eaf38498df6137e8b06a88edcd9d..4e83d558320a19e0b07e9aef1696f2f160de06f1 100755
--- 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
index ff782eaf74d09bc91e3664ea93906c3741c8951a..ce5a7fe302aab8476301ffceb123015ec6b77ee5 100755
--- 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,6 +1641,7 @@ VOID OsWaitConsoleSendTaskPend(UINT32 taskID)
UINT32 i;
CONSOLE_CB *console = NULL;
LosTaskCB *taskCB = NULL;
+ INT32 waitTime = 3000; /* 3000: 3 seconds */
for (i = 0; i < CONSOLE_NUM; i++) {
console = g_console[i];
@@ -1638,8 +1654,9 @@ VOID OsWaitConsoleSendTaskPend(UINT32 taskID)
}
taskCB = OS_TCB_FROM_TID(console->sendTaskID);
- while ((taskCB->taskEvent == NULL) && (taskID != console->sendTaskID)) {
+ while ((waitTime > 0) && (taskCB->taskEvent == NULL) && (taskID != console->sendTaskID)) {
LOS_Mdelay(1); /* 1: wait console task pend */
+ --waitTime;
}
}
}
diff --git a/kernel/common/console.h b/kernel/common/console.h
index 97c91a77cb99a2c8f26f8e70fd7f8a8725a3c64b..7b2a7ef42c5b3e54158cef1bf7e02b4589ae3cae 100755
--- 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
old mode 100755
new mode 100644
index bccf3541349bc92c26cd9b875ef677ca93336f89..981375cb320c92d72f3dc95ada696835b0de4446
--- 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
old mode 100755
new mode 100644
index 610eb11e4efb429086efadf596c023a3d67d694a..c00ae1f947fbd1d40f69c716374f4fda9aa4f162
--- 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
old mode 100755
new mode 100644
index b721bc0b195cc7b95b2a99cad9285539bbbd33d4..3bd7b951976a7b82f4184d9332906a56884544ed
--- 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
old mode 100755
new mode 100644
index 312fd4379896acebef67b6a30b5e156c2d17ffa9..9e990ec05efd0d4a543a8d112aadb0b196d469bc
--- 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
index 368dd63140037b135ea15c8cedcfbd9446f78414..91875330b5ed5aa268dd4a3b658ed3ebfb2c2bcb 100755
--- 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,12 +120,28 @@
#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 */
+STATIC SystemRebootFunc g_rebootHook = NULL;
+
+VOID OsSetRebootHook(SystemRebootFunc func)
+{
+ g_rebootHook = func;
+}
+
+SystemRebootFunc OsGetRebootHook(VOID)
+{
+ return g_rebootHook;
+}
+
extern UINT32 OsSystemInit(VOID);
extern VOID SystemInit(VOID);
@@ -140,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;
@@ -205,13 +190,22 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsDriverHiEventInit(VOID)
extern void configure (void);
LITE_OS_SEC_TEXT_INIT STATIC INT32 OsBsdInit(VOID)
{
+ /*
+ * WORKAROUND: Inside configure(), nexus_init() function calls
+ * HiSi-specific, library procedure - machine_resource_init().
+ * The latter one is defined in libhi35xx_bsp.a which is only
+ * available for Hi3516 and Hi3518.
+ * Temporarily ifdef configure until this routine is implemented
+ * by other platforms.
+ */
+#if defined(LOSCFG_PLATFORM_HI3516DV300) || defined(LOSCFG_PLATFORM_HI3518EV300)
configure();
+#endif
mi_startup(SI_SUB_ARCH_INIT);
return LOS_OK;
}
#endif
-
LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
{
UINT32 ret;
@@ -229,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 */
@@ -265,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;
@@ -296,7 +295,7 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
}
#endif
- ret = OsKernelInitProcess();
+ ret = OsSystemProcessCreate();
if (ret != LOS_OK) {
return ret;
}
@@ -337,15 +336,17 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
if (ret != LOS_OK) {
return ret;
}
+#if (LOSCFG_BASE_CORE_HILOG == YES)
+ ret = HiLogDriverInit();
+ if (ret != LOS_OK) {
+ return ret;
+ }
+#endif
#if LOSCFG_DRIVERS_HIEVENT
OsDriverHiEventInit();
#endif
-#if (LOSCFG_KERNEL_TRACE == YES)
- LOS_TraceInit();
-#endif
-
#if (LOSCFG_KERNEL_LITEIPC == YES)
ret = LiteIpcInit();
if (ret != LOS_OK) {
@@ -353,13 +354,6 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
}
#endif
-#if (LOSCFG_BASE_CORE_HILOG == YES)
- ret = HiLogDriverInit();
- if (ret != LOS_OK) {
- return ret;
- }
-#endif
-
#ifdef LOSCFG_KERNEL_VDSO
ret = OsInitVdso();
if (ret != LOS_OK) {
@@ -398,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)
{
@@ -435,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
index 38b7086fdf7f4c5ad8b45530e60fedb91b8107b8..be16a7128413e1fa34bef8e8a869895c53d75df1 100755
--- 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
old mode 100755
new mode 100644
index 49b6cc7b9d22936c088cba5ad77273bd33ec3e66..8a2825939ed9827c1ea0a951f6b1a1650afe82fb
--- 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
old mode 100755
new mode 100644
index 0a3cc0af1efff8446a76fc2d797f129ecadbf47d..dcced5754e500a9444228a80a6b9159abec494eb
--- 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
old mode 100755
new mode 100644
index 00d24c000ca07046edb04018b30033d70d2df6e8..6a34fce13436fbb77c1ab27b85b30b9f0983cee9
--- 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
old mode 100755
new mode 100644
index ab10c401643015f2ed4ff9f01e54b2abf2976613..24f0d0437635e868d2f30e5109adbbe7b86e27b8
--- 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
index 612029bae4bb94b04ddb896c4d2529acf12a5c96..e1a798dc7f03485187f01a98473778a2477ced7f 100755
--- 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);
@@ -178,7 +177,7 @@ static ssize_t HiLogRead(FAR struct file *filep, char *buffer, size_t bufLen)
}
if (bufLen < header.len + sizeof(header)) {
- dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize, header.nsec);
+ dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize);
retval = -ENOMEM;
goto out;
}
@@ -248,13 +247,14 @@ static void HiLogCoverOldLog(size_t bufLen)
struct HiLogEntry header;
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
- while (totalSize + g_hiLogDev.size >= HILOG_BUFFER) {
+ while (totalSize + g_hiLogDev.size > HILOG_BUFFER) {
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
if (retval < 0) {
break;
}
- HiLogBufferDec(sizeof(header) + header.len);
+ HiLogBufferDec(sizeof(header));
+ HiLogBufferDec(header.len);
}
}
@@ -262,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
index 90073979429eca32cb1fdbf51b8700624eca7816..9cf10e66e9d5b9d29dd2ebf181c709a4d1a7cc8b 100755
--- 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
old mode 100755
new mode 100644
index 6cf31323755f31427b50976df0786c6d696662c8..280870662cd54fb2fbc3696ff96f09c94ebdb401
--- 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
old mode 100755
new mode 100644
index 012dafca8b393b2aac3b50fae4e905950f552a02..266d49ba19fdcb5dcf7f9211595e2a4ecc4ecdcf
--- 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
index ea00840eb4db4af07fe106a9390c3595176b013f..401332861c704ffa59e4138f69b645bcc39799bf 100755
--- 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
index 8add614e8896251b061a1fea16f1d2dfbb6ca562..11a2de933425f18f07d37d1d1466f2a3fd6ec7ab 100755
--- 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"
-#ifdef LOSCFG_PLATFORM_HI3518EV300
+#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,11 +194,30 @@ 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
#endif
+
+#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
+#define CFIFLASH_CAPACITY 64 * 1024 * 1024
+ 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");
+ } else {
+ rootDev = "/dev/cfiflash0";
+ ret = add_mtd_partition("cfi-flash", (rootAddr + rootSize),
+ CFIFLASH_CAPACITY - rootAddr - rootSize, 1);
+ if (ret != LOS_OK) {
+ PRINT_ERR("Failed to add cfi-flash storage partition!\n");
+ }
+ }
+ } else
+#endif
{
PRINT_ERR("Failed to find root dev type: %s\n", rootType);
}
@@ -190,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;
@@ -203,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");
@@ -218,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");
@@ -231,6 +273,15 @@ STATIC INT32 GetArgs(CHAR **args)
goto ERROUT;
}
#endif
+#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
+ /*
+ * TODO: Implement method of fetching bootargs for
+ * Qemu ARM virtual platform. If used without
+ * bootloader it will pass DTB by default.
+ */
+ (void)ret;
+ cmdLine = "bootargs=root=cfi-flash fstype=jffs2 rootaddr=0xA00000 rootsize=27M";
+#endif
for (i = 0; i < COMMAND_LINE_SIZE; i += len + 1) {
len = strlen(cmdLine + i);
@@ -249,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)
@@ -332,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) {
@@ -349,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;
}
@@ -363,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;
@@ -421,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();
@@ -445,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();
@@ -460,6 +517,19 @@ STATIC INT32 OsMountRootfsAndUserfs(const CHAR *rootDev, const CHAR *fsType)
PRINT_ERR("Failed to mount /storage, errno %d: %s\n", err, strerror(err));
}
}
+#endif
+#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
+ ret = mkdir("/storage", DEFAULT_STORAGE_MOUNT_DIR_MODE);
+ if (ret != LOS_OK) {
+ err = get_errno();
+ PRINT_ERR("Failed to reserve inode /storage, errno %d: %s\n", err, strerror(err));
+ } else {
+ ret = mount("/dev/cfiflash1", "/storage", fsType, 0, NULL);
+ if (ret != LOS_OK) {
+ err = get_errno();
+ PRINT_ERR("Failed to mount /storage, errno %d: %s\n", err, strerror(err));
+ }
+ }
#endif
}
return LOS_OK;
diff --git a/kernel/common/los_rootfs.h b/kernel/common/los_rootfs.h
index 7260f1c8d3a364f92df144fd21a141a25b2e67fb..c73813b8e0659fab6bd40827ce4b1c1e02aa931c 100755
--- 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
index 826d14379636485ca9f0e311cd02e0075ab3c57a..f91ffa719a03d9bff98d5ea2344e56124787c86c 100755
--- 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
index d22ffc78b902e4d8b844a049bdddab231c4140c2..e048ba61ea1c4b216dee46163539153b2355bb11 100755
--- 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
old mode 100755
new mode 100644
index 33c19eedf4dd8477ccbc1be3e7d4aa832d920b64..6017d8b07dcb11b463738506cb91499522124f60
--- 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 0000000000000000000000000000000000000000..b7c111455725203c0318a149bb0567d2d3a6fc26
--- /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 0000000000000000000000000000000000000000..64d687646f31309fc165759fb03e27140ac88d4a
--- /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 0000000000000000000000000000000000000000..c2556011204f8e82ff59d6fb278b00f2b01a396e
--- /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
old mode 100755
new mode 100644
similarity index 54%
rename from kernel/base/include/los_multipledlinkhead_pri.h
rename to kernel/common/patchfs/los_partition_utils.h
index aa34e273bebf7a6cda74de5a06e0fda499c859f1..8fcc167511f20124d2bf61c537400af761336d28
--- 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 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)
-typedef struct {
- LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM];
-} LosMultipleDlinkHead;
+#define BYTES_PER_MBYTE 0x100000
+#define BYTES_PER_KBYTE 0x400
+#define DEC_NUMBER_STRING "0123456789"
+#define HEX_NUMBER_STRING "0123456789abcdefABCDEF"
-STATIC INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listNodeHead)
-{
- LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
+#define COMMAND_LINE_ADDR LOSCFG_BOOTENV_ADDR * BYTES_PER_KBYTE
+#define COMMAND_LINE_SIZE 1024
- return (&head->listHead[OS_MULTI_DLNK_NUM - 1] == listNodeHead) ? NULL : (listNodeHead + 1);
-}
+#if defined(LOSCFG_STORAGE_SPINOR)
+#define FLASH_TYPE "spinor"
+#define STORAGE_TYPE "flash"
+#define FS_TYPE "jffs2"
+#else
+#define STORAGE_TYPE "emmc"
+#endif
-extern VOID OsDLnkInitMultiHead(VOID *headAddr);
-extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size);
+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;
+};
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+INT32 GetPartitionInfo(struct PartitionInfo *partInfo);
+const CHAR *GetDevNameOfPartition(const struct PartitionInfo *partInfo);
+INT32 ResetDevNameofPartition(const struct PartitionInfo *partInfo);
-#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 0000000000000000000000000000000000000000..fa1012c461ed1b90a4aa3d8527b8d494fb97b737
--- /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 0000000000000000000000000000000000000000..72e3e8768f86b172712815574d9ef7257961d4ab
--- /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
index 184ea766474e8b27d85394e56a839309616e86a2..7e38fc8a4b952954c522654e3202f53a89118238 100755
--- 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
index 9dae4ee91eab970b9bb87b8fea04bdab8bde40e5..d8def05d151bd0cf6d65855e7e9408428d8c304c 100755
--- 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
old mode 100755
new mode 100644
index f7162b79f49d4bf7b86534ef79657e6d00372bba..ceefe83d100025130709ec4508135396cd755e02
--- 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
old mode 100755
new mode 100644
index 671f9e84b09779fda5285fd598b9d2b414c4cf96..826bd05a286e7915fe856748ef55451a6802232e
--- 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
index 0ff60e0f8545208991ea06ca52626bcd6e892207..7c17d995007b0311d73b380f96137e9666b6329e 100755
--- 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
old mode 100755
new mode 100644
index 3ccf9877a6f7f0a836b467b71e3581236c1480c3..61b090299232e6244f4d2d8fa8a5df05bb7f3e8f
--- 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
index 68ecfa872c39f2b2fc8bca6ee0a01c597bb728d2..cbff72cc70ab24d74270a33e563ef3ea0e1242ba 100755
--- 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
index 9436e8a5255e78b3c1c454dcb36a456df493480f..131e00d29721a90a89f5e3a6099614b7ab0b8410 100755
--- 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;
- }
- }
-
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
- timeInIrqPerProcessSwitch[loop] = 0;
+ for (index = 0; index < g_processMaxNum; index++) {
+ processCB = OS_PCB_FROM_PID(index);
+ OsResetCpup(&processCB->processCpup, cycle);
}
-#endif
-
- (VOID)LOS_SwtmrStart(swtmrID);
- LOS_IntRestore(intSave);
- cpupInitFlg = 1;
-
- return;
-}
-
-LITE_OS_SEC_TEXT_MINOR VOID OsSetCpuCycle(UINT64 cycles)
-{
- 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;
+ for (index = 0; index < g_taskMaxNum; index++) {
+ taskCB = OS_TCB_FROM_TID(index);
+ OsResetCpup(&taskCB->taskCpup, cycle);
}
- /*
- * 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;
+ if (g_irqCpup != NULL) {
+ for (index = 0; index < cpupMaxNum; index++) {
+ OsResetCpup(&g_irqCpup[index].cpup, cycle);
}
- g_cpup[runPID].allTime -= timeInIrqPerProcessSwitch[loop];
- timeInIrqPerProcessSwitch[loop] = 0;
+ for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
+ timeInIrqSwitch[index] = 0;
+ }
}
-}
#endif
-/*
- * Description: start process to get cycles count in current process begining
- */
-LITE_OS_SEC_TEXT_MINOR STATIC VOID OsProcessCycleStart(VOID)
-{
- UINT32 pid;
-
- 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;
-#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- OsRemoveInterTimeFromPorcess(runPID);
-#endif
- g_cpup[runPID].startTime = 0;
+ (VOID)LOS_SwtmrStart(cpupSwtmrID);
+ LOS_IntRestore(intSave);
+ cpupInitFlg = 1;
return;
}
-/*
- * Description: start process to get cycles count in current process ending
- */
-LITE_OS_SEC_TEXT_MINOR VOID OsProcessCycleEndStart(UINT32 newID, UINT16 runTaskCount)
+VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
{
- UINT32 runPID;
- UINT64 cpuCycle;
- OsCpupCB *cpup = NULL;
+ /* 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;
}
- 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;
+ if (runTaskCpup->startTime != 0) {
+ cycleIncrement = cpuCycle - runTaskCpup->startTime;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
- OsRemoveInterTimeFromPorcess(runPID);
+ cycleIncrement -= timeInIrqSwitch[cpuID];
+ timeInIrqSwitch[cpuID] = 0;
#endif
+ runTaskCpup->allTime += cycleIncrement;
+ processCpup->allTime += cycleIncrement;
+ runTaskCpup->startTime = 0;
}
- 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;
+ }
- 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);
+ processCB = OS_PCB_FROM_PID(pid);
+ if (OsProcessIsUnused(processCB)) {
+ return LOS_ERRNO_CPUP_NO_CREATED;
}
- OsProcessCycleStart();
+ OsCpupGetPos(mode, &pos, &prePos);
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- 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;
+ OsCpupGetPos(mode, &pos, &prePos);
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+
+ return OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
+}
+
+LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 tid, UINT16 mode)
+{
+ UINT32 intSave;
+ UINT32 cpup;
+
+ 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;
}
-#endif
- if (numTmpMax > numMax) {
- numTmpMax = numMax;
+ if ((cpupInfo == NULL) || (len < (sizeof(CPUP_INFO_S) * number))) {
+ return LOS_ERRNO_CPUP_PTR_ERR;
}
- OsProcessCycleEnd();
+ (VOID)memset_s(cpupInfo, len, 0, len);
+ return LOS_OK;
+}
+
+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);
- cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
+ cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
- for (loop = numTmpMin; loop < numTmpMax; loop++) {
- if (g_cpup[loop].status == OS_CPUP_UNUSED) {
+ for (processID = 0; processID < g_processMaxNum; processID++) {
+ processCB = OS_PCB_FROM_PID(processID);
+ if (OsProcessIsUnused(processCB)) {
continue;
}
- index = loop - numTmpMin;
- cpuCycleCurProcess = g_cpup[loop].historyTime[pos] - g_cpup[loop].historyTime[prePos];
- cpupInfo[index].usStatus = g_cpup[loop].status;
-
- if (cpuCycleAll) {
- cpupInfo[index].uwUsage = (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * cpuCycleCurProcess) / cpuCycleAll);
- }
+ cpupInfo[processID].usage = OsCalculateCpupUsage(&processCB->processCpup, pos, prePos, cpuAllCycle);
+ cpupInfo[processID].status = OS_CPUP_USED;
}
- OsProcessCycleStart();
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 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
old mode 100755
new mode 100644
index 4b216c0c427ff0777da2ef921c19f548f1e81150..28d86ed1f64a34b04bf48459220b614e540a6842
--- 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
index b2e979a64f13831034a40bdc1c73442d44aef930..56a7a34c934c3d6ecf9d3b64426035911e0ab816 100755
--- 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
index c0e17b847cbcae420d21b28b1fde50792dc6ee4b..ad8220b06401b9f164964f4a2b89f8cda4b10a0e 100755
--- 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
index 2a5d53fc0c48d8e3d36dcbfa0e38ccbcc14ffdee..39e8594980dc37e95fa3fc3e442442eb54c548a1 100755
--- 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
index 237f291c82b94a768ba4bdb86027c59b4a54c9e5..9912954f6e9f1c87a570d807b3fa959dc83105b2 100755
--- 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
index a8ef083fef9c25e7099548412c77c2d15c748fbf..f1934daf696fd8278056b1d36620f27db7cea2dd 100755
--- 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
index 2d02b04a24e3daea7f031784c43f101fff0daa7e..be5c65adb11624a16a6920cf617f70d7a9c9c001 100755
--- 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;
-
- ret = OsGetFileLength(&loadInfo->execFileLen, 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;
- }
- PRINT_ERR("%s[%d], Failed to open ELF file: %s!\n", __FUNCTION__, __LINE__, fileName);
- return -ENOENT;
- }
-
-#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);
- }
-#endif
- ret = OsReadELFInfo(loadInfo->execFD, (UINT8 *)&loadInfo->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);
- if (ret != LOS_OK) {
- PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
- return -ENOEXEC;
- }
-
- return LOS_OK;
+ loadInfo->execInfo.fd = INVALID_FD;
+ loadInfo->interpInfo.fd = INVALID_FD;
}
-STATIC INT32 OsLoadProgramHdrs(ELFLoadInfo *loadInfo)
+STATIC INT32 OsReadEhdr(const CHAR *fileName, 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);
+ ret = OsGetFileLength(&elfInfo->fileLen, fileName);
if (ret != LOS_OK) {
return -ENOENT;
}
- loadInfo->interpFD = open(fileName, O_RDONLY);
- if (loadInfo->interpFD < 0) {
+ 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;
- ret = OsReadELFInfo(loadInfo->interpFD, (UINT8 *)&loadInfo->interpELFEhdr, sizeof(LD_ELF_EHDR), 0);
+#ifdef LOSCFG_DRIVERS_TZDRIVER
+ 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(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->interpELFEhdr, loadInfo->interpFileLen);
+ ret = OsVerifyELFEhdr(&elfInfo->elfEhdr, elfInfo->fileLen);
if (ret != LOS_OK) {
- PRINT_ERR("%s[%d], ELF header of file: %s is invalid!\n", __FUNCTION__, __LINE__, fileName);
- return -ELIBBAD;
+ PRINT_ERR("%s[%d]\n", __FUNCTION__, __LINE__);
+ return isExecFile ? -ENOEXEC : -ELIBBAD;
}
return LOS_OK;
}
-STATIC INT32 OsLoadInterpProgramHdrs(ELFLoadInfo *loadInfo)
+STATIC INT32 OsReadPhdrs(ELFInfo *elfInfo, BOOL isExecFile)
{
- 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);
@@ -983,6 +940,7 @@ STATIC VOID OsFlushAspace(ELFLoadInfo *loadInfo)
processCB->vmSpace->heapBase += OsGetRndOffset(loadInfo);
processCB->vmSpace->heapNow = processCB->vmSpace->heapBase;
processCB->vmSpace->mapBase += OsGetRndOffset(loadInfo);
+ processCB->vmSpace->mapSize = loadInfo->stackBase - processCB->vmSpace->mapBase;
LOS_ArchMmuContextSwitch(&OsCurrProcessGet()->vmSpace->archMmu);
}
@@ -992,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);
@@ -1019,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;
}
@@ -1039,7 +999,7 @@ INT32 OsLoadELFFile(ELFLoadInfo *loadInfo)
goto OUT;
}
- (VOID)OsFlushAspace(loadInfo);
+ OsFlushAspace(loadInfo);
ret = OsLoadELFSegment(loadInfo);
if (ret != LOS_OK) {
@@ -1048,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
index 7b2c8d56ed55ec662eb2627f8cda9e317f52a734..b19426a2a25bd386afb6a1f4f4bcd23ebe6ed96c 100755
--- 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
index 3c988797750e812b77c341c48bcc0d5d7ec6e310..585ab11adccc39e8e5ff676fad7bca2f050a1997 100755
--- 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
index 398eae4ad231a44c600f174866fee2dfc8f65dae..3af1a5049a33b748fc1c4bddacfabe74c3d6e36d 100755
--- 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
index 9339ab0bbf1eb9364444c63ef637e2b5b23cba64..c35b4bcafb30c2d8d2045c5b615cbc5794ee5965 100755
--- 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"
@@ -48,7 +50,7 @@
#define USE_TASKID_AS_HANDLE YES
#define USE_MMAP YES
#define IPC_MSG_DATA_SZ_MAX 1024
-#define IPC_MSG_OBJECT_NUM_MAX 256
+#define IPC_MSG_OBJECT_NUM_MAX (IPC_MSG_DATA_SZ_MAX / sizeof(SpecialObj))
#define LITE_IPC_POOL_NAME "liteipc"
#define LITE_IPC_POOL_PAGE_MAX_NUM 64 /* 256KB */
@@ -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", "DEATH_NOTIFY"};
+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)) {
@@ -929,7 +856,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CopyDataFromUser(IpcListNode *node, UINT32 bufSz,
return LOS_OK;
}
-LITE_OS_SEC_TEXT STATIC BOOL IsLeagalReply(const IpcContent *content)
+LITE_OS_SEC_TEXT STATIC BOOL IsValidReply(const IpcContent *content)
{
UINT32 curProcessID = LOS_GetCurrProcessID();
IpcListNode *node = (IpcListNode *)GetIpcKernelAddr(curProcessID, (INTPTR)(content->buffToFree));
@@ -983,14 +910,13 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid)
if ((flag & BUFF_FREE) != BUFF_FREE) {
return -EINVAL;
}
- if (!IsLeagalReply(content)) {
+ if (!IsValidReply(content)) {
return -EINVAL;
}
#if (USE_TIMESTAMP == YES)
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
index 2f02e3910ad2df14f0fcfe0760120629092487a8..dc9806af4d343cae94411cb659f1267f119a7683 100755
--- 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 100755
index 48b0d4f8ea83b4ddcf9e1be58da597978bba1737..0000000000000000000000000000000000000000
--- 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
index 80e6829f26d5fde6e5072f244954f008dd1e2424..c6ceffcd3a3f26a581a65be4891eee8b31f966b0 100755
--- 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
index 2628a4356c56b9dc1a8c2a5cc4863db10eb76073..ad63323aa9a7f8e5bef27d01c5aa751d3f62eb2d 100755
--- 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 0000000000000000000000000000000000000000..0f8306b887621bd4d8c5a1c637268d2fbea15ceb
--- /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 0000000000000000000000000000000000000000..5c0d18e4d2b725dd192511e48c38e0bdad9b8114
--- /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
index 88cd008075fc6503b6596aa53ff1a054f4c2c51c..a16cc5d9d50fb8262db9150997d0246f1c1da88b 100755
--- 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
index cacf644f00268748ef9ed86281c21131ce8c02e5..3df321a40c2c1cb4421e35fbc9997c7dd1f8fc33 100755
--- 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
index 62bee155164ecd7427d762fe7e050da2af222b8e..fece0026146de7644a48fa51b5e6df857ae7b92b 100755
--- 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
old mode 100755
new mode 100644
index 682e37f8e73ea542bfc2911fc9c4f928544724b4..90e2c7148ea8c5a51b6b5376ee12fdd015ced956
--- 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
index 588861aefbec6ec581ebe0e55f8bd05457900084..378632cb0258125785ffb1cc690dd892a89b2686 100755
--- 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
old mode 100755
new mode 100644
index 3485ba67a90b1a755c511da3fb7c5bd7aa98c429..fcf8224ecbfc2b31f9d9ddf94b33fb052e0f5764
--- 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
index a692e3dcf8ba7c789b76e0ae0a3d61e8dfc0f1e4..aac0727e92022e48bfb2ad512095c01ce6a2a127 100755
--- 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_sys.c b/kernel/extended/vdso/usr/los_vdso_sys.c
index 7ae1f2236017423c3d2aa81262f50014fc350ceb..14a72109322949a1588d2ce87f85984440da274e 100755
--- 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
index 7cdd2cc15a61fd7bc55809550aa5605a2a293288..7c5fe36d1085d7e3b203e0c8b9b4d0a6a2846c0b 100755
--- 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
index 474805fed3760351b7639166837ad1b1e3754007..20b1d89f28c4b8f4a2464dff712b0d7c5c233ca3 100755
--- 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
index 8118ac0080003699725a5bc95b94da08738b7054..f905d4496dc7e637ab57de6ee1d7bd273ab4897f 100755
--- 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
old mode 100755
new mode 100644
index 148b7b77e62cb6f5fe7b26ce4323fae548b8915e..7873fb4f60f107568cf32857f062fa30528241f4
--- 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 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 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 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_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_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 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 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, and the maximum number must be usable. 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
- * (maxNum * sizeof (CPUP_INFO_S)).
+ * (LOS_GetSystemProcessMaximum() * sizeof (CPUP_INFO_S)).
*
*
- * @param maxNum [IN] UINT16. The Maximum number of threads or hwis.
+ * @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 flag [IN] UINT16. The parameter value 0 indicates that the CPU usage of hwi. Other values indicate that
- * the CPU usage of process.
+ * @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_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_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_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag);
+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
index a937b8e78b3875dece85c0024a6df84107f1a657..612134b9ecbf6f5adf9d83924cb53039f1474cd1 100755
--- 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
old mode 100755
new mode 100644
index 74c80ac631386a8ef307f6226252de6414969b44..c001a330d62e522a9cdf159311a7f5a4367a9a0a
--- 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
old mode 100755
new mode 100644
index faddb393df8859d21884db3b211f883839c7cdc6..c98d35528261320226673fea8d071ef173830878
--- 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
old mode 100755
new mode 100644
similarity index 58%
rename from kernel/include/los_tickless.h
rename to kernel/include/los_hash.h
index 9ebd7c1b3afefa4a2ca37ed348ce878aaa882e0f..7cbf257be4a9f233388fffae1d8eeb996e708038
--- 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
old mode 100755
new mode 100644
index 3af48c67a6551d861e57baff038746a6af066f77..9187f7e414a613ad68981c068372931816d2dc22
--- 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
index dfdede2018af3d9715bdeca954fe5c88a96582d6..7b7bd88cb87bcbdd3a796c4e082045e64c506e67 100755
--- 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
index 3cef99016446740614c4d997810539dd68ca425a..fe050a5a92549773979b9522332ca71e9cfa1cca 100755
--- 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:
@@ -125,7 +125,7 @@ extern VOID OsLockDepCheckOut(SPIN_LOCK_S *lock);
* @ingroup los_lockdep
*
* @par Description:
- * This API is used to clear lockdep record of curret task.
+ * This API is used to clear lockdep record of current task.
* @attention
*
* None.
diff --git a/kernel/include/los_membox.h b/kernel/include/los_membox.h
old mode 100755
new mode 100644
index 0e5f11b29226a94f7954082b9cdfe266f38e79a7..55c9989b468bf0a4e263f6a3b59f30f98b745d4e
--- 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
index 1c4f2979ad5b5d1648c6be5446ab65c83e6a6351..3ced9ad0affa0b7405f4309cc16a597694f3f21f 100755
--- 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
old mode 100755
new mode 100644
index 3c1b21b8d3e8c6c42516eb9e802a8b0baac00fde..2b45662001315a3b9d14240c931b24706b84b2d5
--- 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
index eb7218f37fad64115f50ad0d05ad1f57491dd52e..37c7efcaf891a342b1c3896e44020c2db4d5ce39 100755
--- 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
old mode 100755
new mode 100644
index 24e1099e9712048798ae8372b9970afbf30d2ff8..510839a18da14ab5c8226f8af9eef60c91b9e484
--- 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
index 2fd741785174e24b749c33deb519a012ebca439c..cf47c3cc0af72e24a8f56f906852358ad4c398f8 100755
--- 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
old mode 100755
new mode 100644
index 639908bad582b39f35485a84d6e0749ae757eabb..b9469fcead9304315319896e21967046f69e7b9b
--- 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 0000000000000000000000000000000000000000..6464932318a9b1a3777f747bbfcf88c9af184c35
--- /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
old mode 100755
new mode 100644
index 647db1441c531be64647da818bd704547d504178..6e37a569884e9d4cd37a19bf5bfe3cadb806997e
--- 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
index 5dee0c19c3b7da15474eaebb90582feae43dade4..504fcfb0474650afa15aa30fd00e7c9caba5d6a3 100755
--- 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,34 +57,28 @@ 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()
-
-#define SPIN_LOCK_INITIALIZER(lockName) \
-{ \
- .rawLock = 0U, \
- .cpuid = (UINT32)(-1), \
- .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()
+#endif
+
+#if (LOSCFG_KERNEL_SMP == YES)
+#define SPINLOCK_OWNER_INIT NULL
+
#define SPIN_LOCK_INITIALIZER(lockName) \
{ \
.rawLock = 0U, \
+ .cpuid = (UINT32)(-1), \
+ .owner = SPINLOCK_OWNER_INIT, \
+ .name = #lockName, \
}
-#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
index 205539f0a2a19474fd554fc2fd857ccf3df7722b..68b77c0c10fdd553c044ef81d9262fe9ad14d162 100755
--- 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
old mode 100755
new mode 100644
index 82747253b34bf05507ebaa47ec004909cf6cbf55..26475697335cf8b008f3e3ee3fc18e3a0a5a50cc
--- 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
index fc66f23eb53638fe2c559ec9e2ba8520cbf1cac8..5b67ac88392747f0e2359ea5796b0cbfe37ec3c7 100755
--- 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
index afae40cac565a5f1f98708571e55bfbf28edb3bb..49df83b3fa57e1f5803cddf0d6b3c5b632d7d6e0 100755
--- 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
old mode 100755
new mode 100644
index 54597e601e552f8bb16cff588990da2319f09b19..80b3006d471f8d060d383b1e0af9ad722ac36e89
--- 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
old mode 100755
new mode 100644
index c9d2302ff08edb16ec2f77ab7a9bc397a615762f..f118498cb3939e9bfabef166873bb83a3c796a8f
--- 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
index df88b09022e13cc11952aed340883040b03a3519..6a97f1a6f0ab82997dda30b13687ea6483fd0c88 100755
--- 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: 0x02001403
+ * Value: 0x02001402
*
- * Solution: Use valid filled size 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
+ * Solution: Use valid type to regeister the new trace.
*/
-#define IRQ_DIRECT_OUT 0
+#define LOS_ERRNO_TRACE_TYPE_EXISTED LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
/**
* @ingroup los_trace
- * It's the length of tag, filled by los_trace system
+ * Task error code: The type is not registered.
+ *
+ * Value: 0x02001403
+ *
+ * Solution: Use valid type to regeister the new trace.
*/
-#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
index 620018370c3ab17bb534ceeb2514826667e038dd..b2f5e4ca8809c8334c8e1c279df0bf0fa4e7b126 100755
--- 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
index e5a3d4559dbb94cc2d6383d429370025ed5b7e29..6dc3fc56004eb8023a296780021f8f24aba2adca 100755
--- 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
index 9dadcc8d201ceec08a974cc26841cc14070d1113..225ccbe3aa42f64f4efce2c23c632ecc863193e7 100755
--- 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
index e1bb9cfd8e4aa67e60858832282f93c356970114..b16c6634be09862ca55fc22514c9a8dedbfaed03 100755
--- 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:
@@ -30,11 +30,15 @@
*/
#include "los_user_init.h"
+
+#ifdef LOSCFG_KERNEL_DYNLOAD
#include "los_syscall.h"
#define SYS_CALL_VALUE 0x900001
-#ifdef LOSCFG_KERNEL_DYNLOAD
+#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
@@ -55,6 +59,7 @@ LITE_USER_SEC_TEXT STATIC UINT32 sys_call3(UINT32 nbr, UINT32 parm1, UINT32 parm
return reg0;
}
+#endif
LITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args)
{
diff --git a/kernel_test.sources b/kernel_test.sources
new file mode 100755
index 0000000000000000000000000000000000000000..cab52bfd7cf3df11552766210114aa3b4ac088ad
--- /dev/null
+++ b/kernel_test.sources
@@ -0,0 +1 @@
+../../kernel/liteos_a/test/apps/src/osTest.c
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index a355a1edc627df3bfc88317f4a7b2c0f8efbb4e8..66a4146b524312035aedd4cc823646608747661a 100755
--- 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 0000000000000000000000000000000000000000..939d63a1539bd61b9112b74c2a06c841b843be97
--- /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 0000000000000000000000000000000000000000..eda33c218cf0ade0d63f863c60fd042da6a1ee35
--- /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 0000000000000000000000000000000000000000..2c97f410ea23f9bfac370b3fec7d4cd574188a64
--- /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 0000000000000000000000000000000000000000..921ebe90e95900dddbfefa239b18d7f1e50e7c26
--- /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 0000000000000000000000000000000000000000..ab07c4d157b820042e213f95bf82a881778c24b3
--- /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 0000000000000000000000000000000000000000..eecf51cce11ac14ea21a6a42f58b9dc228ee7384
--- /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 0000000000000000000000000000000000000000..1cb01634a381b70b2e29c883800b990f5b700874
--- /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/libmbedtls/Makefile b/lib/libmbedtls/Makefile
old mode 100755
new mode 100644
diff --git a/lib/libscrew/Makefile b/lib/libscrew/Makefile
old mode 100755
new mode 100644
diff --git a/lib/libscrew/include/los_crc32.h b/lib/libscrew/include/los_crc32.h
old mode 100755
new mode 100644
index ef89f30d5d6419baa2652d4433bb4887eee363b2..7101e2d11de6343df43cace5774dc13816d1d3b3
--- 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
old mode 100755
new mode 100644
index d21bccaf426f3b5bfa27eab8eed9a81cfa6933b5..7919f689a602a2e5eb41e67ac3c6d6df124c28e3
--- 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
old mode 100755
new mode 100644
index 81b66a8dde2ecd4594c6fb6df57f5d62e05275c4..ad6ea030cb464f314365e89861fd638e84b8bfdd
--- 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
index b9466e7850bc9bc7689c4abc9c33f38fa71fb143..bcd02dda6787325bcf4cd91da7891785668b73f1 100755
--- 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/zlib/Makefile b/lib/zlib/Makefile
old mode 100755
new mode 100644
diff --git a/net/Kconfig b/net/Kconfig
old mode 100755
new mode 100644
index 4e1e47d74312143ad241ac1d82d58b1f3a986078..36a9e16bfc372ca64b1fa467ee2f695955d0a61d
--- 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
old mode 100755
new mode 100644
index 7ce79fcccc26c547f07c06eb3d7488a3c86b8996..c38e91197e0571408c2f2e92e2e0321b75cc4259
--- 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:
@@ -44,7 +44,7 @@ LOCAL_FLAGS += $(LOCAL_INCLUDE)
LOCAL_SRCS := $(wildcard porting/src/*.c $(LWIPNOAPPSFILES))
LOCAL_SRCS += $(wildcard enhancement/src/*.c)
-LOCAL_SRCS += $(wildcard $(LWIPDIR)/core/ipv4/dhcps.c)
+LOCAL_SRCS := $(filter-out $(LWIPDIR)/core/ipv4/dhcp.c, $(LOCAL_SRCS))
LOCAL_SRCS := $(filter-out $(LWIPDIR)/core/ipv4/etharp.c, $(LOCAL_SRCS))
LOCAL_SRCS := $(filter-out $(LWIPDIR)/api/sockets.c, $(LOCAL_SRCS))
diff --git a/net/lwip-2.1/enhancement/include/dhcps_fix.h b/net/lwip-2.1/enhancement/include/dhcps_fix.h
deleted file mode 100755
index 616eab7ef585bd3c76526ec25da848eff0cff760..0000000000000000000000000000000000000000
--- a/net/lwip-2.1/enhancement/include/dhcps_fix.h
+++ /dev/null
@@ -1,102 +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 LITEOS_A_DHCPS_FIXME_H
-#define LITEOS_A_DHCPS_FIXME_H
-
-#include "lwip/opt.h"
-
-#if (LWIP_DHCP) && (LWIP_DHCPS)
-
-#define LWIP_STATIC static
-
-
-/* Option handling: options are parsed in dhcp_parse_reply
- * and saved in an array where other functions can load them from.
- * This might be moved into the struct dhcp (not necessarily since
- * lwIP is single-threaded and the array is only used while in recv
- * callback). */
-enum dhcp_option_idx {
- DHCP_OPTION_IDX_OVERLOAD = 0,
- DHCP_OPTION_IDX_MSG_TYPE,
- DHCP_OPTION_IDX_SERVER_ID,
- DHCP_OPTION_IDX_LEASE_TIME,
- DHCP_OPTION_IDX_T1,
- DHCP_OPTION_IDX_T2,
- DHCP_OPTION_IDX_SUBNET_MASK,
- DHCP_OPTION_IDX_ROUTER,
-#if LWIP_DHCP_PROVIDE_DNS_SERVERS
- DHCP_OPTION_IDX_DNS_SERVER,
- DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1,
-#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
-#if LWIP_DHCP_GET_NTP_SRV
- DHCP_OPTION_IDX_NTP_SERVER,
- DHCP_OPTION_IDX_NTP_SERVER_LAST = DHCP_OPTION_IDX_NTP_SERVER + LWIP_DHCP_MAX_NTP_SERVERS - 1,
-#endif /* LWIP_DHCP_GET_NTP_SRV */
- DHCP_OPTION_IDX_REQUESTED_IP,
- DHCP_OPTION_IDX_MAX
-};
-
-#define DHCP_OPTION_ROUTER_SIZE 4
-#define DHCP_OPTION_SUBNET_MASK_SIZE 4
-#define DHCP_OPTION_LEASE_TIME_SIZE 4
-#define DHCP_OPTION_SERVER_ID_LEN 4
-#define DHCP_OPTION_T1_LEN 4
-#define DHCP_OPTION_T2_LEN 4
-
-#define DHCP_CLIENT_PORT 68
-#define DHCP_SERVER_PORT 67
-
-#define DHCP_BROADCAST_FLAG 0x8000
-#define DHCP_MAX_MSG_LEN_MIN_REQUIRED 576
-
-struct dyn_lease_addr {
- u8_t cli_hwaddr[DHCP_CHADDR_LEN];
- u32_t flags;
- u32_t leasetime;
- u32_t proposed_leasetime;
- ip4_addr_t cli_addr;
-};
-
-struct dhcps {
- struct udp_pcb *pcb;
- struct dyn_lease_addr leasearr[LWIP_DHCPS_MAX_LEASE];
- u8_t pcb_allocated;
- u8_t lease_num;
- struct netif *netif;
- ip4_addr_t start_addr;
- ip4_addr_t end_addr;
-};
-
-
-#endif // (LWIP_DHCP) && (LWIP_DHCPS)
-
-#endif // LITEOS_A_DHCPS_FIXME_H
diff --git a/net/lwip-2.1/enhancement/include/api_shell.h b/net/lwip-2.1/enhancement/include/lwip/api_shell.h
similarity index 90%
rename from net/lwip-2.1/enhancement/include/api_shell.h
rename to net/lwip-2.1/enhancement/include/lwip/api_shell.h
index ae6918a0acbd15ca97310be4513020c160cda7ad..7b212301209679d13bff2fd45939195fb620f482 100755
--- a/net/lwip-2.1/enhancement/include/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:
@@ -29,8 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LWIP_API_SHELL_H
-#define LWIP_API_SHELL_H
+#ifndef LWIP_HDR_API_SHELL_H
+#define LWIP_HDR_API_SHELL_H
#include "arch/cc.h"
#include "lwip/opt.h"
@@ -58,6 +58,4 @@ void netstat_internal(void *ctx);
}
#endif
-
-#endif
-
+#endif /* LWIP_HDR_API_SHELL_H */
diff --git a/net/lwip-2.1/enhancement/include/dhcps.h b/net/lwip-2.1/enhancement/include/lwip/dhcps.h
old mode 100755
new mode 100644
similarity index 75%
rename from net/lwip-2.1/enhancement/include/dhcps.h
rename to net/lwip-2.1/enhancement/include/lwip/dhcps.h
index 0a3adf4b1481e18794e12f6161a2ecc6e46fb3d3..bab711a412abc79937ccb4a75f69d3088f48e1dd
--- a/net/lwip-2.1/enhancement/include/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:
@@ -63,16 +63,6 @@ extern "C" {
err_t dhcps_start(struct netif *netif, const char *start_ip, u16_t ip_num);
void dhcps_stop(struct netif *netif);
-void dhcp_common_option(struct dhcp_msg *msg_out, u8_t option_type, u8_t option_len, u16_t *options_out_len);
-void dhcp_common_option_byte(struct dhcp_msg *msg_out, u8_t value, u16_t *options_out_len);
-void dhcp_common_option_short(struct dhcp_msg *msg_out, u16_t value, u16_t *options_out_len);
-void dhcp_common_option_long(struct dhcp_msg *msg_out, u32_t value, u16_t *options_out_len);
-void dhcp_common_option_trailer(struct dhcp_msg *msg_out, u16_t *options_out_len);
-#if LWIP_DHCP_BOOTP_FILE
-err_t dhcps_parse_options(struct pbuf *p, char *boot_file_name);
-#else
-err_t dhcps_parse_options(struct pbuf *p);
-#endif
#if defined (__cplusplus) && __cplusplus
}
diff --git a/net/lwip-2.1/enhancement/include/api_shell_fix.h b/net/lwip-2.1/enhancement/include/lwip/fixme.h
old mode 100755
new mode 100644
similarity index 63%
rename from net/lwip-2.1/enhancement/include/api_shell_fix.h
rename to net/lwip-2.1/enhancement/include/lwip/fixme.h
index 198d81db7ffe79f7bf77a1e8c123ac8ed5c946c3..49bec93d8422ccaab21cc19279d06f9496f4d111
--- a/net/lwip-2.1/enhancement/include/api_shell_fix.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:
@@ -29,17 +29,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LITEOS_A_FIXME_H
-#define LITEOS_A_FIXME_H
-
-#define LWIP_ENABLE_LOS_SHELL_CMD 1
-#define LWIP_ENABLE_IP_CONFLICT_SIGNAL 0
-#define PF_PKT_SUPPORT 1
-#define NETCONN_PKT_RAW 0x80
+#ifndef LWIP_HDR_FIXME_H
+#define LWIP_HDR_FIXME_H
#include "lwip/opt.h"
-
-#if LWIP_ENABLE_LOS_SHELL_CMD
+#include "netif/etharp.h"
+#include "lwip/netif.h"
#define link_rx_drop cachehit
#define link_tx_drop cachehit
@@ -51,61 +46,55 @@
#define ip_rx_bytes cachehit
#define ip_tx_bytes cachehit
-#define LWIP_STATIC static
-#define SYS_ARCH_ERROR SYS_ARCH_TIMEOUT
-
-#include "netif/etharp.h"
-#include "lwip/netif.h"
+#define DUP_ARP_DETECT_TIME 2000 /* 2 seconds period */
+#define NETCONN_PKT_RAW 0x80
+#define SYS_ARCH_ERROR 0x7fffffffUL
-#define LWIP_SHELL_CMD_PING_RETRY_TIMES 4
+#define LWIP_ENABLE_LOS_SHELL_CMD LOSCFG_SHELL
+#define LWIP_SHELL_CMD_PING_RETRY_TIMES 4
#define LWIP_SHELL_CMD_PING_TIMEOUT 2000
+#define LWIP_MAX_UDP_RAW_SEND_SIZE 65332
+#define LWIP_EXT_POLL_SUPPORT LWIP_SOCKET_POLL
-#define TRANSFER_MODE_BINARY 1
-
-u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
- u16_t usTftpServPort,
- u8_t ucTftpTransMode,
- s8_t *szSrcFileName,
- s8_t *szDestDirPath);
-
-u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr,
- u16_t usTftpServPort,
- u8_t cTftpTransMode,
- s8_t *szSrcFileName,
- s8_t *szDestDirPath);
-
-
-#define ip_addr_set_val(dest, src) do { IP_SET_TYPE_VAL(*dest, IP_GET_TYPE(src)); if(IP_IS_V6_VAL(*(src))) { \
- ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); } else { \
- ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }} while (0)
+#define ip_addr_set_val(dest, src) do { \
+ IP_SET_TYPE_VAL(*dest, IP_GET_TYPE(src)); \
+ if(IP_IS_V6_VAL(*(src))) { \
+ ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); \
+ } else { \
+ ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); \
+ } \
+ } while (0)
#define ip_addr_ismulticast_val(ipaddr) ((IP_IS_V6_VAL(*ipaddr)) ? \
- ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
- ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
-
+ ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
+ ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
#define ip_addr_isbroadcast_val(ipaddr, netif) ((IP_IS_V6_VAL(*ipaddr)) ? \
- 0 : \
- ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
+ 0 : \
+ ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
#define ip_addr_netcmp_val(addr1, addr2, mask) ((IP_IS_V6_VAL(*(addr1)) && IP_IS_V6_VAL(*(addr2))) ? \
- 0 : \
- ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
+ 0 : \
+ ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
-#if LWIP_DHCP
+#define ip6_addr_isnone_val(ip6addr) (((ip6addr).addr[0] == 0xffffffffUL) && \
+ ((ip6addr).addr[1] == 0xffffffffUL) && \
+ ((ip6addr).addr[2] == 0xffffffffUL) && \
+ ((ip6addr).addr[3] == 0xffffffffUL))
-/*
- * Close DHCP and set static network.
- *
- * @param netif a pre-allocated netif structure
- *
- * @return ERR_OK, or ERR_VAL if failed.
- */
-err_t netif_dhcp_off(struct netif *netif);
+#define ip6_addr_isnone(ip6addr) (((ip6addr) == NULL) || ip6_addr_isnone_val(*(ip6addr)))
+
+#define ipaddr_ntoa_unsafe(addr) ((IP_IS_V6_VAL(*addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr)))
-#endif /* LWIP_DHCP */
+#ifdef ip6_addr_cmp
+#undef ip6_addr_cmp
+#define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
+ ((addr1)->addr[1] == (addr2)->addr[1]) && \
+ ((addr1)->addr[2] == (addr2)->addr[2]) && \
+ ((addr1)->addr[3] == (addr2)->addr[3]))
+#endif
-#include "lwip/prot/dhcp.h"
+err_t netif_dhcp_off(struct netif *netif);
err_t netif_do_rmv_ipv6_addr(struct netif *netif, void *arguments);
@@ -113,49 +102,20 @@ err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu);
err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw_len);
-struct netif *netifapi_netif_find_by_name(const char *name);
-
-/* 2 seconds period */
-#define DUP_ARP_DETECT_TIME 2000
-
err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags);
err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr);
-#define LWIP_MAX_UDP_RAW_SEND_SIZE 65332
-
-#define ip6_addr_isnone_val(ip6addr) (((ip6addr).addr[0] == 0xffffffffUL) && \
- ((ip6addr).addr[1] == 0xffffffffUL) && \
- ((ip6addr).addr[2] == 0xffffffffUL) && \
- ((ip6addr).addr[3] == 0xffffffffUL))
-
-#define ip6_addr_isnone(ip6addr) (((ip6addr) == NULL) || ip6_addr_isnone_val(*(ip6addr)))
-
-
err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver);
err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver);
-#define ipaddr_ntoa_unsafe(addr) ((IP_IS_V6_VAL(*addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr)))
-
-#define SOF_BINDNONUNICAST 0x0800U /* socket has bind to a non unicast */
-
#if PF_PKT_SUPPORT
extern struct raw_pcb *pkt_raw_pcbs;
#endif
+#if LWIP_RAW
extern struct raw_pcb *raw_pcbs;
+#endif
-#ifdef ip6_addr_cmp
-#undef ip6_addr_cmp
-#define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
- ((addr1)->addr[1] == (addr2)->addr[1]) && \
- ((addr1)->addr[2] == (addr2)->addr[2]) && \
- ((addr1)->addr[3] == (addr2)->addr[3]))
-#endif //ip6_addr_cmp
-
-#define LWIP_EXT_POLL_SUPPORT LWIP_SOCKET_POLL
-
-#endif //LWIP_ENABLE_LOS_SHELL_CMD
-
-#endif //LITEOS_A_FIXME_H
+#endif /* LWIP_HDR_FIXME_H */
diff --git a/net/lwip-2.1/enhancement/src/api_shell.c b/net/lwip-2.1/enhancement/src/api_shell.c
old mode 100755
new mode 100644
index 1a8b98d0d304d20e4395c71a628305bb34530463..28921cd400287e1922a567c4051b89e78a7dcbae
--- 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:
@@ -33,7 +33,7 @@
#define icmp6_hdr netinet_icmp6_hdr
#include
#undef icmp6_hdr
-#include "api_shell_fix.h"
+#include "lwip/fixme.h"
#include "lwip/opt.h"
#if LWIP_ENABLE_LOS_SHELL_CMD
@@ -62,7 +62,7 @@
#include
#include
-#include "api_shell.h"
+#include "lwip/api_shell.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
@@ -78,7 +78,7 @@
#include "shell.h"
#endif
-#define netif_find netifapi_netif_find_by_name
+#define LWIP_STATIC static
#if LWIP_ARP
extern sys_sem_t ip_conflict_detect;
@@ -208,31 +208,31 @@ int netstat_netconn_sendq(struct netconn *conn);
#define PRINT_BUF_LEN 1024
#define MAX_MACADDR_STRING_LENGTH 18 /* including NULL */
-#define CONVERT_STRING_TO_HEX(_src, _dest) \
-{ \
- const char *_srcString = (char *)_src; \
- _dest = 0; \
- while (*_srcString) { \
- _dest = (unsigned char)((_dest << 4) & 0xFF); \
- if ((*_srcString >= 48) && (*_srcString <= 57)) /* between 0 to 9 */ \
- _dest |= (unsigned char)(*_srcString - 48); \
- else if ((*_srcString >= 65 && *_srcString <= 70)) /* between A to F */ \
- _dest |= (unsigned char)((*_srcString - 65) + 10); \
- else if ((*_srcString >= 97 && *_srcString <= 102)) /* between a to f */ \
- _dest |= (unsigned char)((*_srcString - 97) + 10); \
- else break; \
- ++_srcString; \
- } \
+#define CONVERT_STRING_TO_HEX(_src, _dest) \
+{ \
+ const char *_srcString = (char *)_src; \
+ _dest = 0; \
+ while (*_srcString) { \
+ _dest = (unsigned char)((_dest << 4) & 0xFF); \
+ if ((*_srcString >= 48) && (*_srcString <= 57)) /* between 0 to 9 */ \
+ _dest |= (unsigned char)(*_srcString - 48); \
+ else if ((*_srcString >= 65 && *_srcString <= 70)) /* between A to F */ \
+ _dest |= (unsigned char)((*_srcString - 65) + 10); \
+ else if ((*_srcString >= 97 && *_srcString <= 102)) /* between a to f */ \
+ _dest |= (unsigned char)((*_srcString - 97) + 10); \
+ else break; \
+ ++_srcString; \
+ } \
}
-#define ERR_IFCONFIG_STRING_PUT(ret, str) do \
-{ \
- (ret) = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, \
- PRINT_BUF_LEN - ifconfig_cmd->print_len, \
- ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), (str)); \
- if (((ret) > 0) && ((unsigned int)(ret) < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) \
- ifconfig_cmd->print_len += (unsigned int)(ret); \
-} while(0)
+#define ERR_IFCONFIG_STRING_PUT(ret, str) \
+ do { \
+ (ret) = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, \
+ PRINT_BUF_LEN - ifconfig_cmd->print_len, \
+ ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), (str)); \
+ if (((ret) > 0) && ((unsigned int)(ret) < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) \
+ ifconfig_cmd->print_len += (unsigned int)(ret); \
+ } while (0) \
#define LWIP_MSECS_TO_SECS(time_in_msecs) (time_in_msecs / 1000)
struct ifconfig_option {
@@ -275,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 {
@@ -1172,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;
@@ -1873,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;
}
@@ -1922,149 +1928,149 @@ SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShe
u32_t osShellPing(int argc, const char **argv)
{
- int sfd;
- struct sockaddr_in to;
- struct icmp_echo_hdr iecho;
- struct pbuf *pbuf_resp = NULL;
- struct icmp_echo_hdr *iecho_resp = NULL;
- struct ip_hdr *iphdr_resp = NULL;
- s16_t ip_hlen;
- ip_addr_t dst_ipaddr;
- fd_set fdReadSet;
- struct timeval stTimeVal;
- struct timespec start, end;
- int ret;
- s32_t i;
- long rtt;
- s32_t pingcount;
- char buf[50];
-
- if (!tcpip_init_finish) {
- PRINTK("ping: tcpip_init have not been called\n");
- return LOS_NOK;
- }
+ int sfd;
+ struct sockaddr_in to;
+ struct icmp_echo_hdr iecho;
+ struct pbuf *pbuf_resp = NULL;
+ struct icmp_echo_hdr *iecho_resp = NULL;
+ struct ip_hdr *iphdr_resp = NULL;
+ s16_t ip_hlen;
+ ip_addr_t dst_ipaddr;
+ fd_set fdReadSet;
+ struct timeval stTimeVal;
+ struct timespec start, end;
+ int ret;
+ s32_t i;
+ long rtt;
+ s32_t pingcount;
+ char buf[50];
- if ((argc < 1) || (argv == NULL)) {
- PRINTK("ping : invalid arguments, ping command receives ip as command line argument \n");
- return LOS_NOK;
- }
-
- if (argc == 2) {
- pingcount = atoi(argv[1]);
- if (pingcount < 1)
- pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
- } else {
- pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
- }
- PRINTK("ping %u packets start.\n", pingcount);
-
- /* initialize dst IP address */
+ if (!tcpip_init_finish) {
+ PRINTK("ping: tcpip_init have not been called\n");
+ return LOS_NOK;
+ }
+
+ if ((argc < 1) || (argv == NULL)) {
+ PRINTK("ping : invalid arguments, ping command receives ip as command line argument \n");
+ return LOS_NOK;
+ }
+
+ if (argc == 2) {
+ pingcount = atoi(argv[1]);
+ if (pingcount < 1)
+ pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
+ } else {
+ pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
+ }
+ PRINTK("ping %u packets start.\n", pingcount);
+
+ /* initialize dst IP address */
#if LWIP_DNS
- ip_2_ip4(&dst_ipaddr)->addr = get_hostip(argv[0]);
+ ip_2_ip4(&dst_ipaddr)->addr = get_hostip(argv[0]);
#else /* LWIP_DNS */
- ip_2_ip4(&dst_ipaddr)->addr = inet_addr(argv[0]);
+ ip_2_ip4(&dst_ipaddr)->addr = inet_addr(argv[0]);
#endif /* LWIP_DNS */
- to.sin_family = AF_INET;
- to.sin_addr.s_addr = ip_2_ip4(&dst_ipaddr)->addr;
- to.sin_port = 0;
+ to.sin_family = AF_INET;
+ to.sin_addr.s_addr = ip_2_ip4(&dst_ipaddr)->addr;
+ 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]);
- return LOS_NOK;
- }
+ if (to.sin_addr.s_addr == IPADDR_NONE || to.sin_addr.s_addr == IPADDR_ANY) {
+ PRINTK("ping : invalid ip address : NONE or ANY\n");
+ return LOS_NOK;
+ }
- sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
- if (sfd == -1) {
- PRINTK("ping : failed, socket creation failed\n");
- return LOS_NOK;
- }
+ sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
+ if (sfd == -1) {
+ PRINTK("ping : failed, socket creation failed\n");
+ return LOS_NOK;
+ }
- pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM);
- if (pbuf_resp == NULL) {
- PRINTK("ping : memory allocation failed\n");
- goto FAILURE;
- }
+ pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM);
+ if (pbuf_resp == NULL) {
+ PRINTK("ping : memory allocation failed\n");
+ goto FAILURE;
+ }
- for (i = 0; i < pingcount; i++) {
- (void)memset_s(&iecho, sizeof(iecho), 0, sizeof(iecho));
- ICMPH_TYPE_SET(&iecho, (u8_t)ICMP_ECHO);
- iecho.chksum = inet_chksum(&iecho, sizeof(struct icmp_echo_hdr));
+ for (i = 0; i < pingcount; i++) {
+ (void)memset_s(&iecho, sizeof(iecho), 0, sizeof(iecho));
+ ICMPH_TYPE_SET(&iecho, (u8_t)ICMP_ECHO);
+ iecho.chksum = inet_chksum(&iecho, sizeof(struct icmp_echo_hdr));
- ret = lwip_sendto(sfd, &iecho, sizeof(struct icmp_echo_hdr), 0, (struct sockaddr *)&to, (socklen_t)sizeof(to));
- if (ret == -1) {
- PRINTK("ping : sending ICMP echo msg failed\n");
- goto FAILURE;
- }
+ ret = lwip_sendto(sfd, &iecho, sizeof(struct icmp_echo_hdr), 0, (struct sockaddr *)&to, (socklen_t)sizeof(to));
+ if (ret == -1) {
+ PRINTK("ping : sending ICMP echo msg failed\n");
+ goto FAILURE;
+ }
- /* capture the start time to calculate round trip time */
- (void)clock_gettime(CLOCK_MONOTONIC_RAW, &start);
- /* Wait in select for ICMP response msg */
- FD_ZERO(&fdReadSet);
- FD_SET(sfd, &fdReadSet);
- stTimeVal.tv_sec = LWIP_SHELL_CMD_PING_TIMEOUT / 1000;
- stTimeVal.tv_usec = 0;
+ /* capture the start time to calculate round trip time */
+ (void)clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+ /* Wait in select for ICMP response msg */
+ FD_ZERO(&fdReadSet);
+ FD_SET(sfd, &fdReadSet);
+ stTimeVal.tv_sec = LWIP_SHELL_CMD_PING_TIMEOUT / 1000;
+ stTimeVal.tv_usec = 0;
DO_SELECT:
- ret = select(sfd + 1, &fdReadSet, 0, 0, &stTimeVal);
- if (ret < 0) {
- PRINTK("ping : select failure\n");
- goto FAILURE;
- } else if (ret == 0) {
- PRINTK("Request timed out.\n");
- continue;
- }
+ ret = select(sfd + 1, &fdReadSet, 0, 0, &stTimeVal);
+ if (ret < 0) {
+ PRINTK("ping : select failure\n");
+ goto FAILURE;
+ } else if (ret == 0) {
+ PRINTK("Request timed out.\n");
+ continue;
+ }
+
+ /* capture the end time to calculate round trip time */
+ (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
+ rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
- /* capture the end time to calculate round trip time */
- (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
- rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
+ ret = lwip_recv(sfd, pbuf_resp->payload, pbuf_resp->len, 0);
+ if (ret == -1) {
+ PRINTK("ping : receiving ICMP echo response msg failed\n");
+ goto FAILURE;
+ }
- ret = lwip_recv(sfd, pbuf_resp->payload, pbuf_resp->len, 0);
- if (ret == -1) {
- PRINTK("ping : receiving ICMP echo response msg failed\n");
- goto FAILURE;
- }
-
- /* Accessing ip header and icmp header */
- iphdr_resp = (struct ip_hdr*)(pbuf_resp->payload);
- ip_hlen = (s16_t)(IPH_HL(iphdr_resp) * 4);
- if (pbuf_header(pbuf_resp, (s16_t)(-ip_hlen))) {
- /* this failure will never happen, but failure handle is written just to be in safe side */
- PRINTK("ping : memory management failure\n");
- goto FAILURE;
- }
- iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload;
-
- /* Reverting back pbuf to its original state */
- if (pbuf_header(pbuf_resp, ip_hlen)) {
- /* this failure will never happen, but failure handle is written just to be in safe side */
- PRINTK("ping : memory management failure\n");
- goto FAILURE;
- }
-
- if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
- if (ICMPH_TYPE(iecho_resp) == ICMP_ER) {
- PRINTK("[%u]Reply from %s: time=%ims TTL=%u\n", i,
- inet_ntoa_r(to.sin_addr.s_addr, buf, sizeof(buf)), rtt, iphdr_resp->_ttl);
- } else if (ICMPH_TYPE(iecho_resp) == ICMP_ECHO) {
- /* If ping self, stack will receive a ICMP_ECHO request message flowing a ICMP_ER reply message,
- and we need reply only, do select again */
- goto DO_SELECT;
- }
+ /* Accessing ip header and icmp header */
+ iphdr_resp = (struct ip_hdr *)(pbuf_resp->payload);
+ ip_hlen = (s16_t)(IPH_HL(iphdr_resp) * 4);
+ if (pbuf_header(pbuf_resp, (s16_t)(-ip_hlen))) {
+ /* this failure will never happen, but failure handle is written just to be in safe side */
+ PRINTK("ping : memory management failure\n");
+ goto FAILURE;
+ }
+ iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload;
+
+ /* Reverting back pbuf to its original state */
+ if (pbuf_header(pbuf_resp, ip_hlen)) {
+ /* this failure will never happen, but failure handle is written just to be in safe side */
+ PRINTK("ping : memory management failure\n");
+ goto FAILURE;
+ }
+
+ if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
+ if (ICMPH_TYPE(iecho_resp) == ICMP_ER) {
+ PRINTK("[%u]Reply from %s: time=%ims TTL=%u\n", i,
+ inet_ntoa_r(to.sin_addr.s_addr, buf, sizeof(buf)), rtt, iphdr_resp->_ttl);
+ } else if (ICMPH_TYPE(iecho_resp) == ICMP_ECHO) {
+ /* If ping self, stack will receive a ICMP_ECHO request message flowing a ICMP_ER reply message,
+ and we need reply only, do select again */
+ goto DO_SELECT;
+ }
+ }
}
- }
- (void)lwip_close(sfd);
- (void)pbuf_free(pbuf_resp);
- return LOS_OK;
+ (void)lwip_close(sfd);
+ (void)pbuf_free(pbuf_resp);
+ return LOS_OK;
FAILURE:
- (void)lwip_close(sfd);
- if (pbuf_resp != NULL) {
- (void)pbuf_free(pbuf_resp);
- }
+ (void)lwip_close(sfd);
+ if (pbuf_resp != NULL) {
+ (void)pbuf_free(pbuf_resp);
+ }
- return LOS_NOK;
+ return LOS_NOK;
}
#ifdef LOSCFG_SHELL
@@ -2389,11 +2395,11 @@ LWIP_STATIC int create_ping6_socket(u8_t type, const void *param)
}
/*
- Function to parse the command line args for ping6 shell utility
- @return:
- Success: ERR_OK
- Failure: -1
-*/
+ * Function to parse the command line args for ping6 shell utility
+ * @return:
+ * Success: ERR_OK
+ * Failure: -1
+ */
LWIP_STATIC int parse_args_ping6(int argc, const char **argv, ping6_args_t *ping6_params)
{
int pingcount;
@@ -2581,170 +2587,50 @@ SHELLCMD_ENTRY(ping6_shellcmd, CMD_TYPE_EX, "ping6", XARGS, (CmdCallBackFunc)osS
#endif /* LOSCFG_SHELL_CMD_DEBUG */
#endif /* LWIP_IPV6 */
-#if LWIP_SNTP
+#if LWIP_SNTP
u32_t osShellNtpdate(int argc, const char **argv)
{
- int server_num = 0;
- char *ret = NULL;
- struct timeval get_time;
- char buf[50];
-
- (void)memset_s(&get_time, sizeof(struct timeval), 0, sizeof(struct timeval));
-
- if (!tcpip_init_finish) {
- PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
- return LOS_NOK;
- }
-
- if (argc < 1 || argv == NULL) {
- goto usage;
- }
-
- server_num = lwip_sntp_start(argc, (char **)argv, &get_time);
- if (server_num >= 0 && server_num < argc) {
- ret = ctime_r((time_t *)&get_time.tv_sec, buf);
- if (ret != NULL) {
- PRINTK("time server %s: %s\n", argv[server_num], ret);
- } else {
- PRINTK("ctime return null error\n");
- }
- } else {
- PRINTK("no server suitable for synchronization found\n");
- }
-
- return LOS_OK;
-
-usage:
- PRINTK("\nUsage:\n");
- PRINTK("ntpdate [SERVER_IP1] [SERVER_IP2] ...\n");
- return LOS_NOK;
-}
-
-#ifdef LOSCFG_SHELL_CMD_DEBUG
-SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc)osShellNtpdate);
-#endif /* LOSCFG_SHELL_CMD_DEBUG */
-
-#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",
-};
+ int server_num = 0;
+ char *ret = NULL;
+ struct timeval get_time;
+ char buf[50];
-#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;
- }
+ (void)memset_s(&get_time, sizeof(struct timeval), 0, sizeof(struct timeval));
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) {
+ if (argc < 1 || argv == NULL) {
goto usage;
}
- if (ucTftpGet) {
- ret = lwip_tftp_get_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
- TRANSFER_MODE_BINARY, szRemoteFileName, szLocalFileName);
+ server_num = lwip_sntp_start(argc, (char **)argv, &get_time);
+ if (server_num >= 0 && server_num < argc) {
+ ret = ctime_r((time_t *)&get_time.tv_sec, buf);
+ if (ret != NULL) {
+ PRINTK("time server %s: %s\n", argv[server_num], ret);
+ } else {
+ PRINTK("ctime return null error\n");
+ }
} else {
- ret = lwip_tftp_put_file_by_filename(ntohl(ulRemoteAddr), usTftpServPort,
- TRANSFER_MODE_BINARY, szLocalFileName, szRemoteFileName);
+ PRINTK("no server suitable for synchronization found\n");
}
- LWIP_ASSERT("TFTP UNKNOW ERROR!", ret < ARRAY_SIZE(TftpError));
- PRINTK("%s", TftpError[ret]);
- if (ret) {
- return LOS_NOK;
- } else {
- return LOS_OK;
- }
+ return LOS_OK;
+
usage:
- PRINTK("usage:\nTransfer a file from/to tftp server\n");
- PRINTK("tftp <-g/-p> -l FullPathLocalFile -r RemoteFile Host\n");
+ PRINTK("\nUsage:\n");
+ PRINTK("ntpdate [SERVER_IP1] [SERVER_IP2] ...\n");
return LOS_NOK;
}
+
#ifdef LOSCFG_SHELL_CMD_DEBUG
-SHELLCMD_ENTRY(tftp_shellcmd, CMD_TYPE_EX, "tftp", XARGS, (CmdCallBackFunc)osShellTftp);
+SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc)osShellNtpdate);
#endif /* LOSCFG_SHELL_CMD_DEBUG */
-#endif /* LOSCFG_NET_LWIP_SACK_TFTP */
+#endif /* LWIP_SNTP*/
#if LWIP_DNS
u32_t osShellDns(int argc, const char **argv)
@@ -2840,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;
}
@@ -2929,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;
}
@@ -3163,8 +3047,10 @@ void netstat_internal(void *ctx)
int recvQlen = 0;
int sendQlen = 0;
u_int proto;
+#if PF_PKT_SUPPORT
u8_t netif_name[IFNAMSIZ];
struct netif *netif = NULL;
+#endif
if (ndata == NULL) {
return;
@@ -3548,113 +3434,113 @@ SHELLCMD_ENTRY(dhclient_shellcmd, CMD_TYPE_EX, "dhclient", XARGS, (CmdCallBackFu
#define MAX_SIZE 1024
void tcp_access(int sockfd)
{
- size_t n, i;
- ssize_t ret;
- char msg[MAX_SIZE] = {0};
- while (1) {
- PRINTK("waiting for recv\n");
- (void)memset_s(msg, MAX_SIZE, 0, MAX_SIZE);
- ret = recv(sockfd, msg, MAX_SIZE - 1, 0);
- if (ret < 0) {
- PRINTK("recv failed, %d.\n", (u32_t)ret);
- (void)closesocket(sockfd);
- return;
- } else if (ret == 0) {
- (void)closesocket(sockfd);
- PRINTK("client disconnect.\n");
- return;
- }
-
- n = strlen(msg);
- for (i = 0; i < n; ++i) {
- if (msg[i] >= 'a' && msg[i] <= 'z') {
- msg[i] = (char)(msg[i] + ('A' - 'a'));
- } else if (msg[i] >= 'A' && msg[i] <= 'Z') {
- msg[i] = (char)(msg[i] + ('a' - 'A'));
- }
- }
+ size_t n, i;
+ ssize_t ret;
+ char msg[MAX_SIZE] = {0};
+ while (1) {
+ PRINTK("waiting for recv\n");
+ (void)memset_s(msg, MAX_SIZE, 0, MAX_SIZE);
+ ret = recv(sockfd, msg, MAX_SIZE - 1, 0);
+ if (ret < 0) {
+ PRINTK("recv failed, %d.\n", (u32_t)ret);
+ (void)closesocket(sockfd);
+ return;
+ } else if (ret == 0) {
+ (void)closesocket(sockfd);
+ PRINTK("client disconnect.\n");
+ return;
+ }
+
+ n = strlen(msg);
+ for (i = 0; i < n; ++i) {
+ if (msg[i] >= 'a' && msg[i] <= 'z') {
+ msg[i] = (char)(msg[i] + ('A' - 'a'));
+ } else if (msg[i] >= 'A' && msg[i] <= 'Z') {
+ msg[i] = (char)(msg[i] + ('a' - 'A'));
+ }
+ }
- if (send(sockfd, msg, n, 0) < 0) {
- PRINTK("send failed!\r\n");
- continue;
+ if (send(sockfd, msg, n, 0) < 0) {
+ PRINTK("send failed!\r\n");
+ continue;
+ }
}
- }
}
u32_t osTcpserver(int argc, const char **argv)
{
- uint16_t port;
- int sockfd = -1;
- int ret;
- struct sockaddr_in seraddr;
- struct sockaddr_in cliaddr;
- u32_t cliaddr_size = (u32_t)sizeof(cliaddr);
- int reuse, iPortVal;
-
- if (tcpip_init_finish == 0) {
- PRINTK("tcpip_init have not been called\n");
- return LOS_NOK;
- }
+ uint16_t port;
+ int sockfd = -1;
+ int ret;
+ struct sockaddr_in seraddr;
+ struct sockaddr_in cliaddr;
+ u32_t cliaddr_size = (u32_t)sizeof(cliaddr);
+ int reuse, iPortVal;
- if (argc < 1 || argv == NULL) {
- PRINTK("\nUsage: tcpserver \n");
- return LOS_NOK;
- }
+ if (tcpip_init_finish == 0) {
+ PRINTK("tcpip_init have not been called\n");
+ return LOS_NOK;
+ }
- iPortVal = atoi(argv[0]);
- /* Port 0 not supported , negative values not supported , max port limit is 65535 */
- if (iPortVal <= 0 || iPortVal > 65535) {
- PRINTK("\nUsage: Invalid port\n");
- return LOS_NOK;
- }
+ if (argc < 1 || argv == NULL) {
+ PRINTK("\nUsage: tcpserver \n");
+ return LOS_NOK;
+ }
- port = (uint16_t)iPortVal;
+ iPortVal = atoi(argv[0]);
+ /* Port 0 not supported , negative values not supported , max port limit is 65535 */
+ if (iPortVal <= 0 || iPortVal > 65535) {
+ PRINTK("\nUsage: Invalid port\n");
+ return LOS_NOK;
+ }
- /* removed the print of argv[1] as its accessing argv[1] without verifying argc and
- * argv[1] not used anywhere else */
- PRINTK("argv[0]:%s, argc:%d\r\n", argv[0], argc);
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0) {
- PRINTK("\nUsage: create socket fail!\n");
- return LOS_NOK;
- }
- reuse = 1;
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuse, sizeof(reuse)) != 0) {
- (void)closesocket(sockfd);
- PRINTK("set SO_REUSEADDR failed\n");
- return LOS_NOK;
- }
+ port = (uint16_t)iPortVal;
- (void)memset_s(&seraddr, sizeof(seraddr), 0, sizeof(seraddr));
- seraddr.sin_family = AF_INET;
- seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
- seraddr.sin_port = htons(port);
+ /* removed the print of argv[1] as its accessing argv[1] without verifying argc and
+ * argv[1] not used anywhere else */
+ PRINTK("argv[0]:%s, argc:%d\r\n", argv[0], argc);
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ PRINTK("\nUsage: create socket fail!\n");
+ return LOS_NOK;
+ }
+ reuse = 1;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuse, sizeof(reuse)) != 0) {
+ (void)closesocket(sockfd);
+ PRINTK("set SO_REUSEADDR failed\n");
+ return LOS_NOK;
+ }
- ret = bind(sockfd, (struct sockaddr*)&seraddr, sizeof(seraddr));
- if (ret < 0) {
- PRINTK("bind ip and port failed");
- (void)closesocket(sockfd);
- return LOS_NOK;
- }
+ (void)memset_s(&seraddr, sizeof(seraddr), 0, sizeof(seraddr));
+ seraddr.sin_family = AF_INET;
+ seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ seraddr.sin_port = htons(port);
- ret = listen(sockfd, 5);
- if (ret < 0) {
- (void)closesocket(sockfd);
- PRINTK("listen failed\n");
- return LOS_NOK;
- }
- while (1) {
- PRINTK("waiting for accept\n");
- (void)memset_s(&cliaddr, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in));
- ret = (int)accept(sockfd, (struct sockaddr*)&cliaddr, &cliaddr_size);
+ ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));
+ if (ret < 0) {
+ PRINTK("bind ip and port failed");
+ (void)closesocket(sockfd);
+ return LOS_NOK;
+ }
+
+ ret = listen(sockfd, 5);
if (ret < 0) {
- (void)closesocket(sockfd);
- PRINTK("Accept failed, %d\n", ret);
- break ;
+ (void)closesocket(sockfd);
+ PRINTK("listen failed\n");
+ return LOS_NOK;
+ }
+ while (1) {
+ PRINTK("waiting for accept\n");
+ (void)memset_s(&cliaddr, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in));
+ ret = (int)accept(sockfd, (struct sockaddr *)&cliaddr, &cliaddr_size);
+ if (ret < 0) {
+ (void)closesocket(sockfd);
+ PRINTK("Accept failed, %d\n", ret);
+ break;
+ }
+ tcp_access(ret);
}
- tcp_access(ret);
- }
- return LOS_NOK; // Hits Only If Accept Fails
+ return LOS_NOK; // Hits Only If Accept Fails
}
#ifdef LOSCFG_SHELL_CMD_DEBUG
@@ -3665,71 +3551,71 @@ SHELLCMD_ENTRY(tcpserver_shellcmd, CMD_TYPE_EX, "tcpserver", XARGS, (CmdCallBack
#ifdef LWIP_DEBUG_UDPSERVER
void udpserver(int argc, const char **argv)
{
- int sockfd, fromlen;
- int ret, iPortVal;
- struct sockaddr_in seraddr;
- struct sockaddr_in cliaddr;
- size_t n, i;
+ int sockfd, fromlen;
+ int ret, iPortVal;
+ struct sockaddr_in seraddr;
+ struct sockaddr_in cliaddr;
+ size_t n, i;
- char msg[MAX_SIZE] = {0};
- uint16_t port;
+ char msg[MAX_SIZE] = {0};
+ uint16_t port;
- if (argc < 1) {
- PRINTK("\nUsage: udpserver \n");
- return;
- }
+ if (argc < 1) {
+ PRINTK("\nUsage: udpserver \n");
+ return;
+ }
- iPortVal = atoi(argv[0]);
- /* Port 0 not supported , negative values not supported , max port limit is 65535 */
- if (iPortVal <= 0 || iPortVal > 65535) {
- PRINTK("\nUsage: Invalid Port\n");
- return ;
- }
+ iPortVal = atoi(argv[0]);
+ /* Port 0 not supported , negative values not supported , max port limit is 65535 */
+ if (iPortVal <= 0 || iPortVal > 65535) {
+ PRINTK("\nUsage: Invalid Port\n");
+ return;
+ }
- port = (uint16_t)iPortVal;
+ port = (uint16_t)iPortVal;
- PRINTK("port:%d\r\n", port);
+ PRINTK("port:%d\r\n", port);
- sockfd = lwip_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (sockfd == -1) {
- PRINTK("\ncreate socket fail\n");
- return;
- }
-
- (void)memset_s(&seraddr, sizeof(seraddr), 0, sizeof(seraddr));
- (void)memset_s(&cliaddr, sizeof(cliaddr), 0, sizeof(cliaddr));
- seraddr.sin_family = AF_INET;
- seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
- seraddr.sin_port = htons(port);
- ret = lwip_bind(sockfd, (struct sockaddr*)&seraddr, sizeof(seraddr));
- if (ret < 0) {
- PRINTK("bind ip and port failed:%d\n", errno);
- (void)closesocket(sockfd);
- return;
- }
+ sockfd = lwip_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (sockfd == -1) {
+ PRINTK("\ncreate socket fail\n");
+ return;
+ }
- while(1) {
- ret = recvfrom(sockfd, msg, MAX_SIZE - 1, 0, (struct sockaddr *)&cliaddr, (socklen_t *)&fromlen);
- if (ret >= 0) {
- n = strlen(msg);
- for (i = 0; i < n; ++i) {
- if (msg[i] >= 'a' && msg[i] <= 'z') {
- msg[i] = (char)(msg[i] + 'A' - 'a');
- } else if (msg[i] >= 'A' && msg[i] <= 'Z') {
- msg[i] = (char)(msg[i] + 'a' - 'A');
+ (void)memset_s(&seraddr, sizeof(seraddr), 0, sizeof(seraddr));
+ (void)memset_s(&cliaddr, sizeof(cliaddr), 0, sizeof(cliaddr));
+ seraddr.sin_family = AF_INET;
+ seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ seraddr.sin_port = htons(port);
+ ret = lwip_bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));
+ if (ret < 0) {
+ PRINTK("bind ip and port failed:%d\n", errno);
+ (void)closesocket(sockfd);
+ return;
+ }
+
+ while (1) {
+ ret = recvfrom(sockfd, msg, MAX_SIZE - 1, 0, (struct sockaddr *)&cliaddr, (socklen_t *)&fromlen);
+ if (ret >= 0) {
+ n = strlen(msg);
+ for (i = 0; i < n; ++i) {
+ if (msg[i] >= 'a' && msg[i] <= 'z') {
+ msg[i] = (char)(msg[i] + 'A' - 'a');
+ } else if (msg[i] >= 'A' && msg[i] <= 'Z') {
+ msg[i] = (char)(msg[i] + 'a' - 'A');
+ }
+ }
+ ret = sendto(sockfd, msg, n + 1, 0, (struct sockaddr *)&cliaddr, (socklen_t)fromlen);
+ if (ret <= 0 && errno == EPIPE) {
+ break;
+ }
+ } else {
+ break;
}
- }
- ret = sendto(sockfd, msg, n + 1, 0, (struct sockaddr *)&cliaddr, (socklen_t)fromlen);
- if (ret <= 0 && errno == EPIPE) {
- break;
- }
- } else {
- break;
}
- }
- (void)closesocket(sockfd);
- return;
+ (void)closesocket(sockfd);
+ return;
}
#ifdef LOSCFG_SHELL_CMD_DEBUG
@@ -3741,115 +3627,115 @@ SHELLCMD_ENTRY(udpserver_shellcmd, CMD_TYPE_EX, "udpserver", XARGS, (CmdCallBack
LWIP_STATIC
u32_t netdebug_memp(int argc, const char **argv)
{
- u32_t ret = LOS_OK;
- int type;
-
- if (argc == 2) {
- if (!strcmp("-i", argv[1])) {
- debug_memp_info();
- } else if (!strcmp("-udp", argv[1])) {
- debug_memp_type_info(MEMP_UDP_PCB);
- } else if (!strcmp("-tcp", argv[1])) {
- debug_memp_type_info(MEMP_TCP_PCB);
- } else if (!strcmp("-raw", argv[1])) {
- debug_memp_type_info(MEMP_RAW_PCB);
- } else if (!strcmp("-conn", argv[1])) {
- debug_memp_type_info(MEMP_NETCONN);
+ u32_t ret = LOS_OK;
+ int type;
+
+ if (argc == 2) {
+ if (!strcmp("-i", argv[1])) {
+ debug_memp_info();
+ } else if (!strcmp("-udp", argv[1])) {
+ debug_memp_type_info(MEMP_UDP_PCB);
+ } else if (!strcmp("-tcp", argv[1])) {
+ debug_memp_type_info(MEMP_TCP_PCB);
+ } else if (!strcmp("-raw", argv[1])) {
+ debug_memp_type_info(MEMP_RAW_PCB);
+ } else if (!strcmp("-conn", argv[1])) {
+ debug_memp_type_info(MEMP_NETCONN);
+ } else {
+ ret = LOS_NOK;
+ }
+ } else if (argc == 3) {
+ if (!strcmp("-d", argv[1])) {
+ type = atoi(argv[2]);
+ if (type >= 0) {
+ debug_memp_detail(type);
+ } else {
+ PRINTK("Error: type < 0\n");
+ ret = LOS_NOK;
+ }
+ } else {
+ ret = LOS_NOK;
+ }
} else {
- ret = LOS_NOK;
- }
- } else if (argc == 3) {
- if (!strcmp("-d", argv[1])) {
- type = atoi(argv[2]);
- if (type >= 0) {
- debug_memp_detail(type);
- } else {
- PRINTK("Error: type < 0\n");
ret = LOS_NOK;
- }
- } else {
- ret = LOS_NOK;
}
- } else {
- ret = LOS_NOK;
- }
- return ret;
+ return ret;
}
LWIP_STATIC
u32_t netdebug_sock(int argc, const char **argv)
{
- int idx;
- u32_t ret = LOS_NOK;
-
- if (argc == 2) {
- if (!strcmp("-i", argv[1])) {
- /* netdebug sock -i */
- for (idx = 0; idx < (int)LWIP_CONFIG_NUM_SOCKETS; idx++) {
- debug_socket_info(idx, 1, 0);
- }
- ret = LOS_OK;
- }
- } else if (argc == 3) {
- if (!strcmp("-d", argv[1])) {
- /* netdebug sock -d */
- idx = atoi(argv[2]);
- if (idx >= 0) {
- debug_socket_info(idx, 1, 1);
- ret = LOS_OK;
- } else {
- PRINTK("Error: idx < 0\n");
- }
+ int idx;
+ u32_t ret = LOS_NOK;
+
+ if (argc == 2) {
+ if (!strcmp("-i", argv[1])) {
+ /* netdebug sock -i */
+ for (idx = 0; idx < (int)LWIP_CONFIG_NUM_SOCKETS; idx++) {
+ debug_socket_info(idx, 1, 0);
+ }
+ ret = LOS_OK;
+ }
+ } else if (argc == 3) {
+ if (!strcmp("-d", argv[1])) {
+ /* netdebug sock -d */
+ idx = atoi(argv[2]);
+ if (idx >= 0) {
+ debug_socket_info(idx, 1, 1);
+ ret = LOS_OK;
+ } else {
+ PRINTK("Error: idx < 0\n");
+ }
+ }
}
- }
- return ret;
+ return ret;
}
u32_t osShellNetDebug(int argc, const char **argv)
{
- u32_t ret = LOS_NOK;
-
- if (argc < 1 || argv == NULL) {
- goto usage;
- }
+ u32_t ret = LOS_NOK;
- if (!strcmp("memp", argv[0])) {
- ret = netdebug_memp(argc, argv);
- if (ret != LOS_OK) {
- goto usage_memp;
+ if (argc < 1 || argv == NULL) {
+ goto usage;
}
- } else if (!strcmp("sock", argv[0])) {
- /* netdebug sock {-i | -d } */
- ret = netdebug_sock(argc, argv);
- if (ret != LOS_OK) {
- goto usage_sock;
+
+ if (!strcmp("memp", argv[0])) {
+ ret = netdebug_memp(argc, argv);
+ if (ret != LOS_OK) {
+ goto usage_memp;
+ }
+ } else if (!strcmp("sock", argv[0])) {
+ /* netdebug sock {-i | -d } */
+ ret = netdebug_sock(argc, argv);
+ if (ret != LOS_OK) {
+ goto usage_sock;
+ }
+ } else {
+ goto usage;
}
- } else {
- goto usage;
- }
- return ret;
+ return ret;
usage:
- /* Cmd help */
- PRINTK("\nUsage:\n");
- PRINTK("netdebug memp {-i | -d | -udp | -tcp | -raw |-conn}\n");
- PRINTK("netdebug sock {-i | -d }\n");
- return LOS_NOK;
+ /* Cmd help */
+ PRINTK("\nUsage:\n");
+ PRINTK("netdebug memp {-i | -d | -udp | -tcp | -raw |-conn}\n");
+ PRINTK("netdebug sock {-i | -d }\n");
+ return LOS_NOK;
usage_memp:
- /* netdebug memp help */
- PRINTK("\nUsage:\n");
- PRINTK("netdebug memp {-i | -d | -udp | -tcp | -raw |-conn}\n");
- return LOS_NOK;
+ /* netdebug memp help */
+ PRINTK("\nUsage:\n");
+ PRINTK("netdebug memp {-i | -d | -udp | -tcp | -raw |-conn}\n");
+ return LOS_NOK;
usage_sock:
- /* netdebug sock help */
- PRINTK("\nUsage:\n");
- PRINTK("netdebug sock {-i | -d }\n");
- return LOS_NOK;
+ /* netdebug sock help */
+ PRINTK("\nUsage:\n");
+ PRINTK("netdebug sock {-i | -d }\n");
+ return LOS_NOK;
}
#endif /* LWIP_DEBUG_INFO */
@@ -3880,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);
@@ -3907,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",
@@ -3941,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);
@@ -3968,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);
@@ -3991,7 +3877,7 @@ extern void cmd_reset(void);
void osShellReboot(int argc, const char **argv)
{
- cmd_reset();
+ cmd_reset();
}
#ifdef LOSCFG_SHELL_CMD_DEBUG
diff --git a/net/lwip-2.1/enhancement/src/dhcps.c b/net/lwip-2.1/enhancement/src/dhcps.c
new file mode 100644
index 0000000000000000000000000000000000000000..e31a47943348c0cb502b57a676bb4ac03778718c
--- /dev/null
+++ b/net/lwip-2.1/enhancement/src/dhcps.c
@@ -0,0 +1,982 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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.
+ */
+
+/**
+ * @file
+ * Dynamic Host Configuration Protocol Server
+ *
+ */
+
+#include "../core/ipv4/dhcp.c" /* for enum dhcp_option_idx/dhcp_option_xx/dhcp_parse_reply etc. */
+
+#include "lwip/opt.h"
+
+#if (LWIP_DHCP) && (LWIP_DHCPS) /* don't build if not configured for use in lwipopts.h */
+#include
+
+#include "lwip/stats.h"
+#include "lwip/mem.h"
+#include "lwip/udp.h"
+#include "lwip/ip_addr.h"
+#include "lwip/netif.h"
+#include "lwip/def.h"
+#include "lwip/prot/dhcp.h"
+#include "lwip/dhcp.h"
+#include "lwip/dhcps.h"
+#include "lwip/sys.h"
+#include "netif/etharp.h"
+
+#define DHCPS_ADDRESS_FREE 0x0
+#define DHCPS_ADDRESS_OFFERRED 0x1
+#define DHCPS_ADDRESS_BOUND 0x2
+#define DHCPS_ADDRESS_DECLINED 0x3
+
+#define LWIP_STATIC static
+#define DHCP_OPTION_ROUTER_SIZE 4
+#define DHCP_OPTION_SUBNET_MASK_SIZE 4
+#define DHCP_OPTION_LEASE_TIME_SIZE 4
+#define DHCP_OPTION_SERVER_ID_LEN 4
+#define DHCP_OPTION_T1_LEN 4
+#define DHCP_OPTION_T2_LEN 4
+
+#define DHCP_CLIENT_PORT 68
+#define DHCP_SERVER_PORT 67
+
+#define DHCP_BROADCAST_FLAG 0x8000
+
+struct dyn_lease_addr {
+ u8_t cli_hwaddr[DHCP_CHADDR_LEN];
+ u32_t flags;
+ u32_t leasetime;
+ u32_t proposed_leasetime;
+ ip4_addr_t cli_addr;
+};
+
+struct dhcps {
+ struct dhcp dhcp;
+ struct udp_pcb *pcb;
+ struct dyn_lease_addr leasearr[LWIP_DHCPS_MAX_LEASE];
+ u8_t pcb_allocated;
+ u8_t lease_num;
+ struct netif *netif;
+ ip4_addr_t start_addr;
+ ip4_addr_t end_addr;
+};
+
+#define dhcps_option_given(dhcps, idx) dhcp_option_given(&(dhcps)->dhcp, idx)
+#define dhcps_got_option(dhcps, idx) dhcp_got_option(&(dhcps)->dhcp, idx)
+#define dhcps_clear_option(dhcps, idx) dhcp_clear_option(&(dhcps)->dhcp, idx)
+#define dhcps_clear_all_options(dhcps) dhcp_clear_all_options(&(dhcps)->dhcp)
+#define dhcps_get_option_value(dhcps, idx) dhcp_get_option_value(&(dhcps)->dhcp, idx)
+#define dhcps_set_option_value(dhcps, idx, val) dhcp_set_option_value(&(dhcps)->dhcp, idx, val)
+
+#define netif_get_dhcps(netif) ((struct dhcps*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS))
+#define netif_set_dhcps(netif, dhcps) netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS, dhcps)
+
+LWIP_STATIC void dhcp_common_option(struct dhcp_msg *msg_out, u8_t option_type, u8_t option_len, u16_t *options_out_len);
+LWIP_STATIC void dhcp_common_option_byte(struct dhcp_msg *msg_out, u8_t value, u16_t *options_out_len);
+LWIP_STATIC void dhcp_common_option_long(struct dhcp_msg *msg_out, u32_t value, u16_t *options_out_len);
+LWIP_STATIC void dhcp_common_option_trailer(struct dhcp_msg *msg_out, u16_t options_out_len, struct pbuf *p_out);
+LWIP_STATIC err_t dhcps_parse_options(struct pbuf *p, struct dhcps *dhcps);
+
+LWIP_STATIC struct pbuf *dhcps_create_base_msg(struct dhcp_msg *client_msg);
+LWIP_STATIC void remove_stale_entries(struct dhcps *dhcps);
+LWIP_STATIC void add_client_entry(struct dhcps *dhcps, unsigned int idx, struct dhcp_msg *client_msg);
+LWIP_STATIC int find_free_slot(struct dhcps *dhcps);
+LWIP_STATIC struct dyn_lease_addr *find_client_lease(struct dhcps *dhcps, struct dhcp_msg *client_msg);
+LWIP_STATIC ip4_addr_t validate_discover(struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr **client_lease);
+LWIP_STATIC void handle_discover(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease);
+LWIP_STATIC ip4_addr_t validate_request_message(struct netif *netif, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease, ip4_addr_t serverid);
+LWIP_STATIC void handle_request(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease, ip4_addr_t serverid);
+LWIP_STATIC void handle_decline(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease);
+LWIP_STATIC void handle_inform(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg);
+LWIP_STATIC void handle_client_messages(struct netif *netif, struct dhcps *dhcps,
+ struct dhcp_msg *client_msg, ip4_addr_t serverid, u8_t msg_type);
+LWIP_STATIC void dhcps_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p,
+ const ip_addr_t *ip_addr, u16_t port);
+
+LWIP_STATIC struct pbuf *dhcps_create_base_msg(struct dhcp_msg *client_msg)
+{
+ struct pbuf *srvr_msg_pbuf = NULL;
+ struct dhcp_msg *srvr_msg = NULL;
+
+ srvr_msg_pbuf = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM);
+ if (srvr_msg_pbuf == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
+ ("dhcps_create_base_msg(): could not allocate pbuf\n"));
+ return NULL;
+ }
+
+ LWIP_ASSERT("dhcps_create_base_msg: check that first pbuf can hold struct dhcp_msg",
+ (srvr_msg_pbuf->len >= sizeof(struct dhcp_msg)));
+#if DRIVER_STATUS_CHECK
+ srvr_msg_pbuf->flags |= PBUF_FLAG_DHCP_BUF;
+#endif
+
+ srvr_msg = (struct dhcp_msg *)srvr_msg_pbuf->payload;
+ srvr_msg->op = DHCP_BOOTREPLY;
+ srvr_msg->htype = client_msg->htype;
+ srvr_msg->hlen = client_msg->hlen;
+ srvr_msg->hops = 0;
+ srvr_msg->xid = client_msg->xid;
+ srvr_msg->secs = 0;
+ srvr_msg->flags = client_msg->flags;
+ ip4_addr_set_zero(&srvr_msg->ciaddr);
+ ip4_addr_set_zero(&srvr_msg->yiaddr);
+ ip4_addr_set_zero(&srvr_msg->siaddr);
+ ip4_addr_copy(srvr_msg->giaddr, client_msg->giaddr);
+ if (memcpy_s(srvr_msg->chaddr, sizeof(srvr_msg->chaddr), client_msg->chaddr, DHCP_CHADDR_LEN) != EOK) {
+ (void)pbuf_free(srvr_msg_pbuf);
+ return NULL;
+ }
+ (void)memset_s(srvr_msg->sname, sizeof(srvr_msg->sname), 0, DHCP_SNAME_LEN);
+ (void)memset_s(srvr_msg->file, sizeof(srvr_msg->file), 0, DHCP_FILE_LEN);
+ srvr_msg->cookie = PP_HTONL(DHCP_MAGIC_COOKIE);
+
+ return srvr_msg_pbuf;
+}
+
+LWIP_STATIC void remove_stale_entries(struct dhcps *dhcps)
+{
+ int i = 0;
+ u32_t curr_time = sys_now();
+
+ for (i = 0; i < dhcps->lease_num; i++) {
+ /* Slot should not be free or have infinite lease time */
+ if ((dhcps->leasearr[i].flags != DHCPS_ADDRESS_FREE) && (dhcps->leasearr[i].leasetime != (u32_t)~0)) {
+ if (dhcps->leasearr[i].leasetime < curr_time) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("remove_stale_entries: Removing Client Entry at Index = %"U32_F"\n", i));
+ (void)memset_s(&(dhcps->leasearr[i]), sizeof(struct dyn_lease_addr), 0, sizeof(struct dyn_lease_addr));
+ dhcps->leasearr[i].flags = DHCPS_ADDRESS_FREE;
+ }
+ }
+ }
+}
+
+LWIP_STATIC void add_client_entry(struct dhcps *dhcps, unsigned int idx, struct dhcp_msg *client_msg)
+{
+ u32_t client_lease_time = (u32_t)(LWIP_DHCPS_LEASE_TIME);
+
+ if ((dhcps_option_given(dhcps, DHCP_OPTION_IDX_LEASE_TIME))
+#if (LWIP_DHCPS_LEASE_TIME != ~0)
+ && (dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_LEASE_TIME) < LWIP_DHCPS_LEASE_TIME)
+#endif
+ ) {
+ client_lease_time = (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_LEASE_TIME);
+ }
+
+ (void)memset_s(&(dhcps->leasearr[idx]), sizeof(struct dyn_lease_addr), 0, sizeof(struct dyn_lease_addr));
+ if (memcpy_s(dhcps->leasearr[idx].cli_hwaddr, DHCP_CHADDR_LEN,
+ client_msg->chaddr, sizeof(client_msg->chaddr)) != EOK) {
+ return;
+ }
+ /* This is called only during offer message, so adding offer time.
+ This is later updated to lease time when request message is handled */
+ dhcps->leasearr[idx].leasetime = sys_now() + (LWIP_DHCPS_OFFER_TIME * 1000);
+ dhcps->leasearr[idx].cli_addr.addr = dhcps->start_addr.addr + idx;
+ dhcps->leasearr[idx].flags = DHCPS_ADDRESS_OFFERRED;
+ dhcps->leasearr[idx].proposed_leasetime = client_lease_time;
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("add_client_entry: Adding Client Entry at Index = %"U32_F"\n", idx));
+}
+
+LWIP_STATIC int find_free_slot(struct dhcps *dhcps)
+{
+ int i;
+ for (i = 0; i < dhcps->lease_num; i++) {
+ if ((dhcps->leasearr[i].flags == DHCPS_ADDRESS_FREE) &&
+ (htonl(dhcps->start_addr.addr + (u32_t)i) != ip_2_ip4(&dhcps->netif->ip_addr)->addr)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("find_free_slot: Found Free Slot at Index = %"U32_F"\n", i));
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+LWIP_STATIC struct dyn_lease_addr *find_client_lease(struct dhcps *dhcps, struct dhcp_msg *client_msg)
+{
+ int i;
+ for (i = 0; i < dhcps->lease_num; i++) {
+ if (dhcps->leasearr[i].flags != DHCPS_ADDRESS_FREE) {
+ if (memcmp(dhcps->leasearr[i].cli_hwaddr, client_msg->chaddr, client_msg->hlen) == 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("find_client_lease: Found Client Lease at Index = %"U32_F"\n", i));
+ return &(dhcps->leasearr[i]);
+ }
+ }
+ }
+
+ return NULL;
+}
+
+LWIP_STATIC ip4_addr_t validate_discover(struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr **client_lease)
+{
+ ip4_addr_t client_ip;
+ int idx = -1;
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_discover: Validating Discover Message\n"));
+
+ client_ip.addr = 0;
+ if (*client_lease == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_discover: Existing Client Lease not Found\n"));
+ if (dhcps_option_given(dhcps, DHCP_OPTION_IDX_REQUESTED_IP)) {
+ client_ip.addr = (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_REQUESTED_IP);
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_discover function: Requested IP from client = %"U32_F"\n", client_ip.addr));
+#endif
+
+ if ((client_ip.addr >= dhcps->start_addr.addr) && (client_ip.addr <= dhcps->end_addr.addr)) {
+ idx = (int)(client_ip.addr - dhcps->start_addr.addr);
+ if ((dhcps->leasearr[idx].flags != DHCPS_ADDRESS_FREE) ||
+ (ntohl(client_ip.addr) == ip_2_ip4(&dhcps->netif->ip_addr)->addr)) {
+ /* Requested IP is not available */
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_discover function: Requested IP from client = %"U32_F" Not available \n", client_ip.addr));
+#endif
+ idx = -1;
+ }
+ }
+ }
+
+ if (idx == -1) {
+ idx = find_free_slot(dhcps);
+ if (idx == -1) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_discover function: No Free Slot available for Storing addresses\n"));
+ client_ip.addr = 0;
+ return client_ip;
+ }
+ client_ip.addr = dhcps->start_addr.addr + (u32_t)idx;
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_discover function: New IP = %"U32_F" is being assigned\n", client_ip.addr));
+#endif
+ }
+
+ add_client_entry(dhcps, (unsigned int)idx, client_msg);
+ (*client_lease) = &(dhcps->leasearr[idx]);
+ } else {
+ client_ip.addr = (*client_lease)->cli_addr.addr;
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_discover: Existing Client Lease Found. Existing IP =%"U32_F"\n", client_ip.addr));
+#endif
+
+ if ((dhcps_option_given(dhcps, DHCP_OPTION_IDX_LEASE_TIME))
+#if (~0 != LWIP_DHCPS_LEASE_TIME)
+ && (dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_LEASE_TIME) < LWIP_DHCPS_LEASE_TIME)
+#endif
+ ) {
+ /* Assign the newly requested time or else use the existing lease time as-is */
+ (*client_lease)->proposed_leasetime = (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_LEASE_TIME);
+ }
+ }
+
+ return client_ip;
+}
+
+void dhcp_common_option(struct dhcp_msg *msg_out, u8_t option_type, u8_t option_len, u16_t *options_out_len)
+{
+ *options_out_len = dhcp_option(*options_out_len, msg_out->options, option_type, option_len);
+}
+
+void dhcp_common_option_byte(struct dhcp_msg *msg_out, u8_t value, u16_t *options_out_len)
+{
+ *options_out_len = dhcp_option_byte(*options_out_len, msg_out->options, value);
+}
+
+void dhcp_common_option_long(struct dhcp_msg *msg_out, u32_t value, u16_t *options_out_len)
+{
+ *options_out_len = dhcp_option_long(*options_out_len, msg_out->options, value);
+}
+
+void dhcp_common_option_trailer(struct dhcp_msg *msg_out, u16_t options_out_len, struct pbuf *p_out)
+{
+ dhcp_option_trailer(options_out_len, msg_out->options, p_out);
+}
+
+LWIP_STATIC void handle_discover(struct netif *netif, struct dhcps *dhcps,
+ struct dhcp_msg *client_msg, struct dyn_lease_addr *client_lease)
+{
+#if !LWIP_DHCPS_DISCOVER_BROADCAST
+ ip_addr_t client_ipaddr;
+#endif
+
+ ip4_addr_t client_ip;
+ ip_addr_t dst_addr;
+ struct pbuf *out_msg = NULL;
+ struct dhcp_msg *srvr_msg = NULL;
+ u16_t options_len = 0;
+#if !LWIP_DHCPS_DISCOVER_BROADCAST
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ struct eth_addr ethaddr;
+#endif
+#endif
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: Processing Discover Message\n"));
+
+ client_ip = validate_discover(dhcps, client_msg, &client_lease);
+ if (client_ip.addr == 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_discover: Returning as unable to get a proper address for client\n"));
+ return;
+ }
+
+ out_msg = dhcps_create_base_msg(client_msg);
+ if (out_msg == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_discover function: Memory allocation for base message failed\n"));
+ return;
+ }
+
+ srvr_msg = (struct dhcp_msg *)out_msg->payload;
+ // no need check msg pointer from payload here
+ srvr_msg->yiaddr.addr = htonl(client_ip.addr);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
+ dhcp_common_option_byte(srvr_msg, DHCP_OFFER, &options_len);
+
+ /* hilink need this router option */
+ dhcp_common_option(srvr_msg, DHCP_OPTION_ROUTER, DHCP_OPTION_ROUTER_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip_2_ip4(&netif->ip_addr)->addr), &options_len);
+
+ /* netif already holds the Server ID in network order. so, no need to convert it again */
+ dhcp_common_option(srvr_msg, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SERVER_ID_LEN, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip_2_ip4(&netif->ip_addr)->addr), &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_LEASE_TIME_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, client_lease->proposed_leasetime, &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_T1, DHCP_OPTION_T1_LEN, &options_len);
+ dhcp_common_option_long(srvr_msg, (client_lease->proposed_leasetime / 2), &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_T2, DHCP_OPTION_T2_LEN, &options_len);
+ /* calculate safe periods for lease (proposed_leasetime * 0.875 -> 87.5%) */
+ dhcp_common_option_long(srvr_msg, ((client_lease->proposed_leasetime * 7) / 8), &options_len);
+
+ /* No need to convert netmask into network order as it is already stored in network order */
+ dhcp_common_option(srvr_msg, DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_SUBNET_MASK_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip4_addr_get_u32(ip_2_ip4(&netif->netmask))), &options_len);
+
+ dhcp_common_option_trailer(srvr_msg, options_len, out_msg);
+
+ if (client_msg->ciaddr.addr != 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: sendto(OFFER, ciaddr, DHCP_CLIENT_PORT)\n"));
+ ip_addr_set_ip4_u32_val(dst_addr, (u32_t)(client_msg->ciaddr.addr));
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, &dst_addr, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+ }
+#if !LWIP_DHCPS_DISCOVER_BROADCAST
+ else if (ntohs(client_msg->flags) & DHCP_BROADCAST_FLAG) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_discover: sendto(OFFER, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT)\n"));
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+ } else {
+ client_ip.addr = htonl(client_ip.addr);
+
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: Updating ARP Static Entry for unicast reply\n"));
+ if (memcpy_s(ethaddr.addr, ETHARP_HWADDR_LEN, client_msg->chaddr, client_msg->hlen) != EOK) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("memcpy_s failed\n"));
+ (void)pbuf_free(out_msg);
+ return;
+ }
+ if (etharp_add_static_entry(&client_ip, ðaddr) != ERR_OK) {
+ (void)pbuf_free(out_msg);
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: Adding static entry to arp cache failed\n"));
+ return;
+ }
+#endif
+
+ /* Need to check and add an arp entry to make this pass through smoothly */
+ ip_addr_copy_from_ip4(client_ipaddr, client_ip);
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, &client_ipaddr, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ /* We just added the entry above and checked for it's success too. so, the below function call cannot fail */
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_discover: Removing ARP Static Entry added for unicast reply\n"));
+ (void)etharp_remove_static_entry(&client_ip);
+#endif
+ }
+#else
+ else {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_discover: sendto(OFFER, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT)\n"));
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+ }
+#endif
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: deleting()ing\n"));
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_discover: Sending Reply has been successful\n"));
+
+ (void)pbuf_free(out_msg);
+ return;
+}
+
+LWIP_STATIC ip4_addr_t validate_request_message(struct netif *netif, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease, ip4_addr_t serverid)
+{
+ struct dhcps *dhcps = netif_get_dhcps(netif);
+ ip4_addr_t requested_ip;
+ requested_ip.addr = 0;
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_request_message: Processing Request Message\n"));
+
+ if ((client_lease != NULL) && (client_lease->flags == DHCPS_ADDRESS_OFFERRED)) {
+ /* Now, we are in selecting state */
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_request_message: In Selecting State\n"));
+
+ if ((serverid.addr == 0) || (client_msg->ciaddr.addr != 0) ||
+ (!dhcps_option_given(dhcps, DHCP_OPTION_IDX_REQUESTED_IP))) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("Server ID or ciaddr or requested ip option is not present\n"));
+ return requested_ip;
+ }
+
+ if (serverid.addr != ip_2_ip4(&netif->ip_addr)->addr) {
+ /* This message is not meant for us. The client intends to talk to some other server */
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: Server id doesn't match with ours. Message not for us\n"));
+ requested_ip.addr = 1;
+ return requested_ip;
+ }
+
+ requested_ip.addr = (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_REQUESTED_IP);
+ } else {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: In Init-Reboot, Renew or Rebinding State\n"));
+
+ /* Now, we can be either in Init-reboot state or renew state or rebinding state */
+ if (dhcps_option_given(dhcps, DHCP_OPTION_IDX_REQUESTED_IP)) {
+ /* Requested IP option is filled in. Indicates we are mostly in Init-Reboot State */
+ if (client_lease == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: No Configuration found corresponding to request message\n"));
+ return requested_ip;
+ }
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: Requested IP Option is present. So, considering as Init-Reboot State\n"));
+
+ if (client_msg->ciaddr.addr != 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: Error: ciaddr is filled in the Init-Reboot state. \n"));
+ return requested_ip;
+ }
+
+ requested_ip.addr = (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_REQUESTED_IP);
+ } else {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_request_message: \
+ Requested IP Option is not present. So, considering as Renewing or Rebinding State\n"));
+
+ if (client_msg->ciaddr.addr == 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("validate_request_message: Error: ciaddr is not filled in the Renewing or Rebinding state. \n"));
+ return requested_ip;
+ }
+
+ requested_ip.addr = ntohl(client_msg->ciaddr.addr);
+ }
+ }
+
+ /* requested_ip is in host order and DHCP Server IP is in network order,
+ so converting the former to network order for check */
+ if (htonl(requested_ip.addr) == ip_2_ip4(&netif->ip_addr)->addr) {
+ /* This requested_ip is the dhcp server is using, it is invalid */
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("validate_request_message: Requested IP addr is invalid\n"));
+ requested_ip.addr = 1;
+ }
+
+ return requested_ip;
+}
+
+LWIP_STATIC void handle_request(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease, ip4_addr_t serverid)
+{
+ ip4_addr_t requested_ip;
+ struct pbuf *out_msg = NULL;
+ struct dhcp_msg *srvr_msg = NULL;
+ u16_t options_len = 0;
+ ip_addr_t dst_addr;
+ ip_addr_t ip_send;
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ struct eth_addr ethaddr;
+#endif
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: Processing Request Message\n"));
+
+ requested_ip = validate_request_message(netif, client_msg, client_lease, serverid);
+ if (requested_ip.addr == 1) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_request: Validation of request message failed. Dropping the packet.\n"));
+ return;
+ }
+
+ out_msg = dhcps_create_base_msg(client_msg);
+ if (out_msg == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: Creating base message failed\n"));
+ return;
+ }
+
+ srvr_msg = (struct dhcp_msg *)out_msg->payload;
+ dhcp_common_option(srvr_msg, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SERVER_ID_LEN, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip_2_ip4(&netif->ip_addr)->addr), &options_len);
+
+ /* hilink need this router option */
+ dhcp_common_option(srvr_msg, DHCP_OPTION_ROUTER, DHCP_OPTION_ROUTER_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip_2_ip4(&netif->ip_addr)->addr), &options_len);
+
+ if ((client_lease != NULL) && (client_lease->cli_addr.addr == requested_ip.addr)) {
+ if (client_lease->proposed_leasetime != (u32_t)(~0)) {
+ if (client_lease->flags == DHCPS_ADDRESS_OFFERRED) {
+ client_lease->leasetime = sys_now() + (client_lease->proposed_leasetime * 1000);
+ } else {
+ client_lease->leasetime += (client_lease->proposed_leasetime * 1000);
+ }
+ } else {
+ client_lease->leasetime = client_lease->proposed_leasetime;
+ }
+
+ client_lease->flags = DHCPS_ADDRESS_BOUND;
+ srvr_msg->yiaddr.addr = htonl(client_lease->cli_addr.addr);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
+ dhcp_common_option_byte(srvr_msg, DHCP_ACK, &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_LEASE_TIME_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, client_lease->proposed_leasetime, &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_T1, DHCP_OPTION_T1_LEN, &options_len);
+ dhcp_common_option_long(srvr_msg, (client_lease->proposed_leasetime / 2), &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_T2, DHCP_OPTION_T2_LEN, &options_len);
+ /* calculate safe periods for lease (proposed_leasetime * 0.875 -> 87.5%) */
+ dhcp_common_option_long(srvr_msg, ((client_lease->proposed_leasetime * 7) / 8), &options_len);
+
+ dhcp_common_option(srvr_msg, DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_SUBNET_MASK_SIZE, &options_len);
+ dhcp_common_option_long(srvr_msg, ntohl(ip_2_ip4(&netif->netmask)->addr), &options_len);
+
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_request: Send ACK. to=%"U32_F" lease time=%"U32_F"\n",
+ requested_ip.addr, client_lease->proposed_leasetime));
+#endif
+ } else {
+ dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
+ dhcp_common_option_byte(srvr_msg, DHCP_NAK, &options_len);
+
+ /* Just set this here, so that the NAK message is brcasted.
+ The correct flags has already been added in the respose message during base message creation */
+ client_msg->flags |= htons(DHCP_BROADCAST_FLAG);
+ client_msg->ciaddr.addr = 0; /* This is done so that NAK Gets brcasted */
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_request: Send NAK. Requested from=%"U32_F"\n", requested_ip.addr));
+#endif
+ }
+
+ requested_ip.addr = htonl(requested_ip.addr);
+ dhcp_common_option_trailer(srvr_msg, options_len, out_msg);
+
+ if (client_msg->ciaddr.addr != 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: sendto(ACK, ciaddr, DHCP_CLIENT_PORT)\n"));
+ ip_addr_set_ip4_u32_val(dst_addr, (u32_t)(client_msg->ciaddr.addr));
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, &dst_addr, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+ } else if (ntohs(client_msg->flags) & DHCP_BROADCAST_FLAG) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: sending reply using brdcast \n"));
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+ } else {
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: Updating ARP Static Entry for unicast reply\n"));
+ if (memcpy_s(ethaddr.addr, ETHARP_HWADDR_LEN, client_msg->chaddr, client_msg->hlen) != EOK) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: Copy chaddr failed\n"));
+ (void)pbuf_free(out_msg);
+ return;
+ }
+ if (ERR_OK != etharp_add_static_entry(&requested_ip, ðaddr)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: Adding static entry to arp cache failed\n"));
+ (void)pbuf_free(out_msg);
+ return;
+ }
+#endif
+ /* Need to check and add an arp entry to make this pass through smoothly */
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_request: sending reply using unicast Client IP =%"U32_F"\n", requested_ip.addr));
+#endif
+ ip_send.u_addr.ip4.addr = requested_ip.addr;
+ ip_send.type = IPADDR_TYPE_V4;
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, &ip_send, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+
+#if ETHARP_SUPPORT_STATIC_ENTRIES
+ /* We just added the entry above and checked for it's success too. so, the below function call cannot fail */
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_request: Removing ARP Static Entry added for unicast reply\n"));
+ (void)etharp_remove_static_entry(&requested_ip);
+#endif
+ }
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_request: deleting\n"));
+
+ (void)pbuf_free(out_msg);
+ return;
+}
+
+LWIP_STATIC void handle_decline(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg,
+ struct dyn_lease_addr *client_lease)
+{
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_decline: Processing Decline Message\n"));
+
+ if ((client_lease != NULL) && (dhcps_option_given(dhcps, DHCP_OPTION_IDX_REQUESTED_IP)) &&
+ (client_msg->ciaddr.addr == 0)) {
+ if (client_lease->cli_addr.addr == (u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_REQUESTED_IP)) {
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_decline: Marking Client Entry as declined. Client IP =%"U32_F"\n",
+ client_lease->cli_addr.addr));
+#endif
+ (void)memset_s(client_lease->cli_hwaddr, sizeof(client_lease->cli_hwaddr), 0, DHCP_CHADDR_LEN);
+ client_lease->proposed_leasetime = 0;
+ client_lease->leasetime = sys_now() + (LWIP_DHCPS_DECLINE_TIME * 1000);
+ client_lease->flags = DHCPS_ADDRESS_DECLINED;
+ }
+ }
+}
+
+LWIP_STATIC void handle_inform(struct netif *netif, struct dhcps *dhcps, struct dhcp_msg *client_msg)
+{
+ struct pbuf *out_msg = NULL;
+ struct dhcp_msg *srvr_msg = NULL;
+ u16_t options_len = 0;
+ ip_addr_t dst_addr;
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_inform: Processing Inform Message\n"));
+
+ if (client_msg->ciaddr.addr == 0) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_inform: ciaddr is empty. Can't send back a response\n"));
+ return;
+ }
+
+ out_msg = dhcps_create_base_msg(client_msg);
+ if (out_msg == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_inform: Creating base message failed\n"));
+ return;
+ }
+
+ srvr_msg = (struct dhcp_msg *)out_msg->payload;
+ dhcp_common_option(srvr_msg, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, &options_len);
+ dhcp_common_option_byte(srvr_msg, DHCP_ACK, &options_len);
+
+ dhcp_common_option_trailer(srvr_msg, options_len, out_msg);
+
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("handle_inform: Send ACK to Client. Client is=%"U32_F"\n", client_msg->ciaddr.addr));
+#endif
+ ip_addr_set_ip4_u32_val(dst_addr, client_msg->ciaddr.addr);
+ (void)udp_sendto_if_src(dhcps->pcb, out_msg, &dst_addr, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("handle_inform: deleting pbuf\n"));
+ (void)pbuf_free(out_msg);
+
+ return;
+}
+
+LWIP_STATIC void handle_client_messages(struct netif *netif, struct dhcps *dhcps,
+ struct dhcp_msg *client_msg, ip4_addr_t serverid, u8_t msg_type)
+{
+ struct dyn_lease_addr *client_lease = NULL;
+
+ client_lease = find_client_lease(dhcps, client_msg);
+ switch (msg_type) {
+ case DHCP_DISCOVER:
+ handle_discover(netif, dhcps, client_msg, client_lease);
+ break;
+ case DHCP_REQUEST:
+ handle_request(netif, dhcps, client_msg, client_lease, serverid);
+ break;
+ case DHCP_DECLINE:
+ handle_decline(netif, dhcps, client_msg, client_lease);
+ break;
+ case DHCP_RELEASE:
+ if ((client_lease != NULL) && (client_lease->cli_addr.addr == ntohl(client_msg->ciaddr.addr))) {
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("DHCP Release: Client IPAdd =%"U32_F"\n", client_msg->ciaddr.addr));
+#endif
+ (void)memset_s(client_lease, sizeof(struct dyn_lease_addr), 0, sizeof(struct dyn_lease_addr));
+ client_lease->flags = DHCPS_ADDRESS_FREE;
+ }
+ break;
+ case DHCP_INFORM:
+ handle_inform(netif, dhcps, client_msg);
+ break;
+ default:
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP Server. Invalid message type received %d\n", msg_type));
+ }
+}
+
+err_t dhcps_parse_options(struct pbuf *p, struct dhcps *dhcps)
+{
+ return dhcp_parse_reply(p, &dhcps->dhcp);
+}
+
+LWIP_STATIC void dhcps_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *ip_addr, u16_t port)
+{
+ struct netif *netif = (struct netif *)arg;
+ struct dhcps *dhcps = netif_get_dhcps(netif);
+ struct dhcp_msg *client_msg = (struct dhcp_msg *)p->payload;
+ u8_t msg_type;
+ ip4_addr_t serverid;
+ ip4_addr_t addr;
+
+ if (client_msg == NULL) {
+ return;
+ }
+ addr.addr = ip_addr->u_addr.ip4.addr;
+ serverid.addr = 0;
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("dhcps_recv(pbuf = %p) from DHCP Client %"U16_F".%"U16_F".%"U16_F".%"U16_F" port %"U16_F"\n", (void*)p,
+ ip4_addr1_16(&addr), ip4_addr2_16(&addr), ip4_addr3_16(&addr), ip4_addr4_16(&addr), port));
+#endif
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->len = %"U16_F"\n", p->len));
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->tot_len = %"U16_F"\n", p->tot_len));
+ /* prevent warnings about unused arguments */
+ LWIP_UNUSED_ARG(pcb);
+ LWIP_UNUSED_ARG(addr);
+ LWIP_UNUSED_ARG(port);
+
+ dhcps_clear_all_options(dhcps);
+
+ /* Check and remove old entries on each call to dhcp_recv. This way, we don't need to maintain timers */
+ remove_stale_entries(dhcps);
+
+ if (p->len < DHCP_OPTIONS_OFS) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP client message or pbuf too short. pbuf len =%"U16_F" DHCP MIN Reply Len = %"U32_F"\n",
+ p->len, DHCP_MIN_REPLY_LEN));
+ goto free_pbuf_and_return;
+ }
+
+ if (client_msg->op != DHCP_BOOTREQUEST) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("Not a DHCP reply message, Type %"U16_F"\n", (u16_t)client_msg->op));
+ goto free_pbuf_and_return;
+ }
+
+ if (client_msg->cookie != PP_HTONL(DHCP_MAGIC_COOKIE)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP Server. Cookie Value is incorrect. %"U32_F"\n", (u32_t)client_msg->cookie));
+ goto free_pbuf_and_return;
+ }
+
+ if (client_msg->hlen != ETHARP_HWADDR_LEN) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP Server. Invalid hardware address length %"U16_F"\n", (u16_t)client_msg->hlen));
+ goto free_pbuf_and_return;
+ }
+
+ if (dhcps_parse_options(p, dhcps) != ERR_OK) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("Parsing of Options failed in DHCP Client Message\n"));
+ goto free_pbuf_and_return;
+ }
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("Searching DHCP_OPTION_MESSAGE_TYPE\n"));
+ /* obtain pointer to DHCP message type */
+ if (!dhcps_option_given(dhcps, DHCP_OPTION_IDX_MSG_TYPE)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP_OPTION_MESSAGE_TYPE option not found\n"));
+ goto free_pbuf_and_return;
+ }
+
+ /* read DHCP message type */
+ msg_type = (u8_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_MSG_TYPE);
+
+ if (dhcps_option_given(dhcps, DHCP_OPTION_IDX_SERVER_ID)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("DHCP_OPTION_SERVER_ID option found\n"));
+ /* Parse options would have changed it to host order. But, we have our IP stored in netif in network order */
+ serverid.addr = htonl((u32_t)dhcps_get_option_value(dhcps, DHCP_OPTION_IDX_SERVER_ID));
+ }
+
+ if ((serverid.addr != 0) && ((msg_type == DHCP_DISCOVER) || (msg_type == DHCP_INFORM))) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("Serverid present in DHCP_DISCOVER and DHCP_INFORM messages\n"));
+ goto free_pbuf_and_return;
+ }
+
+ if ((!ip4_addr_cmp(&serverid, ip_2_ip4(&netif->ip_addr))) &&
+ ((msg_type == DHCP_DECLINE) || (msg_type == DHCP_RELEASE))) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
+ ("Serverid not present in DHCP_RELEASE and DHCP_DECLINE messages\n"));
+ goto free_pbuf_and_return;
+ }
+
+ handle_client_messages(netif, dhcps, client_msg, serverid, msg_type);
+
+free_pbuf_and_return:
+ (void)pbuf_free(p);
+}
+
+err_t dhcps_start(struct netif *netif, const char *start_ip, u16_t ip_num)
+{
+ struct dhcps *dhcps = NULL;
+ ip4_addr_t address_in_hton;
+ int err;
+
+ LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
+ dhcps = netif_get_dhcps(netif);
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
+ ("dhcps_start(netif=%p) %s\n", (void *)netif, netif_get_name(netif)));
+
+ if (netif->mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("MTU =%"U16_F",DHCP Msg Len Required =%"U32_F"\n", netif->mtu, DHCP_MAX_MSG_LEN_MIN_REQUIRED));
+ return ERR_MEM;
+ }
+
+ if (dhcps != NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_start(): DHCP Server is already started\n"));
+ return ERR_MEM;
+ }
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_start(): starting new DHCP Server\n"));
+ dhcps = (struct dhcps *)mem_malloc(sizeof(struct dhcps));
+ if (dhcps == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_start(): could not allocate dhcp\n"));
+ return ERR_MEM;
+ }
+
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_start(): allocated dhcp"));
+
+ (void)memset_s(dhcps, sizeof(struct dhcps), 0, sizeof(struct dhcps));
+
+ dhcps->pcb = udp_new();
+ if (dhcps->pcb == NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): could not allocate pcb\n"));
+ mem_free((void *)dhcps);
+ return ERR_MEM;
+ }
+
+#if LWIP_SO_BINDTODEVICE
+ /* bind dhcp udp_pcb to specific netif, this could make dhcp server start on multiple netif */
+ dhcps->pcb->ifindex = netif->ifindex;
+#endif
+ if ((start_ip == NULL) || (ip_num == 0)) {
+ /* use default ip lease configuration. */
+ dhcps->start_addr.addr = ntohl(ip_2_ip4(&netif->ip_addr)->addr & ip_2_ip4(&netif->netmask)->addr) + 1;
+ dhcps->end_addr.addr = ntohl(ip_2_ip4(&netif->ip_addr)->addr | (~ip_2_ip4(&netif->netmask)->addr)) - 1;
+ dhcps->lease_num = (u8_t)(dhcps->end_addr.addr - dhcps->start_addr.addr + 1);
+ if (dhcps->lease_num > LWIP_DHCPS_MAX_LEASE) {
+ dhcps->lease_num = LWIP_DHCPS_MAX_LEASE;
+ dhcps->end_addr.addr = dhcps->start_addr.addr + LWIP_DHCPS_MAX_LEASE - 1;
+ }
+ } else {
+ dhcps->start_addr.addr = ntohl(ipaddr_addr(start_ip));
+ dhcps->end_addr.addr = (u32_t)(dhcps->start_addr.addr +
+ (u32_t)(LWIP_MIN(ip_num - 1, LWIP_DHCPS_MAX_LEASE - 1)));
+
+ ip4_addr_set_hton(&address_in_hton, &dhcps->start_addr);
+
+ if (!ip4_addr_netcmp((&address_in_hton), ip_2_ip4(&netif->ip_addr), ip_2_ip4(&netif->netmask)) ||
+ ip4_addr_isbroadcast((&address_in_hton), netif)) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): %s in not a valid ip lease\n", start_ip));
+ udp_remove(dhcps->pcb);
+ mem_free((void *)dhcps);
+ return ERR_ARG;
+ }
+
+ ip4_addr_set_hton(&address_in_hton, &dhcps->end_addr);
+
+ if (!ip4_addr_netcmp((&address_in_hton), ip_2_ip4(&netif->ip_addr), ip_2_ip4(&netif->netmask)) ||
+ ip4_addr_isbroadcast((&address_in_hton), netif)) {
+ dhcps->end_addr.addr = ntohl(ip_2_ip4(&netif->ip_addr)->addr | (~ip_2_ip4(&netif->netmask)->addr)) - 1;
+ }
+ dhcps->lease_num = (u8_t)(dhcps->end_addr.addr - dhcps->start_addr.addr + 1);
+ }
+
+ dhcps->netif = netif;
+ dhcps->pcb->so_options |= SOF_BROADCAST;
+ err = udp_bind(dhcps->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT);
+ if (err != ERR_OK) {
+ udp_remove(dhcps->pcb);
+ mem_free((void *)dhcps);
+ return ERR_MEM;
+ }
+
+ err = udp_connect(dhcps->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
+ if (err != ERR_OK) {
+ udp_remove(dhcps->pcb);
+ mem_free((void *)dhcps);
+ return ERR_MEM;
+ }
+ udp_recv(dhcps->pcb, dhcps_recv, netif);
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_start(): starting DHCPS Successfully\n"));
+#ifdef LWIP_DEV_DEBUG
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("dhcps_start(): DHCPS Conf:: netif addr = %"U32_F" dhcps start addr%"U32_F" dhcp end addr%"U32_F"\n",
+ ip_2_ip4(&netif->ip_addr)->addr, dhcps->start_addr.addr, dhcps->end_addr.addr));
+#endif
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
+ ("dhcps_start(): DHCPS Lease Conf:: Lease Time = %"U32_F" Offer Time = %"U32_F"\n",
+ LWIP_DHCPS_LEASE_TIME, LWIP_DHCPS_OFFER_TIME));
+ netif_set_dhcps(netif, dhcps);
+ return ERR_OK;
+}
+
+void dhcps_stop(struct netif *netif)
+{
+ LWIP_ERROR("dhcps_stop: netif != NULL", (netif != NULL), return);
+ struct dhcps *dhcps = netif_get_dhcps(netif);
+ if (dhcps != NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_stop(): Stopping DHCP Server\n"));
+ if (dhcps->pcb != NULL) {
+ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcps_stop(): Removing UDP PCB\n"));
+ udp_remove(dhcps->pcb);
+ dhcps->pcb = NULL;
+ }
+
+ mem_free(dhcps);
+ netif_set_dhcps(netif, NULL);
+ }
+}
+
+#endif
+
diff --git a/net/lwip-2.1/enhancement/src/api_shell_fix.c b/net/lwip-2.1/enhancement/src/fixme.c
old mode 100755
new mode 100644
similarity index 67%
rename from net/lwip-2.1/enhancement/src/api_shell_fix.c
rename to net/lwip-2.1/enhancement/src/fixme.c
index 56ab3e5f72994e4278986c54e41aaa45040819e4..5bb6c3f768a836855c36034968e232febc22c3d2
--- a/net/lwip-2.1/enhancement/src/api_shell_fix.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:
@@ -29,46 +29,26 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "api_shell_fix.h"
-
-#include
+#include "lwip/fixme.h"
#include
#include
#include
#include
-#include
#include
-#include "securec.h"
-
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
-
-/**
- *
- *
- * ################# FOR API_SHELL ONLY #################
- *
- *
- *
- */
-
-
-#if LWIP_ENABLE_LOS_SHELL_CMD
-
#if LWIP_DHCP
#include
/*
* Close DHCP and set static network.
- *
* @param netif a pre-allocated netif structure
- *
* @return ERR_OK, or ERR_VAL if failed.
*/
err_t netif_dhcp_off(struct netif *netif)
@@ -85,32 +65,48 @@ err_t netif_dhcp_off(struct netif *netif)
old_gateway = netif->gw;
if (netif_dhcp_data(netif)) {
- (void) dhcp_release(netif);
- (void) dhcp_stop(netif);
- (void) dhcp_cleanup(netif);
+ (void)dhcp_release(netif);
+ (void)dhcp_stop(netif);
+ (void)dhcp_cleanup(netif);
LWIP_DEBUGF(NETIF_DEBUG, ("DHCP is close;set static IP\n"));
}
ip_addr_set_val(&netif->ip_addr, &old_ipaddr);
ip_addr_set_val(&netif->netmask, &old_netmask);
ip_addr_set_val(&netif->gw, &old_gateway);
- (void) netif_set_up(netif);
+ (void)netif_set_up(netif);
return ERR_OK;
}
+err_t dhcp_is_bound(struct netif *netif)
+{
+ struct dhcp *dhcp = NULL;
+
+ LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
+
+ dhcp = netif_dhcp_data(netif);
+ LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG);
+
+ if (dhcp->state == DHCP_STATE_BOUND) {
+ return ERR_OK;
+ } else {
+ return ERR_INPROGRESS;
+ }
+}
+
#endif /* LWIP_DHCP */
#if LWIP_DHCPS
-#include "dhcps.h"
+#include "lwip/dhcps.h"
-static err_t netifapi_do_dhcps_start (struct tcpip_api_call_data *m)
+static err_t netifapi_do_dhcps_start(struct tcpip_api_call_data *m)
{
/* cast through void* to silence alignment warnings.
* We know it works because the structs have been instantiated as struct netifapi_msg */
err_t ret;
- struct netifapi_msg *msg = (struct netifapi_msg*)(void*)m;
+ struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
ret = dhcps_start(msg->netif, msg->msg.dhcp_start_params.start_ip, msg->msg.dhcp_start_params.ip_num);
return ret;
}
@@ -124,8 +120,8 @@ err_t netifapi_dhcps_start(struct netif *netif, char *start_ip, u16_t ip_num)
NETIFAPI_VAR_ALLOC(msg);
NETIFAPI_VAR_REF(msg).netif = netif;
- NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.start_ip = start_ip ;
- NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.ip_num = ip_num ;
+ NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.start_ip = start_ip;
+ NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.ip_num = ip_num;
err = tcpip_api_call(netifapi_do_dhcps_start, &API_VAR_REF(msg).call);
@@ -216,19 +212,19 @@ static struct netif *netif_find_by_name(const char *name)
return NULL;
}
- if (strcmp("lo", name) == 0) {
- LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
- return netif_find(name);
- }
-
NETIF_FOREACH(netif) {
+ if (strcmp("lo", name) == 0 && (netif->name[0] == 'l' && netif->name[1] == 'o')) {
+ LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found lo\n"));
+ return netif;
+ }
+
if (strcmp(netif->full_name, name) == 0) {
- LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
+ LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found %s\n", name));
return netif;
}
}
- LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
+ LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: didn't find %s\n", name));
return NULL;
}
@@ -294,7 +290,7 @@ err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu)
#endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif: MTU of interface %s is changed to %d\n",
- netif_get_name(netif), netif->mtu));
+ netif_get_name(netif), netif->mtu));
return ERR_OK;
}
@@ -322,31 +318,35 @@ err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
("netif: HW address of interface %s set to %02X:%02X:%02X:%02X:%02X:%02X\n",
- netif_get_name(netif),
- netif->hwaddr[0], netif->hwaddr[1], netif->hwaddr[2],
- netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]));
+ netif_get_name(netif),
+ netif->hwaddr[0], netif->hwaddr[1], netif->hwaddr[2],
+ netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]));
return ERR_OK;
}
err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
{
+ // FIXME
return 0;
}
err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr)
{
+ // FIXME
return 0;
}
err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
{
+ // FIXME
return 0;
}
err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver)
{
+ // FIXME
return 0;
}
@@ -354,57 +354,124 @@ err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver)
struct raw_pcb *pkt_raw_pcbs;
#endif
-struct raw_pcb *raw_pcbs;
-
+#if LWIP_RAW
+struct raw_pcb *raw_pcbs; /* already defined in raw.c, but is static */
+#endif
-/******************************************************************/
#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
u32_t is_ip_conflict_signal = 0;
sys_sem_t ip_conflict_detect;
#endif
-
u32_t is_dup_detect_initialized = 0;
sys_sem_t dup_addr_detect;
-int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time)
-{
- return 0;
-}
+#if LWIP_SNTP
-u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
- u16_t usTftpServPort,
- u8_t ucTftpTransMode,
- s8_t *szSrcFileName,
- s8_t *szDestDirPath)
-{
- return 0;
-}
+#include
-u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr,
- u16_t usTftpServPort,
- u8_t cTftpTransMode,
- s8_t *szSrcFileName,
- s8_t *szDestDirPath)
+int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time)
{
+ // FIXME
return 0;
}
+#endif
const char *const tcp_state_str[] = {
- "CLOSED",
- "LISTEN",
- "SYN_SENT",
- "SYN_RCVD",
- "ESTABLISHED",
- "FIN_WAIT_1",
- "FIN_WAIT_2",
- "CLOSE_WAIT",
- "CLOSING",
- "LAST_ACK",
- "TIME_WAIT"
+ "CLOSED",
+ "LISTEN",
+ "SYN_SENT",
+ "SYN_RCVD",
+ "ESTABLISHED",
+ "FIN_WAIT_1",
+ "FIN_WAIT_2",
+ "CLOSE_WAIT",
+ "CLOSING",
+ "LAST_ACK",
+ "TIME_WAIT"
};
volatile int tcpip_init_finish = 1; // needed by api_shell.c
-#endif
+int ip6addr_aton(const char *cp, ip6_addr_t *addr)
+{
+ const int ipv6_blocks = 8;
+ u16_t current_block_index = 0;
+ u16_t current_block_value = 0;
+ u16_t addr16[ipv6_blocks];
+ u16_t *a16 = (u16_t *)addr->addr;
+ int squash_pos = ipv6_blocks;
+ int i;
+ const char *s = cp;
+ const char *ss = cp-1;
+
+ for (; ; s++) {
+ if (current_block_index >= ipv6_blocks) {
+ return 0; // address too long
+ }
+ if (*s == 0) {
+ if (s - ss == 1) {
+ if (squash_pos != current_block_index) {
+ return 0; // empty address or address ends with a single ':'
+ } // else address ends with one valid "::"
+ } else {
+ addr16[current_block_index++] = current_block_value;
+ }
+ break;
+ } else if (*s == ':') {
+ if (s - ss == 1) {
+ if (s != cp || s[1] != ':') {
+ return 0; // address begins with a single ':' or contains ":::"
+ } // else address begins with one valid "::"
+ } else {
+ addr16[current_block_index++] = current_block_value;
+ }
+ if (s[1] == ':') {
+ if (squash_pos != ipv6_blocks) {
+ return 0; // more than one "::"
+ }
+ squash_pos = current_block_index;
+ s++;
+ }
+ ss = s; // ss points to the recent ':' position
+ current_block_value = 0;
+ } else if (lwip_isxdigit(*s) && (s - ss) < 5) { // 4 hex-digits at most
+ current_block_value = (current_block_value << 4) +
+ ((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;
+ int ret = ip4addr_aton(ss+1, &ip4);
+ if (!ret) {
+ return 0;
+ }
+ ip4.addr = lwip_ntohl(ip4.addr);
+ addr16[current_block_index++] = (u16_t)(ip4.addr >> 16);
+ addr16[current_block_index++] = (u16_t)(ip4.addr);
+ break;
+#endif /* LWIP_IPV4 */
+ } else {
+ return 0; // unexpected char or too many digits
+ }
+ }
+
+ if (squash_pos == ipv6_blocks && current_block_index != ipv6_blocks) {
+ return 0; // address too short
+ }
+ if (squash_pos != ipv6_blocks && current_block_index == ipv6_blocks) {
+ return 0; // unexpected "::" in address
+ }
+
+ for (i = 0; i < squash_pos; ++i) {
+ a16[i] = lwip_htons(addr16[i]);
+ }
+ for (; i < ipv6_blocks - current_block_index + squash_pos; ++i) {
+ a16[i] = 0;
+ }
+ for (; i < ipv6_blocks; ++i) {
+ a16[i] = lwip_htons(addr16[i - ipv6_blocks + current_block_index]);
+ }
+
+ return 1;
+}
diff --git a/net/lwip-2.1/porting/include/arch/cc.h b/net/lwip-2.1/porting/include/arch/cc.h
old mode 100755
new mode 100644
index 44846c7d51520ca4c98a32af30aea50e91b92247..9dd49830b624a222b45cd3750606825781e49f10
--- 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
old mode 100755
new mode 100644
index 4c510336a36f3b2477375344343db32e9383b199..dea6a6946fd0fcef33caa75031a8893d794011a4
--- 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
old mode 100755
new mode 100644
index 798fdecda71f5f180862dd4f177709a57ad3bfb0..19e76beeb15719559ae6c3e6a582542e9277f79a
--- 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
old mode 100755
new mode 100644
index 54938fb922a5fd90162cb61721df2e3c9f6d283d..59b52e707462a8495588a66c96603ed361ca0cfe
--- 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:
@@ -32,13 +32,32 @@
#ifndef _LWIP_PORTING_DHCP_H_
#define _LWIP_PORTING_DHCP_H_
+#include
+
+#if LWIP_DHCPS
+#define DHCP_OPTION_IDX_SERVER_ID DHCP_OPTION_IDX_SERVER_ID, \
+ DHCP_OPTION_IDX_REQUESTED_IP
+#endif
#include_next
+#if LWIP_DHCPS
+#undef DHCP_OPTION_IDX_SERVER_ID
+#endif
+
#include // For DHCP_STATE_BOUND, DHCP_DISCOVER etc. by `mac/common/mac_data.c'
#ifdef __cplusplus
extern "C" {
#endif
+#if LWIP_DHCPS
+#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) \
+ LWIP_UNUSED_ARG(msg); \
+ break; \
+ case (DHCP_OPTION_REQUESTED_IP): \
+ LWIP_ERROR("len == 4", len == 4, return ERR_VAL); \
+ decode_idx = DHCP_OPTION_IDX_REQUESTED_IP;
+#endif
+
err_t dhcp_is_bound(struct netif *netif);
#ifdef __cplusplus
diff --git a/net/lwip-2.1/porting/include/lwip/inet.h b/net/lwip-2.1/porting/include/lwip/inet.h
old mode 100755
new mode 100644
index 0f833f7bc750ed11a108eb282b180f4db0bb2728..414b6bc68729accc9489cb7f55def6cb238419ab
--- 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
index 8d446171526137daa2ab799c07766affef0af3f0..3656f696c989b85bc1e1d798712d15ae2c3ee807 100755
--- 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:
@@ -32,6 +32,7 @@
#ifndef _LWIP_PORTING_LWIPOPTS_H_
#define _LWIP_PORTING_LWIPOPTS_H_
+#include "menuconfig.h"
// lwIP debug options, comment the ones you don't want
#if LWIP_DEBUG
@@ -215,7 +216,10 @@
#define LWIP_CONFIG_NUM_SOCKETS 128
#define IP_REASS_MAX_MEM_SIZE (MEM_SIZE / 4)
+// Options for enhancement code, same for old lwipopts.h
+#define LWIP_NETIF_PROMISC 1
#define LWIP_DHCPS 1
#define LWIP_ENABLE_NET_CAPABILITY 1
+#define LWIP_ENABLE_CAP_NET_BROADCAST 0
#endif /* _LWIP_PORTING_LWIPOPTS_H_ */
diff --git a/net/lwip-2.1/porting/include/lwip/netif.h b/net/lwip-2.1/porting/include/lwip/netif.h
old mode 100755
new mode 100644
index 51a5fbf3939560233c8cd312e9a2450ba7f8ffb8..2633cd71f86d8000f71338fa6cfc4c61ddbaed5d
--- 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:
@@ -35,16 +35,23 @@
#include // For IFNAMSIZ/IF_NAMESIZE and `struct ifreq', by `lwip/netif.h' and `api/sockets.c'
#include // For IP_OFFMASK, by `core/ipv4/ip4_frag.c'
-struct dhcps;
+#define netif_find netifapi_netif_find_by_name
+
+#if LWIP_DHCPS
+#define LWIP_NETIF_CLIENT_DATA_INDEX_DHCP LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, \
+ LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS
+#endif
#define linkoutput linkoutput; \
void (*drv_send)(struct netif *netif, struct pbuf *p); \
u8_t (*drv_set_hwaddr)(struct netif *netif, u8_t *addr, u8_t len); \
void (*drv_config)(struct netif *netif, u32_t config_flags, u8_t setBit); \
- struct dhcps *dhcps; \
char full_name[IFNAMSIZ]; \
u16_t link_layer_type
#include_next
#undef linkoutput
+#if LWIP_DHCPS
+#undef LWIP_NETIF_CLIENT_DATA_INDEX_DHCP
+#endif
#include // For ETHARP_HWADDR_LEN, by `hieth-sf src/interface.c' and `wal/wal_net.c'
@@ -64,9 +71,7 @@ err_t driverif_init(struct netif *netif);
void driverif_input(struct netif *netif, struct pbuf *p);
#ifndef __LWIP__
-struct netif *netifapi_netif_find_by_name(const char *name);
-#define PF_PKT_SUPPORT 1 // For netif->drv_config
-#define netif_find(name) netifapi_netif_find_by_name(name)
+#define PF_PKT_SUPPORT LWIP_NETIF_PROMISC
#define netif_add(a, b, c, d) netif_add(a, b, c, d, (a)->state, driverif_init, tcpip_input)
#else /* __LWIP__ */
#define netif_get_name(netif) ((netif)->full_name)
diff --git a/net/lwip-2.1/porting/include/lwip/netifapi.h b/net/lwip-2.1/porting/include/lwip/netifapi.h
old mode 100755
new mode 100644
index e88c78f09e16fdfccd4f70c1d1b2e11f5fd685eb..4bfcc8350a54715ae6a5b3c883dba577da0a12b8
--- 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:
@@ -45,6 +45,7 @@ err_t netifapi_dhcps_stop(struct netif *netif);
#define netifapi_dhcp_is_bound(n) netifapi_netif_common(n, NULL, dhcp_is_bound)
void netifapi_netif_rmv_ip6_address(struct netif *netif, ip_addr_t *ipaddr);
+struct netif *netifapi_netif_find_by_name(const char *name);
#ifndef __LWIP__
#define netifapi_netif_add(a, b, c, d) netifapi_netif_add(a, b, c, d, (a)->state, driverif_init, tcpip_input)
diff --git a/net/lwip-2.1/porting/include/lwip/pbuf.h b/net/lwip-2.1/porting/include/lwip/pbuf.h
old mode 100755
new mode 100644
index c7915a35350c39e7f0329226678148ce542720d3..79968178f7149baa05b4314e3eb7359ab2f96711
--- 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
old mode 100755
new mode 100644
index 3492b0461e1f3b1dc5ee137e584fcec7b1f72a97..573aac6b7b4a3363f9fc9c12cc7c56f4eaa25c37
--- 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
old mode 100755
new mode 100644
index e96bd93533b1a6d9249072160112d0c834d0a1e5..dfab001ef7fcb75b9eea5a2cc5b49b01df5e513d
--- 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
old mode 100755
new mode 100644
index 30a5a7d866700a852cd437cb86f2d9538929311c..af3dcb25ce4b7d08dc3d729df2a79a2e978556d4
--- 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
old mode 100755
new mode 100644
index 2e24ce6eff04fcea75901357796422518a7796a3..5a2d3545b0310ab7cd5ffb6e490d5be6291c8f49
--- 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
old mode 100755
new mode 100644
index 6eb5201d718880b15034a9c15073d0cc96f7c59e..ed23383827c320d903983d23b5fd525c01d8045e
--- 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:
@@ -44,7 +44,6 @@
#define link_rx_drop cachehit
#define link_rx_overrun cachehit
-#define NETIF_NAME_LEN 2
#define LWIP_STATIC static
#ifndef LWIP_NETIF_IFINDEX_MAX_EX
@@ -57,6 +56,9 @@ driverif_init_ifname(struct netif *netif)
struct netif *tmpnetif = NULL;
const char *prefix = (netif->link_layer_type == WIFI_DRIVER_IF) ? "wlan" : "eth";
+ netif->name[0] = prefix[0];
+ netif->name[1] = prefix[1];
+
for (int i = 0; i < LWIP_NETIF_IFINDEX_MAX_EX; ++i) {
if (snprintf_s(netif->full_name, sizeof(netif->full_name), sizeof(netif->full_name) - 1,
"%s%d", prefix, i) < 0) {
@@ -140,7 +142,7 @@ driverif_input(struct netif *netif, struct pbuf *p)
#endif
#else
u16_t ethhdr_type;
- struct eth_hdr* ethhdr = NULL;
+ struct eth_hdr *ethhdr = NULL;
#endif
err_t ret = ERR_VAL;
@@ -241,7 +243,6 @@ err_t
driverif_init(struct netif *netif)
{
u16_t link_layer_type;
- err_t ret;
if (netif == NULL) {
return ERR_IF;
@@ -262,17 +263,7 @@ driverif_init(struct netif *netif)
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
-#if LOSCFG_NET_LWIP_SACK_2_0
- if (strncpy_s(netif->hostname, NETIF_HOSTNAME_MAX_LEN,
- LWIP_NETIF_HOSTNAME_DEFAULT, NETIF_HOSTNAME_MAX_LEN - 1) == EOK) {
- netif->hostname[NETIF_HOSTNAME_MAX_LEN - 1] = '\0';
- } else {
- LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_init: hostname %s in invalid\n", LWIP_NETIF_HOSTNAME_DEFAULT));
- netif->hostname[0] = '\0';
- }
-#else
netif->hostname = LWIP_NETIF_HOSTNAME_DEFAULT;
-#endif
#endif /* LWIP_NETIF_HOSTNAME */
/*
@@ -285,21 +276,6 @@ driverif_init(struct netif *netif)
netif->output = etharp_output;
netif->linkoutput = driverif_output;
- if (link_layer_type == ETHERNET_DRIVER_IF) {
- ret = memcpy_s(netif->name, sizeof(netif->name), "et", NETIF_NAME_LEN);
- } else {
- ret = memcpy_s(netif->name, sizeof(netif->name), "wl", NETIF_NAME_LEN);
- }
- if (ret != EOK) {
-#if LWIP_NETIF_HOSTNAME
-#if LOSCFG_NET_LWIP_SACK_2_0
- netif->hostname[0] = '\0';
-#else
- netif->hostname = NULL;
-#endif
-#endif
- return ERR_IF;
- }
/* init the netif's full name */
driverif_init_ifname(netif);
@@ -309,30 +285,30 @@ driverif_init(struct netif *netif)
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
-#if DRIVER_STATUS_CHECK
- NETIF_FLAG_DRIVER_RDY |
-#endif
-#if LWIP_IGMP
- NETIF_FLAG_IGMP |
-#endif
-
-/**
-@page RFC-2710 RFC-2710
-@par Compliant Sections
-Section 5. Node State Transition Diagram
-@par Behavior Description
-MLD messages are sent for multicast addresses whose scope is 2
-(link-local), including Solicited-Node multicast addresses.\n
-Behavior:Stack will send MLD6 report /Done to solicited node multicast address
-if the LWIP_MLD6_ENABLE_MLD_ON_DAD is enabled. By default, this is disabled.
-*/
-/* Enable sending MLD report /done for solicited address during neighbour discovery */
-#if LWIP_IPV6 && LWIP_IPV6_MLD
-#if LWIP_MLD6_ENABLE_MLD_ON_DAD
- NETIF_FLAG_MLD6 |
-#endif /* LWIP_MLD6_ENABLE_MLD_ON_DAD */
-#endif
- NETIF_FLAG_LINK_UP;
+ #if DRIVER_STATUS_CHECK
+ NETIF_FLAG_DRIVER_RDY |
+ #endif
+ #if LWIP_IGMP
+ NETIF_FLAG_IGMP |
+ #endif
+
+ /**
+ @page RFC-2710 RFC-2710
+ @par Compliant Sections
+ Section 5. Node State Transition Diagram
+ @par Behavior Description
+ MLD messages are sent for multicast addresses whose scope is 2
+ (link-local), including Solicited-Node multicast addresses.\n
+ Behavior:Stack will send MLD6 report /Done to solicited node multicast address
+ if the LWIP_MLD6_ENABLE_MLD_ON_DAD is enabled. By default, this is disabled.
+ */
+ /* Enable sending MLD report /done for solicited address during neighbour discovery */
+ #if LWIP_IPV6 && LWIP_IPV6_MLD
+ #if LWIP_MLD6_ENABLE_MLD_ON_DAD
+ NETIF_FLAG_MLD6 |
+ #endif /* LWIP_MLD6_ENABLE_MLD_ON_DAD */
+ #endif
+ NETIF_FLAG_LINK_UP;
#if DRIVER_STATUS_CHECK
netif->waketime = -1;
diff --git a/net/lwip-2.1/porting/src/sockets.c b/net/lwip-2.1/porting/src/sockets.c
index 29f25598f6b2bd4df3262d039bd893ac0ab4eea3..95cfa0bfe92d82bcfa75d80d0700083f0425d6c9 100755
--- 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:
@@ -31,7 +31,7 @@
#include
#include
-#include
+#include
#if LWIP_ENABLE_NET_CAPABILITY
#include "capability_type.h"
@@ -39,8 +39,6 @@
#define BIND_SERVICE_CAP_MIN_PORT 1024
#endif
-#define netif_find netifapi_netif_find_by_name
-
#define IOCTL_CMD_CASE_HANDLER() \
{ \
err_t err; \
@@ -86,7 +84,8 @@ int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
return lwip_bind_wrap(s, name, namelen);
}
-static ssize_t lwip_sendto_wrap(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen);
+static ssize_t lwip_sendto_wrap(int s, const void *dataptr, size_t size, int flags,
+ const struct sockaddr *to, socklen_t tolen);
ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
{
return lwip_sendto_wrap(s, dataptr, size, flags, to, tolen);
@@ -143,12 +142,14 @@ static int lwip_setsockopt_wrap(int s, int level, int optname, const void *optva
#if LWIP_ENABLE_NET_CAPABILITY
if (level == SOL_SOCKET) {
switch (optname) {
+#if LWIP_ENABLE_CAP_NET_BROADCAST
case SO_BROADCAST:
if (!IsCapPermit(CAP_NET_BROADCAST)) {
set_errno(EPERM);
return -1;
}
break;
+#endif
case SO_DEBUG:
case SO_MARK:
case SO_PRIORITY:
@@ -167,7 +168,7 @@ static int lwip_setsockopt_wrap(int s, int level, int optname, const void *optva
return lwip_setsockopt2(s, level, optname, optval, optlen);
}
-#if LWIP_ENABLE_NET_CAPABILITY
+#if LWIP_ENABLE_NET_CAPABILITY && LWIP_ENABLE_CAP_NET_BROADCAST
static int ip_addr_isbroadcast_bysock(const ip_addr_t *ipaddr, int s)
{
struct sockaddr sa;
@@ -216,16 +217,12 @@ static int lwip_bind_wrap(int s, const struct sockaddr *name, socklen_t namelen)
LWIP_ERROR("permission deny: NET_BIND_SERVICE\n", IsCapPermit(CAP_NET_BIND_SERVICE),
set_errno(EPERM); return -1);
}
- if (ip_addr_isany(&ipaddr)) {
- LWIP_ERROR("permission deny: NET_RAW\n", IsCapPermit(CAP_NET_RAW),
- set_errno(EPERM); return -1);
- LWIP_ERROR("permission deny: NET_ADMIN\n", IsCapPermit(CAP_NET_ADMIN),
- set_errno(EPERM); return -1);
- }
+#if LWIP_ENABLE_CAP_NET_BROADCAST
if (ip_addr_ismulticast(&ipaddr) || ip_addr_isbroadcast_bysock(&ipaddr, s)) {
LWIP_ERROR("permission deny: NET_BROADCAST\n", IsCapPermit(CAP_NET_BROADCAST),
set_errno(EPERM); return -1);
}
+#endif
}
#endif
@@ -233,21 +230,22 @@ static int lwip_bind_wrap(int s, const struct sockaddr *name, socklen_t namelen)
}
static ssize_t lwip_sendto_wrap(int s, const void *dataptr, size_t size, int flags,
- const struct sockaddr *to, socklen_t tolen)
+ const struct sockaddr *to, socklen_t tolen)
{
#if LWIP_ENABLE_NET_CAPABILITY
if (to &&
((to->sa_family == AF_INET && tolen >= sizeof(struct sockaddr_in)) ||
- (to->sa_family == AF_INET6 && tolen >= sizeof(struct sockaddr_in6)))) {
+ (to->sa_family == AF_INET6 && tolen >= sizeof(struct sockaddr_in6)))) {
ip_addr_t ipaddr;
u16_t port;
SOCKADDR_TO_IPADDR_PORT(to, &ipaddr, port);
-
+#if LWIP_ENABLE_CAP_NET_BROADCAST
if (ip_addr_ismulticast(&ipaddr) || ip_addr_isbroadcast_bysock(&ipaddr, s)) {
LWIP_ERROR("permission deny: NET_BROADCAST\n", IsCapPermit(CAP_NET_BROADCAST),
set_errno(EPERM); return -1);
}
+#endif
}
#endif
@@ -372,7 +370,6 @@ int get_unused_socket_num(void)
// Options for lwip ioctl
#define LWIP_IOCTL_ROUTE 1
#define LWIP_IOCTL_IF 1
-#define LWIP_NETIF_PROMISC 1
#define LWIP_NETIF_ETHTOOL 0
#define LWIP_IOCTL_IPV6DPCTD 0
#undef LWIP_IPV6_DUP_DETECT_ATTEMPTS
@@ -764,7 +761,7 @@ static u8_t lwip_ioctl_internal_SIOCSIFNETMASK(struct ifreq *ifr)
loc_netif = loc_netif->next;
}
-#if LWIP_DHCP // LWIP_DHCP
+#if LWIP_DHCP
if ((netif_dhcp_data(netif) != NULL) &&
(netif_dhcp_data(netif)->state != DHCP_STATE_OFF)) {
(void)netif_dhcp_off(netif);
diff --git a/net/lwip-2.1/porting/src/sys_arch.c b/net/lwip-2.1/porting/src/sys_arch.c
old mode 100755
new mode 100644
index da8d282d7c916a4f5b18edef689cfac6e4dc1395..9826fba75e4cbd4100e0babfaa3a5e5e6ddc3bc0
--- 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:
@@ -46,6 +46,7 @@ static u32_t lwprot_thread = LOS_ERRNO_TSK_ID_INVALID;
static int lwprot_count = 0;
#endif /* LOSCFG_KERNEL_SMP == YES */
+#define ROUND_UP_DIV(val, div) (((val) + (div) - 1) / (div))
/**
* Thread and System misc
@@ -59,11 +60,11 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
/* Create host Task */
task.pfnTaskEntry = (TSK_ENTRY_FUNC)thread;
- task.uwStackSize = stackSize;
+ task.uwStackSize = stackSize;
task.pcName = (char *)name;
task.usTaskPrio = prio;
task.auwArgs[0] = (UINTPTR)arg;
- task.uwResved = LOS_TASK_STATUS_DETACHED;
+ task.uwResved = LOS_TASK_STATUS_DETACHED;
ret = LOS_TaskCreate(&taskID, &task);
if (ret != LOS_OK) {
LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: LOS_TaskCreate error %u\n", ret));
@@ -84,9 +85,17 @@ void sys_init(void)
u32_t sys_now(void)
{
/* Lwip docs mentioned like wraparound is not a problem in this funtion */
- return (u32_t)(((double)LOS_TickCountGet() * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND);
+ return (u32_t)((LOS_TickCountGet() * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND);
}
+#if (LWIP_CHKSUM_ALGORITHM == 4) /* version #4, asm based */
+#include "in_cksum.h"
+u16_t lwip_standard_chksum(const void *dataptr, int len)
+{
+ return ~(u16_t)(in_cksum(dataptr, len));
+}
+#endif
+
/**
* Protector
@@ -140,7 +149,7 @@ void sys_arch_unprotect(sys_prot_t pval)
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
CHAR qName[] = "lwIP";
- UINT32 ret = LOS_QueueCreate(qName, (UINT16)size, mbox, 0, sizeof(void*));
+ UINT32 ret = LOS_QueueCreate(qName, (UINT16)size, mbox, 0, sizeof(void *));
switch (ret) {
case LOS_OK:
return ERR_OK;
@@ -184,8 +193,8 @@ err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg);
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs)
{
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
- UINT64 tick = ((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND;
- UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void*), tick ? (UINT32)tick : LOS_WAIT_FOREVER);
+ UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
+ UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), tick ? (UINT32)tick : LOS_WAIT_FOREVER);
switch (ret) {
case LOS_OK:
return ERR_OK;
@@ -202,7 +211,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs)
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
- UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void*), 0);
+ UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), 0);
switch (ret) {
case LOS_OK:
return ERR_OK;
@@ -255,7 +264,7 @@ void sys_sem_signal(sys_sem_t *sem)
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs)
{
- UINT64 tick = ((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND;
+ UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
UINT32 ret = LOS_SemPend(*sem, tick ? (UINT32)tick : LOS_WAIT_FOREVER); // timeoutMs 0 means wait forever
switch (ret) {
case LOS_OK:
diff --git a/net/mac/los_mac.h b/net/mac/los_mac.h
old mode 100755
new mode 100644
index c42ea628390892f5c44568840f48757e9c2b54aa..88d36a14ee07f8b0521b64836a4f075c4930139b
--- 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/Kconfig b/net/telnet/Kconfig
old mode 100755
new mode 100644
diff --git a/net/telnet/Makefile b/net/telnet/Makefile
old mode 100755
new mode 100644
index 8143998fd043a414e878daae8de72a33066eaced..aa2f3b8d6ec87ce3c736b5bac1ec1ff0c5e47746
--- 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
index 77815488a49388f03813bc819f7caa4db62dc234..23d56fc822bba1f301adb9f22f00a43035f3f683 100755
--- 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
index 7388a77ea0caa0ec6b5c77e49a2ea79194465262..c8ef2f1f0c315880d3b2c60106a6060aac76a57a 100755
--- 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
old mode 100755
new mode 100644
index a1d24e8bf29bfd60044edf62f57662b5e2853a86..e710c9109a6b60a0a6ece77de43486beeb84f45b
--- 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
index e921aa9a5705d30419184cbdb15b735fcc64f6ae..77fbca0782dc74fd1a900ca9bff78d69faa7c575 100755
--- 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
old mode 100755
new mode 100644
index 8f69c7b79cd687fdbe7dafb8f36ee6674b2b610f..87747b18ebf0b83dc727802a4fbf44b217463b3f
--- 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
index 2b34a8dcd12cb170a67dceb873b04602bfe1fd20..a9886b3ce8979e55c8a4cee97389045371808566 100755
--- a/platform/Kconfig
+++ b/platform/Kconfig
@@ -2,14 +2,31 @@ config PLATFORM
string
default "hi3516dv300" if PLATFORM_HI3516DV300
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:
hi3516dv300
hi3518ev300
+ Qemu ARM Virt variants (based on different CPU types):
+ qemu_arm_virt_ca7
config PLATFORM_HI3516DV300
bool "hi3516dv300"
@@ -19,8 +36,37 @@ config PLATFORM_HI3518EV300
bool "hi3518ev300"
select ARCH_CORTEX_A7
+config PLATFORM_QEMU_ARM_VIRT_CA7
+ bool "qemu_arm_virt_ca7"
+ select ARCH_CORTEX_A7
+ help
+ QEMU ARM Virtual Platform using Cortex-A7 CPU.
+
+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
@@ -47,3 +93,10 @@ config PLATFORM_BSP_GIC_V3
General Interrupt Controller version 3.
endchoice
+
+config HRTIMER_ENABLE
+ bool "HR TIMER enable"
+ default y
+ help
+ Enable High-resolution timer support
+
diff --git a/platform/Makefile b/platform/Makefile
index e7ced6bb81f54e57e9984813a9309c66922e31b7..33e81e1af1e1878210e1cebc353d8e5d9e7f0fa5 100755
--- 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:
@@ -33,28 +33,33 @@ MODULE_NAME := bsp
LOCAL_SRCS = $(wildcard $(HWI_SRC)/*.c) \
$(wildcard $(TIMER_SRC)/*.c) \
- $(wildcard $(HRTIMER_SRC)/*.c) \
$(wildcard $(UART_SRC)/*.c) \
$(wildcard ./main.c)
+ifeq ($(LOSCFG_HRTIMER_ENABLE), y)
+LOCAL_SRCS += $(wildcard $(HRTIMER_SRC)/*.c)
+endif
+
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/compat/posix/src \
-I $(LITEOSTOPDIR)/bsd/dev/random
-ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
+MAIN_PLATFORMS := $(LOSCFG_PLATFORM_HI3518EV300) \
+ $(LOSCFG_PLATFORM_HI3516DV300) \
+ $(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
+ifeq ($(findstring y, $(MAIN_PLATFORMS)), y)
LOCAL_SRCS += $(wildcard ../kernel/common/*.c)
LOCAL_SRCS := $(filter-out ../kernel/common/los_rootfs.c, $(LOCAL_SRCS))
ifneq ($(LOSCFG_FS_VFS), y)
LOCAL_SRCS := $(filter-out ../kernel/common/console.c ../kernel/common/virtual_serial.c, $(LOCAL_SRCS))
endif
+ifneq ($(LOSCFG_BASE_CORE_HILOG), y)
+LOCAL_SRCS := $(filter-out ../kernel/common/los_hilog.c, $(LOCAL_SRCS))
+endif
else
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
old mode 100755
new mode 100644
index ef3d8171302c7d8e3bca49e32a15964a1205b7ec..92788d045d94a384001f966dd857d1f38bdcaa2f
--- 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
index 7714dbfa9486c17e8381b87b74a4c1b568a2cb80..b2dc921631dc64a2d6952f31dd3923bd021ac354 100755
--- 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:
@@ -56,11 +56,19 @@ else ifeq ($(LOSCFG_PLATFORM_HI3518EV300), y)
USB_TYPE := usb3.0_hi3518ev300
LITEOS_CMACRO_TEST += -DTEST3518EV300
+########################## Qemu ARM Virt Options##############################
+else ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
+ HWI_TYPE := arm/interrupt/gic
+ TIMER_TYPE := arm/timer/arm_generic
+ UART_TYPE := amba_pl011
+
endif
+ifeq ($(LOSCFG_HRTIMER_ENABLE), y)
+HRTIMER_SRC := hw/$(HRTIMER_TYPE)
+endif
HWI_SRC := hw/$(HWI_TYPE)
TIMER_SRC := hw/$(TIMER_TYPE)
-HRTIMER_SRC := hw/$(HRTIMER_TYPE)
NET_SRC := net/$(NET_TYPE)
UART_SRC := uart/$(UART_TYPE)
USB_SRC := usb/$(USB_TYPE)
@@ -69,22 +77,27 @@ LITEOS_BASELIB += -lbsp
LITEOS_PLATFORM := $(subst $\",,$(LOSCFG_PLATFORM))
-PLATFORM_BSP_HISI_BASE := $(LITEOSTOPDIR)/platform
+PLATFORM_BSP_BASE := $(LITEOSTOPDIR)/platform
-PLATFORM_INCLUDE := -I $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board/include \
- -I $(PLATFORM_BSP_HISI_BASE)/../kernel/common \
- -I $(PLATFORM_BSP_HISI_BASE)/../../../drivers/liteos/platform/pm \
- -I $(PLATFORM_BSP_HISI_BASE)/hw/include \
- -I $(PLATFORM_BSP_HISI_BASE)/include \
- -I $(PLATFORM_BSP_HISI_BASE)/$(UART_SRC)
+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/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
#
-LIB_SUBDIRS += $(PLATFORM_BSP_HISI_BASE)
+LIB_SUBDIRS += $(PLATFORM_BSP_BASE)
LITEOS_PLATFORM_INCLUDE += $(PLATFORM_INCLUDE)
LITEOS_CXXINCLUDE += $(PLATFORM_INCLUDE)
diff --git a/platform/hw/arm/interrupt/gic/gic_v2.c b/platform/hw/arm/interrupt/gic/gic_v2.c
index 872269022650f838ccb1532f16a75d821bbe568b..463d20deca3e57469c9ad2529759c9cec6d4f82b 100755
--- 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
index 3e20c60cc7a3a923d8b116b38ec0e4d9ce29d23d..8451f1087c9cc86371f3ed12c27bf64557477b2e 100755
--- 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
index f203699be6f29f1836681bd45caed5fbab3dc3eb..f7d0a9bcab9c8e4b0a3b6343d6fbe01a3de9d62f 100755
--- 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
old mode 100755
new mode 100644
index 1e94d02269ed319fc9e449b975377011f97bffb2..c21dff1f9a8ed1816325653d9b5fac65b434596a
--- 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
old mode 100755
new mode 100644
index 947573b062908a4c8556e96df99cd032ec970c0b..c85b598068e0904ed530f7e8d8548142488a04d7
--- 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
old mode 100755
new mode 100644
index 81b2bd4e0b16107414f7f730401dfe9e24a516d3..f78882fcf4ac59b303efa2f64fe5f03795a11f99
--- 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
old mode 100755
new mode 100644
index 239b003a9d66ea1bc66b006109ebfea54ee73bad..3a72a9c8c0fabcae510f63b0a0db34195aa167ce
--- 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
index 2781f51a75265a523eea7c1c385c6345cc9206ee..7f84673264a80c28ad5ccb3f14b985a3c072f9cf 100755
--- 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
old mode 100755
new mode 100644
index 211c23f32c706b415e48179824ae1b880fc74197..9d08589a415189a916a25b371184b78fd2f73272
--- 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
old mode 100755
new mode 100644
index 780e46f69979f8dd686cf10e30333d1df33d3d13..380b36216db4a26e287d8b9b01c9c24d73cd183a
--- 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
old mode 100755
new mode 100644
index 1074dd47eac86ecc9960d8db8a04023a02e7ff0b..921ca0479780c38d59c5a794bb931ab5c43041a4
--- 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
old mode 100755
new mode 100644
index 788ee2b8e191fbc1610a2b7883f3091358bb9fa5..25adc557066c2e8ceb5fe47ec77d4858bbb8264b
--- 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
index 3d60b0b54f9e338036b54a6a72e2d1a5fc7cac5d..7978ec14fd5f10e6c041137fc966c383f97a4034 100755
--- 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
old mode 100755
new mode 100644
index 1de43758aa21e817a068a293aa3e2ef13e160851..6de19dec34741f51709ef2382889baf80bddfcb5
--- 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
old mode 100755
new mode 100644
index 2b2fb2b8e79da14736da441696054c999163abe7..bd03df9eeff6fb54853f15b780009097a995eb8b
--- 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 100755
index 03e1093d24307951df284d8cda63ad912dd07c83..0000000000000000000000000000000000000000
--- 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 100755
index 1302e921d1dd9a5c3dd5b6132ab4736c83812478..0000000000000000000000000000000000000000
--- 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 100755
index b3784e47999aac4837d2ee24b5ae9eb81fb27a48..0000000000000000000000000000000000000000
--- 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/Kconfig b/security/Kconfig
old mode 100755
new mode 100644
diff --git a/security/Makefile b/security/Makefile
index b557bd937a82429116d24257ced2b620dfe7dcb0..a300fb8922968fd4c4bc00fc5e86ca3036819018 100755
--- 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
index 7a63cb75606725955f575653a20c3540160a5fa5..a32f48af769aab1f2131474486b4ec3e40523a97 100755
--- 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
index 23363f7f9031b764b9f901c43bcc5557727c6d18..00eb4a42b397f49426ab0d5d04253b01efbab30b 100755
--- 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
index a8851eb5dc5d5503304071bf4b2e9b0a19e4770a..51e7233d4bf8a567ce1cb1589e422a707014f9a8 100755
--- 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
index 4f5414844360fdd30624d526c9ad5747b7fb1098..b5163325740ca2f7980464fb361d626049280457 100755
--- 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
index 0da5be0a65605c142d0caaae562d9ae8e61588af..f460c6c70af419be73dbf696f2fffc20dcbec1b8 100755
--- 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:
@@ -138,6 +138,7 @@ static UINT16 GetFreeVid(VOID)
}
(void)memcpy_s(tmp, mapMaxNum * sizeof(UINT32), idMap->bitMap, (mapMaxNum - 1) * sizeof(UINT32));
+ LOS_MemFree(m_aucSysMem0, idMap->bitMap);
idMap->bitMap = tmp;
idMap->mapCount = mapMaxNum;
idMap->bitMap[i] = 1;
diff --git a/security/vid/vid_api.h b/security/vid/vid_api.h
index 67ca6d6972c3dc6e4a0eb04a4793ec99c3791555..12a7c75d7693d616e9977fbbcf3e9360e62367ce 100755
--- 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
index 6bd0f36eeb2e3ab6f0ab1c451a15db03952abfa8..835e4716a5ffaba3683a89b8b4e23cb77bda2a1d 100755
--- 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
index 1ae5e4f95374dc8d3546056f6e53b638e27903cd..6e8dc0bb4b2aa0d06d8a41bb7c80cc3aa46aa1ff 100755
--- 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/Kconfig b/shell/Kconfig
old mode 100755
new mode 100644
diff --git a/shell/Makefile b/shell/Makefile
index 91fc0e2a4d7223829ec6ca9b370dae715933818c..d49850a13b6de25d1c815bc03c8b30ed401fac24 100755
--- 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
index 6a3f939be0777d1ee1a6c8b32e67a4dd23f10782..15cde68786c0e00b93d924c8041335867ec77842 100755
--- 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
old mode 100755
new mode 100644
index dd48e266268aff34d2cdeef8a097078ce966eb55..6f73ca19b448700da67abe734c765bc05449f579
--- 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
index 999f9d4b9d480e3ec75d8c68219f01a504d3bbb0..754f30dc2ebdc328185f5e7681c3e557183cf842 100755
--- 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
old mode 100755
new mode 100644
index c337d0e9a1ca7e0596b9656abdd198dc2cb4d03d..d4a7111c46712cdee76e95026619c515c13db0b3
--- 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
old mode 100755
new mode 100644
index 6f03dee595d2f5f914c97a48fe236a7118679305..c2899d4f7f813e02de85cd44ff6c85cb7cbf0b84
--- 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
old mode 100755
new mode 100644
index b825c883b959ccfc61430f2815cd4cce25f49d91..7cd587627b3294c71552b7c32e2d4380ba12d8e6
--- 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
old mode 100755
new mode 100644
index 278636bed529e9b27f93530327615b5c5366caba..022ae1455c12a68276ab05e062cf6663dd9f1ef6
--- 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
index 0b0d3b555580f16f47ea4c9836de1e5fe75fc99c..9159dd383f9518b92feae4abb90f800455a64392 100755
--- 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
index e6c8d1ab5812e00d0b8a04ef0774ece14d4e8d90..27bb369f4755c02e82249709667ec7c4872075f1 100755
--- 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
index 5dbc73e2d42207186441cf88d74346e6e9ab03a4..34e11ce505ac9226b536e8a5f19d9359d3f694bc 100755
--- 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
index 2238a8edb7385340b30c7c55fe431b601f72388c..b7a71854286820525ebbe9ceaddb48147fd74856 100755
--- 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
index 0a5ab5bdcc21a4fc131ff0db42d42942165628c0..c7630443d42422ad033719b30924d15f84065b1f 100755
--- 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
index 8f1f94a51cf01521d5722a186222d277b762787b..6ffe776d5e1a9477241b88645867495b985976be 100755
--- 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
index 4b9cce00b0ed32e83710bc67d3f4c511eba86bb8..178778b9fd16d73245e183184f5e2d64661a2118 100755
--- 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
@@ -100,7 +96,16 @@ STATIC UINT32 OsShellSourceInit(INT32 consoleId)
ret = LOS_NOK;
goto ERR_OUT4;
}
+#if !defined(LOSCFG_PLATFORM_ROOTFS)
+ /*
+ * In case of ROOTFS disabled but
+ * serial console enabled, it is required
+ * to create Shell task in kernel for it.
+ */
+ if (consoleId == CONSOLE_TELNET || consoleId == CONSOLE_SERIAL) {
+#else
if (consoleId == CONSOLE_TELNET) {
+#endif
ret = OsShellCreateTask(shellCB);
if (ret != LOS_OK) {
goto ERR_OUT4;
@@ -121,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
index b5fe826e5fc6034127ed4eb22b220b0285f8fcbf..2c594b3af3bda53cf49c8bf55119fa5677d02733 100755
--- 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
index f64a61accf281896ba2ae513edf47861c577c4c4..961d39d7fff04183bcb5293133066f130128b287 100755
--- 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
index 213c6e464e4ad90be0bf3ea6695a9b99f2016988..06a484cede2a2ecb408d79b37d680ed9fae26121 100755
--- 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
old mode 100755
new mode 100644
index 12ab01833a69b41433b315548ce1ae40f5098b26..38124666f89a3e775bca599886f778ff4bf15090
--- 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
index 8141be80d6127c34d6c542a36f9547a62860aa73..33f885923b441f2163a24b34bc65c8ffd230f315 100755
--- 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
index ef0e26a72ddb6433efb51e018e85e449e782fa8c..d4dc0c72999195f9226bab201a5f7375d18357c7 100755
--- 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:
@@ -33,10 +33,14 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
+ifneq ($(LOSCFG_NET_LWIP_SACK), y)
+LOCAL_SRCS := $(filter-out net_syscall.c, $(LOCAL_SRCS))
+endif
+
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/base/include \
+ -I $(LITEOSTOPDIR)/kernel/extended/dynload/include \
-I $(LITEOSTOPDIR)/fs/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
index ab7e43e706227ea074c52d99cbfab0023702febe..c1b8c7909bf63ec64076e8462a47aef3ee0b7c89 100755
--- 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);
@@ -500,6 +502,26 @@ out:
return 0;
}
+#ifdef LOSCFG_FS_NFS
+static int NfsMountRef(const char *serverIpAndPath, const char *mountPath,
+ unsigned int uid, unsigned int gid) __attribute__((weakref("nfs_mount")));
+
+static int NfsMount(const char *serverIpAndPath, const char *mountPath,
+ unsigned int uid, unsigned int gid)
+{
+ int ret;
+
+ if ((serverIpAndPath == NULL) || (mountPath == NULL)) {
+ return -EINVAL;
+ }
+ ret = NfsMountRef(serverIpAndPath, mountPath, uid, gid);
+ if (ret < 0) {
+ ret = -get_errno();
+ }
+ return ret;
+}
+#endif
+
int SysMount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
const void *data)
{
@@ -534,6 +556,12 @@ int SysMount(const char *source, const char *target, const char *filesystemtype,
goto OUT;
}
}
+#ifdef LOSCFG_FS_NFS
+ if (strcmp(fstypeRet, "nfs") == 0) {
+ ret = NfsMount(sourceRet, targetRet, 0, 0);
+ goto OUT;
+ }
+#endif
}
ret = mount(sourceRet, targetRet, (filesystemtype ? fstypeRet : NULL), mountflags, data);
@@ -543,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;
}
@@ -574,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;
}
@@ -583,6 +611,7 @@ int SysAccess(const char *path, int amode)
{
int ret;
struct stat buf;
+ struct statfs fsBuf;
char *pathRet = NULL;
if (path != NULL) {
@@ -592,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)) {
@@ -603,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;
@@ -637,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;
}
@@ -664,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;
}
@@ -688,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;
}
@@ -724,7 +765,7 @@ void SysSync(void)
int SysUmount2(const char *target, int flags)
{
if (flags != 0) {
- return -ENOSYS;
+ return -EINVAL;
}
return SysUmount(target);
}
@@ -773,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;
@@ -813,6 +855,7 @@ int SysPipe(int pipefd[2]) /* 2 : pipe fds for read and write */
}
return ret;
}
+#endif
int SysDup2(int fd1, int fd2)
{
@@ -866,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;
}
}
@@ -915,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();
}
@@ -937,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) {
@@ -973,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;
}
@@ -981,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) {
@@ -1006,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;
}
@@ -1051,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;
}
@@ -1087,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;
}
@@ -1118,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;
}
@@ -1149,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;
}
@@ -1342,7 +1385,12 @@ int SysPrctl(int option, ...)
}
name = va_arg(ap, unsigned long);
- err = OsSetCurrTaskName((const char *)(uintptr_t)name);
+ if (!LOS_IsUserAddress(name)) {
+ err = EFAULT;
+ goto ERROR;
+ }
+
+ err = OsSetTaskName(OsCurrTaskGet(), (const char *)(uintptr_t)name, TRUE);
if (err != LOS_OK) {
goto ERROR;
}
@@ -1379,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;
}
@@ -1417,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;
}
@@ -1446,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;
}
@@ -1536,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;
}
@@ -1565,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;
}
@@ -1594,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;
}
@@ -1635,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;
}
@@ -1671,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;
@@ -1680,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();
}
@@ -1694,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;
@@ -1713,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();
}
@@ -1727,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();
}
@@ -1761,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;
}
@@ -1805,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;
}
@@ -1819,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;
@@ -1862,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;
@@ -1892,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;
}
@@ -1926,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
index a1890ed11e24abd5e8e678be942d6ede890e9499..551f4984228470dd121e6a9cad37e85572b20c2f 100755
--- 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
index 136c2ef0975ecb7a79a772e0b8ce8c8d5ac09497..bd3c464d1765f37328a12697716182a49147e199 100755
--- 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:
@@ -30,6 +30,12 @@
*/
#define _GNU_SOURCE
+#include "menuconfig.h"
+#ifdef LOSCFG_FS_VFS
+#include "fs/fs.h"
+#include "fs/file.h"
+#endif
+#include "los_signal.h"
#include "los_syscall.h"
#include "los_task_pri.h"
#include "los_process_pri.h"
@@ -40,10 +46,6 @@
#include "mqueue.h"
#include "los_futex_pri.h"
#include "sys/times.h"
-#ifdef LOSCFG_FS_VFS
-#include "fs/fs.h"
-#include "fs/file.h"
-#endif
#include "dirent.h"
#include "fcntl.h"
#include "unistd.h"
diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h
index e4614771e1bb10cfc2c8127628f78daf60e7a6bc..0827b0a68fa7195ba291c997e265261eebd2873a 100755
--- 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
index 5e185b01b8d028d4798873f9ceb2cd9989a30060..c048dc1c34e6c32e44f47bbc5e2590c9565a8cfd 100755
--- 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
index f1ac24899e83dbb79d38f09453f2d81fab6495f7..1532eb1293870b36589d9ebd2c3a8bc5d1a7a789 100755
--- 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,17 +29,28 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "los_syscall.h"
+#include "syscall_pub.h"
+#include "stdlib.h"
+#include "fs_file.h"
+#include "fs/fs.h"
#include "los_process_pri.h"
-#include "lwip/sockets.h"
-#include
+#include "los_signal.h"
+#include "los_syscall.h"
#include "los_vm_map.h"
+#include "lwip/sockets.h"
#include "user_copy.h"
-#include "fs_file.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); \
@@ -52,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;
@@ -281,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();
@@ -298,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();
@@ -347,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;
@@ -359,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();
@@ -371,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;
@@ -383,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();
@@ -403,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();
@@ -422,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) {
@@ -441,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();
@@ -468,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);
@@ -527,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();
@@ -559,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);
@@ -601,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
index 7bb1ec90b5144c97b472a5b0a279ee285ba02af8..b54f8bb83cf3a476d715e9028d7d8076506ebed3 100755
--- 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,48 +195,33 @@ int SysSchedGetParam(int id, int flag)
return OsGetProcessPriority(LOS_PRIO_PROCESS, id);
}
-int SysSchedSetParam(int id, unsigned int prio, int flag)
+int SysSetProcessPriority(int which, int who, unsigned int prio)
{
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();
+ if (who == 0) {
+ who = (int)LOS_GetCurrProcessID();
}
- ret = OsPermissionToCheck(id, LOS_GetCurrProcessID());
+ ret = OsPermissionToCheck(who, LOS_GetCurrProcessID());
if (ret < 0) {
return ret;
}
- return OsSetProcessScheduler(LOS_PRIO_PROCESS, id, prio, LOS_SCHED_RR, FALSE);
+ return OsSetProcessScheduler(which, who, prio, LOS_GetProcessScheduler(who));
}
-int SysSetProcessPriority(int which, int who, unsigned int prio)
+int SysSchedSetParam(int id, unsigned int prio, int flag)
{
- int ret;
-
- if (prio < OS_USER_PROCESS_PRIORITY_HIGHEST) {
- return -EINVAL;
- }
-
- if (who == 0) {
- who = (int)LOS_GetCurrProcessID();
- }
-
- ret = OsPermissionToCheck(who, LOS_GetCurrProcessID());
- if (ret < 0) {
- return ret;
+ if (flag < 0) {
+ return -OsUserTaskSchedulerSet(id, LOS_SCHED_RR, prio, false);
}
- return OsSetProcessScheduler(which, who, prio, LOS_SCHED_RR, 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
index a35b3acd650c505767c49317b746b941733586d8..bb72f2b8a5d6c3c519cb2526215149c1293d1f62 100755
--- 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/syscall/syscall_pub.c b/syscall/syscall_pub.c
new file mode 100644
index 0000000000000000000000000000000000000000..dbfd0f5abe246e04e9e7926081d02f5686e60591
--- /dev/null
+++ b/syscall/syscall_pub.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 0000000000000000000000000000000000000000..6c9015f04360d86f5d31acd1f413bf43d2358690
--- /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
index af2188dcc7ad888fc599f5b1611b62a7b27ae417..10ef483cc26146d98a732a3670befd1fa8fb4b2c 100755
--- 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:
@@ -36,6 +36,7 @@
#include "time.h"
#include "user_copy.h"
#include "sys/times.h"
+#include "los_signal.h"
#include "los_memory.h"
#include "los_strncpy_from_user.h"
@@ -330,7 +331,7 @@ int SysClockNanoSleep(clockid_t clk, int flags, const struct timespec *req, stru
{
int ret;
struct timespec sreq;
- struct timespec srem;
+ struct timespec srem = { 0 };
if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec))) {
errno = EFAULT;
@@ -354,7 +355,7 @@ int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp)
{
int ret;
struct timespec srqtp;
- struct timespec srmtp;
+ struct timespec srmtp = { 0 };
if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
errno = EFAULT;
@@ -379,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;
}
@@ -477,9 +484,9 @@ int SysClockNanoSleep64(clockid_t clk, int flags, const struct timespec64 *req,
{
int ret;
struct timespec rq;
- struct timespec rm;
+ 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
index 6afe3b1e2929e2e7a69443dc9c390fd5618d142e..c1344ea1a7818645873dc4b99985391a88389755 100755
--- 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/.gitignore b/tools/.gitignore
old mode 100755
new mode 100644
diff --git a/tools/build/config.mk b/tools/build/config.mk
old mode 100755
new mode 100644
index 4d06aea78a5a1e7a31dff2e84c68c53b46af4ebe..6b468487a3afac1ca140b8346421fd2f1dbd0379
--- 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 100755
index fb17d09fd77a57caaacdfa7c6b75ca956154a79b..0000000000000000000000000000000000000000
--- 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 100755
index a34f516f6f887f5105eeb0dbc753597a8172d00e..0000000000000000000000000000000000000000
--- a/tools/build/config/debug/hi3516dv300_clang.config
+++ /dev/null
@@ -1,190 +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_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/hi3518ev300.config b/tools/build/config/debug/hi3518ev300.config
deleted file mode 100755
index 57654ae208b82f4d5aa9ab09a8125c5e6615f502..0000000000000000000000000000000000000000
--- 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 100755
index 8a4d6ebed6bec1659bb9f1cdf3bac3bca1f4b7d9..0000000000000000000000000000000000000000
--- a/tools/build/config/debug/hi3518ev300_clang.config
+++ /dev/null
@@ -1,183 +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_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/hispark_aries.config b/tools/build/config/debug/hispark_aries.config
new file mode 100755
index 0000000000000000000000000000000000000000..772b3f04d4eed15c0d311c4d15987eed84f96be3
--- /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 0000000000000000000000000000000000000000..ad900b693774565778f7d3392b26f0fb1531fbb5
--- /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 0000000000000000000000000000000000000000..4bee10953feecf013fec90e382326757911366d2
--- /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 0000000000000000000000000000000000000000..8cd8585015989136c2de52182446a4f0ba44dc57
--- /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 0000000000000000000000000000000000000000..03dff37019203ed9272b6faa8b3e269177ef27bd
--- /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 0000000000000000000000000000000000000000..eb1feba59ce003b5441aef99f1f226a923d83be7
--- /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 0000000000000000000000000000000000000000..05e8c829cc0c6bde48997042208f47d673ebe072
--- /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 0000000000000000000000000000000000000000..d7c5566f0cadc1ddc05a3db0d1dba3449bce33c8
--- /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 0000000000000000000000000000000000000000..655891d1fdbedb12769796877d51f1240f639141
--- /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 0000000000000000000000000000000000000000..5c9f45350bd1666032f8744e11da963611321c70
--- /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/hi3516dv300_clang_release.config b/tools/build/config/hi3516dv300_clang_release.config
deleted file mode 100755
index 5fb2798a987ba147a098c56e52ef717bdaded421..0000000000000000000000000000000000000000
--- a/tools/build/config/hi3516dv300_clang_release.config
+++ /dev/null
@@ -1,173 +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_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 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 100755
index a3b4d5c0cb815369674c3379d7d5a486bf2a83d2..0000000000000000000000000000000000000000
--- 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 100755
index 28dc1d19d1b66af32ef401c2c4dbf8e3fab72b39..0000000000000000000000000000000000000000
--- 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 100755
index 982d0f53bdc2d8bd4536096710fd6be7269c7453..0000000000000000000000000000000000000000
--- a/tools/build/config/hi3518ev300_clang_release.config
+++ /dev/null
@@ -1,166 +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_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 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 100755
index 41716002e73db2fc03b46d2d5fe7161bc1eeaab2..0000000000000000000000000000000000000000
--- 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 100755
index f21be7b2e2f994614a4d656860146eb32878de0d..0000000000000000000000000000000000000000
--- 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 0000000000000000000000000000000000000000..53d622bf5b00dc105393b8ce6c71d7b57bf7975b
--- /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 0000000000000000000000000000000000000000..772b3f04d4eed15c0d311c4d15987eed84f96be3
--- /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 0000000000000000000000000000000000000000..e7c564cb74aa6485d67fb48c1456c5df7e2c105e
--- /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 0000000000000000000000000000000000000000..4f0f51ea0bdc9b7e3f651fdb16929f98932f5df9
--- /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 0000000000000000000000000000000000000000..d920789eb9d9239b20e6200f755252f96243bb02
--- /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 0000000000000000000000000000000000000000..b0965c3cc9ca91535b7b52dab9c5ca5d92bac1a5
--- /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 0000000000000000000000000000000000000000..a3ee089ac0803c4a07ce834a979d9a36ecf2b4dd
--- /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 0000000000000000000000000000000000000000..c7a42fa0de5eece82989bfa450a1eb646ea6b5de
--- /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 0000000000000000000000000000000000000000..df3a8e52ff768c83c822c4e5643acabfd9f02b58
--- /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 0000000000000000000000000000000000000000..18ed73cc9320aff7e56b760e3e7ad75165cd755f
--- /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 0000000000000000000000000000000000000000..df2abca462642251129cd70d97ea9d01deccce2c
--- /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 0000000000000000000000000000000000000000..6c2b9e471975bcd301e0811f0f1671e9d968fdbf
--- /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 0000000000000000000000000000000000000000..52d48e03933fdb16526ffec19ee54d7d6ae051c0
--- /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 0000000000000000000000000000000000000000..a0ab25a39c0fc60d24656cf9f0b9c8ef9be75de1
--- /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 0000000000000000000000000000000000000000..a0ab25a39c0fc60d24656cf9f0b9c8ef9be75de1
--- /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 0000000000000000000000000000000000000000..015e238e565bc27a5d6a8ad5f1646a226647c53d
--- /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 0000000000000000000000000000000000000000..6c0ea04f7df04033d3350259dee18f6988b2f3e2
--- /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 0000000000000000000000000000000000000000..326021a519a628383755c041ca1441e8b88ef504
--- /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 0000000000000000000000000000000000000000..88da9ef9b9414aaeb5f9e6e2f3dd96dade1791bd
--- /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/mk/dynload.mk b/tools/build/mk/dynload.mk
index 0cc4bb1294b2ebdbef612b7d0042d3d46a814362..5b802f30e951bd7862bfad399e72fdbce4d3ad7f 100755
--- 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 0000000000000000000000000000000000000000..191e90462663d72a408b3341bc39235235a5758e
--- /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 1fa12631a91d1116c1d9e3b40f02e1cdf9dccd8c..243c984bda21209f8a05fe6862da081bf5d70220 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
index 5e8f9e1357f4012a1005af1d13ebf51405cb0f42..07d50a02379a328d1910351c995eb3cd8a340321 100755
--- 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
index ff273f2cf1b37d8506709b1c814eac726e58dee2..66e2be8417fd8b24868f822df4154c69d4e98c05 100755
--- 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,8 +169,12 @@ LITEOS_BASELIB += -lbase
LIB_SUBDIRS += kernel/base
LITEOS_KERNEL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/include
-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)
LITEOS_BASELIB += -lcpup
@@ -191,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
@@ -211,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 ################################
@@ -336,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 ##################################
@@ -350,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")
@@ -358,10 +374,9 @@ endif
#################################### Net Option End####################################
LITEOS_DRIVERS_BASE_PATH := $(LITEOSTOPDIR)/../../drivers/liteos
-LITEOS_VENDOR_DRIVERS_BASE_PATH := $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/platform
################################## 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)
@@ -370,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
@@ -388,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)
@@ -431,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
@@ -440,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 #######################################
@@ -457,7 +447,14 @@ ifeq ($(LOSCFG_COMPILE_DEBUG), y)
LITEOS_COPTS_OPTION = -g -gdwarf-2
else
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
- LITEOS_COPTS_OPTMIZE = -Oz -flto
+ ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
+ # WORKAROUND: Disable LTO to avoid undefined __stack_chk_guard
+ # problem. "externally_visible" attribute could be
+ # a fix for that but it is not known to our LLVM.
+ LITEOS_COPTS_OPTMIZE = -Oz #-flto
+ else
+ LITEOS_COPTS_OPTMIZE = -Oz -flto
+ endif
else
LITEOS_COPTS_OPTMIZE = -O2
endif
@@ -526,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
@@ -548,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
@@ -578,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)
@@ -607,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
@@ -643,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)
@@ -673,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)
@@ -700,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
index 7c9c015958d8f3a5dca8109b4929cf8254c754c9..5152c6a68668d46a2f30307bc017b3817b09f999 100755
--- 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:
@@ -81,7 +81,7 @@ all : $(LIB)
$(LOCAL_COBJS): $(OBJOUT)/%.o: %.c
$(HIDE)$(OBJ_MKDIR)
- $(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
+ $(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_INCLUDE) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
$(LOCAL_CPPOBJS): $(OBJOUT)/%.o: %.cpp
$(HIDE)$(OBJ_MKDIR)
diff --git a/tools/fsimage/MakeVersion.sh b/tools/fsimage/MakeVersion.sh
index 97302ca9f22207924f0ff59a630cc310a1f3c07e..712d1a110146c6197020d6d2e7f4d3d2d901a31f 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/mkfs.jffs2 b/tools/fsimage/mkfs.jffs2
deleted file mode 100755
index 1d6e2e673d9e97afbb05079c1e498644afadce60..0000000000000000000000000000000000000000
Binary files a/tools/fsimage/mkfs.jffs2 and /dev/null differ
diff --git a/tools/scripts/make_rootfs/releaseinfo.sh b/tools/scripts/make_rootfs/releaseinfo.sh
index 1aab55d76aac308e2dfe36fd4a585bed92293236..65c0cdd86d62ce8b41439d66f68479943b6bb0d0 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 cae9c03cb25d1fd5a49b7ef28af25b26d7520dbb..e1c46223b024b79bd42460f5addd856a295e1fd6 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 13f813209becde71088706192c375c92355aac0f..fe46c91f50673655fc15159a558e2d8c3b99b2ff 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 733ed41c034ee9320d6bd6fc98393e87dcb5d1e4..25b25dafde60cb495f73f534feb2dadf1721897b 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,27 +33,47 @@ set -e
system=$(uname -s)
ROOTFS_DIR=$1
FSTYPE=$2
-ROOTFS_IMG=${ROOTFS_DIR}".img"
-JFFS2_TOOL=$(dirname $(readlink -f "$0"))/../../fsimage/mkfs.jffs2
-WIN_JFFS2_TOOL=$(dirname $(readlink -f "$0"))/../../fsimage/win-x86/mkfs.jffs2.exe
+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
-if [ "${ROOTFS_DIR}" = "*rootfs" ]; then
- chmod -R 755 ${ROOTFS_DIR}
+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 exit, please install it" >&2
+fi
+return 0
+}
+
+chmod -R 755 ${ROOTFS_DIR}
+if [ -f "${ROOTFS_DIR}/bin/init" ]; then
chmod 700 ${ROOTFS_DIR}/bin/init 2> /dev/null
+fi
+if [ -f "${ROOTFS_DIR}/bin/shell" ]; then
chmod 700 ${ROOTFS_DIR}/bin/shell 2> /dev/null
fi
if [ "${FSTYPE}" = "jffs2" ]; then
if [ "${system}" != "Linux" ] ; then
+ tool_check ${WIN_JFFS2_TOOL}
${WIN_JFFS2_TOOL} -q -o ${ROOTFS_IMG} -d ${ROOTFS_DIR} --pagesize=4096
else
- chmod +x ${JFFS2_TOOL}
+ 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!"
+ echo "Unsupported fs type!" >&2
else
+ tool_check ${VFAT_TOOL}
+ tool_check ${MCOPY_TOOL}
BLK_SIZE=512
CLT_SIZE=2048
FAT_TAB_NUM=2
@@ -73,9 +93,9 @@ elif [ "${FSTYPE}" = "vfat" ]; then
IMG_CNT=$(( (${IMG_SIZE} + ${BLK_SIZE} - 1) / ${BLK_SIZE} ))
echo mtools_skip_check=1 >> ~/.mtoolsrc
dd if=/dev/zero of=${ROOTFS_IMG} count=${IMG_CNT} bs=${BLK_SIZE}
- mkfs.vfat ${ROOTFS_IMG} -s ${CLT_CNT} -f ${FAT_TAB_NUM} -S ${BLK_SIZE} > /dev/null
- mcopy -i ${ROOTFS_IMG} ${ROOTFS_DIR}/* -/ ::/
+ ${VFAT_TOOL} ${ROOTFS_IMG} -s ${CLT_CNT} -f ${FAT_TAB_NUM} -S ${BLK_SIZE} > /dev/null
+ ${MCOPY_TOOL} -i ${ROOTFS_IMG} ${ROOTFS_DIR}/* -/ ::/
fi
else
- echo "Unsupported fs type!"
+ echo "Unsupported fs type!" >&2
fi