diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2020-12-08 00:38:17 +0300 |
---|---|---|
committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2020-12-08 00:38:17 +0300 |
commit | 8d6ae7f2a817751fad151168fa10ce28ee0869d8 (patch) | |
tree | 281032f7ec07c41589aa094bd165cc2a98f2d3a7 /meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh | |
parent | c16fb8893b19075db4bcf3b5bf33c1db8c3ca2bd (diff) | |
parent | 5da3c2284560a7e08ffafd03c5b5ba44a3242228 (diff) | |
download | openbmc-8d6ae7f2a817751fad151168fa10ce28ee0869d8.tar.xz |
Merge tag '0.26' of ssh://git-amr-1.devtools.intel.com:29418/openbmc-openbmc into update
Diffstat (limited to 'meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh')
-rw-r--r-- | meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh b/meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh new file mode 100644 index 000000000..3a215fa50 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh @@ -0,0 +1,84 @@ +#!/bin/sh +# Copyright 2020 Google LLC +# Copyright 2020 Quanta Computer Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Global variables + +# GPIO to control the host SPI mux +SPI_SW_SELECT=169 + +# Kernel control string for bind/unbind +KERNEL_FIU_ID="c0000000.fiu" + +# Kernel sysfs path for bind/unbind +KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU" + +IMAGE_FILE="/tmp/image-bios" + +# Taken from /run/initramfs/update +# Given label name, return mtd node. e.g. `findmtd bmc` returns 'mtd0' +findmtd() { + m=$(grep -xl "$1" /sys/class/mtd/*/name) + m=${m%/name} + m=${m##*/} + echo $m +} + +cleanup() { + if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then + echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind + fi + echo low > /sys/class/gpio/gpio${SPI_SW_SELECT}/direction # Switch mux to host + rm -f ${IMAGE_FILE} +} +trap cleanup EXIT SIGHUP SIGINT SIGTERM + +main() { + if [ ! -f ${IMAGE_FILE} ]; then + echo "Invalid bios image file!" + exit 1 + fi + + echo "Starting bios update..." + if [ ! -d "/sys/class/gpio/gpio${SPI_SW_SELECT}" ]; then + echo "${SPI_SW_SELECT}" > /sys/class/gpio/export + fi + + echo high > /sys/class/gpio/gpio${SPI_SW_SELECT}/direction # Switch mux to BMC + + if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then + echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind + fi + echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind + + # BIOS flash is labelled 'pnor' + pnor_mtd=$(findmtd pnor) + if [ -z "${pnor_mtd}" ]; then + echo "Cannot find bios flash mtd partition!" + exit 1 + fi + + flashcp -v $IMAGE_FILE /dev/"${pnor_mtd}" + if [ $? -eq 0 ]; then + echo "bios update successfully..." + else + echo "bios update failed..." + exit 1 + fi +} +# Exit without running main() if sourced +return 0 2>/dev/null + +main "$@" |