Makefile 9.5 KB

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