blob: 0b87e71c00fcc9c6cb0de2248b191e89228bf9b6 [file] [log] [blame]
Sam Ravnborgd39a206b2006-04-11 13:24:32 +02001#
2# kbuild file for usr/ - including initramfs image
3#
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Sam Ravnborgd39a206b2006-04-11 13:24:32 +02005klibcdirs:;
Sam Ravnborg48f1f052006-07-23 19:37:44 +02006PHONY += klibcdirs
7
Nicholas Pigginae30ab42017-01-05 20:29:35 +10008suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION))
Nicholas Piggin9e3596b2017-01-05 20:29:36 +10009datafile_y = initramfs_data.cpio$(suffix_y)
10AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)"
11
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070012
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020013# Generate builtin.o based on initramfs_data.o
Hendrik Brueckner6ae64e42010-09-17 15:24:09 -070014obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Alain Knaffa26ee602009-01-07 00:10:27 -080016# initramfs_data.o contains the compressed initramfs_data.cpio image.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017# The image is included using .incbin, a dependency which is not
18# tracked automatically.
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100019$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020021#####
22# Generate the initramfs cpio archive
23
24hostprogs-y := gen_init_cpio
25initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
26ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
Thomas Choua26d79c2006-11-25 11:09:18 -080027 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020028ramfs-args := \
29 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
Nickolayff541712006-06-09 21:24:14 +040030 $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020031
Alain Knaffa26ee602009-01-07 00:10:27 -080032# .initramfs_data.cpio.d is used to identify all files included
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020033# in initramfs and to detect if any files are added/removed.
34# Removed files are identified by directory timestamp being updated
35# The dependency list is generated by gen_initramfs.sh -l
Alain Knaffa26ee602009-01-07 00:10:27 -080036ifneq ($(wildcard $(obj)/.initramfs_data.cpio.d),)
37 include $(obj)/.initramfs_data.cpio.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070038endif
39
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020040quiet_cmd_initfs = GEN $@
41 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100043targets := $(datafile_y)
44
Sam Ravnborg58a2f7d2006-08-07 20:58:28 +020045# do not try to update files included in initramfs
46$(deps_initramfs): ;
47
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020048$(deps_initramfs): klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080049# We rebuild initramfs_data.cpio if:
50# 1) Any included file is newer then initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020051# 2) There are changes in which files are included (added or deleted)
Alain Knaffa26ee602009-01-07 00:10:27 -080052# 3) If gen_init_cpio are newer than initramfs_data.cpio
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020053# 4) arguments to gen_initramfs.sh changes
Nicholas Piggin9e3596b2017-01-05 20:29:36 +100054$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
Alain Knaffa26ee602009-01-07 00:10:27 -080055 $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
Sam Ravnborgd39a206b2006-04-11 13:24:32 +020056 $(call if_changed,initfs)