*************************************************************************
*                                                                      	*
*  DiskOnChip(R) TrueFFS(R) driver for Linux				*
*                                                                      	*
*  Version 5.1.4							*
*  Based on TrueFFS version 5.1.4					*
*                                                                      	*
*  Copyright M-Systems (c) 2002						*
*                                                                      	*
*  Release notes							*
*                                                                      	*
*************************************************************************

This document is an installtion manual for the Linux driver for X86.
This software should be used for DiskOnChip devices only.

-------------------------------------------------------------------------------
Note: We do not support RedHat (versions 7.0 and higher) extensions of Linux
      kernels. 
      If you use RedHat distribution, please replace the kernel sources with
      the same version of standard kernel from www.kernel.org
      See detailed instructions in Appendix A below.
Note: The Linux driver was qualified with Linux kernels 2.4.17, 2.4.18,
      and 2.4.19.

Note: (for DiskOnChip Plus customers who upgrade from TrueFFS 5.1.x)
In TrueFFS 5.1.x versions (5.1.1, 5.1.2 and 5.1.3) there is a bug with
all DiskOnChip Plus devices in reading the bad block table in few specific
cases.
Therefore, customers who upgrade from TrueFFS 5.1.x, DiskOnChip Plus devices
formatted by 5.1.x have to be formatted again using 5.1.4.
Reasons for this:
1. If the media header is written already on a bad block because of the bug,
   in binary partitions it might be found using 5.1.4. 
2. There might be data loss:  Information that was written on bad blocks by
   5.1.x, will be ignored by 5.1.4, because the bad blocks will be ignored. 

-------------------------------------------------------------------------------
 
1. Before you begin
2. Installing DiskOnChip driver
3. Using DiskOnChip extended functionality
4. Driver usage
5. Known limitations
6. Contact information

1. Before you begin

The following instructions assume that you have installed Linux with kernel
version 2.x.xx, DiskOnChip Linux driver unpacked in _doc_linux_dir_, dformat 
utility and firmware file doc512.exb in _dformat_dir_ and kernel 
sources in _kernel_sources_dir_.

We recommend creating an emergency boot diskette prior to installation.
You may use 
    _doc_linux_dir_/mkbootdisk --device /dev/fd0 2.x.xx

You must be 'root' user to perform the installation.

2. Installing DiskOnChip driver

The DiskOnChip TrueFFS Linux driver should be installed as a loadable 
kernel module.

There are two main types of installation: installing as a boot device and as 
a storage device.

2.1. Format the DiskOnChip

    cd _dformat_dir_

For using as a storage device:
    ./dformat -WIN:xxxx -S:! -Y -NODOS
This command should remove firmware, if exists, and create low level format.

For using as a boot device:
    ./dformat -WIN:xxxx -S:doc514.exb -EMPTY -Y -NODOS
                         
This command should leave space for firmware and create low level format.
The -EMPTY flag is used in order to prevent booting from DiskOnChip before
completing the installation.

For detailed description of the dformat parameters see "DiskOnChip Software Utilities" 
User Manual.

2.2. Install driver sources

    cd _doc_linux_dir_/driver
    patch -p1 -d _kernel_sources_dir_ < linux-x_x_x-patch
                                              
    cp doc/* _kernel_sources_dir_/drivers/block/doc/

Where x_x_x is the kernel version number you use (or the one which is most close
to it, but not bigger).

Note: If the patch command fails, open the patch file (linux-xxx-patch) and try to
      perform the updating manually.

2.3. Create nodes

    cd _doc_linux_dir_/driver
    ./mknod_fl

This command should create fla1...fld4 nodes in /dev/msys/

2.4. Change kernel configuration

    cd _kernel_sources_dir_
    make menuconfig

Enter "Loadable module support" menu.
Make sure all the options on that menu are turned ON.

Enter "Block devices" menu.
Select the "M-Systems driver" as module. 
If you install as a boot device, select the "Loopback device support" and 
"RAM disk support" as built-in.

Save the configuration, then compile the kernel

    make dep
    make clean
    make bzImage
    make install
    make modules
    make modules_install

Reboot the machine.

After boot call "insmod doc".

2.5. Initialize file system on DiskOnChip

Create partition table and partitions by calling 'fdisk':

    fdisk /dev/msys/fla

2.6. Mount DiskOnChip partitions

    mkdir -p /mnt/fla1
    mount /dev/msys/fla1 /mnt/fla1

-------------------------------------------------------
Now DiskOnChip is ready to be used as a storage device.
-------------------------------------------------------

2.7. Install the correct boot loader

We need to install John Coffman's lilo 22.1 or later.


You should do one of the following options:
    
(a) replace /sbin/lilo and /boot/boot.b with compiled versions from 
_doc_linux_dir_/lilo

    cp _doc_linux_dir_/lilo/lilo /sbin/lilo
    cp _doc_linux_dir_/lilo/boot.b /boot/boot.b

(b) compile lilo sources in _doc_linux_dir_/lilo/lilo-22.3.2

(c) compile the latest version from http://brun.dyndns.org/pub/linux/lilo/

Lilo sources assigns major number of DOC device 62, while driver uses 100
by default. You may fix this by:

(a) patching the lilo sources by _doc_linux_dir_/lilo.h.patch
(b) manual editing of _doc_linux_dir_/lilo/lilo-22.3.2/lilo.h: replace string
    #define MAJOR_FL 62
by 
    #define MAJOR_FL 100
(c)create appropriate nodes in /dev/msys by 
    ./mknod_fl 62
and always load the driver with parameter fl_major=62.

Th binary lilo compiled with major 100.

2.8. Modify /etc/lilo.conf as follows

    boot=/dev/msys/fla
    compact
    install=/boot/boot.b
    map=/boot/System.map
    disk=/dev/msys/fla
        bios=0x80

    prompt
    delay=50
    timeout=50

    image=/boot/vmlinuz
        label=linux
        root=/dev/msys/fla1
        initrd=/boot/initrd.img
        read-only

Please pay attention to 'bios=...'.

2.9. Create initrd file

If your Linux distribution includes command 'mkinitrd' (as RedHat) you may 
do the following in order to create initrd image and copy it to /boot:

    cd _doc_linux_dir_/driver
    ./mkinitrd_doc

Otherwise, you need to create the file manually.  
                                                  

2.10. Copy Linux system files to DiskOnChip

Copy Linux system files to the DiskOnChip so that it will become a bootable 
Linux disk.

We have 3 examples of the necessary file list for RedHat 5.2, 6.2 and 7.1:
_doc_linux_dir_/build/redhat-x.x.files. Create your own file list and 
install it as follows:

    cd _doc_linux_dir_/build
    ./mkdocimg _your_own_file_list_

or copy the files manually.

2.11. Store new lilo configuration

    lilo -v -C /etc/lilo.conf -r /mnt/fla1

2.12. Update firmware

    cd _dformat_dir_
    ./dformat -WIN:xxxx -S:doc512.exb -Y -NOFORMAT -FIRST
                        
This command should set the firmware and make DiskOnChip BIOS disk 0x80.

2.13.

Reboot and enjoy.

3. Using DiskOnChip extended functionality

The basic function of TrueFFS is to enable regular file systems to access the
DiskOnChip as if it were a block device (disk). To do this, TrueFFS provides 
a standard block-device interface, with the capability of reading and writing 
logical sectors to and from the DiskOnChip. This capability, along with 
advanced Flash management features (transparent to the OS and file system) are 
enough to enable file-systems and operating systems to manage the DiskOnChip as 
a standard storage device.

In addition to the standard storage device functionality, the TrueFFS 5.1.4                                                               
driver provides access to extended functionality, not part of standard 
file systems API.

The driver implements the interface of the extended functionality by exporting 
a list of extended functions (through IOCTLs). Every extended function is 
represented by a code defined as enumerated type defined in 
_doc_linux_dir_/ioctl/lnxioctl.h.

Note: See implementation example of IOCTL Functionality of DiskOnChip at the end 
of this section.

Note: Detailed explanations regarding the DiskOnChip extended functionality 
      is found in: Developer Guide - "Extended Functions of DiskOnChip Driver Based
      on TrueFFS version 5.1.x" which exists in our web site.

3.1 Using IOCTLs to access binary partitions in Linux.
-------------------------------------------------------
Accessing binary partitions in Linux requires an IOCTL that does not exist 
in other TrueFFS drivers for other OSs. The additional IOCTL is:

FL_IOCTL_LNX
        
        Input Record:
        typedef struct
        {
            unsigned long command;
            unsigned long data;
        }flInputLnxRecord;

        Output Record:
        typedef struct
        {
            unsigned long status;
            unsigned long data;
        }flOutputLnxRecord;


It is used to specify which is the active BDK partition. For example, before 
calling to FL_IOCTL_BINARY_HW_PROTECTION or FL_IOCTL_BDK_OPERATION IOCTLs you 
must specify the number of the active BDK partition by calling FL_IOCTL_LNX 
with following parameters:

     Input:
     flInputLnxRecord.command        0
     flInputLnxRecord.data           bits 0-3 - DiskOnChip number, 
                                     bits 4-7 - BDK partition number

     Output:
     flOutputLnxRecord.status        flOK or flBadParameter
     flOutputLnxRecord.data          nothing

3.2 Source code example of accessing binary partition using IOCTLs
-------------------------------------------------------------------
#include <stdio.h>

#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>

#include <sys/ioctl.h>

#include <linux/fs.h>

#include "/ioctl/lnxioctl.h"

#define DEV1 "/dev/msys/fla1"

int main()
{
    int fd1,ioctlResult;
    FILE*log;
    flIOctlRecord ioctlRecord;
    flBDKOperationInput bdkOperationInput;
    flOutputStatusRecord outputStatusRecord;
    flInputLnxRecord inputLnxRecord;
    flOutputLnxRecord outputLnxRecord;

    char pBuffW[512];
    char pBuffR[512];

    if( (log=fopen("log.txt","wb"))==NULL )
    {
        perror("Opening log ");
        exit(1);
    }

    if( (fd1=open(DEV1, O_RDWR))==0 )
    {
        perror("Opening device ");
        goto close_log;
    }

    ioctlRecord.inputRecord=&inputLnxRecord;
    ioctlRecord.outputRecord=&outputLnxRecord;
    inputLnxRecord.command=0;
    inputLnxRecord.data=0;
    if( (ioctlResult=ioctl(fd1,FL_IOCTL_LNX,&ioctlRecord)) != 0)
    {
        perror("Error in ioctl(FL_IOCTL_LNX) ");
        goto close_fd1;
    }
    if(outputLnxRecord.status!=flOK)
    {
        printf("ioctl(FL_IOCTL_LNX) returns %d\n",outputStatusRecord.status);
        goto close_fd1;
    }

    ioctlRecord.inputRecord=&bdkOperationInput;
    ioctlRecord.outputRecord=&outputStatusRecord;
    bdkOperationInput.bdkStruct.flags=0;
    bdkOperationInput.bdkStruct.length=512;
    bdkOperationInput.bdkStruct.startingBlock=5;
    bdkOperationInput.bdkStruct.signOffset=8;
    memcpy(bdkOperationInput.bdkStruct.oldSign,"BIPO",4);

    bdkOperationInput.type=BDK_INIT_WRITE;
    if( (ioctlResult=ioctl(fd1,FL_IOCTL_BDK_OPERATION,&ioctlRecord)) != 0)
    {
        perror("Error in ioctl(FL_IOCTL_BDK_OPERATION:BDK_INIT_WRITE) ");
        goto close_fd1;
    }
    if(outputStatusRecord.status!=flOK)
    {
        printf("ioctl(FL_IOCTL_BDK_OPERATION:BDK_INIT_WRITE) returns %d\n",outputStatusRecord.status);
        goto close_fd1;
    }

    bdkOperationInput.type=BDK_WRITE;
    bdkOperationInput.bdkStruct.bdkBuffer=pBuffW;
    memset(pBuffW,0xa5,512);
    if( (ioctlResult=ioctl(fd1,FL_IOCTL_BDK_OPERATION,&ioctlRecord)) != 0)
    {
        perror("Error in ioctl(FL_IOCTL_BDK_OPERATION:BDK_WRITE) ");
        goto close_fd1;
    }
    if(outputStatusRecord.status!=flOK)
    {
        printf("ioctl(FL_IOCTL_BDK_OPERATION:BDK_WRITE) returns %d\n",outputStatusRecord.status);
        goto close_fd1;
    }

    bdkOperationInput.type=BDK_INIT_READ;
    if( (ioctlResult=ioctl(fd1,FL_IOCTL_BDK_OPERATION,&ioctlRecord)) != 0)
    {
        perror("Error in ioctl(FL_IOCTL_BDK_OPERATION:BDK_INIT_READ) ");
        goto close_fd1;
    }
    if(outputStatusRecord.status!=flOK)
    {
        printf("ioctl(FL_IOCTL_BDK_OPERATION:BDK_INIT_READ) returns %d\n",outputStatusRecord.status);
        goto close_fd1;
    }

    bdkOperationInput.type=BDK_READ;
    bdkOperationInput.bdkStruct.bdkBuffer=pBuffR;
    memset(pBuffR,0,512);
    if( (ioctlResult=ioctl(fd1,FL_IOCTL_BDK_OPERATION,&ioctlRecord)) != 0)
    {
        perror("Error in ioctl(FL_IOCTL_BDK_OPERATION:BDK_READ) ");
        goto close_fd1;
    }

    if((ioctlResult=memcmp(pBuffW,pBuffR,512)))
    {
        printf("Error comparing buffers in byte %d.\n",ioctlResult);
        goto close_fd1;
    }

    if(outputStatusRecord.status!=flOK)
    {
        printf("ioctl(FL_IOCTL_BDK_OPERATION:BDK_read) returns %d\n",outputStatusRecord.status);
        goto close_fd1;
    }

    printf("\nOK\n");

close_fd1:
    close(fd1);
close_log:
    fclose(log);
    exit(0);
}

4. Driver Usage

General

The '_kernel_sources_dir_/drives/block/doc/' directory contains M-Systems' 
TrueFFS driver files for Linux  Kernel versions 2.0.x, 2.2.x, and 2.4.x for
the entire DiskOnChip product line.

This version is backward compatible with all DiskOnChip products and supports 
M-Systems' latest products (the DiskOnChip Millennium Plus and the DiskOnChip 
2000 TSOP). 
  
For detailed information on how to use TrueFFS utilities, please refer to the 
DiskOnChip Software Utilities User Manual. For the most updated manuals and 
documentation, please see M-Systems' web site (http://www.m-sys.com) or send 
your requests to e-mail: info@m-sys.com

Installation

To install DiskOnChip as an alternative disk drive run the below:

Usage:
-----
    insmod doc.o [fl_winl=_address_] [fl_winh=_address_] 
                 [fl_part_prot=_ndev_ fl_key_prot=_8_chars_key_]
                 [fl_nftl_cache=0|1] [fl_is_ram_check=0|1]
                 [fl_8bit_access=0|1] [fl_mtd_bus_access_type 0...255]
                 [fl_verify_write_bdtl 0|1] [fl_verify_write_binary 0|1]
                  [fl_sectors_verified_per_folding ...]

fl_winl=;fl_winh=
    Set the upper and top memory range in which driver will search for DiskOnChip. 
    Default values fl_winl=0xc0000 and fl_winh=0xf0000.  
fl_part_prot=;fl_key_prot
    Enables insert protection key _8_chars_key_ to device number _ndev_ 
    before loading driver.

    Residual parameters sets environment variables (see Developer Guide
    "Extended Functions of DiskOnChip Driver Based on TrueFFS version 5.1.x") 
    before loading driver. The Developer Guide exists inour web site.

5. Known limitations

5.1  We do not support RedHat extensions of Linux kernels. If you use RedHat distribution, 
     please replace the kernel sources with the same version of standard kernel from
     www.kernel.org

5.2 When formatting an 8MB BDTL partition, use the native file systems high 
     level format and not the TrueFFS built in FAT formatter.

5.3 If write protection is activated on a partition that was not mounted as write 
     protected, then writing to a write protected partition will show a fail
     message only after the data is flushed from the system cache.

5.4 Step 6.3 in the installation (mkinitrd_doc) may hang the computer when 
     performed in Linux kernel 2.4.2. To avoid this, and assuming you are 
     interested to keep using kernel version 2.4.2, perform the following:

     (A) follow the installation instructions on your 2.4.2 machine up until 
         step 6.2 (including). Perform step 6.3 on another machine, running 
     with another Linux kernel (2.4.4, 2.4.0, and so on). Return to your 
     2.4.2 machine to complete the rest of the installation.


Known limitations for Linux driver 5.1.4
----------------------------------------
1. Number of sockets is limited to 4.
2. Open absent device returns OK.
3. Inserting driver module with key from the command line for protected partition
    loads this partition as KEY_INSERTED. However, removing driver module does not
    remove the key.
4. We do not support RedHat (versions 7.0 and higher) extensions of Linux
   kernels. 
   If you use RedHat distribution, please replace the kernel sources with
   the same version of standard kernel from www.kernel.org
   See detailed instructions in Appendix A below.
 

 
 Appendix A - replacing RedHat 7.3 kernel by a kernel from www.kernel.org
 -----------------------------------------------------------------------

How to replace kernel in RedHat:

1. Download the coresponded kernel:
   
   For RedHat 7.3, download the kernel from
   http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.18.tar.bz2.
   
   (For RedAht 7.2 , doownload from 
   http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.7.tar.bz2. )
   
   Copy the downloaded file to '/usr/src'.

2. Remove links to old kernel.

	cd /usr/src
	rm linux
	rm linux-2.4

2. Extract downloaded kernel.

	cd /usr/src
	bzip2 -cd linux-2.4.18.tar.bz2 | tar -xvf -
	
   You will get directory '/usr/src/linux' contains the uncompressed kernel sources.

3. Rename the kernel directory.

	cd /usr/src
	mv linux linux-2.4.18

4. Make links to new kernel sources.

	ln -s linux-2.4.18 linux
	ln -s linux-2.4.18 linux-2.4

5. Update boot loader configuration.

   Add option to boot new kernel to /etc/lilo.conf.
   Below is an example of the file /etc/lilo.conf:

	install=/boot/boot.b
	prompt
	timeout=50
	default=2.4.18
	boot=/dev/hda
	map=/boot/map
	lba32

	# boot original kernel
	image=/boot/vmlinuz-2.4.18
		label=2.4.18
		read-only
		root=/dev/hda1

	# boot RH kernel
	image=/boot/vmlinuz-2.4.18-3
		label=2.4.18-3
		read-only
		root=/dev/hda1

  vmlinuz-2.4.18 will be copied to /boot during the driver installation process


6. (OPTIONAL) Configure your kernel.

   Set your hardware in menuconfig. It is necessary for running XWindows but
   you may work from command line without this.

	cd /usr/src/linux-2.4.18
	make menuconfig

-------------------------------------------------------------------------------

6. Contact information

  Please visit our website for the latest driver versions and updated 
  information.  

  Internet:      http://www.m-sys.com
  
  E-mail:	 info@m-sys.com
  
  USA:           M-Systems Inc. 
                 8371 Central Ave, Suite A 
                 Newark CA 94560 USA
  		 Phone: +1-510-494-2090
  		 Fax:   +1-510-494-5545
  
  Taiwan:        M-System Asia Ltd. 
                 Room B, 13F, No. 133, Sec. 3
  		 Min Sheng East Road
                 Taipei, Taiwan
                 R.O.C.
                 Phone: +886-2-8770-6226
  		 Fax:   +886-2-8770-6295

  Japan:         M-Systems Japan Inc. 
                 Asahi Seimei Gotanda Bldg., 3F
                 5-25-16 Higashi-Gotanda
                 Shinagawa-ku Tokyo, 141-0022
                 Phone: +81-3-5423-8101
                 Fax:   +81-3-5423-8102
  
  China:         M-Systems China Ltd.
                 25A International Business Commercial Bldg.
                 Nanhu Rd., Lou Hu District
                 Shenzhen, China 518001
                 Phone: +86-755-2519-4732
                 Fax:   +86-755-2519-4729

  Europe/Israel: M-Systems Ltd. 
                 Central Park 2000 
                 7 Atir Yeda St. 
                 Kfar Saba 44425, Israel
  		 Tel: 972-9-764-5000
  		 Fax: 972-3-548-8666
  

