Skip to content

Commit 659a935

Browse files
authored
[fwutil]: Command-line utility for interacting with platform components (sonic-net#772)
* [fwutil]: initial version. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: Fix UI: enable progressbar render finalizer. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: integrate utility with SONiC CLI. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: update CLI command reference documentation. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: Revisit CLI architecture: avoid direct imports. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: Fix review comments: refactor CLI command reference. Signed-off-by: Nazarii Hnydyn <[email protected]> * [fwutil]: Fix review comments: update CLI documentation. Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent c45ad99 commit 659a935

File tree

9 files changed

+1486
-0
lines changed

9 files changed

+1486
-0
lines changed

config/main.py

+42
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,48 @@ def platform():
20302030
if asic_type == 'mellanox':
20312031
platform.add_command(mlnx.mlnx)
20322032

2033+
# 'firmware' subgroup ("config platform firmware ...")
2034+
@platform.group()
2035+
def firmware():
2036+
"""Firmware configuration tasks"""
2037+
pass
2038+
2039+
# 'install' subcommand ("config platform firmware install")
2040+
@firmware.command(
2041+
context_settings=dict(
2042+
ignore_unknown_options=True,
2043+
allow_extra_args=True
2044+
),
2045+
add_help_option=False
2046+
)
2047+
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
2048+
def install(args):
2049+
"""Install platform firmware"""
2050+
cmd = "fwutil install {}".format(" ".join(args))
2051+
2052+
try:
2053+
subprocess.check_call(cmd, shell=True)
2054+
except subprocess.CalledProcessError as e:
2055+
sys.exit(e.returncode)
2056+
2057+
# 'update' subcommand ("config platform firmware update")
2058+
@firmware.command(
2059+
context_settings=dict(
2060+
ignore_unknown_options=True,
2061+
allow_extra_args=True
2062+
),
2063+
add_help_option=False
2064+
)
2065+
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
2066+
def update(args):
2067+
"""Update platform firmware"""
2068+
cmd = "fwutil update {}".format(" ".join(args))
2069+
2070+
try:
2071+
subprocess.check_call(cmd, shell=True)
2072+
except subprocess.CalledProcessError as e:
2073+
sys.exit(e.returncode)
2074+
20332075
#
20342076
# 'watermark' group ("show watermark telemetry interval")
20352077
#

data/etc/bash_completion.d/fwutil

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_fwutil_completion() {
2+
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
3+
COMP_CWORD=$COMP_CWORD \
4+
_FWUTIL_COMPLETE=complete $1 ) )
5+
return 0
6+
}
7+
8+
complete -F _fwutil_completion -o default fwutil;

doc/Command-Reference.md

+169
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
* [NTP](#ntp)
7474
* [NTP show commands](#ntp-show-commands)
7575
* [NTP config commands](#ntp-config-commands)
76+
* [Platform Component Firmware](#platform-component-firmware)
77+
* [Platform Component Firmware show commands](#platform-component-firmware-show-commands)
78+
* [Platform Component Firmware config commands](#platform-component-firmware-config-commands)
7679
* [Platform Specific Commands](#platform-specific-commands)
7780
* [PortChannels](#portchannels)
7881
* [PortChannel Show commands](#portchannel-show-commands)
@@ -3788,6 +3791,172 @@ This command is used to delete a configured NTP server IP address.
37883791
Go Back To [Beginning of the document](#) or [Beginning of this section](#NTP)
37893792
37903793
3794+
## Platform Component Firmware
3795+
3796+
### Platform Component Firmware show commands
3797+
3798+
**show platform firmware**
3799+
3800+
This command displays platform components firmware status information.
3801+
3802+
- Usage:
3803+
```bash
3804+
show platform firmware
3805+
```
3806+
3807+
- Example:
3808+
```bash
3809+
root@sonic:/home/admin# show platform firmware
3810+
Chassis Module Component Version Description
3811+
--------- -------- ----------- ----------------------- ---------------------------------------
3812+
Chassis1 N/A BIOS 0ACLH004_02.02.007_9600 BIOS - Basic Input/Output System
3813+
CPLD 5.3.3.1 CPLD - includes all CPLDs in the switch
3814+
```
3815+
3816+
### Platform Component Firmware config commands
3817+
3818+
**config platform firmware install**
3819+
3820+
This command is used to install a platform component firmware.
3821+
Both modular and non modular chassis platforms are supported.
3822+
3823+
- Usage:
3824+
```bash
3825+
config platform firmware install chassis component <component_name> fw <fw_path> [-y|--yes]
3826+
config platform firmware install module <module_name> component <component_name> fw <fw_path> [-y|--yes]
3827+
```
3828+
3829+
- Example:
3830+
```bash
3831+
root@sonic:/home/admin# config platform firmware install chassis component BIOS fw /etc/mlnx/fw/sn3800/chassis1/bios.bin
3832+
New firmware will be installed, continue? [y/N]: y
3833+
Installing firmware:
3834+
/etc/mlnx/fw/sn3800/chassis1/bios.bin
3835+
3836+
root@sonic:/home/admin# config platform firmware install module Module1 component BIOS fw http://mellanox.com/fw/sn3800/module1/bios.bin
3837+
New firmware will be installed, continue? [y/N]: y
3838+
Downloading firmware:
3839+
[##################################################] 100%
3840+
Installing firmware:
3841+
/tmp/bios.bin
3842+
```
3843+
3844+
Supported options:
3845+
1. -y|--yes - automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively
3846+
3847+
**config platform firmware update**
3848+
3849+
This command is used for automatic FW update of all available platform components.
3850+
Both modular and non modular chassis platforms are supported.
3851+
3852+
Automatic FW update requires `platform_components.json` to be created and placed at:
3853+
sonic-buildimage/device/<platform_name>/<onie_platform>/platform_components.json
3854+
3855+
Example:
3856+
1. Non modular chassis platform
3857+
```json
3858+
{
3859+
"chassis": {
3860+
"Chassis1": {
3861+
"component": {
3862+
"BIOS": {
3863+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/bios.bin",
3864+
"version": "0ACLH003_02.02.010",
3865+
"info": "Cold reboot is required"
3866+
},
3867+
"CPLD": {
3868+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/cpld.bin",
3869+
"version": "10",
3870+
"info": "Power cycle is required"
3871+
},
3872+
"FPGA": {
3873+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/fpga.bin",
3874+
"version": "5",
3875+
"info": "Power cycle is required"
3876+
}
3877+
}
3878+
}
3879+
}
3880+
}
3881+
```
3882+
3883+
2. Modular chassis platform
3884+
```json
3885+
{
3886+
"chassis": {
3887+
"Chassis1": {
3888+
"component": {
3889+
"BIOS": {
3890+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/bios.bin",
3891+
"version": "0ACLH003_02.02.010",
3892+
"info": "Cold reboot is required"
3893+
},
3894+
"CPLD": {
3895+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/cpld.bin",
3896+
"version": "10",
3897+
"info": "Power cycle is required"
3898+
},
3899+
"FPGA": {
3900+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/chassis1/fpga.bin",
3901+
"version": "5",
3902+
"info": "Power cycle is required"
3903+
}
3904+
}
3905+
}
3906+
},
3907+
"module": {
3908+
"Module1": {
3909+
"component": {
3910+
"CPLD": {
3911+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/module1/cpld.bin",
3912+
"version": "10",
3913+
"info": "Power cycle is required"
3914+
},
3915+
"FPGA": {
3916+
"firmware": "/etc/<platform_name>/fw/<onie_platform>/module1/fpga.bin",
3917+
"version": "5",
3918+
"info": "Power cycle is required"
3919+
}
3920+
}
3921+
}
3922+
}
3923+
}
3924+
```
3925+
3926+
Note: FW update will be skipped if component definition is not provided (e.g., 'BIOS': { })
3927+
3928+
- Usage:
3929+
```bash
3930+
config platform firmware update [-y|--yes] [-f|--force] [-i|--image=current|next]
3931+
```
3932+
3933+
- Example:
3934+
```bash
3935+
root@sonic:/home/admin# config platform firmware update
3936+
Chassis Module Component Firmware Version Status Info
3937+
--------- -------- ----------- ------------------------------------- ------------------------------------------------- ------------------ -----------------------
3938+
Chassis1 N/A BIOS /etc/mlnx/fw/sn3800/chassis1/bios.bin 0ACLH004_02.02.007_9600 / 0ACLH004_02.02.007_9600 up-to-date Cold reboot is required
3939+
CPLD /etc/mlnx/fw/sn3800/chassis1/cpld.bin 5.3.3.1 / 5.3.3.2 update is required Power cycle is required
3940+
New firmware will be installed, continue? [y/N]: y
3941+
3942+
Summary:
3943+
3944+
Chassis Module Component Status
3945+
--------- -------- ----------- ----------
3946+
Chassis1 N/A BIOS up-to-date
3947+
CPLD success
3948+
```
3949+
3950+
Supported options:
3951+
1. -y|--yes - automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively
3952+
2. -f|--force - install FW regardless the current version
3953+
3. -i|--image - update FW using current/next SONiC image
3954+
3955+
Note: the default option is --image=current
3956+
3957+
Go Back To [Beginning of the document](#) or [Beginning of this section](#platform-component-firmware)
3958+
3959+
37913960
## Platform Specific Commands
37923961
37933962
There are few commands that are platform specific. Mellanox has used this feature and implemented Mellanox specific commands as follows.

fwutil/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
try:
2+
from sonic_platform.platform import Platform
3+
from . import main
4+
except ImportError as e:
5+
raise ImportError("Required module not found: {}".format(str(e)))

0 commit comments

Comments
 (0)