kbuild: factor out the common installation code into scripts/install.sh

Many architectures have similar install.sh scripts.

The first half is really generic; it verifies that the kernel image
and System.map exist, then executes ~/bin/${INSTALLKERNEL} or
/sbin/${INSTALLKERNEL} if available.

The second half is kind of arch-specific; it copies the kernel image
and System.map to the destination, but the code is slightly different.

Factor out the generic part into scripts/install.sh.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
This commit is contained in:
Masahiro Yamada 2022-05-03 11:47:16 +09:00
parent f18379a302
commit f774f5bb87
24 changed files with 63 additions and 247 deletions

View File

@ -1298,7 +1298,8 @@ scripts_unifdef: scripts_basic
# to this Makefile to build and install external modules. # to this Makefile to build and install external modules.
# Cancel sub_make_done so that options such as M=, V=, etc. are parsed. # Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
install: sub_make_done := quiet_cmd_install = INSTALL $(INSTALL_PATH)
cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Tools # Tools

View File

@ -318,9 +318,9 @@ $(BOOT_TARGETS): vmlinux
$(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
@$(kecho) ' Kernel: $(boot)/$@ is ready' @$(kecho) ' Kernel: $(boot)/$@ is ready'
$(INSTALL_TARGETS): KBUILD_IMAGE = $(boot)/$(patsubst %install,%Image,$@)
$(INSTALL_TARGETS): $(INSTALL_TARGETS):
$(CONFIG_SHELL) $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" \ $(call cmd,install)
$(boot)/$(patsubst %install,%Image,$@) System.map "$(INSTALL_PATH)"
PHONY += vdso_install PHONY += vdso_install
vdso_install: vdso_install:

21
arch/arm/boot/install.sh Normal file → Executable file
View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# #
# arch/arm/boot/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public # This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive # License. See the file "COPYING" in the main directory of this archive
# for more details. # for more details.
@ -18,25 +16,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
if [ "$(basename $2)" = "zImage" ]; then if [ "$(basename $2)" = "zImage" ]; then
# Compressed install # Compressed install

View File

@ -162,11 +162,9 @@ Image: vmlinux
Image.%: Image Image.%: Image
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
install: install-image := Image install: KBUILD_IMAGE := $(boot)/Image
zinstall: install-image := Image.gz
install zinstall: install zinstall:
$(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ $(call cmd,install)
$(boot)/$(install-image) System.map "$(INSTALL_PATH)"
PHONY += vdso_install PHONY += vdso_install
vdso_install: vdso_install:

21
arch/arm64/boot/install.sh Normal file → Executable file
View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# #
# arch/arm64/boot/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public # This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive # License. See the file "COPYING" in the main directory of this archive
# for more details. # for more details.
@ -18,25 +16,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
if [ "$(basename $2)" = "Image.gz" ]; then if [ "$(basename $2)" = "Image.gz" ]; then
# Compressed install # Compressed install

View File

@ -72,8 +72,9 @@ archheaders:
CLEAN_FILES += vmlinux.gz CLEAN_FILES += vmlinux.gz
install: KBUILD_IMAGE := vmlinux.gz
install: install:
sh $(srctree)/arch/ia64/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)" $(call cmd,install)
define archhelp define archhelp
echo '* compressed - Build compressed kernel image' echo '* compressed - Build compressed kernel image'

10
arch/ia64/install.sh Normal file → Executable file
View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# #
# arch/ia64/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public # This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive # License. See the file "COPYING" in the main directory of this archive
# for more details. # for more details.
@ -17,14 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install - same as make zlilo
if [ -f $4/vmlinuz ]; then if [ -f $4/vmlinuz ]; then
mv $4/vmlinuz $4/vmlinuz.old mv $4/vmlinuz $4/vmlinuz.old

View File

@ -138,5 +138,6 @@ CLEAN_FILES += vmlinux.gz vmlinux.bz2
archheaders: archheaders:
$(Q)$(MAKE) $(build)=arch/m68k/kernel/syscalls all $(Q)$(MAKE) $(build)=arch/m68k/kernel/syscalls all
install: KBUILD_IMAGE := vmlinux.gz
install: install:
sh $(srctree)/arch/m68k/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)" $(call cmd,install)

22
arch/m68k/install.sh Normal file → Executable file
View File

@ -15,28 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install - same as make zlilo
if [ -f $4/vmlinuz ]; then if [ -f $4/vmlinuz ]; then
mv $4/vmlinuz $4/vmlinuz.old mv $4/vmlinuz $4/vmlinuz.old

View File

@ -56,8 +56,7 @@ $(BOOT_TARGETS): vmlinux
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
install: install:
sh $(srctree)/$(nios2-boot)/install.sh $(KERNELRELEASE) \ $(call cmd,install)
$(KBUILD_IMAGE) System.map "$(INSTALL_PATH)"
define archhelp define archhelp
echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))' echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'

22
arch/nios2/boot/install.sh Normal file → Executable file
View File

@ -15,28 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install - same as make zlilo
if [ -f $4/vmlinuz ]; then if [ -f $4/vmlinuz ]; then
mv $4/vmlinuz $4/vmlinuz.old mv $4/vmlinuz $4/vmlinuz.old

View File

@ -184,12 +184,11 @@ vdso_install:
$(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@ $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@
$(if $(CONFIG_COMPAT_VDSO), \ $(if $(CONFIG_COMPAT_VDSO), \
$(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@) $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@)
install:
$(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ install: KBUILD_IMAGE := vmlinux
$(KERNELRELEASE) vmlinux System.map "$(INSTALL_PATH)" zinstall: KBUILD_IMAGE := vmlinuz
zinstall: install zinstall:
$(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ $(call cmd,install)
$(KERNELRELEASE) vmlinuz System.map "$(INSTALL_PATH)"
CLEAN_FILES += lifimage CLEAN_FILES += lifimage
MRPROPER_FILES += palo.conf MRPROPER_FILES += palo.conf

28
arch/parisc/install.sh Normal file → Executable file
View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# #
# arch/parisc/install.sh, derived from arch/i386/boot/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public # This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive # License. See the file "COPYING" in the main directory of this archive
# for more details. # for more details.
@ -17,32 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -n "${INSTALLKERNEL}" ]; then
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
if [ -x /usr/sbin/${INSTALLKERNEL} ]; then exec /usr/sbin/${INSTALLKERNEL} "$@"; fi
fi
# Default install
if [ "$(basename $2)" = "vmlinuz" ]; then if [ "$(basename $2)" = "vmlinuz" ]; then
# Compressed install # Compressed install

View File

@ -408,8 +408,7 @@ endef
PHONY += install PHONY += install
install: install:
sh -x $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" vmlinux \ $(call cmd,install)
System.map "$(INSTALL_PATH)"
ifeq ($(KBUILD_EXTMOD),) ifeq ($(KBUILD_EXTMOD),)
# We need to generate vdso-offsets.h before compiling certain files in kernel/. # We need to generate vdso-offsets.h before compiling certain files in kernel/.

23
arch/powerpc/boot/install.sh Normal file → Executable file
View File

@ -15,32 +15,9 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
# Bail with error code if anything goes wrong
set -e set -e
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install
# this should work for both the pSeries zImage and the iSeries vmlinux.sm # this should work for both the pSeries zImage and the iSeries vmlinux.sm
image_name=`basename $2` image_name=`basename $2`

View File

@ -139,11 +139,10 @@ $(BOOT_TARGETS): vmlinux
Image.%: Image Image.%: Image
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
install: install-image = Image install: KBUILD_IMAGE := $(boot)/Image
zinstall: install-image = Image.gz zinstall: KBUILD_IMAGE := $(boot)/Image.gz
install zinstall: install zinstall:
$(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ $(call cmd,install)
$(boot)/$(install-image) System.map "$(INSTALL_PATH)"
PHONY += rv32_randconfig PHONY += rv32_randconfig
rv32_randconfig: rv32_randconfig:

21
arch/riscv/boot/install.sh Normal file → Executable file
View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# #
# arch/riscv/boot/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public # This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive # License. See the file "COPYING" in the main directory of this archive
# for more details. # for more details.
@ -18,25 +16,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
if [ "$(basename $2)" = "Image.gz" ]; then if [ "$(basename $2)" = "Image.gz" ]; then
# Compressed install # Compressed install

View File

@ -128,8 +128,7 @@ all: bzImage
KBUILD_IMAGE := $(boot)/bzImage KBUILD_IMAGE := $(boot)/bzImage
install: install:
sh -x $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ $(call cmd,install)
System.map "$(INSTALL_PATH)"
bzImage: vmlinux bzImage: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

6
arch/s390/boot/install.sh Normal file → Executable file
View File

@ -14,12 +14,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
echo "Warning: '${INSTALLKERNEL}' command not available - additional " \ echo "Warning: '${INSTALLKERNEL}' command not available - additional " \
"bootloader config required" >&2 "bootloader config required" >&2

View File

@ -72,8 +72,7 @@ image zImage uImage tftpboot.img vmlinux.aout: vmlinux
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
install: install:
sh $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ $(call cmd,install)
System.map "$(INSTALL_PATH)"
archheaders: archheaders:
$(Q)$(MAKE) $(build)=arch/sparc/kernel/syscalls all $(Q)$(MAKE) $(build)=arch/sparc/kernel/syscalls all

22
arch/sparc/boot/install.sh Normal file → Executable file
View File

@ -15,28 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install - same as make zlilo
if [ -f $4/vmlinuz ]; then if [ -f $4/vmlinuz ]; then
mv $4/vmlinuz $4/vmlinuz.old mv $4/vmlinuz $4/vmlinuz.old

View File

@ -271,8 +271,7 @@ $(BOOT_TARGETS): vmlinux
PHONY += install PHONY += install
install: install:
$(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ $(call cmd,install)
$(KBUILD_IMAGE) System.map "$(INSTALL_PATH)"
PHONY += vdso_install PHONY += vdso_install
vdso_install: vdso_install:

22
arch/x86/boot/install.sh Normal file → Executable file
View File

@ -15,28 +15,6 @@
# $2 - kernel image file # $2 - kernel image file
# $3 - kernel map file # $3 - kernel map file
# $4 - default install path (blank if root directory) # $4 - default install path (blank if root directory)
#
verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
exit 1
fi
}
# Make sure the files actually exist
verify "$2"
verify "$3"
# User may have a custom install script
if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
# Default install - same as make zlilo
if [ -f $4/vmlinuz ]; then if [ -f $4/vmlinuz ]; then
mv $4/vmlinuz $4/vmlinuz.old mv $4/vmlinuz $4/vmlinuz.old

40
scripts/install.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 1995 by Linus Torvalds
#
# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
# Common code factored out by Masahiro Yamada
set -e
# Make sure the files actually exist
for file in "${KBUILD_IMAGE}" System.map
do
if [ ! -f "${file}" ]; then
echo >&2
echo >&2 " *** Missing file: ${file}"
echo >&2 ' *** You need to run "make" before "make install".'
echo >&2
exit 1
fi
done
# User/arch may have a custom install script
for file in "${HOME}/bin/${INSTALLKERNEL}" \
"/sbin/${INSTALLKERNEL}" \
"${srctree}/arch/${SRCARCH}/install.sh" \
"${srctree}/arch/${SRCARCH}/boot/install.sh"
do
if [ ! -x "${file}" ]; then
continue
fi
# installkernel(8) says the parameters are like follows:
#
# installkernel version zImage System.map [directory]
exec "${file}" "${KERNELRELEASE}" "${KBUILD_IMAGE}" System.map "${INSTALL_PATH}"
done
echo "No install script found" >&2
exit 1