blob: 34a9fcd0f5373e7d9781adda38a344758d87bf95 [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)
11AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)"
12
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070013
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020014# Generate builtin.o based on initramfs_data.o
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070015obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Alain Knaffa26ee602009-01-07 00:10:27 -080017# initramfs_data.o contains the compressed initramfs_data.cpio image.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018# The image is included using .incbin, a dependency which is not
19# tracked automatically.
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100020$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020022#####
23# Generate the initramfs cpio archive
24
25hostprogs-y := gen_init_cpio
26initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
27ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
Thomas Choua26d79c2006-11-25 11:09:18 -080028 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020029ramfs-args := \
30 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
Nickolayff541712006-06-09 21:24:14 +040031 $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020032
Alain Knaffa26ee602009-01-07 00:10:27 -080033# .initramfs_data.cpio.d is used to identify all files included
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020034# in initramfs and to detect if any files are added/removed.
35# Removed files are identified by directory timestamp being updated
36# The dependency list is generated by gen_initramfs.sh -l
Alain Knaffa26ee602009-01-07 00:10:27 -080037ifneq ($(wildcard $(obj)/.initramfs_data.cpio.d),)
38 include $(obj)/.initramfs_data.cpio.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070039endif
40
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020041quiet_cmd_initfs = GEN $@
42 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100044targets := $(datafile_y)
45
Sam Ravnborg58a2f7d2006-08-07 20:58:28 +020046# do not try to update files included in initramfs
47$(deps_initramfs): ;
48
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020049$(deps_initramfs): klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080050# We rebuild initramfs_data.cpio if:
51# 1) Any included file is newer then initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020052# 2) There are changes in which files are included (added or deleted)
Alain Knaffa26ee602009-01-07 00:10:27 -080053# 3) If gen_init_cpio are newer than initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020054# 4) arguments to gen_initramfs.sh changes
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100055$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080056 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020057 $(call if_changed,initfs)