Linux development: patching PDAs for Fun and Profit

Source: Internet
Author: User
Article title: Linux development: patching PDAs for fun and profit purposes. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
If you are new to embedded development, there may be too many available bootloader, distribution, file systems, and GUIs. However, these rich options are actually a gift that allows you to adjust the development or user environment to fully meet your needs. An overview of Linux embedded development will help you understand all these options.
  
Linux is developing steadily in the field of embedded development. Because Linux uses GPL (see references later in this article ), therefore, anyone who is interested in customizing Linux to PDA, handheld computers, or wearable devices can download their kernels and applications from the Internet for free and start porting or development. Many Linux improvements cater to the embedded/real-time market. These include RTLinux (real-time Linux), uclinux (Linux for non-MMU devices), and Montavista Linux (Linux distribution for ARM, MIPS, and PPC), ARM-Linux (Linux on arm) and other Linux systems (see references to link to these terms and other products mentioned in this article .)
  
Embedded Linux development involves three levels: boot loader, Linux kernel, and graphical user interface (or GUI ). In this article, we will focus on some basic concepts related to these three layers, and gain an in-depth understanding of how the boot loader, kernel, and file systems interact; it will also look at part of the many options available for file systems, GUIs, and boot loaders.
  
   Bootstrap loader
The bootstrap loader is usually the first piece of code executed on any hardware. In conventional systems such as desktops, Boot loaders are usually loaded into Master Boot Record (MBR, or load the first sector of the disk where Linux resides. In general, the BIOS transfers control to the boot loader on a desktop or other system. This raises an interesting question: who loads the boot loader (in most cases) on an embedded device without a BIOS?
  
There are two common technologies to solve this problem: specialized software and tiny boot code ).
  
Private software can directly interact with flash devices on a remote system and install the boot loader in a given location of flash. Flash devices are special chips that function like storage devices and can persistently store information-that is, they do not erase content during reboot.
  
This software uses the JTAG port on the target (embedded devices are usually called targets in embedded development). It is an interface used to execute commands from external input (usually from host machines. JFlash-linux is a popular tool for writing flash memory directly. It supports a large number of flash chips; it is on the host machine (generally i386 machine-in this article we call an i386 machine as the host) and use the parallel port to access the target flash memory chip through the JTAG interface. Of course, this means that the target needs a parallel interface to enable it to communicate with the host. Jflash-linux can be used in both Linux and Windows versions. you can run the following command on the command line to start it:
  
Jflash-linux <bootloader>
  
Some types of embedded devices have tiny boot code-according to several bytes of instructions-it will initialize some DRAM settings and enable a serial (or USB, or Ethernet) on the target) the Port communicates with the host program. Then, the host program or loader can use this connection to send the bootstrap loader to the target and write it into flash memory.
  
After installing it and giving it control, the bootstrap loader performs the following functions:
  
CPU initialization speed
Initializes the memory, including enabling the memory library and initializing the memory configuration registers.
Initialize the serial port (if any)
Enable command/data cache
Set stack pointer
Set the parameter area and construct the parameter structure and tag (this is an important step because the kernel uses the bootstrap parameter to identify the root device, page size, memory size, and more)
Perform POST (power-on self-check) to identify the existing device and report any problems
Support pending/restoring power management
Jump to the start of the kernel
  
The typical memory layout of a system with boot loader, parameter structure, kernel, and file system may be as follows:
  
Listing 1. typical Memory layout/* Top Of Memory */
  
Bootloader
Parameter Area
Kernel
Filesystem
  
/* End Of Memory */
  
  
  
  
Some popular and free Linux boot loaders on embedded devices include Blob, Redboot, and Bootldr (see references for links ). All these boot loaders are used in Linux based on arm devices, and Jflash-linux tools are required for installation.
  
Once the boot loader is installed in the target flash memory, it will execute all the initialization work we mentioned above. Then, it is ready to receive the kernel and file system from the host. Once the kernel is loaded, the boot loader transfers the control to the kernel.
  
   Set tool chains
Set the toolchain to create a build environment on the host machine for compiling the kernel and applications that will run on the target-this is because the target hardware may not have a host-compatible binary execution level.
  
A tool chain consists of a set of components used to compile, compile, and link the kernel and applications. These components include:
  
Binutils-a set of utilities used to operate binary files. They include utilities such as ar, as, objdump, and objcopy.
  
Gcc-gnu c compiler.
Glibc-all user applications are linked to the C library. Avoid using any C-library function kernel and other applications to compile without this library.
  
Build a tool chain to establish a cross-compiler environment. The local compiler compiles commands of the same processor as the local machine. The cross compiler runs on a certain processor, but can compile the commands of another processor. Setting the cross-compiler toolchain with repeated headers is not a simple task: it includes downloading source code, patching, configuration, compilation, setting header files, installation, and many other operations. In addition, such a thorough construction process has a huge demand for memory and hard disks. If there is not enough memory and hard disk space, many problems will pop up during the build phase due to problems such as relevance, configuration or header file settings.
  
Therefore, obtaining pre-compiled binary files from the Internet is a good thing (but it is not good that most of them are currently limited to ARM-based systems, but will change sooner or later ). Some popular pre-compiled tool chains include those from Compaq (Familiar Linux), LART (LART Linux), and Embedian (based on Debian but not related to it) tool chain-all these tool chains are used for arm-based platforms.
  
   Kernel settings
The Linux community is actively adding feature components and support for new hardware, correcting errors in the kernel, and making regular improvements in a timely manner. This results in a stable new release of the Linux tree every six months (or less than six months. Different maintainers maintain different kernel trees and patches for specific architectures. When you select a kernel for a project, you need to evaluate the stability of the latest release, whether it meets project requirements and hardware platforms, the degree of comfort from a programming perspective, and other uncertain aspects. It is also important to find all the patches that need to be applied to the basic kernel to adjust the kernel for a specific architecture.
  
   Kernel layout
The kernel layout is divided into the architecture-specific part and the architecture-independent part. In the kernel, the architecture-specific part is first executed. hardware registers are configured, memory ING is configured, architecture-specific initialization is executed, and control is transferred to the architecture-independent part of the kernel. The rest of the system is initialized during this second phase. The directory arch/under the kernel tree is composed of different sub-directories, each sub-directory is used for a different architecture (MIPS, arm, i386, iSCSI, PPC, etc ). Each of these subdirectories contains the kernel/And mm/subdirectories, they contain system-specific code to perform operations such as initializing memory, setting IRQ, enabling cache, and setting kernel page tables. Once the kernel is loaded and controlled, these functions are called first, and the rest of the system is initialized.
  
Based on available system resources and boot loader functions, the kernel can be compiled into vmlinux, Image, or zImage. The main difference between vmlinux and zImage is that vmlinux is an actual (uncompressed) executable file, zImage, however, is a self-decompressed compressed file that contains more or less the same information-it is only limited by the boot time of 640 KB for processing (usually forced by Intel. For all these authoritative interpretations, see the Linux Magazine article "Kernel Configuration: dealing with the unexpected" (see references ).
  
   Kernel link and Mount
Once the kernel is compiled for the target system, it is loaded into the target Flash memory by using the boot loader ), the kernel is loaded into the memory of the target system (in DRAM or flash memory ). The boot loader communicates with the host by using a serial, USB, or Ethernet port to transmit the kernel to the target flash memory or DRAM. After the kernel is fully loaded into the target, the boot loader will pass control to the address where the kernel is loaded.
  
The kernel executable file consists of many object files linked together. Object files have many sections, such as text, data, init data, and bass. These object files are all linked and loaded by a file called a linker script. The function of this linker script is to map the sections of the input object file to the output file. In other words, it links all input object files to a single executable file, load the sections of the executable file to the specified address. Vmlinux. lds is the kernel linker script that exists in the arch/<target>/Directory. it is responsible for linking each section of the kernel and loading them to a specific offset in the memory. The typical vmlinux. lds looks like this:
  
Listing 2. typical vmlinux. lds file OUTPUT_ARCH (<arch>)/* <arch> supported des architecture type */
ENTRY (stext)/* stext is the kernel entry point */
SECTIONS/* SECTIONS command describes the layout
Of the output file */
{
. = TEXTADDR;/* TEXTADDR is LMA for the kernel */
. Init: {/* Init code and data */
_ Stext =.;/* First section is stext followed
By _ init data section */
_ Init_begin = .;
* (. Text. init)
_ Init_end = .;

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.