Linux 开机程序之研讨( 四 )




****************************; rc.serial; ******************************

#!/bin/sh
#
# /etc/rc.serial
#;;;;Initializes the serial ports on your system
#
#;;;;Version 2.01

echo "======================= rc.serial is begin !!! ====================="
cd /dev

## 下面三行中的前两行是设定一些变数 , 由於在这个 shell script 中 , 须要
## 用到 /bin/setserial -b; 这个指令 , 或是须要用到所有以 cua 开头的 node
## 的次数太多了 , 因此 , 把它们设定为一个变数 , 是一个不错的方法 . 尤其
## PORTS=`echo cua? cua??` 这是一个聪明的写法 , 那为什麽不写成 PORT=
## `echo cua*` 呢 ? 各位可以在 /dev 下分别使用这两个指令 , 观察输出到底
## 有什麽不同 ......

SETSERIAL="/bin/setserial -b"
PORTS=`echo cua? cua??`
echo -n "Configuring serial ports...."


## 下面这行 , 没有学过 shell programming 的人很可能会看不懂 , 不过没有
## 关系 , 这行中的 ${SETSERIAL} 会被换成 /bin/setserial -b , 而 ${PORTS}
## 会被换成 cua0 cua1 cua2 ....... cua31 , 所以整句翻译就是 :
## /bin/setserial -b -W cua0 cua1 cua2 cua3 cua4 cua5 cua6 ...... cua31
## 那这行指令到底在做什麽呢 ? 其实只是在做中断侦测的工作 .

${SETSERIAL} -W ${PORTS}


## 各位看到下面原来的注解了吧 . 当你有一些特殊的卡时 , 你可以把相对应部
## 份前面的 "#" 去掉 , 以便能做自动设定的工作 . 其实呢 , 这种情况实在
## 不多 , 大部份人的设备都差不了多少 , 说到关於串连埠 , 差异就更少了 .
#
# AUTOMATIC CONFIGURATION
#
# Uncomment the appropriate lines below to enable auto-configuration
# of a particular board.; Or comment them out to disable them....
#


## 好了 , 这下我们又多了一个变数 : AUTO_IRQ , 这在下面会用到 .

AUTO_IRQ=auto_irq


## 下面几行非常整齐 , 它们可以分别被换成 :
## /bin/setserial -b /dev/cua? auto_irq skip_test autoconfig
## setserial 说穿了也没什麽 , 这个指令可以让你对 serial port 做设定及回报
## 的动作 , 像 IRQ , I/O port 啦等等的事情 . 一般的情况下 , 大家的电脑中
## 通常只有 COM1-COM4 , 但假如你想增加新的 port , 那 setserial 就派上用
## 场了 .

# These are the standard COM1 through COM4 devices
#
# If you have an internal modeme with a Rockwell Chipset, add a "skip_test"
# to the /dev/cua3 line below.; (It"s not added by default because it will
# screw up people with 8514 displays).
#
${SETSERIAL} /dev/cua0 ${AUTO_IRQ} skip_test autoconfig
${SETSERIAL} /dev/cua1 ${AUTO_IRQ} skip_test autoconfig
${SETSERIAL} /dev/cua2 ${AUTO_IRQ} skip_test autoconfig
${SETSERIAL} /dev/cua3 ${AUTO_IRQ} autoconfig

# These are for the first AST Fourport board (base address 0x1A0)
#
${SETSERIAL} /dev/cua4 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua5 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua6 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua7 ${AUTO_IRQ} autoconfig

# These are for the second AST Fourport board (base address 0x2A0)
#
${SETSERIAL} /dev/cua8 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua9 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua10 ${AUTO_IRQ} autoconfig
${SETSERIAL} /dev/cua11 ${AUTO_IRQ} autoconfig


## 从这里以下 , 我省略了一大段 , 因为这一大段都是支援特殊的卡

# These are the 3rd and 4th ports on the Accent Async board.
#
#${SETSERIAL} /dev/cua12 ${AUTO_IRQ} autoconfig
#${SETSERIAL} /dev/cua13 ${AUTO_IRQ} autoconfig
#


.
.
.
.
.
.
.


## 好了 , 我们跳掉了一大段 , 直到这里 . 各位看到下面的注解了 .
## 假如你想用手动的方法指定 IRQ , I/O port , 及指定 chip 的型别
## 那你可以拿掉下面对应那行前面的 "#" 并作适当的修改 , 比如说
## 你用的是比较新的 16550 或 16550A , 而不是 16450 , 那你就可以

推荐阅读