armbian-build/scripts/armhwinfo

157 lines
5.0 KiB
Bash

#! /bin/bash
### BEGIN INIT INFO
# Provides: armhwinfo
# Required-Start:
# Required-Stop: glibc
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Get some info about hardware for some ARM single board computers and set some basic things
### END INIT INFO
TMPFILE=$(mktemp /tmp/${0##*/}.XXXXXX)
trap "rm \"${TMPFILE}\" ; exit 0" 0 1 2 3 15
dmesg >"${TMPFILE}"
SERVER_IP=$(hostname -I)
CORES=$(grep -c ^processor /proc/cpuinfo)
MEMTOTAL=$(( $(awk -F" " '/^MemTotal/ {print $2}' </proc/meminfo) / 1024 ))
ARCH=$(lscpu | awk '/Architecture/ {print $2}')
RTC=$(awk '/rtc0/ {print $(NF)}' <"${TMPFILE}")
HB_PCI=$(grep '16c3:abcd' "${TMPFILE}")
HARDWARE=$(awk '/Hardware/ {print $3}' </proc/cpuinfo)
GMAC=$(grep "sun6i_gmac" "${TMPFILE}")$(grep "gmac0-" "${TMPFILE}")
ORANGEPIPHY="$(awk -F"PHY ID " '/PHY ID / {print $2}' <"${TMPFILE}")"
LEDS=$(grep "green:ph02:led1" "${TMPFILE}")
TERMINUS=$(lsusb | grep "1a40:0101")
SWITCH=$(grep "BCM53125" "${TMPFILE}")
INTERUPT=$(grep "eth0" /proc/interrupts)
WIFI8189ES=$(lsmod | grep 8189es)
case "$1" in
start)
# ARM
for i in $( lsblk -idn -o NAME ); do
read ROTATE </sys/block/$i/queue/rotational
# mechanical drives
if [ "$ROTATE" = 1 ]; then echo cfq > /sys/block/$i/queue/scheduler;
echo -e "[\e[0;32m ok \x1B[0m] Setting cfg I/O scheduler for $i"
# solid state drives
elif [ "$ROTATE" = 0 ]; then echo noop > /sys/block/$i/queue/scheduler;
echo -e "[\e[0;32m ok \x1B[0m] Setting noop I/O scheduler for $i"
fi
done
if [ "$ARCH" = "armv7l" ]; then
if [ $HARDWARE = "ODROID-XU3" ]; then
ID="Odroid XU4"
fi
if [ $HARDWARE = "Marvell" ]; then
ID="Clearfog"
fi
if [ $HARDWARE = "gs705a" ]; then
ID="Guitar"
fi
if [ $HARDWARE = "sun8i" ]; then
ID="Orange H3"
if [ "$TERMINUS" != "" ]; then
ID="Orange Pi+"
if [ $MEMTOTAL -gt 1500 ]; then
ID="Orange Pi+ 2"
fi
# redistribute USB irqs to dedicated cores
echo 2 >/proc/irq/$(awk -F":" '/usb2/ {print $1}' </proc/interrupts)/smp_affinity
echo 4 >/proc/irq/$(awk -F":" '/usb3/ {print $1}' </proc/interrupts)/smp_affinity
echo 8 >/proc/irq/$(awk -F":" '/gmac0/ {print $1}' </proc/interrupts)/smp_affinity
case ${ORANGEPIPHY} in
00441400*)
if [ "$WIFI8189ES" != "" ]; then
ID="Orange Pi 2"
else
ID="Orange Pi 2 mini"
fi
;;
esac
elif [ "$WIFI8189ES" != "" ]; then
ID="Orange Pi Lite"
elif [ $MEMTOTAL -gt 600 ]; then
ID="Orange Pi PC"
# redistribute USB irqs to dedicated cores
echo 2 >/proc/irq/$(awk -F":" '/usb2/ {print $1}' </proc/interrupts)/smp_affinity
echo 4 >/proc/irq/$(awk -F":" '/usb3/ {print $1}' </proc/interrupts)/smp_affinity
echo 8 >/proc/irq/$(awk -F":" '/usb4/ {print $1}' </proc/interrupts)/smp_affinity
else
ID="Orange Pi One"
fi
fi
if [ $HARDWARE = "sun4i" ] || [ $HARDWARE = "Allwinner" ]; then
ID="Cubieboard"
fi
if [ $HARDWARE = "sun7i" ] || [ $HARDWARE = "Allwinner" ]; then
# redistribute irq to dedicated core
if [ "$INTERUPT" != "" ] && [ "$CORES" -gt 1 ]; then
echo 2 >/proc/irq/$(awk -F":" '/eth0/ {print $1}' </proc/interrupts)/smp_affinity
fi
if [ $MEMTOTAL -gt 1500 ]; then
ID="Cubietruck"
elif [ -n "$GMAC" ]; then
if [ "$TERMINUS" != "" ]; then
ID="Orange"
elif [ "$SWITCH" != "" ]; then
ID="Lamobo R1"
elif [ "$LEDS" != "" ]; then
ID="Lime 2"
else
ID="Banana"
fi
elif [ "$LEDS" != "" ]; then
ID="Lime"
elif [ $MEMTOTAL -lt 1500 ]; then
ID="Micro"
else
ID="Cubieboard"
fi
elif [ "$HARDWARE" = "Freescale" ]; then
if [ $MEMTOTAL -gt 1500 ]; then
ID="Cubox i4"
elif [ "$HB_PCI" != "" ]; then
ID="HB i2eX"
elif [ "$RTC" = "rtc0" ]; then
ID="Cubox i2eX"
elif [ "$CORES" = 1 ]; then
ID="HB i1"
else
ID="HB i2"
fi
[ -f /proc/asound/imxvt1613audio/id ] && ID="Udoo"
fi
fi
[ -f /proc/device-tree/model ] && MACHINE=$(cat /proc/device-tree/model)
if [[ $MACHINE == *LIME2 ]]; then ID="Lime 2"; fi
if [[ $MACHINE == *LIME ]]; then ID="Lime"; fi
if [[ $MACHINE == *Micro ]]; then ID="Micro"; fi
if [[ $MACHINE == *Banana* ]]; then ID="Banana"; fi
if [[ $MACHINE == *Udoo* ]]; then ID="udoo"; fi
if [[ $MACHINE == *Lamobo* ]]; then ID="Lamobo R1"; fi
if [[ $MACHINE == *Orange* ]]; then ID="Orange"; fi
if [[ $MACHINE == *Neo* ]]; then ID="Udoo Neo"; fi
if [[ $MACHINE == *Cubietruck* ]]; then ID="Cubietruck"; fi
if [[ $MACHINE == *Cubieboard* ]]; then ID="Cubieboard"; fi
if [[ $MACHINE == *Pro* ]]; then ID="Banana Pro"; fi
if [[ $MACHINE == *M2* ]]; then ID="Banana M2"; fi
echo -e "[\e[0;32m ok \x1B[0m] Starting ARM hardware info: $ID"
echo $ID >> /var/run/machine.id
;;
stop|reload|restart|force-reload|status)
echo -e "[\e[0;32m ok \x1B[0m] Stopping ARM hardware info ..."
;;
*)
exit 1
;;
esac