From 13d9d9ed21d6ba9b8821b2e851868485d92482f0 Mon Sep 17 00:00:00 2001 From: hehaoyang Date: Tue, 14 May 2024 18:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E8=84=9A=E6=9C=AC=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipes/hvgo-tvis/files/hvgo.c | 2 +- .../recipes/motovis-tvis/motovis-tvis.bb | 2 - .../files/network-manager.service | 13 --- .../files/network-manager.sh | 41 ---------- .../network-manager-tvis.bb | 26 ------ .../files/networkd-configuration.sh | 80 +++++++++++++++++++ .../networkd-configuration/enP1p17s0.address | 1 + .../networkd-configuration/enP1p17s0.dhcp | 1 + .../networkd-configuration/enP1p17s0.metric | 1 + .../files/networkd-configuration/eth0.address | 1 + .../files/networkd-configuration/eth0.dhcp | 1 + .../files/networkd-configuration/eth0.metric | 1 + .../networkd-configuration-tvis.bb | 24 ++++++ .../packagegroups/packagegroup-tvis-app.bb | 2 +- 14 files changed, 112 insertions(+), 84 deletions(-) delete mode 100644 yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.service delete mode 100644 yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.sh delete mode 100644 yocto/meta-tvis-app/recipes/network-manager-tvis/network-manager-tvis.bb create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration.sh create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.address create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.dhcp create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.metric create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.address create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.dhcp create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.metric create mode 100644 yocto/meta-tvis-app/recipes/networkd-configuration-tvis/networkd-configuration-tvis.bb diff --git a/yocto/meta-tvis-app/recipes/hvgo-tvis/files/hvgo.c b/yocto/meta-tvis-app/recipes/hvgo-tvis/files/hvgo.c index e3dc946ce5..b045d46525 100755 --- a/yocto/meta-tvis-app/recipes/hvgo-tvis/files/hvgo.c +++ b/yocto/meta-tvis-app/recipes/hvgo-tvis/files/hvgo.c @@ -18,7 +18,7 @@ static version versions[] = { {"V1.07 20240425", "1.继承SDK1.3版本; 2. rtsp-server 更新; 3. 有线网卡脚本优化;"}, {"V1.08 20240430", "修复485+RTC"}, {"V1.09 20240508", "1.添加 i2c-tools、can-utils、ifmetric、network-manager等测试工具包; 2.解决QT界面程序编译报错问题"}, - {"V1.10 20240510", "重写网络控制脚本"}, + {"V1.10 20240514", "重写网络控制脚本"}, }; /* 获取版本信息说明 */ diff --git a/yocto/meta-tvis-app/recipes/motovis-tvis/motovis-tvis.bb b/yocto/meta-tvis-app/recipes/motovis-tvis/motovis-tvis.bb index b17458dbc5..f01edae9d1 100755 --- a/yocto/meta-tvis-app/recipes/motovis-tvis/motovis-tvis.bb +++ b/yocto/meta-tvis-app/recipes/motovis-tvis/motovis-tvis.bb @@ -9,9 +9,7 @@ do_package_qa[noexec] = "1" do_install() { install -d ${D}/opt/algmode -# install -m 0755 ${WORKDIR}/algmode ${D}/opt/algmode cp -rf ${WORKDIR}/algmode/* ${D}/opt/algmode/ -# cp -rf ${WORKDIR}/algmode/adas_detect.bin ${D}/opt/algmode/adas_detect.bin } INSANE_SKIP:${PN} += "already-stripped" diff --git a/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.service b/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.service deleted file mode 100644 index 8148fda138..0000000000 --- a/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=network-manager-service -SourcePath=/usr/bin/network-manager.sh -After=pcie1scan.service - -[Service] -Restart=no -RemainAfterExit=yes -ExecStartPre=/bin/sleep 10 -ExecStart=/usr/bin/network-manager.sh - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.sh b/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.sh deleted file mode 100644 index b914feb822..0000000000 --- a/yocto/meta-tvis-app/recipes/network-manager-tvis/files/network-manager.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -eth0_dhcp=false -eth0_address="192.168.10.12/24" -eth0_gateway="192.168.10.1" -eth0_dns="192.168.10.1" - -enP1p17s0_dhcp=false -enP1p17s0_address="192.168.1.249/24" -enP1p17s0_gateway="192.168.1.1" -enP1p17s0_dns="192.168.1.1" - -# 禁用DHCP服务 -systemctl stop dhcpcd.service -systemctl disable dhcpcd.service - -# 删除默认配置 -nmcli connection delete "Wired connection 1" -nmcli connection delete "Wired connection 2" -nmcli connection delete eth0 -nmcli connection delete enP1p17s0 - -if $eth0_dhcp ;then - nmcli connection add type ethernet con-name eth0 ifname eth0 -else - nmcli connection add type ethernet con-name eth0 ifname eth0 ipv4.addresses $eth0_address ipv4.gateway $eth0_gateway ipv4.dns $eth0_dns ipv4.method manual -fi - -if $enP1p17s0_dhcp ;then - nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0 -else - nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0 ipv4.addresses $enP1p17s0_address ipv4.gateway $enP1p17s0_gateway ipv4.dns $enP1p17s0_dns ipv4.method manual -fi - -# 启动 -nmcli connection up eth0 -nmcli connection up enP1p17s0 - -# 设置优先级 -ifmetric eth0 2100 -ifmetric enP1p17s0 2000 \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/network-manager-tvis/network-manager-tvis.bb b/yocto/meta-tvis-app/recipes/network-manager-tvis/network-manager-tvis.bb deleted file mode 100644 index fc9b1eee1a..0000000000 --- a/yocto/meta-tvis-app/recipes/network-manager-tvis/network-manager-tvis.bb +++ /dev/null @@ -1,26 +0,0 @@ -DESCRIPTION = "Install network manager application" -SECTION = "network-manager" -DEPENDS = "" -LICENSE = "CLOSED" - -SRC_URI += "file://network-manager.sh" -SRC_URI += "file://network-manager.service" - -S = "${WORKDIR}" - -## prebuilt library don't need following steps -do_configure[noexec] = "1" -do_compile[noexec] = "1" -do_package_qa[noexec] = "1" - -do_install() { - install -d ${D}${bindir} - install -m 0755 ${WORKDIR}/network-manager.sh ${D}${bindir} - - install -d ${D}/etc/systemd/system/ - install -d ${D}/etc/systemd/system/multi-user.target.wants/ - install -m 0644 ${WORKDIR}/network-manager.service -D ${D}/etc/systemd/system/network-manager.service - ln -sf /etc/systemd/system/network-manager.service ${D}/etc/systemd/system/multi-user.target.wants/network-manager.service -} - -FILES_${PN} += "/etc/*" \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration.sh b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration.sh new file mode 100644 index 0000000000..c134e6bb80 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +INTERFACE=$1 # 状态发生变化的网络接口 +STATUS=$2 # 网络接口的新状态:up, down, vpn-up, vpn-down + +echo "INTERFACE=$INTERFACE STATUS=$STATUS" + +if [ $STATUS = "up" ]; then + # 禁用DHCP服务 + systemctl stop dhcpcd.service + systemctl disable dhcpcd.service + + # 删除默认配置 + if test ! -z "$(nmcli connection | grep 'Wired connection 1')"; then + nmcli connection delete "Wired connection 1" + fi + + if test ! -z "$(nmcli connection | grep 'Wired connection 1')"; then + nmcli connection delete "Wired connection 2" + fi + + dhcp=false + metric=2000 + address="" + + # 判断是哪一张网卡 + if [ $INTERFACE = "eth0" ]; then + dhcp=`cat /etc/networkd-configuration/eth0.dhcp` + metric=`cat /etc/networkd-configuration/eth0.metric` + address=`cat /etc/networkd-configuration/eth0.address` + elif [ $INTERFACE = "enP1p17s0" ]; then + dhcp=`cat /etc/networkd-configuration/enP1p17s0.dhcp` + metric=`cat /etc/networkd-configuration/enP1p17s0.metric` + address=`cat /etc/networkd-configuration/enP1p17s0.address` + fi + + gateway=${address/${address##*.}/"1"} + + echo "dhcp=$dhcp address=$address gateway=$gateway dns=$gateway" + + # 地址为空, 不是eth0/enP1p17s0网卡 + if test -z "$address"; then + exit 1 + fi + + # 如果不存在网卡配置 + if test -z "$(nmcli connection | grep $INTERFACE)"; then + # 创建网卡配置 + if $dhcp ; then + nmcli connection add type ethernet con-name $INTERFACE ifname $INTERFACE + else + nmcli connection add type ethernet con-name $INTERFACE ifname $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual + fi + else + # 动态分配IP的情况下 + if $dhcp ; then + # 检查 ipv4.method 配置是否一致,不一致需要重新设置并重启网卡 + str=`nmcli connection show $INTERFACE | grep ipv4.method` + if [${str##*:} != "auto" ]; then + nmcli connection modify $INTERFACE ipv4.addresses "" ipv4.gateway "" ipv4.dns "" ipv4.method auto + echo "nmcli connection modify $INTERFACE ipv4.addresses ipv4.gateway ipv4.dns ipv4.method auto" + # 启动网卡 + nmcli connection up $INTERFACE + fi + else + # 检查 ipv4.address 配置是否一致,不一致需要重新设置并重启网卡 + str1=`nmcli connection show $INTERFACE | grep ipv4.method` + str2=`nmcli connection show $INTERFACE | grep ipv4.addresses` + if [${str1##*:} != "manual" ] || [${str2##*:} != $address ]; then + nmcli connection modify $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual + echo "nmcli connection modify $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual" + # 启动网卡 + nmcli connection up $INTERFACE + fi + fi + fi + + # 设置优先级 + ifmetric $INTERFACE $metric +fi diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.address b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.address new file mode 100644 index 0000000000..755df35ae6 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.address @@ -0,0 +1 @@ +192.168.1.249 \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.dhcp b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.dhcp new file mode 100644 index 0000000000..02e4a84d62 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.dhcp @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.metric b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.metric new file mode 100644 index 0000000000..9463411b62 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/enP1p17s0.metric @@ -0,0 +1 @@ +2000 \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.address b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.address new file mode 100644 index 0000000000..5203ce2b41 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.address @@ -0,0 +1 @@ +192.168.10.22 \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.dhcp b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.dhcp new file mode 100644 index 0000000000..02e4a84d62 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.dhcp @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.metric b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.metric new file mode 100644 index 0000000000..71bbc92a36 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/files/networkd-configuration/eth0.metric @@ -0,0 +1 @@ +2100 \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/networkd-configuration-tvis.bb b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/networkd-configuration-tvis.bb new file mode 100644 index 0000000000..d42c521ab4 --- /dev/null +++ b/yocto/meta-tvis-app/recipes/networkd-configuration-tvis/networkd-configuration-tvis.bb @@ -0,0 +1,24 @@ +DESCRIPTION = "Install network configuration" +SECTION = "network-configuration-tvis" +DEPENDS = "" +LICENSE = "CLOSED" + +SRC_URI += "file://networkd-configuration" +SRC_URI += "file://networkd-configuration.sh" + +S = "${WORKDIR}" + +## prebuilt library don't need following steps +do_configure[noexec] = "1" +do_compile[noexec] = "1" +do_package_qa[noexec] = "1" + +do_install() { + install -d ${D}/etc/networkd-configuration + cp -rf ${WORKDIR}/networkd-configuration/* ${D}/etc/networkd-configuration/ + + install -d ${D}/etc/NetworkManager/dispatcher.d/ + install -m 0755 ${WORKDIR}/networkd-configuration.sh -D ${D}/etc/NetworkManager/dispatcher.d/10-networkd-configuration.sh +} + +FILES_${PN} += "/etc/*" \ No newline at end of file diff --git a/yocto/meta-tvis-app/recipes/packagegroups/packagegroup-tvis-app.bb b/yocto/meta-tvis-app/recipes/packagegroups/packagegroup-tvis-app.bb index 44143dca6f..c43b533907 100755 --- a/yocto/meta-tvis-app/recipes/packagegroups/packagegroup-tvis-app.bb +++ b/yocto/meta-tvis-app/recipes/packagegroups/packagegroup-tvis-app.bb @@ -10,6 +10,6 @@ RDEPENDS:${PN} = "\ motovis-tvis \ netcore-tvis \ opencv-tvis \ - network-manager-tvis \ + networkd-configuration-tvis \ rtsp-server-tvis \ " \ No newline at end of file