Makefile 5.4 KB

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