SATA300 TX4

PromiseのSATAカードを買ってきたんだけど、ちょっとはまったのと、カーネル変えるとまた作り直す羽目になるのでまとめてみた。

#!/bin/sh
#How to make a driver module of SATA300TX4 for RHEL4U2

TGT_KRN_VERSION="2.6.9-22.EL"
USB_DEV_NODE="/dev/sda"
FILES_NEEDED_TO_CPY="scsi.h scsi_obsolete.h scsi_module.c scsi_typedefs.h"

#0.download files from Red Hat Network and Promise's Support Site
#  from RHN(https:/rhn.redhat.com/)
#  /root/kernel-${TGT_KRN_VERSION}.src.rpm
#  /root/kernel-smp-devel-${TGT_KRN_VERSION}.i686.rpm
#  from Promise(http://www.promise.com/support/download/download_eng.asp)
#  /root/2_sataii150-300-tx-series-rhel4-x86_v1.01.0.20.tar.gz
#  /root/2_sataii150-300-tx-series-linux2.6-src-x86_v1.01.0.20.tar.gz

#1.install rpms
  rpm -ivh ~/kernel-${TGT_KRN_VERSION}.src.rpm
  rpm -ivh ~/kernel-smp-devel-${TGT_KRN_VERSION}.i686.rpm

#2.make symbolic link
  ln -s /usr/src/kernels/${TGT_KRN_VERSION}-i686/ /usr/src/linux

#3.extract kernel source codes
  cd /usr/src/redhat/SOURCES/
  tar jxvf linux-2.6.9.tar.bz2
  cd linux-2.6.9/drivers/scsi/
  for i in $FILES_NEEDED_TO_CPY; do
      cp $i /usr/src/linux/drivers/scsi/
  done

#4.extract Promises's source code and make
  mkdir ~/tmp; cd ~/tmp/
  tar zxvf ~/2_sataii150-300-tx-series-linux2.6*.tar.gz
  cd ut_mod
  make clean
  make DRIVER_SRC_DIR=`pwd` UTSVERSION="${TGT_KRN_VERSION}"

#5.make a directory and copy a ulsata2.ko to it
  mkdir -p ~/${TGT_KRN_VERSION}/i686
  cp ulsata2.ko ~/${TGT_KRN_VERSION}/i686/

#6.If you have a smp machine, you need to do as followings
  rm -f /usr/src/linux
  ln -s /usr/src/kernels/${TGT_KRN_VERSION}-smp-i686/ /usr/src/linux
  cd /usr/src/redhat/SOURCES/linux-2.6.9/drivers/scsi/
  for i in $FILES_NEEDED_TO_CPY; do
      cp $i /usr/src/linux/drivers/scsi/
  done
  cd ~/tmp/ut_mod/
  make clean
  make DRIVER_SRC_DIR=`pwd` UTSVERSION="${TGT_KRN_VERSION}smp"
  mkdir -p ~/${TGT_KRN_VERSION}smp/i686
  cp ulsata2.ko ~/${TGT_KRN_VERSION}smp/i686/

#7.extract Promises's driver disk and dump .img file to USB(ex. /dev/sda)
  mkdir ~/old_ddisk; cd ~/old_ddisk
  tar zxvf ~/2_sataii150-300-tx-series-rhel4*.tar.gz
  dd if=ddisk/B20--RedHatEL4.img of=${USB_DEV_NODE}
  mount ${USB_DEV_NODE} ~/tmp
  rm -f ~/tmp/modules.cgz
  cd

#8.make modules.cgz
  find ${TGT_KRN_VERSION}* -name 'ulsata2.ko' | \
    cpio -oH crc | gzip -9 > ~/tmp/modules.cgz
  sync;sync;sync
  umount ~/tmp/

#9.clean working directories and files.
  echo "cleaning files..."
  rm -f /usr/src/linux
  rm -rf ~/tmp
  rm -rf ~/old_ddisk
  rm -rf ~/${TGT_KRN_VERSION}*
  cd /usr/src/kernels/${TGT_KRN_VERSION}-i686/drivers/scsi/
  for i in $FILES_NEEDED_TO_CPY; do
      rm -f $i
  done
  cd /usr/src/kernels/${TGT_KRN_VERSION}-smp-i686/drivers/scsi/
  for i in $FILES_NEEDED_TO_CPY; do
      rm -f $i
  done
  rm -rf /usr/src/redhat/SOURCES/*
  rm -rf /usr/src/redhat/SPECS/*