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