Production and Application of patches in Linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. This is because there are several common files to be modified during the u-boot porting process. It is too troublesome to manually modify them each time. Patch creation can solve this problem.
The collection of learning materials is relatively simple. The method 1 is similar to this kind of elementary problem. There are a lot of online materials. google or baidu searches for valuable materials and then selects valuable materials. The method 2 is to read man's online documents. To complete the collection, of course, we will eventually conduct an experiment on our own Linux system, make a summary, and digest and absorb your own things. To remove such a wrong idea, you must learn it all. You need to know that it is impossible to learn all at once. You can only learn the most common ones first. In the future, you will gradually enrich your learning experience and eventually reach a relatively high level. The principle is to apply what you have learned on a daily basis to promote learning.
First, describe diff and patch. All options in the man online document will not be described here, which is unnecessary. In the 99% period, we only use a few options. Therefore, you must learn these options.
1. diff
--------------------
NAME
Diff-find differences between two files
SYNOPSIS
Diff [options] from-file to-file
--------------------
Simply put, the diff function is used to compare the differences between the two files, and then record them, that is, the so-called diff patch. Syntax format: diff [Option] source file (folder) Destination File (folder), that is, to patch the source file (folder) to make it into the destination file (folder ), the term is "Upgrade ". The following describes the three most common options:
-R is a recursive option. With this option set, diff compares all the corresponding files in the source code directories of two different versions, including subdirectory files.
-N option ensures that the patch file correctly processes the files that have been created or deleted.
-U option creates patch files in a uniform format, which is more compact than the default format.
2. patch
------------------
NAME
Patch-apply a diff file to an original
SYNOPSIS
Patch [options] [originalfile [patchfile]
But usually just
Patch-pnum
------------------
In short, patch refers to the use of patches made by diff to realize conversion between source files (CLIPS) and target files (CLIPS. This means you can have a source file (folder)?> The target file (folder) or the target file (folder)?> Source file (folder ). The following describes the most common options:
-P0 option: Find the target file (folder) from the current directory)
-The p1 option should ignore the first-level directory and start searching from the current directory.
If you use the-p0 parameter, it means to find a folder named old from the current directory, and find the pcitable file under modules under it to execute the patch operation.
If the-p1 parameter is used, ignore the first-level directory (regardless of the old directory), find the modules folder from the current directory, and find pcitable under it. The premise is that the current directory must be the directory where modules is located. The diff patch file can be located anywhere, as long as the path of the diff patch file is specified. Of course, you can use relative paths or absolute paths. However, I usually use relative paths.
-E indicates that if an empty file is found, delete it.
-The "R" option indicates that the "new" and "old" files in the patch file need to be replaced now (in fact, the new version is patched to make it an old version)
The following examples are used to analyze and solve the problem. There are two types: patching a single file and patching multiple files in the folder.
Environment: log on with an armlinux user under RedHat 9.0.
The directory tree is as follows:
| -- Bootloader
| -- Debug
| -- Images
| -- Kernel
| -- Program
| -- Rootfiles
| -- Software
| -- Source
| -- Sysapps
| -- Tmp
'-- Tools
Next, create a patch folder under the program folder as an experiment, and then enter the patch folder.
The patch header contains two lines starting with ---/++ to indicate the files to be patched. --- The beginning indicates the old file, and the beginning of ++ indicates the new file.
Multiple patches in a patch file
A patch file may contain many sections starting with ---/++, each of which is used for a patch. Therefore, a patch file can contain many patches.
Block
The block is the part to be modified in the patch. It usually starts and ends with something that does not need to be modified. They are only used to indicate the location to be modified. They usually start with @ and end with another block or a new patch header.
Block indent
Blocks will be reduced into one column, and this column is used to indicate whether to add or delete this row.
First column of the block
+ Indicates that this line is to be added.
-Indicates that this row is to be deleted.
There is no plus sign or minus sign, indicating that this is just referenced and does not need to be modified.
Patch the kernel. When creating a cross-compilation toolchain, one step is to patch the kernel. At that time, I was not very familiar with it, but now it is clear. Refer to the previous article "establishing a development tool chain based on ARM + Linux embedded development".
1. decompress the package because the released patch files are compressed using gzip.
$ Gunzip ../setup-dir/patch-2.4.21-rmk1.gz
2. Enter your kernel source code directory.
$ Linux-2.4.21 cd
3. Patch
$ Patch? P1 <../setup-dir/patch-2.4.21-rmk1
After the patch is installed, check whether the file is rejected, that is, check the existence of the. rej file. Run the following command:
$ Find.-name *. rej
If it is found, it will be output to the standard output terminal, the default screen. Of course, you can also use redirection to output to a specified file, such as reject.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.