Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 CreateStorlinkProlog
  77. # 512 bytes copy routine
  78. dd if=$(KDIR)/copy-kernel-$(2).bin of=$(1)
  79. # Add OpenWrt prolog header (used by partition splitter)
  80. echo "OPENWRT-PROLOG-512" >> $(1)
  81. stat -c %s ${IMAGE_KERNEL} >> $(1)
  82. $(call Image/pad-to,$(1),512)
  83. endef
  84. define CreateStorlinkFactoryfile
  85. mkdir -p [email protected]
  86. $(call CreateStorlinkProlog,[email protected]/zImage,$(2))
  87. # Copy first part of the kernel into zImage
  88. dd if=$(IMAGE_KERNEL) [email protected]/zImage bs=1 seek=512 count=$(3)
  89. $(call Image/pad-to,[email protected]/zImage,128k)
  90. # Put the rest of the kernel into the "ramdisk"
  91. dd if=$(IMAGE_KERNEL) of=$@-ramdisk bs=1 skip=$(3) conv=sync
  92. $(call Image/pad-to,$@-ramdisk,128k)
  93. # Append the root filesystem right after this
  94. dd if=$(IMAGE_ROOTFS) >> $@-ramdisk
  95. $(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >> $@-ramdisk
  96. # Now rd.gz is too big so split off rd.gz and the tail into "hddapp.gz"
  97. dd if=$@-ramdisk [email protected]/rd.gz bs=1 count=6144k conv=sync
  98. dd if=$@-ramdisk [email protected]/hddapp.tgz bs=1 skip=6144k count=6144k conv=sync
  99. rm -f $@-ramdisk
  100. # Taglabel
  101. cp ./ImageInfo-$(1) [email protected]/ImageInfo
  102. sed -i -e "s/DATESTR/`date +%Y%m%d $(if $(SOURCE_DATE_EPOCH),--date "@$(SOURCE_DATE_EPOCH)")`/g" [email protected]/ImageInfo
  103. (cd [email protected]; tar --sort=name --owner=0 --group=0 --numeric-owner -czf $@ * \
  104. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)"))
  105. rm -rf [email protected]
  106. exit 0
  107. endef
  108. define CreateStorlinkSysupgradefile
  109. $(call CreateStorlinkProlog,$@,$(2))
  110. # Catenate the kernel
  111. dd if=$(IMAGE_KERNEL) >> $@
  112. $(call Image/pad-to,$@,128k)
  113. # Append the root filesystem right after this
  114. dd if=$(IMAGE_ROOTFS) >> $@
  115. $(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >> $@
  116. endef
  117. # 2048k "Kern" partition
  118. define Build/storlink-2048k-factory-image
  119. $(call CreateStorlinkFactoryfile,$(1),2048k,2096640)
  120. endef
  121. define Build/storlink-2048k-sysupgrade-image
  122. $(call CreateStorlinkSysupgradefile,$(1),2048k)
  123. endef
  124. # 3072k "Kern" partition
  125. define Build/storlink-3072k-factory-image
  126. $(call CreateStorlinkFactoryfile,$(1),3072k,3145216)
  127. endef
  128. define Build/storlink-3072k-sysupgrade-image
  129. $(call CreateStorlinkSysupgradefile,$(1),3072k)
  130. endef
  131. # WBD-111 and WBD-222:
  132. # work around the bootloader's bug with extra nops
  133. # FIXME: is this really needed now that we no longer append the code
  134. # to change the machine ID number? Needs testing on Wiliboard.
  135. define Build/wbd-nops
  136. mv $@ [email protected]
  137. echo -en "\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1" > $@
  138. cat [email protected] >> $@
  139. rm -f [email protected]
  140. endef
  141. # All DTB files are prefixed with "gemini-"
  142. define Device/Default
  143. PROFILES := Default
  144. DEVICE_DTS_DIR = $$(DTS_DIR)/gemini
  145. KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
  146. KERNEL_NAME := zImage
  147. KERNEL := kernel-bin | append-dtb
  148. BLOCKSIZE := 128k
  149. endef
  150. # A reasonable set of default packages handling the NAS type
  151. # of devices out of the box (former NAS42x0 IcyBox defaults)
  152. GEMINI_NAS_PACKAGES := $(DEFAULT_PACKAGES.nas) \
  153. kmod-md-mod kmod-md-linear \
  154. kmod-md-raid0 kmod-md-raid1 kmod-md-raid10 kmod-md-raid456 \
  155. kmod-fs-btrfs kmod-fs-cifs kmod-fs-nfs \
  156. kmod-fs-nfsd kmod-fs-ntfs3 kmod-fs-reiserfs kmod-fs-vfat \
  157. kmod-nls-utf8 kmod-usb-storage-extras kmod-hwmon-drivetemp \
  158. cfdisk e2fsprogs badblocks \
  159. partx-utils
  160. # The DIR-685 flash layout is kernel in WRGG format, padded and followed
  161. # by the appended rootfs followed by some reasonable JFFS padding, the
  162. # remainder will be used by JFFS2 through overlayfs.
  163. #
  164. # - For the factory image, the WRGG image includes the rootfs so that the
  165. # default firmware will flash it properly as all it knows is WRGG format.
  166. # - For the sysupgrade, we do not include the rootfs in the kernel image
  167. # so it is not needelessly tossed into the RAM by the boot loader.
  168. # This will be flashed from OpenWrt userland anyways so we only need
  169. # the minimum to make the boot loader happy.
  170. define Device/dlink_dir-685
  171. DEVICE_VENDOR := D-Link
  172. DEVICE_MODEL := DIR-685 Xtreme N Storage Router
  173. DEVICE_DTS := gemini-dlink-dir-685
  174. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) \
  175. kmod-dsa-rtl8366rb
  176. IMAGES := factory.bin sysupgrade.bin
  177. # Pad to 128k erase blocks with 160 bytes WRGG header
  178. IMAGE/factory.bin := append-kernel | pad-offset 128k 160 | append-rootfs | dir685-pad-rootfs | dir685-image
  179. IMAGE/sysupgrade.bin := append-kernel | pad-offset 128k 160 | dir685-image | append-rootfs | dir685-pad-rootfs | append-metadata
  180. endef
  181. TARGET_DEVICES += dlink_dir-685
  182. define Device/dlink_dns-313
  183. DEVICE_VENDOR := D-Link
  184. DEVICE_MODEL := DNS-313 1-Bay Network Storage Enclosure
  185. DEVICE_DTS := gemini-dlink-dns-313
  186. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) usbgadget-acm
  187. BLOCKSIZE := 1k
  188. FILESYSTEMS := ext4
  189. IMAGES := factory.bin.gz
  190. IMAGE/factory.bin.gz := dns313-images | gzip
  191. endef
  192. TARGET_DEVICES += dlink_dns-313
  193. # Default images setup used by the StorLink reference designs
  194. define Device/storlink-reference
  195. COMPILE := copy-kernel-$(1).bin
  196. COMPILE/copy-kernel-$(1).bin := copy-kernel.bin
  197. IMAGES := factory.bin sysupgrade.bin
  198. FILESYSTEMS := squashfs
  199. DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
  200. endef
  201. define Device/itian_sq201
  202. $(Device/storlink-reference)
  203. DEVICE_VENDOR := ITian
  204. DEVICE_MODEL := Square One SQ201
  205. DEVICE_DTS := gemini-sq201
  206. IMAGE/factory.bin := storlink-2048k-factory-image $(1)
  207. IMAGE/sysupgrade.bin := storlink-2048k-sysupgrade-image $(1) |\
  208. append-metadata
  209. DEVICE_PACKAGES += kmod-rt61-pci kmod-usb2-pci kmod-dsa-vsc73xx-spi
  210. endef
  211. TARGET_DEVICES += itian_sq201
  212. define Device/raidsonic_ib-4210-b
  213. $(Device/storlink-reference)
  214. DEVICE_VENDOR := Raidsonic
  215. DEVICE_MODEL := NAS IB-4210-B
  216. DEVICE_DTS := gemini-nas4210b
  217. IMAGE/factory.bin := storlink-3072k-factory-image $(1)
  218. IMAGE/sysupgrade.bin := storlink-3072k-sysupgrade-image $(1) |\
  219. append-metadata
  220. endef
  221. TARGET_DEVICES += raidsonic_ib-4210-b
  222. define Device/raidsonic_ib-4220-b
  223. $(Device/storlink-reference)
  224. DEVICE_VENDOR := Raidsonic
  225. DEVICE_MODEL := NAS IB-4220-B
  226. DEVICE_DTS := gemini-nas4220b
  227. IMAGE/factory.bin := storlink-3072k-factory-image $(1)
  228. IMAGE/sysupgrade.bin := storlink-3072k-sysupgrade-image $(1) |\
  229. append-metadata
  230. endef
  231. TARGET_DEVICES += raidsonic_ib-4220-b
  232. define Device/storlink_sl93512r
  233. $(Device/storlink-reference)
  234. DEVICE_VENDOR := StorLink
  235. DEVICE_MODEL := SL93512r
  236. DEVICE_DTS := gemini-sl93512r
  237. IMAGE/factory.bin := storlink-3072k-factory-image $(1)
  238. IMAGE/sysupgrade.bin := storlink-3072k-sysupgrade-image $(1) |\
  239. append-metadata
  240. DEVICE_PACKAGES += kmod-dsa-vsc73xx-spi
  241. endef
  242. TARGET_DEVICES += storlink_sl93512r
  243. define Device/verbatim_s08v1901_d1
  244. $(Device/storlink-reference)
  245. DEVICE_VENDOR := Verbatim
  246. DEVICE_MODEL := S08V1901-D1 (Gigabit Ethernet Hard Drive)
  247. DEVICE_DTS := gemini-verbatim-s08v1901-d1
  248. IMAGE/factory.bin := storlink-3072k-factory-image $(1)
  249. IMAGE/sysupgrade.bin := storlink-3072k-sysupgrade-image $(1) |\
  250. append-metadata
  251. endef
  252. TARGET_DEVICES += verbatim_s08v1901_d1
  253. # The wiliboard images need some changes to be functional and buildable.
  254. #
  255. # The dts would need to use the redboot-fis partition parser to get
  256. # the correct partition offsets and size.
  257. #
  258. # The mkfwimage2 call need to be adjusted to reflect the real size of kernel
  259. # and rootfs. It is expected that the OEM firmware adjusts the on flash
  260. # partition table with the values defined in the image header.
  261. define Device/wiliboard_wbd111
  262. DEVICE_VENDOR := Wiliboard
  263. DEVICE_MODEL := WBD-111
  264. DEVICE_DTS := gemini-wbd111
  265. KERNEL := kernel-bin | append-dtb | wbd-nops
  266. IMAGES := factory.bin
  267. IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WILIBOARD"
  268. endef
  269. define Device/wiliboard_wbd222
  270. DEVICE_VENDOR := Wiliboard
  271. DEVICE_MODEL := WBD-222
  272. DEVICE_DTS := gemini-wbd222
  273. KERNEL := kernel-bin | append-dtb | wbd-nops
  274. IMAGES := factory.bin
  275. IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WBD222"
  276. endef
  277. $(eval $(call BuildImage))