Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platofrm/cel-device/alibaba] - Add firmware upgrade function #33

Merged
merged 1 commit into from Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import subprocess
import requests
import os

try:
from sonic_fwmgr.fwgmr_base import FwMgrUtilBase
Expand All @@ -20,6 +21,7 @@ def __init__(self):
self.platform_name = "AS1332h"
self.onie_config_file = "/host/machine.conf"
self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc"
self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw"
self.onie_config_file = "/host/machine.conf"
self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name
self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name
Expand Down Expand Up @@ -162,3 +164,84 @@ def get_fpga_version(self):
version = "{}.{}".format(
int(version[2:][:4], 16), int(version[2:][4:], 16))
return str(version)

def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
"""
@fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc'
@fw_path MANDATORY, target firmware file
@fw_extra OPTIONAL, extra information string,

for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ...
or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc',
value should be one of 'master' or 'slave' or 'both'
"""

if fw_type == 'bmc':

# Copy BMC image file to BMC
scp_command = 'scp ' + \
os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/'

print "Uploading image to BMC..."
print "Running command : ", scp_command
print "Please enter the BMC password"
p = subprocess.Popen(
scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()

if err != "":
print "Failed"
return False

print "Installing BMC image..."

filename_w_ext = os.path.basename(fw_path)
json_data = dict()
json_data["data"] = "flashcp /home/root/" + \
filename_w_ext + " /dev/mtd5"
json_data["timeout"] = 300

r = requests.post(self.bmc_raw_command_url, json=json_data)
if r.status_code == 200:
print "DONE, Rebooting BMC....."
reboot_dict = dict()
reboot_dict["data"] = "reboot"
r = requests.post(self.bmc_raw_command_url, json=reboot_dict)
else:
print "Failed"
return False

elif fw_type == 'fpga':
command = 'fpga_prog ' + fw_path
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

elif 'cpld' in fw_type:
command = 'ispvm ' + fw_path
if fw_extra is not None:
command = 'ispvm -c ' + \
str(fw_extra) + " " + os.path.abspath(fw_path)
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

return None
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import subprocess
import requests
import os

try:
from sonic_fwmgr.fwgmr_base import FwMgrUtilBase
Expand All @@ -20,6 +21,7 @@ def __init__(self):
self.platform_name = "AS1348f8h"
self.onie_config_file = "/host/machine.conf"
self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc"
self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw"
self.onie_config_file = "/host/machine.conf"
self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name
self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name
Expand Down Expand Up @@ -130,7 +132,7 @@ def get_onie_version(self):
return str(onie_verison)

def get_pcie_version(self):
"""Get PCiE version from SONiC
"""Get PCiE version from SONiC
:returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" }

"""
Expand Down Expand Up @@ -162,3 +164,84 @@ def get_fpga_version(self):
version = "{}.{}".format(
int(version[2:][:4], 16), int(version[2:][4:], 16))
return str(version)

def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
"""
@fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc'
@fw_path MANDATORY, target firmware file
@fw_extra OPTIONAL, extra information string,

for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ...
or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc',
value should be one of 'master' or 'slave' or 'both'
"""

if fw_type == 'bmc':

# Copy BMC image file to BMC
scp_command = 'scp ' + \
os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/'

print "Uploading image to BMC..."
print "Running command : ", scp_command
print "Please enter the BMC password"
p = subprocess.Popen(
scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()

if err != "":
print "Failed"
return False

print "Installing BMC image..."

filename_w_ext = os.path.basename(fw_path)
json_data = dict()
json_data["data"] = "flashcp /home/root/" + \
filename_w_ext + " /dev/mtd5"
json_data["timeout"] = 300

r = requests.post(self.bmc_raw_command_url, json=json_data)
if r.status_code == 200:
print "DONE, Rebooting BMC....."
reboot_dict = dict()
reboot_dict["data"] = "reboot"
r = requests.post(self.bmc_raw_command_url, json=reboot_dict)
else:
print "Failed"
return False

elif fw_type == 'fpga':
command = 'fpga_prog ' + fw_path
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

elif 'cpld' in fw_type:
command = 'ispvm ' + fw_path
if fw_extra is not None:
command = 'ispvm -c ' + \
str(fw_extra) + " " + os.path.abspath(fw_path)
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

return None
83 changes: 83 additions & 0 deletions device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import subprocess
import requests
import os

try:
from sonic_fwmgr.fwgmr_base import FwMgrUtilBase
Expand All @@ -20,6 +21,7 @@ def __init__(self):
self.platform_name = "AS23128h"
self.onie_config_file = "/host/machine.conf"
self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc"
self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw"
self.onie_config_file = "/host/machine.conf"
self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name
self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name
Expand Down Expand Up @@ -162,3 +164,84 @@ def get_fpga_version(self):
version = "{}.{}".format(
int(version[2:][:4], 16), int(version[2:][4:], 16))
return str(version)

def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
"""
@fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc'
@fw_path MANDATORY, target firmware file
@fw_extra OPTIONAL, extra information string,

for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ...
or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc',
value should be one of 'master' or 'slave' or 'both'
"""

if fw_type == 'bmc':

# Copy BMC image file to BMC
scp_command = 'scp ' + \
os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/'

print "Uploading image to BMC..."
print "Running command : ", scp_command
print "Please enter the BMC password"
p = subprocess.Popen(
scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()

if err != "":
print "Failed"
return False

print "Installing BMC image..."

filename_w_ext = os.path.basename(fw_path)
json_data = dict()
json_data["data"] = "flashcp /home/root/" + \
filename_w_ext + " /dev/mtd5"
json_data["timeout"] = 300

r = requests.post(self.bmc_raw_command_url, json=json_data)
if r.status_code == 200:
print "DONE, Rebooting BMC....."
reboot_dict = dict()
reboot_dict["data"] = "reboot"
r = requests.post(self.bmc_raw_command_url, json=reboot_dict)
else:
print "Failed"
return False

elif fw_type == 'fpga':
command = 'fpga_prog ' + fw_path
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

elif 'cpld' in fw_type:
command = 'ispvm ' + fw_path
if fw_extra is not None:
command = 'ispvm -c ' + \
str(fw_extra) + " " + os.path.abspath(fw_path)
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

return None