How to compile LinuxBootloader when Linux is transplanted

Source: Internet
Author: User
Linux programming and kernel information-Linux general technology-how to compile LinuxBootloader during Linux porting. The following is a detailed description. 1. Overview

Linux runs in protection mode, but it is in real mode when the machine starts to reset. Therefore, the work of writing bootloader is also done in the real mode.

Linux Kernel has a variety of formats, such as the old-fashioned zImage and the new bzImage. The biggest difference between them is the size limit on the kernel. Because the zImage kernel needs to be placed within 1 MB of memory in the real mode, its volume is limited. At present, most of the kernel formats used are bzImage, which has no 1 MB memory limit. The following sections take bzImage as an example.

   2. bzImage kernel structure

The bzImage kernel is divided into three parts from the front to the back. The first 512 bytes are called bootsect. This is the bootloader used when a floppy disk is used to guide linux. If it is not booted from a floppy disk, this part is useless, the default values of kernel startup options generated during compilation are stored. The 512 * n Bytes starting from 512 bytes are called the setup part, which is the real mode part of the Linux kernel and runs in the real mode, the main function is to prepare an environment for Linux kernel startup in protected mode. This part will switch to the protection mode and jump to the kernel execution in the protection mode. The last part is the kernel of the protection mode, that is, the Linux kernel in the true sense. The size of n can be obtained from the rear half of bootsect. For details, refer to linux boot protocol.

   3. Overview of the guiding process

Step 1: open the refrigerator door; Step 2: Put the elephant in the refrigerator ...... Don't laugh. The process is so simple. First, copy the setup part of the Linux kernel to the address starting from 9020 H: 0, and then copy the kernel in the protection mode to the address starting from 1 MB, then, set the content of the parameter area according to the content of Linux Boot Protocol 2.03. The base address is 9000 H: 0, and then use an ljmp $0x9020, $0 to jump to the setup section, the rest is linux's own ^ _ ^. It's really easy!

   4. the linux/I386 BOOT PROTOCOL

This is the Protocol we use to guide linux. It is located in: deleetation/i386/boot.txt. It details all the knowledge needed to guide linux. For CPU of other architectures, there must be something similar, just follow the method in this article.

   5. Details 1: Basic boot parameters

Of course, the Linux kernel can be started without specifying any parameters, but this may start into a framebuffer mode that we do not support, resulting in no screen display; it is also possible that the wrong root partition fails to be mounted, resulting in No Init Found's kernel panic. So we must specify something.

If you are a lazy person like me, you can copy the bootsect directly to the 9000 H: 0 location. When using a soft disk boot, the hacker will copy the token to this location. For details, see boot.txt.

The first is the root location. Here, bootsect_pos points to the 9000 H: 0 address.
  
Bootsect_pos [0x1fc] = root_minor;
Bootsect_pos [0x1fd] = root_major;

Root_minor and root_major are the root master and secondary device numbers respectively.

Current display mode:

Bootsect_pos [0x1fa] = 0xff;
Bootsect_pos [0x1fb] = 0xff;
 
The two values are equivalent to the value of the guiding parameter vga = 0xHHH, and the two 0xff represent the text mode.
  
Bootsect_pos [0x210] = 0xff;
  
This is to set the type of your bootloader. In fact, as long as it is not 0, it means that the loader is too old to guide the new kernel. After setup finds this, it will stop. According to the specification, you should write it as 0xff, which indicates the unknown boot loader. If your bootloader has an officially assigned type id, write your own value.

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.