From 73d92cbb61d87be9e5f5f4c8830d6dd8d69df9c8 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Wed, 8 Jan 2025 13:46:18 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat(plugin=20:=20scripts)=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=9F=BA=E6=9C=ACI2C=E5=8A=9F=E8=83=BD=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/i2c_m6.sh | 9 +++++++++ tool/plugin/i2c_m7.sh | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 tool/plugin/i2c_m6.sh create mode 100644 tool/plugin/i2c_m7.sh diff --git a/tool/plugin/i2c_m6.sh b/tool/plugin/i2c_m6.sh new file mode 100644 index 0000000..a489524 --- /dev/null +++ b/tool/plugin/i2c_m6.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +i2c_bus=$1 +wc=$2 +slave=$3 +data=$4 +rc=$5 + +i2c_test -b $i2c_bus -s $slave -rc $rc -d $data | awk 'NR==3{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}' \ No newline at end of file diff --git a/tool/plugin/i2c_m7.sh b/tool/plugin/i2c_m7.sh new file mode 100644 index 0000000..a0b269e --- /dev/null +++ b/tool/plugin/i2c_m7.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +i2c_bus=$1 +wc=$2 +slave=$3 +data=$4 +rc=$5 + +i2ctransfer - y $i2c_bus w$wc@$slave $data r$5 \ No newline at end of file From 0b3f79b1af1860e5268fbe29a12869a84ed12b74 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Wed, 19 Feb 2025 13:43:50 +0800 Subject: [PATCH 2/8] code sync --- tool/plugin/format_print.sh | 19 ++++++++ tool/plugin/nicsensor.sh | 88 ++++++++++++++++++++++++++++++++++ tool/plugin/platform_5280m7.sh | 88 ++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 tool/plugin/format_print.sh create mode 100644 tool/plugin/nicsensor.sh create mode 100644 tool/plugin/platform_5280m7.sh diff --git a/tool/plugin/format_print.sh b/tool/plugin/format_print.sh new file mode 100644 index 0000000..27c095e --- /dev/null +++ b/tool/plugin/format_print.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +logfile="/tmp/nicsensor_debug.log" + +direction=$1 +level=$2 +content=$3 + +case "${direction}" in + "console") + echo ">>> [$level] : $content" + ;; + "log") + echo "[$level] : $content" >> $logfile + ;; + *) + echo "Error In format_print.sh! Param : $direction" + ;; +esac diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh new file mode 100644 index 0000000..4a66b1a --- /dev/null +++ b/tool/plugin/nicsensor.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +server_type="5280m7" +server_platform="m7" + +slot_name=$1 +sensor_type=$2 +chip_slave=$3 + +nic_type="" +slot_id="" + +server_script="platform_${server_type}.sh" +sensor_script="plugin_${sensor_type}.sh" +i2c_script="i2c_${server_platform}.sh" +fmt_print="format_print.sh" + +conf_pre_check(){ + + # init debug log + if [ -e "/tmp/nicsensor_debug.log" ];then + rm /tmp/nicsensor_debug.log + fi + + if [ ! -e $fmt_print ];then + echo "Missing file $fmt_print !!!" + exit 1 + fi + + if [ ! -e $server_script ];then + $fmt_print "console" "Error" "$server_script not exist!" + exit 1 + fi + + if [ ! -e $sensor_script ];then + $fmt_print "console" "Error" "$sensor_script not exist!" + exit 1 + fi + + if [ ! -e $i2c_script ];then + $fmt_print "console" "Error" "$i2c_script not exist!" + exit 1 + fi +} + +parse_slot_name(){ + # Get nic type and slot id from slot name + case "{$slot_name}" in + ocp*) + nic_type="ocp" + slot_id=`echo $slot_name | cut -c 4` + ;; + pcie*) + nic_type="pcie" + slot_id=`echo $slot_name | cut -c 5-` + ;; + *) + $fmt_print "log" "Warning" "Undetermined nic type, default set to pcie" + nic_type="pcie" + slot_id=$slot_name + ;; + esac +} + +connect_i2c(){ + $server_script "connect" "$nic_type" "$slot_id" + + if [ $? -ne 0 ];then + $fmt_print "console" "Error" "Can't build i2c connection" + exit 1 + fi +} + +start_sensor_reading(){ + +} +# --------------------------------------------------------- +# Start Execute Script +# --------------------------------------------------------- +conf_pre_check + +parse_slot_name + +connect_i2c + +start_sensor_reading + + diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh new file mode 100644 index 0000000..40507f7 --- /dev/null +++ b/tool/plugin/platform_5280m7.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +action=$1 +nic_type=$2 +slot_id=$3 + +i2c_script="i2c_m7.sh" +fmt_print="format_print.sh" + +pca9548_slave="" +pca9641_slave="" +i2c_bus="" +pca9548_channel="" + +set_i2c_config(){ + # set pca9641 address && I2C BUS + if [ $nic_type == "ocp" ];then + pca9548_slave="0x70" + i2c_bus=3 + else + if [ $slot_id -le 2 ];then + pca9641_slave="0x41" + pca9548_slave="0x72" + i2c_bus=12 + else + pca9641_slave="0x42" + pca9548_slave="0x72" + i2c_bus=13 + fi + fi + + # set pca9548 switch channel + if [ $nic_type == "ocp" ];then + if [ $slot_id -eq 0 ];then + pca9548_channel="0x01" + elif [ $slot_id -eq 1 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 2 ];then + pca9548_channel="0x04" + else + $fmt_print "console" "Warning" "Unspecified card slot!" + fi + else + if [ $slot_id -eq 0 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 1 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 2 ];then + pca9548_channel="0x08" + elif [ $slot_id -eq 3 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 4 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 5 ];then + pca9548_channel="0x08" + else + $fmt_print "console" "Warning" "Unspecified card slot!" + fi + fi +} + +build_i2c_connect(){ + $fmt_print "log" "Info" "[platform_5280m7] Start build i2c connect" + +} + +detect_on_server(){ + $fmt_print "log" "Info" "[platform_5280m7] Start i2c detect" +} + +# --------------------------------------------------- +# Start Execute Script +# --------------------------------------------------- +case "${action}" in + "connect") + build_i2c_connect + ;; + "detect") + detect_on_server + ;; + *) + $fmt_print "console" "Error" "[platform_5280m7] Unspecified Operation : $action" + exit 1 + ;; +esac + +exit 0 + From f0662a752d68afdaa0b558b198150436cb5c1783 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Thu, 20 Feb 2025 18:10:19 +0800 Subject: [PATCH 3/8] code sync --- tool/plugin/i2c_m7.sh | 6 ++++- tool/plugin/nicsensor.sh | 19 ++++++++------- tool/plugin/platform_5280m7.sh | 43 ++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/tool/plugin/i2c_m7.sh b/tool/plugin/i2c_m7.sh index a0b269e..e12abbd 100644 --- a/tool/plugin/i2c_m7.sh +++ b/tool/plugin/i2c_m7.sh @@ -6,4 +6,8 @@ slave=$3 data=$4 rc=$5 -i2ctransfer - y $i2c_bus w$wc@$slave $data r$5 \ No newline at end of file +if [ $rc -eq 0 ];then + i2ctransfer - y $i2c_bus w$wc@$slave $data +else + i2ctransfer - y $i2c_bus w$wc@$slave $data r$5 +fi \ No newline at end of file diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 4a66b1a..995a1e0 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -10,10 +10,11 @@ chip_slave=$3 nic_type="" slot_id="" -server_script="platform_${server_type}.sh" -sensor_script="plugin_${sensor_type}.sh" -i2c_script="i2c_${server_platform}.sh" -fmt_print="format_print.sh" +path=`pwd` +server_script="${path}/platform_${server_type}.sh" +sensor_script="${path}/plugin_${sensor_type}.sh" +i2c_script="${path}/i2c_${server_platform}.sh" +fmt_print="${path}/format_print.sh" conf_pre_check(){ @@ -45,20 +46,20 @@ conf_pre_check(){ parse_slot_name(){ # Get nic type and slot id from slot name - case "{$slot_name}" in + case "${slot_name}" in ocp*) nic_type="ocp" slot_id=`echo $slot_name | cut -c 4` - ;; + ;; pcie*) nic_type="pcie" slot_id=`echo $slot_name | cut -c 5-` - ;; + ;; *) $fmt_print "log" "Warning" "Undetermined nic type, default set to pcie" nic_type="pcie" slot_id=$slot_name - ;; + ;; esac } @@ -72,7 +73,7 @@ connect_i2c(){ } start_sensor_reading(){ - + $fmt_print "log" "Info" "start sensor reading" } # --------------------------------------------------------- # Start Execute Script diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh index 40507f7..0119c90 100644 --- a/tool/plugin/platform_5280m7.sh +++ b/tool/plugin/platform_5280m7.sh @@ -4,20 +4,25 @@ action=$1 nic_type=$2 slot_id=$3 -i2c_script="i2c_m7.sh" -fmt_print="format_print.sh" +path=`pwd` +i2c_script="${path}/i2c_m7.sh" +fmt_print="${path}/format_print.sh" pca9548_slave="" pca9641_slave="" i2c_bus="" pca9548_channel="" +is_have_pca9641=0 + set_i2c_config(){ # set pca9641 address && I2C BUS - if [ $nic_type == "ocp" ];then + if [ "${nic_type}" = "ocp" ];then + is_have_pca9641=0 pca9548_slave="0x70" i2c_bus=3 else + is_have_pca9641=1 if [ $slot_id -le 2 ];then pca9641_slave="0x41" pca9548_slave="0x72" @@ -30,7 +35,7 @@ set_i2c_config(){ fi # set pca9548 switch channel - if [ $nic_type == "ocp" ];then + if [ "${nic_type}" = "ocp" ];then if [ $slot_id -eq 0 ];then pca9548_channel="0x01" elif [ $slot_id -eq 1 ];then @@ -59,9 +64,37 @@ set_i2c_config(){ fi } +record_i2c_status(){ + $fmt_print "log" "Info" "[platform_5280m7] Start record i2c configuration" + $fmt_print "log" "Info" "Nic Type: $nic_type" + $fmt_print "log" "Info" "Nic slot: $slot_id" + $fmt_print "log" "Info" "i2c bus: $i2c_bus" + $fmt_print "log" "Info" "is have pca9641: $is_have_pca9641" + $fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641" + $fmt_print "log" "Info" "pca9548 slave: $pca9548_slave" + $fmt_print "log" "Info" "pca9548 channel: $pca9548_channel" +} + +get_pca9641_control(){ + $fmt_print "log" "Info" "[platform_5280m7] Start Get pca9641 control" +} + +select_pca9548_channel(){ + $fmt_print "log" "Info" "[platform_5280m7] Start Switch PCA9548" + # $i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0 +} + build_i2c_connect(){ $fmt_print "log" "Info" "[platform_5280m7] Start build i2c connect" - + set_i2c_config + record_i2c_status + + if [ $is_have_pca9641 -eq 1 ];then + get_pca9641_control + fi + + select_pca9548_channel + echo "$i2c_bus" } detect_on_server(){ From 7393c6bfb437b2a6c2c455c2edd6a6f3bd0c284f Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Fri, 21 Feb 2025 09:33:20 +0800 Subject: [PATCH 4/8] code sync --- tool/plugin/i2c_m7.sh | 12 +++++++++--- tool/plugin/nicsensor.sh | 19 ++++++++++++++++--- tool/plugin/platform_5280m7.sh | 2 +- tool/plugin/plugin_tmp112.sh | 27 +++++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/tool/plugin/i2c_m7.sh b/tool/plugin/i2c_m7.sh index e12abbd..1896119 100644 --- a/tool/plugin/i2c_m7.sh +++ b/tool/plugin/i2c_m7.sh @@ -6,8 +6,14 @@ slave=$3 data=$4 rc=$5 +path=`pwd` +fmt_print="${path}/format_print.sh" + if [ $rc -eq 0 ];then - i2ctransfer - y $i2c_bus w$wc@$slave $data + cmd="i2ctransfer -y $i2c_bus w$wc@$slave $data" else - i2ctransfer - y $i2c_bus w$wc@$slave $data r$5 -fi \ No newline at end of file + cmd="i2ctransfer -y $i2c_bus w$wc@$slave $data r$5" +fi + +$fmt_print "log" "Info" "[M7 i2c Command]: $cmd" +$cmd \ No newline at end of file diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 995a1e0..1cc05f1 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -6,6 +6,7 @@ server_platform="m7" slot_name=$1 sensor_type=$2 chip_slave=$3 +param_num=$# nic_type="" slot_id="" @@ -16,8 +17,18 @@ sensor_script="${path}/plugin_${sensor_type}.sh" i2c_script="${path}/i2c_${server_platform}.sh" fmt_print="${path}/format_print.sh" +print_helper(){ + echo "Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]" + echo "For Detect: ./nicsensor.sh detect [ocp/pcie]" +} + conf_pre_check(){ + if [ $param_num -lt 1 ];then + print_helper + exit 0 + fi + # init debug log if [ -e "/tmp/nicsensor_debug.log" ];then rm /tmp/nicsensor_debug.log @@ -29,12 +40,12 @@ conf_pre_check(){ fi if [ ! -e $server_script ];then - $fmt_print "console" "Error" "$server_script not exist!" + $fmt_print "console" "Error" "Server Script $server_script not exist! Maybe unsupport for now!" exit 1 fi if [ ! -e $sensor_script ];then - $fmt_print "console" "Error" "$sensor_script not exist!" + $fmt_print "console" "Error" "Sensor Script $sensor_script not exist! Maybe unsupport for now!" exit 1 fi @@ -74,6 +85,8 @@ connect_i2c(){ start_sensor_reading(){ $fmt_print "log" "Info" "start sensor reading" + + $sensor_script "read" "${i2c_bus}" "${chip_slave}" "${server_platform}" } # --------------------------------------------------------- # Start Execute Script @@ -82,7 +95,7 @@ conf_pre_check parse_slot_name -connect_i2c +i2c_bus=`connect_i2c` start_sensor_reading diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh index 0119c90..6134c62 100644 --- a/tool/plugin/platform_5280m7.sh +++ b/tool/plugin/platform_5280m7.sh @@ -81,7 +81,7 @@ get_pca9641_control(){ select_pca9548_channel(){ $fmt_print "log" "Info" "[platform_5280m7] Start Switch PCA9548" - # $i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0 + $i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0 } build_i2c_connect(){ diff --git a/tool/plugin/plugin_tmp112.sh b/tool/plugin/plugin_tmp112.sh index 290e4a5..b82e03a 100644 --- a/tool/plugin/plugin_tmp112.sh +++ b/tool/plugin/plugin_tmp112.sh @@ -1,5 +1,16 @@ #!/bin/sh +mode=$1 +i2c_bus=$2 +chip_slave=$3 +server_platform=$4 + +path=`pwd` +fmt_print="${path}/format_print.sh" +i2c_script="${path}/i2c_${server_platform}.sh" + +sensor_name="TMP112" + # @Param1 tmp112 data high 8bit # @Param2 tmp112 data low 8bit # @Param3 customization sensor name @@ -34,5 +45,17 @@ convert_tmp112_data(){ echo "$3 : $temp" } -# E.G. ./plugin_tmp112.sh 0x08 0x40 temp -convert_tmp112_data $1 $2 $3 \ No newline at end of file +read_tmp112_data(){ + res=`$i2c_script $i2c_bus "1" "$chip_slave" "0x00" "2"` + convert_tmp112_data $res "$sensor_name" +} + + +case "${mode}" in + "read") + read_tmp112_data + ;; + *) + $fmt_print "console" "Error" "[plugin_tmp112]Unexpected Input Param : $mode" + ;; +esac From 576d831af1c9d14d02f141e4d489cd3d2408e61e Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Fri, 21 Feb 2025 11:10:37 +0800 Subject: [PATCH 5/8] code sync --- tool/plugin/plugin_adc128.sh | 23 +++++++++++++++++++++-- tool/plugin/plugin_emc1413.sh | 22 +++++++++++++++++++++- tool/plugin/plugin_ina3221.sh | 22 +++++++++++++++++++++- tool/plugin/plugin_tmp468.sh | 22 +++++++++++++++++++++- 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/tool/plugin/plugin_adc128.sh b/tool/plugin/plugin_adc128.sh index 6eb936b..1b577ab 100644 --- a/tool/plugin/plugin_adc128.sh +++ b/tool/plugin/plugin_adc128.sh @@ -1,5 +1,14 @@ #!/bin/sh +mode=$1 +i2c_bus=$2 +chip_slave=$3 +server_platform=$4 + +path=`pwd` +fmt_print="${path}/format_print.sh" +i2c_script="${path}/i2c_${server_platform}.sh" + # process sensor data then print to console # @Param 1 adc128 data high 8bit # @Param 2 adc128 data low 8bit @@ -30,5 +39,15 @@ convert_adc128_data(){ echo "$3 : $format_volt v, hex value: $upper_hex_value" } -# E.G. convert_adc128_data 0x08 0x20 "3V3" "1" -convert_adc128_data $1 $2 $3 $4 \ No newline at end of file +read_adc128_data(){ + +} + +case "${mode}" in + "read") + read_adc128_data + ;; + *) + $fmt_print "console" "Error" "[plugin_adc128]Unexpected Input Param : $mode" + ;; +esac \ No newline at end of file diff --git a/tool/plugin/plugin_emc1413.sh b/tool/plugin/plugin_emc1413.sh index 6a7f011..4cd9244 100644 --- a/tool/plugin/plugin_emc1413.sh +++ b/tool/plugin/plugin_emc1413.sh @@ -1,5 +1,14 @@ #!/bin/sh +mode=$1 +i2c_bus=$2 +chip_slave=$3 +server_platform=$4 + +path=`pwd` +fmt_print="${path}/format_print.sh" +i2c_script="${path}/i2c_${server_platform}.sh" + # @Param1 emc1413 data high 8bit # @Param2 emc1413 data low 8bit # @Param3 customization channel name @@ -42,4 +51,15 @@ convert_emc1413_data(){ } -convert_emc1413_data $1 $2 $3 \ No newline at end of file +read_emc1413_data(){ + +} + +case "${mode}" in + "read") + read_emc1413_data + ;; + *) + $fmt_print "console" "Error" "[plugin_emc1413]Unexpected Input Param : $mode" + ;; +esac \ No newline at end of file diff --git a/tool/plugin/plugin_ina3221.sh b/tool/plugin/plugin_ina3221.sh index 7cc124c..a1d08f7 100644 --- a/tool/plugin/plugin_ina3221.sh +++ b/tool/plugin/plugin_ina3221.sh @@ -1,5 +1,14 @@ #!/bin/sh +mode=$1 +i2c_bus=$2 +chip_slave=$3 +server_platform=$4 + +path=`pwd` +fmt_print="${path}/format_print.sh" +i2c_script="${path}/i2c_${server_platform}.sh" + # @Param1 ina3221 data high 8bit # @Param2 ina3221 data high 8bit # @Param3 channel number @@ -76,4 +85,15 @@ convert_ina3221_data(){ fi } -convert_ina3221_data $1 $2 $3 $4 $5 $6 \ No newline at end of file +read_ina3221_data(){ + +} + +case "${mode}" in + "read") + read_ina3221_data + ;; + *) + $fmt_print "console" "Error" "[plugin_ina3221]Unexpected Input Param : $mode" + ;; +esac \ No newline at end of file diff --git a/tool/plugin/plugin_tmp468.sh b/tool/plugin/plugin_tmp468.sh index b80b96a..c18350f 100644 --- a/tool/plugin/plugin_tmp468.sh +++ b/tool/plugin/plugin_tmp468.sh @@ -1,5 +1,14 @@ #!/bin/sh +mode=$1 +i2c_bus=$2 +chip_slave=$3 +server_platform=$4 + +path=`pwd` +fmt_print="${path}/format_print.sh" +i2c_script="${path}/i2c_${server_platform}.sh" + # @Param1 tmp468 data high 8bit # @Param2 tmp468 data high 8bit # @Param3 customization channel name @@ -26,4 +35,15 @@ convert_tmp468_data(){ echo "$3 : $temp " } - convert_tmp468_data $1 $2 $3 \ No newline at end of file +read_tmp468_data(){ + +} + +case "${mode}" in + "read") + read_tmp468_data + ;; + *) + $fmt_print "console" "Error" "[plugin_tmp468]Unexpected Input Param : $mode" + ;; +esac \ No newline at end of file From 99cd4926d60957e76edac3be825484dbfec352fd Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Mon, 24 Feb 2025 20:15:41 +0800 Subject: [PATCH 6/8] code sync --- tool/plugin/autoauth.sh | 1 + tool/plugin/nicsensor.sh | 8 ++-- tool/plugin/platform_5280m7.sh | 78 ++++++++++++++++++++++++++++------ 3 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 tool/plugin/autoauth.sh diff --git a/tool/plugin/autoauth.sh b/tool/plugin/autoauth.sh new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/tool/plugin/autoauth.sh @@ -0,0 +1 @@ +#!/bin/sh diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 1cc05f1..05e92b9 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -96,7 +96,9 @@ conf_pre_check parse_slot_name i2c_bus=`connect_i2c` +if [ $? -ne 0 ];then + $fmt_print "console" "Error" "An Error occured when build i2c connection with ${slot_name}" + exit 1 +fi -start_sensor_reading - - +start_sensor_reading \ No newline at end of file diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh index 6134c62..e396fab 100644 --- a/tool/plugin/platform_5280m7.sh +++ b/tool/plugin/platform_5280m7.sh @@ -15,6 +15,17 @@ pca9548_channel="" is_have_pca9641=0 +record_i2c_status(){ + $fmt_print "log" "Info" "[platform_5280m7] Start record i2c configuration" + $fmt_print "log" "Info" "Nic Type: $nic_type" + $fmt_print "log" "Info" "Nic slot: $slot_id" + $fmt_print "log" "Info" "i2c bus: $i2c_bus" + $fmt_print "log" "Info" "is have pca9641: $is_have_pca9641" + $fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641" + $fmt_print "log" "Info" "pca9548 slave: $pca9548_slave" + $fmt_print "log" "Info" "pca9548 channel: $pca9548_channel" +} + set_i2c_config(){ # set pca9641 address && I2C BUS if [ "${nic_type}" = "ocp" ];then @@ -62,21 +73,24 @@ set_i2c_config(){ $fmt_print "console" "Warning" "Unspecified card slot!" fi fi -} - -record_i2c_status(){ - $fmt_print "log" "Info" "[platform_5280m7] Start record i2c configuration" - $fmt_print "log" "Info" "Nic Type: $nic_type" - $fmt_print "log" "Info" "Nic slot: $slot_id" - $fmt_print "log" "Info" "i2c bus: $i2c_bus" - $fmt_print "log" "Info" "is have pca9641: $is_have_pca9641" - $fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641" - $fmt_print "log" "Info" "pca9548 slave: $pca9548_slave" - $fmt_print "log" "Info" "pca9548 channel: $pca9548_channel" + record_i2c_status } get_pca9641_control(){ $fmt_print "log" "Info" "[platform_5280m7] Start Get pca9641 control" + + # Request 9641 lock + res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1` + $fmt_print "log" "Info" "[platform_5280m7]After request 9641 lock, The REG value is $res_lock" + + # Build 9641 Connection + res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1` + $fmt_print "log" "Info" "[platform_5280m7]After Build 9641 connection, The REG value is $res_build" + + if [ "$res_build" != "0x87" ];then + $fmt_print "log" "Error" "Cannot establish connection with pca9641 !!!" + exit 1 + fi } select_pca9548_channel(){ @@ -87,7 +101,6 @@ select_pca9548_channel(){ build_i2c_connect(){ $fmt_print "log" "Info" "[platform_5280m7] Start build i2c connect" set_i2c_config - record_i2c_status if [ $is_have_pca9641 -eq 1 ];then get_pca9641_control @@ -97,8 +110,47 @@ build_i2c_connect(){ echo "$i2c_bus" } +# switch pca9548 channels then do i2cdetect one times +# @Param1 i2c bus number +# @Param2 pca9548 slave address +# @Param3 pca9548 channel hex value +# @Param4 pca9548 channel +# @Param5 pcie slot number +do_i2c_detect(){ + if [ $nic_type == "ocp" ];then + $fmt_print "log" "Info" "OCP slot $5 : bus$1 9548channel$4" + else + $fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4" + fi + i2ctransfer -y $1 w1@$2 $3 + i2cdetect -y $1 +} + detect_on_server(){ - $fmt_print "log" "Info" "[platform_5280m7] Start i2c detect" + $fmt_print "console" "Info" "[platform_5280m7] Start i2c detect" + + if [ "${nic_type}" = "ocp" ];then + i2c_bus=3 + do_i2c_detect 3 0x70 0x01 0 0 + do_i2c_detect 3 0x70 0x02 1 1 + do_i2c_detect 3 0x70 0x04 2 2 + else + i2c_bus=12 + pca9641_slave="0x41" + get_pca9641_control + + do_i2c_detect 12 0x72 0x02 1 0 + do_i2c_detect 12 0x72 0x04 2 1 + do_i2c_detect 12 0x72 0x08 3 2 + + i2c_bus=13 + pca9641_slave="0x42" + get_pca9641_control + + do_i2c_detect 13 0x72 0x02 1 3 + do_i2c_detect 13 0x72 0x04 2 4 + do_i2c_detect 13 0x72 0x08 3 5 + fi } # --------------------------------------------------- From d71261692dad394468029caa3708ec6cad889ff4 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Wed, 26 Feb 2025 16:28:01 +0800 Subject: [PATCH 7/8] code sync --- tool/plugin/autoauth.sh | 22 ++++++++++++++++++++++ tool/plugin/nicsensor.sh | 15 +++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tool/plugin/autoauth.sh b/tool/plugin/autoauth.sh index 1a24852..33cd4db 100644 --- a/tool/plugin/autoauth.sh +++ b/tool/plugin/autoauth.sh @@ -1 +1,23 @@ #!/bin/sh + +# Get file conut first +file_num=`ls -l | wc -l` + +i=2 + +while true +do + i=$(($i+1)) + + # Get filename by ls and awk + file=`ls -l | awk -v cnt=$i 'NR==cnt{print $9}'` + cmd="chmod +x $file" + echo "File ID: $i , $cmd" + # perform chmod + $cmd + + if [ $i -eq $file_num ];then + echo "Done to add exec auth for every file" + break + fi +done \ No newline at end of file diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 05e92b9..226b3b8 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -22,6 +22,15 @@ print_helper(){ echo "For Detect: ./nicsensor.sh detect [ocp/pcie]" } +perform_detect(){ + if [ ! -e $server_script ];then + $fmt_print "console" "Error" "Server Script $server_script not exist! Maybe unsupport for now!" + exit 1 + fi + + $server_script "detect" +} + conf_pre_check(){ if [ $param_num -lt 1 ];then @@ -91,6 +100,12 @@ start_sensor_reading(){ # --------------------------------------------------------- # Start Execute Script # --------------------------------------------------------- +# check if is detect option +if [ "$1" = "detect" ];then + perform_detect + exit 0 +fi + conf_pre_check parse_slot_name From 2b91b4ac614888aaa2d67d88a2f3c9647e122463 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Thu, 13 Mar 2025 16:34:05 +0800 Subject: [PATCH 8/8] code sync --- tool/plugin/i2c_m6.sh | 13 ++- tool/plugin/nicsensor.sh | 28 ++++-- tool/plugin/platform_5280m7.sh | 14 +-- tool/plugin/platform_5688m7.sh | 161 +++++++++++++++++++++++++++++++++ tool/plugin/plugin_adc128.sh | 118 +++++++++++++++++++++++- tool/plugin/plugin_emc1413.sh | 58 +++++++++++- tool/plugin/plugin_ina3221.sh | 86 +++++++++++++++++- tool/plugin/plugin_tmp112.sh | 35 ++++++- tool/plugin/plugin_tmp468.sh | 77 +++++++++++++++- 9 files changed, 567 insertions(+), 23 deletions(-) create mode 100644 tool/plugin/platform_5688m7.sh diff --git a/tool/plugin/i2c_m6.sh b/tool/plugin/i2c_m6.sh index a489524..890ccc7 100644 --- a/tool/plugin/i2c_m6.sh +++ b/tool/plugin/i2c_m6.sh @@ -6,4 +6,15 @@ slave=$3 data=$4 rc=$5 -i2c_test -b $i2c_bus -s $slave -rc $rc -d $data | awk 'NR==3{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}' \ No newline at end of file +path=`pwd` +fmt_print="${path}/format_print.sh" + +if [ $rc -eq 0 ];then + cmd=`i2c-test -b $i2c_bus -s $slave -w -d $data` +else + cmd=`i2c-test -b $i2c_bus -s $slave -m 1 -rc $rc -d $data | awk 'NR==2{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}'` +fi + +$fmt_print "log" "Info" "[M6 i2c Command]: $cmd" +$cmd + diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 226b3b8..df45386 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -1,6 +1,7 @@ #!/bin/sh -server_type="5280m7" +script_version="v2.0" +server_type="5688m7" server_platform="m7" slot_name=$1 @@ -18,8 +19,11 @@ i2c_script="${path}/i2c_${server_platform}.sh" fmt_print="${path}/format_print.sh" print_helper(){ - echo "Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]" - echo "For Detect: ./nicsensor.sh detect [ocp/pcie]" + echo "======>>> nicsensor Scirpt Usage <<<======" + echo "Genenral Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]" + echo "For Detect : ./nicsensor.sh detect [ocp/pcie]" + echo "Current Server : $server_type" + echo "Script Version : $script_version" } perform_detect(){ @@ -38,11 +42,6 @@ conf_pre_check(){ exit 0 fi - # init debug log - if [ -e "/tmp/nicsensor_debug.log" ];then - rm /tmp/nicsensor_debug.log - fi - if [ ! -e $fmt_print ];then echo "Missing file $fmt_print !!!" exit 1 @@ -62,6 +61,12 @@ conf_pre_check(){ $fmt_print "console" "Error" "$i2c_script not exist!" exit 1 fi + + res_date=`date +%Y-%m-%dT%H:%M:%S` + $fmt_print "log" "Info" "Start Time : $res_date" + $fmt_print "log" "Info" "Script Version : $script_version" + $fmt_print "log" "Info" "Server Type : $server_type" + $fmt_print "log" "Info" "Slot Name : $slot_name" } parse_slot_name(){ @@ -100,6 +105,11 @@ start_sensor_reading(){ # --------------------------------------------------------- # Start Execute Script # --------------------------------------------------------- +# init debug log +if [ -e "/tmp/nicsensor_debug.log" ];then + rm /tmp/nicsensor_debug.log +fi + # check if is detect option if [ "$1" = "detect" ];then perform_detect @@ -112,7 +122,7 @@ parse_slot_name i2c_bus=`connect_i2c` if [ $? -ne 0 ];then - $fmt_print "console" "Error" "An Error occured when build i2c connection with ${slot_name}" + $fmt_print "console" "Error" "An Error occured when build i2c connection with ${nic_type} ${slot_id}" exit 1 fi diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh index e396fab..a933c59 100644 --- a/tool/plugin/platform_5280m7.sh +++ b/tool/plugin/platform_5280m7.sh @@ -28,7 +28,7 @@ record_i2c_status(){ set_i2c_config(){ # set pca9641 address && I2C BUS - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then is_have_pca9641=0 pca9548_slave="0x70" i2c_bus=3 @@ -46,7 +46,7 @@ set_i2c_config(){ fi # set pca9548 switch channel - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then if [ $slot_id -eq 0 ];then pca9548_channel="0x01" elif [ $slot_id -eq 1 ];then @@ -81,14 +81,14 @@ get_pca9641_control(){ # Request 9641 lock res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1` - $fmt_print "log" "Info" "[platform_5280m7]After request 9641 lock, The REG value is $res_lock" + $fmt_print "log" "Info" "[platform_5280m7] After request 9641 lock, The REG value is $res_lock" # Build 9641 Connection res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1` - $fmt_print "log" "Info" "[platform_5280m7]After Build 9641 connection, The REG value is $res_build" + $fmt_print "log" "Info" "[platform_5280m7] After Build 9641 connection, The REG value is $res_build" if [ "$res_build" != "0x87" ];then - $fmt_print "log" "Error" "Cannot establish connection with pca9641 !!!" + $fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!" exit 1 fi } @@ -117,7 +117,7 @@ build_i2c_connect(){ # @Param4 pca9548 channel # @Param5 pcie slot number do_i2c_detect(){ - if [ $nic_type == "ocp" ];then + if [ "${nic_type}" == "ocp" ];then $fmt_print "log" "Info" "OCP slot $5 : bus$1 9548channel$4" else $fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4" @@ -129,7 +129,7 @@ do_i2c_detect(){ detect_on_server(){ $fmt_print "console" "Info" "[platform_5280m7] Start i2c detect" - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then i2c_bus=3 do_i2c_detect 3 0x70 0x01 0 0 do_i2c_detect 3 0x70 0x02 1 1 diff --git a/tool/plugin/platform_5688m7.sh b/tool/plugin/platform_5688m7.sh new file mode 100644 index 0000000..d3be9d9 --- /dev/null +++ b/tool/plugin/platform_5688m7.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +action=$1 +nic_type=$2 +slot_id=$3 + +path=`pwd` +i2c_script="${path}/i2c_m7.sh" +fmt_print="${path}/format_print.sh" + +pca9548_slave="" +pca9641_slave="" +i2c_bus="" +pca9548_channel="" + +is_have_pca9641=0 + +record_i2c_status(){ + $fmt_print "log" "Info" "[platform_5688m7] Start record i2c configuration" + $fmt_print "log" "Info" "Nic Type: $nic_type" + $fmt_print "log" "Info" "Nic slot: $slot_id" + $fmt_print "log" "Info" "i2c bus: $i2c_bus" + $fmt_print "log" "Info" "is have pca9641: $is_have_pca9641" + $fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641" + $fmt_print "log" "Info" "pca9548 slave: $pca9548_slave" + $fmt_print "log" "Info" "pca9548 channel: $pca9548_channel" +} + +set_i2c_config(){ + # set pca9641 address && I2C BUS + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic" + exit 1 + else + is_have_pca9641=1 + i2c_bus=12 + pca9641_slave="0x31" + if [ $slot_id -le 3 ];then + pca9548_slave="0x71" + else + pca9548_slave="0x72" + fi + fi + + # set pca9548 switch channel + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic" + exit 1 + else + if [ $slot_id -eq 0 ];then + pca9548_channel="0x01" + elif [ $slot_id -eq 1 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 2 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 3 ];then + pca9548_channel="0x08" + elif [ $slot_id -eq 4 ];then + pca9548_channel="0x01" + elif [ $slot_id -eq 5 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 6 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 7 ];then + pca9548_channel="0x08" + else + $fmt_print "console" "Warning" "Unspecified card slot!" + fi + fi + record_i2c_status +} + +get_pca9641_control(){ + $fmt_print "log" "Info" "[platform_5688m7] Start Get pca9641 control" + + # Request 9641 lock + res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1` + $fmt_print "log" "Info" "[platform_5688m7] After request 9641 lock, The REG value is $res_lock" + + # Build 9641 Connection + res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1` + $fmt_print "log" "Info" "[platform_5688m7] After Build 9641 connection, The REG value is $res_build" + + if [ "$res_build" != "0x87" ];then + $fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!" + exit 1 + fi +} + +select_pca9548_channel(){ + $fmt_print "log" "Info" "[platform_5688m7] Start Switch PCA9548" + $i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0 +} + +build_i2c_connect(){ + $fmt_print "log" "Info" "[platform_5688m7] Start build i2c connect" + set_i2c_config + + if [ $is_have_pca9641 -eq 1 ];then + get_pca9641_control + fi + + select_pca9548_channel + echo "$i2c_bus" +} + +# switch pca9548 channels then do i2cdetect one times +# @Param1 i2c bus number +# @Param2 pca9548 slave address +# @Param3 pca9548 channel hex value +# @Param4 pca9548 channel +# @Param5 pcie slot number +do_i2c_detect(){ + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Info" "OCP slot $5 : bus$1 9548channel$4" + else + $fmt_print "console" "Info" "PCIe slot $5 : bus$1 9548channel$4" + fi + i2ctransfer -y $1 w1@$2 $3 + i2cdetect -y $1 +} + +detect_on_server(){ + $fmt_print "console" "Info" "[platform_5688m7] Start i2c detect" + + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic I2C Detect" + else + i2c_bus=12 + pca9641_slave="0x31" + get_pca9641_control + + do_i2c_detect $i2c_bus 0x71 0x01 0 0 + do_i2c_detect $i2c_bus 0x71 0x02 1 1 + do_i2c_detect $i2c_bus 0x71 0x04 2 2 + do_i2c_detect $i2c_bus 0x71 0x08 3 3 + do_i2c_detect $i2c_bus 0x72 0x01 0 4 + do_i2c_detect $i2c_bus 0x72 0x02 1 5 + do_i2c_detect $i2c_bus 0x72 0x04 2 6 + do_i2c_detect $i2c_bus 0x72 0x08 3 7 + fi +} + +# --------------------------------------------------- +# Start Execute Script +# --------------------------------------------------- +case "${action}" in + "connect") + build_i2c_connect + ;; + "detect") + detect_on_server + ;; + *) + $fmt_print "console" "Error" "[platform_5688m7] Unspecified Operation : $action" + exit 1 + ;; +esac + +exit 0 + diff --git a/tool/plugin/plugin_adc128.sh b/tool/plugin/plugin_adc128.sh index 1b577ab..e6f5d8d 100644 --- a/tool/plugin/plugin_adc128.sh +++ b/tool/plugin/plugin_adc128.sh @@ -1,14 +1,86 @@ #!/bin/sh +# ADC128 Division factor +votage_division_factor_0="1" +votage_division_factor_1="1" +votage_division_factor_2="1" +votage_division_factor_3="0.8" +votage_division_factor_4="0.6" +votage_division_factor_5="0.6" +votage_division_factor_6="0.2326" +votage_division_factor_7="1" + +# ADC128 channel name +ADC128_Channel0_name="Channel0" +ADC128_Channel1_name="Channel1" +ADC128_Channel2_name="Channel2" +ADC128_Channel3_name="Channel3" +ADC128_Channel4_name="Channel4" +ADC128_Channel5_name="Channel5" +ADC128_Channel6_name="Channel6" +ADC128_Channel7_name="Channel7" + mode=$1 i2c_bus=$2 chip_slave=$3 server_platform=$4 +# Only for test purpose +test_data1=$2 +test_data2=$3 +test_factor=$4 + path=`pwd` fmt_print="${path}/format_print.sh" i2c_script="${path}/i2c_${server_platform}.sh" +REG_adc128_config="0x00" +REG_adc128_advance="0x0b" +REG_adc128_status="0x0c" +REG_adc128_ch0="0x20" +REG_adc128_ch1="0x21" +REG_adc128_ch2="0x22" +REG_adc128_ch3="0x23" +REG_adc128_ch4="0x24" +REG_adc128_ch5="0x25" +REG_adc128_ch6="0x26" +REG_adc128_ch7="0x27" + +print_help(){ + echo "---------------------------------------------------------" + echo "