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