How does the Pi know it being under-powered and to show the lighting bolt?
This is a very good question, IMHO, and since it doesn't seem to have a current and complete answer, I'd like to chime in. First, I need to credit @Ghanima's Q&A here for calling out the PMIC (Power Management IC) as the MXL7704.
The operation of the MxL7704 is covered here, and in the data sheet.
If we begin with the Rev 4 schematics for the RPi 4B, we see the pertinent connections between the MxL7704 and the USB-C power input summarized in the schematic below:

simulate this circuit – Schematic created using CircuitLab
Note first the 5V_SYS
node is simply a low-pass filtered version of the VBUS
5V input power. The filter has a time constant determined by R5 & C12 of 0.1 msec. 5V_SYS
is the voltage monitored by the MxL7704, and compared to its 4.63V internal reference to determine the state of the Power Good
outputs (PG1
& PG2
) at pins 5 & 20, respectively. Please refer to the MxL7704 data sheet, and the block diagram (copied below) for details.

Knowing how the RPi's 5V power input is low-pass filtered, and routed to the MxL7704 as 5V_SYS
, the Block Diagram fills in most of the other details to answer the question:
The 4.63V voltage monitor (MON) provides a binary output indicating whether 5V_SYS
is above the 4.63V threshold, or below it. This output is stored in a data register in the I2C
block, and from there it is also available to the PGOOD
state machine.
The PGOOD
state machine receives inputs from the "external system" (RPi's SOC) via the I2C
bus that configure the state machine. This configuration, in turn, determines how it processes its various inputs to yield the PG1
and PG2
outputs at pins 5 & 20 of the MxL7704.
The status of the 5V_SYS
voltage (i.e. above or below 4.63V) is kept in one of the registers internal to the MxL7704. The section of the data sheet titled Input Voltage Monitor Flag covers details, but of course cannot tell us how the RPi's proprietary hardware and firmware interact with the MxL7704.
Nevertheless, it is evident that this binary representation of the 5V_SYS
status stored in these registers is the value used by the RPi to set and clear the Low Voltage Warning flag.
vcgenmd
not found on my pi 3B, but/opt/vc/bin/vcgencmd
found.