10 开源鸿蒙中芯片与开发板对应的源码(硬件相关的部分)

开源鸿蒙中芯片与开发板对应的源码(硬件相关的部分)

作者 将狼才鲸
日期 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
  • 参考网址:

源码框架

shell 复制代码
.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函数里面启动操作系统
c 复制代码
/*****************************************************************************
 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,之后会全部换成鸿蒙内核
相关推荐
Wallace Zhang2 小时前
STM32 - Embedded IDE - GCC - 显著减少固件的体积
stm32·单片机·嵌入式硬件
fengfuyao98513 小时前
STM32如何定位HardFault错误,一种实用方法
stm32·单片机·嵌入式硬件
爱学习的颖颖14 小时前
EXTI外部中断的执行逻辑|以对射式红外传感器计次为例
单片机·嵌入式硬件·exti中断
AI精钢15 小时前
H20芯片与中国的科技自立:一场隐形的博弈
人工智能·科技·stm32·单片机·物联网
etcix18 小时前
implement copy file content to clipboard on Windows
windows·stm32·单片机
谱写秋天18 小时前
在STM32F103上进行FreeRTOS移植和配置(STM32CubeIDE)
c语言·stm32·单片机·freertos
globbo1 天前
【嵌入式STM32】I2C总结
单片机·嵌入式硬件
玖別ԅ(¯﹃¯ԅ)1 天前
SysTick寄存器(嘀嗒定时器实现延时)
stm32·单片机·嵌入式硬件
Blossom.1181 天前
把 AI 推理塞进「 8 位 MCU 」——0.5 KB RAM 跑通关键词唤醒的魔幻之旅
人工智能·笔记·单片机·嵌入式硬件·深度学习·机器学习·搜索引擎
桃源学社(接毕设)1 天前
基于人工智能和物联网融合跌倒监控系统(LW+源码+讲解+部署)
人工智能·python·单片机·yolov8