Skip to content

Commit 163a0e2

Browse files
authored
[Arista7260cx3] Add platform specific reboot tool (#1318)
* [Arista7260cx3] Add platform specific reboot tool * [utilities] update sonic-utilities submodule
1 parent 33157dc commit 163a0e2

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
3+
# Arista Networks, Inc. Confidential and Proprietary.
4+
5+
# Reboot script for 7260CX3
6+
7+
from __future__ import print_function
8+
import sys
9+
import mmap, os
10+
import subprocess
11+
from struct import pack, unpack
12+
13+
class MmapResource( object ):
14+
"""Resource implementation for a directly-mapped memory region."""
15+
16+
def __init__( self, path ):
17+
try:
18+
fd = os.open( path, os.O_RDWR )
19+
except EnvironmentError:
20+
print( "FAIL can not open scd memory-map resource file" )
21+
print( "FAIL are you running on the proper platform?" )
22+
sys.exit( 1 )
23+
try:
24+
size = os.fstat( fd ).st_size
25+
except EnvironmentError:
26+
print( "FAIL can not fstat scd memory-map resource file" )
27+
print( "FAIL are you running on the proper platform?" )
28+
sys.exit( 1 )
29+
try:
30+
self.mmap_ = mmap.mmap( fd, size, mmap.MAP_SHARED,
31+
mmap.PROT_READ | mmap.PROT_WRITE )
32+
except EnvironmentError:
33+
print( "FAIL can not map scd memory-map file" )
34+
print( "FAIL are you running on the proper platform?" )
35+
sys.exit( 1 )
36+
finally:
37+
try:
38+
# Note that closing the file descriptor has no effect on the memory map
39+
os.close( fd )
40+
except EnvironmentError:
41+
print( "FAIL failed to close scd memory-map file" )
42+
sys.exit( 1 )
43+
44+
def read32( self, addr ):
45+
return unpack( '<L', self.mmap_[ addr : addr + 4 ] )[ 0 ]
46+
47+
def write32( self, addr, value ):
48+
self.mmap_[ addr: addr + 4 ] = pack( '<L', value )
49+
50+
def scdRegTest( scd, offset, val1, count ):
51+
scd.write32( offset, val1 )
52+
val2 = scd.read32( offset )
53+
if val1 != val2:
54+
print( "FAIL: scd write 0x%08x but read back 0x%08x in iter %d" %
55+
( val1, val2, count ) )
56+
sys.exit( 17 )
57+
58+
def scdScrRegTest( scd ):
59+
scrOffset = 0x0130
60+
for i in range( 0, 3 ):
61+
scdRegTest( scd, scrOffset, 0xdeadbeef, i )
62+
scdRegTest( scd, scrOffset, 0xa5a5a5a5, i )
63+
scdRegTest( scd, scrOffset, 0x00000000, i )
64+
65+
def reboot( scd ):
66+
# reboot the system by writing to register 0x7000
67+
print( "Rebooting" )
68+
scd.write32( 0x7000, 0xDEAD )
69+
print( "REBOOTED" )
70+
71+
def main():
72+
busName = "/sys/bus/pci/devices/0000:ff:0b.3/resource0"
73+
74+
subprocess.call( [ 'modprobe', 'scd' ] )
75+
76+
scd = MmapResource( busName )
77+
78+
#
79+
# verify that we can read/write scd scratch register
80+
#
81+
scdScrRegTest( scd )
82+
83+
# reboot the system
84+
reboot( scd )
85+
86+
if __name__ == "__main__":
87+
main()

src/sonic-utilities

0 commit comments

Comments
 (0)