Creating the root Filesystem
The Project Trailblazer engineers' decision to use the MontaVista compiled versions of the binary, library, and configuration files that are required in order for the kernel to execute init and bash was just the beginning. Many Linux programs aren't distributed singly; rather, they're grouped by functionality and distributed as a package. For example, the ls program doesn't exist as the ls package, nor does the ls source code exist on its own. The GNU developers bundled ls and other file utilities into the fileutils package, which contains chgrp, chmod, chown, cp, dd, df, dir, dircolors, du, install, ln, ls, mkdir, mkfifo, mknod, mv, rm, rmdir, touch, vdir, and sync. If you want only the ls program, you have to extract it from the fileutils package.
You should extract files from packages into a temporary directory. After all the packages are extracted, the required binaries from Table 4.1 should be copied from the temporary directory to a new root filesystem directory. Linux distribution packages, whether they're Red Hat Package Management (RPMs2) files or Debian Package Management (debs3) files, contain extra files, such as man pages, that may not have any application in the new root filesystem. These extra files just take up space. When you build the root filesystem, the contents of a package are extracted to a temporary directory and then you can copy required files to the new root filesystem directory. Later, this new root filesystem directory can be used to create the actual root filesystem that the target systems will mount.
Deciding Which Package to Use
The engineers used the Debian Web site (www.debian.org) to determine what packages contained the programs the new root filesystem requires. They searched the Debian package section (www.debian.org/distrib/packages) for the program they wanted, using the "search on descriptions" option. For example, they found that the ls program is contained in the fileutils package. If they couldn't determine which package to use for a program, they explored the MontaVista Journeyman FTP site (ftp.mvista.com) to find it. Table 4.2 shows the engineers' list of files from Table 4.1 and the packages in which these programs are contained.
The Process for Building the root Filesystem
The procedure for building a root filesystem consists of the two steps: Edit the buildrootfilesystem script PACKAGES line, incorporating the package information from Table 4.2, and then execute the buildrootfilesystem script. The buildrootfilesystem script performs the following operations:
buildrootfilesystem simplifies the creation of the root filesystem for the ARM, PowerPC, and i386 target boards. This script downloads the current versions of packages, extracts their contents, copies required programs, strips these programs of their debugging information, creates configuration files, creates devices, and prepares the root filesystem for target board operation. Before you run the buildrootfilesystem script, you need to add two additional packages to the tbdev1 workstation that you built in Chapter 3: lynx and alien. The buildrootfilesystem script uses lynx in dump mode to get the contents of an FTP directory. alien converts packages from one format to another (for example, it converts an RPM file to a compressed tar archive). You can start building the root filesystem by installing lynx and alien and then downloading the buildrootfilesystem script from the Web site. On tbdev1, log in as root and execute these commands:
root@tbdev1: apt-get -y install lynx root@tbdev1: apt-get -y install alien root@tbdev1: cd /root/cross root@tbdev1: wget http://www.embeddedlinuxinterfacing.com/chapters/04/ buildrootfilesystem/buildrootfilesystem root@tbdev1: chmod 755 buildrootfilesystem
The following sections describe the buildrootfilesystem script steps.
Step 1: Determine What Packages to Download
The Project Trailblazer engineers determined what packages are required for the root filesystem. They edited the PACKAGES line in the buildrootfilesystem script. Step 1 sets the PACKAGES variable:
PACKAGES="glibc-2 bash procps textutils fileutils shellutils sysvinit netbase libncurses libstdc mount telnet-client net-tools ping gdbserver"
Step 2: Create the Build and New Target root Filesystem Directories
Step 2 of the buildrootfilesystem script creates the build and the new target root filesystem directories. You can use the same build directory from Chapter 2: /root/cross/build. A separate directory, one per architecture within /root/cross/build, holds the downloaded RPMs. buildrootfilesystem then creates a separate root filesystem directory in /tftpboot for each architecture in the case of Project Trailblazer, /tftpboot/powerpc-rootfs, /tfpboot/arm-rootfs, and /tftpboot/i386-rootfs. In Chapter 5, "Debugging," targets use the /tftpboot directories to mount their root filesystems using Network File System (NFS).
Within the root filesystem, buildrootfilesystem creates these directories: dev, etc, etc/init.d, bin, sbin, lib, usr, usr/bin, proc, and tmp.
Step 3: Download the Packages
Step 3 of the buildrootfilesystem script uses lynx to download the current list of files at the MontaVista FTP site. From this list, buildrootfilesystem scans PACKAGES and downloads the package RPM file by using wget.
Step 4: Extract the Packages' Contents into a Temporary Directory
The MontaVista binaries are contained within an RPM file. You don't want to install the entire RPM file contents; you just want to extract the contents to a temporary directory. The program alien converts the RPM into a compressed tar archive (called a tarball). Using tar decompresses the archive and extracts the contents into a temporary directory. This seems like a lot of work, but this extraction instead of installation into a temporary directory will make step 5 easier.
Step 5: Copy the Required Programs to the New Target root Filesystem Directory
The tar command from step 4 extracts the MontaVista binaries in the temporary directory, for example /root/cross/builds/powerpc-rootrpms/opt/hardhat/devkit/ppc/8xx/target. Step 5 of the buildrootfilesystem script changes into that directory, and then copies the required binaries from lib, usr, sbin, bin, and usr/bin to the new root filesystem directory.
In step 5, the script also creates helloworld.c in the /tmp directory and then compiles it. We'll use this cross-compiled version of helloworld to verify PBR-6.
Step 6: Strip the Required Programs of Their Debugging Information
Step 6 of the buildrootfilesystem script uses the cross-compiled version of strip to remove the debugging symbols from libraries and other binary executables within the new target root filesystem. How can you tell if a binary contains debugging symbols? You use the file command, as in the following example:
root@tbdev1: cd /root/cross/builds/powerpc-rootrpms/ root@tbdev1: cd opt/hardhat/devkit/ppc/8xx/target/ root@tbdev1: file bin/bash bin/bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked (uses shared libs), not stripped root@tbdev1: ls -l bin/bash -rwxr-xr-x 1 5003 510 702350 May 23 15:16 bin/bash* root@tbdev1: powerpc-linux-strip -s -g bin/bash root@tbdev1: file bin/bash bin/bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked (uses shared libs), stripped root@tbdev1: ls -l bin/bash -rwxr-xr-x 1 5003 510 605480 Aug 23 15:08 bin/bash*
Step 7: Create Extra Configuration Files
Step 7 of the buildrootfilesystem script creates the following files:
Step 8: Create the Devices in the /dev Directory
Step 8 of the buildrootfilesystem script creates the tty, tty0, ttyS0, console, null, and ram devices in the /dev directory. These are the minimum devices needed for Linux to run.
Step 9: Prepare the root Filesystem for Operation on the Target Board
When step 8 completes, the new target root filesystem, located in /tftpboot /powerpc-rootfs, is almost ready for use. Step 9 of the buildrootfilesystem script prepares the root filesystem for the target board. The ARM and PowerPC target boards in field operation will extract the contents of their root filesystem into a RAM disk. The i386 platforms won't use a RAM disk; instead, they will use their flash memory as an IDE hard disk. During debugging in Chapter 5, this root filesystem won't exist as a RAM disk or hard disk. The platforms will mount their root filesystem over the Ethernet network via NFS, which makes remote debugging of code more efficient.
In summary, the preparation of the root filesystem is dependent on the field application and target board architecture. The specific preparations for Project Trailblazer are as follows:
Each preparation requires different procedures, as described in the following sections.
Step 9, Preparation A: The root Filesystem on a RAM Disk
If it is configured with RAM disk support, the kernel contains code to create a disk drive in RAM memory, extract the contents of this RAM disk from another location, and then mount this RAM disk as its root filesystem. This common procedure allows embedded system operation without a hard disk. Keep in mind that the RAM disk exists only until the power cycles or the machine reboots. The contents of the RAM disk are not typically stored across reboots. (Project Trailblazer accepts this limitation because no field unit will store information locally.)
To prepare a RAM disk, the buildrootfilesystem script implements these steps:
Step 9 of the buildrootfilesystem script contains the commands to create, fill, and compress ramrootfs. See the section "Booting the Embedded Planet RPX-CLLF," later in this chapter for specific instructions on getting the PowerPC board booted using ramrootfs. See the section "Booting the Brightstar Engineering MediaEngine," later in this chapter, for specific instructions to boot the ARM board.
Step 9, Preparation B: The root Filesystem on a Flash IDE Drive
The buildrootfilesystem script can completely configure an IDE drive to boot an i386 platform. With a partitioned drive, either hard disk or Flash disk, located as the master on tbdev1's secondary IDE controller (that is, /dev/hdc1), step 9 in the script creates additional devices, creates lilo and mount configuration files, copies the root filesystem to the drive, and executes lilo and installs lilo in the master boot record (MBR) of the second drive. When step 9 completes, you can place this second drive on the primary IDE controller, and Linux will boot from it. See the section "Booting i386 Platforms," later in this chapter for specific instructions to boot the i386 boards.
buildrootfilesystem gives you the option to erase all the files in /dev/hdc1 to effectively make a clean minimum root filesystem. Make sure that you have your disk drives connected properly before you erase all the files.
Step 9, Preparation C: The root Filesystem for NFS Mounting
Chapter 5 addresses mounting the target root filesystem using NFS. See that chapter for more information.