查看: 4813|回复: 8

Embedded Linux Howto

[复制链接]
发表于 2009-7-16 11:55:31 | 显示全部楼层 |阅读模式
关键词: Embedded , Howto , linux
此文为转载的,希望能对大家有点帮助。

------------------------------------------------------------------------
--------
This document describes how to create a small linux system to be used as
embedded purpose from your desktop linux and some additional
specialized packages.
------------------------------------------------------------------------
--------


1. Introduction
1.1 Subject
1.2 New Versions
1.3 History
1.4 TODO
1.5 License
1.6 Contact

2. Dependencies
2.1 A Desktop Linux
2.2 Some software packages

3. The boot process.
3.1 Bios
3.2 The boot loader
3.3 The Kernel
3.4 Init
3.5 inittab
3.6 The login process

4. Creating a root file system
4.1 Creating a new partition
4.2 Creating an ext2 file system on the new partition
4.3 Mounting the partition
4.4 Populating the filesystem

5. Installing TinyLogin & login dependencies
5.1 Configuring TinyLogin
5.2 Installing TinyLogin
5.3 Installing Sysvinit & start-stop-daemon
5.4 Configuring Sysvinit
5.5 Creating initial boot scripts
5.6 Copying passwd & group files

6. Not finished: Installing the ash root shell
6.1 Preparing ash
6.2 Configuring ash

7. Not finished: Installing BusyBox
7.1 Preparing BusyBox
7.2 Deploying BusyBox

8. Not finished: Installing required libraries
8.1 Which ones ?
8.2 Copying
8.3 ldconfig
 楼主| 发表于 2009-7-16 11:55:46 | 显示全部楼层
1. Introduction
1.1 Subject
I made the LEM distro (aka Linux EMbedded) in February 1999. It is a
tiny linux distribution i used with some x86 hardware to make a touch
panel Graphical User Interface to audio, video, conferencing and polling
hardware for ERE Acoustic. It is not hard to make a small linux from
scratch. However, i made this document to spare people losing time
wrestling with many (usefull) docs and howtos. This document describes
how the LEM distro has been made.

1.2 New Versions
The latest version of the document may be found at http:
//linux-embedded.org

1.3 History
This document is started for a while but has never been published before
v0.3 because lacking a good structure. Recently, i have discovered
Gerard Beekmans's Linux From Scratch Howto, and decided to rewrite
this document using the structure from the LFS-HOWTO. Luc Herman's and
Paul Moody also granted me to use their jobs to improve this document.


1.4 TODO
...At least a todo section...

1.5 License
Copyright ? 1999,2000 by Sebastien Huet.

This document may be distributed under the terms set forth in the
Linux Documentation Project License at http:://linuxdoc.org

This is free documentation. It is distributed in the hope that it will
be useful, but without any warranty; without even the implied warranty
of merchantability or fitness for a particular purpose.

1.6 Contact
Feel free to send me your informations and comments at
sebhuet@linux-embedded.org.
 楼主| 发表于 2009-7-16 11:55:59 | 显示全部楼层
2. Dependencies
2.1 A Desktop Linux
You will need a full linux distribution to build your own embedded linux
OS. It will contains everything you need (utilities, sources, compiler,
debugger, documentation....).

2.2 Some software packages
This is a list of the software i used to make LEM. Other specialized
software for embedded purpose may be foud at http://linux-embedded.org

TinyLogin
TinyLogin is a suite of tiny Unix utilities for handling logging into,
being authenticated by, changing one's password for, and otherwise
maintaining users and groups on an embedded system. It also provides
shadow password support to enhance system security. TinyLogin is, as the
name implies, very small, and makes an excellent complement to
BusyBox on an embedded System. TinyLogin is being maintained by Erik
Andersen

TinyLogin is available at http://tinylogin.lineo.com

BusyBox
Busybox is a multicall binary used to provide a minimal subset of
POSIX style commands and specialized functions.It is geared toward the
very small, i.e. boot floppies, embedded-systems, etc. Specifically it
is used in the Debian Rescue/Install system (which caused the original
busybox to be made), the Linux Routeur Project, LEM, lineo and others.
Busybox is being maintained by Erik Andersen


Busybox is available at http://busybox.lineo.com

Ash
Ash is a very small Bourne shell available at http://www.debian.
org/Packages/unstable/shells/ash.html

Sysvinit
Sysvinit is the most used init package for Linux. We will use init and
the C version of the start-stop-deamon. Sysvinit is available at \"ftp.
debian.org/debian/dists/slink/main/source/base\"
 楼主| 发表于 2009-7-16 11:56:16 | 显示全部楼层
3. The boot process.
This section is for the most based on the Bootdisk-HOWTO.

3.1 Bios
All PC systems start the boot process by executing code in ROM
(specifically, the BIOS) to load the sector from sector 0, cylinder 0 of
the boot drive. The boot drive is usually the first floppy drive
(designated A: in DOS and /dev/fd0 in Linux). The BIOS then tries to
execute this sector. On most bootable disks, sector 0, cylinder 0
contains either:

Code from a boot loader such as LILO, which locates the kernel, loads it
and executes it to start the boot proper.
he start of an operating system kernel, such as Linux.
If a Linux kernel has been raw-copied to a diskette, a hard drive or
another media, the first sector of the disk will be the first sector
of the Linux kernel itself. This first sector will continue the boot
process by loading the rest of the kernel from the boot device.
3.2 The boot loader
We will use a boot loader like lilo to operate our boot process. It
permits to have the dev and production platforms on the same hardware
and to switch from one to the other by only rebooting. The lilo boot
loader is loaded by the bios. Then, it loads kernels or the boot sectors
of other operating systems. It also provides a simple command-line
interface to interactively select the item to boot with its options.
More may be found in the Lilo documentation at ftp://sunsite.unc.
edu/pub/Linux/system/boot/lilo/.

3.3 The Kernel
The kernel checks the hardware and mounts the root device. Then it looks
for the init program on the root filesystem and executes it.

3.4 Init
Init is the parent of all other processes that will run on your linux
OS, it will watch it's child processes and start, stop, re-lauch them if
needed. init takes all information from /etc/inittab.

3.5 inittab
The file /etc/inittab/ refers to scripts named /etc/rc... to do the
system setup. It also has entries for the getty tool to handle the login
process.

3.6 The login process
There is one getty available in the inittab file for each console you
allow for the users. Getty will launch /bin/login to verify the user
password.

More info about the boot process may be found at Linux Documentation
Project and in the init and inittab man pages.
 楼主| 发表于 2009-7-16 11:56:28 | 显示全部楼层
4. Creating a root file system
4.1 Creating a new partition
Quoted from the LFS-HOWTO at http://huizen.dds.nl/~glb/

Before we can build our new Linux system, we need to have an empty Linux
partition on which we can build our new system. If you already have a
Linux Native partition available, you can skip this subsection and the
following one.

Start the fdisk program (or cfdisk if you prefer that program) with
the appropriate hard disk as the option (like /dev/hda if you want to
create a new partition on the primary master IDE disk). Create a Linux
Native partition, write the partition table and exit the (c)fdisk
program. If you get the message that you need to reboot your system to
ensure that that partition table is updated, then please reboot your
system now before continuing.

4.2 Creating an ext2 file system on the new partition
Quoted from the LFS-HOWTO at http://huizen.dds.nl/~glb/

To create a new ext2 file system we use the mke2fs command. Give $LFS as
the only option and the file system will be created.

From now on I'll refer to this newly created partition as $EMBPART.
$EMBPART should be substituted with the partition you have created.

4.3 Mounting the partition
To access the newly created filesystem, you have to mount it. For this
create a /mnt/hda? directory and type at shell prompt:

mkdir /mnt/hda?
mount $EMBPART /mnt/hda?
If you created your partition on /dev/hda4, and you mounted it on
/mnt/hda4, when this document will tell you to copy a file to $dollar;
EMBPART/usr/bin then you will need to copy that file to
/mnt/hda4/usr/bin.




4.4 Populating the filesystem
The root filesystem must contain everything needed to support a full
Linux system. We will build a directory structure not that far from
the File Hierarchy Standard

Directories
Directories are made by using the mkdir fonction in the new mounted
filesystem.

/proc
Directory stub required by the proc filesystem.

/etc
System configuration file

/sbin
Critical System binaries

/bin
Basic binaries considered part of the system

/lib
Shared Libraries to provide run time support

/mnt
Mount point for maintenance

/usr
Additional utilities and applications


cd /mnt/hda?
mkdir bin dev home proc sbin usr boot etc liv mnt root tmp var
mkdir -p usr/bin usr/sbin usr/share usr/lib
mkdir -p etc/config etc/default etc/init.d etc/rc.boot
mkdir -p etc/rc0.d etc/rc1.d etc/rc2.d etc/rc3.d etc/rc4.d etc/rc5.d
etc/rc6.d etc/rcS.d
the /dev directory
The dev directory is the stub required to perform devices input /
output. Each file in this directory may be created using the mknod
function. You may avoid losing time by directly copying the required dev
entries from your desktop Linux.

cp -av /dev/???? /mnt/hda?
 楼主| 发表于 2009-7-16 11:56:46 | 显示全部楼层
5. Installing TinyLogin & login dependencies
TinyLogin is available at http://tinylogin.lineo.com.

It will give us the following tools in less than 35Ko :

/bin/addgroup, /bin/adduser, /bin/delgroup, /bin/deluser, /bin/login,
/bin/su, /sbin/getty, /sbin/sulogin, /usr/bin/passwd

Please refers to your main distribution doc or man pages to have a
full description of those commands.

5.1 Configuring TinyLogin
[... part of TinyLogin README ...] TinyLogin is modularized to easily
allow you to build only the components you need, thereby reducing binary
size. To turn off unwanted TinyLogin components, simply edit the file
tinylogin.def.h and comment out the parts you do not want using C++
style (//) comments.

5.2 Installing TinyLogin
After the build is complete a tinylogin.links file is generated which is
then used by 'make install' to create symlinks to the tinylogin
binary for all compiled in functions. By default, 'make install' will
place a symlink forest into `pwd`/_install unless you have defined the
PREFIX environment variable.

5.3 Installing Sysvinit & start-stop-daemon
After the kernel is done loading it attempts to run the init program
to finalize the boot process.

Unpack the Sysvinit archive.
Go to the src directory
Compile the package by running make
Copy the init executable in $EMBPART/sbin
The Sysvinit package also offers a C version of the start-stop-deamon in
the contrib directory.
Compile it.
Copy the file in $EMBPART/usr/sbin
5.4 Configuring Sysvinit
Sysvinit needs a configuration file named inittab and placed in
$EMBPART/etc. The following is the one used in the LEM distro:



# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.6 1997/01/30 15:03:55 miquels Exp $
# Modified for LEM 2/99 by Sebastien HUET <sebhuet@linux-embedded.org>

# default rl.
id:2:initdefault:

# first except in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# 0:halt 1:single-user 2-5:multi-user (5 may be X with xdm or other) 6:
reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6

# CTRL-ALT-DEL pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -r now

# Action on special keypress (ALT-UpArrow).
kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this
work."

# /sbin/mingetty invocations for runlevels.
1:2345:respawn:/sbin/getty 9600 tty1
2:23:respawn:/sbin/getty 9600 tty2
#3:23:respawn:/sbin/getty tty3 #you may add console there
#4:23:respawn:/sbin/getty tty4

5.5 Creating initial boot scripts
As seen in the inittab file, Sysvinit needs additional scripts in
their own directories.

Creating the necessary directories and base files

                cd $EMBPART/etc
                mkdir rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d init.d
rcS.d rc.boot
               

Go to the unpacked Sysvinit source directory.
Copy the debian/etc/init.d/rc toEMBART/etc/init.d
Go to the $EMBPART/etc/init.d/
Create a new file rcS like those in LEM:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
./etc/default/rcS
export VERBOSE
# Trap CTRL-C  only in this shell so we can interrupt subprocesses.
trap ":" 2 3 20
# Call all parts in order.
for i in /etc/rcS.d/S??*
do
        [ ! -f "$i" ] && continue
        case "$i" in
                *.sh)
                        (
                                trap - 2 3 20
                                . $i start
                        )
                        ;;
                *)
                        $i start
                        ;;
        esac
done
# run the files in /etc/rc.boot
[ -d /etc/rc.boot ] && run-parts /etc/rc.boot

Copy run-parts from your distro to $EMBPART/bin
Adding base scripts


Create a new file reboot containing the following:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
echo -n "Rebooting... "
reboot -d -f -i



Create a new file halt containing the following:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
halt -d -f -i -p



Create a new file mountfs containing the following:

Creating initial scripts

5.6 Copying passwd & group files


------------------------------------------------------------------------
--------
 楼主| 发表于 2009-7-16 11:57:04 | 显示全部楼层
6. Not finished: Installing the ash root shell
6.1 Preparing ash

6.2 Configuring ash

7. Not finished: Installing BusyBox
7.1 Preparing BusyBox

7.2 Deploying BusyBox

8. Not finished: Installing required libraries
8.1 Which ones ?

8.2 Copying

8.3 ldconfig

--
发表于 2009-7-22 09:31:20 | 显示全部楼层
考弟兄们英语呢????
发表于 2010-8-5 18:56:09 | 显示全部楼层
More performance, few words,
as a user instructor.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表