SVN: geninitrd/trunk/geninitrd
glen
glen at pld-linux.org
Sat Feb 9 19:53:53 CET 2008
Author: glen
Date: Sat Feb 9 19:53:53 2008
New Revision: 9272
Modified:
geninitrd/trunk/geninitrd
Log:
- drop old code, optimize modules_add_linuxrc with shell code
Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd (original)
+++ geninitrd/trunk/geninitrd Sat Feb 9 19:53:53 2008
@@ -266,23 +266,23 @@
# Finds module dependencies
#
-# @param $mode silent | normal
# @param $module
+# @param $mode [silent]
#
# Outputs each dependant module full path including the module itself.
find_depmod() {
- local mode="$1"
- local module="$2"
+ local module="$1"
+ local mode="$2"
# backwards compatible, process $mode
local modfile
- if [ "$mode" = silent ]; then
+ if [ "$mode" = "silent" ]; then
modfile=$(modinfo -n $module 2>/dev/null)
else
modfile=$(modinfo -n $module)
fi
if [ ! -f "$modfile" ]; then
- if [ "$mode" != silent ]; then
+ if [ "$mode" != "silent" ]; then
warn "$module: module not found for $kernel kernel"
fi
if ! is_no "$EXIT_IF_MISSING"; then
@@ -299,102 +299,11 @@
done
}
-find_depmod_old () {
- typeset mods module f level depfile first
-
- depfile=/lib/modules/$kernel/modules.dep
-
- if [ ! -f $depfile ]; then
- die "No $depfile! Run depmod and rerun $PROGRAM."
- fi
-
- # prepend / if no path given, append $modext.gz if not given,
- # quote /
- origmodule="$2"
- module=$(echo "$2" | \
- awk '/\// {print;next} {print "/" $0}' | \
- awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
- awk '{gsub("/","\\/");print}')
- mods=$(awk '
-BEGIN { here = 0 }
-/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
-/:/ { here = 0 }
-/(.*)/ { gsub(/\\/," "); if (here) print }
-' $depfile | xargs)
-
- # fallback to $modext
- if [ "$mods" = "" ]; then
- module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
- # ") - vim
- fi
-
- mods=$(awk '
-BEGIN { here = 0 }
-/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
-/:/ { here = 0 }
-/(.*)/ { gsub(/\\/," "); if (here) print }
-' $depfile | xargs)
-
- if [ "$mods" = "" ]; then
- if [ "$1" != silent ]; then
- warn "$origmodule: module not found in $depfile"
- fi
- if ! is_no "$EXIT_IF_MISSING"; then
- exit 1
- else
- warn "If $origmodule isn't compiled in kernel then this initrd may not start your system."
- fi
- fi
-
- level=$3
- if [ "$level" = "" ]; then
- level=0
- fi
- level=$((level + 1))
- if [ $level -gt 20 ]; then
- die "$origmodule: cycle in $depfile"
- fi
-
- first=
- for f in $mods; do
- if [ "$first" = "" ]; then
- first=$f
- else
- find_depmod $1 $f $level
- fi
- done
-
- echo $first
-}
-
-addmodule() {
- local fmPath=$1
- local skiperrors=$2
-
- if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
- if [ -n "$skiperrors" ]; then
- # XXX should not ignore here errors
- return
- fi
-
- die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)"
- fi
-
- # only need to add each module once
- local m have=0
- for m in $MODULES; do
- [ $m = $fmPath ] && have=1
- done
- if [ $have = 0 ]; then
- MODULES="$MODULES $fmPath"
- fi
-}
-
findmodule() {
local skiperrors=""
local modName=$1
- if [ ${modName#-} != ${modName} ]; then
+ if [ ${modName#-} != $modName ]; then
skiperrors=1
modName=${modName#-}
fi
@@ -409,19 +318,27 @@
findmodule socal
fi
- local mod allModulesToFind
+ local mod depmod
if [ "$skiperrors" = 1 ]; then
- allModulesToFind=$(find_depmod silent $modName)
+ depmod=$(find_depmod $modName silent)
else
- allModulesToFind=$(find_depmod normal $modName)
+ depmod=$(find_depmod $modName)
if [ $? != 0 ]; then
exit 1
fi
fi
- for mod in $allModulesToFind; do
+ for mod in $depmod; do
mod=${mod#/lib/modules/$kernel/}
- addmodule $mod "$skiperrors"
+
+ # add each module only once
+ local m have=0
+ for m in $MODULES; do
+ [ $m = $mod ] && have=1
+ done
+ if [ $have = 0 ]; then
+ MODULES="$MODULES $mod"
+ fi
done
}
@@ -1024,7 +941,7 @@
local mod
for mod in $modules; do
- MODULEDIR=$(dirname "$mod")
+ MODULEDIR=${mod%/*}
inst_d "/lib/modules/$kernel/$MODULEDIR"
cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
@@ -1032,19 +949,21 @@
}
modules_add_linuxrc() {
- local modules="$1"
- local mod
+ local mod modpath
- for mod in $modules; do
- MODULE2=$(dirname "$mod")
- NAME2=$(basename "$mod" .gz)
- MODULE2=$MODULE2/$NAME2
- module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
- options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
-
- generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
- sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
- firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
+ for mod in "$@"; do
+ # module path without optional compression
+ modpath=${mod%.gz}
+
+ # name of the module
+ module=${modpath##*/}
+ module=${module%$modext}
+
+ options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
+
+ generic_module=$(echo $module | tr - _)
+ sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
+ firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
if [ -n "$verbose" ]; then
s=""
@@ -1060,8 +979,8 @@
if [ -n "$firmware_var" ]; then
firmware_install_module "$module" "$firmware_var"
fi
- echo "$insmod /lib/modules/$kernel/$MODULE2 $options" | add_linuxrc
- if [ -n "${sleep_var}" ]; then
+ echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
+ if [ -n "$sleep_var" ]; then
echo "usleep $sleep_var" | add_linuxrc
fi
done
@@ -1935,7 +1854,7 @@
fi
EOF
-modules_add_linuxrc "$MODULES"
+modules_add_linuxrc $MODULES
# TODO: rewrite for busybox
#if [ -n "$loopDev" ]; then
More information about the pld-cvs-commit
mailing list