How openharmony/kernel_liteos_a works
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: los_syscall.c Syscall dispatch · main.c Kernel startup · los_sched.c Tasks & scheduler · vnode.c VFS
Components 22
Build & Platform
- Build selection · Selects target, features, and kernel build.
BUILD.gn - Board platform · Supplies board linkage and BSP integration.
platform/board.ld.S
Boot & Kernel
- ARM reset vectors
arch/arm/arm/src/startup/reset_vector_up.S - Kernel startup · Initializes core subsystems before user initialization.
kernel/common/main.c - ARM architecture port · Owns exceptions, MMU, interrupts, SMP, ticks, and context dispatch.
arch/arm/arm/src/los_arch_mmu.c - GIC interrupt driver
arch/arm/gic/gic_v2.c - Tasks & scheduler · Manages processes, tasks, priorities, and scheduling.
kernel/base/sched/los_sched.c - Memory & VM
kernel/base/vm/los_vm_map.c - Kernel IPC · Provides events, queues, signals, mutexes, and futexes.
kernel/base/ipc/los_queue.c - User initialization
kernel/user/src/los_user_init.c
ABI & Runtime
- Syscall dispatch · Dispatches privileged service requests to domain handlers.
syscall/los_syscall.c - POSIX adaptation · Maps pthread, socket, and message-queue APIs to LiteOS services.
compat/posix/src/pthread.c - C library · Musl or newlib runtime options.
System Services
- VFS · Provides paths, mounts, vnodes, descriptors, polling, and filesystem operations.
fs/vfs/vnode.c - Root filesystem
fs/rootfs/los_rootfs.c - Block & MTD drivers
drivers/block/disk/src/disk.c - lwIP network stack · Ports lwIP scheduling, interfaces, and sockets to LiteOS.
net/lwip-2.1/porting/src/sys_arch.c - USB subsystem · FreeBSD-derived USB core, controllers, and class drivers.
bsd/dev/usb/usb_core.c - Init application · Configured first user application.
apps/init/src/init.c - Interactive shell
apps/shell/src/main.c
Extensions & Security
- Kernel extensions · Adds ELF loading, LiteIPC, containers, tracing, and performance monitoring.
kernel/extended/dynload/src/los_exec_elf.c - Capabilities & virtual IDs
security/cap/capability.c
Connections 28
- 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