2 # Copyright (C) 2006-2010 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
9 include $(INCLUDE_DIR)/prereq.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/host.mk
15 override MAKE:=$(SUBMAKE)
16 KDIR=$(KERNEL_BUILD_DIR)
18 IMG_PREFIX:=openwrt-$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
20 ifneq ($(CONFIG_BIG_ENDIAN),)
21 JFFS2OPTS := --pad --big-endian --squash-uids -v
23 JFFS2OPTS := --pad --little-endian --squash-uids -v
26 ifeq ($(CONFIG_JFFS2_RTIME),y)
29 ifeq ($(CONFIG_JFFS2_ZLIB),y)
32 ifeq ($(CONFIG_JFFS2_LZMA),y)
33 JFFS2OPTS += -X lzma --compression-mode=size
35 ifneq ($(CONFIG_JFFS2_RTIME),y)
38 ifneq ($(CONFIG_JFFS2_ZLIB),y)
41 ifneq ($(CONFIG_JFFS2_LZMA),y)
45 SQUASHFS_BLOCKSIZE := 256k
46 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
48 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
49 ifeq ($(CONFIG_SQUASHFS_LZMA),y)
50 SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
52 ifeq ($(CONFIG_SQUASHFS_XZ),y)
53 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
54 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
56 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
59 JFFS2_BLOCKSIZE ?= 64k 128k
62 echo -ne '\xde\xad\xc0\xde' >> $(1)
65 # pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
66 define prepare_generic_squashfs
67 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
71 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
73 define Image/BuildKernel
74 cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux.elf
75 $(call Image/Build/Initramfs)
80 ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
81 define Image/mkfs/jffs2/sub
82 # FIXME: removing this line will cause strange behaviour in the foreach loop below
83 $(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 '/^.+$$$$/'
84 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
85 $(call Image/Build,jffs2-$(1))
87 define Image/mkfs/jffs2
88 $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
92 ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
93 define Image/mkfs/squashfs
94 @mkdir -p $(TARGET_DIR)/overlay
95 $(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)
96 $(call Image/Build,squashfs)
100 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
101 define Image/mkfs/ubifs
102 $(CP) ./ubinize.cfg $(KDIR)
103 $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(UBIFS_OPTS) -o $(KDIR)/root.ubifs -d $(TARGET_DIR)
104 $(call Image/Build,ubifs)
106 $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
107 $(call Image/Build,ubi)
113 ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
114 define Image/mkfs/cpiogz
115 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
119 ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
120 define Image/mkfs/targz
121 # Preserve permissions (-p) when building as non-root user
122 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
126 ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
127 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
129 define Image/mkfs/ext4
130 # generate an ext2 fs
131 $(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)
133 $(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
135 $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
136 $(call Image/Build,ext4)
140 ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
141 define Image/mkfs/iso
142 $(call Image/Build,iso)
147 define Image/mkfs/prepare/default
148 # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
149 - $(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
150 - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
151 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
152 $(INSTALL_DIR) $(TARGET_DIR)/tmp
153 chmod 1777 $(TARGET_DIR)/tmp
156 define Image/mkfs/prepare
157 $(call Image/mkfs/prepare/default)
161 define Image/Checksum
163 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
164 md5sum --binary > md5sums \
175 compile: compile-targets FORCE
176 $(call Build/Compile)
182 install: compile install-targets FORCE
183 $(call Image/Prepare)
184 $(call Image/mkfs/prepare)
185 $(call Image/BuildKernel)
186 $(call Image/mkfs/cpiogz)
187 $(call Image/mkfs/targz)
188 $(call Image/mkfs/ext4)
189 $(call Image/mkfs/iso)
190 $(call Image/mkfs/jffs2)
191 $(call Image/mkfs/squashfs)
192 $(call Image/mkfs/ubifs)
193 $(call Image/Checksum)
195 install: compile install-targets
196 $(call Image/BuildKernel)
197 $(call Image/mkfs/cpiogz)
198 $(call Image/mkfs/targz)
199 $(call Image/mkfs/ext4)
200 $(call Image/mkfs/iso)
201 $(call Image/mkfs/jffs2)
202 $(call Image/mkfs/squashfs)
203 $(call Image/mkfs/ubifs)
204 $(call Image/Checksum)