Building the r8168 driver for RealTek RTL8168B/8111B, RTL8168C/8111C, RTL8168CP/8111CP, RTL8168D/8111D, DP/8111DP, and RTL8168E/8111E Gigabit Ethernet controllers with PCI-Express interface.

* Official download page (download link captcha is broken):
   https://www.realtek.com/en/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-pci-express-software
* Download from Debian instead (check that they've got the latest version first):
   http://deb.debian.org/debian/pool/non-free/r/r8168/

* cd /tmp
* kerver=`uname -r` && wget http://tinycorelinux.net/`version -m`.x/`uname -m`/release/src/kernel/linux-${kerver%-*}-patched.txz
  (~120MB download)
* tce-load -i compiletc squashfs-tools submitqc gettext bc elfutils-dev.tcz 
* kerver=`uname -r` && tar xvJf /tmp/linux-${kerver%-*}-patched.txz
* cd linux-${kerver%-*}
* sudo ln -s "`pwd`" /lib/modules/`uname -r`/build
* wget -O .config http://tinycorelinux.net/`version -m`.x/`uname -m`/release/src/kernel/config-${kerver%-*}-tinycore64
* wget http://tinycorelinux.net/`version -m`.x/`uname -m`/release/src/kernel/Module.symvers-${kerver%-*}-tinycore64.gz
* gunzip -c Module.symvers-${kerver%-*}-tinycore64.gz > Module.symvers
* export CFLAGS="-mtune=generic -Os -pipe" CXXFLAGS="-mtune=generic -Os -pipe" LDFLAGS="-Wl,-O1"
* make oldconfig && make prepare && make modules_prepare
* Unpack driver source archive somewhere
* Enter driver source directory and run: make modules
  - Failed with: "r8168.h:569:57: error: too many arguments to function 'netif_napi_add'"
   - Use Debian patch:
     wget http://deb.debian.org/debian/pool/non-free/r/r8168/r8168_8.051.02-2.debian.tar.xz
     tar xvJf r8168_8.051.02-2.debian.tar.xz
     patch -p1 < debian/patches/linux-6.1.patch
     make modules
* cd src
* r8168.ko is the kernel module
* strip module debugging symbols with: strip --strip-unneeded r8168.ko
* gzip r8168.ko

#config (manual):

* Add "blacklist=r8169" bootcode to bootloader parameters list to prevent the Linux kernel driver from automatically loading at boot.
* Add "modprobe r8168" command to /opt/bootlocal.sh

#Making an extension:

* mkdir -p r8168/usr/local/lib/modules/`uname -r`/kernel/drivers/net/ethernet/realtek
* cp r8168.ko.gz r8168/usr/local/lib/modules/`uname -r`/kernel/drivers/net/ethernet/realtek/
* sudo chown -R root:root r8168
* mksquashfs r8168 r8168-`uname -r`.tcz
* md5sum r8168-`uname -r`.tcz > r8168-`uname -r`.tcz.md5.txt
* submitqc
