Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # kbuild file for usr/ - including initramfs image
0004 #
0005 
0006 compress-y                                      := copy
0007 compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP)   := gzip
0008 compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2)  := bzip2
0009 compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA)   := lzma
0010 compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ)     := xzmisc
0011 compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO)    := lzo
0012 compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4)    := lz4
0013 compress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD)   := zstd
0014 
0015 obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
0016 
0017 $(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
0018 
0019 ramfs-input := $(CONFIG_INITRAMFS_SOURCE)
0020 cpio-data :=
0021 
0022 # If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
0023 # default contents.
0024 ifeq ($(ramfs-input),)
0025 ramfs-input := $(srctree)/$(src)/default_cpio_list
0026 endif
0027 
0028 ifeq ($(words $(ramfs-input)),1)
0029 
0030 # If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
0031 # .cpio, use it directly as an initramfs.
0032 ifneq ($(filter %.cpio,$(ramfs-input)),)
0033 cpio-data := $(ramfs-input)
0034 endif
0035 
0036 # If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
0037 # .cpio.*, use it directly as an initramfs, and avoid double compression.
0038 ifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
0039 cpio-data := $(ramfs-input)
0040 compress-y := copy
0041 endif
0042 
0043 endif
0044 
0045 # For other cases, generate the initramfs cpio archive based on the contents
0046 # specified by CONFIG_INITRAMFS_SOURCE.
0047 ifeq ($(cpio-data),)
0048 
0049 cpio-data := $(obj)/initramfs_data.cpio
0050 
0051 hostprogs := gen_init_cpio
0052 
0053 # .initramfs_data.cpio.d is used to identify all files included
0054 # in initramfs and to detect if any files are added/removed.
0055 # Removed files are identified by directory timestamp being updated
0056 # The dependency list is generated by gen_initramfs.sh -l
0057 -include $(obj)/.initramfs_data.cpio.d
0058 
0059 # do not try to update files included in initramfs
0060 $(deps_initramfs): ;
0061 
0062 quiet_cmd_initfs = GEN     $@
0063       cmd_initfs = \
0064         $(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
0065         $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
0066         $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
0067         $(ramfs-input)
0068 
0069 # We rebuild initramfs_data.cpio if:
0070 # 1) Any included file is newer than initramfs_data.cpio
0071 # 2) There are changes in which files are included (added or deleted)
0072 # 3) If gen_init_cpio are newer than initramfs_data.cpio
0073 # 4) Arguments to gen_initramfs.sh changes
0074 $(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
0075         $(call if_changed,initfs)
0076 
0077 endif
0078 
0079 $(obj)/initramfs_inc_data: $(cpio-data) FORCE
0080         $(call if_changed,$(compress-y))
0081 
0082 targets += initramfs_data.cpio initramfs_inc_data
0083 
0084 subdir-$(CONFIG_UAPI_HEADER_TEST) += include