image.mk 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 -v
  18. else
  19. JFFS2OPTS := --pad --little-endian --squash -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. SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS)
  48. endif
  49. JFFS2_BLOCKSIZE ?= 64k 128k
  50. define add_jffs2_mark
  51. echo -ne '\xde\xad\xc0\xde' >> $(1)
  52. endef
  53. # pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
  54. define prepare_generic_squashfs
  55. $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
  56. endef
  57. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  58. define Image/BuildKernel
  59. cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux.elf
  60. $(call Image/Build/Initramfs)
  61. endef
  62. else
  63. ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
  64. define Image/mkfs/jffs2/sub
  65. # FIXME: removing this line will cause strange behaviour in the foreach loop below
  66. $(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 '/^.+$$$$/'
  67. $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
  68. $(call Image/Build,jffs2-$(1))
  69. endef
  70. define Image/mkfs/jffs2
  71. $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
  72. endef
  73. endif
  74. ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
  75. define Image/mkfs/squashfs
  76. @mkdir -p $(TARGET_DIR)/overlay
  77. $(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)
  78. $(call Image/Build,squashfs)
  79. endef
  80. endif
  81. ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
  82. define Image/mkfs/ubifs
  83. $(CP) ./ubinize.cfg $(KDIR)
  84. $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(UBIFS_OPTS) -o $(KDIR)/root.ubifs -d $(TARGET_DIR)
  85. (cd $(KDIR); \
  86. $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
  87. $(call Image/Build,ubi)
  88. endef
  89. endif
  90. endif
  91. ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
  92. define Image/mkfs/cpiogz
  93. ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
  94. endef
  95. endif
  96. ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
  97. define Image/mkfs/targz
  98. # Preserve permissions (-p) when building as non-root user
  99. $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
  100. endef
  101. endif
  102. ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
  103. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
  104. define Image/mkfs/ext4
  105. # generate an ext2 fs
  106. $(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -N $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4
  107. # convert it to ext4
  108. $(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
  109. # fix it up
  110. $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
  111. $(call Image/Build,ext4)
  112. endef
  113. endif
  114. ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
  115. define Image/mkfs/iso
  116. $(call Image/Build,iso)
  117. endef
  118. endif
  119. define Image/mkfs/prepare/default
  120. # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
  121. - $(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
  122. - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
  123. - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
  124. $(INSTALL_DIR) $(TARGET_DIR)/tmp
  125. chmod 1777 $(TARGET_DIR)/tmp
  126. endef
  127. define Image/mkfs/prepare
  128. $(call Image/mkfs/prepare/default)
  129. endef
  130. define Image/Checksum
  131. ( cd ${BIN_DIR} ; \
  132. $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
  133. md5sum --binary > md5sums \
  134. )
  135. endef
  136. define BuildImage
  137. download:
  138. prepare:
  139. ifeq ($(IB),)
  140. compile: compile-targets FORCE
  141. $(call Build/Compile)
  142. else
  143. compile:
  144. endif
  145. ifeq ($(IB),)
  146. install: compile install-targets FORCE
  147. $(call Image/Prepare)
  148. $(call Image/mkfs/prepare)
  149. $(call Image/BuildKernel)
  150. $(call Image/mkfs/cpiogz)
  151. $(call Image/mkfs/targz)
  152. $(call Image/mkfs/ext4)
  153. $(call Image/mkfs/iso)
  154. $(call Image/mkfs/jffs2)
  155. $(call Image/mkfs/squashfs)
  156. $(call Image/mkfs/ubifs)
  157. $(call Image/Checksum)
  158. else
  159. install: compile install-targets
  160. $(call Image/BuildKernel)
  161. $(call Image/mkfs/cpiogz)
  162. $(call Image/mkfs/targz)
  163. $(call Image/mkfs/ext4)
  164. $(call Image/mkfs/iso)
  165. $(call Image/mkfs/jffs2)
  166. $(call Image/mkfs/squashfs)
  167. $(call Image/mkfs/ubifs)
  168. $(call Image/Checksum)
  169. endif
  170. ifeq ($(IB),)
  171. clean: clean-targets
  172. $(call Build/Clean)
  173. else
  174. clean:
  175. endif
  176. compile-targets:
  177. install-targets:
  178. clean-targets:
  179. endef