Compare commits

..

75 Commits

Author SHA1 Message Date
openharmony_ci
56565beeb6 !668 修复fatfs中GetLdPath无法正常返回结果
Merge pull request !668 from xiexg-dc/riscv32-virt
2022-04-11 06:18:21 +00:00
openharmony_ci
a77aa7de98 !670 fix: 告警修复
Merge pull request !670 from Zhaotianyu/0408codex_fix
2022-04-11 02:05:02 +00:00
openharmony_ci
db8c284cd1 !670 fix: 告警修复
Merge pull request !670 from Zhaotianyu/0408codex_fix
2022-04-11 02:05:01 +00:00
arvinzzz
b1daca7f82 fix: 告警修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: If3c36a8b2d3ad3c825bc3e5ef68efa8896d54884
2022-04-08 16:11:12 +08:00
xiexg-dc
46546688c9 fix: 修复fatfs中GetLdPath无法正常返回结果
fix: #I4XBJ6

Signed-off-by: xiexg-dc <xiexg@digitalchina.com>
Change-Id: I919d48de744f01f56b6fb7376b8b770386380197
2022-04-06 10:37:03 +08:00
openharmony_ci
d017af7459 !669 refactor: 优化任务状态,EXIT状态仅表示任务已退出
Merge pull request !669 from zhushengle/exit
2022-04-02 08:10:15 +00:00
zhushengle
4e9f8c71f9 refactor: 优化任务状态,EXIT状态仅表示任务已退出
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I53e98540af4deb44e64f6879df340b27efb201b8
2022-04-02 14:55:20 +08:00
openharmony_ci
e34c4050f9 !666 解决taskCB未定义以及初始化的问题
Merge pull request !666 from 夏不白/master
2022-04-01 03:18:21 +00:00
xia-bubai
67b579161d Description: add initialize of taskCB in function ArchTskStackInit
IssueNo:https://gitee.com/openharmony/kernel_liteos_m/issues/I50NRJ
Feature or Bugfix: Bugfix

Signed-off-by: xia-bubai <xiacong4@huawei.com>
2022-04-01 10:33:45 +08:00
openharmony_ci
d5b90399b7 !622 feat:增加玄铁ck804ef架构内核支持文件
Merge pull request !622 from qubo/master
2022-03-31 06:22:56 +00:00
bob_qu
1ab2ffcd4a fix:按照评审意见,调整目录到V2下,修改代码review问题
合入原因:按照规划增加winnermicro w800芯片OH适配
          需要新增CK804芯片架构支持代码
修改:在kernel/liteos_m、device/soc、device/board、vendor/hihope
       仓下增加CK804芯片架构、芯片SDK、开发板和产品配置文件
影响:由于是新增芯片架构,与其他平台编译隔离,无副作用

Signed-off-by: bob_qu <qu_bo@hoperun.com>
2022-03-30 21:57:04 +08:00
openharmony_ci
ec9f0e47e9 !660 fix: 低功耗tick timer休眠时间计算有误
Merge pull request !660 from zhushengle/pm
2022-03-28 13:27:56 +00:00
zhushengle
8550117b01 fix: 低功耗tick timer休眠时间计算有误
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I3dfa2a8ec7562a1182dae74cc706c7a660ae867a
2022-03-28 15:54:06 +08:00
openharmony_ci
f29973e995 !658 fix: 修复README格式问题
Merge pull request !658 from zhushengle/readme
2022-03-24 13:51:28 +00:00
zhushengle
9e0e39f277 fix: 修复README格式问题
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I35a67592ceaab7bdaaf3c2bf4122f6a4bc4a66bb
2022-03-24 21:40:56 +08:00
openharmony_ci
2f19ba3653 !645 队列支持变长读
Merge pull request !645 from chenliming_kh/master
2022-03-24 01:51:31 +00:00
openharmony_ci
fe7191183e !657 fix:告警修复
Merge pull request !657 from Zhaotianyu/0323codex_fix_1
2022-03-23 09:37:33 +00:00
arvinzzz
d84471ff29 fix: 告警修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I1c00ca1dda35c62b06bff78353737f7943a647e9
2022-03-23 17:15:52 +08:00
openharmony_ci
45654cee93 !635 Fix : menuconfig配置Enable Dynamic Link Feature后编译报错
Merge pull request !635 from yinjiaming/master
2022-03-23 08:49:46 +00:00
openharmony_ci
110ee01118 !635 Fix : menuconfig配置Enable Dynamic Link Feature后编译报错
Merge pull request !635 from yinjiaming/master
2022-03-23 08:49:45 +00:00
openharmony_ci
b51e7f93d4 !637 Fix : 开启lwip后编译失败
Merge pull request !637 from yinjiaming/fix
2022-03-23 08:49:19 +00:00
openharmony_ci
2d9e476c0b !652 fix:告警修复
Merge pull request !652 from Zhaotianyu/0322codex_fix_2
2022-03-22 13:56:49 +00:00
openharmony_ci
9ee49f1bb8 !647 feat: L0支持systick动态调频
Merge pull request !647 from zhushengle/freq
2022-03-22 13:46:21 +00:00
openharmony_ci
befe8ecf9d !647 feat: L0支持systick动态调频
Merge pull request !647 from zhushengle/freq
2022-03-22 13:46:21 +00:00
arvinzzz
637de91170 fix: 告警修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I4c69ab116920db527b39070038d36e7f0bd4e331
2022-03-22 21:39:09 +08:00
zhushengle
390a488a97 feat: L0支持systick动态调频
Close #I4YXW9
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I052fe71e507f76184c8ac5d6349e368494033cde
2022-03-22 20:44:25 +08:00
openharmony_ci
9d3d983376 !650 fix:告警修复
Merge pull request !650 from Zhaotianyu/0322codex_fix_1
2022-03-22 12:06:53 +00:00
arvinzzz
0e2dded346 fix: 告警修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I09d6e86c958838d95297176c235fe1a7ad34c88c
2022-03-22 19:47:03 +08:00
openharmony_ci
b0393151a6 !648 fix: 告警修复
Merge pull request !648 from Zhaotianyu/0322codex_fix
2022-03-22 11:15:34 +00:00
arvinzzz
38f8472ddb fix: 告警修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Iaec45e835737c0ae7eea88408b2a1a4a79f1a40c
2022-03-22 18:29:16 +08:00
chenliming
7167ba7578 chenliming@kaihongdigi.com: 队列支持变长读
Signed-off-by: chenliming <chenliming@kaihongdigi.com>
2022-03-22 17:04:06 +08:00
openharmony_ci
d28c8a0423 !643 fix: 内源检视修复
Merge pull request !643 from Zhaotianyu/0321codex_fix
2022-03-21 03:44:17 +00:00
arvinzzz
17daa50fa2 fix: 内源检视修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ic8f63a512a5b2c88e7abee6c167473f37ecc9f3b
2022-03-21 11:02:16 +08:00
openharmony_ci
57a0002252 !642 fix:3.1内源代码检视问题
Merge pull request !642 from xuxinyu/master
2022-03-19 12:50:08 +00:00
x_xiny
4f12ab9a2a fix:3.1代码检视问题
Signed-off-by: x_xiny <1301913191@qq.com>
Change-Id: Ib69620ebf3c139b0e69c3fb5347eaf54cab275de
2022-03-19 19:37:23 +08:00
openharmony_ci
e703376d68 !636 修改menuconfig关闭VFS选项后编译无法通过
Merge pull request !636 from wangchen/0317_m
2022-03-19 08:24:14 +00:00
openharmony_ci
8f1dc3a1ff !636 修改menuconfig关闭VFS选项后编译无法通过
Merge pull request !636 from wangchen/0317_m
2022-03-19 08:24:14 +00:00
openharmony_ci
9bf8ff9ce5 !641 fix: 规范整改
Merge pull request !641 from zhushengle/sample
2022-03-19 08:02:11 +00:00
zhushengle
a09d4882c4 fix: 规范整改
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7be78853291d53636fd199104b4c72bbab222bcd
2022-03-19 15:46:10 +08:00
openharmony_ci
98a82ba357 !640 Fix : 修改了源码检视过程中的一些问题
Merge pull request !640 from yinjiaming/latest
2022-03-18 08:52:24 +00:00
yinjiaming
e7e850a6a6 fix: 修复3.1代码检视中的问题
【背景】
3.1 代码检视中有一些问题需要修改

【修改方案】
在可能内存泄露的地方进行了修改,在安全函数前加void转换

【影响】
对现有的产品编译不会有影响。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I8a37ecf7c8d81d24ebe153d0c0a7db008cc3e4b9
2022-03-18 08:14:18 +00:00
wangchen
3ad47afec4 fix: 通过menuconfig关闭VFS选项后,代码编译无法通过
【背景】关闭VFS时,编译无法通过

【修改方案】
1,添加对fs依赖的模块中对fs开启情况的判断

【影响】
对现有的产品编译不会有影响。

re #I4X5DX
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-03-18 06:48:47 +00:00
openharmony_ci
6f04b5345c !639 【liteos_m】线程id判断存在问题
Merge pull request !639 from LiteOS/master
2022-03-18 05:04:13 +00:00
LiteOS2021
83b6331aad fix(线程id判断有误,cmsis优先级创建修改): 线程id判断有误,cmsis优先级创建修改
线程id判断有误,cmsis优先级创建修改

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-03-18 11:16:51 +08:00
yinjiaming
67a5b580f6 fix: 修复配置Enable Dynamic Link Feature后编译报错的问题
【背景】
在menuconfig中开启Enable Dynamic Link Feature后,内核编译报错

【修改方案】
将Kconfig 文件中的DYNLINK 改为 KERNEL_DYNLINK

【影响】
对现有的产品编译不会有影响。

re #I4XZN3

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I0a91b0f48fef78791307810e3780c53c17d7d0c8
2022-03-17 11:10:32 +00:00
yinjiaming
f5ee192962 fix: 修复开启lwip后编译失败的问题
【背景】
LWIP_STATS宏定义为0时开启lwip会有编译失败

【修改方案】
给可能重复定义的宏LWIP_STATS_DISPLAY 添加了相应的条件判断

【影响】
对现有的产品编译不会有影响。

re #I4X2DP

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Id1a4769dbbce4c56e8b681d9174be5aa54e74c02
2022-03-17 10:55:46 +00:00
openharmony_ci
a42ba7aed6 !633 chore:Kconfig调整
Merge pull request !633 from Zhaotianyu/0315Kconfig
2022-03-15 09:37:35 +00:00
arvinzzz
1fc024a158 chore: Kconfig 修改
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I3a6839a55cd63cab1493929269df86c19d278a90
2022-03-15 17:10:59 +08:00
openharmony_ci
21ee0b2c1d !631 C库性能优化
Merge pull request !631 from Zhaotianyu/0314libc_opt
2022-03-14 14:13:08 +00:00
openharmony_ci
b0cfa5e52c !632 Fix:内源代码检视用例问题
Merge pull request !632 from xuxinyu/Fixmem
2022-03-14 13:52:53 +00:00
x_xiny
543732f522 fix:根据内源代码检视意见对用例进行整改
【背景】3.1代码review问题修改

    【修改方案】
     修复用例问题

     Signed-off-by: xuiny <xuxinyu6@huawei.com>

Change-Id: I8ee5d8f5f5765e469cf72c810af8a3831a3879f9
2022-03-14 21:38:55 +08:00
arvinzzz
dab1a0d62f feature: libc opt
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I9252c83e5b8a40f23e0df04ea165b9f51a4482b3
2022-03-14 19:47:45 +08:00
openharmony_ci
6a8f24ba01 !626 Fix : 修改了源码检视过程中的一些问题
Merge pull request !626 from yinjiaming/master
2022-03-14 11:08:14 +00:00
openharmony_ci
40bbb4d6c4 !628 fix: 删除测试用例中的工号
Merge pull request !628 from zhushengle/sample
2022-03-14 08:24:05 +00:00
zhushengle
90a027090a fix: 删除测试用例中的工号
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7f83a26a5bbf2bc53b614e9fce68e26ed2c6352b
2022-03-14 15:15:52 +08:00
yinjiaming
bcd177bbd3 fix: 修复3.1代码检视中的问题
【背景】
3.1 代码检视中有一些问题需要修改

【修改方案】
在README 中添加了文档链接,更改了非可执行文件的权限

【影响】
对现有的产品编译不会有影响。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I25eb1a2bfcbfdf7bc40b0516bcf9262c2d67f8b4
2022-03-14 06:57:32 +00:00
openharmony_ci
cde2b3bd31 !627 修复L0 fs Opendir打开失败返回值不为空问题
Merge pull request !627 from 龙幸开/master
2022-03-11 06:53:18 +00:00
longxingkai
e3e9b2f5a5 fix fs opendir bug
Signed-off-by: longxingkai <longxingkai@talkweb.com.cn>
2022-03-11 10:23:38 +08:00
openharmony_ci
536e9b4584 !619 fix: 内源代码检视问题
Merge pull request !619 from xuxinyu/fix
2022-03-10 12:15:52 +00:00
x_xiny
632ea10418 fix:内源代码检视修改
【背景】3.1代码review问题修改

    【修改方案】

     re #I4WV56

     Signed-off-by: xuiny <xuxinyu6@huawei.com>

Change-Id: I1f3d98ab84b739c5d3a924559b1825659dc0ea74
2022-03-10 19:33:41 +08:00
openharmony_ci
73b77d11a1 !625 修复FileSystem menuconfig配置问题
Merge pull request !625 from 方烨/develop
2022-03-10 01:58:53 +00:00
fangye
9aa32ae743 fix: 修复FileSystem menuconfig配置问题
Signed-off-by: fangye <fangye@talkweb.com.cn>
Change-Id: Ibbac507ec290657489e47a708d2926ec709fa6b8
2022-03-10 09:27:16 +08:00
openharmony_ci
133e87b1b1 !380 refactor: liteos-m vfs refactory
Merge pull request !380 from MGY917/m-vfs
2022-03-09 07:34:01 +00:00
Guangyao Ma
09034de68a refactor: liteos-m vfs refactory
close #I4RV26

Change-Id: I76d5d5128d37efa5fbcde6d105c78f4d7be607de
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
2022-03-09 12:07:15 +08:00
openharmony_ci
867a6edcdc !621 M核内源代码检视问题修改
Merge pull request !621 from wangchen/0308_m
2022-03-09 02:27:20 +00:00
bob_qu
3dceae52aa feat:增加玄铁ck804ef架构内核支持文件
合入原因:按照规划增加winnermicro w800芯片OH适配
          需要新增CK804芯片架构支持代码
修改:在kernel/liteos_m、device/soc、device/board、vendor/hihope
       仓下增加CK804芯片架构、芯片SDK、开发板和产品配置文件
影响:由于是新增芯片架构,与其他平台编译隔离,无副作用

Signed-off-by: bob_qu <qu_bo@hoperun.com>
2022-03-08 20:17:49 +08:00
wangchen
43baa4fdc4 fix: 内源代码检视问题
【背景】内源代码检视问题

【修改方案】
1,按检视意见,进行资源泄露等问题的修改

【影响】
对现有的产品编译不会有影响。

re #I4WV56
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-03-08 09:38:03 +00:00
openharmony_ci
bedef30658 !615 fix: 修复codex及合规问题
Merge pull request !615 from Zhaotianyu/0307codex_fix
2022-03-08 08:06:30 +00:00
openharmony_ci
7e284239b3 !613 fix: 文档与实际代码目录保持一致
Merge pull request !613 from Zhaotianyu/0305md_fix
2022-03-07 12:18:31 +00:00
arvinzzz
f34b94e98d fix: codex等问题修复
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib2c46be5e117fab5506bb7b5229f31e611195f1b
2022-03-07 16:16:26 +08:00
arvinzzz
bc33bcd319 fix: 文档与实际代码目录不符
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ic07896cac1c32de38d86206a5cae9f419f0cf8dd
2022-03-05 17:14:24 +08:00
openharmony_ci
ae7a374ebb !573 M核安全隔离
Merge pull request !573 from Zhaotianyu/0117sec_init
2022-03-03 13:42:06 +00:00
arvinzzz
fb76350771 feature:M核安全隔离
新增用户态,上层业务进行box隔离,共享C库

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib6ecc3fcb230a7539f9e0f3663290900198d2ba9
2022-03-03 20:41:15 +08:00
openharmony_ci
ea5b2e8ae4 !612 代码检视意见清零
Merge pull request !612 from JerryH/pipe_poll
2022-03-03 07:01:44 +00:00
JerryH
c5a3ed4fb1 fix: 处理检视出来的代码问题
close #I4VY0A

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I3bc2d3da95ecae53b3d124d086b8296ea4608d3a
2022-03-02 16:02:32 +08:00
91 changed files with 5229 additions and 2964 deletions

13
Kconfig
View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -317,7 +317,7 @@ config CPUP_INCLUDE_IRQ
help
If you wish to include irq usage for cpup.
config DYNLINK
config KERNEL_DYNLINK
bool "Enable Dynamic Link Feature"
default n
depends on KERNEL_EXTKERNEL && ARCH_ARM
@@ -600,11 +600,11 @@ endmenu
######################## config options os security #######################
menu "Security"
osource "security/Kconfig"
config SECURE_TRUSTZONE
bool "Enable ARM TrustZone"
default n
depends on ARCH_ARM
depends on ARCH_ARM_V8M
config SECURE_HEAP_SIZE
int "TrustZone Heap Size (bytes)"
default 2048
@@ -615,6 +615,13 @@ config SECURE_STACK_DEFAULT_SIZE
depends on SECURE_TRUSTZONE
help
The secure stack must be allocated before the task calls non-secure functions.
config SECURE
bool "Enable Security"
default n
select MPU_ENABLE
config MPU_ENABLE
bool "Enable MPU"
default n
endmenu
menu "Test"

View File

@@ -39,7 +39,8 @@ module_group("arch") {
"$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" ||
"$board_cpu" == "cortex-m33" || "$board_cpu" == "cortex-m55") {
modules += [ "arm" ]
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") {
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802" ||
"$board_cpu" == "ck804ef") {
modules += [ "csky" ]
} else if ("$board_cpu" == "") {
if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") {

View File

@@ -16,12 +16,16 @@ config ARCH_ARM_AARCH32
config ARCH_ARM_V7M
bool
config ARCH_ARM_V8M
bool
config ARCH_ARM_V5TE
bool
config ARCH_ARM_VER
string
default "armv7-m" if ARCH_ARM_V7M
default "armv8-m" if ARCH_ARM_V8M
default "armv5te" if ARCH_ARM_V5TE
#
@@ -84,23 +88,20 @@ config ARCH_CORTEX_M7
select ARCH_ARM_AARCH32
select ARCH_FPU_VFP_V4
select ARCH_FPU_VFP_D32
select ARCH_FPU_VFP_NEON
config ARCH_CORTEX_M33
bool
select ARCH_ARM_V7M
select ARCH_ARM_V8M
select ARCH_ARM_AARCH32
select ARCH_FPU_VFP_V4
select ARCH_FPU_VFP_D32
select ARCH_FPU_VFP_NEON
config ARCH_CORTEX_M55
bool
select ARCH_ARM_V7M
select ARCH_ARM_V8M
select ARCH_ARM_AARCH32
select ARCH_FPU_VFP_V4
select ARCH_FPU_VFP_D32
select ARCH_FPU_VFP_NEON
config ARCH_ARM9
bool

View File

@@ -576,19 +576,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -572,14 +572,14 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsTickHandler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = OsTickHandler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -572,14 +572,14 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsTickHandler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = OsTickHandler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -577,19 +577,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -577,19 +577,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -121,6 +121,29 @@ typedef struct TagTskContext {
*/
extern VOID HalStartToRun(VOID);
#if (LOSCFG_SECURE == 1)
/**
* @ingroup los_config
* @brief: User Task Stack Initialize.
*
* @par Description:
* This API is used to init a user task stack.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param: context [IN] Task context.
* @param: taskEntry [IN] Task entry function address.
* @param: stack [IN] Task stack address.
*
* @retval None.
*
* @par Dependency: <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack);
#endif
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -148,6 +148,15 @@ VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandl
return (VOID *)context;
}
#if (LOSCFG_SECURE == 1)
VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
{
context->uwR0 = stack;
context->uwPC = (UINT32)taskEntry;
context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
}
#endif
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
{
(VOID)LOS_IntLock();

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -40,6 +40,12 @@
.equ OS_NVIC_PENDSV_PRI, 0xF0F00000
.equ OS_NVIC_PENDSVSET, 0x10000000
.equ OS_TASK_STATUS_RUNNING, 0x0010
.equ OS_CONTROL_FPCA_ENABLE, 0x4
.equ OS_CONTROL_KERNEL_MODE, 0x2
#if (LOSCFG_SECURE == 1)
.equ OS_CONTROL_USER_MODE, 0x3
.equ OS_TASK_FLAG_USER_TASK, 0x0200
#endif
.section .text
.thumb
@@ -63,7 +69,7 @@ HalStartToRun:
ldr r5, =OS_NVIC_PENDSV_PRI
str r5, [r4]
mov r0, #2
mov r0, #OS_CONTROL_KERNEL_MODE
msr CONTROL, r0
ldr r1, =g_losTask
@@ -141,7 +147,7 @@ ArchTaskSchedule:
bx lr
dsb
isb
.fnend
.fnend
.type HalPendSV, %function
.global HalPendSV
@@ -194,6 +200,14 @@ SignalContextRestore:
vldmia r1!, {d8-d15}
__DisabledFPU2:
#if (LOSCFG_SECURE == 1)
ldrh r7, [r0, #4]
tst r7, #OS_TASK_FLAG_USER_TASK
ite eq
moveq r3, #OS_CONTROL_KERNEL_MODE
movne r3, #OS_CONTROL_USER_MODE
msr CONTROL, r3
#endif
ldmfd r1!, {r4-r12}
msr psp, r1

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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,15 +57,15 @@
.equ FLAG_ADDR_VALID, 0x10000
.equ FLAG_HWI_ACTIVE, 0x20000
.equ FLAG_NO_FLOAT, 0x10000000
.equ FLAG_NO_FLOAT, 0x10000000
.equ OS_NVIC_FSR , 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
.equ OS_NVIC_HFSR , 0xE000ED2C //HardFault State Register
.equ OS_NVIC_BFAR , 0xE000ED38
.equ OS_NVIC_MMAR , 0xE000ED34
.equ OS_NVIC_ACT_BASE , 0xE000E300
.equ OS_NVIC_SHCSRS , 0xE000ED24
.equ OS_NVIC_SHCSR_MASK , 0xC00
.equ OS_NVIC_FSR, 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
.equ OS_NVIC_HFSR, 0xE000ED2C //HardFault State Register
.equ OS_NVIC_BFAR, 0xE000ED38
.equ OS_NVIC_MMAR, 0xE000ED34
.equ OS_NVIC_ACT_BASE, 0xE000E300
.equ OS_NVIC_SHCSRS, 0xE000ED24
.equ OS_NVIC_SHCSR_MASK, 0xC00
.type HalExcNMI, %function
.global HalExcNMI
@@ -155,10 +155,25 @@ HalExcSvcCall:
.cantunwind
TST LR, #0x4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
LDR R1, [R0,#24]
LDRB R0, [R1,#-2]
MRSEQ R1, MSP
BNE _svcCallFromPsp
B _svcCall
_svcCallFromPsp:
#ifdef LOSCFG_SECURE
PUSH {R0-R12, LR}
MOV R0, SP
CPSIE I
BL OsSyscallHandle
CPSID I
MRS R12, PSP
STM R12, {R0-R1}
POP {R0-R12, LR}
BX LR
#endif
MRS R1, PSP
_svcCall:
LDR R0, [R1,#24]
LDRB R0, [R0,#-2]
MOV R1, #0
B osExcDispatch
.fnend
@@ -284,7 +299,7 @@ _ExcInMSP:
PUSH {R4-R12} // store message-->exc: {R4-R12}
VPUSH {D8-D15} // FPU
B _handleEntry
.fnend
.fnend
.type _NoFloatInMsp, %function
.global _NoFloatInMsp
@@ -298,7 +313,7 @@ _NoFloatInMsp:
PUSH {R4-R12} // store message-->exc: {R4-R12}
ORR R0, R0, #FLAG_NO_FLOAT
B _handleEntry
.fnend
.fnend
.type _hwiActiveCheckNext, %function
.global _hwiActiveCheckNext
@@ -347,7 +362,7 @@ _hwiActiveCheckNext:
VSTMDB R2!, {D8-D15} // FPU
STMFD R2!, {R4-R11}
B _handleEntry
.fnend
.fnend
.type _NoFloatInPsp, %function
.global _NoFloatInPsp
@@ -367,7 +382,7 @@ _NoFloatInPsp:
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
STMFD R2!, {R4-R11}
ORR R0, R0, #FLAG_NO_FLOAT
.fnend
.fnend
.type _handleEntry, %function
.global _handleEntry
@@ -380,4 +395,4 @@ _handleEntry:
B HalExcHandleEntry
NOP
.fnend
.fnend

View File

@@ -580,19 +580,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -578,19 +578,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -580,14 +580,14 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsTickHandler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = OsTickHandler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -137,7 +137,7 @@ ArchTaskSchedule:
dsb
isb
bx lr
.fnend
.fnend
.type HalPendSV, %function
.global HalPendSV
@@ -178,7 +178,7 @@ TaskContextSwitch:
str r0, [r5]
ldr r1, [r0]
SignalContextRestore:
SignalContextRestore:
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
vldmia r1!, {d8-d15}

View File

@@ -29,9 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.syntax unified
.arch armv7e-m
.thumb
.syntax unified
.arch armv7e-m
.thumb
.fpu fpv5-d16
.section .text
@@ -284,7 +284,7 @@ _ExcInMSP:
PUSH {R4-R12} // store message-->exc: {R4-R12}
VPUSH {D8-D15}
B _handleEntry
.fnend
.fnend
.type _NoFloatInMsp, %function
.global _NoFloatInMsp
@@ -298,7 +298,7 @@ _NoFloatInMsp:
PUSH {R4-R12} // store message-->exc: {R4-R12}
ORR R0, R0, #FLAG_NO_FLOAT
B _handleEntry
.fnend
.fnend
.type _hwiActiveCheckNext, %function
.global _hwiActiveCheckNext
@@ -347,7 +347,7 @@ _hwiActiveCheckNext:
VSTMDB R2!, {D8-D15}
STMFD R2!, {R4-R11}
B _handleEntry
.fnend
.fnend
.type _NoFloatInPsp, %function
.global _NoFloatInPsp
@@ -367,7 +367,7 @@ _NoFloatInPsp:
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
STMFD R2!, {R4-R11}
ORR R0, R0, #FLAG_NO_FLOAT
.fnend
.fnend
.type _handleEntry, %function
.global _handleEntry
@@ -380,5 +380,5 @@ _handleEntry:
B HalExcHandleEntry
NOP
.fnend
.fnend

View File

@@ -565,19 +565,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -574,19 +574,19 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)SysTick_Handler;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;

View File

@@ -59,13 +59,33 @@ typedef struct TagTskContext {
UINT32 R12;
UINT32 R13;
UINT32 R15;
#ifdef CPU_CK804
UINT32 R16;
UINT32 R17;
UINT32 R18;
UINT32 R19;
UINT32 R20;
UINT32 R21;
UINT32 R22;
UINT32 R23;
UINT32 R24;
UINT32 R25;
UINT32 R26;
UINT32 R27;
UINT32 R28;
UINT32 R29;
UINT32 R30;
UINT32 R31;
#endif
UINT32 EPSR;
UINT32 EPC;
} TaskContext;
VOID HalStartToRun(VOID);
VOID HalTaskContextSwitch(VOID);
#ifndef CPU_CK804
VOID HalIrqEndCheckNeedSched(VOID);
#endif
#ifdef __cplusplus
#if __cplusplus

View File

@@ -82,7 +82,7 @@ typedef VOID (**HWI_VECTOR_FUNC)(VOID);
* @ingroup los_arch_interrupt
* Count of interrupts.
*/
extern UINT32 g_intCount;
extern volatile UINT32 g_intCount;
/* *
* @ingroup los_arch_interrupt

View File

@@ -38,7 +38,9 @@
#include "los_interrupt.h"
#include "los_debug.h"
#ifndef CPU_CK804
STATIC UINT32 g_sysNeedSched = FALSE;
#endif
/* ****************************************************************************
Function : ArchInit
@@ -93,8 +95,29 @@ LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VO
context->R11 = 0x11111111L;
context->R12 = 0x12121212L;
context->R13 = 0x13131313L;
#ifdef CPU_CK804
context->R15 = (UINT32)ArchSysExit;
context->R16 = 0x16161616L;
context->R17 = 0x17171717L;
context->R18 = 0x18181818L;
context->R19 = 0x19191919L;
context->R20 = 0x20202020L;
context->R21 = 0x21212121L;
context->R22 = 0x22222222L;
context->R23 = 0x23232323L;
context->R24 = 0x24242424L;
context->R25 = 0x25252525L;
context->R26 = 0x26262626L;
context->R27 = 0x27272727L;
context->R28 = 0x28282828L;
context->R29 = 0x29292929L;
context->R30 = 0x30303030L;
context->R31 = 0x31313131L;
context->EPSR = 0x80000340L;
#else
context->R15 = (UINT32)ArchSysExit;
context->EPSR = 0xe0000144L;
#endif
context->EPC = (UINT32)OsTaskEntry;
return (VOID *)context;
}
@@ -107,6 +130,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
return LOS_OK; /* never return */
}
#ifndef CPU_CK804
VOID HalIrqEndCheckNeedSched(VOID)
{
if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
@@ -132,3 +156,10 @@ VOID ArchTaskSchedule(VOID)
LOS_IntRestore(intSave);
return;
}
#else
VOID ArchTaskSchedule(VOID)
{
HalTaskContextSwitch();
}
#endif

View File

@@ -32,6 +32,89 @@
#define OS_TASK_STATUS_RUNNING 0x0010
#define VIC_TSPDR 0XE000EC08
#ifdef CPU_CK804
.section .text
.align 2
.type HalStartToRun, %function
.global HalStartToRun
HalStartToRun:
lrw r1, g_losTask
lrw r2, g_losTask + 4
ldw r0, (r2)
st.w r0, (r1)
st.w r0, (r2)
ldw sp, (r0)
ldw r0, (sp, 128)
mtcr r0, epc
ldw r0, (sp, 124)
mtcr r0, epsr
ldw r15, (sp, 56)
ldm r0-r13, (sp)
addi sp, 60
ldm r16-r31, (sp)
addi sp, 72
rte
.align 2
.type HalTaskContextSwitch, %function
.global HalTaskContextSwitch
HalTaskContextSwitch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
nop
nop
nop
rts
.align 2
.type tspend_handler, %function
.global tspend_handler
tspend_handler:
subi sp, 132
stm r0-r13, (sp)
stw r15, (sp, 56)
addi r0, sp, 60
stm r16-r31, (r0)
mfcr r1, epsr
stw r1, (sp, 124)
mfcr r1, epc
stw r1, (sp, 128)
jbsr OsSchedTaskSwitch
bez r0, ret_con
lrw r2, g_losTask
ldw r0, (r2)
stw sp, (r0)
lrw r3, g_losTask + 4
ldw r0, (r3)
stw r0, (r2)
ldw sp, (r0)
ret_con:
ldw r0, (sp, 128)
mtcr r0, epc
ldw r0, (sp, 124)
mtcr r0, epsr
ldw r15, (sp, 56)
ldm r0-r13, (sp)
addi sp, 60
ldm r16-r31, (sp)
addi sp, 72
rte
#else
.section .text
.align 2
.type HalStartToRun, %function
@@ -87,3 +170,4 @@ HalTaskContextSwitch:
rte
#endif

View File

@@ -32,6 +32,57 @@
.import HalExcHandleEntry
.extern g_trapStackBase
#ifdef CPU_CK804
.section .text
.align 2
.global HandleEntry
HandleEntry:
mov r10, sp
lrw r14, g_trapStackBase
stm r0-r15, (sp)
stw r10, (sp, 56)
addi r0, sp, 64
stm r16-r31, (r0)
mfcr r0, epsr
stw r0, (sp, 128)
mfcr r0, epc
stw r0, (sp, 132)
mov r0, sp
mfcr r1, epc
mov sp, r10
lrw r2, HalExcHandleEntry
jmp r2
.section .text
.align 2
.global IrqEntry
IrqEntry:
psrset ee
subi sp, 136
stm r0-r15, (sp)
addi r0, sp, 64
stm r16-r31, (r0)
mfcr r0, epsr
stw r0, (sp, 128)
mfcr r0, epc
stw r0, (sp, 132)
jbsr HalInterrupt
ldw r0, (sp, 132)
mtcr r0, epc
ldw r0, (sp, 128)
bseti r0, r0, 6
mtcr r0, epsr
ldm r0-r15, (sp)
addi sp, 64
ldm r16-r31, (sp)
addi sp, 72
rte
#else
.section .text
.align 2
.global HandleEntry
@@ -75,3 +126,4 @@ IrqEntry:
ldm r0-r15, (sp)
addi sp, 72
rte
#endif

View File

@@ -52,13 +52,12 @@
#define MASK_8_BITS 0xFF
#define MASK_32_BITS 0xFFFFFFFF
#define BYTES_OF_128_INT 4
#define TIM_INT_NUM 1
#define OS_USER_HWI_MIN 0
#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
#define HWI_ALIGNSIZE 0x400
UINT32 g_intCount = 0;
UINT32 volatile g_intCount = 0;
CHAR g_trapStackBase[OS_TRAP_STACK_SIZE];
VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
@@ -334,7 +333,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
intSave = LOS_IntLock();
g_intCount--;
#ifndef CPU_CK804
HalIrqEndCheckNeedSched();
#endif
LOS_IntRestore(intSave);
}
@@ -586,6 +587,10 @@ WEAK VOID __stack_chk_fail(VOID)
__builtin_return_address(0));
}
WEAK void HalHwiHandleReInit(UINT32 hwiFormAddr)
{
}
/* ****************************************************************************
Function : HalHwiInit
Description : initialization of the hardware interrupt
@@ -604,6 +609,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) {
g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry;
}
HalHwiHandleReInit((UINT32)&g_hwiForm);
HalSetVbr((UINT32)&g_hwiForm);
for (int i = 0; i < BYTES_OF_128_INT; i++) {

View File

@@ -50,7 +50,11 @@ typedef struct {
#define CORETIM_SOURCE (1UL << 2)
#define CORETIM_MODE (1UL << 16)
#ifdef CPU_CK804
#define TIM_INT_NUM 25
#else
#define TIM_INT_NUM 1
#endif
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);

View File

@@ -48,7 +48,9 @@
│ ├── lms --- Lite memory sanitizer functions
│ ├── net --- Networking functions
│ ├── power --- Power management
│ ├── security --- Security isolation
│ ├── shell --- Shell function
│ ├── signal --- Signal support
│ ├── fs --- File systems
│ └── trace --- Trace tool
├── drivers --- driver Kconfig
@@ -71,14 +73,13 @@
│   │   └── los_tick.h --- Tick
│   └── src
├── targets
│   └── targets
   ── riscv_nuclei_demo_soc_gcc
│ ├── GCC --- Compilation config
│ ├── OS_CONFIG --- Board config
── SoC --- SOC codes
│ └── Src --- Application codes
│   └── riscv_nuclei_gd32vf103_soc_gcc
│   └── riscv_sifive_fe310_gcc
│   └── riscv_nuclei_demo_soc_gcc
── GCC --- Compilation config
│ │ ├── OS_CONFIG --- Board config
│ │ ├── SoC --- SOC codes
│ │ ── Src --- Application codes
   └── riscv_nuclei_gd32vf103_soc_gcc
│   └── riscv_sifive_fe310_gcc
├── testsuites --- Kernel testsuites
├── tools --- Kernel tools
└── utils

View File

@@ -48,7 +48,9 @@
│ ├── lms --- Lite memory sanitizer 机制
│ ├── net --- Network功能
│ ├── power --- 低功耗管理
│ ├── security --- 安全隔离
│ ├── shell --- shell功能
│ ├── signal --- signal支持
│ └── trace --- trace 工具
├── drivers --- 驱动框架Kconfig
├── kal --- 内核抽象层提供内核对外接口当前支持CMSIS接口和部分POSIX接口
@@ -70,14 +72,13 @@
│   │   └── los_tick.h --- Tick时钟
   └── src
├── targets
   └── targets
   ── riscv_nuclei_demo_soc_gcc
│ ├── GCC --- 编译相关
│ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
── SoC --- SOC相关代码
│ └── Src --- Application相关代码
   └── riscv_nuclei_gd32vf103_soc_gcc
│   └── riscv_sifive_fe310_gcc
└── riscv_nuclei_demo_soc_gcc
── GCC --- 编译相关
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
│ │ ├── SoC --- SOC相关代码
│ │ ── Src --- Application相关代码
└── riscv_nuclei_gd32vf103_soc_gcc
│ └── riscv_sifive_fe310_gcc
├── testsuites --- 内核测试用例
├── tools --- 内核工具
└── utils

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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 @@ group("components") {
"lms",
"net",
"power",
"security",
"shell",
"signal",
"trace",
@@ -57,6 +58,7 @@ config("public") {
"fs:public",
"net:public",
"power:public",
"security:public",
"shell:public",
"trace:public",
"lmk:public",

View File

@@ -36,39 +36,3 @@ config FS_FAT
help
Answer Y to enable LiteOS support fat filesystem.
config FS_FAT_CACHE
bool "Enable FAT Cache"
default y
depends on FS_FAT
help
Answer Y to enable LiteOS fat filesystem support cache.
config FS_FAT_CACHE_SYNC_THREAD
bool "Enable FAT Cache Sync Thread"
default n
depends on FS_FAT_CACHE
help
Answer Y to enable LiteOS fat filesystem support cache sync thread.
config FS_FAT_CHINESE
bool "Enable Chinese"
default y
depends on FS_FAT
help
Answer Y to enable LiteOS fat filesystem support Chinese.
config FS_FAT_VIRTUAL_PARTITION
bool "Enabel Virtual Partition"
default n
depends on FS_FAT
config FS_FAT_VOLUMES
int
depends on FS_FAT
default 32 if PLATFORM_HI3731
default 16
config FS_FAT_DISK
bool "Enable partinfo for storage device"
depends on FS_FAT
default y

File diff suppressed because it is too large Load Diff

View File

@@ -32,14 +32,7 @@
#ifndef _FATFS_H
#define _FATFS_H
#include "dirent.h"
#include "fatfs_conf.h"
#include "fcntl.h"
#include "fs_config.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#include "unistd.h"
#include "ff.h"
#ifdef __cplusplus
#if __cplusplus
@@ -47,58 +40,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int fatfs_mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
int fatfs_umount(const char *target);
int fatfs_umount2(const char *target, int flag);
int fatfs_open(const char *path, int oflag, ...);
int fatfs_close(int fd);
ssize_t fatfs_read(int fd, void *buf, size_t nbyte);
ssize_t fatfs_write(int fd, const void *buf, size_t nbyte);
off_t fatfs_lseek(int fd, off_t offset, int whence);
int fatfs_unlink(const char *path);
int fatfs_fstat(int fd, struct stat *buf);
int fatfs_stat(const char *path, struct stat *buf);
int fatfs_fsync(int fd);
int fatfs_mkdir(const char *path, mode_t mode);
DIR *fatfs_opendir(const char *dirName);
struct dirent *fatfs_readdir(DIR *dir);
int fatfs_closedir(DIR *dir);
int fatfs_rmdir(const char *path);
int fatfs_rename(const char *oldName, const char *newName);
int fatfs_statfs(const char *path, struct statfs *buf);
int fatfs_ftruncate(int fd, off_t length);
ssize_t fatfs_pread(int fd, void *buf, size_t nbyte, off_t offset);
ssize_t fatfs_pwrite(int fd, const void *buf, size_t nbyte, off_t offset);
/**
* @brief divide a physical drive (SD card, U disk, and MMC card), this function is OHOS-specific
* @param pdrv physical drive number.
* @param partTbl list of partition size to create on the drive.
* -- item is <= 100: specifies the partition size in percentage of the entire drive space.
* -- item is > 100: specifies number of sectors.
* @return fdisk result
* @retval -1 fdisk error
* @retval 0 fdisk successful
*/
int fatfs_fdisk(int pdrv, const unsigned int *partTbl);
/**
* @brief format FAT device (SD card, U disk, and MMC card), this function is OHOS-specific
* @param dev device name.
* @param sectors sectors per cluster, can be 0 OR power of 2. The sector size for standard FAT volumes is 512 bytes.
* -- sector number is 0 OR >128: automatically choose the appropriate cluster size.
* -- sector number is 1 ~ 128: cluster size = sectors per cluster * 512B.
* @param option file system type.
* -- FMT_FAT
* -- FMT_FAT32
* -- FMT_ANY
* @return format result
* @retval -1 format error
* @retval 0 format successful
*/
int fatfs_format(const char *dev, int sectors, int option);
void FatFsInit(void);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -34,7 +34,7 @@ module_switch = defined(LOSCFG_FS_LITTLEFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
configs += [ "$LITEOSTOPDIR:warn_config" ]
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_api.c" ]
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_adapter.c" ]
}
config("public") {

View File

@@ -0,0 +1,596 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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.
*/
#define _GNU_SOURCE 1
#include "lfs_adapter.h"
#include "los_config.h"
#include "vfs_files.h"
#include "vfs_operations.h"
#include "vfs_partition.h"
#include "vfs_maps.h"
#include "vfs_mount.h"
#include "securec.h"
struct dirent g_nameValue;
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
static int ConvertFlagToLfsOpenFlag (int oflags)
{
int lfsOpenFlag = 0;
if (oflags & O_CREAT) {
lfsOpenFlag |= LFS_O_CREAT;
}
if (oflags & O_EXCL) {
lfsOpenFlag |= LFS_O_EXCL;
}
if (oflags & O_TRUNC) {
lfsOpenFlag |= LFS_O_TRUNC;
}
if (oflags & O_APPEND) {
lfsOpenFlag |= LFS_O_APPEND;
}
if (oflags & O_RDWR) {
lfsOpenFlag |= LFS_O_RDWR;
}
if (oflags & O_WRONLY) {
lfsOpenFlag |= LFS_O_WRONLY;
}
if (oflags == O_RDONLY) {
lfsOpenFlag |= LFS_O_RDONLY;
}
return lfsOpenFlag;
}
static int LittlefsErrno(int result)
{
return (result < 0) ? -result : result;
}
int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
{
int ret;
lfs_t *mountHdl = NULL;
if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) {
errno = EFAULT;
ret = LOS_NOK;
goto errout;
}
mountHdl = (lfs_t *)malloc(sizeof(lfs_t));
if (mountHdl == NULL) {
errno = ENODEV;
ret = LOS_NOK;
goto errout;
}
(void)memset_s(mountHdl, sizeof(lfs_t), 0, sizeof(lfs_t));
mp->mData = (void *)mountHdl;
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config *)data);
if (ret != 0) {
ret = lfs_format((lfs_t *)mp->mData, (struct lfs_config*)data);
if (ret == 0) {
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config*)data);
}
}
if (ret != 0) {
free(mountHdl);
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
errout:
return ret;
}
int LfsUmount(struct MountPoint *mp)
{
int ret;
if (mp == NULL) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
ret = lfs_unmount((lfs_t *)mp->mData);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
free(mp->mData);
mp->mData = NULL;
return ret;
}
int LfsUnlink(struct MountPoint *mp, const char *fileName)
{
int ret;
if ((mp == NULL) || (fileName == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
ret = lfs_remove((lfs_t *)mp->mData, fileName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsMkdir(struct MountPoint *mp, const char *dirName)
{
int ret;
if ((dirName == NULL) || (mp == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
lfs_t *lfs = (lfs_t *)mp->mData;
ret = lfs_mkdir(lfs, dirName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsRmdir(struct MountPoint *mp, const char *dirName)
{
int ret;
lfs_t *lfs = NULL;
if (mp == NULL) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
lfs = (lfs_t *)mp->mData;
if (dirName == NULL) {
errno = EFAULT;
return LOS_NOK;
}
ret = lfs_remove(lfs, dirName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsOpendir(struct Dir *dir, const char *dirName)
{
int ret;
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
lfs_dir_t *dirInfo = (lfs_dir_t *)malloc(sizeof(lfs_dir_t));
if (dirInfo == NULL) {
errno = ENOMEM;
return LOS_NOK;
}
(void)memset_s(dirInfo, sizeof(lfs_dir_t), 0, sizeof(lfs_dir_t));
ret = lfs_dir_open(lfs, dirInfo, dirName);
if (ret != 0) {
free(dirInfo);
errno = LittlefsErrno(ret);
goto errout;
}
dir->dData = dirInfo;
dir->dOffset = 0;
return LOS_OK;
errout:
return LOS_NOK;
}
int LfsReaddir(struct Dir *dir, struct dirent *dent)
{
int ret;
struct lfs_info lfsInfo;
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL) ||
(dent == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (dir->dData == NULL) {
errno = EBADF;
return LOS_NOK;
}
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
ret = lfs_dir_read(lfs, dirInfo, &lfsInfo);
if (ret == TRUE) {
pthread_mutex_lock(&g_FslocalMutex);
(void)strncpy_s(dent->d_name, sizeof(dent->d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
if (lfsInfo.type == LFS_TYPE_DIR) {
dent->d_type = DT_DIR;
} else if (lfsInfo.type == LFS_TYPE_REG) {
dent->d_type = DT_REG;
}
dent->d_reclen = lfsInfo.size;
pthread_mutex_unlock(&g_FslocalMutex);
return LOS_OK;
}
if (ret != 0) {
errno = LittlefsErrno(ret);
}
return LOS_NOK;
}
int LfsClosedir(struct Dir *dir)
{
int ret;
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (dir->dData == NULL) {
errno = EBADF;
return LOS_NOK;
}
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
ret = lfs_dir_close(lfs, dirInfo);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
free(dirInfo);
dir->dData = NULL;
return ret;
}
int LfsOpen(struct File *file, const char *pathName, int openFlag)
{
int ret;
lfs_file_t *lfsHandle = NULL;
if ((pathName == NULL) || (file == NULL) || (file->fMp == NULL) ||
(file->fMp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
lfsHandle = (lfs_file_t *)malloc(sizeof(lfs_file_t));
if (lfsHandle == NULL) {
errno = ENOMEM;
return LOS_NOK;
}
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
ret = lfs_file_open((lfs_t *)file->fMp->mData, lfsHandle, pathName, lfsOpenFlag);
if (ret != 0) {
free(lfsHandle);
errno = LittlefsErrno(ret);
goto errout;
}
file->fData = (void *)lfsHandle;
return ret;
errout:
return INVALID_FD;
}
int LfsRead(struct File *file, char *buf, size_t len)
{
int ret;
struct MountPoint *mp = NULL;
lfs_file_t *lfsHandle = NULL;
if (buf == NULL) {
errno = EFAULT;
return LOS_NOK;
}
if ((file == NULL) || (file->fData == NULL)) {
errno = EBADF;
return LOS_NOK;
}
lfsHandle = (lfs_file_t *)file->fData;
mp = file->fMp;
if ((mp == NULL) || (mp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
ret = lfs_file_read((lfs_t *)mp->mData, lfsHandle, buf, len);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsWrite(struct File *file, const char *buf, size_t len)
{
int ret;
struct MountPoint *mp = NULL;
lfs_file_t *lfsHandle = NULL;
if (buf == NULL) {
errno = EFAULT;
return LOS_NOK;
}
if ((file == NULL) || (file->fData == NULL)) {
errno = EBADF;
return LOS_NOK;
}
lfsHandle = (lfs_file_t *)file->fData;
mp = file->fMp;
if ((mp == NULL) || (mp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
ret = lfs_file_write((lfs_t *)mp->mData, lfsHandle, buf, len);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
off_t LfsSeek(struct File *file, off_t offset, int whence)
{
off_t ret;
struct MountPoint *mp = NULL;
lfs_file_t *lfsHandle = NULL;
if ((file == NULL) || (file->fData == NULL)) {
errno = EBADF;
return LOS_NOK;
}
lfsHandle = (lfs_file_t *)file->fData;
mp = file->fMp;
if ((mp == NULL) || (mp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
ret = (off_t)lfs_file_seek((lfs_t *)mp->mData, lfsHandle, offset, whence);
if (ret < 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsClose(struct File *file)
{
INT32 ret;
struct MountPoint *mp = NULL;
lfs_file_t *lfsHandle = NULL;
if ((file == NULL) || (file->fData == NULL)) {
errno = EBADF;
return LOS_NOK;
}
lfsHandle = (lfs_file_t *)file->fData;
mp = file->fMp;
if ((mp == NULL) || (mp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
pthread_mutex_lock(&g_FslocalMutex);
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
pthread_mutex_unlock(&g_FslocalMutex);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
free(file->fData);
file->fData = NULL;
return ret;
}
int LfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
{
int ret;
if ((mp == NULL) || (oldName == NULL) || (newName == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
ret = lfs_rename((lfs_t *)mp->mData, oldName, newName);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
{
int ret;
struct lfs_info info;
if ((mp == NULL) || (path == NULL) || (buf == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
if (mp->mData == NULL) {
errno = ENOENT;
return LOS_NOK;
}
ret = lfs_stat((lfs_t *)mp->mData, path, &info);
if (ret == 0) {
buf->st_size = info.size;
if (info.type == LFS_TYPE_REG) {
buf->st_mode = S_IFREG;
} else {
buf->st_mode = S_IFDIR;
}
} else {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
int LfsSync(struct File *file)
{
int ret;
struct MountPoint *mp = NULL;
if ((file == NULL) || (file->fData == NULL)) {
errno = EBADF;
return LOS_NOK;
}
if ((file->fMp == NULL) || (file->fMp->mData == NULL)) {
errno = EFAULT;
return LOS_NOK;
}
mp = file->fMp;
ret = lfs_file_sync((lfs_t *)mp->mData, (lfs_file_t *)file->fData);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = LOS_NOK;
}
return ret;
}
static struct MountOps g_lfsMnt = {
.mount = LfsMount,
.umount = LfsUmount,
.umount2 = NULL,
.statfs = NULL,
};
static struct FileOps g_lfsFops = {
.open = LfsOpen,
.close = LfsClose,
.read = LfsRead,
.write = LfsWrite,
.lseek = LfsSeek,
.stat = LfsStat,
.truncate = NULL,
.unlink = LfsUnlink,
.rename = LfsRename,
.ioctl = NULL, /* not support */
.sync = LfsSync,
.rmdir = LfsRmdir,
.opendir = LfsOpendir,
.readdir = LfsReaddir,
.closedir = LfsClosedir,
.mkdir = LfsMkdir,
};
static struct FsManagement g_lfsMgt = {
.fdisk = NULL,
.format = NULL,
};
void LfsInit(void)
{
(void)OsFsRegister("littlefs", &g_lfsMnt, &g_lfsFops, &g_lfsMgt);
}

View File

@@ -29,75 +29,22 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LFS_API_H_
#define _LFS_API_H_
#ifndef _LFS_ADAPTER_H_
#define _LFS_ADAPTER_H_
#include "fcntl.h"
#include "sys/stat.h"
#include "dirent.h"
#include "errno.h"
#include "fs_operations.h"
#include "vfs_operations.h"
#include "lfs.h"
#include "lfs_conf.h"
#include "lfs_util.h"
#include "memory.h"
#include "pthread.h"
#define INVALID_FD (-1)
#ifndef VFS_ERROR
#define VFS_ERROR (-1)
#endif
#ifndef VFS_OK
#define VFS_OK 0
#endif
typedef struct {
uint8_t useFlag;
const char *pathName;
lfs_t *lfsHandle;
lfs_file_t file;
} LittleFsHandleStruct;
struct FileOpInfo {
uint8_t useFlag;
const struct FileOps *fsVops;
char *dirName;
lfs_t lfsInfo;
};
typedef struct {
uint8_t useFlag;
char *dirName;
lfs_t *lfsHandle;
lfs_dir_t dir;
} FileDirInfo;
LittleFsHandleStruct *GetFreeFd(int *fd);
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
const void *data);
int LfsUmount(const char *target);
int LfsUnlink(const char *fileName);
int LfsMkdir(const char *dirName, mode_t mode);
int LfsRmdir(const char *dirName);
DIR *LfsOpendir(const char *dirName);
struct dirent *LfsReaddir(DIR *dir);
int LfsClosedir(DIR *dir);
int LfsOpen(const char *pathName, int openFlag, ...);
int LfsRead(int fd, void *buf, unsigned int len);
int LfsWrite(int fd, const void *buf, unsigned int len);
off_t LfsSeek(int fd, off_t offset, int whence);
int LfsClose(int fd);
int LfsRename(const char *oldName, const char *newName);
int LfsStat(const char *path, struct stat *buf);
int LfsFsync(int fd);
int LfsFstat(int fd, struct stat *buf);
int SetDefaultMountPath(int pathNameIndex, const char* target);
int LfsPread(int fd, void *buf, size_t nbyte, off_t offset);
int LfsPwrite(int fd, const void *buf, size_t nbyte, off_t offset);
#endif /* _LFS_API_H_ */
void LfsInit(void);
#endif /* _LFS_ADAPTER_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,4 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 +31,26 @@ import("//kernel/liteos_m/liteos.gni")
module_switch = defined(LOSCFG_FS_VFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_fs.c" ]
sources = [
"vfs_files.c",
"vfs_fs.c",
"vfs_init.c",
"vfs_maps.c",
"vfs_mount.c",
"vfs_partition.c",
]
include_dirs = [
"//kernel/liteos_m/kernel/arch/include",
"//kernel/liteos_m/kernel/include",
"//kernel/liteos_m/utils",
"../",
".",
]
deps = [ "//kernel/liteos_m/kal" ]
configs += [ "$LITEOSTOPDIR:warn_config" ]
cflags = [ "-Wno-parentheses" ]
}
config("public") {

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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,5 +30,6 @@
config FS_VFS
bool "Enable FS VFS"
default y
help
Answer Y to enable LiteOS support VFS.

View File

@@ -1,82 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FS_OPERATIONS_H_
#define _FS_OPERATIONS_H_
#include "fcntl.h"
#include "dirent.h"
#include "unistd.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#define FS_SUCCESS 0
#define FS_FAILURE (-1)
#define MAX_FILESYSTEM_LEN 2
struct MountOps {
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
const void *data);
int (*Umount)(const char* target);
int (*Umount2)(const char* target, int flag);
int (*Statfs)(const char *path, struct statfs *buf);
};
struct FsMap {
const char *fileSystemtype;
const struct MountOps *fsMops;
const struct FileOps *fsFops;
};
struct FileOps {
int (*Open)(const char *path, int openFlag, ...);
int (*Close)(int fd);
int (*Unlink)(const char *fileName);
int (*Rmdir)(const char *dirName);
int (*Mkdir)(const char *dirName, mode_t mode);
struct dirent *(*Readdir)(DIR *dir);
DIR *(*Opendir)(const char *dirName);
int (*Closedir)(DIR *dir);
int (*Read)(int fd, void *buf, size_t len);
int (*Write)(int fd, const void *buf, size_t len);
off_t (*Seek)(int fd, off_t offset, int whence);
int (*Getattr)(const char *path, struct stat *buf);
int (*Rename)(const char *oldName, const char *newName);
int (*Fsync)(int fd);
int (*Fstat)(int fd, struct stat *buf);
int (*Stat)(const char *path, struct stat *buf);
int (*Ftruncate)(int fd, off_t length);
int (*Pread)(int fd, void *buf, size_t nbyte, off_t offset);
int (*Pwrite)(int fd, const void *buf, size_t nbyte, off_t offset);
};
#endif /* _FS_OPERATIONS_H_ */

View File

@@ -1,653 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_fs.h"
#include "los_config.h"
#include "fs_operations.h"
#if (LOSCFG_SUPPORT_FATFS == 1)
#include "fatfs.h"
#endif
#include "dirent.h"
#include "errno.h"
#include "fcntl.h"
#include "securec.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sys/mount.h"
#include "sys/statfs.h"
#include "sys/stat.h"
#include "unistd.h"
#ifdef LOSCFG_NET_LWIP_SACK
#define _BSD_SOURCE
#include "lwip/sockets.h"
#endif
#include "vfs_config.h"
#ifdef LOSCFG_RANDOM_DEV
#include "hks_client.h"
#define RANDOM_DEV_FD CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS
#define RANDOM_DEV_PATH "/dev/random"
#endif
#if (LOSCFG_POSIX_PIPE_API == 1)
#include "pipe_impl.h"
#ifdef LOSCFG_RANDOM_DEV
#define PIPE_DEV_FD (RANDOM_DEV_FD + 1)
#else
#define PIPE_DEV_FD (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
#endif
int PollQueryFd(int fd, struct PollTable *table)
{
if (fd >= PIPE_DEV_FD) {
return PipePoll(fd, table);
}
return -ENODEV;
}
#endif
#define FREE_AND_SET_NULL(ptr) do { \
free(ptr); \
ptr = NULL; \
} while (0)
#ifdef LOSCFG_RANDOM_DEV
/**
* @brief Get canonical form of a given path based on cwd(Current working directory).
*
* @param cwd Indicates the current working directory.
* @param path Indicates the path to be canonicalization.
* @param buf Indicates the pointer to the buffer where the result will be return.
* @param bufSize Indicates the size of the buffer.
* @return Returns the length of the canonical path.
*
* @attention if path is an absolute path, cwd is ignored. if cwd if not specified, it is assumed to be root('/').
* if the buffer is not big enough the result will be truncated, but the return value will always be the
* length of the canonical path.
*/
static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, size_t bufSize)
{
size_t offset;
if (!path) {
path = "";
}
if (!cwd || path[0] == '/') {
cwd = "";
}
offset = strlen("///") + 1; // three '/' and one '\0'
size_t tmpLen = strlen(cwd) + strlen(path) + offset;
char *tmpBuf = (char *)malloc(tmpLen);
if (tmpBuf == NULL) {
return FS_SUCCESS;
}
if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
free(tmpBuf);
return FS_SUCCESS;
}
char *p;
/* replace /./ to / */
offset = strlen("/./") - 1;
while ((p = strstr(tmpBuf, "/./")) != NULL) {
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
free(tmpBuf);
return FS_SUCCESS;
}
}
/* replace // to / */
while ((p = strstr(tmpBuf, "//")) != NULL) {
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
free(tmpBuf);
return FS_SUCCESS;
}
}
/* handle /../ (e.g., replace /aa/bb/../ to /aa/) */
offset = strlen("/../") - 1;
while ((p = strstr(tmpBuf, "/../")) != NULL) {
char *start = p;
while (start > tmpBuf && *(start - 1) != '/') {
--start;
}
if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
free(tmpBuf);
return FS_SUCCESS;
}
}
size_t totalLen = strlen(tmpBuf);
/* strip the last / */
if (totalLen > 1 && tmpBuf[totalLen - 1] == '/') {
tmpBuf[--totalLen] = 0;
}
if (!buf || bufSize == 0) {
free(tmpBuf);
return totalLen;
}
if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
free(tmpBuf);
return FS_SUCCESS;
}
buf[bufSize - 1] = 0;
free(tmpBuf);
return totalLen;
}
#endif
static struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
static struct FsMap *g_fs = NULL;
static void InitMountInfo(void)
{
#if (LOSCFG_SUPPORT_FATFS == 1)
extern struct MountOps g_fatfsMnt;
extern struct FileOps g_fatfsFops;
g_fsmap[0].fileSystemtype = strdup("fat");
g_fsmap[0].fsMops = &g_fatfsMnt;
g_fsmap[0].fsFops = &g_fatfsFops;
#endif
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
extern struct MountOps g_lfsMnt;
extern struct FileOps g_lfsFops;
g_fsmap[1].fileSystemtype = strdup("littlefs");
g_fsmap[1].fsMops = &g_lfsMnt;
g_fsmap[1].fsFops = &g_lfsFops;
#endif
}
static struct FsMap *MountFindfs(const char *fileSystemtype)
{
struct FsMap *m = NULL;
for (int i = 0; i < MAX_FILESYSTEM_LEN; i++) {
m = &(g_fsmap[i]);
if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
return m;
}
}
return NULL;
}
int LOS_FsMount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
static int initFlag = 0;
if (initFlag == 0) {
InitMountInfo();
initFlag = 1;
}
g_fs = MountFindfs(filesystemtype);
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Mount == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
}
int LOS_FsUmount(const char *target)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Umount(target);
}
int LOS_FsUmount2(const char *target, int flag)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount2 == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Umount2(target, flag);
}
int LOS_Open(const char *path, int oflag, ...)
{
#ifdef LOSCFG_RANDOM_DEV
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
if ((unsigned)oflag & ~flags) {
errno = EINVAL;
return FS_FAILURE;
}
size_t pathLen = strlen(path) + 1;
if ((unsigned)pathLen > PATH_MAX) {
errno = EINVAL;
return FS_FAILURE;
}
char *canonicalPath = (char *)malloc(pathLen);
if (!canonicalPath) {
errno = ENOMEM;
return FS_FAILURE;
}
if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
FREE_AND_SET_NULL(canonicalPath);
errno = ENOMEM;
return FS_FAILURE;
}
if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
FREE_AND_SET_NULL(canonicalPath);
if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
errno = EPERM;
return FS_FAILURE;
}
if ((unsigned)oflag & O_DIRECTORY) {
errno = ENOTDIR;
return FS_FAILURE;
}
return RANDOM_DEV_FD;
}
if (strcmp(canonicalPath, "/") == 0 || strcmp(canonicalPath, "/dev") == 0) {
FREE_AND_SET_NULL(canonicalPath);
if ((unsigned)oflag & O_DIRECTORY) {
errno = EPERM;
return FS_FAILURE;
}
errno = EISDIR;
return FS_FAILURE;
}
FREE_AND_SET_NULL(canonicalPath);
#endif
#if (LOSCFG_POSIX_PIPE_API == 1)
if ((path != NULL) && !strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) {
return PipeOpen(path, oflag, PIPE_DEV_FD);
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Open == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Open(path, oflag);
}
int LOS_Close(int fd)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
return FS_SUCCESS;
}
#endif
#ifdef LOSCFG_NET_LWIP_SACK
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
return closesocket(fd);
}
#endif
#if (LOSCFG_POSIX_PIPE_API == 1)
if (fd >= PIPE_DEV_FD) {
return PipeClose(fd);
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Close == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Close(fd);
}
ssize_t LOS_Read(int fd, void *buf, size_t nbyte)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
if (nbyte == 0) {
return FS_SUCCESS;
}
if (buf == NULL) {
errno = EINVAL;
return FS_FAILURE;
}
if (nbyte > 1024) { /* 1024, max random_size */
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
}
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
if (hks_generate_random(&key) != 0) {
errno = EIO;
return FS_FAILURE;
}
return (ssize_t)nbyte;
}
#endif
#ifdef LOSCFG_NET_LWIP_SACK
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
return recv(fd, buf, nbyte, 0);
}
#endif
#if (LOSCFG_POSIX_PIPE_API == 1)
if (fd >= PIPE_DEV_FD) {
return PipeRead(fd, buf, nbyte);
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Read(fd, buf, nbyte);
}
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
errno = EBADF; /* "/dev/random" is readonly */
return FS_FAILURE;
}
#endif
#ifdef LOSCFG_NET_LWIP_SACK
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
return send(fd, buf, nbyte, 0);
}
#endif
#if (LOSCFG_POSIX_PIPE_API == 1)
if (fd >= PIPE_DEV_FD) {
return PipeWrite(fd, buf, nbyte);
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Write == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Write(fd, buf, nbyte);
}
off_t LOS_Lseek(int fd, off_t offset, int whence)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Seek == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Seek(fd, offset, whence);
}
int LOS_Unlink(const char *path)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Unlink == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Unlink(path);
}
int LOS_Fstat(int fd, struct stat *buf)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Fstat == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Fstat(fd, buf);
}
int LOS_Stat(const char *path, struct stat *buf)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Getattr == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Getattr(path, buf);
}
int LOS_Fsync(int fd)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Fsync == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Fsync(fd);
}
int LOS_Mkdir(const char *path, mode_t mode)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Mkdir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Mkdir(path, mode);
}
DIR *LOS_Opendir(const char *dirName)
{
if (g_fs == NULL) {
errno = ENODEV;
return NULL;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Opendir == NULL) {
errno = ENOSYS;
return NULL;
}
return g_fs->fsFops->Opendir(dirName);
}
struct dirent *LOS_Readdir(DIR *dir)
{
if (g_fs == NULL) {
errno = ENODEV;
return NULL;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Readdir == NULL) {
errno = ENOSYS;
return NULL;
}
return g_fs->fsFops->Readdir(dir);
}
int LOS_Closedir(DIR *dir)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Closedir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Closedir(dir);
}
int LOS_Rmdir(const char *path)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Rmdir == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Rmdir(path);
}
int LOS_Rename(const char *oldName, const char *newName)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Rename == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Rename(oldName, newName);
}
int LOS_Statfs(const char *path, struct statfs *buf)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsMops == NULL || g_fs->fsMops->Statfs == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsMops->Statfs(path, buf);
}
int LOS_Ftruncate(int fd, off_t length)
{
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Ftruncate == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Ftruncate(fd, length);
}
ssize_t LOS_Pread(int fd, void *buf, size_t nbyte, off_t offset)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
if (nbyte == 0) {
return FS_SUCCESS;
}
if (buf == NULL) {
errno = EINVAL;
return FS_FAILURE;
}
if (nbyte > 1024) { /* 1024, max random_size */
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
}
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
if (hks_generate_random(&key) != 0) {
errno = EIO;
return FS_FAILURE;
}
return (ssize_t)nbyte;
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Pread == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Pread(fd, buf, nbyte, offset);
}
ssize_t LOS_Pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
#ifdef LOSCFG_RANDOM_DEV
if (fd == RANDOM_DEV_FD) {
errno = EBADF; /* "/dev/random" is readonly */
return FS_FAILURE;
}
#endif
if (g_fs == NULL) {
errno = ENODEV;
return FS_FAILURE;
}
if (g_fs->fsFops == NULL || g_fs->fsFops->Pwrite == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
return g_fs->fsFops->Pwrite(fd, buf, nbyte, offset);
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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,18 +30,19 @@
*/
/**
* @defgroup los_vfs fs
* @defgroup los_fs fs
* @ingroup kernel
*/
#ifndef _LOS_VFS_H_
#define _LOS_VFS_H_
#ifndef _LOS_FS_H_
#define _LOS_FS_H_
#include "los_config.h"
#include "dirent.h"
#include "sys/mount.h"
#include "sys/statfs.h"
#include "sys/stat.h"
#include "sys/uio.h"
#include "unistd.h"
#ifdef __cplusplus
@@ -50,51 +51,72 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int LOS_Open(const char *path, int oflag, ...);
int LOS_Open(const char *path, int flags, ...);
int LOS_Close(int fd);
ssize_t LOS_Read(int fd, void *buf, size_t nbyte);
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte);
off_t LOS_Lseek(int fd, off_t offset, int whence);
int LOS_Unlink(const char *path);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Stat(const char *path, struct stat *buf);
int LOS_Fsync(int fd);
int LOS_Mkdir(const char *path, mode_t mode);
DIR *LOS_Opendir(const char *dirName);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Rmdir(const char *path);
int LOS_Rename(const char *oldName, const char *newName);
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
off_t LOS_Lseek(int fd, off_t off, int whence);
int LOS_Stat(const char *path, struct stat *stat);
int LOS_Statfs(const char *path, struct statfs *buf);
int LOS_Unlink(const char *path);
int LOS_Rename(const char *oldpath, const char *newpath);
int LOS_Fsync(int fd);
DIR *LOS_Opendir(const char *path);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Mkdir(const char *path, mode_t mode);
int LOS_Rmdir(const char *path);
int LOS_Lstat(const char *path, struct stat *buffer);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Fcntl(int fd, int cmd, ...);
int LOS_Ioctl(int fd, int req, ...);
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
int LOS_Isatty(int fd);
int LOS_Access(const char *path, int amode);
int LOS_Ftruncate(int fd, off_t length);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsUmount(const char *target);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsMount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const char *fsType, unsigned long mountflags,
const void *data);
/*
* @brief Divide the device into partitions.
*
* @param dev Device name, which customized by caller, it is recommended to
* name it as: "emmc0", "emmc1", "flash0", etc. The name is combined with
* "device_type" + "device_id", and the last character is device_id.
* device_id >= 0 && device_id <= 9.
* @param fsType Filesystem type.
* @param lengthArray List of partition size. For example:
* [0x10000000, 0x2000000], 256M and 512M partitions will be created and
* left all will not allocated.
* @param partNum Length of 'lengthArray'.
*
* @return Return LOS_NOK if error. Return LOS_OK if success.
* Partition naming rules:
* In the current vfs, after successfully calling the 'fdisk' hook,
* "partNum" partitions will be created.
* The partition naming rules is:
* The name is a combination of: 'deviceName'+'p'+'partitionId',
* such as "emmc0p0", "emmc0p1", "emmc0p2"...
*/
int LOS_DiskPartition(const char *dev, const char *fsType, int *lengthArray,
int partnum);
ssize_t LOS_Pread(int fd, void *buf, size_t nbyte, off_t offset);
ssize_t LOS_Pwrite(int fd, const void *buf, size_t nbyte, off_t offset);
/*
* @brief Format a partition.
*
* @param partName PartitionName, following the rule of fdisk hook.
* @param data For FatFs, the data indicates a pointer to a byte which
* specifies combination of FAT type flags, FM_FAT, FM_FAT32, FM_EXFAT and
* bitwise-or of these three, FM_ANY.
*
* @return Return LOS_NOK if error. Return LOS_OK if success.
*/
int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
#ifdef __cplusplus
#if __cplusplus
@@ -102,4 +124,4 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_FS_H_ */
#endif /* _LOS_FS_H_ */

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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,54 +32,8 @@
#ifndef _VFS_CONFIG_H_
#define _VFS_CONFIG_H_
#define PATH_MAX 256
#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure
/* file system configur */
#define CONFIG_FS_WRITABLE // enable file system can be written
#define CONFIG_FS_READABLE // enable file system can be read
#define CONFIG_DEBUG_FS // enable vfs debug function
/* fatfs cache configur */
/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */
#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64
/* config block num for fat file system */
#define CONFIG_FS_FAT_READ_NUMS 7
#define CONFIG_FS_FAT_BLOCK_NUMS 28
#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
/* config the priority of sync task */
#define CONFIG_FS_FAT_SYNC_THREAD_PRIO 10
/* config dirty ratio of bcache for fat file system */
#define CONFIG_FS_FAT_DIRTY_RATIO 60
/* config time interval of sync thread for fat file system, in milliseconds */
#define CONFIG_FS_FAT_SYNC_INTERVAL 5000
#endif
#define CONFIG_FS_FLASH_BLOCK_NUM 1
#define CONFIG_FS_MAX_LNK_CNT 40
/* nfs configure */
#define CONFIG_NFS_MACHINE_NAME "IPC" // nfs device name is IPC
#define CONFIG_NFS_MACHINE_NAME_SIZE 3 // size of nfs machine name
/* file descriptors configure */
#define CONFIG_NFILE_STREAMS 1 // enable file stream
#define CONFIG_STDIO_BUFFER_SIZE 0
#define CONFIG_NUNGET_CHARS 0
#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively
/* net configure */
@@ -87,12 +41,8 @@
#ifdef LOSCFG_NET_LWIP_SACK // enable socket and net function
#include "lwip/lwipopts.h"
#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS // max numbers of socket descriptor
#define CONFIG_NET_SENDFILE 1 // enable sendfile function
#define CONFIG_NET_TCP 1 // enable sendfile and send function
#else
#define CONFIG_NSOCKET_DESCRIPTORS 0
#define CONFIG_NET_SENDFILE 0 // disable sendfile function
#define CONFIG_NET_TCP 0 // disable sendfile and send function
#endif
/* max numbers of other descriptors except socket descriptors */

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_files.h"
#include "errno.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "los_config.h"
#include "vfs_config.h"
#include "vfs_mount.h"
#include "vfs_operations.h"
static struct File g_files[NR_OPEN_DEFAULT];
int FileToFd(struct File *file)
{
if (file == NULL) {
return LOS_NOK;
}
return file - g_files + MIN_START_FD;
}
struct File *FdToFile(int fd)
{
if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
return NULL;
}
return &g_files[fd - MIN_START_FD];
}
struct File *VfsFileGet(void)
{
int i;
/* protected by g_fsMutex */
for (i = 0; i < NR_OPEN_DEFAULT; i++) {
if (g_files[i].fStatus == FILE_STATUS_NOT_USED) {
g_files[i].fStatus = FILE_STATUS_INITING;
return &g_files[i];
}
}
return NULL;
}
struct File *VfsFileGetSpec(int fd)
{
if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
return NULL;
}
if (g_files[fd - MIN_START_FD].fStatus == FILE_STATUS_NOT_USED) {
g_files[fd - MIN_START_FD].fStatus = FILE_STATUS_INITING;
return &g_files[fd - MIN_START_FD];
}
return NULL;
}
void VfsFilePut(struct File *file)
{
if (file == NULL) {
return;
}
file->fFlags = 0;
file->fFops = NULL;
file->fData = NULL;
file->fMp = NULL;
file->fOffset = 0;
file->fOwner = -1;
file->fullPath = NULL;
file->fStatus = FILE_STATUS_NOT_USED;
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 _VFS_FILES_H_
#define _VFS_FILES_H_
#include "dirent.h"
#include "sys/stat.h"
#include "unistd.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define FILE_STATUS_NOT_USED 0
#define FILE_STATUS_INITING 1
#define FILE_STATUS_READY 2
#define FILE_STATUS_CLOSING 3
struct FileOps;
struct File;
struct Dir;
struct MountPoint;
struct FileOps {
int (*open)(struct File *, const char *, int);
int (*close)(struct File *);
ssize_t (*read)(struct File *, char *, size_t);
ssize_t (*write)(struct File *, const char *, size_t);
off_t (*lseek)(struct File *, off_t, int);
int (*stat)(struct MountPoint *, const char *, struct stat *);
int (*truncate)(struct File *, off_t);
int (*unlink)(struct MountPoint *, const char *);
int (*rename)(struct MountPoint *, const char *, const char *);
int (*ioctl)(struct File *, int, unsigned long);
int (*sync)(struct File *);
int (*opendir)(struct Dir *, const char *);
int (*readdir)(struct Dir *, struct dirent *);
int (*closedir)(struct Dir *);
int (*mkdir)(struct MountPoint *, const char *);
int (*rmdir)(struct MountPoint *, const char *);
};
struct File {
const struct FileOps *fFops;
UINT32 fFlags;
UINT32 fStatus;
off_t fOffset;
INT32 fOwner;
struct MountPoint *fMp;
void *fData; /* file system opreations handle, fatfs FIL, etc. */
const char *fullPath;
};
struct Dir {
struct MountPoint *dMp;
struct dirent dDent;
off_t dOffset;
void *dData;
};
int FileToFd(struct File *file);
struct File *FdToFile(int fd);
struct File *VfsFileGet(void);
struct File *VfsFileGetSpec(int fd);
void VfsFilePut(struct File *file);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VFS_FILES_H_ */

1398
components/fs/vfs/vfs_fs.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 "stdlib.h"
#include "vfs_operations.h"
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
#include "lfs_adapter.h"
#endif
#if (LOSCFG_SUPPORT_FATFS == 1)
#include "fatfs.h"
#endif
#include "los_compiler.h"
#include "los_mux.h"
int OsVfsInit(void)
{
if (LOS_MuxCreate(&g_fsMutex) != LOS_OK) {
return LOS_NOK;
}
#if (LOSCFG_SUPPORT_FATFS == 1)
FatFsInit();
#endif
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
LfsInit();
#endif
return LOS_OK;
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_maps.h"
#include "vfs_operations.h"
#include <stdlib.h>
#include "securec.h"
#include "los_debug.h"
#include "los_compiler.h"
struct FsMap *g_fsMap = NULL;
struct FsMap *VfsFsMapGet(const char *fsType)
{
struct FsMap *curr = g_fsMap;
(void)VfsLock();
while (curr != NULL) {
if ((curr->fsType != NULL) && (fsType != NULL) &&
(strcmp(curr->fsType, fsType) == 0)) {
(void)VfsUnlock();
return curr;
}
curr = curr->next;
}
VfsUnlock();
return NULL;
}
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt)
{
if ((fsMops == NULL) || (fsFops == NULL)) {
return LOS_NOK;
}
struct FsMap *newfs = (struct FsMap *)malloc(sizeof(struct FsMap));
if (newfs == NULL) {
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
return LOS_NOK;
}
(void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap));
newfs->fsType = strdup(fsType);
if (newfs->fsType == NULL) {
free(newfs);
return LOS_NOK;
}
newfs->fsMops = fsMops;
newfs->fsFops = fsFops;
newfs->fsMgt = fsMgt;
newfs->fsRefs = 0;
(void)VfsLock();
newfs->next = g_fsMap;
g_fsMap = newfs;
VfsUnlock();
return LOS_OK;
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 _VFS_MAPS_H_
#define _VFS_MAPS_H_
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
struct MountOps;
struct FsManagement {
int (*fdisk)(const char *dev, int *lengthArray, int partNum);
int (*format)(const char *partName, void *data);
};
struct FsMap {
const char *fsType;
const struct MountOps *fsMops;
const struct FileOps *fsFops;
const struct FsManagement *fsMgt;
UINT32 fsRefs;
struct FsMap *next;
};
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt);
struct FsMap *VfsFsMapGet(const char *fsType);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VFS_MAPS_H_ */

View File

@@ -0,0 +1,294 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_mount.h"
#include "vfs_files.h"
#include "vfs_maps.h"
#include "vfs_config.h"
#include "stdlib.h"
#include "string.h"
#include "vfs_operations.h"
#include "los_compiler.h"
#include "los_debug.h"
#include "los_fs.h"
#include "los_mux.h"
struct MountPoint *g_mountPoints = NULL;
static void MpDeleteFromList(struct MountPoint *mp)
{
struct MountPoint *prev = NULL;
/* delete mp from mount list */
if (g_mountPoints == mp) {
g_mountPoints = mp->mNext;
} else {
for (prev = g_mountPoints; prev != NULL; prev = prev->mNext) {
if (prev->mNext != mp) {
continue;
}
prev->mNext = mp->mNext;
break;
}
}
}
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
{
struct MountPoint *mp = g_mountPoints;
struct MountPoint *bestMp = NULL;
int bestMatches = 0;
if (path == NULL) {
return NULL;
}
if (pathInMp != NULL) {
*pathInMp = NULL;
}
while ((mp != NULL) && (mp->mPath != NULL)) {
const char *mPath = mp->mPath;
const char *iPath = path;
const char *t = NULL;
int matches = 0;
do {
while ((*mPath == '/') && (*(mPath + 1) != '/')) {
mPath++;
}
while ((*iPath == '/') && (*(iPath + 1) != '/')) {
iPath++;
}
t = strchr(mPath, '/');
if (t == NULL) {
t = strchr(mPath, '\0');
}
if ((t == mPath) || (t == NULL)) {
break;
}
if (strncmp(mPath, iPath, (size_t)(t - mPath)) != 0) {
goto next; /* this mount point do not match, check next */
}
iPath += (t - mPath);
if ((*iPath != '\0') && (*iPath != '/')) {
goto next;
}
matches += (t - mPath);
mPath += (t - mPath);
} while (*mPath != '\0');
if (matches > bestMatches) {
bestMatches = matches;
bestMp = mp;
while ((*iPath == '/') && (*(iPath + 1) != '/')) {
iPath++;
}
if (pathInMp != NULL) {
*pathInMp = path;
}
}
next:
mp = mp->mNext;
}
return bestMp;
}
int LOS_FsMount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data)
{
int ret;
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) {
return LOS_NOK;
}
(void)VfsLock();
/* find mp by target, to see if it was mounted */
mp = VfsMpFind(target, &pathInMp);
if (mp != NULL && pathInMp != NULL) {
goto errout;
}
/* Find fsMap coresponding to the fsType */
struct FsMap *mFs = VfsFsMapGet(fsType);
if ((mFs == NULL) || (mFs->fsMops == NULL) ||
(mFs->fsMops->mount == NULL)) {
goto errout;
}
mp = (struct MountPoint *)malloc(sizeof(struct MountPoint));
if (mp == NULL) {
goto errout;
}
mp->mFs = mFs;
mp->mDev = NULL;
if (source != NULL) {
mp->mDev = strdup(source);
if (mp->mDev == NULL) {
goto errout;
}
}
mp->mPath = strdup(target);
if (mp->mPath == NULL) {
goto errout;
}
ret = mp->mFs->fsMops->mount(mp, mountflags, data);
if (ret != 0) {
/* errno is set */
PRINT_ERR("mount failed, target %s.\n", target);
goto errout;
}
mp->mRefs = 0;
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
mp->mFs->fsRefs++;
mp->mNext = g_mountPoints;
g_mountPoints = mp;
VfsUnlock();
return LOS_OK;
errout:
free((void *)mp->mPath);
free((void *)mp->mDev);
free(mp);
VfsUnlock();
return LOS_NOK;
}
int LOS_FsUmount(const char *target)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = LOS_NOK;
(void)VfsLock();
if (target == NULL) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
if ((mp == NULL) || (mp->mRefs != 0)) {
goto errout;
}
if ((mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
(mp->mFs->fsMops->umount == NULL)) {
goto errout;
}
ret = mp->mFs->fsMops->umount(mp);
if (ret != 0) {
/* errno is set */
goto errout;
}
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
free((void *)mp->mPath);
free((void *)mp->mDev);
free(mp);
VfsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
return LOS_NOK;
}
static void CloseFdsInMp(struct MountPoint *mp)
{
for (int fd = 0; fd < NR_OPEN_DEFAULT; fd++) {
struct File *f = FdToFile(fd);
if (f == NULL) {
continue;
}
if ((f->fMp == mp) &&
(f->fFops != NULL) &&
(f->fFops->close != NULL)) {
(void)f->fFops->close(f);
}
}
}
int LOS_FsUmount2(const char *target, int flag)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = LOS_NOK;
(void)VfsLock();
if (target == NULL) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
if ((mp == NULL) || (mp->mRefs != 0) ||
(mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
(mp->mFs->fsMops->umount2 == NULL)) {
goto errout;
}
/* Close all files under the mount point */
if ((UINT32)flag & MNT_FORCE) {
CloseFdsInMp(mp);
}
ret = mp->mFs->fsMops->umount2(mp, flag);
if (ret != 0) {
/* errno is set */
goto errout;
}
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
free((void *)mp->mPath);
free((void *)mp->mDev);
free(mp);
VfsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
return LOS_NOK;
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 _VFS_MOUNT_H_
#define _VFS_MOUNT_H_
#include "sys/statfs.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
struct FsMap;
struct MountPoint;
struct MountOps {
int (*mount)(struct MountPoint *mp, unsigned long mountflags,
const void *data);
int (*umount)(struct MountPoint *mp);
int (*umount2)(struct MountPoint *mp, int flag);
int (*statfs)(const char *path, struct statfs *buf);
};
struct MountPoint {
struct FsMap *mFs; /* file system info */
struct MountPoint *mNext; /* point to next mount point */
const char *mPath; /* target path, /system, /usr, etc. */
const char *mDev; /* device, "emmc0p0", "emmc0p1", etc. */
UINT32 mRefs; /* reference to mount point */
void *mData; /* specific file system handle */
BOOL mWriteEnable; /* writable flag */
};
extern struct MountPoint *g_mountPoints;
#define LOS_MP_FOR_EACH_ENTRY(prev) \
for (prev = g_mountPoints; prev != NULL; prev = prev->mNext)
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VFS_MOUNT_H_ */

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 _VFS_OPERATIONS_H_
#define _VFS_OPERATIONS_H_
#include "errno.h"
#include "fcntl.h"
#include "dirent.h"
#include "stdint.h"
#include "unistd.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define VFS_ERRNO_SET(err) (errno = (err))
extern UINT32 g_fsMutex;
int OsVfsInit(void);
int VfsLock(void);
void VfsUnlock(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VFS_OPERATIONS_H_ */

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_partition.h"
#include "vfs_operations.h"
#include "los_fs.h"
#include "los_list.h"
#include "vfs_maps.h"
#include "vfs_mount.h"
#include "securec.h"
#include "stdlib.h"
#include "string.h"
int GetPartIdByPartName(const char *partName)
{
if (partName == NULL) {
return LOS_NOK;
}
/* the character next to p is the partId */
char *p = strrchr(partName, 'p');
if (p + 1 != NULL) {
return atoi(p + 1);
}
return LOS_NOK;
}
int GetDevIdByDevName(const char *dev)
{
if (dev == NULL) {
return LOS_NOK;
}
/* last character is the deviceId */
char *p = (char *)dev + strlen(dev) - 1;
if (p != NULL) {
return atoi(p);
}
return LOS_NOK;
}
int LOS_DiskPartition(const char *dev, const char *fsType, int *lengthArray,
int partnum)
{
int ret = LOS_NOK;
struct FsMap *fMap = VfsFsMapGet(fsType);
if ((fMap != NULL) && (fMap->fsMgt != NULL) &&
(fMap->fsMgt->fdisk != NULL)) {
ret = fMap->fsMgt->fdisk(dev, lengthArray, partnum);
}
return ret;
}
int LOS_PartitionFormat(const char *partName, char *fsType, void *data)
{
int ret = LOS_NOK;
/* check if the device is mounted by iterate the mp list
format is not allowed when the device has been mounted. */
struct MountPoint *iter = NULL;
LOS_MP_FOR_EACH_ENTRY(iter) {
if ((iter->mFs != NULL) && (iter->mFs->fsType != NULL) &&
strcmp(iter->mFs->fsType, fsType) == 0) {
errno = EBUSY;
return LOS_NOK;
}
}
struct FsMap *fMap = VfsFsMapGet(fsType);
if ((fMap != NULL) && (fMap->fsMgt != NULL) &&
(fMap->fsMgt->format != NULL)) {
ret = fMap->fsMgt->format(partName, data);
}
return ret;
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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 _VFS_PARTITION_H_
#define _VFS_PARTITION_H_
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define MAX_PARTITION_NUM 4
int GetPartIdByPartName(const char *partName);
int GetDevIdByDevName(const char *dev);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _VFS_PARTITION_H_ */

View File

@@ -178,6 +178,11 @@
#define NO_SYS 0
#define TCP_QUEUE_OOSEQ LWIP_TCP
#if defined LWIP_STATS_DISPLAY && !LWIP_STATS
#undef LWIP_STATS_DISPLAY
#define LWIP_STATS_DISPLAY 0
#endif
// Change some options for lwIP 2.1.2
#undef TCP_MAXRTX
#define TCP_MAXRTX 12

View File

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

View File

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

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_box.h"
#include "los_task.h"
#include "los_context.h"
#include "los_arch_context.h"
#include "los_debug.h"
static UserTaskCB g_UserTaskCBArray[LOSCFG_BASE_CORE_TSK_LIMIT] = { 0 };
static LosBoxCB g_boxCB[1];
VOID OsUserTaskInit(UINT32 taskID, UINTPTR entry, UINTPTR userArea, UINTPTR userSp)
{
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
taskCB->taskStatus |= OS_TASK_FLAG_USER_TASK;
HalUserTaskStackInit(taskCB->stackPointer, entry, userSp);
g_UserTaskCBArray[taskID].userArea = userArea;
g_UserTaskCBArray[taskID].userSp = userSp;
g_UserTaskCBArray[taskID].boxID = g_UserTaskCBArray[g_losTask.runTask->taskID].boxID;
}
VOID OsUserTaskDelete(UINT32 taskID)
{
(VOID)memset_s(&g_UserTaskCBArray[taskID], sizeof(UserTaskCB), 0, sizeof(UserTaskCB));
}
UserTaskCB *OsGetUserTaskCB(UINT32 taskID)
{
return &g_UserTaskCBArray[taskID];
}
static UINT32 BoxInit(VOID)
{
UINT32 count = sizeof(g_boxCB) / sizeof(LosBoxCB);
for (UINT32 i = 0; i < count; i++) {
LosBoxCB *box = &g_boxCB[i];
box->boxStackAddr = box->boxStartAddr + box->boxSize - box->boxStackSize;
}
return LOS_OK;
}
VOID OsBoxStart(VOID)
{
UINT32 ret, taskID;
UINT32 count = sizeof(g_boxCB) / sizeof(LosBoxCB);
TSK_INIT_PARAM_S taskInitParam = { 0 };
for (UINT32 i = 0; i < count; i++) {
LosBoxCB *box = &g_boxCB[i];
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)box->boxStartAddr;
taskInitParam.uwStackSize = 0x1000;
taskInitParam.pcName = "BoxMainTask";
taskInitParam.usTaskPrio = LOSCFG_BOX_PRIO;
taskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
ret = LOS_TaskCreateOnly(&taskID, &taskInitParam);
if (ret != LOS_OK) {
PRINT_ERR("Create box %u main task failed, Error 0x%x\n", i, ret);
return;
}
OsUserTaskInit(taskID, (UINTPTR)_ulibc_start, 0, box->boxStackAddr + box->boxStackSize);
g_UserTaskCBArray[taskID].boxID = i;
ret = LOS_TaskResume(taskID);
if (ret != LOS_OK) {
PRINT_ERR("Box(%u) resume task %u failed, Error 0x%x\n", i, taskID, ret);
return;
}
}
}
UINT32 LOS_BoxStart(VOID)
{
UINT32 ret, taskID;
TSK_INIT_PARAM_S taskInitParam = { 0 };
ret = BoxInit();
if (ret != LOS_OK) {
PRINT_ERR("Box init failed! Error 0x%x\n", ret);
return ret;
}
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsBoxStart;
taskInitParam.uwStackSize = 0x1000;
taskInitParam.pcName = "BoxStart";
taskInitParam.usTaskPrio = LOSCFG_BOX_START_PRIO;
taskInitParam.uwResved = 0;
return LOS_TaskCreate(&taskID, &taskInitParam);
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_BOX_H
#define _LOS_BOX_H
#include "los_compiler.h"
#define LOSCFG_BOX_START_PRIO 5
#define LOSCFG_BOX_PRIO 10
/*
* -------------------- boxStartAddr(main)
* | .text |
* | -----------------
* | .data |
* | ----------------- boxHeapAddr
* | .heap |
* | ----------------- boxStackAddr
* | boxStackSize |
* --------------------
*/
typedef struct {
UINTPTR boxStartAddr;
UINTPTR boxSize;
UINTPTR boxHeapAddr;
UINTPTR boxHeapSize;
UINTPTR boxStackAddr; /* box main task stack addr */
UINTPTR boxStackSize;
} LosBoxCB;
typedef struct {
unsigned long userArea;
unsigned long userSp;
unsigned int boxID;
} UserTaskCB;
VOID OsUserTaskInit(UINT32 taskID, UINTPTR entry, UINTPTR userArea, UINTPTR userSp);
VOID OsUserTaskDelete(UINT32 taskID);
UserTaskCB *OsGetUserTaskCB(UINT32 taskID);
UINT32 LOS_BoxStart(VOID);
extern INT32 _ulibc_start(UINTPTR main);
#endif

View File

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

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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.
*/
#define GNU_SOURCE
#include "los_syscall.h"
#include "los_context.h"
#include "los_task.h"
#include "los_debug.h"
#include "unistd.h"
#include "errno.h"
#define SYS_CALL_NUM_LIMIT (__NR_syscallend + 1)
#define SYS_CALL_NUM_REG_OFFSET 7
#define NARG_BITS 4
#define NARG_MASK 0x0F
#define NARG_PER_BYTE 2
typedef UINT32 (*SyscallFun1)(UINT32);
typedef UINT32 (*SyscallFun2)(UINT32, UINT32);
typedef UINT32 (*SyscallFun3)(UINT32, UINT32, UINT32);
typedef UINT32 (*SyscallFun4)(UINT32, UINT32, UINT32, UINT32);
typedef UINT32 (*SyscallFun5)(UINT32, UINT32, UINT32, UINT32, UINT32);
typedef UINT32 (*SyscallFun7)(UINT32, UINT32, UINT32, UINT32, UINT32, UINT32, UINT32);
static UINTPTR g_syscallHandle[SYS_CALL_NUM_LIMIT] = {0};
static UINT8 g_syscallNArgs[(SYS_CALL_NUM_LIMIT + 1) / NARG_PER_BYTE] = {0};
void OsSyscallHandleInit(void)
{
#define SYSCALL_HAND_DEF(id, fun, rType, nArg) \
if ((id) < SYS_CALL_NUM_LIMIT) { \
g_syscallHandle[(id)] = (UINTPTR)(fun); \
g_syscallNArgs[(id) / NARG_PER_BYTE] |= ((id) & 1) ? (nArg) << NARG_BITS : (nArg); \
} \
#include "syscall_lookup.h"
#undef SYSCALL_HAND_DEF
}
/* The SYSCALL ID is in R7 on entry. Parameters follow in R0..R6 */
VOID OsSyscallHandle(UINT32 *args)
{
UINT32 ret;
UINT8 nArgs;
UINTPTR handle;
UINT32 svcNum = (UINT32)args[SYS_CALL_NUM_REG_OFFSET];
if (svcNum >= SYS_CALL_NUM_LIMIT) {
PRINT_ERR("Syscall ID: error %d !!!\n", svcNum);
return;
}
handle = g_syscallHandle[svcNum];
nArgs = g_syscallNArgs[svcNum / NARG_PER_BYTE]; /* 4bit per nargs */
nArgs = (svcNum & 1) ? (nArgs >> NARG_BITS) : (nArgs & NARG_MASK);
if ((handle == 0) || (nArgs > ARG_NUM_7)) {
PRINT_ERR("Unsupported syscall ID: %d nArgs: %d\n", svcNum, nArgs);
args[ARG_NUM_0] = -ENOSYS;
return;
}
switch (nArgs) {
case ARG_NUM_0:
case ARG_NUM_1:
ret = (*(SyscallFun1)handle)(args[ARG_NUM_0]);
break;
case ARG_NUM_2:
ret = (*(SyscallFun2)handle)(args[ARG_NUM_0], args[ARG_NUM_1]);
break;
case ARG_NUM_3:
ret = (*(SyscallFun3)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2]);
break;
case ARG_NUM_4:
ret = (*(SyscallFun4)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3]);
break;
case ARG_NUM_5:
ret = (*(SyscallFun5)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3], \
args[ARG_NUM_4]);
break;
default:
ret = (*(SyscallFun7)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3], \
args[ARG_NUM_4], args[ARG_NUM_5], args[ARG_NUM_6]);
}
args[ARG_NUM_0] = ret;
return;
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_SYSCALL_H
#define _LOS_SYSCALL_H
#include "los_arch_context.h"
#include "los_task.h"
#include "syscall.h"
void OsSyscallHandleInit(void);
void OsSyscallHandle(UINT32 *regs);
/* pthread */
int SysUserTaskCreate(unsigned long entry, unsigned long userArea, unsigned long userSp, BOOL joinable);
int SysSchedSetScheduler(unsigned int tid, int policy, int priority);
int *SysSchedGetArea(unsigned int tid);
int SysSetThreadArea(const char *area);
char *SysGetThreadArea(void);
int SysFutex(const unsigned int *uAddr, unsigned int flags, int val,
unsigned int absTime, const unsigned int *newUserAddr);
#endif /* _LOS_SYSCALL_H */

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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_task.h"
#include "securec.h"
#include "los_config.h"
#include "los_debug.h"
#include "los_hook.h"
#include "los_interrupt.h"
#include "los_memory.h"
#include "los_mpu.h"
#include "los_sched.h"
#include "los_mux.h"
#include "los_sem.h"
#include "los_timer.h"
#include "los_arch_context.h"
#include "los_box.h"
#include "los_syscall.h"
int SysUserTaskCreate(unsigned long entry, unsigned long userArea, unsigned long userSp, BOOL joinable)
{
UINT32 ret, taskID;
TSK_INIT_PARAM_S taskInitParam = { 0 };
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)entry;
taskInitParam.uwStackSize = 0x1000;
taskInitParam.pcName = "UserTask";
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
taskInitParam.stackAddr = userSp;
if (joinable) {
taskInitParam.uwResved |= LOS_TASK_ATTR_JOINABLE;
}
ret = LOS_TaskCreateOnly(&taskID, &taskInitParam);
if (ret != LOS_OK) {
return -EINVAL;
}
OsUserTaskInit(taskID, entry, userArea, userSp);
return taskID;
}
int SysSchedSetScheduler(unsigned int tid, int policy, int priority)
{
if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) {
return EINVAL;
}
if (policy != 0) {
return EINVAL;
}
if ((priority <= 0) || (priority > OS_TASK_PRIORITY_LOWEST)) {
return EINVAL;
}
UINT32 ret = LOS_TaskPriSet((UINT32)tid, (UINT16)priority);
if (ret != LOS_OK) {
return EINVAL;
}
return 0;
}
int *SysSchedGetArea(unsigned int tid)
{
unsigned int intSave;
int *area = NULL;
if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) {
return NULL;
}
intSave = LOS_IntLock();
area = (int *)OsGetUserTaskCB(tid)->userArea;
LOS_IntRestore(intSave);
return area;
}
int SysSetThreadArea(const char *area)
{
unsigned int intSave;
intSave = LOS_IntLock();
LosTaskCB *runTask = g_losTask.runTask;
OsGetUserTaskCB(runTask->taskID)->userArea = (unsigned long)(uintptr_t)area;
LOS_IntRestore(intSave);
return 0;
}
char *SysGetThreadArea(void)
{
unsigned int intSave;
char *area = NULL;
intSave = LOS_IntLock();
LosTaskCB *runTask = g_losTask.runTask;
area = (char *)OsGetUserTaskCB(runTask->taskID)->userArea;
LOS_IntRestore(intSave);
return area;
}

View File

@@ -0,0 +1,270 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. 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.
*/
/* SYSCALL_HAND_DEF must be defined before including this file. */
/* SYSCALL_HAND_DEF(id, fun, rtype, narg); note if we have 64bit arg, narg should be ARG_NUM_7 */
// #ifdef LOSCFG_FS_VFS
// SYSCALL_HAND_DEF(__NR_read, SysRead, ssize_t, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_write, SysWrite, ssize_t, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_open, SysOpen, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_close, SysClose, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_creat, SysCreat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_link, SysLink, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_readlink, SysReadlink, ssize_t, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_symlink, SysSymlink, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_unlink, SysUnlink, int, ARG_NUM_1)
// #ifdef LOSCFG_KERNEL_DYNLOAD
// SYSCALL_HAND_DEF(__NR_execve, SysExecve, int, ARG_NUM_3)
// #endif
// SYSCALL_HAND_DEF(__NR_sysinfo, SysInfo, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_fchdir, SysFchdir, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_chdir, SysChdir, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_fchmodat, SysFchmodat, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_fchmod, SysFchmod, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_chmod, SysChmod, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_lseek, SysLseek, off_t, ARG_NUM_7) /* current only support 32bit max 4G file */
// SYSCALL_HAND_DEF(__NR_mount, SysMount, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_umount, SysUmount, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_access, SysAccess, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_faccessat, SysFaccessat, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_sync, SysSync, void, ARG_NUM_0)
// 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(__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)
// SYSCALL_HAND_DEF(__NR_fstatfs, SysFstatfs, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_fstatfs64, SysFstatfs64, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_stat, SysStat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_lstat, SysLstat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_fstat, SysFstat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_fstatat64, SysFstatat64, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_fsync, SysFsync, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR__llseek, SysLseek64, off64_t, ARG_NUM_5) /* current only support 32bit max 4G file */
// SYSCALL_HAND_DEF(__NR__newselect, SysSelect, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_pselect6, SysPselect6, int, ARG_NUM_6)
// SYSCALL_HAND_DEF(__NR_readv, SysReadv, ssize_t, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_writev, SysWritev, ssize_t, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_poll, SysPoll, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_ppoll, SysPpoll, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_prctl, SysPrctl, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_pread64, SysPread64, ssize_t, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_pwrite64, SysPwrite64, ssize_t, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_epoll_create, SysEpollCreate, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_epoll_create1, SysEpollCreate1, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_epoll_ctl, SysEpollCtl, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_epoll_wait, SysEpollWait, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_epoll_pwait, SysEpollPwait, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_getcwd, SysGetcwd, char *, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_sendfile, SysSendFile, ssize_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_truncate64, SysTruncate64, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_ftruncate64, SysFtruncate64, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_stat64, SysStat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_lstat64, SysLstat, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_fstat64, SysFstat64, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_fcntl64, SysFcntl64, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_sendfile64, SysSendFile, ssize_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_preadv, SysPreadv, ssize_t, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_pwritev, SysPwritev, ssize_t, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_fallocate, SysFallocate64, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_getdents64, SysGetdents64, int, ARG_NUM_3)
// #ifdef LOSCFG_FS_FAT
// SYSCALL_HAND_DEF(__NR_format, SysFormat, int, ARG_NUM_3)
// #endif
// SYSCALL_HAND_DEF(__NR_linkat, SysLinkat, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_symlinkat, SysSymlinkat, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_readlinkat, SysReadlinkat, ssize_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_unlinkat, SysUnlinkat, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_renameat, SysRenameat, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_openat, SysOpenat, int, ARG_NUM_7)
// SYSCALL_HAND_DEF(__NR_mkdirat, SysMkdirat, int, ARG_NUM_3)
// 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
// #endif
// SYSCALL_HAND_DEF(__NR_exit, SysThreadExit, void, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_fork, SysFork, int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_vfork, SysVfork, int, ARG_NUM_0)
// 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)
// SYSCALL_HAND_DEF(__NR_getgid, SysGetGroupID, int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_setpgid, SysSetProcessGroupID, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_getppid, SysGetPPID, unsigned int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_getpgrp, SysGetProcessGroupID, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_munmap, SysMunmap, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_getpriority, SysGetProcessPriority, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setpriority, SysSetProcessPriority, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_setitimer, SysSetiTimer, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_getitimer, SysGetiTimer, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_wait4, SysWait, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_waitid, SysWaitid, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_uname, SysUname, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_mprotect, SysMprotect, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_getpgid, SysGetProcessGroupID, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_sched_setparam, SysSchedSetParam, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_sched_getparam, SysSchedGetParam, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_sched_setscheduler, SysSchedSetScheduler, int, ARG_NUM_3)
// 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)
// SYSCALL_HAND_DEF(__NR_umask, SysUmask, mode_t, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_rt_sigaction, SysSigAction, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_rt_sigprocmask, SysSigprocMask, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_rt_sigpending, SysSigPending, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_rt_sigtimedwait, SysSigTimedWait, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_rt_sigsuspend, SysSigSuspend, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_fchownat, SysFchownat, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_fchown32, SysFchown, int, ARG_NUM_3)
// 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_2)
// SYSCALL_HAND_DEF(__NR_ohoscapset, SysCapSet, UINT32, ARG_NUM_1)
// #endif
// SYSCALL_HAND_DEF(__NR_mmap2, SysMmap, void*, ARG_NUM_6)
// SYSCALL_HAND_DEF(__NR_getuid32, SysGetUserID, int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_getgid32, SysGetGroupID, unsigned int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_geteuid32, SysGetEffUserID, int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_getegid32, SysGetEffGID, unsigned int, ARG_NUM_0)
// SYSCALL_HAND_DEF(__NR_getresuid32, SysGetRealEffSaveUserID, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_getresgid32, SysGetRealEffSaveGroupID, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_setresuid32, SysSetRealEffSaveUserID, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_setresgid32, SysSetRealEffSaveGroupID, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_setreuid32, SysSetRealEffUserID, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setregid32, SysSetRealEffGroupID, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setgroups32, SysSetGroups, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_getgroups32, SysGetGroups, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setuid32, SysSetUserID, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_setgid32, SysSetGroupID, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_gettid, SysGetTid, unsigned int, ARG_NUM_0)
// 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(__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)
// SYSCALL_HAND_DEF(__NR_timer_getoverrun, SysTimerGetoverrun, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_timer_delete, SysTimerDelete, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_clock_settime32, SysClockSettime, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_clock_gettime32, SysClockGettime, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_clock_getres_time32, SysClockGetres, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_clock_nanosleep_time32, SysClockNanoSleep, int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_mq_open, SysMqOpen, mqd_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_mq_unlink, SysMqUnlink, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_mq_timedsend, SysMqTimedSend, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_mq_timedreceive, SysMqTimedReceive, ssize_t, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_mq_notify, SysMqNotify, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_mq_getsetattr, SysMqGetSetAttr, int, ARG_NUM_3)
// #ifdef LOSCFG_NET_LWIP_SACK
// SYSCALL_HAND_DEF(__NR_socket, SysSocket, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_bind, SysBind, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_connect, SysConnect, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_listen, SysListen, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_accept, SysAccept, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_getsockname, SysGetSockName, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_getpeername, SysGetPeerName, int, ARG_NUM_3)
// SYSCALL_HAND_DEF(__NR_send, SysSend, ssize_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_sendto, SysSendTo, ssize_t, ARG_NUM_6)
// SYSCALL_HAND_DEF(__NR_recv, SysRecv, ssize_t, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_recvfrom, SysRecvFrom, ssize_t, ARG_NUM_6)
// SYSCALL_HAND_DEF(__NR_shutdown, SysShutdown, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setsockopt, SysSetSockOpt, int, ARG_NUM_5)
// SYSCALL_HAND_DEF(__NR_getsockopt, SysGetSockOpt, int, ARG_NUM_5)
// 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)
// /* LiteOS customized syscalls, not compatible with ARM EABI */
// SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDetach, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_pthread_join, SysThreadJoin, int, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_pthread_deatch, SysUserThreadDetach, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_creat_user_thread, SysUserTaskCreate, unsigned int, ARG_NUM_4)
// SYSCALL_HAND_DEF(__NR_getrusage, SysGetrusage, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_sysconf, SysSysconf, long, ARG_NUM_1)
// SYSCALL_HAND_DEF(__NR_ugetrlimit, SysUgetrlimit, int, ARG_NUM_2)
// SYSCALL_HAND_DEF(__NR_setrlimit, SysSetrlimit, int, ARG_NUM_2)

View File

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

View File

@@ -42,11 +42,13 @@ kernel_module(module_name) {
"src/cmds/mempt_shellcmd.c",
"src/cmds/shell_shellcmd.c",
"src/cmds/task_shellcmd.c",
"src/cmds/vfs_shellcmd.c",
]
if (defined(LOSCFG_NET_LWIP_SACK)) {
defines = [ "LWIP_SHELLCMD_ENABLE" ]
}
if (defined(LOSCFG_FS_VFS)) {
sources += [ "src/cmds/vfs_shellcmd.c" ]
}
}
config("public") {

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. 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 @@ CmdItem g_shellcmdAll[] = {
{CMD_TYPE_EX, "ifconfig", XARGS, (CmdCallBackFunc)lwip_ifconfig},
{CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)OsShellPing},
#endif
#if LOSCFG_FS_VFS
{CMD_TYPE_EX, "touch", XARGS, (CmdCallBackFunc)OsShellCmdTouch},
{CMD_TYPE_EX, "ls", XARGS, (CmdCallBackFunc)OsShellCmdLs},
{CMD_TYPE_EX, "pwd", XARGS, (CmdCallBackFunc)OsShellCmdPwd},
@@ -60,6 +61,8 @@ CmdItem g_shellcmdAll[] = {
{CMD_TYPE_EX, "rmdir", XARGS, (CmdCallBackFunc)OsShellCmdRmdir},
{CMD_TYPE_EX, "mkdir", XARGS, (CmdCallBackFunc)OsShellCmdMkdir},
{CMD_TYPE_EX, "cp", XARGS, (CmdCallBackFunc)OsShellCmdCp},
#endif
{CMD_TYPE_EX, "help", 0, (CmdCallBackFunc)OsShellCmdHelp},
};
@@ -193,7 +196,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCmdAscendingInsert(CmdItemNode *cmd)
}
for (cmdItem = LOS_DL_LIST_ENTRY((&cmdInfo.cmdList.list)->pstPrev, CmdItemNode, list);
&cmdItem->list != &(cmdInfo.cmdList.list); ) {
&cmdItem->list != &(cmdInfo.cmdList.list);) {
cmdNext = LOS_DL_LIST_ENTRY(cmdItem->list.pstPrev, CmdItemNode, list);
if (&cmdNext->list != &(cmdInfo.cmdList.list)) {
if ((strncmp(cmdItem->cmd->cmdKey, cmd->cmd->cmdKey, strlen(cmd->cmd->cmdKey)) >= 0) &&

View File

@@ -33,13 +33,12 @@ import("//third_party/musl/porting/liteos_m/kernel/musl.gni")
module_switch = defined(LOSCFG_LIBC_MUSL)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "malloc.c" ]
sources = [
"fs.c",
"malloc.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
if (defined(LOSCFG_LIBC_MUSL_FS)) {
sources += [ "fs.c" ]
}
deps = [ "//third_party/musl/porting/liteos_m/kernel" ]
}

View File

@@ -30,7 +30,6 @@
*/
#include "los_config.h"
#include "los_fs.h"
#include "stdarg.h"
#include "dirent.h"
#include "sys/mount.h"
@@ -38,9 +37,16 @@
#include "sys/stat.h"
#include "unistd.h"
#ifdef LOSCFG_LIBC_MUSL_FS
#include "los_fs.h"
#else
#include "sys/stat.h"
#endif
#ifdef LOSCFG_LIBC_MUSL_FS
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}
@@ -154,3 +160,119 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return LOS_Pwrite(fd, buf, nbyte, offset);
}
#else /* #ifdef LOSCFG_FS_VFS */
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return -1;
}
int umount(const char *target)
{
return -1;
}
int umount2(const char *target, int flag)
{
return -1;
}
int open(const char *path, int oflag, ...)
{
return -1;
}
int close(int fd)
{
return -1;
}
ssize_t read(int fd, void *buf, size_t nbyte)
{
return -1;
}
ssize_t write(int fd, const void *buf, size_t nbyte)
{
return -1;
}
off_t lseek(int fd, off_t offset, int whence)
{
return -1;
}
int unlink(const char *path)
{
return -1;
}
int fstat(int fd, struct stat *buf)
{
return -1;
}
int stat(const char *path, struct stat *buf)
{
return -1;
}
int fsync(int fd)
{
return -1;
}
int mkdir(const char *path, mode_t mode)
{
return -1;
}
DIR *opendir(const char *dirName)
{
return NULL;
}
struct dirent *readdir(DIR *dir)
{
return NULL;
}
int closedir(DIR *dir)
{
return -1;
}
int rmdir(const char *path)
{
return -1;
}
int rename(const char *oldName, const char *newName)
{
return -1;
}
int statfs(const char *path, struct statfs *buf)
{
return -1;
}
int ftruncate(int fd, off_t length)
{
return -1;
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return -1;
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return -1;
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View File

@@ -33,6 +33,7 @@
#include <sys/features.h>
#include <sys/types.h>
#include <sys/uio.h>
#ifdef __cplusplus
extern "C" {
@@ -41,11 +42,6 @@ extern "C" {
typedef unsigned socklen_t;
typedef unsigned short sa_family_t;
struct iovec {
void *iov_base;
size_t iov_len;
};
struct msghdr {
void *msg_name;
socklen_t msg_namelen;

View File

@@ -40,6 +40,11 @@ extern "C" {
#define UIO_MAXIOV 1024
struct iovec {
void *iov_base;
size_t iov_len;
};
ssize_t readv(int, const struct iovec *, int);
ssize_t writev(int, const struct iovec *, int);

View File

@@ -29,11 +29,16 @@
*/
#include "los_config.h"
#include "los_fs.h"
#include "stdio.h"
#include "stdarg.h"
#include <sys/ioctl.h>
#ifdef LOSCFG_LIBC_NEWLIB_FS
#include "los_fs.h"
#else
#include "sys/stat.h"
#endif
#ifdef LOSCFG_LIBC_NEWLIB_FS
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
@@ -144,7 +149,12 @@ int ftruncate(int fd, off_t length)
int ioctl(int fd, int req, ...)
{
return -1;
va_list ap;
va_start(ap, req);
int ret;
ret = LOS_Ioctl(fd, req, ap);
va_end(ap);
return ret;
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)

View File

@@ -31,7 +31,6 @@
#include <fcntl.h>
#include <poll.h>
#include "securec.h"
#include "los_fs.h"
#include "los_list.h"
#include "los_mux.h"
#include "los_sem.h"

View File

@@ -89,6 +89,8 @@ BOOL OsSchedTaskSwitch(VOID);
LosTaskCB *OsGetTopTask(VOID);
VOID OsSchedTimeConvertFreq(UINT32 oldFreq);
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
{
return LOS_SysCycleGet();

View File

@@ -78,9 +78,9 @@ STATIC INLINE VOID OsDeleteNodeSortLink(SortLinkList *sortList)
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
}
STATIC INLINE UINT64 GetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime, UINT32 tickPrecision)
STATIC INLINE UINT64 GetSortLinkNextExpireTime(SortLinkAttribute *sortHead, UINT64 startTime, UINT32 tickPrecision)
{
LOS_DL_LIST *head = &sortHeader->sortLink;
LOS_DL_LIST *head = &sortHead->sortLink;
LOS_DL_LIST *list = head->pstNext;
if (LOS_ListEmpty(head)) {
@@ -103,11 +103,13 @@ STATIC INLINE UINT64 OsGetNextExpireTime(UINT64 startTime, UINT32 tickPrecision)
}
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type);
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHead);
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
VOID OsDeleteSortLink(SortLinkList *node);
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHead);
VOID OsSortLinkResponseTimeConvertFreq(UINT32 oldFreq);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -1277,6 +1277,16 @@ extern UINT32 LOS_TaskDetach(UINT32 taskID);
*/
#define OS_TASK_STATUS_EXIT 0x0100
#if (LOSCFG_SECURE == 1)
/**
* @ingroup los_task
* Flag that indicates the task or task control block status.
*
* This task is a user mode task.
*/
#define OS_TASK_FLAG_USER_TASK 0x0200
#endif
/**
* @ingroup los_task
* Flag that indicates the task or task control block status.
@@ -1493,6 +1503,11 @@ typedef struct {
LOSCFG_TASK_STRUCT_EXTENSION /**< Task extension field */
} LosTaskCB;
STATIC INLINE BOOL OsTaskIsExit(const LosTaskCB *taskCB)
{
return ((taskCB->taskStatus & OS_TASK_STATUS_EXIT) != 0);
}
typedef struct {
LosTaskCB *runTask;
LosTaskCB *newTask;

View File

@@ -157,10 +157,6 @@ extern UINT32 g_sysClock;
#define OS_SYS_NS_TO_CYCLE(time, freq) (((time) / OS_SYS_NS_PER_SECOND) * (freq) + \
((time) % OS_SYS_NS_PER_SECOND) * (freq) / OS_SYS_NS_PER_SECOND)
#define OS_SYS_TICK_TO_CYCLE(ticks) (((UINT64)(ticks) * g_sysClock) / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_SYS_CYCLE_TO_TICK(cycle) ((((UINT64)(cycle)) * LOSCFG_BASE_CORE_TICK_PER_SECOND) / g_sysClock)
/**
* @ingroup los_tick
* System time basic function error code: Null pointer.
@@ -265,6 +261,58 @@ UINT32 OsTickTimerInit(VOID);
VOID OsTickSysTimerStartTimeSet(UINT64 currTime);
STATIC INLINE UINT64 OsTimeConvertFreq(UINT64 time, UINT32 oldFreq, UINT32 newFreq)
{
if (oldFreq >= newFreq) {
return (time / (oldFreq / newFreq));
}
return (time * (newFreq / oldFreq));
}
/**
* @ingroup los_tick
* @brief Adjust the system tick timer clock frequency function hooks.
*
* @par Description:
* This API is used to adjust the system tick timer clock frequency.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param param [IN] Function parameters.
*
* @retval 0: Adjust the system tick timer clock frequency failed.
* @retval more than zero: Adjust after the system tick timer clock frequency.
* @par Dependency:
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
typedef UINT32 (*SYS_TICK_FREQ_ADJUST_FUNC)(UINTPTR param);
/**
* @ingroup los_tick
* @brief Adjust the system tick timer clock frequency.
*
* @par Description:
* This API is used to adjust the system tick timer clock frequency.
* @attention
* <ul>
* <li>This function needs to be invoked only when the clock frequency of the system tick timer adjust as a result of
* changing the CPU frequency.</li>
* </ul>
*
* @param handler [IN] Adjust the system tick timer clock frequency function hooks.
* @param param [IN] Function parameters.
*
* @retval LOS_OK or Error code.
* @par Dependency:
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTPTR param);
/**
* @ingroup los_tick
* @brief Obtain the number of Ticks.

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -82,6 +82,15 @@
#include "los_signal.h"
#endif
#if (LOSCFG_SECURE == 1)
#include "los_syscall.h"
#include "los_box.h"
#endif
#if (LOSCFG_FS_VFS == 1)
#include "vfs_operations.h"
#endif
/*****************************************************************************
Function : LOS_Reboot
Description : system exception, die in here, wait for watchdog.
@@ -210,6 +219,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
}
#endif
#if (LOSCFG_FS_VFS == 1)
ret = OsVfsInit();
if (ret != LOS_OK) {
PRINT_ERR("OsVfsInit error\n");
return ret;
}
#endif
ret = OsIdleTaskCreate();
if (ret != LOS_OK) {
return ret;
@@ -262,6 +279,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
}
#endif
#if (LOSCFG_SECURE == 1)
OsSyscallHandleInit();
LOS_BoxStart();
#endif
return LOS_OK;
}

View File

@@ -245,6 +245,7 @@ static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
} else {
if (OS_QUEUE_IS_READ(operateType)) {
msgDataSize = *((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32)));
msgDataSize = (*bufferSize < msgDataSize) ? *bufferSize : msgDataSize;
rc = memcpy_s((VOID *)bufferAddr, *bufferSize, (VOID *)queueNode, msgDataSize);
if (rc != EOK) {
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
@@ -269,9 +270,7 @@ static INLINE UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32
return LOS_ERRNO_QUEUE_NOT_CREATE;
}
if (OS_QUEUE_IS_READ(operateType) && (*bufferSize < (queueCB->queueSize - sizeof(UINT32)))) {
return LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL;
} else if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
}

View File

@@ -47,10 +47,7 @@ extern "C" {
#define OS_PRIORITY_QUEUE_NUM 32
#define PRIQUEUE_PRIOR0_BIT 0x80000000U
#define OS_SCHED_TIME_SLICES ((LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE)
#define OS_TIME_SLICE_MIN (INT32)((50 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 50us */
#define OS_TICK_RESPONSE_TIME_MAX LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
#if (LOSCFG_BASE_CORE_TICK_RESPONSE_MAX == 0)
#error "Must specify the maximum value that tick timer counter supports!"
#endif
@@ -67,6 +64,11 @@ STATIC UINT32 g_schedResponseID = 0;
STATIC UINT16 g_tickIntLock = 0;
STATIC UINT64 g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
STATIC INT32 g_schedTimeSlice;
STATIC INT32 g_schedTimeSliceMin;
STATIC UINT32 g_schedTickMinPeriod;
STATIC UINT32 g_tickResponsePrecision;
VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
{
if (responseTime <= g_schedResponseTime) {
@@ -91,15 +93,15 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTim
BOOL isTimeSlice = FALSE;
UINT64 currTime = OsGetCurrSchedTimeCycle();
UINT64 nextExpireTime = OsGetNextExpireTime(currTime, OS_TICK_RESPONSE_PRECISION);
UINT64 nextExpireTime = OsGetNextExpireTime(currTime, g_tickResponsePrecision);
/* The response time of the task time slice is aligned to the next response time in the delay queue */
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > g_schedTickMinPeriod)) {
nextExpireTime = taskEndTime;
isTimeSlice = TRUE;
}
if ((g_schedResponseTime <= nextExpireTime) ||
((g_schedResponseTime - nextExpireTime) < OS_TICK_RESPONSE_PRECISION)) {
((g_schedResponseTime - nextExpireTime) < g_tickResponsePrecision)) {
return;
}
@@ -111,8 +113,8 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTim
}
nextResponseTime = nextExpireTime - currTime;
if (nextResponseTime < OS_TICK_RESPONSE_PRECISION) {
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
if (nextResponseTime < g_tickResponsePrecision) {
nextResponseTime = g_tickResponsePrecision;
}
g_schedResponseTime = currTime + OsTickTimerReload(nextResponseTime);
}
@@ -131,10 +133,10 @@ VOID OsSchedUpdateExpireTime(VOID)
isPmMode = OsIsPmMode();
#endif
if ((runTask->taskID != g_idleTaskID) && !isPmMode) {
INT32 timeSlice = (runTask->timeSlice <= OS_TIME_SLICE_MIN) ? (INT32)OS_SCHED_TIME_SLICES : runTask->timeSlice;
INT32 timeSlice = (runTask->timeSlice <= g_schedTimeSliceMin) ? g_schedTimeSlice : runTask->timeSlice;
endTime = runTask->startTime + timeSlice;
} else {
endTime = OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
endTime = OS_SCHED_MAX_RESPONSE_TIME - g_tickResponsePrecision;
}
OsSchedSetNextExpireTime(runTask->taskID, endTime);
}
@@ -227,10 +229,10 @@ VOID OsSchedTaskEnQueue(LosTaskCB *taskCB)
LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
if (taskCB->taskID != g_idleTaskID) {
if (taskCB->timeSlice > OS_TIME_SLICE_MIN) {
if (taskCB->timeSlice > g_schedTimeSliceMin) {
OsSchedPriQueueEnHead(&taskCB->pendList, taskCB->priority);
} else {
taskCB->timeSlice = OS_SCHED_TIME_SLICES;
taskCB->timeSlice = g_schedTimeSlice;
OsSchedPriQueueEnTail(&taskCB->pendList, taskCB->priority);
}
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, taskCB);
@@ -266,6 +268,7 @@ VOID OsSchedTaskExit(LosTaskCB *taskCB)
OsDeleteSortLink(&taskCB->sortList);
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
}
taskCB->taskStatus |= OS_TASK_STATUS_EXIT;
}
VOID OsSchedYield(VOID)
@@ -417,7 +420,44 @@ UINT32 OsTaskNextSwitchTimeGet(VOID)
UINT64 OsSchedGetNextExpireTime(UINT64 startTime)
{
return OsGetNextExpireTime(startTime, OS_TICK_RESPONSE_PRECISION);
return OsGetNextExpireTime(startTime, g_tickResponsePrecision);
}
STATIC VOID TaskSchedTimeConvertFreq(UINT32 oldFreq)
{
for (UINT32 loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
LosTaskCB *taskCB = (((LosTaskCB *)g_taskCBArray) + loopNum);
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
if (taskCB->timeSlice > 0) {
taskCB->timeSlice = (INT32)OsTimeConvertFreq((UINT64)taskCB->timeSlice, oldFreq, g_sysClock);
} else {
taskCB->timeSlice = 0;
}
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
taskCB->startTime = OsTimeConvertFreq(taskCB->startTime, oldFreq, g_sysClock);
}
}
}
STATIC VOID SchedTimeBaseInit(VOID)
{
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
g_schedTickMinPeriod = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI;
g_tickResponsePrecision = (g_schedTickMinPeriod * 75) / 100; /* 75 / 100: minimum accuracy */
g_schedTimeSlice = (INT32)(((UINT64)g_sysClock * LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT) / OS_SYS_US_PER_SECOND);
g_schedTimeSliceMin = (INT32)(((UINT64)g_sysClock * 50) / OS_SYS_US_PER_SECOND); /* Minimum time slice 50 us */
}
VOID OsSchedTimeConvertFreq(UINT32 oldFreq)
{
SchedTimeBaseInit();
TaskSchedTimeConvertFreq(oldFreq);
OsSortLinkResponseTimeConvertFreq(oldFreq);
OsSchedUpdateExpireTime();
}
UINT32 OsSchedInit(VOID)
@@ -434,7 +474,7 @@ UINT32 OsSchedInit(VOID)
}
OsSortLinkInit(g_taskSortLinkList);
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
SchedTimeBaseInit();
return LOS_OK;
}
@@ -512,7 +552,7 @@ BOOL OsSchedTaskSwitch(VOID)
if (newTask->taskID != g_idleTaskID) {
endTime = newTask->startTime + newTask->timeSlice;
} else {
endTime = OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
endTime = OS_SCHED_MAX_RESPONSE_TIME - g_tickResponsePrecision;
}
if (g_schedResponseID == runTask->taskID) {

View File

@@ -42,15 +42,15 @@ extern "C" {
SortLinkAttribute g_taskSortLink;
SortLinkAttribute g_swtmrSortLink;
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHead)
{
LOS_ListInit(&sortLinkHeader->sortLink);
LOS_ListInit(&sortLinkHead->sortLink);
return LOS_OK;
}
STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHead, SortLinkList *sortList)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
if (LOS_ListEmpty(head)) {
LOS_ListAdd(head, &sortList->sortLinkNode);
@@ -81,19 +81,19 @@ STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLin
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
{
UINT32 intSave;
SortLinkAttribute *sortLinkHeader = NULL;
SortLinkAttribute *sortLinkHead = NULL;
if (type == OS_SORT_LINK_TASK) {
sortLinkHeader = &g_taskSortLink;
sortLinkHead = &g_taskSortLink;
} else if (type == OS_SORT_LINK_SWTMR) {
sortLinkHeader = &g_swtmrSortLink;
sortLinkHead = &g_swtmrSortLink;
} else {
LOS_Panic("Sort link type error : %u\n", type);
}
intSave = LOS_IntLock();
SET_SORTLIST_VALUE(node, startTime + OS_SYS_TICK_TO_CYCLE(waitTicks));
OsAddNode2SortLink(sortLinkHeader, node);
SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
OsAddNode2SortLink(sortLinkHead, node);
LOS_IntRestore(intSave);
}
@@ -109,6 +109,31 @@ VOID OsDeleteSortLink(SortLinkList *node)
LOS_IntRestore(intSave);
}
STATIC INLINE VOID SortLinkNodeTimeUpdate(SortLinkAttribute *sortLinkHead, UINT32 oldFreq)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
if (LOS_ListEmpty(head)) {
return;
}
LOS_DL_LIST *nextNode = head->pstNext;
do {
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(nextNode, SortLinkList, sortLinkNode);
listSorted->responseTime = OsTimeConvertFreq(listSorted->responseTime, oldFreq, g_sysClock);
nextNode = nextNode->pstNext;
} while (nextNode != head);
}
VOID OsSortLinkResponseTimeConvertFreq(UINT32 oldFreq)
{
SortLinkAttribute *taskHead = &g_taskSortLink;
SortLinkAttribute *swtmrHead = &g_swtmrSortLink;
SortLinkNodeTimeUpdate(taskHead, oldFreq);
SortLinkNodeTimeUpdate(swtmrHead, oldFreq);
}
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type)
{
if (type == OS_SORT_LINK_TASK) {
@@ -130,9 +155,9 @@ UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *target
return (targetSortList->responseTime - currTime);
}
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHead)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
if (LOS_ListEmpty(head)) {
return 0;

View File

@@ -141,8 +141,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
STATIC UINT64 OsSwtmrCalcStartTime(UINT64 currTime, SWTMR_CTRL_S *swtmr, const SWTMR_CTRL_S *alignSwtmr)
{
UINT64 usedTime, startTime;
UINT64 alignEnd = OS_SYS_TICK_TO_CYCLE(alignSwtmr->uwInterval);
UINT64 swtmrTime = OS_SYS_TICK_TO_CYCLE(swtmr->uwInterval);
UINT64 alignEnd = (UINT64)alignSwtmr->uwInterval * OS_CYCLE_PER_TICK;
UINT64 swtmrTime = (UINT64)swtmr->uwInterval * OS_CYCLE_PER_TICK;
UINT64 remainTime = OsSortLinkGetRemainTime(currTime, &alignSwtmr->stSortList);
if (remainTime == 0) {
startTime = GET_SORTLIST_VALUE(&alignSwtmr->stSortList);
@@ -357,7 +357,7 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
UINT32 intSave = LOS_IntLock();
UINT64 time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
LOS_IntRestore(intSave);
time = OS_SYS_CYCLE_TO_TICK(time);
time = time / OS_CYCLE_PER_TICK;
if (time > OS_NULL_INT) {
time = OS_NULL_INT;
}
@@ -367,7 +367,7 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
LITE_OS_SEC_TEXT UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
{
UINT64 time = OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
time = OS_SYS_CYCLE_TO_TICK(time);
time = time / OS_CYCLE_PER_TICK;
if (time > OS_NULL_INT) {
time = OS_NULL_INT;
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -146,7 +146,7 @@ STATIC VOID OsRecycleTaskResources(LosTaskCB *taskCB, UINTPTR *stackPtr)
taskCB->topOfStack = (UINT32)NULL;
taskCB->taskStatus &= ~OS_TASK_FLAG_STACK_FREE;
}
if (!(taskCB->taskStatus & OS_TASK_STATUS_EXIT)) {
if (!(taskCB->taskStatus & OS_TASK_FLAG_JOINABLE)) {
OsInsertTCBToFreeList(taskCB);
}
}
@@ -931,7 +931,6 @@ STATIC VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB)
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
OsSchedTaskWake(resumedTask);
}
taskCB->taskStatus |= OS_TASK_STATUS_EXIT;
}
}
@@ -1003,7 +1002,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
}
intSave = LOS_IntLock();
taskCB->taskStatus &= ~OS_TASK_STATUS_EXIT;
taskCB->taskStatus &= ~OS_TASK_FLAG_JOINABLE;
OsRecycleTaskResources(taskCB, &stackPtr);
LOS_IntRestore(intSave);
(VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr);
@@ -1101,8 +1100,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
}
OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, taskCB);
OsSchedTaskExit(taskCB);
OsTaskJoinPostUnsafe(taskCB);
OsSchedTaskExit(taskCB);
LOS_EventDestroy(&(taskCB->event));
taskCB->event.uwEventID = OS_NULL_INT;
@@ -1122,7 +1121,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
LOSCFG_TASK_DELETE_EXTENSION_HOOK(taskCB);
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
if (!(taskCB->taskStatus & OS_TASK_STATUS_EXIT)) {
if (!(taskCB->taskStatus & OS_TASK_FLAG_JOINABLE)) {
taskCB->taskStatus |= OS_TASK_STATUS_UNUSED;
OsRunningTaskDelete(taskID, taskCB);
}

View File

@@ -48,17 +48,14 @@ LITE_OS_SEC_BSS STATIC UINT64 g_tickTimerStartTime;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
STATIC UINT64 g_tickTimerBase;
STATIC BOOL g_tickTimerBaseUpdate = FALSE;
STATIC UINT64 g_oldTickTimerBase;
LITE_OS_SEC_TEXT STATIC VOID OsUpdateSysTimeBase(VOID)
{
UINT32 period = 0;
if (g_tickTimerBaseUpdate == FALSE) {
(VOID)g_sysTickTimer->getCycle(&period);
g_tickTimerBase += period;
}
g_tickTimerBaseUpdate = FALSE;
(VOID)g_sysTickTimer->getCycle(&period);
g_tickTimerBase += period;
}
LITE_OS_SEC_TEXT VOID OsTickTimerBaseReset(UINT64 currTime)
@@ -91,21 +88,19 @@ LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID)
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 1)
return g_sysTickTimer->getCycle(NULL);
#else
STATIC UINT64 oldSchedTime = 0;
UINT32 period = 0;
UINT32 intSave = LOS_IntLock();
UINT64 time = g_sysTickTimer->getCycle(&period);
UINT64 schedTime = g_tickTimerBase + time;
if (schedTime < oldSchedTime) {
if (schedTime < g_oldTickTimerBase) {
/* Turn the timer count */
g_tickTimerBase += period;
schedTime = g_tickTimerBase + time;
g_tickTimerBaseUpdate = TRUE;
}
LOS_ASSERT(schedTime >= oldSchedTime);
LOS_ASSERT(schedTime >= g_oldTickTimerBase);
oldSchedTime = schedTime;
g_oldTickTimerBase = schedTime;
LOS_IntRestore(intSave);
return schedTime;
#endif
@@ -235,6 +230,47 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const
return LOS_OK;
}
UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTPTR param)
{
UINT32 intSave;
UINT32 freq;
UINT32 oldFreq = g_sysClock;
if (handler == NULL) {
return LOS_ERRNO_SYS_HOOK_IS_NULL;
}
intSave = LOS_IntLock();
g_sysTickTimer->lock();
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 currTimeCycle = LOS_SysCycleGet();
#endif
freq = handler(param);
if ((freq == 0) || (freq == g_sysClock)) {
g_sysTickTimer->unlock();
LOS_IntRestore(intSave);
return LOS_ERRNO_SYS_CLOCK_INVALID;
}
g_sysTickTimer->reload(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
g_sysTickTimer->unlock();
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
g_tickTimerBase = OsTimeConvertFreq(currTimeCycle, oldFreq, freq);
g_oldTickTimerBase = OsTimeConvertFreq(g_oldTickTimerBase, oldFreq, freq);
g_tickTimerStartTime = OsTimeConvertFreq(g_tickTimerStartTime, oldFreq, freq);
#endif
g_sysTickTimer->freq = freq;
g_sysClock = g_sysTickTimer->freq;
g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND;
OsSchedTimeConvertFreq(oldFreq);
LOS_IntRestore(intSave);
return LOS_OK;
}
LITE_OS_SEC_TEXT_MINOR VOID OsTickSysTimerStartTimeSet(UINT64 currTime)
{
g_tickTimerStartTime = currTime;
@@ -249,7 +285,7 @@ Return : current tick
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
{
return OS_SYS_CYCLE_TO_TICK(LOS_SysCycleGet() - g_tickTimerStartTime);
return (LOS_SysCycleGet() - g_tickTimerStartTime) / g_cyclesPerTick;
}
/*****************************************************************************

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -2288,7 +2288,7 @@ UINT32 OsMemSystemInit(VOID)
#endif
ret = LOS_MemInit(m_aucSysMem0, LOSCFG_SYS_HEAP_SIZE);
PRINT_INFO("LiteOS heap memory address:%p, size:0x%lx\n", m_aucSysMem0, LOSCFG_SYS_HEAP_SIZE);
PRINT_INFO("LiteOS heap memory address:%p, size:0x%lx\n", m_aucSysMem0, (unsigned long int)LOSCFG_SYS_HEAP_SIZE);
return ret;
}

View File

@@ -48,7 +48,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -47,7 +47,7 @@ static UINT32 Testcase(VOID)
// 6, Set a value less than QUEUE_BASE_MSGSIZE, for test erro code LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL
ret = LOS_QueueRead(g_testQueueID01, &buff2, 6, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -45,9 +45,6 @@ static UINT32 Testcase(VOID)
ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, for boundary value test
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
// 6, to verify the correct value

View File

@@ -45,7 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 6, 0); // 6 < QUEUE_BASE_MSGSIZE for erro code LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:
ret = LOS_QueueDelete(g_testQueueID01);

View File

@@ -45,9 +45,6 @@ static UINT32 Testcase(VOID)
ret = LOS_QueueWriteHead(g_testQueueID01, buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, read size
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ICUNIT_GOTO_EQUAL(*((char *)(intptr_t)buff2 + 6), buff1[6], *((char *)(intptr_t)buff2 + 6), EXIT); // 6, In order to verify the content

View File

@@ -45,7 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, buffer2 max - 1
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:
ret = LOS_QueueDelete(g_testQueueID01);