Creating a Root File System for Linux on OMAP35x – 为Linux基

本文原载于

http://processors.wiki.ti.com/index.php?title=Creating_a_Root_File_System_for_Linux_on_OMAP35x

翻译文章,转载本文请标明出处,谢谢。

今天,我们只关注root file system的创建,并不聚焦具体的芯片是什么。

ABSTRACT

A Linux kernel is not very useful without a root file system containing applications and settings. Root file systems can be created in several formats: mountable over a network (NFS), a RAMDISK, or stored in flash (flash file system). Instructions on building and using these file systems is scattered over the Internet and/or in the Documentation directory in a Linux distribution. This note will describe building a simple root file system in the following formats: mountable over NFS, RAMDISK, Journaling Flash File System 2 (JFFS2), and a read-only flash file system known as CRAMFS.

概述

root file system包含应用程序和设置,没有root file system的Linux kernel并不是很有用。Root file system可以几种形式进行创建:通过网络可挂接的(NFS),RAMDISK,或者存储在flash(flash file system)中的。构建以及使用这些file system的指导分散在internet上,和/或Linux发布的Documentation目录里。本注释将要描述如何以如下的形式构建一个简单的root file system:通过NFS可挂接的,RAMDISK,日志Flash文件系统2(JFFS2),还有称作CRAMFS的只读的flash文件系统。

Introduction

The root file system built in this note is based on BusyBox, also known as “The Swiss Army Knife of Embedded Linux”. BusyBox contains reduced size versions of the most commonly used Unix utilities, all in a single executable. It is customizable so that only the utilities that are needed are built.This note guides the reader through the following:

Downloading and building BusyBoxMounting the root file system over NFSBuilding and testing a RAMDISK from the BusyBox targetBuilding and testing a JFFS2 file system from the BusyBox targetBuilding and testing a CRAMFS file system from the BusyBox target

This note assumes that the reader has root privileges on a PC running Linux. The busybox executable and all symbolic links to it must have user and group ownership set to “root”. This is required because the kernel boots as root. If the generated root file system does not have user/group set to root, the kernel will not boot. There are utility programs on the Internet that can change this, but these are out of the scope of this document.

介绍

本注释中构建的root file system基于BusyBox,也被称作“嵌入式Linux中的瑞士军刀”。BusyBox包含简化版的最经常使用的Unix工具,都在一个可执行文件中。它也可以定制,以便只包含需要的工具。本注释在以下方便对读者进行指导:

下载以及构建BusyBox

通过NFS挂接root file system

从BusyBox目标构建并测试RAMDISK

从BusyBox目标构建并测试JFFS2文件系统

从BusyBox目标构建并测试CRAMFS文件系统

本注释假定读者拥有运行Linux的PC的root权限。busybox可执行文件以及到它的所有符号链接的user和group属性必须设置为“root”。此要求是因为kernel是以root启动的。如果生成的root file system没有把user/group设置为root,kernel不会启动。网络上也有工具程序可以做这个事,但是,它们超出了本文档的范围。

Nomenclature

For this note, all source and target files are assumed to be in the user’s home directory. For simplicity, this note will assume the user’s directory is “user”. The home directory is then

/home/user

All source code will be in the “src” directory, or

/home/user/src

Code will be built in the “build” directory, or

/home/user/build

The target root file system will be built in the “target” directory, or

/home/user/target

To create these directories, go to /home/user and enter

[root@localhost user]# cd /home/user[root@localhost user]# mkdir src[root@localhost user]# mkdir build[root@localhost user]# mkdir target

命名

对于本注释,所有的source和target files都假定在用户的home目录下。为了表达的简易性,本注释假定用户的目录是"user"。 home路径就是

/home/user

所有的源代码会在“src”路径下,或者

/home/user/src

代码会编译到"build"路径下,或者

/home/user/build目标 root file system会构建在"target"目录下,或者

/home/user/target

为了创建这些目录,进入到 /home/user 然后输入

[root@localhost user]# cd /home/user[root@localhost user]# mkdir src[root@localhost user]# mkdir build[root@localhost user]# mkdir target

Configure the Linux Kernel to Support File Systems

The Linux kernel must be configured to support the file systems described in this note. To configure the kernel enter “make menuconfig” on the command line. The sub-menus and options to select follow. The Linux kernel source used in this note is from the Texas Instruments V2.6.22.18-OMAP3 release. The sub-menus may be different for other Linux sources and versions.

配置Linux Kernel以支持 File Systems

Linux kernel必须进行配置,以支持本注释中描述的file systems。为了配置kernel,在命令行输入 “make menuconfig”。子菜单和选项的选择在后面。本注释中使用的Linux Kernel source来自于TI V2.6.22.18-OMAP3。其他Linux sources和版本的子菜单可能会不同。

Device Node Creation

In Linux root file systems the /dev directory contains device nodes – special files that give application access to devices on the system. One example is a serial port. The device node for the first serial port on the system could be /dev/ttyS0. An application could open/read/write/close the serial port. The problem when creating a root file system is which device nodes are needed and which are not?

创建设备节点

在Linux root file system中,/dev 目录包含了设备节点 —— 特定的文件,给予应用程序访问系统中的设备的通道。其中的一个例子是 串口。系统上的第一个串口的设备节点可以是 /dev/ttyS0。应用程序可以打开/读取/写/关闭 这个串口。创建root file system时候的一个问题是,哪些设备节点是需要的,哪些是不需要的?

Early on in Linux root file systems, the creator would statically build the nodes with the “mknod” command (e.g. mknod target/dev/ttyS0 c 4 64). This led to missing nodes, unnecessary nodes, or nodes with the wrong name. During the 2.4.x kernels, the devfs file system was introduced. When device drivers loaded they would register with the devfs file system and the device node would be created. There were problems with this so that starting at 2.6.11 kernels, devfs was removed and replaced.

在Linux root file system的早期,创建者会使用"mknod"命令(例如,mknod target/dev/ttyS0 c 4 64)静态地构建节点。这会导致错失的节点,不必要的节点,或者错误名字的节点。在2.4.x kernels期间,devfs file system加入了进来。当device drivers加载的时候,他们可以与devfs file system注册,这样,就会创建device node了。不过,这也会有问题,因此,在2.6.11 kernels开始,devfs就剔除替换掉了。

The current method for dynamic device node creation is to use kernel hotplug with the sysfs and tmpfs file systems. During initialization, when file systems are getting mounted, the tmpfs file system is mounted on /dev. That way all device nodes are in virtual memory and are not saved between reboots of the board.

当前用于动态的设备节点创建的方法是使用kernel hotplug与sysfs和tmpfs file systems搭配的方法。在初始化期间,当file systems挂接的时候,tmpfs file system挂接在 /dev。这个方法,所有的设备节点都处于虚拟内存之中,在板子的reboots期间不会进行保存。

A driver registers with sysfs and gets added to the system. The kernel then runs the application pointed to by /proc/sys/kernel/hotplug to create the device node and to run any additional scripts (e.g. mounting a device). The application used by the Texas Instruments v2.6.22.x releases is built into busybox and is called “mdev.” This will be described later.

驱动与sysfs注册并加入到系统中来。之后,kernel运行指向于/proc/sys/kernel/hotplug的应用程序以创建设备节点,并运行任何额外的脚本(例如,挂接设备)。TI v2.6.22.x使用的应用程序构建到了busybox中,称作"mdev"。稍后会对它进行描述。

The v2.6.22.x releases default to enabling hotplug, sysfs, and tmpfs. To make sure hotplug is set, type in “make menuconfig” and from the “Main menu” use the down arrow key to scroll down to the “General setup” entry and press the Enter key to select it. Scroll down to “Configure standard kernel features (for small systems)” and press the Enter key. Scroll down to “Support for hot-pluggable devices” and make sure it is set. The Space Bar selects and de-selects options. A sample sub-menu is shown below:

v2.6.22.x默认使能了hotplug,sysfs,还有tmpfs。为了确定设置了hotplug,输入“make menuconfig”,从“Main menu”中使用向下键滑到“General setup”项,并输入回车键选择它。向下滑到“Configure standard kernel features(for small systems)”并按回车键。向下滑动到“Support for hot-pluggable devices”,并确定它是被置位了。空格键可以选择,去选择选项。以下是子菜单的一个样例:

 ┌──────── Configure standard kernel features (for small systems) ─────────┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.                           │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,                  │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>                  │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >                        │ │ ┌──────────────────────────────────────────┐ │ │ │    --- Configure standard kernel features (for small systems)                      │ │ │ │    [*]   Enable 16-bit UID system calls                                            │ │ │ │    [ ]   Sysctl syscall support                                                    │ │ │ │    [*]   Load all symbols for debugging/ksymoops                                   │ │ │ │    [ ]     Include all symbols in kallsyms                                         │ │ │ │    [*]     Do an extra kallsyms pass                                               │ │ │ │    [*]   Support for hot-pluggable devices                                   │ │ │ │    [*]   Enable support for printk                                                 │ │ │ │    [*]   BUG() support                                                             │ │ │ │    [*]   Enable ELF core dumps                                                     │ │ │ └────v(+)────────────────────────────────────┘ │ ├─────────────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                                      │

To ensure sysfs and tmpfs are selected, start back at the “Main menu” and scroll down to the “File systems” option. Press Enter to select it and then scroll down to the “Pseudo filesystems” option and press Enter to select it. The file systems selected here should be: /proc, /proc/sys, sysfs, and “Virtual memory file system support.” That last one is also referred to as /tmpfs. A sample sub-menu is shown below.

为了确定 选择了sysfs和tmpfs,回到“Main menu”开始,下滑到“File systems”选项。按回车键选择它,之后,下滑到“Pseudo filesystems”选项,按回车键进行选择。在这里,选择的file system应该有: /proc, /proc/sys, sysfs, 还有 "Virtual memory file system support"。其中,最后的也被称作/tmpfs。下面显示的是子菜单的一个样例:

 ┌────────────────────────── Pseudo filesystems ────┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.                 │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,        │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>        │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >              │ │ ┌─────────────────────────────────────┐ │ │ │    [*] /proc file system support                                    │ │ │ │    [*]   Sysctl support (/proc/sys)                                 │ │ │ │    [*] sysfs file system support                                    │ │ │ │    [*] Virtual memory file system support (former shm fs)       │ │ │ │    [ ]   Tmpfs POSIX Access Control Lists                                │ │ │ │    < > Userspace-driven configuration filesystem (EXPERIMENTAL)          │ │ │ │                                                                          │ │ │ │                                                                          │ │ │ │                                                                          │ │ │ │                                                                          │ │ │ └─────────────────────────────────────┘ │ ├────────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                            │ └────────────────────────────────────────┘

Configure the Linux Kernel for Root File System over NFS

In this configuration the root file system resides on a PC running a NFS server. From the “Main Menu” use the down arrow to scroll down to “File systems” and select it by pressing the Enter key. Under “File Systems” scroll down to “Network file systems” and select it. On this page make sure that “NFS file system support”, “Provide NFSv3 client support”, “Provide NFSv4 client support,” and “Root file system on NFS” are selected. A sample sub-menu is shown below.

为通过NFS挂接的Root File System配置Linux Kernel

在这个配置中,root file system驻存在运行NFS服务器的PC上。从“Main menu”使用向下的箭头下滑到“File systems”,通过回车键选择它。在“File systems”下,下滑到“Network file systems”,并选择它。在该页上,确定“NFS file system support”,“Provide NFSv3 client support”,“Provide NFSv4 client support”,和“Root file system on NFS”是选中的。下面是子菜单的样例:

 ┌───────────────────────── Network File Systems ──────────── ┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.                                  │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,                         │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>                         │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >                               │ │ ┌─────────────────────────────────────────── ──┐ │ │ │    <*> NFS file system support                                                        │ │ │ │    [*]   Provide NFSv3 client support                                                │ │ │ │    [ ]     Provide client support for the NFSv3 ACL protocol extensi                       │ │ │ │    [*]   Provide NFSv4 client support (EXPERIMENTAL)                               │ │ │ │    [ ]   Allow direct I/O on NFS files                                                     │ │ │ │    < > NFS server support                                                                  │ │ │ │    [*] Root file system on NFS                                                        │ │ │ │    [ ] Support for rpcbind versions 3 & 4 (EXPERIMENTAL)                                   │ │ │ │    --- Secure RPC: Kerberos V mechanism (EXPERIMENTAL)                                    │ │ │ │    < > Secure RPC: SPKM3 mechanism (EXPERIMENTAL)                                         │ │ │ └────v(+)────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                                              │ └─────────────────────────────────────────────────┘

Configure the Linux Kernel for RAMDISK support

In this configuration the u-boot boot loader is used to download a binary image to RAM and pass parameters to the kernel telling it the root file system is on a ramdisk, where it is located, and its size. From the “Main menu” scroll down to “Device Drivers” and select it. Then scroll down to “Block devices” and select it. On this sub-menu make sure “RAM disk support” is selected. For the “Default RAM disk size” enter 16384. The RAM disk built in this note is 16M.

为支持RAMDISK配置Linux Kernel

在这个配置中,使用u-boot boot loader下载binary image 到RAM中,并传递参数到kernel,告诉它root file system在ramdisk上,告诉它它自己处于什么位置,以及它的大小。

从“Main menu”下滑到“Device Drivers”并选择它。然后,下滑到“Block devices”并选择它。在这个子菜单上,确保“RAM disk support”选中了。“Default RAM disk size”输入16384. 本注释构建的RAM disk是16M。

 ┌───────────────────────────── Block devices ─ ─┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.               │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,      │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>      │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >            │ │ ┌────────────────────────────────────┐ │ │ │    <*> Loopback device support                                         │ │ │ │    < >   Cryptoloop Support                                            │ │ │ │    < > Network block device support                                    │ │ │ │    < > Low Performance USB Block driver                                │ │ │ │    <*> RAM disk support                                             │ │ │ │    (16)  Default number of RAM disks                              │ │ │ │    (16384) Default RAM disk size (kbytes)                        │ │ │ │    (1024) Default RAM disk block size (bytes)                   │ │ │ │    < > Packet writing on CD/DVD media                                  │ │ │ │    < > ATA over Ethernet support                                       │ │ │ └────────────────────────────────────┘ │ ├───────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                          │ └───────────────────────────────────────┘

The step above configures the kernel for build in a ramdisk. Now go back to the “Main menu” and again select “General setup.” Scroll down and make sure “Initial RAM filesystem and RAM disk (initramfs/initrd) support” is selected. By default in the T.I. kernel it is.

上面的步骤为ramdisk配置了kernel。现在,返回到“Main menu”,再次选择“General setup”。下滑,并确保“Initial RAM filesystem and RAM disk (initramfs/initrd) support”选中了。TI kernel 默认是选中的。

 ┌───────────────────────────── General setup ───────┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.                        │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,               │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>               │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >                     │ │ ┌────^(-)────────────────────────────── ────┐ │ │ │    [ ] Auditing support                                                         │ │ │ │    <*> Kernel .config support                                                   │ │ │ │    [*] Enable access to .config through /proc/config.gz                         │ │ │ │    (14) Kernel log buffer size (16 => 64KB, 17 => 128KB)                        │ │ │ │    [*] Create deprecated sysfs files                                            │ │ │ │    [ ] Kernel->user space relay support (formerly relayfs)                      │ │ │ │    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) suppor │ │ │ │    ()    Initramfs source file(s)                                               │ │ │ │    [*] Optimize for size (Look out for broken compilers!)                       │ │ │ │    [*] Configure standard kernel features (for small systems)  --->             │ │ │ │        Choose SLAB allocator (SLAB)  --->                                       │ │ │ └───────────────────────────────────── ───┘ │ ├──────────────────────────────── ───────────┤ │                    <Select>    < Exit >    < Help >                                   │ └────────────────────────────────────── ─────┘

Configure the Linux Kernel for Memory Technology Devices (MTD)

To use any of the flash file systems, such as JFFS2 or CRAMFS, the MTD layer must be configured. MTD are typically flash devices used for storage. Configuring the individual drivers can be tricky. If a device is CFI compliant then all that is needed is to select the CFI options. In this example, CFI is selected, as is Intel/Sharp just in case the part it not CFI compliant.Starting at the “Main menu” scroll down to “Device Drivers” and select it. Scroll down to “Memory Technology Devices (MTD) support” and select it. There are numerous options that can/should be selected. The screen captures below are lengthy.

为Memory Technology Devices(MTD)配置Linux Kernel

为了使用任何的flash file system,诸如 JFFS2 或者CRAMFS,必须配置MTD层。 MTD是典型的用于存储的flash设备。配置独立的drivers是需要技巧的。如果设备是 CFI兼容的,那么所需要的就是选择CFI选项。在这个例子中,CFI选中了,(空余)。 从“Main menu”开始下滑到“Device Drivers”,并选择它。下滑到“Memory Technology Devices(MTD) support”,并选择它。这里有很多选择可以/应该选中。下面的抓屏比较长。

 ┌──────────────── Memory Technology Device (MTD) support ──┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.             │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,    │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>    │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >          │ │ ┌───────────────────────────────────┐ │ │ │    --- Memory Technology Device (MTD) support                        │ │ │ │    [ ]   Debugging                                                   │ │ │ │    <*>   MTD concatenating support                                   │ │ │ │    [*]   MTD partitioning support                                    │ │ │ │    < >     RedBoot partition table parsing                           │ │ │ │    [*]     Command line partition table parsing                      │ │ │ │    < >     ARM Firmware Suite partition parsing                      │ │ │ │    ---   User Modules And Translation Layers                         │ │ │ │    <*>   Direct char device access to MTD devices                    │ │ │ │    ---   Common interface to block layer for MTD 'translation layers │ │ │ │    <*>   Caching block device access to MTD devices                  │ │ │ │    < >   FTL (Flash Translation Layer) support                       │ │ │ │    < >   NFTL (NAND Flash Translation Layer) support                 │ │ │ │    < >   INFTL (Inverse NAND Flash Translation Layer) support        │ │ │ │    < >   Resident Flash Disk (Flash Translation Layer) support       │ │ │ │    < >   NAND SSFDC (SmartMedia) read only translation layer         │ │ │ │          RAM/ROM/Flash chip drivers  --->                            │ │ │ │          Mapping drivers for chip access  --->                       │ │ │ │          Self-contained MTD device drivers  --->                     │ │ │ │    <*>   NAND Device Support  --->                                   │ │ │ │    <*>   OneNAND Device Support  --->                                │ │ │ │          UBI - Unsorted block images  --->                           │ │ │ └───────────────────────────────────┘ │ ├──────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                        │ └──────────────────────────────────────┘

Select the “RAM/ROM/Flash chip drivers” and ensure CFI and Intel/Sharp are selected.

选择“RAM/ROM/Flash chip drivers”,并确保CFI和Intel/Sharp是选中的。

 ┌────────────────────── RAM/ROM/Flash chip drivers ──────┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.                     │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,            │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>            │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >                  │ │ ┌───────────────────────────────────────┐ │ │ │    <*> Detect flash chips by Common Flash Interface (CFI) probe    │ │ │ │    < > Detect non-CFI AMD/JEDEC-compatible flash chips                       │ │ │ │    [ ] Flash chip driver advanced configuration options                      │ │ │ │    <*> Support for Intel/Sharp flash chips                             │ │ │ │    < > Support for AMD/Fujitsu flash chips                                   │ │ │ │    < > Support for ST (Advanced Architecture) flash chips                    │ │ │ │    < > Support for RAM chips in bus mapping                                  │ │ │ │    < > Support for ROM chips in bus mapping                                  │ │ │ │    < > Support for absent chips in bus mapping                               │ │ │ │                                                                              │ │ │ │                                                                              │ │ │ └───────────────────────────────────────┘ │ ├──────────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                                │ └──────────────────────────────────────────┘

Finally, go back to the MTD menu and select the “Mapping drivers for chip access” option. This option enables the partitioning of the MTD into four partitions: u-boot, u-boot environment, kernel, and file system.

最后,返回到MTD 菜单,选择“Mapping drivers for chip access”选项。该选项使能了MTD分区成4个分区:u-boot,u-boot环境,kernel,还有file system。

 ┌──────────────────── Mapping drivers for chip access ──┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.              │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,     │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>     │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >           │ │ ┌────────────────────────────────── ─┐ │ │ │    [ ] Support non-linear mappings of flash chips                     │ │ │ │    < > CFI Flash device in physical memory map                        │ │ │ │    < > CFI Flash device mapped on ARM Integrator/P720T                │ │ │ │    <*> TI OMAP board mappings                                    │ │ │ │    < > Map driver for platform device RAM (mtd-ram)                   │ │ │ │                                                                       │ │ │ │                                                                       │ │ │ └────────────────────────────── ─────┘ │ ├──────────────────────────────── ──────┤ │                    <Select>    < Exit >    < Help >                         │ └────────────────────────────────── ────┘

Configure the Linux Kernel for Flash File Systems (JFFS2 and CRAMFS)

JFFS2 is a second generation journaling flash file system with improved wear leveling and compression. CRAMFS is a compressed ROM file system that is read-only, therefore any writes will generate error messages on the console. If any of the logging utilities are started, they should re-direct their output to a file on a file system capable of read-write. Otherwise, do not start any of the logging utilities at boot.To configure the kernel, start at the “Main menu”, scroll down to the “File systems” entry, and select it. Scroll down to “Miscellaneous filesystems” and select it. Scroll down to “Journalling Flash File System v2 (JFFS2) support” and select it. There are other JFFS2 options to select – see the sub-menu below. Continue scrolling down and select “Compressed ROM file system support (cramfs)”.

为Flash File System(JFFS2 和 CRAMFS)配置Linux Kernel

JFFS2是第二代日志flash file system,提升了wear leveling和压缩。CRAMFS是压缩的ROM file system,它是只读的,因此对它的任何的写操作会在终端输出错误信息。

如果启动了任何的logging工具,工具应该重定向终端的输出到能够读写的file system上。否则,不要在启动阶段启动任何的logging 工具。为了配置kernel,从“Main menu”开始,下滑到“File systems”项,选择它。下滑到“Miscellaneous filesystems”,并选择它。下滑到“Journalling Flash File System v2(JFFS2) support”并选择它。这,还有其他的JFFS2选项要选择 —— 看下面的子菜单。继续下滑,选择“Compressed ROM file system support(cramfs)”。

 ┌─────────────────────── Miscellaneous filesystems ─┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.            │ │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes,   │ │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </>   │ │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >         │ │ ┌────^(-)──────────────────────────── ┐ │ │ │    <*> Journalling Flash File System v2 (JFFS2) support    │ │ │ │    (0)   JFFS2 debugging verbosity (0 = quiet, 2 = noisy)           │ │ │ │    [*]   JFFS2 write-buffering support                        │ │ │ │    [ ]   JFFS2 summary support (EXPERIMENTAL)                       │ │ │ │    [ ]   JFFS2 XATTR support (EXPERIMENTAL)                         │ │ │ │    [*]   Advanced compression options for JFFS2             │ │ │ │    [*]     JFFS2 ZLIB compression support                    │ │ │ │    [*]     JFFS2 RTIME compression support                   │ │ │ │    [ ]     JFFS2 RUBIN compression support                          │ │ │ │            JFFS2 default compression mode (priority)  --->          │ │ │ │    <*> Compressed ROM file system support (cramfs)          │ │ │ │    < > FreeVxFS file system support (VERITAS VxFS(TM) compatible)   │ │ │ └────v(+)─────────────────────────── ─┘ │ ├─────────────────────────────────── ──┤ │                    <Select>    < Exit >    < Help >                       │ └──────────────────────────────────── ─┘

Download and Build BusyBox

The source to BusyBox can be downloaded from http://www.busybox.net/downloads. One of the smallest and most stable version at the time of this writing is busybox-1.11.1.tar.bz2. Download it to the /home/user/src directory. Change directory to the build directory and extract the source code with the tar utility. The command line options to tar are:x extract the filesj the is a file zipped with bzip2 so use bunzip2 to uncompressv display the files as they are extractedf the following file contains the source

下载构建BusyBox

BusyBox的source可以从http://www.busybox.net/downloads下载。在写作本注释的时候,最小最稳定的版本之一是busybox-1.11.1.tar.bz2。将其下载到/home/user/src目录。改变路径到build目录,利用tar工具解压source code。tar的命令行选项是:x -解压文件,j – 该文件用bzip2压缩的, 所以使用bunzip2解压,v – 解压文件的时候显示文件,f –

[root@localhost src]# cd ../build[root@localhost build]# tar -xjvf ../src/busybox-1.2.2.1.tar.bz2

As the files are extracted, their names are displayed.

当这些文件解压的时候,会显示它们的名字。

Under the /home/user/build directory there should now be a busybox-1.2.2.1 directory. Change directory to it to start selecting build options. To configure build options, type in make menuconfig.

在/home/user/build目录下,现在应该会有一个busybox-1.2.2.1目录了。改变路径到它,开始选择构建选项。为了配置构建选项,输入 make menuconfig

[root@localhost build]# cd busybox-1.2.2.1[root@localhost busybox-1.2.2.1]# make menuconfig

The following screen should be displayed:

输入命令后,会显示如下的屏幕:

 ┌───────────────────────── BusyBox Configuration ─ ┐ │  Arrow keys navigate the menu.  <Enter> selects submenus --->.             │ │  Highlighted letters are hotkeys.  Pressing <Y> selectes a feature,        │ │  while <N> will exclude a feature.  Press <Esc><Esc> to exit, <?> for      │ │  Help, </> for Search.  Legend: [*] feature is selected  [ ] feature is    │ │ ┌───────────────────────────────────┐ │ │ │               Busybox Settings  --->                                 │ │ │ │           --- Applets                                                │ │ │ │               Archival Utilities  --->                               │ │ │ │               Coreutils  --->                                        │ │ │ │               Console Utilities  --->                                │ │ │ │               Debian Utilities  --->                                 │ │ │ │               Editors  --->                                          │ │ │ │               Finding Utilities  --->                                │ │ │ │               Init Utilities  --->                                   │ │ │ │               Login/Password Management Utilities  --->              │ │ │ │               Linux Ext2 FS Progs  --->                              │ │ │ │               Linux Module Utilities  --->                           │ │ │ └───────────v(+)──────────────────────┘ │ ├──────────────────────────────────────┤ │                    <Select>    < Exit >    < Help >                        │ └──────────────────────────────────────┘

To save on space, a hierarchical listing of options that must be selected is shown below.

为了存储,下面显示了必须选择的选项的一个分层的列表。

Busybox Settings  General Configuration     Show terse applet usage messages     Store applet usage messages in compressed form     Use the devpts filesystem for Unix98 PTYs     (/proc/self/exe) Path to BusyBox executable  Build Options     Build BusyBox as a static binary (no shared libs)     Build with Large File Support     Do you want to build BusyBox with a Cross Compiler     (/opt/arm-2007q3/bin/arm-none-linux-gnueabi-) Cross Compiler prefix  Coreutils     basename     cat     chmod     cp     cut     echo     false     head     hostid     ln     ls     mkdir     mkfifo     mknod     mv     pwd     rm     sync     tail     touch     true     uname     yes  Console Utilities     clear     reset  Editors     awk     sed     vi  Finding Utilities     find     grep  Init Utilities     init (keep the defaults that come with this selection)     Support running commands with a controlling-tty     poweroff, halt, and reboot     mesg  Login/Password Management Utilities     Use internal password and group functuions     getty     login       (de-select Support for /etc/securetty)  Linux Module Utilities     insmod     rmmod     lsmod     modprobe     Support version 2.6.x Linux kernels  Linux System Utilities     dmesg     mdev     Support /etc/mdev.conf     Support command execution at device addition/removal     mkswap     more     mount     swaponoff     umount     umount –a option  Networking Utilities     hostname     ifconfig     ping     telnet     telnetd Process Utilities     kill     killall     pidof     ps  Shells     ash (keep all the defaults)     Expand prompt string     ---Bourne Shell Options        Command line editing        History saving        Tab completion        Fancy shell prompts  System Logging Utilities     syslogd     klogd

To build BusyBox, simply type in make at the command line. After a few minutes the compile should be complete. When compilation is complete install BusyBox to the target directory. The make and install commands are show below:

为了构建BusyBox,在命令行简单地输入make。编译应该会在几分钟内完成。当编译完成的时候,将BusyBox安装到target目录中。make 和 install 命令如下所示:

[root@localhost busybox-1.2.2.1]# make[root@localhost busybox-1.2.2.1]# make CONFIG_PREFIX=/home/user/target install

Configure the New Target Root File System

Looking at the newly built root file system, there are only three subdirectories of binaries and a symbolic link of bin/busybox to linuxrc. More directories must be created before the file system can be used. Some device nodes should be created, too.

配置新的 目标 Root File System

查看一下新构建的root file system,仅有3个二进制的子目录,还有一个到linuxrc的bin/busybox符号链接。在file system可以使用之前,必须创建更多的目录。也需要创建一些设备节点。

[root@localhost bin]# cd /home/user/target/[root@localhost target]# dirtotal 28drwxr-xr-x  2 root root 4096 Nov 21 10:20 binlrwxrwxrwx  1 root root   11 Nov 21 10:20 linuxrc -> bin/busyboxdrwxr-xr-x  2 root root 4096 Nov 21 10:20 sbindrwxr-xr-x  4 root root 4096 Nov 21 10:20 usr[root@localhost target]#

Create the dev, dev/pts, etc, etc/init.d, lib, mnt, opt, proc, root, sys, tmp, var, and var/log directories. Also create the device node for the initial console.

创建dev,dev/pts, etc,etc/init.d,lib,mnt,opt,proc,root,sys,tmp,var,和 var/log目录。也要为初始化终端创建设备节点。

[root@localhost target]# mkdir dev[root@localhost target]# mknod dev/console c 5 1[root@localhost target]# mkdir dev/pts[root@localhost target]# mkdir etc[root@localhost target]# mkdir etc/init.d[root@localhost target]# mkdir lib[root@localhost target]# mkdir mnt[root@localhost target]# mkdir opt[root@localhost target]# mkdir proc[root@localhost target]# mkdir root[root@localhost target]# mkdir sys[root@localhost target]# mkdir tmp[root@localhost target]# mkdir var[root@localhost target]# mkdir var/log

Since 2.6.11 the debugfs has been introduced and so you may optionally create a directory called debug for mounting the debugfs.

从2.6.11 开始,debugfs加入进来,因此,你或许可选地创建一个目录叫做debug,以挂接debugfs。

[root@localhost target]# mkdir debug

To have the /proc and /dev/pts file systems mounted at boot time, the file etc/fstab must be created in the etc directory. Use an editor to create the file. The example below uses vi to create the file. The two lines to enter into fstab are shown below the vi fstab line.

为了在启动时可以挂接/proc和/dev/pts file system,必须在etc目录创建文件 etc/fstab。使用一个编辑器创建该文件。下边的例子使用vi创建这个文件。输入到fstab的2行显示在vi fstab 那一行的下面。

[root@localhost target]# cd etc[root@localhost etc]# vi fstabproc            /proc           proc    defaults        0 0none            /dev/pts        devpts  mode=0622       0 0

The login utilities use the files group, hosts, and passwd in the etc directory for logging in. For now, only root needs to be defined in group and passwd while hosts just needs to have localhost defined. The contents of the three files are show below:

登陆工具使用 etc目录下的group,hosts,和 passwd文件用于登陆。现在,只需要root定义在group和passwd中,而hosts中只需要定义localhost。3个文件的内容显示在下面:

[root@localhost etc]# vi grouproot:x:0:root[root@localhost etc]# vi passwdroot::0:0:root:/root:/bin/ash [root@localhost etc]# vi hosts127.0.0.1       localhost

The kernel starts “/sbin/init” after it boots (actually the kernel attempts to execute several known programs until one succeeds). Init reads the etc/inittab file to determine what to do at start up, shutdown, or when a user logs in. These inittab files can get quite complicated. A simple one is shown below:

在kernel启动之后(实际上,kernel尝试执行几个知名的程序,直到有一个成功),kernel启动“/sbin/init”。init 读取 etc/inittab 文件以决定启动的时候做什么,关闭的时候做什么,或者用户登录的时候做什么。这些inittab文件可以非常的复杂。简单的一个如下所示:

[root@localhost etc]# vi inittab::sysinit:/etc/init.d/rcS # /bin/ash## Start an "askfirst" shell on the serial portttyS0::askfirst:-/bin/ash# Stuff to do when restarting the init process::restart:/sbin/init# Stuff to do before rebooting::ctrlaltdel:/sbin/reboot::shutdown:/bin/umount -a -r::shutdown:/sbin/swapoff -a

The “sysinit” line tells init to run the /etc/init.d/rcS script to set up the system. The rest are self explanatory.

“sysinit”这一行告诉init运行 /etc/init.d/rcS脚本以建立起该系统。其他的都是自解释的。

A simple etc/init.d/rcS file could assume file systems existed in the kernel and would simply mount the mount points as needed. A more complicated one would test for the existence of file systems and if found, mount them; if not found, find ways to still get the system booted.

一个简单的 etc/init.d/rcS文件可以假定file systems存在于kernel中,然后当需要的时候,挂接这些挂接点。比较复杂的脚本会测试file system是否存在,如果找到了,就挂接它们;如果没有找到,寻找其他方法启动系统。

The author has taken the etc/init.d/rcS and mdev.conf files from the V2.6.22.18-OMAP3 release for a simple example. The rcS script will test for the existence of file systems and mount them accordingly. The 1.11.1 version of BusyBox does not create a link for /bin/sh so change any /bin/sh to /bin/ash. The contents are shown below:

本文作者以V2.6.22.18-OMAP3中的etc/init.d/rcS和 mdev.conf文件为例。rcS脚本会测试file systems是否存在,并相应地挂接它们。BusyBox 1.11.1版本不会创建/bin/sh的链接,因此,将/bin/sh改为/bin/ash。 脚本的内容如下:

[root@localhost etc]# vi init.d/rcS#!/bin/sh#   ---------------------------------------------#   Common settings#   ---------------------------------------------HOSTNAME=OMAP3EVMVERSION=1.0.0hostname $HOSTNAME#   ---------------------------------------------#   Prints execution status.##   arg1: Execution status#   arg2: Continue (0) or Abort (1) on error#   ---------------------------------------------status (){       if [ $1 -eq 0 ]; then               echo "[SUCCESS]"       else               echo "[FAILED]"               if [ $2 -eq 1 ]; then                       echo "... System init aborted."                       exit 1               fi       fi}#   ---------------------------------------------#   Get verbose#   ---------------------------------------------echo ""echo "    System initialization..."echo ""echo "    Hostname      : $HOSTNAME"echo "    Filesystem    : v$VERSION"echo ""echo ""echo "    Kernel release: `uname -s` `uname -r`"echo "    Kernel version: `uname -v`"echo ""#   ---------------------------------------------#   MDEV Support#   (Requires sysfs support in the kernel)#   ---------------------------------------------echo -n " Mounting /proc            : "mount -n -t proc /proc /procstatus $? 1echo -n " Mounting /sys             : "mount -n -t sysfs sysfs /sysstatus $? 1echo -n " Mounting /dev             : "mount -n -t tmpfs mdev /devstatus $? 1echo -n " Mounting /dev/pts         : "mkdir /dev/ptsmount -t devpts devpts /dev/ptsstatus $? 1echo -n " Enabling hot-plug         : "echo "/sbin/mdev" > /proc/sys/kernel/hotplugstatus $? 0echo -n " Populating /dev           : "mkdir /dev/inputmkdir /dev/sndmdev -sstatus $? 0#   ---------------------------------------------#   Disable power management#   (Requires sysfs support in the kernel)#   ---------------------------------------------echo -n " Disabling Power mgmt      : "echo -n "1" > /sys/power/cpuidle_deepest_statestatus $? 1#   ---------------------------------------------#   Turn off LCD after 1 hour of inactivity#   (Requires sysfs support in the kernel)#   ---------------------------------------------echo -n " Turn off LCD after 1 hour : "echo -n "3600" > /sys/power/fb_timeout_valuestatus $? 1#   ---------------------------------------------#   Mount the default file systems#   ---------------------------------------------echo -n " Mounting other filesystems: "mount -astatus $? 0#   ---------------------------------------------#   Set PATH#   ---------------------------------------------export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin#   ---------------------------------------------#   Start other daemons#   ---------------------------------------------echo -n " Starting syslogd          : "/sbin/syslogdstatus $? 0echo -n " Starting telnetd          : "/usr/sbin/telnetdstatus $? 0#   ---------------------------------------------#   Done!#   ---------------------------------------------echo ""echo "System initialization complete."#   ---------------------------------------------#   Start demo app#   ---------------------------------------------#if [[ -x /etc/init.d/demo_start ]]; then#       echo " Starting Demo Application..."#       /etc/init.d/demo_start &#       sleep 5#fi

Please note that in more recent kernels (2.6.29 and newer) the sysfs entries shown above to disable power management and control the LCD inactivity timeout shown above have been removed. For latest details on using OMAP Power Management in Linux please refer to this article.

注意到,在近来的版本(2.6.29,以及更新的版本),上边显示的去使能电源管理,控制LCD非动态的超时时间的sysfs条目已经被剔除了。在linux中使用OMAP 电源管理的最新的细节可以查看http://elinux.org/OMAP_Power_Management

To automatically mount the debugfs on start-up the following can be added to the above rcS file. Please note that the debugfs needs to be selected in the kernel configuration and built into the kernel before you can mount it. The below script checks to see if the debugfs is supported by the kernel before attempting to mount the file-system. To enable the debugfs run "make menuconfig" and go to "Kernel Hacking" and select "Debug Filesystem".

为了在启动的时候,自动挂接debugfs,可以添加下面的内容到上面的rcS文件。注意到,在可以挂接debugfs之前,debugfs需要在kernel 配置中进行选择,并编译到kernel中。下面的脚本在尝试挂接file system之前查看debugfs是否在kernel支持了。为了使能debugfs,运行“make menuconfig”,到“Kernel Hacking”下选择“Debug Filesystem”。

cat /proc/filesystems | grep -q debugfsif [ $? -eq 0 ]; then        echo -n " Mounting /debug            : "        mount -n -t debugfs none /debug        status $? 1fi

After saving the file, change its access permissions so that it is executable for all.

在保存文件之后,改变其访问权限,以便所有的都可以执行它。

[root@localhost etc]# vi mdev.confaudio       0:5 0666console     0:5 0600control.*   0:0 0660 @/bin/mv /dev/$MDEV /dev/snd/dsp         0:5 0666event.*     0:0 0600 @/bin/mv /dev/$MDEV /dev/input/fb          0:5 0666nfs         0:5 0770null        0:0 0777pcm.*       0:0 0660 @/bin/mv /dev/$MDEV /dev/snd/rtc         0:0 0666tty         0:5 0660tty0*       0:5 0660tty1*       0:5 0660tty2*       0:5 0660tty3*       0:5 0660tty4*       0:5 0660tty5*       0:5 0660tty6*       0:5 0660ttyS*       0:5 0640urandom     0:0 0444zero        0:0 0666

Add the Shared Libraries Applications will Require

Various applications will be built using the libraries in the tool chain so the runtime libraries must be copied to the root file system. Care should be taken to only copy the libraries that are required so that the root file system does not grow based on unused libraries. This note will simply demonstrate how to copy all the shared libraries to the root file system and strip out any debug information from the libraries.

添加应用程序需要的共享库

各种应用程序构建的时候会使用工具链中的库文件,因此,必须把运行时库拷贝到root file system中。注意,一定只拷贝需要的库文件,不要使得root file system因不需要的库尔增加大小。本注释会简单地说明怎么样拷贝所有的共享库到root file system,并从库文件中剔除任何的调试信息。

In the Code Sourcery tool chain, most of the libraries are found in the /opt/arm-2007q1/arm-none-linux-gnueabi/libc/lib directory. Simply copy these files to the root file system, maintaining symbolic links and then strip out unneeded debug information.

在Code Sourcery 工具链中,大部分的库在 /opt/arm-2007q1/arm-none-linux-gnueabi/libc/lib 目录下。可以简单地拷贝这些文件到 root file system中,维护好符号链接并剔除不需要的调试信息。

[root@localhost user]# cd /home/user/target/lib[root@localhost lib]# cp –r /opt/arm-2007q1/arm-none-linux-gnueabi/libc/lib/* .[root@localhost lib]# arm-none-linux-gnueabi-strip *

Some libraries might be in other directories in the tool chain; those would have to be found on a “trial and error” basis when applications do not load because of a missing shared library.

一些库文件可能在工具链的其他路径中;可以基于应用程序加载时因缺失的一些共享库而提示的“trail and error”来找到这些库文件。

A minimal, working root file system has now been built. It will boot, but does not have kernel modules yet. These will be added later after testing.

一个最小的,可工作的root file system现在就构建起来了。它可以启动,但是还没有kernel modules。稍后在测试之后会将它们加入进来。

Mounting the Root File System over NFS

In this scenario, the target device and the host system are connected via Ethernet, either directly through a crossover cable or to a hub or switch. The host must export the target file system through NFS and the NFS server daemon must be running. For configuring and running NFS on a Linux PC, see the HOWTOs at any Linux Documentation Internet site. In this simple example, the exported file system is /home/user/target and anybody can mount it via NFS. The /etc/exports file is shown below

通过NFS挂接Root File System

在本场景中,目标设备和主机系统通过以太网互联,或者通过交叉电缆直连或者通过一个hub或者switch。主机必须通过NFS来输出目标 file system,并且,NFS server daemon必须是处于运行中。为了在Linux PC上配置并运行NFS,可以查看任何的Linux Documentation internet 站点上的HOWTOS。在这个简单的例子中,输出的 file system是 /home/user/target,任何人可以通过NFS来挂接它。 /etc/exports文件显示如下:

/home/user/target        *(rw,no_root_squash)

On the target side, the u-boot environment variable bootargs must be set to boot from NFS and contain the mount address of the root file system. In the example below, the NFS server is at IP address 192.168.1.104.

在目标设备一端,u-boot环境变量bootargs必须设置为从NFS启动,并且包含root file system的挂接地址。在下面的例子中,NFS服务器的IP地址是 192.168.1.104

[root@OMAP3EVM /] # setenv bootargs mem=64M ip=dhcp noinitrd console=ttyS0,115200n8 root=/dev/nfs rw nfsroot=192.168.1.104:/home/user/target,nolock,rsize=1024,wsize=1024[root@OMAP3EVM /] # saveenv

After booting the kernel, the final boot messages should look similar to below.

在启动kernel之后,最终的启动消息看起来与如下的消息相似。

Sending DHCP requests .<6>eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1., OKIP-Config: Got DHCP answer from 255.255.255.255, my address is 128.247.107.23IP-Config: Complete:     device=eth0, addr=128.247.107.23, mask=255.255.254.0, gw=128.247.106.2,    host=128.247.107.23, domain=am.dhcp.ti.com, nis-domain=(none),    bootserver=255.255.255.255, rootserver=128.247.107.35, rootpath=Looking up port of RPC 100003/2 on 128.247.107.35Looking up port of RPC 100005/1 on 128.247.107.35VFS: Mounted root (nfs filesystem).Freeing init memory: 136Kinit started: BusyBox v1.11.1 (2008-10-05 04:40:51 CDT)starting pid 288, tty : '/etc/init.d/rcS'   System initialization...   Hostname      : OMAP3EVM   Filesystem    : v1.0.0   Kernel release: Linux 2.6.22.18-omap3   Kernel version: #12 Mon Oct 6 01:22:49 CDT 2008Mounting /proc            : [SUCCESS]Mounting /sys             : [SUCCESS]Mounting /dev             : [SUCCESS]Mounting /dev/pts         : [SUCCESS]Enabling hot-plug         : [SUCCESS]Populating /dev           : [SUCCESS]Disabling Power mgmt      : [SUCCESS]Turn off LCD after 1 hour : [SUCCESS]Mounting other filesystems: [SUCCESS]Starting syslogd          : [SUCCESS]Starting telnetd          : [SUCCESS]System initialization complete.Please press Enter to activate this console.

Creating and Booting a RAMDISK

A ramdisk is simply an ext2 file system. The tools to build one are shipped with just about every Linux distribution. The steps to build the ramdisk from the target file system are as follows:

创建并启动RAMDISK

简单来说,ramdisk,就是一个ext2 file system。构建ramdisk的工具是与每一个linux发布一起出厂的。从 target file system开始, 构建ramdisk的步骤如下:

    Change directory to the /home/user directory. 改变路径到 /home/user 目录Use the dd utility to create a 16M file of “zero” that will contain the file system.使用dd工具创建16M的内容为“0”的文件,它将用于包含 file system。Use mke2fs to create the empty file system in the file from 2. 使用mke2fs从步骤2得到的文件中创建一个空的 file systemMount the file to a mount point using the loop device. 将该文件挂接到使用 loop 设备的挂载点上。Use tar to create an archive from the target and pipe it into tar to extract the target to the mount point. 用tar从target创建一个archive,管道该archive到tar,以提取target到挂接点Un-mount the file. 卸载掉该文件Copy it to the /tftpboot directory so that u-boot can download it to the target device.拷贝该文件到/tftpboot目录,以便u-boot能download它到目标设备上。
[root@localhost user]# cd /home/user[root@localhost user]# dd if=/dev/zero of=rd-ext2.bin bs=1k count=16384[root@localhost user]# mke2fs –F –m0 rd-ext2.bin[root@localhost user]# mount –t ext2 rd-ext2.bin /mnt –o loop[root@localhost user]# tar –C target –cf - . | tar –C /mnt –xf –[root@localhost user]# umount /mnt[root@localhost user]# cp rd-ext2.bin /tftpboot

To boot the kernel with the root file system on the ramdisk, the u-boot environment variable “bootargs” must be modified. The “bootargs” variable contains information that gets passed to the kernel at boot up time and has information such as memory size, ip address, where the root file system is, what kind of file system it is, etc. For this note, a TI OMAP 3530 EVM is used so all RAM and flash addresses are specific to that platform.

为了配合位于ramdisk上的root file system启动kernel,必须修改u-boot的环境变量“bootargs”。“bootargs”变量包含启动时需要传递到kernel的信息,还有诸如memory大小,ip地址,root file system所在的位置,它是哪种file system等信息。对于本注释而言,使用了TI OMAP 3530 EVM,因此,所有的RAM和flash地址都是针对于那个平台的。

Start up a terminal program on the host and turn on the target. It is assumed that u-boot has already been flashed to the target board. The ramdisk will be downloaded to RAM at address 0x81600000 and is 16M in size. At the u-boot prompt, change the bootargs variable as follows:

在主机端开启一个终端程序,并打开target。假定,u-boot已经烧写到目标板的flash。ramdisk会被下载到RAM的0x81600000,大小是16M。在u-boot的提示符下,如下般改变bootargs变量

[root@OMAP3EVM /] # setenv bootargs mem=88M ip=dhcp console=ttyS0,115200n8                     root=/dev/ram0 rw initrd=0x81600000,16M ramdisk_size=16384[root@OMAP3EVM /] # saveenv

All the text should be entered as one line.Now download the kernel to 0x80000000 and the ramdisk to 0x81600000 and then boot the kernel.

所有输入的text应该是同一行。现在,下载kernel到0x80000000,下载ramdisk到0x81600000,之后启动kernel

[root@OMAP3EVM /] # tftp 81600000 rd-ext2.bin[root@OMAP3EVM /] # tftp 80000000 uImage[root@OMAP3EVM /] # bootm

After the kernel boots, the terminal should show the usual boot up messages and then finally indicates that the filesystem is mounted as a RAMDISK.

在kernel启动之后,终端会显示惯常的启动信息,之后,最终指示出filesystem以RAMDISK的形式挂接。

RAMDISK: ext2 filesystem found at block 0RAMDISK: Loading 16384KiB [1 disk] into ram disk... done.VFS: Mounted root (ext2 filesystem).Freeing init memory: 136Kinit started: BusyBox v1.11.1 (2008-10-05 04:40:51 CDT)starting pid 287, tty : '/etc/init.d/rcS'   System initialization...   Hostname      : OMAP3EVM   Filesystem    : v1.0.0   Kernel release: Linux 2.6.22.18-omap3   Kernel version: #12 Mon Oct 6 01:22:49 CDT 2008Mounting /proc            : [SUCCESS]Mounting /sys             : [SUCCESS]Mounting /dev             : [SUCCESS]Mounting /dev/pts         : [SUCCESS]Enabling hot-plug         : [SUCCESS]Populating /dev           : [SUCCESS]Disabling Power mgmt      : [SUCCESS]Turn off LCD after 1 hour : [SUCCESS]Mounting other filesystems: [SUCCESS]Starting syslogd          : [SUCCESS]Starting telnetd          : [SUCCESS]System initialization complete.Please press Enter to activate this console.

MTD Partitions

Before discussing flash file systems, “MTD partitions” must be explained. A flash device must be partitioned on an embedded device just as a hard disk must be partitioned on a Linux PC. On a Linux PC there would be a partition for /boot, a swap partition, a /usr partition, etc. For the embedded device the partitions are usually just for the boot loader, its environment variables, the kernel, and a flash file system.

MTD分区

在讨论flash file systems之前,必须解释一下“MTD partitions”。嵌入式设备上的flash设备必须进行分区,其原因就像,Linux PC上的硬盘必须被分区一样。在Linux PC上,有用于/boot的分区,有用于swap的分区,有/usr分区,等。对于嵌入式设备而言,分区通常是用于boot loader,其环境变量,kernel,和flash file system。

There is no “fdisk” for flash devices like there is for a hard disk. Instead, the partitioning is done in software. The exact file that does the partitioning is different based on the chip, board, CPU, and Linux source code. For this note, the board used is the TI OMAP 3530 EVM and the kernel source is from the SDK1.0.0 release. The file containing the MTD driver and partitions is linux/kernel_org/2.6_kernel/arch/arm/mach-omap2/board-omap3evm-flash.c.

硬盘有fdisk命令,但是对于flash设备则没有相似的命令。代替的是,分区是在软件中完成的。基于chip,board,CPU,Linux source code的不同,进行分区的文件也是不同的。对于我们这次讨论而言,使用的板子是 TI OMAP 3530 EVM,kernel source是SDK1.0.0。包含MTD驱动和分区的文件是 linux/kernel_org/2.6_kernel/arch/arm/mach-omap2/board-omap3evm-flash.c。

Looking at the file, the structure omap_partitions[ ] contains the partition table for the H4 board.

看一下这个文件,结构omap_partitions[]为H4 board包含了如下的分区表。

static struct mtd_partition omap3evm_onenand_partitions[] = {       {               .name           = "X-Loader-ONENAND",               .offset         = 0,               .size           = 4 * (64 * 2048),               .mask_flags     = MTD_WRITEABLE /* force read-only */       },       {               .name           = "U-Boot-ONENAND",               .offset         = MTDPART_OFS_APPEND,               .size           =  14*(64*2048),               .mask_flags     = MTD_WRITEABLE /* force read-only */       },       {               .name           = "Boot Env-ONENAND",               .offset         = MTDPART_OFS_APPEND,               .size           = 2*(64*2048),       },       {               .name           = "Kernel-ONENAND",               .offset         = MTDPART_OFS_APPEND,               .size           = 40*(64*2048),       },       {               .name           = "File System - ONENAND",               .offset         = MTDPART_OFS_APPEND,               .size           = MTDPART_SIZ_FULL,       },

};The boot loader has a partition size of 256k. The u-boot environment variables fit in a 128k partition for ES1.0 or 256k for ES2.0. The kernel partion is 2M while what is left is used for a file system.

boot loader分区大小是256k。u-boot环境变量位于ES1.0的128k大小的分区中,或者ES2.0的256k大小的分区中。kernel分区是2M,而剩下的空间用于file system。

When the kernel boots and the driver loads, device nodes are created based on the partitions. The device nodes take on the form /dev/mtdblock/x or /dev/mtdblockx.

当kernel启动,driver加载的时候,基于分区创建了设备节点。设备节点采用诸如/dev/mtdblock/x或者/dev/mtdblockx的形式。

                      Flash Physical Adress Range  Bank  Device Node     Partition Name0x00080000-0x00020000  1     /dev/mtdblock0  "X-Loader-NAND"0x001c0000-0x00020000  1     /dev/mtdblock1  "U-Boot-NAND"0x00040000-0x00020000  1     /dev/mtdblock2  "Boot Env-NAND"0x00500000-0x00020000  1     /dev/mtdblock3  "Kernel-NAND"0x0f880000-0x00020000  1     /dev/mtdblock4  "File System - NAND"

The physical address is set by u-boot. Look at the file u-boot/include/asm/arch/cpu.h to see the flash physical address mappings:

物理地址是由u-boot设置的。查看u-boot/include/asm/arch/cpu.h文件以获知flash物理地址的映射:

/* GPMC Mapping */# define FLASH_BASE             0x10000000  /* NOR flash (aligned to 256 Meg) */# define FLASH_BASE_SDPV1       0x04000000  /* NOR flash (aligned to 64 Meg) */# define FLASH_BASE_SDPV2       0x10000000  /* NOR flash (aligned to 256 Meg) */# define DEBUG_BASE             0x08000000  /* debug board */# define NAND_BASE              0x10000000  /* NAND addr (actual size small port)*/# define PISMO2_BASE            0x18000000  /* PISMO2 CS1/2 */# define ONENAND_MAP            0x20000000  /* OneNand addr (actual size small port */

Creating and Booting a JFFS2 Root File System

Since jffs2 is used only on flash devices, a standard Linux distribution does not have the tools to make a jffs2 file system. The Internet sitehttp://sources.redhat.com/jffs2 explains where and how to obtain the latest source to MTD code and file systems. mkfs.jffs2 is the tool needed to build a jffs2 file system and the source is in this code. All of the MTD code will be downloaded but only the code to build mkfs.jffs2 is built.

创建并启动JFFS2 root file system

因为jffs2仅用于flash设备,标准的Linux 发布没有工具制作jffs2 file system。internet网址http://sources.redhat.com/jffs2说明了在哪里怎么样得到最新的MTD code和 file system的源。构建jffs2 file system需要使用mkfs.jffs2工具,源在code中。所有的MTD代码都会被下载下来,但是只有构建mkfs.jffs2的代码会被编译。

The source code is maintained in a CVS tree. CVS is version control software and is usually installed when the Linux distribution is installed. CVS does not work across firewalls so a direct connection to the Internet is required. From the command line enter the following:

源代码维护在CVS树中。CVS是版本控制软件,它通常在Linux发布安装的时候进行安装。CVS不能通过防火墙工作,所以,需要一个到internet的直接的连接。从命令行输入下面的内容:

[root@localhost user]# cd /home/user/build[root@localhost build]# cvs –d:pserver:anoncvs@cvs.infradead.org:/home/cvs login CVS password: anoncvs[root@localhost build]# cvs –d:pserver:anoncvs@cvs.infradead.org:/home/cvs co mtd

There should now be a mtd directory under /home/user/build. The source to mkfs.jffs2 is found in the util directory under mtd. To build mkfs.jffs2 simply change directory to mtd/util and enter “make mkfs.jffs2”. When the build is complete, copy the mkfs.jffs2 file to the /sbin directory; that is where the other utilities that make file systems reside.

现在,在/home/user/build目录下应该有一个mtd目录。mkfs.jffs2的源可以在mtd下的util目录下找到。为了构建mkfs.jffs2,很简单地改变路径到mtd/util目录下,输入“make mkfs.jffs2”。当构建完成的时候,将mkfs.jffs2文件拷贝到/sbin目录下,其他的制作file system的工具也驻存在那里。

[root@localhost build]# cd mtd/util[root@localhost util]# make mkfs.jffs2[root@localhost util]# cp mkfs.jffs2 /sbin

With the mkfs.jffs2 utility built and in place it is now time to make the jffs2 file system from of the target directory. Change to the /home/user directory and enter the mkfs.jffs2 command below. Probably the most important argument to the utility is the erase block size. For the NAND part on the OMAP3530 EVM board the erase block is 128k Consult either u-boot, the kernel, or the data manual for the flash part used to find the erase block size.

mkfs.jffs2构建完毕并已经就位,现在是时候从target目录下制作jffs2 file system了。改变路径到/home/user目录下,输入如下的mkfs.jffs2命令。该工具最重要的参数或许就是擦除块的大小了。对于 OMAP3530 EVM 板子上的NAND部分而言,擦除块是128k。查询kernel,u-boot,或者数据手册的flash部分,以找到擦除块的大小。

[root@localhost util]# cd /home/user[root@localhost util]# mkfs.jffs2 -lqnp –e 128 -r target -o /tftpboot/rd-jffs2.bin

By building the file in the /tftpboot directory, the step of copying it over is eliminated.The file must now be written into flash at a specific location. In u-boot, the flash file system will get flashed to the physical address 0x780000 and will be mounted by the kernel from /dev/mtdblock4. The steps to perform this are:

通过构建/tftpboot目录下的文件,消除了拷贝它的步骤。现在,文件必须被写到flash中特定的位置。在u-boot里,flash file system会被烧写到物理地址 0x780000,会被kernel挂接到/dev/mtdblock4。执行这个的步骤如下:

    Unprotect the flash area where the file system will reside. 消除 对file system将要驻存的flash区域的保护Erase that area.擦除这个区域Download the rd-jffs2.bin file.下载rd-jffs2.bin文件Write it to flash.将该文件写到flash中Modify bootargs to support a JFFS2 file system as root on /dev/mtdblock4. 修改bootargs 以支持JFFS2 file system作为/dev/mtdblock4上的rootSave the environment variables. 保存环境变量

NOTE: (Not up to date – based on a different kernel – see SDK1.0.0 reprogramming scripts:C:\OMAP35x_SDK_1.0.0\board_utilities\scripts\ reflash-samsung.txt)

注意:(不要更新 – 基于不同的kernel – 查看SDK1.0.0重编程脚本:C:\OMAP35x_SDK_1.0.0\board_utilities\scripts\reflash-samsung.txt )

[root@OMAP3EVM /] # onenand unlock 0x0 0x8000000    [root@OMAP3EVM /] # mw.b 0x81600000 0xff 0x1400000   [root@OMAP3EVM /] # onenand erase block 60-1023            [root@OMAP3EVM /] # tftpboot 0x81600000 rd-jffs2.bin[root@OMAP3EVM /] # onenand write 0x81600000 0x780000 0x1400000[root@OMAP3EVM /] # setenv bootargs mem=88M noinitrd ip=dhcp console=ttyS0,115200n8  root=/dev/mtdblock4 rootfstype=jffs2[root@OMAP3EVM /] # saveenv

Boot the kernel and near the end of boot-up the following messages should be seen:

启动kernel,几乎在启动过程块结束的时候,下面的信息将会显示出来:

IP-Config: Gateway not on directly connected network.VFS: Mounted root (jffs2 filesystem).Freeing init memory: 136Keth0: link up, 100Mbps, full-duplex, lpa 0xCDE1init started: BusyBox v1.11.1 (2008-10-05 04:40:51 CDT)starting pid 288, tty : '/etc/init.d/rcS'   System initialization...   Hostname      : OMAP3EVM   Filesystem    : v1.0.0   Kernel release: Linux 2.6.22.18-omap3   Kernel version: #1 Tue Jul 1 17:16:34 IST 2008Mounting /proc            : [SUCCESS]Mounting /sys             : [SUCCESS]Mounting /dev             : [SUCCESS]Mounting /dev/pts         : [SUCCESS]Enabling hot-plug         : [SUCCESS]Populating /dev           : [SUCCESS]Disabling Power mgmt      : [SUCCESS]Turn off LCD after 1 hour : [SUCCESS]Mounting other filesystems: [SUCCESS]Starting syslogd          : [SUCCESS]Starting telnetd          : [SUCCESS]System initialization complete.Please press Enter to activate this console.

Creating and Booting a CRAMFS Root File System

Since CRAMFS is another embedded file system, the host Linux distribution might not have the mkcramfs utility. The source to the cramfs tools can be found athttp://sourceforge.net/projects/cramfs/. As usual, download, build, and install them.

创建并启动CRAMFS root file system

因为CRAMFS是另一个嵌入式的 file system,主机Linux发布可能没有mkcramfs工具。cramfs工具的源代码可以在http://sourceforge.net/projects/cramfs/找到。像往常一样,下载,构建,安装。

The first step is to edit the etc/init.d/rcS file so that the logging daemons do not get started. Since CRAMFS is a read-only file system, the serial console would be filled with errors as these loggers try to write messages to disk. After that, change to the /home/user directory and use the mkcramfs utility to create the file image. The –v argument only says to be verbose and display messages as the file system is built.

第一步是编辑 etc/init.d/rcS文件,这样,logging daemons就不会启动。因为CRAMFS是只读的 file system,串口终端会被错误填满,因为这些loggers试图将信息写入到disk上。在那之后,改变路径到 /home/user目录下,使用mkcramfs工具创建 file image。-v参数标明显示详细信息,在file system构建的时候显示信息。

[root@localhost home]# cd /home/user[root@localhost user]# mkcramfs –v target /tftpboot/rd-cramfs.bin

By building the file in the /tftpboot directory, the step of copying it over is eliminated.

通过构建/tftpboot目录下的文件,省去了拷贝它的步骤。

The file must now be written into flash at a specific location.

该文件现在必须被写到flash中特定的位置。

In u-boot, the flash file system will get flashed to the physical address 0x780000 and will be mounted by the kernel from /dev/mtdblock4. The steps to perform this are:

在u-boot中,flash file system会被烧写到物理地址 0x780000,并且会被kernel挂接到/dev/mtdblock4。执行这个的步骤如下:

    Unprotect the flash area where the file system will reside. 去除file system 将会驻存的flash 区域的保护Erase that area.擦除该区域Download the rd-cramfs.bin file.下载rd-cramfs.bin文件Write it to flash.写到flash中Modify bootargs to support a CRAMFS file system as root on /dev/mtdblock4.修改bootargs以支持CRAMFS file system作为 /dev/mtdblock4上的rootSave the environment variables. 保存环境变量
[root@OMAP3EVM /] # onenand unlock 0x0 0x8000000[root@OMAP3EVM /] # mw.b 0x81600000 0xff 0x1400000[root@OMAP3EVM /] # onenand erase block 60-1023[root@OMAP3EVM /] # tftpboot 0x81600000 rd-cramfs.bin[root@OMAP3EVM /] # onenand write 0x81600000 0x780000 0x1400000[root@OMAP3EVM /] # setenv bootargs mem=88M noinitrd ip=dhcp console=ttyS0,115200n8 root=/dev/mtdblock4 rootfstype=cramfs[root@OMAP3EVM /] # saveenv

Boot the kernel and near the end of boot-up the following messages should be seen:NOTE: (Not up to date – based on a different kernel)

VFS: Mounted root (cramfs filesystem) readonly.Freeing init memory: 136KMounting proc: OKMounting sysfs: OKMounting /dev: OKCreating local mdev devices   System initialization...   Hostname      : OMAP3EVM   Filesystem    : v1.0.0   Kernel release: Linux 2.6.22.18-omap3   Kernel version: #1 Tue Jul 1 17:16:34 IST 2008Mounting devpts: OKSetting up networkingConfiguring lo: OKMounting filesystems: OKSystem initialization complete.Please press Enter to activate this console.

Enhancing the Root File System

The root file system built contains only the bare minimum files to operate. Kernel driver modules have not been added yet. Also, as applications are built and added, the shared libraries used by the applications will need to be added. The file system will get larger when these files are added.

增强 root file system

构建的root file system只包含了较少的能够操作的文件。kernel 驱动模块还没有添加。另外,当应用程序构建并添加的时候,应用程序使用的共享库需要被添加进来。当这些文件加入进来的时候,file system将会变得比较大。

Add the Kernel Driver Modules to the Root File System

Any drivers built as modules need to be added to the target root file system. This is fairly simple; after building the kernel, build the modules, and then use the same kernel Makefile to install the files to the target.

添加kernel驱动模块到root file system

任何以模块形式构建的驱动需要被添加到 target root file system中。这很简单;在构建好kernel之后,构建modules,之后,使用相同的kernel Makefile以将这些文件安装到target中

[root@localhost 2.6_kernel]# make modules[root@localhost 2.6_kernel]# make INSTALL_MOD_PATH=/home/user/target modules_install

After the second make is performed, the kernel modules will be copied to the /home/user/target/lib/modules directory. One problem still exists – the modules still have debug information so they are larger than they need to be. When debug information is no longer needed, use the arm-none-linux-gnueabi-strip utility to remove it. Unfortunately the strip utility does not have a recursive option to go into each directory and strip the driver. If there are only a few drivers, the find utility can be used to find each .o file recursively and then pass the file name to strip. An example is shown below.

在第二个make执行之后,kernel modules将会被拷贝到/home/user/target/lib/modules目录下。仍旧存在一个问题 —— modules仍旧含有调试信息,因此它们比我们想要的还大一些。当调试信息不再需要的时候,使用 arm-none-linux-gnueabi-strip工具将它们剔除。不幸的是,strip工具并没有递归的选项以进入到每一个目录,并剔除driver中的无用内容。如果只有几个drivers的话,find工具可以用来递归地找到每一个.o文件,之后,传递文件名给strip。下面是一个例子。

[root@localhost user]# cd /home/user/target/lib/modules[root@localhost modules]# arm-none-linux-gnueabi-strip `find . –name “*.ko”`

Note that the ` character is the “tick” key that is on the left-hand side of the keyboard and is a lowercase ~.

注意到,` 字符是位于键盘上左手边的"tick"键,是小写的~。

RAMDISK Considerations

As files get added to the target root file system, the image size will grow beyond 16M. The kernel must be configured to the new RAMDISK size and re-built. See section “3.3 Configure the Linux Kernel for RAMDISK support” for more information on how to change the RAMDISK size in the kernel. The amount of RAM used for the RAMDISK should not be too big so that the kernel has enough RAM to load and run programs. For example, on a board with only 32M RAM, a 20M RAMDISK would only leave 12M for the kernel to use. This could cause a shortage of memory for programs to run.If a development platform has more then 32M, then that should also be reflected in the u-boot environment variable “bootargs”. For example, assume a development platform now has 64M of RAM. The bootargs variable could be changed from “mem=32M” to “mem=64M”. A RAMDISK of 20M would no longer be a problem.One last hint on keeping the RAMDISK image small. Use the arm-none-linux-gnueabi-strip program to strip off unneeded headers and debug information once an application or driver has been fully debugged and ready for inclusion in the image.

RAMDISK的考量

因为文件加入到了target root file system中,image大小会超过16M。kernel必须配置新的RAMDISK大小,并重新构建。查看章节 “3.3 Configure the Linux Kernel for RAMDISK support” ,获取更多的关于怎么改变kernel中RAMDISK大小的信息。用于RAMDISK的RAM的容量不应该太大,以便kernel有足够的RAM以加载并运行程序。例如,在只有32M RAM的板子上,20M大小的RAMDISK只留下了12M给kernel使用。这会在程序运行的时候,引起内存不足。如果一个开发平台有超过32M的RAM,这会反映在u-boot环境变量“bootargs”中。例如,假定开发平台现在有64M的RAM。bootargs 变量将会由“mem=32M”改变为“mem=64M”。20M的RAMDISK将不会有什么问题。最后一点提醒是,保持RAMDISK image尽量的小。一旦应用程序或者驱动已经完全调试完毕,并且已准备好加入到iamge中,可以使用 arm-none-linux-gnueabi-strip程序剔除不需要的头和调试信息。

Trouble Shooting

If you are having problems booting the kernel please refer to this article for help.

问题定位

如果在启动kernel过程中有什么问题,可以到 http://processors.wiki.ti.com/index.php/Kernel_-_Common_Problems_Booting_Linux寻求帮助。

最有效的资本是我们的信誉,它24小时不停为我们工作。

Creating a Root File System for Linux on OMAP35x – 为Linux基

相关文章:

你感兴趣的文章:

标签云: