Makefile 7.7 KB

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