blob: 237a028693ce9b497deabb95aa8f922485bee5fd [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
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070014
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020015# Generate builtin.o based on initramfs_data.o
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070016obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Alain Knaffa26ee602009-01-07 00:10:27 -080018# initramfs_data.o contains the compressed initramfs_data.cpio image.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019# The image is included using .incbin, a dependency which is not
20# tracked automatically.
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100021$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020023#####
24# Generate the initramfs cpio archive
25
26hostprogs-y := gen_init_cpio
27initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
28ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
Thomas Choua26d79c2006-11-25 11:09:18 -080029 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020030ramfs-args := \
31 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
Nickolayff541712006-06-09 21:24:14 +040032 $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020033
Florian Fainellie08b1872017-11-02 15:59:44 -070034# $(datafile_d_y) is used to identify all files included
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020035# in initramfs and to detect if any files are added/removed.
36# Removed files are identified by directory timestamp being updated
37# The dependency list is generated by gen_initramfs.sh -l
Florian Fainellie08b1872017-11-02 15:59:44 -070038ifneq ($(wildcard $(obj)/$(datafile_d_y)),)
39 include $(obj)/$(datafile_d_y)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040endif
41
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020042quiet_cmd_initfs = GEN $@
43 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100045targets := $(datafile_y)
46
Sam Ravnborg58a2f7d2006-08-07 20:58:28 +020047# do not try to update files included in initramfs
48$(deps_initramfs): ;
49
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020050$(deps_initramfs): klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080051# We rebuild initramfs_data.cpio if:
52# 1) Any included file is newer then initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020053# 2) There are changes in which files are included (added or deleted)
Alain Knaffa26ee602009-01-07 00:10:27 -080054# 3) If gen_init_cpio are newer than initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020055# 4) arguments to gen_initramfs.sh changes
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100056$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
Florian Fainellie08b1872017-11-02 15:59:44 -070057 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020058 $(call if_changed,initfs)