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 ifneq ($(CONFIG_LINUX_2_4
)$(CONFIG_LINUX_2_6_25
),)
32 ifneq ($(USE_SQUASHFS3
),)
33 MKSQUASHFS_CMD
:= $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma
35 MKSQUASHFS_CMD
:= $(STAGING_DIR_HOST
)/bin
/mksquashfs4
36 SQUASHFS_OPTS
:= -comp lzma
-processors
1
39 JFFS2_BLOCKSIZE ?
= 64k
128k
42 echo
-ne
'\xde\xad\xc0\xde' >> $(1)
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.
*
59 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS
),)
61 define Image
/BuildKernel
62 cp
$(KDIR
)/vmlinux.elf
$(BIN_DIR
)/$(IMG_PREFIX
)-vmlinux.elf
63 $(call Image
/Build
/Initramfs
)
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))
75 define Image
/mkfs
/jffs2
76 $(foreach SZ
,$(JFFS2_BLOCKSIZE
),$(call Image
/mkfs
/jffs2
/sub
,$(SZ
)))
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
)
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
)
93 $(STAGING_DIR_HOST
)/bin
/ubinize
$(UBINIZE_OPTS
) -o
$(KDIR
)/root.ubi ubinize.cfg
)
94 $(call Image
/Build
,ubi
)
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
)
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
)/ .
112 ifneq ($(CONFIG_TARGET_ROOTFS_EXT2FS
),)
113 E2SIZE
=$(shell echo
$$(($(CONFIG_TARGET_ROOTFS_PARTSIZE
)*1024)))
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
)
121 ifneq ($(CONFIG_TARGET_ROOTFS_ISO
),)
122 define Image
/mkfs
/iso
123 $(call Image
/Build
,iso
)
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
136 define Image
/mkfs
/prepare
137 $(call Image
/mkfs
/prepare
/default
)
141 define Image
/Checksum
143 $(FIND
) -maxdepth
1 -type f \
! -name
'md5sums' -printf
"%P\n" |
sort | xargs \
144 md5sum
--binary
> md5sums \
155 compile
: compile-targets FORCE
156 $(call Build
/Compile
)
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
)
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
)