Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # kbuild file for usr/ - including initramfs image
  4. #
  5. compress-y := copy
  6. compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip
  7. compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2
  8. compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma
  9. compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc
  10. compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo
  11. compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4
  12. compress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD) := zstd
  13. obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
  14. $(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
  15. ramfs-input := $(CONFIG_INITRAMFS_SOURCE)
  16. cpio-data :=
  17. # If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
  18. # default contents.
  19. ifeq ($(ramfs-input),)
  20. ramfs-input := $(srctree)/$(src)/default_cpio_list
  21. endif
  22. ifeq ($(words $(ramfs-input)),1)
  23. # If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
  24. # .cpio, use it directly as an initramfs.
  25. ifneq ($(filter %.cpio,$(ramfs-input)),)
  26. cpio-data := $(ramfs-input)
  27. endif
  28. # If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with
  29. # .cpio.*, use it directly as an initramfs, and avoid double compression.
  30. ifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
  31. cpio-data := $(ramfs-input)
  32. compress-y := copy
  33. endif
  34. endif
  35. # For other cases, generate the initramfs cpio archive based on the contents
  36. # specified by CONFIG_INITRAMFS_SOURCE.
  37. ifeq ($(cpio-data),)
  38. cpio-data := $(obj)/initramfs_data.cpio
  39. hostprogs := gen_init_cpio
  40. # .initramfs_data.cpio.d is used to identify all files included
  41. # in initramfs and to detect if any files are added/removed.
  42. # Removed files are identified by directory timestamp being updated
  43. # The dependency list is generated by gen_initramfs.sh -l
  44. -include $(obj)/.initramfs_data.cpio.d
  45. # do not try to update files included in initramfs
  46. $(deps_initramfs): ;
  47. quiet_cmd_initfs = GEN $@
  48. cmd_initfs = \
  49. $(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
  50. $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
  51. $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
  52. $(ramfs-input)
  53. # We rebuild initramfs_data.cpio if:
  54. # 1) Any included file is newer than initramfs_data.cpio
  55. # 2) There are changes in which files are included (added or deleted)
  56. # 3) If gen_init_cpio are newer than initramfs_data.cpio
  57. # 4) Arguments to gen_initramfs.sh changes
  58. $(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
  59. $(call if_changed,initfs)
  60. endif
  61. $(obj)/initramfs_inc_data: $(cpio-data) FORCE
  62. $(call if_changed,$(compress-y))
  63. targets += initramfs_data.cpio initramfs_inc_data
  64. subdir-$(CONFIG_UAPI_HEADER_TEST) += include