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