Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+63 -247
+2 -1
Makefile
··· 1298 1298 # to this Makefile to build and install external modules. 1299 1299 # Cancel sub_make_done so that options such as M=, V=, etc. are parsed. 1300 1300 1301 - install: sub_make_done := 1301 + quiet_cmd_install = INSTALL $(INSTALL_PATH) 1302 + cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh 1302 1303 1303 1304 # --------------------------------------------------------------------------- 1304 1305 # Tools
+2 -2
arch/arm/Makefile
··· 318 318 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 319 319 @$(kecho) ' Kernel: $(boot)/$@ is ready' 320 320 321 + $(INSTALL_TARGETS): KBUILD_IMAGE = $(boot)/$(patsubst %install,%Image,$@) 321 322 $(INSTALL_TARGETS): 322 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" \ 323 - $(boot)/$(patsubst %install,%Image,$@) System.map "$(INSTALL_PATH)" 323 + $(call cmd,install) 324 324 325 325 PHONY += vdso_install 326 326 vdso_install:
-21
arch/arm/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/arm/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "zImage" ]; then 40 23 # Compressed install
+2 -4
arch/arm64/Makefile
··· 162 162 Image.%: Image 163 163 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 164 164 165 - install: install-image := Image 166 - zinstall: install-image := Image.gz 165 + install: KBUILD_IMAGE := $(boot)/Image 167 166 install zinstall: 168 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 169 - $(boot)/$(install-image) System.map "$(INSTALL_PATH)" 167 + $(call cmd,install) 170 168 171 169 PHONY += vdso_install 172 170 vdso_install:
-21
arch/arm64/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/arm64/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "Image.gz" ]; then 40 23 # Compressed install
+2 -1
arch/ia64/Makefile
··· 72 72 73 73 CLEAN_FILES += vmlinux.gz 74 74 75 + install: KBUILD_IMAGE := vmlinux.gz 75 76 install: 76 - sh $(srctree)/arch/ia64/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)" 77 + $(call cmd,install) 77 78 78 79 define archhelp 79 80 echo '* compressed - Build compressed kernel image'
-10
arch/ia64/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/ia64/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 15 17 # $2 - kernel image file 16 18 # $3 - kernel map file 17 19 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - # User may have a custom install script 21 - 22 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 23 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 24 - 25 - # Default install - same as make zlilo 26 20 27 21 if [ -f $4/vmlinuz ]; then 28 22 mv $4/vmlinuz $4/vmlinuz.old
+2 -1
arch/m68k/Makefile
··· 138 138 archheaders: 139 139 $(Q)$(MAKE) $(build)=arch/m68k/kernel/syscalls all 140 140 141 + install: KBUILD_IMAGE := vmlinux.gz 141 142 install: 142 - sh $(srctree)/arch/m68k/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)" 143 + $(call cmd,install)
-22
arch/m68k/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+1 -2
arch/nios2/Makefile
··· 56 56 $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ 57 57 58 58 install: 59 - sh $(srctree)/$(nios2-boot)/install.sh $(KERNELRELEASE) \ 60 - $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)" 59 + $(call cmd,install) 61 60 62 61 define archhelp 63 62 echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'
-22
arch/nios2/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+5 -6
arch/parisc/Makefile
··· 184 184 $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@ 185 185 $(if $(CONFIG_COMPAT_VDSO), \ 186 186 $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@) 187 - install: 188 - $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ 189 - $(KERNELRELEASE) vmlinux System.map "$(INSTALL_PATH)" 190 - zinstall: 191 - $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ 192 - $(KERNELRELEASE) vmlinuz System.map "$(INSTALL_PATH)" 187 + 188 + install: KBUILD_IMAGE := vmlinux 189 + zinstall: KBUILD_IMAGE := vmlinuz 190 + install zinstall: 191 + $(call cmd,install) 193 192 194 193 CLEAN_FILES += lifimage 195 194 MRPROPER_FILES += palo.conf
-28
arch/parisc/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/parisc/install.sh, derived from arch/i386/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 15 17 # $2 - kernel image file 16 18 # $3 - kernel map file 17 19 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - 37 - if [ -n "${INSTALLKERNEL}" ]; then 38 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 39 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 40 - if [ -x /usr/sbin/${INSTALLKERNEL} ]; then exec /usr/sbin/${INSTALLKERNEL} "$@"; fi 41 - fi 42 - 43 - # Default install 44 20 45 21 if [ "$(basename $2)" = "vmlinuz" ]; then 46 22 # Compressed install
+1 -2
arch/powerpc/Makefile
··· 408 408 409 409 PHONY += install 410 410 install: 411 - sh -x $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" vmlinux \ 412 - System.map "$(INSTALL_PATH)" 411 + $(call cmd,install) 413 412 414 413 ifeq ($(KBUILD_EXTMOD),) 415 414 # We need to generate vdso-offsets.h before compiling certain files in kernel/.
-23
arch/powerpc/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 18 20 - # Bail with error code if anything goes wrong 21 19 set -e 22 - 23 - verify () { 24 - if [ ! -f "$1" ]; then 25 - echo "" 1>&2 26 - echo " *** Missing file: $1" 1>&2 27 - echo ' *** You need to run "make" before "make install".' 1>&2 28 - echo "" 1>&2 29 - exit 1 30 - fi 31 - } 32 - 33 - # Make sure the files actually exist 34 - verify "$2" 35 - verify "$3" 36 - 37 - # User may have a custom install script 38 - 39 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 40 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 41 - 42 - # Default install 43 20 44 21 # this should work for both the pSeries zImage and the iSeries vmlinux.sm 45 22 image_name=`basename $2`
+3 -4
arch/riscv/Makefile
··· 139 139 Image.%: Image 140 140 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 141 141 142 - install: install-image = Image 143 - zinstall: install-image = Image.gz 142 + install: KBUILD_IMAGE := $(boot)/Image 143 + zinstall: KBUILD_IMAGE := $(boot)/Image.gz 144 144 install zinstall: 145 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 146 - $(boot)/$(install-image) System.map "$(INSTALL_PATH)" 145 + $(call cmd,install) 147 146 148 147 PHONY += rv32_randconfig 149 148 rv32_randconfig:
-21
arch/riscv/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/riscv/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "Image.gz" ]; then 40 23 # Compressed install
+1 -2
arch/s390/Makefile
··· 128 128 KBUILD_IMAGE := $(boot)/bzImage 129 129 130 130 install: 131 - sh -x $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ 132 - System.map "$(INSTALL_PATH)" 131 + $(call cmd,install) 133 132 134 133 bzImage: vmlinux 135 134 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
-6
arch/s390/boot/install.sh
··· 14 14 # $2 - kernel image file 15 15 # $3 - kernel map file 16 16 # $4 - default install path (blank if root directory) 17 - # 18 - 19 - # User may have a custom install script 20 - 21 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 22 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 23 17 24 18 echo "Warning: '${INSTALLKERNEL}' command not available - additional " \ 25 19 "bootloader config required" >&2
+1 -2
arch/sparc/Makefile
··· 72 72 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 73 73 74 74 install: 75 - sh $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ 76 - System.map "$(INSTALL_PATH)" 75 + $(call cmd,install) 77 76 78 77 archheaders: 79 78 $(Q)$(MAKE) $(build)=arch/sparc/kernel/syscalls all
-22
arch/sparc/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+1 -2
arch/x86/Makefile
··· 271 271 272 272 PHONY += install 273 273 install: 274 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 275 - $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)" 274 + $(call cmd,install) 276 275 277 276 PHONY += vdso_install 278 277 vdso_install:
-22
arch/x86/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+40
scripts/install.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + # 4 + # Copyright (C) 1995 by Linus Torvalds 5 + # 6 + # Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin 7 + # Common code factored out by Masahiro Yamada 8 + 9 + set -e 10 + 11 + # Make sure the files actually exist 12 + for file in "${KBUILD_IMAGE}" System.map 13 + do 14 + if [ ! -f "${file}" ]; then 15 + echo >&2 16 + echo >&2 " *** Missing file: ${file}" 17 + echo >&2 ' *** You need to run "make" before "make install".' 18 + echo >&2 19 + exit 1 20 + fi 21 + done 22 + 23 + # User/arch may have a custom install script 24 + for file in "${HOME}/bin/${INSTALLKERNEL}" \ 25 + "/sbin/${INSTALLKERNEL}" \ 26 + "${srctree}/arch/${SRCARCH}/install.sh" \ 27 + "${srctree}/arch/${SRCARCH}/boot/install.sh" 28 + do 29 + if [ ! -x "${file}" ]; then 30 + continue 31 + fi 32 + 33 + # installkernel(8) says the parameters are like follows: 34 + # 35 + # installkernel version zImage System.map [directory] 36 + exec "${file}" "${KERNELRELEASE}" "${KBUILD_IMAGE}" System.map "${INSTALL_PATH}" 37 + done 38 + 39 + echo "No install script found" >&2 40 + exit 1