Makefile 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2009-2018 OpenWrt.org
  4. include $(TOPDIR)/rules.mk
  5. include $(INCLUDE_DIR)/image.mk
  6. define Build/copy-kernel.bin
  7. $(call locked,$(MAKE) -C copy-kernel CROSS_COMPILE=$(TARGET_CROSS) O=$(KDIR),gemini-copy-kernel.bin)
  8. endef
  9. # Cook a "WRGG" image, this board is apparently one in the D-Link
  10. # WRGG family and uses the exact same firmware format as other
  11. # D-Link devices.
  12. define Build/dir685-image
  13. mkwrggimg -i $@ \
  14. -o [email protected] \
  15. -d /dev/mtdblock/1 \
  16. -s wrgns01_dlwbr_dir685RBWW \
  17. -v 'N/A' \
  18. -m dir685 \
  19. -B 96bb
  20. mv [email protected] $@
  21. endef
  22. # Padding added after the rootfs to an even 128k boundary
  23. # as this is 128k eraseblocks flash.
  24. define Build/dir685-pad-rootfs
  25. $(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >>$@
  26. endef
  27. # Build D-Link DNS-313 images using the special header tool.
  28. # rootfs.tgz and rd.tgz contains nothing, we only need them
  29. # to satisfy the boot loader on the device. The zImage is
  30. # the only real content.
  31. define Build/dns313-images
  32. mkdir -p [email protected]/.boot
  33. chmod 755 [email protected]/.boot
  34. echo "dummy" > [email protected]/dummyfile
  35. dns313-header [email protected]/dummyfile \
  36. [email protected]/.boot/rootfs.tgz
  37. dns313-header [email protected]/dummyfile \
  38. [email protected]/.boot/rd.gz
  39. dns313-header $(IMAGE_KERNEL) \
  40. [email protected]/.boot/zImage
  41. rm [email protected]/dummyfile
  42. genext2fs --block-size $(BLOCKSIZE:%k=%Ki) \
  43. --size-in-blocks $$((1024 * $(CONFIG_TARGET_KERNEL_PARTSIZE))) \
  44. --squash-uids \
  45. --root [email protected] [email protected]
  46. # The device firmware needs revision 1 of EXT2
  47. tune2fs -O filetype [email protected]
  48. e2fsck -pDf [email protected] > /dev/null
  49. ./dns313_gen_hdd_img.sh $@ [email protected] $(IMAGE_ROOTFS) \
  50. $(CONFIG_TARGET_KERNEL_PARTSIZE) \
  51. $(CONFIG_TARGET_ROOTFS_PARTSIZE)
  52. rm -rf [email protected]
  53. endef
  54. define Build/wiligear-image
  55. $(STAGING_DIR_HOST)/bin/mkfwimage2 \
  56. -m GEOS -f 0x30000000 -z \
  57. -v $(1).v5.00.SL3512.OpenWrt.00000.000000.000000 \
  58. -p Kernel:0x020000:0x100000:0:0:$(IMAGE_KERNEL) \
  59. -p Ramdisk:0x120000:0x500000:0:0:$@ \
  60. -o [email protected]
  61. mv [email protected] $@
  62. endef
  63. # Create the default image format used by the StorLink reference design
  64. # SL93512r, Raidsonic NAS4220B and Itian Square One SQ201
  65. # with the squashfs and overlay inside the "application" partition.
  66. #
  67. # These devices have a hard-coded partition table that the boot loader
  68. # constantly reflashes back, so we need to work around it like this:
  69. #
  70. # 0x000000120000-0x000000320000 : "Kern" - small copy routine and first
  71. # part of the kernel goes here
  72. # 0x000000320000-0x000000920000 : "Ramdisk" - second part of the kernel and
  73. # some padding goes here
  74. # 0x000000920000-0x000000f20000 : "Application" - rootfs goes here
  75. define Build/storlink-default-images
  76. mkdir -p [email protected]
  77. # "App" partition is the rootfs
  78. mv $@ [email protected]/hddapp.tgz
  79. # 256 bytes copy routine
  80. dd if=$(KDIR)/copy-kernel.bin [email protected]/zImage
  81. $(call Image/pad-to,[email protected]/zImage,512)
  82. # Copy first part of the kernel into zImage
  83. dd if=$(IMAGE_KERNEL) [email protected]/zImage bs=1 seek=512 count=2096640
  84. # Put the rest of the kernel into the "ramdisk"
  85. dd if=$(IMAGE_KERNEL) [email protected]/rd.gz bs=1 skip=2096640 count=6144k conv=sync
  86. cp ./ImageInfo-$(1) [email protected]/ImageInfo
  87. sed -i -e "s/DATESTR/`date +%Y%m%d $(if $(SOURCE_DATE_EPOCH),--date "@$(SOURCE_DATE_EPOCH)")`/g" [email protected]/ImageInfo
  88. (cd [email protected]; tar --sort=name --owner=0 --group=0 --numeric-owner -czf $@ * \
  89. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)"))
  90. rm -rf [email protected]
  91. endef
  92. # WBD-111 and WBD-222:
  93. # work around the bootloader's bug with extra nops
  94. # FIXME: is this really needed now that we no longer append the code
  95. # to change the machine ID number? Needs testing on Wiliboard.
  96. define Build/wbd-nops
  97. mv $@ [email protected]
  98. echo -en "\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1" > $@
  99. cat [email protected] >> $@
  100. rm -f [email protected]
  101. endef
  102. # All DTB files are prefixed with "gemini-"
  103. define Device/Default
  104. PROFILES := Default
  105. KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
  106. KERNEL_NAME := zImage
  107. KERNEL := kernel-bin | append-dtb
  108. BLOCKSIZE := 128k
  109. endef
  110. # A reasonable set of default packages handling the NAS type
  111. # of devices out of the box (former NAS42x0 IcyBox defaults)
  112. GEMINI_NAS_PACKAGES := $(DEFAULT_PACKAGES.nas) \
  113. kmod-md-mod kmod-md-linear kmod-md-multipath \
  114. kmod-md-raid0 kmod-md-raid1 kmod-md-raid10 kmod-md-raid456 \
  115. kmod-fs-btrfs kmod-fs-cifs kmod-fs-nfs \
  116. kmod-fs-nfsd kmod-fs-ntfs kmod-fs-reiserfs kmod-fs-vfat \
  117. kmod-nls-utf8 kmod-usb-storage-extras kmod-hwmon-drivetemp \
  118. cfdisk e2fsprogs badblocks \
  119. partx-utils
  120. # The DIR-685 flash layout is kernel in WRGG format, padded and followed
  121. # by the appended rootfs followed by some reasonable JFFS padding, the
  122. # remainder will be used by JFFS2 through overlayfs.
  123. #
  124. # - For the factory image, the WRGG image includes the rootfs so that the
  125. # default firmware will flash it properly as all it knows is WRGG format.
  126. # - For the sysupgrade, we do not include the rootfs in the kernel image
  127. # so it is not needelessly tossed into the RAM by the boot loader.
  128. # This will be flashed from OpenWrt userland anyways so we only need
  129. # the minimum to make the boot loader happy.
  130. define Device/dlink_dir-685
  131. DEVICE_VENDOR := D-Link
  132. DEVICE_MODEL := DIR-685 Xtreme N Storage Router
  133. DEVICE_DTS := gemini-dlink-dir-685
  134. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) \
  135. kmod-rt2800-pci
  136. IMAGES := factory.bin sysupgrade.bin
  137. # Pad to 128k erase blocks with 160 bytes WRGG header
  138. IMAGE/factory.bin := append-kernel | pad-offset 128k 160 | append-rootfs | dir685-pad-rootfs | dir685-image
  139. IMAGE/sysupgrade.bin := append-kernel | pad-offset 128k 160 | dir685-image | append-rootfs | dir685-pad-rootfs | append-metadata
  140. endef
  141. TARGET_DEVICES += dlink_dir-685
  142. define Device/dlink_dns-313
  143. DEVICE_VENDOR := D-Link
  144. DEVICE_MODEL := DNS-313 1-Bay Network Storage Enclosure
  145. DEVICE_DTS := gemini-dlink-dns-313
  146. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
  147. BLOCKSIZE := 1k
  148. FILESYSTEMS := ext4
  149. IMAGES := factory.bin.gz
  150. IMAGE/factory.bin.gz := dns313-images | gzip
  151. endef
  152. TARGET_DEVICES += dlink_dns-313
  153. # Default images setup used by the StorLink reference designs
  154. define Device/storlink-reference
  155. COMPILE := copy-kernel-$(1).bin
  156. COMPILE/copy-kernel-$(1).bin := copy-kernel.bin
  157. IMAGES := factory.bin
  158. FILESYSTEMS := squashfs
  159. IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 6144k | \
  160. storlink-default-images $(1)
  161. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
  162. endef
  163. define Device/itian_sq201
  164. $(Device/storlink-reference)
  165. DEVICE_VENDOR := ITian
  166. DEVICE_MODEL := Square One SQ201
  167. DEVICE_DTS := gemini-sq201
  168. DEVICE_PACKAGES += kmod-rt61-pci kmod-usb2-pci
  169. endef
  170. TARGET_DEVICES += itian_sq201
  171. define Device/raidsonic_ib-4220-b
  172. $(Device/storlink-reference)
  173. DEVICE_VENDOR := Raidsonic
  174. DEVICE_MODEL := NAS IB-4220-B
  175. DEVICE_DTS := gemini-nas4220b
  176. endef
  177. TARGET_DEVICES += raidsonic_ib-4220-b
  178. define Device/storlink_sl93512r
  179. $(Device/storlink-reference)
  180. DEVICE_VENDOR := StorLink
  181. DEVICE_MODEL := SL93512r
  182. DEVICE_DTS := gemini-sl93512r
  183. endef
  184. TARGET_DEVICES += storlink_sl93512r
  185. # The wiliboard images need some changes to be functional and buildable.
  186. #
  187. # The dts would need to use the redboot-fis partition parser to get
  188. # the correct partition offsets and size.
  189. #
  190. # The mkfwimage2 call need to be adjusted to reflect the real size of kernel
  191. # and rootfs. It is expected that the OEM firmware adjusts the on flash
  192. # partition table with the values defined in the image header.
  193. define Device/wiliboard_wbd111
  194. DEVICE_VENDOR := Wiliboard
  195. DEVICE_MODEL := WBD-111
  196. DEVICE_DTS := gemini-wbd111
  197. KERNEL := kernel-bin | append-dtb | wbd-nops
  198. IMAGES := factory.bin
  199. IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WILIBOARD"
  200. endef
  201. define Device/wiliboard_wbd222
  202. DEVICE_VENDOR := Wiliboard
  203. DEVICE_MODEL := WBD-222
  204. DEVICE_DTS := gemini-wbd222
  205. KERNEL := kernel-bin | append-dtb | wbd-nops
  206. IMAGES := factory.bin
  207. IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WBD222"
  208. endef
  209. $(eval $(call BuildImage))