Blame SOURCES/find-requires.ksyms

ddba73
#! /bin/bash
ddba73
ddba73
IFS=$'\n'
ddba73
ddba73
all_provides() {
ddba73
    nm "$@" \
ddba73
    | sed -r -ne 's:^([0-9a-f]+) A __crc_(.+):\1\t\2:p' \
ddba73
    | sort -k2 -u
ddba73
}
ddba73
ddba73
all_requires() {
ddba73
    for module in "$@"; do
ddba73
        set -- $(/sbin/modinfo -F vermagic "$module" | sed -e 's: .*::' -e q)
ddba73
        /sbin/modprobe --dump-modversions "$module" \
ddba73
        | awk --non-decimal-data '
ddba73
            BEGIN { FS = "\t" ; OFS = "\t" }
ddba73
            {printf("0x%08x\t%s\n", $1, $2)}' \
ddba73
        | sed -r -e 's:$:\t'"$1"':'
ddba73
    done \
ddba73
    | sort -k2 -u
ddba73
}
ddba73
ddba73
rm -rf /tmp/krava
ddba73
ddba73
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
ddba73
    cat > /dev/null
ddba73
    exit 0
ddba73
fi
ddba73
ddba73
modules=($(grep -E '/lib/modules/.+\.ko$'))
ddba73
ddba73
if [ ${#modules[@]} -gt 0 ]; then
ddba73
    kernel=$(/sbin/modinfo -F vermagic "${modules[0]}" | sed -e 's: .*::' -e q)
ddba73
ddba73
    # get all that kernel provides
ddba73
    symvers=$(mktemp -t ${0##*/}.XXXXX)
ddba73
    cat /usr/src/kernels/$kernel/Module.symvers | awk '
ddba73
        BEGIN { FS = "\t" ; OFS = "\t" }
ddba73
        { print $2 "\t" $1 }
ddba73
    ' \
ddba73
    | sed -r -e 's:$:\t'"$1"':' \
ddba73
    | sort -u -k2 > $symvers
ddba73
ddba73
    # get all that we demands
ddba73
    reqs=$(mktemp -t ${0##*/}.XXXXX)
ddba73
    join -t $'\t' -j 2 -v 1 \
ddba73
            <(all_requires "${modules[@]}") \
ddba73
            <(all_provides "${modules[@]}") \
ddba73
    | sort -u -k2 > $reqs
ddba73
ddba73
    # get kernel dependencies - kernel(symbol) = 0xHEX
ddba73
    join -t $'\t' -j2 -o 1.1 1.2 $symvers $reqs \
ddba73
    | sort -u \
ddba73
    | awk '
ddba73
    { FS = "\t" ; OFS = "\t" }
ddba73
            { print "kernel(" $1 ") = " $2 }
ddba73
    '
ddba73
ddba73
    # get module dependencies - ksym(symbol) = 0xHEX
ddba73
    join -t $'\t' -j2 -v2 $symvers $reqs \
ddba73
    | sort -u | awk '
ddba73
    { FS = "\t" ; OFS = "\t" }
ddba73
            { print "ksym(" $2 ") = " $1 }
ddba73
    '
ddba73
fi