]> git.pld-linux.org Git - projects/geninitrd.git/blame - mod-ide.sh
Timeout here is not a good idea. rootfs cannot be mounted and kernel oopses due to...
[projects/geninitrd.git] / mod-ide.sh
CommitLineData
30ca4815 1#!/bin/sh
30ca4815
ER
2# geninitrd mod: ide
3
74578b86
AM
4PREIDEMODS="-ide-core unknown -ide-detect -ide-disk -ide-gd_mod"
5PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk -ide-gd_mod"
30ca4815
ER
6
7# ???
8ide_only_root=${ide_only_root:-no}
9
10# allow forcing loading IDE modules, likely from sysconfig/geninitrd
11ADDIDE=${ADDIDE:-no}
12
13# return true if node is ide device
14# @param string $node device node to be examined
15# @access public
16is_ide() {
17 local node="$1"
18 if [ ! -e "$node" ]; then
19 warn "is_ide(): node $node doesn't exist!"
20 return 1
21 fi
22
23 # TODO: more sophisticated check, not just pathname check
24 if is_yes "$(echo "$node" | awk '/^\/dev\/(hd[a-l]|ide\/)/ { print "yes"; }')"; then
25 return 0
26 fi
27
28 return 1
29}
30
31# find modules for $devpath
32# @param $devpath device to be examined
33# @access public
34find_modules_ide() {
35 local devpath=$1
36 # remove partition, if any
37 local disk=${devpath%[0-9]*}
38 # set blockdev for rootfs (hda, sdc, ...)
39 local rootblkdev=${disk#/dev/}
40
41 local n
b02a6b13 42 if [ "$kernel_version_long" -lt "002004021" ]; then
02ba8ab7 43 verbose "Finding IDE modules for kernels <= 2.4.20"
30ca4815 44 for n in $PREIDEMODSOLD; do
b02a6b13 45 find_module "$n"
30ca4815
ER
46 done
47 else
48 local tryauto=1
49 for n in $PREIDEMODS; do
50 if [ "X$n" = "Xunknown" ]; then
02ba8ab7 51 verbose "Finding IDE modules using ide_hostadapter"
99e7251e 52 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ { print $3 }')
30ca4815 53 for mod in $idemodules; do
99e7251e 54 tryauto=0
b02a6b13 55 find_module "$mod"
30ca4815
ER
56 done
57
58 if [ "$tryauto" -eq 1 ]; then
59 # If tryauto {{{
60 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
02ba8ab7 61 verbose "Finding IDE modules using PCI ID database"
30ca4815
ER
62 # Finding IDE modules using PCI ID database {{{
63 if is_yes "${ide_only_root}"; then
64 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
65 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
66 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
67 searchpciid="${vendorid}${deviceid}"
68 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
69 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
70 fi
71 fi
72
73 if [ -z "${searchpciid}" ]; then
74 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
75 fi
76
77 idemodules=""
78
79 for nb in $searchpciid; do
80 eval `awk -v pciid="$nb" '{
81 gsub("\t"," ");
82 gsub(" +", " ");
83 gsub("^ ","");
84 if (/^[\t ]*#/)
85 next;
86 compmod = $1 ""; # make sure comparison type will be string
87 # cause pci IDs are hexadecimal numeric
88 if (compmod == pciid) {
89 module=$2;
90 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
91 # max_kernel=$4; #
92 exit 0;
93 }
94 }
95
96 END {
97 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
98 }' /usr/share/pci-database/ide.pci`
99 [ -n "$module" ] && idemodules="$idemodules $module"
100 done
d4b2c605 101 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
30ca4815
ER
102 new_idemodules=""
103 for nc in idemodules; do
104 new_idemodules="$nc $new_idemodules"
105 done
106 idemodules="${new_idemodules}"
107 fi
108
109 if [ -z "$idemodules" ]; then
110 warn "rootfs on IDE device but no related modules found, loading ide-generic."
111 idemodules="ide-generic"
112 fi
113
114 # }}}
115 for nd in $idemodules; do
b02a6b13 116 find_module "-$nd"
30ca4815
ER
117 done
118 # }}}
119 # else tryauto {{{
120 else
121 [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
122 [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
123 warn "Automatic IDE modules finding not available."
124 fi
125 # }}}
126 fi
127 else
b02a6b13 128 find_module "$n"
30ca4815
ER
129 fi
130 done
131 fi
132}
133
134# generate initrd fragment for ide device init
135# @access public
136initrd_gen_ide() {
137 # nothing to do here
138 return 0
139}
This page took 0.979839 seconds and 4 git commands to generate.