Makefile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. LOADADDR = 0x80010000 # RAM start + 64K
  11. KERNEL_ENTRY = $(LOADADDR) # Newer kernels add a jmp to the kernel_entry at the start of the binary
  12. LOADER_ENTRY = 0x80a00000 # RAM start + 10M, for relocate
  13. RAMSIZE = 0x02000000 # 32MB
  14. LZMA_TEXT_START = 0x81800000 # 32MB - 8MB
  15. LOADER_MAKEOPTS= \
  16. KDIR=$(KDIR) \
  17. LOADADDR=$(LOADADDR) \
  18. KERNEL_ENTRY=$(KERNEL_ENTRY) \
  19. RAMSIZE=$(RAMSIZE) \
  20. LZMA_TEXT_START=$(LZMA_TEXT_START) \
  21. RELOCATE_MAKEOPTS= \
  22. CACHELINE_SIZE=16 \
  23. KERNEL_ADDR=$(KERNEL_ENTRY) \
  24. CROSS_COMPILE=$(TARGET_CROSS) \
  25. LZMA_TEXT_START=$(LOADER_ENTRY)
  26. define Build/Compile
  27. rm -rf $(KDIR)/relocate
  28. $(CP) ../../generic/image/relocate $(KDIR)
  29. $(MAKE) -C $(KDIR)/relocate $(RELOCATE_MAKEOPTS)
  30. endef
  31. ### Kernel scripts ###
  32. define Build/append-dtb
  33. $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb)
  34. cat $@.dtb >> $@
  35. endef
  36. define Build/hcs-initramfs
  37. $(STAGING_DIR_HOST)/bin/hcsmakeimage --magic_bytes=$(HCS_MAGIC_BYTES) \
  38. --rev_maj=$(HCS_REV_MAJ) --rev_min=$(HCS_REV_MIN) --input_file=$@ \
  39. --output_file=$@.hcs --ldaddress=$(LOADADDR)
  40. mv $@.hcs $@
  41. endef
  42. define Build/loader-lzma
  43. rm -rf $@.src
  44. $(MAKE) -C lzma-loader \
  45. $(LOADER_MAKEOPTS) \
  46. PKG_BUILD_DIR="$@.src" \
  47. TARGET_DIR="$(dir $@)" \
  48. LOADER_DATA="$@" \
  49. LOADER_NAME="$(notdir $@)" \
  50. compile loader.$(1)
  51. mv "$@.$(1)" "$@"
  52. rm -rf $@.src
  53. endef
  54. define Build/lzma
  55. # CFE is a LZMA nazi! It took me hours to find out the parameters!
  56. # Also I think lzma has a bug cause it generates different output depending on
  57. # if you use stdin / stdout or not. Use files instead of stdio here, cause
  58. # otherwise CFE will complain and not boot the image.
  59. $(STAGING_DIR_HOST)/bin/lzma e $@ -d22 -fb64 -a1 $@.lzma
  60. mv $@.lzma $@
  61. endef
  62. define Build/lzma-cfe
  63. # Strip out the length, CFE doesn't like this
  64. dd if=$@ of=$@.lzma.cfe bs=5 count=1
  65. dd if=$@ of=$@.lzma.cfe ibs=13 obs=5 skip=1 seek=1 conv=notrunc
  66. mv $@.lzma.cfe $@
  67. endef
  68. define Build/relocate-kernel
  69. # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
  70. # kernel might get larger than that, so let CFE unpack and load at a
  71. # higher address and make the kernel relocate itself to the expected
  72. # location.
  73. ( \
  74. dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
  75. perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
  76. cat $@ \
  77. ) > $@.relocate
  78. mv $@.relocate $@
  79. endef
  80. ### Image scripts ###
  81. define rootfspad/jffs2-128k
  82. --align-rootfs
  83. endef
  84. define rootfspad/jffs2-64k
  85. --align-rootfs
  86. endef
  87. define rootfspad/squashfs
  88. endef
  89. define Image/LimitName16
  90. $(shell expr substr "$(1)" 1 16)
  91. endef
  92. define Image/FileSystemStrip
  93. $(subst root.,,$(notdir $(1)))
  94. endef
  95. define Build/cfe-bin
  96. $(STAGING_DIR_HOST)/bin/imagetag -i $(word 1,$^) -f $(word 2,$^) \
  97. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CFE_CHIP_ID) \
  98. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  99. --info1 "$(call Image/LimitName16,$(DEVICE_NAME))" \
  100. --info2 "$(call Image/FileSystemStrip,$(word 2,$^))" \
  101. $(call rootfspad/$(call Image/FileSystemStrip,$(word 2,$^))) \
  102. $(CFE_EXTRAS) $(1)
  103. endef
  104. define Build/cfe-old-bin
  105. $(TOPDIR)/scripts/brcmImage.pl -t -p \
  106. -o $@ -b $(CFE_BOARD_ID) -c $(CFE_CHIP_ID) \
  107. -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
  108. -k $(word 1,$^) -r $(word 2,$^) \
  109. $(CFE_EXTRAS)
  110. endef
  111. define Build/cfe-spw303v-bin
  112. $(STAGING_DIR_HOST)/bin/imagetag -i $(word 1,$^) -f $(word 2,$^) \
  113. --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CFE_CHIP_ID) \
  114. --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
  115. $(call rootfspad/$(call Image/FileSystemStrip,$(word 2,$^))) \
  116. $(CFE_EXTRAS) $(1)
  117. endef
  118. define Build/spw303v-bin
  119. $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o $@.spw303v
  120. mv $@.spw303v $@
  121. endef
  122. define Build/xor-image
  123. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o $@.xor
  124. mv $@.xor $@
  125. endef
  126. define Build/zyxel-bin
  127. $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o $@.zyxel
  128. mv $@.zyxel $@
  129. endef
  130. define Build/redboot-bin
  131. # Prepare kernel and rootfs
  132. dd if=$(word 1,$^) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
  133. dd if=$(word 2,$^) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(word 2,$^)) bs=64k conv=sync
  134. echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(word 2,$^))
  135. # Generate the scripted image
  136. $(TOPDIR)/scripts/redboot-script.pl \
  137. -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
  138. -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(word 2,$^)) \
  139. -a $(strip $(LOADADDR)) -f 0xbe430000 -l 0x7c0000 \
  140. -s 0x1000 -t 20 -o $@.redbootscript
  141. dd if="$@.redbootscript" of="$@.redbootscript.padded" bs=4096 conv=sync
  142. cat \
  143. "$@.redbootscript.padded" \
  144. "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
  145. "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(word 2,$^))" \
  146. > "$@"
  147. endef
  148. define Device/Default
  149. PROFILES = Default $$(DEVICE_NAME)
  150. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
  151. KERNEL_INITRAMFS_SUFFIX := .elf
  152. DEVICE_DTS :=
  153. endef
  154. DEVICE_VARS += DEVICE_DTS
  155. ATH5K_PACKAGES := kmod-ath5k wpad-mini
  156. ATH9K_PACKAGES := kmod-ath9k wpad-mini
  157. B43_PACKAGES := kmod-b43 wpad-mini
  158. BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
  159. RT28_PACKAGES := kmod-rt2800-pci wpad-mini
  160. RT61_PACKAGES := kmod-rt61-pci wpad-mini
  161. USB1_PACKAGES := kmod-usb-ohci kmod-ledtrig-usbdev
  162. USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-ledtrig-usbdev
  163. include bcm63xx.mk
  164. $(eval $(call BuildImage))