cjktty
18 Sep 2015 • Leave CommentsAn alternative is Univt patch.
In this post, we will show how to extract cjktty.patch from a patched kernel. Afterwards, we will apply the extracted patch to our own kernel. During the process, we might look into several relevant commands.
- Suppose our current system kernel is 4.0.5. We will generate a cjktty.patch suitable for this kernel.
-
The patched kernel is linux-cjktty from which we will extract the desired patch.
According to past experience, cjktty.patch for kernel 3.18 ~ 3.19 fits 4.0 as well. We will choose the branch 3.19-utf8.
-
Clone the chosen branch locally.
$ cd ~/workspace $ git clone --branch 3.19-utf8 --depth 4 https://github.com/Gentoo-zh/linux-cjktty.git
--branch
: we only need branch 3.19-utf8. If not specified, git will clone all the branches, spending a day maybe depending on bandwidth.--depth
: from the repository, we find the the top 3 commits are enough to extract our cjktty.patch. We MUST clone at least the top3 + 1 = 4
commits.
-
git log
commit 9a5a7d3215307e28df3aea6ac09931a4d55e151e Author: microcai <microcai@fedoraproject.org> Date: Thu Jan 13 05:18:45 2011 +0800 [vt] add cjk font that has 65536 chars commit 3dbe651a011ac6b6bbd976d96b5d08fb2baf709c Author: microcai <microcai@fedoraproject.org> Date: Mon Feb 21 12:58:18 2011 +0800 [vt] diable setfont if we have cjk font in kernel commit a2553800e3e8ea1d13f3e3a4211599a3268ce9a2 Author: microcai <microcaicai@gmail.com> Date: Fri Jan 9 12:45:07 2015 +0800 [vt] fix 255 glyph limit, prepare for CJK font support commit d8cf08a565defc2f9810b9ecd33b1b3211b029e1 Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Thu Mar 26 14:00:21 2015 +0100 Linux 3.19.3
From the output, we can see only 4 commits history as expected. We will extract the patch from the top 3 commits authored by microcai.
-
Extraction
~ $ git diff d8cf08a565defc2f9810b9ecd33b1b3211b029e1 9a5a7d3215307e28df3aea6ac09931a4d55e151e -- > cjktty.patch # or ~ $ git diff HEAD~3 -- > cjktty.patch # or ~ $ git format-patch HEAD~3 --stdout > cjktty.patch # or ~ $ git format-patch -3 HEAD --stdout > cjktty.patch
- Pay attention to the order of commit ID (SHA1 hash). Put the earliest commit ID (4th) before the latest one (HEAD).
HEAD~3
means extract patch from top to 3rd commits (inclusive). The latest ID (HEAD) precedes the 3rd one.- format-patch is similar to git diff.
-n <commit>
is equivalent of<commit>~n
. The patch file orgnization is a little different from that of git diff. - We recommend to use format-patch to include commit messages, making it more appropriate for most scenarios involving exchanging patches over the Internet. Details refer to reference 1.
-
Test the patch
Attention please; the
-p [num]
must be right, otherwise the wrong files would be patched even when no errors prompt up. Inpsect the patch file to see the pathname.~ # cd /usr/src/linux/ # determine the '-p' option value ~ # less /path/to/cjktty.patch ~ # patch --verbose -p1 --dry-run < /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --stat /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --numstat /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --check /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --summary /path/to/cjktty.patch
When testing patch file, it might remind errors like:
Hunk #17 FAILED at 2708. # or error: patch failed: drivers/video/console/fbcon.c:2689 error: drivers/video/console/fbcon.c: patch does not apply
- Error number 2708 (reported by patch) refers to line number in Linux-cjktty sources, while 2689 (reported by git apply) in Gentoo-sources. Search 2708 or 2689 in patch file and check either/both kernel sources.
- Some error are caused by extra whitespaces, especially those on blank lines.
By default, all pathnames will be patched. Sometimes, we can patch only perticular pathnames by
git apply --include <pattern>
. patch does not support this feature.~ # git apply --verbose --whitespace=warn -p1 --include '*myfile.lua' --stat /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --include '/path/to/dir' --stat /path/to/cjktty.patch
Vice versa, we can
--exclude <pattern>
:~ # git apply --verbose --whitespace=warn -p1 --exclude <pathname-pattern> --stat /path/to/cjktty.patch
If both
--include
and--exlude
options are present, the first match determines if a pathname is patched or not. -
Apply the patch
~ # cd /usr/src/linux/ ~ # patch --verbose -p1 < /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 /path/to/cjktty.patch
-
We can, revert the patch by the
-R
option.~ # cd /usr/src/linux/ ~ # patch --verbose -p1 --dry-run -R < /path/to/cjktty.patch ~ # git apply --verbose --whitespace=warn -p1 --check -R /path/to/cjktty.patch
You can reverse a patch by adding
-R
argument. -
If /usr/src/linux source is polluted by patch error, you can re-install the kernel source.
We cannot reverse a patch error.
# emerge -av --unmerge gentoo-sources-4.0.5 # rm -r /usr/src/linux-4.0.5-gentoo # emerge -av gentoo-sources-4.0.5
- Pay attention to use unmerge instead of depclean. The former will keep package dependencies.
- Maybe we can just extract the source code to /usr/src/linux.
- Reference