Skip to content

Boot Chain, Dynamic Partitions & Tiered Storage ​

Running OpenHarmony cleanly on modern Android GKI 6.x A/B hardware requires bridging the device's stock bootloader and super dynamic partition layout into OpenHarmony's two-stage switch_root initialization chain without touching low-level boot firmware.

1. Two-Stage init_boot to switch_root Pipeline ​

01 / BOOTLOADERStock Boot & AVBboot_{a,b} (GKI Image)init_boot + vendor_bootdtbo + vbmeta flagsLow-level chain stock02 / STAGE-1 PID1early-bringup / init_early1. /proc, /sys, /dev (chmod 0755)2. misc+0x1000 + USB ACM console3. Parse super LP → dm-linear4. Load early .ko (EEXIST safe)5. Mount OpenHarmony root → /usrfstab.required → switch_root03 / STAGE-2 INIT/bin/init --second-stage/system, /vendor (EROFS)/sys_prod, /chip_prod/data (F2FS + HMFS ioctl)modem/nvram: ro,norecovery04 / USERLANDServices Readysamgr / hilogd / hdcdhdf_devmgr / VDIBionic Sidecar (ro)RenderService + ArkUISafe Rollback: Keep stock _a logical partitions untouched; fastboot set_active a restores stock OS

Stage-1 PID1 (UniOHOS/core/early-bringup) ​

init_boot_{a,b} carries the first-stage ramdisk and modular PID1 router (stage1-init):

  1. Early Pseudo-Filesystems & Permissions: Mounts /proc, /sys, and /dev, explicitly setting chmod 0755 /dev (and socket directories) so non-root OpenHarmony services never hit EACCES on Unix domain sockets.
  2. Solderless Early Diagnostics:
    • Initializes a persistent ring buffer at a reserved offset in misc (e.g., misc+0x1000, leaving standard BCB untouched) to capture /dev/kmsg and PID1 checkpoints across panics or watchdog resets.
    • Starts usb-udc-guard to bring up ConfigFS USB ACM (/dev/ttyACM0) and hdc early without physical UART soldering.
  3. Dynamic Partition Mapping (super / liblp / dm-linear):
    • Reads AOSP LP metadata headers from the physical super block device and creates /dev/block/mapper/* dm-linear targets for the active target slot (system_b, vendor_b, sys_prod_b, chip_prod_b, odm_b, *_dlkm_b).
  4. Early Kernel Module Closure:
    • Loads required early .ko modules from vendor_boot in topological dependency order, treating EEXIST (already loaded) as non-fatal so watchdog and storage drivers always initialize cleanly.
  5. Staging Mount & switch_root:
    • Mounts the OpenHarmony root filesystem onto /usr (OpenHarmony's standard staging mountpoint), applies fstab.required, verifies critical modem/calibration partitions remain ro,norecovery, and executes:
      text
      switch_root /usr /bin/init --second-stage

Stage-2 OpenHarmony Init ​

Once /bin/init --second-stage takes over as PID1 inside Musl userland, it mounts /system, /vendor, /sys_prod, /chip_prod, and /data, brings up samgr, hilogd, hdf_devmgr, and hdcd, and triggers graphics and isolated Sidecar services.

2. Tiered Read-Only EROFS & 64KB PTE_CONT Alignment ​

Read-only system partitions (system, vendor, sys_prod, chip_prod, odm) use EROFS (LZ4, LZ4HC, or ZSTD):

  • Tier-0 Hot Shared Libraries (tier0-preload.txt): High-frequency cold-boot libraries (such as librender_service.z.so, libace_compatible.z.so, libipc_single.z.so, and display VDIs) can be packed uncompressed (FLAT_PLAIN) and aligned on 64KB boundaries (16 x 4KB blocks) via UniOHOS/builder/fs-tools/tools/erofs_v2_64k_packer.py.
  • ARM64 PTE_CONT Coalescing: On 4KB-page ARM64 kernels with large folios, 64KB-aligned hot text/code mappings enable PTE_CONT contiguous TLB entries (1 TLB entry covering 16x 4KB pages), reducing cold-start iTLB pressure.
  • Deterministic Offline Verification: fs-tools validates every packed image via unmodified fsck.erofs --extract SHA-256 roundtrip matching and deterministic two-round builds (R1 == R2).

3. Native F2FS /data with Lightweight HMFS ioctl Compatibility ​

Instead of requiring destructive conversion of /data to a proprietary filesystem format, UniOHOS keeps the device's native Linux F2FS partition and adds a lightweight HMFS ioctl compatibility patch (0xf5xx, matching UniOHOS/builder/fs-tools/tools/hmfs_ioctl_compat.h) inside the GPL-2.0-only kernel patch stack (patches/20-hmos/). This preserves full native F2FS tooling, fscrypt support, and recovery compatibility.

Independent Open-Source Community (CC-BY-4.0). Not affiliated with Huawei, HiSilicon, OpenAtom Foundation, Xiaomi, Qualcomm, MediaTek, or Arm.