Skip to content

Commit

Permalink
[device]: DellEmc-S6000 : Back-end work for last reboot reason (#2974)
Browse files Browse the repository at this point in the history
* DellEmc-S6000 Backend work for lastreboot reason
  • Loading branch information
gengankarthik authored and lguohan committed Jun 7, 2019
1 parent bf2c9cd commit f7774be
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 9 deletions.
61 changes: 52 additions & 9 deletions device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
#!/bin/sh
#!/usr/bin/python
import sys
import os
import struct

# Export GPIO10 if needed
[ -d /sys/class/gpio/gpio10 ] || echo 10 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio10/direction
NVRAM_RES = '/dev/nvram'
COLD_RESET = 0xE # Cold Reset
WARM_RESET = 0x6 # Warm Reset

#Toggle GPIO10 pin (to reset MUX)
echo 1 > /sys/class/gpio/gpio10/value
echo 0 > /sys/class/gpio/gpio10/value
def io_reg_write(resource, offset, val):
fd = os.open(resource, os.O_RDWR)
if(fd < 0):
print 'file open failed %s" % resource'
return
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
print 'lseek failed on %s' % resource
return
ret = os.write(fd, struct.pack('B', val))
if(ret != 1):
print 'write failed %d' % ret
return
os.close(fd)


#Power Reset
echo 1 > /sys/devices/platform/dell-s6000-cpld.0/power_reset
def power_reset(val):
with open('/sys/devices/platform/dell-s6000-cpld.0/power_reset', 'w') as p:
p.write(str(int(val)) + '\n')
p.flush()

def gpio_direction(pin,direction):
kernpath = '/sys/class/gpio/gpio'+str(pin)+'/direction'
with open(('kernpath'), 'w') as p:
p.write(str(direction) + '\n')
p.flush()

def gpio_set(pin,value):
kernpath = '/sys/class/gpio/gpio'+str(pin)+'/value'
with open(('kernpath'), 'w') as p:
p.write(str(int(value)) + '\n')
p.flush()

def gpio_export(value):
with open('/sys/class/gpio/export', 'w') as p:
p.write(str(int(value)) + '\n')
p.flush()


if __name__ == "__main__":
io_reg_write(NVRAM_RES, 0x49, COLD_RESET)
if not os.path.isdir("/sys/class/gpio/gpio10"):
gpio_export(10)
gpio_direction("10","out")
#Toggle GPIO10 pin (to reset MUX)
gpio_set("10",1)
gpio_set("10",0)
power_reset(1)
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ start)
depmod -a
modprobe i2c_mux_gpio
modprobe dell_s6000_platform
modprobe nvram

add_i2c_devices

Expand All @@ -81,6 +82,7 @@ stop)

remove_i2c_devices

rmmod nvram
rmmod dell_s6000_platform
rmmod i2c_mux_gpio
;;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
systemd/platform-modules-s6000.service lib/systemd/system
scripts/io_rd_wr.py usr/local/bin
93 changes: 93 additions & 0 deletions platform/broadcom/sonic-platform-modules-s6000/scripts/io_rd_wr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/python
#Script to read/write the io based registers

import sys
import os
import getopt
import struct

io_resource='/dev/port'

def usage():
''' This is the Usage Method '''

print 'Utility for IO read/write'
print '\t\t io_rd_wr.py --get --offset <offset>'
print '\t\t io_rd_wr.py --set --val <val> --offset <offset>'
sys.exit(1)

def io_reg_read(io_resource,offset):
fd=os.open(io_resource, os.O_RDONLY)
if(fd<0):
print 'file open failed %s"%io_resource'
return
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
print 'lseek failed on %s'%io_resource
return
buf=os.read(fd,1)
reg_val1=ord(buf)
print 'reg value %x'%reg_val1
os.close(fd)

def io_reg_write(io_resource,offset,val):
fd=os.open(io_resource,os.O_RDWR)
if(fd<0):
print 'file open failed %s"%io_resource'
return
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
print 'lseek failed on %s'%io_resource
return
ret=os.write(fd,struct.pack('B',val))
if(ret != 1):
print 'write failed %d'%ret
return
os.close(fd)

def main(argv):

''' The main function will read the user input from the
command line argument and process the request '''

opts = ''
val = ''
choice = ''
resouce = ''
offset = ''

try:
opts, args = getopt.getopt(argv, "hgs:" , \
["val=","offset=","help", "get", "set"])

except getopt.GetoptError:
usage()

for opt,arg in opts:

if opt in ('-h','--help'):
choice = 'help'

elif opt in ('-g', '--get'):
choice = 'get'

elif opt in ('-s', '--set'):
choice = 'set'

elif opt == '--offset':
offset = int(arg,16)

elif opt == '--val':
val = int(arg,16)

if choice == 'get' and offset != '':
io_reg_read(io_resource,offset)

elif choice == 'set' and offset != '' and val != '':
io_reg_write(io_resource,offset,val)

else:
usage()

#Calling the main method
if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit f7774be

Please sign in to comment.