Enable kernel module for rtw_8821

I’m trying to use a RealTek WiFi chip that doesn’t seem to be supported in the UC20 amd64 at least. it is working just fine on Classic, but not showing up on UC.

Here are the details:

$ lspci -v
[...]
01:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8821CE 802.11ac PCIe Wireless Network Adapter
        Subsystem: AzureWave RTL8821CE 802.11ac PCIe Wireless Network Adapter
        Flags: bus master, fast devsel, latency 0, IRQ 130
        I/O ports at 4000 [size=256]
        Memory at 90100000 (64-bit, non-prefetchable) [size=64K]
        Capabilities: [40] Power Management version 3
        Capabilities: [50] MSI: Enable+ Count=1/1 Maskable- 64bit+
        Capabilities: [70] Express Endpoint, MSI 00
        Capabilities: [100] Advanced Error Reporting
        Capabilities: [148] Device Serial Number [redacted]
        Capabilities: [158] Latency Tolerance Reporting
        Capabilities: [160] L1 PM Substates
        Capabilities: [170] Precision Time Measurement
        Capabilities: [17c] Vendor Specific Information: ID=0003 Rev=1 Len=054 <?>
        Kernel driver in use: rtw_8821ce
        Kernel modules: rtw88_8821ce
[...]

Is there any way to easily enable this in your own disk image while still using Secure Boot?

1 Like

Do you know if the module is in the 20/stable track of the pc-kernel snap? If not, that would be the first step is getting it included there. If it’s already there you can load it from an unconfined shell via modprobe. If you need to load the kernel module from a strictly confined snap, you can do so very soon with the very new and very shiny kernel-module-load interface (as opposed to the existing and deprecated kernel-module-observe interface). Docs for that interface should appear soon, but in the meantime you can take a look at the PR here: https://github.com/snapcore/snapd/pull/10977

My impression is that it is not included:

$ sudo modprobe rtw88_8821ce
modprobe: FATAL: Module rtw88_8821ce not found in directory /lib/modules/5.4.0-91-generic

I’m struggling to find the actual code base for the pc-kernel snap. The Snapcraft listing is lacking a link to the respective GitHub or LP project

The source for the kernel snap is actually just a Makefile which pulls in kernel debs. If you can figure out which debian package the module comes from on classic that may help in identifying what additional kernel debs might need to be added to the snapcraft.yaml Makefile to enable this.

The driver appears to be provided by ‘linux-modules-extra’.

$ dpkg-query -S 'rtw88_8821ce'
linux-modules-extra-5.11.0-27-generic: /lib/modules/5.11.0-27-generic/kernel/drivers/net/wireless/realtek/rtw88/rtw88_8821ce.ko

Can you file a bug against the kernel at https://bugs.launchpad.net/ubuntu/+source/linux/+filebug with this information? (that the kernel module is not included in the 20/ track kernel snap but is available in linux-modules-extra). If the bot says you need to attach logs, just ignore it and set the bug back to New

Thanks – done:

1 Like

Hi, are there any instructions on how to actually build it - the same version UC 20 uses?

I cloned the kernel for focal from launchpad. Snapcraft.yaml seems incomplete - it’s missing build-base, version comes from CI I guess, I am not sure what branch is used for stable releases.

After I added build-base I can’t build it with the following error anyhow:

❯ ❯ snapcraft --destructive-mode
Failed to load plugin: unknown plugin: 'kernel'

try using @ondra’s local kernel plugin for core20 kernel snaps:

https://github.com/kubiko/snapcraft-kernel-plugin

@ogra I had a chat with @ondra about this earlier this week. His concern with side-loading a module like this is that it could a situation where the kernel updates, but the module hasn’t been updated (since it’s part of the snap) thus causing the device to lose connectivity.

oh, i understood above you are building a complete kernel snap … was that wrong ?

Ok, I cloned it and put it to focal/snap/plugins. Am I doing something completely wrong?

❯ snapcraft snap --destructive-mode Loaded local plugin for kernel The plugin used by part ‘kernel’ does not support snaps using base ‘core20’.

Just for test, I set the base to core18:

❯ snapcraft snap --destructive-mode Loaded local plugin for kernel Err linux-firmware_1.190.6_all.deb
404 Not Found [IP: 213.180.204.183 80]
Fetched 0 B in 0s (0 B/s)
Package fetch error: The item ‘/home/sergey/.cache/snapcraft/download/linux-firmware_1.190.6_all.deb’ could not be fetched: 404 Not Found [IP: 213.180.204.183 80]

Am I doing something completely wrong here?

try using build-base: core20 instead of base

Oh my bad. Then please ignore :slight_smile:

That’s exactly what I did. Steps here:

  1. Cloned kernel from launchpad - https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal
  2. Modified snapcraft.yaml: changed version, name of the snap and added build-base:
name: screenly-pc-kernel
version: '1.0'
version-script: |
    . debian/debian.env
    dpkg-parsechangelog -l $DEBIAN/changelog -S version
summary: The Ubuntu generic Linux kernel
description: This Ubuntu generic Linux kernel
grade: stable
confinement: strict
type: kernel
build-base: core20

parts:
  kernel:
    plugin: kernel
    source: .
    source-type: git
    kconfigflavour: generic
    kconfigs:
      - CONFIG_DEBUG_INFO=n
      - CONFIG_RTW88_CORE=m
      - CONFIG_RTW88_8821CE=m
      - CONFIG_RTW88_PCI=m
    override-build: |
      cp debian/scripts/retpoline-extract-one \
        $SNAPCRAFT_PART_BUILD/scripts/ubuntu-retpoline-extract-one
      snapcraftctl build
    kernel-with-firmware: false
  firmware:
    plugin: nil
    stage-packages:
      - linux-firmware
    organize:
      lib/firmware: firmware
    prime:
      - -usr
      - -lib
    build-packages:
      - cpio
      - libssl-dev
  1. Cloned the kernel plugin you linked and put it to the focal/snap/plugins
  2. Ran snapcraft --destructive-mode
  3. Got an immediate error:
❯ snapcraft snap --destructive-mode
Loaded local plugin for kernel
The plugin used by part 'kernel' does not support snaps using base 'core20'.

@ondra any hints ?

Just a followup, kernel-module-load will be available starting in snapd 2.54, you can see docs published here: The kernel-module-load interface (eventually that will be published on snapcraft.io/docs soon too)