summarylogtreecommitdiffstats
path: root/rocketport-upci-firmware.sh
blob: 41bc34ef25f2d716ba19a66945288c67277d05a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/bash

# 2017-07-17 -CJS (GPL)

# switches:
#   --systemd - run notify at end. This MUST be the first switch
#   Add any of the loadrm2 switches you want
# Examples
#   rocketport-upci-firmware.sh -p
#   rocketport-upci-firmware.sh --systemd -p

#ROCKETMODEM II NOTE

#If you are using a RocketModem II board, further installation and
#setup is required.  Note: this does not apply to RocketModem IIs
#boards.

# Load firmware onto all RocketModem II
# The instructions say to load it on all ports but that
# causes long delays.

# sudo sed -e 's:^:#:g' '/proc/tty/driver/rocketupci'
#serinfo:1.0 driver revision:
#0: uart:RP UPCI Plus 4 port RJ45 port:0001B000 irq:18 tx:30 rx:0
#1: uart:RP UPCI Plus 4 port RJ45 port:0001B002 irq:18 tx:30 rx:0
#2: uart:RP UPCI Plus 4 port RJ45 port:0001B004 irq:18 tx:30 rx:0
#3: uart:RP UPCI Plus 4 port RJ45 port:0001B006 irq:18 tx:30 rx:0

#No response from RocketModem on /dev/ttyR0, trying reset...
#No response from RocketModem on /dev/ttyR1, trying reset...
#No response from RocketModem on /dev/ttyR2, trying reset...
#No response from RocketModem on /dev/ttyR3, trying reset...
#No response from RocketModem on /dev/ttyR0, couldn't initialize.
#No response from RocketModem on /dev/ttyR1, couldn't initialize.
#No response from RocketModem on /dev/ttyR2, couldn't initialize.
#No response from RocketModem on /dev/ttyR3, couldn't initialize.

# The right modems are easy to detect.

set -e
set -u

module='rocket'

if [ "${EUID}" -ne 0 ]; then
  echo 'root is required to load firmware'
  exit 1
fi

_opt_systemd=0
if [ "${1:-}" = '--systemd' ]; then
  _opt_systemd=1
  shift
fi

# just in case the boot is too fast
if [ ! -f "/proc/tty/driver/${module}" ]; then
  echo "wait for online: /proc/tty/driver/${module}"
  sleep 5
fi

if readarray -t rockets < "/proc/tty/driver/${module}"; then
  #declare -p rockets
  rocketmodems=()
  for rocket in "${rockets[@]}"; do
    #echo "Checking ${rocket}"
    if [[ "${rocket^^}" =~ ^[0-9]+:.*' PCI RocketModem II ' ]]; then
      rocketmodems+=("/dev/ttyR${rocket%%:*}")
    fi
  done
  if [ "${#rocketmodems[@]}" -ne 0 ]; then
    loadrm2 "$@" "${rocketmodems[@]}"
  fi
fi

if [ "${_opt_systemd}" -ne 0 ]; then
  systemd-notify --ready
fi