xref: /OK3568_Linux_fs/kernel/usr/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# kbuild file for usr/ - including initramfs image
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun# cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the
7*4882a593Smuzhiyun# size at the end of the compressed file, which unfortunately does not work
8*4882a593Smuzhiyun# with unpack_to_rootfs(). Make size_append no-op.
9*4882a593Smuzhiyunoverride size_append := :
10*4882a593Smuzhiyun
11*4882a593Smuzhiyuncompress-y					:= shipped
12*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP)	:= gzip
13*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2)	:= bzip2
14*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA)	:= lzma
15*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_XZ)	:= xzmisc
16*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_LZO)	:= lzo
17*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4)	:= lz4
18*4882a593Smuzhiyuncompress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD)	:= zstd
19*4882a593Smuzhiyun
20*4882a593Smuzhiyunobj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
23*4882a593Smuzhiyun
24*4882a593Smuzhiyunramfs-input := $(strip $(shell echo $(CONFIG_INITRAMFS_SOURCE)))
25*4882a593Smuzhiyuncpio-data :=
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
28*4882a593Smuzhiyun# default contents.
29*4882a593Smuzhiyunifeq ($(ramfs-input),)
30*4882a593Smuzhiyunramfs-input := $(srctree)/$(src)/default_cpio_list
31*4882a593Smuzhiyunendif
32*4882a593Smuzhiyun
33*4882a593Smuzhiyunifeq ($(words $(ramfs-input)),1)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
36*4882a593Smuzhiyun# .cpio, use it directly as an initramfs.
37*4882a593Smuzhiyunifneq ($(filter %.cpio,$(ramfs-input)),)
38*4882a593Smuzhiyuncpio-data := $(ramfs-input)
39*4882a593Smuzhiyunendif
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
42*4882a593Smuzhiyun# .cpio.*, use it directly as an initramfs, and avoid double compression.
43*4882a593Smuzhiyunifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
44*4882a593Smuzhiyuncpio-data := $(ramfs-input)
45*4882a593Smuzhiyuncompress-y := shipped
46*4882a593Smuzhiyunendif
47*4882a593Smuzhiyun
48*4882a593Smuzhiyunendif
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun# For other cases, generate the initramfs cpio archive based on the contents
51*4882a593Smuzhiyun# specified by CONFIG_INITRAMFS_SOURCE.
52*4882a593Smuzhiyunifeq ($(cpio-data),)
53*4882a593Smuzhiyun
54*4882a593Smuzhiyuncpio-data := $(obj)/initramfs_data.cpio
55*4882a593Smuzhiyun
56*4882a593Smuzhiyunhostprogs := gen_init_cpio
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun# .initramfs_data.cpio.d is used to identify all files included
59*4882a593Smuzhiyun# in initramfs and to detect if any files are added/removed.
60*4882a593Smuzhiyun# Removed files are identified by directory timestamp being updated
61*4882a593Smuzhiyun# The dependency list is generated by gen_initramfs.sh -l
62*4882a593Smuzhiyun-include $(obj)/.initramfs_data.cpio.d
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun# do not try to update files included in initramfs
65*4882a593Smuzhiyun$(deps_initramfs): ;
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunquiet_cmd_initfs = GEN     $@
68*4882a593Smuzhiyun      cmd_initfs = \
69*4882a593Smuzhiyun	$(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
70*4882a593Smuzhiyun	$(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
71*4882a593Smuzhiyun	$(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
72*4882a593Smuzhiyun	$(ramfs-input)
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun# We rebuild initramfs_data.cpio if:
75*4882a593Smuzhiyun# 1) Any included file is newer than initramfs_data.cpio
76*4882a593Smuzhiyun# 2) There are changes in which files are included (added or deleted)
77*4882a593Smuzhiyun# 3) If gen_init_cpio are newer than initramfs_data.cpio
78*4882a593Smuzhiyun# 4) Arguments to gen_initramfs.sh changes
79*4882a593Smuzhiyun$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
80*4882a593Smuzhiyun	$(call if_changed,initfs)
81*4882a593Smuzhiyun
82*4882a593Smuzhiyunendif
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun$(obj)/initramfs_inc_data: $(cpio-data) FORCE
85*4882a593Smuzhiyun	$(call if_changed,$(compress-y))
86*4882a593Smuzhiyun
87*4882a593Smuzhiyuntargets += initramfs_data.cpio initramfs_inc_data
88*4882a593Smuzhiyun
89*4882a593Smuzhiyunsubdir-$(CONFIG_UAPI_HEADER_TEST) += include
90