========================= Basic Knowledge =========================
First, the basic structure of the Linux system:
1, Loader
2, kernel
3, filesystem
Second, the starting step:
1, the CPU from ROM(if any) of the 0x0 address start reading code, execute loader;
2. Loader initialize Ramand copy uboot from ROM or Kernel The image to the specified address of the Ram , performing the image;
3, If there is uboot Span style= "Font-family:calibri" >uboot Before the start of the setup, you can initialize some of the hardware, you can manually enter Span style= "Font-family:calibri" >uboot environment, etc., last copy kernel image to uboot
4. the previous step is called the loader part. Kernel is loaded into Ram ,Kernel 's Bootargs will be overwritten, Kernel start up;
5, load the driver;
6. load file system, read and execute /etc/inittab.
Three, cross compiler:
arm-linux-gnueabihf-gcc
Iv. use of Makefile files and make
(Too easy,,,, as noted separately)
========================= Transplant System =========================
One, cross-compiler configuration:
Modify ~/.BASHRC:
Export path=/home/hexh/toolchain/hfcctool/bin: gcc can be executed $PATH #shell any directory
Export cross_compile=arm-linux-gnueabihf-# A variable required to compile loader, kernel
Reboot under shell, or source ~/.BASHRC
Second, compile loader and kernel:
1, the company generally based on the Development Board modification to get their own products, so the first compilation to strictly refer to the official information (this information is not, or make up, that is to pull the eggs), familiar with self-modification of the source code;
2, kernel configuration command:make Arch=arm menuconfig;
Three, the most simple file system:
1. Compiling BusyBox
Execute make Menuconfig
(1) modify Build Options--Cross Compiler prefix
(2) rookie must check Build Options--No shared libs
(3) Modify installation Options ("Make Install" behavior) Àbusybox installation prefix to : /target, the minimum root file system will be generated under target of the project directory ;
Make && make install
Enter the target directory, the file system folder, and the yellow part must be guaranteed to exist:
Bin etc Lib mnt proc run sys usr
Dev home linuxrc opt root sbin tmp var
/BIN/SBIN/USR, these folders have been busybox configured, do not need to add things themselves,etc directory needs to contain all the configuration information, BusyBox This folder is not processed and needs to be customized.
2,/etc/inittab
This file configures the default action that the system initiates, and if the file cannot be read, it causes kernel panic
in busybox , and PC slightly different, file format:
output Device :: Run Level : Command
Common operating level:sysinit(Power-on self-starter) respawn(keep running)
Cases:
# Initialize the root file system
Null::sysinit:/bin/mkdir-p/dev/pts
Null::sysinit:/bin/mkdir-p/DEV/SHM
Null::sysinit:/bin/mount–a
# Initialize hostname(requires a machine name in the /etc/hostname file)
Null::sysinit:/bin/hostname-f/etc/hostname
# Execute startup script (can be freely customized)
:: Sysinit:/etc/init.d/rcs
# in serial 0 Open login, and automatic login root(without password case)
Ttys0::respawn:/bin/login-f Root
3,/etc/fstab
command Mount–a the files that need to be used, before init initialization work is completed, the corresponding file system needs to be created in /proc/tmp/sys/dev
Content:
PROC/PROC proc Defaults 0 0
Tmpfs/tmp TMPFS Defaults 0 0
Sysfs/sys Sysfs Defaults 0 0
Tmpfs/dev TMPFS Defaults 0 0
4,/etc/passwd and /etc/shadow
These two files are account data, the work in Inittab is not important, but login user environment is conducive to debugging work, set the password can also effectively prevent external cracking the way of products.
The second piece of data in each row of these two files determines
Example: Root user no password configuration
[email protected]/etc]# cat passwd
Root:x:0:0:root:/mnt/root:/bin/sh
[email protected]/etc]# cat Shadow
Root::10933:0:99999:7:::
5,/etc/profile
profile This script will be executed automatically when the user logs on, without affecting the inittab phase.
Content:
# Initialize Shell
User= "$ (id-un)"
Logname= $USER
Ps1= ' [\[email protected]\h \w]# '
Path= $PATH:/mnt/bin:/mnt/usr/bin:/mnt/sbin:/mnt/usr/sbin
Hostname= '/bin/hostname '
Export USER LOGNAME PS1 PATH Ld_library_path
Iv. creation of file system images:
here are 4 ways to make a file system Image:fat ext4 Cramfs ubifs
1. Formatting tool fdisk
Example: Formatting U --- Fdisk/dev/sdb
Common commands:
M: Help;
P: Print partition list;
N: New partition;
T: Modify the format of the partition (but not the format);
A: Set the bootable partition;
2, Fat Format production method (running the system on the SD card)
Example: Formatting U- disk ÀMKFS.VFAT/DEV/SDB1
3, EXT4 Format production method (on the SD card running system)
Example: Formatting U- disk ÀMKFS.EXT4/DEV/SDB1
4, Cramfs production method (boot image)
Example: Mkfs.cramfs-b 4096-n little ${source} ${image}
5, Ubifs production method
There are two tools to use:mkfs.ubifs ubinize
First Use mkfs.ubifs to make the root file directory into ubifs file system, and then use ubinize will ubifs The file system is made into Ubi mirroring;
Cases:
Mkfs.ubifs-r ${SRC}-e 0x1f000-c 2048-m 0x800-o rootfs.ubifs
Ubinize-o rootfs.ubi-m 0x800-p 0x20000-s 2048 ubinize.cfg
content of Ubinize.cfg:
[Ubifs]
Mode=ubi
Image=rootfs.ubifs
Vol_id=0
Vol_type=dynamic
Vol_name=rootfs
Vol_alignment=1
Vol_flags=autoresize
The porting of Linux system on embedded hardware