Makefile 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 += IMAGE_SIZE DTB_SIZE
  8. define Device/Default
  9. PROFILES := Default
  10. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
  11. DEVICE_DTS :=
  12. KERNEL_ENTRY := 0x00000000
  13. KERNEL_LOADADDR := 0x00000000
  14. DEVICE_DTS_DIR := ../dts
  15. SUPPORTED_DEVICES = $(subst _,$(comma),$(1))
  16. endef
  17. define Build/dtb
  18. $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,[email protected],,--space $(DTB_SIZE))
  19. endef
  20. define Build/prepend-dtb
  21. cat "[email protected]" "$@" > "[email protected]"
  22. mv "[email protected]" "$@"
  23. endef
  24. define Build/export-dtb
  25. cp $(IMAGE_KERNEL).dtb $@
  26. endef
  27. ifeq ($(SUBTARGET),nand)
  28. define Image/cpiogz
  29. ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz )
  30. endef
  31. define Build/copy-file
  32. cat "$(1)" > "$@"
  33. endef
  34. define Build/MerakiAdd-dtb
  35. $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,[email protected])
  36. ( \
  37. dd [email protected] bs=$(DTB_SIZE) conv=sync; \
  38. dd if=$@ bs=$(BLOCKSIZE) conv=sync; \
  39. ) > [email protected]
  40. @mv [email protected] $@
  41. endef
  42. define Build/MerakiAdd-initramfs
  43. $(call Image/cpiogz)
  44. -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T ramdisk \
  45. -C gzip -n "$(PROFILE) rootfs" \
  46. -d $(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz \
  47. $(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz
  48. ( \
  49. dd if=$@ bs=1k conv=sync; \
  50. dd if=$(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz bs=$(BLOCKSIZE) conv=sync; \
  51. ) > [email protected]
  52. @mv [email protected] $@
  53. endef
  54. define Build/MerakiNAND
  55. -$(STAGING_DIR_HOST)/bin/mkmerakifw \
  56. -B $(BOARD_NAME) -s \
  57. -i $@ \
  58. -o [email protected]
  59. @cp [email protected] $@
  60. endef
  61. define Device/meraki_mr24
  62. DEVICE_TITLE := Cisco Meraki MR24
  63. DEVICE_PACKAGES := kmod-spi-gpio -swconfig
  64. BOARD_NAME := mr24
  65. DEVICE_DTS := meraki-mr24
  66. BLOCKSIZE := 63k
  67. IMAGES := sysupgrade.tar
  68. DTB_SIZE := 64512
  69. IMAGE_SIZE := 8191k
  70. KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
  71. KERNEL_INITRAMFS := kernel-bin | lzma | dtb | MuImage-initramfs lzma
  72. IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
  73. UBINIZE_OPTS := -E 5
  74. SUPPORTED_DEVICES += mr24
  75. endef
  76. TARGET_DEVICES += meraki_mr24
  77. define Device/meraki_mx60
  78. DEVICE_TITLE := Cisco Meraki MX60/MX60W
  79. DEVICE_PACKAGES := kmod-spi-gpio kmod-usb-ledtrig-usbport kmod-usb-dwc2 \
  80. kmod-usb-storage block-mount
  81. BOARD_NAME := mx60
  82. DEVICE_DTS := meraki-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 := 2984k
  91. IMAGE_SIZE := 1021m
  92. KERNEL := kernel-bin | gzip | uImage gzip | MerakiAdd-dtb | MerakiNAND
  93. KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | gzip | uImage gzip | \
  94. check-size $$(KERNEL_SIZE) | \
  95. MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
  96. MerakiNAND
  97. IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
  98. UBINIZE_OPTS := -E 5
  99. SUPPORTED_DEVICES += mx60
  100. endef
  101. TARGET_DEVICES += meraki_mx60
  102. define Build/create-uImage-dtb
  103. # flat_dt target expect FIT image - which WNDR4700's uboot doesn't support
  104. -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) \
  105. -O linux -T kernel -C none \
  106. -n '$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' \
  107. -d "[email protected]" "[email protected]"
  108. endef
  109. define Build/MuImage-initramfs
  110. rm -rf [email protected] [email protected]
  111. dd if=/dev/zero [email protected] bs=32 count=1 conv=sync
  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 [email protected]
  121. # 3. The device tree binary which is in [email protected]
  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. -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T multi \
  129. -C $(1) -a $(KERNEL_LOADADDR) -e $(KERNEL_ENTRY) \
  130. -n '$(BOARD_NAME) initramfs' -d $@:[email protected]:[email protected] [email protected]
  131. mv [email protected] $@
  132. rm -rf [email protected]
  133. endef
  134. define Device/netgear_wndr4700
  135. DEVICE_TITLE := Netgear Centria N900 WNDR4700/WNDR4720
  136. DEVICE_PACKAGES := badblocks block-mount e2fsprogs \
  137. kmod-dm kmod-fs-ext4 kmod-fs-vfat kmod-usb-ledtrig-usbport \
  138. kmod-md-mod kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-iso8859-15 \
  139. kmod-nls-utf8 kmod-usb3 kmod-usb-dwc2 kmod-usb-storage \
  140. partx-utils
  141. BOARD_NAME := wndr4700
  142. DEVICE_DTS := netgear-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 := 3584k
  150. # append a fake/empty rootfs to fool netgear's uboot
  151. # CHECK_DNI_FIRMWARE_ROOTFS_INTEGRITY in do_chk_dniimg()
  152. KERNEL := kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
  153. append-uImage-fakehdr filesystem | dtb | create-uImage-dtb | prepend-dtb
  154. KERNEL_INITRAMFS := kernel-bin | gzip | dtb | MuImage-initramfs gzip
  155. IMAGE/factory.img := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi | \
  156. netgear-dni | check-size $$$$(IMAGE_SIZE)
  157. IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
  158. IMAGE/kernel.dtb := export-dtb | uImage none
  159. NETGEAR_BOARD_ID := WNDR4700
  160. NETGEAR_HW_ID := 29763875+128+256
  161. UBINIZE_OPTS := -E 5
  162. SUPPORTED_DEVICES += wndr4700
  163. endef
  164. TARGET_DEVICES += netgear_wndr4700
  165. endif
  166. ifeq ($(SUBTARGET),sata)
  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. [email protected]
  172. endef
  173. define Build/boot-img
  174. $(RM) -rf [email protected]
  175. mkdir -p [email protected]/boot
  176. $(CP) [email protected] [email protected]/boot/boot.scr
  177. $(CP) $(IMAGE_KERNEL).dtb [email protected]/boot/$(DEVICE_DTB)
  178. $(CP) $(IMAGE_KERNEL) [email protected]/boot/uImage
  179. genext2fs --block-size $(BLOCKSIZE:%k=%Ki) --size-in-blocks $$((1024 * $(BOOT_SIZE))) --root [email protected] [email protected]
  180. # convert it to revision 1 - needed for u-boot ext2load
  181. $(STAGING_DIR_HOST)/bin/tune2fs -O filetype [email protected]
  182. $(STAGING_DIR_HOST)/bin/e2fsck -pDf [email protected] > /dev/null
  183. endef
  184. define Build/hdd-img
  185. ./mbl_gen_hdd_img.sh $@ [email protected] $(IMAGE_ROOTFS) $(BOOT_SIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
  186. endef
  187. define Device/wd_mybooklive
  188. DEVICE_TITLE := Western Digital My Book Live Series (Single + Duo)
  189. DEVICE_PACKAGES := kmod-usb-dwc2 kmod-usb-ledtrig-usbport kmod-usb-storage kmod-fs-vfat wpad-mini
  190. DEVICE_DTS := wd-mybooklive
  191. SUPPORTED_DEVICES += mbl wd_mybooklive-duo
  192. BLOCKSIZE := 1k
  193. DTB_SIZE := 16384
  194. KERNEL := kernel-bin | dtb | gzip | uImage gzip
  195. KERNEL_INITRAMFS := kernel-bin | dtb | gzip | uImage gzip
  196. BOOT_SIZE := 8
  197. IMAGES := factory.img.gz kernel.dtb sysupgrade.img.gz
  198. DEVICE_DTB := apollo3g.dtb
  199. FILESYSTEMS := ext4 squashfs
  200. IMAGE/factory.img.gz := boot-script | boot-img | hdd-img | gzip
  201. IMAGE/kernel.dtb := export-dtb
  202. IMAGE/sysupgrade.img.gz := boot-script | boot-img | hdd-img | gzip | append-metadata
  203. endef
  204. TARGET_DEVICES += wd_mybooklive
  205. endif
  206. $(eval $(call BuildImage))