Linux System Build Learning Notes

Source: Internet
Author: User

Embedded System Architecture: (Hardware + software)
Application software layer:
Application
GNU C Library (glibc)
File system:

System layer:
API (Systern call Interface)
OS Core + Power mannager+ File Manager + GUI Mannager
TCP/IP HTTP WAP DataBase Browser
DDI (Device drver Interface)
Board-level support: Bsp:board supporting Package
OEM adaptation Layer
Device Driver Inerface
Bootloader
Hardware layer:
Cpu,exiternal devices

Embedded Linux System composition:

Boot load: Bootloader:vivi u-boot
Kernel: Kernel
Root file system: Yaffs

System Application: Web server
Graphical Interface System: QTE


Build an embedded Linux cross-development environment based on ARM:

Building an embedded Linux development environment = Building a cross-compilation environment
The target machine has fewer resources and the development machine (PC) cannot compile and run.
PC programming debugging, download to the target machine to run, to achieve cross-platform development.

Contains:
Development machine Linux operating system: Redhat,fedora,ubuntu

Basic services:
TFTP file transfer, download kernel or file
Install the XINUETD service first.
xinetd-2.3.14-18.fc9.i386.rpm
tftp-server-0.48-3.fc9.i386.rpm
tftp-0.48-3.fc9.i386.rpm
Nfs:network File System network filesystem (installed by default)
The root filesystem of the development Board is hooked up to the shared directory of the PC.


Basic software: Qemu: Simulating an ARM Development Board operating environment on a PC
If you do not have a zlib library, install the Zlib library first.
Zlib-1.2.7.tar.gz
Mini2440-head1.tar.gz

Cross-compilation Toolchain (device provides an agreed system)
Arm-linux-gcc-4.3.2.tgz
Cross compiler arm-linux-gcc,arm-linux-g++
Cross Assembler: Arm-linux-as
CROSS linker: ARM-LINUX-LD
Debugger: GDB
Library: Lib
Binary tools: Binutils:arm-linux-readelf,arm-linux-ar,arm-linux-ranlib,arm-linux-objcopy


The various source code required for development:
Kernel Source code: LINUX-2.6.32.2-MINI2440-20100113.TGZ
QT Tool Source code: x86-qtopia-20100108.tar.gz
Arm-qtopia-20100108.tar.gz
File system source code: BUSYBOX-1.13.3-MINI2440.TGZ
Test instance Program source code: EXAMPLES-20100108.TAR.GZ
Boot loader source code: vboot-src-20100106.tar.gz
Bootloader.tgz
Target file System source code: ROOT_QTOPIA-20100108.TAR.GZ

Various tools for developing your needs:
Target file system Image authoring Tool Mkyaffs2image: Make the Root_qtopia directory into an image file (can be burned into the target board)
Mkyaffs2image.tgz
Install logo maker Tool Logomaker:
Logomaker.tgz


---BootLoader---*******************

The first software code that runs after booting, initializes the hardware, and reads into the operating system. Based on a specific hardware platform.

Nand Flash storage structure:
BootLoader +boot Parameters
Kernel
Root filesystem


Vivi: Korea Mizi Company, acquired by Samsung
Redboot: Red Hat company embedded Debug Program
U-boot:univeral Bootloader Germany Denx Group developed, supporting a variety of processors. Multiple embedded operating systems.


Two modes:

Boot load mode: (Bootstrap autonomous)


Stage1 (assembly): Address: 0x00000000
1. Basic Hardware Device Initialization
Turn off interrupts, turn off the watchdog, configure the PLL, configure memory, initialize the operating mode stack, configure interrupts, copy the RW segment, initialize the Zi segment
2. Preparing RAM space for phase 2 code
3. Copy stage2 code into RAM space
4. Set up the stack
5. Jump to Stage2 's C program entry point

Stage2 (C language):
1. Initialize the hardware used in this phase
At least one serial port, network, USB, etc., used and user I/O output information.
2. Detect the system memory map.
3. Read the kernel and root file system images from Flash to ram space.
4. Start this parameter for kernel settings
5. Calling the kernel
CPU Register: R0 is 0;R1 for machine type ID;R2 as startup parameter. (Machine type See Linux/arch/arm/tools/mach-types catalogue)
CPU Mode: SVC mode, disable interrupt Irqs,fiqs
MMU and Cache settings: The MMU must be closed, the command cache can not be opened, the data cache must be closed.


Download mode: (downloading)


The 1.supervivi command "a" can download files to Nandflash, while "D" is only downloaded to memory and executed
2. Download line download to flash with USB, and serial cable to transfer commands, interact with the user, to control

System Boot Mode:
1. is using Flash storage device
2. Using a disk device
3. Guided through the network, suitable for the development phase
1. Download the system kernel via TFTP
2. Mount the root file system via NFS while the kernel is running

U-boot Source code directory structure:
Board: Development Board-related files
CPU:CPU Schema-related code
Common: Implementing Uboot Support Commands
Disk: Support for disks
Doc: Document Directory
Drivers: Device driver
Fs: File system support
Include: Header File
Configs: Development Board-related configuration header file
ASM:CPU architecture-Related header files
NET: network protocol stack related code, TFTP,RARP
Tool: Generate Uboot Tools source code, MKIGMAGE,CRC and so on.

Makefile:1. Performing various board-related configurations
2. Compile and build the Uboot.bin file

To generate Uboot.bin steps:
1. Select the board you want to use
Make Smdk2410_config

2. Compile Build U-boot.bin
Make cross_compile=arm-linux-


Uboot packages for MINI2440 that have been ported:
Tekkamanninja-u-boot-2009.11_tekkaman-16deca6.tar.gz
1. Use: Under the board has done a/tekkamanninja/nini2440/
Modify the makefile file and compile the tool for arm-linux-
Make Mini2440_config
Make

2. Modify it yourself.
1.board set up its own Development Board directory my2440, copy the similar various board files, change the name my2440.c
2. Add your own my2440.h header files by copying under Include/configs
3. Modify the first stage code CPU/ARM920T/START.S
4. Modify the second-stage code LIB_ARM/BOARD.C
5.Makefile modified: 1.board under my2440 makefile in the build target file
2. Compilation of comprehensive resources in top-level makefile
6. Generate the U-boot.bin file as described above.

U-boot Code Analysis:
First stage: Cpu/arm920t/start.s
Starting from Start_code, _start_armboot jumps to. c files

Set the CPU mode to SVC mode
Turn off the watchdog
Disable all interrupts
Set the frequency to the CPU
Copy yourself to ram
Configuring the Memory Area control register
Configuration of the Stack space
Enter the C code section


Second stage: LIB_ARM/BOARD.C, enter into the Main_loop () command line loop, accept the user's input command. Then the input works accordingly.
The Main_loop () function is defined in Include/common.h, implemented in MAIN.C in the common directory


Enter start Linux command, u-boot kernel image (Zimage) read from Nandflash to RAM, set startup parameters for the kernel, start liunx


After the compilation is complete, the link assignment file needs to be read before the connection is Cpu/arm920t/uboot.lds
Output_format ("Elf32-littlearm", "Elf32-littlearm", "Elf32-littlearm")
Output_arch (ARM)
ENTRY (_start)
SECTIONS
{
. = 0x00000000;

. = ALIGN (4);
. Text:
{
CPU/ARM920T/START.O (. Text)
BOARD/TEKKAMANNINJA/MINI2440/LOWLEVEL_INIT.O (. Text)
BOARD/TEKKAMANNINJA/MINI2440/NAND_READ.O (. Text)
* (. Text)
}

. = ALIGN (4);
. Rodata: {* (Sort_by_alignment (Sort_by_name (. rodata*))}

. = ALIGN (4);
. Data: {* (. data)}

. = ALIGN (4);
. Got: {* (. Got)}

. = .;
__u_boot_cmd_start =.;
. U_boot_cmd: {* (. u_boot_cmd)}
__u_boot_cmd_end =.;

. = ALIGN (4);
__bss_start =.;
. BSS (NOLOAD): {* (. bss). = ALIGN (4);}
_end =.;
}

---linux kernel---*******************

Linux composition structure:
User space
User applications
GNU C Library (glibc)

System space
Systerm Call Interface
Kernel
Architectur-dependent Kernel Code

In x86, the user runs on the Ring3 of the CPU, and the system space runs on the RING0 (Privileged command);
In arm, the user runs in the USR user mode of the CPU (there is a limit) and the system space runs in the SYS system mode (privileged command);
The user program goes to kernel space through system calls and hardware interrupts.


Core composition:
System call Interface (SCI)
Provides standard system call functions for user space.

Memory Management (MM) RAM management
Control multiple processes secure shared memory

Process Management (PM) Progress Management
1. Create a process
2. Stop the process
3. Control: Process scheduling, sharing CPU
4. Communication

Virtual file System (VFS)
Ext2,fat,nfs

Network Stack protocol stack
Network protocol

Arch
Device Drivers (DD)


Source Code Analysis (tree structure):
Arch
Store platform-related code
Arm/boot: Kernel boot code (compressed/head. S, kernel decompression)
ARM/KERNEL,LIB,MM: Kernel implementation (signal, clock), hardware-related tool functions, memory management
arm/mach-s3c2410:
Arm/tools: All board machine numbers supported by Linux are saved in Mach-types
Arm/configs: A reference kernel configuration file

Block
Partial block device drivers

Crypto
Encryption, compression, CRC check algorithm

Documentation
Documentation for the kernel

Drivers
Device drivers that account for the entire kernel code more than half.

Fs
Ext2
Fat
Each subdirectory corresponds to a file system implementation

Include
The header files required by the kernel
Platform-related header files are placed in the appropriate subdirectories
include/asm-arm/s3c2410
The platform-independent header files are in the Linux sub-directory.

Init
Kernel initialization code (non-boot code), equivalent to the main function
MAIN.C VERSION.C

Ipc
Implementation code for inter-process communication

Kernel
Linux master core, including process management and IRQ
Platform-related code under Arch/arm/kernel

Lib
Library File Code

Mm
Platform-independent Memory Management Section
Platform-related code under ARCH/ARM/MML

Net
Implementation code of the network protocol
IPv4

Samples
Some examples of kernel programming

Scripts
Configuring the kernel's scripts

Security
The SELinux module

Sound
Audio device drivers

Usr
Cpio Command Implementation

Virt
Kernel virtual machine

Kernel configuration steps:
Configuration
Kconfig:arch/arm/kconfig
1. Configuration options when controlling make Menuconfig
2. Generate a. config profile based on the user's choice
. config: When compiling, Makefile will use it to determine which ones to be, which are templates, and which ones do not.
1.make menuconfig Manually Select to configure (generate). config
2.make Mini2440_defconfig By default configuration of the Development Board. config


1.* Cleanup: Make Distclean
2. Configuration: Make Menuconfig

Compile:
Top Floor Makefile
1. Decide which files and directories in the root directory to compile into the kernel
2. Set file compilation link Options
3. Create an image file from the Arch/arm/kernel/**.lds organization file according to the link script

subdirectory Makefile (Kbuild)
1. Determine which files and directories in the current subdirectory are being compiled into the kernel
2. Set all file compilation link options in the current directory

3. Compiling: Make Zimage
Make Uimage
Make modules
Vmlinux (uncompressed)->zimage (compressed)->bzimage (decompressed to high-end memory, kernel larger)->uimage (u-boot)

Customize your Linux system:

In Arch/arm/tools/mach_types there is support for mini2440 1999, the kernel starts when the incoming Mach_type determines which platform to start.
Because the mini2440 and smdk2440 circuits are the same, you can use SMDK2440.C to copy one of your own mini2440.c


I. Building the Environment
Second, define the system hardware resource drive part
1.NandFlash
2. Porting the YAFFS2 file system


---file system---*******************

File Management System: the software organization responsible for managing and storing file information in the operating system.
Composition: Management software + file + data structure

Common file Systems

Log file system: Data integrity, but system resource consumption, suitable for hard disk
Ext3
RAMDisk File System
Romfs File System
Cramfs
JFFS2 File System

YAFFS2 (yet another Flash filesystem)
Log file system designed for Nandflash

Startup process:
1. The kernel finally starts the init process. In Init/main.c (Init_post () function)
Open/dev/console Device file
The Ramdisk_exiecut_command variable specifies the program to search for stars:
Search:/sbin/init,/etc/int,/bin/init, bin/sh program, start the first program found
The environment parameter when executing/sbin/init is "home=/", "Term=linux"

Init boot system: Located in Busybox/init/init.c
Initialize the console: If the kernel init starts up the console then uses the specified device, if it is not open, use/dev/null
Parsing Inittab
Executes the Inittab command, where each entry defines how a child process is started.

After startup, the first program to run is the root directory of LINUXRC, which points to the/bin/busybox connection
BusyBox attempts to parse/etc/inittab to get initialization information further
The New_init_action (Sysinit,init_script, "") in the Parse_inittab () function in init/init.c, so the next execution
The value defined by Init_script, which is/etc/init.d/rcs

Files required to build the file system:
BusyBox: The integration compresses many Linux tools and commands.
Root_qtopia: Provides the required library files for the file system.
Mkyaffs2image:yaffs File System Authoring tool (also available in YAFFS2).


Steps to build the file system:
1. Create a directory structure of your own custom file system
2. Complete the library file customization
3. Compiling the configuration Busuybox
4. Making configuration files in the file system
5. Making a file system image

QT Transplant
Qtcreator programming QT Applications under Windows-cross-compiling-download to board run
The cross-platform nature of QT applications--programming everywhere compiles
For QT applications developed under Windows, the cross-compilation tool must be compiled under Linux before porting to the Development Board
Implementation process
Build a cross-compilation environment on the Development Board
Developing applications under Windows or under Linux
Compiling using the Cross compiler
Download
Run

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.