forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_and_install_module.sh
More file actions
executable file
·97 lines (83 loc) · 3.77 KB
/
Copy pathbuild_and_install_module.sh
File metadata and controls
executable file
·97 lines (83 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
#
# build and install team/vrf driver
#
set -e
source /etc/os-release
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
build_and_install_kmodule()
{
if sudo modprobe team 2>/dev/null && sudo modprobe vrf 2>/dev/null && sudo modprobe macsec 2>/dev/null; then
echo "The module team, vrf and macsec exist."
return 0
fi
[ -z "$WORKDIR" ] && WORKDIR=$(mktemp -d)
cd $WORKDIR
KERNEL_RELEASE=$(uname -r)
KERNEL_MAINVERSION=$(echo $KERNEL_RELEASE | cut -d- -f1)
EXTRAVERSION=$(echo $KERNEL_RELEASE | cut -d- -f2)
LOCALVERSION=$(echo $KERNEL_RELEASE | cut -d- -f3)
VERSION=$(echo $KERNEL_MAINVERSION | cut -d. -f1)
PATCHLEVEL=$(echo $KERNEL_MAINVERSION | cut -d. -f2)
SUBLEVEL=$(echo $KERNEL_MAINVERSION | cut -d. -f3)
# Install the required debian packages to build the kernel modules
apt-get update
apt-get install -y build-essential linux-headers-${KERNEL_RELEASE} autoconf pkg-config fakeroot
apt-get install -y flex bison libssl-dev libelf-dev dwarves
apt-get install -y libnl-route-3-200 libnl-route-3-dev libnl-cli-3-200 libnl-cli-3-dev libnl-3-dev
# Add the apt source mirrors and download the linux image source code
cp /etc/apt/sources.list /etc/apt/sources.list.bk
sed -i "s/^# deb-src/deb-src/g" /etc/apt/sources.list
apt-get update
KERNEL_PACKAGE_SOURCE=$(trim $(apt-cache show linux-image-unsigned-${KERNEL_RELEASE} | grep ^Source: | cut -d':' -f 2))
KERNEL_PACKAGE_VERSION=$(trim $(apt-cache show linux-image-unsigned-${KERNEL_RELEASE} | grep ^Version: | cut -d':' -f 2))
SOURCE_PACKAGE_VERSION=$(apt-cache showsrc "${KERNEL_PACKAGE_SOURCE}" | grep ^Version: | cut -d':' -f 2 | tr '\n' ' ')
if ! echo "${SOURCE_PACKAGE_VERSION}" | grep "\b${KERNEL_PACKAGE_VERSION}\b"; then
echo "WARN: the running kernel version (${KERNEL_PACKAGE_VERSION}) doesn't match any of the available source " \
"package versions (${SOURCE_PACKAGE_VERSION}) being downloaded. There's no guarantee any of the available " \
"source packages can be loaded into the kernel or function correctly. Please update your kernel and reboot " \
"your system so that it's running a matching kernel version." >&2
fi
apt-get source "linux-image-unsigned-${KERNEL_RELEASE}"
# Recover the original apt sources list
cp /etc/apt/sources.list.bk /etc/apt/sources.list
apt-get update
# Build the Linux kernel module drivers/net/team and vrf
cd ${KERNEL_PACKAGE_SOURCE}-*
if [ -e debian/debian.env ]; then
source debian/debian.env
if [ -n "${DEBIAN}" -a -e ${DEBIAN}/reconstruct ]; then
bash ${DEBIAN}/reconstruct
fi
fi
make allmodconfig
mv .config .config.bk
cp /boot/config-$(uname -r) .config
grep NET_TEAM .config.bk >> .config
make VERSION=$VERSION PATCHLEVEL=$PATCHLEVEL SUBLEVEL=$SUBLEVEL EXTRAVERSION=-${EXTRAVERSION} LOCALVERSION=-${LOCALVERSION} modules_prepare
cp /usr/src/linux-headers-$(uname -r)/Module.symvers .
make -j$(nproc) M=drivers/net/team
mv drivers/net/Makefile drivers/net/Makefile.bak
echo 'obj-$(CONFIG_NET_VRF) += vrf.o' > drivers/net/Makefile
echo 'obj-$(CONFIG_MACSEC) += macsec.o' >> drivers/net/Makefile
make -j$(nproc) M=drivers/net
# Install the module
SONIC_MODULES_DIR=/lib/modules/$(uname -r)/updates/sonic
mkdir -p $SONIC_MODULES_DIR
cp drivers/net/team/*.ko drivers/net/vrf.ko drivers/net/macsec.ko $SONIC_MODULES_DIR/
depmod
modinfo team vrf macsec
modprobe team
modprobe vrf
modprobe macsec
cd /tmp
rm -rf $WORKDIR
}
build_and_install_kmodule