Skip to content

Commit 68e8e02

Browse files
authored
Merge pull request #34 from microsoft/hwsimcompile
Include mac80211_hwsim module in Docker development environment image.
2 parents c4f89b3 + c2d245a commit 68e8e02

File tree

2 files changed

+101
-7
lines changed

2 files changed

+101
-7
lines changed

.docker/netremote-dev/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ RUN apt-get update && \
8585
ssh \
8686
sudo \
8787
# Generic development tools.
88-
# emacs gdb nano policycoreutils-python-utils python-is-python3 vim
88+
# emacs gdb kmod nano policycoreutils-python-utils python-is-python3 vim
8989
emacs \
9090
gdb \
91+
kmod \
9192
nano \
9293
policycoreutils-python-utils \
9394
python-is-python3 \
@@ -98,14 +99,16 @@ RUN apt-get update && \
9899
rm -rf /var/lib/apt/lists/*
99100

100101
# Copy outside content into container.
101-
COPY entrypoint.sh /bin/entrypoint.sh
102-
COPY 50-sysinfo /etc/update-motd.d/50-sysinfo
102+
COPY --chmod=0755 entrypoint.sh /bin/entrypoint.sh
103+
COPY --chmod=0755 50-sysinfo /etc/update-motd.d/50-sysinfo
104+
COPY --chmod=0755 build-mac80211_hwsim-kmod.sh /tmp/build-mac80211_hwsim-kmod.sh
103105

104106
# Message of the day settings.
105-
RUN chmod 0755 /etc/update-motd.d/50-sysinfo && \
106-
rm -f /etc/update-motd.d/50-landscape-sysinfo && \
107-
# Permission for entrypoint script
108-
chmod +x /bin/entrypoint.sh
107+
RUN rm -f /etc/update-motd.d/50-landscape-sysinfo
108+
109+
# Build the mac80211_hwsim kernel module.
110+
RUN /tmp/build-mac80211_hwsim-kmod.sh && \
111+
mv /tmp/build-mac80211_hwsim-kmod.sh ${HOME}/
109112

110113
# Set entrypoint and start interactive shell (bash).
111114
ENTRYPOINT [ "/bin/entrypoint.sh" ]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
# Determine active kernel version number.
6+
KERNEL_VERSION=`uname -r | grep -Eo '([0-9]+)*(\.?[0-9]+)*' | head -1`
7+
8+
# URL for kernel sources of active kernel version.
9+
KERNEL_FILE_NAME_PREFIX=linux-msft-wsl-
10+
KERNEL_FILE_NAME_STEM=${KERNEL_FILE_NAME_PREFIX}${KERNEL_VERSION}
11+
KERNEL_FILE_NAME_SUFFIX=.tar.gz
12+
KERNEL_FILE_NAME=${KERNEL_FILE_NAME_STEM}${KERNEL_FILE_NAME_SUFFIX}
13+
KERNEL_URL_BASE=https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags
14+
KERNEL_URL_FILE=${KERNEL_URL_BASE}/${KERNEL_FILE_NAME}
15+
KERNEL_CONFIG_UTIL=scripts/config
16+
17+
# WSL kernel source directory name.
18+
WSL_SRC_DIRECTORY_BASE_DEFAULT=${HOME}/src
19+
WSL_SRC_DIRECTORY_BASE=${WSL_SRC_DIRECTORY_BASE:=${WSL_SRC_DIRECTORY_BASE_DEFAULT}}
20+
WSL_SRC_DIRECTORY_PREFIX=WSL2-Linux-Kernel-
21+
WSL_SRC_DIRECTORY=${WSL_SRC_DIRECTORY_PREFIX}${KERNEL_FILE_NAME_STEM}
22+
WSL_SRC_CONFIG_FILE_NAME=config-${KERNEL_VERSION}
23+
WSL_SRC_CONFIG_DIRECTORY=Microsoft
24+
WSL_SRC_CONFIG=${WSL_SRC_CONFIG_DIRECTORY}/${WSL_SRC_CONFIG_FILE_NAME}
25+
26+
# WSL kernel compilation arguments.
27+
WSL_KERNEL_COMPILE_ARG_PARALLEL="-j $(expr $(nproc) - 1)"
28+
29+
# Additional arguments passed to wget when downloading kernel source.
30+
# Mostly used for testing.
31+
WGET_XTRA_ARGS=
32+
33+
# Print debug information if DEBUG is set to 1.
34+
if [[ $DEBUG -eq 1 ]]; then
35+
echo "DEBUG: KERNEL_VERSION=${KERNEL_VERSION}"
36+
echo "DEBUG: KERNEL_FILE_NAME=${KERNEL_FILE_NAME}"
37+
echo "DEBUG: KERNEL_URL_FILE=${KERNEL_URL_FILE}"
38+
echo "DEBUG: WSL_SRC_DIRECTORY=${WSL_SRC_DIRECTORY}"
39+
echo "DEBUG: WSL_SRC_CONFIG_FILE_NAME=${WSL_SRC_CONFIG_FILE_NAME}"
40+
echo "DEBUG: WSL_SRC_CONFIG=${WSL_SRC_CONFIG}"
41+
fi
42+
43+
# Install dependencies for building kernel modules.
44+
# (see https://github.com/microsoft/WSL2-Linux-Kernel)
45+
# added bc, python-is-python3
46+
echo "Installing dependencies for building kernel modules..."
47+
sudo apt-get update
48+
sudo apt-get install -y build-essential bc bison flex dwarves kmod libssl-dev libelf-dev python-is-python3 wget
49+
50+
# Download and unpack kernel source.
51+
echo "Downloading and unpacking kernel source..."
52+
if [[ ! -d ${WSL_SRC_DIRECTORY_BASE} ]]; then
53+
mkdir -p ${WSL_SRC_DIRECTORY_BASE}
54+
fi
55+
56+
cd ${WSL_SRC_DIRECTORY_BASE}
57+
wget ${KERNEL_URL_FILE} ${WGET_XTRA_ARGS:+"${WGET_XTRA_ARGS}"} -O - | tar xzvf -
58+
cd ${WSL_SRC_DIRECTORY}
59+
60+
# Prepare the kernel source with the configuration for the running kernel.
61+
echo "Preparing kernel source with configuration for running kernel..."
62+
if [[ ! -f ${WSL_SRC_CONFIG} ]]; then
63+
cat /proc/config.gz | gzip -d > ${WSL_SRC_CONFIG}
64+
fi
65+
66+
if [[ ! -f .config ]]; then
67+
ln -s ${WSL_SRC_CONFIG} .config
68+
fi
69+
70+
# Supply defaults for any new/unspecified options in the configuration.
71+
make olddefconfig
72+
73+
# Prepare the source tree for building external modules.
74+
echo "Preparing kernel source tree for building external modules..."
75+
make prepare modules_prepare ${WSL_KERNEL_COMPILE_ARG_PARALLEL}
76+
77+
# Update the configuration to build the mac80211_hwsim module and its dependencies.
78+
echo "Updating kernel configuration to build mac80211_hwsim module and its dependencies..."
79+
${KERNEL_CONFIG_UTIL} \
80+
--module CONFIG_RFKILL \
81+
--module CONFIG_CFG80211 \
82+
--module CONFIG_MAC80211 \
83+
--module CONFIG_MAC80211_HWSIM
84+
85+
echo "Building kernel modules..."
86+
make modules ${WSL_KERNEL_COMPILE_ARG_PARALLEL}
87+
88+
echo "Installing kernel modules..."
89+
sudo make modules_install
90+
91+
echo "Done."

0 commit comments

Comments
 (0)