I have a tentative circuit for power switching the RPi CM3 that behaves like the power switching in a PC:
1) Pressing the button while the power is off turns it on;
2) Pressing the button again in the early stages of the boot turns it off;
3) Pressing the button once the system has enabled write access to the file system activates a shutdown request;
4) Holding the button unconditionally forces the power off after five seconds.
The circuit can be powered from the coin cell that runs the RTC while off, and from the wall power while on.
Since the function of the button must change at a particular point in the boot, I'm wondering if this is possible using the gpio-poweroff and gpio-shutdown overlays. I should be able to configure the latter so that the weak pullup on GPIO 26 keeps it low in the early boot, then it is driven high when the overlay initializes, and then low again when shutdown is complete. But there are two questions:
1) Is it guaranteed that overlays are loaded and initialized before the root file system is mounted as read/write?
2) Is there a way to control the order of overlays, so that gpio-shutdown is ready to respond to a shutdown request before gpio-poweroff has told my circuit to change the button function?