Initial commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
|
||||
bios_image=$(ls $1/*.bin)
|
||||
|
||||
bios_mtd="/dev/mtd/bios"
|
||||
bios_id=$(basename "$1")
|
||||
bios_slot=""
|
||||
|
||||
power_obj="xyz.openbmc_project.State.Chassis"
|
||||
power_path="/xyz/openbmc_project/state/chassis0"
|
||||
power_intf="xyz.openbmc_project.State.Chassis"
|
||||
power_prop="CurrentPowerState"
|
||||
|
||||
update_obj="xyz.openbmc_project.Software.BMC.Updater"
|
||||
update_path="/xyz/openbmc_project/software/"
|
||||
target_intf="xyz.openbmc_project.Software.UpdateTarget"
|
||||
target_prop="UpdateTargetSlot"
|
||||
|
||||
check_env() {
|
||||
echo "[Info]: Check Environment."
|
||||
#check power status. if On, set to Off.
|
||||
#power_status=$(busctl get-property $power_obj $power_path $power_intf $power_prop)
|
||||
#if [[ $power_status == *On* ]]; then
|
||||
# busctl set-property $power_obj $power_path $power_intf RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.Off
|
||||
#fi
|
||||
sleep 10
|
||||
|
||||
#add other action to prepare flash bios.
|
||||
bios_slot=$(busctl get-property $update_obj $update_path$bios_id $target_intf $target_prop)
|
||||
bios_slot=$(echo "$bios_slot" |cut -d "\"" -f2)
|
||||
if [ "$bios_slot" = "xyz.openbmc_project.Software.UpdateTarget.TargetSlot.Primary" ]; then
|
||||
bios_slot="Primary"
|
||||
elif [ "$bios_slot" = "xyz.openbmc_project.Software.UpdateTarget.TargetSlot.Secondary" ]; then
|
||||
bios_slot="Backup"
|
||||
elif [ "$bios_slot" = "xyz.openbmc_project.Software.UpdateTarget.TargetSlot.Both" ]; then
|
||||
bios_slot="Both"
|
||||
fi
|
||||
}
|
||||
|
||||
switch_primary_flash_to_bmc() {
|
||||
echo "[Info]: Switch Main BIOS Flash To BMC."
|
||||
if [ -d /sys/bus/platform/drivers/spi-aspeed-smc/1e630000.spi ]; then
|
||||
echo -n "1e630000.spi" > /sys/bus/platform/drivers/spi-aspeed-smc/unbind
|
||||
fi
|
||||
|
||||
#Set Mux to bmc.
|
||||
i2ctransfer -y -a 0 w3@0x0d 0xa0 0x03 0x80
|
||||
|
||||
#Switch to primary BIOS flash
|
||||
i2ctransfer -y -a 0 w3@0x0d 0xa1 0x03 0x80
|
||||
|
||||
#mount bios flash to BMC
|
||||
echo -n "1e630000.spi" > /sys/bus/platform/drivers/spi-aspeed-smc/bind
|
||||
sleep 5
|
||||
cat /proc/mtd
|
||||
}
|
||||
|
||||
switch_secondary_flash_to_bmc() {
|
||||
echo "[Info]: Switch Backup BIOS Flash To BMC."
|
||||
if [ -d /sys/bus/platform/drivers/spi-aspeed-smc/1e630000.spi ]; then
|
||||
echo -n "1e630000.spi" > /sys/bus/platform/drivers/spi-aspeed-smc/unbind
|
||||
fi
|
||||
|
||||
#Set Mux to bmc.
|
||||
i2ctransfer -y -a 0 w3@0x0d 0xa0 0x03 0x80
|
||||
|
||||
#Switch to backup BIOS flash
|
||||
i2ctransfer -y -a 0 w3@0x0d 0xa1 0x03 0x40
|
||||
|
||||
#mount bios flash to BMC
|
||||
echo -n "1e630000.spi" > /sys/bus/platform/drivers/spi-aspeed-smc/bind
|
||||
sleep 5
|
||||
cat /proc/mtd
|
||||
}
|
||||
|
||||
flash_bios() {
|
||||
echo "[Info]: Flash BIOS."
|
||||
#Which flash need to be update, e.g. get for Manifest or Settings.
|
||||
# bios_update_select=
|
||||
#Check MTD Exist
|
||||
|
||||
if [[ ! -e $bios_mtd ]]; then
|
||||
echo "[Error]: bios flash not found in $bios_mtd"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
echo "[Info]: bios_image=$bios_image"
|
||||
echo "[Info]: bios_mtd=$bios_mtd"
|
||||
echo "/usr/sbin/flashcp $bios_image $bios_mtd"
|
||||
/usr/sbin/flashcp $bios_image $bios_mtd
|
||||
}
|
||||
|
||||
switch_flash_to_cpu() {
|
||||
echo "[Info]: Switch Main BIOS Flash To CPU."
|
||||
echo -n "1e630000.spi" > /sys/bus/platform/drivers/spi-aspeed-smc/unbind
|
||||
|
||||
sleep 5
|
||||
#Set Mux to CPU.
|
||||
i2ctransfer -y -a 0 w3@0x0d 0xa0 0x03 0x00
|
||||
}
|
||||
|
||||
power_on_system() {
|
||||
echo "[Info]: Power On System After Update BIOS."
|
||||
#check power status. if Off, set to On.
|
||||
power_status=$(busctl get-property $power_obj $power_path $power_intf $power_prop)
|
||||
if [[ $power_status == *Off* ]]; then
|
||||
sleep 5
|
||||
busctl set-property $power_obj $power_path $power_intf RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.On
|
||||
fi
|
||||
}
|
||||
|
||||
check_env
|
||||
if [ "$bios_slot" = "Primary" ]; then
|
||||
switch_primary_flash_to_bmc
|
||||
flash_bios
|
||||
elif [ "$bios_slot" = "Backup" ]; then
|
||||
switch_secondary_flash_to_bmc
|
||||
flash_bios
|
||||
elif [ "$bios_slot" = "Both" ]; then
|
||||
switch_primary_flash_to_bmc
|
||||
flash_bios
|
||||
sleep 5
|
||||
switch_secondary_flash_to_bmc
|
||||
flash_bios
|
||||
fi
|
||||
switch_flash_to_cpu
|
||||
#power_on_system
|
||||
sleep 5
|
||||
Reference in New Issue
Block a user