Blame SOURCES/find-requires.ksyms

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