8dc7e114b695958cc2289cfcbaad00a5b482f5ed
[openwrt/svn-archive/archive.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 ifneq ($(CONFIG_BIG_ENDIAN),y)
21 JFFS2OPTS := --pad --little-endian --squash -v
22 SQUASHFS_OPTS := -le
23 else
24 JFFS2OPTS := --pad --big-endian --squash -v
25 SQUASHFS_OPTS := -be
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 ifneq ($(CONFIG_LINUX_2_4)$(CONFIG_LINUX_2_6_25),)
48 USE_SQUASHFS3 := y
49 endif
50
51 ifneq ($(USE_SQUASHFS3),)
52 MKSQUASHFS_CMD := $(STAGING_DIR_HOST)/bin/mksquashfs-lzma
53 else
54 MKSQUASHFS_CMD := $(STAGING_DIR_HOST)/bin/mksquashfs4
55 SQUASHFS_OPTS := -comp lzma -processors 1
56 endif
57
58 JFFS2_BLOCKSIZE ?= 64k 128k
59
60 define add_jffs2_mark
61 echo -ne '\xde\xad\xc0\xde' >> $(1)
62 endef
63
64 # pad to 4k, 8k, 64k, 128k and add jffs2 end-of-filesystem mark
65 define prepare_generic_squashfs
66 dd if=$(1) of=$(KDIR)/tmpfile.0 bs=4k conv=sync
67 $(call add_jffs2_mark,$(KDIR)/tmpfile.0)
68 dd if=$(KDIR)/tmpfile.0 of=$(KDIR)/tmpfile.1 bs=4k conv=sync
69 $(call add_jffs2_mark,$(KDIR)/tmpfile.1)
70 dd if=$(KDIR)/tmpfile.1 of=$(KDIR)/tmpfile.2 bs=64k conv=sync
71 $(call add_jffs2_mark,$(KDIR)/tmpfile.2)
72 dd if=$(KDIR)/tmpfile.2 of=$(1) bs=64k conv=sync
73 $(call add_jffs2_mark,$(1))
74 rm -f $(KDIR)/tmpfile.*
75 endef
76
77 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
78 ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y)
79 define Image/mkfs/jffs2/sub
80 # FIXME: removing this line will cause strange behaviour in the foreach loop below
81 $(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 '/^.+$$$$/'
82 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
83 $(call Image/Build,jffs2-$(1))
84 endef
85 define Image/mkfs/jffs2
86 $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
87 endef
88 endif
89
90 ifeq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),y)
91 define Image/mkfs/squashfs
92 @mkdir -p $(TARGET_DIR)/overlay
93 $(MKSQUASHFS_CMD) $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned $(SQUASHFS_OPTS)
94 $(call Image/Build,squashfs)
95 endef
96 endif
97
98 ifeq ($(CONFIG_TARGET_ROOTFS_UBIFS),y)
99 define Image/mkfs/ubifs
100 $(CP) ./ubinize.cfg $(KDIR)
101 $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(UBIFS_OPTS) -o $(KDIR)/root.ubifs -d $(TARGET_DIR)
102 (cd $(KDIR); \
103 $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
104 $(call Image/Build,ubi)
105 endef
106 endif
107 else
108 define Image/BuildKernel
109 cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux.elf
110 $(call Image/Build/Initramfs)
111 endef
112 endif
113
114 define Image/Checksum
115 ( cd ${BIN_DIR} ; \
116 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
117 md5sum --binary > md5sums \
118 )
119 endef
120
121
122 ifeq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),y)
123 define Image/mkfs/cpiogz
124 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
125 endef
126 endif
127
128 ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y)
129 define Image/mkfs/tgz
130 $(TAR) -zcf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tgz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
131 endef
132 endif
133
134 ifeq ($(CONFIG_TARGET_ROOTFS_EXT2FS),y)
135 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_FSPART)*1024)))
136
137 define Image/mkfs/ext2
138 $(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -N $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext2
139 $(call Image/Build,ext2)
140 endef
141 endif
142
143 ifeq ($(CONFIG_TARGET_ROOTFS_ISO),y)
144 define Image/mkfs/iso
145 $(call Image/Build,iso)
146 endef
147 endif
148
149
150 define Image/mkfs/prepare/default
151 - $(FIND) $(TARGET_DIR) -type f -not -perm +0100 -not -name 'ssh_host*' -print0 | $(XARGS) -0 chmod 0644
152 - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod 0755
153 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod 0755
154 $(INSTALL_DIR) $(TARGET_DIR)/tmp
155 chmod 0777 $(TARGET_DIR)/tmp
156 endef
157
158 define Image/mkfs/prepare
159 $(call Image/mkfs/prepare/default)
160 endef
161
162 define BuildImage
163 download:
164 prepare:
165 ifneq ($(IB),1)
166 compile: compile-targets FORCE
167 $(call Build/Compile)
168 else
169 compile:
170 endif
171
172 ifneq ($(IB),1)
173 install: compile install-targets FORCE
174 $(call Image/Prepare)
175 $(call Image/mkfs/prepare)
176 $(call Image/BuildKernel)
177 $(call Image/mkfs/jffs2)
178 $(call Image/mkfs/squashfs)
179 $(call Image/mkfs/tgz)
180 $(call Image/mkfs/cpiogz)
181 $(call Image/mkfs/ext2)
182 $(call Image/mkfs/iso)
183 $(call Image/mkfs/ubifs)
184 $(call Image/Checksum)
185 else
186 install: compile install-targets
187 $(call Image/BuildKernel)
188 $(call Image/mkfs/jffs2)
189 $(call Image/mkfs/squashfs)
190 $(call Image/mkfs/tgz)
191 $(call Image/mkfs/cpiogz)
192 $(call Image/mkfs/ext2)
193 $(call Image/mkfs/iso)
194 $(call Image/mkfs/ubifs)
195 $(call Image/Checksum)
196 endif
197
198 ifneq ($(IB),1)
199 clean: clean-targets
200 $(call Build/Clean)
201 else
202 clean:
203 endif
204
205 compile-targets:
206 install-targets:
207 clean-targets:
208 endef
209
210