Makefile.sample 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #
  2. # Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
  3. #
  4. # SPDX-License-Identifier: GPL-2.0
  5. #
  6. export BUILD_TOPDIR=/home/wareck/u-boot_mod
  7. export STAGING_DIR=/home/wareck/u-boot_mod/tmp
  8. export MAKECMD=make --silent ARCH=mips CROSS_COMPILE=mips-openwrt-linux-uclibc-
  9. export PATH:=/home/wareck/u-boot_mod/toolchain/bin/:$(PATH)
  10. SHELL = bash
  11. HOSTARCH := $(shell uname -m | \
  12. sed -e s/i.86/x86_32/ \
  13. -e s/sun4u/sparc64/ \
  14. -e s/arm.*/arm/ \
  15. -e s/sa110/arm/ \
  16. -e s/powerpc/ppc/ \
  17. -e s/macppc/ppc/)
  18. HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
  19. sed -e 's/\(cygwin\).*/cygwin/')
  20. ifneq ($(HOSTOS), darwin)
  21. ifneq ($(HOSTOS), linux)
  22. $(error Error! Unsupported host operating system/arch: "$(HOSTOS)-$(HOSTARCH)")
  23. endif
  24. endif
  25. export HOSTOS
  26. export HOSTARCH
  27. export BUILD_TOPDIR = $(PWD)
  28. export STAGING_DIR = $(BUILD_TOPDIR)/tmp
  29. export SOURCE_DIR = $(BUILD_TOPDIR)/u-boot
  30. export BIN_DIR = $(BUILD_TOPDIR)/bin
  31. export SUB_MAKE_CMD = $(MAKE) --silent --no-print-directory \
  32. ARCH=mips V=1 SHELL=$(SHELL)
  33. # ==========================================================================
  34. # You can override some default configuration options below or pass them on
  35. # command line, for example:
  36. # make ... IMG_SIZE=256 IMG_LZMA=0 CROSS_COMPILE=...
  37. # Set to 1 if you want to build RAM-loadable image, without low level
  38. # initialization of the hardware (PLL/clocks, DRAM):
  39. # IMG_RAM =
  40. # You can change limit of the image size in KB with below option (image will
  41. # be filled up to the selected size with 0xFF):
  42. # IMG_SIZE =
  43. # If you don't want LZMA compressed image, set below option to 1 (by default
  44. # images for all targets are LZMA compressed):
  45. # IMG_LZMA =
  46. # Define _absolute_ path to your toolchain directory, for example:
  47. # export TOOLCHAIN_DIR:=/home/user/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.15
  48. # export PATH:=$(TOOLCHAIN_DIR)/bin:$(PATH)
  49. ifndef CROSS_COMPILE
  50. CROSS_COMPILE = mips-openwrt-linux-musl-
  51. endif
  52. export CROSS_COMPILE
  53. # By default, optimization for size (-Os) is enabled, set below option
  54. # to n or remove it if you want only basic optimization (-O/-O1)
  55. # BUILD_OPTIMIZED = n
  56. ifneq ($(BUILD_OPTIMIZED), n)
  57. BUILD_OPTIMIZED = y
  58. endif
  59. export BUILD_OPTIMIZED
  60. # ==========================================================================
  61. # =======================
  62. # CUSTOM HELPER FUNCTIONS
  63. # =======================
  64. define echo_green
  65. echo -e "\e[92m$(1)\e[0m"
  66. endef
  67. define echo_red
  68. echo -e "\e[91m$(1)\e[0m"
  69. endef
  70. define echo_blue
  71. echo -e "\e[96m$(1)\e[0m"
  72. endef
  73. # $(1): size
  74. define img_size
  75. $(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
  76. endef
  77. # $(1): value
  78. define is_lzma
  79. $(if $(IMG_LZMA),\
  80. $(if $(filter $(strip $(IMG_LZMA)),1),1,0),\
  81. $(if $(filter $(strip $(1)),1),1,0)\
  82. )
  83. endef
  84. define git_branch
  85. $(shell git symbolic-ref --short -q HEAD 2>/dev/null || echo "unknown")
  86. endef
  87. define git_hash
  88. $(shell git rev-parse --short=8 -q HEAD 2>/dev/null || echo "unknown")
  89. endef
  90. define git_branch_hash
  91. git_$(call git_branch)-$(call git_hash)
  92. endef
  93. # $(1): file extension
  94. define img_name
  95. u-boot_mod__$@__$(shell date +"%Y%m%d")__$(call git_branch_hash)$(if \
  96. $(filter $(IMG_RAM),1),__RAM-LOAD-ONLY)$(if $(1),.$(1))
  97. endef
  98. define md5_sum
  99. $(call echo_green,Calculating MD5 sum for the final image...)
  100. md5sum $(BIN_DIR)/$(call img_name,bin) | \
  101. awk '{print $$1}' | \
  102. tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
  103. echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
  104. endef
  105. # $(1): size
  106. define padded_img
  107. $(call echo_green,Preparing $(1) KB image padded with 0xFF...)
  108. tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
  109. of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
  110. endef
  111. define final_img
  112. $(call echo_green,Preparing final image...)
  113. dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
  114. conv=notrunc 2> /dev/null
  115. rm -f $(BIN_DIR)/temp.bin
  116. endef
  117. # $(1): path to image
  118. # $(2): size limit in KB
  119. define size_chk
  120. $(call echo_green,Checking size of the image...)
  121. if [ `wc -c < $(1)` -gt $$(($(2) * 1024)) ]; then \
  122. echo; \
  123. $(call echo_red, ======================); \
  124. $(call echo_red, IMAGE SIZE IS TOO BIG!); \
  125. $(call echo_red, ======================); \
  126. echo; \
  127. rm -f $(1); \
  128. exit 1; \
  129. fi;
  130. endef
  131. # $(1): filename of image to copy
  132. # $(2): image size limit (check if set)
  133. define copy_img
  134. echo;
  135. $(call echo_green,Copying compiled image...)
  136. cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
  137. $(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
  138. endef
  139. # $(1): size limit in KB
  140. # $(2): if set to 1, use LZMA
  141. # $(3): other parameters passed to subdir make
  142. define build
  143. args="IMG_SIZE=$$((1024*$(call img_size,$(1)))) \
  144. IMG_LZMA=$(strip $(call is_lzma,$(2))) \
  145. $(strip $(3))"; \
  146. cd $(SOURCE_DIR) && \
  147. $(SUB_MAKE_CMD) $@ $$args && \
  148. $(SUB_MAKE_CMD) all $$args
  149. $(if $(filter $(IMG_RAM),1),\
  150. $(call copy_img,u-boot), \
  151. $(if $(filter $(strip $(call is_lzma,$(2))),1), \
  152. $(call copy_img,tuboot,$(call img_size,$(1))), \
  153. $(call copy_img,u-boot,$(call img_size,$(1))) \
  154. ) \
  155. )
  156. $(if $(filter $(IMG_RAM),1),,$(call padded_img,$(1)))
  157. $(call final_img)
  158. $(call md5_sum)
  159. echo;
  160. $(call echo_green,DONE!)
  161. $(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
  162. if [ "x$$IMG_RAM" = "x1" ]; then \
  163. echo; \
  164. $(call echo_blue, ================================); \
  165. $(call echo_blue, THIS IMAGE IS ONLY FOR RAM LOAD!); \
  166. $(call echo_blue, DO NOT WRITE IT INTO FLASH CHIP!); \
  167. $(call echo_blue, ================================); \
  168. echo; \
  169. fi;
  170. endef
  171. # ===========================================
  172. # TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
  173. # ===========================================
  174. COMMON_AR933X_TARGETS = \
  175. gainstrong_oolite_v1_dev \
  176. gl-inet_6416 \
  177. hak5_lan-turtle \
  178. hak5_packet-squirrel \
  179. hak5_wifi-pineapple-nano \
  180. tp-link_tl-mr10u_v1 \
  181. tp-link_tl-mr13u_v1 \
  182. tp-link_tl-mr3020_v1 \
  183. tp-link_tl-mr3040_v1v2 \
  184. tp-link_tl-mr3220_v2 \
  185. tp-link_tl-wr703n_v1 \
  186. tp-link_tl-wr710n_v1 \
  187. tp-link_tl-wr720n_v3_CN \
  188. tp-link_tl-wr740n_v4
  189. $(COMMON_AR933X_TARGETS):
  190. @$(call build,123,1)
  191. COMMON_ETHS27_TARGETS = \
  192. gainstrong_oolite_v5.2 \
  193. gainstrong_oolite_v5.2_dev \
  194. tp-link_tl-mr22u_v1 \
  195. tp-link_tl-mr3420_v2 \
  196. tp-link_tl-mr3420_v3 \
  197. tp-link_tl-mr6400_v1v2 \
  198. tp-link_tl-wa801nd_v2 \
  199. tp-link_tl-wa830re_v2 \
  200. tp-link_tl-wa850re_v2 \
  201. tp-link_tl-wdr3500_v1 \
  202. tp-link_tl-wr802n_v1 \
  203. tp-link_tl-wr810n_v1 \
  204. tp-link_tl-wr810n_v2 \
  205. tp-link_tl-wr820n_v1_CN \
  206. tp-link_tl-wr841n_v10 \
  207. tp-link_tl-wr841n_v11 \
  208. tp-link_tl-wr841n_v8 \
  209. tp-link_tl-wr841n_v9 \
  210. tp-link_tl-wr842n_v3 \
  211. tp-link_tl-wr902ac_v1
  212. $(COMMON_ETHS27_TARGETS):
  213. @$(call build,123,1,ETH_CONFIG=_s27)
  214. 8devices_carambola2 \
  215. alfa-network_hornet-ub \
  216. alfa-network_tube2h \
  217. creatcomm-technology_d3321 \
  218. gl-inet_gl-ar150 \
  219. gl-inet_gl-usb150:
  220. @$(call build,256,1)
  221. alfa-network_ap121f:
  222. @$(call build,192,1)
  223. alfa-network_n5q \
  224. alfa-network_r36a:
  225. @$(call build,384,1,ETH_CONFIG=_s27)
  226. comfast_cf-e314n \
  227. comfast_cf-e320n_v2 \
  228. comfast_cf-e520n \
  229. comfast_cf-e530n:
  230. @$(call build,64,1,ETH_CONFIG=_s27)
  231. d-link_dir-505_a1:
  232. @$(call build,64,1)
  233. dragino_ms14:
  234. @$(call build,192,1,DEVICE_VENDOR=dragino)
  235. engenius_ens202ext \
  236. gl-inet_gl-ar300 \
  237. gl-inet_gl-ar300m-lite \
  238. gl-inet_gl-ar750 \
  239. p2w_cpe505n \
  240. p2w_r602n \
  241. yuncore_ap90q \
  242. yuncore_cpe830 \
  243. yuncore_t830 \
  244. whqx_e600g_v2 \
  245. whqx_e600gac_v2 \
  246. zbtlink_zbt-we1526:
  247. @$(call build,256,1,ETH_CONFIG=_s27)
  248. tp-link_tl-wdr3600_v1 \
  249. tp-link_tl-wdr43x0_v1 \
  250. tp-link_tl-wr1041n_v2:
  251. @$(call build,123,1,ETH_CONFIG=_s17)
  252. unwireddevices_unwired-one:
  253. @$(call build,128,1,DEVICE_VENDOR=SE)
  254. village-telco_mesh-potato_v2:
  255. @$(call build,192,1,DEVICE_VENDOR=villagetelco)
  256. wallys_dr531:
  257. @$(call build,192,1,ETH_CONFIG=_s27)
  258. yuncore_cpe870:
  259. @$(call build,64,1,ETH_CONFIG=_s27)
  260. # =============
  261. # CLEAN TARGETS
  262. # =============
  263. lzma_host_clean:
  264. @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) $@
  265. clean:
  266. @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
  267. @rm -f $(SOURCE_DIR)/httpd/fsdata.c
  268. clean_all: clean
  269. @$(call echo_green,Removing all binary images...)
  270. @rm -f $(BIN_DIR)/*.bin
  271. @rm -f $(BIN_DIR)/*.md5