1#
2# Copyright (C) 2012-2015 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7
8JFFS2_BLOCKSIZE = 128k
9
10include $(TOPDIR)/rules.mk
11include $(INCLUDE_DIR)/image.mk
12
13LOADADDR:=0x00008000
14
15define Image/Build/DTB
16	cp $(KDIR)/zImage$(2) $(KDIR)/zImage$(2)-$(1);
17	cat $(DTS_DIR)/$(1).dtb >> $(KDIR)/zImage$(2)-$(1);
18	$(call Image/BuildKernel/MkuImage, \
19		none, $(LOADADDR), $(LOADADDR), \
20		$(KDIR)/zImage$(2)-$(1), $(KDIR)/uImage$(2)-$(1))
21endef
22
23# $(1): Profile Name
24# $(2): DTB Name
25# $(3): Erase Block Size
26# $(4): Page Size
27# $(5): Sub-Page Size (optional)
28# $(6): VID offset (optional)
29define NANDProfile
30  define Image/BuildKernel/Profile/$(1)
31	$(call Image/Build/DTB,$(2))
32    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
33	$(call Image/Build/Profile,$(1)/Initramfs)
34    endif
35  endef
36
37  define Image/Build/Profile/$(1)/BuildSysupgrade
38	$(call Image/Build/SysupgradeNAND,$(2),$$(1),$(KDIR)/uImage-$(2))
39  endef
40
41  define Image/Build/Profile/$(1)/Initramfs
42	$(call Image/Build/DTB,$(2),-initramfs)
43	cp $(KDIR)/uImage-initramfs-$(2) $(BIN_DIR)/$(IMG_PREFIX)-$(2)-initramfs
44  endef
45
46  define Image/Build/Profile/$(1)/squashfs
47	$(call Image/Build/UbinizeImage,$(2),,squashfs, -p $(3) -m $(4) $(if $(5),-s $(5)) $(if $(6),-O $(6)))
48  endef
49
50  PROFILES_LIST += $(1)
51endef
52
53# $(1): Profile Name
54# $(2): DTB Name
55# $(3): Erase Block Size
56define UBINORProfile
57  define Image/BuildKernel/Profile/$(1)
58	$(call Image/Build/DTB,$(2))
59    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
60	$(call Image/Build/Profile,$(1)/Initramfs)
61    endif
62  endef
63
64  define Image/Build/Profile/$(1)/Initramfs
65	$(call Image/Build/DTB,$(2),-initramfs)
66  endef
67
68  define Image/Build/Profile/$(1)/squashfs
69	$(call Image/Build/UbinizeImage,$(2),,squashfs, -p $(3) -m 1)
70  endef
71
72  PROFILES_LIST += $(1)
73endef
74
75# $(1): Profile Name
76# $(2): DTB Name
77# $(3): Erase Block Size
78define NORProfile
79  define Image/BuildKernel/Profile/$(1)
80	$(call Image/Build/DTB,$(2))
81    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
82	$(call Image/Build/Profile,$(1)/Initramfs)
83    endif
84  endef
85
86  define Image/Build/Profile/$(1)/Initramfs
87	$(call Image/Build/DTB,$(2),-initramfs)
88  endef
89
90  define Image/Build/Profile/$(1)/squashfs
91	( \
92		dd if=$(KDIR)/uImage-$(2) bs=$(patsubst %KiB,%k,$(3)) conv=sync; \
93		dd if=$(KDIR)/root.squashfs bs=$(patsubst %KiB,%k,$(3)) conv=sync; \
94	) > $$(BIN_DIR)/$$(IMG_PREFIX)-$(2)-squashfs-firmware.bin
95  endef
96
97  PROFILES_LIST += $(1)
98endef
99
100# $(1): Profile Name
101# $(2): DTB Name
102define MMCProfile
103  define Image/BuildKernel/Profile/$(1)
104	$(call Image/Build/DTB,$(2))
105	cp $(KDIR)/zImage-$(2) $(BIN_DIR)/zImage-$(1);
106	cp $(DTS_DIR)/$(2).dtb $(BIN_DIR)/$(1).dtb;
107    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
108	$(call Image/Build/Profile,$(1)/Initramfs)
109    endif
110  endef
111
112  define Image/Build/Profile/$(1)/Initramfs
113	$(call Image/Build/DTB,$(2),-initramfs)
114	cp $(KDIR)/uImage-initramfs-$(2) $(BIN_DIR)/$(IMG_PREFIX)-$(2)-initramfs
115  endef
116
117  PROFILES_LIST += $(1)
118endef
119
120# $(1): Profile Name
121# $(2): Sub Profiles list
122define MultiProfile
123  define Image/BuildKernel/Profile/$(1)
124	$(foreach profile, $(2),
125		$(call Image/BuildKernel/Profile/$(profile)))
126  endef
127
128  define Image/Build/Profile/$(1)/BuildSysupgrade
129	$(foreach profile, $(2),
130		$(call Image/Build/Profile/$(profile)/BuildSysupgrade,$$(1)))
131  endef
132
133  define Image/Build/Profile/$(1)/Initramfs
134	$(foreach profile, $(2),
135		$(call Image/Build/Profile/$(profile)/Initramfs))
136  endef
137
138  define Image/Build/Profile/$(1)/squashfs
139	$(foreach profile, $(2),
140		$(call Image/Build/Profile/$(profile)/squashfs))
141  endef
142endef
143
144# Boards with NAND, without subpages
145$(eval $(call NANDProfile,370-DB,armada-370-db,512KiB,4096))
146$(eval $(call NANDProfile,370-RD,armada-370-rd,512KiB,4096))
147$(eval $(call NANDProfile,385-DB-AP,armada-385-db-ap,256KiB,4096))
148$(eval $(call NANDProfile,Mirabox,armada-370-mirabox,512KiB,4096))
149$(eval $(call NANDProfile,XP-DB,armada-xp-db,512KiB,4096))
150$(eval $(call NANDProfile,XP-GP,armada-xp-gp,512KiB,4096))
151
152# Boards with NAND, with subpages
153$(eval $(call NANDProfile,Mamba,armada-xp-linksys-mamba,128KiB,2048,512,2048))
154$(eval $(call NANDProfile,Caiman,armada-385-linksys-caiman,128KiB,2048,512,2048))
155$(eval $(call NANDProfile,Cobra,armada-385-linksys-cobra,128KiB,2048,512,2048))
156$(eval $(call NANDProfile,Rango,armada-385-linksys-rango,128KiB,2048,512,2048))
157$(eval $(call NANDProfile,Shelby,armada-385-linksys-shelby,128KiB,2048,512,2048))
158
159# Boards with large NOR, where we want to use UBI
160$(eval $(call UBINORProfile,OpenBlocks-AX-3-4,armada-xp-openblocks-ax3-4,128KiB))
161
162# Boards with small NOR, where UBI doesn't make sense
163$(eval $(call NORProfile,388-RD,armada-388-rd,256KiB))
164
165$(eval $(call MMCProfile,Solidrun-Clearfog-A1,armada-388-clearfog))
166
167###
168### Linksys
169###
170
171# Caiman: Linksys WRT1200AC
172define Image/Build/Profile/Caiman/squashfs
173	$(call Image/Build/UbinizeImage,armada-385-linksys-caiman,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
174	( \
175		dd if=$(KDIR)/uImage-armada-385-linksys-caiman bs=6144k conv=sync; \
176		dd if=$(KDIR)/$(IMG_PREFIX)-armada-385-linksys-caiman-squashfs-ubinized.bin \
177		bs=2048 conv=sync; \
178	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-385-linksys-caiman-squashfs-factory.img
179endef
180
181# Cobra: Linksys WRT1900ACv2
182define Image/Build/Profile/Cobra/squashfs
183	$(call Image/Build/UbinizeImage,armada-385-linksys-cobra,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
184	( \
185		dd if=$(KDIR)/uImage-armada-385-linksys-cobra bs=6144k conv=sync; \
186		dd if=$(KDIR)/$(IMG_PREFIX)-armada-385-linksys-cobra-squashfs-ubinized.bin \
187		bs=2048 conv=sync; \
188	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-385-linksys-cobra-squashfs-factory.img
189endef
190
191# Mamba: Linksys WRT1900AC
192define Image/Build/Profile/Mamba/squashfs
193	$(call Image/Build/UbinizeImage,armada-xp-linksys-mamba,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
194	( \
195		dd if=$(KDIR)/uImage-armada-xp-linksys-mamba bs=3072k conv=sync; \
196		dd if=$(KDIR)/$(IMG_PREFIX)-armada-xp-linksys-mamba-squashfs-ubinized.bin \
197		bs=2048 conv=sync; \
198	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-xp-linksys-mamba-squashfs-factory.img
199endef
200
201# Shelby: Linksys WRT1900ACS
202define Image/Build/Profile/Shelby/squashfs
203	$(call Image/Build/UbinizeImage,armada-385-linksys-shelby,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
204	( \
205		dd if=$(KDIR)/uImage-armada-385-linksys-shelby bs=6144k conv=sync; \
206		dd if=$(KDIR)/$(IMG_PREFIX)-armada-385-linksys-shelby-squashfs-ubinized.bin \
207		bs=2048 conv=sync; \
208	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-385-linksys-shelby-squashfs-factory.img
209endef
210
211# Rango: Linksys WRT3200ACM
212define Image/Build/Profile/Rango/squashfs
213	$(call Image/Build/UbinizeImage,armada-385-linksys-rango,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
214	( \
215		dd if=$(KDIR)/uImage-armada-385-linksys-rango bs=6144k conv=sync; \
216		dd if=$(KDIR)/$(IMG_PREFIX)-armada-385-linksys-rango-squashfs-ubinized.bin \
217		bs=2048 conv=sync; \
218	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-385-linksys-rango-squashfs-factory.img
219endef
220
221###
222### Marvell
223###
224
225# Marvell Armada 385 Access Point Development board (DB-88F6820-AP)
226define Image/Build/Profile/385-DB-AP/squashfs
227	$(call Image/Build/UbinizeImage,armada-385-db-ap,,squashfs, -p 256KiB -m 4096)
228	( \
229		dd if=$(KDIR)/uImage-armada-385-db-ap bs=8M conv=sync; \
230		dd if=$(KDIR)/$(IMG_PREFIX)-armada-385-db-ap-squashfs-ubinized.bin \
231		bs=4096 conv=sync; \
232	) > $(BIN_DIR)/$(IMG_PREFIX)-armada-385-db-ap-squashfs-factory.img
233endef
234
235
236# The Default profile should build everything
237$(eval $(call MultiProfile,Default,$(PROFILES_LIST)))
238
239define Image/BuildKernel
240	$(call Image/BuildKernel/Profile/$(PROFILE))
241endef
242
243define Image/Build/squashfs
244	# Align the squashfs image size before calling the profiles,
245	# otherwise the size would keep growing
246	$(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
247	$(call Image/Build/Profile/$(PROFILE)/squashfs)
248endef
249
250define Image/Build
251	$(call Image/Build/$(1))
252	$(call Image/Build/Profile/$(PROFILE)/BuildSysupgrade,$(1))
253ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
254	$(call Image/Build/Profile/$(PROFILE)/Initramfs)
255endif
256endef
257
258$(eval $(call BuildImage))
259