嵌入式linux中文站在线图书

  Previous section   Next section


Booting the Tri-M MZ104 and the COTS PC with a Flash IDE Drive

The x86 CPU powers the final two targets: the Tri-M MZ104 and COTS PC. These targets boot from and use Flash IDE drives. This section presents the flash IDE technology selected and shows how to compile the kernel, create the target root filesystem, and prepare the flash drive for booting.

Flash IDE Technology

Flash technology has matured and provides a "no moving parts" solution for embedded designs. Flash ATA IDE drive capacity ranges from 8MB to 384MB, with single-piece pricing starting at $25 (as of fall 2001). The smallest size, 8MB, provides ample capacity for the Project Trailblazer root filesystem. The following components were selected for evaluation:

TIP

Connecting a Compact Flash memory card to an IDE controller requires an adapter. Using Compact Flash IDE drives eliminates moving parts from your design.


Pricing shown here reflects the manufacturer's suggested retail price in fall 2001. The SanDisk Compact Flash Card and SST ATA-Disk chip claim 100% ATA IDE compatibility. This means the Project Trailblazer engineers should be able to treat it like a regular drive (that is, they should be able to use fdisk, format, copy, and so on). The engineers also discovered that removable IDE drive bays, such as the StarTech SNT127A (www.startech.com), ease swapping IDE drives during development.

Preparing the Tri-M MZ104 and the COTS PC

Installing Linux with a distribution CD, such as Debian or Red Hat, on a commercial off-the-shelf PC is easy. Just put in the CD, boot, and install. As you saw earlier in this chapter, a minimum Debian installation requires 67MB and Red Hat requires 382MB, both of which are beyond the capacity of the Project Trailblazer Flash IDE drives.

During these installations, what actually happens? The distribution installation program partitions the destination drive, and if necessary, formats the drive, creates directories, extracts files from an archive file into these directories, configures various systems and subsystems, prepares the drive to be bootable, and then reboots. Sounds simple enough, doesn't it?

Preparing the root filesystem presents the largest challenge for distribution vendors. They have to select from among the thousands of existing programs. The Project Trailblazer engineers decided earlier in this chapter what their target Linux machines require. They also know what configuration files are necessary to boot the target root filesystem. Therefore, they now have to partition and format the Flash IDE drive, compile the x86 kernel, build the target root filesystem on the IDE drive, and boot the target board.

Partitioning and Formatting the Flash IDE Drive

The Tri-M MZ104 or the COTS PC will boot from and mount its root filesystem from a Flash IDE drive. Here are the steps in partitioning and formatting the Flash IDE drive using tbdev1:

  1. Using an IDE-to-Compact Flash adapter, connect the Compact Flash IDE drive to tbdev1's secondary controller. Set its jumper to master. Note that partitioning the Compact Flash IDE drive will destroy all data on it.

  2. Boot tbdev1 and log in as root.

  3. Use the dmesg command to get a report on the Compact Flash drive:

    TIP

    If your PC doesn't recognize the Compact Flash IDE drive, you might have to upgrade your PC BIOS.

    root@tbdev1[506]: dmesg
    Linux version 2.2.19pre17-idepci (root@oink) (gcc version 2.7.2.3) #1
    BIOS-provided physical RAM map:
    . . .
        ide0: BM-DMA at 0xf000-0xf007, BIOS settings: hda:pio, hdb:pio
        ide1: BM-DMA at 0xf008-0xf00f, BIOS settings: hdc:pio, hdd:pio
    hda: Maxtor 85120 A8 -, ATA DISK drive
    hdb: probing with STATUS(0x00) instead of ALTSTATUS(0x50)
    hdb: probing with STATUS(0x00) instead of ALTSTATUS(0x50)
    hdc: SunDisk SDCFB-40, ATA DISK drive
    ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
    ide1 at 0x170-0x177,0x376 on irq 15
    hda: Maxtor 85120 A8 -, 4884MB w/256kB Cache, CHS=622/255/63
    hdc: SunDisk SDCFB-40, 38MB w/1kB Cache, CHS=612/4/32
    

    The dmesg output shows that the SunDisk SDCFB-40 is located on hdc, which is the 40MB Flash disk.

  4. Partition the drive with the cfdisk command on /dev/hdc:

    TIP

    fdisk and cfdisk both partition hard disks. cfdisk is easier to use.

    root@tbdev1[507]: cfdisk /dev/hdc
    
  5. The cfdisk screen presents a list of current partitions and a menu along the bottom. Use the up and down arrow keys to select from the partition list. Use the right and left arrow keys to select a menu item. Select the first partition, and then select Delete and press Enter. Continue until you have deleted all the drive partitions.

  6. Select Free Space from the partition list.

  7. Make a new partition by selecting the New menu, and then select Primary. Set the size to use the remainder of the drive space, and then press Enter.

  8. The partition list should now have an hdc1 entry. With hdc1 selected, select the Type menu and set the type to 83 (Linux).

  9. Select hdc1 from the partition list, and then make hdc1 bootable by selecting the Bootable menu.

  10. Finalize this partitioning by selecting Write and confirm the write operation by typing yes.

  11. Exit from the cfdisk screen by selecting Quit.

  12. The partition you just created is /dev/hdc1. Format it with this command:

    root@tbdev1[510]: mke2fs /dev/hdc1
    
  13. Mount the drive on /mnt and check disk usage with these commands:

    root@tbdev1[515]: mount /dev/hdc1 /mnt
    
    root@tbdev1[516]: df
    
    Filesystem           1k-blocks      Used Available Use% Mounted on
    
    /dev/hda2              4854280   1838440   2769244  40% /
    
    /dev/hdc1                37910        13     35940   0% /mnt
    
  14. Unmount /dev/hdc1 by using this command:

    root@tbdev1[517]: umount /dev/hdc1
    

The flash IDE drive is now ready for the kernel, the root filesystem, and booting preparation.

Compiling the i386 Kernel

Before you can boot the Tri-M MZ104 or COTS PC, you need to compile the kernel for it. This section describes how to compile the 2.4.10 kernel for the x86 target boards. Here are the steps to compile the x86 kernel:

  1. Download the kernel source from www.kernel.org into the /usr/src directory. This example uses version 2.4.10:

    root@tbdev1[503]: cd /usr/src
    root@tbdev1[504]: wget  http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.10.tar.gz
    
  2. Extract the kernel source from the downloaded compressed tar file:

    root@tbdev1[505]: tar zxvf /root/cross/linux-2.4.10.tar.gz
    
  3. You should now have a directory /usr/src/linux. Configure the kernel by using these commands:

    root@tbdev1[506]: cd /usr/src/linux
    root@tbdev1[507]: make mrproper
    root@tbdev1[508]: make menuconfig
    

    NOTE

    For more kernel compiling information, please see "The Linux kernel HOWTO: Compiling the kernel."4

  4. Scan through the menus and exclude (by using [ ]) anything you don't require, such as SCSI support, sound, plug-and-play, or USB. The more items you exclude, the smaller the kernel. For now, don't compile anything as modules. Items you do want built in (marked by [*]) include the following:

    • Processor type and features (select your processor family, the MZ104 has a 486 processor)

    • Network device support

      • Select Ethernet (10Mbps or 100Mbps)

      • Select Other ISA cards

      • Select NE2000/NE1000 support, the MZ104 has an NE2000 ISA card.

      • Remember to select built-in[*], not module [M]

  5. Exit from make menuconfig and save the new kernel configuration:

    root@tbdev1[509]: make dep
    root@tbdev1[510]: make bzImage
    

This should create a compressed kernel image called bzImage in the arch/i386/boot directory. The buildrootfilesystem script requires this file.

Building the Target root Filesystem on the Compact Flash IDE Drive

The target root filesystem can now be placed on the flash IDE drive. The drive has been partitioned, formatted, and checked, and the kernel has been compiled. MontaVista's Journeyman FTP site provides the RPMs for root filesystem required programs. The buildrootfilesystem script also works for x86 platforms. The script performs the following steps:

  1. It downloads RPMs and extracts their contents into a temporary directory.

  2. It then copies the required target root filesystem programs and creates various system configuration files in the /tftpboot/i386-rootfs directory.

  3. It installs the Linux loader (LILO) into the master boot record of the flash drive, /dev/hdc. Installing LILO makes the drive boot to Linux.

  4. It copies the target root filesystem to the drive and checks the filesystem for integrity. See the script section "Step 9: Prepare the root Filesystem for Operation on the Target Board," earlier in this chapter.

  5. Run buildrootfilesystem to create and prepare the flash IDE drive for Linux boot and operation:

    root@tbdev1[511]: cd /root/cross
    root@tbdev1[512]: buildrootfilesystem i386
    
  6. You can check the flash IDE drive by mounting it and examining the file contents:

    root@tbdev1[513]: mount /dev/hdc1 /mnt
    root@tbdev1[514]: cd /mnt
    root@tbdev1[515]: ls
    bin/  boot/  dev/  etc/  lib/  lost+found/  proc/  sbin/  tmp/  usr/
    root@tbdev1[516]: ls -l boot/bzImage
    -rw-r--r--    1 root     root       876986 Aug 25 00:53 boot/bzImage
    root@tbdev1[517]: umount /dev/hdc1
    
  7. Shut down tbdev1 with the init 6 command, power down, and remove the flash IDE drive from the secondary IDE controller.

Booting the Tri-M MZ104 Target

The Flash IDE drive contains the kernel and the root filesystem for the x86 target boards. Connect the Flash IDE drive to the x86 target primary IDE controller and power up. The target BIOS should find the flash IDE drive. LILO starts by showing the boot prompt then the kernel loads. The kernel mounts the root filesystem. The kernel then executes init, which executes bash. Here's the console output for the MZ104 power-up to bash prompt boot sequence:

LILO boot:
Loading linux...............
Linux version 2.4.10 (root@tbdev1) (gcc version 2.95.2 20000220 (Debian GNU/Linux)) #1 
graphics/ccc.gifFri Dec 7 02:28:38 MST 2001
BIOS-provided physical RAM map:
 BIOS-e820: 0000000000000000 - 000000000009f400 (usable)
 BIOS-e820: 000000000009f400 - 00000000000a0000 (reserved)
 BIOS-e820: 00000000000d0000 - 00000000000d4000 (reserved)
 BIOS-e820: 00000000000e5c00 - 0000000000100000 (reserved)
 BIOS-e820: 0000000000100000 - 0000000002000000 (usable)
 BIOS-e820: 00000000fff80000 - 0000000100000000 (reserved)
On node 0 totalpages: 8192
zone(0): 4096 pages.
zone(1): 4096 pages.
zone(2): 0 pages.
Kernel command line: auto BOOT_IMAGE=linux ro root=301 BOOT_FILE=/tmp/tmpmnt/boot/bzImage
Initializing CPU#0
Console: colour VGA+ 80x25
Calibrating delay loop... 39.83 BogoMIPS
Memory: 30020k/32768k available (1098k kernel code, 2360k reserved, 313k data, 180k init, 
graphics/ccc.gif0k highmem)
Checking if this processor honours the WP bit even in supervisor mode... Ok.
Dentry-cache hash table entries: 4096 (order: 3, 32768 bytes)
Inode-cache hash table entries: 2048 (order: 2, 16384 bytes)
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 8192 (order: 3, 32768 bytes)
CPU: Before vendor init, caps: 00000000 00000000 00000000, vendor = 1
CPU: After vendor init, caps: 00000000 00000000 00000000 00000000
CPU:     After generic, caps: 00000000 00000000 00000000 00000000
CPU:             Common caps: 00000000 00000000 00000000 00000000
CPU: Cyrix Cx486DX4
Checking 'hlt' instruction... OK.
POSIX conformance testing by UNIFIX
PCI: PCI BIOS revision 2.10 entry at 0xfd99e, last bus=0
PCI: Using configuration type 1
PCI: Probing PCI hardware
PCI: Cannot allocate resource region 0 of device 00:00.0
 got res[1040:107f] for resource 1 of PCI device 1078:0400 (Cyrix Corporation)
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Starting kswapd
Detected PS/2 Mouse Port.
pty: 256 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIAL_PCI enabled
ttyS00 at 0x03f8 (irq = 4) is a 16550A
ttyS01 at 0x02f8 (irq = 3) is a 16550A
block: 64 slots per queue, batch=8
Uniform Multi-Platform E-IDE driver Revision: 6.31
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx
PCI_IDE: unknown IDE controller on PCI bus 00 device 92, VID=1078, DID=0402
PCI_IDE: chipset revision 1
PCI_IDE: not 100% native mode: will probe irqs later
    ide0: BM-DMA at 0x1000-0x1007, BIOS settings: hda:pio, hdb:pio
    ide1: BM-DMA at 0x1008-0x100f, BIOS settings: hdc:pio, hdd:pio
hda: SunDisk SDCFB-40, ATA DISK drive
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
hda: 78336 sectors (40 MB) w/1KiB Cache, CHS=612/4/32
Partition check:
 hda: hda1
Floppy drive(s): fd0 is 1.44M
FDC 0 is a National Semiconductor PC87306
ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)
Last modified Nov 1, 2000 by Paul Gortmaker
NE*000 ethercard probe at 0x300: 00 40 33 55 3d c7
eth0: NE2000 found at 0x300, using IRQ 5.
loop: loaded (max 8 devices)
Linux Kernel Card Services 3.1.22
  options:  [pci] [cardbus]
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP, IGMP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 2048 bind 2048)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
ds: no socket drivers loaded!
VFS: Disk change detected on device ide0(3,1)
 hda: hda1
VFS: Mounted root (ext2 filesystem) readonly.
Freeing unused kernel memory: 180k freed
INIT: version 2.78 booting
INIT: Entering runlevel: 2
Starting Network
bash-2.04#

You're now at the bash prompt on the COTS PC.

Tri-M MZ104 Target Platform Boot Requirements Review

In this section, the seven PBRs are reviewed for the MZ104. Remember that each target board needs to fulfill the seven PBRs in order to be used in Project Trailblazer.

PBR-1 for the MZ104

The target board should use Linux kernel 2.4 or greater. Here's the MZ104 console output during the boot process:

Linux version 2.4.10 (root@tbdev1) (gcc version 2.95.2 20000220 (Debian GNU/Linux)) #1 
graphics/ccc.gifFri Dec 7 02:28:38 MST 2001

PBR-1 is fulfilled because Linux version 2.4.10 boots.

PBR-2 for the MZ104

The target board will execute the bash shell. Exiting from the bash shell re-executes the bash shell. On the MZ104 console, exit from the bash shell by using the exit command:

bash-2.04# exit
exit
bash-2.04#

PBR-2 is fulfilled because exiting from bash respawns bash. init is properly configured.

PBR-3 for the MZ104

The system should execute the bash shell without security authentication. Here's the MZ104 console output during the boot process:

INIT: version 2.78 booting
INIT: Entering runlevel: 2
Starting Network
bash-2.04#

PBR-3 is fulfilled because init starts bash without authentication.

PBR-4 for the MZ104

The system should boot, initialize the Ethernet hardware, set a static IP address, and be configured to use DNS. At the bash prompt, use ifconfig to display the Ethernet hardware configuration and use ping to verify proper DNS configuration:

bash-2.04# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:40:33:55:3D;C7
          inet addr:192.168.1.23  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17 errors:1 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:5 Base address:0x300
bash-2.04# ping yahoo.com
PING yahoo.com (216.115.108.245): 56 data bytes
64 bytes from 216.115.108.245: icmp_seq=0 ttl=246 time=49.2 ms
64 bytes from 216.115.108.245: icmp_seq=1 ttl=246 time=48.8 ms
64 bytes from 216.115.108.245: icmp_seq=2 ttl=246 time=53.0 ms

PBR-4 is fulfilled because the Ethernet hardware is initialized. The target board's resolver translated yahoo.com to 216.115.108.245. This verifies proper DNS configuration.

PBR-5 for the MZ104

The system should contain the ping program to debug network programs:

bash-2.04# ping yahoo.com
PING yahoo.com (216.115.108.245): 56 data bytes
64 bytes from 216.115.108.245: icmp_seq=0 ttl=246 time=49.2 ms
64 bytes from 216.115.108.245: icmp_seq=1 ttl=246 time=48.8 ms
64 bytes from 216.115.108.245: icmp_seq=2 ttl=246 time=53.0 ms

PBR-5 is fulfilled because a yahoo.com ping is successful.

PBR-6 for the MZ104

The system should be capable of executing the Project Trailblazer compiled version of helloworld. At the bash prompt, execute the helloworld program:

bash-2.04# /tmp/helloworld-i386
Hello world 1 times!
Hello world 2 times!
Hello world 3 times!
. . .

PBR-6 is fulfilled because the i386 version of helloworld executes.

PBR-7 for the MZ104

The system should use the current version of GNU glibc. At the bash prompt, list the library directory and confirm the current versions:

bash-2.04# ls /lib
ld-2.2.3.so      libncurses.so.5.2      libresolv.so.2
ld-linux.so.2    libnss_dns-2.2.3.so    librt-2.2.3.so
libc-2.2.3.so    libnss_dns.so.2        librt.so.1
libc.so.6        libnss_files-2.2.3.so  libstdc++-3-libc6.1-2-2.10.0.so
libdl-2.2.3.so   libnss_files.so.2      libstdc++-libc6.1-2.so.3
libdl.so.2       libproc.so.2.0.7       libutil-2.2.3.so
libm-2.2.3.so    libpthread-0.9.so      libutil.so.1
libm.so.6        libpthread.so.0
libncurses.so.5  libresolv-2.2.3.so

PBR-7 is fulfilled because the target boots with the current version of GNU glibc.

The Tri-M MZ104 fulfills all the PBRs.


      Previous section   Next section
    Top