Modifying the slush command set

8 May

Modifying the slush command set
Now that you have shown you can recompile slush relatively easily, let’s actually do some real, beneficial modifications to slush. Modifying an existing slush command is as simple as editing the command class, as we did with Deleting commands from slush is as simple as removing the reference from the initializeShellCommands() method in Adding new commands to Slush consists of writing a new command implementation and adding that command to the initializeShellCommands() method.

We can remove commands we don’t need or don’t want. For instance, we can improve the security of our TINI by removing all commands that allow us to add new users or delete files, or we can simply remove the commands we don’t need and increase the available memory for other purposes. We can add new aliases for commands in an effort to make slush easier to use. And we can even add new commands. In the slush source directory hierarchy Dallas Semiconductor has included several additional commands for slush that are not part of the base compilation (because they take up more memory).

First things first. Open in a  text editor and examine the source code.
Notice how slush works (sort of). Skip down to around line 418, to the method
initializeShellCommands.  You will see a number of lines like this one:
CommandInterpreter.addCommand(“arp”, new ARPCommand());

There should be a line like this for each command in slush. This is where slush commands are added to the command interpreter. In this case arp is the command that is added to slush and ARPCommand is the name of the corresponding class that implements this command (we will look at that part in a bit). To remove commands from slush, you could simply delete the lines like this for the commands you don’t want. Similarly, to add new commands, you could add lines like this for the new classes that contain new slush commands. Also, scroll down a little and examine the copy command:

SlushCommand copy = new CopyCommand();
CommandInterpreter.addCommand(“copy”,  copy);
CommandInterpreter.addCommand(“cp”,  copy);

This is essentially the same as the previous single line for adding a command to slush, except that we first define a new “SlushCommand” object and then we add it to the command interpreter twice, with different names, cp and copy. This is how aliases for commands are added to slush.

Around line 417, look for the method
private void initializeShellCommands()
In here, comment out the commands you don’t want buy putting // at the beginning of
the line. I commented out the chown,  arp,  useradd,  userdel,  sendmail,
append, who, whoami,  clear, wd  and wall commands.
// CommandInterpreter.addCommand(“chown”, new ChownCommand());
Also, since we are making some changes, I find that I want to use more rather than
cat to view a text file, so we are going to add that as an alias to Slush. Change:
CommandInterpreter.addCommand(“cat”, new CatCommand());

SlushCommand  cat = new CatCommand();
CommandInterpreter.addCommand(“cat”,  cat);
CommandInterpreter.addCommand(“more”,  cat);
Recompile slush as we did in the previous step. Notice the final file size.
Converting to flash format. (56585 bytes)
Segment start address: 70100, length: 56585, CRC: a7a9
Flash file size: 56592
Finished with build.

Not much smaller, is it? What happened? We commented out the commands but they are still added to the slush.tbin by TINIConvertor because the .class files are still in the command directory. We need to go back in and delete the .class files for these commands, as they are still there from our previous compiles. Notice that the class for useradd is AddUserCommand.class and userdel is RemoveUserCommand.class.

You don’t need to recompile—you simply need to rerun TINIConvertor after these class files have been removed. Examine the final file size.

Converting to flash format. (49159 bytes)
Segment start address: 70100, length: 49159, CRC: b65b
Flash file size: 49166
Finished with build.

OK, that’s much better. Now load the new version of slush to the TINI and test it out.
It should work just fine. You can verify these commands are not in Slush. Try a few:

TINI /> whoami
ERROR: Unknown Command: whoami
TINI /> who
ERROR: Unknown Command: who

Also notice that “help” does not list the commands you deleted.

Adding optional commands to slush
Now that you have deleted some commands from slush, you have room to add some new commands. Some commands come with slush but are not in the initial version to save space (if they were included slush would exceed 64kbytes). You can add these if you want to use them. These commands are: PPPCommand.class,

SledCommand.class,  PollMemoryCommand.class,  ThreadStatCommand.class,
and DiffCommand.class. These are found in
%TINI_HOME%\src\OptionalSlushCommandsSrc.jar. The command lines options
and function of these commands were discussed near the beginning of this chapter.
To add these commands:
C:\> cd \projects\slush
C:\> jar -xf %TINI_HOME%\src\OptionalSlushCommandsSrc.jar

This will unjar the optional slush commands into com\dalsemi\slush\command, so
be sure to change directory to \projects\slush so these new optional commands
will be placed in the existing slush hierarchy.

Edit and add some of these lines to the initializeShellCommands() method:

CommandInterpreter.addCommand(“PPP”, new PPPCommand());
CommandInterpreter.addCommand(“sled”, new SledCommand());
CommandInterpreter.addCommand(“pollmemory”,  new  PollMemoryCommand());
CommandInterpreter.addCommand(“threadstat”,  new  ThreadStatCommand());
CommandInterpreter.addCommand(“diff”, new DiffCommand());

You probably can’t get away with adding all of these commands at once, unless you remove a number of existing commands, because you will exceed the 64kbyte limit for the flash file format.

Compile slush and run TINIConvertor. If you see output of TINIConvertor similar to the following, then you have exceeded the 64kbyte limit and you need to remove some slush commands (and don’t forget to delete all of the class files for the commands you deleted).

Converting to flash format. (76497 bytes) Segment start address: 70100, length: 65280, CRC: 39fc

Warning, address exceeds normal TINI flash memory boundaries!

Segment start address: 80000, length: 11217, CRC: e9b0
Flash file size: 76511
Finished with build.

Random Posts

Comments are closed.