Skip to content

Commit

Permalink
[Arista7260cx3] Add platform specific reboot tool (#1318)
Browse files Browse the repository at this point in the history
* [Arista7260cx3] Add platform specific reboot tool

* [utilities] update sonic-utilities submodule
  • Loading branch information
yxieca authored Jan 19, 2018
1 parent 33157dc commit 163a0e2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions device/arista/x86_64-arista_7260cx3_64/platform_reboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python
# Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

# Reboot script for 7260CX3

from __future__ import print_function
import sys
import mmap, os
import subprocess
from struct import pack, unpack

class MmapResource( object ):
"""Resource implementation for a directly-mapped memory region."""

def __init__( self, path ):
try:
fd = os.open( path, os.O_RDWR )
except EnvironmentError:
print( "FAIL can not open scd memory-map resource file" )
print( "FAIL are you running on the proper platform?" )
sys.exit( 1 )
try:
size = os.fstat( fd ).st_size
except EnvironmentError:
print( "FAIL can not fstat scd memory-map resource file" )
print( "FAIL are you running on the proper platform?" )
sys.exit( 1 )
try:
self.mmap_ = mmap.mmap( fd, size, mmap.MAP_SHARED,
mmap.PROT_READ | mmap.PROT_WRITE )
except EnvironmentError:
print( "FAIL can not map scd memory-map file" )
print( "FAIL are you running on the proper platform?" )
sys.exit( 1 )
finally:
try:
# Note that closing the file descriptor has no effect on the memory map
os.close( fd )
except EnvironmentError:
print( "FAIL failed to close scd memory-map file" )
sys.exit( 1 )

def read32( self, addr ):
return unpack( '<L', self.mmap_[ addr : addr + 4 ] )[ 0 ]

def write32( self, addr, value ):
self.mmap_[ addr: addr + 4 ] = pack( '<L', value )

def scdRegTest( scd, offset, val1, count ):
scd.write32( offset, val1 )
val2 = scd.read32( offset )
if val1 != val2:
print( "FAIL: scd write 0x%08x but read back 0x%08x in iter %d" %
( val1, val2, count ) )
sys.exit( 17 )

def scdScrRegTest( scd ):
scrOffset = 0x0130
for i in range( 0, 3 ):
scdRegTest( scd, scrOffset, 0xdeadbeef, i )
scdRegTest( scd, scrOffset, 0xa5a5a5a5, i )
scdRegTest( scd, scrOffset, 0x00000000, i )

def reboot( scd ):
# reboot the system by writing to register 0x7000
print( "Rebooting" )
scd.write32( 0x7000, 0xDEAD )
print( "REBOOTED" )

def main():
busName = "/sys/bus/pci/devices/0000:ff:0b.3/resource0"

subprocess.call( [ 'modprobe', 'scd' ] )

scd = MmapResource( busName )

#
# verify that we can read/write scd scratch register
#
scdScrRegTest( scd )

# reboot the system
reboot( scd )

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/sonic-utilities

0 comments on commit 163a0e2

Please sign in to comment.