image.mk: move KDIR_TMP definition to a central location
[openwrt/staging/wigyori.git] / target / linux / oxnas / image / Makefile
1 #
2 # Copyright (C) 2013 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
9
10 STG212_UBI_OPTS = -m 2048 -p 128KiB -s 512
11 STG212_UBIFS_OPTS = -m 2048 -e 126KiB -c 4096
12
13 KD20_UBI_OPTS = -m 2048 -p 128KiB -s 512
14 KD20_UBIFS_OPTS = -m 2048 -e 126KiB -c 4096
15
16 POGOPLUG_PRO_UBI_OPTS = -m 2048 -p 128KiB -s 512
17 POGOPLUG_PRO_UBIFS_OPTS = -m 2048 -e 126KiB -c 4096
18
19 POGOPLUG_V3_UBI_OPTS = -m 2048 -p 128KiB -s 512
20 POGOPLUG_V3_UBIFS_OPTS = -m 2048 -e 126KiB -c 4096
21
22 VMLINUX:=$(BIN_DIR)/$(IMG_PREFIX)-vmlinux
23 UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage
24
25 define sanitize_profile_name
26 $(shell echo $(PROFILE) | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g')
27 endef
28
29 define Image/BuildKernel/Template
30 $(CP) $(DTS_DIR)/ox820-$(1).dtb $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb
31
32 $(call Image/BuildKernel/MkFIT,$(1),$(KDIR)/zImage,$(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb,none,0x60008000,0x60008000)
33 $(CP) $(KDIR)/fit-$(1).itb $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage.itb
34
35 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
36 $(call Image/BuildKernel/MkFIT,$(1),$(KDIR)/zImage-initramfs,$(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb,none,0x60008000,0x60008000,-initramfs)
37 $(CP) $(KDIR)/fit-$(1)-initramfs.itb $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage-initramfs.itb
38 if [ -e "$(KDIR)/u-boot.bin" ]; then \
39 ( dd if=$(KDIR)/u-boot.bin bs=128k conv=sync ; dd if=$(KDIR)/fit-$(1)-initramfs.itb bs=128k conv=sync ) \
40 > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-u-boot-initramfs.bin; \
41 fi
42 endif
43
44 $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage
45 $(call Image/BuildKernel/MkuImage, \
46 none, 0x60008000, 0x60008000, \
47 $(BIN_DIR)/$(IMG_PREFIX)-zImage, \
48 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
49 )
50
51 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
52 $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
53 $(call Image/BuildKernel/MkuImage, \
54 none, 0x60008000, 0x60008000, \
55 $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
56 $(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
57 )
58 endif
59 endef
60
61 define Image/InstallKernel/Template
62
63 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_KERNEL),)
64 $(INSTALL_DIR) $(TARGET_DIR)/boot
65 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_UIMAGE),)
66 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/
67 ln -sf $(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/uImage
68 endif
69 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_ZIMAGE),)
70 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/
71 ln -sf $(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/zImage
72 endif
73 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_FIT),)
74 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage.itb $(TARGET_DIR)/boot/
75 ln -sf $(IMG_PREFIX)-$(1)-fit-uImage.itb $(TARGET_DIR)/boot/uImage.itb
76 endif
77 endif
78
79 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_DTB),)
80 $(INSTALL_DIR) $(TARGET_DIR)/boot
81 ifneq ($(1),)
82 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/
83 ln -sf $(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/$(1).dtb
84 endif
85 endif
86 endef
87
88 define Image/Build/squashfs
89 $(call Image/Build/SysupgradeNAND,$(call sanitize_profile_name),$(1),$(KDIR)/fit-$(call sanitize_profile_name).itb)
90 $(call Image/Build/UbinizeImage,$(call sanitize_profile_name),--uboot-env --kernel $(KDIR)/fit-$(call sanitize_profile_name).itb,$(1),$($(PROFILE)_UBI_OPTS))
91 cp $(KDIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-squashfs-ubinized.bin $(BIN_DIR)
92 endef
93
94 define Image/mkfs/targz
95
96 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
97 endef
98
99 define Image/Build/ubifs
100
101 ifneq ($($(PROFILE)_UBIFS_OPTS),)
102 $(call Image/Build/SysupgradeNAND,$(call sanitize_profile_name),ubifs,$(KDIR)/fit-$(call sanitize_profile_name).itb)
103 $(call Image/Build/UbinizeImage,$(call sanitize_profile_name),--uboot-env --kernel $(KDIR)/fit-$(call sanitize_profile_name).itb,ubifs,$($(PROFILE)_UBI_OPTS))
104 cp $(KDIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-ubifs-ubinized.bin $(BIN_DIR)
105 endif
106
107 endef
108
109 Image/BuildKernel/Template/POGOPLUG_PRO=$(call Image/BuildKernel/Template,pogoplug-pro)
110 Image/InstallKernel/Template/POGOPLUG_PRO=$(call Image/InstallKernel/Template,pogoplug-pro)
111
112 Image/BuildKernel/Template/POGOPLUG_V3=$(call Image/BuildKernel/Template,pogoplug-v3)
113 Image/InstallKernel/Template/POGOPLUG_V3=$(call Image/InstallKernel/Template,pogoplug-v3)
114
115 Image/BuildKernel/Template/STG212=$(call Image/BuildKernel/Template,stg212)
116 Image/InstallKernel/Template/STG212=$(call Image/InstallKernel/Template,stg212)
117
118 Image/BuildKernel/Template/KD20=$(call Image/BuildKernel/Template,kd20)
119 Image/InstallKernel/Template/KD20=$(call Image/InstallKernel/Template,kd20)
120
121 define Image/BuildKernel
122 $(call Image/BuildKernel/Template/$(PROFILE))
123 endef
124
125 define Image/InstallKernel
126 $(call Image/InstallKernel/Template/$(PROFILE))
127 endef
128
129 define Image/Build
130 $(if $(Image/Build/$(1)), \
131 $(call Image/Build/$(1),$(1)), \
132 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-$(1).img \
133 )
134 endef
135
136 $(eval $(call BuildImage))