Transplantation of Embedded Linux)

Source: Internet
Author: User

1. Basic concepts of transplantation
Migration refers to migrating software from one platform to another, including the following:
-- Port Data from one hardware platform to another;
-- Port Data from one operating system to another;
-- Porting from one software library environment to another.
2. Linux hardware platform

In the Linux kernel, each processor instruction set corresponds to an independent architecture, such as alpha, arm, i386, MIPS,
PPC. Each architecture can have several variants, variant, or hardware machines with different configurations, collectively referred to as sub-architecture. End with arm system
Example:
-- Variants includes ARM7TDMI, arm926ejs, Strongarm, and XScale;
-- Machine includes EDB7312, smdk2410, omap-h2.
3. hardware platform for C Program Impact

The processor word length is defined as the number of data digits that the processor can process at a time. The font length is equal to the width of the internal data path of the processor. It can be determined by the width of the General Register. The length of the processor may affect int,
Length of C type such as long. C Code You need to use a data type of the specified size. You can use an explicit length type, such as u8, S8, 162's, S16, u32, s32,
U64 and s64.
4. Data Alignment
Data Alignment means that the address of the index data block is an integer multiple of a specific size, for example:
-- 32-bit processor word alignment N * 4
-- Page alignment N * pagesize
-- Cache line alignment N * clinesize
Data access requires at least word alignment. In most cases, the compiler processes data access alignment. Example of Non-Alignment access:
-- Char a [10];
-- Unsigned long * PL = (unsigned long *) (a + 1 );
-- Unsigned L = * pl;
5. byte order
Byte order refers to the byte order in a word. Different hardware may adopt different byte orders, such:
-- X86 little-Endian
-- PPC big-Endian
Linux
The kernel puts the byte order of the hardware in <ASM/byteorder. h> and defines it, __big_endian or
_ Little_endian. There are several header files in include/Linux/byteorder/, which are defined:
-- U23 _ cpu_to_be32 (u32);/* convert CPU's byte order to bigendian */
-- U32 _ cpu_to_le32 (u32);/* convert CPU's byte order to littleendian */
-- U32 _ be32_to_cpu (u32);/* convert big-Endian to CPU's byte order */
-- U32 _ le32_to_cpus (u32);/* convert little-Endian to CPU's byte order */
6. Time
Time-related code in the software also affects porting. The platform-independent time expression method can improve code portability. In the Linux kernel, Hz is used to indicate the number of internal clocks per second. The following time descriptions are platform-independent:
-- Hz/* One second */
-- (2 * Hz)/* Two Seconds */
-- (Hz/2)/* half a second */
-- (Hz/100)/* 10 MS */
-- (2 * Hz/100)/* 20 MS */
7. Memory Page size
Linux
The virtual memory mechanism is used to manage the memory. The memory usage is based on pages. Different architectures have different page sizes. The commonly used 32-bit processor uses a page size of 4 kb. Some architectures can also support multiple
Page size. The kernel defines page_size and page_shift in <ASM/page. h>:
-- Page_size indicates the page size;
-- Page_shift indicates the offset of the page number in the address;
-- Page_size = 2 ^ page_shift.
8. Linux OS migration
(1) tool chain migration
-- Binutils (assembler, linker ..)
-- GCC (compiler, libgcc)
-- Glibc/uclibc
(2) kernel porting
-- Arch implementation
-- Drivers porting
(3) porting applications
-- C program recompile
-- Implement absent Library
9. Linux kernel platform-related code
The Linux Kernel provides good support for multiple platforms. The kernel is unified with external interfaces and has nothing to do with the platform. Most kernel code is not related to the platform. The main architecture-related code exists in:
-- ARCH/architecture
-- Include/ASM-Architecture
For example, the platform-related code of the arm system is:
-- ARCH/ARM
-- Include/ASM-arm
10. Porting existing code to the Linux Kernel
There are some restrictions on porting existing code to the kernel:
(1) There is no standard C library support in the kernel;
(2) There is no memory protection like a user program in the kernel;
(3) floating point operations are inconvenient in the kernel;
(4) The Kernel stack is fixed and limited;
(5) In the kernel, programmers need to consider the competition and risks brought about by concurrency, as well as synchronization issues.
11. Linux kernel porting
Linux Kernel code can be divided into platform-related and platform-independent parts. The vast majority of Linux kernel code is platform-independent and can be shared by various platforms, such:
-- Scheduling Algorithm
-- Memory Management
-- I/O subsystem
-- Network protocol stack
Code dependent on specific hardware is differentiated by Conditional compilation in Linux:
-- Arch = x86: Open the code unique to x86
-- Arch = arm: enables the unique arm code.
12. Linux kernel arch directory
Go to the arch directory, and each architecture code has a subdirectory:

Go to the arm directory. In the ARM architecture, you can see many sub-arch sub-directories:


13. implement Sub-arch
In the sub-arch sub-directory, take the mach-s3c2410 as an example. A hardware platform supports the following hardware-related files:
Mach-s3c2410.c, IRQ. C, clock. C, DMA. C, gpio. C, PM. C, sleep. C, time. c
At the same time in include/ASM-arm/arch-s3c2410 to achieve:
-- Low-level IRQ helper macros
-- Debug output macros
-- IRQ Number definations
-- DMA definations
-- Memory Mapping/Translation
-- Reset operation
-- Idle Function
14. mach-smdk2410
In the mach-smdk2410.c, we need to define the following:
Smdk2410_iodesc, which describes all the Reserved Device Io addresses. This descriptor is very important for us to transplant a specific target board. The description file also defines:
-- Phys_ram
-- Phys_io
-- Io_pg_offst
-- Boot_params
-- Map_io
-- Init_irq
-- Timer
15. map_io
In map_io, you must initialize the device Io. The smdk2410_iodesc descriptor is used here. This descriptor is an array in which each item describes the IO ing of a device. In addition, the UART settings of the clock PLL can be called in map_io.
16. init_irq
In this call, the initialization of the interrupt will be completed:
-- Clear the interrupt pending register
-- Register the main interrupt handler
-- Set device interruptions in the system
17. Timer
Timer is a sys_timer structure, which includes the following members:
-- Init: Call and execute hardware-related timer initialization;
-- Offset: the number of microseconds that have elapsed since the last timer interruption;
-- Resume: Call and execute the timer recovery operation after system wake-up, which is generally the same as the initialization in init.
18. porting applications
Ideally, the program can not be changed, or just install some patches, and then instruct the compiling environment to compile according to the requirements of the target environment.
-- Busybox
-- Bash
-- Sysv init
It is often more difficult to port applications that depend on certain platform features. For example:
-- Graphics library
-- Code optimized for speed, such as the codecs
The cross-platform nature of the software programming language directly affects the portability of the software. There are also other factors, such as the degree of openness of software protocols/source code.
19. FAQs about application porting
Software dependencies cause portability problems:
-- C library version Problems
-- Problems caused by the graphics library
-- Problems caused by software dependency on certain services
Network applications are processed on the little-Endian platform, and data transmitted over the network is big-Endian.
The software depends on the features of a specific platform.
Differences in the Data Consistency model of the platform.

Related Article

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.