Thinstation / thinstation

A framework for making thin and light Linux based images for x86 based machines and thinclients.
https://www.thinstation.net/
777 stars 188 forks source link

Add custom driver for Wifi-USB Adapter #771

Open Snify89 opened 1 year ago

Snify89 commented 1 year ago

I would like to add this firmware to the thinstation client: https://github.com/fastoe/RTL8812BU

How am I able to add this?

Edit: I have looked into this a little bit further and got some progress ( I guess ) I would just like to have the Wifi Adapter working ( e.g. wlan0 in ifconfig ) To use Wifi later on I use the Wifi packages from thinstation (wpa_supplicant, etc.)

Here are some questions:

  1. There are 2 repositories for this chipset:
    1. https://github.com/morrownr/88x2bu-20210702
    2. https://github.com/fastoe/RTL8812BU which one should I use most preferably? (e.g. for the latest TS 6 version and/or 5.6)
  2. Is this considered a module and/or firmware?!
  3. Where should I put the Pkgfile? (/ts/ports/...?)
  4. Do I need the dkms stuff?
  5. Do I need to sign any compiled modules?

Thank you for your help and answers. I will post the Pkgfile, etc. later on during my progress.

Snify89 commented 1 year ago

So far my progress: I have created a folder in: /ts/ports/kernel-modules/rtl8812bu

I have then added the following Pkgfile:

# Description:  Realtek 8812bu USB Wireless Driver
# URL:          https://github.com/morrownr/88x2bu-20210702
release=1
repo_name=88x2bu-20210702
name=rtl8812bu
version=f0a2c9c74045cf2c3701084f389e358f9236fc8c
source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz)
kver=`cat /ts/ports/kernel-modules/VERSION`

build() 
{
    for KERNELTYPE in TS; do
        export REPORT_KERNEL=${kver}$KERNELTYPE
        cd "${repo_name}"-"${version}"  
        make clean
        make
        mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/
        install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/
    done
}

Everything worked so far (I might need the modprobe.d file as well)

When I add "module rtl8812bu" and build the image, I get this output:

Module 5.15.51TS: rtl8812bu
Notice! Module rtl8812bu.ko not found for kernel 5.15.51TS

Is there something I am missing?

Doncuppjr commented 1 year ago

You built the port, but did you install it? 

Sent from Yahoo Mail for iPhone

On Tuesday, April 4, 2023, 7:27 AM, Snify89 @.***> wrote:

So far my progress: I have created a folder in: /ts/ports/kernel-modules/rtl8812bu

I have then added the following Pkgfile:

Description: Realtek 8812bu USB Wireless Driver

URL: https://github.com/morrownr/88x2bu-20210702

release=1 repo_name=88x2bu-20210702 name=rtl8812bu version=f0a2c9c74045cf2c3701084f389e358f9236fc8c source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz) kver=cat /ts/ports/kernel-modules/VERSION

build() { for KERNELTYPE in TS; do export REPORT_KERNEL=${kver}$KERNELTYPE cd "${repo_name}"-"${version}"
make clean make mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ done }

Everything worked so far (I might need the modprobe.d file as well)

When I add "module rtl8812bu" and build the image, I get this output: Module 5.15.51TS: rtl8812bu Notice! Module rtl8812bu.ko not found for kernel 5.15.51TS

Is there something I am missing?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

Snify89 commented 1 year ago

You built the port, but did you install it?  Sent from Yahoo Mail for iPhone On Tuesday, April 4, 2023, 7:27 AM, Snify89 @.> wrote: So far my progress: I have created a folder in: /ts/ports/kernel-modules/rtl8812bu I have then added the following Pkgfile: # Description: Realtek 8812bu USB Wireless Driver # URL: https://github.com/morrownr/88x2bu-20210702 release=1 repo_name=88x2bu-20210702 name=rtl8812bu version=f0a2c9c74045cf2c3701084f389e358f9236fc8c source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz) kver=cat /ts/ports/kernel-modules/VERSION build() { for KERNELTYPE in TS; do export REPORT_KERNEL=${kver}$KERNELTYPE cd "${repo_name}"-"${version}" make clean make mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ done } Everything worked so far (I might need the modprobe.d file as well) When I add "module rtl8812bu" and build the image, I get this output: Module 5.15.51TS: rtl8812bu Notice! Module rtl8812bu.ko not found for kernel 5.15.51TS Is there something I am missing? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>

I did. First pgkmk -id then mkrepackage rtl8812bu
I can use it now as a package in the build.conf

However unsigned modules are rejected.

I am now recompiling the kernel and disabled module signature check. Will everything still work then?

Thinstation commented 1 year ago

Yes. rebuild-kernel would make a new signing key

On Tue, Apr 4, 2023 at 10:55 AM Snify89 @.***> wrote:

You built the port, but did you install it? Sent from Yahoo Mail for iPhone On Tuesday, April 4, 2023, 7:27 AM, Snify89 @.> wrote: So far my progress: I have created a folder in: /ts/ports/kernel-modules/rtl8812bu I have then added the following Pkgfile: # Description: Realtek 8812bu USB Wireless Driver # URL: https://github.com/morrownr/88x2bu-20210702 https://github.com/morrownr/88x2bu-20210702 release=1 repo_name=88x2bu-20210702 name=rtl8812bu version=f0a2c9c74045cf2c3701084f389e358f9236fc8c source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz https://github.com/morrownr/%24%7Brepo_name%7D/archive/%24%7Bversion%7D.tar.gz) kver=cat /ts/ports/kernel-modules/VERSION build() { for KERNELTYPE in TS; do export REPORT_KERNEL=${kver}$KERNELTYPE cd "${repo_name}"-"${version}" make clean make mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/ done } Everything worked so far (I might need the modprobe.d file as well) When I add "module rtl8812bu" and build the image, I get this output: Module 5.15.51TS: rtl8812bu Notice! Module rtl8812bu.ko not found for kernel 5.15.51TS Is there something I am missing? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>

I did. First pgkmk -id then mkrepackage rtl8812bu I can use it now as a package in the build.conf

However unsigned modules are rejected.

I am now recompiling the kernel and disabled module signature check. Will everything still work then?

— Reply to this email directly, view it on GitHub https://github.com/Thinstation/thinstation/issues/771#issuecomment-1496302182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVW47WY6HJ65ZDWI2BRUILW7RG75ANCNFSM6AAAAAAWSLPAWI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Snify89 commented 1 year ago

Yes. rebuild-kernel would make a new signing key

Ok thanks. So will signed modules (by you) still work then? (I mean modules/firmware stuff, which is not included in the kernel) Not sure if they are somehow encrypted or just "checked" if the keys match / are valid.

We will see. I will upload my results/experience as soon as I got further.

Thinstation commented 1 year ago

no, all module ports need to be rebuilt. rebuild-kernel -a

On Tue, Apr 4, 2023 at 11:26 AM Snify89 @.***> wrote:

Yes. rebuild-kernel would make a new signing key

Ok thanks. So will signed modules (by you) still work then? (I mean modules/firmware stuff, which is not included in the kernel) Not sure if they are somehow encrypted or just "checked" if the keys match / are valid.

We will see. I will upload my results/experience as soon as I got further.

— Reply to this email directly, view it on GitHub https://github.com/Thinstation/thinstation/issues/771#issuecomment-1496340424, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVW47TPSNQERDRRXXQNZTLW7RKUNANCNFSM6AAAAAAWSLPAWI . You are receiving this because you commented.Message ID: @.***>

Snify89 commented 1 year ago

So I have compiled the new kernel and ran pkgmk -u and got this result:

=======> Package '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz' is up to date.
=======> Installing '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz'.
pkgadd -u /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz
pkgadd: could not open /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz: Invalid or incomplete multibyte or wide character
=======> ERROR: Installing '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz' failed.

any idea what went wrong? Edit: the package is empty with 0 bytes, due to low memory (compression) :(

these are the last outputs of the rebuil-kernels command:

=======> WARNING: Footprint ignored.
=======> Building '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz' succeeded.
prt-get: reinstalling kernel-TS 1-1

-- Packages updated
kernel-TS

prt-get: updated successfully
prt-get: updating /ts/ports/kernel-modules/kernel-TS
=======> Footprint updated.
prt-get: reinstalling kernel-TS 1-1

-- Packages updated
kernel-TS

prt-get: updated successfully
prt-get: updating /ts/ports/kernel-modules/kernel-TS
=======> Md5sum updated.
prt-get: reinstalling kernel-TS 1-1

-- Packages updated
kernel-TS

prt-get: updated successfully
+ port=kernel-TS
++ prt-get printf %v --filter=kernel-TS
+ version=1
++ prt-get printf %r --filter=kernel-TS
+ release=1
++ prt-get path kernel-TS
+ path=/ts/ports/kernel-modules/kernel-TS
+ '[' -e /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.gz ']'
+ '[' -e /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz ']'
+ sarchive=/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz
+ darchive=/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz
+ '[' -z /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz ']'
+ '[' -z /ts/ports/kernel-modules/kernel-TS ']'
+ '[' -e /tmp/shrink ']'
+ mkdir -p /tmp/shrink
+ mount -t tmpfs -o size=1G tmpfs /tmp/shrink
+ tar -xf /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz -C /tmp/shrink
++ du -sb /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz
++ cut -f1
+ oldsize=64020332
+ cd /tmp/shrink
+ xz -9 --lzma2=dict=max
+ tar -c boot lib usr
xz: (stdin): Cannot allocate memory # EDIT: I see, probably not enough memory on my VM (Ubuntu machine with 4096MB RAM)
++ du -sb /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz.new
++ cut -f1
+ newsize=0
+ '[' 64020332 -gt 0 ']'
+ cp /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz.new /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz
+ rm /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz.new
+ cd /ts/ports/kernel-modules/kernel-TS
+ umount /tmp/shrink
+ rmdir /tmp/shrink

Also: I tried to compile the driver with Thinstation 5.6 for i686 and got this error:

make ARCH=i686 CROSS_COMPILE= -C /lib/modules/4.14.70TS/build M=/ts/ports/kernel-modules/rtl8812bu/work/src/88x2bu-20210702-f0a2c9c74045cf2c3701084f389e358f9236fc8c  modules
make[1]: Entering directory '/usr/src/kernels/4.14.70TS'
Makefile:642: arch/i686/Makefile: No such file or directory
make[1]: *** No rule to make target 'arch/i686/Makefile'.  Stop.
make[1]: Leaving directory '/usr/src/kernels/4.14.70TS'
Makefile:2506: recipe for target 'modules' failed
make: *** [modules] Error 2

As far as I can see, thinstation 5.6 has signing modules active but allows unsigned modules regardless. It would be nice to also have a i386 module for thinstation 5.6

Doncuppjr commented 1 year ago

Possibly the ‘shrink’ script did something bad to the archive. Try manual extraction/ or just rebuild it again.

Sent from Yahoo Mail for iPhone

On Wednesday, April 5, 2023, 12:38 AM, Snify89 @.***> wrote:

So I have compiled the new kernel and ran pkgmk -u and got this result: =======> Package '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz' is up to date. =======> Installing '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz'. pkgadd -u /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz pkgadd: could not open /ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz: Invalid or incomplete multibyte or wide character =======> ERROR: Installing '/ts/ports/kernel-modules/kernel-TS/kernel-TS#1-1.pkg.tar.xz' failed.

any idea what went wrong?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Snify89 commented 1 year ago

Possibly the ‘shrink’ script did something bad to the archive. Try manual extraction/ or just rebuild it again.

Thank you for your answer. It was really a memory issue after all. I am working between Thinstation 5.6 and the latest 6.2 (stable) versions right now... i386 compilation works with a small tweak in the makefile

I am also getting further to make this work...

I have disabled module signing and tried to disable module versioning as well. The module finally loaded but I come across this type of error(s): https://stackoverflow.com/questions/7513184/unknown-symbol-in-while-loading-a-kernel-module

I have also read a little bit about modules here: https://www.kernel.org/doc/Documentation/kbuild/modules.txt

I am kind of confused about the 5.6 version. It has 3 Kernel-TS modules (kernel-TS kernel-TS_64 kernel-TS_SMP) What is the meaning of this? The module get's installed in the wrong library path How do I deal with this to make everything work? :(

Doncuppjr commented 1 year ago

There should actually be three kernels for 5.6.TS is a Non-PAE kernel for very old systems. TS_SMP for early generation multi processor systems and TS_64 for modern 64 bit systems.

Sent from Yahoo Mail for iPhone

On Wednesday, April 5, 2023, 6:44 AM, Snify89 @.***> wrote:

Possibly the ‘shrink’ script did something bad to the archive. Try manual extraction/ or just rebuild it again.

Thank you for your answer. It was really a memory issue after all. I am working between Thinstation 5.6 and the latest 6.2 (stable) versions right now...

I am also getting further to make this work...

I have disabled module signing and tried to disable module versioning as well. The module finally loaded but I come across this type of error(s): https://stackoverflow.com/questions/7513184/unknown-symbol-in-while-loading-a-kernel-module

I have also read a little bit about modules here: https://www.kernel.org/doc/Documentation/kbuild/modules.txt

I am kind of confused about the 5.6 version. It has 2 Kernel-TS modules (TS & TS_SMP) What is the meaning of this? The module get's installed in the wrong library path How do I deal with this to make everything work? :(

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Snify89 commented 1 year ago

Let me post my progress here:

I have used version 5.6 (stable) here as I prefer the 32bit platforms:

First I have followed these instructions: https://github.com/Thinstation/thinstation/wiki/Custom-Kernel

Before running "rebuild-kernels", I have disabled Module Signing and Versioning entirely on the TS_SMP kernel. and then used pkgmk -u(f) on the compiled kernel type as the instruction(s) told me.

I have then created a folder in /ts/ports/kernel-modules/rtl18812bu (alternatively /ts/ports/components/rtl18812bu should also work)

and added the following Pkgfile:

# Description:  Realtek 8812bu USB Wireless Driver
# URL:          https://github.com/morrownr/88x2bu-20210702
release=1
repo_name=88x2bu-20210702
name=rtl8812bu
version=f0a2c9c74045cf2c3701084f389e358f9236fc8c
source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz)
kver=`cat /ts/ports/kernel-modules/VERSION`

build()
{
        # Change dir to unpacked source
        cd "${repo_name}"-"${version}"
        # Removed TS_64 and TS
        for KERNELTYPE in TS_SMP
        do
                export REPORT_KERNEL=${kver}$KERNELTYPE

                # Make for i386
                sed -i '160s/.*/CONFIG\_PLATFORM\_AUTODETECT\ \=\ n/' Makefile
                sed -i '161s/.*/CONFIG\_PLATFORM\_I386\_PC\ \=\ y/' Makefile

                # make clean target
                make clean

                # Compile / Make
                make

                # Create module path
                mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/

                # Copy/Create Modprobe
                mkdir -p "${PKG}"/etc/modprobe.d/
                cp -f 88x2bu.conf "${PKG}"/etc/modprobe.d/

                # Install module manually (as opposed to make install)
                install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/

        done
}

I then used "pkgmk -d" and "pkgmk -i" and "mkrepackage rtl8812bu"

I can then add the "package rtl8812bu" to my build.conf(.example)

Everything works just fine now :)

Since I got this to work now, I would like to know more about the different kernel types in 5.6

How can I switch to e.g. the non PAE/x64 kernel?

My machine uses the TS_SMP kernel only right now.

How does this exactly work?

Thank you for all the help :)

Doncuppjr commented 1 year ago

./build —kernel 64./build —kernel UP (for uniprocessor)

Sent from Yahoo Mail for iPhone

On Wednesday, April 19, 2023, 1:27 AM, Snify89 @.***> wrote:

Let me post my progress here:

I have used version 5.6 (stable) here as I prefer the 32bit platforms:

First I have followed these instructions: https://github.com/Thinstation/thinstation/wiki/Custom-Kernel

Before running "rebuild-kernels", I have disabled Module Signing and Versioning entirely on the TS_SMP kernel. and then used pkgmk -u(f) on the compiled kernel type as the instruction(s) told me.

I have then created a folder in /ts/ports/kernel-modules/rtl18812bu (alternatively /ts/ports/components/rtl18812bu should also work)

and added the following Pkgfile:

Description: Realtek 8812bu USB Wireless Driver

URL: https://github.com/morrownr/88x2bu-20210702

release=1 repo_name=88x2bu-20210702 name=rtl8812bu version=f0a2c9c74045cf2c3701084f389e358f9236fc8c source=(https://github.com/morrownr/${repo_name}/archive/${version}.tar.gz) kver=cat /ts/ports/kernel-modules/VERSION

build() {

Change dir to unpacked source

    cd "${repo_name}"-"${version}"
    # Removed TS_64 and TS
    for KERNELTYPE in TS_SMP
    do
            export REPORT_KERNEL=${kver}$KERNELTYPE

            # Make for i386
            sed -i '160s/.*/CONFIG\_PLATFORM\_AUTODETECT\ \=\ n/' Makefile
            sed -i '161s/.*/CONFIG\_PLATFORM\_I386\_PC\ \=\ y/' Makefile

            # make clean target
            make clean

            # Compile / Make
            make

            # Create module path
            mkdir -p "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/

            # Copy/Create Modprobe
            mkdir -p "${PKG}"/etc/modprobe.d/
            cp -f 88x2bu.conf "${PKG}"/etc/modprobe.d/

            # Install module manually (as opposed to make install)
            install -p -m 644 88x2bu.ko -t "${PKG}"/lib/modules/$REPORT_KERNEL/kernel/drivers/net/wireless/

    done

}

I then used "pkgmk -d" and "pkgmk -i" and "mkrepackage rtl8812bu"

I can then add the "package rtl8812bu" to my build.conf(.example)

Everything works just fine now :)

Since I got this to work now, I would like to know more about the different kernel types in 5.6

How can I switch to e.g. the non PAE/x64 kernel?

My machine uses the TS_SMP kernel only right now.

How does this exactly work?

Thank you for all the help :)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>