xref: /openbmc/linux/scripts/depmod.sh (revision b2441318)
1fc4da9a3SMichal Marek#!/bin/sh
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3fc4da9a3SMichal Marek#
4fc4da9a3SMichal Marek# A depmod wrapper used by the toplevel Makefile
5fc4da9a3SMichal Marek
68937e897SJames Hoganif test $# -ne 3; then
78937e897SJames Hogan	echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
8fc4da9a3SMichal Marek	exit 1
9fc4da9a3SMichal Marekfi
10fc4da9a3SMichal MarekDEPMOD=$1
11fc4da9a3SMichal MarekKERNELRELEASE=$2
128937e897SJames HoganSYMBOL_PREFIX=$3
13fc4da9a3SMichal Marek
14fc4da9a3SMichal Marekif ! test -r System.map -a -x "$DEPMOD"; then
15fc4da9a3SMichal Marek	exit 0
16fc4da9a3SMichal Marekfi
178937e897SJames Hogan
188937e897SJames Hogan# older versions of depmod don't support -P <symbol-prefix>
198937e897SJames Hogan# support was added in module-init-tools 3.13
208937e897SJames Hoganif test -n "$SYMBOL_PREFIX"; then
218937e897SJames Hogan	release=$("$DEPMOD" --version)
228937e897SJames Hogan	package=$(echo "$release" | cut -d' ' -f 1)
238937e897SJames Hogan	if test "$package" = "module-init-tools"; then
248937e897SJames Hogan		version=$(echo "$release" | cut -d' ' -f 2)
258937e897SJames Hogan		later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1)
268937e897SJames Hogan		if test "$later" != "$version"; then
278937e897SJames Hogan			# module-init-tools < 3.13, drop the symbol prefix
288937e897SJames Hogan			SYMBOL_PREFIX=""
298937e897SJames Hogan		fi
308937e897SJames Hogan	fi
318937e897SJames Hogan	if test -n "$SYMBOL_PREFIX"; then
328937e897SJames Hogan		SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
338937e897SJames Hogan	fi
348937e897SJames Hoganfi
358937e897SJames Hogan
36bfe5424aSMichal Marek# older versions of depmod require the version string to start with three
37bfe5424aSMichal Marek# numbers, so we cheat with a symlink here
38bfe5424aSMichal Marekdepmod_hack_needed=true
398fc62e59SMichal Marektmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
408fc62e59SMichal Marekmkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
418fc62e59SMichal Marekif "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
428fc62e59SMichal Marek	if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
438fc62e59SMichal Marek		-e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
44bfe5424aSMichal Marek		depmod_hack_needed=false
45bfe5424aSMichal Marek	fi
46bfe5424aSMichal Marekfi
478fc62e59SMichal Marekrm -rf "$tmp_dir"
48bfe5424aSMichal Marekif $depmod_hack_needed; then
49bfe5424aSMichal Marek	symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
50bfe5424aSMichal Marek	ln -s "$KERNELRELEASE" "$symlink"
51bfe5424aSMichal Marek	KERNELRELEASE=99.98.$KERNELRELEASE
52bfe5424aSMichal Marekfi
53bfe5424aSMichal Marek
54fc4da9a3SMichal Marekset -- -ae -F System.map
55fc4da9a3SMichal Marekif test -n "$INSTALL_MOD_PATH"; then
56fc4da9a3SMichal Marek	set -- "$@" -b "$INSTALL_MOD_PATH"
57fc4da9a3SMichal Marekfi
588937e897SJames Hogan"$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
59bfe5424aSMichal Marekret=$?
60bfe5424aSMichal Marek
61bfe5424aSMichal Marekif $depmod_hack_needed; then
62bfe5424aSMichal Marek	rm -f "$symlink"
63bfe5424aSMichal Marekfi
64bfe5424aSMichal Marek
65bfe5424aSMichal Marekexit $ret
66