Modifying slush

8 May

Modifying slush
Now that you have seen how easy it is to replace slush with your own program, we are going to start some simple modifications to slush itself. Slush is fitted with a variety of commands for development of TINI applications but it doesn’t have to end there. We can add some new commands to slush and remove a few of the ones we don’t need or want. We are going to discuss three ways to modify slush: recompiling slush, deleting commands from slush, and adding new commands to slush.

Recompiling Slush

Before we start to add and delete commands, let’s first determine that we can properly recompile slush and transfer it to a TINI and verify that we are actually running our new version of slush. We need to start by creating a directory in which we can unpack the slush source files and recompile them. For this section we are using the directory

c:\projects\modslush. You can use this or create a directory of your choosing.
C:\> mkdir projects
C:\> cd projects
C:\> mkdir modslush
C:\> cd modslush

Note that you need to find the Slush source jar file; it should be in %TINI_HOME%\src\.
Look for the file SlushSrc.jar. You will need to use the Java jar program to unpack the
jar and create the slush directory hierarchy in \projects\modslush\.

Notice where Slush.java is located (\projects\modslush\com\dalsemi\slush\). View this in your favorite text editor. Notice around line 418 the method initializeShellCommands(). This is where commands are added to the slush shell command list. For each of the commands in the initializeShellCommands() method notice that in \projects\modslush\com\dalsemi\slush\command\ is a separate Java class that implements this command. We will make a simple change to slush so we know for sure that the newly compiled version is indeed what we are running on TINI when we do finally succeed in loading it there.

•  Edit StatsCommand.java (in
\projects\modslush\com\dalsemi\slush\command\)
•  Somewhere around line 60, after the static find byte[] declarations, we are going to add a greeting message so that we know we are using our new version of Slush. Insert these lines:

// Added for verification
static final byte[] greeting = “Greetings from SLUSH!”.getBytes();

•  Then around line 135, find the code that looks like this:
try
{
// Display system version info (add API version)
out.write(slushVer);
out.write(osVer);
•  Modify this to print out the greeting message by adding a line, like this:
try
{
// Display system version info (add API version)
out.write(greeting);
out.write(slushVer);
out.write(osVer);

These changes simply make the stats command in slush print out the greeting as the first line of output. This way, after slush has been ported to our TINI we can verify that we are actually running the version of slush that we just compiled and not the real slush. Save the modified StatCommand.java file if you have not done so already and exit the editor.

Compile slush. Do this by compiling slush.java. All of the commands will be compiled also.

C:\> set SMUSH=C:\projects\modslush
C:\> cd \projects\modslush\com\dalsemi\slush\
C:\> javac -classpath %TINI_HOME%\bin\tiniclasses.jar;%SMUSH%;.
Slush.java

Notice how we have the CLASSPATH set for finding both the tiniclasses.jar and the slush classes by specifying the path to the top level of the slush source files and using the SMUSH environment variable. If you place your slush source files somewhere else on your disk, you need to set the SMUSH environment variable appropriately. We do not specify the path all the way to where the slush.java lives; these are included in slush.java through the import statements:

import  com.dalsemi.slush.command.*;

The com.dalsemi.slush.command is specified in the import statement and provides the path to com\dalsemi\slush\command so we only include in the CLASSPATH where to find the start of this path.

When you compile slush you will see this message:
Note: Slush.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

If you want to see what has been deprecated15 (usage is no longer recommended) add the -deprecation option to the compile command and then you will see four warnings like this:

Slush.java:1081: warning: readLine() in java.io.DataInputStream has been deprecated while ((line = input.readLine()) != null) If you saw any errors when compiling slush, be sure you included the proper path to tiniclasses.jar and the top level of the slush source in your CLASSPATH. Also check that you have correctly made the modifications to StatCommand.java (including the semicolon at the end of the two lines that you added).

Next we need to run  TINIConvertor to make the .class files into a .tbin file.

C:\> java -cp %TINI_HOME%\bin\tini.jar TINIConvertor
-o Slush.tbin
-l
-d %TINI_HOME%\bin\tini.db
-f .

We have included some new command line options to TINIConvertor

-l  Tells TINIConvertor to use the flash file format.
We do this because we are going to load slush into the beginning of the flash as the boot program.
-f  Specifies to TINIConvertor the class file to convert. A “.” will use the current directory (and included subdirectories and files).
-o Specifies the name of the output file, Slush.tbin.
-d  Specifies the path to the  TINIConvertor database, tini.bd.

You should not have seen any errors but, if you did, likely possibilities include either not properly specifying the path to tini.jar (so Java can’t find the TINIConvertor), not properly specifying the path to tini.db, and not specifying the “.” for the input file/directory.

When TINIConvertor runs, you will see some output lines like the following (where you
see … , many of the similar messages were deleted to shorten the output printed here):

TINIConvertor + ZIP
Version 0.73 for TINI
built on or around January 24, 2001
Disassembler/Builder Version 0.15 TINI, October 30, 2000
JiBDB 0.60 for TINI, November 10, 2000
Copyright (C) 1996 – 2001 Dallas Semiconductor Corporation.
MainStartClass: First available.
Target address: 0×70100
Changed tag to 8000
Recursing directory: .
directory: /home/dan/Projects/book/newslush/com/dalsemi/slush/./command
Adding  file:  /home/dan/Projects/book/newslush/com/dalsemi/slush/./
command/StatsCommand.class
Adding  file:/home/dan/Projects/book/newslush/com/dalsemi/slush/./
Slush.class
Adding  file:/home/dan/Projects/book/newslush/com/dalsemi/slush/./
CommandInterpreter.class
Set mainClassIndex to: 51
Using ROM API Version: 8009
Writing Class Offsets
Writing:  com/dalsemi/slush/command/StatsCommand
Writing:  com/dalsemi/slush/command/NetStatCommand
Writing:  com/dalsemi/slush/Slush$SlushDHCPListener
Writing:  com/dalsemi/slush/Slush$1
Writing Application: com/dalsemi/slush/Slush
Writing: com/dalsemi/slush/Slush
Writing:  com/dalsemi/slush/CommandInterpreter
Total Application length: 56931
Writing Application Entry point
Main offset for class with main: 6965
class num: 51
main class index: 51
main class tag: 8033
Converting to flash format. (56979 bytes)
Segment start address: 70100, length: 56979, CRC: dbda
Flash file size: 56986
Finished with build.

The first important thing to notice here is the “Finished with build” line, which means TINIConvertor successfully converted the class files. Note the “Flash file size: 56990”. Yours may differ slightly depending on what you personalized. Recall from a previous section in this chapter that each converted class file can’t be larger than 64k. This will be more important when we start adding new commands to Slush. The last thing we need to do is to get this new slush.tbin file to your TINI using JavaKit and try running it.

C:\> javakit -port COM1 -noDTRtest

Use the -noDTRtest command line switch if you previously found you needed it. When JavaKit starts up, press the reset button and then use the file/load menu command. Find the slush.tbin file you just created, select it and press OK. If you received an error, try loading the new slush again. When loading is complete and you see the loader prompt “>” press E enter to exit the loader and start executing slush. Once slush completes booting you can log in.

Now let’s test our new slush. Try the stats command and see what happens.
TINI /> stats
Greetings from SLUSH!
TINI slush null
TINI OS 1.02
System up time:
Days: 0
Hours: 0
Minutes: 0
Seconds: 12
Free RAM: 355264
FTP Server:active
Telnet Server:active
Serial Server:active

If this didn’t work, go back to verify that you did all the steps properly. Also be sure to check that you loaded the new slush and not the original slush.tbin. We have verified that we can successfully recompile slush and get it to our TINI board, so we can move on to more complex modifications to slush with confidence.

Random Posts

Comments are closed.