Building the DiskOnChip Files

This procedure uses the Embedded Linux Workshop presented in Chapter 7. We’ll use the workshop to re-create our favorite example, the Minicom appliance (also used in Chapter 8).

1.
Acquire root privileges for your machine, if you don’t already have them. Because the Embedded Linux Workshop mounts and unmounts filesystems, there’s really no way to run it except as root.

2.
Download the Embedded Linux Workshop. It’s available from http://elw.sourceforge.net or ftp://elw.sourceforge.net/pub/elw/. There are a lot of files to download if you want the full source to the ELW. However, for now you only need the workshop itself. It will be named elw-X.Y.Z.tgz, where X.Y.Z is the current version number. If you just want to experiment with the Embedded Linux Workshop, you won’t need to download all the source code to all the packages. However, if you’re targeting a non–x86 CPU or want to do more than fool around with the software, you’ll have to download most of the Embedded Linux Workshop source code over time.

3.
cd /usr/local 

Change to the /usr/local directory.This is the easiest place to install the Embedded Linux Workshop. If you decide to install it somewhere else, make sure that you point your /usr/local/elw symbolic link to the right place.

4.
tar xvzf /tmp/elw-X.Y.Z.tgz 

Install the Embedded Linux Workshop into the /usr/local directory.The example command assumes that you downloaded the elw-X.Y.Z.tgz tarball into the /tmp directory.

5.
rm -f elw && ln -s elw-X.Y.Z elw 

Remove the old elw symbolic link and create a new one that points to the directory you just installed. If you need to revert to a previous version of the Embedded Linux Workshop, you can just point this symbolic link back to the old version.

6.
cd /usr/bin && rm -f elw && ln -s /usr/local/elw/bin/elw elw 

Remove any old /usr/bin/elw link and create a new one that points to the elw script in the elw package.

7.
cd ∼yourhome/projects 

Change to the directory where you want your new project to live.

8.
elw --newproject minicom 

Use the elw command installed in the previous steps to create the new project. Several directories and files are created within the new minicom directory.

9.
cd minicom/arch/i386/src 

Change to the src directory.

10.
mkdir minicom 

Create the minicom directory, in which you’ll keep the source code for Minicom.

11.
mkdir DOC 

Create the DOC directory (short for DiskOnChip), in which you’ll keep the source code for the DiskOnChip driver.

12.
cd minicom 

Change to the new minicom directory.

13.
Download Minicom from www.pp.clinet.fi/∼walker/minicom.html. If it’s not there, use www.freshmeat.net to find it. If you have trouble downloading it, use http://ftpsearch.lycos.com to search for the filename; choose a site near you to download from. At the time of this writing, the latest version was 1.83.1.

14.
tar xzf minicom-1.83.1.src.tar.gz 

Untar Minicom. (To see the files that are created, change xzf in the command to xvzf.)

15.
ln -s minicom-1.83.1 minicom 

Create a symbolic link named minicom that points to minicom-1.83.1.This symlink will be used in the opt/minicom/Makefile; this way, if you decide to upgrade to a later version of Minicom in the future, you can just change the symbolic link to point to the new version.

16.
cd minicom/src 

Change to the minicom source directory.

17.
We have to make a small change to the source code for Minicom, to make sure that it works properly in our mini-environment.We’ll remove a Minicom security feature that’s unnecessary in our embedded application. In minicom.c, search for the line that reads as follows:

if (real_uid == 0 && dosetup == 0) {

Delete about 61 lines—up to, but not including the following line:

buf[0] = 0; 

If these lines are not removed, Minicom will bail out at this point. Since we don’t have to be concerned with permissions and correct users in our embedded environment, it’s safe to simply remove this code.

Save your changes.

18.
make 

Make the minicom executable file. If everything goes well, you’ll end up with an executable file called minicom.

19.
cd ../../../kernel 

Change to the kernel source directory.

20.
Download the current production Linux kernel from

ftp.kernel.org/pub/linux/kernel. 

At the time of this writing, the latest version was 2.2.15. It shouldn’t really matter which version of the kernel you use for this exercise; anything from version 2.0 through 2.4+ should work just fine. However, the binary-only DiskOnChip driver may have trouble with some kernels. It’s best to use whichever kernel the DiskOnChip driver is compiled on.That may be difficult to do until you try it with one kernel and it complains.

21.
tar xzf linux-2.2.15.tar.gz 

Untar the kernel.When you’re done, there will be a new directory named linux.

Normally, as soon as I untar a kernel I rename it to linux-X.Y.Z and create a symbolic link named linux back to it, so I’ll know what it is later on. Be very careful not to blow away your current sources if you already have a linux directory. On more than one occasion I’ve untarred a newly downloaded kernel source tree and blown away another kernel I was already working on.

22.
cd ../DOC 

Change to the DiskOnChip source directory, DOC.

23.
Download the latest DiskOnChip drivers from M-System’s Web site (www.m-sys.com).You may have to fill out a form to do this.

24.
tar xvf DOC_Linux4.2.1.tar 

M-Systems is trying to be Linux-friendly, but as of this writing they haven’t quite figured it out. Every time I test this step, M-Systems has changed the way their download works, so if the filename isn’t right or what you get doesn’t match the instructions, you’re on your own.The package you get is put together in a non–Linux way. It’s a tar file containing a License.TXT and a tgz. The tgz contains the actual driver code.

25.
tar xvzf driver*tgz 

Untar the tgz. You’ll get a new tree, the root of which should look something like Linux_DOC_4.2.1.

26.
cd Linux_DOC_4.2.1/driver 

This directory contains the files we need. README.kit contains a detailed set of instructions for the Linux DiskOnChip driver.We’re interested in section 3, the part that talks about compiling a loadable module.

27.
./create-standalone driver-patch ../../../kernel/linux 

The ../../kernel/linux directory should be the Linux directory you created earlier.This step is supposed to create a new directory named doc-module in the root of the Linux source tree—the driver files will end up in this new directory.

28.
[ -d doc-module ] && mv doc-module ../../../kernel/linux 

This step fixes a bug in the create-standalone script. In the current driver version (as of this writing), the doc-module is created in the wrong place.This step puts it where it belongs—in the kernel source tree.

29.
./mknod_fl 

This script creates all the device entries for the DiskOnChip in the /dev directory.You can’t do anything with these devices until you’ve loaded the driver.

30.
[ -d /dev/msys ] && (cd /dev/msys && mv * .. && cd .. && rmdir msys) 

The Embedded Linux Workshop expects the devices it uses to be in /dev, so we simply move the devices created in step 29 into the /dev directory.

31.
cd ../../../kernel/linux 

Change to the kernel directory.

32.
make menuconfig 

Configure the kernel using the make menuconfig command.The following options are based on a 2.2.15 Intel kernel; your kernel configuration may be a bit different.Turn these options on with an asterisk (*), not an M; everything else should be turned off to save space. You’ll have to go into each of the top-level menus, even the ones not listed here, to make sure that they’re off.

Processor Type and features

386 processor family

1G Maximum Physical Memory

Loadable module support

Enable loadable module support

General Setup

Kernel support for ELF binaries

Block Devices

Normal PC floppy disk support

RAM disk support

Initial RAM disk (initrd) support

Character devices

Virtual Terminal

Support for console on virtual terminal

Standard/generic (dumb) serial support

Filesystems

DOS FAT fs support

MSDOS fs support

VFAT (Windows-95) fs support

/proc filesystem support

Second extended fs support

Console Drivers

VGA text console

33.
make dep && make bzImage 

Build the kernel.We use the “and” continuation (&&) instead of the semicolon (;) so that the second make won’t happen if the first fails. I’ve never seen make dep fail when building the kernel, but this is good practice for all long software builds with more than one make.This way, if there’s an error in one of the makes, the subsequent makes won’t even start, leaving any error messages still on the screen.We don’t need to make any modules for this kernel, but if we did, I’d simply add each module to the command line like this:

make dep && make bzImage && make modules
							

34.
cd doc-module 

Change to the directory created by the create-standalone script from the DiskOnChip distribution.

35.
make 

Build the doc.o module.

36.
cd ∼yourname/projects/minicom 

Change back to the root directory of your project.

37.
mkdir -p opt/minicom/bin opt/minicom/etc/rc 

Create the Minicom package directories.

38.
Use the cat command to build the Makefile:

cat > opt/minicom/Makefile 

everytime: 

binaries: 
     @(cd ../../src/minicom/minicom/src && make) 
     @cp -f ../../src/minicom/minicom/src/minicom bin 
     @strip bin/minicom 
     @strip --remove-section=.note --remove-section=.comment bin/minicom 

dependencies: 

     @echo "libncurses" 

Press Ctrl+D here.

In the Embedded Linux Workshop, each opt package can have a Makefile. The Makefile has three targets: everytime, binaries, and dependencies. The everytime target is normally not used. The binaries target is used to rebuild any binaries whose source has changed since the last build and then move those binaries into the opt package. Once in the package, the binaries are then stripped. Finally, the dependencies target lists any dependencies for the opt package. For instance, the minicom executable depends on the ncurses library. Obviously, you don’t have to use the cat command to build the Makefile; it’s just the most convenient way in this HOWTO.

Note that the indented lines are indented with a single tab.

39.
Now we’ll use the cat command to create the startup script for Minicom:

cat > opt/minicom/etc/rc/S99minicom 

#!/bin/sh 
echo "Press a key for minicom..." 
read x 
minicom -s 

Press Ctrl+D here.

The Embedded Linux Workshop comes complete with a set of startup scripts that work similarly to the Red Hat startup scripts. Each script in the /etc/rc directory that begins with the letter S is executed in increasing sort order. Naming a script S99{something} implies that it should be the last script to run and that it may not return to the caller.

We use the -s option so Minicom will go directly into setup mode. It defaults to COM2; change that setting if necessary. In a real device, you would create a minicom configuration file and let it start directly. Also, in a real application we wouldn’t force the user to press a key to start, but this way we can see any bootup error messages before Minicom erases them.

40.
chmod a+x opt/minicom/etc/rc/S99minicom 

Make the script executable.

41.
mkdir -p opt/doc/modules opt/doc/etc/rc 

Create the doc package directories.

42.
Back to the cat command once more to create the DiskOnChip Makefile:

cat > opt/doc/Makefile 

everytime: 

binaries: 

     @cp -f ../../src/kernel/linux/doc-module/doc.o modules 

Press Ctrl+D here.

By convention, we don’t recompile any part of the kernel or libc—it just takes too long.

43.
cp -P /usr/share/terminfo/l/linux opt/minicom 

Create the terminfo file for the console. This file contains the definitions of escape sequences for the console for operations such as clearing the screen and drawing lines.

44.
Type the following commands:

cat > opt/doc/etc/rc/P01doc 
#!/bin/sh 
insmod -f /modules/doc.o 

Press Ctrl+D here.

Each script in the /etc/rc directory that begins with the letter P is executed in increasing sort order before the boot media (flash filesystem) is mounted. This is how we’re able to load the DiskOnChip module before we ever try to reference it. We use the -f (force) option of insmod because the kernel version encoded in the DiskOnChip driver may not agree with the kernel version we use. This happens because we aren’t compiling the DiskOnChip driver from scratch, since we don’t have the source.

45.
chmod a+x opt/doc/etc/rc/P01doc 

Make the script executable.

46.
Modify the config file in the root of the project in the following ways:

$APP_ROOT="/dev/fla1";

After @OPT=("minicom"); add the following new line:

@OPT=(@OPT,"doc");

47.
elw 

Run the elw command.

48.
Choose the Build binaries option to build the binaries. Unless you take the time to download all the source files to the Embedded Linux Workshop, most of the binaries will fail to build. That’s okay; the binaries that ship will work.You must rerun this option each time you make a change.

49.
Choose the Build image option to build the Linux files and image.

Congratulations—you’ve just created a new embedded Linux disk image!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.252.140