In arm64 SHI: turn on PoE fan in U-Boot and Linux
This enables the Power-over-Ethernet fan at 100%
speed when U-Boot starts up, as well as creates a
Linux service that ensures the fan is on as well.
Future variants might modify the service to vary
the fan speed based on temperature.
Bug: 147114554
Test: local build and boot
Change-Id: Ifb63a2be4a4e17788dc8b6269b06e6467244b9e3
diff --git a/tools/create_base_image_arm.sh b/tools/create_base_image_arm.sh
index 69c2a01..64133e9 100755
--- a/tools/create_base_image_arm.sh
+++ b/tools/create_base_image_arm.sh
@@ -181,6 +181,8 @@
fi
cat > ${mntdir}/boot/boot.cmd << "EOF"
+setenv start_poe 'gpio set 150; gpio clear 146'
+run start_poe
setenv bootcmd_dhcp '
mw.b ${scriptaddr} 0 0x8000
mmc dev 0 0
@@ -328,6 +330,66 @@
git clone https://github.com/google/android-cuttlefish.git
cd -
+ echo "Creating PoE script..."
+ cat > ${mntdir}/usr/local/bin/poe << "EOF"
+#!/bin/bash
+
+if [ "$1" == "--start" ]; then
+ echo 146 > /sys/class/gpio/export
+ echo out > /sys/class/gpio/gpio146/direction
+ echo 0 > /sys/class/gpio/gpio146/value
+ echo 150 > /sys/class/gpio/export
+ echo out > /sys/class/gpio/gpio150/direction
+ echo 1 > /sys/class/gpio/gpio150/value
+ exit 0
+fi
+
+if [ "$1" == "--stop" ]; then
+ echo 0 > /sys/class/gpio/gpio146/value
+ echo 146 > /sys/class/gpio/unexport
+ echo 0 > /sys/class/gpio/gpio150/value
+ echo 150 > /sys/class/gpio/unexport
+ exit 0
+fi
+
+if [ ! -e /sys/class/gpio/gpio146/value ] || [ ! -e /sys/class/gpio/gpio150/value ]; then
+ echo "error: PoE service not initialized"
+ exit 1
+fi
+
+if [ "$1" == "0" ] || [ "$1" == "off" ] || [ "$1" == "OFF" ]; then
+ echo 0 > /sys/class/gpio/gpio150/value
+ exit 0
+fi
+
+if [ "$1" == "1" ] || [ "$1" == "on" ] || [ "$1" == "ON" ]; then
+ echo 1 > /sys/class/gpio/gpio150/value
+ exit 0
+fi
+
+echo "usage: poe <0|1>"
+exit 1
+EOF
+ chown root:root ${mntdir}/usr/local/bin/poe
+ chmod 755 ${mntdir}/usr/local/bin/poe
+
+ echo "Creating PoE service..."
+ cat > ${mntdir}/etc/systemd/system/poe.service << EOF
+[Unit]
+ Description=PoE service
+ ConditionPathExists=/usr/local/bin/poe
+
+[Service]
+ Type=oneshot
+ ExecStart=/usr/local/bin/poe --start
+ ExecStop=/usr/local/bin/poe --stop
+ RemainAfterExit=true
+ StandardOutput=journal
+
+[Install]
+ WantedBy=multi-user.target
+EOF
+
echo "Creating led script..."
cat > ${mntdir}/usr/local/bin/led << "EOF"
#!/bin/bash
@@ -513,6 +575,7 @@
chroot ${mntdir} /bin/bash << "EOT"
echo "Enabling services..."
+systemctl enable poe
systemctl enable led
systemctl enable sd-dupe