Build your own kernel headers

Since receiving my uConsole, I have been fighting with really terrible WiFi reception. It seems that at least some CM4 owners are affected. There are already a couple threads on this board so I won’t go into the details here.

At first, I wanted to try a different antenna, but sadly the one I bought off Amazon had a connector that was even smaller than the one on the CM4 board. Whoops.

I then decided to try a “supported” USB WiFi adapter. I wanted one that specifically supported Raspberry Pi “out-of-the-box” so I chose the Edimax EW-7811Un V2 (aka N150) off of Amazon. Not linking here because I don’t want people thinking I’m some sort of affiliate link shill (LOL). I chose this one because of 1) Out of the box Raspberry Pi support. 2) Small and very unobtrusive form factor. And finally 3) It only supports 2.4Ghz and not 5Ghz because I valued signal strength over maximum transfer speed. Lower frequencies penetrate walls better than high frequencies and at least anecdotally I’ve observed 2.4Ghz connections are more stable than 5Ghz.

To my utter disappointment, when I received the adapter I found that ClockworkPi have built their own kernel and it did NOT support this adapter! :sadpanda: No problem, the manufacturer has a git repo with build instructions at GitHub - lwfinger/rtl8188eu: Repository for stand-alone RTL8188EU driver.

To my utter shock and continued disappointment, I discovered ClockworkPi doesn’t provide kernels headers for their kernel! OMGWTFBBQ!

Eventually, I found Joseph Hewitt’s page at uconsole [Joseph's Projects]

I followed a slightly different set of instructions, as I only wanted kernel headers. As follows:

Get packages needed for compiling “kernel stuff”

sudo apt install crossbuild-essential-arm64 build-essential gcc-aarch64-linux-gnu flex bison libncurses-dev libssl-dev libelf-dev

Get the Raspberry Pi official kernel that ClockworkPi has patched for its custom kernel

git clone https://github.com/raspberrypi/linux.git
cd linux

Move the local repository to the commit that was patched

git reset --hard 3a33f11c48572b9dd0fecac164b3990fc9234da8

Get and apply ClockworkPi’s patch to this revision

wget https://raw.githubusercontent.com/clockworkpi/uConsole/master/Code/patch/cm4/20230630/0001-patch-cm4.patch
git apply 0001-patch-cm4.patch

Start building stuff. The second step takes quite a while

KERNEL=kernel8 make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
KERNEL=kernel8 make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j2

Make the modules directory and copy the build directory

mkdir ./modules
rm -rf ./modules/*
INSTALL_MOD_PATH=./modules make modules_install
sudo cp -r modules/lib/modules/5.10.17-v8+/build /lib/modules/5.10.17-v8+/

At this point you should be able to follow the instructions to build the driver/module for the Edimax WiFi adapter.

2 Likes

Aside of building drivers for external devices, you might find my post helpful.
TL;DR: change antenna’s orientation

ps: of course keep in mind that if your CM has its own wifi chip then pluggin UFL jack into onboard socket will be fruitless ;p