blob: e6f7cb2f81db4a2936cd6d633ec1853c85355294 [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
Sam Ravnborgd39a206b2006-04-11 13:24:32 +02006klibcdirs:;
Sam Ravnborg48f1f052006-07-23 19:37:44 +02007PHONY += klibcdirs
8
Nicholas Pigginae30ab42017-01-05 20:29:35 +10009suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION))
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100010datafile_y = initramfs_data.cpio$(suffix_y)
Florian Fainellie08b1872017-11-02 15:59:44 -070011datafile_d_y = .$(datafile_y).d
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100012AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)"
13
Greg Thelen6279eb32019-09-23 15:33:05 -070014# clean rules do not have CONFIG_INITRAMFS_COMPRESSION. So clean up after all
15# possible compression formats.
16clean-files += initramfs_data.cpio*
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070017
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020018# Generate builtin.o based on initramfs_data.o
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070019obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Alain Knaffa26ee602009-01-07 00:10:27 -080021# initramfs_data.o contains the compressed initramfs_data.cpio image.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022# The image is included using .incbin, a dependency which is not
23# tracked automatically.
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100024$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020026#####
27# Generate the initramfs cpio archive
28
29hostprogs-y := gen_init_cpio
Masahiro Yamadaf6f57a42018-08-21 00:29:51 +090030initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020031ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
Thomas Choua26d79c2006-11-25 11:09:18 -080032 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020033ramfs-args := \
34 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
Nickolayff541712006-06-09 21:24:14 +040035 $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020036
Florian Fainellie08b1872017-11-02 15:59:44 -070037# $(datafile_d_y) is used to identify all files included
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020038# in initramfs and to detect if any files are added/removed.
39# Removed files are identified by directory timestamp being updated
40# The dependency list is generated by gen_initramfs.sh -l
Florian Fainellie08b1872017-11-02 15:59:44 -070041ifneq ($(wildcard $(obj)/$(datafile_d_y)),)
42 include $(obj)/$(datafile_d_y)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043endif
44
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020045quiet_cmd_initfs = GEN $@
46 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100048targets := $(datafile_y)
49
Sam Ravnborg58a2f7d2006-08-07 20:58:28 +020050# do not try to update files included in initramfs
51$(deps_initramfs): ;
52
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020053$(deps_initramfs): klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080054# We rebuild initramfs_data.cpio if:
Eugen Cazacuc7fe0602018-12-01 17:03:22 +010055# 1) Any included file is newer than initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020056# 2) There are changes in which files are included (added or deleted)
Alain Knaffa26ee602009-01-07 00:10:27 -080057# 3) If gen_init_cpio are newer than initramfs_data.cpio
Eugen Cazacuc7fe0602018-12-01 17:03:22 +010058# 4) Arguments to gen_initramfs.sh changes
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100059$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
Florian Fainellie08b1872017-11-02 15:59:44 -070060 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020061 $(call if_changed,initfs)
Masahiro Yamadad6fc9fc2019-07-01 09:58:40 +090062
63subdir-$(CONFIG_UAPI_HEADER_TEST) += include