162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci# 362306a36Sopenharmony_ci# kbuild file for usr/ - including initramfs image 462306a36Sopenharmony_ci# 562306a36Sopenharmony_ci 662306a36Sopenharmony_cicompress-y := copy 762306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip 862306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2 962306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma 1062306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc 1162306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo 1262306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4 1362306a36Sopenharmony_cicompress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD) := zstd 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciobj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciramfs-input := $(CONFIG_INITRAMFS_SOURCE) 2062306a36Sopenharmony_cicpio-data := 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the 2362306a36Sopenharmony_ci# default contents. 2462306a36Sopenharmony_ciifeq ($(ramfs-input),) 2562306a36Sopenharmony_ciramfs-input := $(srctree)/$(src)/default_cpio_list 2662306a36Sopenharmony_ciendif 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciifeq ($(words $(ramfs-input)),1) 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with 3162306a36Sopenharmony_ci# .cpio, use it directly as an initramfs. 3262306a36Sopenharmony_ciifneq ($(filter %.cpio,$(ramfs-input)),) 3362306a36Sopenharmony_cicpio-data := $(ramfs-input) 3462306a36Sopenharmony_ciendif 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with 3762306a36Sopenharmony_ci# .cpio.*, use it directly as an initramfs, and avoid double compression. 3862306a36Sopenharmony_ciifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2) 3962306a36Sopenharmony_cicpio-data := $(ramfs-input) 4062306a36Sopenharmony_cicompress-y := copy 4162306a36Sopenharmony_ciendif 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciendif 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci# For other cases, generate the initramfs cpio archive based on the contents 4662306a36Sopenharmony_ci# specified by CONFIG_INITRAMFS_SOURCE. 4762306a36Sopenharmony_ciifeq ($(cpio-data),) 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_cicpio-data := $(obj)/initramfs_data.cpio 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_cihostprogs := gen_init_cpio 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci# .initramfs_data.cpio.d is used to identify all files included 5462306a36Sopenharmony_ci# in initramfs and to detect if any files are added/removed. 5562306a36Sopenharmony_ci# Removed files are identified by directory timestamp being updated 5662306a36Sopenharmony_ci# The dependency list is generated by gen_initramfs.sh -l 5762306a36Sopenharmony_ci-include $(obj)/.initramfs_data.cpio.d 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci# do not try to update files included in initramfs 6062306a36Sopenharmony_ci$(deps_initramfs): ; 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciquiet_cmd_initfs = GEN $@ 6362306a36Sopenharmony_ci cmd_initfs = \ 6462306a36Sopenharmony_ci $(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \ 6562306a36Sopenharmony_ci $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \ 6662306a36Sopenharmony_ci $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \ 6762306a36Sopenharmony_ci $(if $(KBUILD_BUILD_TIMESTAMP), -d "$(KBUILD_BUILD_TIMESTAMP)") \ 6862306a36Sopenharmony_ci $(ramfs-input) 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci# We rebuild initramfs_data.cpio if: 7162306a36Sopenharmony_ci# 1) Any included file is newer than initramfs_data.cpio 7262306a36Sopenharmony_ci# 2) There are changes in which files are included (added or deleted) 7362306a36Sopenharmony_ci# 3) If gen_init_cpio are newer than initramfs_data.cpio 7462306a36Sopenharmony_ci# 4) Arguments to gen_initramfs.sh changes 7562306a36Sopenharmony_ci$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE 7662306a36Sopenharmony_ci $(call if_changed,initfs) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciendif 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci$(obj)/initramfs_inc_data: $(cpio-data) FORCE 8162306a36Sopenharmony_ci $(call if_changed,$(compress-y)) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_citargets += initramfs_data.cpio initramfs_inc_data 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cisubdir-$(CONFIG_UAPI_HEADER_TEST) += include 86