Incorrect checkout of git submodules
[openwrt/openwrt.git] / include / image.mk
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
8 override TARGET_BUILD=
9 include $(INCLUDE_DIR)/prereq.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/host.mk
12
13 .NOTPARALLEL:
14 override MAKEFLAGS=
15 override MAKE:=$(SUBMAKE)
16 KDIR=$(KERNEL_BUILD_DIR)
17
18 IMG_PREFIX:=openwrt-$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
19
20 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
21
22 ifneq ($(CONFIG_BIG_ENDIAN),)
23 JFFS2OPTS := --big-endian --squash-uids -v
24 else
25 JFFS2OPTS := --little-endian --squash-uids -v
26 endif
27
28 ifeq ($(CONFIG_JFFS2_RTIME),y)
29 JFFS2OPTS += -X rtime
30 endif
31 ifeq ($(CONFIG_JFFS2_ZLIB),y)
32 JFFS2OPTS += -X zlib
33 endif
34 ifeq ($(CONFIG_JFFS2_LZMA),y)
35 JFFS2OPTS += -X lzma --compression-mode=size
36 endif
37 ifneq ($(CONFIG_JFFS2_RTIME),y)
38 JFFS2OPTS += -x rtime
39 endif
40 ifneq ($(CONFIG_JFFS2_ZLIB),y)
41 JFFS2OPTS += -x zlib
42 endif
43 ifneq ($(CONFIG_JFFS2_LZMA),y)
44 JFFS2OPTS += -x lzma
45 endif
46
47 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
48
49 SQUASHFS_BLOCKSIZE := 256k
50 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
51 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
52 SQUASHFSCOMP := gzip
53 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
54 ifeq ($(CONFIG_SQUASHFS_LZMA),y)
55 SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
56 endif
57 ifeq ($(CONFIG_SQUASHFS_XZ),y)
58 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
59 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
60 endif
61 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
62 endif
63
64 JFFS2_BLOCKSIZE ?= 64k 128k
65
66 define add_jffs2_mark
67 echo -ne '\xde\xad\xc0\xde' >> $(1)
68 endef
69
70 # pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
71 define prepare_generic_squashfs
72 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
73 endef
74
75 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
76 define Image/BuildKernel/Initramfs
77 cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux-initramfs.elf
78 $(call Image/Build/Initramfs)
79 endef
80 else
81 define Image/BuildKernel/Initramfs
82 endef
83 endif
84
85 define Image/mkfs/jffs2/sub
86 # FIXME: removing this line will cause strange behaviour in the foreach loop below
87 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) --pad -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2) -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
88 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2)-raw -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
89 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2))
90 $(call Image/Build,jffs2-$(2))
91 endef
92
93 ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
94 define Image/mkfs/jffs2
95 $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ),$(SZ),$(JFFS2OPTS)))
96 endef
97 endif
98
99 ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2_NAND),)
100 define Image/mkfs/jffs2_nand
101 $(foreach SZ,$(NAND_BLOCKSIZE), $(call Image/mkfs/jffs2/sub, \
102 $(word 2,$(subst :, ,$(SZ))),nand-$(subst :,-,$(SZ)), \
103 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst :, ,$(SZ)))) \
104 )
105 endef
106 endif
107
108 ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
109 define Image/mkfs/squashfs
110 @mkdir -p $(TARGET_DIR)/overlay
111 $(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)
112 $(call Image/Build,squashfs)
113 endef
114 endif
115
116 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
117 define Image/mkfs/ubifs
118 $(CP) ./ubinize.cfg $(KDIR)
119 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
120 $(UBIFS_OPTS) \
121 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
122 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--force-compr=none) \
123 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--force-compr=lzo) \
124 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--force-compr=zlib) \
125 --jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE) \
126 -o $(KDIR)/root.ubifs \
127 -d $(TARGET_DIR)
128 $(call Image/Build,ubifs)
129 (cd $(KDIR); \
130 $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
131 $(call Image/Build,ubi)
132 endef
133 endif
134
135 ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
136 define Image/mkfs/cpiogz
137 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
138 endef
139 endif
140
141 ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
142 define Image/mkfs/targz
143 # Preserve permissions (-p) when building as non-root user
144 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
145 endef
146 endif
147
148 ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
149 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
150
151 define Image/mkfs/ext4
152 # generate an ext2 fs
153 $(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) $(MKFS_DEVTABLE_OPT)
154 # convert it to ext4
155 $(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
156 # fix it up
157 $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
158 $(call Image/Build,ext4)
159 endef
160 endif
161
162 ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
163 define Image/mkfs/iso
164 $(call Image/Build,iso)
165 endef
166 endif
167
168
169 define Image/mkfs/prepare/default
170 # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
171 - $(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
172 - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
173 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
174 $(INSTALL_DIR) $(TARGET_DIR)/tmp
175 chmod 1777 $(TARGET_DIR)/tmp
176 endef
177
178 define Image/mkfs/prepare
179 $(call Image/mkfs/prepare/default)
180 endef
181
182
183 define Image/Checksum
184 ( cd ${BIN_DIR} ; \
185 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
186 md5sum --binary > md5sums \
187 )
188 endef
189
190
191 define BuildImage
192
193 download:
194 prepare:
195
196 ifeq ($(IB),)
197 compile: compile-targets FORCE
198 $(call Build/Compile)
199 else
200 compile:
201 endif
202
203 ifeq ($(IB),)
204 install: compile install-targets FORCE
205 $(call Image/Prepare)
206 $(call Image/mkfs/prepare)
207 $(call Image/BuildKernel)
208 $(call Image/BuildKernel/Initramfs)
209 $(call Image/InstallKernel)
210 $(call Image/mkfs/cpiogz)
211 $(call Image/mkfs/targz)
212 $(call Image/mkfs/ext4)
213 $(call Image/mkfs/iso)
214 $(call Image/mkfs/jffs2)
215 $(call Image/mkfs/jffs2_nand)
216 $(call Image/mkfs/squashfs)
217 $(call Image/mkfs/ubifs)
218 $(call Image/Checksum)
219 else
220 install: compile install-targets
221 $(call Image/BuildKernel)
222 $(call Image/BuildKernel/Initramfs)
223 $(call Image/InstallKernel)
224 $(call Image/mkfs/cpiogz)
225 $(call Image/mkfs/targz)
226 $(call Image/mkfs/ext4)
227 $(call Image/mkfs/iso)
228 $(call Image/mkfs/jffs2)
229 $(call Image/mkfs/jffs2_nand)
230 $(call Image/mkfs/squashfs)
231 $(call Image/mkfs/ubifs)
232 $(call Image/Checksum)
233 endif
234
235 ifeq ($(IB),)
236 clean: clean-targets
237 $(call Build/Clean)
238 else
239 clean:
240 endif
241
242 compile-targets:
243 install-targets:
244 clean-targets:
245
246 endef