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
-v
24 JFFS2OPTS
:= --pad
--little-endian
--squash
-v
28 ifeq ($(CONFIG_JFFS2_RTIME
),y
)
31 ifeq ($(CONFIG_JFFS2_ZLIB
),y
)
34 ifeq ($(CONFIG_JFFS2_LZMA
),y
)
35 JFFS2OPTS
+= -X lzma
--compression-mode
=size
37 ifneq ($(CONFIG_JFFS2_RTIME
),y
)
40 ifneq ($(CONFIG_JFFS2_ZLIB
),y
)
43 ifneq ($(CONFIG_JFFS2_LZMA
),y
)
47 MKSQUASHFS_CMD
:= $(STAGING_DIR_HOST
)/bin
/mksquashfs4
48 SQUASHFS_OPTS
:= -comp lzma
-processors
1
50 JFFS2_BLOCKSIZE ?
= 64k
128k
53 echo
-ne
'\xde\xad\xc0\xde' >> $(1)
56 # pad to 4k, 8k, 64k, 128k and add jffs2 end-of-filesystem mark
57 define prepare_generic_squashfs
58 dd if
=$(1) of
=$(KDIR
)/tmpfile
.0 bs
=4k conv
=sync
59 $(call add_jffs2_mark
,$(KDIR
)/tmpfile
.0)
60 dd if
=$(KDIR
)/tmpfile
.0 of
=$(KDIR
)/tmpfile
.1 bs
=4k conv
=sync
61 $(call add_jffs2_mark
,$(KDIR
)/tmpfile
.1)
62 dd if
=$(KDIR
)/tmpfile
.1 of
=$(KDIR
)/tmpfile
.2 bs
=64k conv
=sync
63 $(call add_jffs2_mark
,$(KDIR
)/tmpfile
.2)
64 dd if
=$(KDIR
)/tmpfile
.2 of
=$(1) bs
=64k conv
=sync
65 $(call add_jffs2_mark
,$(1))
66 rm -f
$(KDIR
)/tmpfile.
*
70 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS
),)
72 define Image
/BuildKernel
73 cp
$(KDIR
)/vmlinux.elf
$(BIN_DIR
)/$(IMG_PREFIX
)-vmlinux.elf
74 $(call Image
/Build
/Initramfs
)
79 ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2
),)
80 define Image
/mkfs
/jffs2
/sub
81 # FIXME: removing this line will cause strange behaviour in the foreach loop below
82 $(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
'/^.+$$$$/'
83 $(call add_jffs2_mark
,$(KDIR
)/root.jffs2-
$(1))
84 $(call Image
/Build
,jffs2-
$(1))
86 define Image
/mkfs
/jffs2
87 $(foreach SZ
,$(JFFS2_BLOCKSIZE
),$(call Image
/mkfs
/jffs2
/sub
,$(SZ
)))
91 ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS
),)
92 define Image
/mkfs
/squashfs
93 @mkdir
-p
$(TARGET_DIR
)/overlay
94 $(MKSQUASHFS_CMD
) $(TARGET_DIR
) $(KDIR
)/root.squashfs
-nopad
-noappend
-root-owned
$(SQUASHFS_OPTS
)
95 $(call Image
/Build
,squashfs
)
99 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS
),)
100 define Image
/mkfs
/ubifs
101 $(CP
) .
/ubinize.cfg
$(KDIR
)
102 $(STAGING_DIR_HOST
)/bin
/mkfs.ubifs
$(UBIFS_OPTS
) -o
$(KDIR
)/root.ubifs
-d
$(TARGET_DIR
)
104 $(STAGING_DIR_HOST
)/bin
/ubinize
$(UBINIZE_OPTS
) -o
$(KDIR
)/root.ubi ubinize.cfg
)
105 $(call Image
/Build
,ubi
)
111 ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ
),)
112 define Image
/mkfs
/cpiogz
113 ( cd
$(TARGET_DIR
); find . | cpio
-o
-H newc | gzip
-9 >$(BIN_DIR
)/$(IMG_PREFIX
)-rootfs.cpio.gz
)
117 ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ
),)
118 define Image
/mkfs
/targz
119 $(TAR
) -zcf
$(BIN_DIR
)/$(IMG_PREFIX
)-rootfs.
tar.gz
--numeric-owner
--owner
=0 --group
=0 -C
$(TARGET_DIR
)/ .
123 ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS
),)
124 E2SIZE
=$(shell echo
$$(($(CONFIG_TARGET_ROOTFS_PARTSIZE
)*1024)))
126 define Image
/mkfs
/ext4
127 # generate an ext2 fs
128 $(STAGING_DIR_HOST
)/bin
/genext2fs
-U
-b
$(E2SIZE
) -N
$(CONFIG_TARGET_ROOTFS_MAXINODE
) -d
$(TARGET_DIR
)/ $(KDIR
)/root.ext4
130 $(STAGING_DIR_HOST
)/bin
/tune2fs
-O extents
,uninit_bg
,dir_index
$(KDIR
)/root.ext4
132 $(STAGING_DIR_HOST
)/bin
/e2fsck
-fy
$(KDIR
)/root.ext4
133 $(call Image
/Build
,ext4
)
137 ifneq ($(CONFIG_TARGET_ROOTFS_ISO
),)
138 define Image
/mkfs
/iso
139 $(call Image
/Build
,iso
)
144 define Image
/mkfs
/prepare
/default
145 - $(FIND
) $(TARGET_DIR
) -type f
-not
-perm
+0100 -not
-name
'ssh_host*' -print0 |
$(XARGS
) -0 chmod
0644
146 - $(FIND
) $(TARGET_DIR
) -type f
-perm
+0100 -print0 |
$(XARGS
) -0 chmod
0755
147 - $(FIND
) $(TARGET_DIR
) -type d
-print0 |
$(XARGS
) -0 chmod
0755
148 $(INSTALL_DIR
) $(TARGET_DIR
)/tmp
149 chmod
0777 $(TARGET_DIR
)/tmp
152 define Image
/mkfs
/prepare
153 $(call Image
/mkfs
/prepare
/default
)
157 define Image
/Checksum
159 $(FIND
) -maxdepth
1 -type f \
! -name
'md5sums' -printf
"%P\n" |
sort | xargs \
160 md5sum
--binary
> md5sums \
171 compile
: compile-targets FORCE
172 $(call Build
/Compile
)
178 install: compile install-targets FORCE
179 $(call Image
/Prepare
)
180 $(call Image
/mkfs
/prepare
)
181 $(call Image
/BuildKernel
)
182 $(call Image
/mkfs
/cpiogz
)
183 $(call Image
/mkfs
/targz
)
184 $(call Image
/mkfs
/ext4
)
185 $(call Image
/mkfs
/iso
)
186 $(call Image
/mkfs
/jffs2
)
187 $(call Image
/mkfs
/squashfs
)
188 $(call Image
/mkfs
/ubifs
)
189 $(call Image
/Checksum
)
191 install: compile install-targets
192 $(call Image
/BuildKernel
)
193 $(call Image
/mkfs
/cpiogz
)
194 $(call Image
/mkfs
/targz
)
195 $(call Image
/mkfs
/ext4
)
196 $(call Image
/mkfs
/iso
)
197 $(call Image
/mkfs
/jffs2
)
198 $(call Image
/mkfs
/squashfs
)
199 $(call Image
/mkfs
/ubifs
)
200 $(call Image
/Checksum
)