From 4c89d8896cc64319452f7967a4ada78cb6cacd20 Mon Sep 17 00:00:00 2001 From: fuxuan Date: Wed, 3 Jul 2024 14:06:36 +0800 Subject: [PATCH 1/2] phosphor-software-manager: Supports remote BIOS firmware update Signed-off-by: fuxuan --- .../phosphor-software-manager/bios_flash.sh | 227 ++++++++++++++++++ .../obmc-flash-host-bios@.service | 8 + .../obmc-update-cpld@.service | 2 +- .../progress_monitoring.sh | 127 ++++++++++ .../phosphor-software-manager/update-cpld.sh | 2 +- .../phosphor-software-manager_%.bbappend | 9 +- 6 files changed, 372 insertions(+), 3 deletions(-) create mode 100755 meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/bios_flash.sh create mode 100755 meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-host-bios@.service create mode 100755 meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/progress_monitoring.sh diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/bios_flash.sh b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/bios_flash.sh new file mode 100755 index 0000000000..26a54f69d8 --- /dev/null +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/bios_flash.sh @@ -0,0 +1,227 @@ +#!/bin/bash + +# Temporary file path. +IMAGE_DIR=$1 + +IMAGE_ID=${IMAGE_DIR##*/} +IMAGE_FILE=${IMAGE_DIR}/bios.bin +BIOS_MTD_DEVICE= + +CURRENT_VERSION= +UPDATE_VERSION= + +# Get the current BIOS version. +get_bios_version() +{ + OBJ='xyz.openbmc_project.Software.BMC.Updater' + INTERFACE='xyz.openbmc_project.Software.Version' + PROPERTY='Version' + + OBJ_PATH="/xyz/openbmc_project/software/${IMAGE_ID}" + CMD="busctl get-property $OBJ $OBJ_PATH $INTERFACE $PROPERTY" + str=$($CMD) + str=${str#*\"} + UPDATE_VERSION=${str%%\"*} + + OBJ_PATH="/xyz/openbmc_project/software/bios_active" + CMD="busctl get-property $OBJ $OBJ_PATH $INTERFACE $PROPERTY" + str=$($CMD) + str=${str#*\"} + CURRENT_VERSION=${str%%\"*} + + return 0 +} + +# Generate redfish logs. +generate_redfish_log() +{ + if [ ! -d "/var/log" ]; then + mkdir -p /var/log + fi + + OPENBMC_TAG="OpenBMC.0.1.$1" + PARA="" + shift + while [ $# -ne 0 ]; do + PARA=$PARA",$1" + shift + done + logger -p local7.info "${OPENBMC_TAG}${PARA}" +} + +# Delete the path after the update failed. +delete_error_image() +{ + ERROR_PATH=/xyz/openbmc_project/software/${IMAGE_ID} + + busctl call xyz.openbmc_project.Software.BMC.Updater \ + ${ERROR_PATH} xyz.openbmc_project.Object.Delete Delete + +} + +# Check the command status. +check_cmd_state() +{ + if [ $? -ne 0 ]; then + echo "$1 Failed..." + generate_redfish_log "FirmwareUpdateFailed" "$CURRENT_VERSION" \ + "$UPDATE_VERSION" "$1 Failed..." + + delete_error_image + exit 1 + fi +} + +# Check the MTD device. +check_mtd_device() +{ + all_mtd_device=`ls /sys/class/mtd/mtd*/name` + for mtd in $all_mtd_device ; do + d=`cat $mtd` + if [[ $d == $1 ]]; then + tmp=${mtd%/*} + BIOS_MTD_DEVICE=/dev/${tmp##*/} + return 0 + fi + done + echo "Not find $1 mtd device" + return 1 +} + +setup_spi_drive() +{ + if [ $1 = "bind" ]; then + if [ -e ${SPI_PATH}/$SPI_DEV ]; then + echo "${SPI_DEV}" > ${SPI_PATH}/unbind + fi + + sleep 0.5 + echo "${SPI_DEV}" > ${SPI_PATH}/bind + + check_mtd_device "pnor" + return $? + elif [[ $1 = "unbind" && -e ${SPI_PATH}/$SPI_DEV ]]; then + echo "${SPI_DEV}" > ${SPI_PATH}/unbind + sleep 0.5 + fi + + return 0; +} + +#Set GPIO to make CPLD enable or disable spi channel of BIOS +setup_bios_update() +{ + BIOS_UPDATE_ENABLE="CPU1_SPI_SELECT" + echo "Setup BMC Update BIOS: Flash to $1" + + data=`gpioutil get $BIOS_UPDATE_ENABLE` + data=${data#*: } + if [[ "$1" = "cpu" && "$data" = "1" ]]; then + gpioutil set $BIOS_UPDATE_ENABLE 0 + elif [[ "$1" = "bmc" && "$data" = "0" ]]; then + gpioutil set $BIOS_UPDATE_ENABLE 1 + fi + + sleep 0.5 + + return 0 + +} + +# Set bios update dbus progress interface +# $1=Progress +set_dbus_progress_info() +{ + OBJ='xyz.openbmc_project.Software.BMC.Updater' + OBJ_PATH="/xyz/openbmc_project/software/${IMAGE_ID}" + INTERFACE='xyz.openbmc_project.Software.ActivationProgress' + PROPERTY='Progress' + + busctl set-property $OBJ $OBJ_PATH $INTERFACE $PROPERTY y $1 + check_cmd_state "Set FW:$ID progress=$1% progress to dbus interface" + + return 0 +} + +# Flash the new firmware into the BIOS +start_flash_BIOS() +{ + echo "Flashing bios image to $BIOS_MTD_DEVICE..." + if [ ! -e $BIOS_MTD_DEVICE ]; then + generate_redfish_log "FirmwareUpdateFailed" "$CURRENT_VERSION" \ + "$UPDATE_VERSION" "flashcp updated Failed : BIOS mtd device \ + $BIOS_MTD_DEVICE does not exist" + + return 1 + fi + + # Added progress monitoring function + echo "wait" > /tmp/bios_flash_progress + sh /usr/local/progress_monitoring.sh $IMAGE_DIR $1 $2& + + # sleep 2 + flashcp -v $IMAGE_FILE $BIOS_MTD_DEVICE > /tmp/bios_flash_progress + if [ $? -eq 0 ]; then + echo "bios flashcp updated successfully..." + else + echo "bios flashcp updated Failed..." + echo "Unbind spi driver" + setup_spi_drive "unbind" + generate_redfish_log "FirmwareUpdateFailed" "$CURRENT_VERSION" \ + "$UPDATE_VERSION" "flashcp updated Failed..." + + sleep 0.5 + + return 1 + fi + echo "end" > /tmp/bios_flash_progress + + # Wait for the subscript progress_monitoring.sh to exit + wait + + return 0 +} + +############################################################# +# +#MIAN +# +############################################################# +echo "Bios upgrade started at $(date)" + +get_bios_version + +# Check the file to be burned +set_dbus_progress_info 21 +if [ ! -e "$IMAGE_FILE" ]; then + echo "Bios image $IMAGE_FILE doesn't exist" + generate_redfish_log "FirmwareUpdateFailed" "$CURRENT_VERSION" \ + "$UPDATE_VERSION" "Uploading the wrong firmware,BIOS image \ + $IMAGE_FILE doesn't exist" + + exit 1 +fi + +# Flip GPIO to access SPI flash used by host. +# Enable Update,BIOS to BMC +setup_bios_update "bmc" +set_dbus_progress_info 22 + +# Bind spi driver to access flash +setup_spi_drive "bind" +check_cmd_state "Bind BIOS SPI Flash " +set_dbus_progress_info 25 + +# Flashcp image to device. +start_flash_BIOS 30 100 + +echo "Start Unbind bmc spi controller driver" +setup_spi_drive "unbind" + +# Flip GPIO back for host to access SPI flash +# Disable Update,BIOS to CPU +setup_bios_update "cpu" + +generate_redfish_log "FirmwareUpdateCompleted" "$CURRENT_VERSION" "$UPDATE_VERSION" + +echo "Bios eeprom service update finish" diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-host-bios@.service b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-host-bios@.service new file mode 100755 index 0000000000..aabe7a4c10 --- /dev/null +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-host-bios@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Flash Host Bios image %I to Host. + +[Service] +Type=oneshot +RemainAfterExit=no +EnvironmentFile={envfiledir}/obmc/update +ExecStart=/usr/local/bios_flash.sh /tmp/images/%i diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-update-cpld@.service b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-update-cpld@.service index 8529d0af3a..da037414b5 100644 --- a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-update-cpld@.service +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/obmc-update-cpld@.service @@ -5,4 +5,4 @@ Description=Update board cpld %I. Type=oneshot RemainAfterExit=no EnvironmentFile={envfiledir}/obmc/update -ExecStart=/usr/local/update-cpld.sh /tmp/images/%i $CPLD_GPIO +ExecStart=/usr/local/update-cpld.sh /tmp/images/%i diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/progress_monitoring.sh b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/progress_monitoring.sh new file mode 100755 index 0000000000..56c135e3a7 --- /dev/null +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/progress_monitoring.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +################################################ +#Single flash total_progress: +#00-20:Upload firmware +#21-30:pre-update(Discover MTD device...) +#31-60:Erase firmware +#61-90:Write firmware +#91-99:Verify firmware +# +#Dual flash total_progress: +#00-20:Upload firmware +#21-30:pre-update(Discover MTD device...) +#31-45:Erase firmware1 +#46-60:Write firmware1 +#61-65:Verify firmware1 +#66-80:Erase firmware2 +#81-95:Write firmware2 +#96-100:Verify firmware2 +################################################# + +check_cmd_state() +{ + if [ $? -ne 0 ]; then + echo "$1 Failed..." + exit 1 ##exit script + fi +} + +########################################################### +#Filter the last occurrence of the specified string, +#remove the parentheses,and set the progress bar variable. +# +#arg1:String to filter +#arg2:percentage of total progress +# +########################################################### +find_str_progress() +{ + str=$(echo "$data" | grep -i $1 |tail -n 1) + if [ -z "$str" ]; then + #echo "return $1" + return 0 + fi + str=${str##*(} + progress=${str%)*} + if [ -n $progress ]; then + total_progress=$(echo $progress $2 $3 $total_progress |awk '{print int($1*$2*$3+$4)}') + #echo "[$1] : $progress,$2,$3 = $total_progress" >> /tmp/find_str_progress.log + fi + return 0 +} + +#################### +#check_update_state(): +#return +#0 : Update +#1 : End Update +#################### +check_update_state() +{ + state=$(echo "$data" | grep "end") + if [ -n "$state" ]; then + return 1 + fi + return 0 +} + +##Set bios update dbus progress interface +## $1=ID $2=Progress +set_dbus_progress_info() +{ + if [ "$set_progress" == $2 ]; then + return 0 + fi + set_progress=$2 + FILE=$1 + ID=${FILE##*/} + OBJ='xyz.openbmc_project.Software.BMC.Updater' + OBJ_PATH="/xyz/openbmc_project/software/$ID" + INTERFACE='xyz.openbmc_project.Software.ActivationProgress' + PROPERTY='Progress' + + busctl set-property $OBJ $OBJ_PATH $INTERFACE $PROPERTY y $2 + check_cmd_state "Set FW:$ID progress=$2% progress to dbus interface" + return 0 +} + +########################### +# +#MAIN +# +########################### +set_progress=0 +start_progress=$2 +end_progress=$3 +ratio=$(echo $start_progress $end_progress |awk '{print int($2-$1)/70}') +while : +do + # + ##Get progress data output by flashcp and remove '\r\n' characters. + # + data=`cat /tmp/bios_flash_progress | sed 's/\r/\n/g'` + + # + ##Check if the update is over,exit loop. + # + check_update_state + if [ $? -eq 1 ]; then + break + fi + + # + ##Calculate the progress value of each programming + ##Initial value equal to 30% or 65%. + ##contains upload firmware and pre-update phase + # + total_progress=$start_progress + find_str_progress "Erasing" "0.3" "$ratio" + find_str_progress "Writing" "0.3" "$ratio" + find_str_progress "Verifying" "0.09" "$ratio" + + ##Write the progress value to the DBUS interface. + set_dbus_progress_info $1 $total_progress + sleep 2 +done + diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/update-cpld.sh b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/update-cpld.sh index 8c8d7917b8..9d70836357 100755 --- a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/update-cpld.sh +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager/update-cpld.sh @@ -2,7 +2,7 @@ ### Variable image_dir=$1 -gpio_name=$2 +gpio_name=${CPLD_GPIO} cpld_file="${image_dir}/jtag.svf" jtag="/dev/jtag0" progress_file="/tmp/cpld_progress" diff --git a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager_%.bbappend b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager_%.bbappend index 988167e617..f990b0305b 100644 --- a/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager_%.bbappend +++ b/meta-phytium-openbmc/meta-common/recipes-phosphor/flash/phosphor-software-manager_%.bbappend @@ -3,17 +3,24 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" SRC_URI += "\ file://0001-cpld-update-Add-cpld-update-support.patch \ file://update-cpld.sh \ + file://bios_flash.sh \ + file://progress_monitoring.sh \ " RDEPENDS:${PN}-updater += "bash" SYSTEMD_ENVIRONMENT_FILE:${PN}-updater:append := " obmc/update" PACKAGECONFIG[update-cpld] = "-Dhost-cpld-upgrade=enabled, -Dhost-cpld-upgrade=disabled" -PACKAGECONFIG:append:phytium = " update-cpld" +PACKAGECONFIG:append = " update-cpld flash_bios" + SYSTEMD_SERVICE:${PN}-updater += "${@bb.utils.contains('PACKAGECONFIG', 'update-cpld', 'obmc-update-cpld@.service', '', d)}" RDEPENDS:${PN}-updater += "${@bb.utils.contains('PACKAGECONFIG', 'update-cpld', 'loadsvf', '', d)}" do_install:append() { # intsall cpld update script install -m 0755 ${WORKDIR}/update-cpld.sh ${D}/usr/local/update-cpld.sh + + # intsall bios update script + install -m 0755 ${WORKDIR}/bios_flash.sh ${D}/usr/local/bios_flash.sh + install -m 0755 ${WORKDIR}/progress_monitoring.sh ${D}/usr/local/progress_monitoring.sh } -- Gitee From ba6f52ab6b9538f8bf0228227f8066cc7a92325f Mon Sep 17 00:00:00 2001 From: fuxuan Date: Wed, 3 Jul 2024 14:09:13 +0800 Subject: [PATCH 2/2] phosphor-software-manager: BIOS Updates board configuration Signed-off-by: fuxuan --- .../flash/phosphor-software-manager/obmc/update | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meta-phytium-openbmc/meta-tx64/recipes-phosphor/flash/phosphor-software-manager/obmc/update b/meta-phytium-openbmc/meta-tx64/recipes-phosphor/flash/phosphor-software-manager/obmc/update index 573c5779ab..c403cd0889 100644 --- a/meta-phytium-openbmc/meta-tx64/recipes-phosphor/flash/phosphor-software-manager/obmc/update +++ b/meta-phytium-openbmc/meta-tx64/recipes-phosphor/flash/phosphor-software-manager/obmc/update @@ -1 +1,4 @@ CPLD_GPIO=CPU_JTAG_SELECT + +SPI_PATH=/sys/bus/platform/drivers/phytium_spi +SPI_DEV=2803a000.spi -- Gitee