I think the way that Pixel phones work is as close to ideal as we've got right now: there's measured boot, i.e. the first thing the SoC does when it boots is it checks if its firmware is signed by a key that it trusts. On some other kinds of devices, if the firmware's not signed, it abandons the boot attempt. Not genuine means no dice. But on my Pixel, I can flash whatever I want (like GrapheneOS), and when the phone starts up, it displays a big yellow exclamation point alert that the phone is running unsigned firmware. I can run whatever I want on my phone, but there's no way for me to pass off my firmware as genuine.
And to get at your question a little more directly: the Pixel requires me to have the phone unlocked and accessible before I flash it, i.e. I have to have physical access and some verification that I'm the owner of the phone. I can imagine a hypothetical car modification scenario doing something similar. And if I'm a shithead and I modify my car's headlight firmware to intentionally blind other road users, well, we've got existing laws that are supposed to deal with that sort of thing.