summaryrefslogtreecommitdiff
path: root/scripts/package-build/linux-kernel
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-10-07 15:58:30 +0100
committerGitHub <noreply@github.com>2024-10-07 15:58:30 +0100
commit49d41fa34ab0ac31ccea687e97ed0cad6f60c1e5 (patch)
tree41cf3e423a92ae5af508f0eb5d49040656ec6a2a /scripts/package-build/linux-kernel
parentbeb5d83003fe54071bff044a3442c64c56f3c49c (diff)
parenta3b515ca716bc2505c15900c4d5e549a672e7dfa (diff)
downloadvyos-build-49d41fa34ab0ac31ccea687e97ed0cad6f60c1e5.tar.gz
vyos-build-49d41fa34ab0ac31ccea687e97ed0cad6f60c1e5.zip
Merge pull request #762 from sever-sever/T6713-current-realtek
T6713: Update Realtek r8152 driver
Diffstat (limited to 'scripts/package-build/linux-kernel')
-rwxr-xr-xscripts/package-build/linux-kernel/build-driver-realtek-r8152.py88
-rwxr-xr-xscripts/package-build/linux-kernel/build.py7
-rw-r--r--scripts/package-build/linux-kernel/package.toml6
3 files changed, 101 insertions, 0 deletions
diff --git a/scripts/package-build/linux-kernel/build-driver-realtek-r8152.py b/scripts/package-build/linux-kernel/build-driver-realtek-r8152.py
new file mode 100755
index 00000000..81dfb901
--- /dev/null
+++ b/scripts/package-build/linux-kernel/build-driver-realtek-r8152.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+
+from tomllib import loads as toml_loads
+from requests import get
+from pathlib import Path
+from subprocess import run
+
+# dependency modifier
+def add_depends(package_dir: str, package_name: str,
+ depends: list[str]) -> None:
+ """Add dependencies to a package
+ Args:
+ package_dir (str): a directory where package sources are located
+ package_name (str): a name of package
+ depends (list[str]): a list of dependencies to add
+ """
+ depends_list: str = ', '.join(depends)
+ depends_line: str = f'misc:Depends={depends_list}\n'
+
+ substvars_file = Path(f'{package_dir}/debian/{package_name}.substvars')
+ substvars_file.write_text(depends_line)
+
+
+# find kernel version and source path
+defaults_file: str = Path('../../../data/defaults.toml').read_text()
+architecture_file: str = Path('../../../data/architectures/amd64.toml').read_text()
+KERNEL_VER: str = toml_loads(defaults_file).get('kernel_version')
+KERNEL_FLAVOR: str = toml_loads(defaults_file).get('kernel_flavor')
+KERNEL_SRC: str = Path.cwd().as_posix() + '/linux'
+
+# define variables
+PACKAGE_NAME: str = 'vyos-drivers-realtek-r8152'
+PACKAGE_VERSION: str = '2.18.1'
+PACKAGE_DIR: str = f'{PACKAGE_NAME}-{PACKAGE_VERSION}'
+SOURCES_ARCHIVE: str = 'r8152-2.18.1-1.tar.gz'
+SOURCES_URL: str = f'https://github.com/bb-qq/r8152/archive/refs/tags/2.18.1-1.tar.gz'
+
+# download sources
+sources_archive = Path(SOURCES_ARCHIVE)
+sources_archive.write_bytes(get(SOURCES_URL).content)
+
+# prepare sources
+debmake_cmd: list[str] = [
+ 'debmake', '-e', 'support@vyos.io', '-f', 'VyOS Support', '-p',
+ PACKAGE_NAME, '-u', PACKAGE_VERSION, '-a', SOURCES_ARCHIVE
+]
+run(debmake_cmd)
+
+# add kernel to dependencies
+add_depends(PACKAGE_DIR, PACKAGE_NAME,
+ [f'linux-image-{KERNEL_VER}-{KERNEL_FLAVOR}'])
+
+# configure build rules
+build_rules_text: str = '''#!/usr/bin/make -f
+# config
+export KERNELDIR := {KERNEL_SRC}
+PACKAGE_BUILD_DIR := debian/{PACKAGE_NAME}
+KVER := {KERNEL_VER}-{KERNEL_FLAVOR}
+MODULES_DIR := updates/drivers/net/usb
+# main packaging script based on dh7 syntax
+%:
+\tdh $@
+
+override_dh_clean:
+\tdh_clean --exclude=debian/{PACKAGE_NAME}.substvars
+
+override_dh_prep:
+\tdh_prep --exclude=debian/{PACKAGE_NAME}.substvars
+
+override_dh_auto_clean:
+\tmake clean
+
+override_dh_auto_build:
+\techo "KERNELDIR=${{KERNELDIR}}"
+\techo "CURDIR=${{CURDIR}}"
+\tmake -C ${{KERNELDIR}} M=${{CURDIR}} modules
+
+override_dh_auto_install:
+\tinstall -D -m 644 r8152.ko ${{PACKAGE_BUILD_DIR}}/lib/modules/${{KVER}}/${{MODULES_DIR}}/r8152.ko
+\tinstall -D -m 644 50-usb-realtek-net.rules ${{PACKAGE_BUILD_DIR}}/etc/udev/rules.d/50-usb-realtek-net.rules
+'''.format(KERNEL_SRC=KERNEL_SRC, PACKAGE_NAME=PACKAGE_NAME, KERNEL_VER=KERNEL_VER, KERNEL_FLAVOR=KERNEL_FLAVOR)
+
+build_rules_path = Path(f'{PACKAGE_DIR}/debian/rules')
+build_rules_path.write_text(build_rules_text, encoding='utf-8')
+
+# build a package
+debuild_cmd: list[str] = ['debuild']
+run(debuild_cmd, cwd=PACKAGE_DIR, check=True)
diff --git a/scripts/package-build/linux-kernel/build.py b/scripts/package-build/linux-kernel/build.py
index 318cb0ce..2a239adc 100755
--- a/scripts/package-build/linux-kernel/build.py
+++ b/scripts/package-build/linux-kernel/build.py
@@ -100,6 +100,8 @@ def build_package(package: dict, dependencies: list) -> None:
build_intel_ixgbevf()
elif package['build_cmd'] == 'build_mellanox_ofed':
build_mellanox_ofed()
+ elif package['build_cmd'] == 'build_realtek_r8152':
+ build_realtek_r8152()
elif package['build_cmd'] == 'build_jool':
build_jool()
elif package['build_cmd'] == 'build_openvpn_dco':
@@ -190,6 +192,11 @@ def build_mellanox_ofed():
run(['sudo', './build-mellanox-ofed.sh'], check=True)
+def build_realtek_r8152():
+ """Build Realtek r8152"""
+ run(['sudo', './build-driver-realtek-r8152.py'], check=True)
+
+
def build_jool():
"""Build Jool"""
run(['echo y | ./build-jool.py'], check=True, shell=True)
diff --git a/scripts/package-build/linux-kernel/package.toml b/scripts/package-build/linux-kernel/package.toml
index 44102298..035a442e 100644
--- a/scripts/package-build/linux-kernel/package.toml
+++ b/scripts/package-build/linux-kernel/package.toml
@@ -65,3 +65,9 @@ name = "mlnx"
commit_id = ""
scm_url = ""
build_cmd = "build_mellanox_ofed"
+
+[[packages]]
+name = "realtek-r8152"
+commit_id = ""
+scm_url = ""
+build_cmd = "build_realtek_r8152"