10 开源鸿蒙中芯片与开发板对应的源码(硬件相关的部分)
温馨提示:这篇文章已超过371天没有更新,请注意相关的内容是否还可用!
开源鸿蒙中芯片与开发板对应的源码(硬件相关的部分)
作者 | 将狼才鲸 |
---|---|
日期 | 2024-03-20 |
-
开源鸿蒙通过芯片仓存放指定芯片和指定开发板的代码,硬件相关的代码和纯逻辑代码是分开存放的
(图片来源网络,侵删)- 源码模块的组织结构在manifest这个Git仓库,这也是拉取源码时的顶层仓库:https://gitee.com/openharmony/manifest
- 平台仓都组织在manifests/ohos/ohos.xml文件中,而芯片仓都组织在manifests/chipsets/目录下
- 每个芯片平台会在device和vendor目录下创建相应的仓,把这类仓称为芯片仓,其它的仓称为平台仓,芯片仓可能会随着硬件的演进而逐渐废弃,生命周期相对较短
- default.xml由ohos/ohos.xml和chipsets/all.xml组成,是所有平台仓和芯片仓的集合;可以通过缺省参数下载所有代码仓(全量代码)
- chipsets/chipsetN/chipsetN-detail.xml是单个芯片平台所引入的仓集合
- 每个开发板的chipsets/chipsetN/chipsetN-detail.xml里主要包括device/soc,device/board以及vendor相关仓
- 官方支持的开发板和模拟器种类-编译形态整体说明
-
因为硬件各种各样,为了学习方便,这里选择几个ARM核的QEMU模拟器(不使用硬件,使用虚拟开发板)
- 编译参数(产品名):qemu_arm_linux_headless,开发板名称:qemu-arm-linux,芯片名称:qemu,芯片内核:ARM Cortex-A,系统类型:标准,系统内核:linux,开发板参数:https://gitee.com/openharmony/vendor_ohemu/blob/master/qemu_arm_linux_headless/config.json
- 编译参数(产品名):qemu_small_system_demo,开发板名称:arm_virt,芯片名称:qemu,芯片内核:ARM Cortex-A,系统类型:小型,系统内核:liteos_a,开发板参数:https://gitee.com/openharmony/vendor_ohemu/blob/master/qemu_small_system_demo/config.json
- 编译参数(产品名):qemu_mini_system_demo,开发板名称:arm_mps2_an386,芯片名称:qemu,芯片内核:ARM Cortex-M4,系统类型:轻型,系统内核:liteos_m,开发板参数:https://gitee.com/openharmony/vendor_ohemu/blob/master/qemu_mini_system_demo/config.json
-
verdor芯片仓的开发板配置
- https://gitee.com/openharmony/vendor_ohemu/tree/master/qemu_arm_linux_headless
- https://gitee.com/openharmony/vendor_ohemu/tree/master/qemu_small_system_demo
- https://gitee.com/openharmony/vendor_ohemu/tree/master/qemu_mini_system_demo
-
device芯片仓的源码和配置
- https://gitee.com/openharmony/device_qemu/tree/master/arm_virt/linux
- https://gitee.com/openharmony/device_qemu/tree/master/arm_virt/liteos_a
- https://gitee.com/openharmony/device_qemu/tree/master/arm_virt/liteos_a_mini
- https://gitee.com/openharmony/device_qemu/tree/master/arm_mps2_an386含上电后的初始化代码
- https://gitee.com/openharmony/device_qemu/tree/master/drivers
-
参考网址:
- QEMU Arm MPS2 and MPS3 boards
源码框架
-
以下配置文件指示了你要下载哪些Git仓库,并将他们拉取到哪个子文件夹下,拉取完成后才会构成完整的开源鸿蒙源码
- https://gitee.com/openharmony/manifest/blob/master/default.xml 分为平台仓和芯片仓
- https://gitee.com/openharmony/manifest/blob/master/ohos/ohos.xml 所有与硬件无关的平台仓,按group类型拉取代码,是你的group则拉取,不是则忽略
- 例如,将 https://gitee.com/openharmony/kernel_liteos_m 仓库拉取到 kernel/liteos_m 目录下
- https://gitee.com/openharmony/manifest/blob/master/chipsets/all.xml 所有与硬件相关的芯片仓,按芯片名称分类
- https://gitee.com/openharmony/manifest/blob/master/chipsets/qemu.xml 选中一款芯片,例如选中qemu这款虚拟芯片,平台仓还是选中全量,芯片仓则选中特有的
- https://gitee.com/openharmony/manifest/blob/master/chipsets/qemu/qemu.xml qemu这款虚拟芯片的芯片仓代码
- 将 https://gitee.com/openharmony/vendor_ohemu 这个仓库拉取到 vendor/ohemu 文件夹下,含模块依赖关系、操作系统的配置参数、OEM-ID-密钥源码
- 将 https://gitee.com/openharmony/device_qemu 这个仓库拉取到 device/qemu 文件夹下,包含芯片相关驱动底层硬件相关部分
-
以ARM Cortex-M内核的arm_mps2_an386开发板为例,简述源码结构
-
openHarmony\device\qemu\arm_mps2_an386\liteos_m\board\startup.s(源码网址https://gitee.com/openharmony/device_qemu/blob/master/arm_mps2_an386/liteos_m/board/startup.s) 中描述了芯片上电后的第二行代码:复位中断(第一行代码RAM 0地址的复位中断融合到编译器里面去了),在复位中断中跳转到C语言的main函数
.global Reset_Handler .section .text .type Reset_Handler, %function Reset_Handler: ldr r0, =__bss_start ldr r1, =__bss_end mov r2, #0 bss_loop: str r2, [r0, #0] add r0, r0, #4 subs r3, r1, r0 bne bss_loop ldr sp, =__irq_stack_top b main .size Reset_Handler, .-Reset_Handler
- openHarmony\device\qemu\arm_mps2_an386\liteos_m\board\main.c(源码网址https://gitee.com/openharmony/device_qemu/blob/master/arm_mps2_an386/liteos_m/board/main.c) 中在main函数里面启动操作系统
/***************************************************************************** Function : main Description : Main function entry Input : None Output : None Return : None *****************************************************************************/ LITE_OS_SEC_TEXT_INIT int main(void) { unsigned int ret; UartInit(); ret = LOS_KernelInit(); if (ret != LOS_OK) { printf("LiteOS kernel init failed! ERROR: 0x%x\n", ret); goto EXIT; } #if (LOSCFG_SUPPORT_LITTLEFS == 1) LfsLowLevelInit(); #endif Uart0RxIrqRegister(); NetInit(); #if (LOSCFG_USE_SHELL == 1) ret = LosShellInit(); if (ret != LOS_OK) { printf("LosAppInit failed! ERROR: 0x%x\n", ret); } #endif ret = LosAppInit(); if (ret != LOS_OK) { printf("LosAppInit failed! ERROR: 0x%x\n", ret); } LOS_Start(); EXIT: while (1) { __asm volatile("wfi"); } }
- openHarmony\device\qemu\arm_mps2_an386\liteos_m\board\driver 包含了芯片的底层驱动代码
- 接下来就是理解操作系统内核模块,当前时LiteOS-M、LiteOS-A和Linux,之后会全部换成鸿蒙内核
- openHarmony\device\qemu\arm_mps2_an386\liteos_m\board\main.c(源码网址https://gitee.com/openharmony/device_qemu/blob/master/arm_mps2_an386/liteos_m/board/main.c) 中在main函数里面启动操作系统
-
- QEMU Arm MPS2 and MPS3 boards
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!