Makefile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # clean rules do not have CONFIG_INITRAMFS_COMPRESSION. So clean up after all
  12. # possible compression formats.
  13. clean-files += initramfs_data.cpio*
  14. # Generate builtin.o based on initramfs_data.o
  15. obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
  16. # initramfs_data.o contains the compressed initramfs_data.cpio image.
  17. # The image is included using .incbin, a dependency which is not
  18. # tracked automatically.
  19. $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
  20. #####
  21. # Generate the initramfs cpio archive
  22. hostprogs-y := gen_init_cpio
  23. initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
  24. ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
  25. $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
  26. ramfs-args := \
  27. $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
  28. $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
  29. # $(datafile_d_y) is used to identify all files included
  30. # in initramfs and to detect if any files are added/removed.
  31. # Removed files are identified by directory timestamp being updated
  32. # The dependency list is generated by gen_initramfs.sh -l
  33. ifneq ($(wildcard $(obj)/$(datafile_d_y)),)
  34. include $(obj)/$(datafile_d_y)
  35. endif
  36. quiet_cmd_initfs = GEN $@
  37. cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
  38. targets := $(datafile_y)
  39. # do not try to update files included in initramfs
  40. $(deps_initramfs): ;
  41. $(deps_initramfs): klibcdirs
  42. # We rebuild initramfs_data.cpio if:
  43. # 1) Any included file is newer then initramfs_data.cpio
  44. # 2) There are changes in which files are included (added or deleted)
  45. # 3) If gen_init_cpio are newer than initramfs_data.cpio
  46. # 4) arguments to gen_initramfs.sh changes
  47. $(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
  48. $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
  49. $(call if_changed,initfs)