
              NS486SXF PCMCIA bootable extension utility (PCMBOOT)

                              December 5, 1996

____________________________________________________________________________
                                   
This directory contains a simple utility that can be used to convert a
binary image into a PCMCIA bootable extension for the NS486SXF evaluation
board.

There are four files that come with this utility:

    PCMBOOT.EXE   - DOS utility to convert file.
    HELLOX.BIN    - Simple relocatable program with the first 6 bytes of
                    the image left blank. This file is the same as the
                    sample "hello.bin" in the "flashldr" directory, but
                    there are six additional bytes at the start of the
                    file, to leave room for the bootable extension header.
    BOOTIMG.BIN   - This is a copy of HELLOX.BIN that has been converted
                    into a PCMCIA bootable extension.
    README.TXT    - This file.

The PCMBOOT utility performs the necessary modifications to a file to 
turn it into a bootable extension.  It does the following:

    (1) Makes the size of the file an integer multiple of 512 bytes.  Unless
        the file size is already an integer multiple of 512 bytes, PCMBOOT
        will increase the size and fill the extra bytes with 0's.

    (2) Fills in the 6 byte header at the start of the image with the
        correct header information.  The short jump instruction will
        point to the first byte past the header.

Therfore, after running this utility on the file you can program the
image into a PCMCIA memory card starting anywhere in the first 64K of 
the card memory space, at a 512 byte boundary.  Once the image is
in the card, resetting (or turning on) the NS486SXF evaluation board
with the card in and the MONITOR jumper removed will cause the Target
Loader to pass execution to the bootable extension automatically.

This utility will only work on a file up to 128K in size.  The first 6
bytes of the file will be replaced with the header, so no data should
be put in the first 6 bytes of the input file.  The extension made
by this utility will always pass execution to byte 7 of the image.
Therefore, valid code must be located at this location.  Ideally,
all code made into a PCMCIA boot extension should be fully position
independant, although the code may use absolute addresses if you know
where the boot extension will be placed in the system memory space.
The Target Loader maps the first 8MB of the PCMCIA memory card at address 
0x07800000.

Note: the Target Loader does not do any "loading" or perform fix-ups on
the image in PCMCIA, so the program placed in the extension must be
fully linked and located (basically an absolute binary file).

The file "HELLOX.BIN" is an exact copy of the "HELLO.BIN" examples found
in the "FLASHLDR" directory, with 6 blank (0) bytes added to the start
of the file.  Since this file is a position independant binary file,
no changes were required to the file.

If you want to try out the utility, copy "HELLOX.BIN" to a new file name,
"BOOT.BIN", and then use the PCMBOOT utility: "PCMBOOT BOOT.BIN".  The
program will spit out a few messages and then exit.  You will notice that
the size of the "BOOT.BIN" file was increased to an integer multiple of
512.  The file "BOOTIMG.BIN" is a copy of "HELLOX.BIN" that has already
been processed by PCMBOOT.  Since PCMBOOT writes to the input file, be
sure to make a copy of your original program before running PCMBOOT on it.

Once you have the bootable extension, you just need to program it into a
PCMCIA card and try it out.  You must find your own way to program the
image into the PCMCIA card.  The toolchain from QNX Software Systems Ltd 
includes such a utility.  There are probably other utilities that can
also program a PCMCIA card.  If you are using a SRAM card, it would be
fairly easy to modify the NSDEMO program included with the evaluation board
software to write an image to the card.

For your reference, the following is a section from the "README.TXT" file
for the Flash Loader that describes booting from PCMCIA.

13.0 BOOTING FROM PCMCIA

  This version of the Target Loader will check for a PCMCIA memory card
  with a certain signature when booting with the MONITOR (W6) jumper off.
  In this case, the Target Loader will jump to an address in the PCMCIA
  range.  This allows automatic booting from a PCMCIA SRAM or Flash card
  if installed.  If no card is inserted or the card is not booted from, the
  Target Loader will disable the PCMCIA controller before jumping to the 
  boot program, so the Target Loader use of the PCMCIA card should not 
  affect other code.

  If the Target Loader detects a PCMCIA card, it will map the first 8MB
  of the card memory at address 0x0780_0000.  It then scans the first
  64K of that memory at every 512 byte boundary until it finds a valid
  "Flash Loader bootable program".  The first valid bootable program will
  be jumped to by the Target Loader.

  For a program in the PCMCIA card to be recognized as bootable, it must
  meet several criteria.  The program (starting at a 512 byte boundary) 
  must contain the following header:

          Offset    Size      Description
          ------    ----      -----------
          0         2 bytes   signature (0x55, 0xAA)
          2         1 byte    length of program (bytes) divided by 512
          3         2 bytes   short jump instruction to start of program
          5         1 byte    checksum

  Please note that the use of the word "program" in this description is
  the set of bytes containing the code to boot from.  Therefore, it is
  most likely a binary file that has been linked and located.

  If the Target Loader sees the proper signature (i.e., the first two
  bytes of the program are 0x55 and 0xAA respectively), it will then
  make sure that the program checksum is correct.  The checksum is a
  single byte that makes the sum of all the bytes in the program
  (including the header) modulo 256 equal to zero.

  Since the program size is indicated by the byte at offset 2 multiplied
  by 512, the program length should be a multiple of 512 bytes.  If extra
  bytes are needed at the end of the program to make it a multiple of
  512 bytes, they should be filled with zeros.

  If the Target Loader detects a valid signature and checksum, it will
  transfer execution to the instruction at byte offset 3.  Since the
  checksum is at offset 5, this must be a two byte jump instruction, such
  as a short jump.

  To use the PCMCIA boot option you must make sure your program has a valid
  header.  The suggested algorithm is as follows:

       (0) leave 6 bytes open at the start of the program for the header
           information.

       (1) increase the size of the program (binary) so that is is an
           integral multiple of 512.  (E.g., a 400 byte program would 
           become 512 bytes.) 

       (2) if the file size was increased, set the extra padding bytes to
           zero.

       (3) fill in the bytes at offsets 0 and 1 to 0x55 and 0xAA
           respectively (signature).

       (4) fill in the byte at offset 2 (length) to the length of the
           binary (in bytes) divided by 512.

       (5) put a short jump instruction at offset 3 to the start of
           your program.  The byte sequence 0xEB, 0x01 is a jump to
           offset 6, which is the simplest solution.  If the program
           is created in assembly you can simple put the short jump
           instruction in the assembly at this offset.

       (6) sum all the bytes of the program (and the extra padding bytes)
           and discard any overflow past the one byte.  Then subtract this
           value from 0 to obtain the one byte checksum.  Put this value
           at offset 5 within the header.

  Please note that the size field is only one byte, so valid sizes
  are 512 bytes (0x01 * 512) to 131,072 bytes (0xFF * 512).  However, this
  size field is only used to compute the checksum, so if the program is
  larger than 128K you can simply set the size to 0xFF and compute the
  checksum based only on the first 128K.  It is also possible to set the
  size to any length less than the program and compute the checksum based
  on that size.  The checksum is intended to verify that the program
  in the PCMCIA is valid, so it is desirable to compute the checksum based
  on the full size of the program.

  The latest release of the NS486SXF evaluation board included a sample
  bootable program and a utility to convert a binary file into a bootable
  program.  See the README file for that utility for more information.

____________________________________________________________________________
