Compare commits

...

166 Commits

Author SHA1 Message Date
openharmony_ci
b62463abc5 !594 处理M核编译告警
Merge pull request !594 from yinjiaming/OpenHarmony-3.0-LTS
2022-02-15 01:21:53 +00:00
yinjiaming
6ffea886d3 fix: 编译告警清零
【背景】

3.0 LTS 告警清零

【修改方案】
添加了安全函数的检查,将不安全的函数改写为安全函数

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

re #I4TM2U

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I4479172e755821916aa6f299607fdceac763d468
2022-02-14 12:41:52 +00:00
openharmony_ci
9de6f57cda !549 挑单 pthread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码
Merge pull request !549 from wangchen/exit_3
2022-01-18 03:54:25 +00:00
openharmony_ci
307ab396a5 !548 挑单 L0 pthread_cond_timedwait接口存在计算溢出
Merge pull request !548 from wangchen/cond_3
2022-01-18 03:53:40 +00:00
wangchen
96b2eaeab6 fix: thread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码
【背景】thread_create创建的线程未设置detach属性,主动退出后,OsGetAllTskInfo调用后,相关的任务名为乱码

【修改方案】
修改线程退出流程
【影响】
对现有的产品编译不会有影响。

re #I4R4D3
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-01-17 08:02:20 +00:00
wangchen
58e67dde3b fix: L0 pthread_cond_timedwait接口实现存在的几个问题
【背景】L0 pthread_cond_timedwait接口存在计算溢出

【修改方案】
1,新增abstick 相关修改,先判断再转成32位,避免截断
2,LOS_Event相关函数返回值的处理已存在,无需处理
【影响】
对现有的产品编译不会有影响。

re #I4R4A5
Signed-off-by: wangchen <wangchen64@huawei.com>
2022-01-17 07:14:09 +00:00
openharmony_ci
f74067b24f !519 chore: shell体验优化
Merge pull request !519 from huangshan/cherry-pick-1640932575
2022-01-07 03:21:00 +00:00
huangshan
86bc68744d fixed 57cff79 from https://gitee.com/uhamc/kernel_liteos_m/pulls/386
chore: shell完善帮助信息,特殊处理不可见字符

Signed-off-by: huangshan <huangshan9@huawei.com>
Change-Id: I3cbc559c388b5d5a524783c1f55c1e569a44465c
2021-12-31 06:36:18 +00:00
openharmony_ci
39db69b6bf !478 添加bundle.json
Merge pull request !478 from pjscc/OpenHarmony-3.0-LTS
2021-12-31 03:13:18 +00:00
openharmony_ci
87c6e9476d !500 【fix】api_shell.c 宏修改
Merge pull request !500 from pef/lts_sync
2021-12-30 08:20:32 +00:00
openharmony_ci
94537e17ae !507 fix:在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁 挑单到3.0分支
Merge pull request !507 from x_xiny/fix_pthread_mutex_lock
2021-12-29 07:21:32 +00:00
openharmony_ci
9717eafff7 !514 fix the compile warning
Merge pull request !514 from laojr1/OpenHarmony-3.0-LTS
2021-12-29 06:23:04 +00:00
老家荣
0712c2df56 chore: 解决 cmsis_liteos2.c:115:23: warning 编译告警
Signed-off-by: laojr1 <laojr1@midea.com>
2021-12-29 14:11:44 +08:00
pjscc
50b4e91f91 feat: 添加bundle.json作为hpm包管理描述文件
Signed-off-by: pjscc <pangjiashuai@huawei.com>
2021-12-29 10:33:46 +08:00
openharmony_ci
443d9deb9b !483 fix: 修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题
Merge pull request !483 from kenneth/cherry-pick-1640158553
2021-12-29 00:54:26 +00:00
kenneth
caa28225a8 fixed d32e25f from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/362
fix: 修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题

修复los_interrupt.c文件中HalHwiInit函数里未使能未对齐异常问题

close #I4EJGR

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-28 09:13:14 +08:00
openharmony_ci
fdb12dbe31 !486 fix: 移除los_arch_interrupt.h文件中冗余声明的函数VOID OsExcInit(VOID)
Merge pull request !486 from kenneth/cherry-pick-1640158838
2021-12-28 00:54:46 +00:00
openharmony_ci
8ebfe352f5 !490 fix: gcc编译testsuite编译问题修复
Merge pull request !490 from kenneth/cherry-pick-1640160367
2021-12-28 00:53:56 +00:00
x-xiny
2332f34a79 fix:在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁
【背景】
 在非静态初始化条件下pthread_mutex_lock,没有经过init初始化就可以对已销毁的锁进行加锁

【修改方案】
 在pthread_mutex_destroy中将mutex的magic标记字段清除

 re #I4I7OA

 Signed-off-by: x-xiny <1301913191@qq.com>

Change-Id: I5d4cceff852e20e659a7cd06acf27cc6f381962c
2021-12-27 06:23:22 +00:00
pef
314af71a48 fix: 将未定义小写"true","false"改为"TRUE","FALSE"。
【背景】
api_shell.c文件使用小写的true和false 却没有定义
[OHOS ERROR] ../../../kernel/liteos_m/components/net/lwip-2.1/porting/src/api_shell.c:342:25: error: 'false' undeclared (first use in this function)
[OHOS ERROR]      BOOL timeout_flag = false;
编译报错。
【修改方案】
1. 将未定义的 true,false改为已定义的宏TRUE,FALSE。

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

re #I43D20

Change-Id: If66adab35f2315d0caca2a487960be887567126b
Signed-off-by: pef <cyd1997@126.com>
2021-12-27 09:55:08 +08:00
openharmony_ci
2ef5ff366e !488 fix: 删除LOS_TRACE 记录SWTMR_START中的无效字段
Merge pull request !488 from Zhaotianyu/cherry-pick-1640159998
2021-12-23 08:46:38 +00:00
openharmony_ci
5acd9b36ff !481 fix:修复Fault异常模块中FPU宏等问题
Merge pull request !481 from kenneth/cherry-pick-1640158227
2021-12-23 07:17:18 +00:00
openharmony_ci
314102c234 !485 fix: los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误
Merge pull request !485 from kenneth/cherry-pick-1640158674
2021-12-23 07:15:36 +00:00
openharmony_ci
b31437fe27 !489 fix: 解决los_pm.c:743:19: warning 编译告警
Merge pull request !489 from kenneth/cherry-pick-1640160304
2021-12-23 07:11:28 +00:00
openharmony_ci
a2852d8bce !482 fix:hook层LOS_HOOK_TYPE_SEM_PEND的runningTask入参可能为空
Merge pull request !482 from Zhaotianyu/cherry-pick-1640158494
2021-12-22 09:33:02 +00:00
openharmony_ci
0ce46a3989 !484 fix:修复不能开启硬浮点选项的问题
Merge pull request !484 from Zhaotianyu/cherry-pick-1640158615
2021-12-22 09:32:42 +00:00
openharmony_ci
b5db6ee2d4 !487 解决gmtime和localtime接口由于g_tm全局变量导致的竞态问题
Merge pull request !487 from JerryH/cherry-pick-1640159938
2021-12-22 08:47:05 +00:00
kenneth
f0ed09be65 fixed f7d26b8 from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/343
fix: gcc编译testsuite编译问题修复

修复It_los_mem.h中没有定义LOS_DLNK_NODE_HEAD_SIZE、MIN_DLNK_POOL_SIZE,编译告警等问题。

close #I4DAOU

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 08:06:07 +00:00
kenneth
802e01de21 fixed 0c72c8b from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/340
fix: 解决los_pm.c:743:19: warning 编译告警

修复PRINT_ERR函数格式化参数数目不一致。

close #I4D4L8

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 08:05:04 +00:00
LiteOS2021
d95a1523f2 fixed afbc9a5 from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/348
fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
close #I4DPR7

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2021-12-22 07:59:58 +00:00
JerryH
0a1df72f7e fixed 1454b76 from https://gitee.com/JerryH1011/kernel_liteos_m/pulls/454
fix: 解决gmtime和localtime接口由于g_tm全局变量导致的竞态问题

删除全局变量,接口使用自己的内部静态变量,避免竞态

Close #I4LW3H

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I3c74b1897b3909df93d21b9d521af270cc6fc610
2021-12-22 07:59:00 +00:00
kenneth
48484444ce fixed 136952f from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/342
fix: 移除los_arch_interrupt.h文件中冗余声明的函数VOID OsExcInit(VOID)

VOID OsExcInit(VOID)函数的注释中参数描述错误,并且该函数并没有在C源文件中使用到,需要删除。

close #I4D9OO

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:40:38 +00:00
kenneth
6240af2522 fixed c51df7a from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/363
fix: los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误

修复los_exc.S中_ExcInMsp主栈中异常处理函数中异常返回类型错误

close #I4EJI4

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:37:56 +00:00
arvinzzz
b1b46451e7 fixed 988fd85 from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/300
fix: 支持硬浮点编译

1. 通过本工程的gn编译时,需要在device目录下,单板的关于内核的config.gn中指定-mfloat-abi的等级,并在单板相关代码的编译选项中保持-mfloat-abi一致
2. 通过本工程的Makefile编译时,需要在kernel/liteos_m/targets/下添加单板相关的代码配置,在Makefile中设置-mfloat-abi即可
3. 通过IDE编译本工程时,需要在IDE的汇编文件相关编译选项中加入 -imacros $(LITEOSTOPDIR)/kernel/include/los_config.h,保证浮点等级在汇编文件中生效

close: #I48KJP
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ibf9b750b922be2530de349981d55e40b5919933f
2021-12-22 07:36:56 +00:00
arvinzzz
54936c19bd fixed 3fd22ac from https://gitee.com/arvinzzz/kernel_liteos_m/pulls/324
fix: 修复hook层LOS_HOOK_TYPE_SEM_PEND的runningTask入参可能为空

在校验完semPend之后,就获取好runningTask并且与semPend关联

close: #I4BU4P
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib56a1a1db8e4471d9e2adb0b7c3d8b17b1f87b8d
2021-12-22 07:34:56 +00:00
kenneth
7a6242549f fixed 2da043c from https://gitee.com/rtos_yuan/kernel_liteos_m/pulls/367
fix:修复Fault异常模块中FPU宏等问题

去掉不必要的宏判断__FPU_PRESENT;参数变量名称 uwPid改为pid,和函数HalExcHandleEntry的参数保持一致

close #I4D575

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-22 07:30:27 +00:00
openharmony_ci
07ef35ccdf !467 pthread_cond_timedwait接口不规范
Merge pull request !467 from wangchen/posix_cond
2021-12-20 03:53:26 +00:00
wangchen
08e3025ec5 fix: pthread_cond_timedwait接口入参不规范
【背景】pthread_cond_timedwait函数的入参时间应该是绝对时间

【修改方案】
1,修改为相对时间
2,每次等待事件前清理

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

re #I4MVUO
Signed-off-by: wangchen <253227059@qq.com>
2021-12-20 01:39:45 +00:00
openharmony_ci
ae2c3c5823 !463 fix: tick中断处理时,无挂起任务时应更新当前运行任务的时间片, 并触发一次调度
Merge pull request !463 from zhushengle/cherry-pick-1639542040
2021-12-17 03:25:22 +00:00
zhushengle
d32fea7096 fixed ea12d40 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/456
fix: tick中断处理时,无挂起任务时应更新当前运行任务的时间片, 并触发一次调度

Close #I4LRZG

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I4472fb50c775b832688aa7a555498901a80e2999
2021-12-15 04:20:42 +00:00
openharmony_ci
915e5b9517 !438 fix: 取消cpu进入低功耗前开中断操作,优化注册机制
Merge pull request !438 from zhushengle/cherry-pick-1638271705
2021-12-03 09:26:16 +00:00
zhushengle
6e665e6771 fixed bd39e9e from https://gitee.com/zhushengle/kernel_liteos_m/pulls/435
fix: 取消cpu进入低功耗前开中断操作

    开中断导致低功耗流程非原子,容易造成流程出错。
    提供低功耗默认处理函数,优化注册机制

Close #I4KDP8
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ied8bab691e7725e207b8b3cfb058f851eafe3052
2021-11-30 11:28:25 +00:00
openharmony_ci
a338ba8f69 !391 补充内存释放函数和去除多余参数。
Merge pull request !391 from pef/OpenHarmony-3.0-LTS
2021-11-25 08:33:08 +00:00
pef
81d02b4fea 补充内存释放函数和去除多余参数。
【背景】
1.有手动申请内存在return前未释放。
2.PRINTK存在多余参数

【修改方案】
1. 添加free(fullpath),释放内存。
2. 去掉多余参数。

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

Change-Id: Ifa74d5b443e98b03c10a34cca4ce6eaebfb2a120
Signed-off-by: pef <cyd1997@126.com>
2021-11-25 03:21:20 +00:00
openharmony_ci
bd607c8922 !388 fix: 修复cortex-m系列系统提供的timer在低频下时间不准的问题
Merge pull request !388 from zhushengle/cherry-pick-1636507317
2021-11-11 02:38:39 +00:00
zhushengle
f23481e041 fixed 3e569ba from https://gitee.com/zhushengle/kernel_liteos_m/pulls/385
fix: 修复cortex-m系列系统提供的timer在低频下时间不准的问题

触发场景:
    cpu主频比较高,timer频率较低时,当SysTick->VAL == 0时,
触发tick中断,在中断中系统将当前周期累加到基准时间里,在中
断结束更新tick响应时间时,会更新系统基准时间(为了让时间更
加准确)此时由于SysTick->VAL任然等于0,接口HalGetTickCycle
返回的仍然是当前周期,导致该周期被累加了两次。

解决方案:
    接口HalGetTickCycle在SysTick->VAL == 0时返回0.
因为SysTick->VAL == 0时,必然会触发tick中断,周期
的累加是由中断处理的,此时只需要返回0即可。

Close #I4HBGR
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iba6e8799b0ae851fc94aa23867b2360a4245994d
2021-11-10 01:21:57 +00:00
openharmony_ci
792b131d55 !379 修改inet_addr等宏为函数,外层调用可不包含lwip头文件
Merge pull request !379 from 刘建东/cherry-pick-1635579054
2021-10-30 08:57:44 +00:00
YOUR_NAME
3969fbfac8 fixed b30e913 from https://gitee.com/life-liu/kernel_liteos_m/pulls/377
fix: switch inet_addr to a function

switch inet_addr to a function

close: #I4G4I4

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-30 07:30:54 +00:00
openharmony_ci
33e2b5e085 !376 m核优化lwip默认配置
Merge pull request !376 from 刘建东/cherry-pick-1635479803
2021-10-30 03:08:58 +00:00
YOUR_NAME
79099bb28c fixed b2e3849 from https://gitee.com/life-liu/kernel_liteos_m/pulls/375
fix: optimize default configuration

optimize default configuration

close: #I4FSC9

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-29 14:46:02 +08:00
openharmony_ci
11e8e895d3 !373 m核ioctl支持SIOCGIFBRDADDR选项
Merge pull request !373 from 刘建东/cherry-pick-1635300312
2021-10-29 02:19:05 +00:00
YOUR_NAME
a562b67f90 fixed 33ee492 from https://gitee.com/life-liu/kernel_liteos_m/pulls/360
feat: add option SIOCGIFBRDADDR for ioctl

add option SIOCGIFBRDADDR for ioctl

close: #I4EGNG

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-27 02:05:13 +00:00
openharmony_ci
fafd3b66d4 !365 fix:修复文件系统vfs层未正确判空g_fs的问题
Merge pull request !365 from Far/cherry-pick-1634701427
2021-10-20 04:18:58 +00:00
Far
5e3a29dd97 fix:修复文件系统vfs层未正确判空g_fs的问题
Close #I4ELVA

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: Id8cbbd6c65df0411f22af11412f01b57fa8c27d1
2021-10-20 11:50:35 +08:00
openharmony_ci
d1d19e088d !352 fix: 调用LOS_TaskDetach操作已退出的joinable的任务时,未正确回收该任务
Merge pull request !352 from zhushengle/cherry-pick-1634283734
2021-10-15 10:38:32 +00:00
zhushengle
2c85b0ec6d fixed 49c93b3 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/351
fix: 调用LOS_TaskDetach操作已退出的joinable的任务时,未正确回收该任务

Close #I4DZL7
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iac88818317c07807d0636712025f2c75b3b1f766
2021-10-15 07:42:15 +00:00
openharmony_ci
773613af16 !333 fix: OS_TASK_STACK_PROTECT_SIZE undeclared error
Merge pull request !333 from kenneth/mpu-3.0
2021-09-29 03:49:03 +00:00
openharmony_ci
0f0e4dfafd !334 fix: LOS_QueueInfoGet函数统计等待读写任务有误
Merge pull request !334 from kenneth/queue-3.0
2021-09-29 02:57:37 +00:00
kenneth
2a5a515f50 fix: fix OS_TASK_STACK_PROTECT_SIZE undeclared error
当开启LOSCFG_EXC_HARDWARE_STACK_PROTECTION宏时,增加定义OS_TASK_STACK_PROTECT_SIZE宏

close #I4C5RW

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-09-28 10:30:49 +08:00
kenneth
215a1f6dc0 fix: LOS_QueueInfoGet函数统计等待读写任务有误
LOS_QueueInfoGet使用32位无符号数组来记录阻塞队列的任务,每个数组元素的每个bit位对应一个任务编号。
比如第一个数组元素的32个bit位对应任务编号0-31,第二个数组元素的32个bit位对应任务编号32-63....计算任务对应的数组的bit位数时使用
掩码OS_WAIT_TASK_ARRAY_ELEMENT_MASK的值应该为31,不应该依赖任务最大数目。

close #I4C6P2

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-09-28 10:18:41 +08:00
openharmony_ci
093af869d5 !329 解决dailycheck告警
Merge pull request !329 from Caoruihong/cherry-pick-1632647820
2021-09-26 10:14:11 +00:00
openharmony_ci
ef8d27db07 !329 解决dailycheck告警
Merge pull request !329 from Caoruihong/cherry-pick-1632647820
2021-09-26 10:14:10 +00:00
openharmony_ci
b22234dd6a !326 fix: 添加文件版权头等信息
Merge pull request !326 from Harylee/cherry-pick-1632645903
2021-09-26 09:34:41 +00:00
Caoruihong
5169a23adf fixed 4aba2c0 from https://gitee.com/caoruihong/kernel_liteos_m/pulls/327
chore: fix dailycheck issues

master --> HEAD
remove useless @since

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Id3452cccdcc823c374f873cf4905015351580d15
2021-09-26 09:17:00 +00:00
Haryslee
bc42e348d0 fixed cf4e017 from https://gitee.com/harylee/kernel_liteos_m/pulls/325
fix: 添加文件版权头等信息

close #I4BXBH

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Id798eec0473a9b8e18b1c8be31f3dd6babb879b0
2021-09-26 08:45:03 +00:00
openharmony_ci
93cc5747a2 !322 feat: 支持posix 和 cmsis join能力
Merge pull request !322 from zhushengle/cherry-pick-1632465410
2021-09-24 08:10:40 +00:00
zhushengle
96b4c460e2 fixed ecfdf7f from https://gitee.com/zhushengle/kernel_liteos_m/pulls/311
feat: 支持posix 和 cmsis join能力

支持API:
  LOS_TaskJoin
  LOS_TaskDeatch
  pthread_join
  pthread_deatch
  osThreadJoin
  osThreadDetach
Close #I44V26

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib61e69c280eef2e4b3b79d9bba7bbd5a300c7fe4
2021-09-24 06:36:51 +00:00
openharmony_ci
23f634bde5 !319 fix: 修复pthread_create行为与posix不一致问题
Merge pull request !319 from zhushengle/cherry-pick-1632447173
2021-09-24 06:10:15 +00:00
openharmony_ci
aee17ecfa6 !320 cherry-pick PR259: 完善CMSIS-RTOS V2部分接口(osSemaphoreNew,osThreadJoin)
Merge pull request !320 from Caoruihong/cherry-pick-1632450240
2021-09-24 02:26:39 +00:00
Caoruihong
9b160141c4 fixed d478152 from https://gitee.com/caoruihong/kernel_liteos_m/pulls/259
feat(cmsis): support max_count for osSemaphoreNew

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Iacb6cb7771ae32ea1ca645c72fda241e8e85d422
2021-09-24 02:24:01 +00:00
zhushengle
3141961013 fixed 2b1e5a7 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/308
fix: 修复pthread_create行为与posix不一致问题

1.提升posix接口和LOS接口的兼容性
2.支持优先级继承属性

Close #I49W9F
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I4d9df778a559f094dd3062e5e7030e3a03c884ec
2021-09-24 01:32:54 +00:00
openharmony_ci
51a6c21315 !315 fix: risc-v 低功耗下存在功能问题
Merge pull request !315 from zhushengle/cherry-pick-1631945741
2021-09-22 03:55:32 +00:00
zhushengle
c5a9ba4abf fixed 9f185b5 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/314
fix: pm模块解冻线程时存在删除空链表且时间片频繁唤醒系统

1.如果冻结线程状态为delay,则此时pendlist为NULL,解冻时不需要delete
2.低功耗时关闭时间片,减少时间片频繁唤醒系统
3.risc-v 中64位相加存在溢出
Close #I4AKUS

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Icb9e8f7df8488635f9660d3932b06fa6f57e6133
2021-09-18 06:15:45 +00:00
openharmony_ci
7fa979c67c !313 挑单 shell模块task命令踩内存问题修改
Merge pull request !313 from wangchen/shell_lts
2021-09-17 07:46:26 +00:00
wangchen
b5e84d5516 fix: shell模块task命令踩内存问题修改
【背景】定期M核代码消除。

【修改方案】
1,对task命令中获取内存信息时的入参进行调整,避免引起内存问题

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

re #II4AIAQ
Signed-off-by: wangchen <253227059@qq.com>
2021-09-17 14:35:27 +08:00
openharmony_ci
c277e8d543 !309 feat: 低功耗支持冻结线程等需求
Merge pull request !309 from zhushengle/cherry-pick-1631622669
2021-09-15 00:58:09 +00:00
zhushengle
230a2f348f fixed 9b5739a from https://gitee.com/zhushengle/kernel_liteos_m/pulls/298
feat: 低功耗支持冻结线程等需求

1.支持低功耗时冻结线程
2.支持延时锁
3.低功耗与idle分离
4.支持对接电源管组件的低功耗接口
LOS_PmReadLock --- 常阻塞,低功耗线程阻塞于该接口,当系统无任何模块持锁时会唤醒低功耗线程, 触发低功耗流程
LOS_PmSuspend --- 进入低功耗流程
Close #I49FJF

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I009255cfa1852b109dd8bfaf9c779e976660d621
2021-09-14 12:31:10 +00:00
openharmony_ci
92e3844061 !303 fix: 修复pm编译告警导致内核编译失败
Merge pull request !303 from zhushengle/cherry-pick-1631346536
2021-09-11 08:52:28 +00:00
zhushengle
088a6d5bbd fixed 18b0524 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/301
fix: 修复pm编译告警导致内核编译失败

Close #I49MIN
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I6b448790b170bf5980d16698ecfff27bda6c3600
2021-09-11 07:48:56 +00:00
openharmony_ci
d4d6489fb9 !297 fix: 优化低功耗流程
Merge pull request !297 from zhushengle/cherry-pick-1631173853
2021-09-09 09:00:36 +00:00
zhushengle
c1b2b15a87 fixed c6600d9 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/281
fix: 优化低功耗流程

1.normal和其它模式分离,流程分层化,使得结构较为清晰
2.tick timer处理实现优化为注册对应机制则默认支持,不注册则不执行,简化使用逻辑
3.添加 pm测试用例
Close #I46VXK

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7810ce0ca12dce96972399adf88e8319bb487905
2021-09-09 07:50:56 +00:00
openharmony_ci
1d9a5820f2 !291 修复HalTickStart错误的函数参数定义
Merge pull request !291 from 野生毛霉君/master
2021-09-07 06:11:28 +00:00
mucor
4443b74ea6 fix: fix bad params def in HalTickStart
close: #I48YWT

Signed-off-by: mucor <mucorwang@gmail.com>
2021-09-07 11:40:17 +08:00
openharmony_ci
6e1bdfe1de !275 fix: 内核模块编译增加-Werror编译选项,且清除内核编译告警
Merge pull request !275 from zhushengle/Werror
2021-09-06 11:16:42 +00:00
zhushengle
3798091d87 fix: 内核模块编译增加-Werror编译选项,且清除内核编译告警
Close #I46E6S

Change-Id: If1362c02a0a344da881a9bf90e41f0a43ba33609
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-09-06 16:16:43 +08:00
openharmony_ci
459cabf7de !286 按任务统计已经alloc的内存大小
Merge pull request !286 from lnlan/taskinfo
2021-09-01 01:48:21 +00:00
lnlan
475db62db1 feat: los_memory.c代码重复率处理
【背景】
los_memory.c中有4处遍历内存节点的操作,重复率较高
【修改方案】
1.提取一个遍历内存节点的函数,入参可传入处理函数来应对不同处理场景
【影响】
对现有的产品编译不会有影响。

re #I44WNU

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: Iafd25be39e76ee29e4fb27e5ef65f1888cc23f02
2021-08-31 02:30:30 +00:00
openharmony_ci
d46c69ee78 !266 新增内存分析工具
Merge pull request !266 from Denny/memtools
2021-08-30 07:14:07 +00:00
openharmony_ci
047203b7fb !287 修复software timer线程 readsize在第一次循环后可能未被正确赋值的问题
Merge pull request !287 from xfan1024/master
2021-08-28 09:06:20 +00:00
xiaofan
61cbf83f5d fix:修复software timer线程
readsize在第一次循环后可能未被正确赋值的问题

Signed-off-by: xiaofan <xiaofan@iscas.ac.cn>
2021-08-28 16:23:37 +08:00
lnlan
53117f9f47 feat: 按任务统计已经alloc的内存大小
【背景】
m核需补充shell命令,按任务统计已经alloc的内存大小
【修改方案】
1.新增在task命令中,在打印task
info前遍历所有内存节点,统计各任务所占用的内存节
点大小,在打印时将其打出。
2.内存节点中,taskid所占位数随系统最大任务数调整
【影响】
对现有的产品编译不会有影响。

re #I44WNU

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: I080b5dd056966784c0752408f9e320ca0e97c7f7
2021-08-28 06:14:34 +00:00
openharmony_ci
75f975c424 !279 feat: 完善m核qemu串口驱动,支持shell输入
Merge pull request !279 from lnlan/shell_fix
2021-08-26 02:03:22 +00:00
lnlan
c4dc5ab0f8 feat: 完善m核qemu串口驱动,支持shell输入
【背景】
m核qemu需完善串口驱动,支持shell输入
【修改方案】
1.完善串口驱动
2.添加shell任务,获取串口输入并下发处理
【影响】
对现有的产品编译不会有影响。

re #I46N7F

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: Ib58d4e633081743e64412cb65aa209d3356d6c1c
2021-08-26 01:15:17 +00:00
openharmony_ci
c8015dcb49 !282 m核lwip增加dhcp_is_bound接口
Merge pull request !282 from 刘建东/master
2021-08-24 10:30:36 +00:00
openharmony_ci
7719bb28e5 !283 M核编译配置修改
Merge pull request !283 from wangchen/gn_codex
2021-08-24 07:05:59 +00:00
YOUR_NAME
84a180d585 feat: add interface of dhcp_is_bound
add interface of dhcp_is_bound

close: #I46W08

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-24 11:34:03 +08:00
wangchen
deff7c921f fix: M核编译配置修改
【背景】完善M核编译配置选项。

【修改方案】
1,在build.gn中添加config.gni的包含
2,修改部分build.gn中的格式规范问题

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

re #I46XEA
Signed-off-by: wangchen <253227059@qq.com>
2021-08-24 10:57:48 +08:00
openharmony_ci
e4e3caccf2 !272 m核lwip和hilog解耦,简化配置
Merge pull request !272 from 刘建东/master
2021-08-23 02:48:58 +00:00
openharmony_ci
19aa1bb5bc !278 M核告警消除
Merge pull request !278 from wangchen/m_codex
2021-08-21 09:34:31 +00:00
openharmony_ci
9996ef80d6 !269 M33平台GCC环境下TZ增加默认选项适配
Merge pull request !269 from wangchen/new_tz
2021-08-21 09:31:36 +00:00
wangchen
f63c45930c 【背景】M33平台GCC环境下TZ默认开启TZ。
【修改方案】
1,在M33平台下增加默认选项及开关
2,删除build.gn编译tz的部分,该部分由使用者编译在安全态
3,修改tz初始化的一个问题

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

re #I45UYU
Signed-off-by: wangchen <253227059@qq.com>
2021-08-20 20:01:01 +08:00
wangchen
5a9d53b644 fix: M核告警消除
【背景】定期M核代码消除。

【修改方案】
1,根据工具扫描结果,对代码告警进行更改

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

re #I46LHG
Signed-off-by: wangchen <253227059@qq.com>
2021-08-20 18:44:33 +08:00
YOUR_NAME
be03374c3c refactor: decouple lwip and hilog for liteos_m
decouple lwip and hilog for liteos_m

close: #I46DAH

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-20 16:17:32 +08:00
openharmony_ci
4e11ded476 !267 fix: 删除延时节点后,存在时间无法有效刷新的场景
Merge pull request !267 from zhushengle/sched
2021-08-19 00:39:21 +00:00
openharmony_ci
8023547244 !270 解决中断操作等接口头文件位置变更,引入的编译问题
Merge pull request !270 from JerryH/hwi
2021-08-18 07:31:59 +00:00
JerryH
013a953926 fix: 修复中断操作接口头文件位置变更,导致的编译错误
close #I4665Z

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I5596179dea198dfe571420a7640abb00587abee1
2021-08-18 14:47:59 +08:00
openharmony_ci
97c4a5813f !249 堆内存算法支持多段非连续性内存区域
Merge pull request !249 from kenneth/multiple_mem
2021-08-17 07:43:18 +00:00
openharmony_ci
ada151d89b !268 删除m核lwip未使用的头文件和宏
Merge pull request !268 from 刘建东/master
2021-08-17 07:26:21 +00:00
kenneth
0facb0c017 feat: support non-continuous memory regions
The multiple non-continuous memory regions are supported when the macro
LOSCFG_MEM_MUL_REGIONS is enabled. The array of the type LOS_MEM_REGION should be defined,
and each array element defines the start address and the length for each memory regions, \
begining from the lower address to the higher memory address.

close #I43XOP

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-08-17 09:07:04 +08:00
YOUR_NAME
7ad3a22b4d fix: delete unused symbols for default config
delete unused symbols for default config

close: #I45HN3

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-08-16 17:54:52 +08:00
zhushengle
0a87c04d58 fix: 删除延时节点后,存在时间无法有效刷新的场景
1.从延时队列上删除延时节点时,如果该延时节点的响应时间比当前系统tick的响应时间小时,
将tick的响应时间修改为OS_SCHED_MAX_RESPONSE_TIME,以保证tick响应时间能够被刷新。
2.任务切换时,若g_schedResponseID为旧任务的taskID时(tick的响应时间为旧任务的时间片
结束时间),将tick的响应时间修改为OS_SCHED_MAX_RESPONSE_TIME。
Close #I45I9Y

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ia77b789a10112935b719e8f733ba33835894e060
2021-08-14 15:53:28 +08:00
denny
ee3403deaf feat: 新增ROM/RAM分析工具
Signed-off-by: denny <denny.shenwei@huawei.com>
2021-08-14 15:19:47 +08:00
openharmony_ci
02beb6b04d !265 fix: 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效
Merge pull request !265 from zhushengle/sched_time
2021-08-14 06:23:30 +00:00
zhushengle
509cf59bef fix: 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效
初始化调度时间不以g_sysSchedStartTime是否为0为界限,而以g_sysSchedStartTime是否为64位最大值,
为界限, 避免特殊以下场景:调度开启时系统时间为0,导致初始化的g_sysSchedStartTime还是0,导致
调度启动后获取的调度时间轴始终为0.

Close #I45HP5

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie0ef4e7d149f09ac466c649c0f2d6538f5322439
2021-08-14 11:30:46 +08:00
openharmony_ci
2868891bc8 !264 feat: L0 arm qemu剥离工具链头文件
Merge pull request !264 from give-me-five/master
2021-08-12 09:07:09 +00:00
silen
67d74559d1 feat: L0 armquem 剥离工具链
Change-Id: I19c13fd24141271087948fad9434558b823df62b
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-12 16:23:31 +08:00
openharmony_ci
251a597bb4 !263 fix: 修复文档链接失效问题
Merge pull request !263 from Harylee/qemu
2021-08-12 07:51:49 +00:00
Haryslee
5d53c84812 fix: 修复文档链接失效问题
close #I4529I

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ia3c885789f11bcbfeafaabf1c835bee93bcc54c0
2021-08-12 14:59:13 +08:00
openharmony_ci
af5bc32e38 !261 宏LOSCFG_SUPPORT_FATFS在fs.c中存在使用问题,导致无fatfs的情况下,编译出错
Merge pull request !261 from zhangfanfan2/master
2021-08-12 02:01:00 +00:00
zhangfanfan2
c1614ce2b4 fix: 宏LOSCFG_SUPPORT_FATFS在fs.c中存在使用问题,导致无fatfs的情况下,编译出错
代码中使用#ifdef LOSCFG_SUPPORT_FATFS控制业务逻辑,但LOSCFG_SUPPORT_FATFS的
默认定义为:#define LOSCFG_SUPPORT_FATFS 0,这样#ifdef LOSCFG_SUPPORT_FATFS控制
的逻辑一定会被编译。修改方式:使用的地方统一为#if的形式

close: #I44XNR

Signed-off-by: zff <zhangfanfan2@huawei.com>
2021-08-11 09:32:09 +00:00
openharmony_ci
93f029b430 !250 某些编译器下编译告警消除
Merge pull request !250 from 野生毛霉君/master
2021-08-11 09:23:07 +00:00
openharmony_ci
fa0b8b0dcb !227 feat: 支持native动态加载组件
Merge pull request !227 from Harylee/mem
2021-08-11 03:14:24 +00:00
Haryslee
d75383400e feat: 支持native动态加载组件
1.【需求描述】
动态库开发部分:
gcc的sample code。
提供生成暴露接口生成机制,并允许产品新增需要暴露的接口。
提供可以判断库允许资源大小的能力,并提供相关工具辅助开发者确定开发的库要求的资源是否可以满足。

动态库运行部分:
提供elf load的api,可以加载指定路径下的库,并完成符号重映射等运行准备。
提供elf 暴露符号调用的api,用于调用库的api。
elf加载&链接异常时,有明确错误记录,返回明确错误类型。
提供elf 卸载的api。

2.【方案描述】
(1) 通过灌段的形式记录需要导出符号的地址信息,用于暴露内核对外的接口,在加载链接器中通过查询
对应的符号信息获取符号地址。
(2) 加载链接时,解析共享库并将共享库中可加载段通过文件系统读入内存中,并对共享库中未定义的、
需要重定位的符号进行重定位。需要调用符号时,根据符号名通过哈希表即可查询共享库提供的对应符号
的地址。

BREAKING CHANGE:
新增4个对外接口,声明在los_dynlink.h文件中,分别为:
(1) LOS_DynlinkInit: 动态加载模块初始化。
(2) LOS_SoLoad: 加载指定路径的共享库。
(3) LOS_FindSym: 根据共享库句柄查找指定符号。
(4) LOS_SoUnload: 卸载共享库。

close #I418HJ

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I7669b7ef20096294f9d1094c85ac6602fefad354
2021-08-10 20:26:40 +08:00
openharmony_ci
669f619040 !258 添加MPU功能的开关宏
Merge pull request !258 from JerryH/mpu
2021-08-10 12:01:26 +00:00
JerryH
9709d29b87 fix: 增加MPU功能的开关宏,默认关闭
close #I3WE0S

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: Id193fd555877ac0c6b5b43e5dd5ede32531b86c4
2021-08-10 19:27:14 +08:00
openharmony_ci
11bca47b6e !247 fix: tick 动态化计算优化,减小中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。
Merge pull request !247 from zhushengle/tick_sched
2021-08-10 06:16:34 +00:00
zhushengle
2118c84616 fix: tick 动态化计算优化,减小中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。
方案描述:
    1.周期软件定时器超时添加一个startTime字段,用于记录当前软件定时器的开始计时的时间,
    在定时器响应时,开始时间修改为上一次响应的结束时间(消除了中断执行时间对软件定时器
    的影响)。
    2. 在执行tick中断的过程当中,持有tick动态计算锁,保证在该过程中不会触发tick周期
    的计算,在tick中断结束时统一计算设置。 --- 提升tick中断的执行效率
    3. 在设置tick周期时,减掉tick中断执行的时间,减小周期动态化带来的时间误差
    4.新增LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI配置宏,用于配置tick中断的最小响应精度
Close #I3YGP1

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ia53e4accce497bce870557c2c3387ce51fa3fed3
2021-08-09 21:16:22 +08:00
openharmony_ci
7fe9cc9aa0 !253 fix: L0 net 编译修复
Merge pull request !253 from give-me-five/master
2021-08-09 03:46:44 +00:00
silen
299813cdb4 fix: net compile fix
Change-Id: Ieb264f28e831f867d833a66fa25fec57e740a162
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-09 10:01:23 +08:00
openharmony_ci
870cf67c51 !252 新增OAT配置文件,用作oat扫描
Merge pull request !252 from SimonLi/master
2021-08-05 16:42:50 +00:00
SimonLi
f64457162c chore(oat): 新增OAT配置文件,用作oat扫描
Signed-off-by: SimonLi <likailong@huawei.com>
2021-08-06 00:29:03 +08:00
openharmony_ci
c8064436dd !251 修复licese
Merge pull request !251 from lnlan/fix_stl
2021-08-05 15:16:52 +00:00
lnlan
218d16f85f style:修改 liteos_a unittest 测试文件的 licence 注释
【背景】解除告警
【修改方案】
 格式化修改告警文件的文件头注释格式

re #I44497

Signed-off-by: lanleinan <lanleinan@163.com>
Change-Id: Id2d61deb9d9a14d5e29b915c3a64c75e11e12eda
2021-08-05 14:32:21 +00:00
mucor
8dea15c4fc fix: compile warning fix
close: #I4330B
Signed-off-by: mucor <mucorwang@gmail.com>
2021-08-05 21:02:42 +08:00
openharmony_ci
56dfd80ea5 !242 cmsis添加ThreadFlags接口支持
Merge pull request !242 from 野生毛霉君/master
2021-08-05 12:31:09 +00:00
mucor
cea551e99e feat: add cmsis ThreadFlags support
close: I43AYB

Signed-off-by: mucor <mucorwang@gmail.com>
2021-08-05 17:01:20 +08:00
openharmony_ci
b195b40bf2 !245 解决arm9编译冲突的问题
Merge pull request !245 from JerryH/arm9
2021-08-03 11:57:47 +00:00
openharmony_ci
1a56599021 !244 backatrace代码段判断函数解耦
Merge pull request !244 from JerryH/backtrace-bugfix
2021-08-03 11:37:55 +00:00
JerryH
c1a6245368 fix: 解决arm9编译冲突问题
close #I420PQ

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I788de96b176ae73541f1dc0577262b57179151a7
2021-08-03 10:27:20 +08:00
JerryH
8692ed33a3 fix: backtrace代码段判断函数定义成弱函数,如果有多个代码段,那么可根据实际情况重定义
close #I420SD

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: Id2e89e11df8aeb906cdd36b2c40c51c2e140a569
2021-08-02 15:43:01 +08:00
openharmony_ci
ff7da435cf !243 fix: qemu中,timer模块缺少头文件
Merge pull request !243 from give-me-five/master
2021-08-02 03:43:09 +00:00
silen
12fed74722 fix: timer qemu 头文件缺失
Change-Id: I763ee6f0d013d84f36da9a7cb6d369f3d02e6c45
Signed-off-by: silen <wuyunjie@huawei.com>
2021-08-02 10:37:47 +08:00
openharmony_ci
4fd6a663ac !235 fix: 修复QUEUE_INFO_S中waitReadTask无法保存大于32的任务编号
Merge pull request !235 from kenneth/master
2021-08-02 02:07:12 +00:00
openharmony_ci
23d56f4b2a !241 M核代码告警清零
Merge pull request !241 from wangchen/m_codex
2021-07-31 03:40:50 +00:00
openharmony_ci
8f5cefe41a !225 fix: 在内核初始化前期启动tick timer
Merge pull request !225 from zhushengle/tick
2021-07-31 02:59:35 +00:00
openharmony_ci
1d33f5e4b0 !234 feat: L0 支持Trace
Merge pull request !234 from LiteOS/master
2021-07-31 02:58:59 +00:00
wangchen
cb5f862eaf fix: M核代码告警清零
【背景】定期M核代码告警清零。

【修改方案】
根据工具扫描结果,对代码告警进行更改。

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

re #I4386N
Signed-off-by: wangchen <253227059@qq.com>
2021-07-30 18:34:08 +08:00
openharmony_ci
3027311003 !239 fix: L0 支持smoke测试用例
Merge pull request !239 from zhushengle/smoke_test
2021-07-30 06:06:21 +00:00
openharmony_ci
3b37750f37 !240 Mutex锁释放后,无任务持有的情况下,owner未清空
Merge pull request !240 from zhangfanfan2/master
2021-07-30 03:21:26 +00:00
YOUR_NAME
c136cfdf97 fix: Mutex锁释放后,无任务持有的情况下,owner未清空
close: #I40OC8

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: Ia06c4dc7f6d0a24a9ea05b37599ffac4f359a29f
2021-07-30 09:44:41 +08:00
LiteOS2021
56c93a641b feat: L0 支持Trace
1.【需求描述】
 L0 支持Trace,提供两种工作模式:在线模式、离线缓存模式, 用于按时间线追踪系统事件,如任务切换、中断、ipc等。
2.【方案描述】
 (1).在内核模块预置静态代码桩
  (2).触发桩后,收集系统上下文信息
  (3).离线模式则写入内存,用户可通过dump导出;
  (4).在线模式通过pipeline对接IDE进行可视化解析和展示;

BREAKING CHANGE:
1.新增一系列trace的对外API,位于los_trace.h中.
LOS_TRACE_EASY简易插桩
LOS_TRACE标准插桩
LOS_TraceInit配置Trace缓冲区的地址和大小
LOS_TraceStart开启事件记录
LOS_TraceStop停止事件记录
LOS_TraceRecordDump输出Trace缓冲区数据
LOS_TraceRecordGet获取Trace缓冲区的首地址
LOS_TraceReset清除Trace缓冲区中的事件
LOS_TraceEventMaskSet设置事件掩码,仅记录某些模块的事件
LOS_TraceHwiFilterHookReg注册过滤特定中断号事件的钩子函数

Close #I41Y9Y

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2021-07-30 09:29:37 +08:00
openharmony_ci
285d90979b !238 M33 平台 trust zone 适配修改
Merge pull request !238 from wangchen/tz_fix
2021-07-29 12:40:50 +00:00
zhushengle
3ad5942301 fix: 支持smoke 测试用例
默认只运行smoke测试用例,如需要运行全量测试用例,
请在target_config.h中添加配置项: LOS_KERNEL_TEST_FULL
或在config.json中配置enable_ohos_kernel_liteos_m_test_full
Close #I424RX

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I1f72a7666bf30631090e3e00faf6c432105dec17
2021-07-29 20:31:22 +08:00
openharmony_ci
7bd5a806e9 !232 feat: open shell
Merge pull request !232 from give-me-five/master
2021-07-29 07:06:08 +00:00
silen
911a767992 fix: open shell & fix qemu compile
Change-Id: Ia7488c02db7a41e0f681d008882b7c2721e6b207
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-29 11:19:03 +08:00
wangchen
15a2c17f79 fix: trustzone 中断适配
【背景】当前无法使用 trustzone。

【修改方案】
由于tz需要使用svc中断,因此删除之前使用的HalExcSvcCall的地方,改为HalSVCHandler

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

re #I42TFV
Signed-off-by: wangchen <253227059@qq.com>
2021-07-28 17:40:03 +08:00
kenneth
704cca97b1 fix: 修复QUEUE_INFO_S中waitReadTask无法保存大于32的任务编号
根据任务最大数创建waitReadTask数组来保存任务编号信息

close #I41N78

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-07-28 11:19:39 +08:00
openharmony_ci
6b732ca351 !237 fix: risc-v 锁中断在调度后失效
Merge pull request !237 from zhushengle/risc-v
2021-07-28 02:40:28 +00:00
openharmony_ci
71c76e8b08 !236 补充两个获取最高\最低优先级的接口
Merge pull request !236 from lnlan/add_prio
2021-07-28 02:11:05 +00:00
zhushengle
70f3aa1c11 fix: risc-v 锁中断在调度后失效
risc-v架构中,由于执行完mret指令之后,未将mstatus.mpie位清除,
导致锁中断后调度保存上下文信息后, 恢复上下文时误将中断打开。

Close #I42OLJ
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib97b8bd0fc56bd4b2a7e5c474cb240db4e9c2419
2021-07-28 08:57:45 +08:00
lnlan
c24c38b084 feat(kernel): 补充获取最高、最低优先级接口
【背景】
补充获取最高、最低优先级接口
【修改方案】
pthread补充这两个接口
int sched_get_priority_min(int policy)
int sched_get_priority_max(int policy)
【影响】
对现有的产品编译不会有影响。

re #I42HM7

Signed-off-by: lnlanc <lanleinan@163.com>
Change-Id: Id2ffc07e606ad497e8036f45dab1fa6a5ba981b3
2021-07-27 11:21:05 +00:00
openharmony_ci
403d6dc428 !231 riscv_nuclei 编译失败
Merge pull request !231 from zhushengle/riscv_nuclei
2021-07-21 09:27:34 +00:00
zhushengle
d3fb23cca0 fix: riscv_nuclei 编译失败
riscv_nuclei编译失败原因:
1.采用Makefile编译,未包含power模块
2.安全函数库重复包含,导致链接时报重定义错误

Close #I41PQJ
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Id3d20cdb6050fa01aff432be8a9e21dc3c590e29
2021-07-21 14:56:33 +08:00
zhushengle
b3841ed1dd fix: 在内核初始化前期启动tick timer
解决系统未初始化完成前无timer可用的问题。

Close #I410F0
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I3799b9b0ff03cb1dfe80a97816a484df28ae49fd
2021-07-21 10:02:42 +08:00
openharmony_ci
10f683da91 !230 fix: ping cmd compile fail
Merge pull request !230 from give-me-five/master
2021-07-21 01:39:06 +00:00
silen
ae05de3ffd fix: ping cmd compile fail
Change-Id: I692de82275b8da03ac51b493b2f74148c96574d0
Signed-off-by: silen <wuyunjie@huawei.com>
2021-07-21 08:50:28 +08:00
294 changed files with 12743 additions and 2660 deletions

View File

@@ -29,40 +29,65 @@
import("config.gni")
LITEOS_LOS_CONFIG_H = rebase_path("$LITEOSTOPDIR/kernel/include/los_config.h")
config("los_config") {
cflags = [ "-Werror" ]
asmflags = [
"-DCLZ=CLZ",
"-imacros",
"$LITEOS_LOS_CONFIG_H",
]
include_dirs = [
"//kernel/liteos_m/kernel/include",
"//kernel/liteos_m/kernel/arch/include",
"//kernel/liteos_m/utils",
"//third_party/bounds_checking_function/include",
]
}
group("kernel") {
deps = [
"kernel:kernel",
"utils:utils",
"//third_party/bounds_checking_function:libsec_static",
]
if (enable_ohos_kernel_liteos_m_cppsupport == true) {
if (enable_ohos_kernel_liteos_m_cppsupport) {
deps += [ "components/cppsupport:cppsupport" ]
}
if (enable_ohos_kernel_liteos_m_cpup == true) {
if (enable_ohos_kernel_liteos_m_cpup) {
deps += [ "components/cpup:cpup" ]
}
if (enable_ohos_kernel_liteos_m_exchook == true) {
if (enable_ohos_kernel_liteos_m_exchook) {
deps += [ "components/exchook:exchook" ]
}
if (enable_ohos_kernel_liteos_m_backtrace == true) {
if (enable_ohos_kernel_liteos_m_backtrace) {
deps += [ "components/backtrace:backtrace" ]
}
if (enable_ohos_kernel_liteos_m_fs == true) {
if (enable_ohos_kernel_liteos_m_fs) {
deps += [ "components/fs:fs" ]
}
if (enable_ohos_kernel_liteos_m_pm == true) {
if (enable_ohos_kernel_liteos_m_pm) {
deps += [ "components/power:pm" ]
}
if (enable_ohos_kernel_liteos_m_kal == true) {
if (enable_ohos_kernel_liteos_m_trace) {
deps += [ "components/trace:trace" ]
}
if (enable_ohos_kernel_liteos_m_kal) {
deps += [ "kal:kal" ]
}
if (enable_ohos_kernel_liteos_m_shell== true) {
if (enable_ohos_kernel_liteos_m_shell) {
deps += [ "components/shell:shell" ]
}
if (enable_ohos_kernel_liteos_m_test == true) {
if (enable_ohos_kernel_liteos_m_test) {
deps += [ "testsuits:test" ]
}
if (enable_ohos_kernel_liteos_m_lwip == true) {
if (enable_ohos_kernel_liteos_m_lwip) {
deps += [ ohos_kernel_liteos_m_lwip_path ]
}
if (enable_ohos_kernel_liteos_m_dynlink) {
deps += [ "components/dynlink:dynlink" ]
}
}

86
OAT.xml Normal file
View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="copyright" name="Huawei Technologies Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="文件属于FreeBSD仓库软连接本仓库屏蔽告警在FreeBSD仓库进行处理">
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei/gcc/nmsis/Library/.*" desc="文件属于三方芯片的二进制代码,属于社区贡献,不用提供额外的说明"/>
<filteritem type="filepath" name="targets/riscv_nuclei_demo_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码文件头说明跟随liteos_m/LICENSE不用额外说明"/>
<filteritem type="filepath" name="targets/riscv_nuclei_gd32vf103_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码文件头说明跟随liteos_m/LICENSE不用额外说明"/>
<filteritem type="filepath" name="NOTICE" desc="NOTICE文件"/>
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei" desc="该文件的license为apache 2.0符合"/>
</filefilter>
<filefilter name="defaultFilter" desc="Files not to check">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
</filefilterlist>
<licensematcherlist>
<!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
<licensetext name="
uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
<licensetext name="
uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
</licensematcher-->
</licensematcherlist>
</oatconfig>
</configuration>

View File

@@ -23,6 +23,7 @@ The directory structure is listed as below, for the detailed directories, please
│ ├── backtrace # Backtrace support
│ ├── cppsupport # C++ support
│ ├── cpup # CPU possession (CPUP)
│ ├── dynlink # Dynamic loader & linker
│ ├── exchook # Exception hook
│ ├── fs # File system
│ └── net # Network support
@@ -70,7 +71,7 @@ After the compilation is successful, the executable file **NUCLEO-F767.hex** i
## Repositories Involved<a name="section1371113476307"></a>
[Kernel subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/kernel.md)
[Kernel subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel.md)
**kernel\_liteos\_m**

View File

@@ -23,6 +23,7 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
│ ├── backtrace # 回溯栈支持
│ ├── cppsupport # C++支持
│ ├── cpup # CPUP功能
│ ├── dynlink # 动态加载与链接
│ ├── exchook # 异常钩子
│ ├── fs # 文件系统
│ └── net # Network功能
@@ -47,15 +48,15 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
## 使用说明<a name="section3732185231214"></a>
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统支持按组件配置、裁剪和拼装按需构建出定制化的产品。编译构建系统的详细信息可以参考[轻量和小型系统编译构建指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/%E8%BD%BB%E9%87%8F%E5%92%8C%E5%B0%8F%E5%9E%8B%E7%B3%BB%E7%BB%9F%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA%E6%8C%87%E5%AF%BC.md)。本文主要介绍如何基于gn和ninja编译LiteOS-M工程GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统支持按组件配置、裁剪和拼装按需构建出定制化的产品。本文主要介绍如何基于gn和ninja编译LiteOS-M工程GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
### 搭建系统基础环境
在搭建各个开发板环境前需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Ubuntu%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87.md)。开发者需要根据环境搭建文档完成下述软件的安装Python3.7+、gn、ninja、hb。对于LiteOS-M内核还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
在搭建各个开发板环境前需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/quick-start/quickstart-lite-env-setup-linux.md)。开发者需要根据环境搭建文档完成下述软件的安装Python3.7+、gn、ninja、hb。对于LiteOS-M内核还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
### 获取OpenHarmony源码
开发者需要在Linux服务器上通过Git克隆获取OpenHarmony最新源码详细的源码获取方式请见[源码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md)。获取OpenHarmony完整仓代码后假设克隆目录为`~/openHarmony`
开发者需要在Linux服务器上通过Git克隆获取OpenHarmony最新源码详细的源码获取方式请见[源码获取](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md)。获取OpenHarmony完整仓代码后假设克隆目录为`~/openHarmony`
### 获取示例工程源码
@@ -77,7 +78,7 @@ chmod +x ~/openHarmony/device/st/nucleo_f767zi/build.sh
cp -r ~/nucleo_f767zi/vendor/st ~/openHarmony/vendor/st
```
关于示例代码目录的说明,可以参考资料站点[板级目录规范](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/%E7%A7%BB%E6%A4%8D%E6%A6%82%E8%BF%B0-0.md#section6204129143013)。如果需要自行移植开发板,请参考[板级系统移植](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/%E6%9D%BF%E7%BA%A7%E7%B3%BB%E7%BB%9F%E7%A7%BB%E6%A4%8D.md)。
关于示例代码目录的说明,可以参考资料站点[板级目录规范](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/transplant-chip-board-overview.md)。如果需要自行移植开发板,请参考[板级系统移植](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/transplant-chip-board.md)。
### 编译运行
@@ -120,7 +121,7 @@ LiteOS-M内核移植的具体开发板的工程由社区开发者提供可以
## 相关仓<a name="section1371113476307"></a>
[内核子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[内核子系统](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
**kernel\_liteos\_m**

View File

@@ -4,6 +4,7 @@
│   ├── backtrace --- Backtrace
│   ├── cppsupport --- C++
│   ├── cpup --- CPUP
│   ├── dynlink --- Dynamic loader & linker
│   ├── exchook --- Exception hook
│   ├── fs --- File System
│   └── net --- Network

View File

@@ -4,6 +4,7 @@
│   ├── backtrace --- 回溯栈支持
│   ├── cppsupport --- C++支持
│   ├── cpup --- CPUP功能
│   ├── dynlink --- 动态加载与链接
│   ├── exchook --- 异常钩子
│   ├── fs --- 文件系统
│   └── net --- 网络功能

59
bundle.json Normal file
View File

@@ -0,0 +1,59 @@
{
"name": "@ohos/kernel_liteos_m",
"version": "",
"description": "liteos-m内核",
"homePage": "https://gitee.com/openharmony",
"license": "BSD 3-clause",
"repository": "https://gitee.com/openharmony/kernel_liteos_m",
"domain": "os",
"language": "",
"publishAs": "code-segment",
"private": false,
"scripts": {},
"tags": [
"kernel"
],
"keywords": [
"kernel",
"liteos-m"
],
"envs": [],
"dirs": [],
"author": {
"name": "",
"email": "",
"url": ""
},
"contributors": [
{
"name": "",
"email": "",
"url": ""
}
],
"segment": {
"destPath": "kernel/liteos_m"
},
"component": {
"name": "liteos-m",
"subsystem": "liteos_m",
"syscap": [
"SystemCapability.Kernel.liteos-m"
],
"features": [],
"adapted_system_type": [
"mini"
],
"rom": "",
"ram": "",
"deps": {
"components": [],
"third_party": []
},
"build": {
"sub_component": [],
"inner_kits": [],
"test": []
}
}
}

View File

@@ -27,13 +27,10 @@
# 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/config.gni")
static_library("backtrace") {
sources = [ "los_backtrace.c" ]
include_dirs = [
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -33,8 +33,19 @@
#include "los_task.h"
#include "los_debug.h"
#if (LOSCFG_BACKTRACE_TYPE != 0)
/* This function is used to judge whether the data in the stack is a code section address.
The default code section is only one, but there may be more than one. Modify the
judgment condition to support multiple code sections. */
WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
{
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
return TRUE;
}
return FALSE;
}
#if (LOSCFG_BACKTRACE_TYPE == 1)
#define OS_BACKTRACE_START 2
/* Thumb instruction, so the pc must be an odd number */

View File

@@ -56,7 +56,7 @@ extern "C" {
#pragma section=CSTACK_SECTION_NAME
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)__section_begin(CODE_SECTION_NAME))
#define CODE_END_ADDR ((UINTPTR)__section_end(CODE_SECTION_NAME))
@@ -84,7 +84,7 @@ extern CHAR *CODE_SECTION_START(CODE_SECTION_NAME);
extern CHAR *CODE_SECTION_END(CODE_SECTION_NAME);
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START(CODE_SECTION_NAME))
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END(CODE_SECTION_NAME))
@@ -106,7 +106,7 @@ extern CHAR *CSTACK_SECTION_START;
extern CHAR *CSTACK_SECTION_END;
/* Default only one code section. In fact, there may be more than one.
You can define more than one and modify the OsStackDataIsCodeAddr function
You can define more than one and redefine the OsStackDataIsCodeAddr function
to support searching in multiple code sections */
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
@@ -140,17 +140,6 @@ extern CHAR *CSTACK_SECTION_END;
#endif
#endif
/* This function is used to judge whether the data in the stack is a code section address.
The default code section is only one, but there may be more than one. Modify the
judgment condition to support multiple code sections. */
STATIC INLINE BOOL OsStackDataIsCodeAddr(UINTPTR value)
{
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
return TRUE;
}
return FALSE;
}
/* This function is currently used to register the memory leak check hook,
other uses do not need to be called temporarily. */
VOID OSBackTraceInit(VOID);

View File

@@ -27,8 +27,10 @@
# 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/config.gni")
static_library("cppsupport") {
sources = [ "los_cppsupport.c" ]
include_dirs = [ "../../utils" ]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -31,7 +31,6 @@
#include "los_cppsupport.h"
typedef VOID (*InitFunc)(VOID);
INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
@@ -39,12 +38,10 @@ INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
UINTPTR *start;
InitFunc initFunc = NULL;
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++){
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++) {
initFunc = (InitFunc)(*start);
initFunc();
}
return 0;
}

View File

@@ -27,13 +27,10 @@
# 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/config.gni")
static_library("cpup") {
sources = [ "los_cpup.c" ]
include_dirs = [
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -0,0 +1,48 @@
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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/config.gni")
config("dynlink_config") {
include_dirs = [ "./" ]
if (arch == "arm") {
include_dirs += [ "../../kernel/arch/arm/include" ]
} else {
assert(false,
"Dynlink module does not support for other archs except for arm!")
}
}
static_library("dynlink") {
sources = [ "los_dynlink.c" ]
public_configs = [ ":dynlink_config" ]
configs += [ "$LITEOSTOPDIR:los_config" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

935
components/dynlink/los_dynlink.c Executable file
View File

@@ -0,0 +1,935 @@
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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_dynlink.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include "fcntl.h"
#include "errno.h"
#include "limits.h"
#include "sys/stat.h"
#include "securec.h"
#include "arch_elf.h"
#include "los_task.h"
#include "los_debug.h"
#include "los_mux.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_DYNLINK == 1)
#if defined(__ICCARM__) || defined(__CC_ARM)
/**
* Place instructions below in .icf linker file:
*
* keep {section .TABLE.START};
* keep {section .sym.*};
* keep {section .table.end};
* define block SYMBOL_TABLE with fixed order
* {
* section .TABLE.START,
* section .sym.*,
* section .table.end
* };
* place in ROM_region {readonly, block SYMBOL_TABLE};
*/
const SymInfo symTableStart __attribute__((section(".TABLE.START"))) = {
.name = "start",
.addr = 0
};
const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
.name = "end",
.addr = 0
};
#pragma section=".TABLE.START"
#pragma section=".table.end"
#elif defined(__CLANG_ARM) || defined(__GNUC__)
/**
* Place instructions below in rodata segment of .ld linker file:
*
* __sym_table_start = .;
* KEEP(*( SORT (.sym.*)));
* __sym_table_end = .;
*/
extern char __sym_table_start[];
extern char __sym_table_end[];
#else
#error Unknown compiler.
#endif
STATIC LOS_DL_LIST g_dynSharedObjLink;
STATIC UINT32 g_dynlinkMux;
STATIC DynSharedObj *OsIsPreLoaded(const CHAR *fileName)
{
DynSharedObj *dso = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
if (!strcmp(fileName, dso->fileName)) {
++dso->ref;
return dso;
}
}
return NULL;
}
STATIC INT32 OsVerifyEhdr(const LD_ELF_EHDR *ehdr, UINT32 fileLen)
{
if (memcmp(ehdr->e_ident, LD_ELFMAG, LD_SELFMAG) != LOS_OK) {
PRINT_ERR("The file is not elf format\n");
return LOS_NOK;
}
if (ehdr->e_type != ET_DYN) {
PRINT_ERR("The file is not shared library\n");
return LOS_NOK;
}
if (!check_arch(ehdr)) {
PRINT_ERR("The file can not load in current platform\n");
return LOS_NOK;
}
if (ehdr->e_phnum > PHDR_NUM_MAX) {
PRINT_ERR("The num of program header is out of limit\n");
return LOS_NOK;
}
if (ehdr->e_phoff > fileLen) {
PRINT_ERR("The offset of program header is invalid, elf file is bad\n");
return LOS_NOK;
}
return LOS_OK;
}
STATIC INT32 OsReadELFInfo(INT32 fd, UINT8 *buffer, size_t readSize, off_t offset)
{
ssize_t byteNum;
off_t returnPos;
if (readSize > 0) {
returnPos = lseek(fd, offset, SEEK_SET);
if (returnPos != offset) {
PRINT_ERR("Failed to seek the position!, offset: %#x\n", offset);
return LOS_NOK;
}
byteNum = read(fd, buffer, readSize);
if (byteNum <= 0) {
PRINT_ERR("Failed to read from offset: %#x!\n", offset);
return LOS_NOK;
}
}
return LOS_OK;
}
STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
{
struct stat buf;
INT32 ret;
ret = stat(fileName, &buf);
if (ret < 0) {
PRINT_ERR("Failed to stat file: %s, errno: %d\n", fileName, errno);
return LOS_NOK;
}
if (buf.st_size > FILE_LENGTH_MAX) {
PRINT_ERR("The file: %s length is out of limit!\n", fileName);
return LOS_NOK;
}
*fileLen = (UINT32)buf.st_size;
return LOS_OK;
}
STATIC INT32 OsReadEhdr(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
{
INT32 ret;
ret = OsReadELFInfo(fd, (UINT8 *)&dlInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
if (ret != LOS_OK) {
return -EIO;
}
ret = OsVerifyEhdr(&dlInfo->elfEhdr, fileLen);
if (ret != LOS_OK) {
return -ELIBBAD;
}
return LOS_OK;
}
STATIC INT32 OsReadPhdrs(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
{
INT32 ret;
UINT32 size;
LD_ELF_EHDR *ehdr = &dlInfo->elfEhdr;
if ((ehdr->e_phnum == 0) || (ehdr->e_phentsize != sizeof(LD_ELF_PHDR))) {
goto ERR;
}
size = sizeof(LD_ELF_PHDR) * ehdr->e_phnum;
if ((ehdr->e_phoff + size) > fileLen) {
goto ERR;
}
dlInfo->elfPhdr = (LD_ELF_PHDR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
if (dlInfo->elfPhdr == NULL) {
return -ENOMEM;
}
ret = OsReadELFInfo(fd, (UINT8 *)dlInfo->elfPhdr, size, ehdr->e_phoff);
if (ret != LOS_OK) {
LOS_MemFree(OS_SYS_MEM_ADDR, dlInfo->elfPhdr);
return -EIO;
}
return LOS_OK;
ERR:
PRINT_ERR("the file is bad\n");
return -ELIBBAD;
}
STATIC DynSharedObj *OsLoadInit(const CHAR *fileName, VOID *pool)
{
DynSharedObj *dso = NULL;
UINT32 allocSize, nameLen;
UINT32 fileLen = 0;
INT32 ret;
nameLen = strlen(fileName);
if (nameLen > PATH_MAX) {
PRINT_ERR("file name length is too long\n");
errno = ENAMETOOLONG;
return NULL;
}
allocSize = sizeof(DynSharedObj) + nameLen + 1;
dso = (DynSharedObj *)LOS_MemAlloc(OS_SYS_MEM_ADDR, allocSize);
if (dso == NULL) {
PRINT_ERR("failed to alloc for dso\n");
errno = ENOMEM;
return NULL;
}
(VOID)memset_s(dso, allocSize, 0, allocSize);
dso->dlInfo = (DynLinkInfo *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(DynLinkInfo));
if (dso->dlInfo == NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
PRINT_ERR("failed to alloc for loadInfo\n");
errno = ENOMEM;
return NULL;
}
(VOID)memset_s(dso->dlInfo, sizeof(DynLinkInfo), 0, sizeof(DynLinkInfo));
ret = OsGetFileLength(&fileLen, fileName);
if (ret != LOS_OK) {
errno = ENOENT;
goto ERR1;
}
dso->fd = open(fileName, O_RDONLY);
if (dso->fd < 0) {
PRINT_ERR("Failed to open ELF file: %s!\n", fileName);
goto ERR1;
}
ret = OsReadEhdr(dso->fd, fileLen, dso->dlInfo);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
ret = OsReadPhdrs(dso->fd, fileLen, dso->dlInfo);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
strcpy(dso->buf, fileName);
dso->fileName = dso->buf;
dso->ref = 1;
dso->pool = (pool ? pool : OS_SYS_MEM_ADDR);
LOS_ListInit(&dso->dsoNode);
return dso;
ERR2:
close(dso->fd);
ERR1:
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return NULL;
}
STATIC INT32 OsReserveSpace(const DynLinkInfo *dlInfo, UINT32 *boundary)
{
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
UINTPTR addrMin = SIZE_MAX;
UINTPTR addrMax = 0;
UINT32 offStart = 0;
UINT64 size;
INT32 i;
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type == PT_TLS) {
PRINT_ERR("unsupport tls\n");
return 0;
}
if (elfPhdrTemp->p_type != PT_LOAD) {
continue;
}
if (*boundary == 0) {
*boundary = elfPhdrTemp->p_align;
}
if (elfPhdrTemp->p_vaddr < addrMin) {
addrMin = elfPhdrTemp->p_vaddr;
offStart = elfPhdrTemp->p_offset;
}
if ((elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz) > addrMax) {
addrMax = elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz;
}
}
if ((addrMin == addrMax) || (addrMax < addrMin)) {
return 0;
}
size = ELF_ALIGN_UP(addrMax, *boundary) - ELF_ALIGN_DOWN(addrMin, *boundary) + ELF_ALIGN_DOWN(offStart, *boundary);
return (size > UINT_MAX) ? 0 : (UINT32)size;
}
STATIC UINTPTR OsDoLoadFile(INT32 fd, UINTPTR addr, const LD_ELF_PHDR *elfPhdr, UINT32 boundary)
{
INT32 ret;
UINT32 offset = elfPhdr->p_offset - ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
UINT32 size = elfPhdr->p_filesz + ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
if (size == 0) {
return 0;
}
addr = ELF_ALIGN_DOWN(addr, boundary);
ret = OsReadELFInfo(fd, (UINT8 *)addr, size, offset);
if (ret != LOS_OK) {
return 0;
}
return addr;
}
STATIC INT32 OsLoadELFFile(DynSharedObj *dso, UINT32 boundary)
{
DynLinkInfo *dlInfo = dso->dlInfo;
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
const LD_ELF_EHDR *elfEhdr = &dlInfo->elfEhdr;
UINTPTR loadBase = dso->loadBase;
UINTPTR vAddr, loadAddr, bssStart, bssEnd;
INT32 i;
for (i = 0; i < elfEhdr->e_phnum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type != PT_LOAD) {
continue;
}
if ((elfPhdrTemp->p_flags & PF_R) == 0) {
return -ENOEXEC;
}
vAddr = elfPhdrTemp->p_vaddr;
loadAddr = OsDoLoadFile(dso->fd, (vAddr + loadBase), elfPhdrTemp, boundary);
if (loadAddr == 0) {
return -EFAULT;
}
if ((elfPhdrTemp->p_memsz > elfPhdrTemp->p_filesz) && (elfPhdrTemp->p_flags & PF_W)) {
bssStart = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_filesz;
bssEnd = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_memsz;
(VOID)memset_s((VOID *)bssStart, bssEnd - bssStart, 0, bssEnd - bssStart);
}
}
return LOS_OK;
}
STATIC INT32 OsLoadLibrary(DynSharedObj *dso)
{
UINT32 loadSize;
UINT32 boundary = 0;
INT32 ret;
loadSize = OsReserveSpace(dso->dlInfo, &boundary);
if (loadSize == 0) {
PRINT_ERR("failed to reserve space!\n");
return -EINVAL;
}
dso->loadBase = (UINTPTR)LOS_MemAllocAlign(dso->pool, loadSize, boundary);
if (dso->loadBase == 0) {
PRINT_ERR("failed to alloc memory for loading shared library\n");
return -ENOMEM;
}
ret = OsLoadELFFile(dso, boundary);
if (ret != LOS_OK) {
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
PRINT_ERR("failed to load shared library\n");
return ret;
}
return LOS_OK;
}
STATIC INT32 OsGetDynBase(DynSharedObj *dso)
{
DynLinkInfo *dlInfo = dso->dlInfo;
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
INT32 i;
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
if (elfPhdrTemp->p_type != PT_DYNAMIC) {
continue;
}
dlInfo->dynBase = dso->loadBase + elfPhdrTemp->p_vaddr;
return LOS_OK;
}
return LOS_NOK;
}
STATIC INT32 OsParseDynamic(DynSharedObj *dso)
{
LD_ELF_DYN *dyn = NULL;
DynLinkInfo *dlInfo = dso->dlInfo;
RelocInfoTab *relInfoTab = &dlInfo->relInfoTab;
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
switch (dyn->d_tag) {
case DT_NEEDED:
PRINT_ERR("shared library should not depend on others\n");
return -ENOTSUP;
case DT_TEXTREL:
PRINT_ERR("you should recompile shared library with -fPIC\n");
return -EFAULT;
case DT_HASH:
dlInfo->hashTab = (UINT32 *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_SYMTAB:
dlInfo->symTab = (LD_ELF_SYM *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_STRTAB:
dlInfo->symStrings = (CHAR *)(dso->loadBase + dyn->d_un.d_ptr);
break;
case DT_REL:
relInfoTab->rel.relTab = dso->loadBase + dyn->d_un.d_ptr;
relInfoTab->rel.relEntSize = sizeof(LD_ELF_REL);
break;
case DT_RELSZ:
relInfoTab->rel.relTabSize = dyn->d_un.d_val;
break;
case DT_RELA:
relInfoTab->rela.relTab = dso->loadBase + dyn->d_un.d_ptr;
relInfoTab->rela.relEntSize = sizeof(LD_ELF_RELA);
break;
case DT_RELASZ:
relInfoTab->rela.relTabSize = dyn->d_un.d_val;
break;
case DT_JMPREL:
relInfoTab->jmpRel.relTab = dso->loadBase + dyn->d_un.d_ptr;
break;
case DT_PLTRELSZ:
relInfoTab->jmpRel.relTabSize = dyn->d_un.d_val;
break;
case DT_PLTREL:
relInfoTab->jmpRel.relEntSize = (dyn->d_un.d_val == DT_REL) ? sizeof(LD_ELF_REL) : sizeof(LD_ELF_RELA);
default:
break;
}
}
return LOS_OK;
}
STATIC UINT32 OsGetHashVal(const CHAR *name)
{
UINT32 hashVal = 0;
UINT32 tmp;
const UINT8 *str = (const UINT8 *)name;
while (*str) {
hashVal = (*str) + (hashVal << WORD_SHIFT);
tmp = hashVal & HASH_MASK;
if (tmp != 0) {
hashVal ^= tmp >> HASH_SHIFT;
}
hashVal &= ~tmp;
++str;
}
return hashVal;
}
STATIC LD_ELF_SYM *OsFindSymInDso(const DynLinkInfo *dlInfo, const CHAR *name)
{
LD_ELF_SYM *symTab = dlInfo->symTab;
LD_ELF_SYM *sym = NULL;
CHAR *symStr = dlInfo->symStrings;
UINT32 *hashTab = dlInfo->hashTab;
UINT32 bucketNum = hashTab[0];
UINT32 *bucket = &hashTab[BUCKET_IDX];
UINT32 *chain = &bucket[bucketNum];
UINT32 hashVal = OsGetHashVal(name);
UINT32 symIdx;
for (symIdx = bucket[hashVal % bucketNum]; symIdx; symIdx = chain[symIdx]) {
if (strcmp(name, symStr + symTab[symIdx].st_name) != 0) {
continue;
}
sym = symTab + symIdx;
if ((sym->st_value == 0) || (sym->st_shndx == 0)) {
return NULL;
}
return symTab + symIdx;
}
return NULL;
}
STATIC SymInfo *OsFindSymInTable(const CHAR *name)
{
#if defined(__ICCARM__) || defined(__CC_ARM)
SymInfo *symTab = (SymInfo *)__section_end(".TABLE.START");
UINT32 symTableSize = ((UINTPTR)__section_begin(".table.end") -
(UINTPTR)__section_end(".TABLE.START")) / sizeof(SymInfo);
#elif defined(__CLANG_ARM) || defined(__GNUC__)
SymInfo *symTab = (SymInfo *)__sym_table_start;
UINT32 symTableSize = (__sym_table_end - __sym_table_start) / sizeof(SymInfo);
#endif
INT32 startIdx = 0;
INT32 endIdx = symTableSize - 1;
INT32 ret, midIdx;
while (startIdx <= endIdx) {
midIdx = startIdx + ((UINT32)(endIdx - startIdx) >> 1);
ret = strcmp(symTab[midIdx].name, name);
if (ret > 0) {
endIdx = midIdx - 1;
} else if (ret < 0) {
startIdx = midIdx + 1;
} else {
return symTab + midIdx;
}
}
return NULL;
}
STATIC UINTPTR OsFindSym(const DynSharedObj *dso, INT32 symIdx)
{
DynLinkInfo *dlInfo = dso->dlInfo;
CHAR *symStrings = dlInfo->symStrings;
CHAR *symStr = NULL;
LD_ELF_SYM *symTab = dlInfo->symTab;
LD_ELF_SYM *sym = NULL;
LD_ELF_SYM *symInDso = NULL;
SymInfo *symInTab = NULL;
sym = symTab + symIdx;
symStr = symStrings + sym->st_name;
if ((symInDso = OsFindSymInDso(dlInfo, symStr)) != NULL) {
return dso->loadBase + symInDso->st_value;
} else if ((symInTab = OsFindSymInTable(symStr)) != NULL) {
return symInTab->addr;
} else {
PRINT_ERR("failed to relocate %s, symbol: %s not found\n", dso->fileName, symStr);
return 0;
}
}
STATIC INT32 OsDoReloc(const DynSharedObj *dso, INT32 type, UINTPTR relocAddr, UINT32 addend, UINTPTR symAddr)
{
switch (type) {
case R_ARCH_NONE:
break;
case R_ARCH_GLOB_DAT:
case R_ARCH_JUMP_SLOT:
*(UINTPTR *)relocAddr = symAddr + addend;
break;
case R_ARCH_ABS32:
*(UINTPTR *)relocAddr = symAddr + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
break;
case R_ARCH_RELATIVE:
*(UINTPTR *)relocAddr = dso->loadBase + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
break;
default:
PRINT_ERR("failed to relocate %s, unsupported reloc type: %d\n", dso->fileName, type);
return -ENOTSUP;
}
return LOS_OK;
}
STATIC INT32 OsDoRelocSyms(DynSharedObj *dso, RelocInfo *relInfo)
{
UINT32 relStride = relInfo->relEntSize / sizeof(UINT32);
UINT32 *relTab = (UINT32 *)relInfo->relTab;
UINT32 addend;
UINTPTR relocAddr, symAddr;
INT32 i, symIdx, ret, type;
for (i = 0; i < relInfo->relTabSize; i += relInfo->relEntSize, relTab += relStride) {
type = REL_TYPE(relTab[1]);
if (type == R_ARCH_NONE) {
continue;
}
symIdx = REL_SYM(relTab[1]);
if (symIdx == 0) {
symAddr = 0;
} else {
symAddr = OsFindSym(dso, symIdx);
if (symAddr == 0) {
return -EFAULT;
}
}
relocAddr = dso->loadBase + relTab[0];
addend = (relInfo->relEntSize == sizeof(LD_ELF_REL)) ? 0 : relTab[relStride - 1];
ret = OsDoReloc(dso, type, relocAddr, addend, symAddr);
if (ret != LOS_OK) {
return ret;
}
}
return LOS_OK;
}
STATIC INT32 OsRelocSyms(DynSharedObj *dso)
{
DynLinkInfo *dlInfo = dso->dlInfo;
RelocInfo *relInfo = (RelocInfo *)&dlInfo->relInfoTab;
INT32 relTypes = sizeof(RelocInfoTab) / sizeof(RelocInfo);
INT32 i, ret;
for (i = 0; i < relTypes; ++i, ++relInfo) {
if (relInfo->relTab == 0) {
continue;
}
ret = OsDoRelocSyms(dso, relInfo);
if (ret != LOS_OK) {
return ret;
}
}
return LOS_OK;
}
STATIC INT32 OsDoDynLink(DynSharedObj *dso)
{
INT32 ret;
ret = OsGetDynBase(dso);
if (ret != LOS_OK) {
PRINT_ERR("there are no dynamic segments in elf file\n");
return -ELIBBAD;
}
ret = OsParseDynamic(dso);
if (ret != LOS_OK) {
return ret;
}
ret = OsRelocSyms(dso);
if (ret != LOS_OK) {
return ret;
}
return LOS_OK;
}
STATIC VOID OsDeLoadInit(DynSharedObj *dso)
{
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
dso->dlInfo->elfPhdr = NULL;
close(dso->fd);
}
STATIC VOID OsGetInitFini(DynSharedObj *dso)
{
LD_ELF_DYN *dyn = NULL;
DynLinkInfo *dlInfo = dso->dlInfo;
InitFiniTab *initFiniTab = &dso->initFiniTab;
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
switch (dyn->d_tag) {
case DT_INIT:
initFiniTab->init.func = dyn->d_un.d_ptr;
break;
case DT_INIT_ARRAY:
initFiniTab->init.array = dyn->d_un.d_ptr;
break;
case DT_INIT_ARRAYSZ:
initFiniTab->init.arraySz = dyn->d_un.d_val;
break;
case DT_FINI:
initFiniTab->fini.func = dyn->d_un.d_ptr;
break;
case DT_FINI_ARRAY:
initFiniTab->fini.array = dyn->d_un.d_ptr;
break;
case DT_FINI_ARRAYSZ:
initFiniTab->fini.arraySz = dyn->d_un.d_val;
break;
default:
break;
}
}
}
STATIC VOID OsDoInit(DynSharedObj *dso)
{
InitFiniTab *initFiniTab = &dso->initFiniTab;
INIT_FINI_FUNC initFunc = NULL;
UINTPTR *func = NULL;
UINT32 funcNum;
OsGetInitFini(dso);
if (initFiniTab->init.func != 0) {
initFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->init.func);
initFunc();
}
if (initFiniTab->init.array == 0) {
return;
}
funcNum = initFiniTab->init.arraySz / sizeof(UINTPTR);
func = (UINTPTR *)(dso->loadBase + initFiniTab->init.array);
while (funcNum--) {
initFunc = (INIT_FINI_FUNC)(*func);
initFunc();
++func;
}
}
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
{
INT32 ret;
DynSharedObj *dso = NULL;
if (fileName == NULL) {
PRINT_ERR("invalid file name\n");
errno = EINVAL;
return NULL;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsIsPreLoaded(fileName);
if (dso != NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
return dso;
}
dso = OsLoadInit(fileName, pool);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
return NULL;
}
ret = OsLoadLibrary(dso);
if (ret != LOS_OK) {
errno = -ret;
goto ERR1;
}
ret = OsDoDynLink(dso);
if (ret != LOS_OK) {
errno = -ret;
goto ERR2;
}
OsDoInit(dso);
LOS_ListAdd(&g_dynSharedObjLink, &dso->dsoNode);
(VOID)LOS_MuxPost(g_dynlinkMux);
OsDeLoadInit(dso);
return dso;
ERR2:
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
ERR1:
close(dso->fd);
(VOID)LOS_MuxPost(g_dynlinkMux);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return NULL;
}
STATIC DynSharedObj *OsCheckHandle(VOID *handle)
{
DynSharedObj *dso = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
if (handle == dso) {
return dso;
}
}
return NULL;
}
VOID *LOS_FindSym(VOID *handle, const CHAR *name)
{
LD_ELF_SYM *sym = NULL;
DynSharedObj *dso = NULL;
VOID *symAddr = NULL;
if ((handle == NULL) || (name == NULL)) {
goto ERR;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsCheckHandle(handle);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
goto ERR;
}
sym = OsFindSymInDso(dso->dlInfo, name);
if (sym == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
PRINT_ERR("failed to find symbol: %s\n", name);
errno = EFAULT;
return NULL;
}
symAddr = (VOID *)(dso->loadBase + sym->st_value);
(VOID)LOS_MuxPost(g_dynlinkMux);
return symAddr;
ERR:
PRINT_ERR("invalid input param\n");
errno = EINVAL;
return NULL;
}
STATIC VOID OsDoFini(DynSharedObj *dso)
{
InitFiniTab *initFiniTab = &dso->initFiniTab;
INIT_FINI_FUNC finiFunc = NULL;
UINTPTR *func = NULL;
UINT32 funcNum;
if (initFiniTab->fini.array != 0) {
funcNum = initFiniTab->fini.arraySz / sizeof(UINTPTR);
func = (UINTPTR *)(dso->loadBase + initFiniTab->fini.array) + funcNum;
while (funcNum--) {
--func;
finiFunc = (INIT_FINI_FUNC)(*func);
finiFunc();
}
}
if (initFiniTab->fini.func != 0) {
finiFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->fini.func);
finiFunc();
}
}
INT32 LOS_SoUnload(VOID *handle)
{
DynSharedObj *dso = NULL;
if (handle == NULL) {
goto ERR;
}
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
dso = OsCheckHandle(handle);
if (dso == NULL) {
(VOID)LOS_MuxPost(g_dynlinkMux);
goto ERR;
}
if (dso->ref > 1) {
--dso->ref;
(VOID)LOS_MuxPost(g_dynlinkMux);
return LOS_OK;
}
OsDoFini(dso);
LOS_ListDelete(&dso->dsoNode);
(VOID)LOS_MuxPost(g_dynlinkMux);
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
return LOS_OK;
ERR:
PRINT_ERR("invalid handle\n");
errno = EINVAL;
return LOS_NOK;
}
INT32 LOS_DynlinkInit(VOID)
{
UINT32 ret;
LOS_ListInit(&g_dynSharedObjLink);
ret = LOS_MuxCreate(&g_dynlinkMux);
if (ret != LOS_OK) {
return LOS_NOK;
}
return LOS_OK;
}
#endif /* LOSCFG_DYNLINK */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

201
components/dynlink/los_dynlink.h Executable file
View File

@@ -0,0 +1,201 @@
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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_DYNLINK_H
#define _LOS_DYNLINK_H
#include "elf.h"
#include "los_compiler.h"
#include "los_list.h"
#include "los_memory.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_AARCH64
typedef Elf64_Ehdr LD_ELF_EHDR;
typedef Elf64_Phdr LD_ELF_PHDR;
typedef Elf64_Sym LD_ELF_SYM;
typedef Elf64_Dyn LD_ELF_DYN;
typedef Elf64_Rel LD_ELF_REL;
typedef Elf64_Rela LD_ELF_RELA;
#define REL_TYPE(x) ELF64_R_TYPE(x)
#define REL_SYM(x) ELF64_R_SYM(x)
#define REL_INFO ELF64_R_INFO
#else
typedef Elf32_Ehdr LD_ELF_EHDR;
typedef Elf32_Phdr LD_ELF_PHDR;
typedef Elf32_Sym LD_ELF_SYM;
typedef Elf32_Dyn LD_ELF_DYN;
typedef Elf32_Rel LD_ELF_REL;
typedef Elf32_Rela LD_ELF_RELA;
#define REL_TYPE(x) ELF32_R_TYPE(x)
#define REL_SYM(x) ELF32_R_SYM(x)
#define REL_INFO ELF32_R_INFO
#endif
#define LD_ELFMAG "\177ELF"
#define LD_SELFMAG 4
#define PHDR_NUM_MAX 128
#define DYNAMIC_CNT 32
#define HASH_MASK 0xf0000000
#define WORD_SHIFT 4
#define HASH_SHIFT 24
#define BUCKET_IDX 2
#define ELF_ALIGN_UP(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
#define ELF_ALIGN_DOWN(a, b) ((a) & ~((b) - 1))
#define ELF_ALIGN_OFFSET(a, b) ((a) & ((b) - 1))
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#ifndef FILE_LENGTH_MAX
#define FILE_LENGTH_MAX 0x40000
#endif
typedef VOID (*INIT_FINI_FUNC)(VOID);
typedef struct {
UINTPTR relTab;
UINT32 relTabSize;
UINT32 relEntSize;
} RelocInfo;
typedef struct {
RelocInfo rel;
RelocInfo rela;
RelocInfo jmpRel;
} RelocInfoTab;
typedef struct {
UINTPTR func;
UINTPTR array;
UINT32 arraySz;
} InitFiniInfo;
typedef struct {
InitFiniInfo init;
InitFiniInfo fini;
} InitFiniTab;
typedef struct {
LD_ELF_EHDR elfEhdr;
LD_ELF_PHDR *elfPhdr;
UINTPTR dynBase;
UINT32 *hashTab;
LD_ELF_SYM *symTab;
CHAR *symStrings;
RelocInfoTab relInfoTab;
} DynLinkInfo;
typedef struct {
CHAR *fileName;
INT32 fd;
DynLinkInfo *dlInfo;
UINTPTR loadBase;
InitFiniTab initFiniTab;
LOS_DL_LIST dsoNode;
UINT32 ref;
VOID *pool;
CHAR buf[];
} DynSharedObj;
typedef struct {
CHAR *name;
UINTPTR addr;
} SymInfo;
#define SYM_EXPORT(func) \
const SymInfo sym_##func __attribute__((section(".sym."#func))) = { \
.name = #func, \
.addr = (UINTPTR)func \
};
/*
* @brief Load the shared library file named by the NULL-terminated string filename and
* return a valid handle for the loaded library.
*
* @param fileName The name pointer of shared library.
* @param pool The heap for shared library to load. If the parameter, pool, is NULL, then
* the dynamic loader & linker module will use the default heap and the pool is not NULL,
* then the shared library will be loaded to the heap by pool.
*
* @note When the heap, pool, is not NULL, you should call LOS_MemInit() to initialize the
* pool before calling LOS_SoLoad(). By the way, the system will comsume a certain amount
* of memory to initialize the pool. LOS_SoLoad must not be called in interrupt callback.
*
* @return Return NULL if error. Return non-NULL if success.
*/
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
/*
* @brief Get the address of symbol named by the parameter, name, from the parameter, handle.
*
* @param handle The handle for the loaded shared library.
* @param name The name of symbol to search.
*
* @note LOS_FindSym must not be called in interrupt callback.
*
* @return Return NULL if error. Return non-NULL if success.
*/
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
/*
* @brief Decrement the reference count on the loaded shared library refered to by handle.
* If the reference count drops to zero, then the library is unloaded.
*
* This function validates that the handle is valid.
*
* @param handle The handle for the loaded shared library by LOS_SoLoad() interface.
*
* @note LOS_SoUnload must not be called in interrupt callback.
*
* @return Return 1 if error. Return 0 if success.
*/
INT32 LOS_SoUnload(VOID *handle);
/*
* @brief Initialization for dynamic loader & linker module.
*
* @param VOID.
*
* @return Return LOS_NOK if error. Return LOS_OK if success.
*/
INT32 LOS_DynlinkInit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_DYNLINK_H */

View File

@@ -0,0 +1,65 @@
#!/bin/bash
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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.
# Description: The script is used to calculate the memory size that the specified shared library
# will occupy when loading to the RAM.
READELF=readelf
RM=rm
SIZE=0x0
SIZE_ALL=0x0
SIZE_MAX=0
TMP_FILE=tmp.txt
if [ $# -lt 1 ]; then
echo "Usage: ./so_parse lib.so"
exit 1
fi
parse_line()
{
MEM_SIZE=$(echo $1 | awk '{print $6}')
echo ${MEM_SIZE}
}
${READELF} -l $1 | while read line; do
HEAD_STRING=$(echo ${line} | awk '{print $1}')
if [[ "${HEAD_STRING}" == *"LOAD"* ]]; then
SIZE=`parse_line "${line}"`
SIZE=`echo ${SIZE}`
SIZE_ALL=$((SIZE_ALL+SIZE))
fi
echo ${SIZE_ALL} >> ${TMP_FILE}
done
NEED_SIZE=`tail -n 1 ${TMP_FILE}`
echo "${NEED_SIZE} kb memory to reserve for $1!"
${RM} -f ${TMP_FILE}

View File

@@ -27,15 +27,13 @@
# 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/config.gni")
static_library("exchook") {
sources = [
"los_exc_info.c",
"los_exchook.c",
]
include_dirs = [
"../../kernel/arch/include",
"../../kernel/include",
"../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -28,9 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("fs_operations") {
sources = [
"./fs.c",
]
sources = [ "./fs.c" ]
include_dirs = [
"../../../kernel/arch/include",
@@ -51,10 +49,10 @@ declare_args() {
group("fs") {
deps = []
deps += [ ".:fs_operations" ]
if (enable_ohos_kernel_liteos_m_fatfs == true) {
if (enable_ohos_kernel_liteos_m_fatfs) {
deps += [ "fatfs:fatfs" ]
}
if (enable_ohos_kernel_liteos_m_littlefs == true) {
if (enable_ohos_kernel_liteos_m_littlefs) {
deps += [ "littlefs:littlefs" ]
}
}

View File

@@ -30,7 +30,7 @@
*/
#include "fs_operations.h"
#include "los_config.h"
#ifdef LOSCFG_SUPPORT_FATFS
#if (LOSCFG_SUPPORT_FATFS == 1)
#include "fatfs.h"
#endif
#include "dirent.h"
@@ -331,7 +331,7 @@ ssize_t read(int fd, void *buf, size_t nbyte)
errno = EINVAL;
return FS_FAILURE;
}
if (nbyte > 1024) {
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};
@@ -347,14 +347,14 @@ ssize_t read(int fd, void *buf, size_t nbyte)
return recv(fd, buf, nbyte, 0);
}
#endif
if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
errno = ENOSYS;
return FS_FAILURE;
}
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);
}

View File

@@ -29,9 +29,9 @@
static_library("littlefs") {
sources = [
"lfs_api.c",
"//third_party/littlefs/lfs.c",
"//third_party/littlefs/lfs_util.c",
"lfs_api.c",
]
include_dirs = [

View File

@@ -41,7 +41,7 @@ struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0};
struct dirent g_nameValue;
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"};
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a", "/b", "/c"};
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
{

View File

@@ -1,50 +1,52 @@
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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("lwip_porting.gni")
import("//third_party/lwip/lwip.gni")
config("lwip_depends") {
defines = [ "_BSD_SOURCE = 1" ]
}
static_library("lwip") {
include_dirs = [
"//kernel/liteos_m/kal/posix/include",
"//kernel/liteos_m/kernel/arch/include",
]
include_dirs += LWIP_PORTING_INCLUDE_DIRS
include_dirs += LWIP_INCLUDE_DIRS
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
configs += [ ":lwip_depends" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}
import("//third_party/lwip/lwip.gni")
import("lwip_porting.gni")
config("lwip_depends") {
defines = [ "_BSD_SOURCE = 1" ]
}
static_library("lwip") {
include_dirs = [
"//kernel/liteos_m/kal/posix/include",
"//kernel/liteos_m/kernel/arch/include",
]
include_dirs += LWIP_PORTING_INCLUDE_DIRS
include_dirs += LWIP_INCLUDE_DIRS
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
sources -= [ "$LWIPDIR/api/sockets.c" ]
configs += [ ":lwip_depends" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

View File

@@ -39,6 +39,27 @@
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
#if LWIP_DHCP
#include <lwip/dhcp.h>
#include <lwip/prot/dhcp.h>
err_t dhcp_is_bound(struct netif *netif)
{
struct dhcp *dhcp = NULL;
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
dhcp = netif_dhcp_data(netif);
LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG);
if (dhcp->state == DHCP_STATE_BOUND) {
return ERR_OK;
} else {
return ERR_INPROGRESS;
}
}
#endif /* LWIP_DHCP */
static struct netif *netif_find_by_name(const char *name)
{
struct netif *netif = NULL;

View File

@@ -242,7 +242,7 @@ static void getifaddrs_internal(struct getifaddrs_arg *arg)
if_storage = new_ifaddrs_storage();
if (if_storage == NULL) {
lwip_freeifaddrs(
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
arg->ret = ENOMEM;
goto RETURN;
}

89
components/net/lwip-2.1/lwip_porting.gni Normal file → Executable file
View File

@@ -1,44 +1,45 @@
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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/config.gni")
LWIP_PORTING_DIR = "//kernel/liteos_m/components/net/lwip-2.1"
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
LWIP_PORTING_FILES = [
"$LWIP_PORTING_DIR/porting/src/driverif.c",
"$LWIP_PORTING_DIR/porting/src/lwip_init.c",
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
if (enable_ohos_kernel_liteos_m_shell== true) {
"$LWIP_PORTING_DIR/porting/src/api_shell.c",
}
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
]
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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/config.gni")
LWIP_PORTING_DIR = "//kernel/liteos_m/components/net/lwip-2.1"
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
LWIP_PORTING_FILES = [
"$LWIP_PORTING_DIR/porting/src/driverif.c",
"$LWIP_PORTING_DIR/porting/src/lwip_init.c",
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
]
if (enable_ohos_kernel_liteos_m_shell) {
LWIP_PORTING_FILES += [ "$LWIP_PORTING_DIR/porting/src/api_shell.c" ]
}

View File

@@ -44,7 +44,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "securec.h"
#include "memory_pool.h"
#ifdef htons
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
@@ -94,33 +93,17 @@
#define LWIP_RAND rand
extern void HilogPrintf(const char *fmt, ...);
#ifndef HILOG_INFO
#define HILOG_INFO(...)
#ifndef HILOG_MODULE_APP
#define HILOG_MODULE_APP 0
#endif
#ifndef LWIP_LOGGER
#define LWIP_LOGGER(msg)
#endif
#ifndef HILOG_ERROR
#define HILOG_ERROR(...)
#endif
#define LWIP_PLATFORM_DIAG(vars) HilogPrintf vars
#define LWIP_PLATFORM_ASSERT(x) do {HILOG_ERROR(HILOG_MODULE_APP, \
"Assertion \"%s\" errno %d line %d in %s\n", \
x, errno, __LINE__, __FILE__);} while (0)
#define mem_clib_malloc LWIP_MEM_ALLOC
#define mem_clib_free LWIP_MEM_FREE
#define mem_clib_calloc LWIP_MEM_CALLOC
extern void LwipLogPrintf(const char *fmt, ...);
#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars
#define LWIP_PLATFORM_ASSERT(x) do { \
LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \
} while (0)
#define init_waitqueue_head(...)
#define poll_check_waiters(...)
#define IOCTL_CMD_CASE_HANDLER()
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.114.114")))
#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.115.115")))
#endif /* _LWIP_PORTING_CC_H_ */

View File

@@ -1,39 +1,33 @@
/**********************************************************************************
* Copyright (c) <2013-2015>, <Huawei Technologies Co., Ltd>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 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.
* 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.
***********************************************************************************/
/**********************************************************************************
* Notice of Export Control Law
===============================================
* Huawei LiteOS may be subject to applicable export control laws and regulations, which
* might include those applicable to Huawei LiteOS of U.S. and the country in which you
* are located.
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance
* with such applicable export control laws and regulations.
***********************************************************************************/
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 LWIP_API_SHELL_H
#define LWIP_API_SHELL_H

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. 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 _LWIP_PORTING_DHCP_H_
#define _LWIP_PORTING_DHCP_H_
#include_next <lwip/dhcp.h>
err_t dhcp_is_bound(struct netif *netif);
#endif /* _LWIP_PORTING_DHCP_H_ */

View File

@@ -43,9 +43,6 @@
(ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
/* directly map this to the lwip internal functions */
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
#endif /* LWIP_IPV4 */
#if LWIP_IPV6

View File

@@ -134,7 +134,7 @@
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_RAW 1
#define LWIP_SOCKET_OFFSET FAT_MAX_OPEN_FILES
#define LWIP_SOCKET_OFFSET 0
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
@@ -216,79 +216,15 @@
#define LWIP_ENABLE_NET_CAPABILITY 1
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
// Options for GT
// Options for liteos_m
#undef LWIP_NETIF_PROMISC
#define LWIP_NETIF_PROMISC 0
#undef LWIP_ICMP
#define LWIP_ICMP 0
#undef LWIP_DHCP
#define LWIP_DHCP 0
#undef LWIP_IGMP
#define LWIP_IGMP 0
#define MEMP_MEM_MALLOC 1
#undef LWIP_IPV6
#define LWIP_IPV6 0
#undef LWIP_IPV6_DHCP6
#define LWIP_IPV6_DHCP6 0
#undef TCP_SND_BUF
#define TCP_SND_BUF (65535 / 3)
#undef TCP_WND
#define TCP_WND ((TCP_SND_BUF * 2) / 3)
#undef TCP_SND_QUEUELEN
#define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF / TCP_MSS))
#undef MEMP_NUM_NETDB
#define MEMP_NUM_NETDB 1
#undef MEMP_NUM_ARP_QUEUE
#define MEMP_NUM_ARP_QUEUE 4
#undef MEMP_NUM_NETBUF
#define MEMP_NUM_NETBUF 12
#undef MEMP_NUM_NETCONN
#define MEMP_NUM_NETCONN 32
#undef MEMP_NUM_PBUF
#define MEMP_NUM_PBUF 0
#undef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 0
#undef MEMP_NUM_RAW_PCB
#define MEMP_NUM_RAW_PCB 8
#undef MEMP_NUM_REASSDATA
#define MEMP_NUM_REASSDATA 12
#undef MEMP_NUM_TCPIP_MSG_API
#define MEMP_NUM_TCPIP_MSG_API 32
#undef MEMP_NUM_TCPIP_MSG_INPKT
#define MEMP_NUM_TCPIP_MSG_INPKT 32
#undef MEMP_NUM_TCP_PCB
#define MEMP_NUM_TCP_PCB 8
#undef MEMP_NUM_TCP_PCB_LISTEN
#define MEMP_NUM_TCP_PCB_LISTEN 4
#undef MEMP_NUM_TCP_SEG
#define MEMP_NUM_TCP_SEG 64
#undef MEMP_NUM_UDP_PCB
#define MEMP_NUM_UDP_PCB 4
#undef TCPIP_THREAD_STACKSIZE
#define TCPIP_THREAD_STACKSIZE 0x1000
#undef LWIP_SOCKET_SELECT
#define LWIP_SOCKET_SELECT 1

View File

@@ -41,7 +41,6 @@
#include <limits.h>
#include <fcntl.h>
#include_next <lwip/sockets.h>
#include <fatfs.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -1,39 +1,33 @@
/**********************************************************************************
* Copyright (c) <2013-2015>, <Huawei Technologies Co., Ltd>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 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.
* 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.
***********************************************************************************/
/**********************************************************************************
* Notice of Export Control Law
===============================================
* Huawei LiteOS may be subject to applicable export control laws and regulations, which
* might include those applicable to Huawei LiteOS of U.S. and the country in which you
* are located.
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance
* with such applicable export control laws and regulations.
***********************************************************************************/
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 LWIP_STATIC static
#define DHCP_STATE_OFF 0
@@ -47,11 +41,9 @@
#include "lwip/icmp.h"
#include "los_config.h"
#include <string.h>
#include "lwip/api_shell.h"
#include "shcmd.h"
#include "shell.h"
#include "los_timer_pri.h"
#include "los_debug.h"
#include "los_task.h"
@@ -104,10 +96,10 @@ int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
if (buf_len < 1) {
goto out;
}
if(netif->link_layer_type == LOOPBACK_IF){
ret = snprintf_s(tmp, buf_len, (buf_len-1), "%s\t", netif->name);
if (netif->link_layer_type == LOOPBACK_IF) {
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s\t", netif->name);
} else {
ret = snprintf_s(tmp, buf_len, (buf_len-1), "%s%u\t", netif->name, netif->num);
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s%u\t", netif->name, netif->num);
}
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
@@ -317,8 +309,7 @@ static int ping_kill = 0;
static void lwip_ping_usage(void)
{
PRINTK("Usage:"\
"\n ping [ip]\n"
PRINTK("Usage:\n ping [ip]\n");
}
LWIP_STATIC int OsPingFunc(u32_t *parg)
@@ -332,17 +323,17 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
u32_t iecho_len;
s16_t ip_hlen;
u32_t forever;
u32_t i = 0;
u32_t i;
u32_t succ_cnt = 0;
u32_t failed_cnt = 0;
struct timespec start, end;
long timout_ms = 0;
long timout_ms;
struct pollfd pfd;
long rtt;
int ret = 0;
u32_t intrvl;
char *data_buf = NULL;
BOOL timeout_flag = false;
BOOL timeout_flag = FALSE;
char buf[50];
u32_t destip = parg[0];
@@ -407,14 +398,14 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
do {
pfd.events = POLLIN;
pfd.revents = 0;
timeout_flag = false;
timeout_flag = FALSE;
ret = poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
if (ret < 0) {
perror("Ping: poll\n");
goto FAILURE;
} else if (ret == 0) {
/* first type timeout event */
timeout_flag = true;
timeout_flag = TRUE;
break;
}
@@ -454,7 +445,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
} while (timout_ms >= 0);
/* all timeout events are true timeout */
if ((timout_ms < 0) || (timeout_flag == true)) {
if ((timout_ms < 0) || (timeout_flag == TRUE)) {
failed_cnt++;
i++;
PRINTK("\nPing: destination unreachable ...");

View File

@@ -29,8 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/sockets.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/priv/sockets_priv.h"
#include <lwip/sockets.h>
#if !LWIP_COMPAT_SOCKETS
#if LWIP_SOCKET
@@ -160,6 +161,27 @@ int inet_pton(int af, const char *src, void *dst)
return lwip_inet_pton(af, src, dst);
}
#ifndef LWIP_INET_ADDR_FUNC
in_addr_t inet_addr(const char *cp)
{
return ipaddr_addr(cp);
}
#endif
#ifndef LWIP_INET_NTOA_FUNC
char *inet_ntoa(struct in_addr addr)
{
return ip4addr_ntoa((const ip4_addr_t*)&(addr));
}
#endif
#ifndef LWIP_INET_ATON_FUNC
int inet_aton(const char *cp, struct in_addr *addr)
{
return ip4addr_aton(cp, (ip4_addr_t*)addr);
}
#endif
int ioctlsocket(int s, long cmd, void *argp)
{
return lwip_ioctl(s, cmd, argp);
@@ -185,4 +207,81 @@ unsigned int if_nametoindex(const char *ifname)
}
#endif
#endif /* !LWIP_COMPAT_SOCKETS */
#endif /* !LWIP_COMPAT_SOCKETS */
#define IOCTL_CMD_CASE_HANDLER() do { \
err_t err; \
struct lwip_ioctl_apimsg msg; \
msg.sock = sock; \
msg.cmd = cmd; \
msg.argp = argp; \
\
err = tcpip_api_call(lwip_do_ioctl_impl, &msg.call); \
if (err != ENOSYS) { \
sock_set_errno(sock, err); \
done_socket(sock); \
return -(err != ERR_OK); \
} \
} while (0)
struct lwip_ioctl_apimsg {
struct tcpip_api_call_data call;
struct lwip_sock *sock;
long cmd;
void *argp;
};
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call);
#include "../api/sockets.c"
static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr)
{
struct netif *netif = NULL;
struct sockaddr_in *sock_in = NULL;
/* get netif subnet broadcast addr */
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
}
if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) {
return ENXIO;
}
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
sock_in->sin_family = AF_INET;
sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr));
return 0;
}
static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp)
{
u8_t err = 0;
struct ifreq *ifr = (struct ifreq *)argp;
bool is_ipv6 = 0;
/* allow it only on IPv6 sockets... */
is_ipv6 = NETCONNTYPE_ISIPV6((unsigned int)(sock->conn->type));
switch ((u32_t)cmd) {
case SIOCGIFBRDADDR:
if (is_ipv6 != 0) {
err = EINVAL;
} else {
err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr);
}
break;
default:
err = ENOSYS;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(UNIMPL: 0x%lx)\n", cmd));
break;
}
return err;
}
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call)
{
struct lwip_ioctl_apimsg *msg = (struct lwip_ioctl_apimsg *)(void *)call;
return lwip_ioctl_impl(msg->sock, msg->cmd, msg->argp);
}

View File

@@ -324,7 +324,7 @@ void sys_mutex_set_invalid(sys_mutex_t *mutex)
*mutex = LOSCFG_BASE_IPC_MUX_LIMIT;
}
void HilogPrintf(const char *fmt, ...)
void LwipLogPrintf(const char *fmt, ...)
{
if ((fmt == NULL) || (strlen(fmt) == 0)) {
return;
@@ -337,8 +337,8 @@ void HilogPrintf(const char *fmt, ...)
len = vsprintf_s(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
if (len < 0) {
HILOG_INFO(HILOG_MODULE_APP, "log param invalid or buf is not enough.");
LWIP_LOGGER("log param invalid or buf is not enough.");
return;
}
HILOG_INFO(HILOG_MODULE_APP, buf);
LWIP_LOGGER(buf);
}

View File

@@ -27,13 +27,10 @@
# 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/config.gni")
static_library("pm") {
sources = [ "los_pm.c" ]
include_dirs = [
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -34,20 +34,22 @@
#include "los_sched.h"
#include "los_timer.h"
#include "los_memory.h"
#include "los_swtmr.h"
#if (LOSCFG_KERNEL_PM == 1)
#define OS_PM_NODE_FREE 0x80000000U
#define OS_PM_LOCK_MAX 0xFFFFU
#define OS_PM_SYS_EARLY 1
#define OS_PM_SYS_DEVICE_EARLY 2
typedef UINT32 (*Suspend)(VOID);
typedef UINT32 (*Suspend)(UINT32 mode);
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
typedef struct {
CHAR *name;
UINT32 count;
UINT32 swtmrID;
LOS_DL_LIST list;
} OsPmLockCB;
#endif
typedef struct {
LOS_SysSleepEnum pmMode;
@@ -60,72 +62,92 @@ typedef struct {
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 enterSleepTime;
#endif
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
LOS_DL_LIST lockList;
#endif
} LosPmCB;
#define PM_EVENT_LOCK_MASK 0xF
#define PM_EVENT_LOCK_RELEASE 0x1
STATIC EVENT_CB_S g_pmEvent;
STATIC LosPmCB g_pmCB;
STATIC LosPmSysctrl *g_sysctrl = NULL;
STATIC LosPmSysctrl g_sysctrl;
STATIC UINT64 g_pmSleepTime;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
STATIC VOID OsPmSysctrlInit(VOID)
{
UINT32 intSave;
UINT64 currTime, sleepTime, realSleepTime;
LosPmTickTimer *tickTimer = pm->tickTimer;
intSave = LOS_IntLock();
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq);
realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, OS_SYS_CLOCK);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
OsSchedTimerBaseReset(currTime);
OsSchedUpdateExpireTime(currTime, FALSE);
tickTimer->tickUnlock();
LOS_IntRestore(intSave);
return;
/* Default handler functions, which are implemented by the product */
g_sysctrl.early = NULL;
g_sysctrl.late = NULL;
g_sysctrl.normalSuspend = HalEnterSleep;
g_sysctrl.normalResume = NULL;
g_sysctrl.lightSuspend = HalEnterSleep;
g_sysctrl.lightResume = NULL;
g_sysctrl.deepSuspend = HalEnterSleep;
g_sysctrl.deepResume = NULL;
g_sysctrl.shutdownSuspend = NULL;
g_sysctrl.shutdownResume = NULL;
}
STATIC VOID OsPmTickTimerStop(LosPmCB *pm)
STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
{
UINT64 sleepCycle;
UINT64 realSleepTime = g_pmSleepTime;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 currTime, sleepTime, realSleepTime;
#endif
LosPmTickTimer *tickTimer = pm->tickTimer;
if (realSleepTime == 0) {
if ((tickTimer == NULL) || (tickTimer->tickUnlock == NULL)) {
return;
}
sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, OS_SYS_CLOCK);
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
if (tickTimer->timerStop != NULL) {
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
/* The main CPU reduces the frequency */
pm->enterSleepTime = OsGetCurrSchedTimeCycle();
tickTimer->tickLock();
tickTimer->timerStart(sleepCycle);
realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq);
realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, OS_SYS_CLOCK);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
OsSchedTimerBaseReset(currTime);
}
#endif
tickTimer->tickUnlock();
return;
}
STATIC BOOL OsPmTickTimerStop(LosPmCB *pm)
{
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 sleepCycle;
UINT64 realSleepTime = g_pmSleepTime;
#endif
LosPmTickTimer *tickTimer = pm->tickTimer;
if ((tickTimer == NULL) || (tickTimer->tickLock == NULL)) {
return FALSE;
}
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
if (tickTimer->timerStart != NULL) {
if (realSleepTime == 0) {
return FALSE;
}
sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, OS_SYS_CLOCK);
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
/* The main CPU reduces the frequency */
pm->enterSleepTime = OsGetCurrSysTimeCycle();
tickTimer->tickLock();
tickTimer->timerStart(sleepCycle);
return TRUE;
}
#endif
STATIC VOID OsPmTickTimerResume(LosPmCB *pm)
{
if ((pm->sysMode == LOS_SYS_DEEP_SLEEP) && (pm->tickTimer->tickUnlock != NULL)) {
pm->tickTimer->tickUnlock();
} else {
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
/* Sys tick timer is restored from low power mode */
if (pm->enterSleepTime != 0) {
OsPmTickTimerStart(pm);
}
#endif
}
tickTimer->tickLock();
return TRUE;
}
STATIC VOID OsPmCpuResume(LosPmCB *pm)
@@ -139,126 +161,137 @@ STATIC VOID OsPmCpuResume(LosPmCB *pm)
}
}
STATIC Suspend OsPmCpuSuspend(LosPmCB *pm)
STATIC VOID OsPmCpuSuspend(LosPmCB *pm)
{
Suspend sysSuspend = NULL;
/* cpu enter low power mode */
LOS_ASSERT(pm->sysctrl != NULL);
if (pm->sysMode == LOS_SYS_NORMAL_SLEEP) {
sysSuspend = pm->sysctrl->normalSuspend;
pm->sysctrl->normalSuspend();
} else if (pm->sysMode == LOS_SYS_LIGHT_SLEEP) {
sysSuspend = pm->sysctrl->lightSuspend;
pm->sysctrl->lightSuspend();
} else if (pm->sysMode == LOS_SYS_DEEP_SLEEP) {
sysSuspend = pm->sysctrl->deepSuspend;
pm->sysctrl->deepSuspend();
} else {
sysSuspend = pm->sysctrl->shutdownSuspend;
pm->sysctrl->shutdownSuspend();
}
LOS_ASSERT(sysSuspend != NULL);
return sysSuspend;
}
STATIC VOID OsPmTickTimerSuspend(LosPmCB *pm)
STATIC VOID OsPmResumePrepare(LosPmCB *pm, UINT32 mode, UINT32 prepare)
{
if (((pm->sysMode == LOS_SYS_DEEP_SLEEP) || (pm->sysMode == LOS_SYS_SHUTDOWN)) &&
(pm->tickTimer->tickLock != NULL)) {
pm->tickTimer->tickLock();
} else {
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
/* Sys tick timer enter low power mode */
if (pm->tickTimer == NULL) {
return;
}
if ((prepare == 0) && (pm->device->resume != NULL)) {
pm->device->resume(mode);
}
if ((pm->tickTimer->timerStart != NULL) &&
(pm->tickTimer->timerStop != NULL) &&
(pm->tickTimer->timerCycleGet == NULL) &&
(pm->tickTimer->freq != 0)) {
OsPmTickTimerStop(pm);
}
#endif
if (((prepare == 0) || (prepare == OS_PM_SYS_DEVICE_EARLY)) && (pm->sysctrl->late != NULL)) {
pm->sysctrl->late(mode);
}
}
STATIC VOID OsPmEnter(BOOL isIdle)
STATIC UINT32 OsPmSuspendPrepare(Suspend sysSuspendEarly, Suspend deviceSuspend, UINT32 mode, UINT32 *prepare)
{
UINT32 ret;
if (sysSuspendEarly != NULL) {
ret = sysSuspendEarly(mode);
if (ret != LOS_OK) {
*prepare = OS_PM_SYS_EARLY;
return ret;
}
}
if (deviceSuspend != NULL) {
ret = deviceSuspend(mode);
if (ret != LOS_OK) {
*prepare = OS_PM_SYS_DEVICE_EARLY;
return ret;
}
}
return LOS_OK;
}
STATIC UINT32 OsPmSuspendCheck(LosPmCB *pm, Suspend *sysSuspendEarly, Suspend *deviceSuspend, LOS_SysSleepEnum *mode)
{
UINT32 intSave;
Suspend sysSuspend = NULL;
LosPmCB *pm = &g_pmCB;
BOOL isTaskLock = FALSE;
intSave = LOS_IntLock();
pm->sysMode = pm->pmMode;
if (isIdle) {
if ((pm->sysMode != LOS_SYS_NORMAL_SLEEP) && (pm->sysMode != LOS_SYS_LIGHT_SLEEP)) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
}
} else {
if ((pm->sysMode != LOS_SYS_DEEP_SLEEP) && (pm->sysMode != LOS_SYS_SHUTDOWN)) {
LOS_IntRestore(intSave);
return;
}
}
if ((pm->sysMode == LOS_SYS_NORMAL_SLEEP) || (pm->sysMode == LOS_SYS_LIGHT_SLEEP)) {
if (pm->lock > 0) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
}
} else if (pm->lock > 0) {
if (pm->lock > 0) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
LOS_IntRestore(intSave);
return;
return LOS_NOK;
}
if (pm->sysMode != LOS_SYS_NORMAL_SLEEP) {
pm->isWake = FALSE;
LOS_TaskLock();
isTaskLock = TRUE;
ret = pm->device->suspend((UINT32)pm->sysMode);
if (ret != LOS_OK) {
goto EXIT;
}
}
OsPmTickTimerSuspend(pm);
sysSuspend = OsPmCpuSuspend(pm);
pm->isWake = FALSE;
*mode = pm->sysMode;
*sysSuspendEarly = pm->sysctrl->early;
*deviceSuspend = pm->device->suspend;
LOS_IntRestore(intSave);
return LOS_OK;
}
if (!isTaskLock || (isTaskLock && !pm->isWake)) {
(VOID)sysSuspend();
STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
{
UINT32 ret, intSave;
Suspend sysSuspendEarly, deviceSuspend;
LOS_SysSleepEnum mode;
UINT32 prepare = 0;
BOOL tickTimerStop = FALSE;
UINT64 currTime;
ret = OsPmSuspendCheck(pm, &sysSuspendEarly, &deviceSuspend, &mode);
if (ret != LOS_OK) {
return ret;
}
ret = OsPmSuspendPrepare(sysSuspendEarly, deviceSuspend, (UINT32)mode, &prepare);
if (ret != LOS_OK) {
intSave = LOS_IntLock();
LOS_TaskLock();
goto EXIT;
}
intSave = LOS_IntLock();
LOS_TaskLock();
if (pm->isWake || (pm->lock > 0)) {
goto EXIT;
}
tickTimerStop = OsPmTickTimerStop(pm);
if (!tickTimerStop) {
currTime = OsGetCurrSchedTimeCycle();
OsSchedResetSchedResponseTime(0);
OsSchedUpdateExpireTime(currTime, TRUE);
}
OsPmCpuSuspend(pm);
OsPmCpuResume(pm);
OsPmTickTimerResume(pm);
if (pm->sysMode != LOS_SYS_NORMAL_SLEEP) {
pm->device->resume((UINT32)pm->sysMode);
}
if (pm->pmMode == LOS_SYS_DEEP_SLEEP) {
pm->pmMode = LOS_SYS_NORMAL_SLEEP;
}
OsPmTickTimerStart(pm);
EXIT:
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
OsPmResumePrepare(pm, (UINT32)mode, prepare);
LOS_IntRestore(intSave);
if (isTaskLock) {
LOS_TaskUnlock();
}
return;
LOS_TaskUnlock();
return ret;
}
STATIC VOID OsPmTask(VOID)
STATIC VOID OsPmNormalSleep(VOID)
{
OsPmEnter(FALSE);
UINT32 intSave;
LosPmCB *pm = &g_pmCB;
intSave = LOS_IntLock();
OsPmCpuSuspend(pm);
OsPmCpuResume(pm);
LOS_IntRestore(intSave);
}
STATIC UINT32 OsPmDeviceRegister(LosPmCB *pm, LosPmDevice *device)
@@ -280,27 +313,60 @@ STATIC UINT32 OsPmTickTimerRegister(LosPmCB *pm, LosPmTickTimer *tickTimer)
{
UINT32 intSave;
intSave = LOS_IntLock();
if ((tickTimer->tickLock == NULL) || (tickTimer->tickUnlock == NULL)) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
if (((tickTimer->timerStart == NULL) && (tickTimer->timerStop == NULL) &&
(tickTimer->timerCycleGet == NULL) && (tickTimer->freq == 0)) ||
((tickTimer->timerStart != NULL) && (tickTimer->timerStop != NULL) &&
(tickTimer->timerCycleGet != NULL) && (tickTimer->freq != 0))) {
intSave = LOS_IntLock();
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
pm->enterSleepTime = 0;
pm->enterSleepTime = 0;
#endif
pm->tickTimer = tickTimer;
LOS_IntRestore(intSave);
return LOS_OK;
pm->tickTimer = tickTimer;
LOS_IntRestore(intSave);
return LOS_OK;
}
return LOS_ERRNO_PM_INVALID_PARAM;
}
STATIC UINT32 OsPmSysctrlRegister(LosPmCB *pm, LosPmSysctrl *sysctrl)
{
UINT32 intSave;
if (sysctrl->normalSuspend == NULL) {
return LOS_ERRNO_PM_INVALID_PARAM;
UINT32 intSave = LOS_IntLock();
if (sysctrl->early != NULL) {
pm->sysctrl->early = sysctrl->early;
}
if (sysctrl->late != NULL) {
pm->sysctrl->late = sysctrl->late;
}
if (sysctrl->normalSuspend != NULL) {
pm->sysctrl->normalSuspend = sysctrl->normalSuspend;
}
if (sysctrl->normalResume != NULL) {
pm->sysctrl->normalResume = sysctrl->normalResume;
}
if (sysctrl->lightSuspend != NULL) {
pm->sysctrl->lightSuspend = sysctrl->lightSuspend;
}
if (sysctrl->lightResume != NULL) {
pm->sysctrl->lightResume = sysctrl->lightResume;
}
if (sysctrl->deepSuspend != NULL) {
pm->sysctrl->deepSuspend = sysctrl->deepSuspend;
}
if (sysctrl->deepResume != NULL) {
pm->sysctrl->deepResume = sysctrl->deepResume;
}
if (sysctrl->shutdownSuspend != NULL) {
pm->sysctrl->shutdownSuspend = sysctrl->shutdownSuspend;
}
if (sysctrl->shutdownResume != NULL) {
pm->sysctrl->shutdownResume = sysctrl->shutdownResume;
}
intSave = LOS_IntLock();
pm->sysctrl = sysctrl;
LOS_IntRestore(intSave);
return LOS_OK;
}
@@ -362,27 +428,13 @@ STATIC UINT32 OsPmTickTimerUnregister(LosPmCB *pm, LosPmTickTimer *tickTimer)
STATIC UINT32 OsPmSysctrlUnregister(LosPmCB *pm, LosPmSysctrl *sysctrl)
{
UINT32 intSave;
VOID *freeNode = NULL;
intSave = LOS_IntLock();
if (pm->sysctrl == sysctrl) {
if (pm->sysctrl == g_sysctrl) {
freeNode = (VOID *)pm->sysctrl;
g_sysctrl = NULL;
}
pm->sysctrl = NULL;
LOS_IntRestore(intSave);
if (freeNode != NULL) {
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, freeNode);
}
return LOS_OK;
}
(VOID)sysctrl;
UINT32 intSave = LOS_IntLock();
OsPmSysctrlInit();
pm->pmMode = LOS_SYS_NORMAL_SLEEP;
LOS_IntRestore(intSave);
return LOS_ERRNO_PM_INVALID_NODE;
return LOS_OK;
}
UINT32 LOS_PmUnregister(LOS_PmNodeType type, VOID *node)
@@ -433,11 +485,8 @@ LOS_SysSleepEnum LOS_PmModeGet(VOID)
UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode)
{
UINT32 intSave;
UINT32 taskID;
UINT32 ret;
LosPmCB *pm = &g_pmCB;
INT32 sleepMode = (INT32)mode;
TSK_INIT_PARAM_S taskInitParam = { 0 };
if ((sleepMode < 0) || (sleepMode > LOS_SYS_SHUTDOWN)) {
return LOS_ERRNO_PM_INVALID_MODE;
@@ -464,29 +513,9 @@ UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode)
return LOS_ERRNO_PM_HANDLER_NULL;
}
if ((mode == LOS_SYS_DEEP_SLEEP) || (mode == LOS_SYS_SHUTDOWN)) {
if ((pm->tickTimer == NULL) ||
(pm->tickTimer->tickLock == NULL) ||
(pm->tickTimer->tickUnlock == NULL)) {
LOS_IntRestore(intSave);
return LOS_ERRNO_PM_TICK_TIMER_NULL;
}
}
pm->pmMode = mode;
LOS_IntRestore(intSave);
if ((mode == LOS_SYS_DEEP_SLEEP) || (mode == LOS_SYS_SHUTDOWN)) {
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsPmTask;
taskInitParam.uwStackSize = LOSCFG_KERNEL_PM_TASK_STACKSIZE;
taskInitParam.pcName = "pm";
taskInitParam.usTaskPrio = LOSCFG_KERNEL_PM_TASK_PTIORITY;
ret = LOS_TaskCreate(&taskID, &taskInitParam);
if (ret != LOS_OK) {
return ret;
}
}
return LOS_OK;
}
@@ -513,24 +542,17 @@ VOID LOS_PmLockInfoShow(VOID)
}
#endif
UINT32 LOS_PmLockRequest(const CHAR *name)
UINT32 OsPmLockRequest(const CHAR *name, UINT32 swtmrID)
{
UINT32 intSave;
UINT32 ret = LOS_ERRNO_PM_NOT_LOCK;
LosPmCB *pm = &g_pmCB;
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
OsPmLockCB *listNode = NULL;
OsPmLockCB *lock = NULL;
LOS_DL_LIST *head = &pm->lockList;
LOS_DL_LIST *list = head->pstNext;
if (name == NULL) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
#endif
intSave = LOS_IntLock();
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
while (list != head) {
listNode = LOS_DL_LIST_ENTRY(list, OsPmLockCB, list);
if (strcmp(name, listNode->name) == 0) {
@@ -549,11 +571,17 @@ UINT32 LOS_PmLockRequest(const CHAR *name)
}
lock->name = (CHAR *)name;
lock->count = 1;
lock->swtmrID = swtmrID;
LOS_ListTailInsert(head, &lock->list);
} else if (lock->count < OS_PM_LOCK_MAX) {
lock->count++;
}
#endif
if ((lock->swtmrID != OS_INVALID) && (lock->count > 1)) {
lock->count--;
LOS_IntRestore(intSave);
return LOS_ERRNO_PM_ALREADY_LOCK;
}
if (pm->lock < OS_PM_LOCK_MAX) {
pm->lock++;
@@ -564,25 +592,34 @@ UINT32 LOS_PmLockRequest(const CHAR *name)
return ret;
}
UINT32 LOS_PmLockRequest(const CHAR *name)
{
if (name == NULL) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
return OsPmLockRequest(name, OS_INVALID);
}
UINT32 LOS_PmLockRelease(const CHAR *name)
{
UINT32 intSave;
UINT32 ret = LOS_ERRNO_PM_NOT_LOCK;
LosPmCB *pm = &g_pmCB;
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
OsPmLockCB *lock = NULL;
OsPmLockCB *listNode = NULL;
LOS_DL_LIST *head = &pm->lockList;
LOS_DL_LIST *list = head->pstNext;
VOID *lockFree = NULL;
OsPmLockCB *lockFree = NULL;
BOOL isRelease = FALSE;
UINT32 mode;
if (name == NULL) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
#endif
intSave = LOS_IntLock();
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
mode = (UINT32)pm->pmMode;
while (list != head) {
listNode = LOS_DL_LIST_ENTRY(list, OsPmLockCB, list);
if (strcmp(name, listNode->name) == 0) {
@@ -603,25 +640,141 @@ UINT32 LOS_PmLockRelease(const CHAR *name)
lockFree = lock;
}
}
#endif
if (pm->lock > 0) {
pm->lock--;
if (pm->lock == 0) {
isRelease = TRUE;
}
ret = LOS_OK;
}
LOS_IntRestore(intSave);
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, lockFree);
#endif
if (lockFree != NULL) {
(VOID)LOS_SwtmrDelete(lockFree->swtmrID);
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, lockFree);
}
if (isRelease && (mode > LOS_SYS_NORMAL_SLEEP)) {
(VOID)LOS_EventWrite(&g_pmEvent, PM_EVENT_LOCK_RELEASE);
}
return ret;
}
VOID OsPmFreezeTaskUnsafe(UINT32 taskID)
{
UINT64 responseTime;
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
OsDeleteSortLink(&taskCB->sortList, OS_SORT_LINK_TASK);
SET_SORTLIST_VALUE(&taskCB->sortList, responseTime);
taskCB->taskStatus |= OS_TASK_FALG_FREEZE;
return;
}
VOID OsPmUnfreezeTaskUnsafe(UINT32 taskID)
{
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
UINT64 currTime, responseTime;
UINT32 remainTick;
taskCB->taskStatus &= ~OS_TASK_FALG_FREEZE;
currTime = OsGetCurrSchedTimeCycle();
responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
if (responseTime > currTime) {
remainTick = ((responseTime - currTime) + OS_CYCLE_PER_TICK - 1) / OS_CYCLE_PER_TICK;
OsAdd2SortLink(&taskCB->sortList, currTime, remainTick, OS_SORT_LINK_TASK);
return;
}
SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
if (taskCB->taskStatus & OS_TASK_STATUS_PEND) {
LOS_ListDelete(&taskCB->pendList);
}
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_PEND);
return;
}
STATIC VOID OsPmSwtmrHandler(UINT32 arg)
{
const CHAR *name = (const CHAR *)arg;
UINT32 ret = LOS_PmLockRelease(name);
if (ret != LOS_OK) {
PRINT_ERR("Pm delay lock %s release faled! : 0x%x\n", name, ret);
}
}
UINT32 LOS_PmTimeLockRequest(const CHAR *name, UINT64 millisecond)
{
UINT32 ticks;
UINT32 swtmrID;
UINT32 ret;
if ((name == NULL) || !millisecond) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
ticks = (UINT32)((millisecond + OS_MS_PER_TICK - 1) / OS_MS_PER_TICK);
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
ret = LOS_SwtmrCreate(ticks, LOS_SWTMR_MODE_ONCE, OsPmSwtmrHandler, &swtmrID, (UINT32)(UINTPTR)name,
OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE);
#else
ret = LOS_SwtmrCreate(ticks, LOS_SWTMR_MODE_ONCE, OsPmSwtmrHandler, &swtmrID, (UINT32)(UINTPTR)name);
#endif
if (ret != LOS_OK) {
return ret;
}
ret = OsPmLockRequest(name, swtmrID);
if (ret != LOS_OK) {
(VOID)LOS_SwtmrDelete(swtmrID);
return ret;
}
ret = LOS_SwtmrStart(swtmrID);
if (ret != LOS_OK) {
(VOID)LOS_PmLockRelease(name);
}
return ret;
}
UINT32 LOS_PmReadLock(VOID)
{
UINT32 ret = LOS_EventRead(&g_pmEvent, PM_EVENT_LOCK_MASK, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
if (ret > PM_EVENT_LOCK_MASK) {
PRINT_ERR("%s event read failed! ERROR: 0x%x\n", __FUNCTION__, ret);
}
return LOS_OK;
}
UINT32 LOS_PmSuspend(UINT32 wakeCount)
{
(VOID)wakeCount;
return OsPmSuspendSleep(&g_pmCB);
}
STATIC VOID OsPmSleepTimeSet(UINT64 sleepTime)
{
g_pmSleepTime = sleepTime;
}
BOOL OsIsPmMode(VOID)
{
LosPmCB *pm = &g_pmCB;
UINT32 intSave = LOS_IntLock();
if ((pm->sysMode != LOS_SYS_NORMAL_SLEEP) && (pm->lock == 0)) {
LOS_IntRestore(intSave);
return TRUE;
}
LOS_IntRestore(intSave);
return FALSE;
}
UINT32 OsPmInit(VOID)
{
UINT32 ret;
@@ -630,34 +783,21 @@ UINT32 OsPmInit(VOID)
(VOID)memset_s(pm, sizeof(LosPmCB), 0, sizeof(LosPmCB));
pm->pmMode = LOS_SYS_NORMAL_SLEEP;
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
LOS_ListInit(&pm->lockList);
#endif
(VOID)LOS_EventInit(&g_pmEvent);
ret = OsSchedRealSleepTimeSet(OsPmSleepTimeSet);
if (ret != LOS_OK) {
return ret;
}
ret = OsPmEnterHandlerSet(OsPmEnter);
ret = OsPmEnterHandlerSet(OsPmNormalSleep);
if (ret != LOS_OK) {
return ret;
}
g_sysctrl = (LosPmSysctrl *)LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(LosPmSysctrl));
if (g_sysctrl == NULL) {
return LOS_NOK;
}
(VOID)memset_s(g_sysctrl, sizeof(LosPmSysctrl), 0, sizeof(LosPmSysctrl));
g_sysctrl->normalSuspend = HalEnterSleep;
ret = LOS_PmRegister(LOS_PM_TYPE_SYSCTRL, (VOID *)g_sysctrl);
if (ret != LOS_OK) {
(VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, g_sysctrl);
g_sysctrl = NULL;
}
OsPmSysctrlInit();
pm->sysctrl = &g_sysctrl;
return ret;
}
#endif

View File

@@ -118,6 +118,15 @@
*/
#define LOS_ERRNO_PM_DEVICE_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_PM, 0x09)
/**
* @ingroup los_pm
* Pm error code: The delay lock has already been activated.
*
* Value: 0x0200200a
*
*/
#define LOS_ERRNO_PM_ALREADY_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_PM, 0x0a)
typedef enum {
LOS_SYS_NORMAL_SLEEP = 0,
LOS_SYS_LIGHT_SLEEP,
@@ -132,8 +141,8 @@ typedef enum {
} LOS_PmNodeType;
typedef struct {
UINT32 (*suspend)(UINT32 mode);
VOID (*resume)(UINT32 mode);
UINT32 (*suspend)(UINT32 mode); /* The device enters low power consumption, Unlocked task scheduling. */
VOID (*resume)(UINT32 mode); /* The device exits from low power consumption, Unlocked task scheduling. */
} LosPmDevice;
typedef struct {
@@ -146,13 +155,47 @@ typedef struct {
} LosPmTickTimer;
typedef struct {
/* Preparations before the CPU enters low power consumption.
* All modes except normal mode are invoked.
* Unlocked task scheduling.
*/
UINT32 (*early)(UINT32 mode);
/* The system performs low-power recovery.
* All modes except normal mode are invoked.
* Unlocked task scheduling.
*/
VOID (*late)(UINT32 mode);
/* The system enters the Normal sleep mode.
* In normal mode, the value cannot be NULL.
*/
UINT32 (*normalSuspend)(VOID);
/* The system recovers from normal sleep.
* The value can be NULL.
*/
VOID (*normalResume)(VOID);
/* The system enters the light sleep mode.
* In light sleep mode, the value cannot be NULL.
*/
UINT32 (*lightSuspend)(VOID);
/* The system recovers from light sleep.
* The value can be NULL.
*/
VOID (*lightResume)(VOID);
/* The system enters the deep sleep mode.
* In deep sleep mode, the value cannot be NULL.
*/
UINT32 (*deepSuspend)(VOID);
/* The system recovers from deep sleep.
* The value can be NULL.
*/
VOID (*deepResume)(VOID);
/* The system enters the shutdown mode.
* In shutdown mode, the value cannot be NULL.
*/
UINT32 (*shutdownSuspend)(VOID);
/* The system recovers from shutdown.
* In shutdown mode, the value cannot be NULL.
*/
VOID (*shutdownResume)(VOID);
} LosPmSysctrl;
@@ -174,6 +217,60 @@ typedef struct {
*/
UINT32 OsPmInit(VOID);
/**
* @ingroup los_pm
* @brief Whether the low power consumption condition is met.
*
* @par Description:
* This API is used to check whether low power consumption is met.
*
* @attention None.
*
* @param None.
*
* @retval TRUE or FALSE.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see
*/
BOOL OsIsPmMode(VOID);
/**
* @ingroup los_pm
* @brief Freeze delay tasks, internal interfaces between modules.
*
* @par Description:
* This API is used to freeze delay tasks.
*
* @attention None.
*
* @param taskID [IN] task ID.
*
* @retval None.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see OsPmUnfreezeTaskUnsafe
*/
VOID OsPmFreezeTaskUnsafe(UINT32 taskID);
/**
* @ingroup los_pm
* @brief Unfreeze delayed tasks, internal interface between modules.
*
* @par Description:
* This API is used to unfreeze delayed tasks.
*
* @attention None.
*
* @param taskID [IN] task ID.
*
* @retval None.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see OsPmFreezeTaskUnsafe
*/
VOID OsPmUnfreezeTaskUnsafe(UINT32 taskID);
/**
* @ingroup los_pm
* @brief Register a power management node.
@@ -285,6 +382,27 @@ UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode);
*/
UINT32 LOS_PmLockRequest(const CHAR *name);
/**
* @ingroup los_pm
* @brief Request to obtain the lock in current mode, so that the system will not enter
* this mode when it enters the idle task next time. After the specified interval, the
* lock is automatically released.
*
* @par Description:
* This API is used to obtain the delay lock in current mode.
*
* @attention None.
*
* @param name [IN] Who requests the lock.
* @param millisecond [IN] Specifies the time to automatically release the lock.
*
* @retval error code, LOS_OK means success.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see LOS_PmLockRelease
*/
UINT32 LOS_PmTimeLockRequest(const CHAR *name, UINT64 millisecond);
/**
* @ingroup los_pm
* @brief Release the lock in current mode so that the next time the system enters
@@ -304,7 +422,42 @@ UINT32 LOS_PmLockRequest(const CHAR *name);
*/
UINT32 LOS_PmLockRelease(const CHAR *name);
#if (LOSCFG_KERNEL_PM_DEBUG == 1)
/**
* @ingroup los_pm
* @brief Gets the current PM lock status.
*
* @par Description:
* This API is used to Get the current PM lock status.
*
* @attention None.
*
* @param NA.
*
* @retval Number of awakening sources of the device.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see
*/
UINT32 LOS_PmReadLock(VOID);
/**
* @ingroup los_pm
* @brief The system enters the low-power flow.
*
* @par Description:
* This API is used to enter the system into a low-power process.
*
* @attention None.
*
* @param wakeCount [IN] Number of wake sources.
*
* @retval error code, LOS_OK means success.
* @par Dependency:
* <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul>
* @see
*/
UINT32 LOS_PmSuspend(UINT32 wakeCount);
/**
* @ingroup los_pm
* @brief Output the locking information of the pm lock.
@@ -323,4 +476,3 @@ UINT32 LOS_PmLockRelease(const CHAR *name);
*/
VOID LOS_PmLockInfoShow(VOID);
#endif
#endif

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
static_library("shell") {
sources = [
"src/base/shcmd.c",
@@ -34,11 +36,11 @@ static_library("shell") {
"src/base/shmsg.c",
"src/base/show.c",
"src/cmds/date_shell.c",
"src/cmds/fullpath.c",
"src/cmds/mempt_shellcmd.c",
"src/cmds/shell_shellcmd.c",
"src/cmds/task_shellcmd.c",
"src/cmds/vfs_shellcmd.c",
"src/cmds/mempt_shellcmd.c",
"src/cmds/fullpath.c",
]
include_dirs = [
@@ -48,6 +50,9 @@ static_library("shell") {
"./include",
]
if (enable_ohos_kernel_liteos_m_lwip) {
defines = [ "LWIP_SHELLCMD_ENABLE" ]
}
deps = [
"//kernel/liteos_m/kal/posix",
"//third_party/bounds_checking_function:libsec_static",

View File

@@ -47,8 +47,10 @@ CmdItem g_shellcmdAll[] = {
{CMD_TYPE_STD, "date", XARGS, (CmdCallBackFunc)OsShellCmdDate},
{CMD_TYPE_EX, "task", 1, (CmdCallBackFunc)OsShellCmdDumpTask},
{CMD_TYPE_EX, "free", XARGS, (CmdCallBackFunc)OsShellCmdFree},
#ifdef LWIP_SHELLCMD_ENABLE
{CMD_TYPE_EX, "ifconfig", XARGS, (CmdCallBackFunc)lwip_ifconfig},
{CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)OsShellPing},
#endif
{CMD_TYPE_EX, "touch", XARGS, (CmdCallBackFunc)OsShellCmdTouch},
{CMD_TYPE_EX, "ls", XARGS, (CmdCallBackFunc)OsShellCmdLs},
{CMD_TYPE_EX, "pwd", XARGS, (CmdCallBackFunc)OsShellCmdPwd},
@@ -190,7 +192,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

@@ -29,11 +29,20 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "shmsg.h"
#include "securec.h"
#include "shcmd.h"
#include "show.h"
#include "securec.h"
#if (LOSCFG_USE_SHELL == 1)
#include "uart.h"
#endif
#include "los_event.h"
#include "los_task.h"
EVENT_CB_S g_shellInputEvent;
#define SHELL_CMD_MAX_SIZE 64
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType)
{
@@ -60,17 +69,17 @@ UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType)
return OS_INVALID;
}
char *GetCmdName(const char *cmdline, unsigned int len)
CHAR *GetCmdName(const CHAR *cmdline, UINT32 len)
{
unsigned int loop;
const char *tmpStr = NULL;
bool quotes = FALSE;
char *cmdName = NULL;
UINT32 loop;
const CHAR *tmpStr = NULL;
BOOL quotes = FALSE;
CHAR *cmdName = NULL;
if (cmdline == NULL) {
return NULL;
}
cmdName = (char *)malloc(len + 1);
cmdName = (CHAR *)malloc(len + 1);
if (cmdName == NULL) {
PRINTK("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
return NULL;
@@ -78,7 +87,7 @@ char *GetCmdName(const char *cmdline, unsigned int len)
/* Scan the 'cmdline' string for command */
/* Notice: Command string must not have any special name */
for (tmpStr = cmdline, loop = 0; (*tmpStr != '\0') && (loop < len);) {
for (tmpStr = cmdline, loop = 0; (*tmpStr != '\0') && (loop < len); ) {
/* If reach a double quotes, switch the quotes matching status */
if (*tmpStr == '\"') {
SWITCH_QUOTES_STATUS(quotes);
@@ -99,9 +108,9 @@ char *GetCmdName(const char *cmdline, unsigned int len)
return cmdName;
}
int ShellCmdExec(const char *msgName, const char *cmdString)
INT32 ShellCmdExec(const CHAR *msgName, const CHAR *cmdString)
{
unsigned int uintRet;
UINT32 uintRet;
errno_t err;
CmdParsed cmdParsed;
@@ -114,30 +123,31 @@ int ShellCmdExec(const char *msgName, const char *cmdString)
}
uintRet = ShellMsgTypeGet(&cmdParsed, msgName);
if (uintRet != LOS_OK) {
PRINTK("%s:command not found\n", msgName);
return -EFAULT;
} else {
(void)OsCmdExec(&cmdParsed, (char *)cmdString);
(VOID)OsCmdExec(&cmdParsed, (CHAR *)cmdString);
}
return 0;
}
unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *outputlen)
UINT32 PreHandleCmdline(const CHAR *input, CHAR **output, UINT32 *outputlen)
{
unsigned int shiftLen;
unsigned int ret;
const char *cmdBuf = input;
unsigned int cmdBufLen = strlen(cmdBuf);
char *shiftStr = (char *)malloc(cmdBufLen + 1);
UINT32 shiftLen;
UINT32 ret;
const CHAR *cmdBuf = input;
UINT32 cmdBufLen = strlen(cmdBuf);
if ((cmdBufLen + 1) > SHELL_CMD_MAX_SIZE) {
return SH_NOK;
}
CHAR *shiftStr = (CHAR *)malloc(cmdBufLen + 1);
if (shiftStr == NULL) {
PRINTK("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
return SH_NOK;
}
(void)memset_s(shiftStr, cmdBufLen + 1, 0, cmdBufLen + 1);
(VOID)memset_s(shiftStr, cmdBufLen + 1, 0, cmdBufLen + 1);
/* Call function 'OsCmdKeyShift' to squeeze and clear useless or overmuch space if string buffer */
ret = OsCmdKeyShift(cmdBuf, shiftStr, cmdBufLen + 1);
@@ -158,12 +168,12 @@ END:
return ret;
}
static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsigned int len)
static VOID ParseAndExecCmdline(CmdParsed *cmdParsed, const CHAR *cmdline, UINT32 len)
{
int i;
unsigned int ret;
char *cmdlineOrigin = NULL;
char *cmdName = NULL;
INT32 i;
UINT32 ret;
CHAR *cmdlineOrigin = NULL;
CHAR *cmdName = NULL;
cmdlineOrigin = strdup(cmdline);
if (cmdlineOrigin == NULL) {
@@ -178,13 +188,13 @@ static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsig
return;
}
ret = OsCmdParse((char *)cmdline, cmdParsed);
ret = OsCmdParse((CHAR *)cmdline, cmdParsed);
if (ret != SH_OK) {
PRINTK("cmd parse failure in %s[%d]\n", __FUNCTION__, __LINE__);
goto OUT;
}
(void)ShellCmdExec(cmdName, cmdlineOrigin);
(VOID)ShellCmdExec(cmdName, cmdlineOrigin);
OUT:
for (i = 0; i < cmdParsed->paramCnt; i++) {
@@ -197,11 +207,11 @@ OUT:
free(cmdlineOrigin);
}
LITE_OS_SEC_TEXT_MINOR void ExecCmdline(const char *cmdline)
LITE_OS_SEC_TEXT_MINOR VOID ExecCmdline(const CHAR *cmdline)
{
unsigned int ret;
char *output = NULL;
unsigned int outputlen;
UINT32 ret;
CHAR *output = NULL;
UINT32 outputlen;
CmdParsed cmdParsed;
if (cmdline == NULL) {
@@ -216,8 +226,70 @@ LITE_OS_SEC_TEXT_MINOR void ExecCmdline(const char *cmdline)
return;
}
(void)memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));
(VOID)memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));
ParseAndExecCmdline(&cmdParsed, output, outputlen);
free(output);
}
#if (LOSCFG_USE_SHELL == 1)
VOID ShellTaskEntry(VOID)
{
CHAR buf[SHELL_CMD_MAX_SIZE] = {0};
CHAR *ptr = buf;
PRINTK("OHOS # ");
while (1) {
(VOID)LOS_EventRead(&g_shellInputEvent, 0x1, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
while ((*ptr = (UINT8)UartGetc()) != 0 && *ptr != 13) {
if (*ptr == '\x03') { /* ctrl + c */
PRINTK("^C\n\rOHOS # ", *ptr);
ptr = buf;
break;
}
if (!VISIABLE_CHAR(*ptr)) {
break;
}
PRINTK("%c", *ptr);
if ((ptr - buf) == (sizeof(buf) - 1)) {
break;
}
ptr++;
}
if (ptr != buf) {
if (*ptr == 13 || ((ptr - buf) == (sizeof(buf) - 1))) {
*ptr = '\0';
ptr = buf;
PRINTK("\n\r");
ExecCmdline(buf);
PRINTK("OHOS # ");
}
} else if (*ptr == 13) {
PRINTK("\n\rOHOS # ");
}
}
}
LITE_OS_SEC_TEXT_MINOR UINT32 LosShellInit(VOID)
{
UINT32 ret;
UINT32 taskID1, taskID2;
TSK_INIT_PARAM_S task1 = { 0 };
ret = LOS_EventInit(&g_shellInputEvent);
if (ret != LOS_OK) {
PRINTK("Init shellInputEvent failed! ERROR: 0x%x\n", ret);
return ret;
}
task1.pfnTaskEntry = (TSK_ENTRY_FUNC)ShellTaskEntry;
task1.uwStackSize = 0x1000;
task1.pcName = "ShellTaskEntry";
task1.usTaskPrio = LOSCFG_SHELL_PRIO;
ret = LOS_TaskCreate(&taskID1, &task1);
if (ret != LOS_OK) {
PRINTK("Create Shell Task failed! ERROR: 0x%x\n", ret);
return ret;
}
return ret;
}
#endif

View File

@@ -88,11 +88,11 @@ static char *StrNormalizePath(char *fullpath)
while (*src != '\0') {
if (*src == '.') {
if (*(src + 1) == '/') {
src += 2;
src += 2; /* 2, sizeof "./" */
continue;
} else if (*(src + 1) == '.') {
if ((*(src + 2) == '/') || (*(src + 2) == '\0')) {
src += 2;
if ((*(src + 2) == '/') || (*(src + 2) == '\0')) { /* 2, 2, offset to check */
src += 2; /* 2, sizeof offset */
} else {
while ((*src != '\0') && (*src != '/')) {
*dest++ = *src++;
@@ -174,7 +174,7 @@ static char *VfsNotAbsolutePath(const char *directory, const char *filename, cha
/* 2: The position of the path character: / and the end character /0 */
if ((namelen > 1) && (filename[0] == '.') && (filename[1] == '/')) {
filename += 2;
filename += 2; /* 2, sizeof "./" */
}
fullpath = (char *)malloc(strlen(directory) + namelen + 2);
@@ -184,8 +184,7 @@ static char *VfsNotAbsolutePath(const char *directory, const char *filename, cha
return (char *)NULL;
}
/* join path and file name */
/* 2, sizeof "./", join path and file name */
ret = snprintf_s(fullpath, strlen(directory) + namelen + 2, strlen(directory) + namelen + 1,
"%s/%s", directory, filename);
if (ret < 0) {
@@ -213,7 +212,6 @@ static char *VfsNormalizeFullpath(const char *directory, const char *filename, c
/* it's a absolute path, use it directly */
fullpath = strdup(filename); /* copy string */
if (fullpath == NULL) {
*pathname = NULL;
SetErrno(ENOMEM);
@@ -246,8 +244,7 @@ int VfsNormalizePath(const char *directory, const char *filename, char **pathnam
return -EINVAL;
}
/* 2: The position of the path character: / and the end character /0 */
/* 2, The position of the path character: / and the end character /0 */
if ((filename[0] != '/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) {
return -ENAMETOOLONG;
}

View File

@@ -31,6 +31,10 @@
#include "shcmd.h"
#define DEFAULT_SCREEN_WIDTH 80
#define MAX_CMD_KEY_WIDTH 8
#define CMD_ITEM_PER_LINE (DEFAULT_SCREEN_WIDTH / (MAX_CMD_KEY_WIDTH + 1))
INT32 OsShellCmdHelp(INT32 argc, const CHAR **argv)
{
UINT32 loop = 0;
@@ -45,10 +49,10 @@ INT32 OsShellCmdHelp(INT32 argc, const CHAR **argv)
PRINTK("*******************shell commands:*************************\n");
LOS_DL_LIST_FOR_EACH_ENTRY(curCmdItem, &(cmdInfo->cmdList.list), CmdItemNode, list) {
if ((loop & (8 - 1)) == 0) { /* 8 - 1:just align print */
if ((loop % CMD_ITEM_PER_LINE) == 0) { /* just align print */
PRINTK("\n");
}
PRINTK("%-12s ", curCmdItem->cmd->cmdKey);
PRINTK("%-8s ", curCmdItem->cmd->cmdKey);
loop++;
}

View File

@@ -39,37 +39,22 @@
#define OS_INVALID_SEM_ID 0xFFFFFFFF
#define OS_ALL_TASK_MASK 0xFFFFFFFF
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
{
if (taskStatus & OS_TASK_STATUS_RUNNING) {
return (UINT8 *)"Running";
} else if (taskStatus & OS_TASK_STATUS_READY) {
return (UINT8 *)"Ready";
} else {
if (taskStatus & OS_TASK_STATUS_DELAY) {
return (UINT8 *)"Delay";
} else if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
return (UINT8 *)"PendTime";
} else if (taskStatus & OS_TASK_STATUS_PEND) {
return (UINT8 *)"Pend";
} else if (taskStatus & OS_TASK_STATUS_SUSPEND) {
return (UINT8 *)"Suspend";
}
}
return (UINT8 *)"Invalid";
}
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
{
PRINTK("\r\nName TaskEntryAddr TID ");
PRINTK("Name TaskEntryAddr TID ");
PRINTK("Priority Status "
#if (LOSCFG_TASK_MEM_USED == 1)
"AllocSize "
#endif
"StackSize StackPoint TopOfStack");
PRINTK("\n");
PRINTK("---- ------------- --- ");
PRINTK("-------- -------- "
#if (LOSCFG_TASK_MEM_USED == 1)
"--------- "
#endif
"--------- ---------- ----------");
PRINTK("\n");
}
@@ -89,7 +74,17 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
UINT32 semId;
#if (LOSCFG_TASK_MEM_USED == 1)
UINT32 arraySize = sizeof(UINT32) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1);
UINT32 *getUsedSizeArray = (UINT32 *)LOS_MemAlloc(m_aucSysMem0, arraySize);
if (getUsedSizeArray == NULL) {
PRINTK("Memory is not enough to save task info!\n");
return;
}
(VOID)memset_s(getUsedSizeArray, arraySize, 0, arraySize);
OsTaskMemUsed(m_aucSysMem0, getUsedSizeArray, (LOSCFG_BASE_CORE_TSK_LIMIT + 1));
#endif
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
@@ -97,14 +92,21 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
continue;
}
semId = OsGetSemID(taskCB);
PRINTK("%-23s%-20p0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskID);
#if (LOSCFG_TASK_MEM_USED == 1)
PRINTK("%-11u%-13s0x%-11x 0x%-11x 0x%-8x 0x%-10x ", taskCB->priority,
OsConvertTskStatus(taskCB->taskStatus), getUsedSizeArray[loop], taskCB->stackSize,
taskCB->stackPointer, taskCB->topOfStack);
#else
PRINTK("%-11u%-13s0x%-11x 0x%-8x 0x%-10x ", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
taskCB->stackPointer, taskCB->topOfStack, semId);
OsConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
taskCB->stackPointer, taskCB->topOfStack);
#endif
PRINTK("\n");
}
#if (LOSCFG_TASK_MEM_USED == 1)
(VOID)LOS_MemFree(m_aucSysMem0, getUsedSizeArray);
#endif
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)

View File

@@ -276,6 +276,7 @@ int OsShellCmdCat(int argc, const char **argv)
if (fd == -1) {
ret = -1;
free(fullpath);
return ret;
}
@@ -522,7 +523,10 @@ static int OsShellCmdDoRmdir(const char *pathname)
char *fullpath = NULL;
int ret;
(void)memset_s(&statInfo, sizeof(statInfo), 0, sizeof(struct stat));
ret = memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
if (ret != 0) {
return -1;
}
if (stat(pathname, &statInfo) != 0) {
return -1;
}

50
components/trace/BUILD.gn Normal file
View File

@@ -0,0 +1,50 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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/config.gni")
static_library("trace") {
sources = [
"cnv/trace_cnv.c",
"los_trace.c",
"pipeline/serial/trace_pipeline_serial.c",
"pipeline/trace_pipeline.c",
"pipeline/trace_tlv.c",
"trace_offline.c",
"trace_online.c",
]
include_dirs = [
"./",
"cnv",
"pipeline",
"pipeline/serial",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -0,0 +1,272 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 "trace_cnv.h"
#include "los_trace.h"
#include "los_task.h"
#include "los_sem.h"
#include "los_mux.h"
#include "los_queue.h"
#include "los_event.h"
#include "los_swtmr.h"
#include "los_hook.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
STATIC VOID LOS_TraceMemInit(VOID *pool, UINT32 size)
{
LOS_TRACE(MEM_INFO_REQ, pool);
}
STATIC VOID LOS_TraceMemAlloc(VOID *pool, VOID *ptr, UINT32 size)
{
LOS_TRACE(MEM_ALLOC, pool, (UINTPTR)ptr, size);
}
STATIC VOID LOS_TraceMemFree(VOID *pool, VOID *ptr)
{
LOS_TRACE(MEM_FREE, pool, (UINTPTR)ptr);
}
STATIC VOID LOS_TraceMemRealloc(VOID *pool, VOID *ptr, UINT32 size)
{
LOS_TRACE(MEM_REALLOC, pool, (UINTPTR)ptr, size);
}
STATIC VOID LOS_TraceMemAllocAlign(VOID *pool, VOID *ptr, UINT32 size, UINT32 boundary)
{
LOS_TRACE(MEM_ALLOC_ALIGN, pool, (UINTPTR)ptr, size, boundary);
}
STATIC VOID LOS_TraceEventInit(PEVENT_CB_S eventCB)
{
LOS_TRACE(EVENT_CREATE, (UINTPTR)eventCB);
}
STATIC VOID LOS_TraceEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
{
LOS_TRACE(EVENT_READ, (UINTPTR)eventCB, eventCB->uwEventID, eventMask, mode, timeout);
}
STATIC VOID LOS_TraceEventWrite(PEVENT_CB_S eventCB, UINT32 events)
{
LOS_TRACE(EVENT_WRITE, (UINTPTR)eventCB, eventCB->uwEventID, events);
}
STATIC VOID LOS_TraceEventClear(PEVENT_CB_S eventCB, UINT32 events)
{
LOS_TRACE(EVENT_CLEAR, (UINTPTR)eventCB, eventCB->uwEventID, events);
}
STATIC VOID LOS_TraceEventDestroy(PEVENT_CB_S eventCB)
{
LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, LOS_OK);
}
STATIC VOID LOS_TraceQueueCreate(const LosQueueCB *queueCB)
{
LOS_TRACE(QUEUE_CREATE, queueCB->queueID, queueCB->queueLen, queueCB->queueSize - sizeof(UINT32),
(UINTPTR)queueCB, 0);
}
STATIC VOID LOS_TraceQueueRW(const LosQueueCB *queueCB, UINT32 operateType,
UINT32 bufferSize, UINT32 timeout)
{
LOS_TRACE(QUEUE_RW, queueCB->queueID, queueCB->queueSize, bufferSize, operateType,
queueCB->readWriteableCnt[OS_QUEUE_READ], queueCB->readWriteableCnt[OS_QUEUE_WRITE], timeout);
}
STATIC VOID LOS_TraceQueueDelete(const LosQueueCB *queueCB)
{
LOS_TRACE(QUEUE_DELETE, queueCB->queueID, queueCB->queueState, queueCB->readWriteableCnt[OS_QUEUE_READ]);
}
STATIC VOID LOS_TraceSemCreate(const LosSemCB *semCB)
{
LOS_TRACE(SEM_CREATE, semCB->semID, 0, semCB->semCount);
}
STATIC VOID LOS_TraceSemPost(const LosSemCB *semCB, const LosTaskCB *resumedTask)
{
(VOID)resumedTask;
LOS_TRACE(SEM_POST, semCB->semID, 0, semCB->semCount);
}
STATIC VOID LOS_TraceSemPend(const LosSemCB *semCB, const LosTaskCB *runningTask, UINT32 timeout)
{
(VOID)runningTask;
LOS_TRACE(SEM_PEND, semCB->semID, semCB->semCount, timeout);
}
STATIC VOID LOS_TraceSemDelete(const LosSemCB *semCB)
{
LOS_TRACE(SEM_DELETE, semCB->semID, LOS_OK);
}
STATIC VOID LOS_TraceMuxCreate(const LosMuxCB *muxCB)
{
LOS_TRACE(MUX_CREATE, muxCB->muxID);
}
STATIC VOID LOS_TraceMuxPost(const LosMuxCB *muxCB)
{
LOS_TRACE(MUX_POST, muxCB->muxID, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID);
}
STATIC VOID LOS_TraceMuxPend(const LosMuxCB *muxCB, UINT32 timeout)
{
LOS_TRACE(MUX_PEND, muxCB->muxID, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID, timeout);
}
STATIC VOID LOS_TraceMuxDelete(const LosMuxCB *muxCB)
{
LOS_TRACE(MUX_DELETE, muxCB->muxID, muxCB->muxStat, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID);
}
STATIC VOID LOS_TraceTaskCreate(const LosTaskCB *taskCB)
{
LOS_TRACE(TASK_CREATE, taskCB->taskID, taskCB->taskStatus, taskCB->priority);
}
STATIC VOID LOS_TraceTaskPriModify(const LosTaskCB *taskCB, UINT32 prio)
{
LOS_TRACE(TASK_PRIOSET, taskCB->taskID, taskCB->taskStatus, taskCB->priority, prio);
}
STATIC VOID LOS_TraceTaskDelete(const LosTaskCB *taskCB)
{
LOS_TRACE(TASK_DELETE, taskCB->taskID, taskCB->taskStatus, (UINTPTR)taskCB->stackPointer);
}
STATIC VOID LOS_TraceTaskSwitchedIn(VOID)
{
LosTaskCB *newTask = g_losTask.newTask;
LosTaskCB *runTask = g_losTask.runTask;
LOS_TRACE(TASK_SWITCH, newTask->taskID, runTask->priority, runTask->taskStatus,
newTask->priority, newTask->taskStatus);
}
STATIC VOID LOS_TraceTaskResume(const LosTaskCB *taskCB)
{
LOS_TRACE(TASK_RESUME, taskCB->taskID, taskCB->taskStatus, taskCB->priority);
}
STATIC VOID LOS_TraceTaskSuspend(const LosTaskCB *taskCB)
{
LOS_TRACE(TASK_SUSPEND, taskCB->taskID, taskCB->taskStatus, g_losTask.runTask->taskID);
}
STATIC VOID LOS_TraceIsrEnter(UINT32 hwiNum)
{
LOS_TRACE(HWI_RESPONSE_IN, hwiNum);
}
STATIC VOID LOS_TraceIsrExit(UINT32 hwiNum)
{
LOS_TRACE(HWI_RESPONSE_OUT, hwiNum);
}
STATIC VOID LOS_TraceSwtmrCreate(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_CREATE, swtmr->usTimerID);
}
STATIC VOID LOS_TraceSwtmrDelete(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_DELETE, swtmr->usTimerID);
}
STATIC VOID LOS_TraceSwtmrExpired(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_EXPIRED, swtmr->usTimerID);
}
STATIC VOID LOS_TraceSwtmrStart(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwInterval);
}
STATIC VOID LOS_TraceSwtmrStop(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_STOP, swtmr->usTimerID);
}
VOID OsTraceCnvInit(VOID)
{
LOS_HookReg(LOS_HOOK_TYPE_MEM_ALLOC, LOS_TraceMemAlloc);
LOS_HookReg(LOS_HOOK_TYPE_MEM_FREE, LOS_TraceMemFree);
LOS_HookReg(LOS_HOOK_TYPE_MEM_INIT, LOS_TraceMemInit);
LOS_HookReg(LOS_HOOK_TYPE_MEM_REALLOC, LOS_TraceMemRealloc);
LOS_HookReg(LOS_HOOK_TYPE_MEM_ALLOCALIGN, LOS_TraceMemAllocAlign);
LOS_HookReg(LOS_HOOK_TYPE_EVENT_INIT, LOS_TraceEventInit);
LOS_HookReg(LOS_HOOK_TYPE_EVENT_READ, LOS_TraceEventRead);
LOS_HookReg(LOS_HOOK_TYPE_EVENT_WRITE, LOS_TraceEventWrite);
LOS_HookReg(LOS_HOOK_TYPE_EVENT_CLEAR, LOS_TraceEventClear);
LOS_HookReg(LOS_HOOK_TYPE_EVENT_DESTROY, LOS_TraceEventDestroy);
LOS_HookReg(LOS_HOOK_TYPE_QUEUE_CREATE, LOS_TraceQueueCreate);
LOS_HookReg(LOS_HOOK_TYPE_QUEUE_DELETE, LOS_TraceQueueDelete);
LOS_HookReg(LOS_HOOK_TYPE_QUEUE_READ, LOS_TraceQueueRW);
LOS_HookReg(LOS_HOOK_TYPE_QUEUE_WRITE, LOS_TraceQueueRW);
LOS_HookReg(LOS_HOOK_TYPE_SEM_CREATE, LOS_TraceSemCreate);
LOS_HookReg(LOS_HOOK_TYPE_SEM_DELETE, LOS_TraceSemDelete);
LOS_HookReg(LOS_HOOK_TYPE_SEM_POST, LOS_TraceSemPost);
LOS_HookReg(LOS_HOOK_TYPE_SEM_PEND, LOS_TraceSemPend);
LOS_HookReg(LOS_HOOK_TYPE_MUX_CREATE, LOS_TraceMuxCreate);
LOS_HookReg(LOS_HOOK_TYPE_MUX_POST, LOS_TraceMuxPost);
LOS_HookReg(LOS_HOOK_TYPE_MUX_PEND, LOS_TraceMuxPend);
LOS_HookReg(LOS_HOOK_TYPE_MUX_DELETE, LOS_TraceMuxDelete);
LOS_HookReg(LOS_HOOK_TYPE_TASK_PRIMODIFY, LOS_TraceTaskPriModify);
LOS_HookReg(LOS_HOOK_TYPE_TASK_DELETE, LOS_TraceTaskDelete);
LOS_HookReg(LOS_HOOK_TYPE_TASK_CREATE, LOS_TraceTaskCreate);
LOS_HookReg(LOS_HOOK_TYPE_TASK_SWITCHEDIN, LOS_TraceTaskSwitchedIn);
LOS_HookReg(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, LOS_TraceTaskResume);
LOS_HookReg(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, LOS_TraceTaskSuspend);
LOS_HookReg(LOS_HOOK_TYPE_ISR_ENTER, LOS_TraceIsrEnter);
LOS_HookReg(LOS_HOOK_TYPE_ISR_EXIT, LOS_TraceIsrExit);
LOS_HookReg(LOS_HOOK_TYPE_SWTMR_CREATE, LOS_TraceSwtmrCreate);
LOS_HookReg(LOS_HOOK_TYPE_SWTMR_DELETE, LOS_TraceSwtmrDelete);
LOS_HookReg(LOS_HOOK_TYPE_SWTMR_EXPIRED, LOS_TraceSwtmrExpired);
LOS_HookReg(LOS_HOOK_TYPE_SWTMR_START, LOS_TraceSwtmrStart);
LOS_HookReg(LOS_HOOK_TYPE_SWTMR_STOP, LOS_TraceSwtmrStop);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 _TRACE_CNV_H
#define _TRACE_CNV_H
#include "stdarg.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern VOID OsTraceCnvInit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TRACE_CNV_H */

View File

@@ -0,0 +1,434 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_trace_pri.h"
#include "trace_pipeline.h"
#include "los_memory.h"
#include "los_config.h"
#include "securec.h"
#include "trace_cnv.h"
#if (LOSCFG_KERNEL_SMP == 1)
#include "los_mp_pri.h"
#endif
#if (LOSCFG_SHELL == 1)
#include "shcmd.h"
#include "shell.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_KERNEL_TRACE == 1)
LITE_OS_SEC_BSS STATIC UINT32 g_traceEventCount;
LITE_OS_SEC_BSS STATIC volatile enum TraceState g_traceState = TRACE_UNINIT;
LITE_OS_SEC_DATA_INIT STATIC volatile BOOL g_enableTrace = FALSE;
LITE_OS_SEC_BSS STATIC UINT32 g_traceMask = TRACE_DEFAULT_MASK;
TRACE_EVENT_HOOK g_traceEventHook = NULL;
TRACE_DUMP_HOOK g_traceDumpHook = NULL;
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
LITE_OS_SEC_BSS STATIC UINT32 g_traceTaskId;
#endif
#define EVENT_MASK 0xFFFFFFF0
#define MIN(x, y) ((x) < (y) ? (x) : (y))
LITE_OS_SEC_BSS STATIC TRACE_HWI_FILTER_HOOK g_traceHwiFliterHook = NULL;
#if (LOSCFG_KERNEL_SMP == 1)
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_traceSpin);
#endif
STATIC_INLINE BOOL OsTraceHwiFilter(UINT32 hwiNum)
{
BOOL ret = ((hwiNum == NUM_HAL_INTERRUPT_UART) || (hwiNum == OS_TICK_INT_NUM));
#if (LOSCFG_KERNEL_SMP == 1)
ret |= (hwiNum == LOS_MP_IPI_SCHEDULE);
#endif
if (g_traceHwiFliterHook != NULL) {
ret |= g_traceHwiFliterHook(hwiNum);
}
return ret;
}
STATIC VOID OsTraceSetFrame(TraceEventFrame *frame, UINT32 eventType, UINTPTR identity, const UINTPTR *params,
UINT16 paramCount)
{
INT32 i;
UINT32 intSave;
(VOID)memset_s(frame, sizeof(TraceEventFrame), 0, sizeof(TraceEventFrame));
if (paramCount > LOSCFG_TRACE_FRAME_MAX_PARAMS) {
paramCount = LOSCFG_TRACE_FRAME_MAX_PARAMS;
}
TRACE_LOCK(intSave);
frame->curTask = OsTraceGetMaskTid(LOS_CurTaskIDGet());
frame->identity = identity;
frame->curTime = LOS_SysCycleGet();
frame->eventType = eventType;
#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
frame->core.cpuId = ArchCurrCpuid();
frame->core.hwiActive = OS_INT_ACTIVE ? TRUE : FALSE;
frame->core.taskLockCnt = MIN(OsPercpuGet()->taskLockCnt, 0xF); /* taskLockCnt is 4 bits, max vaule = 0xF */
frame->core.paramCount = paramCount;
#endif
#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
frame->eventCount = g_traceEventCount;
g_traceEventCount++;
#endif
TRACE_UNLOCK(intSave);
for (i = 0; i < paramCount; i++) {
frame->params[i] = params[i];
}
}
VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb)
{
errno_t ret;
(VOID)memset_s(obj, sizeof(ObjData), 0, sizeof(ObjData));
obj->id = OsTraceGetMaskTid(tcb->taskID);
obj->prio = tcb->priority;
ret = strncpy_s(obj->name, LOSCFG_TRACE_OBJ_MAX_NAME_SIZE, tcb->taskName, LOSCFG_TRACE_OBJ_MAX_NAME_SIZE - 1);
if (ret != EOK) {
TRACE_ERROR("Task name copy failed!\n");
}
}
VOID OsTraceHook(UINT32 eventType, UINTPTR identity, const UINTPTR *params, UINT16 paramCount)
{
if ((eventType == TASK_CREATE) || (eventType == TASK_PRIOSET)) {
OsTraceObjAdd(eventType, identity); /* handle important obj info, these can not be filtered */
}
if ((g_enableTrace == TRUE) && (eventType & g_traceMask)) {
UINTPTR id = identity;
if (TRACE_GET_MODE_FLAG(eventType) == TRACE_HWI_FLAG) {
if (OsTraceHwiFilter(identity)) {
return;
}
} else if (TRACE_GET_MODE_FLAG(eventType) == TRACE_TASK_FLAG) {
id = OsTraceGetMaskTid(identity);
} else if (eventType == MEM_INFO_REQ) {
LOS_MEM_POOL_STATUS status;
LOS_MemInfoGet((VOID *)identity, &status);
LOS_TRACE(MEM_INFO, identity, status.totalUsedSize, status.totalFreeSize);
return;
}
TraceEventFrame frame;
OsTraceSetFrame(&frame, eventType, id, params, paramCount);
OsTraceWriteOrSendEvent(&frame);
}
}
BOOL OsTraceIsEnable(VOID)
{
return g_enableTrace == TRUE;
}
STATIC VOID OsTraceHookInstall(VOID)
{
g_traceEventHook = OsTraceHook;
#if (LOSCFG_RECORDER_MODE_OFFLINE == 1)
g_traceDumpHook = OsTraceRecordDump;
#endif
}
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
STATIC BOOL OsTraceCmdIsValid(const TraceClientCmd *msg)
{
return ((msg->end == TRACE_CMD_END_CHAR) && (msg->cmd < TRACE_CMD_MAX_CODE));
}
STATIC VOID OsTraceCmdHandle(const TraceClientCmd *msg)
{
if (!OsTraceCmdIsValid(msg)) {
return;
}
switch (msg->cmd) {
case TRACE_CMD_START:
LOS_TraceStart();
break;
case TRACE_CMD_STOP:
LOS_TraceStop();
break;
case TRACE_CMD_SET_EVENT_MASK:
/* 4 params(UINT8) composition the mask(UINT32) */
LOS_TraceEventMaskSet(TRACE_MASK_COMBINE(msg->param1, msg->param2, msg->param3, msg->param4));
break;
case TRACE_CMD_RECODE_DUMP:
LOS_TraceRecordDump(TRUE);
break;
default:
break;
}
}
VOID TraceAgent(VOID)
{
UINT32 ret;
TraceClientCmd msg;
while (1) {
(VOID)memset_s(&msg, sizeof(TraceClientCmd), 0, sizeof(TraceClientCmd));
ret = OsTraceDataWait();
if (ret == LOS_OK) {
OsTraceDataRecv((UINT8 *)&msg, sizeof(TraceClientCmd), 0);
OsTraceCmdHandle(&msg);
}
}
}
STATIC UINT32 OsCreateTraceAgentTask(VOID)
{
UINT32 ret;
TSK_INIT_PARAM_S taskInitParam;
(VOID)memset_s((VOID *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TraceAgent;
taskInitParam.usTaskPrio = LOSCFG_TRACE_TASK_PRIORITY;
taskInitParam.pcName = "TraceAgent";
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
#if (LOSCFG_KERNEL_SMP == 1)
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
ret = LOS_TaskCreate(&g_traceTaskId, &taskInitParam);
return ret;
}
#endif
UINT32 OsTraceInit(VOID)
{
UINT32 intSave;
UINT32 ret;
TRACE_LOCK(intSave);
if (g_traceState != TRACE_UNINIT) {
TRACE_ERROR("trace has been initialized already, the current state is :%d\n", g_traceState);
ret = LOS_ERRNO_TRACE_ERROR_STATUS;
goto LOS_ERREND;
}
#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
ret = OsTracePipelineInit();
if (ret != LOS_OK) {
goto LOS_ERREND;
}
#endif
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
ret = OsCreateTraceAgentTask();
if (ret != LOS_OK) {
TRACE_ERROR("trace init create agentTask error :0x%x\n", ret);
goto LOS_ERREND;
}
#endif
#if (LOSCFG_RECORDER_MODE_OFFLINE == 1)
ret = OsTraceBufInit(LOSCFG_TRACE_BUFFER_SIZE);
if (ret != LOS_OK) {
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
(VOID)LOS_TaskDelete(g_traceTaskId);
#endif
goto LOS_ERREND;
}
#endif
OsTraceHookInstall();
OsTraceCnvInit();
g_traceEventCount = 0;
#if (LOSCFG_RECORDER_MODE_ONLINE == 1) /* Wait trace client to start trace */
g_enableTrace = FALSE;
g_traceState = TRACE_INITED;
#else
g_enableTrace = TRUE;
g_traceState = TRACE_STARTED;
#endif
TRACE_UNLOCK(intSave);
return LOS_OK;
LOS_ERREND:
TRACE_UNLOCK(intSave);
return ret;
}
UINT32 LOS_TraceStart(VOID)
{
UINT32 intSave;
UINT32 ret = LOS_OK;
TRACE_LOCK(intSave);
if (g_traceState == TRACE_STARTED) {
goto START_END;
}
if (g_traceState == TRACE_UNINIT) {
TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n");
ret = LOS_ERRNO_TRACE_ERROR_STATUS;
goto START_END;
}
OsTraceNotifyStart();
g_enableTrace = TRUE;
g_traceState = TRACE_STARTED;
TRACE_UNLOCK(intSave);
LOS_TRACE(MEM_INFO_REQ, m_aucSysMem0);
return ret;
START_END:
TRACE_UNLOCK(intSave);
return ret;
}
VOID LOS_TraceStop(VOID)
{
UINT32 intSave;
TRACE_LOCK(intSave);
if (g_traceState != TRACE_STARTED) {
goto STOP_END;
}
g_enableTrace = FALSE;
g_traceState = TRACE_STOPED;
OsTraceNotifyStop();
STOP_END:
TRACE_UNLOCK(intSave);
}
VOID LOS_TraceEventMaskSet(UINT32 mask)
{
g_traceMask = mask & EVENT_MASK;
}
VOID LOS_TraceRecordDump(BOOL toClient)
{
if (g_traceState != TRACE_STOPED) {
TRACE_ERROR("trace dump must after trace stopped , the current state is : %d\n", g_traceState);
return;
}
OsTraceRecordDump(toClient);
}
OfflineHead *LOS_TraceRecordGet(VOID)
{
return OsTraceRecordGet();
}
VOID LOS_TraceReset(VOID)
{
if (g_traceState == TRACE_UNINIT) {
TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n");
return;
}
OsTraceReset();
}
VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook)
{
UINT32 intSave;
TRACE_LOCK(intSave);
g_traceHwiFliterHook = hook;
TRACE_UNLOCK(intSave);
}
#if (LOSCFG_SHELL == 1)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceSetMask(INT32 argc, const CHAR **argv)
{
size_t mask;
CHAR *endPtr = NULL;
if (argc >= 2) { /* 2:Just as number of parameters */
PRINTK("\nUsage: trace_mask or trace_mask ID\n");
return OS_ERROR;
}
if (argc == 0) {
mask = TRACE_DEFAULT_MASK;
} else {
mask = strtoul(argv[0], &endPtr, 0);
}
LOS_TraceEventMaskSet((UINT32)mask);
return LOS_OK;
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceDump(INT32 argc, const CHAR **argv)
{
BOOL toClient;
CHAR *endPtr = NULL;
if (argc >= 2) { /* 2:Just as number of parameters */
PRINTK("\nUsage: trace_dump or trace_dump [1/0]\n");
return OS_ERROR;
}
if (argc == 0) {
toClient = FALSE;
} else {
toClient = strtoul(argv[0], &endPtr, 0) != 0 ? TRUE : FALSE;
}
LOS_TraceRecordDump(toClient);
return LOS_OK;
}
SHELLCMD_ENTRY(tracestart_shellcmd, CMD_TYPE_EX, "trace_start", 0, (CmdCallBackFunc)LOS_TraceStart);
SHELLCMD_ENTRY(tracestop_shellcmd, CMD_TYPE_EX, "trace_stop", 0, (CmdCallBackFunc)LOS_TraceStop);
SHELLCMD_ENTRY(tracesetmask_shellcmd, CMD_TYPE_EX, "trace_mask", 1, (CmdCallBackFunc)OsShellCmdTraceSetMask);
SHELLCMD_ENTRY(tracereset_shellcmd, CMD_TYPE_EX, "trace_reset", 0, (CmdCallBackFunc)LOS_TraceReset);
SHELLCMD_ENTRY(tracedump_shellcmd, CMD_TYPE_EX, "trace_dump", 1, (CmdCallBackFunc)OsShellCmdTraceDump);
#endif
#endif /* LOSCFG_KERNEL_TRACE == 1 */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,590 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup los_trace Trace
* @ingroup kernel
*/
#ifndef _LOS_TRACE_H
#define _LOS_TRACE_H
#include "los_task.h"
#include "trace_cnv.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
/**
* @ingroup los_trace
* Trace Control agent task's priority.
*/
#define LOSCFG_TRACE_TASK_PRIORITY 2
#endif
#define LOSCFG_TRACE_OBJ_MAX_NAME_SIZE LOS_TASK_NAMELEN
/**
* @ingroup los_trace
* Trace records the max number of objects(kernel object, like tasks), range is [0, LOSCFG_BASE_CORE_TSK_LIMIT].
* if set to 0, trace will not record any object.
*/
#define LOSCFG_TRACE_OBJ_MAX_NUM 0
/**
* @ingroup los_trace
* Trace tlv encode buffer size, the buffer is used to encode one piece raw frame to tlv message in online mode.
*/
#define LOSCFG_TRACE_TLV_BUF_SIZE 100
/**
* @ingroup los_trace
* Trace error code: init trace failed.
*
* Value: 0x02001400
*
* Solution: Follow the trace State Machine.
*/
#define LOS_ERRNO_TRACE_ERROR_STATUS LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
/**
* @ingroup los_trace
* Trace error code: Insufficient memory for trace buf init.
*
* Value: 0x02001401
*
* Solution: Expand the configured system memory or decrease the value defined by LOS_TRACE_BUFFER_SIZE.
*/
#define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
/**
* @ingroup los_trace
* Trace error code: Insufficient memory for trace struct.
*
* Value: 0x02001402
*
* Solution: Increase trace buffer's size.
*/
#define LOS_ERRNO_TRACE_BUF_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
/**
* @ingroup los_trace
* Trace state.
*/
enum TraceState {
TRACE_UNINIT = 0, /**< trace isn't inited */
TRACE_INITED, /**< trace is inited but not started yet */
TRACE_STARTED, /**< trace is started and system is tracing */
TRACE_STOPED, /**< trace is stopped */
};
/**
* @ingroup los_trace
* Trace mask is used to filter events in runtime. Each mask keep only one unique bit to 1, and user can define own
* module's trace mask.
*/
typedef enum {
TRACE_SYS_FLAG = 0x10,
TRACE_HWI_FLAG = 0x20,
TRACE_TASK_FLAG = 0x40,
TRACE_SWTMR_FLAG = 0x80,
TRACE_MEM_FLAG = 0x100,
TRACE_QUE_FLAG = 0x200,
TRACE_EVENT_FLAG = 0x400,
TRACE_SEM_FLAG = 0x800,
TRACE_MUX_FLAG = 0x1000,
TRACE_MAX_FLAG = 0x80000000,
TRACE_USER_DEFAULT_FLAG = 0xFFFFFFF0,
} LOS_TRACE_MASK;
/**
* @ingroup los_trace
* Trace event type which indicate the exactly happend events, user can define own module's event type like
* TRACE_#MODULE#_FLAG | NUMBER.
* 28 4
* 0 0 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0
* | | |
* trace_module_flag number
*
*/
typedef enum {
/* 0x10~0x1F */
SYS_ERROR = TRACE_SYS_FLAG | 0,
SYS_START = TRACE_SYS_FLAG | 1,
SYS_STOP = TRACE_SYS_FLAG | 2,
/* 0x20~0x2F */
HWI_CREATE = TRACE_HWI_FLAG | 0,
HWI_CREATE_SHARE = TRACE_HWI_FLAG | 1,
HWI_DELETE = TRACE_HWI_FLAG | 2,
HWI_DELETE_SHARE = TRACE_HWI_FLAG | 3,
HWI_RESPONSE_IN = TRACE_HWI_FLAG | 4,
HWI_RESPONSE_OUT = TRACE_HWI_FLAG | 5,
HWI_ENABLE = TRACE_HWI_FLAG | 6,
HWI_DISABLE = TRACE_HWI_FLAG | 7,
HWI_TRIGGER = TRACE_HWI_FLAG | 8,
HWI_SETPRI = TRACE_HWI_FLAG | 9,
HWI_CLEAR = TRACE_HWI_FLAG | 10,
HWI_SETAFFINITY = TRACE_HWI_FLAG | 11,
HWI_SENDIPI = TRACE_HWI_FLAG | 12,
/* 0x40~0x4F */
TASK_CREATE = TRACE_TASK_FLAG | 0,
TASK_PRIOSET = TRACE_TASK_FLAG | 1,
TASK_DELETE = TRACE_TASK_FLAG | 2,
TASK_SUSPEND = TRACE_TASK_FLAG | 3,
TASK_RESUME = TRACE_TASK_FLAG | 4,
TASK_SWITCH = TRACE_TASK_FLAG | 5,
TASK_SIGNAL = TRACE_TASK_FLAG | 6,
/* 0x80~0x8F */
SWTMR_CREATE = TRACE_SWTMR_FLAG | 0,
SWTMR_DELETE = TRACE_SWTMR_FLAG | 1,
SWTMR_START = TRACE_SWTMR_FLAG | 2,
SWTMR_STOP = TRACE_SWTMR_FLAG | 3,
SWTMR_EXPIRED = TRACE_SWTMR_FLAG | 4,
/* 0x100~0x10F */
MEM_ALLOC = TRACE_MEM_FLAG | 0,
MEM_ALLOC_ALIGN = TRACE_MEM_FLAG | 1,
MEM_REALLOC = TRACE_MEM_FLAG | 2,
MEM_FREE = TRACE_MEM_FLAG | 3,
MEM_INFO_REQ = TRACE_MEM_FLAG | 4,
MEM_INFO = TRACE_MEM_FLAG | 5,
/* 0x200~0x20F */
QUEUE_CREATE = TRACE_QUE_FLAG | 0,
QUEUE_DELETE = TRACE_QUE_FLAG | 1,
QUEUE_RW = TRACE_QUE_FLAG | 2,
/* 0x400~0x40F */
EVENT_CREATE = TRACE_EVENT_FLAG | 0,
EVENT_DELETE = TRACE_EVENT_FLAG | 1,
EVENT_READ = TRACE_EVENT_FLAG | 2,
EVENT_WRITE = TRACE_EVENT_FLAG | 3,
EVENT_CLEAR = TRACE_EVENT_FLAG | 4,
/* 0x800~0x80F */
SEM_CREATE = TRACE_SEM_FLAG | 0,
SEM_DELETE = TRACE_SEM_FLAG | 1,
SEM_PEND = TRACE_SEM_FLAG | 2,
SEM_POST = TRACE_SEM_FLAG | 3,
/* 0x1000~0x100F */
MUX_CREATE = TRACE_MUX_FLAG | 0,
MUX_DELETE = TRACE_MUX_FLAG | 1,
MUX_PEND = TRACE_MUX_FLAG | 2,
MUX_POST = TRACE_MUX_FLAG | 3,
} LOS_TRACE_TYPE;
/**
* @ingroup los_trace
* struct to store the trace config information.
*/
typedef struct {
UINT32 bigLittleEndian; /**< big little endian flag */
UINT32 clockFreq; /**< system clock frequency */
UINT32 version; /**< trace version */
} TraceBaseHeaderInfo;
/**
* @ingroup los_trace
* struct to store the event infomation
*/
typedef struct {
UINT32 eventType; /**< event type */
UINT32 curTask; /**< current running task */
UINT64 curTime; /**< current timestamp */
UINTPTR identity; /**< subject of the event description */
#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
struct CoreStatus {
UINT32 cpuId : 8, /**< cpuid */
hwiActive : 4, /**< whether is in hwi response */
taskLockCnt : 4, /**< task lock count */
paramCount : 4, /**< event frame params' number */
reserves : 12; /**< reserves */
} core;
#endif
#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
UINT32 eventCount; /**< the sequence of happend events */
#endif
UINTPTR params[LOSCFG_TRACE_FRAME_MAX_PARAMS]; /**< event frame's params */
} TraceEventFrame;
/**
* @ingroup los_trace
* struct to store the kernel obj information, we defined task as kernel obj in this system.
*/
typedef struct {
UINT32 id; /**< kernel obj's id */
UINT32 prio; /**< kernel obj's priority */
CHAR name[LOSCFG_TRACE_OBJ_MAX_NAME_SIZE]; /**< kernel obj's name */
} ObjData;
/**
* @ingroup los_trace
* struct to store the trace data.
*/
typedef struct {
TraceBaseHeaderInfo baseInfo; /**< basic info, include bigLittleEndian flag, system clock freq */
UINT16 totalLen; /**< trace data's total length */
UINT16 objSize; /**< sizeof #ObjData */
UINT16 frameSize; /**< sizeof #TraceEventFrame */
UINT16 objOffset; /**< the offset of the first obj data to record beginning */
UINT16 frameOffset; /**< the offset of the first event frame data to record beginning */
} OfflineHead;
/**
* @ingroup los_trace
* @brief Define the type of trace hardware interrupt filter hook function.
*
* @par Description:
* User can register fliter function by LOS_TraceHwiFilterHookReg to filter hardware interrupt events. Return true if
* user don't need trace the certain number.
*
* @attention
* None.
*
* @param hwiNum [IN] Type #UINT32. The hardware interrupt number.
* @retval #TRUE 0x00000001: Not record the certain number.
* @retval #FALSE 0x00000000: Need record the certain number.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
*/
typedef BOOL (*TRACE_HWI_FILTER_HOOK)(UINT32 hwiNum);
typedef VOID (*TRACE_EVENT_HOOK)(UINT32 eventType, UINTPTR identity, const UINTPTR *params, UINT16 paramCount);
extern TRACE_EVENT_HOOK g_traceEventHook;
/**
* @ingroup los_trace
* Trace event params:
1. Configure the macro without parameters so as not to record events of this type;
2. Configure the macro at least with one parameter to record this type of event;
3. User can delete unnecessary parameters which defined in corresponding marco;
* @attention
* <ul>
* <li>The first param is treat as key, keep at least this param if you want trace this event.</li>
* <li>All parameters were treated as UINTPTR.</li>
* </ul>
* eg. Trace a event as:
* #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
* eg. Not Trace a event as:
* #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio)
* eg. Trace only you need parmas as:
* #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId
*/
#define TASK_SWITCH_PARAMS(taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus) \
taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus
#define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
#define TASK_CREATE_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
#define TASK_DELETE_PARAMS(taskId, taskStatus, usrStack) taskId, taskStatus, usrStack
#define TASK_SUSPEND_PARAMS(taskId, taskStatus, runTaskId) taskId, taskStatus, runTaskId
#define TASK_RESUME_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
#define TASK_SIGNAL_PARAMS(taskId, signal, schedFlag) // taskId, signal, schedFlag
#define SWTMR_START_PARAMS(swtmrId, mode, interval) swtmrId, mode, interval
#define SWTMR_DELETE_PARAMS(swtmrId) swtmrId
#define SWTMR_EXPIRED_PARAMS(swtmrId) swtmrId
#define SWTMR_STOP_PARAMS(swtmrId) swtmrId
#define SWTMR_CREATE_PARAMS(swtmrId) swtmrId
#define HWI_CREATE_PARAMS(hwiNum, hwiPrio, hwiMode, hwiHandler) hwiNum, hwiPrio, hwiMode, hwiHandler
#define HWI_CREATE_SHARE_PARAMS(hwiNum, pDevId, ret) hwiNum, pDevId, ret
#define HWI_DELETE_PARAMS(hwiNum) hwiNum
#define HWI_DELETE_SHARE_PARAMS(hwiNum, pDevId, ret) hwiNum, pDevId, ret
#define HWI_RESPONSE_IN_PARAMS(hwiNum) hwiNum
#define HWI_RESPONSE_OUT_PARAMS(hwiNum) hwiNum
#define HWI_ENABLE_PARAMS(hwiNum) hwiNum
#define HWI_DISABLE_PARAMS(hwiNum) hwiNum
#define HWI_TRIGGER_PARAMS(hwiNum) hwiNum
#define HWI_SETPRI_PARAMS(hwiNum, priority) hwiNum, priority
#define HWI_CLEAR_PARAMS(hwiNum) hwiNum
#define HWI_SETAFFINITY_PARAMS(hwiNum, cpuMask) hwiNum, cpuMask
#define HWI_SENDIPI_PARAMS(hwiNum, cpuMask) hwiNum, cpuMask
#define EVENT_CREATE_PARAMS(eventCB) eventCB
#define EVENT_DELETE_PARAMS(eventCB, delRetCode) eventCB, delRetCode
#define EVENT_READ_PARAMS(eventCB, eventId, mask, mode, timeout) \
eventCB, eventId, mask, mode, timeout
#define EVENT_WRITE_PARAMS(eventCB, eventId, events) eventCB, eventId, events
#define EVENT_CLEAR_PARAMS(eventCB, eventId, events) eventCB, eventId, events
#define QUEUE_CREATE_PARAMS(queueId, queueSz, itemSz, queueAddr, memType) \
queueId, queueSz, itemSz, queueAddr, memType
#define QUEUE_DELETE_PARAMS(queueId, state, readable) queueId, state, readable
#define QUEUE_RW_PARAMS(queueId, queueSize, bufSize, operateType, readable, writeable, timeout) \
queueId, queueSize, bufSize, operateType, readable, writeable, timeout
#define SEM_CREATE_PARAMS(semId, type, count) semId, type, count
#define SEM_DELETE_PARAMS(semId, delRetCode) semId, delRetCode
#define SEM_PEND_PARAMS(semId, count, timeout) semId, count, timeout
#define SEM_POST_PARAMS(semId, type, count) semId, type, count
#define MUX_CREATE_PARAMS(muxId) muxId
#define MUX_DELETE_PARAMS(muxId, state, count, owner) muxId, state, count, owner
#define MUX_PEND_PARAMS(muxId, count, owner, timeout) muxId, count, owner, timeout
#define MUX_POST_PARAMS(muxId, count, owner) muxId, count, owner
#define MEM_ALLOC_PARAMS(pool, ptr, size) pool, ptr, size
#define MEM_ALLOC_ALIGN_PARAMS(pool, ptr, size, boundary) pool, ptr, size, boundary
#define MEM_REALLOC_PARAMS(pool, ptr, size) pool, ptr, size
#define MEM_FREE_PARAMS(pool, ptr) pool, ptr
#define MEM_INFO_REQ_PARAMS(pool) pool
#define MEM_INFO_PARAMS(pool, usedSize, freeSize) pool, usedSize, freeSize
#define SYS_ERROR_PARAMS(errno) errno
#if (LOSCFG_KERNEL_TRACE == 1)
/**
* @ingroup los_trace
* @brief Trace static code stub.
*
* @par Description:
* This API is used to instrument trace code stub in source code, to track events.
* @attention
* None.
*
* @param TYPE [IN] Type #LOS_TRACE_TYPE. The event type.
* @param IDENTITY [IN] Type #UINTPTR. The subject of this event description.
* @param ... [IN] Type #UINTPTR. This piece of event's params.
* @retval None.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
*/
#define LOS_TRACE(TYPE, IDENTITY, ...) \
do { \
UINTPTR _inner[] = {0, TYPE##_PARAMS((UINTPTR)IDENTITY, ##__VA_ARGS__)}; \
UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR); \
if ((_n > 1) && (g_traceEventHook != NULL)) { \
g_traceEventHook(TYPE, _inner[1], _n > 2 ? &_inner[2] : NULL, _n - 2); \
} \
} while (0)
#else
#define LOS_TRACE(TYPE, ...)
#endif
#if (LOSCFG_KERNEL_TRACE == 1)
/**
* @ingroup los_trace
* @brief Trace static easier user-defined code stub.
*
* @par Description:
* This API is used to instrument user-defined trace code stub in source code, to track events simply.
* @attention
* None.
*
* @param TYPE [IN] Type #UINT32. The event type, only low 4 bits take effect.
* @param IDENTITY [IN] Type #UINTPTR. The subject of this event description.
* @param ... [IN] Type #UINTPTR. This piece of event's params.
* @retval None.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
*/
#define LOS_TRACE_EASY(TYPE, IDENTITY, ...) \
do { \
UINTPTR _inner[] = {0, ##__VA_ARGS__}; \
UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR); \
if (g_traceEventHook != NULL) { \
g_traceEventHook(TRACE_USER_DEFAULT_FLAG | TYPE, (UINTPTR)IDENTITY, _n > 1 ? &_inner[1] : NULL, _n - 1); \
} \
} while (0)
#else
#define LOS_TRACE_EASY(...)
#endif
/**
* @ingroup los_trace
* @brief Start trace.
*
* @par Description:
* This API is used to start trace.
* @attention
* <ul>
* <li>Start trace</li>
* </ul>
*
* @param None.
* @retval #LOS_ERRNO_TRACE_ERROR_STATUS 0x02001400: Trace start failed.
* @retval #LOS_OK 0x00000000: Trace start success.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceStart
*/
extern UINT32 LOS_TraceStart(VOID);
/**
* @ingroup los_trace
* @brief Stop trace sample.
*
* @par Description:
* This API is used to start trace sample.
* @attention
* <ul>
* <li>Stop trace sample</li>
* </ul>
*
* @param None.
* @retval #None.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceStop
*/
extern VOID LOS_TraceStop(VOID);
/**
* @ingroup los_trace
* @brief Clear the trace buf.
*
* @par Description:
* Clear the event frames in trace buf only at offline mode.
* @attention
* <ul>
* <li>This API can be called only after that trace buffer has been established.</li>
* Otherwise, the trace will be failed.</li>
* </ul>
*
* @param None.
* @retval #NA
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceReset
*/
extern VOID LOS_TraceReset(VOID);
/**
* @ingroup los_trace
* @brief Set trace event mask.
*
* @par Description:
* Set trace event mask.
* @attention
* <ul>
* <li>Set trace event filter mask.</li>
* <li>The Default mask is (TRACE_HWI_FLAG | TRACE_TASK_FLAG), stands for switch on task and hwi events.</li>
* <li>Customize mask according to the type defined in enum LOS_TRACE_MASK to switch on corresponding module's
* trace.</li>
* <li>The system's trace mask will be overrode by the input parameter.</li>
* </ul>
*
* @param mask [IN] Type #UINT32. The mask used to filter events of LOS_TRACE_MASK.
* @retval #NA.
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceEventMaskSet
*/
extern VOID LOS_TraceEventMaskSet(UINT32 mask);
/**
* @ingroup los_trace
* @brief Offline trace buffer display.
*
* @par Description:
* Display trace buf data only at offline mode.
* @attention
* <ul>
* <li>This API can be called only after that trace stopped. Otherwise the trace dump will be failed.</li>
* <li>Trace data will be send to pipeline when user set toClient = TRUE. Otherwise it will be formatted and printed
* out.</li>
* </ul>
*
* @param toClient [IN] Type #BOOL. Whether send trace data to Client through pipeline.
* @retval #NA
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceRecordDump
*/
extern VOID LOS_TraceRecordDump(BOOL toClient);
/**
* @ingroup los_trace
* @brief Offline trace buffer export.
*
* @par Description:
* Return the trace buf only at offline mode.
* @attention
* <ul>
* <li>This API can be called only after that trace buffer has been established. </li>
* <li>The return buffer's address is a critical resource, user can only ready.</li>
* </ul>
*
* @param NA
* @retval #OfflineHead* The trace buffer's address, analyze this buffer according to the structure of
* OfflineHead.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceRecordGet
*/
extern OfflineHead *LOS_TraceRecordGet(VOID);
/**
* @ingroup los_trace
* @brief Hwi num fliter hook.
*
* @par Description:
* Hwi fliter function.
* @attention
* <ul>
* <li>Filter the hwi events by hwi num</li>
* </ul>
*
* @param hook [IN] Type #TRACE_HWI_FILTER_HOOK. The user defined hook for hwi num filter,
* the hook should return true if you don't want trace this hwi num.
* @retval #None
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceHwiFilterHookReg
*/
extern VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_TRACE_H */

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_TRACE_PRI_H
#define _LOS_TRACE_PRI_H
#include "los_trace.h"
#include "los_task.h"
#include "los_debug.h"
#include "los_interrupt.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
#define TRACE_CMD_END_CHAR 0xD
#endif
#define TRACE_ERROR PRINT_ERR
#define TRACE_MODE_OFFLINE 0
#define TRACE_MODE_ONLINE 1
/* just task and hwi were traced */
#define TRACE_DEFAULT_MASK (TRACE_HWI_FLAG | TRACE_TASK_FLAG)
#define TRACE_CTL_MAGIC_NUM 0xDEADBEEF
#define TRACE_BIGLITTLE_WORD 0x12345678
#define TRACE_VERSION(MODE) (0xFFFFFFFF & (MODE))
#define TRACE_MASK_COMBINE(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
#define TRACE_GET_MODE_FLAG(type) ((type) & 0xFFFFFFF0)
#if (LOSCFG_KERNEL_SMP == 1)
extern SPIN_LOCK_S g_traceSpin;
#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state))
#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state))
#else
#define TRACE_LOCK(state) (state) = LOS_IntLock()
#define TRACE_UNLOCK(state) LOS_IntRestore(state)
#endif
typedef VOID (*TRACE_DUMP_HOOK)(BOOL toClient);
extern TRACE_DUMP_HOOK g_traceDumpHook;
enum TraceCmd {
TRACE_CMD_START = 1,
TRACE_CMD_STOP,
TRACE_CMD_SET_EVENT_MASK,
TRACE_CMD_RECODE_DUMP,
TRACE_CMD_MAX_CODE,
};
/**
* @ingroup los_trace
* struct to store the trace cmd from traceClient.
*/
typedef struct {
UINT8 cmd;
UINT8 param1;
UINT8 param2;
UINT8 param3;
UINT8 param4;
UINT8 param5;
UINT8 end;
} TraceClientCmd;
/**
* @ingroup los_trace
* struct to store the event infomation
*/
typedef struct {
UINT32 cmd; /* trace start or stop cmd */
UINT32 param; /* magic numb stand for notify msg */
} TraceNotifyFrame;
/**
* @ingroup los_trace
* struct to store the trace config information.
*/
typedef struct {
struct WriteCtrl {
UINT16 curIndex; /* The current record index */
UINT16 maxRecordCount; /* The max num of track items */
UINT16 curObjIndex; /* The current obj index */
UINT16 maxObjCount; /* The max num of obj index */
ObjData *objBuf; /* Pointer to obj info data */
TraceEventFrame *frameBuf; /* Pointer to the track items */
} ctrl;
OfflineHead *head;
} TraceOfflineHeaderInfo;
extern UINT32 OsTraceInit(VOID);
extern UINT32 OsTraceGetMaskTid(UINT32 taskId);
extern VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb);
extern VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame);
extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId);
extern BOOL OsTraceIsEnable(VOID);
extern OfflineHead *OsTraceRecordGet(VOID);
#if (LOSCFG_RECORDER_MODE_ONLINE == 1)
extern VOID OsTraceSendHead(VOID);
extern VOID OsTraceSendObjTable(VOID);
extern VOID OsTraceSendNotify(UINT32 type, UINT32 value);
#define OsTraceNotifyStart() do { \
OsTraceSendNotify(SYS_START, TRACE_CTL_MAGIC_NUM); \
OsTraceSendHead(); \
OsTraceSendObjTable(); \
} while (0)
#define OsTraceNotifyStop() do { \
OsTraceSendNotify(SYS_STOP, TRACE_CTL_MAGIC_NUM); \
} while (0)
#define OsTraceReset()
#define OsTraceRecordDump(toClient)
#else
extern UINT32 OsTraceBufInit(UINT32 size);
extern VOID OsTraceReset(VOID);
extern VOID OsTraceRecordDump(BOOL toClient);
#define OsTraceNotifyStart()
#define OsTraceNotifyStop()
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_TRACE_PRI_H */

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "trace_pipeline_serial.h"
#include "trace_pipeline.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
UINT32 SerialPipelineInit(VOID)
{
return uart_hwiCreate();
}
UINT32 SerialDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
{
return uart_read(data, size, timeout);
}
UINT32 SerialWait(VOID)
{
return uart_wait_adapt();
}
#else
UINT32 SerialPipelineInit(VOID)
{
return LOS_OK;
}
UINT32 SerialDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
{
return LOS_OK;
}
UINT32 SerialWait(VOID)
{
return LOS_OK;
}
#endif
VOID SerialDataSend(UINT16 len, UINT8 *data)
{
UINT32 i;
for (i = 0; i < len; i++) {
UART_PUTC(data[i]);
}
}
STATIC const TracePipelineOps g_serialOps = {
.init = SerialPipelineInit,
.dataSend = SerialDataSend,
.dataRecv = SerialDataReceive,
.wait = SerialWait,
};
UINT32 OsTracePipelineInit(VOID)
{
OsTracePipelineReg(&g_serialOps);
return g_serialOps.init();
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 _TRACE_PIPELINE_SERIAL_H
#define _TRACE_PIPELINE_SERIAL_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern INT32 uart_putc(CHAR c);
#define UART_PUTC(c) uart_putc((c))
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TRACE_PIPELINE_SERIAL_H */

View File

@@ -0,0 +1,162 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 "trace_pipeline.h"
#include "trace_tlv.h"
#include "los_trace_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_KERNEL_SMP == 1)
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_pipeSpin);
#define PIPE_LOCK(state) LOS_SpinLockSave(&g_pipeSpin, &(state))
#define PIPE_UNLOCK(state) LOS_SpinUnlockRestore(&g_pipeSpin, (state))
#else
#define PIPE_LOCK(state) (state) = LOS_IntLock()
#define PIPE_UNLOCK(state) LOS_IntRestore(state)
#endif
STATIC TlvTable g_traceTlvTblNotify[] = {
{ CMD, LOS_OFF_SET_OF(TraceNotifyFrame, cmd), sizeof(UINT32) },
{ PARAMS, LOS_OFF_SET_OF(TraceNotifyFrame, param), sizeof(UINT32) },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblHead[] = {
{ ENDIAN, LOS_OFF_SET_OF(TraceBaseHeaderInfo, bigLittleEndian), sizeof(UINT32) },
{ VERSION, LOS_OFF_SET_OF(TraceBaseHeaderInfo, version), sizeof(UINT32) },
{ CLOCK_FREQ, LOS_OFF_SET_OF(TraceBaseHeaderInfo, clockFreq), sizeof(UINT32) },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblObj[] = {
{ ADDR, LOS_OFF_SET_OF(ObjData, id), sizeof(UINT32) },
{ PRIO, LOS_OFF_SET_OF(ObjData, prio), sizeof(UINT32) },
{ NAME, LOS_OFF_SET_OF(ObjData, name), sizeof(CHAR) * LOSCFG_TRACE_OBJ_MAX_NAME_SIZE },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblEvent[] = {
#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
{ CORE, LOS_OFF_SET_OF(TraceEventFrame, core), sizeof(UINT32) },
#endif
{ EVENT_CODE, LOS_OFF_SET_OF(TraceEventFrame, eventType), sizeof(UINT32) },
{ CUR_TIME, LOS_OFF_SET_OF(TraceEventFrame, curTime), sizeof(UINT64) },
#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
{ EVENT_COUNT, LOS_OFF_SET_OF(TraceEventFrame, eventCount), sizeof(UINT32) },
#endif
{ CUR_TASK, LOS_OFF_SET_OF(TraceEventFrame, curTask), sizeof(UINT32) },
{ IDENTITY, LOS_OFF_SET_OF(TraceEventFrame, identity), sizeof(UINTPTR) },
{ EVENT_PARAMS, LOS_OFF_SET_OF(TraceEventFrame, params), sizeof(UINTPTR) * LOSCFG_TRACE_FRAME_MAX_PARAMS },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable *g_traceTlvTbl[] = {
g_traceTlvTblNotify,
g_traceTlvTblHead,
g_traceTlvTblObj,
g_traceTlvTblEvent
};
STATIC UINT32 DefaultPipelineInit(VOID)
{
return LOS_OK;
}
STATIC VOID DefaultDataSend(UINT16 len, UINT8 *data)
{
(VOID)len;
(VOID)data;
}
STATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
{
(VOID)data;
(VOID)size;
(VOID)timeout;
return LOS_OK;
}
STATIC UINT32 DefaultWait(VOID)
{
return LOS_OK;
}
STATIC TracePipelineOps g_defaultOps = {
.init = DefaultPipelineInit,
.dataSend = DefaultDataSend,
.dataRecv = DefaultDataReceive,
.wait = DefaultWait,
};
STATIC const TracePipelineOps *g_tracePipelineOps = &g_defaultOps;
VOID OsTracePipelineReg(const TracePipelineOps *ops)
{
g_tracePipelineOps = ops;
}
VOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data)
{
UINT32 intSave;
UINT8 outBuf[LOSCFG_TRACE_TLV_BUF_SIZE] = {0};
if ((type > TRACE_MSG_MAX) || (len > LOSCFG_TRACE_TLV_BUF_SIZE)) {
return;
}
len = OsTraceDataEncode(type, g_traceTlvTbl[type], data, &outBuf[0], sizeof(outBuf));
PIPE_LOCK(intSave);
g_tracePipelineOps->dataSend(len, &outBuf[0]);
PIPE_UNLOCK(intSave);
}
UINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout)
{
return g_tracePipelineOps->dataRecv(data, size, timeout);
}
UINT32 OsTraceDataWait(VOID)
{
return g_tracePipelineOps->wait();
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 _TRACE_PIPELINE_H
#define _TRACE_PIPELINE_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
UINT32 (*init)(VOID);
VOID (*dataSend)(UINT16 len, UINT8 *data);
UINT32 (*dataRecv)(UINT8 *data, UINT32 size, UINT32 timeout);
UINT32 (*wait)(VOID);
} TracePipelineOps;
/* used as tlv's tag */
enum TraceMsgType {
NOTIFY,
HEAD,
OBJ,
EVENT,
TRACE_MSG_MAX,
};
enum TraceNotifySubType {
CMD = 0x1,
PARAMS,
};
enum TraceHeadSubType {
ENDIAN = 0x1,
VERSION,
OBJ_SIZE,
OBJ_COUNT,
CUR_INDEX,
MAX_RECODE,
CUR_OBJ_INDEX,
CLOCK_FREQ,
};
enum TraceObjSubType {
ADDR = 0x1,
PRIO,
NAME,
};
enum TraceEvtSubType {
CORE = 0x1,
EVENT_CODE,
CUR_TIME,
EVENT_COUNT,
CUR_TASK,
IDENTITY,
EVENT_PARAMS,
};
extern VOID OsTracePipelineReg(const TracePipelineOps *ops);
extern UINT32 OsTracePipelineInit(VOID);
extern VOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data);
extern UINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout);
extern UINT32 OsTraceDataWait(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TRACE_PIPELINE_H */

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 "trace_tlv.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define CRC_WIDTH 8
#define CRC_POLY 0x1021
#define CRC_TOPBIT 0x8000
STATIC UINT16 CalcCrc16(const UINT8 *buf, UINT32 len)
{
UINT32 i;
UINT16 crc = 0;
for (; len > 0; len--) {
crc = crc ^ (*buf++ << CRC_WIDTH);
for (i = 0; i < CRC_WIDTH; i++) {
if (crc & CRC_TOPBIT) {
crc = (crc << 1) ^ CRC_POLY;
} else {
crc <<= 1;
}
}
}
return crc;
}
STATIC UINT32 OsWriteTlv(UINT8 *tlvBuf, UINT8 type, UINT8 len, UINT8 *value)
{
TraceMsgTlvBody *body = (TraceMsgTlvBody *)tlvBuf;
if (len == 0) {
return 0;
}
body->type = type;
body->len = len;
/* Do not check return value for performance, if copy failed, only this package will be discarded */
(VOID)memcpy_s(body->value, len, value, len);
return len + sizeof(body->type) + sizeof(body->len);
}
STATIC UINT32 OsTlvEncode(const TlvTable *table, UINT8 *srcBuf, UINT8 *tlvBuf, INT32 tlvBufLen)
{
UINT32 len = 0;
const TlvTable *tlvTableItem = table;
while (tlvTableItem->tag != TRACE_TLV_TYPE_NULL) {
if ((len + tlvTableItem->elemSize + sizeof(UINT8) + sizeof(UINT8)) > tlvBufLen) {
break;
}
len += OsWriteTlv(tlvBuf + len, tlvTableItem->tag, tlvTableItem->elemSize, srcBuf + tlvTableItem->elemOffset);
tlvTableItem++;
}
return len;
}
UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen)
{
UINT16 crc;
INT32 len;
INT32 tlvBufLen;
UINT8 *tlvBuf = NULL;
TraceMsgTlvHead *head = (TraceMsgTlvHead *)dest;
tlvBufLen = destLen - sizeof(TraceMsgTlvHead);
if ((tlvBufLen <= 0) || (table == NULL)) {
return 0;
}
tlvBuf = dest + sizeof(TraceMsgTlvHead);
len = OsTlvEncode(table, src, tlvBuf, tlvBufLen);
crc = CalcCrc16(tlvBuf, len);
head->magicNum = TRACE_TLV_MSG_HEAD;
head->msgType = type;
head->len = len;
head->crc = crc;
return len + sizeof(TraceMsgTlvHead);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 _TRACE_TLV_H
#define _TRACE_TLV_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define TRACE_TLV_MSG_HEAD 0xFF
#define TRACE_TLV_TYPE_NULL 0xFF
typedef struct {
UINT8 magicNum;
UINT8 msgType;
UINT16 len;
UINT16 crc;
} TraceMsgTlvHead;
typedef struct {
UINT8 type;
UINT8 len;
UINT8 value[];
} TraceMsgTlvBody;
typedef struct {
UINT8 tag;
UINT8 elemOffset;
UINT8 elemSize;
} TlvTable;
/**
* @ingroup los_trace
* @brief Encode trace raw data.
*
* @par Description:
* This API is used to encode trace raw data to tlv data.
* @attention
* <ul>
* <li>Encade trace data</li>
* </ul>
*
* @param type [IN] Type #UINT8. The type stands for different struct of src data.
* @param src [IN] Type #UINT8 *. The raw trace data.
* @param table [IN] Type #const TlvTable *. The tlv table descript elemOffset and elemSize.
* @param dest [OUT] Type #UINT8 *. The tlv data.
* @param destLen [IN] Type #UINT8 *. The tlv buf max len.
* @retval #0 convert failed.
* @retval #UINT32 convert success bytes.
*
* @par Dependency:
* <ul><li>trace_tlv.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceDataEncode
*/
extern UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TRACE_TLV_H */

View File

@@ -0,0 +1,265 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_trace_pri.h"
#include "trace_pipeline.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_RECORDER_MODE_OFFLINE == 1)
#define BITS_NUM_FOR_TASK_ID 16
LITE_OS_SEC_BSS STATIC TraceOfflineHeaderInfo g_traceRecoder;
LITE_OS_SEC_BSS STATIC UINT32 g_tidMask[LOSCFG_BASE_CORE_TSK_LIMIT] = {0};
UINT32 OsTraceGetMaskTid(UINT32 tid)
{
return tid | ((tid < LOSCFG_BASE_CORE_TSK_LIMIT) ? g_tidMask[tid] << BITS_NUM_FOR_TASK_ID : 0); /* tid < 65535 */
}
UINT32 OsTraceBufInit(UINT32 size)
{
UINT32 headSize;
VOID *buf = NULL;
headSize = sizeof(OfflineHead) + sizeof(ObjData) * LOSCFG_TRACE_OBJ_MAX_NUM;
if (size <= headSize) {
TRACE_ERROR("trace buf size not enough than 0x%x\n", headSize);
return LOS_ERRNO_TRACE_BUF_TOO_SMALL;
}
buf = LOS_MemAlloc(m_aucSysMem0, size);
if (buf == NULL) {
return LOS_ERRNO_TRACE_NO_MEMORY;
}
(VOID)memset_s(buf, size, 0, size);
g_traceRecoder.head = (OfflineHead *)buf;
g_traceRecoder.head->baseInfo.bigLittleEndian = TRACE_BIGLITTLE_WORD;
g_traceRecoder.head->baseInfo.version = TRACE_VERSION(TRACE_MODE_OFFLINE);
g_traceRecoder.head->baseInfo.clockFreq = OS_SYS_CLOCK;
g_traceRecoder.head->objSize = sizeof(ObjData);
g_traceRecoder.head->frameSize = sizeof(TraceEventFrame);
g_traceRecoder.head->objOffset = sizeof(OfflineHead);
g_traceRecoder.head->frameOffset = headSize;
g_traceRecoder.head->totalLen = size;
g_traceRecoder.ctrl.curIndex = 0;
g_traceRecoder.ctrl.curObjIndex = 0;
g_traceRecoder.ctrl.maxObjCount = LOSCFG_TRACE_OBJ_MAX_NUM;
g_traceRecoder.ctrl.maxRecordCount = (size - headSize) / sizeof(TraceEventFrame);
g_traceRecoder.ctrl.objBuf = (ObjData *)((UINTPTR)buf + g_traceRecoder.head->objOffset);
g_traceRecoder.ctrl.frameBuf = (TraceEventFrame *)((UINTPTR)buf + g_traceRecoder.head->frameOffset);
return LOS_OK;
}
VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId)
{
UINT32 intSave;
UINT32 index;
ObjData *obj = NULL;
TRACE_LOCK(intSave);
/* add obj begin */
index = g_traceRecoder.ctrl.curObjIndex;
if (index >= LOSCFG_TRACE_OBJ_MAX_NUM) { /* do nothing when config LOSCFG_TRACE_OBJ_MAX_NUM = 0 */
TRACE_UNLOCK(intSave);
return;
}
obj = &g_traceRecoder.ctrl.objBuf[index];
if (taskId < LOSCFG_BASE_CORE_TSK_LIMIT) {
g_tidMask[taskId]++;
}
OsTraceSetObj(obj, OS_TCB_FROM_TID(taskId));
g_traceRecoder.ctrl.curObjIndex++;
if (g_traceRecoder.ctrl.curObjIndex >= g_traceRecoder.ctrl.maxObjCount) {
g_traceRecoder.ctrl.curObjIndex = 0; /* turn around */
}
/* add obj end */
TRACE_UNLOCK(intSave);
}
VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame)
{
UINT16 index;
UINT32 intSave;
TRACE_LOCK(intSave);
index = g_traceRecoder.ctrl.curIndex;
(VOID)memcpy_s(&g_traceRecoder.ctrl.frameBuf[index], sizeof(TraceEventFrame), frame, sizeof(TraceEventFrame));
g_traceRecoder.ctrl.curIndex++;
if (g_traceRecoder.ctrl.curIndex >= g_traceRecoder.ctrl.maxRecordCount) {
g_traceRecoder.ctrl.curIndex = 0;
}
TRACE_UNLOCK(intSave);
}
VOID OsTraceReset(VOID)
{
UINT32 intSave;
UINT32 bufLen;
TRACE_LOCK(intSave);
bufLen = sizeof(TraceEventFrame) * g_traceRecoder.ctrl.maxRecordCount;
(VOID)memset_s(g_traceRecoder.ctrl.frameBuf, bufLen, 0, bufLen);
g_traceRecoder.ctrl.curIndex = 0;
TRACE_UNLOCK(intSave);
}
STATIC VOID OsTraceInfoObj(VOID)
{
UINT32 i;
ObjData *obj = &g_traceRecoder.ctrl.objBuf[0];
if (g_traceRecoder.ctrl.maxObjCount > 0) {
PRINTK("CurObjIndex = %u\n", g_traceRecoder.ctrl.curObjIndex);
PRINTK("Index TaskID TaskPrio TaskName \n");
for (i = 0; i < g_traceRecoder.ctrl.maxObjCount; i++, obj++) {
PRINTK("%-7u 0x%-6x %-10u %s\n", i, obj->id, obj->prio, obj->name);
}
PRINTK("\n");
}
}
STATIC VOID OsTraceInfoEventTitle(VOID)
{
PRINTK("CurEvtIndex = %u\n", g_traceRecoder.ctrl.curIndex);
PRINTK("Index Time(cycles) EventType CurTask Identity ");
#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
PRINTK("cpuId hwiActive taskLockCnt ");
#endif
#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
PRINTK("eventCount ");
#endif
if (LOSCFG_TRACE_FRAME_MAX_PARAMS > 0) {
PRINTK("params ");
}
PRINTK("\n");
}
STATIC VOID OsTraceInfoEventData(VOID)
{
UINT32 i, j;
TraceEventFrame *frame = &g_traceRecoder.ctrl.frameBuf[0];
for (i = 0; i < g_traceRecoder.ctrl.maxRecordCount; i++, frame++) {
PRINTK("%-7u 0x%-15llx 0x%-12x 0x%-7x 0x%-11x ", i, (UINT32)frame->curTime, frame->eventType,
frame->curTask, frame->identity);
#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
UINT32 taskLockCnt = frame->core.taskLockCnt;
#if (LOSCFG_KERNEL_SMP == 1)
/*
* For smp systems, TRACE_LOCK will requst taskLock, and this counter
* will increase by 1 in that case.
*/
taskLockCnt -= 1;
#endif
PRINTK("%-11u %-11u %-11u", frame->core.cpuId, frame->core.hwiActive, taskLockCnt);
#endif
#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
PRINTK("%-11u", frame->eventCount);
#endif
for (j = 0; j < LOSCFG_TRACE_FRAME_MAX_PARAMS; j++) {
PRINTK("0x%-11x", frame->params[j]);
}
PRINTK("\n");
}
}
STATIC VOID OsTraceInfoDisplay(VOID)
{
OfflineHead *head = g_traceRecoder.head;
PRINTK("*******TraceInfo begin*******\n");
PRINTK("clockFreq = %u\n", head->baseInfo.clockFreq);
OsTraceInfoObj();
OsTraceInfoEventTitle();
OsTraceInfoEventData();
PRINTK("*******TraceInfo end*******\n");
}
#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
STATIC VOID OsTraceSendInfo(VOID)
{
UINT32 i;
ObjData *obj = NULL;
TraceEventFrame *frame = NULL;
OsTraceDataSend(HEAD, sizeof(OfflineHead), (UINT8 *)g_traceRecoder.head);
obj = &g_traceRecoder.ctrl.objBuf[0];
for (i = 0; i < g_traceRecoder.ctrl.maxObjCount; i++) {
OsTraceDataSend(OBJ, sizeof(ObjData), (UINT8 *)(obj + i));
}
frame = &g_traceRecoder.ctrl.frameBuf[0];
for (i = 0; i < g_traceRecoder.ctrl.maxRecordCount; i++) {
OsTraceDataSend(EVENT, sizeof(TraceEventFrame), (UINT8 *)(frame + i));
}
}
#endif
VOID OsTraceRecordDump(BOOL toClient)
{
if (!toClient) {
OsTraceInfoDisplay();
return;
}
#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
OsTraceSendInfo();
#endif
}
OfflineHead *OsTraceRecordGet(VOID)
{
return g_traceRecoder.head;
}
#endif /* LOSCFG_RECORDER_MODE_OFFLINE == 1 */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_trace_pri.h"
#include "trace_pipeline.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_RECORDER_MODE_ONLINE == 1)
UINT32 OsTraceGetMaskTid(UINT32 taskId)
{
return taskId;
}
VOID OsTraceSendHead(VOID)
{
TraceBaseHeaderInfo head = {
.bigLittleEndian = TRACE_BIGLITTLE_WORD,
.version = TRACE_VERSION(TRACE_MODE_ONLINE),
.clockFreq = OS_SYS_CLOCK,
};
OsTraceDataSend(HEAD, sizeof(TraceBaseHeaderInfo), (UINT8 *)&head);
}
VOID OsTraceSendNotify(UINT32 type, UINT32 value)
{
TraceNotifyFrame frame = {
.cmd = type,
.param = value,
};
OsTraceDataSend(NOTIFY, sizeof(TraceNotifyFrame), (UINT8 *)&frame);
}
STATIC VOID OsTraceSendObj(const LosTaskCB *tcb)
{
ObjData obj;
OsTraceSetObj(&obj, tcb);
OsTraceDataSend(OBJ, sizeof(ObjData), (UINT8 *)&obj);
}
VOID OsTraceSendObjTable(VOID)
{
UINT32 loop;
LosTaskCB *tcb = NULL;
for (loop = 0; loop < g_taskMaxNum; ++loop) {
tcb = g_taskCBArray + loop;
if (tcb->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
OsTraceSendObj(tcb);
}
}
VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId)
{
if (OsTraceIsEnable()) {
OsTraceSendObj(OS_TCB_FROM_TID(taskId));
}
}
VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame)
{
OsTraceDataSend(EVENT, sizeof(TraceEventFrame), (UINT8 *)frame);
}
OfflineHead *OsTraceRecordGet(VOID)
{
return NULL;
}
#endif /* LOSCFG_RECORDER_MODE_ONLINE == 1 */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

7
config.gni Normal file → Executable file
View File

@@ -33,10 +33,15 @@ declare_args() {
enable_ohos_kernel_liteos_m_exchook = true
enable_ohos_kernel_liteos_m_kal = true
enable_ohos_kernel_liteos_m_fs = true
enable_ohos_kernel_liteos_m_shell = false
enable_ohos_kernel_liteos_m_shell = true
enable_ohos_kernel_liteos_m_backtrace = true
enable_ohos_kernel_liteos_m_test = false
enable_ohos_kernel_liteos_m_pm = true
enable_ohos_kernel_liteos_m_trace = false
enable_ohos_kernel_liteos_m_lwip = false
enable_ohos_kernel_liteos_m_dynlink = false
enable_ohos_kernel_liteos_m_tz = false
ohos_kernel_liteos_m_lwip_path = "components/net/lwip-2.1:lwip"
}
LITEOSTOPDIR = "//kernel/liteos_m"

View File

@@ -37,11 +37,11 @@ declare_args() {
lite_component("kal") {
features = []
if (enable_ohos_kernel_liteos_m_cmsis == true) {
if (enable_ohos_kernel_liteos_m_cmsis) {
features += [ "cmsis" ]
}
if (enable_ohos_kernel_liteos_m_posix == true) {
if (enable_ohos_kernel_liteos_m_posix) {
features += [ "posix" ]
}
}

View File

@@ -27,17 +27,13 @@
# 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/config.gni")
static_library("cmsis") {
sources = [ "cmsis_liteos2.c" ]
include_dirs = [
"//third_party/bounds_checking_function/include",
"../../kernel/include",
"../../kernel/arch/include",
"../../utils",
]
public_configs = [ ":include" ]
configs += [ "$LITEOSTOPDIR:los_config" ]
}
config("include") {

View File

@@ -112,7 +112,7 @@ osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
}
uwRet = memcpy_s(id_buf, id_size, KERNEL_ID, id_size);
if (uwRet != EOK) {
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, uwRet);
PRINT_ERR("%s[%d] memcpy failed, error type = %lu\n", __FUNCTION__, __LINE__, uwRet);
return osError;
}
}
@@ -299,7 +299,9 @@ osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr
stTskInitParam.uwStackSize = attr ? attr->stack_size : LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
stTskInitParam.pcName = (CHAR *)(attr ? attr->name : "[NULL]");
stTskInitParam.usTaskPrio = usPriority;
if (attr->attr_bits == osThreadJoinable) {
stTskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
}
uwRet = LOS_TaskCreate(&uwTid, &stTskInitParam);
if (LOS_OK != uwRet) {
@@ -576,6 +578,46 @@ osStatus_t osThreadResume(osThreadId_t thread_id)
}
osStatus_t osThreadDetach(osThreadId_t thread_id)
{
UINT32 ret;
LosTaskCB *taskCB = (LosTaskCB *)thread_id;
if (thread_id == NULL) {
return osErrorParameter;
}
ret = LOS_TaskDetach(taskCB->taskID);
if (ret == LOS_ERRNO_TSK_NOT_ALLOW_IN_INT) {
return osErrorISR;
} else if (ret != LOS_OK) {
return osErrorResource;
}
return osOK;
}
osStatus_t osThreadJoin(osThreadId_t thread_id)
{
UINT32 ret;
LosTaskCB *taskCB = (LosTaskCB *)thread_id;
if (thread_id == NULL) {
return osErrorParameter;
}
ret = LOS_TaskJoin(taskCB->taskID, NULL);
if (ret == LOS_ERRNO_TSK_NOT_ALLOW_IN_INT) {
return osErrorISR;
} else if (ret != LOS_OK) {
return osErrorResource;
}
return osOK;
}
osStatus_t osThreadTerminate(osThreadId_t thread_id)
{
UINT32 uwRet;
@@ -1087,8 +1129,9 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
{
UINT32 uwRet;
UINT32 uwRet = LOS_NOK;
UINT32 uwSemId;
UINT32 intSave;
UNUSED(attr);
@@ -1096,14 +1139,16 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const
return (osSemaphoreId_t)NULL;
}
if (1 == max_count) {
uwRet = LOS_BinarySemCreate((UINT16)initial_count, &uwSemId);
} else {
if (max_count > 0 && max_count <= OS_SEM_COUNTING_MAX_COUNT) {
uwRet = LOS_SemCreate((UINT16)initial_count, &uwSemId);
}
if (uwRet == LOS_OK) {
return (osSemaphoreId_t)(GET_SEM(uwSemId));
osSemaphoreId_t semaphore_id = (osSemaphoreId_t)(GET_SEM(uwSemId));
intSave = LOS_IntLock();
((LosSemCB *)semaphore_id)->maxSemCount = max_count;
LOS_IntRestore(intSave);
return semaphore_id;
} else {
return (osSemaphoreId_t)NULL;
}
@@ -1649,3 +1694,120 @@ const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id)
return p;
}
// ==== Thread Flags Functions ====
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
{
UINT32 ret;
LosTaskCB *taskCB = (LosTaskCB *)thread_id;
EVENT_CB_S *eventCB = NULL;
UINT32 curFlags;
if (taskCB == NULL) {
return (uint32_t)osFlagsErrorParameter;
}
eventCB = &(taskCB->event);
curFlags = eventCB->uwEventID | flags;
ret = LOS_EventWrite(eventCB, (UINT32)flags);
if (ret == LOS_ERRNO_EVENT_SETBIT_INVALID) {
return (uint32_t)osFlagsErrorParameter;
}
if (ret != LOS_OK) {
return (uint32_t)osFlagsErrorResource;
}
if (curFlags & taskCB->eventMask) {
return curFlags & (~taskCB->eventMask);
}
return curFlags;
}
uint32_t osThreadFlagsClear(uint32_t flags)
{
UINT32 ret;
UINT32 saveFlags;
LosTaskCB *runTask = NULL;
EVENT_CB_S *eventCB = NULL;
if (OS_INT_ACTIVE) {
return (uint32_t)osFlagsErrorUnknown;
}
runTask = g_losTask.runTask;
eventCB = &(runTask->event);
saveFlags = eventCB->uwEventID;
ret = LOS_EventClear(eventCB, ~(UINT32)flags);
if (ret == LOS_OK) {
return (uint32_t)saveFlags;
}
return (uint32_t)osFlagsErrorResource;
}
uint32_t osThreadFlagsGet(void)
{
LosTaskCB *runTask = NULL;
EVENT_CB_S *eventCB = NULL;
if (OS_INT_ACTIVE) {
return (uint32_t)osFlagsErrorUnknown;
}
runTask = g_losTask.runTask;
eventCB = &(runTask->event);
return (uint32_t)(eventCB->uwEventID);
}
uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
{
UINT32 ret;
UINT32 mode = 0;
LosTaskCB *runTask = NULL;
EVENT_CB_S *eventCB = NULL;
if (OS_INT_ACTIVE) {
return (uint32_t)osFlagsErrorUnknown;
}
if (options > (osFlagsWaitAny | osFlagsWaitAll | osFlagsNoClear)) {
return (uint32_t)osFlagsErrorParameter;
}
if ((options & osFlagsWaitAll) == osFlagsWaitAll) {
mode |= LOS_WAITMODE_AND;
} else {
mode |= LOS_WAITMODE_OR;
}
if ((options & osFlagsNoClear) == osFlagsNoClear) {
mode &= ~LOS_WAITMODE_CLR;
} else {
mode |= LOS_WAITMODE_CLR;
}
runTask = g_losTask.runTask;
eventCB = &(runTask->event);
ret = LOS_EventRead(eventCB, (UINT32)flags, mode, (UINT32)timeout);
if (!(ret & LOS_ERRTYPE_ERROR)) {
return (uint32_t)eventCB->uwEventID | ret;
}
switch (ret) {
case LOS_ERRNO_EVENT_PTR_NULL:
case LOS_ERRNO_EVENT_SETBIT_INVALID:
case LOS_ERRNO_EVENT_EVENTMASK_INVALID:
case LOS_ERRNO_EVENT_FLAGS_INVALID:
return (uint32_t)osFlagsErrorParameter;
case LOS_ERRNO_EVENT_READ_TIMEOUT:
return (uint32_t)osFlagsErrorTimeout;
default:
return (uint32_t)osFlagsErrorResource;
}
}

View File

@@ -50,10 +50,10 @@ extern "C" {
* @version 1.0
*/
typedef enum {
/** The timer is not allowed to wake up the RTOS. */
osTimerRousesIgnore = 0,
/** The timer is allowed to wake up the RTOS. */
osTimerRousesAllow = 1
/** The timer is not allowed to wake up the RTOS. */
osTimerRousesIgnore = 0,
/** The timer is allowed to wake up the RTOS. */
osTimerRousesAllow = 1
} osTimerRouses_t;
/**
@@ -61,10 +61,10 @@ typedef enum {
*
*/
typedef enum {
/** The timer ignores alignment. */
osTimerAlignIgnore = 0,
/** The timer allows alignment. */
osTimerAlignAllow = 1
/** The timer ignores alignment. */
osTimerAlignIgnore = 0,
/** The timer allows alignment. */
osTimerAlignAllow = 1
} osTimerAlign_t;
osTimerId_t osTimerExtNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
config("include") {
include_dirs = [ "include" ]
}
@@ -45,16 +47,8 @@ static_library("posix") {
"src/time.c",
]
include_dirs = [
"../../kernel/arch/include",
"../../kernel/include",
"../../utils",
]
public_configs = [ ":include" ]
configs += [ "$LITEOSTOPDIR:los_config" ]
public_deps = [
"//third_party/musl/porting/liteos_m/kernel",
"//third_party/bounds_checking_function:libsec_static",
]
public_deps = [ "//third_party/musl/porting/liteos_m/kernel" ]
}

View File

@@ -34,56 +34,65 @@
#include <stdlib.h>
#include <unistd.h>
#include <securec.h>
#include <limits.h>
#include "los_config.h"
#include "los_task.h"
#define PTHREAD_DEFAULT_NAME "pthread"
#define PTHREAD_DEFAULT_NAME_LEN 8
#define PTHREAD_NAMELEN 16
typedef struct {
void *(*startRoutine)(void *);
void *param;
char name[PTHREAD_NAMELEN];
}PthreadData;
} PthreadData;
static void *PthreadEntry(UINT32 param)
{
PthreadData *pthreadData = (PthreadData *)(UINTPTR)param;
void *(*startRoutine)(void *) = pthreadData->startRoutine;
void *ret = startRoutine(pthreadData->param);
free(pthreadData);
pthread_exit(ret);
return ret;
}
static inline int IsPthread(pthread_t thread)
{
return ((UINT32)thread <= LOSCFG_BASE_CORE_TSK_LIMIT) &&
(OS_TCB_FROM_TID((UINT32)thread)->taskEntry == PthreadEntry);
return ((UINT32)thread <= LOSCFG_BASE_CORE_TSK_LIMIT);
}
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*startRoutine)(void *), void *arg)
static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutine)(void *), void *arg,
TSK_INIT_PARAM_S *taskInitParam)
{
TSK_INIT_PARAM_S taskInitParam = {0};
const pthread_attr_t *threadAttr = attr;
struct sched_param schedParam = { 0 };
PthreadData *pthreadData = NULL;
UINT32 taskID;
if ((thread == NULL) || (startRoutine == NULL)) {
return EINVAL;
INT32 policy = 0;
pthread_attr_t attrTmp;
INT32 ret;
errno_t error;
if (!attr) {
(VOID)pthread_attr_init(&attrTmp);
threadAttr = &attrTmp;
}
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
if (attr) {
if (attr->detachstate == PTHREAD_CREATE_DETACHED) {
return ENOTSUP;
if (threadAttr->stackaddr_set != 0) {
return ENOTSUP;
}
if (threadAttr->stacksize < PTHREAD_STACK_MIN) {
return EINVAL;
}
taskInitParam->uwStackSize = threadAttr->stacksize;
if (threadAttr->inheritsched == PTHREAD_EXPLICIT_SCHED) {
taskInitParam->usTaskPrio = (UINT16)threadAttr->schedparam.sched_priority;
} else {
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
if (ret != 0) {
return ret;
}
if (attr->stackaddr_set) {
return ENOTSUP;
}
if (attr->stacksize_set) {
taskInitParam.uwStackSize = attr->stacksize;
}
taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority;
taskInitParam->usTaskPrio = (UINT16)schedParam.sched_priority;
}
pthreadData = (PthreadData *)malloc(sizeof(PthreadData));
@@ -91,19 +100,42 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return ENOMEM;
}
pthreadData->startRoutine = startRoutine;
pthreadData->param = arg;
taskInitParam.pcName = pthreadData->name;
taskInitParam.pfnTaskEntry = PthreadEntry;
taskInitParam.uwArg = (UINT32)(UINTPTR)pthreadData;
if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
error = memcpy_s(pthreadData->name, PTHREAD_NAMELEN, PTHREAD_DEFAULT_NAME, PTHREAD_DEFAULT_NAME_LEN);
if (error != EOK) {
free(pthreadData);
return error;
}
pthreadData->startRoutine = startRoutine;
pthreadData->param = arg;
taskInitParam->pcName = pthreadData->name;
taskInitParam->pfnTaskEntry = PthreadEntry;
taskInitParam->uwArg = (UINT32)(UINTPTR)pthreadData;
if (threadAttr->detachstate != PTHREAD_CREATE_DETACHED) {
taskInitParam->uwResved = LOS_TASK_ATTR_JOINABLE;
}
return 0;
}
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*startRoutine)(void *), void *arg)
{
TSK_INIT_PARAM_S taskInitParam = { 0 };
UINT32 taskID;
UINT32 ret;
if ((thread == NULL) || (startRoutine == NULL)) {
return EINVAL;
}
/* set pthread default name */
(void)sprintf_s(taskInitParam.pcName, PTHREAD_NAMELEN, "pthread%u", taskID);
ret = PthreadCreateAttrInit(attr, startRoutine, arg, &taskInitParam);
if (ret != 0) {
return ret;
}
if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
free((VOID *)(UINTPTR)taskInitParam.uwArg);
return EINVAL;
}
(void)LOS_TaskResume(taskID);
@@ -164,55 +196,74 @@ int pthread_cancel(pthread_t thread)
int pthread_join(pthread_t thread, void **retval)
{
UINT32 taskStatus;
if (!IsPthread(thread)) {
UINTPTR result;
UINT32 ret = LOS_TaskJoin((UINT32)thread, &result);
if (ret == LOS_ERRNO_TSK_NOT_JOIN_SELF) {
return EDEADLK;
} else if (ret != LOS_OK) {
return EINVAL;
}
if (retval) {
/* retrieve thread exit code is not supported currently */
return ENOTSUP;
if (retval != NULL) {
*retval = (VOID *)result;
}
if (thread == pthread_self()) {
return EDEADLK;
}
while (LOS_TaskStatusGet((UINT32)thread, &taskStatus) == LOS_OK) {
(void)LOS_TaskDelay(10); /* 10: Waiting for the end of thread execution. */
}
return 0;
}
int pthread_detach(pthread_t thread)
{
if (!IsPthread(thread)) {
UINT32 ret = LOS_TaskDetach((UINT32)thread);
if (ret == LOS_ERRNO_TSK_NOT_JOIN) {
return ESRCH;
} else if (ret != LOS_OK) {
return EINVAL;
}
return ENOSYS;
return 0;
}
void pthread_exit(void *retVal)
{
(void)retVal;
UINT32 intSave;
LosTaskCB *tcb = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
free((PthreadData *)(UINTPTR)tcb->arg);
(void)LOS_TaskDelete(LOS_CurTaskIDGet());
tcb->joinRetval = (UINTPTR)retVal;
PthreadData *pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
intSave = LOS_IntLock();
tcb->taskName = PTHREAD_DEFAULT_NAME;
LOS_IntRestore(intSave);
free(pthreadData);
(void)LOS_TaskDelete(tcb->taskID);
}
int pthread_setname_np(pthread_t thread, const char *name)
{
UINT32 intSave;
LosTaskCB *taskCB = NULL;
char *taskName = LOS_TaskNameGet((UINT32)thread);
if (taskName == NULL || !IsPthread(thread)) {
return EINVAL;
}
if (strnlen(name, PTHREAD_NAMELEN) >= PTHREAD_NAMELEN) {
return ERANGE;
}
(void)strcpy_s(taskName, PTHREAD_NAMELEN, name);
taskCB = OS_TCB_FROM_TID((UINT32)thread);
intSave = LOS_IntLock();
if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) {
LOS_IntRestore(intSave);
return EINVAL;
}
if (taskCB->taskEntry == PthreadEntry) {
(void)strcpy_s(taskName, PTHREAD_NAMELEN, name);
} else {
LOS_IntRestore(intSave);
return EINVAL;
}
LOS_IntRestore(intSave);
return 0;
}

View File

@@ -231,3 +231,23 @@ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
return 0;
}
int sched_get_priority_min(int policy)
{
if (policy != SCHED_RR) {
errno = EINVAL;
return -1;
}
return LOS_TASK_PRIORITY_LOWEST;
}
int sched_get_priority_max(int policy)
{
if (policy != SCHED_RR) {
errno = EINVAL;
return -1;
}
return LOS_TASK_PRIORITY_HIGHEST;
}

View File

@@ -202,18 +202,22 @@ STATIC INT32 ProcessReturnVal(pthread_cond_t *cond, INT32 val)
}
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *absTime)
const struct timespec *ts)
{
UINT32 absTicks;
INT32 ret;
UINT64 absTicks;
const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
struct timespec tp;
UINT64 nseconds;
UINT64 currTime;
if ((cond == NULL) || (mutex == NULL) || (absTime == NULL)) {
if ((cond == NULL) || (mutex == NULL) || (ts == NULL)) {
return EINVAL;
}
if (CondInitCheck(cond)) {
ret = pthread_cond_init(cond, NULL);
if (ret != ENOERR) {
if (ret != 0) {
return ret;
}
}
@@ -222,22 +226,29 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
cond->count++;
(VOID)pthread_mutex_unlock(cond->mutex);
if ((absTime->tv_sec == 0) && (absTime->tv_nsec == 0)) {
return ETIMEDOUT;
}
if (!ValidTimeSpec(absTime)) {
if (!ValidTimeSpec(ts)) {
return EINVAL;
}
absTicks = OsTimeSpec2Tick(absTime);
if (pthread_mutex_unlock(mutex) != ENOERR) {
clock_gettime(CLOCK_REALTIME, &tp);
currTime = (UINT64)tp.tv_sec * OS_SYS_NS_PER_SECOND + tp.tv_nsec;
nseconds = (UINT64)ts->tv_sec * OS_SYS_NS_PER_SECOND + ts->tv_nsec;
if (currTime >= nseconds) {
return ETIMEDOUT;
}
absTicks = ((nseconds - currTime) + nsPerTick - 1) / nsPerTick + 1;
if (absTicks >= UINT32_MAX) {
return EINVAL;
}
if (pthread_mutex_unlock(mutex) != 0) {
PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__);
}
ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, absTicks);
(VOID)LOS_EventClear(&(cond->event), 0);
ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, (UINT32)absTicks);
if (pthread_mutex_lock(mutex) != ENOERR) {
if (pthread_mutex_lock(mutex) != 0) {
PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__);
}

View File

@@ -93,6 +93,7 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex)
return MapError(ret);
}
mutex->handle = _MUX_INVALID_HANDLE;
mutex->magic = 0;
return 0;
}

View File

@@ -42,6 +42,7 @@
#include "los_swtmr.h"
#include "los_tick.h"
#include "los_context.h"
#include "los_interrupt.h"
/* accumulative time delta from discontinuous modify */
STATIC struct timespec g_accDeltaFromSet;
@@ -62,9 +63,6 @@ STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
*/
long timezone = -8 * 60 * 60; // defaults to CST: 8 hours east of the Prime Meridian
/* internal shared struct tm object for localtime and gmtime */
static struct tm g_tm;
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
UINT64 nseconds;
@@ -507,7 +505,8 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result)
struct tm *gmtime(const time_t *timer)
{
return gmtime_r(timer, &g_tm);
static struct tm tm;
return gmtime_r(timer, &tm);
}
struct tm *localtime_r(const time_t *timep, struct tm *result)
@@ -525,7 +524,8 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
struct tm *localtime(const time_t *timer)
{
return localtime_r(timer, &g_tm);
static struct tm tm;
return localtime_r(timer, &tm);
}
static time_t ConvertUtc2Secs(struct tm *tm)

View File

@@ -27,33 +27,34 @@
# 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/config.gni")
static_library("kernel") {
sources = [
"src/los_event.c",
"src/los_init.c",
"src/los_mux.c",
"src/los_queue.c",
"src/los_sched.c",
"src/los_sem.c",
"src/los_sortlink.c",
"src/los_swtmr.c",
"src/los_task.c",
"src/los_tick.c",
"src/los_sched.c",
"src/los_sortlink.c",
"src/mm/los_membox.c",
"src/mm/los_memory.c",
]
include_dirs = [
"include",
"arch/include",
"../components/cpup",
"../components/exchook",
"../components/backtrace",
"../components/power",
"../utils",
"//third_party/bounds_checking_function/include",
"../components/dynlink",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
if ("$board_cpu" == "cortex-m3") {
deps = [ "arch/arm/cortex-m3/gcc/:arch" ]
} else if ("$board_cpu" == "cortex-m4") {
@@ -61,7 +62,11 @@ static_library("kernel") {
} else if ("$board_cpu" == "cortex-m7") {
deps = [ "arch/arm/cortex-m7/gcc/:arch" ]
} else if ("$board_cpu" == "cortex-m33") {
deps = [ "arch/arm/cortex-m33/gcc/:arch" ]
if (enable_ohos_kernel_liteos_m_tz) {
deps = [ "arch/arm/cortex-m33/gcc/TZ:arch" ]
} else {
deps = [ "arch/arm/cortex-m33/gcc/NTZ:arch" ]
}
} else if ("$board_cpu" == "") {
if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") {
deps = [ "arch/risc-v/riscv32/gcc:arch" ]

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
static_library("arch") {
sources = [
"los_context.c",
@@ -37,10 +39,5 @@ static_library("arch") {
"reset_vector.S",
]
include_dirs = [
"../../../../../kernel/arch/include",
"../../../../../kernel/include",
"../../../../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -46,9 +46,15 @@
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
LITE_OS_SEC_TEXT_INIT VOID HalArchInit(VOID)
{
UINT32 ret;
HalHwiInit();
ret = HalTickStart(OsTickHandler);
if (ret != LOS_OK) {
PRINT_ERR("Tick start failed!\n");
}
}
/* ****************************************************************************
@@ -116,14 +122,9 @@ LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)context;
}
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(VOID)
{
(VOID)LOS_IntLock();
UINT32 ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
OsSchedStart();
HalStartToRun();

View File

@@ -29,18 +29,18 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.equ OS_PSR_THUMB, 0x20U
.equ OS_PSR_INT_DIS, 0xC0U
.equ OS_PSR_FIQ_DIS, 0x40U
.equ OS_PSR_IRQ_DIS, 0x80U
.equ OS_PSR_MODE_MASK, 0x1FU
.equ OS_PSR_MODE_USR, 0x10U
.equ OS_PSR_MODE_FIQ, 0x11U
.equ OS_PSR_MODE_IRQ, 0x12U
.equ OS_PSR_MODE_SVC, 0x13U
.equ OS_PSR_MODE_ABT, 0x17U
.equ OS_PSR_MODE_UND, 0x1BU
.equ OS_PSR_MODE_SYS, 0x1FU
.equ OS_PSR_THUMB, 0x20
.equ OS_PSR_INT_DIS, 0xC0
.equ OS_PSR_FIQ_DIS, 0x40
.equ OS_PSR_IRQ_DIS, 0x80
.equ OS_PSR_MODE_MASK, 0x1F
.equ OS_PSR_MODE_USR, 0x10
.equ OS_PSR_MODE_FIQ, 0x11
.equ OS_PSR_MODE_IRQ, 0x12
.equ OS_PSR_MODE_SVC, 0x13
.equ OS_PSR_MODE_ABT, 0x17
.equ OS_PSR_MODE_UND, 0x1B
.equ OS_PSR_MODE_SYS, 0x1F
.global HalStartToRun
.global OsTaskEntryArm

View File

@@ -29,17 +29,17 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.equ OS_PSR_INT_DIS, 0xC0U
.equ OS_PSR_FIQ_DIS, 0x40U
.equ OS_PSR_IRQ_DIS, 0x80U
.equ OS_PSR_MODE_MASK, 0x1FU
.equ OS_PSR_MODE_USR, 0x10U
.equ OS_PSR_MODE_FIQ, 0x11U
.equ OS_PSR_MODE_IRQ, 0x12U
.equ OS_PSR_MODE_SVC, 0x13U
.equ OS_PSR_MODE_ABT, 0x17U
.equ OS_PSR_MODE_UND, 0x1BU
.equ OS_PSR_MODE_SYS, 0x1FU
.equ OS_PSR_INT_DIS, 0xC0
.equ OS_PSR_FIQ_DIS, 0x40
.equ OS_PSR_IRQ_DIS, 0x80
.equ OS_PSR_MODE_MASK, 0x1F
.equ OS_PSR_MODE_USR, 0x10
.equ OS_PSR_MODE_FIQ, 0x11
.equ OS_PSR_MODE_IRQ, 0x12
.equ OS_PSR_MODE_SVC, 0x13
.equ OS_PSR_MODE_ABT, 0x17
.equ OS_PSR_MODE_UND, 0x1B
.equ OS_PSR_MODE_SYS, 0x1F
.equ OS_EXCEPT_RESET, 0x00
.equ OS_EXCEPT_UNDEF_INSTR, 0x01

View File

@@ -58,7 +58,7 @@ Input : none
output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
{
UINT32 intSave = LOS_IntLock();
UINT32 value;
@@ -67,7 +67,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
value &= ~(OS_TIMER_32K_CLK_BIT);
WRITE_UINT32(value, OS_TIMER_CLK_PWD_ADDR);
value = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
value = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX;
WRITE_UINT32(value, OS_TIMER_PERIOD_REG_ADDR);
READ_UINT32(value, OS_TIMER_CTL_REG_ADDR);
@@ -140,15 +140,11 @@ WEAK VOID HalTickUnlock(VOID)
WRITE_UINT32(value, OS_TIMER_CTL_REG_ADDR);
}
VOID HalEnterSleep(LOS_SysSleepEnum sleep)
UINT32 HalEnterSleep(VOID)
{
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
if (sleep == OS_SYS_DEEP_SLEEP) {
OsSchedToSleep();
}
#endif
dsb();
wfi();
isb();
return LOS_OK;
}

View File

@@ -29,15 +29,15 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.equ CPSR_IRQ_DISABLE, 0x80U
.equ CPSR_FIQ_DISABLE, 0x40U
.equ CPSR_THUMB_ENABLE, 0x20U
.equ CPSR_USER_MODE, 0x10U
.equ CPSR_FIQ_MODE, 0x11U
.equ CPSR_IRQ_MODE, 0x12U
.equ CPSR_SVC_MODE, 0x13U
.equ CPSR_ABT_MODE, 0x17U
.equ CPSR_UNDEF_MODE, 0x1BU
.equ CPSR_IRQ_DISABLE, 0x80
.equ CPSR_FIQ_DISABLE, 0x40
.equ CPSR_THUMB_ENABLE, 0x20
.equ CPSR_USER_MODE, 0x10
.equ CPSR_FIQ_MODE, 0x11
.equ CPSR_IRQ_MODE, 0x12
.equ CPSR_SVC_MODE, 0x13
.equ CPSR_ABT_MODE, 0x17
.equ CPSR_UNDEF_MODE, 0x1B
.global __exc_stack_top
.global __irq_stack_top

View File

@@ -521,25 +521,6 @@ typedef struct TagExcContext {
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/**
* @ingroup los_arch_interrupt
* @brief: Exception initialization.
*
* @par Description:
* This API is used to configure the exception function vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param uwArraySize [IN] Memory size of exception.
*
* @retval: None
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
VOID OsExcInit(VOID);
VOID HalExcNMI(VOID);
VOID HalExcHardFault(VOID);
VOID HalExcMemFault(VOID);

View File

@@ -38,6 +38,7 @@
#include "los_sched.h"
#include "los_interrupt.h"
#include "los_arch_timer.h"
#include "los_debug.h"
/* ****************************************************************************
Function : HalArchInit
@@ -46,9 +47,15 @@
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
LITE_OS_SEC_TEXT_INIT VOID HalArchInit(VOID)
{
UINT32 ret;
HalHwiInit();
ret = HalTickStart(OsTickHandler);
if (ret != LOS_OK) {
PRINT_ERR("Tick start failed!\n");
}
}
/* ****************************************************************************
@@ -147,13 +154,9 @@ LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)context;
}
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(VOID)
{
(VOID)LOS_IntLock();
UINT32 ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
OsSchedStart();
HalStartToRun();
return LOS_OK; /* never return */

View File

@@ -195,10 +195,10 @@ _hwiActiveCheck
RBIT R2, R3
CLZ R2, R2
AND R12, R12, #1
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as uwPid
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as pid
_ExcInMSP
CMP LR, #0XFFFFFFED
CMP LR, #0xFFFFFFE9
BNE _NoFloatInMsp
ADD R3, R13, #104
PUSH {R3}

View File

@@ -273,6 +273,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define UNALIGNFAULT (1 << 3)
#define HARDFAULT_IRQN (-13)
ExcInfo g_excInfo = {0};
@@ -520,8 +521,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
#else
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
#endif
return;
}

View File

@@ -45,7 +45,7 @@ Input : none
output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
{
UINT32 ret;
@@ -66,7 +66,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
g_sysClock = OS_SYS_CLOCK;
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
ret = SysTick_Config(g_cyclesPerTick);
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
if (ret == 1) {
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
}
@@ -85,10 +85,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime)
WEAK UINT64 HalGetTickCycle(UINT32 *period)
{
UINT32 hwCycle;
UINT32 hwCycle = 0;
UINT32 intSave = LOS_IntLock();
UINT32 val = SysTick->VAL;
*period = SysTick->LOAD;
hwCycle = *period - SysTick->VAL;
if (val != 0) {
hwCycle = *period - val;
}
LOS_IntRestore(intSave);
return (UINT64)hwCycle;
}

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
static_library("arch") {
sources = [
"los_context.c",
@@ -36,10 +38,5 @@ static_library("arch") {
"los_timer.c",
]
include_dirs = [
"../../../../../kernel/arch/include",
"../../../../../kernel/include",
"../../../../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
static_library("arch") {
sources = [
"los_context.c",
@@ -36,10 +38,5 @@ static_library("arch") {
"los_timer.c",
]
include_dirs = [
"../../../../../../kernel/arch/include",
"../../../../../../kernel/include",
"../../../../../../utils",
"//third_party/bounds_checking_function/include",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -521,31 +521,12 @@ typedef struct TagExcContext {
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/**
* @ingroup los_arch_interrupt
* @brief: Exception initialization.
*
* @par Description:
* This API is used to configure the exception function vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param uwArraySize [IN] Memory size of exception.
*
* @retval: None
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
VOID OsExcInit(VOID);
VOID HalExcNMI(VOID);
VOID HalExcHardFault(VOID);
VOID HalExcMemFault(VOID);
VOID HalExcBusFault(VOID);
VOID HalExcUsageFault(VOID);
VOID HalExcSvcCall(VOID);
VOID HalSVCHandler(VOID);
VOID HalHwiInit();

View File

@@ -37,6 +37,7 @@
#include "los_sched.h"
#include "los_interrupt.h"
#include "los_arch_timer.h"
#include "los_debug.h"
/* ****************************************************************************
Function : HalArchInit
@@ -45,9 +46,15 @@
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
LITE_OS_SEC_TEXT_INIT VOID HalArchInit(VOID)
{
UINT32 ret;
HalHwiInit();
ret = HalTickStart(OsTickHandler);
if (ret != LOS_OK) {
PRINT_ERR("Tick start failed!\n");
}
}
/* ****************************************************************************
@@ -146,13 +153,9 @@ LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)context;
}
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(VOID)
{
(VOID)LOS_IntLock();
UINT32 ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
OsSchedStart();
HalStartToRun();
return LOS_OK; /* never return */

View File

@@ -41,7 +41,7 @@
.global HalExcMemFault
.global HalExcBusFault
.global HalExcUsageFault
.global HalExcSvcCall
.global HalSVCHandler
.extern HalExcHandleEntry
.extern g_uwExcTbl
@@ -148,9 +148,9 @@ osHFExcCommonBMU:
B osExcDispatch
.fnend
.type HalExcSvcCall, %function
.global HalExcSvcCall
HalExcSvcCall:
.type HalSVCHandler, %function
.global HalSVCHandler
HalSVCHandler:
.fnstart
.cantunwind
TST LR, #0x4
@@ -268,7 +268,7 @@ _hwiActiveCheck:
RBIT R2, R3
CLZ R2, R2
AND R12, R12, #1
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as uwPid
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as pid
.fnend
.type _ExcInMSP, %function
@@ -276,16 +276,13 @@ _hwiActiveCheck:
_ExcInMSP:
.fnstart
.cantunwind
CMP LR, #0XFFFFFFED
CMP LR, #0xFFFFFFE9
BNE _NoFloatInMsp
ADD R3, R13, #104
PUSH {R3}
MRS R12, PRIMASK // store message-->exc: disable int?
PUSH {R4-R12} // store message-->exc: {R4-R12}
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
VPUSH {D8-D15}
#endif
B _handleEntry
.fnend
@@ -341,10 +338,7 @@ _hwiActiveCheckNext:
MRS R12, PRIMASK
PUSH {R4-R12}
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
VPUSH {D8-D15}
#endif
// copy auto saved task register

View File

@@ -263,6 +263,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define UNALIGNFAULT (1 << 3)
#define HARDFAULT_IRQN (-13)
ExcInfo g_excInfo = {0};
@@ -497,7 +498,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
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[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;
@@ -510,8 +511,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
#else
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
#endif
return;
}

View File

@@ -44,7 +44,7 @@ Input : none
output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
{
UINT32 ret;
@@ -65,7 +65,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
g_sysClock = OS_SYS_CLOCK;
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
ret = SysTick_Config(g_cyclesPerTick);
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
if (ret == 1) {
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
}
@@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime)
WEAK UINT64 HalGetTickCycle(UINT32 *period)
{
UINT32 hwCycle;
UINT32 hwCycle = 0;
UINT32 intSave = LOS_IntLock();
UINT32 val = SysTick->VAL;
*period = SysTick->LOAD;
hwCycle = *period - SysTick->VAL;
if (val != 0) {
hwCycle = *period - val;
}
LOS_IntRestore(intSave);
return (UINT64)hwCycle;
}

View File

@@ -27,6 +27,8 @@
# 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/config.gni")
static_library("arch") {
sources = [
"non_secure/los_context.c",
@@ -35,16 +37,12 @@ static_library("arch") {
"non_secure/los_interrupt.c",
"non_secure/los_timer.c",
"non_secure/los_trustzone.c",
"secure/los_secure_context.c",
"secure/los_secure_context_asm.S",
"secure/los_secure_heap.c",
]
include_dirs = [
"../../../../../../kernel/arch/include",
"../../../../../../kernel/arch/include",
"../../../../../../kernel/include",
"../../../../../../utils",
"//third_party/bounds_checking_function/include",
"./non_secure",
"./secure",
]
configs += [ "$LITEOSTOPDIR:los_config" ]
}

View File

@@ -521,31 +521,12 @@ typedef struct TagExcContext {
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/**
* @ingroup los_arch_interrupt
* @brief: Exception initialization.
*
* @par Description:
* This API is used to configure the exception function vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param uwArraySize [IN] Memory size of exception.
*
* @retval: None
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
VOID OsExcInit(VOID);
VOID HalExcNMI(VOID);
VOID HalExcHardFault(VOID);
VOID HalExcMemFault(VOID);
VOID HalExcBusFault(VOID);
VOID HalExcUsageFault(VOID);
VOID HalExcSvcCall(VOID);
VOID HalSVCHandler(VOID);
VOID HalHwiInit();

View File

@@ -37,6 +37,7 @@
#include "los_sched.h"
#include "los_interrupt.h"
#include "los_arch_timer.h"
#include "los_debug.h"
/* ****************************************************************************
Function : HalArchInit
@@ -45,9 +46,15 @@
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
LITE_OS_SEC_TEXT_INIT VOID HalArchInit(VOID)
{
UINT32 ret;
HalHwiInit();
ret = HalTickStart(OsTickHandler);
if (ret != LOS_OK) {
PRINT_ERR("Tick start failed!\n");
}
}
/* ****************************************************************************
@@ -150,13 +157,9 @@ LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)context;
}
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(VOID)
{
(VOID)LOS_IntLock();
UINT32 ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
OsSchedStart();
HalStartToRun();
return LOS_OK; /* never return */

View File

@@ -48,8 +48,6 @@
.type HalStartFirstTask, %function
.global HalStartFirstTask
HalStartFirstTask:
.fnstart
.cantunwind
MOV R0, #2
MSR CONTROL, R0
@@ -77,7 +75,6 @@ __DisabledFPU1:
MSR PSP, R12
CPSIE I
BX R3
.fnend
.type HalIntLock, %function
.global HalIntLock

View File

@@ -41,7 +41,6 @@
.global HalExcMemFault
.global HalExcBusFault
.global HalExcUsageFault
.global HalExcSvcCall
.extern HalExcHandleEntry
.extern g_uwExcTbl
@@ -148,21 +147,6 @@ osHFExcCommonBMU:
B osExcDispatch
.fnend
.type HalExcSvcCall, %function
.global HalExcSvcCall
HalExcSvcCall:
.fnstart
.cantunwind
TST LR, #0x4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
LDR R1, [R0,#24]
LDRB R0, [R1,#-2]
MOV R1, #0
B osExcDispatch
.fnend
.type HalExcBusFault, %function
.global HalExcBusFault
HalExcBusFault:
@@ -268,7 +252,7 @@ _hwiActiveCheck:
RBIT R2, R3
CLZ R2, R2
AND R12, R12, #1
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as uwPid
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as pid
.fnend
.type _ExcInMSP, %function
@@ -276,16 +260,13 @@ _hwiActiveCheck:
_ExcInMSP:
.fnstart
.cantunwind
CMP LR, #0XFFFFFFED
CMP LR, #0xFFFFFFE9
BNE _NoFloatInMsp
ADD R3, R13, #104
PUSH {R3}
MRS R12, PRIMASK // store message-->exc: disable int?
PUSH {R4-R12} // store message-->exc: {R4-R12}
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
VPUSH {D8-D15}
#endif
B _handleEntry
.fnend
@@ -341,10 +322,7 @@ _hwiActiveCheckNext:
MRS R12, PRIMASK
PUSH {R4-R12}
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
VPUSH {D8-D15}
#endif
// copy auto saved task register

View File

@@ -263,6 +263,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define UNALIGNFAULT (1 << 3)
#define HARDFAULT_IRQN (-13)
ExcInfo g_excInfo = {0};
@@ -497,7 +498,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
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[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;
@@ -510,8 +511,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
#else
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
#endif
return;
}

View File

@@ -44,7 +44,7 @@ Input : none
output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
{
UINT32 ret;
@@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime)
WEAK UINT64 HalGetTickCycle(UINT32 *period)
{
UINT32 hwCycle;
UINT32 hwCycle = 0
UINT32 intSave = LOS_IntLock();
UINT32 val = SysTick->VAL;
*period = SysTick->LOAD;
hwCycle = *period - SysTick->VAL;
if (val != 0) {
hwCycle = *period - val;
}
LOS_IntRestore(intSave);
return (UINT64)hwCycle;
}

View File

@@ -34,6 +34,7 @@
#include "los_secure_context.h"
#include "los_debug.h"
#include "los_arch_context.h"
#include "los_interrupt.h"
OsSecureContext *g_secureContext = NULL;
@@ -69,6 +70,7 @@ VOID LOS_SecureContextAlloc(UINT32 secureStackSize)
return;
}
LOS_ASSERT((__get_IPSR() == 0) && (__get_PRIMASK() == 0));
secureStackSize = LOS_Align(secureStackSize, sizeof(UINTPTR));
HalSVCSecureContextAlloc(secureStackSize);
}

View File

@@ -63,5 +63,3 @@ extern VOID HalSecureContextSaveAsm(OsSecureContext *secureContext);
#endif /* __cplusplus */
#endif

View File

@@ -94,7 +94,7 @@ HalSecureContextSaveAsm:
MOV R0, #0
MSR PSPLIM, R0 /* No PSPLIM for the current task. */
MSR PSP, R0 /* No secure stack for the current task. */
.fnend
__ThreadMode:
BX LR
.fnend

View File

@@ -34,7 +34,7 @@
#include "los_config.h"
#include "los_list.h"
STATIC UINT8 g_secureHeap[LOSCFG_SECURE_HEAP_SIZE] = {0};
STATIC UINT8 __attribute__((aligned(0x4)))g_secureHeap[LOSCFG_SECURE_HEAP_SIZE] = {0};
STATIC LOS_DL_LIST g_secureHeapFreeList = {NULL, NULL};
struct OsSecureHeapNode {

Some files were not shown because too many files have changed in this diff Show More