2014-11-26 12:33:58 +01:00
|
|
|
#! /bin/bash
|
2014-10-08 07:39:24 +02:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: armhwinfo
|
|
|
|
# Required-Start:
|
2014-10-12 09:20:35 +02:00
|
|
|
# Required-Stop: glibc
|
2014-10-12 07:27:38 +02:00
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2015-12-02 20:33:32 +01:00
|
|
|
# Short-Description: Get some info about hardware for some ARM single board computers and set some basic things
|
2014-10-08 07:39:24 +02:00
|
|
|
### END INIT INFO
|
|
|
|
|
2016-02-25 23:40:24 +01:00
|
|
|
# Immediately exit if not called from init system at startup
|
|
|
|
if [ "X$1" != "Xstart" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-28 18:17:17 +01:00
|
|
|
create_motd_warning() {
|
|
|
|
cat > /etc/update-motd.d/90-warning <<EOT
|
|
|
|
#!/bin/bash
|
|
|
|
echo -e "\e[0;91mAttention:\x1B[0m $1\n"
|
|
|
|
rm "\$0"
|
|
|
|
EOT
|
|
|
|
chmod +x /etc/update-motd.d/90-warning
|
|
|
|
} # create_motd_warning
|
|
|
|
|
2016-02-20 14:33:17 +01:00
|
|
|
TMPFILE=$(mktemp /tmp/${0##*/}.XXXXXX)
|
|
|
|
trap "rm \"${TMPFILE}\" ; exit 0" 0 1 2 3 15
|
|
|
|
dmesg >"${TMPFILE}"
|
|
|
|
SERVER_IP=$(hostname -I)
|
2014-10-08 07:39:24 +02:00
|
|
|
CORES=$(grep -c ^processor /proc/cpuinfo)
|
2016-02-20 14:33:17 +01:00
|
|
|
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}")
|
2016-02-28 12:36:13 +01:00
|
|
|
SUN8IPHY="$(awk -F"PHY ID " '/PHY ID / {print $2}' <"${TMPFILE}")"
|
2016-02-20 14:33:17 +01:00
|
|
|
LEDS=$(grep "green:ph02:led1" "${TMPFILE}")
|
|
|
|
TERMINUS=$(lsusb | grep "1a40:0101")
|
|
|
|
SWITCH=$(grep "BCM53125" "${TMPFILE}")
|
|
|
|
INTERUPT=$(grep "eth0" /proc/interrupts)
|
2016-02-22 12:10:38 +01:00
|
|
|
WIFI8189ES=$(lsmod | grep 8189es | grep -v "0 $" | grep -v "0$") # ignore when not loaded
|
2016-01-20 09:09:46 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
for i in $( lsblk -idn -o NAME ); do
|
2016-02-20 14:33:17 +01:00
|
|
|
read ROTATE </sys/block/$i/queue/rotational
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2014-10-08 07:39:24 +02:00
|
|
|
if [ "$ARCH" = "armv7l" ]; then
|
2015-12-24 22:42:12 +01:00
|
|
|
if [ $HARDWARE = "ODROID-XU3" ]; then
|
2016-01-01 12:24:16 +01:00
|
|
|
ID="Odroid XU4"
|
2015-12-27 19:28:10 +01:00
|
|
|
fi
|
2016-01-09 10:31:20 +01:00
|
|
|
if [ $HARDWARE = "Marvell" ]; then
|
|
|
|
ID="Clearfog"
|
|
|
|
fi
|
2015-12-27 19:28:10 +01:00
|
|
|
if [ $HARDWARE = "gs705a" ]; then
|
|
|
|
ID="Guitar"
|
|
|
|
fi
|
2015-12-02 20:33:32 +01:00
|
|
|
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
|
2016-02-25 23:40:24 +01:00
|
|
|
echo 2 >/proc/irq/$(awk -F":" '/eth0/ {print $1}' </proc/interrupts | sed 's/\ //g')/smp_affinity
|
2014-10-08 07:39:24 +02:00
|
|
|
fi
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2016-02-20 14:33:17 +01:00
|
|
|
if [ $MEMTOTAL -gt 1500 ]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
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"
|
2016-02-20 14:33:17 +01:00
|
|
|
elif [ $MEMTOTAL -lt 1500 ]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
ID="Micro"
|
|
|
|
else
|
|
|
|
ID="Cubieboard"
|
2014-10-08 07:39:24 +02:00
|
|
|
fi
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
elif [ "$HARDWARE" = "Freescale" ]; then
|
2016-02-20 14:33:17 +01:00
|
|
|
if [ $MEMTOTAL -gt 1500 ]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
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
|
2016-02-25 15:23:02 +01:00
|
|
|
|
|
|
|
if [ -f /proc/device-tree/model ]; then
|
|
|
|
# mainline kernel, parsing cpuinfo is different
|
|
|
|
HARDWARE=$(awk '/Hardware/ {print $4}' </proc/cpuinfo)
|
2016-02-25 23:40:24 +01:00
|
|
|
GbE="eth0"; WiFi="wlan0"; USB1="usb1"; USB2="usb2"; USB3="usb3"
|
2016-02-25 15:23:02 +01:00
|
|
|
else
|
|
|
|
# kernel 3.4.x
|
|
|
|
GbE="gmac0"; WiFi="wlan0"; USB1="usb2"; USB2="usb3"; USB3="usb4"
|
|
|
|
fi
|
|
|
|
if [ $HARDWARE = "sun8i" ]; then
|
|
|
|
ID="Orange H3"
|
2016-02-25 23:40:24 +01:00
|
|
|
# 3 or 30 sec user feedback that the board is ready after 1st login with 3.4 kernel
|
|
|
|
SwapState="$(grep swap /etc/fstab)"
|
|
|
|
if [ -f /sys/class/leds/green_led/trigger -a "X${SwapState}" != "X" ]; then
|
|
|
|
echo timer >/sys/class/leds/green_led/trigger
|
|
|
|
echo 200 >/sys/class/leds/green_led/delay_off
|
|
|
|
echo 200 >/sys/class/leds/green_led/delay_on
|
|
|
|
[ -f "/root/.not_logged_in_yet" ] && BlinkTime=30 || BlinkTime=3
|
|
|
|
(sleep ${BlinkTime} && echo none >/sys/class/leds/green_led/trigger) &
|
|
|
|
fi
|
|
|
|
|
2016-02-25 15:23:02 +01:00
|
|
|
# redistribute USB irqs to dedicated cores
|
|
|
|
echo 2 >/proc/irq/$(awk -F":" "/${USB1}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
|
|
|
echo 4 >/proc/irq/$(awk -F":" "/${USB2}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity 2>/dev/null # OPi One
|
|
|
|
if [ "$TERMINUS" != "" ]; then
|
|
|
|
# Ethernet irqs on cpu3
|
|
|
|
echo 8 >/proc/irq/$(awk -F":" "/${GbE}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
|
|
|
ID="Orange Pi+"
|
|
|
|
if [ $MEMTOTAL -gt 1500 ]; then
|
|
|
|
ID="Orange Pi+ 2"
|
|
|
|
fi
|
2016-02-28 12:36:13 +01:00
|
|
|
case ${SUN8IPHY} in
|
2016-02-25 15:23:02 +01:00
|
|
|
00441400*)
|
|
|
|
if [ "$WIFI8189ES" != "" ]; then
|
|
|
|
ID="Orange Pi 2"
|
|
|
|
else
|
|
|
|
ID="Orange Pi 2 mini"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
elif [ "$WIFI8189ES" != "" ]; then
|
|
|
|
ID="Orange Pi Lite"
|
|
|
|
echo 8 >/proc/irq/$(awk -F":" "/${WiFi}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
|
|
|
elif [ $MEMTOTAL -gt 600 ]; then
|
2016-02-28 12:36:13 +01:00
|
|
|
case ${SUN8IPHY} in
|
|
|
|
00441400*)
|
|
|
|
ID="Orange Pi PC"
|
|
|
|
echo 8 >/proc/irq/$(awk -F":" "/${USB3}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ID="Banana Pi M2+"
|
|
|
|
echo 8 >/proc/irq/$(awk -F":" "/${GbE}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
|
|
|
;;
|
|
|
|
esac
|
2016-02-25 15:23:02 +01:00
|
|
|
else
|
|
|
|
ID="Orange Pi One"
|
|
|
|
fi
|
2016-02-28 12:36:13 +01:00
|
|
|
# prepare board/settings mismatch detection. If we cleanup board/config names then this
|
|
|
|
# might work for all boards later and can be moved from sun8i section further down to support
|
2016-02-28 18:17:17 +01:00
|
|
|
# all $HARDWARE variants. Only check board after 1st login already happened to be not in
|
|
|
|
# conflict with our board auto detection mechanisms
|
2016-02-28 12:36:13 +01:00
|
|
|
ScriptBinName="$(echo "${ID}" | tr '[:upper:]' '[:lower:]' | sed -e 's/+/plus/' -e 's/\ //g' -e 's/2mini$/2/g' -e 's/plus2$/plus/g').bin"
|
|
|
|
ScriptBinUsed="$(readlink -f "/boot/script.bin")"
|
2016-02-28 18:17:17 +01:00
|
|
|
if [ "X${ScriptBinName}" != "X${ScriptBinUsed##*/}" -a ! -f "/root/.not_logged_in_yet" ]; then
|
|
|
|
create_motd_warning "It seems the image is running on ${ID} but you're using wrong settings: ${ScriptBinUsed##*/}"
|
2016-02-28 12:36:13 +01:00
|
|
|
fi
|
2016-02-25 15:23:02 +01:00
|
|
|
fi
|
2016-02-29 16:13:15 +01:00
|
|
|
elif [ "$ARCH" = "aarch64" ]; then
|
|
|
|
if [ $HARDWARE = "sun50iw1p1" ]; then
|
|
|
|
if [ $MEMTOTAL -gt 600 ]; then
|
|
|
|
ID="Pine64+"
|
|
|
|
else
|
|
|
|
ID="Pine64"
|
|
|
|
fi
|
|
|
|
fi
|
2016-02-20 20:11:27 +01:00
|
|
|
fi
|
2016-02-25 15:23:02 +01:00
|
|
|
|
2016-02-25 13:17:13 +01:00
|
|
|
[ -f /proc/device-tree/model ] && read MACHINE </proc/device-tree/model
|
|
|
|
|
2014-11-26 12:33:58 +01:00
|
|
|
if [[ $MACHINE == *LIME2 ]]; then ID="Lime 2"; fi
|
|
|
|
if [[ $MACHINE == *LIME ]]; then ID="Lime"; fi
|
2015-12-02 20:33:32 +01:00
|
|
|
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 == *Neo* ]]; then ID="Udoo Neo"; fi
|
|
|
|
if [[ $MACHINE == *Cubietruck* ]]; then ID="Cubietruck"; fi
|
|
|
|
if [[ $MACHINE == *Cubieboard* ]]; then ID="Cubieboard"; fi
|
2016-02-19 13:28:57 +01:00
|
|
|
if [[ $MACHINE == *Pro* ]]; then ID="Banana Pro"; fi
|
2016-02-09 20:13:57 +01:00
|
|
|
if [[ $MACHINE == *M2* ]]; then ID="Banana M2"; fi
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
echo -e "[\e[0;32m ok \x1B[0m] Starting ARM hardware info: $ID"
|
2016-02-25 15:23:02 +01:00
|
|
|
echo $ID > /var/run/machine.id
|
2016-02-22 12:10:38 +01:00
|
|
|
export HARDWARE DISTROID DISTROCODE ARCH KERNELID MACHINE ID
|