Выбрать главу

/home/<your_home_name>/workspace *(rw,no_root_squash,no_all_squash,sync,nosubtree_check)

This makes the Eclipse workspace/ directory visible to other computers on the network.

Be sure the NFS server is running. In most cases it will be automatically started at boot time. Use the command:

/etc/rc.d/init.d/nfs status

to check this. If it isn’t started automatically, execute the command /etc/rc.d/init.d/nfs start.[5] You can execute this command from a shell window or, better yet, add it near the end of /etc/rc.d/rc.local. This is the last script executed at boot up.

5.4.4 Target Configuration

There are a couple of files that need to be edited on the target to support NFS file mounting. The equivalent of /etc/sysconfig/network-scripts/ifcfg-eth0 needs to be modified to specify a fixed IP address. The exact location, name, and layout of this file will vary from board to board. On the Intellimetrix board it’s /etc/network/interfaces. I usually assign 192.168.1.50 to the target board.

The other file that needs modification is the last script executed by the init process when the system boots. Again, this will vary from board to board. On the Intellimetrix board it’s /etc/init.d/rcS. Add the following line at the end of that file:

/bin/mount –o nolock 192.168.1.2:/home/<your_home_name>/workspace /home

On a PC target /etc/rc.d/rc.local is a good place to add this.

This causes the workspace/ sub-directory under your home directory to appear as /home on the target using the Network File System.

In order to debug on the target, you’ll need a program called gdbserver compiled for the target and loaded on the target’s file system, preferably someplace visible from the PATH environment variable. gdbserver runs the program under test and communicates over the network with GDB running under Eclipse on the host.

5.4.5 Creating a Target Eclipse Project

Even though our thermostat project included a make target for the target version of the thermostat, we’ll create a new project to illustrate some additional features of Eclipse. Create a new C executable project and call it “target.” From the thermostat project, select the following files using the Shift and Ctrl keys in the same way you do when selecting multiple files in Windows or graphical Linux environments:

• AT91RM9200.h

• driver.h

• thermostat.h

• monitor.c

• thermostat.c

• trgdrive.c

Right-click and select Copy. Click on the new target project, right-click and select Paste. We now have all the files we need for the project. But remember that we don’t want to build this project for the host, but rather for the target. This requires configuring the project to use a different GNU tool chain.

The file trgdrive.c provides a set of device driver functions for the Intellimetrix ARM9 board. This is not a real Linux “device driver,” but rather accesses memory mapped I/O directly from user space. If you’re using some other target board, you’ll need to modify the functions in trgdrive.c accordingly.

If your target is a PC, you can skip to the next section on debugging on the target. You don’t need to select a different compiler.

Right-click on the project name and select Properties. Expand the C/C++ Build entry and select Settings. This brings up the dialog shown in Figure 5.11. The first tab, Tool settings, lets you specify which C compiler, C linker, and assembler to use. By default, the compiler and linker are just gcc. This is the standard name for a host GNU C compiler.

Figure 5.11: Project build settings.

By convention, cross compilers are given a prefix that identifies the architecture and the operating system on which the compiled program will run. On my system, the ARM cross compiler is called arm-linux-gcc and I’ve added the path to it to my PATH environment variable. So change the Command name to match your cross compiler. All of the items under GCC C Compiler represent categories of compiler options. Take a look through them to see what’s there.

Likewise, change the GCC C Linker command to match your cross compiler. Here we also have to add a library to the linker command. Select Libraries, click the Add button, and enter “pthread.” This is the library of Posix threads functions. Take a quick look at the categories of linker options.

Finally, change the GCC Assembler to match your cross assembler.

Note that we’ve done all this for the Debug configuration. Click the Configuration drop-down menu at the top, select Release, and make the same changes.

Click OK to exit the Properties dialog. Make sure the active build configuration is Debug and build the project. You’ll find two new entries under the target project in the Project Explorer view: Binaries and Debug. Debug lists all of the built objects including an executable named “target”. Expanding any of the built object entries produces a list of every source file used to build that object. It’s not clear to me what purpose that serves.

5.4.6 Debugging on the Target

From a developer’s standpoint, there’s virtually no difference between debugging on host and debugging on a target board. The only difference is in how Eclipse connects to the debugger. For this you’ll need to create a new debug configuration.

With the target project selected in the Project Explorer view, select Run→Debug Configurations…. Click the New launch configuration button. A new configuration named target Debug is created, referencing the target project and the Debug/target application. Select the Debugger tab (Figure 5.12).

Figure 5.12: Target debug configuration.

Open the Debugger drop-down menu and select gdbserver Debugger. Enter the name of your cross gdb in the GDB debugger field. Click the Connection tab under Debugger Options. Select TCP from the Type drop-down and enter the IP address of your target in the Host name or IP address field (Figure 5.13). Click Apply and then Close. GDB is now configured to talk to your target board over the network.

Figure 5.13: Target debug connection.

But before starting up a debug session, you have to start the application running on the target:

1. Execute minicom from a shell window on the host.

2. Power up your target board and boot into Linux.

3. In minicom, cd /home and verify that it has the same contents as ~/workspace on the host. If not, go back to the section on configuring networking and see if anything isn’t right. Try executing the mount command manually from the shell.

4. cd target/Debug.

5. Execute gdbserver :10000 target.

This last command starts gdbserver telling it to listen for a connection on TCP/IP port 10000, which is the default port assigned in the Eclipse configuration, and start up the target executable. gdbserver responds that it created a process for the target executable and that it is listening on port 10000. Note, incidentally, that you can use any port number you want as long as both sides use the same number and it doesn’t conflict with some other network service. Port numbers below 1024 are reserved for established services and shouldn’t be used.

вернуться

5

This is the location of the nfs script on a Red Hat or Fedora distribution. Other distributions may locate it somewhere else.