Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. LOADER_MAKEOPTS= \
  15. KDIR=$(KDIR) \
  16. LOADADDR=$(KERNEL_LOADADDR) \
  17. RAMSIZE=$(RAMSIZE) \
  18. LZMA_TEXT_START=$(LZMA_TEXT_START)
  19. RELOCATE_MAKEOPTS= \
  20. CACHELINE_SIZE=16 \
  21. KERNEL_ADDR=$(KERNEL_LOADADDR) \
  22. CROSS_COMPILE=$(TARGET_CROSS) \
  23. LZMA_TEXT_START=$(LOADER_ENTRY)
  24. define Build/Compile
  25. rm -rf $(KDIR)/relocate
  26. $(CP) ../../generic/image/relocate $(KDIR)
  27. $(MAKE) -C $(KDIR)/relocate $(RELOCATE_MAKEOPTS)
  28. endef
  29. ### Kernel scripts ###
  30. define Build/hcs-initramfs
  31. $(STAGING_DIR_HOST)/bin/hcsmakeimage --magic_bytes=$(HCS_MAGIC_BYTES) \
  32. --rev_maj=$(HCS_REV_MAJ) --rev_min=$(HCS_REV_MIN) --input_file=$@ \
  33. [email protected] --ldaddress=$(KERNEL_LOADADDR)
  34. mv [email protected] $@
  35. endef
  36. define Build/loader-lzma
  37. rm -rf [email protected]
  38. $(MAKE) -C lzma-loader \
  39. $(LOADER_MAKEOPTS) \
  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 $(CFE_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-old-bin
  96. $(TOPDIR)/scripts/brcmImage.pl -t -p \
  97. -o $@ -b $(CFE_BOARD_ID) -c $(CFE_CHIP_ID) \
  98. -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
  99. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) \
  100. $(CFE_EXTRAS)
  101. endef
  102. define Build/cfe-spw303v-bin
  103. $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
  104. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CFE_CHIP_ID) \
  105. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  106. $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
  107. $(CFE_EXTRAS) $(1)
  108. endef
  109. define Build/spw303v-bin
  110. $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o [email protected]
  111. mv [email protected] $@
  112. endef
  113. define Build/zyxel-bin
  114. $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o [email protected]
  115. mv [email protected] $@
  116. endef
  117. define Build/redboot-bin
  118. # Prepare kernel and rootfs
  119. dd if=$(IMAGE_KERNEL) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
  120. dd if=$(IMAGE_ROOTFS) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) bs=64k conv=sync
  121. echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))
  122. # Generate the scripted image
  123. $(TOPDIR)/scripts/redboot-script.pl \
  124. -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
  125. -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) \
  126. -a $(strip $(LOADER_ENTRY)) -f 0xbe430000 -l 0x7c0000 \
  127. -s 0x1000 -t 20 -o [email protected]
  128. dd if="[email protected]" of="[email protected]" bs=4096 conv=sync
  129. cat \
  130. "[email protected]" \
  131. "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
  132. "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
  133. > "$@"
  134. endef
  135. define Device/Default
  136. PROFILES = Default $$(DEVICE_NAME)
  137. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
  138. KERNEL_INITRAMFS_SUFFIX := .elf
  139. DEVICE_DTS_DIR := ../dts
  140. SOC = bcm$$(CFE_CHIP_ID)
  141. DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
  142. endef
  143. ATH5K_PACKAGES := kmod-ath5k wpad-basic
  144. ATH9K_PACKAGES := kmod-ath9k wpad-basic
  145. B43_PACKAGES := kmod-b43 wpad-basic
  146. BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
  147. RT28_PACKAGES := kmod-rt2800-pci wpad-basic
  148. RT61_PACKAGES := kmod-rt61-pci wpad-basic
  149. USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
  150. USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
  151. include bcm63xx.mk
  152. $(eval $(call BuildImage))