Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2016 OpenWrt.org
  4. include $(TOPDIR)/rules.mk
  5. include $(INCLUDE_DIR)/image.mk
  6. USB1_PACKAGES := kmod-usb-ohci
  7. USB2_PACKAGES := $(USB1_PACKAGES) kmod-usb2
  8. define Build/Clean
  9. $(MAKE) -C lzma-loader clean
  10. endef
  11. define Image/Prepare
  12. # Optimized LZMA compression (with dictionary), handled by lzma-loader.
  13. cat $(KDIR)/vmlinux | $(STAGING_DIR_HOST)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $(KDIR)/vmlinux.lzma
  14. # Less optimal LZMA compression (no dictionary), handled by CFE.
  15. $(STAGING_DIR_HOST)/bin/lzma e -so -d16 $(KDIR)/vmlinux > $(KDIR)/vmlinux-nodictionary.lzma
  16. gzip -nc9 $(KDIR)/vmlinux > $(KDIR)/vmlinux.gz
  17. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  18. cat $(KDIR)/vmlinux-initramfs | $(STAGING_DIR_HOST)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $(KDIR)/vmlinux-initramfs.lzma
  19. $(STAGING_DIR_HOST)/bin/lzma e -so -d16 $(KDIR)/vmlinux-initramfs > $(KDIR)/vmlinux-initramfs-nodictionary.lzma
  20. endif
  21. rm -f $(KDIR)/loader.gz
  22. $(MAKE) -C lzma-loader \
  23. BUILD_DIR="$(KDIR)" \
  24. TARGET="$(KDIR)" \
  25. clean install
  26. echo -ne "\\x00" >> $(KDIR)/loader.gz
  27. rm -f $(KDIR)/fs_mark
  28. echo -ne '\xde\xad\xc0\xde' > $(KDIR)/fs_mark
  29. $(call prepare_generic_squashfs,$(KDIR)/fs_mark)
  30. endef
  31. define trxalign/jffs2-128k
  32. -a 0x20000 -f $(KDIR)/root.$(1)
  33. endef
  34. define trxalign/jffs2-64k
  35. -a 0x10000 -f $(KDIR)/root.$(1)
  36. endef
  37. define trxalign/squashfs
  38. -a 1024 -f $(1) $(if $(2),-f $(2)) -a 0x10000 -A $(KDIR)/fs_mark
  39. endef
  40. #################################################
  41. # Images
  42. #################################################
  43. define Build/trx-with-loader
  44. $(STAGING_DIR_HOST)/bin/trx \
  45. -m 33554432 \
  46. -o [email protected] \
  47. -f $(KDIR)/loader.gz \
  48. -f $(IMAGE_KERNEL) \
  49. $(call trxalign/$(FILESYSTEM),$@)
  50. mv [email protected] $@
  51. endef
  52. define Build/trx-v2-with-loader
  53. $(STAGING_DIR_HOST)/bin/trx \
  54. -2 \
  55. -m 33554432 \
  56. -o [email protected] \
  57. -f $(KDIR)/loader.gz \
  58. -f $(KDIR)/vmlinux.lzma \
  59. $(call trxalign/$(FILESYSTEM),$@,[email protected])
  60. mv [email protected] $@
  61. endef
  62. define Build/trx-without-loader
  63. $(STAGING_DIR_HOST)/bin/trx \
  64. -m 33554432 \
  65. -o [email protected] \
  66. -f $(IMAGE_KERNEL) \
  67. $(call trxalign/$(FILESYSTEM),$@)
  68. mv [email protected] $@
  69. endef
  70. define Build/asus-trx
  71. $(STAGING_DIR_HOST)/bin/asustrx -p $(PRODUCTID) -i $@ -o [email protected]
  72. mv [email protected] $@
  73. endef
  74. define Build/edimax-bin
  75. $(STAGING_DIR_HOST)/bin/trx2edips $@ [email protected]
  76. mv [email protected] $@
  77. endef
  78. define Build/huawei-bin
  79. dd if=/dev/zero [email protected] bs=92 count=1
  80. echo -ne 'HDR0\x08\x00\x00\x00' >> [email protected]
  81. cat $@ >> [email protected]
  82. mv [email protected] $@
  83. endef
  84. define Build/linksys-bin
  85. $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(DEVICE_ID) -v v$(VERSION) $(if $(SERIAL),-s $(SERIAL)) -i $@ -o [email protected]
  86. mv [email protected] $@
  87. endef
  88. define Build/linksys-pattern-partition
  89. $(STAGING_DIR_HOST)/bin/addpattern -5 -p $(DEVICE_ID) -v v$(VERSION) $(if $(SERIAL),-s $(SERIAL)) -i /dev/null -o [email protected]
  90. endef
  91. define Build/motorola-bin
  92. $(STAGING_DIR_HOST)/bin/motorola-bin -$(MOTOROLA_DEVICE) $@ [email protected]
  93. mv [email protected] $@
  94. endef
  95. define Build/prepend-with-elf
  96. mv $@ [email protected]
  97. dd if=$(KDIR)/loader.elf of=$@ bs=131072 conv=sync
  98. cat [email protected] >> $@
  99. endef
  100. define Build/tailed-bin
  101. echo $(BIN_TAIL) >> $@
  102. endef
  103. define Build/usrobotics-bin
  104. $(STAGING_DIR_HOST)/bin/trx2usr $@ [email protected]
  105. mv [email protected] $@
  106. endef
  107. #################################################
  108. # Devices
  109. #################################################
  110. DEVICE_VARS += PRODUCTID
  111. DEVICE_VARS += DEVICE_ID VERSION SERIAL
  112. DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_REGION
  113. DEVICE_VARS += MOTOROLA_DEVICE
  114. DEVICE_VARS += BIN_TAIL
  115. define Device/Default
  116. KERNEL := kernel-bin
  117. DEVICE_IMG_NAME = $$(DEVICE_IMG_PREFIX)-$$(1).$$(2)
  118. KERNEL_NAME = vmlinux.lzma
  119. KERNEL_INITRAMFS_NAME = vmlinux-initramfs.lzma
  120. FILESYSTEMS := $(FS_64K)
  121. IMAGES := trx
  122. IMAGE/trx := append-rootfs | trx-with-loader
  123. endef
  124. define Device/standard
  125. DEVICE_VENDOR := Generic
  126. DEVICE_MODEL := Image with LZMA loader and LZMA compressed kernel
  127. endef
  128. define Device/standard-noloader-gz
  129. DEVICE_VENDOR := Generic
  130. DEVICE_MODEL := Image with gzipped kernel
  131. KERNEL_NAME = vmlinux.gz
  132. IMAGE/trx := append-rootfs | trx-without-loader
  133. endef
  134. define Device/standard-noloader-nodictionarylzma
  135. DEVICE_VENDOR := Generic
  136. DEVICE_MODEL := Image with LZMA compressed kernel matching CFE decompressor
  137. KERNEL_NAME = vmlinux-nodictionary.lzma
  138. IMAGE/trx := append-rootfs | trx-without-loader
  139. endef
  140. define Device/asus
  141. DEVICE_VENDOR := ASUS
  142. IMAGES := trx
  143. IMAGE/trx := append-rootfs | trx-with-loader | asus-trx
  144. endef
  145. define Device/linksys
  146. DEVICE_VENDOR := Linksys
  147. IMAGES := bin
  148. IMAGE/bin := append-rootfs | trx-with-loader | linksys-bin
  149. endef
  150. define Device/motorola
  151. DEVICE_VENDOR := Motorola
  152. IMAGES := bin
  153. IMAGE/bin := append-rootfs | trx-with-loader | motorola-bin
  154. endef
  155. define Device/netgear
  156. DEVICE_VENDOR := NETGEAR
  157. IMAGES := chk
  158. IMAGE/chk := append-rootfs | trx-with-loader | netgear-chk
  159. endef
  160. #################################################
  161. # Subtarget devices
  162. #################################################
  163. include $(SUBTARGET).mk
  164. #################################################
  165. # Shared BuildImage defines
  166. #################################################
  167. define Image/Build/Initramfs
  168. $(STAGING_DIR_HOST)/bin/trx \
  169. -m 33554432 \
  170. -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs.trx \
  171. -f $(KDIR)/loader.gz \
  172. -f $(KDIR)/vmlinux-initramfs.lzma
  173. $(STAGING_DIR_HOST)/bin/trx \
  174. -m 33554432 \
  175. -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs-noloader-nodictionary.trx \
  176. -f $(KDIR)/vmlinux-initramfs-nodictionary.lzma
  177. endef
  178. # $(1): filesystem type.
  179. define Image/Build
  180. # TODO: Move it to Device/*
  181. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  182. $(call Image/Build/Initramfs)
  183. endif
  184. endef
  185. $(eval $(call BuildImage))