xref: /kernel/linux/linux-5.10/usr/Makefile (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#
38c2ecf20Sopenharmony_ci# kbuild file for usr/ - including initramfs image
48c2ecf20Sopenharmony_ci#
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci# cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the
78c2ecf20Sopenharmony_ci# size at the end of the compressed file, which unfortunately does not work
88c2ecf20Sopenharmony_ci# with unpack_to_rootfs(). Make size_append no-op.
98c2ecf20Sopenharmony_cioverride size_append := :
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cicompress-y					:= shipped
128c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP)	:= gzip
138c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2)	:= bzip2
148c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA)	:= lzma
158c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_XZ)	:= xzmisc
168c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZO)	:= lzo
178c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4)	:= lz4
188c2ecf20Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD)	:= zstd
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciobj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciramfs-input := $(strip $(shell echo $(CONFIG_INITRAMFS_SOURCE)))
258c2ecf20Sopenharmony_cicpio-data :=
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
288c2ecf20Sopenharmony_ci# default contents.
298c2ecf20Sopenharmony_ciifeq ($(ramfs-input),)
308c2ecf20Sopenharmony_ciramfs-input := $(srctree)/$(src)/default_cpio_list
318c2ecf20Sopenharmony_ciendif
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciifeq ($(words $(ramfs-input)),1)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
368c2ecf20Sopenharmony_ci# .cpio, use it directly as an initramfs.
378c2ecf20Sopenharmony_ciifneq ($(filter %.cpio,$(ramfs-input)),)
388c2ecf20Sopenharmony_cicpio-data := $(ramfs-input)
398c2ecf20Sopenharmony_ciendif
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
428c2ecf20Sopenharmony_ci# .cpio.*, use it directly as an initramfs, and avoid double compression.
438c2ecf20Sopenharmony_ciifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
448c2ecf20Sopenharmony_cicpio-data := $(ramfs-input)
458c2ecf20Sopenharmony_cicompress-y := shipped
468c2ecf20Sopenharmony_ciendif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciendif
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci# For other cases, generate the initramfs cpio archive based on the contents
518c2ecf20Sopenharmony_ci# specified by CONFIG_INITRAMFS_SOURCE.
528c2ecf20Sopenharmony_ciifeq ($(cpio-data),)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cicpio-data := $(obj)/initramfs_data.cpio
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cihostprogs := gen_init_cpio
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci# .initramfs_data.cpio.d is used to identify all files included
598c2ecf20Sopenharmony_ci# in initramfs and to detect if any files are added/removed.
608c2ecf20Sopenharmony_ci# Removed files are identified by directory timestamp being updated
618c2ecf20Sopenharmony_ci# The dependency list is generated by gen_initramfs.sh -l
628c2ecf20Sopenharmony_ci-include $(obj)/.initramfs_data.cpio.d
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci# do not try to update files included in initramfs
658c2ecf20Sopenharmony_ci$(deps_initramfs): ;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciquiet_cmd_initfs = GEN     $@
688c2ecf20Sopenharmony_ci      cmd_initfs = \
698c2ecf20Sopenharmony_ci	$(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
708c2ecf20Sopenharmony_ci	$(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
718c2ecf20Sopenharmony_ci	$(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
728c2ecf20Sopenharmony_ci	$(ramfs-input)
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci# We rebuild initramfs_data.cpio if:
758c2ecf20Sopenharmony_ci# 1) Any included file is newer than initramfs_data.cpio
768c2ecf20Sopenharmony_ci# 2) There are changes in which files are included (added or deleted)
778c2ecf20Sopenharmony_ci# 3) If gen_init_cpio are newer than initramfs_data.cpio
788c2ecf20Sopenharmony_ci# 4) Arguments to gen_initramfs.sh changes
798c2ecf20Sopenharmony_ci$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
808c2ecf20Sopenharmony_ci	$(call if_changed,initfs)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciendif
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci$(obj)/initramfs_inc_data: $(cpio-data) FORCE
858c2ecf20Sopenharmony_ci	$(call if_changed,$(compress-y))
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_citargets += initramfs_data.cpio initramfs_inc_data
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cisubdir-$(CONFIG_UAPI_HEADER_TEST) += include
90