ebc6a051cc671a6749d06f5f53010a7125131e57
[openwrt/openwrt.git] / target / linux / apm821xx / image / Makefile
1 #
2 # This is free software, licensed under the GNU General Public License v2.
3 # See /LICENSE for more information.
4 #
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/image.mk
7
8 DEVICE_VARS += DEVICE_PROFILE IMAGE_SIZE DTB_SIZE
9
10 define Device/Default
11 PROFILES := Default
12 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
13 DEVICE_PROFILE :=
14 DEVICE_DTS :=
15 KERNEL_ENTRY := 0x00000000
16 KERNEL_LOADADDR := 0x00000000
17 DEVICE_DTS_DIR := ../dts
18 endef
19
20 define Build/dtb
21 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb,,--space $(DTB_SIZE))
22 endef
23
24 define Build/export-dtb
25 cp $(IMAGE_KERNEL).dtb $@
26 endef
27
28 ifeq ($(SUBTARGET),nand)
29
30 define Image/cpiogz
31 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz )
32 endef
33
34 define Build/copy-file
35 cat "$(1)" > "$@"
36 endef
37
38 define Build/MerakiAdd-dtb
39 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb)
40 ( \
41 dd if=$@.dtb bs=$(DTB_SIZE) conv=sync; \
42 dd if=$@ bs=$(BLOCKSIZE) conv=sync; \
43 ) > $@.new
44 @mv $@.new $@
45 endef
46
47 define Build/MerakiAdd-initramfs
48 $(call Image/cpiogz)
49
50 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T ramdisk \
51 -C gzip -n "$(PROFILE) rootfs" \
52 -d $(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz \
53 $(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz
54
55 ( \
56 dd if=$@ bs=1k conv=sync; \
57 dd if=$(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz bs=$(BLOCKSIZE) conv=sync; \
58 ) > $@.new
59 @mv $@.new $@
60 endef
61
62 define Build/MerakiNAND
63 -$(STAGING_DIR_HOST)/bin/mkmerakifw \
64 -B $(DEVICE_PROFILE) -s \
65 -i $@ \
66 -o $@.new
67 @cp $@.new $@
68 endef
69
70 define Device/mr24
71 DEVICE_TITLE := Cisco Meraki MR24
72 DEVICE_PACKAGES := kmod-spi-gpio
73 DEVICE_PROFILE := MR24
74 DEVICE_DTS := MR24
75 BLOCKSIZE := 63k
76 IMAGES := sysupgrade.tar
77 DTB_SIZE := 64512
78 KERNEL_SIZE := 1984k
79 IMAGE_SIZE := 8191k
80 KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
81 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
82 check-size $$(KERNEL_SIZE) | \
83 MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
84 MerakiNAND
85 IMAGE/sysupgrade.tar := sysupgrade-tar
86 UBINIZE_OPTS := -E 5
87 endef
88 TARGET_DEVICES += mr24
89
90 define Device/mx60
91 DEVICE_TITLE := Cisco Meraki MX60/MX60W
92 DEVICE_PACKAGES := kmod-spi-gpio kmod-usb-ledtrig-usbport kmod-usb-dwc2 \
93 kmod-usb-storage block-mount
94 DEVICE_PROFILE := MX60
95 DEVICE_DTS := MX60
96 BLOCKSIZE := 63k
97 IMAGES := sysupgrade.tar
98 DTB_SIZE := 64512
99 # The kernel size will need to match the offset defined in mkmerakifw.c,
100 # otherwise the final image will fail to boot. This is set within the
101 # MX60 kernel header definition which is found at
102 # ./tools/firmware-utils/src/mkmerakifw.c, line 103~
103 KERNEL_SIZE := 2984k
104 IMAGE_SIZE := 1021m
105 KERNEL := kernel-bin | gzip | uImage gzip | MerakiAdd-dtb | MerakiNAND
106 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | gzip | uImage gzip | \
107 check-size $$(KERNEL_SIZE) | \
108 MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
109 MerakiNAND
110 IMAGE/sysupgrade.tar := sysupgrade-tar
111 UBINIZE_OPTS := -E 5
112 endef
113 TARGET_DEVICES += mx60
114
115 define Build/create-uImage-dtb
116 # flat_dt target expect FIT image - which WNDR4700's uboot doesn't support
117 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) \
118 -O linux -T kernel -C none \
119 -n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' \
120 -d $(IMAGE_KERNEL).dtb $@.new
121 @mv $@.new $@
122 endef
123
124 define Build/wndr4700-specialImage
125 rm -rf $@.fakerd $@.new
126
127 dd if=/dev/zero of=$@.fakerd bs=32 count=1 conv=sync
128
129 # Netgear used an old uboot that doesn't have FIT support.
130 # So we are stuck with either a full ext2/4 fs in a initrd.
131 # ... or we try to make the "multi" image approach to work
132 # for us.
133 #
134 # Sadly, the "multi" image has to consists of three
135 # "fixed" parts in the following "fixed" order:
136 # 1. The kernel which is in $@
137 # 2. The (fake) initrd which is in $@.fakerd
138 # 3. The device tree binary which is in $@.dtb
139 #
140 # Now, given that we use the function for the kernel which
141 # already has a initramfs image inside, we still have to
142 # add a "fake" initrd (which a mkimage header) in the second
143 # part of the legacy multi image. Since we need to put the
144 # device tree stuff into part 3.
145
146 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T multi \
147 -C $(1) -a $(KERNEL_LOADADDR) -e $(KERNEL_ENTRY) \
148 -n '$(DEVICE_PROFILE) initramfs' -d $@:$@.fakerd:$@.dtb $@.new
149 mv $@.new $@
150 rm -rf $@.fakerd
151 endef
152
153 define Device/WNDR4700
154 DEVICE_TITLE := Netgear Centria N900 WNDR4700/WNDR4720
155 DEVICE_PACKAGES := badblocks block-mount e2fsprogs \
156 kmod-dm kmod-fs-ext4 kmod-fs-vfat kmod-usb-ledtrig-usbport \
157 kmod-md-mod kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-iso8859-15 \
158 kmod-nls-utf8 kmod-usb3 kmod-usb-dwc2 kmod-usb-storage \
159 partx-utils
160 DEVICE_NAME := wndr4700
161 DEVICE_PROFILE := wndr4700
162 DEVICE_DTS := wndr4700
163 PAGESIZE := 2048
164 SUBPAGESIZE := 512
165 BLOCKSIZE := 128k
166 DTB_SIZE := 131008
167 IMAGE_SIZE := 24960k
168 IMAGES := factory.img sysupgrade.tar kernel.dtb
169 KERNEL_SIZE := 1920k
170 KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
171 append-uImage-fakeroot-hdr
172 KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
173 IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
174 netgear-dni | check-size $$$$(IMAGE_SIZE)
175 IMAGE/sysupgrade.tar := sysupgrade-tar
176 IMAGE/kernel.dtb := export-dtb | uImage none
177 NETGEAR_BOARD_ID := WNDR4700
178 NETGEAR_HW_ID := 29763875+128+256
179 UBINIZE_OPTS := -E 5
180 endef
181 TARGET_DEVICES += WNDR4700
182
183 endif
184
185 ifeq ($(SUBTARGET),sata)
186
187 ### Image scripts for the WD My Book Live Series ###
188 define Build/boot-script
189 $(STAGING_DIR_HOST)/bin/mkimage -A powerpc -T script -C none -n "$(PROFILE) Boot Script" \
190 -d mbl_boot.scr \
191 $@.scr
192 endef
193
194 define Build/boot-img
195 $(RM) -rf $@.bootdir
196 mkdir -p $@.bootdir/boot
197
198 $(CP) $@.scr $@.bootdir/boot/boot.scr
199 $(CP) $(IMAGE_KERNEL).dtb $@.bootdir/boot/$(DEVICE_DTB)
200 $(CP) $(IMAGE_KERNEL) $@.bootdir/boot/uImage
201
202 genext2fs --block-size $(BLOCKSIZE:%k=%Ki) --size-in-blocks $$((1024 * $(BOOT_SIZE))) --root $@.bootdir $@.boot
203
204 # convert it to revision 1 - needed for u-boot ext2load
205 $(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
206 $(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
207 endef
208
209 define Build/hdd-img
210 ./mbl_gen_hdd_img.sh $@ $@.boot $(IMAGE_ROOTFS)
211 endef
212
213 define Device/MyBookLiveDefault
214 IMAGE_SIZE := 48m
215 BLOCKSIZE := 1k
216 DTB_SIZE := 16384
217 KERNEL := kernel-bin | dtb | gzip | uImage gzip
218 KERNEL_INITRAMFS := kernel-bin | dtb | gzip | uImage gzip
219 BOOT_SIZE := 8
220 IMAGES := rootfs.img.gz kernel.dtb
221 DEVICE_DTB := apollo3g.dtb
222 FILESYSTEMS := ext4
223 IMAGE/kernel.dtb := export-dtb
224 IMAGE/rootfs.img.gz := boot-script | boot-img | hdd-img | gzip
225 endef
226
227 define Device/MyBookLiveSingle
228 $(Device/MyBookLiveDefault)
229 DEVICE_TITLE := Western Digital My Book Live
230 DEVICE_DTS := apollo3g
231 DEVICE_PROFILE := apollo3g
232 endef
233
234 TARGET_DEVICES += MyBookLiveSingle
235
236 define Device/MyBookLiveDuo
237 $(Device/MyBookLiveDefault)
238 DEVICE_TITLE := Western Digital My Book Live Duo
239 DEVICE_PACKAGES := kmod-usb-dwc2 kmod-usb-ledtrig-usbport kmod-usb-storage kmod-fs-vfat wpad-mini
240 DEVICE_DTS := apollo3g-duo
241 DEVICE_PROFILE := ap2nc
242 endef
243
244 TARGET_DEVICES += MyBookLiveDuo
245
246 endif
247
248 $(eval $(call BuildImage))