Delayed activation of USB port

We have a CM4 module inside an Andino IO module on their CM4 board.
The RPi4 bootloader is configured to start from our Samsung SSD980 512GB NVMe which has BalenaOS installed.
For communication, we have a 4G/LTE modem connected on the CM4 board USB port.

With everything connected, we sometimes get the “Danger! The device is undervolted!” warning in the Balena dashboard.
The system seems stable even with 4G connected. Assume the voltage is still just enough.

But we have issues with reboots:

  • Sometimes, the boot hangs (status leds are no longer blinking)
  • Sometimes, the modem is not initialized correctly and all modem commands time out.

Rebooting without modem, works stable.

We assume that, during startup, the SSD and 4G take too much current and cause the voltage to drop too low.
We want to try to enable the modem with a delay. So, we can spread the consumption and hopefully get stable reboots.

The modem is connected on the USB port which is enabled by the dtoverlay=dwc2.
Is there a way to delay this overlay?
Or another approach to delay the USB power?

I taught on delaying the NetworkManager interface but the modem is powered even before that service is started.

I’ve reached out to some team members to see if they might be able to provide some more detailed guidance with regards to your issue. In the meantime, this article on dynamically loading device tree overlays might be helpful.

I found a few other articles that might be helpful to you. Here is a balena project which mentions dynamically loading device tree overlays: balena-logging-sensors/ at master · balenalabs-incubator/balena-logging-sensors · GitHub

Here is some Raspberry Pi specific information on the topic, as well: pi 4 - Using the Dynamic Device Tree to add Overlays at Run Time - Raspberry Pi Stack Exchange

Thanks @jmakivic for the links.
I was able to dynamically load the dtoverlay.

I removed the dtoverlay from the device configuration. So, no USB ports are loaded on startup (lsmod is empty)

After startup, I run these commands to enable the USB ports and the modem:

mkdir -p /sys/kernel/config/device-tree/overlays/dwc2
cat /mnt/boot/overlays/dwc2.dtbo > /sys/kernel/config/device-tree/overlays/dwc2/dtbo

I still need to test this approach from a container.
But think it will be possible from a privileged container.