Makefile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # kbuild file for usr/ - including initramfs image
  4. #
  5. klibcdirs:;
  6. PHONY += klibcdirs
  7. suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION))
  8. datafile_y = initramfs_data.cpio$(suffix_y)
  9. datafile_d_y = .$(datafile_y).d
  10. AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)"
  11. # Generate builtin.o based on initramfs_data.o
  12. obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
  13. # initramfs_data.o contains the compressed initramfs_data.cpio image.
  14. # The image is included using .incbin, a dependency which is not
  15. # tracked automatically.
  16. $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
  17. #####
  18. # Generate the initramfs cpio archive
  19. hostprogs-y := gen_init_cpio
  20. initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh
  21. ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
  22. $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
  23. ramfs-args := \
  24. $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
  25. $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
  26. # $(datafile_d_y) is used to identify all files included
  27. # in initramfs and to detect if any files are added/removed.
  28. # Removed files are identified by directory timestamp being updated
  29. # The dependency list is generated by gen_initramfs.sh -l
  30. ifneq ($(wildcard $(obj)/$(datafile_d_y)),)
  31. include $(obj)/$(datafile_d_y)
  32. endif
  33. quiet_cmd_initfs = GEN $@
  34. cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
  35. targets := $(datafile_y)
  36. # do not try to update files included in initramfs
  37. $(deps_initramfs): ;
  38. $(deps_initramfs): klibcdirs
  39. # We rebuild initramfs_data.cpio if:
  40. # 1) Any included file is newer then initramfs_data.cpio
  41. # 2) There are changes in which files are included (added or deleted)
  42. # 3) If gen_init_cpio are newer than initramfs_data.cpio
  43. # 4) arguments to gen_initramfs.sh changes
  44. $(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
  45. $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
  46. $(call if_changed,initfs)