summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-fw.sh18
-rw-r--r--meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh48
2 files changed, 49 insertions, 17 deletions
diff --git a/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-fw.sh b/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-fw.sh
index a0f11544e5..4b0ab09377 100644
--- a/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-fw.sh
+++ b/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-fw.sh
@@ -7,23 +7,13 @@
source /usr/libexec/mori-fw/mori-lib.sh
function fwbios() {
- KERNEL_FIU_ID="c0000000.spi"
- KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
ret=0
if [ ! -f "$1" ]; then
echo " Cannot find the" "$1" "image file"
return 1
fi
- # switch the SPI mux from Host to BMC
- set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 1
-
- # rescan the spi bus
- if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
- echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
- sleep 1
- fi
- echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
+ setup_bios_access
# write to the mtd device
BIOS_MTD=$(grep "hnor" /proc/mtd | sed -n 's/^\(.*\):.*/\1/p')
@@ -34,11 +24,7 @@ function fwbios() {
ret=1
fi
- # switch the SPI mux from BMC to Host
- if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
- echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
- fi
- set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 0
+ cleanup_bios_access
return $ret
}
diff --git a/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh b/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
index 9c443bf718..45303c6296 100644
--- a/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
+++ b/meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
@@ -33,7 +33,7 @@ function get_gpio_num() {
if [[ $(gpiofind "$1" | cut -d " " -f 1) == "$X" ]]; then
# Used to select the correct GPIO_BASE value
#shellcheck disable=SC2086
- GPIO_BASE_DIR=$(echo ${GPIO_BASE_DIR} | cut -d " " -f $count)
+ GPIO_BASE_DIR=("$(echo ${GPIO_BASE_DIR} | cut -d " " -f $count)")
break
fi
count=$((count-1))
@@ -85,6 +85,48 @@ function Does_File_Exist() {
fi
}
+function cleanup_bios_access() {
+ # Run only if setup_bios_access was previously ran
+ if Does_File_Exist /run/bios_access &> /dev/null ; then
+ # switch the SPI mux from BMC to Host
+ if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
+ echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
+ fi
+ set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 0
+
+ # Indicate to host that BMC is finished accessing SPI
+ set_gpio_ctrl S0_BMC_SPI_NOR_ACCESS 0
+
+ rm /run/bios_access
+ fi
+}
+
+function setup_bios_access() {
+ # Run only if setup_bios_access was not previously ran without cleanup
+ if ! Does_File_Exist /run/bios_access &> /dev/null ; then
+ echo "BMC is accessing BIOS" > /run/bios_access
+
+ # rescan the spi bus
+ if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
+ echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
+ usleep 100
+ fi
+
+ # Wait until the host is finished accessing the SPI
+ while [[ $(get_gpio_ctrl S0_SOC_SPI_NOR_ACCESS) == 1 ]]
+ do
+ sleep 1
+ done
+ # Indicate to host that BMC is accessing SPI
+ set_gpio_ctrl S0_BMC_SPI_NOR_ACCESS 1
+
+ # switch the SPI mux from Host to BMC
+ set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 1
+
+ echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
+ fi
+}
+
# Start definitions
# I2C Definitions
@@ -101,3 +143,7 @@ I2C_HOTSWAP_CTRL=(25 1f)
# File Path Definition
# File path used to prevent hotswapping
RST_LOCK_FILE="/etc/FW_FLASH_ONGOING"
+
+# Device name and driver path used for BIOS SPI
+KERNEL_FIU_ID="c0000000.spi"
+KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"