Skip to content

Commit 688c1d1

Browse files
authored
[dpu_tty]: Add a DPU TTY console utility (sonic-net#3535)
* [dpu_tty]: Add a DPU TTY console utility * Add dpu_tty.py * Add dpu_tty.py to scripts Signed-off-by: Wenchung Wang [email protected] What I did Add DPU TTY console utility. How I did it * Read platform.json to retrieve TTY settings in DPUS section. Set up TTY console according to TTY device name and baud rate. * Also provide options to overwrite default TTY device and baud rate. ''' "DPUS": { "dpu0": { "serial-console": { "device": "ttyS4", "baud-rate": "115200" } }, "dpu1": { "serial-console": { "device": "ttyS5", "baud-rate": "115200" } } }, ''' How to verify it Run the utility on a smart switch that provides DPU UART console via ttyS device. The test plan is at https://github.com/sonic-net/sonic-mgmt/pull/12701/files section 1.4. * Correct SA errors * Correct SA errors * Correct SA error * Fix a SA error * Update Command-Reference.md Add DPU serial console utility. * Address review comments
1 parent b8f306f commit 688c1d1

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed

doc/Command-Reference.md

+85-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* [Console config commands](#console-config-commands)
4444
* [Console connect commands](#console-connect-commands)
4545
* [Console clear commands](#console-clear-commands)
46+
* [DPU serial console utility](#dpu-serial-console-utility)
4647
* [CMIS firmware upgrade](#cmis-firmware-upgrade)
4748
* [CMIS firmware version show commands](#cmis-firmware-version-show-commands)
4849
* [CMIS firmware upgrade commands](#cmis-firmware-upgrade-commands)
@@ -229,6 +230,7 @@
229230

230231
| Version | Modification Date | Details |
231232
| --- | --- | --- |
233+
| v9 | Sep-19-2024 | Add DPU serial console utility |
232234
| v8 | Oct-09-2023 | Add CMIS firmware upgrade commands |
233235
| v7 | Jun-22-2023 | Add static DNS show and config commands |
234236
| v6 | May-06-2021 | Add SNMP show and config commands |
@@ -2825,7 +2827,7 @@ Optionally, you can display configured console ports only by specifying the `-b`
28252827
1 9600 Enabled - - switch1
28262828
```
28272829

2828-
## Console config commands
2830+
### Console config commands
28292831

28302832
This sub-section explains the list of configuration options available for console management module.
28312833

@@ -3001,6 +3003,88 @@ Optionally, you can clear with a remote device name by specifying the `-d` or `-
30013003

30023004
Go Back To [Beginning of the document](#) or [Beginning of this section](#console)
30033005

3006+
### DPU serial console utility
3007+
3008+
**dpu-tty.py**
3009+
3010+
This command allows user to connect to a DPU serial console via TTY device with
3011+
interactive CLI program: picocom. The configuration is from platform.json. The
3012+
utility works only on smart switch that provides DPU UART connections through
3013+
/dev/ttyS* devices.
3014+
3015+
- Usage:
3016+
```
3017+
dpu-tty.py (-n|--name) <DPU_NAME> [(-b|-baud) <BAUD_RATE>] [(-t|-tty) <TTY>]
3018+
```
3019+
3020+
- Example:
3021+
```
3022+
root@MtFuji:/home/cisco# dpu-tty.py -n dpu0
3023+
picocom v3.1
3024+
3025+
port is : /dev/ttyS4
3026+
flowcontrol : none
3027+
baudrate is : 115200
3028+
parity is : none
3029+
databits are : 8
3030+
stopbits are : 1
3031+
escape is : C-a
3032+
local echo is : no
3033+
noinit is : no
3034+
noreset is : no
3035+
hangup is : no
3036+
nolock is : no
3037+
send_cmd is : sz -vv
3038+
receive_cmd is : rz -vv -E
3039+
imap is :
3040+
omap is :
3041+
emap is : crcrlf,delbs,
3042+
logfile is : none
3043+
initstring : none
3044+
exit_after is : not set
3045+
exit is : no
3046+
3047+
Type [C-a] [C-h] to see available commands
3048+
Terminal ready
3049+
3050+
sonic login: admin
3051+
Password:
3052+
Linux sonic 6.1.0-11-2-arm64 #1 SMP Debian 6.1.38-4 (2023-08-08) aarch64
3053+
You are on
3054+
____ ___ _ _ _ ____
3055+
/ ___| / _ \| \ | (_)/ ___|
3056+
\___ \| | | | \| | | |
3057+
___) | |_| | |\ | | |___
3058+
|____/ \___/|_| \_|_|\____|
3059+
3060+
-- Software for Open Networking in the Cloud --
3061+
3062+
Unauthorized access and/or use are prohibited.
3063+
All access and/or use are subject to monitoring.
3064+
3065+
Help: https://sonic-net.github.io/SONiC/
3066+
3067+
Last login: Mon Sep 9 21:39:44 UTC 2024 on ttyS0
3068+
admin@sonic:~$
3069+
Terminating...
3070+
Thanks for using picocom
3071+
root@MtFuji:/home/cisco#
3072+
```
3073+
3074+
Optionally, user may overwrite baud rate for experiment.
3075+
3076+
- Example:
3077+
```
3078+
root@MtFuji:/home/cisco# dpu-tty.py -n dpu1 -b 9600
3079+
```
3080+
3081+
Optionally, user may overwrite TTY device for experiment.
3082+
3083+
- Example:
3084+
```
3085+
root@MtFuji:/home/cisco# dpu-tty.py -n dpu2 -t ttyS4
3086+
```
3087+
30043088
## CMIS firmware upgrade
30053089

30063090
### CMIS firmware version show commands

scripts/dpu-tty.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2024 Cisco Systems, Inc.
4+
#
5+
6+
import argparse
7+
import json
8+
import os
9+
import subprocess
10+
from sonic_py_common import device_info
11+
12+
UART_CON = '/usr/bin/picocom'
13+
14+
15+
def get_dpu_tty(dpu, tty, baud):
16+
17+
platform = device_info.get_platform()
18+
if not platform:
19+
print("No platform")
20+
return None
21+
22+
# Get platform path.
23+
platform_path = device_info.get_path_to_platform_dir()
24+
25+
if os.path.isfile(os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)):
26+
json_file = os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)
27+
28+
try:
29+
with open(json_file, 'r') as file:
30+
platform_data = json.load(file)
31+
except (json.JSONDecodeError, IOError, TypeError, ValueError):
32+
print("No platform.json")
33+
return None
34+
35+
dpus = platform_data.get('DPUS', None)
36+
if dpus is None:
37+
print("No DPUs in platform.json")
38+
return None
39+
40+
if tty is None:
41+
dev = dpus[dpu]["serial-console"]["device"]
42+
else:
43+
# overwrite tty device in platform.json
44+
dev = tty
45+
46+
if baud is None:
47+
baud = dpus[dpu]["serial-console"]["baud-rate"]
48+
return dev, baud
49+
50+
51+
def main():
52+
53+
parser = argparse.ArgumentParser(description='DPU TTY Console Utility')
54+
parser.add_argument('-n', '--name', required=True)
55+
parser.add_argument('-t', '--tty')
56+
parser.add_argument('-b', '--baud')
57+
args = parser.parse_args()
58+
59+
dpu_tty, dpu_baud = get_dpu_tty(args.name, args.tty, args.baud)
60+
# Use UART console utility for error checking of dpu_tty and dpu_baud.
61+
62+
p = subprocess.run([UART_CON, '-b', dpu_baud, '/dev/%s' % dpu_tty])
63+
if p.returncode:
64+
print('{} failed'.format(p.args))
65+
if p.stdout:
66+
print(p.stdout)
67+
if p.stderr:
68+
print(p.stderr)
69+
return p.returncode
70+
71+
72+
if __name__ == "__main__":
73+
exit(main())

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
'scripts/decode-syseeprom',
121121
'scripts/dropcheck',
122122
'scripts/disk_check.py',
123+
'scripts/dpu-tty.py',
123124
'scripts/dropconfig',
124125
'scripts/dropstat',
125126
'scripts/dualtor_neighbor_check.py',

0 commit comments

Comments
 (0)