2 # This is free software, licensed under the GNU General Public License v2.
3 # See /LICENSE for more information.
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/image.mk
7 include $(INCLUDE_DIR)/host.mk
9 DEVICE_VARS += DEVICE_PROFILE IMAGE_SIZE DTB_SIZE
13 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
16 KERNEL_ENTRY := 0x00000000
17 KERNEL_LOADADDR := 0x00000000
18 DEVICE_DTS_DIR := ../dts
22 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb,,--space $(DTB_SIZE))
25 define Build/export-dtb
26 cp $(IMAGE_KERNEL).dtb $@
29 ifeq ($(SUBTARGET),nand)
32 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz )
35 define Build/copy-file
39 define Build/MerakiAdd-dtb
40 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb)
42 dd if=$@.dtb bs=$(DTB_SIZE) conv=sync; \
43 dd if=$@ bs=$(BLOCKSIZE) conv=sync; \
48 define Build/MerakiAdd-initramfs
51 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T ramdisk \
52 -C gzip -n "$(PROFILE) rootfs" \
53 -d $(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz \
54 $(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz
57 dd if=$@ bs=1k conv=sync; \
58 dd if=$(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz bs=$(BLOCKSIZE) conv=sync; \
63 define Build/MerakiNAND
64 -$(STAGING_DIR_HOST)/bin/mkmerakifw \
65 -B $(DEVICE_PROFILE) -s \
72 DEVICE_TITLE := Cisco Meraki MR24
73 DEVICE_PACKAGES := kmod-spi-gpio kmod-ath9k wpad-mini
74 DEVICE_PROFILE := MR24
77 IMAGES := sysupgrade.tar
81 KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
82 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
83 check-size $$(KERNEL_SIZE) | \
84 MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
86 IMAGE/sysupgrade.tar := sysupgrade-tar
89 TARGET_DEVICES += mr24
92 DEVICE_TITLE := Cisco Meraki MX60
93 DEVICE_PACKAGES := kmod-spi-gpio swconfig kmod-usb-ledtrig-usbport \
94 kmod-usb-dwc2 kmod-usb-storage block-mount
95 DEVICE_PROFILE := MX60
98 IMAGES := sysupgrade.tar
100 # The kernel size will need to match the offset defined in mkmerakifw.c,
101 # otherwise the final image will fail to boot. This is set within the
102 # MX60 kernel header definition which is found at
103 # ./tools/firmware-utils/src/mkmerakifw.c, line 103~
106 KERNEL := kernel-bin | gzip | uImage gzip | MerakiAdd-dtb | MerakiNAND
107 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | gzip | uImage gzip | \
108 check-size $$(KERNEL_SIZE) | \
109 MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
111 IMAGE/sysupgrade.tar := sysupgrade-tar
114 TARGET_DEVICES += mx60
118 DEVICE_TITLE := Cisco Meraki MX60W
119 DEVICE_PACKAGES += kmod-ath9k wpad-mini
121 TARGET_DEVICES += mx60w
123 define Build/create-uImage-dtb
124 # flat_dt target expect FIT image - which WNDR4700's uboot doesn't support
125 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) \
126 -O linux -T kernel -C none \
127 -n '$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION)' \
128 -d $(IMAGE_KERNEL).dtb $@.new
132 define Build/append-fakerootfs
133 rm -rf $@.fakerootsquashfs $@.fakefs
135 # append a fake/empty rootfs to fool netgear's uboot
136 # CHECK_DNI_FIRMWARE_ROOTFS_INTEGRITY in do_chk_dniimg()
137 dd if=/dev/zero of=$@.fakerd bs=16 count=1 conv=sync
139 -$(STAGING_DIR_HOST)/bin/mkimage \
140 -A $(LINUX_KARCH) -O linux -T filesystem -C none \
141 -a 0x00000000 -e 0x00000000 \
142 -n '$(DEVICE_PROFILE) fakerootfs' \
143 -d $@.fakerd $@.fakefs
146 rm -rf $@.fakerootsquashfs $@.fakefs
149 define Build/wndr4700-specialImage
150 rm -rf $@.fakerd $@.new
152 dd if=/dev/zero of=$@.fakerd bs=32 count=1 conv=sync
154 # Netgear used an old uboot that doesn't have FIT support.
155 # So we are stuck with either a full ext2/4 fs in a initrd.
156 # ... or we try to make the "multi" image approach to work
159 # Sadly, the "multi" image has to consists of three
160 # "fixed" parts in the following "fixed" order:
161 # 1. The kernel which is in $@
162 # 2. The (fake) initrd which is in $@.fakerd
163 # 3. The device tree binary which is in $@.dtb
165 # Now, given that we use the function for the kernel which
166 # already has a initramfs image inside, we still have to
167 # add a "fake" initrd (which a mkimage header) in the second
168 # part of the legacy multi image. Since we need to put the
169 # device tree stuff into part 3.
171 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T multi \
172 -C $(1) -a $(KERNEL_LOADADDR) -e $(KERNEL_ENTRY) \
173 -n '$(DEVICE_PROFILE) initramfs' -d $@:$@.fakerd:$@.dtb $@.new
178 define Device/WNDR4700
179 DEVICE_TITLE := Netgear Centria N900 WNDR4700/WNDR4720
180 DEVICE_PACKAGES := badblocks block-mount e2fsprogs \
181 kmod-ath9k kmod-dm kmod-fs-ext4 kmod-fs-vfat kmod-usb-ledtrig-usbport \
182 kmod-md-mod kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-iso8859-15 \
183 kmod-nls-utf8 kmod-usb3 kmod-usb-dwc2 kmod-usb-storage \
184 partx-utils swconfig wpad-mini
185 DEVICE_NAME := wndr4700
186 DEVICE_PROFILE := wndr4700
187 DEVICE_DTS := wndr4700
193 IMAGES := factory.img sysupgrade.tar kernel.dtb
195 KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | append-fakerootfs
196 KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
197 IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
198 netgear-dni | check-size $$$$(IMAGE_SIZE)
199 IMAGE/sysupgrade.tar := sysupgrade-tar
200 IMAGE/kernel.dtb := export-dtb | uImage none
201 NETGEAR_BOARD_ID := WNDR4700
202 NETGEAR_HW_ID := 29763875+128+256
205 TARGET_DEVICES += WNDR4700
209 ifeq ($(SUBTARGET),sata)
211 ### Image scripts for the WD My Book Live Series ###
212 define Build/boot-script
213 $(STAGING_DIR_HOST)/bin/mkimage -A powerpc -T script -C none -n "$(PROFILE) Boot Script" \
218 define Build/boot-img
220 mkdir -p $@.bootdir/boot
222 $(CP) $@.scr $@.bootdir/boot/boot.scr
223 $(CP) $(IMAGE_KERNEL).dtb $@.bootdir/boot/$(DEVICE_DTB)
224 $(CP) $(IMAGE_KERNEL) $@.bootdir/boot/uImage
226 genext2fs --block-size $(BLOCKSIZE:%k=%Ki) --size-in-blocks $$((1024 * $(BOOT_SIZE))) --root $@.bootdir $@.boot
228 # convert it to revision 1 - needed for u-boot ext2load
229 $(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
230 $(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
234 ./mbl_gen_hdd_img.sh $@ $@.boot $(IMAGE_ROOTFS)
235 $(if $(CONFIG_TARGET_IMAGES_GZIP),gzip -9n -c $@ > $(BIN_DIR)/$(notdir $@).gz)
238 define Device/MyBookLiveDefault
242 KERNEL := kernel-bin | dtb | gzip | uImage gzip
243 KERNEL_INITRAMFS := kernel-bin | dtb | gzip | uImage gzip
245 IMAGES := rootfs.img kernel.dtb
246 DEVICE_DTB := apollo3g.dtb
248 IMAGE/kernel.dtb := export-dtb
249 IMAGE/rootfs.img := boot-script | boot-img | hdd-img
252 define Device/MyBookLiveSingle
253 $(Device/MyBookLiveDefault)
254 DEVICE_TITLE := Western Digital My Book Live
255 DEVICE_DTS := apollo3g
256 DEVICE_PROFILE := apollo3g
259 TARGET_DEVICES += MyBookLiveSingle
261 define Device/MyBookLiveDuo
262 $(Device/MyBookLiveDefault)
263 DEVICE_TITLE := Western Digital My Book Live Duo
264 DEVICE_PACKAGES := kmod-usb-dwc2 kmod-usb-ledtrig-usbport kmod-usb-storage kmod-fs-vfat wpad-mini
265 DEVICE_DTS := apollo3g-duo
266 DEVICE_PROFILE := ap2nc
269 TARGET_DEVICES += MyBookLiveDuo
273 $(eval $(call BuildImage))