如何在本機make kernel driver
debug usb轉rs485
更新記錄
item | note |
---|---|
20161024 | 第一版 |
20161107 | 新增: fedora_kernel |
目錄
- make kernel
- build fedora kernel (Building a Kernel from the source RPM )
- Building a kernel from the exploded git trees
- fedora_kernel
- ch341
- 參考
make kernel
下載kernel
apt-get
kernel download1
apt-get source linux-image-$(uname -r)
make
1
2make menuconfig
make -j8 > /dev/null
build fedora kernel (Building a Kernel from the source RPM )
- uname -r
1
2[erwin@localhost BUILD]$ uname -r
4.6.5-300.fc24.x86_64
Get the Source
If you’ve never built an RPM before, prepare an RPM package-building environment in your (non-root) home directory by running the following command:
rpmdev-setuptree
建立rpmbuild目錄1
2
3
4
5
6
7[erwin@localhost rpmbuild]$ tree
.
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS下載kernel rpm source
1
koji download-build --arch=src kernel-$(uname -r)
將rpm解開
將會解到 ${HOME}/rpmbuild/SOURCES 及 ${HOME}/rpmbuild/SPECS1
rpm -Uvh kernel-$(uname -r).src.rpm
解開內容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25[erwin@localhost rpmbuild]$ tree
.
├── BUILD
├── RPMS
├── SOURCES
│ ├── 0001-drm-i915-Reorganize-WM-structs-unions-in-CRTC-state.patch
│ ├── 0002-drm-i915-Rename-s-skl_compute_pipe_wm-skl_build_pipe.patch
│ ├── 0003-drm-i915-gen9-Cache-plane-data-rates-in-CRTC-state.patch
│ ├── 0004-drm-i915-gen9-Allow-calculation-of-data-rate-for-in-.patch
│ ├── 0005-drm-i915-gen9-Store-plane-minimum-blocks-in-CRTC-wm-.patch
│ ├── 0006-drm-i915-Track-whether-an-atomic-transaction-changes.patch
│ ├── 0007-drm-i915-gen9-Allow-skl_allocate_pipe_ddb-to-operate.patch
..
│ ├── tcp-make-challenge-acks-less-predictable.patch
│ ├── tipc-fix-an-infoleak-in-tipc_nl_compat_link_dump.patch
│ ├── usb-phy-tegra-Add-38.4MHz-clock-table-entry.patch
│ ├── USB-usbfs-fix-potential-infoleak-in-devio.patch
│ ├── watchdog-Disable-watchdog-on-virtual-machines.patch
│ ├── x509.genkey
│ ├── x86-Lock-down-IO-port-access-when-module-security-is.patch
│ ├── x86-Restrict-MSR-access-when-module-loading-is-restr.patch
│ └── xen-pciback-Don-t-disable-PCI_COMMAND-on-PCI-device-.patch
├── SPECS
│ └── kernel.spec
└── SRPMS
Copy the Source Tree and Generate a Patch
This step is for applying a patch to the kernel source. If a patch is not needed, proceed to “Configure Kernel Options”.
此處建立new及orig目錄是為了產生patch file
Configure Kernel Options
- cd ~/rpmbuild/BUILD/kernel-$ver.$fedver/linux-$ver.$subver.$fedver.$arch/
- cp /boot/xx.config .config
- Copy the config file to ~/rpmbuild/SOURCES/:
1
cp .config ~/rpmbuild/SOURCES/config-`uname -m`-generic
Build the New Kernel
- To specify that only a specific kernel should be built:
1
rpmbuild -bb --with <option> --target=`uname -m` kernel.spec
Building a kernel from the exploded git trees
下載之後,checkout到特定版本,build kernel跟一般的build法一樣
git clone
1
git clone git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git
git checkout
checkout kernel-4.6.5-300.fc24 1
2note
1
2
3
4
5
6
7Fedora keeps a git tree containing Fedora patches applied on top of the vanilla sources.
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git
$ git checkout -b my_branch kernel-4.7.4-200.fc24
You can now build the kernel following regular kernel instructions. This tree is useful for generating patches that can be applied to the kernel.spec.
fedora_kernel
How to Compile Linux Kernel from Source to Build Custom Kernel
下載fedora kernel
1
git clone git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git
checkout 特定版本
依據uname -r來決定要make版本1
git checkout kernel-4.6.5-300.fc24
make
1
make -j8 > /dev/null
產生vmlimuz
產生arch/x86/boot/bzImage(即要更換vmlimux)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[erwin@localhost fedora]$ make bzImage
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
DESCEND objtool
CHK include/generated/compile.h
CHK include/generated/uapi/linux/version.h
TEST posttest
Succeed: decoded and checked 2123901 instructions
TEST posttest
arch/x86/tools/insn_sanity: Success: decoded and checked 1000000 random instructions with 0 errors (seed:0x300d2f0b)
Kernel: arch/x86/boot/bzImage is ready (#1)
[erwin@localhost fedora]$更新/boot
make install
會先backup原本vmlinuz 及 System.map1
sh ./arch/x86/boot/install.sh 4.6.5+ arch/x86/boot/bzImage System.map "/boot"
ch341
USB serial driver
- USB serial driver
1
2
3
4
5
6
7
8
9Winchiphead CH341 Driver
This driver is for the Winchiphead CH341 USB-RS232 Converter. This chip
also implements an IEEE 1284 parallel port, I2C and SPI, but that is not
supported by the driver. The protocol was analyzed from the behaviour
of the Windows driver, no datasheet is available at present.
The manufacturer's website: http://www.winchiphead.com/.
For any questions or problems with this driver, please contact
frank@kingswood-consulting.co.uk.
ch341.ko
lsmod
usbserial -> ch3411
2
3
4
5
6
7
8
9
10$ lsmod | grep ch341
ch341 16384 0
usbserial 53248 2 ch341,ftdi_sio
$ lsmod | grep usbserial
usbserial 53248 2 ch341,ftdi_sio
$ lsmod | grep ftdi_sio
ftdi_sio 53248 0
usbserial 53248 2 ch341,ftdi_sio先移除原本的ch341.ko
1
rmmod ch341
install
1
insmod ch341.ko