make your driver as a deb package

如何制作和修改Debian软件包
本文详细介绍了如何从零开始制作Debian软件包,包括设置环境变量、生成deb的架子、修改control文件、添加脚本文件以及打包过程。同时,文章也提到了修改现有包的方法,并解释了依赖冲突的解决策略。

做完自己的开发之后,想要发布自己的代码,怎么办呢,比如如何给已有的系统打补丁,或者作为一个安装包在新部署的系统环境中存在呢?

其实要分情况,如果是社区兼容性的东西(符合社区blueprint),能够被社区admin review通过的,当然直接提交到社区比较合适;如果是自己特有的功能,仅仅是少数几个

文件的修改,使用diff/patch 将改动做成patch,之后apply 即可,如果涉及到文件的增删改,同时相对比较多的时候,且希望使用例如puppet之类的部署工具,作为

一个模块将自己的改动部署掉,则需要打包了,centos上就打rpm包,ubuntu则需要打deb的包,这两天打deb包的过程record一下,以后还可能用,rpm的遇到再说。

事实上deb的包里面内容还是挺多的,有很多种用法,一下是我经验证可以的方式,不一定最佳。

第一种方式. 从零开始制作自己的包:

1. sudo apt-get install packaging-dev dh-make 安装需要的包

2.设置环境变量,这些内容将在deb包中的control文件中出现

DEBEMAIL="your_email_address@domain.com"

DEBFULLNAME="Your Name"

export DEBEMAIL DEBFULLNAME

3.生成deb的架子,各个参数的意义可以使用dh_make --help查看

dh_make -i -n -p packagename_1.0.0 -c gpl2, 生成的目录中ex和EX结尾的文件可以删除

4. 修改control文件,在Depends字段添加该包的依赖,可以修改Section等,不过不修改也没关系,

5. 添加postinst, postrm, preinst三个script文件,实际上是三个脚本(#!/bin/sh),其中preinst是安装开始前做准备的工作,比较在/usr/share下生成一个目录,

删除某个目录,或者做一些检查之类的;postinst是安装之后做一些动作,同样可以增删改文件,重启服务等; postrm表示使用"dpkg -P" 卸载包时做的动作,

一般会将安装时做的修改回退,比如删除添加的文件和目录,使用patch -R,回退修改等。

6. 添加install文件,此文件中内容为“pathA pathB”, 中间以空格隔开的多行数据,表示将pathA下的内容拷贝到pathB下,安装过程会做很多的拷贝,就写在这里,

拷贝的时候pathA的路径是相对路径,比如packagename下面有debian目录和‘test’ 目录,要将test目录中的文件test.txt移到/etc/init.d下,则写为:

“test/test.txt /etc/init.d/”

7. 在packagename目录中运行“debuild -us -uc”, 则在和packagename同级目录生成所需的deb包, 其中us 和uc参数表示不使用GPG签名包。


第二种方式.修改现有的包:

找一个包,解压后修改然后重新打包,有时候更方便,同时如果用第一种方式做的包,结果发现有点儿问题,重新做太麻烦,就用第二种了。

1. 使用 “dpkg -X test.deb test”, 将test.deb解压到testmul

2. mkdir test/DEBIAN, 创建目录,这里DEBIAN是大写,使用小写的debian不识别,创建包的时候用命令生成的是debian的目录,可能跟第一种和第二种做包

的命令不同有关,没继续研究了。

3. 使用“dpkg -e test.deb test/DEBIAN” 将打包过程的信息解压到test/DEBIAN中

4. 在test/DEBIAN中有control,md5sums,postinst, postrm, preinst, 和做包时候的内容一致,做包时候的install文件中的内容在第一步生成的test目录下,

打开其对应的路径,发现其内容是install执行copy之后的实际文件位置

5. 修改control,postinst,postrm,preinst

6. 修改完成后在test同级目录执行“dpkg-deb -b test .”, 则在test同级目录生成test.deb


依赖冲突解决:

无论安装rpm还是deb的包经常遇到各种冲突,比如系统安装的包的版本和“control文件中Depends中定义的不匹配”等,

保险的情况下当然是升级系统的版本,但是各种依赖交叉,会让安装的过程变得很头疼,事实上,有些依赖并不是那么严格,

比如一些小版本等等,为了让安装变得顺利,我们可以将包解压,修改control中的Depends字段,重新打包之后安装。

当然了,除非你对版本之间的差异特别情况,否则请严格测试,否则这样的方式并不推荐。


mark link:

https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

rtw89 A repo for the newest Realtek rtw89 codes. This repo now contains the code for the Realtek RTW8922AE, which is a Wifi 7 device. It has been tested using a Wifi 6 AP as I do not have access to a Wifi 7 model. The driver works very well. This repo is current with rtw-next up to April 3, 2024. This branch was created from the version merged into the wireless-next repo, which is in the 5.16 kernel. IF YOU USE DRIVERS FROM THIS REPO FOR KERNELS 5.16+, YOU MUST BLACKLIST THE KERNEL VERSIONS!!!! FAILING TO DO THIS WILL RESULT IN ALL MANNER OF STRANGE ERRORS. This code will build on any kernel 6.10 and newer as long as the distro has not modified any of the kernel APIs. IF YOU RUN UBUNTU, YOU CAN BE ASSURED THAT THE APIs HAVE CHANGED. NO, I WILL NOT MODIFY THE SOURCE FOR YOU. YOU ARE ON YOUR OWN!!!!! Note that if you use this driver on kernels older than 5.15, the enhanced features of wifi 5 and wifi 6 are greatly crippled as the kernel does hot have the capability to support the new packet widths and speeds. If you use such a kernel, you might as well have an 802.11n (wifi 4) device. This repository includes drivers for the following cards: Realtek 8851BE, 8852AE, 8852BE, 8852CE, and 8922AE. If you are looking for a driver for chips such as RTL8188EE, RTL8192CE, RTL8192CU, RTL8192DE, RTL8192EE, RTL8192SE, RTL8723AE, or RTL8723BE, these should be provided by your kernel. If not, then you should go to the Backports Project (https://backports.wiki.kernel.org/index.php/Main_Page) to obtain the necessary code. If you have an RTW8822B{E,U,S}, RTW8822C{E,U,S}, RTW8723D{E,U,S}, or RTW8821C{E,U,S}, then you should use the drivers at https://github.com/lwfinger/rtw88.git. Installation instruction Requirements You will need to install "make", "gcc", "kernel headers", "kernel build essentials", and "git". For Ubuntu: You can install them with the following command sudo apt-get update sudo apt-get install make gcc linux-headers-$(uname -r) build-essential git Users of Debian, Ubuntu, and similar (Mint etc) may want to scroll down and follow the DKMS instructions at the end of this document instead. For Fedora: You can install them with the following command sudo dnf install kernel-headers kernel-devel sudo dnf group install "C Development Tools and Libraries" For openSUSE: Install necessary headers with sudo zypper install make gcc kernel-devel kernel-default-devel git libopenssl-devel For Arch: After installing the necessary kernel headers and base-devel, git clone https://aur.archlinux.org/rtw89-dkms-git.git cd rtw89-dkms-git makepkg -sri If any of the packages above are not found check if your distro installs them like that. Installation For all distros: git clone https://github.com/lwfinger/rtw89.git cd rtw89 make sudo make install Installation with module signing for SecureBoot For all distros: git clone https://github.com/lwfinger/rtw89.git cd rtw89 make sudo make sign-install You will be prompted with a password, please keep it in mind and use it in the next steps. Reboot to activate the new installed module. In the MOK management screen: Select "Enroll key" and enroll the key created by above sign-install step When prompted, enter the password you entered when create sign key. If you enter wrong password, your computer won't be bootable. In this case, use the BOOT menu from your BIOS, to boot into your OS then do below steps: sudo mokutil --reset Restart your computer Use BOOT menu from BIOS to boot into your OS In the MOK management screen, select reset MOK list Reboot then retry from the step to make sign-install How to unload/reload a Kernel module sudo modprobe -rv rtw_8852ae sudo modprobe -rv rtw89core #These two statements unload the module Due to the behavior of the modprobe utility, it takes both to unload. sudo modprobe -v rtw_8852ae #This loads the module A single modprobe call will reload the module. Uninstall drivers For all distros: sudo make uninstall Problem with recovery after sleep or hibernation Some BIOSs have trouble changing the power state from D3hot to D0. If you have this problem, then sudo cp suspend_rtw89 /usr/lib/systemd/system-sleep/. That script will unload the driver before sleep or hibernation, and reload it following resumption. Option configuration IMPORTANT: If you have an HP or Lenovo laptop, Their BIOS does not handle the PCIe interface correctly. To compensate, run the following command: sudo cp 70-rtw89.conf /etc/modprobe.d/. Then unload the drivers and reload. You should see the options appended to the end of the rtw89_pci or rtw89pci load line. If it turns out that your system needs one of the other configuration options, then do the following: sudo nano /etc/modprobe.d/<dev_name>.conf There, enter the line below: options <driver_name> <<driver_option_name>>=<value> The available options for rtw89pci are disable_clkreq, disable_aspm_l1, and disable_aspm_l1ss. The available options for rtw89core are debug_mask, and disable_ps_mode. If after rebooting the wifi still doesn't work, it might mean that it was not loaded. To fix that, you will have to manually rebuild initramfs. To do that, execute one of the two commands, depending on how old/new your system is. mkinitrd # If you're running an older system dracut -f --regenerate-all # If you're running a newer system After rebuilding initramfs, reboot your computer and check if the wifi works properly now. Normally, none of these will be needed; however, if you are getting firmware errors, one or both of the disable_aspm_* options may help. They are needed when a buggy BIOS fails to implement the PCI specs correctly. When your kernel changes, then you need to do the following: cd ~/rtw89 git pull make clean make sudo make install ;or sudo make sign-install Remember, this MUST be done whenever you get a new kernel - no exceptions. These drivers will not build for kernels older than 5.8. If you must use an older kernel, submit a GitHub issue with a listing of the build errors, but be aware that doing so will cripple your device. Without the errors, the issue will be ignored. I am not a mind reader. When you have problems where the driver builds and loads correctly, but fails to work, a GitHub issue is NOT the best place to report it. I have no idea of the internal workings of any of the chips, and the Realtek engineers who do will not read these issues. To reach them, send E-mail to linux-wireless@vger.kernel.org. Include a detailed description of any messages in the kernel logs and any steps that you have taken to analyze or fix the problem. If your description is not complete, you are unlikely to get any satisfaction. One other thing - your mail MUST be plain test. HTML mail is rejected. DKMS packaging for debian and derivatives DKMS is commonly used on debian and derivatives, like ubuntu, to streamline building extra kernel modules. By following the instructions below and installing the resulting package, the rtw89 driver will automatically rebuild on kernel updates. Secure boot signing will happen automatically as well, as long as the dkms signing key (usually located at /var/lib/dkms/mok.key) is enrolled. See your distro's secure boot documentation for more details. Prerequisites: sudo apt install dh-sequence-dkms debhelper build-essential devscripts git-build-recipe This workflow uses devscripts, which has quite a few perl dependencies. You may wish to build inside a chroot to avoid unnecessary clutter on your system. The debian wiki page for chroot has simple instructions for debian, which you can adapt to other distros as needed by changing the release codename and mirror url. If you do, make sure to install the package on your host system, as it will fail if you try to install inside the chroot. Build and installation # If you've already built as above clean up your workspace or check one out specially (otherwise some temp files can end up in your package) git clean -xfd git deborig HEAD dpkg-buildpackage -us -uc sudo apt install ../rtw89-dkms_1.0.2-3_all.deb This will install the package, and build the module for your currently active kernel. You should then be able to modprobe as above. It will also load automatically on boot. A note regarding firmware Firmware from userspace is required to use this driver. This package will attempt to pull the firmware in automatically as a Recommends. However, if your distro does not provide one of firmware-realtek >= 20230117-1 or linux-firmware >= 20220329.git681281e4-0ubuntu3.10, the driver will fail to load, and dmesg will show an error about a specific missing firmware file. In this case, you can download the firmware files directly from https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/rtw89. 将上述内容翻译成中文
09-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值