image.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #
  2. # Copyright (C) 2006-2010 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. override TARGET_BUILD=
  8. include $(INCLUDE_DIR)/prereq.mk
  9. include $(INCLUDE_DIR)/kernel.mk
  10. include $(INCLUDE_DIR)/host.mk
  11. .NOTPARALLEL:
  12. override MAKEFLAGS=
  13. override MAKE:=$(SUBMAKE)
  14. KDIR=$(KERNEL_BUILD_DIR)
  15. IMG_PREFIX:=openwrt-$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
  16. ifneq ($(CONFIG_BIG_ENDIAN),)
  17. JFFS2OPTS := --pad --big-endian --squash-uids -v
  18. else
  19. JFFS2OPTS := --pad --little-endian --squash-uids -v
  20. endif
  21. ifeq ($(CONFIG_JFFS2_RTIME),y)
  22. JFFS2OPTS += -X rtime
  23. endif
  24. ifeq ($(CONFIG_JFFS2_ZLIB),y)
  25. JFFS2OPTS += -X zlib
  26. endif
  27. ifeq ($(CONFIG_JFFS2_LZMA),y)
  28. JFFS2OPTS += -X lzma --compression-mode=size
  29. endif
  30. ifneq ($(CONFIG_JFFS2_RTIME),y)
  31. JFFS2OPTS += -x rtime
  32. endif
  33. ifneq ($(CONFIG_JFFS2_ZLIB),y)
  34. JFFS2OPTS += -x zlib
  35. endif
  36. ifneq ($(CONFIG_JFFS2_LZMA),y)
  37. JFFS2OPTS += -x lzma
  38. endif
  39. SQUASHFS_BLOCKSIZE := 256k
  40. SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
  41. SQUASHFSCOMP := gzip
  42. LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
  43. ifeq ($(CONFIG_SQUASHFS_LZMA),y)
  44. SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
  45. endif
  46. ifeq ($(CONFIG_SQUASHFS_XZ),y)
  47. ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
  48. BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
  49. endif
  50. SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
  51. endif
  52. JFFS2_BLOCKSIZE ?= 64k 128k
  53. define add_jffs2_mark
  54. echo -ne '\xde\xad\xc0\xde' >> $(1)
  55. endef
  56. # pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
  57. define prepare_generic_squashfs
  58. $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
  59. endef
  60. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  61. define Image/BuildKernel
  62. cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux.elf
  63. $(call Image/Build/Initramfs)
  64. endef
  65. else
  66. ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
  67. define Image/mkfs/jffs2/sub
  68. # FIXME: removing this line will cause strange behaviour in the foreach loop below
  69. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(JFFS2OPTS) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(1) -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
  70. $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
  71. $(call Image/Build,jffs2-$(1))
  72. endef
  73. define Image/mkfs/jffs2
  74. $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
  75. endef
  76. endif
  77. ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
  78. define Image/mkfs/squashfs
  79. @mkdir -p $(TARGET_DIR)/overlay
  80. $(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1)
  81. $(call Image/Build,squashfs)
  82. endef
  83. endif
  84. ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
  85. define Image/mkfs/ubifs
  86. $(CP) ./ubinize.cfg $(KDIR)
  87. $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(UBIFS_OPTS) -o $(KDIR)/root.ubifs -d $(TARGET_DIR)
  88. $(call Image/Build,ubifs)
  89. (cd $(KDIR); \
  90. $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
  91. $(call Image/Build,ubi)
  92. endef
  93. endif
  94. endif
  95. ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
  96. define Image/mkfs/cpiogz
  97. ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
  98. endef
  99. endif
  100. ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
  101. define Image/mkfs/targz
  102. # Preserve permissions (-p) when building as non-root user
  103. $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
  104. endef
  105. endif
  106. ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
  107. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
  108. define Image/mkfs/ext4
  109. # generate an ext2 fs
  110. $(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -N $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4 -m $(CONFIG_TARGET_ROOTFS_RESERVED_PCT)
  111. # convert it to ext4
  112. $(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
  113. # fix it up
  114. $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
  115. $(call Image/Build,ext4)
  116. endef
  117. endif
  118. ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
  119. define Image/mkfs/iso
  120. $(call Image/Build,iso)
  121. endef
  122. endif
  123. define Image/mkfs/prepare/default
  124. # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
  125. - $(FIND) $(TARGET_DIR) -type f -not -perm +0100 -not -name 'ssh_host*' -not -name 'shadow' -print0 | $(XARGS) -0 chmod u+rw,g+r,o+r
  126. - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
  127. - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
  128. $(INSTALL_DIR) $(TARGET_DIR)/tmp
  129. chmod 1777 $(TARGET_DIR)/tmp
  130. endef
  131. define Image/mkfs/prepare
  132. $(call Image/mkfs/prepare/default)
  133. endef
  134. define Image/Checksum
  135. ( cd ${BIN_DIR} ; \
  136. $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
  137. md5sum --binary > md5sums \
  138. )
  139. endef
  140. define BuildImage
  141. download:
  142. prepare:
  143. ifeq ($(IB),)
  144. compile: compile-targets FORCE
  145. $(call Build/Compile)
  146. else
  147. compile:
  148. endif
  149. ifeq ($(IB),)
  150. install: compile install-targets FORCE
  151. $(call Image/Prepare)
  152. $(call Image/mkfs/prepare)
  153. $(call Image/BuildKernel)
  154. $(call Image/mkfs/cpiogz)
  155. $(call Image/mkfs/targz)
  156. $(call Image/mkfs/ext4)
  157. $(call Image/mkfs/iso)
  158. $(call Image/mkfs/jffs2)
  159. $(call Image/mkfs/squashfs)
  160. $(call Image/mkfs/ubifs)
  161. $(call Image/Checksum)
  162. else
  163. install: compile install-targets
  164. $(call Image/BuildKernel)
  165. $(call Image/mkfs/cpiogz)
  166. $(call Image/mkfs/targz)
  167. $(call Image/mkfs/ext4)
  168. $(call Image/mkfs/iso)
  169. $(call Image/mkfs/jffs2)
  170. $(call Image/mkfs/squashfs)
  171. $(call Image/mkfs/ubifs)
  172. $(call Image/Checksum)
  173. endif
  174. ifeq ($(IB),)
  175. clean: clean-targets
  176. $(call Build/Clean)
  177. else
  178. clean:
  179. endif
  180. compile-targets:
  181. install-targets:
  182. clean-targets:
  183. endef