Makefile 7.2 KB

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