Makefile 9.4 KB

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