f6abd6d2931b4b2ea3502f0cacade09f8a390b70
[openwrt/openwrt.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 Image/BuildKernel/Template
26 $(CP) $(DTS_DIR)/ox820-$(1).dtb $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb
27
28 $(call Image/BuildKernel/MkFIT,$(1),$(KDIR)/zImage,$(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb,none,0x60008000,0x60008000)
29 $(CP) $(KDIR)/fit-$(1).itb $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage.itb
30
31 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
32 $(call Image/BuildKernel/MkFIT,$(1),$(KDIR)/zImage-initramfs,$(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb,none,0x60008000,0x60008000,-initramfs)
33 $(CP) $(KDIR)/fit-$(1)-initramfs.itb $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage-initramfs.itb
34 if [ -e "$(KDIR)/u-boot.bin" ]; then \
35 ( dd if=$(KDIR)/u-boot.bin bs=128k conv=sync ; dd if=$(KDIR)/fit-$(1)-initramfs.itb bs=128k conv=sync ) \
36 > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-u-boot-initramfs.bin; \
37 fi
38 endif
39
40 $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage
41 $(call Image/BuildKernel/MkuImage, \
42 none, 0x60008000, 0x60008000, \
43 $(BIN_DIR)/$(IMG_PREFIX)-zImage, \
44 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
45 )
46
47 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
48 $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
49 $(call Image/BuildKernel/MkuImage, \
50 none, 0x60008000, 0x60008000, \
51 $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
52 $(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
53 )
54 endif
55 endef
56
57 define Image/InstallKernel/Template
58
59 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_KERNEL),)
60 $(INSTALL_DIR) $(TARGET_DIR)/boot
61 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_UIMAGE),)
62 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/
63 ln -sf $(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/uImage
64 endif
65 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_ZIMAGE),)
66 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/
67 ln -sf $(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/zImage
68 endif
69 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_FIT),)
70 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fit-uImage.itb $(TARGET_DIR)/boot/
71 ln -sf $(IMG_PREFIX)-$(1)-fit-uImage.itb $(TARGET_DIR)/boot/uImage.itb
72 endif
73 endif
74
75 ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_DTB),)
76 $(INSTALL_DIR) $(TARGET_DIR)/boot
77 ifneq ($(1),)
78 $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/
79 ln -sf $(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/$(1).dtb
80 endif
81 endif
82 endef
83
84 define Image/Build/squashfs
85 $(call Image/Build/SysupgradeNAND,$(PROFILE_SANITIZED),$(1),$(KDIR)/fit-$(PROFILE_SANITIZED).itb)
86 $(call Image/Build/UbinizeImage,$(PROFILE_SANITIZED),--uboot-env --kernel $(KDIR)/fit-$(PROFILE_SANITIZED).itb,$(1),$($(PROFILE)_UBI_OPTS))
87 cp $(KDIR)/$(IMG_PREFIX)-$(PROFILE_SANITIZED)-squashfs-ubinized.bin $(BIN_DIR)
88 endef
89
90 define Image/mkfs/targz
91
92 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE_SANITIZED)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
93 endef
94
95 define Image/Build/ubifs
96
97 ifneq ($($(PROFILE)_UBIFS_OPTS),)
98 $(call Image/Build/SysupgradeNAND,$(PROFILE_SANITIZED),ubifs,$(KDIR)/fit-$(PROFILE_SANITIZED).itb)
99 $(call Image/Build/UbinizeImage,$(PROFILE_SANITIZED),--uboot-env --kernel $(KDIR)/fit-$(PROFILE_SANITIZED).itb,ubifs,$($(PROFILE)_UBI_OPTS))
100 cp $(KDIR)/$(IMG_PREFIX)-$(PROFILE_SANITIZED)-ubifs-ubinized.bin $(BIN_DIR)
101 endif
102
103 endef
104
105 Image/BuildKernel/Template/POGOPLUG_PRO=$(call Image/BuildKernel/Template,pogoplug-pro)
106 Image/InstallKernel/Template/POGOPLUG_PRO=$(call Image/InstallKernel/Template,pogoplug-pro)
107
108 Image/BuildKernel/Template/POGOPLUG_V3=$(call Image/BuildKernel/Template,pogoplug-v3)
109 Image/InstallKernel/Template/POGOPLUG_V3=$(call Image/InstallKernel/Template,pogoplug-v3)
110
111 Image/BuildKernel/Template/STG212=$(call Image/BuildKernel/Template,stg212)
112 Image/InstallKernel/Template/STG212=$(call Image/InstallKernel/Template,stg212)
113
114 Image/BuildKernel/Template/KD20=$(call Image/BuildKernel/Template,kd20)
115 Image/InstallKernel/Template/KD20=$(call Image/InstallKernel/Template,kd20)
116
117 define Image/BuildKernel
118 $(call Image/BuildKernel/Template/$(PROFILE))
119 endef
120
121 define Image/InstallKernel
122 $(call Image/InstallKernel/Template/$(PROFILE))
123 endef
124
125 define Image/Build
126 $(if $(Image/Build/$(1)), \
127 $(call Image/Build/$(1),$(1)), \
128 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE_SANITIZED)-$(1).img \
129 )
130 endef
131
132 $(eval $(call BuildImage))