Skip to content

Commit b63633e

Browse files
committed
T7857: Add Realtek RTL8126 5Gbit driver
Signed-off-by: Thomas Kupper <thomas.kupper@gmail.com>
1 parent 12dbf51 commit b63633e

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
from tomllib import loads as toml_loads
5+
from requests import get
6+
from pathlib import Path
7+
from subprocess import run
8+
9+
CWD = os.getcwd()
10+
11+
# dependency modifier
12+
def add_depends(package_dir: str, package_name: str,
13+
depends: list[str]) -> None:
14+
"""Add dependencies to a package
15+
Args:
16+
package_dir (str): a directory where package sources are located
17+
package_name (str): a name of package
18+
depends (list[str]): a list of dependencies to add
19+
"""
20+
depends_list: str = ', '.join(depends)
21+
depends_line: str = f'misc:Depends={depends_list}\n'
22+
23+
substvars_file = Path(f'{package_dir}/debian/{package_name}.substvars')
24+
substvars_file.write_text(depends_line)
25+
26+
27+
# find kernel version and source path
28+
defaults_file: str = Path('../../../data/defaults.toml').read_text()
29+
architecture_file: str = Path('../../../data/architectures/amd64.toml').read_text()
30+
KERNEL_VER: str = toml_loads(defaults_file).get('kernel_version')
31+
KERNEL_FLAVOR: str = toml_loads(defaults_file).get('kernel_flavor')
32+
KERNEL_SRC: str = Path.cwd().as_posix() + '/linux'
33+
# define variables
34+
PACKAGE_NAME: str = 'vyos-drivers-realtek-r8126'
35+
PACKAGE_VERSION: str = '10.016.00'
36+
PACKAGE_DIR: str = f'{PACKAGE_NAME}-{PACKAGE_VERSION}'
37+
SOURCES_ARCHIVE: str = f'r8126-{PACKAGE_VERSION}.tar.bz2'
38+
SOURCES_URL: str = f'https://packages.vyos.net/source-mirror/{SOURCES_ARCHIVE}'
39+
40+
# download sources
41+
sources_archive = Path(SOURCES_ARCHIVE)
42+
sources_archive.write_bytes(get(SOURCES_URL).content)
43+
44+
# prepare sources
45+
debmake_cmd: list[str] = [
46+
'debmake', '-e', 'support@vyos.io', '-f', 'VyOS Support', '-p',
47+
PACKAGE_NAME, '-u', PACKAGE_VERSION, '-a', SOURCES_ARCHIVE
48+
]
49+
run(debmake_cmd)
50+
51+
# add kernel to dependencies
52+
add_depends(PACKAGE_DIR, PACKAGE_NAME,
53+
[f'linux-image-{KERNEL_VER}-{KERNEL_FLAVOR}'])
54+
55+
# configure build rules
56+
build_rules_text: str = '''#!/usr/bin/make -f
57+
# config
58+
export KERNELDIR := {KERNEL_SRC}
59+
PACKAGE_BUILD_DIR := debian/{PACKAGE_NAME}
60+
KVER := {KERNEL_VER}-{KERNEL_FLAVOR}
61+
MODULES_DIR := updates/drivers/net/ethernet
62+
# main packaging script based on dh7 syntax
63+
%:
64+
\tdh $@
65+
66+
override_dh_clean:
67+
\tdh_clean --exclude=debian/{PACKAGE_NAME}.substvars
68+
69+
override_dh_prep:
70+
\tdh_prep --exclude=debian/{PACKAGE_NAME}.substvars
71+
72+
override_dh_auto_clean:
73+
\tmake clean
74+
75+
override_dh_auto_build:
76+
\techo "KERNELDIR=${{KERNELDIR}}"
77+
\techo "CURDIR=${{CURDIR}}"
78+
\tmake -C ${{KERNELDIR}} M=${{CURDIR}}/src modules
79+
80+
override_dh_auto_install:
81+
\tinstall -D -m 644 src/r8126.ko ${{PACKAGE_BUILD_DIR}}/lib/modules/${{KVER}}/${{MODULES_DIR}}/r8126.ko
82+
\t${{KERNELDIR}}/../sign-modules.sh ${{PACKAGE_BUILD_DIR}}/lib
83+
'''.format(KERNEL_SRC=KERNEL_SRC, PACKAGE_NAME=PACKAGE_NAME, KERNEL_VER=KERNEL_VER, KERNEL_FLAVOR=KERNEL_FLAVOR)
84+
85+
build_rules_path = Path(f'{PACKAGE_DIR}/debian/rules')
86+
build_rules_path.write_text(build_rules_text, encoding='utf-8')
87+
88+
# build a package
89+
debuild_cmd: list[str] = ['debuild']
90+
run(debuild_cmd, cwd=PACKAGE_DIR, check=True)
91+
92+
# Sign generated Kernel modules
93+
clean_cmd: list[str] = ['rm', '-rf', PACKAGE_DIR]
94+
run(clean_cmd, cwd=CWD, check=True)

scripts/package-build/linux-kernel/build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def build_package(package: dict, dependencies: list) -> None:
155155
build_intel(package['name'], package['commit_id'], package['scm_url'])
156156
elif package['build_cmd'] == 'build_mellanox_ofed':
157157
build_mellanox_ofed()
158+
elif package['build_cmd'] == 'build_realtek_r8126':
159+
build_realtek_r8126()
158160
elif package['build_cmd'] == 'build_realtek_r8152':
159161
build_realtek_r8152()
160162
elif package['build_cmd'] == 'build_jool':
@@ -243,6 +245,11 @@ def build_mellanox_ofed():
243245
run(['sudo', './build-mellanox-ofed.sh'], check=True)
244246

245247

248+
def build_realtek_r8126():
249+
"""Build Realtek r8126"""
250+
run(['sudo', './build-realtek-r8126.py'], check=True)
251+
252+
246253
def build_realtek_r8152():
247254
"""Build Realtek r8152"""
248255
run(['sudo', './build-realtek-r8152.py'], check=True)

scripts/package-build/linux-kernel/package.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ commit_id = ""
7676
scm_url = ""
7777
build_cmd = "build_mellanox_ofed"
7878

79+
[[packages]]
80+
name = "realtek-r8126"
81+
commit_id = ""
82+
scm_url = ""
83+
build_cmd = "build_realtek_r8126"
84+
7985
[[packages]]
8086
name = "realtek-r8152"
8187
commit_id = ""

0 commit comments

Comments
 (0)