Makefile 2.9 KB

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