Makefile 8.0 KB

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