鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙看这篇或许真的够了 | 百篇博客分析HarmonyOS源码 | v50.01
百万汉字注解 >> 精读鸿蒙源码,中文注解分析, 深挖地基工程,大脑永久记忆,四大码仓每日同步更新< gitee | github | csdn | coding >
百篇博客分析 >> 故事说内核,问答式导读,生活式比喻,表格化说明,图形化展示,主流站点定期更新中< oschina | 51cto | csdn | harmony >
编译鸿蒙
因对sourceinsight的爱不释手,所以选择了在windows环境下编译鸿蒙.
本篇记录下编译的过程,以备后续不用再去一大堆无效的误导式软文中搜寻芝麻大点有用的信息,那样真挺费时的.
编译环境
-
先安装 Docker Desktop 下载windows版本一直下一步.
-
在windows下拉取
openharmony-docker
官方镜像,Docker方式获取编译环境 强烈推荐这么做.docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3
2.36G, 拉取看网速, 大概10分钟后成功了,有了镜像
PS E:\harmony\kernel_liteos_a_note> docker images REPOSITORY TAG IMAGE ID CREATED SIZE swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker 0.0.3 50d0aa6ea9ba 2 weeks ago 2.36GB
-
vscode对docker的管理插件非常的强大,管理镜像和容器的工作就交给它了.
-
启动docker,创建好容器,本文的选择是这样的,当然大家可以灵活处理,命名.
容器创建成功后可以
inspect
查看到绑定的目录."HostConfig": { "Binds": [ "E:\\harmony\\code-1.0:/home/harmony", "E:\\harmony\\docker:/home/docker" ],
本文这样做的目的为了在windows上能方便的查看文件.
harmony
目录用于下载编译源码目录,另外一个docker
放其他无关文件 -
repo方式下载源码
root@5e3abe332c5a:/home/harmony#repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify root@5e3abe332c5a:/home/harmony#repo sync -c
这个过程也是比网速.慢慢等吧.
-
下载完成之后的样子
root@5e3abe332c5a:/home/harmony# ls applications base build build.py developtools device docs domains drivers foundation kernel ohos_config.json prebuilts test third_party utils vendor
编译过程
-
在源码的根目录执行如下命令安装hb
root@5e3abe332c5a:/home/harmony#python3 -m pip install --user build/lite
-
设置编译路径,选择当前路径
root@5e3abe332c5a:/home/harmony#hb set [OHOS INFO] Input code path: . OHOS Which product do you need? (Use arrow keys) hisilicon ❯ ipcamera_hispark_aries wifiiot_hispark_pegasus ipcamera_hispark_taurus
-
直接回车,代表选择了ipcamera_hispark_aries,这三个对应平台的关系如下
Hi3518:ipcamera_hispark_aries@hisilicon Hi3861:wifiiot_hispark_pegasus@hisilicon Hi3516:ipcamera_hispark_taurus@hisilicon
-
执行编译,过程大概20分钟
root@5e3abe332c5a:/home/harmony#hb build -f
-
查看编译结果
每个的目录含义如下
目录名 描述 applications 应用程序样例,包括wifi-iot,camera等 base 基础软件服务子系统集&硬件服务子系统集 build 组件化编译、构建和配置脚本 docs 说明文档 domains 增强软件服务子系统集 drivers 驱动子系统 foundation 系统基础能力子系统集 kernel 内核子系统 prebuilts 编译器及工具链子系统 test 测试子系统 third_party 开源第三方组件 utils 常用的工具集 vendor 厂商提供的软件 build.py 编译脚本文件 out 编译后生成
编译输出
out
为编译结果输出目录
out/hispark_aries/ipcamera_hispark_aries
root@5e3abe332c5a:/home/harmony/out/hispark_aries/ipcamera_hispark_aries# ls args.gn build.log bundle_daemon_tool.map dev_tools libs NOTICE_FILE OHOS_Image.asm rootfs suites toggleButtonTest.map userfs vendor bin build.ninja config etc liteos.bin obj OHOS_Image.bin rootfs_jffs2.img test toolchain.ninja userfs_jffs2.img bm_tool.map build.ninja.d data foundation.map media_server.map OHOS_Image OHOS_Image.map server.map test_info unstripped usr
系列篇会详细讲解启动过程,此处进入bin目录瞅瞅都有些啥好宝贝.
root@5e3abe332c5a:/home/harmony/out/hispark_aries/ipcamera_hispark_aries/bin# ls ai_server module_ActsAbilityMgrTest.bin module_ActsGraphVersionTest.bin module_ActsJFFS2CapabilityTest.bin module_ActsNFSTest.bin module_ActsSurfaceTest.bin os_dump apphilogcat module_ActsBootstrapTest.bin module_ActsHeapBaseTest.bin module_ActsJFFS2DACTest.bin module_ActsParameterTest.bin module_ActsSysApiTest.bin query.bin appspawn module_ActsBundleMgrTest.bin module_ActsHilogTest.bin module_ActsJFFS2Test.bin module_ActsPMSTest.bin module_ActsTimeApiTest.bin shell bundle_daemon module_ActsColorTest.bin module_ActsIoApiTest.bin module_ActsKvStoreTest.bin module_ActsProcessApiTest.bin module_ActsTransformTest.bin tftp CalcSubTest.bin module_ActsDyloadTest.bin module_ActsIpcMqTest.bin module_ActsListTest.bin module_ActsRectTest.bin module_ActsUiInterfaceTest1.bin wms_server foundation module_ActsFutexApiTest.bin module_ActsIpcPipeTest.bin module_ActsLwipTest.bin module_ActsSamgrTest.bin module_ActsUtilApiTest.bin hilogcat module_ActsGeometyr2dTest.bin module_ActsIpcSemTest.bin module_ActsMathApiTest.bin module_ActsSchedApiTest.bin module_ActsVFATCapabilityTest.bin init module_ActsGraphicMathTest.bin module_ActsIpcShmTest.bin module_ActsMemApiTest.bin module_ActsSecurityDataTest.bin module_ActsVFATDACTest.bin media_server module_ActsGraphMemApiTest.bin module_ActsIpcSignalTest.bin module_ActsNetTest.bin module_ActsSoftBusTest.bin module_ActsVFATTest.bin
这难道都是ELF格式可执行程序? 用readelf
命令试下shell
就知道了.果然是shell程序,加载它将创建激动人心的shell
进程
root@5e3abe332c5a:/home/harmony/out/hispark_aries/ipcamera_hispark_aries/bin# readelf -h shell ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: ARM Version: 0x1 Entry point address: 0x1000 Start of program headers: 52 (bytes into file) Start of section headers: 25268 (bytes into file) Flags: 0x5000200, Version5 EABI, soft-float ABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 11 Size of section headers: 40 (bytes) Number of section headers: 27 Section header string table index: 26
再随便选择一个module_ActsListTest.bin
看下,这些是鸿蒙用于测试的代码生成的.也是一个个的独立程序.可以在工程里找到他们的身影list_test.cpp
,ActsListTest.json
等文件
root@5e3abe332c5a:/home/harmony/out/hispark_aries/ipcamera_hispark_aries/bin# readelf -h module_ActsListTest.bin ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: ARM Version: 0x1 Entry point address: 0xb000 Start of program headers: 52 (bytes into file) Start of section headers: 172256 (bytes into file) Flags: 0x5000200, Version5 EABI, soft-float ABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 11 Size of section headers: 40 (bytes) Number of section headers: 27 Section header string table index: 26
解读 仔细比较下这两个ELF的头文件有哪里是不一样的
Entry point address: 0x1000 Entry point address: 0xb000
这是程序的入口地址,也就是大家熟悉的main()函数的地址,用户程序是从这个位置开始执行.
readelf
的功能很强大,有兴趣的可以玩下这个命令,看看elf里面究竟装的啥.
root@5e3abe332c5a:/home/harmony/out/hispark_aries/ipcamera_hispark_aries/bin# readelf -help readelf: option requires an argument -- 'p' Usage: readelf <option(s)> elf-file(s) Display information about the contents of ELF format files Options are: -a --all Equivalent to: -h -l -S -s -r -d -V -A -I -h --file-header Display the ELF file header -l --program-headers Display the program headers --segments An alias for --program-headers -S --section-headers Display the sections' header --sections An alias for --section-headers -g --section-groups Display the section groups -t --section-details Display the section details -e --headers Equivalent to: -h -l -S -s --syms Display the symbol table --symbols An alias for --syms --dyn-syms Display the dynamic symbol table -n --notes Display the core notes (if present) -r --relocs Display the relocations (if present) -u --unwind Display the unwind info (if present) -d --dynamic Display the dynamic section (if present) -V --version-info Display the version sections (if present) -A --arch-specific Display architecture specific information (if any) -c --archive-index Display the symbol/file index in an archive -D --use-dynamic Use the dynamic section info when displaying symbols -x --hex-dump=<number|name> Dump the contents of section <number|name> as bytes -p --string-dump=<number|name> Dump the contents of section <number|name> as strings -R --relocated-dump=<number|name> Dump the contents of section <number|name> as relocated bytes -z --decompress Decompress section before dumping it -w[lLiaprmfFsoRtUuTgAckK] or --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames, =frames-interp,=str,=loc,=Ranges,=pubtypes, =gdb_index,=trace_info,=trace_abbrev,=trace_aranges, =addr,=cu_index,=links,=follow-links] Display the contents of DWARF debug sections --dwarf-depth=N Do not display DIEs at depth N or greater --dwarf-start=N Display DIEs starting with N, at the same depth or deeper --ctf=<number|name> Display CTF info from section <number|name> --ctf-parent=<number|name> Use section <number|name> as the CTF parent --ctf-symbols=<number|name> Use section <number|name> as the CTF external symtab --ctf-strings=<number|name> Use section <number|name> as the CTF external strtab -I --histogram Display histogram of bucket list lengths -W --wide Allow output width to exceed 80 characters @<file> Read options from <file> -H --help Display this information -v --version Display the version number of readelf
具体的加载过程和elf格式后续有专门的篇幅详细介绍,此处不做说明.
用户进程
去掉bin目录下的干扰*.bin,剩下的就是平台(Hi3518)需要内核创建的用户态进程.
进程ID | 进程名称 | 进程优先级 | 说明 | 备注 |
---|---|---|---|---|
1 | init | 28 | 用户态祖宗进程 | |
ai_server | AI业务子系统 | https://gitee.com/openharmony/ai_engine | ||
media_server | 播放模块框架实现 | https://gitee.com/openharmony/multimedia_media_lite | ||
3 | shell | 9 | 用于窥视内核的窗口 | |
apphilogcat | 提供DFX子系统在轻量系统和小型系统的流水日志功能 | https://gitee.com/openharmony/hiviewdfx_hilog_lite | ||
tftp | ||||
appspawn | 应用孵化模块appspawn进程 | https://gitee.com/openharmony/startup_appspawn_lite | ||
wms_server | 窗口管理服务 | https://gitee.com/openharmony/graphic_wms | ||
bundle_daemon | 用户程序框架内部使用的工具接口 | https://gitee.com/openharmony/appexecfwk_appexecfwk_lite | ||
foundation | foundation系统进程 | https://gitee.com/openharmony/distributedschedule_safwk_lite | ||
hilogcat | ||||
os_dump |
在整个项目工程中能轻易找到他们的入口函数.比如appspawn
的启动过程
//base\startup\appspawn_lite\services\src\main.c int main(int argc, char * const argv[]) { sleep(1); HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] main, enter."); // 1. ipc module init HOS_SystemInit(); // 2. register signal for SIGCHLD SignalRegist(); // 3. keep process alive HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] main, entering wait."); while (1) { // pause only returns when a signal was caught and the signal-catching function returned. // pause only returns -1, no need to process the return value. (void)pause(); } }
鸿蒙将服务做成了组件,为最上层的应用程度提供管理/工具类的服务.但这些都是framework层的工作,超出了内核源码分析的范畴.希望后续有机会能去剖析它们.
鸿蒙源码百篇博客 往期回顾
-
在给 鸿蒙内核源码加中文注释 过程中,整理出以下文章.内容立足源码,常以生活场景打比方尽可能多的将内核知识点置入某种场景,具有画面感.百篇博客绝不是百度教条式的在说一堆诘屈聱牙的概念,那没什么意思.更希望让内核变得栩栩如生,倍感亲切.确实有难度,自不量力,但已经出发,回头已是不可能的了.:P
-
写文章比写代码累多了,越深入研究,越觉得没写好,所以文章和注解会反复修正, .xx代表修改的次数, 将持续完善源码注解和文档内容,精雕细琢,言简意赅, 尽全力打磨精品内容.
-
v45.xx (fork篇) | fork是如何做到调用一次,返回两次的 ? < csdn | 51cto | harmony >
-
v38.xx (寄存器篇) | arm所有寄存器一网打尽,不再神秘 < csdn | 51cto | harmony >
-
v35.xx (时间管理篇) | tick是操作系统的基本时间单位 < csdn | 51cto | harmony >
-
v33.xx (消息队列篇) | 进程间如何异步解耦传递大数据 ? < csdn | 51cto | harmony >
-
v19.xx (位图管理篇) | 为何进程和线程优先级都是32个? < csdn | 51cto | harmony >
参与贡献
-
Fork 本仓库 >> 新建 Feat_xxx 分支 >> 提交代码注解 >> 新建 Pull Request
喜欢请「点赞+关注+收藏」
-
各大站点搜 「鸿蒙内核源码分析」.欢迎转载,请注明出处.
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
通过Wireshark理解Nmap扫描
自从上次女神节征文获得一盒巧克力之后,我总是盼望着再来一个什么征文。那时正是写得顺手的时候,仿佛觉得自己提笔就是一本爱情小说。奈何幻觉它也是有时效性的,巧克力吃完之后,我又变回到一个技术作者的身份,还是一名文思枯竭的作者。就在这时,51CTO又有征文活动,不参加吧,舍不得京东的购书卷,参加吧,这枯竭状态能挤出什么来?两难之时,远处知识的海洋里泛起玲玲波光,定睛一看,好家伙,Wireshark!就是它了,京东的购书卷就靠它了!让我们先来看看,外国的技术人员怎么使用Wireshark的,之后的博客中,我们再讨论自己的想法。 在本文中,您将学习当***者使用NMAP端口扫描方法扫描目标时,如何使用Wireshark捕获网络数据包。 在这里,您将注意到Wireshark如何捕获用于打开和关闭端口的不同网络流量数据包。 TCP扫描 Tcp扫描将扫描TCP端口(例如端口22、21、23、445等),并通过源端口和目标端口之间的三向握手连接确保侦听端口(打开)。如果端口是开放的,则源发出带有SYN数据包的请求,响应目标发送SYN,ACK数据包,然后源发送ACK数据包,最后,源再次发送RST,ACK...
- 下一篇
终于有人将金融风险管理讲明白了
互联网金融是传统金融业务与新兴互联网技术结合的一个交叉领域,例如互联网公司开展的金融业务,或者金融机构的线上化服务,都属于互联网金融的范畴。与传统金融行业的线下模式相比,互联网金融以网络和通信技术为载体,受众群体更广,辐射场景更多,服务效率更高,符合“普惠金融”的核心理念。然而在互联网金融业务的开展过程中,由于机构人员与客户并没有实际接触,因此金融风险无处不在。在此背景下,依托于大数据和机器学习的智能风控与反欺诈技术应运而生,为互联网金融行业的健康发展锦上添花。 作者:蔡主希 来源:华章计算机(hzbook_jsj) 1互联网金融的发展和现状 广义的互联网金融(简称“互金”)包括互联网贷款、第三方支付、众筹、数字货币、网上银行等多种商业模式。其中互联网贷款无疑是起步最早且体量最大的一个场景,截止到2018年末,我国互联网贷款余额超万亿,覆盖了上百家金融机构。可以说国内互联网金融的发展史也是互联网贷款的兴衰史。 国内互联网贷款起源于2007年,当时的背景是中国经济发展达到了一个新高度,消费金融、小微金融需求空前旺盛;同年11月阿里巴巴在港交所上市,标志着国内互联网行业已经初具规模。在此...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- Hadoop3单机部署,实现最简伪集群
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Docker使用Oracle官方镜像安装(12C,18C,19C)