blob: cc0d2824e1006626c1d1bbcc4efc47af6a135e1d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Sam Ravnborgd39a206b2006-04-11 13:24:32 +02002#
3# kbuild file for usr/ - including initramfs image
4#
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Masahiro Yamadad4e90562020-02-04 01:47:08 +09006compress-y := shipped
Masahiro Yamada65e00e02020-01-05 00:02:37 +09007compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip
8compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2
9compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma
10compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc
11compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo
12compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4
Nick Terrella30d8a32020-07-30 12:08:37 -070013compress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD) := zstd
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070014
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070015obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Masahiro Yamada65e00e02020-01-05 00:02:37 +090017$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Masahiro Yamada129ab0d2021-12-14 11:53:53 +090019ramfs-input := $(CONFIG_INITRAMFS_SOURCE)
Masahiro Yamada65e00e02020-01-05 00:02:37 +090020cpio-data :=
21
22# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
23# default contents.
24ifeq ($(ramfs-input),)
25ramfs-input := $(srctree)/$(src)/default_cpio_list
26endif
27
28ifeq ($(words $(ramfs-input)),1)
29
30# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
31# .cpio, use it directly as an initramfs.
32ifneq ($(filter %.cpio,$(ramfs-input)),)
33cpio-data := $(ramfs-input)
34endif
35
36# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
37# .cpio.*, use it directly as an initramfs, and avoid double compression.
38ifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
39cpio-data := $(ramfs-input)
40compress-y := shipped
41endif
42
43endif
44
45# For other cases, generate the initramfs cpio archive based on the contents
46# specified by CONFIG_INITRAMFS_SOURCE.
47ifeq ($(cpio-data),)
48
49cpio-data := $(obj)/initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020050
Masahiro Yamada5f2fb522020-02-02 01:49:24 +090051hostprogs := gen_init_cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020052
Masahiro Yamada65e00e02020-01-05 00:02:37 +090053# .initramfs_data.cpio.d is used to identify all files included
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020054# in initramfs and to detect if any files are added/removed.
55# Removed files are identified by directory timestamp being updated
56# The dependency list is generated by gen_initramfs.sh -l
Masahiro Yamada65e00e02020-01-05 00:02:37 +090057-include $(obj)/.initramfs_data.cpio.d
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100058
Sam Ravnborg58a2f7d2006-08-07 20:58:28 +020059# do not try to update files included in initramfs
60$(deps_initramfs): ;
61
Masahiro Yamada65e00e02020-01-05 00:02:37 +090062quiet_cmd_initfs = GEN $@
63 cmd_initfs = \
64 $(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
65 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
66 $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
67 $(ramfs-input)
68
Alain Knaffa26ee602009-01-07 00:10:27 -080069# We rebuild initramfs_data.cpio if:
Eugen Cazacuc7fe0602018-12-01 17:03:22 +010070# 1) Any included file is newer than initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020071# 2) There are changes in which files are included (added or deleted)
Alain Knaffa26ee602009-01-07 00:10:27 -080072# 3) If gen_init_cpio are newer than initramfs_data.cpio
Eugen Cazacuc7fe0602018-12-01 17:03:22 +010073# 4) Arguments to gen_initramfs.sh changes
Masahiro Yamada65e00e02020-01-05 00:02:37 +090074$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020075 $(call if_changed,initfs)
Masahiro Yamadad6fc9fc2019-07-01 09:58:40 +090076
Masahiro Yamada65e00e02020-01-05 00:02:37 +090077endif
78
79$(obj)/initramfs_inc_data: $(cpio-data) FORCE
80 $(call if_changed,$(compress-y))
81
82targets += initramfs_data.cpio initramfs_inc_data
83
Masahiro Yamadad6fc9fc2019-07-01 09:58:40 +090084subdir-$(CONFIG_UAPI_HEADER_TEST) += include