# openharmony/kernel_liteos_a architecture

> Architecture diagram of the GitHub repository openharmony/kernel_liteos_a, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openharmony/kernel_liteos_a
- Repository: https://github.com/openharmony/kernel_liteos_a

## Overview

#### Purpose and build surface
OpenHarmony LiteOS Cortex-A is a C/C++ embedded OS kernel for ARM Cortex-A/Hi3516D V300-class targets, providing POSIX-facing process, memory, IPC, filesystem, networking, driver, and security services. Builds are selected through GN/Make/Kconfig layers: `BUILD.gn`, `Kconfig`, `build.sh`, and `liteos.gni`.

#### Boot and execution entry points
ARM reset vectors establish CPU execution, then common kernel startup initializes core subsystems and launches user initialization. Key entry points are `arch/arm/arm/src/startup/reset_vector_up.S`, `kernel/common/main.c`, `kernel/common/los_init.c`, and `kernel/user/src/los_user_init.c`. The configured init application is `apps/init/src/init.c`; interactive shell implementations live in `shell/full/src/base/shcmd.c` and `apps/shell/src/main.c`.

#### Architecture and hardware boundary
The ARM port owns exceptions, interrupts, MMU/ASID handling, tick timing, SMP, and context dispatch. Hardware-specific code is isolated below kernel APIs in `arch/arm/arm/src/los_arch_mmu.c`, `arch/arm/arm/src/los_hwi.c`, `arch/arm/arm/src/los_dispatch.S`, and GIC drivers `arch/arm/gic/gic_v2.c` / `arch/arm/gic/gic_v3.c`. Platform/linker integration is supplied by `platform/board.ld.S` and `platform/bsp.mk`.

#### Kernel core: scheduling, processes, memory, IPC
The core kernel manages tasks/processes, priority/deadline scheduling, timers, physical/virtual memory, and synchronization. Primary paths are `kernel/base/core/los_task.c`, `kernel/base/core/los_process.c`, `kernel/base/sched/los_sched.c`, `kernel/base/mem/tlsf/los_memory.c`, and `kernel/base/vm/los_vm_map.c`. IPC objects—events, queues, mutexes, semaphores, futexes, signals—are kernel-resident in `kernel/base/ipc/los_event.c`, `kernel/base/ipc/los_queue.c`, and `kernel/base/ipc/los_signal.c`.

#### User/kernel ABI and compatibility
Applications reach privileged services through syscall dispatch and POSIX adaptation rather than directly through kernel internals. The syscall boundary is defined by `syscall/los_syscall.c`, `syscall/syscall_lookup.h`, and domain handlers such as `syscall/fs_syscall.c`. POSIX APIs map onto LiteOS primitives in `compat/posix/src/pthread.c`, `compat/posix/src/socket.c`, and `compat/posix/src/mqueue.c`; libc options include musl/newlib under `lib/libc/`.

#### Storage, filesystems, and devices
The VFS provides pathname, mount, vnode, descriptor, polling, and filesystem-operation abstractions over FAT, JFFS2, procfs, ramfs, rootfs, NFS, and other enabled filesystems. Its central boundary is `fs/vfs/vnode.c`, `fs/vfs/mount.c`, and `fs/vfs/operation/vfs_init.c`; root filesystem setup is `fs/rootfs/los_rootfs.c`. Block/MTD and character drivers feed this layer through `drivers/block/disk/src/disk.c`, `drivers/mtd/multi_partition/src/mtd_partition.c`, and device drivers under `drivers/char/`.

#### Networking, USB, and external stacks
Networking is based on lwIP 2.1, ported to LiteOS scheduling, driver interfaces, and sockets through `net/lwip-2.1/porting/src/sys_arch.c`, `net/lwip-2.1/porting/src/driverif.c`, and `net/lwip-2.1/porting/src/sockets.c`. Telnet and TFTP are optional user-facing network services in `net/telnet/src/telnet_loop.c` and `apps/tftp/src/tftpc.c`. USB is a FreeBSD-derived subsystem with EHCI/XHCI controllers and class drivers, centered on `bsd/dev/usb/usb_core.c`, `bsd/dev/usb/implementation/usb_init.c`, and `bsd/dev/usb/controller/xhci.c`.

#### Extended facilities and security
Optional kernel extensions add ELF dynamic loading, vDSO, lightweight IPC, containers/resource limits, tracing, performance monitoring, power management, and diagnostics. Architecturally significant paths include `kernel/extended/dynload/src/los_exec_elf.c`, `kernel/extended/liteipc/hm_liteipc.c`, `kernel/extended/container/los_container.c`, `kernel/extended/trace/los_trace.c`, and `kernel/extended/perf/los_perf.c`. Capability and virtual-ID security enforcement reside in `security/cap/capability.c` and `security/vid/vid.c`; mbedTLS, zlib, and BSD crypto are bundled libraries under `lib/libmbedtls/`, `lib/zlib/`, and `bsd/crypto/`.

Main entry points: [`syscall/los_syscall.c`](https://github.com/openharmony/kernel_liteos_a/blob/master/syscall/los_syscall.c) (Syscall dispatch), [`kernel/common/main.c`](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/common/main.c) (Kernel startup), [`kernel/base/sched/los_sched.c`](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/sched/los_sched.c) (Tasks & scheduler), [`fs/vfs/vnode.c`](https://github.com/openharmony/kernel_liteos_a/blob/master/fs/vfs/vnode.c) (VFS)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Platform"]
  node_build["Build selection<br/>GN/Make/Kconfig<br/>[BUILD.gn]"]
  node_platform["Board platform<br/>linker/BSP<br/>[board.ld.S]"]
end

subgraph group_boot["Boot &amp; Kernel"]
  node_reset["ARM reset vectors<br/>assembly entry<br/>[reset_vector_up.S]"]
  node_kernel_main["Kernel startup<br/>kernel entry<br/>[main.c]"]
  node_arch["ARM architecture port<br/>arch/HAL<br/>[los_arch_mmu.c]"]
  node_gic["GIC interrupt driver<br/>interrupt controller<br/>[gic_v2.c]"]
  node_scheduler["Tasks &amp; scheduler<br/>kernel core<br/>[los_sched.c]"]
  node_memory["Memory &amp; VM<br/>kernel memory<br/>[los_vm_map.c]"]
  node_ipc["Kernel IPC<br/>[los_queue.c]"]
  node_user_init["User initialization<br/>kernel/user bridge<br/>[los_user_init.c]"]
end

subgraph group_abi["ABI &amp; Runtime"]
  node_syscalls["Syscall dispatch<br/>user/kernel ABI<br/>[los_syscall.c]"]
  node_posix["POSIX adaptation<br/>compatibility API<br/>[pthread.c]"]
  node_libc["C library<br/>libc"]
end

subgraph group_services["System Services"]
  node_vfs["VFS<br/>filesystem abstraction<br/>[vnode.c]"]
  node_rootfs["Root filesystem<br/>filesystem bootstrap<br/>[los_rootfs.c]"]
  node_storage["Block &amp; MTD drivers<br/>storage drivers<br/>[disk.c]"]
  node_network["lwIP network stack<br/>[sys_arch.c]"]
  node_usb["USB subsystem<br/>USB stack<br/>[usb_core.c]"]
  node_init_app["Init application<br/>user application<br/>[init.c]"]
  node_shell["Interactive shell<br/>user application<br/>[main.c]"]
end

subgraph group_extensions["Extensions &amp; Security"]
  node_extensions["Kernel extensions<br/>optional facilities<br/>[los_exec_elf.c]"]
  node_security["Capabilities &amp; virtual IDs<br/>security enforcement<br/>[capability.c]"]
end

node_build -->|"selects target"| node_platform
node_platform -->|"links image"| node_reset
node_reset -->|"enters"| node_kernel_main
node_kernel_main -->|"initializes"| node_arch
node_arch -->|"uses"| node_gic
node_kernel_main -->|"initializes"| node_scheduler
node_kernel_main -->|"initializes"| node_memory
node_kernel_main -->|"initializes"| node_ipc
node_arch -->|"dispatches contexts"| node_scheduler
node_scheduler -->|"blocks and wakes tasks"| node_ipc
node_memory -->|"supplies process memory"| node_scheduler
node_kernel_main -->|"launches"| node_user_init
node_user_init -->|"starts"| node_init_app
node_init_app -.->|"launches"| node_shell
node_libc -->|"provides API surface"| node_posix
node_posix -->|"invokes"| node_syscalls
node_syscalls -->|"process/task services"| node_scheduler
node_syscalls -->|"memory services"| node_memory
node_syscalls -->|"IPC services"| node_ipc
node_syscalls -->|"filesystem services"| node_vfs
node_vfs -->|"mounts"| node_rootfs
node_vfs -->|"uses devices"| node_storage
node_posix -->|"socket API"| node_network
node_network -->|"ported scheduling"| node_scheduler
node_usb -.->|"exposes devices"| node_vfs
node_extensions -.->|"extends ABI services"| node_syscalls
node_security -->|"enforces access"| node_syscalls
node_security -.->|"constrains facilities"| node_extensions

click node_build "https://github.com/openharmony/kernel_liteos_a/blob/master/BUILD.gn"
click node_platform "https://github.com/openharmony/kernel_liteos_a/blob/master/platform/board.ld.S"
click node_reset "https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/arm/src/startup/reset_vector_up.S"
click node_kernel_main "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/common/main.c"
click node_arch "https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/arm/src/los_arch_mmu.c"
click node_gic "https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/gic/gic_v2.c"
click node_scheduler "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/sched/los_sched.c"
click node_memory "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/vm/los_vm_map.c"
click node_ipc "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/ipc/los_queue.c"
click node_user_init "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/user/src/los_user_init.c"
click node_syscalls "https://github.com/openharmony/kernel_liteos_a/blob/master/syscall/los_syscall.c"
click node_posix "https://github.com/openharmony/kernel_liteos_a/blob/master/compat/posix/src/pthread.c"
click node_vfs "https://github.com/openharmony/kernel_liteos_a/blob/master/fs/vfs/vnode.c"
click node_rootfs "https://github.com/openharmony/kernel_liteos_a/blob/master/fs/rootfs/los_rootfs.c"
click node_storage "https://github.com/openharmony/kernel_liteos_a/blob/master/drivers/block/disk/src/disk.c"
click node_network "https://github.com/openharmony/kernel_liteos_a/blob/master/net/lwip-2.1/porting/src/sys_arch.c"
click node_usb "https://github.com/openharmony/kernel_liteos_a/blob/master/bsd/dev/usb/usb_core.c"
click node_init_app "https://github.com/openharmony/kernel_liteos_a/blob/master/apps/init/src/init.c"
click node_shell "https://github.com/openharmony/kernel_liteos_a/blob/master/apps/shell/src/main.c"
click node_extensions "https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/extended/dynload/src/los_exec_elf.c"
click node_security "https://github.com/openharmony/kernel_liteos_a/blob/master/security/cap/capability.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_build,node_platform toneBlue
class node_reset,node_kernel_main,node_arch,node_gic,node_scheduler,node_memory,node_ipc,node_user_init toneAmber
class node_syscalls,node_posix,node_libc toneMint
class node_vfs,node_rootfs,node_storage,node_network,node_usb,node_init_app,node_shell toneRose
class node_extensions,node_security toneIndigo
```

## Components

### Build & Platform

- [Build selection](https://github.com/openharmony/kernel_liteos_a/blob/master/BUILD.gn): GN/Make/Kconfig · Selects target, features, and kernel build. · `BUILD.gn`
- [Board platform](https://github.com/openharmony/kernel_liteos_a/blob/master/platform/board.ld.S): linker/BSP · Supplies board linkage and BSP integration. · `platform/board.ld.S`

### Boot & Kernel

- [ARM reset vectors](https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/arm/src/startup/reset_vector_up.S): assembly entry · `arch/arm/arm/src/startup/reset_vector_up.S`
- [Kernel startup](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/common/main.c): kernel entry · Initializes core subsystems before user initialization. · `kernel/common/main.c`
- [ARM architecture port](https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/arm/src/los_arch_mmu.c): arch/HAL · Owns exceptions, MMU, interrupts, SMP, ticks, and context dispatch. · `arch/arm/arm/src/los_arch_mmu.c`
- [GIC interrupt driver](https://github.com/openharmony/kernel_liteos_a/blob/master/arch/arm/gic/gic_v2.c): interrupt controller · `arch/arm/gic/gic_v2.c`
- [Tasks & scheduler](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/sched/los_sched.c): kernel core · Manages processes, tasks, priorities, and scheduling. · `kernel/base/sched/los_sched.c`
- [Memory & VM](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/vm/los_vm_map.c): kernel memory · `kernel/base/vm/los_vm_map.c`
- [Kernel IPC](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/base/ipc/los_queue.c): kernel IPC · Provides events, queues, signals, mutexes, and futexes. · `kernel/base/ipc/los_queue.c`
- [User initialization](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/user/src/los_user_init.c): kernel/user bridge · `kernel/user/src/los_user_init.c`

### ABI & Runtime

- [Syscall dispatch](https://github.com/openharmony/kernel_liteos_a/blob/master/syscall/los_syscall.c): user/kernel ABI · Dispatches privileged service requests to domain handlers. · `syscall/los_syscall.c`
- [POSIX adaptation](https://github.com/openharmony/kernel_liteos_a/blob/master/compat/posix/src/pthread.c): compatibility API · Maps pthread, socket, and message-queue APIs to LiteOS services. · `compat/posix/src/pthread.c`
- **C library**: libc · Musl or newlib runtime options.

### System Services

- [VFS](https://github.com/openharmony/kernel_liteos_a/blob/master/fs/vfs/vnode.c): filesystem abstraction · Provides paths, mounts, vnodes, descriptors, polling, and filesystem operations. · `fs/vfs/vnode.c`
- [Root filesystem](https://github.com/openharmony/kernel_liteos_a/blob/master/fs/rootfs/los_rootfs.c): filesystem bootstrap · `fs/rootfs/los_rootfs.c`
- [Block & MTD drivers](https://github.com/openharmony/kernel_liteos_a/blob/master/drivers/block/disk/src/disk.c): storage drivers · `drivers/block/disk/src/disk.c`
- [lwIP network stack](https://github.com/openharmony/kernel_liteos_a/blob/master/net/lwip-2.1/porting/src/sys_arch.c): network stack · Ports lwIP scheduling, interfaces, and sockets to LiteOS. · `net/lwip-2.1/porting/src/sys_arch.c`
- [USB subsystem](https://github.com/openharmony/kernel_liteos_a/blob/master/bsd/dev/usb/usb_core.c): USB stack · FreeBSD-derived USB core, controllers, and class drivers. · `bsd/dev/usb/usb_core.c`
- [Init application](https://github.com/openharmony/kernel_liteos_a/blob/master/apps/init/src/init.c): user application · Configured first user application. · `apps/init/src/init.c`
- [Interactive shell](https://github.com/openharmony/kernel_liteos_a/blob/master/apps/shell/src/main.c): user application · `apps/shell/src/main.c`

### Extensions & Security

- [Kernel extensions](https://github.com/openharmony/kernel_liteos_a/blob/master/kernel/extended/dynload/src/los_exec_elf.c): optional facilities · Adds ELF loading, LiteIPC, containers, tracing, and performance monitoring. · `kernel/extended/dynload/src/los_exec_elf.c`
- [Capabilities & virtual IDs](https://github.com/openharmony/kernel_liteos_a/blob/master/security/cap/capability.c): security enforcement · `security/cap/capability.c`

## Connections

- Build selection → Board platform: selects target
- Board platform → ARM reset vectors: links image
- ARM reset vectors → Kernel startup: enters
- Kernel startup → ARM architecture port: initializes
- ARM architecture port → GIC interrupt driver: uses
- Kernel startup → Tasks & scheduler: initializes
- Kernel startup → Memory & VM: initializes
- Kernel startup → Kernel IPC: initializes
- ARM architecture port → Tasks & scheduler: dispatches contexts
- Tasks & scheduler → Kernel IPC: blocks and wakes tasks
- Memory & VM → Tasks & scheduler: supplies process memory
- Kernel startup → User initialization: launches
- User initialization → Init application: starts
- Init application → Interactive shell: launches
- C library → POSIX adaptation: provides API surface
- POSIX adaptation → Syscall dispatch: invokes
- Syscall dispatch → Tasks & scheduler: process/task services
- Syscall dispatch → Memory & VM: memory services
- Syscall dispatch → Kernel IPC: IPC services
- Syscall dispatch → VFS: filesystem services
- VFS → Root filesystem: mounts
- VFS → Block & MTD drivers: uses devices
- POSIX adaptation → lwIP network stack: socket API
- lwIP network stack → Tasks & scheduler: ported scheduling
- USB subsystem → VFS: exposes devices
- Kernel extensions → Syscall dispatch: extends ABI services
- Capabilities & virtual IDs → Syscall dispatch: enforces access
- Capabilities & virtual IDs → Kernel extensions: constrains facilities
