kbuild: factor out the common installation code into scripts/install.sh
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 3 May 2022 02:47:16 +0000 (11:47 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 11 May 2022 12:45:53 +0000 (21:45 +0900)
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>
24 files changed:
Makefile
arch/arm/Makefile
arch/arm/boot/install.sh [changed mode: 0644->0755]
arch/arm64/Makefile
arch/arm64/boot/install.sh [changed mode: 0644->0755]
arch/ia64/Makefile
arch/ia64/install.sh [changed mode: 0644->0755]
arch/m68k/Makefile
arch/m68k/install.sh [changed mode: 0644->0755]
arch/nios2/Makefile
arch/nios2/boot/install.sh [changed mode: 0644->0755]
arch/parisc/Makefile
arch/parisc/install.sh [changed mode: 0644->0755]
arch/powerpc/Makefile
arch/powerpc/boot/install.sh [changed mode: 0644->0755]
arch/riscv/Makefile
arch/riscv/boot/install.sh [changed mode: 0644->0755]
arch/s390/Makefile
arch/s390/boot/install.sh [changed mode: 0644->0755]
arch/sparc/Makefile
arch/sparc/boot/install.sh [changed mode: 0644->0755]
arch/x86/Makefile
arch/x86/boot/install.sh [changed mode: 0644->0755]
scripts/install.sh [new file with mode: 0755]

index 9a60f73..154c32a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1298,7 +1298,8 @@ scripts_unifdef: scripts_basic
 # to this Makefile to build and install external modules.
 # 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
index a2391b8..187f4b2 100644 (file)
@@ -318,9 +318,9 @@ $(BOOT_TARGETS): vmlinux
        $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
        @$(kecho) '  Kernel: $(boot)/$@ is ready'
 
+$(INSTALL_TARGETS): KBUILD_IMAGE = $(boot)/$(patsubst %install,%Image,$@)
 $(INSTALL_TARGETS):
-       $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" \
-       $(boot)/$(patsubst %install,%Image,$@) System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 PHONY += vdso_install
 vdso_install:
old mode 100644 (file)
new mode 100755 (executable)
index 2a45092..9ec11fa
@@ -1,7 +1,5 @@
 #!/bin/sh
 #
-# arch/arm/boot/install.sh
-#
 # 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
 # for more details.
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
 # Compressed install
index 2f1de88..6d9d4a5 100644 (file)
@@ -162,11 +162,9 @@ Image: vmlinux
 Image.%: Image
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
 
-install: install-image := Image
-zinstall: install-image := Image.gz
+install: KBUILD_IMAGE := $(boot)/Image
 install zinstall:
-       $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \
-       $(boot)/$(install-image) System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 PHONY += vdso_install
 vdso_install:
old mode 100644 (file)
new mode 100755 (executable)
index d91e1f0..7399d70
@@ -1,7 +1,5 @@
 #!/bin/sh
 #
-# arch/arm64/boot/install.sh
-#
 # 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
 # for more details.
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
 # Compressed install
index 6c4bfa5..e55c2f1 100644 (file)
@@ -72,8 +72,9 @@ archheaders:
 
 CLEAN_FILES += vmlinux.gz
 
+install: KBUILD_IMAGE := vmlinux.gz
 install:
-       sh $(srctree)/arch/ia64/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 define archhelp
   echo '* compressed   - Build compressed kernel image'
old mode 100644 (file)
new mode 100755 (executable)
index 0e932f5..2d4b66a
@@ -1,7 +1,5 @@
 #!/bin/sh
 #
-# arch/ia64/install.sh
-#
 # 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
 # for more details.
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
        mv $4/vmlinuz $4/vmlinuz.old
index 740fc97..e358605 100644 (file)
@@ -138,5 +138,6 @@ CLEAN_FILES += vmlinux.gz vmlinux.bz2
 archheaders:
        $(Q)$(MAKE) $(build)=arch/m68k/kernel/syscalls all
 
+install: KBUILD_IMAGE := vmlinux.gz
 install:
-       sh $(srctree)/arch/m68k/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
old mode 100644 (file)
new mode 100755 (executable)
index 57d640d..af65e16
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
        mv $4/vmlinuz $4/vmlinuz.old
index 02d6785..d6a7499 100644 (file)
@@ -56,8 +56,7 @@ $(BOOT_TARGETS): vmlinux
        $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
 
 install:
-       sh $(srctree)/$(nios2-boot)/install.sh $(KERNELRELEASE) \
-       $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 define archhelp
   echo  '* vmImage         - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'
old mode 100644 (file)
new mode 100755 (executable)
index 3cb3f46..34a2fee
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
        mv $4/vmlinuz $4/vmlinuz.old
index 7583fc3..aca1710 100644 (file)
@@ -184,12 +184,11 @@ vdso_install:
        $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@
        $(if $(CONFIG_COMPAT_VDSO), \
                $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@)
-install:
-       $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \
-                       $(KERNELRELEASE) vmlinux System.map "$(INSTALL_PATH)"
-zinstall:
-       $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \
-                       $(KERNELRELEASE) vmlinuz System.map "$(INSTALL_PATH)"
+
+install: KBUILD_IMAGE := vmlinux
+zinstall: KBUILD_IMAGE := vmlinuz
+install zinstall:
+       $(call cmd,install)
 
 CLEAN_FILES    += lifimage
 MRPROPER_FILES += palo.conf
old mode 100644 (file)
new mode 100755 (executable)
index 70d3cff..933d031
@@ -1,7 +1,5 @@
 #!/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
 # License.  See the file "COPYING" in the main directory of this archive
 # for more details.
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
 # Compressed install
index eb541e7..45a9caa 100644 (file)
@@ -408,8 +408,7 @@ endef
 
 PHONY += install
 install:
-       sh -x $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" vmlinux \
-       System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 ifeq ($(KBUILD_EXTMOD),)
 # We need to generate vdso-offsets.h before compiling certain files in kernel/.
old mode 100644 (file)
new mode 100755 (executable)
index 1447315..461902c
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
-#
 
-# Bail with error code if anything goes wrong
 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
 image_name=`basename $2`
 
index 7d81102..2b93ca9 100644 (file)
@@ -139,11 +139,10 @@ $(BOOT_TARGETS): vmlinux
 Image.%: Image
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
 
-install: install-image = Image
-zinstall: install-image = Image.gz
+install: KBUILD_IMAGE := $(boot)/Image
+zinstall: KBUILD_IMAGE := $(boot)/Image.gz
 install zinstall:
-       $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \
-       $(boot)/$(install-image) System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 PHONY += rv32_randconfig
 rv32_randconfig:
old mode 100644 (file)
new mode 100755 (executable)
index 18c3915..4c63f3f
@@ -1,7 +1,5 @@
 #!/bin/sh
 #
-# arch/riscv/boot/install.sh
-#
 # 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
 # for more details.
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
 # Compressed install
index 7a65bca..cc24255 100644 (file)
@@ -128,8 +128,7 @@ all: bzImage
 KBUILD_IMAGE   := $(boot)/bzImage
 
 install:
-       sh -x $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \
-             System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 bzImage: vmlinux
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
old mode 100644 (file)
new mode 100755 (executable)
index 515b27a..616ba16
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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 " \
      "bootloader config required" >&2
index c7008bb..fe58a41 100644 (file)
@@ -72,8 +72,7 @@ image zImage uImage tftpboot.img vmlinux.aout: vmlinux
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
 
 install:
-       sh $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \
-               System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 archheaders:
        $(Q)$(MAKE) $(build)=arch/sparc/kernel/syscalls all
old mode 100644 (file)
new mode 100755 (executable)
index b32851e..4f130f3
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
        mv $4/vmlinuz $4/vmlinuz.old
index 63d50f6..5e1f21a 100644 (file)
@@ -271,8 +271,7 @@ $(BOOT_TARGETS): vmlinux
 
 PHONY += install
 install:
-       $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \
-               $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)"
+       $(call cmd,install)
 
 PHONY += vdso_install
 vdso_install:
old mode 100644 (file)
new mode 100755 (executable)
index d13ec1c..0849f4b
 #   $2 - kernel image file
 #   $3 - kernel map file
 #   $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
        mv $4/vmlinuz $4/vmlinuz.old
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100755 (executable)
index 0000000..9bb0fb4
--- /dev/null
@@ -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