Compile linux0.00 kernel (the Linux kernel completely analysis-Based on 0.12 kernel ") linux-0.00-041217 and linux-0.00-050613

Source: Internet
Author: User

Compile the linux0.00 kernel (full Linux Kernel Analysis-based on the 0.12 kernel)

I have bought a fully-analyzed Linux kernel written by Zhao Ke-based on the 0.12 kernel. It seems that the principles of the first four chapters have never had the courage to practice them by myself. Recently, I have made up my mind to take a good look at this book, and I plan to write some study notes to record some gains and experiences in the course of learning. In this way, I can force myself to review what I have learned, alternatively, you can share your learning experience and some problems encountered during the learning process with other comrades who are learning the Linux kernel. Today is the second day I actually learned about Linux. I learned how to compile the book 140 ~ 146 page Linux-0.00.

First, after several hours of work, I finally entered the code in the book correctly, and then compiled it.

OK. The Boot compilation connection is successful. Next, the head is ready.

Unfortunately, a compilation error occurs. Modify the source code as prompted:

Row 3: movl
Scr_loc, change % Bx to movl
Scr_loc, % EBX

Row 3: movl $65, % Al
Changed to movb $65, % Al

Row 3:
Movl $66, % Al changed to movb $66, % Al

At the same time, change all. Align 2 in head. s to. Align 4 and. Align 3 to. Align 8.

Then compile the connection head. s again.

Although the compilation is successful, the connection fails. By searching for information, the solution is finally found:

Add a line in the. text section of the program:. globl startup_32

Then, use the command LD-M elf_i386-ttext 0-e startup_32-O head. O to compile.

Okay. So far, both the boot and head have been compiled successfully. Run the following command to write the binary code to the disk and run the following command on the 907 page:

$: Sudo dd BS = 32 If = Boot of =/dev/fd0 skip = 1

$: Sudo dd BS = 512 if = head of =/dev/fd0 skip = 2 seek = 1

Write successful.

That's great. Now we can test it on the VM. However, unfortunately, I have no normal boot on virtualbox and bochs 2.3.6, and the running status is always black.

Where is the problem? The website of Dr. Zhao has downloaded linux-0.00-050613.zip. First, write the boot and head files generated by the self-compiled connection to the image file VFD (2). IMG on the floppy disk and write the image to VFD. IMG. Comparing VFD. IMG and VFD (2). IMG using the binary file Comparison Program ultracompare found that the content of the two files is different from 0x00000200, as shown in the preceding section:

This indicates that boot has been correctly written to both imgfiles, but an error occurred while writing the head.

The preliminary assumption is that an error is located when the file is written. This assumption is verified by searching B8 10 at 0x00000200 in VFD, as shown in:

The figure shows that the data starting from x00000200 in VFD. IMG is the same as the data starting from 0x00000e00 in VFD (2. It indicates that the error is indeed caused by dislocation.

Now, the problem is solved. Run the hexdump command to view the head binary code, as shown below:

$: Hexdump head> head.txt

Head.txt contains the following content:

We can see that the data starting from 0x0001000 is exactly what we need. We only need to write the data starting from 0x0001000 to x00000200 in a floppy disk (also an imgfile:

$: Sudo dd BS = 32 If = Boot of =/dev/fd0 skip = 1

$: Sudo dd BS = 512 if = head of =/dev/fd0 skip = 8 seek = 1

OK. The write is successful. Perform the test again. The test results in virtualbox are as follows:

 

 

Slave note:

The above article is a reprinted note from elsewhere. In general, the writing is more detailed. Here are some additional explanations.

1. The above is the linux-0.00-050613 development kit of teacher Zhao Yu, which uses two dd commands in makefile to generate the image file (This file contains the boot part and the main part of the system, in fact, this system is head. o ). The difference between compiling this system with GCC of the advanced version and gcc1.4 (linux-1.11 built-in compiler version that can directly compile the linux-0.00 without any modification) is that, the preceding method generates executable files in the ELF format, and. the header of the out executable file is different. The image file only needs the content after. Text of the system file, and does not need the previous header information. Therefore, you need to remove the header information. The A. out file generated by using gas and GLD has a header information of B, which is the first command required for operating the OS. Therefore, you need to use

$: Sudo dd BS = 512 if = head of =/dev/fd0 skip = 2 seek = 1

Remove the useless content of 512 * 2B. Where is the text address of the System File in ELF format? You can use the readelf tool in Linux to view the system information and obtain the table:

Section headers:
[Nr] Name type ADDR off size es flg LK INF
L
[0] Null 00000000 000000 000000 00 0 0
0
[1]. Text progbits 00000000 001000 00159a 00 ax 0 0
8
[2]. Data progbits 0000259c 00259c 000000 00 wa 0 0
4
[3]. BSS nobits 255.259c 00259c 000000 00 wa 0 0
4
[4]. shstrtab strtab 00000000 00259c 00001c 00 0 0
1
The text segment starts from 0x001000, that is, 4096.

2. If you use the linux-0.00-041217 Development Kit to compile under the current Ubuntu or RedHat, in addition to the modifications made above, you also need to modify build. C program, because this development kit does not use the DD command to generate an image. Instead, it uses a Linux build program to extract the required parts from the boot and system files and generate an image. You need to modify the build. C source program. When the original build. C program reads the system file, it first reads the 1024-byte file header, and then writes the remaining content to the image. When the system is in ELF format, the offset of text is 0x1000, that is, 4096b. before writing, you need to read four 1024 values. The method is as follows:

If (ID = open (argv [2], o_rdonly, 0) <0)
Die ("unable to open 'system '");
If (read (ID, Buf, gcc_header )! = Gcc_header)
Die ("unable to read header of 'system1 '");
If (read (ID, Buf, gcc_header )! = Gcc_header)
Die ("unable to read header of 'system2 '");
If (read (ID, Buf, gcc_header )! = Gcc_header)
Die ("unable to read header of 'system3 '");
If (read (ID, Buf, gcc_header )! = Gcc_header)
Die ("unable to read header of 'system4 '");

You also need to comment out the statements that determine the. Out header:

// If (long *) BUF) [5]! = 0)
// Die ("non-GCC header of 'system '");

Save and make, and start bochs from the image file.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.