kernel-build.mk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. include $(ADK_TOPDIR)/rules.mk
  4. include $(ADK_TOPDIR)/mk/$(ADK_TARGET_OS)-ver.mk
  5. include $(ADK_TOPDIR)/mk/$(ADK_TARGET_OS).mk
  6. include $(ADK_TOPDIR)/mk/kernel-vars.mk
  7. ifeq ($(ADK_TARGET_OS_LINUX),y)
  8. KERNEL_MODULES_USED:=$(shell grep ^ADK_LINUX_KERNEL $(ADK_TOPDIR)/.config|grep =m)
  9. endif
  10. ifeq ($(ADK_TARGET_LINUX_KERNEL_USE_CUSTOMCONFIG),y)
  11. KERNEL_MODULES_USED:=$(shell grep -s =m $(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH))
  12. endif
  13. KERNEL_FILE:=$(ADK_TARGET_KERNEL)
  14. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  15. ifeq ($(ADK_TARGET_KERNEL_LINUXBIN),y)
  16. KERNEL_FILE:=vmlinux
  17. endif
  18. ifeq ($(ADK_TARGET_KERNEL_ZIMAGE),y)
  19. KERNEL_FILE:=vmlinux
  20. endif
  21. ifeq ($(ADK_TARGET_KERNEL_VMLINUX_EFI),y)
  22. KERNEL_FILE:=vmlinux.efi
  23. KERNEL_TARGET:=all
  24. endif
  25. ifeq ($(ADK_TARGET_KERNEL_VMLINUX_GZ),y)
  26. KERNEL_FILE:=vmlinux
  27. KERNEL_TARGET:=all
  28. endif
  29. ifeq ($(ADK_TARGET_KERNEL_BZIMAGE),y)
  30. KERNEL_FILE:=vmlinux
  31. KERNEL_TARGET:=all
  32. endif
  33. ifeq ($(ADK_TARGET_KERNEL_IMAGE),y)
  34. KERNEL_FILE:=vmlinux
  35. endif
  36. ifeq ($(ADK_TARGET_KERNEL_SIMPLEIMAGE),y)
  37. KERNEL_FILE:=vmlinux.bin
  38. KERNEL_TARGET:=simpleImage.milkymist_one
  39. endif
  40. ifneq ($(KERNEL_MODULES_USED),)
  41. KERNEL_TARGET+=modules
  42. endif
  43. ifeq ($(ADK_RUNTIME_DEV_UDEV),y)
  44. ADK_DEPMOD:=$(STAGING_HOST_DIR)/usr/bin/depmod
  45. else
  46. ADK_DEPMOD:=true
  47. endif
  48. $(LINUX_DIR)/.prepared: $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/$(ADK_TARGET_OS)-$(KERNEL_FILE_VER)/.patched
  49. ln -sf $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/$(ADK_TARGET_OS)-$(KERNEL_FILE_VER) $(LINUX_DIR)
  50. mkdir -p $(LINUX_BUILD_DIR)/kmod-control
  51. touch $@
  52. ifeq ($(ADK_TARGET_LINUX_KERNEL_USE_MINICONFIG),y)
  53. $(LINUX_DIR)/.config: $(BUILD_DIR)/.kernelconfig
  54. endif
  55. ifeq ($(ADK_TARGET_LINUX_KERNEL_USE_CUSTOMCONFIG),y)
  56. $(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH):
  57. $(LINUX_DIR)/.config: $(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH)
  58. endif
  59. $(LINUX_DIR)/.config: $(LINUX_DIR)/.prepared
  60. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-configure.. "
  61. echo "-${KERNEL_RELEASE}" >${LINUX_DIR}/localversion
  62. ifeq ($(ADK_TARGET_LINUX_KERNEL_USE_DEFCONFIG),y)
  63. ${KERNEL_MAKE} $(ADK_TARGET_LINUX_KERNEL_DEFCONFIG) $(MAKE_TRACE)
  64. else ifeq ($(ADK_TARGET_LINUX_KERNEL_USE_CUSTOMCONFIG),y)
  65. @if [ ! -f $(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH) ];then \
  66. echo "no kernel configuration found in $(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH)"; \
  67. exit 1; \
  68. fi
  69. ${KERNEL_MAKE} KCONFIG_ALLCONFIG=$(ADK_TOPDIR)/$(ADK_TARGET_LINUX_KERNEL_CUSTOMCONFIG_PATH) allnoconfig $(MAKE_TRACE)
  70. else
  71. $(CP) $(BUILD_DIR)/.kernelconfig $(LINUX_DIR)/mini.config
  72. ${KERNEL_MAKE} KCONFIG_ALLCONFIG=mini.config allnoconfig $(MAKE_TRACE)
  73. endif
  74. $(CMD_TRACE) " done"
  75. $(END_TRACE)
  76. $(LINUX_DIR)/$(KERNEL_FILE): $(LINUX_DIR)/.config
  77. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-compile.. "
  78. ifneq ($(ADK_TARGET_KERNEL_APPEND_DTB),)
  79. ${KERNEL_MAKE} zImage dtbs $(MAKE_TRACE)
  80. (cd $(LINUX_DIR)/arch/$(ADK_TARGET_ARCH)/boot && \
  81. cat dts/${ADK_TARGET_KERNEL_APPEND_DTB}.dtb >> zImage)
  82. endif
  83. ${KERNEL_MAKE} $(KERNEL_TARGET) $(MAKE_TRACE)
  84. $(CMD_TRACE) " done"
  85. $(END_TRACE)
  86. prepare:
  87. compile: $(LINUX_DIR)/$(KERNEL_FILE)
  88. install:
  89. ifneq ($(KERNEL_MODULES_USED),)
  90. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-install.. "
  91. rm -rf $(LINUX_BUILD_DIR)/modules
  92. ${KERNEL_MAKE} DEPMOD=$(ADK_DEPMOD) \
  93. INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules \
  94. modules_install $(MAKE_TRACE)
  95. $(CMD_TRACE) " done"
  96. $(END_TRACE)
  97. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-create-packages.. "
  98. rm -f ${PACKAGE_DIR}/kmod-*
  99. PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/make-module-ipkgs.sh \
  100. "${ADK_TARGET_CPU_ARCH}" \
  101. "${KERNEL_VERSION}" \
  102. "${LINUX_BUILD_DIR}" \
  103. "${PKG_BUILD}" \
  104. "${PACKAGE_DIR}"
  105. $(CMD_TRACE) " done"
  106. $(END_TRACE)
  107. $(START_TRACE) "target/${ADK_TARGET_ARCH}-kernel-modules-install-packages.. "
  108. -for pkg in $(PACKAGE_DIR)/kmod-*; do \
  109. [[ -e "$$pkg" ]] && $(PKG_INSTALL) $$pkg; \
  110. done
  111. $(CMD_TRACE) " done"
  112. $(END_TRACE)
  113. $(CP) $(LINUX_BUILD_DIR)/modules/lib/modules/$(KERNEL_VERSION)/modules.{order,builtin} \
  114. $(TARGET_DIR)/lib/modules/$(KERNEL_VERSION)/
  115. endif
  116. clean:
  117. rm -rf $(LINUX_BUILD_DIR)
  118. rm -f $(wildcard ${PACKAGE_DIR}/kmod-*) $(wildcard ${PACKAGE_DIR}/kernel_*)