Using the "strip" Command

If you want to copy your root filesystem to flash on your target, you need to create one that is small enough to fit into the flash memory’s filesystem partition. To do this, you often need to delete unneeded files. Manpages, other documentation files, and internationalization features such as the contents of the/usr/lib/locale and /usr/lib/gconv directories are typical candidates for removal. You also can strip debugging symbols from some executable files and libraries by running the <toolchain>-linux-strip command, included with TimeSys distributions, from your host, where <toolchain> is the toolchain for your target, such as ppc-7xx, and so on. (You might need to add the toolchain binaries directory to your system’s PATH environment variable before you can use the strip utility.)

The basic syntax for strip is:

strip <option> <file> 

where <file> is the name of the program or library file you want to strip, and <option> can take a number of values, the most useful ones in this context being:

  • -s – Strips all symbols
  • -d – Strips only debugging symbols
  • --strip-unneeded – Strips only those symbols not needed to resolve relocations
  • -o <new_file> – Places the stripped file in <new_file> rather than replacing the input file (the default behavior)

Note

Use the strip binary that is appropriate for the target system, not the host platform’s native strip binary. For example, if you are stripping a binary to deploy on an ADI Coyote, you need to use the appropriate cross toolchain strip, which would be armv5b-linux-strip. If you use an inappropriate strip command, chances are high that it won’t work at all. If it does work, you will almost certainly wind up with a binary that won’t run on the target platform.

Store the customized RFS in a convenient directory that can be accessed from the target. You will create the RFS image from the target, so you must be able to reference the directory containing your customized RFS from the target’s root path (the NFS-mounted RFS that you used when booting the target over the network).

The following procedure first copies the RFS contents to the path <bsp_name>/rfs/ and then removes unneeded files from the copy.

# PATH=<toolchain_dir>/bin:$PATH 
# cd <linux_dir>
# mkdir <bsp_name>
# cp -ax <toolchain>/rfs <bsp_name>/
# cd <bsp_name>/rfs
# rm -rf usr/lib/locale 
# rm -rf usr/lib/gconv 
# rm -rf usr/share/man 
# rm -rf usr/share/doc 
# <toolchain>-linux-strip usr/lib/*.so* 

To create an RFS small enough to fit on flash, you will probably need to remove more components than those shown in this example. Those shown are merely a start in reducing the size of the RFS. TimeSys recommends using their Target Configurator software to create a minimal RFS from the RPMs included with their distributions.

Another Example

The following commands strip a binary named allin1 of all symbols (using the -s option and saving the output in a file named allin1.stripped:

$ strip -s allin1 -o allin1.stripped
$ ls -l allin1 allin1.stripped
-rwxr-xr-x    1 juser  timesys    223932 Apr 15 15:22 allin1*
-rwxr-xr-x    1 juser  timesys     36044 Apr 15 15:22 allin1.stripped

Notice that the stripped binary, allin1.stripped, is only one-sixth the size of the unstripped binary, allin1.