Makefile 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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/LimitName16
  78. $(shell expr substr "$(1)" 1 16)
  79. endef
  80. define Image/FileSystemStrip
  81. $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
  82. endef
  83. define Build/cfe-bin
  84. $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
  85. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
  86. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  87. --info1 "$(call Image/LimitName16,$(DEVICE_NAME))" \
  88. --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
  89. $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
  90. $(CFE_EXTRAS) $(1)
  91. endef
  92. define Build/cfe-jffs2
  93. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
  94. --big-endian \
  95. --pad \
  96. --no-cleanmarkers \
  97. --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
  98. --root=$(1) \
  99. --output=$@ \
  100. --compression-mode=none
  101. $(call Build/pad-to,$(BLOCKSIZE))
  102. endef
  103. define Build/cfe-jffs2-cferam
  104. mv $@ [email protected]
  105. rm -rf $@-cferam
  106. mkdir -p $@-cferam
  107. # CFE ROM checks JFFS2 dirent version of cferam.
  108. # If version is not > 0 it will ignore the fs entry.
  109. # JFFS2 sets version 0 to the first fs entry and increments
  110. # it on the following ones, so let's create a dummy file that
  111. # will have version 0 and let cferam be the second (version 1).
  112. touch $@-cferam/1-openwrt
  113. # Add cferam as the last file in the JFFS2 partition
  114. cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
  115. # The JFFS2 partition creation should result in the following
  116. # layout:
  117. # 1) 1-openwrt (version 0, ino 2)
  118. # 2) cferam.000 (version 1, ino 3)
  119. $(call Build/cfe-jffs2,$@-cferam)
  120. # Some devices need padding between CFE RAM and kernel
  121. $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
  122. # Add CFE partition tag
  123. $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
  124. # Append kernel
  125. dd [email protected] >> $@
  126. rm -f [email protected]
  127. endef
  128. define Build/cfe-jffs2-kernel
  129. rm -rf $@-kernel
  130. mkdir -p $@-kernel
  131. # CFE RAM checks JFFS2 dirent version of vmlinux.
  132. # If version is not > 0 it will ignore the fs entry.
  133. # JFFS2 sets version 0 to the first fs entry and increments
  134. # it on the following ones, so let's create a dummy file that
  135. # will have version 0 and let cferam be the second (version 1).
  136. touch $@-kernel/1-openwrt
  137. # vmlinux is located on a different JFFS2 partition, but CFE RAM
  138. # ignores it, so let's create another dummy file that will match
  139. # the JFFS2 ino of cferam entry on the first JFFS2 partition.
  140. # CFE RAM won't be able to find vmlinux if cferam has the same
  141. # ino as vmlinux.
  142. touch $@-kernel/2-openwrt
  143. # Add vmlinux as the last file in the JFFS2 partition
  144. $(TOPDIR)/scripts/cfe-bin-header.py \
  145. --input-file $@ \
  146. --output-file $@-kernel/vmlinux.lz \
  147. --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
  148. --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
  149. # The JFFS2 partition creation should result in the following
  150. # layout:
  151. # 1) 1-openwrt (version 0, ino 2)
  152. # 2) 2-openwrt (version 1, ino 3)
  153. # 3) vmlinux.lz (version 2, ino 4)
  154. $(call Build/cfe-jffs2,$@-kernel)
  155. endef
  156. define Build/cfe-part-tag
  157. mv $@ [email protected]
  158. $(TOPDIR)/scripts/cfe-partition-tag.py \
  159. --input-file [email protected] \
  160. --output-file $@ \
  161. --flags $(CFE_PART_FLAGS) \
  162. --id $(CFE_PART_ID) \
  163. --name $(VERSION_CODE) \
  164. --version $(DEVICE_NAME)
  165. $(call Build/pad-to,$(BLOCKSIZE))
  166. dd [email protected] >> $@
  167. endef
  168. define Build/cfe-sercomm-part
  169. $(TOPDIR)/scripts/sercomm-partition-tag.py \
  170. --input-file $@ \
  171. --output-file [email protected]_rootfs \
  172. --part-name kernel_rootfs \
  173. --part-version OpenWrt \
  174. --rootfs-version $(SERCOMM_VERSION)
  175. rm -rf $@-rootfs_lib
  176. mkdir -p $@-rootfs_lib
  177. echo $(SERCOMM_VERSION) > $@-rootfs_lib/lib_ver
  178. $(call Build/cfe-jffs2,$@-rootfs_lib)
  179. $(call Build/pad-to,$(BLOCKSIZE))
  180. $(TOPDIR)/scripts/sercomm-partition-tag.py \
  181. --input-file $@ \
  182. --output-file [email protected]_lib \
  183. --part-name rootfs_lib \
  184. --part-version $(SERCOMM_VERSION)
  185. mv [email protected]_rootfs $@
  186. dd [email protected]_lib >> $@
  187. endef
  188. define Build/cfe-sercomm-load
  189. $(TOPDIR)/scripts/sercomm-payload.py \
  190. --input-file $@ \
  191. --output-file [email protected] \
  192. --pid "$(SERCOMM_PID)"
  193. mv [email protected] $@
  194. endef
  195. define Build/cfe-sercomm-crypto
  196. $(TOPDIR)/scripts/sercomm-crypto.py \
  197. --input-file $@ \
  198. --key-file [email protected] \
  199. --output-file [email protected] \
  200. --version OpenWrt
  201. $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
  202. -in $@ -out [email protected] \
  203. -K `cat [email protected]` \
  204. -iv 00000000000000000000000000000000
  205. dd [email protected] >> [email protected]
  206. mv [email protected] $@
  207. rm -f [email protected] [email protected]
  208. endef
  209. define Build/cfe-old-bin
  210. $(TOPDIR)/scripts/brcmImage.pl -t -p \
  211. -o $@ -b $(CFE_BOARD_ID) -c $(CHIP_ID) \
  212. -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
  213. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) \
  214. $(CFE_EXTRAS)
  215. endef
  216. define Build/cfe-spw303v-bin
  217. $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
  218. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
  219. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  220. $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
  221. $(CFE_EXTRAS) $(1)
  222. endef
  223. define Build/cfe-wfi-tag
  224. $(TOPDIR)/scripts/cfe-wfi-tag.py \
  225. --input-file $@ \
  226. --output-file [email protected] \
  227. --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
  228. --chip-id $(CFE_WFI_CHIP_ID) \
  229. --flash-type $(CFE_WFI_FLASH_TYPE) \
  230. $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
  231. mv [email protected] $@
  232. endef
  233. define Build/spw303v-bin
  234. $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o [email protected]
  235. mv [email protected] $@
  236. endef
  237. define Build/zyxel-bin
  238. $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o [email protected]
  239. mv [email protected] $@
  240. endef
  241. define Build/redboot-bin
  242. # Prepare kernel and rootfs
  243. dd if=$(IMAGE_KERNEL) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
  244. dd if=$(IMAGE_ROOTFS) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) bs=64k conv=sync
  245. echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))
  246. # Generate the scripted image
  247. $(TOPDIR)/scripts/redboot-script.pl \
  248. -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
  249. -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) \
  250. -a $(strip $(LOADER_ENTRY)) -f 0xbe430000 -l 0x7c0000 \
  251. -s 0x1000 -t 20 -o [email protected]
  252. dd if="[email protected]" of="[email protected]" bs=4096 conv=sync
  253. cat \
  254. "[email protected]" \
  255. "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
  256. "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
  257. > "$@"
  258. endef
  259. define Device/Default
  260. PROFILES = Default $$(DEVICE_NAME)
  261. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
  262. KERNEL_INITRAMFS_SUFFIX := .elf
  263. DEVICE_DTS_DIR := ../dts
  264. CHIP_ID :=
  265. SOC = bcm$$(CHIP_ID)
  266. DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
  267. DEVICE_LOADADDR :=
  268. endef
  269. DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
  270. ATH5K_PACKAGES := kmod-ath5k wpad-basic-wolfssl
  271. ATH9K_PACKAGES := kmod-ath9k wpad-basic-wolfssl
  272. B43_PACKAGES := kmod-b43 wpad-basic-wolfssl
  273. BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
  274. RT28_PACKAGES := kmod-rt2800-pci wpad-basic-wolfssl
  275. RT61_PACKAGES := kmod-rt61-pci wpad-basic-wolfssl
  276. USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
  277. USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
  278. include bcm63xx.mk
  279. ifeq ($(SUBTARGET),smp)
  280. include bcm63xx_nand.mk
  281. endif
  282. $(eval $(call BuildImage))