ar71xx: create WZR-HP-G300NH network config from uci-defaults
[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 ifneq ($(CONFIG_BIG_ENDIAN),)
21 JFFS2OPTS := --pad --big-endian --squash -v
22 else
23 JFFS2OPTS := --pad --little-endian --squash -v
24 endif
25
26 ifeq ($(CONFIG_JFFS2_RTIME),y)
27 JFFS2OPTS += -X rtime
28 endif
29 ifeq ($(CONFIG_JFFS2_ZLIB),y)
30 JFFS2OPTS += -X zlib
31 endif
32 ifeq ($(CONFIG_JFFS2_LZMA),y)
33 JFFS2OPTS += -X lzma --compression-mode=size
34 endif
35 ifneq ($(CONFIG_JFFS2_RTIME),y)
36 JFFS2OPTS += -x rtime
37 endif
38 ifneq ($(CONFIG_JFFS2_ZLIB),y)
39 JFFS2OPTS += -x zlib
40 endif
41 ifneq ($(CONFIG_JFFS2_LZMA),y)
42 JFFS2OPTS += -x lzma
43 endif
44
45 SQUASHFSCOMP := gzip
46 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
47 ifeq ($(CONFIG_SQUASHFS_LZMA),y)
48 SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
49 endif
50 ifeq ($(CONFIG_SQUASHFS_XZ),y)
51 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS)
52 endif
53
54 JFFS2_BLOCKSIZE ?= 64k 128k
55
56 define add_jffs2_mark
57 echo -ne '\xde\xad\xc0\xde' >> $(1)
58 endef
59
60 # pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
61 define prepare_generic_squashfs
62 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
63 endef
64
65
66 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
67
68 define Image/BuildKernel
69 cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux.elf
70 $(call Image/Build/Initramfs)
71 endef
72
73 else
74
75 ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
76 define Image/mkfs/jffs2/sub
77 # FIXME: removing this line will cause strange behaviour in the foreach loop below
78 $(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 '/^.+$$$$/'
79 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
80 $(call Image/Build,jffs2-$(1))
81 endef
82 define Image/mkfs/jffs2
83 $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
84 endef
85 endif
86
87 ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
88 define Image/mkfs/squashfs
89 @mkdir -p $(TARGET_DIR)/overlay
90 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1)
91 $(call Image/Build,squashfs)
92 endef
93 endif
94
95 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
96 define Image/mkfs/ubifs
97 $(CP) ./ubinize.cfg $(KDIR)
98 $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(UBIFS_OPTS) -o $(KDIR)/root.ubifs -d $(TARGET_DIR)
99 (cd $(KDIR); \
100 $(STAGING_DIR_HOST)/bin/ubinize $(UBINIZE_OPTS) -o $(KDIR)/root.ubi ubinize.cfg)
101 $(call Image/Build,ubi)
102 endef
103 endif
104
105 endif
106
107 ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
108 define Image/mkfs/cpiogz
109 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
110 endef
111 endif
112
113 ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
114 define Image/mkfs/targz
115 # Preserve permissions (-p) when building as non-root user
116 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
117 endef
118 endif
119
120 ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
121 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
122
123 define Image/mkfs/ext4
124 # generate an ext2 fs
125 $(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -N $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4
126 # convert it to ext4
127 $(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
128 # fix it up
129 $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
130 $(call Image/Build,ext4)
131 endef
132 endif
133
134 ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
135 define Image/mkfs/iso
136 $(call Image/Build,iso)
137 endef
138 endif
139
140
141 define Image/mkfs/prepare/default
142 # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
143 - $(FIND) $(TARGET_DIR) -type f -not -perm +0100 -not -name 'ssh_host*' -print0 | $(XARGS) -0 chmod u+rw,g+r,o+r
144 - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
145 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
146 $(INSTALL_DIR) $(TARGET_DIR)/tmp
147 chmod 0777 $(TARGET_DIR)/tmp
148 endef
149
150 define Image/mkfs/prepare
151 $(call Image/mkfs/prepare/default)
152 endef
153
154
155 define Image/Checksum
156 ( cd ${BIN_DIR} ; \
157 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
158 md5sum --binary > md5sums \
159 )
160 endef
161
162
163 define BuildImage
164
165 download:
166 prepare:
167
168 ifeq ($(IB),)
169 compile: compile-targets FORCE
170 $(call Build/Compile)
171 else
172 compile:
173 endif
174
175 ifeq ($(IB),)
176 install: compile install-targets FORCE
177 $(call Image/Prepare)
178 $(call Image/mkfs/prepare)
179 $(call Image/BuildKernel)
180 $(call Image/mkfs/cpiogz)
181 $(call Image/mkfs/targz)
182 $(call Image/mkfs/ext4)
183 $(call Image/mkfs/iso)
184 $(call Image/mkfs/jffs2)
185 $(call Image/mkfs/squashfs)
186 $(call Image/mkfs/ubifs)
187 $(call Image/Checksum)
188 else
189 install: compile install-targets
190 $(call Image/BuildKernel)
191 $(call Image/mkfs/cpiogz)
192 $(call Image/mkfs/targz)
193 $(call Image/mkfs/ext4)
194 $(call Image/mkfs/iso)
195 $(call Image/mkfs/jffs2)
196 $(call Image/mkfs/squashfs)
197 $(call Image/mkfs/ubifs)
198 $(call Image/Checksum)
199 endif
200
201 ifeq ($(IB),)
202 clean: clean-targets
203 $(call Build/Clean)
204 else
205 clean:
206 endif
207
208 compile-targets:
209 install-targets:
210 clean-targets:
211
212 endef
This page took 0.053794 seconds and 5 git commands to generate.