SCSI Formatter 2
Volume Number: 3
Issue Number: 6
Column Tag: Advanced Mac'ing
SCSI Formatter Project, Part II
By Tim Standing, University of Calif. at SF
Where are we going
This article is the second in a series on how to construct and format a SCSI hard
disk. The first (MacTutor, February 1987) described in detail how to assemble a SCSI
hard disk. This article describes a program called Format that performs the low level
formatting of a SCSI hard disk. I have divided this article into three parts. In the first
section, I cover some of the theory regarding the SCSI protocol. Included in this
section is a description of how Apple’s implementation of the protocol has made writing
SCSI software much easier. The second section describes in detail how a SCSI command
is sent to a SCSI hard disk and how data transfer is accomplished. I use U2 Formatter
as an example. In the last section, I give step by step instructions on how to use this
program including comments as to what may go wrong at each step and how to fix it.
During low level formatting, the Macintosh sends information to the controller
card describing the disk drive. This information includes both the physical
characteristics (e.g. number or cylinders and number of heads) and the type of sectors
that are to be used (sector size and interleaving). The controller card uses this
information to write track markings on the disk surface so that information can be
stored there. It also stores this information on a dedicated track on the disk surface so
that it can be read into the controller card RAM when the power is turned on. Once the
low level formatting has been completed, a program such as Apple’s Generic SCSI
Installer (available from Apple Software Support) can be used to construct a files
system, install a driver and write the boot blocks. Although the drive can store
information after low level formatting, it cannot be recognized as a volume by the
Macintosh until a file system has been constructed on it. (A SCSI driver will be the
subject of a future article in this series)
The program Format should work with any hard disk that uses the Adaptec
ACB-4000A controller card or the Adaptec ACB-4070 which is their RLL controller
card. In addition, it should work with any of the Seagate disk drives that have built in
controllers. These drives all have an “N” at the end of the model number (e.g.
“ST225N”). I have referred to the documentation for a Seagate ST225N while writing
this program.
I have developed this program using a 40 megabyte Seagate (ST4051) hard disk
connected to an Adaptec ACB-4000A controller card. I have also tested it with a 155
megabyte CDC Wren III (see side bar article on the Wren drive.) It should work with
other drives and controller cards, but I cannot guarantee it. There are subtle
differences in the way different manufactures implement the SCSI commands that make
writing a universal formatting program difficult.
The Wren III is the fastest drive I have used on the Macintosh. Using the time
needed to assemble and link the Format program as a benchmark, the Wren III is more
than 40% faster than a Data Frame XP-40. Disk Timer II rates the 155 Mbyte drive
as 118 for write, 108 for read and 9 for access time with an interleave of 3:1. The
average access time on the drive is 15 msec. That’s more than twice as fast as any
other drive available for the Mac. In addition, the drive can transfer data at 1.25
Mbytes/second, which is as fast as the Mac II can read it in. The Wren III comes in
three sizes: 86, 121, and 155 Mbytes which range in price from $1510 to $1710.
They are available from Arrow Electronics 521 Weddell Drive, Sunnyvale, CA 94089,
(800-325-3329).
The only problem with the Wren III is that the biege colored Macintosh Plus will
not boot properly from them. If you buy a platinum Macintosh Plus, or get a copy of
the ROMs from one, the Wren III will work fine. The EPROM’s you need to do this are
27C512, 150 nsec. They are made by Atmel and are available from Insight
Electronics, San Diego, (619)-587-0471. (The ROMS in the platinum Mac Plus have
a modified boot code that does a reset on power on and keeps polling until a hard disk
responds. In the standard Mac Plus, they did a reset and poll in a loop of 1 second,
which is shorter than the recovery tme of the Wren III to respond to a reset command.
Hence, the Wren III will never come up! The new ROMS re-poll the driver when they
get a drive not ready signal rather than resetting every second. This is not strict SCSI
protocol and the people at CDC pointed this out to Apple, which then changed it’s ROMS.
To get the ROMS, you need a friend in an Apple dealership who can work with you since
the dealers are not allowed to swap the ROMS unless you fry your board.)
MPW
Before I get into the details of SCSI commands, I will say a few things about MPW.
I switched from the MDS system to MPW because I got tired of waiting for a good linker
to show up for MDS. MPW is powerful and allows you to develop in PASCAL, C or
assembly language and link the results together. More importantly, the MPW
environment provides a lot of tools that make development easier. In this section, I
will describe both a modification that I have made to the “Make utility” to make it
entirely automatic and a few bugs that I have found in the assembler that you should
look out for. This program was developed using MPW version 1.0.1. I have included
all the files that you will need for this project including the Makefile which
establishes the dependency rules used for automatic assembly and linking. You will
notice that the dependencies in the Makefile specify that the program is relinked
anytime after the Rez tool is used. This is because Rez tends to trash the code
resources in the program being built.
I have modified the Make command so that it automatically executes its output.
By doing this, you can build your application by simply typing the command “Make”.
The modification requires that you create a new folder inside the “MPW” folder called
“Scratch”. The enclosed file “MakeIt” must then be placed in the “Tools” folder.
Lastly, the line “Alias Make Makeit” must be placed in the UserStartup file.
Although I have not uncovered any bugs in the linker, the MPW assembler does
not always create the instruction that you specify! On three occasions it assembled
instructions incorrectly. In all three instances, I got the assembler to correctly
assemble the instructions by either changing the instruction order or adding a label to
the line above. If it looks like something funny is happening with your code, check that
the executing code is what you think it is by using the disassemble feature in a
debugger like TMON. Lets hope the 2.0 version will fix this bug as an assembler that
lies is not much good for anything.
Lastly, I use the “dump” assembly directive to load symbols into a file. You will
see that all the files like “Traps.d” are loaded in at the beginning of each source file.
To use this you must place the following lines:
Dump ‘FileName.d’
end
at the end of each of the files in the AIncludes folder and then assemble these files. This
will create a file called “Filename.d” for each file which is a lot like the packed
symbol files in MDS and will make your assembly runs a lot faster.
SCSI Bus Phases
There are seven different states that the SCSI bus can be in. These are called Bus
Phases and are determined by which device has control of the bus and what information
is being transfered on the bus. The bus phases that the SCSI bus goes through during a
SCSI command are: arbitration, selection, command, data, status, message and lastly
bus free. During the arbitration phase, the Mac (the initiator) tries to gain control of
the bus. If it is successful, the initiator tries to select your hard disk (target device)
during a phase called the selection phase. Once a target device has been selected, the
target determines what information will be transferred down the bus and when. The
target also determines which direction the information travels down the bus. The
target device then requests a SCSI command from the initiator in the command phase.
If the SCSI command that was transfered during the command phase indicated that there
was data to be transferred between the target and the initiator, the bus will then enter
the Data phase. An example of this would be a read or write command where blocks of
data are transfered down the bus. Once the target has transfered the number of bytes
specified by the command, the bus enters the status phase. Here the target sends a
single byte of information to the initiator. This status byte is an error code which
describes any errors that may have occured. The status byte is cleared if the command
was completed successfully. The message phase is used to transfer additional
information between the target and the initiator. The Adaptec ACB-4000A always
sends a clear byte in the message phase which is the command complete message. I
have therefore ignored the message byte in my program. At the end of the message
phase, the target determines that there is no more information to transfer down the
bus and disconnects from the initiator. The bus then enters the Bus Free Phase where
no device has control of the bus.
During all of these phases, timing is critical. After each bus phase change, there
is a required amount of time necessary to let the signal settle. There is also a
maximum time delay after which the target device will time out. There are also timing
specifications for the arbitration phase that describe how long an initiator device
should wait to determine if he has gained control of the bus. Apple decided to use the
NCR 5380 chip to connect to the SCSI bus. This has several advantages including the
fact that the chip performs many SCSI bus functions in hardware. It arbitrates for use
of the bus, including performing retries, can select a target, send commands and
transfer data. All of these actions are done in hardware. The timing is determined on
the chip using a gate delay, rather than a clock pulse, which allows Apple to use the
same chip in any computer regardless of the clock speed. (Of course, a vendor change
or manufacturing quirk could change the average gate delay time, rendering some Macs