From 47926d9b1b77e690232a61c5b01fcba25df307e9 Mon Sep 17 00:00:00 2001 From: tianshangfei Date: Wed, 30 Nov 2022 23:39:47 +0800 Subject: [PATCH 1/2] The user framework module complies with s3ip sysfs specification Signed-off-by: tianshangfei --- .../s3ip-sysfs/scripts/s3ip-sysfs.service | 15 ++++ platform/s3ip-sysfs/scripts/s3ip_load.py | 32 ++++++++ .../s3ip-sysfs/scripts/s3ip_sysfs_conf.json | 76 +++++++++++++++++++ .../s3ip-sysfs/scripts/s3ip_sysfs_tool.sh | 59 ++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 platform/s3ip-sysfs/scripts/s3ip-sysfs.service create mode 100755 platform/s3ip-sysfs/scripts/s3ip_load.py create mode 100755 platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json create mode 100755 platform/s3ip-sysfs/scripts/s3ip_sysfs_tool.sh diff --git a/platform/s3ip-sysfs/scripts/s3ip-sysfs.service b/platform/s3ip-sysfs/scripts/s3ip-sysfs.service new file mode 100644 index 00000000000..2446df59d7a --- /dev/null +++ b/platform/s3ip-sysfs/scripts/s3ip-sysfs.service @@ -0,0 +1,15 @@ +[Unit] +Description=s3ip sysfs service +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +User=root +ExecStart=/usr/bin/s3ip_sysfs_tool.sh start +ExecStop=/usr/bin/s3ip_sysfs_tool.sh stop +RemainAfterExit=yes + +[Install] +WantedBy=default.target + diff --git a/platform/s3ip-sysfs/scripts/s3ip_load.py b/platform/s3ip-sysfs/scripts/s3ip_load.py new file mode 100755 index 00000000000..38ae5fb000a --- /dev/null +++ b/platform/s3ip-sysfs/scripts/s3ip_load.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +import json +import os + +if __name__ == '__main__': + os.system("sudo rm -rf /sys_switch;sudo mkdir -p -m 777 /sys_switch") + + with open('/etc/s3ip/s3ip_sysfs_conf.json', 'r') as jsonfile: + json_string = json.load(jsonfile) + for s3ip_sysfs_path in json_string['s3ip_syfs_paths']: + #print('path:' + s3ip_sysfs_path['path']) + #print('type:' + s3ip_sysfs_path['type']) + #print('value:' + s3ip_sysfs_path['value']) + + if s3ip_sysfs_path['type'] == "string" : + (path, file) = os.path.split(s3ip_sysfs_path['path']) + #创建文件 + command = "sudo mkdir -p -m 777 " + path + #print(command) + os.system(command) + command = "sudo echo " + "\"" + s3ip_sysfs_path['value'] + "\"" + " > " + s3ip_sysfs_path['path'] + #print(command) + os.system(command) + elif s3ip_sysfs_path['type'] == "path" : + command = "sudo ln -s " + s3ip_sysfs_path['value'] + " " + s3ip_sysfs_path['path'] + #print(command) + os.system(command) + else: + print('error type:' + s3ip_sysfs_path['type']) + os.system("tree -l /sys_switch") + diff --git a/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json b/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json new file mode 100755 index 00000000000..8b24957c982 --- /dev/null +++ b/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json @@ -0,0 +1,76 @@ +{ + "s3ip_syfs_paths": [ + { + "path": "/sys_switch/temp_sensor", + "type" : "path", + "value" : "/sys/s3ip/temp_sensor", + "description": "温度传感器信息" + }, + { + "path": "/sys_switch/vol_sensor", + "type" : "path", + "value" : "/sys/s3ip/vol_sensor", + "description": "电压传感器信息" + }, + { + "path": "/sys_switch/syseeprom", + "type" : "path", + "value" : "/sys/s3ip/syseeprom", + "description": "ONIE EEPROM" + }, + { + "path": "/sys_switch/fan", + "type" : "path", + "value" : "/sys/s3ip/fan", + "description": "风扇信息" + }, + { + "path": "/sys_switch/psu", + "type" : "path", + "value" : "/sys/s3ip/psu", + "description": "电源信息" + }, + { + "path": "/sys_switch/transceiver", + "type" : "path", + "value" : "/sys/s3ip/transceiver", + "description": "光模块信息" + }, + { + "path": "/sys_switch/sysled", + "type" : "path", + "value" : "/sys/s3ip/sysled", + "description": "指示灯信息" + }, + { + "path": "/sys_switch/fpga", + "type" : "path", + "value" : "/sys/s3ip/fpga", + "description": "FPGA信息" + }, + { + "path": "/sys_switch/cpld", + "type" : "path", + "value" : "/sys/s3ip/cpld", + "description": "CPLD信息" + }, + { + "path": "/sys_switch/watchdog", + "type" : "path", + "value" : "/sys/s3ip/watchdog", + "description": "看门狗信息" + }, + { + "path": "/sys_switch/curr_sensor", + "type" : "path", + "value" : "/sys/s3ip/curr_sensor", + "description": "电流传感器信息" + }, + { + "path": "/sys_switch/slot", + "type" : "path", + "value" : "/sys/s3ip/slot", + "description": "子卡信息" + } + ] +} diff --git a/platform/s3ip-sysfs/scripts/s3ip_sysfs_tool.sh b/platform/s3ip-sysfs/scripts/s3ip_sysfs_tool.sh new file mode 100755 index 00000000000..ed65f0d1d9e --- /dev/null +++ b/platform/s3ip-sysfs/scripts/s3ip_sysfs_tool.sh @@ -0,0 +1,59 @@ +#! /bin/bash + +s3ip_start(){ + sudo insmod /lib/modules/s3ip/s3ip_sysfs.ko + sudo insmod /lib/modules/s3ip/syseeprom_device_driver.ko + sudo insmod /lib/modules/s3ip/fan_device_driver.ko + sudo insmod /lib/modules/s3ip/cpld_device_driver.ko + sudo insmod /lib/modules/s3ip/sysled_device_driver.ko + sudo insmod /lib/modules/s3ip/psu_device_driver.ko + sudo insmod /lib/modules/s3ip/transceiver_device_driver.ko + sudo insmod /lib/modules/s3ip/temp_sensor_device_driver.ko + sudo insmod /lib/modules/s3ip/vol_sensor_device_driver.ko + sudo insmod /lib/modules/s3ip/fpga_device_driver.ko + sudo insmod /lib/modules/s3ip/watchdog_device_driver.ko + sudo insmod /lib/modules/s3ip/curr_sensor_device_driver.ko + sudo insmod /lib/modules/s3ip/slot_device_driver.ko + sudo rm -rf /sys_switch + sudo /usr/bin/s3ip_load.py + echo "s3ip service start" +} +s3ip_stop(){ + sudo rmmod slot_device_driver + sudo rmmod curr_sensor_device_driver + sudo rmmod watchdog_device_driver + sudo rmmod fpga_device_driver + sudo rmmod vol_sensor_device_driver + sudo rmmod temp_sensor_device_driver + sudo rmmod transceiver_device_driver + sudo rmmod psu_device_driver + sudo rmmod sysled_device_driver + sudo rmmod cpld_device_driver + sudo rmmod fan_device_driver + sudo rmmod syseeprom_device_driver + sudo rmmod s3ip_sysfs + sudo rm -rf /sys_switch + echo "s3ip service stop" + +} + +case "$1" in + start) + s3ip_start + ;; + stop) + s3ip_stop + ;; + status) + sudo tree -l /sys_switch + ;; + restart) + s3ip_stop + s3ip_start + ;; + *) + echo "Usage: $0 {start|stop|status|restart}" + exit 1 +esac +exit + From 7dc421cba08abb2d174a7a3cb81fa64ecf6f0c4b Mon Sep 17 00:00:00 2001 From: tianshangfei Date: Mon, 5 Dec 2022 17:52:16 +0800 Subject: [PATCH 2/2] Describe the description in English Signed-off-by: tianshangfei --- .../s3ip-sysfs/scripts/s3ip_sysfs_conf.json | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) mode change 100755 => 100644 platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json diff --git a/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json b/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json old mode 100755 new mode 100644 index 8b24957c982..fc72263c519 --- a/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json +++ b/platform/s3ip-sysfs/scripts/s3ip_sysfs_conf.json @@ -4,13 +4,13 @@ "path": "/sys_switch/temp_sensor", "type" : "path", "value" : "/sys/s3ip/temp_sensor", - "description": "温度传感器信息" + "description": "temperature information" }, { "path": "/sys_switch/vol_sensor", "type" : "path", "value" : "/sys/s3ip/vol_sensor", - "description": "电压传感器信息" + "description": "voltage sensor information" }, { "path": "/sys_switch/syseeprom", @@ -22,55 +22,55 @@ "path": "/sys_switch/fan", "type" : "path", "value" : "/sys/s3ip/fan", - "description": "风扇信息" + "description": "fan information" }, { "path": "/sys_switch/psu", "type" : "path", "value" : "/sys/s3ip/psu", - "description": "电源信息" + "description": "PSU information" }, { "path": "/sys_switch/transceiver", "type" : "path", "value" : "/sys/s3ip/transceiver", - "description": "光模块信息" + "description": "transceiver information" }, { "path": "/sys_switch/sysled", "type" : "path", "value" : "/sys/s3ip/sysled", - "description": "指示灯信息" + "description": "SYS LED information" }, { "path": "/sys_switch/fpga", "type" : "path", "value" : "/sys/s3ip/fpga", - "description": "FPGA信息" + "description": "FPGA information" }, { "path": "/sys_switch/cpld", "type" : "path", "value" : "/sys/s3ip/cpld", - "description": "CPLD信息" + "description": "CPLD information" }, { "path": "/sys_switch/watchdog", "type" : "path", "value" : "/sys/s3ip/watchdog", - "description": "看门狗信息" + "description": "watchdog information" }, { "path": "/sys_switch/curr_sensor", "type" : "path", "value" : "/sys/s3ip/curr_sensor", - "description": "电流传感器信息" + "description": "current sensor information" }, { "path": "/sys_switch/slot", "type" : "path", "value" : "/sys/s3ip/slot", - "description": "子卡信息" + "description": "slot information" } ] }