I am using DEY (digi embedded yocto) to produce an linux image. I have been playing around with the networkwork manager recipe so that I can inject multiple IP addresses into ethernet config files in the image via local.conf.
In a bbappend file I have this code to get variables from the local.conf file using d.getVar. The logic in the code is not important, just know that I am using getvar to get a variable from local.conf
#
# NetworkManager only accepts IP addresses in CIDR format
#
def ipaddr_to_cidr(iface, d):
ipaddr = d.getVar('%s_STATIC_IP' % iface.upper(), True)
netmask = d.getVar('%s_STATIC_NETMASK' % iface.upper(), True)
if ipaddr is None or netmask is None:
return "NONE"
binary_str = ''
for byte in netmask.split('.'):
binary_str += bin(int(byte))[2:].zfill(8)
return ipaddr + '/' + str(len(binary_str.rstrip('0')))
ETH0_STATIC_CIDR = "${@ipaddr_to_cidr('eth0', d)}"
ETH1_STATIC_CIDR = "${@ipaddr_to_cidr('eth1', d)}"
WLAN0_STATIC_CIDR = "${@ipaddr_to_cidr('wlan0', d)}"
ETH0_0_STATIC_CIDR = "${@ipaddr_to_cidr('eth0_0', d)}"
ETH0_1_STATIC_CIDR = "${@ipaddr_to_cidr('eth0_1', d)}"
ETH0_2_STATIC_CIDR = "${@ipaddr_to_cidr('eth0_2', d)}"
ETH0_3_STATIC_CIDR = "${@ipaddr_to_cidr('eth0_3', d)}"
ETH1_0_STATIC_CIDR = "${@ipaddr_to_cidr('eth1_0', d)}"
ETH1_1_STATIC_CIDR = "${@ipaddr_to_cidr('eth1_1', d)}"
ETH1_2_STATIC_CIDR = "${@ipaddr_to_cidr('eth1_2', d)}"
ETH1_3_STATIC_CIDR = "${@ipaddr_to_cidr('eth1_3', d)}"
The variables listed are then used to modify the ethernet config file on the resulting image. The code modifying the resulting image is in a task in the same append file:
do_install:append() {
install -d ${D}${sysconfdir}/init.d ${D}${sysconfdir}/NetworkManager
install -m 0644 ${WORKDIR}/NetworkManager.conf ${D}${sysconfdir}/NetworkManager/
install -m 0755 ${WORKDIR}/networkmanager-init ${D}${sysconfdir}/init.d/networkmanager
#
# Customize NetworkManager
#
sed -i -e "s,##UNMANAGED_DEVICES##,${UNMANAGED_DEVICES},g" ${D}${sysconfdir}/NetworkManager/NetworkManager.conf
#
# Connections config files
#
install -d ${D}${sysconfdir}/NetworkManager/system-connections/
# Ethernet
install -m 0600 ${WORKDIR}/nm.eth0.${ETH0_MODE} ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
if [ "${ETH0_0_STATIC_CIDR}" = "NONE" ]; then
sed -i "s/eth0_0//" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
else
sed -i "s/eth0_0/address1=${ETH0_0_STATIC_CIDR}n/" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
fi
if [ "${ETH0_1_STATIC_CIDR}" = "NONE" ]; then
sed -i "s/eth0_1//" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
else
sed -i "s/eth0_1/address2=${ETH0_1_STATIC_CIDR}n/" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
fi
if [ "${ETH0_2_STATIC_CIDR}" = "NONE" ]; then
sed -i "s/eth0_2//" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
else
sed -i "s/eth0_2/address3=${ETH0_2_STATIC_CIDR}n/" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
fi
if [ "${ETH0_3_STATIC_CIDR}" = "NONE" ]; then
sed -i "s/eth0_3//" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
else
sed -i "s/eth0_3/address4=${ETH0_3_STATIC_CIDR}n/" ${D}${sysconfdir}/NetworkManager/system-connections/nm.eth0
fi
The idea behind this is that you can just set variables in the local.conf file so that the configuration is all in one place. However, I notice that when I modify local.conf and add the ETH## variables, the python function and the task are not being ran. I would like to somehow specify a dependency saying that when the ETH# variables are modified/added, rerun the task (similar to how makefiles will remake when files are modified), but I don’t know how to set a dependency based on a variable.
I tried looking up bitbake documentation on dependencies, but all I could find was specifying dependencies between two tasks, and I couldn’t find anything on specifying a dependency on a variable
Alec You is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.