Makefile 9.3 KB

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