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