# boundarydevices/android_hardware_imx architecture

> Architecture diagram of the GitHub repository boundarydevices/android_hardware_imx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/boundarydevices/android_hardware_imx
- Repository: https://github.com/boundarydevices/android_hardware_imx

## Overview

##### Project type and purpose
- This is an Android system-level “HAL monorepo” for NXP-based hardware. It implements multiple Hardware Abstraction Layers (HALs) and services (Audio, Bluetooth, Camera, Display, EVS, USB, Power, Thermal, Sensor, Vehicle, Secure Enclave, etc.) using HIDL or AIDL, exposing them as binder services to the Android framework.

##### File structure
- Top-level directories correspond to individual HAL modules (alsa, audio, bluetooth, camera, display, evs, usb, power, thermal, sensor, vehicle, secure-enclave, etc.).
- Each module contains:
- Source files (.cpp/.h) implementing the service logic
- Android.bp build scripts
- HIDL/AIDL interface definitions (.hal or .aidl)
- Service registration files (.rc, .xml)
- There are shared libraries (libedid, libextcam) and common code (vehicle/common, sv/corelib).
- gtest folders provide unit and integration tests.
- Build configuration files at root (.clang-format, PREUPLOAD.cfg, MODULE_LICENSE_APACHE2) show it's using Soong and Android’s build rules.

##### What the README would tell you
- (Empty here, but typically would list supported interfaces, versions, and high-level architecture.)

a. Main components
- Android Framework Layer (AudioFlinger, CameraService, BluetoothManager, SurfaceFlinger, PowerManagerService, etc.)
- HIDL/AIDL Binder Interfaces (android.hardware.audio@X.X, android.hardware.bluetooth@X.X, android.hardware.camera.device@X.X, hwcomposer3, etc.)
- HAL Modules (audio/default, bluetooth/, camera/, display/hwcomposer3, sensor/, power/, etc.)
- Shared Libraries (libedid, libextcam, vehicle/common)
- Kernel Drivers (ALSA, V4L2, DRM, ION, IIO, USB, Thermal zones, Power hints, Vehicle CAN, Secure Enclave)
- Hardware Blocks (Audio CODEC, Bluetooth chip, Camera sensor+ISP, Display controllers, EVS cameras and displays, USB PHYs, CPU/GPU, Thermal sensors, Vehicle network, Secure element)
b. Relationships and interactions
- Android Framework calls into HIDL/AIDL stubs via Binder IPC.
- HIDL/AIDL stubs dispatch to HAL module implementations (each running as a separate service process).
- HAL modules invoke lower-level libs or kernel drivers via ioctl, read/write, ALSA lib, tinyalsa, V4L2 APIs, DRM ioctls, ION, IIO, CAN sockets.
- Kernel drivers talk directly to hardware over bus (I2C, SPI, PCIe, USB).
- Some modules share common code (e.g., vehicle/common classes used by vehicle/impl).
c. Architectural patterns and design principles
- Modular per-interface service processes for isolation and independent updates.
- Binder IPC boundary between Framework and HAL.
- HIDL/AIDL as the versioned IDL layer.
- Common utility libraries for code reuse.
- Clear separation of concerns: service registration (.rc/.xml) separate from implementation.
d. Key technologies/frameworks
- Soong build system (Android.bp)
- HIDL and AIDL
- Binder IPC
- ALSA/tinyalsa for audio
- V4L2 for camera/EVS
- DRM/ION for display
- IIO for sensors
- Linux kernel drivers for each hardware block

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Framework Layer
    subgraph "Android Framework" 
        direction TB
        AF["AudioFlinger"]:::framework
        CS["CameraService"]:::framework
        BM["BluetoothManager"]:::framework
        SF["SurfaceFlinger"]:::framework
        PMS["PowerManagerService"]:::framework
        TMS["ThermalService"]:::framework
        SM["SensorManager"]:::framework
        VS["VehicleService"]:::framework
        ES["EnclaveService"]:::framework
    end

    %% HIDL/AIDL Interfaces Layer
    subgraph "HIDL/AIDL Interfaces"
        direction TB
        AHAL["android.hardware.audio@4.0"]:::idl
        BHAL["android.hardware.bluetooth@1.0"]:::idl
        CHAL["android.hardware.camera.device@2.0"]:::idl
        HWC3["hwcomposer3"]:::idl
        GRAL["android.hardware.graphics.allocator@2.0"]:::idl
        EVHAL["android.hardware.evs@1.1"]:::idl
        USBHAL["android.hardware.usb@1.3"]:::idl
        PWHAL["android.hardware.power@1.0"]:::idl
        THHAL["android.hardware.thermal@2.0"]:::idl
        SNHAL["android.hardware.sensors@1.0"]:::idl
        VHAL["android.hardware.vehicle@2.0"]:::idl
        SEHAL["android.hardware.secure_enclave@1.0"]:::idl
    end

    %% HAL Services Layer
    subgraph "HAL Services" 
        direction TB
        AUD["audio/default"]:::hal
        ALSA["alsa"]:::hal
        BLU["bluetooth"]:::hal
        CAM["camera-hal-v2"]:::hal
        DHC3["display/hwcomposer3"]:::hal
        DGRAL["display/gralloc"]:::hal
        DDISP["display/display"]:::hal
        EVH["evs/evs_hal"]:::hal
        EVS["evs/evs_service"]:::hal
        USB1["usb"]:::hal
        UGAD["usb/gadget"]:::hal
        PWR["power"]:::hal
        THL["thermal"]:::hal
        THH["thermal_hidl"]:::hal
        SNS["sensor"]:::hal
        VEHCOM["vehicle/common"]:::utility
        VEHIMP["vehicle/impl"]:::hal
        SEC["secure-enclave/aidl/default"]:::hal
    end

    %% Utilities Layer
    subgraph "Utilities & Libraries"
        direction TB
        EDID["libedid"]:::utility
        EXTCAM["libextcam"]:::utility
        SVCORE["sv/corelib"]:::utility
    end

    %% Kernel Drivers Layer
    subgraph "Kernel Drivers"
        direction TB
        KALSA["ALSA driver"]:::kernel
        KV4L2["V4L2"]:::kernel
        KDRM["DRM"]:::kernel
        KION["ION"]:::kernel
        KIIO["IIO"]:::kernel
        KUSB["USB driver"]:::kernel
        KTHERM["Thermal zones"]:::kernel
        KCAN["CAN sockets"]:::kernel
        KSE["Secure Enclave driver"]:::kernel
    end

    %% Hardware Layer
    subgraph "Hardware Blocks"
        direction TB
        HCODEC["Audio CODEC"]:::hardware
        HBT["Bluetooth chip"]:::hardware
        HCAM["Camera sensor+ISP"]:::hardware
        HDISP["Display controllers"]:::hardware
        HEVS["EVS cameras & displays"]:::hardware
        HPHY["USB PHYs"]:::hardware
        HCPU["CPU/GPU"]:::hardware
        HTS["Thermal sensors"]:::hardware
        HVNET["Vehicle network"]:::hardware
        HSEC["Secure element"]:::hardware
    end

    %% Connections Framework -> IDL
    AF -->|binder| AHAL
    BM -->|binder| BHAL
    CS -->|binder| CHAL
    SF -->|binder| HWC3
    SF -->|binder| GRAL
    CS -->|binder| EVHAL
    USBHAL -->|n/a| USBHAL
    PMS -->|binder| PWHAL
    TMS -->|binder| THHAL
    SM -->|binder| SNHAL
    VS -->|binder| VHAL
    ES -->|binder| SEHAL

    %% IDL -> HAL
    AHAL -->|stub| AUD
    AHAL -->|stub| ALSA
    BHAL -->|stub| BLU
    CHAL -->|stub| CAM
    HWC3 -->|stub| DHC3
    GRAL -->|stub| DGRAL
    EVHAL -->|stub| EVH
    USBHAL -->|stub| USB1
    USBHAL -->|stub| UGAD
    PWHAL -->|stub| PWR
    THHAL -->|stub| THH
    THHAL -->|stub| THL
    SNHAL -->|stub| SNS
    VHAL -->|stub| VEHIMP
    SEHAL -->|stub| SEC

    %% HAL -> Utilities
    ALSA -->|link| EXTCAM
    VEHIMP -->|link| VEHCOM
    CAM -->|link| SVCORE

    %% HAL -> Kernel Drivers
    AUD -->|ALSA API| KALSA
    ALSA -->|tinyalsa| KALSA
    BLU -->|ioctl| KUSB
    CAM -->|V4L2 API| KV4L2
    DHC3 -->|DRM ioctl| KDRM
    DGRAL -->|ION| KION
    EVH -->|V4L2 API| KV4L2
    USB1 -->|usbfs| KUSB
    UGAD -->|gadget| KUSB
    PWR -->|power hints| KTHERM
    THL -->|thermal zones| KTHERM
    THH -->|thermal zones| KTHERM
    SNS -->|IIO| KIIO
    VEHIMP -->|CAN sockets| KCAN
    SEC -->|secure driver| KSE

    %% Drivers -> Hardware
    KALSA -->|I2C/SPI| HCODEC
    KUSB -->|USB bus| HPHY
    KV4L2 -->|CSI/USB| HCAM
    KDRM -->|display bus| HDISP
    KION -->|memory bus| HCPU
    KIIO -->|sensor bus| HTS
    KCAN -->|CAN bus| HVNET
    KSE -->|secure bus| HSEC

    %% Click Events
    click AUD "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/audio/default/Android.bp"
    click AUD "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/audio/default/main.cpp"
    click ALSA "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/alsa/Android.bp"
    click ALSA "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/alsa/tinyalsa_hal.cpp"
    click BLU "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/bluetooth/Android.bp"
    click BLU "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/bluetooth/service.cpp"
    click CAM "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/camera/camera-hal-v2/Android.bp"
    click CAM "https://github.com/boundarydevices/android_hardware_imx/tree/ezurio-android-15.0.0_1.2.0/camera/camera-hal-v2"
    click DHC3 "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/display/hwcomposer3/Android.bp"
    click DHC3 "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/display/hwcomposer3/Main.cpp"
    click DGRAL "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/display/gralloc/Android.bp"
    click DGRAL "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/display/gralloc/aidl/Main.cpp"
    click DDISP "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/display/display/Android.bp"
    click EVH "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/evs/evs_hal/Android.bp"
    click EVH "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/evs/evs_hal/service.cpp"
    click EVS "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/evs/evs_service/Android.bp"
    click EVS "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/evs/evs_service/evs_service.cpp"
    click USB1 "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/usb/Android.bp"
    click USB1 "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/usb/Usb.cpp"
    click UGAD "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/usb/gadget/Android.bp"
    click UGAD "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/usb/gadget/UsbGadget.cpp"
    click PWR "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/power/Android.bp"
    click PWR "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/power/Power.cpp"
    click THL "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/thermal/Android.bp"
    click THL "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/thermal/Thermal.cpp"
    click THH "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/thermal_hidl/Android.bp"
    click THH "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/thermal_hidl/Thermal.cpp"
    click SNS "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/sensor/Android.bp"
    click SNS "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/sensor/Sensor.cpp"
    click VEHCOM "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/vehicle/common/Android.bp"
    click VEHIMP "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/vehicle/impl/vhal_v2_0/VehicleHalServer.cpp"
    click SEC "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/secure-enclave/aidl/default/Android.bp"
    click SEC "https://github.com/boundarydevices/android_hardware_imx/blob/ezurio-android-15.0.0_1.2.0/secure-enclave/aidl/default/SecureEnclave.cpp"

    %% Styles
    classDef framework fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef idl fill:#C8E6C9,stroke:#43A047,color:#1B5E20
    classDef hal fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef utility fill:#E1BEE7,stroke:#8E24AA,color:#4A148C
    classDef kernel fill:#CFD8DC,stroke:#607D8B,color:#263238
    classDef hardware fill:#FFF9C4,stroke:#FBC02D,color:#F57F17
```
