image.mk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #
  2. # Copyright (C) 2006 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(INCLUDE_DIR)/prereq.mk
  8. include $(INCLUDE_DIR)/kernel.mk
  9. include $(INCLUDE_DIR)/host.mk
  10. KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
  11. ifneq ($(CONFIG_BIG_ENDIAN),y)
  12. JFFS2OPTS := --pad --little-endian --squash
  13. SQUASHFS_OPTS := -le
  14. else
  15. JFFS2OPTS := --pad --big-endian --squash
  16. SQUASHFS_OPTS := -be
  17. endif
  18. JFFS2_BLOCKSIZE ?= 64k 128k
  19. define add_jffs2_mark
  20. echo -ne '\xde\xad\xc0\xde' >> $(1)
  21. endef
  22. # pad to 64k and add jffs2 end-of-filesystem mark
  23. # do this twice to make sure that this works with 128k blocksize as well
  24. define prepare_generic_squashfs
  25. dd if=$(1) of=$(KDIR)/tmpfile.1 bs=64k conv=sync
  26. $(call add_jffs2_mark,$(KDIR)/tmpfile.1)
  27. dd of=$(1) if=$(KDIR)/tmpfile.1 bs=64k conv=sync
  28. $(call add_jffs2_mark,$(1))
  29. endef
  30. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  31. ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y)
  32. define Image/mkfs/jffs2/sub
  33. @# FIXME: removing this line will cause the foreach loop below to execute the next statement only on the first iteration, don't ask why ;)
  34. $(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(1) -d $(BUILD_DIR)/root
  35. $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
  36. $(call Image/Build,jffs2-$(1))
  37. endef
  38. define Image/mkfs/jffs2
  39. rm -rf $(BUILD_DIR)/root/jffs
  40. $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
  41. endef
  42. endif
  43. ifeq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),y)
  44. define Image/mkfs/squashfs
  45. @mkdir -p $(BUILD_DIR)/root/jffs
  46. $(STAGING_DIR)/bin/mksquashfs-lzma $(BUILD_DIR)/root $(KDIR)/root.squashfs -nopad -noappend -root-owned $(SQUASHFS_OPTS)
  47. $(call Image/Build,squashfs)
  48. endef
  49. endif
  50. ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y)
  51. define Image/mkfs/tgz
  52. $(TAR) -zcf $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-rootfs.tgz --owner=root --group=root -C $(BUILD_DIR)/root/ .
  53. endef
  54. endif
  55. else
  56. define Image/BuildKernel
  57. cp $(KDIR)/vmlinux.elf $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-vmlinux.elf
  58. $(call Image/Build/Initramfs)
  59. endef
  60. endif
  61. ifeq ($(CONFIG_TARGET_ROOTFS_EXT2FS),y)
  62. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_FSPART)*1024)))
  63. define Image/mkfs/ext2
  64. $(STAGING_DIR)/bin/genext2fs -U -b $(E2SIZE) -I $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(BUILD_DIR)/root/ $(KDIR)/root.ext2
  65. $(call Image/Build,ext2)
  66. endef
  67. endif
  68. define Image/mkfs/prepare/default
  69. find $(BUILD_DIR)/root -type f -not -perm +0100 -not -name 'ssh_host*' | $(XARGS) chmod 0644
  70. find $(BUILD_DIR)/root -type f -perm +0100 | $(XARGS) chmod 0755
  71. find $(BUILD_DIR)/root -type d | $(XARGS) chmod 0755
  72. mkdir -p $(BUILD_DIR)/root/tmp
  73. chmod 0777 $(BUILD_DIR)/root/tmp
  74. endef
  75. define Image/mkfs/prepare
  76. $(call Image/mkfs/prepare/default)
  77. endef
  78. define BuildImage
  79. download:
  80. prepare:
  81. ifneq ($(IB),1)
  82. compile: compile-targets
  83. $(call Build/Compile)
  84. else
  85. compile:
  86. endif
  87. ifneq ($(IB),1)
  88. install: compile install-targets
  89. $(call Image/Prepare)
  90. $(call Image/mkfs/prepare)
  91. $(call Image/BuildKernel)
  92. $(call Image/mkfs/jffs2)
  93. $(call Image/mkfs/squashfs)
  94. $(call Image/mkfs/tgz)
  95. $(call Image/mkfs/ext2)
  96. else
  97. install: compile install-targets
  98. $(call Image/BuildKernel)
  99. $(call Image/mkfs/jffs2)
  100. $(call Image/mkfs/squashfs)
  101. $(call Image/mkfs/tgz)
  102. $(call Image/mkfs/ext2)
  103. endif
  104. ifneq ($(IB),1)
  105. clean: clean-targets
  106. $(call Build/Clean)
  107. else
  108. clean:
  109. endif
  110. compile-targets:
  111. install-targets:
  112. clean-targets:
  113. endef