Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. include $(TOPDIR)/rules.mk
  3. include $(INCLUDE_DIR)/image.mk
  4. KERNEL_LOADADDR := 0x80010000 # RAM start + 64K
  5. LOADER_ENTRY := 0x80a00000 # RAM start + 10M, for relocate
  6. RAMSIZE := 0x02000000 # 32MB
  7. LZMA_TEXT_START := 0x81800000 # 32MB - 8MB
  8. DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
  9. define Build/Compile
  10. rm -rf $(KDIR)/relocate
  11. $(CP) ../../generic/image/relocate $(KDIR)
  12. $(MAKE) -C $(KDIR)/relocate \
  13. CACHELINE_SIZE=16 \
  14. CROSS_COMPILE=$(TARGET_CROSS) \
  15. KERNEL_ADDR=$(KERNEL_LOADADDR) \
  16. LZMA_TEXT_START=$(LOADER_ENTRY)
  17. endef
  18. ### Kernel scripts ###
  19. define Build/loader-lzma
  20. @rm -rf [email protected]
  21. $(MAKE) -C lzma-loader \
  22. CHIP_ID=$(CHIP_ID) \
  23. KERNEL_ADDR=$(KERNEL_LOADADDR) \
  24. KDIR=$(KDIR) \
  25. LOADER_ADDR=$(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
  26. LOADER_DATA="$@" \
  27. LOADER_NAME="$(notdir $@)" \
  28. LZMA_TEXT_START=$(LZMA_TEXT_START) \
  29. PKG_BUILD_DIR="[email protected]" \
  30. RAMSIZE=$(RAMSIZE) \
  31. TARGET_DIR="$(dir $@)" \
  32. compile loader.$(1)
  33. @mv "$@.$(1)" "$@"
  34. @rm -rf [email protected]
  35. endef
  36. define Build/lzma-cfe
  37. # CFE is a LZMA nazi! It took me hours to find out the parameters!
  38. # Also I think lzma has a bug cause it generates different output depending on
  39. # if you use stdin / stdout or not. Use files instead of stdio here, cause
  40. # otherwise CFE will complain and not boot the image.
  41. $(call Build/lzma-no-dict,-d22 -fb64 -a1)
  42. # Strip out the length, CFE doesn't like this
  43. dd if=$@ [email protected] bs=5 count=1
  44. dd if=$@ [email protected] ibs=13 obs=5 skip=1 seek=1 conv=notrunc
  45. @mv [email protected] $@
  46. endef
  47. define Build/relocate-kernel
  48. # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
  49. # kernel might get larger than that, so let CFE unpack and load at a
  50. # higher address and make the kernel relocate itself to the expected
  51. # location.
  52. ( \
  53. dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
  54. perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
  55. cat $@ \
  56. ) > [email protected]
  57. @mv [email protected] $@
  58. endef
  59. ### Image scripts ###
  60. define rootfspad/jffs2-128k
  61. --align-rootfs
  62. endef
  63. define rootfspad/jffs2-64k
  64. --align-rootfs
  65. endef
  66. define rootfspad/squashfs
  67. endef
  68. define Image/FileSystemStrip
  69. $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
  70. endef
  71. define Build/cfe-bin
  72. $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
  73. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
  74. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  75. --info1 "$(call ModelNameLimit16,$(DEVICE_NAME))" \
  76. --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
  77. $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
  78. $(CFE_EXTRAS) $(1)
  79. endef
  80. define Build/cfe-jffs2
  81. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
  82. --big-endian \
  83. --pad \
  84. --no-cleanmarkers \
  85. --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
  86. --root=$(1) \
  87. --output=$@ \
  88. --compression-mode=none
  89. $(call Build/pad-to,$(BLOCKSIZE))
  90. endef
  91. define Build/cfe-jffs2-cferam
  92. mv $@ [email protected]
  93. rm -rf $@-cferam
  94. mkdir -p $@-cferam
  95. # CFE ROM checks JFFS2 dirent version of cferam.
  96. # If version is not > 0 it will ignore the fs entry.
  97. # JFFS2 sets version 0 to the first fs entry and increments
  98. # it on the following ones, so let's create a dummy file that
  99. # will have version 0 and let cferam be the second (version 1).
  100. touch $@-cferam/1-openwrt
  101. # Add cferam as the last file in the JFFS2 partition
  102. cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
  103. # The JFFS2 partition creation should result in the following
  104. # layout:
  105. # 1) 1-openwrt (version 0, ino 2)
  106. # 2) cferam.000 (version 1, ino 3)
  107. $(call Build/cfe-jffs2,$@-cferam)
  108. # Some devices need padding between CFE RAM and kernel
  109. $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
  110. # Add CFE partition tag
  111. $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
  112. # Append kernel
  113. dd [email protected] >> $@
  114. rm -f [email protected]
  115. endef
  116. define Build/cfe-jffs2-kernel
  117. rm -rf $@-kernel
  118. mkdir -p $@-kernel
  119. # CFE RAM checks JFFS2 dirent version of vmlinux.
  120. # If version is not > 0 it will ignore the fs entry.
  121. # JFFS2 sets version 0 to the first fs entry and increments
  122. # it on the following ones, so let's create a dummy file that
  123. # will have version 0 and let cferam be the second (version 1).
  124. touch $@-kernel/1-openwrt
  125. # vmlinux is located on a different JFFS2 partition, but CFE RAM
  126. # ignores it, so let's create another dummy file that will match
  127. # the JFFS2 ino of cferam entry on the first JFFS2 partition.
  128. # CFE RAM won't be able to find vmlinux if cferam has the same
  129. # ino as vmlinux.
  130. touch $@-kernel/2-openwrt
  131. # Add vmlinux as the last file in the JFFS2 partition
  132. $(TOPDIR)/scripts/cfe-bin-header.py \
  133. --input-file $@ \
  134. --output-file $@-kernel/vmlinux.lz \
  135. --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
  136. --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
  137. # The JFFS2 partition creation should result in the following
  138. # layout:
  139. # 1) 1-openwrt (version 0, ino 2)
  140. # 2) 2-openwrt (version 1, ino 3)
  141. # 3) vmlinux.lz (version 2, ino 4)
  142. $(call Build/cfe-jffs2,$@-kernel)
  143. endef
  144. define Build/cfe-part-tag
  145. mv $@ [email protected]
  146. $(TOPDIR)/scripts/cfe-partition-tag.py \
  147. --input-file [email protected] \
  148. --output-file $@ \
  149. --flags $(CFE_PART_FLAGS) \
  150. --id $(CFE_PART_ID) \
  151. --name $(VERSION_CODE) \
  152. --version $(DEVICE_NAME)
  153. $(call Build/pad-to,$(BLOCKSIZE))
  154. dd [email protected] >> $@
  155. endef
  156. define Build/cfe-sercomm-crypto
  157. $(TOPDIR)/scripts/sercomm-crypto.py \
  158. --input-file $@ \
  159. --key-file [email protected] \
  160. --output-file [email protected] \
  161. --version OpenWrt
  162. $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
  163. -in $@ -out [email protected] \
  164. -K `cat [email protected]` \
  165. -iv 00000000000000000000000000000000
  166. dd [email protected] >> [email protected]
  167. mv [email protected] $@
  168. rm -f [email protected] [email protected]
  169. endef
  170. define Build/cfe-sercomm-load
  171. $(TOPDIR)/scripts/sercomm-payload.py \
  172. --input-file $@ \
  173. --output-file [email protected] \
  174. --pid "$(SERCOMM_PID)"
  175. mv [email protected] $@
  176. endef
  177. define Build/cfe-sercomm-part
  178. $(TOPDIR)/scripts/sercomm-partition-tag.py \
  179. --input-file $@ \
  180. --output-file [email protected]_rootfs \
  181. --part-name kernel_rootfs \
  182. --part-version OpenWrt \
  183. --rootfs-version $(SERCOMM_VERSION)
  184. rm -rf $@-rootfs_lib
  185. mkdir -p $@-rootfs_lib
  186. echo $(SERCOMM_VERSION) > $@-rootfs_lib/lib_ver
  187. $(call Build/cfe-jffs2,$@-rootfs_lib)
  188. $(call Build/pad-to,$(BLOCKSIZE))
  189. $(TOPDIR)/scripts/sercomm-partition-tag.py \
  190. --input-file $@ \
  191. --output-file [email protected]_lib \
  192. --part-name rootfs_lib \
  193. --part-version $(SERCOMM_VERSION)
  194. mv [email protected]_rootfs $@
  195. dd [email protected]_lib >> $@
  196. endef
  197. define Build/cfe-wfi-tag
  198. $(TOPDIR)/scripts/cfe-wfi-tag.py \
  199. --input-file $@ \
  200. --output-file [email protected] \
  201. --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
  202. --chip-id $(CFE_WFI_CHIP_ID) \
  203. --flash-type $(CFE_WFI_FLASH_TYPE) \
  204. $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
  205. mv [email protected] $@
  206. endef
  207. ### Device scripts ###
  208. define Device/Default
  209. PROFILES = Default $$(DEVICE_NAME)
  210. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
  211. DEVICE_DTS_DIR := ../dts
  212. CHIP_ID :=
  213. SOC = bcm$$(CHIP_ID)
  214. DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
  215. DEVICE_LOADADDR :=
  216. endef
  217. ATH9K_PACKAGES := kmod-ath9k wpad-basic-mbedtls
  218. B43_PACKAGES := kmod-b43 wpad-basic-mbedtls
  219. USB1_PACKAGES := kmod-usb-ohci kmod-ledtrig-usbdev
  220. USB2_PACKAGES := $(USB1_PACKAGES) kmod-usb2
  221. include bcm63xx_$(SUBTARGET).mk
  222. $(eval $(call BuildImage))