【Note2】macvlan,sol
文章目录
- 6.iptables:(ip+tables)对网络上数据包通过表的形式进行规则的修改
- 6.1 filter表:3个链
- 6.2 nat表:4个链
- 7.linux的route指令:route add
- 1.BMC虚拟多网口:macvlan是kernel提供的一种网卡虚拟化技术,可将网卡(不一定是真实的物理网卡)虚拟出多个接口,这网卡称为master或父接口,这些虚拟接口和外面环境通信都是通过父接口
- 1.1 bridge:ip netns add ns001 / ns002
- 1.2 private:FB Openbmc(AST2520实物芯片)和OcpOpenBMC(qemu ast2500-evb)以及X86 Ubuntu上验证过, Kernel版本均5.0+
- 编译Kernel:BMC/CPU OS的Linux Kernel Config里面加CONFIG_MACVLAN=m/y
- 创建/启动网卡/获取DHCP地址:创建网卡以eth0为目标物理网口,虚拟网口的MAC地址自定义,mode可以选择private不能互通,bridge内部互通等
- 配置路由表:由于5个网口都被分配在一个网段如10.75.159.0/24(掩码一样),导致linux内部路由会以高优先级的网口如eth0来响应外部的arp/icmp/tcp等各种网络请求(如ping 10.75.159.x都走eth0网卡)。为了达到5个虚拟网口能在同网段以5个独立网口的形式工作,呈现5个独立网口MAC地址,需要配置路由表
- 远端服务器检查:ping 10.75.159.117/120/121/125/132
- 案例:iproute2,设置路由重启后不丢失/etc/network/interfaces:up route add -host 10.1.1.2 dev eth1
- 1.3 creat_macvlan.sh:macvlan文件夹里file文件夹里有.sh和.service,file文件夹同级有.bb文件
- 2.rsyslog:rsyslogd一个进程 ,管理每个进程发来的log并往/var/log里写,syslog函数将log写给rsyslogd进程
- 2.1 logrotate:/etc/logrotate.conf = include /etc/logrotate.d
- logrotate-default
- logrotate_%.bbappend
- 2.2 rsyslog:通过rsyslog.conf采集内存中数据并保存
- log_rotate:执行第一行
- rsyslog.logrotate:相当于/etc/logrotate.conf
- rsyslog.conf
- rsyslog_%.bbappend
- 3.journalctl:内存中日志,因为是二进制无法查看,所以用journalctl命令查看
- 4.sol:cpld自动捕捉热键/手动配寄存器
- 5.位号/lspci/
- 6.
6.iptables:(ip+tables)对网络上数据包通过表的形式进行规则的修改
6.1 filter表:3个链
man iptables(防火墙)查看有哪些表(table)。filter(过滤器)表【不转发】
会将进入当前机器数据包进行过滤,以及从机器出去的数据包,不符合条件不给发出去。nat表【转发】
改变目的或源地址和端口。
上面的表是由链构成,进入和出去配置规则放在链中:filter表自带的三个链:FORWARD链
:和nat表相关,路由转发的作用,-L(list)。INPUT和OUTPUT链
:默认(policy)没有一条规则即都能进来和出去。
如下在ip为192.168.0.12机器8081端口上启动服务。
如下本机器(192.168.0.12)收到一个包,这个包目的地址是8081且是tcp包
的话丢弃。
如下在192.168.0.144机器访问0.12。
如下删除后又能访问了。
如上是在input链上进行的防火墙的设置,如下也可以设置output链
,将发往0.144包丢弃,如下没有配置端口,所以ssh连接也断了,因为我在0.144win上ssh双向连接到0.12即如下窗口,可修改0.144win的ip地址,再进行ssh连接。
上面通过-A添加规则,先后顺序是第一条成功了按第一条来,不成功第二条,一直往下匹配,最终也没找到匹配就按照policy。想要当前规则最高优先级用-I(insert),不用-A(append),-I INPUT 5会插在第5条。
6.2 nat表:4个链
如下在0.11机器上。
如下在0.144 win机器上。
把0.12的7788端口转发到0.11的7799端口,实现反向代理。这件事分为下面两步:虽然第一条是请求
转发过去了,但是响应
(第二条)要改为本机,才能发回来。
如下是在0.12机器shell上,第一行对应上面第一条:访问本机即0.12的dport(目的端口)即7788端口的数据包转到0.11的7799端口。第二行对应上面第二条。
如下是上一行命令执行结果,查看一下FOREARD有没有过滤掉。
如下重写FORWARD链为ACCEPT即在上面DOCKER-USER规则前面添加一个ACCEPT规则。
如上不是配置xx.conf的服务不需要重启,随时生效,如下两个都能访问了。
如下绿色方框是net表的链。两条路:改目或不改目。橙色的input用来改源地址和post功能一样,橙色的output用来该目的地址和pre功能一样,那不是和pre,post重复了吗?不重复,当电脑里有一个APP如下(没有左半边即没有pre到Forward),pre和input失效,右半边output起到了改目的地址作用。
7.linux的route指令:route add
如下Gateway指定网关,要访问172.17.0.3这ip,就会根据Destination和Genmask
计算出来满足docker0这一行条件,走这条路由信息。Flags是标识(不重要),U表示正在使用中,G表示第二列Gateway不为*即空即0.0.0.0即不指定掩码)
。H表示指定具体ip(32位掩码,4个255,全掩)而不是网段
。default是指访问一个ip都不满足下面两个路由信息条件,走default这条。255.255.0.0掩了16位即172.17开头的会走第二条,255.255.255.0掩了24位。
PandoraBox.lan其实是个ip,因为在局域网下,默认配置成了域名。172.17.0.7只1跳(直接跳脸上),因为Gateway为*空且都在docker0交换机下。如下命令都是在ubuntu机器上执行,路由信息看该章节最后一张图。
下面用route add
指令添加自己的路由表:两种类型: -net x.x.x.x/xx
指定网络/网段,-host x.x.x.x
指定具体ip。两种指向:-dev
网卡名(指定通过哪个网卡),-gw
网关ip(指定通过哪个网关)。
如下案例:从ubuntu机器ping 199.199.199.199,配置路由使能通:先给win机器添加ip,点高级弹出如下最后一张图,填199.199.199.199,255.0.0.0,最后全点击确定。
未添加路由表时199.199.199.199不属于172.或192.两个网络,所以走了default,到了PandoraBox.lan即路由器网关,继续往上找,光猫也没发现继续往上找,传到了联通,199.199.199.199还没被用或不能被ping。
1.BMC虚拟多网口:macvlan是kernel提供的一种网卡虚拟化技术,可将网卡(不一定是真实的物理网卡)虚拟出多个接口,这网卡称为master或父接口,这些虚拟接口和外面环境通信都是通过父接口
1.1 bridge:ip netns add ns001 / ns002
macvlan模拟的mac不同,如下第一行和第二行创建两个以ens32为父接口
的macvlan1和macvlan2虚拟网口。
如下将ns001/2绑定网卡macvlan1/2,进入ns001虚拟环境,将网卡up起来。
如下添加ip,不通原因是bridge模式和父接口(.138)
是不通的。
如下在ns002虚拟环境,宿主机(76.1)
指的windows这台机器,如下两个都是往外ping。
1.2 private:FB Openbmc(AST2520实物芯片)和OcpOpenBMC(qemu ast2500-evb)以及X86 Ubuntu上验证过, Kernel版本均5.0+
编译Kernel:BMC/CPU OS的Linux Kernel Config里面加CONFIG_MACVLAN=m/y
如下在编译的服务器上编译完后,如果找不到就删除build目录重新编译。
如下在烧录的机器上烧录镜像后,vi第一行.dep文件。
如下不用insmod kernel/drivers/net/maclan.ko。
创建/启动网卡/获取DHCP地址:创建网卡以eth0为目标物理网口,虚拟网口的MAC地址自定义,mode可以选择private不能互通,bridge内部互通等
假设生成5个虚拟网口eth0.1-eth0.5命令如下,ifconfig检查5个虚拟网口的IP地址和MAC地址(都不一样):
ip link add link eth0 dev eth0.1 address D6:D2:52:A8:28:28 type macvlan mode private
ip link add link eth0 dev eth0.2 address D6:D2:52:A8:28:29 type macvlan mode private
ip link add link eth0 dev eth0.3 address D6:D2:52:A8:28:2a type macvlan mode private
ip link add link eth0 dev eth0.4 address D6:D2:52:A8:28:2b type macvlan mode private
ip link add link eth0 dev eth0.5 address D6:D2:52:A8:28:2c type macvlan mode private
ifconfig eth0.1 up
ifconfig eth0.2 up
ifconfig eth0.3 up
ifconfig eth0.4 up
ifconfig eth0.5 up
dhclient eth0.1
dhclient eth0.2
dhclient eth0.3
dhclient eth0.4
dhclient eth0.5
配置路由表:由于5个网口都被分配在一个网段如10.75.159.0/24(掩码一样),导致linux内部路由会以高优先级的网口如eth0来响应外部的arp/icmp/tcp等各种网络请求(如ping 10.75.159.x都走eth0网卡)。为了达到5个虚拟网口能在同网段以5个独立网口的形式工作,呈现5个独立网口MAC地址,需要配置路由表
echo "210 eth0table" >> /etc/iproute2/rt_tables # 210越大优先级越低
echo "220 eth1table" >> /etc/iproute2/rt_tables
echo "230 eth2table" >> /etc/iproute2/rt_tables
echo "240 eth3table" >> /etc/iproute2/rt_tables
echo "250 eth4table" >> /etc/iproute2/rt_tables
ip route add 10.75.159.0/24 dev eth0.1 src 10.75.159.117 table eth0table # 网段(掩码),ip
ip route add 10.75.159.0/24 dev eth0.2 src 10.75.159.120 table eth1table
ip route add 10.75.159.0/24 dev eth0.3 src 10.75.159.121 table eth2table
ip route add 10.75.159.0/24 dev eth0.4 src 10.75.159.125 table eth3table
ip route add 10.75.159.0/24 dev eth0.5 src 10.75.159.132 table eth4table
ip route add default dev eth0.1 via 10.75.159.1 table eth0table # via 网关
ip route add default dev eth0.2 via 10.75.159.1 table eth1table
ip route add default dev eth0.3 via 10.75.159.1 table eth2table
ip route add default dev eth0.4 via 10.75.159.1 table eth3table
ip route add default dev eth0.5 via 10.75.159.1 table eth4table
ip rule add from 10.75.159.117 table eth0table
ip rule add from 10.75.159.120 table eth1table
ip rule add from 10.75.159.121 table eth2table
ip rule add from 10.75.159.125 table eth3table
ip rule add from 10.75.159.132 table eth4table
远端服务器检查:ping 10.75.159.117/120/121/125/132
如下只有发起ping 117才能看到117这个ip,BMC侧IP的MAC地址与远端服务器获取的一致,符合预期。使用tcp方式测试:BMC端(服务端)iperf -s -p port,远端(客户端)iperf -c BMCIP -t 1000 -i 3 -p port。
案例:iproute2,设置路由重启后不丢失/etc/network/interfaces:up route add -host 10.1.1.2 dev eth1
注意如下是规则rule,不是route。
如下没指定路由表就会到main表中。
hping3 -I eth0 -a 10.75.159.37 -S 10.75.159.138 -p 8080 -i u100 发起攻击,iptables限制端口,限制连接数防止攻击。
1.3 creat_macvlan.sh:macvlan文件夹里file文件夹里有.sh和.service,file文件夹同级有.bb文件
#!/bin/sh
IP_ROUTEFILE_PATH="/etc/iproute2/rt_tables"
priority_arry=(210 220 230 240)
tablename_arry=(eth0table eth1table eth2table eth3table)
#dynamic routing configuration for macvlan
dynamic_routing()
{
#Initialize basic network information
index=0
for i in $(ifconfig | grep -o ^[a-z0-9.]* | grep -v lo); do
ipaddr_array[$index]=$(ifconfig "$i" | sed -n 2p | awk '{ print $2 }' | tr -d 'addr:')
devname_array[$index]=$i
gateway_array[$index]=$(route | grep "${devname_array[$index]}" | grep 'default' | awk '{print $2}')
iprange_array[$index]="${ipaddr_array[$index]%[^0-9]*}.0/24"
index=$((index + 1))
done
#Create the table and initialize it
index=0
for i in "${tablename_arry[@]}"; do
tablename=$(cat $IP_ROUTEFILE_PATH | grep "${devname_array[$index]}" | sed -n 1p | awk -F ' ' '{print$2}')
if [ "$tablename" != "${tablename_arry[$index]}" ]; then
echo "${priority_arry[$index]} ${tablename_arry[$index]}" >> $IP_ROUTEFILE_PATH
fi
ip route flush table "${tablename_arry[$index]}"
index=$((index + 1))
done
#Configure dynamic routing for the table
index=0
for i in "${tablename_arry[@]}"; do
ip route add "${iprange_array[$index]}" dev "${devname_array[$index]}" src "${ipaddr_array[$index]}" table "${tablename_arry[$index]}"
ip route add default dev "${devname_array[$index]}" via "${gateway_array[$index]}" table "${tablename_arry[$index]}"
ip rule add from "${ipaddr_array[$index]}" table "${tablename_arry[$index]}"
index=$((index + 1))
done
}
###Creat MAC Vlan
ip link add link eth0 dev eth1 type macvlan
ip link add link eth0 dev eth2 type macvlan
ip link add link eth0 dev eth3 type macvlan
ip link set eth1 up
ip link set eth2 up
ip link set eth3 up
sleep 2
#dhclient eth0.01
#dhclient eth0.02
#dhclient eth0.03
dynamic_routing
# macvlan.service
[Unit]
Description=Mac Vlan Server
After=-xyz.openbmc_project.Network.service
[Service]
ExecStart=/usr/bin/creat_macvlan.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
# macvlan.bb
SUMMARY = "Phosphor BMC Macvlan"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
inherit pkgconfig
inherit obmc-phosphor-systemd
SYSTEMD_SERVICE:${PN} += "macvlan.service"
DEPENDS += "systemd"
SRC_URI += "file://macvlan.service \
file://creat_macvlan.sh \
"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/creat_macvlan.sh ${D}${bindir}/creat_macvlan.sh
}
S = "${WORKDIR}"
2.rsyslog:rsyslogd一个进程 ,管理每个进程发来的log并往/var/log里写,syslog函数将log写给rsyslogd进程
ident将是一个标记,省略的话即打印出进程的名字如下。
facility默认是user。
如下排除文件中以#开头
的和去除空行
。
输出频道为用户可能想要的输出类型提供了保护,在规则中使用前要先定义如下:
10.75.159.146做服务端,/etc/rsyslog.conf 打开如下配置,tcp打开tcp的配置:
module(load="imudp")
input(type="imudp" port="514")
$IncludeConfig /etc/rsyslog.d/*.conf
/etc/rsyslog.d/remote.conf 配置如下(修改完需重启rsyslog进程),sonic将如下直接写在rsyslog.conf:
:fromhost,isequal, "10.75.159.37" /var/log/remote_37.log
以下的ip用lastb查看
2.1 logrotate:/etc/logrotate.conf = include /etc/logrotate.d
logrotate-default
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
logrotate_%.bbappend
FILESEXTRAPATHS_append := "${THISDIR}/${PN}:"
SRC_URI += " \
file://logrotate-3.9.1/examples/logrotate-default \
"
# We need to rotate every hour or could quickly run out of RAM.
LOGROTATE_SYSTEMD_TIMER_BASIS = "hourly"
LOGROTATE_SYSTEMD_TIMER_ACCURACY = "30m"
do_install_append() {
install -p -m 644 ${WORKDIR}/logrotate-3.9.1/examples/logrotate-default ${D}${sysconfdir}/logrotate.conf
if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
# XXX For now we build Yocto with systemd enabled and sysvinit
# compat to allow remaining sysvinit scripts to continue working.
# With both systemd & sysvinit compat on, the logrotate recipe gets
# it wrong and installs both the crontab entry and systemd timer.
# When sysvinit compat is removed then this can go away.
rm -f ${D}${sysconfdir}/cron.daily/logrotate
fi
}
2.2 rsyslog:通过rsyslog.conf采集内存中数据并保存
log_rotate:执行第一行
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit $EXITVALUE
rsyslog.logrotate:相当于/etc/logrotate.conf
/var/log/fscd.log
/var/log/dhclient.log
/var/log/messages
/var/log/sensor-mon.log
/var/log/power-mon.log
/var/log/come-mon.log
/var/log/temp-mon.log
{
rotate 9
missingok
notifempty
size 20M
delaycompress
compress
postrotate
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
rsyslog.conf
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # kernel logging (formerly provided by rklogd)
module(load="imfile") # Provides support for tailing and categorizing existing log files
$ActionQueueType Direct # Do not queue these, write immediately
global(workDirectory="/tmp") # Remembers the last file position when syslog restarts and does not retransmit
# Set the default permissions
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PreserveFQDN on
# Use format recognized by log-util.
$template LogUtilFileFormat," %$YEAR% %TIMESTAMP% %pri-text% __OPENBMC_VERSION__: %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
# Store dhclient logs into dhclient.log,
# store everything else into /var/log/messages
if $programname == "dhclient" then /var/log/dhclient.log
else
# limit size to 21M
$outchannel messagefile_channel, /var/log/messages, 22020096, /usr/local/fbpackages/rotate/log_rotate
*.* :omfile:$messagefile_channel;LogUtilFileFormat
# Save boot messages also to boot.log
local7.* /tmp/boot.log;LogUtilFileFormat
# Store come-mon logs into come-mon_rsyslog.log
if $programname == "come-mon" then
$outchannel comemonfile_channel, /var/log/come-mon.log, 22020096, /usr/local/fbpackages/rotate/log_rotate
*.* :omfile:$comemonfile_channel;LogUtilFileFormat
# Store power-mon logs into power-mon_rsyslog.log
if $programname == "power-mon" then
$outchannel powermonfile_channel, /var/log/power-mon.log, 22020096, /usr/local/fbpackages/rotate/log_rotate
*.* :omfile:$powermonfile_channel;LogUtilFileFormat
# Store sensor-mon logs into sensor-mon_rsyslog.log
if $programname == "sensor-mon" then
$outchannel sensormonfile_channel, /var/log/sensor-mon.log, 22020096, /usr/local/fbpackages/rotate/log_rotate
*.* :omfile:$sensormonfile_channel;LogUtilFileFormat
# Store temp-mon logs into temp-mon_rsyslog.log
if $programname == "temp-mon" then
$outchannel tempmonfile_channel, /var/log/temp-mon.log, 22020096, /usr/local/fbpackages/rotate/log_rotate
*.* :omfile:$tempmonfile_channel;LogUtilFileFormat
#mTerm_server log (TBD)
# Send local3 log to the /var/log/messages
#input(type="imfile"
# File="/var/log/mTerm_consol.log"
# Tag="oob_mTerm_consol"
# Severity="debug"
# Facility="local3"
# reopenOnTruncate="on"
#)
# 如下将info级别及其以上级别(可改成crit等其他级别)的日志发送给target服务端
*.info action(type="omfwd" name="remoteLog" template="LogUtilFileFormat" target="10.75.159.146" port="514" protocol="udp"
queue.type="LinkedList" action.resumeRetryCount="1" action.resumeInterval="60"
queue.size="500" queue.workerthreadminimummessages="101" queue.discardseverity="0"
queue.timeoutenqueue="0" queue.timeoutshutdown="10" queue.timeoutactioncompletion="100"
action.reportSuspension="off" action.reportSuspensionContinuation="off")
$IncludeConfig /etc/rsyslog.d/*.conf
rsyslog_%.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += "file://rsyslog.conf \
file://log_rotate \
file://rsyslog.logrotate \
"
MTERM_LOG_FILES ?= "mTerm_${MACHINE}"
do_install_append() {
dst="${D}/usr/local/fbpackages/rotate"
rsysconf="${D}${sysconfdir}/rsyslog.d"
install -d $dst
install -d ${rsysconf}
install -m 755 ${WORKDIR}/log_rotate ${dst}/log_rotate
install -m 644 ${WORKDIR}/rsyslog.logrotate ${D}${sysconfdir}/logrotate.rsyslog
install -m 644 ${WORKDIR}/rsyslog.conf ${D}${sysconfdir}/rsyslog.conf
sed -i "s/__OPENBMC_VERSION__/${OPENBMC_VERSION}/g" ${D}${sysconfdir}/rsyslog.conf
}
FILES_${PN} += "/usr/local/fbpackages/rotate"
3.journalctl:内存中日志,因为是二进制无法查看,所以用journalctl命令查看
4.sol:cpld自动捕捉热键/手动配寄存器
如下前面板rj45(网口通过rs232串口协议当串口用),cpld捕捉ctrl+urt热键切bmc或cpu。
如下sol cpu(橙线),配cpld寄存器改变接线方式如下,rj45串口直接接到bmc。
如下sol bmc(client启动),接线如下,uart3到cpld再到uart5。
5.位号/lspci/
左面是对应的LC CPLD寄存器的名字 中间是切换后器件在的通道号 右面是器件位号。
如下在9548上,起始地址24是lc2 (switch) cpld的bus号,加上对应通道数就是虚拟的bus号。
traffic:外部loocpack,cpu发包,cpu收包 。MTS:产测 。MTD:开发平台。REL:可靠性(高低温)。EMC:散热。sit系统集成,siv信号硬件。
前面板前36个是loopback(光模块插DAC线或光纤,lookpack内部TX和RX接在一起),37-64网口是fpga和nic卡。100G无4个lan。61和62->mellax 100G,e810 25G。
fpga 100g : cpu - fpga - switch - loopback - switch - fpga。
fpga 25g : fpga - switch。
100g: cpu - 业务口(1-36)。
ctrl - switch cpld。
总线(控制器):平台设备和平台驱动 ,两者相match【锁,上层底层交互,中断】。
python默认sh(库少),bash(库多),lspci -nn(等同-n)。 lspci (高速)| grep 只插了网卡,FW不知。多了eth,ip a看到,ifconfig只能看到有ip的eth。
str : json.load json 。 json : json.loads json 。kcs即lpc(低速),dom和aglex fpga都和switch绑定,fpga的eeprom存指令控制switch。
layout只fpga,1个fpga有8个pcie设备(pf),1个pcie设备有16个通道,fpga 00寄存器版本,20寄存器scratch。
u:unicode中文显示,gpio模拟jtag升级,prbs二进制码。南桥pch和bmc间相连有带内lpc,usb,uart,spi,i2c,还有带外ip。
./uTool -H 10.55.208.89 -U sysadmin -P superuser getip。 sysadmin是串口登录,admin/admin是登录BMC里面的。
ethtool 网卡名 :查看网卡速率,全双工。VR(DC,12直流转直流)。bios配gpio基地址, gpio dw0 : tx rx 高低电平,native function :i2c。
如下阴影是32位寄存器,31-0对应400-403(0,1,2,3【存储8-0bit】)大端存储,devmem2…403 b 读取一个字节。
6.
reboot_str=$(/usr/local/bin/reboot_cpu -i $index -o cycle)
if echo "$reboot_str" | grep Success > /dev/null 2>&1 ; then
version_after=$(show_version lc$index | grep 'COME CPLD Version' | awk -F' ' '{print $7}')
version_before=$(echo $COME_CPLD_FW | cut -d_ -f 6)
version_before="v"$version_before
if [ "$version_after" == "$version_before" ];then
def get_fpga_version(self, also_print_console=False):
fpga_dict = {
"AgilexFPGA1" : "ca",
"AgilexFPGA2" : "cb",
"AgilexFPGA3" : "98",
"AgilexFPGA4" : "99"
}
ret = E.OK
for fpga,bus in fpga_dict.items():
cmd = f"{AGILEX_FPGA_PATH}/devmem 0000:{bus}:00.0 2 0x0000"
status , log = run_command(cmd)
if status !=0 or len(log) == 0:
self.fail_reason.append("get {} version fail.".format(fpga))
ret = E.EFW17001
self.get_firmware_dict[fpga] = " "
else:
self.get_firmware_dict[fpga] = str(log).strip()
return ret
‘NoneType’ object has no attribute ‘name’ 最后没return ret
def stop_all(self, bdf_lst, bar, port, channel):
print(__file__, str(sys._getframe().f_lineno))
for bdf in bdf_lst:
for chn in range(channel):
status, out = self.stop(bdf, bar, port, chn)
if status != E.OK or out != "":
return E.EFAIL, ""
return E.OK, ""
self. 默认第一个参数有self
低配cpu内存条2666,高配3200
不是a的ascii码,9是9,10是a
top -d 1
status, out = run_command(“top -n 1 | grep ‘%Cpu(s)’ | awk {‘print $2’}”)
cpu_run_size_value = ceil(available_cpu_value * (cpu_run_size_percentage - float(out)) )
/lib/modules/4.19.0-12-2-amd64/extra/ 里面.so
root@localhost:/home/admin# blkid
/dev/sda1: SEC_TYPE="msdos" LABEL_FATBOOT="EFI System" LABEL="EFI System" UUID="7936-686F" TYPE="vfat" PARTLABEL="EFI System" PARTUUID="72960493-cc0f-4f8f-b1a0-4917834e7258"
/dev/sda2: LABEL="ONIE-BOOT" UUID="9891037b-e41f-44d3-b68d-234fa28df7bf" TYPE="ext4" PARTLABEL="ONIE-BOOT" PARTUUID="365ad13e-d2f4-405a-b949-589d21d5d0e2"
/dev/sda3: LABEL="SONiC-OS" UUID="2313e1ec-4052-467f-be4e-a3ea79cb4067" TYPE="ext4" PARTLABEL="SONiC-OS" PARTUUID="660e52b5-5830-42fe-a6aa-074588316e1a"
/dev/loop0: TYPE="squashfs"
/dev/sdb: PTUUID="39e44715-989f-41d2-8913-3d6af4d0b37b" PTTYPE="gpt"
/dev/loop1: UUID="a2b20d8b-2326-4533-92e9-9f08aeaadb89" TYPE="ext4"
/dev/sdc1: UUID="B0C7-B868" TYPE="vfat"
root@localhost:/home/admin#
root@localhost:/home/admin# fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition number (4-128, default 4):
First sector (67897344-937703054, default 67897344):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (67897344-937703054, default 937703054): +32G
Created a new partition 4 of type 'Linux filesystem' and of size 32 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
root@localhost:/home/admin# fdisk -l
Disk /dev/sda: 447.1 GiB, 480103981056 bytes, 937703088 sectors
Disk model: SSSTC ER2-GD480
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 39E44715-989F-41D2-8913-3D6AF4D0B37B
Device Start End Sectors Size Type
/dev/sda1 2048 526335 524288 256M EFI System
/dev/sda2 526336 788479 262144 128M ONIE boot
/dev/sda3 788480 67897343 67108864 32G Linux filesystem
/dev/sda4 67897344 135006207 67108864 32G Linux filesystem
The backup GPT table is corrupt, but the primary appears OK, so that will be used.
Disk /dev/sdb: 447.1 GiB, 480103981056 bytes, 937703088 sectors
Disk model: SAMSUNG MZNLH480
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 39E44715-989F-41D2-8913-3D6AF4D0B37B
Device Start End Sectors Size Type
/dev/sdb1 2048 526335 524288 256M EFI System
/dev/sdb2 526336 788479 262144 128M ONIE boot
/dev/sdb3 788480 67897343 67108864 32G Linux filesystem
Disk /dev/loop0: 550 MiB, 576761856 bytes, 1126488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdc: 57.3 GiB, 61530439680 bytes, 120176640 sectors
Disk model: SanDisk 3.2Gen1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdc1 32 120176639 120176608 57.3G c W95 FAT32 (LBA)
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
The backup GPT table is corrupt, but the primary appears OK, so that will be used.
^C^C^C^Z^Z^Z^C^C^C^Cq^C
^C^C^C^C^C
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.3
Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.
Warning! One or more CRCs don't match. You should repair the disk!
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: damaged
****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************
^C^C^C^C^C^C^A^Z^Z^Z^C^C^C^C^C^C^C^C^C^C
^C
^C
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin# mkf
mkfifo mkfs.bfs mkfs.ext2 mkfs.ext4 mkfs.minix
mkfs mkfs.cramfs mkfs.ext3 mkfs.jffs2 mkfs.ubifs
root@localhost:/home/admin# mkfs.ext4 /dev/sdb
mke2fs 1.44.5 (15-Dec-2018)
Found a gpt partition table in /dev/sdb
Proceed anyway? (y,N) y
^C^C^C^C^C^C^C
^C^C
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin# smartctl -a /dev/sdb
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.19.0-12-2-amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Device Model: SAMSUNG MZNLH480HBLR-00005
Serial Number: S5PLNA0RC16766
LU WWN Device Id: 5 002538 e01c2e8da
Firmware Version: HXTB204Q
User Capacity: 480,103,981,056 bytes [480 GB]
Sector Sizes: 512 bytes logical, 4096 bytes physical
Rotation Rate: Solid State Device
Form Factor: M.2
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: ACS-4 T13/BSR INCITS 529 revision 5
SATA Version is: SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Fri Jul 29 09:42:35 2022 UTC
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
General SMART Values:
Offline data collection status: (0x00) Offline data collection activity
was never started.
Auto Offline Data Collection: Disabled.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: ( 0) seconds.
Offline data collection
capabilities: (0x53) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
No Offline surface scan supported.
Self-test supported.
No Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( 2) minutes.
Extended self-test routine
recommended polling time: ( 35) minutes.
SCT capabilities: (0x003d) SCT Status supported.
SCT Error Recovery Control supported.
SCT Feature Control supported.
SCT Data Table supported.
SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 65
12 Power_Cycle_Count 0x0032 099 099 000 Old_age Always - 18
177 Wear_Leveling_Count 0x0013 100 100 005 Pre-fail Always - 0
179 Used_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 0
180 Unused_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 1022
181 Program_Fail_Cnt_Total 0x0032 100 100 010 Old_age Always - 0
182 Erase_Fail_Count_Total 0x0032 100 100 010 Old_age Always - 0
183 Runtime_Bad_Block 0x0013 100 100 010 Pre-fail Always - 0
184 End-to-End_Error 0x0033 100 100 097 Pre-fail Always - 0
187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0032 057 057 000 Old_age Always - 43
194 Temperature_Celsius 0x0022 057 057 000 Old_age Always - 43 (Min/Max 32/43)
195 Hardware_ECC_Recovered 0x001a 200 200 000 Old_age Always - 0
197 Current_Pending_Sector 0x0032 100 100 000 Old_age Always - 0
199 UDMA_CRC_Error_Count 0x003e 100 100 000 Old_age Always - 0
202 Unknown_SSD_Attribute 0x0033 100 100 010 Pre-fail Always - 0
235 Unknown_Attribute 0x0012 099 099 000 Old_age Always - 15
241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 937703088
242 Total_LBAs_Read 0x0032 099 099 000 Old_age Always - 156867
243 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0
244 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0
245 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 65535
246 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 65535
247 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 65535
251 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 937728000
SMART Error Log Version: 1
No Errors Logged
SMART Self-test log structure revision number 1
No self-tests have been logged. [To run self-tests, use: smartctl -t]
SMART Selective self-test log data structure revision number 1
SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
1 0 0 Not_testing
2 0 0 Not_testing
3 0 0 Not_testing
4 0 0 Not_testing
5 0 0 Not_testing
256 0 65535 Read_scanning was never started
Selective self-test flags (0x0):
After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.
root@localhost:/home/admin#
root@localhost:/home/admin#
root@localhost:/home/admin# dd if=/dev/null of=/dev/sdb bs=4M
0+0 records in
0+0 records out
0 bytes copied, 9.2422e-05 s, 0.0 kB/s
root@localhost:/home/admin# dd if=/dev/zero of=/dev/sdb bs=4M
dmidecode |grep -P -A5 “Memory\s+Device”|grep Size|grep -v Range
dmidecode -t bios
break不走else
cat /etc/ssh/sshd_config
systemctl status docker.service
git 提交出现dos格式的解决方法,关闭 git 的自动换行符转换。
git config --global core.autocrlf false
random_num = “{}”.format(hex(random.randint(268435456, 4294967295))) # 0x1000 0000到0xFFFF FFFF
/home_a/yutao/ocp_openbmc/build/kestrel/tmp/work-shared/kestrel/kernel-source/arch/arm/boot/dts/aspeed-bmc-huaqin-kestrel.dts
yutao@obmc-server:~/ocp_openbmc/build/kestrel/workspace/sources/linux-aspeed/arch/arm/boot/dts$ ls aspeed-bmc-huaqin-kestrel.dts
aspeed-bmc-huaqin-kestrel.dts
软件i2c从0开始,硬件i2c+1
断电重启 主,当前永远mtd4
https://cloud.tencent.com/developer/article/1720730
i2cdetect -l
j=69
for ((i=0; i<=j; i++))
do
echo
echo "bus $i:"
echo
i2cdetect -y "$i"
done
功耗超阈值
- EE确定阈值表没问题
- BSP结点无问题不超阈值
- sonic写的 fpga ram寄存器 与 bmc 读寄存器一致 且不超阈值
- sensors 模块中 节点 与 fpga驱动的该节点 一致 且超阈值
结论
驱动对结点拼凑有问题 导致数值异常
root@bmc-oob:~# cat /etc/issue
OpenBMC Release whitebox-209531722-dirty
$ test=(a b c d)
$ echo ${test[*]}
a b c d
$ echo ${test[0]}
a
$ echo $test
a
init单进程,systemd多进程
这样拷会少一个bit
root@bmc-oob:~# source /usr/local/bin/openbmc-utils.sh
root@bmc-oob:~# i2c_device_sysfs_abspath
/sys/bus/i2c/devices/
root@bmc-oob:~# i2c_device_sysfs_abspath 0-000d
/sys/bus/i2c/devices/0-000d
串口登不上,波特率 ctrl+c/x ctrl+urt 1
stty -F /dev/ttyS0 9600
dev_type=${1%[^a-zA-Z]}
dev_index=${1/*[a-zA-Z]/}
break和continue下面都不执行
if [ "x$dev_channel" != "x" ];then
case $dev_type in
"fb") # fb[1-4]
if [ "$dev_channel" -gt 4 ] || [ "$dev_channel" -lt 1 ];then
usage
fi
;;
"psu") # psu[1-2]
if [ "$dev_channel" -gt 2 ] || [ "$dev_channel" -lt 1 ];then
usage
fi
;;
*)
usage
;;
esac
else
case $dev_type in
"come"|"all")
;;
*)
usage
;;
esac
fi
continue从循环头开始,下一个
a(){
return 0
}
if a ; then
echo “123”
fi
$ ./a.sh
123
LC卡的LM75温度,ADC电压电流,DC/DC电压电流的传感器label
declare -i index=${1: -1}
echo $index
yutao@obmc-server:~/abak$ ./a.sh
0
yutao@obmc-server:~/abak$ ./a.sh lslslsls1
1
b()
{
v=1234
echo $v
}
a=$(b)
echo $a
yutao@obmc-server:~/abak$ ./a.sh
1234
修改冲突后覆盖
return是整型,超过255,减去255
https://blog.csdn.net/weixin_45309916/article/details/124117973?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166323255316800180683610%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166323255316800180683610&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_ecpm_v1~rank_v31_ecpm-1-124117973-null-null.nonecase&utm_term=mdio&spm=1018.2226.3001.4450
508 cp board-utils.sh test.sh
509 MACHINE=ttt
510 sed -i “s/PLATFORM/${MACHINE}/g;” test.sh
/dev/mtdblock3 to /mnt/data
10:06
. /usr/local/bin/openbmc-utils.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DEV=“/dev/mmcblk0”
MOUNT_POINT=“/var/log”
info=blkid $DEV
if [ ! “$info” ]; then
echo “Format EMMC disk …”
logger “Format EMMC disk …”
mkfs.ext4
D
E
V
e
c
h
o
"
D
o
n
e
"
e
c
h
o
"
M
o
u
t
i
n
g
E
M
M
C
.
.
.
.
.
.
"
i
f
[
!
−
d
"
DEV echo " Done" echo "Mouting EMMC ......" if [ ! -d "
DEVecho"Done"echo"MoutingEMMC......"if[!−d"MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
mount $DEV
M
O
U
N
T
P
O
I
N
T
e
c
h
o
"
D
o
n
e
"
e
l
s
e
e
c
h
o
"
M
o
u
t
i
n
g
E
M
M
C
.
.
.
.
.
.
"
i
f
[
!
−
d
"
MOUNT_POINT echo " Done" else echo "Mouting EMMC ......" if [ ! -d "
MOUNTPOINTecho"Done"elseecho"MoutingEMMC......"if[!−d"MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
#e2fsck -a $DEV
fsck.ext4 -a $DEV
mount $DEV
M
O
U
N
T
P
O
I
N
T
e
c
h
o
"
D
o
n
e
"
f
i
e
c
h
o
"
MOUNT_POINT echo " Done" fi echo "
MOUNTPOINTecho"Done"fiecho"DEV mounted successfully, device usage:"
df -h “$DEV”
exit 0
/home(内存 掉电失) /overlay/rw/home(mmc 掉电不易失) 都挂载到了/home下
root@bmc-oob:~# parameter_str=$(fruid-util | head -n 1 | awk -F “[” ‘{print $2}’)
root@bmc-oob:~# echo $parameter_str
all, bmc, cmm, fb1, fb2, psu1, psu2, psu3, psu4, lc1, lc2, lc3, lc4, lc5, lc6, lc7, lc8, come1, come2, come3, come4, come5, come6, come7, come8 ]
root@bmc-oob:~# parameter_r_arr=(${parameter_str//,/ })
root@bmc-oob:~# echo $parameter_r_arr
all
root@bmc-oob:~# echo ${parameter_r_arr[@]}
all bmc cmm fb1 fb2 psu1 psu2 psu3 psu4 lc1 lc2 lc3 lc4 lc5 lc6 lc7 lc8 come1 come2 come3 come4 come5 come6 come7 come8 ]
root@bmc-oob:~# echo ${parameter_r_arr[ -1]}
]
root@bmc-oob:~# unset “parameter_r_arr[-1]”
root@bmc-oob:~# echo ${parameter_r_arr[-1]}
come8
root@bmc-oob:~# unset “parameter_r_arr[-1]”
root@bmc-oob:~# echo ${parameter_r_arr[-1]}
come7
for((i=0;i<5;i++));
do
echo "1111111" $i
done
echo "22222" $i
# yutao@obmc-server:~/abak$ ./a.sh
# 1111111 0
# 1111111 1
# 1111111 2
# 1111111 3
# 1111111 4
# 22222 5
ls
echo $?
if ls ; then
echo "111"
fi
yutao@obmc-server:~/abak$ ./a.sh
a.sh come_cpld_auto_upgrade.sh notes.sh
0
a.sh come_cpld_auto_upgrade.sh notes.sh
111
hotswap是对上电后没设备的口进行监控
if [ ${psu_register_status[$i]} -eq 1 ];then # 上次不在
val=$(is_psu_ok $((i + 1))) #这次在
version_after=$(show_version lc$index | grep 'COME CPLD Version' | awk -F' ' '{print $7}')
version_before=$(echo $COME_CPLD_FW | cut -d_ -f 6)
version_before="v"$version_before
if [ "$version_after" == "$version_before" ];then
echo "$PROGRAM:" "come$index cpld upgrade success , failed times is "${come_upgrade_failed_counts[$index]}", limit is "$COME_UPGRADE_FAILED_COUNTS_LIMIT" "
come_upgrade_failed_counts[$index]=0
break
else
ipmb是个协议,驱动是slave-mqueue
compgen -u
if [ ! "$info" ]; then
echo "Format EMMC disk ......"
logger "Format EMMC disk ......"
mkfs.ext4 $DEV
echo " Done"
echo "Mouting EMMC ......"
if [ ! -d "$MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
mount $DEV $MOUNT_POINT
echo " Done"
else
echo "Mouting EMMC ......"
if [ ! -d "$MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
#e2fsck -a $DEV
fsck.ext4 -a $DEV
mount $DEV $MOUNT_POINT
echo " Done"
fi
echo "$DEV mounted successfully, device usage:"
df -h "$DEV"
exit 0
/home_a/yutao/ocp_openbmc-master/meta-phosphor/recipes-phosphor/sel-logger/phosphor-sel-logger_git.bb
cpu有24核,20%即5个核用来跑主diag程序,80%即19个核用来跑cpu和memory压测,19个核中60%跑cpu压测,40%跑内存压测。
改冲突 ctrl+s覆盖
cp /home/root/a.sh /home/root/a/a.sh 可执行成功
覆盖
echo 值 进不存在的文件 , 报错 程序也往下走
hexdump -n 12 /sys/bus/spi/devices/spi2.1/eeprom
shell 中 -r检查它后面的参数是否是文件、是否存在以及是否可读。
cp /home/root/a.sh /home/root/a/a.sh 可执行成功,覆盖
echo 值 进不存在的文件 , 报错 程序也往下走
a=2710
# b=`echo "scale=2; $a/1000" | bc`
# echo $b
b=$(awk 'BEGIN{printf "%.2f\n",'$a'/1000}')
echo $b
左移再右移动作用是将移动位数上清0
partprobe则可以使kernel重新读取分区 信息,从而避免重启系统
umount_dev() {
pids=$(fuser -m $PART2_MOUNT_POINT)
nums=$(echo $pids | awk -F ' ' '{print NF}')
for((i=1;i<=$nums;i++));
do
pid=$(echo $pids | awk -F ' ' '{print $'$i'}')
kill -9 "$pid"
done
umount $PART2 || (echo "umount $PART2 fail !" && exit 1)
}
static inline __s32 i2c_smbus_block_process_call(int file, __u8 command,
__u8 length, __u8 *values)
{
union i2c_smbus_data data;
if (length > 32)
length = 32;
memcpy(&data.block[1], values, length);
data.block[0] = length;
if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_BLOCK_PROC_CALL,&data))
return -1;
else {
memcpy(values, &data.block[1], _I2C_MIN(data.block[0], I2C_SMBUS_BLOCK_MAX));
return data.block[0];
}
}
/home_a/yutao/openbmc-huaqin/common/recipes-lib/obmc-i2c/files/smbus.h
format_fs_1() {
mkfs.ext4 $PART1 << EOF
y
EOF
}
partition_rm_1() {
fdisk $DEV << EOF
d
1
w
EOF
}
format_fs_2() {
mkfs.ext4 $PART2 << EOF
y
EOF
}
partition_rm_2() {
fdisk $DEV << EOF
d
2
w
EOF
}
mount_partition() {
info=$(blkid "$1" |grep ext4 )
if [ ! "$info" ]; then
echo "Format $1 partition ......"
logger -t "mount_data1.sh" "Format $1 partition ......"
mkfs.ext4 "$1"
echo " Done"
echo "Mouting $1 partition ......"
if [ ! -d "$2" ]; then
mkdir -p "$2"
fi
mount "$1" "$2"
echo " Done"
else
echo "Mouting $1 partition ......"
if [ ! -d "$2" ]; then
mkdir -p "$2"
fi
#e2fsck -a $DEV
fsck.ext4 -a "$1"
mount "$1" "$2"
echo " Done"
fi
}
DEV="/dev/mmcblk0"
MOUNT_POINT="/var/log"
info=`blkid $DEV`
if [ ! "$info" ]; then
echo "Format EMMC disk ......"
logger "Format EMMC disk ......"
mkfs.ext4 $DEV
echo " Done"
echo "Mouting EMMC ......"
if [ ! -d "$MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
mount $DEV $MOUNT_POINT
echo " Done"
else
echo "Mouting EMMC ......"
if [ ! -d "$MOUNT_POINT" ]; then
mkdir $MOUNT_POINT
fi
#e2fsck -a $DEV
fsck.ext4 -a $DEV
mount $DEV $MOUNT_POINT
echo " Done"
fi
echo "$DEV mounted successfully, device usage:"
df -h "$DEV"
exit 0
第一个问题umount可以,但是mkfs格式化不了
scp -r yutao@10.75.135.33:/home_a/yutao/alibmc/build/tmp/work/obmc_hq-fb-linux-gnueabi/obmc-hq-image/1.0-r0/rootfs/lib/modules/4.1.51/extra/psu_driver.ko ~/
value = psu_reg_read(dev, attr); value十进制
def d():
fru = {}
fru["d"] = {"a":"c"}
return fru
def Main():
# crt.Screen.Synchronous = True
# for i in range (0,2):
# Checkinfo1()
fru = {}
fru["Name"] = "psu_name"
fru["a"] = {"d":{"a":"c"}}
print(fru)
Main()
from hal.hal_sensor import *
sensor=HalSensor()
from hal.hal_dcdc import *
a=HalDcdc(sensor)
root@bmc:/sys/bus/i2c/devices/i2c-0# echo 0x0 > delete_device
-bash: echo: write error: No such file or directory
root@bmc:/sys/bus/i2c/devices/i2c-0# echo 0xd > delete_device
root@bmc:/sys/bus/i2c/devices/i2c-0#
root@bmc:/sys/bus/i2c/devices/i2c-0# rmmod basecpld
root@bmc:/sys/bus/i2c/devices/i2c-0# insmod ~/basecpld.ko
root@bmc:/sys/bus/i2c/devices/i2c-0# echo basecpld 0xd > new_device
root@bmc:/sys/bus/i2c/devices/i2c-0#
# config_baudrate
URART5_LCR_ADRR=0x1e78400c
URART5_DLH_ADRR=0x1e784004
DLH_value_115200=0x0 #低位已置过
DLH_value_9600=0x0
URART5_DLL_ADRR=0x1e784000
DLL_value_115200=0x0000000D # 波特率分频值=24000000(24M)/16/115200 = 13 (十进制), D (十六进制)
DLL_value_9600=0x0000009C # 波特率分频值=24000000(24M)/16/9600 = 156 (十进制), 9C (十六进制)
get_baud_rate_by_reg() {
lcr_value_r=$(devmem $URART5_LCR_ADRR | sed -n '1p') # 0x00000013 第7bit为0
lcr_value_w=$((lcr_value_r | 0x80)) # 第8位即第7bit置1, 有1为1 # 147 # DLAB置1
devmem $URART5_LCR_ADRR 32 $lcr_value_w # 0x00000093(147)
dll_value_r=$(devmem $URART5_DLL_ADRR | sed -n '1p') #读出DLL值后下行DLAB置为默认值
devmem $URART5_LCR_ADRR 32 "$lcr_value_r"
if [ "$dll_value_r" == "$DLL_value_115200" ]; then
echo "115200"
elif [ "$dll_value_r" == "$DLL_value_9600" ]; then
echo "9600"
fi
lcr_value_w=$((lcr_value_r & 0xFFFFFF7F)) # 第8位即第7bit置0,有0为0 ,保险操作
devmem $URART5_LCR_ADRR 32 $lcr_value_w
}
set_baud_rate_by_reg() {
lcr_value_r=$(devmem $URART5_LCR_ADRR | sed -n '1p')
lcr_value_w=$((lcr_value_r | 0x80))
devmem $URART5_LCR_ADRR 32 $lcr_value_w
case ${1} in
"115200")
devmem $URART5_DLH_ADRR 32 $DLH_value_115200
devmem $URART5_DLL_ADRR 32 $DLL_value_115200
;;
"9600")
devmem $URART5_DLH_ADRR 32 $DLH_value_9600
devmem $URART5_DLL_ADRR 32 $DLL_value_9600
;;
*)
usage
;;
esac
lcr_value_w=$((lcr_value_r & 0xFFFFFF7F))
devmem $URART5_LCR_ADRR 32 "$lcr_value_w"
echo "Set UART baudrate $1 succeed"
}
prog=$(basename "$0")
usage() {
echo "Usage: ${prog} -b <Baudrate>"
echo
echo "Note:"
echo " Do not operate UART until script execution complete"
echo
echo "Baudrate:"
echo " 115200/9600"
echo
echo "Examples:"
echo " $prog -b 115200"
echo
exit 1
}
check_parameter() {
#Handle specific condition for on input parameter
if [ "$#" -eq 0 ]; then
usage
fi
ARGS=$(getopt -o hb: -n "${prog}" -- "$@")
[ $? -ne 0 ] && exit 1
eval set -- "${ARGS}"
while true; do
case "$1" in
-b)
baud_rate_set="$2"
if [ "$baud_rate_set" != 115200 ] && [ "$baud_rate_set" != 9600 ]; then
usage
fi
shift 2
;;
-h)
usage
;;
--)
shift
break
;;
*)
usage
;;
esac
done
if [ -z "$baud_rate_set" ]; then
usage
fi
}
do_action() {
baud_rate_now=$(get_baud_rate_by_reg)
if [ "$baud_rate_now" == "$baud_rate_set" ]; then
echo "UART baudrate is $baud_rate_now,no need to set it"
exit 1
fi
set_baud_rate_by_reg "$baud_rate_set"
}
check_parameter "$@"
do_action
root@bmc-oob:~# stty -F /dev/ttyS0
root@bmc-oob:~# stty -F /dev/ttyS0 9600
cat /proc/cpuinfo | grep "cpu cores" | uniq | awk -F ":" '{print $2}' | awk '{gsub(/^\s + |\s +$/,"");print}'
开机启动不外乎这两种方法,我推荐第一种update-rc.d管理
rc.local
sed -i ‘s/sys_led/sys_url/g’ /home/yutao/sysfs1/s3ip_sysfs_frame/sysurl_sysfs.c
char * chip_select_read(reg_t reg)
{
char result[128];
switch((dev_attr->ida_reg))
{
case 0xFF:
result = "fru.board.part";
break;
case 0xFE:
result = "fru.board.mfg";
break;
case 0xFD:
result = "fru.board.serial";
break;
case 0xFC:
result = "fru.board.custom1";
break;
default:
break;
}
return result;
}
if(dev_attr->ida_reg == 0x32 | 0x42 | 0x52 | 0x62 | 0x72 | 0x36 | 0x46 | 0x56 | 0x66 | 0x76 | 0x34 | 0x44 | 0x54 | 0x64 | 0x74 )
int motor_number;
static ssize_t motor_number_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
if(motor_number[0] == 0)
return scnprintf(buf, PAGE_SIZE,"NA\n");
return scnprintf(buf, PAGE_SIZE,"%s", motor_number);
}
static ssize_t motor_number_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
return scnprintf(motor_number, PAGE_SIZE,"%s",buf);
}
char fan_number[PAGE_SIZE];
static ssize_t fan_number_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
if(fan_number[0] == 0)
return scnprintf(buf, PAGE_SIZE,"NA\n");
return scnprintf(buf, PAGE_SIZE,"%s", fan_number);
}
static ssize_t fan_number_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
return scnprintf(fan_number, PAGE_SIZE,"%s",buf);
}
a=$(find /sys/bus/i2c/devices/24-002b/hwmon -name "hwmon*" | tail -n 1)
echo $a
if [ -f /sys/bus/i2c/devices/48-0058/mfr_id ];then ln -snf /sys/bus/i2c/devices/48-0058/mfr_id /sys_switch/psu/psu1/model_name;fi
root@bmc-oob:/sys/bus/i2c/devices/0-000d# cat psu_1_present
0x0
Note:
0:Absent, 1:Present
oot@bmc-oob:/sys/bus/i2c/devices/5-000d# cat fan3_ledstatus
please echo
6: yellow light flashing
5: green light flashing
2: yellow
1: green
0: dark
static ssize_t chip_led_show(struct device *dev,struct device_attribute *attr,char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
i2c_dev_data_st *data = i2c_get_clientdata(client);
i2c_sysfs_attr_st *i2c_attr = TO_I2C_SYSFS_ATTR(attr);
const i2c_dev_attr_st *dev_attr = i2c_attr->isa_i2c_attr;
int value = -1;
value = i2c_smbus_read_byte_data(client,(dev_attr->ida_reg));
if (value == 0x41)
return scnprintf(buf, PAGE_SIZE, "0\n");
else if (value == 0x44)
return scnprintf(buf, PAGE_SIZE, "1\n");
else if (value == 0x54)
return scnprintf(buf, PAGE_SIZE, "2\n");
else if (value == 0x46)
return scnprintf(buf, PAGE_SIZE, "5\n");
else if (value == 0x56)
return scnprintf(buf, PAGE_SIZE, "6\n");
else
return scnprintf(buf, PAGE_SIZE, "please echo:\n6: yellow light flashing\n5: green light flashing\n2: yellow\n1: green\n0: dark\n");
}
static ssize_t chip_led_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
i2c_dev_data_st *data = i2c_get_clientdata(client);
i2c_sysfs_attr_st *i2c_attr = TO_I2C_SYSFS_ATTR(attr);
const i2c_dev_attr_st *dev_attr = i2c_attr->isa_i2c_attr;
int rc = 0, write_value = 0;
if (buf == NULL) {
return -ENXIO;
}
rc = kstrtoint(buf, 10, &write_value);
if (rc != 0) {
return count;
}
switch(write_value)
{
case 0:
rc = i2c_smbus_write_byte_data(client, (dev_attr->ida_reg), 0x41);
if (rc != 0) {
return count;
}
break;
case 1:
rc = i2c_smbus_write_byte_data(client, (dev_attr->ida_reg), 0x44);
if (rc != 0) {
return count;
}
break;
case 2:
rc = i2c_smbus_write_byte_data(client, (dev_attr->ida_reg), 0x54);
if (rc != 0) {
return count;
}
break;
case 5:
rc = i2c_smbus_write_byte_data(client, (dev_attr->ida_reg), 0x46);
if (rc != 0) {
return count;
}
break;
case 6:
rc = i2c_smbus_write_byte_data(client, (dev_attr->ida_reg), 0x56);
if (rc != 0) {
return count;
}
break;
default:
break;
}
return count;
}
/usr/local/bin/set_fan_speed.sh 30 2
if [ $present -eq 1 ]; then # Present and Alive
echo "1"
elif [ $present -eq 2 ]; then
echo "2"
else
echo "0"
mfr 厂商
root@bmc-oob:/tmp# cat PowerMonResult
Result : BAD
Color : YELLOW
Reason :
(1).PSU 1 Power Bad
root@bmc-oob:/tmp# get_psu_present 1
1
root@bmc-oob:/tmp# get_psu_power_sta 1
1
root@bmc-oob:/tmp# get_psu_power_sta 2
0
mtd4当前
>>> from hal.hal_fan import *
>>> a=HalFan()
>>> a.get_total_number()
5
>>> a.get_rotor_number("fan2")
2
>>> a.get_rotor_number("fan5")
2
>>> a.get_speed("fan1",1)
11550
>>> a.get_speed("fan1",2)
10950
root@bmc-oob:/sys_switch/fan/fan1/motor1# cat ratio
50
>>> a.get_speed_pwm("fan1",1)
5
>>> a.set_speed_pwm("fan1",50,1)
0
>>> a.get_watchdog_status()
'Abnormal'
root@bmc-oob:/sys_switch/fan/fan1/motor1# cat direction
0x0
Note:
0: F2B 1: B2F
>>> a.get_airflow("fan1")
'F2B'
>>> a.get_fru_info("fan1")
{'Name': 'fan1', 'SN': '7NDRA290004', 'PN': 'SH1UDRA290004', 'ModelId': 'HUAQIN', 'HV': 'NA', 'Rotors': 2, 'AirFlow': 'F2B'}
>>> a.get_fan_speed_threshold("fan1",1)
{'SpeedMin': 1000, 'SpeedMax': 23000}
>>> a.set_speed_pwm("fan1",80,1)
0
>>> a.get_speed_pwm("fan1",1)
80
>>> a.get_status("fan1")
{'Rotor1': {'status': 'yes', 'HwAlarm': 'no', 'Speed': 18750}, 'Rotor2': {'status': 'yes', 'HwAlarm': 'no', 'Speed': 11100}}
>>> a.get_fan_info("fan1")
{'Name': 'fan1', 'SN': '7NDRA290004', 'PN': 'SH1UDRA290004', 'ModelId': 'HUAQIN', 'HV': 'NA', 'Rotors': 2, 'AirFlow': 'F2B', 'Present': 'yes', 'Rotor1': {'SpeedMin': 1000, 'SpeedMax': 23000, 'status': 'yes', 'HwAlarm': 'no', 'Speed': 18750}, 'Rotor2': {'SpeedMin': 1000, 'SpeedMax': 19000, 'status': 'yes', 'HwAlarm': 'no', 'Speed': 10950}}
>>> a.get_speed("FAN1")
{'motor1': 11550, 'motor2': 11100}
>>> a.get_speed_pwm("FAN1")
50
>>> a.set_speed_pwm("FAN1",60)
0
>>> a.get_speed_pwm("FAN1")
60
>>> a.get_fan_info("FAN1")
{'Name': 'FAN1', 'SN': '7NDRA290004', 'PN': 'SH1UDRA290004', 'ModelId': 'HUAQIN', 'HV': 'NA', 'Rotors': 2, 'AirFlow': 'F2B', 'Present': 'yes', 'Rotor1': {'SpeedMin': 2350, 'SpeedMax': 22500, 'status': 'yes', 'HwAlarm': 'no', 'Speed': 22050}, 'Rotor2': {'SpeedMin': 2200, 'SpeedMax': 19500, 'status': 'yes', 'HwAlarm': 'no', 'Speed': 18450}}
>>> a.get_total_number()
5
>>> a.get_rotor_number("FAN2")
2
>>> a.get_rotor_number("FAN1")
2
>>> a.get_speed("FAN1",2)
18600
>>> a.get_speed("FAN1",1)
22050
>>> a.set_speed_pwm("FAN2",60)
0
>>> a.get_watchdog_status()
'Normal'
>>> a.enable_watchdog(0)
0
>>> a.get_watchdog_status()
'Abnormal'
>>> a.set_led("FAN1","green")
0
>>> a.set_led("FAN1","yellow")
0
>>> a.get_presence("FAN1")
1
>>> a.get_presence("FAN2")
1
>>> a.get_presence("FAN6")
-1
# if [[ ! "${#ValidPara[@]}" =~ "${1}" ]]; then
check_index_valid()
{
#$1 is index,$2 is max number
#return -1 for invalid
ValidPara=($(seq 1 "$2"))
# if [[ ! "${ValidPara[@]}" =~ "${1}" ]]; then
if [[ "${1}" > "${#ValidPara[@]}" ]]; then
echo "-1"
else
echo "0"
fi
}
NUM_MAX=$(get_fan_num)
# valid=$(check_index_valid "$1" "$NUM_MAX")
RecordEventLog(LOG_INFO,"-----------------111 %s--------------\n",node[i].path);
printf("path:%s, node:%s, addr:%s, name:%s, unit:%s, minvalue:%d, maxvalue:%d, ratio:%d\n", node[i].path, node[i].node, node[i].addr, node[i].name, node[i].unit, node[i].minvalue, node[i].maxvalue , node[i].ratio);
printf("%s\n",fullpath);
// printf("%s\n",fullpath);
// printf("path:%s, node:%s, addr:%s, name:%s, unit:%s, minvalue:%d, maxvalue:%d, ratio:%lf\n", node[i].path, node[i].node, node[i].addr, node[i].name, node[i].unit, node[i].minvalue, node[i].maxvalue , node[i].ratio);
rm build/ -rf
md5sum tmp/work/s3ip-fb-linux-gnueabi/s3ip-image/1.0-r0/rootfs/usr/local/bin/sensor-mon
printk(KERN_INFO “----------------------------high addr:%.2x”,dev_attr->ida_reg+1);
>>> from hal.hal_bmc import *
>>> a=HalBmc()
>>> a.get_bmc_version_all()
{'MasterVersion': 'hollywood-927da1cda5-dirty-old', 'SlaveVersion': 'xs9880-8c-1050cea15e-dirty'}
>>> a.get_bmc_version()
'hollywood-927da1cda5-dirty-old'
>>> a.get_bmc_version("current")
'xs9880-8c-1050cea15e-dirty
# install -m 755 sysfs-link.py ${D}${sysconfdir}/init.d/sysfs-link.py
# update-rc.d -r ${D} sysfs-link.py start 62 S .
ls /etc/init.d/sys*
&(node[i].switch_temp[0]))
(node+sizeof(board_node_t)*i)->inlet_temp).value_path
段错误json文件
root@bmc-oob:~/fan# ./fan-ctrl
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc1_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc2_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp20_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp6_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp6_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp21_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc3_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc4_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc5_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc6_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc7_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
qsfp_cnt 1
check_prst 1
prst_path /sys/bus/i2c/devices/i2c-82/82-000d/lc8_present
switch_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp10_input
cpu_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
inlet_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp7_input
qsfp_temp /sys/bus/i2c/devices/i2c-19/19-000d/temp11_input
// int j;
// for(j=0;j<BoardCnt;j++)
// {
// printf("qsfp_cnt %d\n",board_node[j].qsfp_cnt);
// printf("check_prst %d\n",board_node[j].check_prst);
// printf("prst_path %s\n",board_node[j].prst_path);
// printf("switch_temp %s\n",board_node[j].switch_temp[0].value_path);
// printf("cpu_temp %s\n",board_node[j].cpu_temp[0].value_path);
// printf("inlet_temp %s\n",board_node[j].inlet_temp.value_path);
// printf("qsfp_temp %s\n",board_node[j].qsfp_temp[0].value_path);
// // printf("cpu ki------------%lf\n",pwm_node[j].cpu[0].Ki);
// // printf("check_prst %d\n",pwm_node[j].cpu.Ki);
// // printf("prst_path %s\n",pwm_node[j].cpu.Kd);
// // printf("switch_temp %s\n",pwm_node[j].inlet.Kp);
// // printf("cpu_temp %s\n",pwm_node[j].inlet.Ki);
// // printf("inlet_temp %s\n",pwm_node[j].inlet.Kd);
// // printf("qsfp_temp %s\n",pwm_node[j].switchchip.Kp);
// // printf("qsfp_temp %s\n",pwm_node[j].switchchip.Ki);
// // printf("qsfp_temp %s\n",pwm_node[j].switchchip.Kd);
// }
rc = FillTempStructure((const char*)content,&board_node);
rc = FillPWMStructure((const char*)content,&pwm_node);
// char *content=NULL; //file centent
// fan_status_t * fan_node = NULL;
// board_node_t * board_node = NULL;
// pwm_alg_t * pwm_node = NULL;
// rc |= GetObjectIntValue(json_board,CONFIG_FSC_QSFP_NUMBER_KEY,&node[i].qsfp_cnt); //QSFPNumber
// rc |= GetObjectBoolValue(json_board,CONFIG_FSC_CHECK_PRESENCE_KEY,&node[i].check_prst); //CheckPresence
// rc |= GetObjectStrValue(json_board,CONFIG_FSC_PRESENT_KEY,node[i].prst_path); //Present
// rc |= GetObjectStrValue(json_board,CONFIG_FSC_SWITCH_TEMP_KEY,node[i].switch_temp[0].value_path); //Switch1
// rc |= GetObjectStrValue(json_board,CONFIG_FSC_CPU_TEMP_KEY,node[i].cpu_temp[0].value_path); //CPU1
// rc |= GetObjectStrValue(json_board,CONFIG_FSC_INLET_TEMP_KEY,node[i].inlet_temp.value_path); //Inlet
// rc |= GetObjectStrValue(json_board,CONFIG_FSC_QSFP_KEY,node[i].qsfp_temp[0].value_path); //QSFP1
#if 0
int i,k,q;
for(i=0;i<FanCnt;i++)
{
q=GetFanPresence(&fan_node[i]);
printf("%d",q);
printf("fan name %s\n",fan_node[i].fan_name);
printf("motor number %d\n",fan_node[i].motor_cnt);
printf("present path %s\n",fan_node[i].prst_path);
printf("ratio path %s\n",fan_node[i].ratio_path);
printf("airflow path %s\n",fan_node[i].airflow_path);
for(k=0;k<fan_node[i].motor_cnt;k++)
{
printf("speed path %s\n",fan_node[i].motor[k].speed_path);
printf("speed max path %s\n",fan_node[i].motor[k].max_speed_path);
printf("speed min path %s\n",fan_node[i].motor[k].min_speed_path);
}
}
for (i=0;i<BoardCnt;i++)
{
printf("board name %s\n",board_node[i].board_name);
printf("cpu number %d\n",CpuCnt[i]);
printf("switch number %d\n",SwitchCnt[i]);
printf("need check %d\n",board_node[i].check_prst);
printf("cpu path 1 %s\n",board_node[i].cpu_temp[0].value_path);
printf("cpu path 2 %s\n",board_node[i].cpu_temp[1].value_path);
printf("inlet path %s\n",board_node[i].inlet_temp.value_path);
}
#endif
rc |= GetObjectDoubleValue(json_cpu,CONFIG_FSC_DIFFERENTIAL_KEY,(double *)&node[0].cpu[cpu_index].Kd);
#if 1
int rc=0;
char *content=NULL;
fan_status_t * fan_node = NULL;
rc = FillFanStructure((const char*)content,&fan_node);
free(content);
int i;
for (i=0;i<FanCnt;i++)
{
int ret;
ret=GetFanPresence(fan_node);
printf("------------------------ret %d---",ret);
// printf("------------------------ret %d---",ret);
// printf("fan name %s\n",fan_node[i].fan_name);
// printf("motor number %d\n",fan_node[i].motor_cnt);
// printf("present path %s\n",fan_node[i].prst_path);
// printf("ratio path %s\n",fan_node[i].ratio_path);
// printf("airflow path %s\n",fan_node[i].airflow_path);
// for(k=0;k<fan_node[i].motor_cnt;k++)
// {
// printf("speed path %s\n",fan_node[i].motor[k].speed_path);
// printf("speed max path %s\n",fan_node[i].motor[k].max_speed_path);
// printf("speed min path %s\n",fan_node[i].motor[k].min_speed_path);
// }
}
#endif
printf("------312412412412412434343434------");
printf("------ggggggggggggg %d----",i);
// printf("------fffffffffff %d------",FanCnt);
// for (i=0;i<FanCnt;i++)
// {
// printf("------555555555555555555-");
// int ret;
// ret=GetFanPresence(&fan_node[i]);
// printf("-------ret %d---",ret);
// }
宏加双引号,*json_psu和不加* ,传入函数
pi@raspberrypi-1:~ $ arm-linux-gnueabihf-gcc -o a a.c
pi@raspberrypi-1:~ $ ./a
段错误
/sys/bus/i2c/devices/44-000d/fan1_input(motor1) fan10_input(motor1)
printf(“array---- %d\n”,*(array+k));
printf(“speed_path— %s\n”,(fan_node->motor+k)->speed_path);
//int GetFanSpeed(motor_status_t * speed);
for (i=0;i<BoardCnt;i++)
{
printf("------------pwm_node[%d]-------------\n",i);
for (k=0;k<CpuCnt[i];k++)
{
printf("pwm_cpu_Kp %f\n",pwm_node[i].cpu[k].Kp);
printf("pwm_cpu_Ki %f\n",pwm_node[i].cpu[k].Ki);
printf("pwm_cpu_Kd %f\n",pwm_node[i].cpu[k].Kd);
printf("pwm_cpu_Kd %f\n",pwm_node[i].cpu[k].min_alarm);
printf("pwm_cpu_Kd %d\n",pwm_node[i].cpu[k].min_pwm);
printf("pwm_cpu_Kd %f\n",pwm_node[i].cpu[k].last_temp_2);
}
for (k=0;k<SwitchCnt[i];k++)
{
printf("pwm_switch_Kp %f\n",pwm_node[i].switchchip[k].Kp);
printf("pwm_switch_Ki %f\n",pwm_node[i].switchchip[k].Ki);
printf("pwm_switch_Kd %f\n",pwm_node[i].switchchip[k].Kd);
printf("pwm_switch_Kd %f\n",pwm_node[i].switchchip[k].max_alarm);
printf("pwm_switch_Kd %f\n",pwm_node[i].switchchip[k].fatal_alarm);
printf("pwm_switch_Kd %d\n",pwm_node[i].switchchip[k].last_pwm);
}
}
/build/tmp/work/xs9880_8c-fb-linux-gnueabi/xs9880-8c-image/1.0-r0/rootfs/etc/platform/xs9880-8c$
./fan-ctrl -l 9
printf("%s",str); // %s 0x7f
// sprintf(ret, "%s", str);
// ret=(int)str; // ascii
// ret = atoi(str); //0
sscanf(str,"%x", &ret);
printf("111111111111111111111111%d\n",ret); //127
/*
* Set Fan Speed for specified fan motor
* Use RPM as unit
* Return 0 or -1
*
*/
// int SetFanMotorSpeed(fan_status_t * fan_node,int speed, int motor_index)
// {
// int ret = 0;
// char str[MAX_READ_LEN];
// if(motor_index > fan_node->motor_cnt || motor_index < fan_node->motor_cnt)
// return -1;
// FILE * fp=NULL;
// if ((fp = fopen((fan_node->motor+motor_index)->speed_path,"r")) == NULL)
// {
// RecordEventLog(LOG_ERR,DebugLevel,"%s %s %d:Query Fan speed failed (%s)\n",__FILE__,__func__,__LINE__,(fan_node->motor+motor_index)->speed_path);
// fclose(fp);
// return -1;
// }
// sprintf(str, "%d", speed);
// ret = fwrite(str, sizeof(str) , 1, fp);
// if(ret==1){
// fflush(fp);
// ret = 0;
// }else{
// ret = -1;
// }
// fclose(fp);
// return ret;
// }
// for (i=0;i<FanCnt;i++)
// {
// for(k=0;k<fan_node[i].motor_cnt;k++)
// {
// int ret;
// ret=SetFanMotorSpeed(&fan_node[i],5000,k);
// printf("SetFanMotorSpeed ret: %d\n",ret);
// GetFanSpeed(&fan_node[i],&speed_array);
// printf("fan%d motor%d set and get speed: %d\n",i+1,k+1,speed_array[k]);
// }
// }
打印0是指针地址 &
rc |= GetObjectStrValue(json_board,CONFIG_FSC_INLET_TEMP_KEY,node[i].inlet_temp.value_path);
// max_value = max_value > *speed ? max_value : *speed;
int i,
short max_value=0;
GetFanPwm(fan_node,pwm_out);
for (i=0;i<FanCnt;i++)
{
max_value = max(max_value,*pwm_out);
}
expected identifier or ‘(’ before ‘short’ 上面一行是,号,应该为;号
| fan-status.c:245:1: error: control reaches end of non-void function [-Werror=return-type]
| 245 | } return出错
/home_a/yutao/hq/openbmc-hollywood/meta-huaqin/meta-xs9880-8c/recipes-plats/lm_sensors/files/xs9880-8c.conf
// printf(“set %s and get single pwmspeed: %d\n”,fan_node[1].ratio_path,ret);
printf(“----snprintf-----%s-----\n”,str);
fan-status.c:245:1: error: control reaches end of non-void function [-Werror=return-type]
| 245 | } 错误:控制到达非void函数的末尾 : 没写return
insmod 出现invalid paraterm 应加载全部ko文件
sv restart rsyslogd
// for (i=0;i<g_temp_recover_time;i++)
// {
// if (temp <= ((pwm_node->cpu.min_alarm) -1) ) //50.00-1
// {
// CalculatePWM(&pwm_node->cpu,temp,cur_pwm, &pwm_cpu);
// printf(" pwm_cpu is %d\n",pwm_cpu);
// }
// sleep(1);
// }
printf(" temp is %.2f\n",temp); //46.00
#if 0
rc = OpenCjsonFile(&content);
if(rc<0)
goto err;
rc = FillFanStructure((const char*)content,&fan_node);
free(content);
#endif
printf("prnt_status:%d\n",prnt_status);
printf("last_prnt_before:%d\n",psu_node[i].last_prnt);
implicit declaration of function,去掉static,并在.h中声明
// printf("g_fsc_period %d\n",g_fsc_period); //15
// printf("g_temp_fail_time %d\n",g_temp_fail_time); //300
// printf("g_cpu_cnt %d\n",g_cpu_cnt[1]); //2 //1,3,5线卡不在位
// printf(" %d GetCpuTemp_rc : %d\n",i,rc);
// printf(" %d GetCpuTemp_temp : %d\n",i,temp);
ps | grep -v grep | grep '/usr/local/bin/mTerm_client xs9880-8c' -m 1| |awk '{print $1}'
if( (g_last_temp_status >= CPU_MIN_ALARM) && (rc == NO_ERROR) )
{ //15 20
if ( g_temp_recover_cnt*g_fsc_period < g_temp_recover_time )
{
if( g_temp_recover_cnt < MAX_FAIL_COUNT )
g_temp_recover_cnt++; // 0 ,1 ,2
rc = g_last_temp_status; //8
printf(" rc1 is %d\n",rc);
}
else
{
g_last_temp_status=rc;
g_temp_recover_cnt=0;
}
}
else
{
g_last_temp_status=rc;
g_temp_recover_cnt=0;
}
printf("------------------------------------\n");
printf(" last_temp:%f\n",pwm_node->cpu.last_temp);
printf(" cur_pwm is %d\n",cur_pwm); //50
printf(" pwm_cpu_before is %d\n",pwm_cpu);
printf(" pwm_cpu_after is %d\n",pwm_cpu);
fp=fopen("/tmp/fsc.json","rb");
// pwm_node->cpu.last_temp = 0;
root@bmc-oob:~# echo 59000 > /var/log/temp71_input
root@bmc-oob:~# ./fan-ctrl
33333333333333333
33333333333333333
33333333333333333
^C
root@bmc-oob:~# echo 39000 > /var/log/temp71_input
root@bmc-oob:~# ./fan-ctrl
33333333333333333
rc is 0
temp is 47.00
pwm_cpu is 99
33333333333333333
rc is 0
temp is 47.00
pwm_cpu is 98
root@bmc-oob:~# ./fan-ctrl
eeeeeeeeeeeee_g_last_temp_status:0
rc is 0
temp is 46.00
pwm_cpu is 99
^C
root@bmc-oob:~# echo 59000 > /var/log/temp71_input
root@bmc-oob:~# ./fan-ctrl
eeeeeeeeeeeee_g_last_temp_status:0
eeeeeeeeeeeee_g_last_temp_status:7
eeeeeeeeeeeee_g_last_temp_status:7
root@bmc-oob:~# ./fan-ctrl
before_g_last_temp_status:0
d_g_last_temp_status:0
rc is 0
temp is 49.00
pwm_cpu is 99
before_g_last_temp_status:0
d_g_last_temp_status:0
rc is 0
temp is 49.00
pwm_cpu is 98
^C
root@bmc-oob:~# echo 59000 > /var/log/temp71_input
root@bmc-oob:~# ./fan-ctrl
before_g_last_temp_status:0
d_g_last_temp_status:7
before_g_last_temp_status:7
d_g_last_temp_status:7
before_g_last_temp_status:7
d_g_last_temp_status:7
^C
root@bmc-oob:~# echo 39000 > /var/log/temp71_input
root@bmc-oob:~# ./fan-ctrl
before_g_last_temp_status:0
d_g_last_temp_status:0
rc is 0
temp is 49.00
pwm_cpu is 99
// 上次不正常,这次正常,30s持续满转 后才自适应
if( (g_last_temp_status >= CPU_MIN_ALARM) && (rc == NO_ERROR) )
{
if ( g_temp_recover_cnt*g_fsc_period < g_temp_recover_time )
{
if( g_temp_recover_cnt < MAX_FAIL_COUNT )
g_temp_recover_cnt++;
rc = g_last_temp_status; // 【上次不正常,这次正常】cnt=1(rc=7不正常满转) , 15秒后【上次不正常,这次正常】cnt=2(rc=7不正常满转)
// if (temp <= ((pwm_node->cpu.min_alarm) -1) ) //50.00-1
// {
// g_last_temp_status=rc;
// g_temp_recover_cnt=0;
// }
}
else
{
g_last_temp_status=rc; // 15秒后【上次不正常,这次正常】cnt=3(rc=0正常自适应),走printf(" rc is %d\n",rc);
g_temp_recover_cnt=0;
}
}
else
{
g_last_temp_status=rc; // 15秒后【上次正常,这次正常】,走printf(" rc is %d\n",rc);
g_temp_recover_cnt=0;
}
make -j4 MACHINEROOT=../machine/huaqin MACHINE=hq_sw6133 all
cppcheck 4 -q --enable=all –inconclusive ./
多进程窗口调试
logout exit quit
updatepsu 任一psu失效打印信息
//g_switch_cnt[board_index] : 1
fp=fopen("/tmp/fsc.json","rb");
段错误 替换json文件。不断进程,换窗口
etc/ssh/sshd_config
u字符串类型,\r回车 ,\n换行
vlan usb0
fpga.c -> 节点 -> DCDC json
ONIE:/ # onie-stop
串口连不上:刷新com,cpu挂了,c urt1切到bmc
hexdump fpga.bin
ifconfig eth0 down ifconfig eth0 hw ether aa:11:22:88:cc:dd
ifconfig eth0 up
dhclient eth0
root@localhost:/home/admin# sonic_installer list
Current: SONiC-OS-201911.124-S3IP_999_D4OS_0.04.00-20211217.023007
Next: SONiC-OS-201911.124-S3IP_999_D4OS_0.04.00-20211217.023007
Available:
SONiC-OS-201911.124-S3IP_999_D4OS_0.04.00-20211217.023007
uboot arm才有
syntax error near unexpected token `fi’ , if [$# -eq 3];then ,加then
/usr/bin/python3 -m pip install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
./devmem 0000:c3:00.0 2 0xC010 0x80000060
普及LPC reset pin用途:
- sensor计时监控复位。如CPU/DIMM等需要上电后一段时间才能去监控的sensor,需要根据LPC reset状态来清除计时器。
- IPMI Run Initialization Agent Command 需要lpc reset时执行(http://10.75.142.14/static/material/module/IPMI/ipmi-intelligent-platform-mgt-interface-spec-2nd-gen-v2-0-spec-update.pdf P475)
- ACD 信号量复位 ACDPltRstSemPost()
- port 80 采集计时。从LPC reset(无论软重启、硬重启等都会触发lpc reset)开始计时
- 对于BIOS启动监控,如dual BIOS image 超时切换,也是从lpc reset时开始计时
- 其他HOST监控行为,略
进入/var/lock,删除lockfile,minicom又可以正常启动
ifconfig Ethernet3 hw ether 34:04:04:04:18:ad,这个我是设了LC5的线卡
上行少逗号,,
quit
ps -ef | grep memtester | grep -v grep | cut -c 9-16 | xargs kill -9
回复 俞涛:
cp /home/root/a.sh /home/root/a/a.sh 可执行成功
覆盖
echo 值 进不存在的文件 , 报错 程序也往下走
a=2710
# b=`echo "scale=2; $a/1000" | bc`
# echo $b
b=$(awk 'BEGIN{printf "%.2f\n",'$a'/1000}')
echo $b