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

[device] Add a reboot script for all remaining Arista platforms. #1706

Merged
merged 1 commit into from
May 15, 2018
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
87 changes: 87 additions & 0 deletions device/arista/x86_64-arista_7050_qx32/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 7050QX-32

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:04:00.0/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()
87 changes: 87 additions & 0 deletions device/arista/x86_64-arista_7050_qx32s/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 7050QX-32S

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:02:00.0/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()
18 changes: 18 additions & 0 deletions device/arista/x86_64-arista_7060_cx32s/platform_reboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

# Reboot script for 7060CX-32

from __future__ import print_function

import smbus

def main():
print( "Rebooting" )
bus = smbus.SMBus( 1 )
bus.write_byte_data( 0x23, 0x04, 0xde )
print( "REBOOTED" )

if __name__ == "__main__":
main()