1#
2# kbuild file for usr/ - including initramfs image
3#
4
5klibcdirs:;
6PHONY += klibcdirs
7
8# Gzip
9suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP)   = .gz
10
11# Bzip2
12suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2)  = .bz2
13
14# Lzma
15suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA)   = .lzma
16
17# Lzo
18suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO)   = .lzo
19
20# Generate builtin.o based on initramfs_data.o
21obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data$(suffix_y).o
22
23# initramfs_data.o contains the compressed initramfs_data.cpio image.
24# The image is included using .incbin, a dependency which is not
25# tracked automatically.
26$(obj)/initramfs_data$(suffix_y).o: $(obj)/initramfs_data.cpio$(suffix_y) FORCE
27
28#####
29# Generate the initramfs cpio archive
30
31hostprogs-y := gen_init_cpio
32initramfs   := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
33ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
34			$(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
35ramfs-args  := \
36        $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
37        $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
38
39# .initramfs_data.cpio.d is used to identify all files included
40# in initramfs and to detect if any files are added/removed.
41# Removed files are identified by directory timestamp being updated
42# The dependency list is generated by gen_initramfs.sh -l
43ifneq ($(wildcard $(obj)/.initramfs_data.cpio.d),)
44	include $(obj)/.initramfs_data.cpio.d
45endif
46
47quiet_cmd_initfs = GEN     $@
48      cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
49
50targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.lzo initramfs_data.cpio
51# do not try to update files included in initramfs
52$(deps_initramfs): ;
53
54$(deps_initramfs): klibcdirs
55# We rebuild initramfs_data.cpio if:
56# 1) Any included file is newer then initramfs_data.cpio
57# 2) There are changes in which files are included (added or deleted)
58# 3) If gen_init_cpio are newer than initramfs_data.cpio
59# 4) arguments to gen_initramfs.sh changes
60
61# Broadcom patched
62BUILD_MFG := 0
63ifeq ($(CONFIG_BLK_DEV_INITRD),y)
64ifeq ($(CONFIG_BLK_DEV_RAM),)
65BUILD_MFG := 1
66endif
67endif
68
69ifeq ($(MFG_WAR), 1)
70BUILD_MFG = 0
71ramfs-input = -d
72endif
73
74ifeq ($(BUILD_MFG), 0)
75$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
76	$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
77	$(call if_changed,initfs)
78endif
79