summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/flash/sila-flash-bios/flash-bios
blob: 0ad86deef4aa5d44840ac991874a18a75a788508 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash

set -eo pipefail

programm=`basename $0`

log() {
  logger -t ${programm} -p 1  "$@"
}

FWTYPE="BIOS"
FWVER="0.00"
redfish_log_fw_evt() {
  local evt=$1
  [ -z "$FWTYPE" ] && return
  [ -z "$FWVER" ] && return
  case "$evt" in
    start)
      logger -t ${programm} -p 1 "${FWTYPE} firmware update to version ${FWVER} started"
      ;;
    success)
      logger -t ${programm} -p 1 "${FWTYPE} firmware update to version ${FWVER} completed successfully."
      ;;
    abort)
      logger -t ${programm} -p 1 "${FWTYPE} firmware update to version ${FWVER} failed."
      ;;
    invalid_args)
      logger -t ${programm} -p 1 "${FWTYPE} firmware update failed: Invalid argument"
      ;;
    invalid_image)
      logger -t ${programm} -p 1 "${FWTYPE} firmware update failed: Invalid firmware image"
      ;;
    *) return ;;
  esac
}

wait_for_log_sync()
{
  sync
  sleep 5
}

interface=xyz.openbmc_project.Software.BMC.Updater
busctl_path=
bios_image=
bios_version=
bios_ext_version=

get_firmware_busctl_path() {
  local ipath=$1
  local bpath=/xyz/openbmc_project/software/`echo "${ipath}" | rev | cut -f1 -d'/' | rev`
  echo "${bpath}"
}

get_firmware_purpose() {
  local iface=$1
  local fwpath=$2
  local purpose=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Software.Version Purpose | sed 's,^s ",,' | sed 's,"$,,' | rev | cut -f1 -d'.' | rev`
  echo "${purpose}"
}

get_firmware_activation() {
  local iface=$1
  local fwpath=$2
  local activation=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Software.Activation Activation | sed 's,^s ",,' | sed 's,"$,,' | rev | cut -f1 -d'.' | rev`
  echo "${activation}"
}

get_firmware_path() {
  local iface=$1
  local fwpath=$2
  local path=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Common.FilePath Path | sed 's,^s ",,' | sed 's,"$,,'`
  echo "${path}"
}

get_firmware_version() {
  local iface=$1
  local fwpath=$2
  local version=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Software.Version Version | sed 's,^s ",,' | sed 's,"$,,'`
  echo "${version}"
}

get_firmware_extended_version() {
  local iface=$1
  local fwpath=$2
  local eversion=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Software.ExtendedVersion ExtendedVersion | sed 's,^s ",,' | sed 's,"$,,'`
  echo "${eversion}"
}

get_firmware_file_name() {
  local iface=$1
  local fwpath=$2
  local fname=`busctl get-property ${iface} ${fwpath} xyz.openbmc_project.Inventory.Decorator.Compatible Names | grep "as 1" | sed 's,^as 1 ",,' | sed 's,"$,,'`
  echo "${fname}"
}

get_bios_image() {
  local iface=$1
  local bpath=$2
  local purpose=`get_firmware_purpose ${iface} ${bpath}`
  local active=`get_firmware_activation ${iface} ${bpath}`
  if [ "${purpose}" = "Host" -a "${active}" = "Activating" ] ; then
    local path=`get_firmware_path ${iface} ${bpath}`
    local fname=`get_firmware_file_name ${iface} ${bpath}`
    if [ -f "${path}/${fname}" ] ; then
      echo "${path}/${fname}"
    fi
  fi
}

get_bios_version() {
  local image=$1
  local hash=`echo ${image} | rev | cut -f2 -d'/' | rev`
  local version=`get_firmware_version ${interface} /xyz/openbmc_project/software/${hash}`
  echo "${version}"
}

get_bios_extended_version() {
  local image=$1
  local hash=`echo ${image} | rev | cut -f2 -d'/' | rev`
  local ext_version=`get_firmware_extended_version ${interface} /xyz/openbmc_project/software/${hash}`
  echo "${ext_version}"
}


image_path=$1

if [ "x${image_path}" = "x" ] ; then
  redfish_log_fw_evt invalid_args
  exit 1
fi

busctl_path="`get_firmware_busctl_path ${image_path}`"
bios_image="`get_bios_image ${interface} ${busctl_path}`"
bios_version="`get_bios_version ${bios_image}`"
bios_ext_version="`get_bios_extended_version ${bios_image}`"

if [ "${bios_image}" = "x" ] ; then
  redfish_log_fw_evt invalid_image
  exit 1
fi
if [ "${bios_version}" = "x" ] ; then
  redfish_log_fw_evt invalid_image
  exit 1
fi

FWVER="${bios_version}"

#######################
# Start BIOS Flashing:
#
redfish_log_fw_evt start


#######################
# main routine:
#
logger -t ${programm} -p 1 "Flashing the '${bios_image}' image..."
#
# end of main routine.
#######################


#######################
# Stop BIOS Flashing:
#
redfish_log_fw_evt success
wait_for_log_sync