wrkm.app
Search
Mobile Development

The HAL That Ran Fine by Hand

The HAL That Ran Fine by Hand

Editor
Nov 22, 2026 · 7 min read
The HAL That Ran Fine by Hand

Why a Vehicle HAL that eventually ran cleanly from a root shell still kept an Android Automotive board in a restart loop, and what a real boot checks that a root shell never does.Android Automotive System Internals — Part 4: init, SELinux & the Vendor HAL Boot PathThe speedometer was fixed.The camera bug was fixed.The window manager was fixed.A new vendor Vehicle HAL goes onto an AAOS 16 target. Same interface, IVehicle/default. Different backend: vehicle signals arrive over SOME/IP.The board comes up. SystemUI appears.The launcher never does.Then the framework goes down and starts again. Roughly every 90 to 110 seconds.No crash dialog. No adb, because the framework never stays up long enough for adbd to answer.Eventually the service runs fine by hand from a root shell. The board still loops.That was my bring-up. Three causes on the version that finally booted. Two of them lived in the build and the policy. Only one was in my C++.The Board Never RebootedDuring the loop, the only way in was a serial console. I wired UART to the header pins and captured up to five minutes of a looping boot.What the capture showed:What the capture showed How oftenBooting Linux onceinit sending SIGKILL to zygote every cyclesysrq: Show backtrace of all active CPUs every cycle, right before the killcarwatchdogd asking for IVehicle/default every ~6 s, never answeredEvery line accurate. None of them named the problem.The kernel booted exactly once. This was a framework restart loop: the platform waited for a Vehicle HAL that never registered, the framework went down, zygote restarted, and the wait began again.I checked the other CPUs’ backtraces at one of those dumps. All idle. Nothing was spinning at the kernel level. Something was simply missing.Four Fixes That Changed NothingFirst, I tried four fixes, each one through a full rebuild, reflash and reboot:Startup gave up if a connection wasn’t up yet at that point in boot. I stopped gating registration on it.The middleware had no configuration file on the device. I shipped one.My HAL exposed one property. Suspecting CarService needed the baseline set that FakeVehicleHardware ships, I composed with it instead of replacing it.My service hung waiting on /dev/vndbinder. Pinning the binder driver at startup removed the hang. Why it happened in my service is still an open question.After fix 3 I compared the flashed partition byte for byte against the built image, past the ext4 superblock, to be sure the fix was really on the card. It was.Same loop, every time.My notes from those attempts had one more line. The hand-run tests, they said, ran “under a different SELinux domain” than the one init uses, so they could rule hypotheses out but could not reproduce the boot. I wrote that down as a limitation of the test.It was part of the answer.Then I rewrote the service as a single process, which changed its binary name. The loop came with it. Everything below happened on that version.The Harness That Gave Me adb BackThe method that worked was a harness build:The default VHAL stays primary, so the board boots and adb works.My binary is installed in /vendor/bin/hw/, and its .rc service is declared but disabled.Now I could run my service on a live system, from the image, with its output in front of me.Root cause 1: the plugins were never on the imageRun by hand, it died at once with exit code 1:Configuration module could not be loaded!vsomeip loads its configuration and service-discovery modules at runtime with dlopen: libvsomeip3-cfg.so and libvsomeip3-sd.so. They are not NEEDED entries. The build-time linker never sees them, and neither does Soong.So linking libvsomeip3 installed the core library and nothing else. The plugins never reached /vendor/lib64.The fix is to name them:required: [ "someip_vhal.vsomeip.json", "libvsomeip3-cfg", "libvsomeip3-sd", ... ]Root cause 2: it ran as root, and init still said noWith the plugins installed, the by-hand run worked. As the primary VHAL, the board still looped.So I started it the way init does:adb rootadb shell start vendor.vehicle-hal-someipand init answered (trimmed, path shortened):init: [...] Could not ctl.start for 'vendor.vehicle-hal-someip' [...]:File .../@V4-someip-service(labeled "u:object_r:vendor_file:s0") has incorrect label or no domain transition fromu:r:init:s0 to another SELinux domain defined. [...] Note: this error shows up evenin permissive mode in order to make auditing denials possible.This is a domain calculation, not an access denial, so the enforcement mode doesn’t change it. init computes the domain the new process will run in, and if the answer is init’s own domain, it won’t start the service.Root cause 3: my health check was tied to the networkOnce init could start the service, one restart remained: the launcher.This one was in my code. My hardware layer’s checkHealth() returned INTERNAL_ERROR whenever the SOME/IP side wasn't up yet: peer down, network not ready, discovery still running.DefaultVehicleHal sends carwatchdog its VHAL_HEARTBEAT only when checkHealth() returns OK. carwatchdog expects that heartbeat every 3 seconds by default. No heartbeat, and carwatchdog has the VHAL killed (the kill itself runs in system_server, through CarServiceHelperService). init respawns it, and CarService and the launcher churn with it.The fix was to delegate checkHealth() to FakeVehicleHardware, which returns OK, the same as the stock service. A disconnected peer means SOME/IP values stop updating. The HAL itself is still alive.The Label That Decides the DomainAOSP’s stock system/sepolicy/vendor/file_contexts has one entry for AIDL Vehicle HAL binaries:/(vendor|system/vendor)/bin/hw/android.hardware.automotive.vehicle@V[0-9]+-(default|emulator)-service u:object_r:hal_vehicle_default_exec:s0@V4-default-service matches. @V4-emulator-service matches. @V4-someip-service falls back to the generic vendor_file.Before:init (u:r:init:s0) └── exec @V4-someip-service file label: vendor_file transition: none defined result: would run as u:r:init:s0 -> refusedAfter one file_contexts line:init (u:r:init:s0) └── exec @V4-someip-service file label: hal_vehicle_default_exec transition: init_daemon_domain(hal_vehicle_default) result: runs as u:r:hal_vehicle_default:s0Why Both HidThe by-hand run used a different door. A root shell executes the binary in the shell’s own domain. No transition is requested, so nothing is refused. init asks a question my shell never asks.Nothing in the toolchain knows about a plugin. The build succeeded, the binary linked, and every NEEDED library made it onto the image. Neither the linker nor Soong ever sees a library that only dlopen asks for. The first thing to notice it missing is the process itself, at runtime, on the device, however it is launched. That one, the root shell did catch.Inside init: Where the Decision HappensThe refusal comes from system/core/init/service.cpp. Four steps.Step 1. start sends init a control message. init finds the service by name and calls Service::Start(), which checks that the executable exists.Step 2. If the .rc sets a seclabel, init uses it. Otherwise it calls ComputeContextFromExecutable() with the binary's path.Step 3. That function reads init’s own context (getcon) and the file's label (getfilecon), then asks the policy which domain a process created from that file would get (security_compute_create).Step 4. If the answer equals init’s own context, the function returns the error above. Start() passes it back. There is no fork, no exec, and no log line from your process. IVehicle/default never registers.if (rc == 0 && computed_context == mycon.get()) { return Error() << "File " << service_path << "(labeled "" << filecon.get() << "") has incorrect label or no domain transition from " ...}The Neverallow I Got WrongA SOME/IP stack needs UDP sockets, netlink, and its own lock and socket files.The obvious move is to grant those to hal_vehicle_default. That fails the policy build. system/sepolicy/private/hal_neverallows.te bars HAL server domains from network sockets.My first note concluded that a SOME/IP VHAL needed a custom domain with its own neverallow exception.That note was wrong. The same file carves out an attribute, with this comment:HALs for automotive devices have an exemption from this rule because in a car it is common to have external modules and HALs need to communicate to those modules using network. Using this exemption for non-automotive builds will result in CTS failure.Google’s Cuttlefish automotive target applies it to this exact domain with these two lines:typeattribute hal_vehicle_default hal_automotive_socket_exemption;net_domain(hal_vehicle_default)I had drafted hand-written allow rules first. They were broader than that macro and still missed things. I replaced them with the two lines, plus one dedicated file type for vsomeip’s runtime directory. Its routing-manager lock and local endpoint sockets are load-bearing: without them SOME/IP never starts.The board boots enforcing. The VHAL runs in u:r:hal_vehicle_default:s0 with zero hal_vehicle_default denials.One question stays open. The exemption is a blanket attribute. Whether a SOME/IP VHAL should get it, or a narrower domain of its own, is a design decision in its own right.Why Any Renamed HAL Is ExposedThe stock AIDL entry labels Google’s two reference names, at any interface version. Give your Vehicle HAL any other name and it gets vendor_file until you label it.The same goes for anything a vendor service loads with dlopen. If the build graph can't see it, the image won't carry it.Both failures look the same from outside: a framework restart loop with nothing from your process in any log.What the Working Image Carries1. The module’s Android.bp: install what you dlopen.required: [ "someip_vhal.vsomeip.json", "libvsomeip3-cfg", "libvsomeip3-sd", ... ]2. sepolicy/file_contexts: give the binary a domain./vendor/bin/hw/android.hardware.automotive.vehicle@V4-someip-service u:object_r:hal_vehicle_default_exec:s03. The module’s .te: let the HAL talk to the network.typeattribute hal_vehicle_default hal_automotive_socket_exemption;net_domain(hal_vehicle_default)4. BoardConfig.mk: make the board read that policy.BOARD_SEPOLICY_DIRS += device///someip_vhal/sepolicyAnd in the hardware layer, keep checkHealth() independent of the network backend.The Diagnostic WorkflowBench: the logs, fixes and command outputs shown in this article were captured and verified on a Raspberry Pi 5 running AAOS 16.Check the label on your binary:adb shell ls -Z /vendor/bin/hw/ | grep -i vehicleOn the working image, a label init can transition from:u:object_r:hal_vehicle_default_exec:s0 android.hardware.automotive.vehicle@V4-someip-serviceBefore the fix, that first field was u:object_r:vendor_file:s0, the label init's error reported. Unless its .rc sets a seclabel, a binary carrying it will not start from init.Start it the way init does. Use start; a shell launch skips the check you are testing. init writes to the kernel log, so read dmesg:adb rootadb shell start vendor.vehicle-hal-someipadb shell dmesg | grep "ctl.start"Broken: the no domain transition line above. Working: no error, and the process shows up in its own domain:adb shell ps -AZ | grep -i vehicleu:r:hal_can_socketcan:s0 vehicle_network 717 1 10908868 5952 binder_ioctl_write_read 0 S android.hardware.automotive.can-serviceu:r:hal_vehicle_default:s0 vehicle_network 12997 1 11268304 21112 binder_ioctl_write_read 0 S android.hardware.automotive.vehicle@V4-someip-serviceThe second line is the one that matters: the VHAL in its own domain, running as vehicle_network, parent PID 1.Check that the plugins made it onto the image:adb shell ls /vendor/lib64 | grep vsomeipYou want libvsomeip3-cfg.so and libvsomeip3-sd.so next to libvsomeip3.so. If only the core library is there, the service will exit at init().Read custom properties through CarService. If your hardware layer composes FakeVehicleHardware and delegates dump() to it, then dumpsys android.hardware.automotive.vehicle.IVehicle/default --get answers No property for every property you added. Your property is fine. Ask the binder path instead:adb shell cmd car_service list-vhal-propsadb shell cmd car_service get-property-value The Systemic Mental ModelA binary that runs is not a service that starts.A root shell is the loading dock. You walk in with the binary and it runs. If a plugin is missing, the process fails there too, because that failure lives inside the process. What the loading dock never does is check your badge. Only init asks for a domain. And only a booted platform has carwatchdog checking, every few seconds, that you are still alive.Part 1 traced stale speed data to the IPC return path. Part 2 traced a late camera to process cold start. Part 3 traced a misplaced app to a launch request with half an address. Here, two of the three causes lived outside my C++, in the build and the policy, and one of them only shows up when init does the launching.What to Check on Your Build TodayIf you ship your own native vendor service on AAOS, run this:adb shell ls -Z /vendor/bin/hw/Any binary of yours labeled vendor_file, with no seclabel in its .rc, will not start from init, however well it runs from your shell.Fix it before a bring-up board finds it for you, ninety seconds at a time.Note: This article covers native vendor services started by init on AAOS, where Android runs on the vehicle hardware. It does not apply to Android Auto phone projection. The SOME/IP integration design itself is out of scope here.Key AOSP Referencessystem/core/init/service.cpp: Service::Start(), ComputeContextFromExecutable()system/sepolicy/vendor/file_contexts: stock Vehicle HAL executable labelssystem/sepolicy/vendor/hal_vehicle_default.te: init_daemon_domain(hal_vehicle_default)system/sepolicy/private/hal_neverallows.te: HAL socket neverallows and hal_automotive_socket_exemptiondevice/google/cuttlefish/shared/auto/sepolicy/vendor/hal_vehicle_default.te: where the automotive reference applies the exemptionhardware/interfaces/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp: checkHealth() and the VHAL_HEARTBEAThardware/interfaces/automotive/vehicle/aidl/impl/current/vhal/vhal-default-service.rc: the stock service stanza (class early_hal, user vehicle_network)packages/services/Car/cpp/watchdog/server/src/WatchdogProcessService.cpp: carwatchdogd’s VHAL connection and heartbeat checksAndroid SELinux: label new services: the page init’s error message points toThe HAL That Ran Fine by Hand was originally published in ProAndroidDev on Medium, where people are continuing the conversation by highlighting and responding to this story.

Kaynak: Rohith Gaddam

#Android#Kotlin
Share

From other categories