da7d2174e5965d317d52cb9c01bd34a702b87e8d
[openwrt/openwrt.git] / target / linux / mvebu / image / Makefile
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 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
9
10 LOADADDR:=0x00008000
11
12 JFFS2_BLOCKSIZE = 128k
13
14 KDIR_TMP:=$(KDIR)/tmp
15
16
17 UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage
18
19 define Image/Build/DTB
20 cp $(KDIR)/zImage$(2) $(KDIR)/zImage$(2)-$(1);
21 cat $(DTS_DIR)/$(1).dtb >> $(KDIR)/zImage$(2)-$(1);
22 $(call Image/BuildKernel/MkuImage, \
23 none, $(LOADADDR), $(LOADADDR), \
24 $(KDIR)/zImage$(2)-$(1), $(KDIR)/uImage$(2)-$(1))
25 # The next line will be dropped, migrate your board to use a single firmware file
26 cp $(KDIR)/uImage$(2)-$(1) $(UIMAGE)$(2)-$(1);
27 endef
28
29 # $(1): Profile Name
30 # $(2): DTB Name
31 # $(3): Erase Block Size
32 # $(4): Page Size
33 # $(5): Sub-Page Size (optional)
34 # $(6): VID offset (optional)
35 define NANDProfile
36 define Image/BuildKernel/Profile/$(1)
37 $(call Image/Build/DTB,$(2))
38 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
39 $(call Image/Build/Profile,$(1)/Initramfs)
40 endif
41 endef
42
43 define Image/Build/Profile/$(1)/BuildSysupgrade
44 $(call Image/Build/SysupgradeNAND,$(2),$$(1),$(KDIR)/uImage-$(2))
45 endef
46
47 define Image/Build/Profile/$(1)/Initramfs
48 $(call Image/Build/DTB,$(2),-initramfs)
49 endef
50
51 define Image/Build/Profile/$(1)/squashfs
52 $(call Image/Build/UbinizeImage,$(2),,squashfs, -p $(3) -m $(4) $(if $(5),-s $(5)) $(if $(6),-O $(6)))
53 # The next line will be dropped, migrate your board to use a single firmware file
54 cp $(KDIR)/$$(IMG_PREFIX)-$(2)-squashfs-ubinized.bin $(BIN_DIR)
55 endef
56
57 PROFILES_LIST += $(1)
58 endef
59
60 # $(1): Profile Name
61 # $(2): DTB Name
62 # $(3): Erase Block Size
63 define UBINORProfile
64 define Image/BuildKernel/Profile/$(1)
65 $(call Image/Build/DTB,$(2))
66 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
67 $(call Image/Build/Profile,$(1)/Initramfs)
68 endif
69 endef
70
71 define Image/Build/Profile/$(1)/Initramfs
72 $(call Image/Build/DTB,$(2),-initramfs)
73 endef
74
75 define Image/Build/Profile/$(1)/squashfs
76 $(call Image/Build/UbinizeImage,$(2),,squashfs, -p $(3) -m 1)
77 endef
78
79 PROFILES_LIST += $(1)
80 endef
81
82 # $(1): Profile Name
83 # $(2): DTB Name
84 # $(3): Erase Block Size
85 define NORProfile
86 define Image/BuildKernel/Profile/$(1)
87 $(call Image/Build/DTB,$(2))
88 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
89 $(call Image/Build/Profile,$(1)/Initramfs)
90 endif
91 endef
92
93 define Image/Build/Profile/$(1)/Initramfs
94 $(call Image/Build/DTB,$(2),-initramfs)
95 endef
96
97 define Image/Build/Profile/$(1)/squashfs
98 ( \
99 dd if=$(KDIR)/uImage-$(2) bs=$(3) conv=sync; \
100 dd if=$(KDIR)/root.squashfs bs=$(3) conv=sync; \
101 ) > $$(BIN_DIR)/$$(IMG_PREFIX)-$(2)-squashfs-firmware.bin
102 endef
103
104 PROFILES_LIST += $(1)
105 endef
106
107 # $(1): Profile Name
108 # $(2): Sub Profiles list
109 define MultiProfile
110 define Image/BuildKernel/Profile/$(1)
111 $(foreach profile, $(2),
112 $(call Image/BuildKernel/Profile/$(profile)))
113 endef
114
115 define Image/Build/Profile/$(1)/BuildSysupgrade
116 $(foreach profile, $(2),
117 $(call Image/Build/Profile/$(profile)/BuildSysupgrade,$$(1)))
118 endef
119
120 define Image/Build/Profile/$(1)/Initramfs
121 $(foreach profile, $(2),
122 $(call Image/Build/Profile/$(profile)/Initramfs))
123 endef
124
125 define Image/Build/Profile/$(1)/squashfs
126 $(foreach profile, $(2),
127 $(call Image/Build/Profile/$(profile)/squashfs))
128 endef
129 endef
130
131 # Boards with NAND, without subpages
132 $(eval $(call NANDProfile,370-DB,armada-370-db,512KiB,4096))
133 $(eval $(call NANDProfile,370-RD,armada-370-rd,512KiB,4096))
134 $(eval $(call NANDProfile,385-DB-AP,armada-385-db-ap,256KiB,4096))
135 $(eval $(call NANDProfile,Mirabox,armada-370-mirabox,512KiB,4096))
136 $(eval $(call NANDProfile,XP-DB,armada-xp-db,512KiB,4096))
137 $(eval $(call NANDProfile,XP-GP,armada-xp-gp,512KiB,4096))
138
139 # Boards with NAND, with subpages
140 $(eval $(call NANDProfile,Mamba,armada-xp-mamba,128KiB,2048,512,2048))
141
142 # Boards with large NOR, where we want to use UBI
143 $(eval $(call UBINORProfile,OpenBlocks-AX-3-4,armada-xp-openblocks-ax3-4,128KiB))
144
145 # Boards with small NOR, where UBI doesn't make sense
146 $(eval $(call NORProfile,385-RD,armada-385-rd,256KiB))
147
148 define Image/Build/Profile/Mamba/squashfs
149 $(call Image/Build/UbinizeImage,armada-xp-mamba,,squashfs, -p 128KiB -m 2048 -s 512 -O 2048)
150 ( \
151 dd if=$(KDIR)/uImage-armada-xp-mamba bs=3072k conv=sync; \
152 dd if=$(KDIR)/$(IMG_PREFIX)-armada-xp-mamba-squashfs-ubinized.bin \
153 bs=2048 conv=sync; \
154 ) > $(BIN_DIR)/$(IMG_PREFIX)-armada-xp-mamba-squashfs-factory.img
155 endef
156
157 # The Default profile should build everything
158 $(eval $(call MultiProfile,Default,$(PROFILES_LIST)))
159
160 define Image/BuildKernel
161 $(call Image/BuildKernel/Profile/$(PROFILE))
162 endef
163
164 define Image/Build/squashfs
165 # Align the squashfs image size before calling the profiles,
166 # otherwise the size would keep growing
167 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
168 $(call Image/Build/Profile/$(PROFILE)/squashfs)
169 endef
170
171 define Image/Build
172 $(call Image/Build/$(1))
173 # The next line will be dropped, migrate your board to use a single firmware file
174 dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
175 $(call Image/Build/Profile/$(PROFILE)/BuildSysupgrade,$(1))
176 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
177 $(call Image/Build/Profile/$(PROFILE)/Initramfs)
178 endif
179 endef
180
181 $(eval $(call BuildImage))