extension.cmake 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. # All rights reserved.
  3. #
  4. # This software is supplied "AS IS" without any warranties.
  5. # RDA assumes no responsibility or liability for the use of the software,
  6. # conveys no license or title under any patent, copyright, or mask work
  7. # right to the product. RDA reserves the right to make changes in the
  8. # software without notification. RDA also make no representation or
  9. # warranty that such application will be suitable for the specified use
  10. # without further testing or modification.
  11. function(print arg)
  12. message(STATUS "${arg}: ${${arg}}")
  13. endfunction()
  14. macro(install_header src dst)
  15. # get_filename_component(dst_dir ${dst} DIRECTORY)
  16. # file(RELATIVE_PATH src_rel ${dst_dir} ${CMAKE_CURRENT_SOURCE_DIR}/${src})
  17. # file(GENERATE OUTPUT ${dst} CONTENT "#include \"${src_rel}\"\n")
  18. configure_file(${src} ${dst} COPYONLY)
  19. endmacro()
  20. macro(install_headers) # <sources> OUTPUT <dstdir>
  21. cmake_parse_arguments(MY "" "" "OUTPUT" ${ARGN})
  22. foreach(src ${MY_UNPARSED_ARGUMENTS})
  23. get_filename_component(src_name ${src} NAME)
  24. configure_file(${src} ${MY_OUTPUT}/${src_name} COPYONLY)
  25. endforeach()
  26. endmacro()
  27. # Helper to set source with conditions
  28. macro(target_sources_if) # <conditon> THEN <command>
  29. cmake_parse_arguments(MY "" "" "THEN" ${ARGN})
  30. if(${MY_UNPARSED_ARGUMENTS})
  31. target_sources(${MY_THEN})
  32. endif()
  33. endmacro()
  34. # Helper to link libraries with conditions
  35. macro(target_link_libraries_if) # <conditon> THEN <command>
  36. cmake_parse_arguments(MY "" "" "THEN" ${ARGN})
  37. if(${MY_UNPARSED_ARGUMENTS})
  38. target_link_libraries(${MY_THEN})
  39. endif()
  40. endmacro()
  41. # Helper to link libraries with conditions
  42. macro(target_include_targets_if) # <conditon> THEN <command>
  43. cmake_parse_arguments(MY "" "" "THEN" ${ARGN})
  44. if(${MY_UNPARSED_ARGUMENTS})
  45. target_include_targets(${MY_THEN})
  46. endif()
  47. endmacro()
  48. # Helper to set variable with conditions
  49. macro(set_if var) # <condition> THEN <val_true> OTHERWISE <val_false>
  50. cmake_parse_arguments(MY "" "" "THEN;OTHERWISE" ${ARGN})
  51. if(${MY_UNPARSED_ARGUMENTS})
  52. if(MY_THEN)
  53. set(${var} ${MY_THEN})
  54. endif()
  55. else()
  56. if (MY_OTHERWISE)
  57. set(${var} ${MY_OTHERWISE})
  58. endif()
  59. endif()
  60. endmacro()
  61. function(add_subdirectory_if)
  62. cmake_parse_arguments(MY "" "" "THEN" ${ARGN})
  63. if(${MY_UNPARSED_ARGUMENTS})
  64. add_subdirectory(${MY_THEN})
  65. endif()
  66. endfunction()
  67. # Set a target to include all interface directories of depended targets.
  68. # The arguments must be target.
  69. function(target_include_targets target type)
  70. foreach(arg ${ARGN})
  71. target_include_directories(${target} ${type}
  72. $<TARGET_PROPERTY:${arg},INTERFACE_INCLUDE_DIRECTORIES>)
  73. endforeach()
  74. endfunction()
  75. # Include all interface directories of depended targets
  76. # The arguments must be target.
  77. function(include_targets)
  78. foreach(arg ${ARGN})
  79. include_directories($<TARGET_PROPERTY:${arg},INTERFACE_INCLUDE_DIRECTORIES>)
  80. endforeach()
  81. endfunction()
  82. # Set library files as application libraries
  83. function(add_app_libraries)
  84. get_property(app_libraries GLOBAL PROPERTY app_libraries)
  85. set_property(GLOBAL PROPERTY app_libraries ${app_libraries} ${ARGN})
  86. endfunction()
  87. macro(target_add_revision target)
  88. set(revision_file ${CMAKE_CURRENT_BINARY_DIR}/${target}_revision.c)
  89. set(revision_variable ${target}_build_revision)
  90. set(revision_value ${BUILD_TARGET}-${BUILD_RELEASE_TYPE}-${BUILD_AUTO_REVISION})
  91. configure_file(${SOURCE_TOP_DIR}/cmake/auto_revision.c.in ${revision_file})
  92. target_sources(${target} PRIVATE ${revision_file})
  93. endmacro()
  94. # Link targets with --whole-archive. PUBLIC/PRIVATE is required as parameter,
  95. # but PRIVATE will be used forcedly.
  96. function(target_link_whole_archive target signature)
  97. target_link_libraries(${target} PRIVATE -Wl,--whole-archive)
  98. foreach(arg ${ARGN})
  99. target_link_libraries(${target} PRIVATE ${arg})
  100. endforeach()
  101. target_link_libraries(${target} PRIVATE -Wl,--no-whole-archive)
  102. endfunction()
  103. # Link targets with --start-group. PUBLIC/PRIVATE is required as parameter,
  104. # but PRIVATE will be used forcedly.
  105. function(target_link_group target signature)
  106. target_link_libraries(${target} PRIVATE -Wl,--start-group)
  107. foreach(arg ${ARGN})
  108. target_link_libraries(${target} PRIVATE ${arg})
  109. endforeach()
  110. target_link_libraries(${target} PRIVATE -Wl,--end-group)
  111. endfunction()
  112. function(add_subdirectory_if_exist dir)
  113. if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
  114. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt)
  115. add_subdirectory(${dir})
  116. endif()
  117. endif()
  118. endfunction()
  119. # don't compile soure codes with lto, even lto is enabled by default
  120. function(source_files_no_lto)
  121. set_source_files_properties(${ARGN} PROPERTIES COMPILE_OPTIONS "-fno-lto")
  122. endfunction()
  123. # don't compile target with lto, even lto is enabled by default
  124. function(target_no_lto target)
  125. target_compile_options(${target} PRIVATE "-fno-lto")
  126. endfunction()
  127. function(cpp_only target file)
  128. add_library(${target} OBJECT ${file})
  129. set_source_files_properties(${file} PROPERTIES LANGUAGE C)
  130. target_compile_options(${target} PRIVATE -E -P -x c)
  131. foreach(dep ${ARGN})
  132. target_include_directories(${target}
  133. PRIVATE $<TARGET_PROPERTY:${dep},INTERFACE_INCLUDE_DIRECTORIES>)
  134. endforeach()
  135. foreach(dep ${ARGN})
  136. target_compile_definitions(${target}
  137. PRIVATE $<TARGET_PROPERTY:${dep},INTERFACE_COMPILE_DEFINITIONS>)
  138. endforeach()
  139. endfunction()
  140. # Final link depends on generated linker script
  141. function(target_depend_rom_ld ${target})
  142. if(CONFIG_SOC_8811)
  143. add_dependencies(${target}_ldscript nbrom_for_link)
  144. target_include_directories(${target}_ldscript PRIVATE ${out_hex_dir})
  145. endif()
  146. endfunction()
  147. # Generate asm file with incbin, with optional alignment.
  148. function(target_incbin target binfile sym) # BALIGN <balign>
  149. cmake_parse_arguments(MY "" "" "BALIGN" ${ARGN})
  150. set(symbol_balign 4)
  151. if(${MY_BALIGN})
  152. set(symbol_balign ${MY_BALIGN})
  153. endif()
  154. get_filename_component(bin_path ${binfile} ABSOLUTE)
  155. get_filename_component(bin_file_name ${binfile} NAME)
  156. set(symbol_name ${sym})
  157. set(asmfile ${CMAKE_CURRENT_BINARY_DIR}/${bin_file_name}.S)
  158. configure_file(${SOURCE_TOP_DIR}/cmake/incbin.S.in ${asmfile})
  159. target_sources(${target} PRIVATE ${asmfile})
  160. set_source_files_properties(${asmfile} PROPERTIES OBJECT_DEPENDS ${binfile})
  161. endfunction()
  162. # Generate asm file with incbin, and provide size with symbol (rather than variable)
  163. function(target_incbin_size target binfile sym symsize) # BALIGN <balign>
  164. cmake_parse_arguments(MY "" "" "BALIGN" ${ARGN})
  165. set(symbol_balign 4)
  166. if(${MY_BALIGN})
  167. set(symbol_balign ${MY_BALIGN})
  168. endif()
  169. get_filename_component(bin_path ${binfile} ABSOLUTE)
  170. get_filename_component(bin_file_name ${binfile} NAME)
  171. set(symbol_name ${sym})
  172. set(symbol_size_name ${symsize})
  173. set(asmfile ${CMAKE_CURRENT_BINARY_DIR}/${bin_file_name}.S)
  174. configure_file(${SOURCE_TOP_DIR}/cmake/incbin_size.S.in ${asmfile})
  175. target_sources(${target} PRIVATE ${asmfile})
  176. set_source_files_properties(${asmfile} PROPERTIES OBJECT_DEPENDS ${binfile})
  177. endfunction()
  178. function(add_uimage target ldscript) # <sources> OUTPUT_DIR <dir>
  179. cmake_parse_arguments(MY "WITH_FLASH2" "" "OUTPUT_DIR" ${ARGN})
  180. set(MY_SOURCES ${MY_UNPARSED_ARGUMENTS})
  181. if(NOT MY_OUTPUT_DIR)
  182. set(MY_OUTPUT_DIR ${out_hex_dir})
  183. endif()
  184. set(gen_ldscript ${target}_ldscript)
  185. set(target_map_file ${MY_OUTPUT_DIR}/${target}.map)
  186. set(target_img_file ${MY_OUTPUT_DIR}/${target}.img)
  187. set(target_flash2bin_file ${MY_OUTPUT_DIR}/${target}.flash2.bin)
  188. cpp_only(${gen_ldscript} ${ldscript} hal)
  189. add_executable(${target} ${MY_SOURCES})
  190. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MY_OUTPUT_DIR})
  191. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  192. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections ${link_cref_option})
  193. target_depend_rom_ld(${target})
  194. #quectel update
  195. if(CONFIG_QUEC_PROJECT_FEATURE_IMAGE_TIMESTAMP)
  196. set(cfg_img_timestamp )
  197. else()
  198. set(cfg_img_timestamp --timestamp 0)
  199. endif()
  200. if(MY_WITH_FLASH2)
  201. add_custom_command(TARGET ${target} POST_BUILD
  202. COMMAND ${cmd_mkuimage} --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}" ${cfg_img_timestamp}#quectel update
  203. $<TARGET_FILE:${target}> ${target_img_file}
  204. COMMAND ${cmd_elf2bin} --start __flash2_start --end __flash2_end --allow-empty
  205. $<TARGET_FILE:${target}> ${target_flash2bin_file}
  206. BYPRODUCTS ${target_img_file} ${target_map_file} ${target_flash2bin_file}
  207. )
  208. else()
  209. add_custom_command(TARGET ${target} POST_BUILD
  210. COMMAND ${cmd_mkuimage} --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}" ${cfg_img_timestamp}#quectel update
  211. $<TARGET_FILE:${target}> ${target_img_file}
  212. BYPRODUCTS ${target_img_file} ${target_map_file}
  213. )
  214. endif()
  215. endfunction()
  216. function(add_simage target ldscript) # <sources> IMGVER <ver> OUTPUT_DIR <dir>
  217. #cmake_parse_arguments(MY "" "IMGVER" "OUTPUT_DIR" ${ARGN})
  218. cmake_parse_arguments(MY "WITH_FLASH2" "IMGVER" "OUTPUT_DIR" ${ARGN}) #quectel update
  219. set(MY_SOURCES ${MY_UNPARSED_ARGUMENTS})
  220. if(NOT MY_OUTPUT_DIR)
  221. set(MY_OUTPUT_DIR ${out_hex_dir})
  222. endif()
  223. if(NOT MY_IMGVER)
  224. set(MY_IMGVER "1.1")
  225. endif()
  226. set(gen_ldscript ${target}_ldscript)
  227. set(target_map_file ${MY_OUTPUT_DIR}/${target}.map)
  228. set(target_img_file ${MY_OUTPUT_DIR}/${target}.img)
  229. set(target_flash2bin_file ${MY_OUTPUT_DIR}/${target}.flash2.bin)#quectel update
  230. cpp_only(${gen_ldscript} ${ldscript} hal)
  231. add_executable(${target} ${MY_SOURCES})
  232. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MY_OUTPUT_DIR})
  233. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  234. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections ${link_cref_option})
  235. target_depend_rom_ld(${target})
  236. #quectel update
  237. if(CONFIG_QUEC_PROJECT_FEATURE_IMAGE_TIMESTAMP)
  238. set(cfg_img_timestamp )
  239. else()
  240. set(cfg_img_timestamp --timestamp 0)
  241. endif()
  242. if(MY_WITH_FLASH2) #quectel update start
  243. add_custom_command(TARGET ${target} POST_BUILD
  244. COMMAND ${cmd_mksimage} --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}" ${cfg_img_timestamp}#quectel update
  245. --imgver ${MY_IMGVER} --platform "8811" --check crc
  246. $<TARGET_FILE:${target}> ${target_img_file}
  247. COMMAND ${cmd_elf2bin} --start __flash2_start --end __flash2_end --allow-empty
  248. $<TARGET_FILE:${target}> ${target_flash2bin_file}
  249. BYPRODUCTS ${target_img_file} ${target_map_file} ${target_flash2bin_file}
  250. )
  251. else()
  252. add_custom_command(TARGET ${target} POST_BUILD
  253. COMMAND ${cmd_mksimage} --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}" ${cfg_img_timestamp}#quectel update
  254. --imgver ${MY_IMGVER} --platform "8811" --check crc
  255. $<TARGET_FILE:${target}> ${target_img_file}
  256. BYPRODUCTS ${target_img_file} ${target_map_file}
  257. )
  258. endif() #quectel update end
  259. #add_custom_command(TARGET ${target} POST_BUILD
  260. # COMMAND ${cmd_mksimage} --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}"
  261. # --imgver ${MY_IMGVER} --platform "8811" --check crc
  262. # $<TARGET_FILE:${target}> ${target_img_file}
  263. # BYPRODUCTS ${target_img_file} ${target_map_file}
  264. #)
  265. endfunction()
  266. macro(pac_init_fdl cmd)
  267. if(CONFIG_SOC_8910)
  268. set(${cmd}
  269. cfg-init --pname "UIX8910_MODEM" --palias ${BUILD_TARGET}
  270. --pversion "8910 MODULE" --version "BP_R1.0.0"
  271. --flashtype 1
  272. cfg-host-fdl -a ${CONFIG_FDL1_IMAGE_START} -s ${CONFIG_FDL1_IMAGE_SIZE}
  273. -p ${out_hex_dir}/fdl1.sign.img
  274. cfg-fdl2 -a ${CONFIG_FDL2_IMAGE_START} -s ${CONFIG_FDL2_IMAGE_SIZE}
  275. -p ${out_hex_dir}/fdl2.sign.img
  276. )
  277. endif()
  278. if(CONFIG_SOC_8811)
  279. set(${cmd}
  280. cfg-init --pname "8811_MODEM" --palias ${BUILD_TARGET}
  281. --pversion "8811 MODULE" --version "BP_R1.0.0"
  282. --flashtype 0
  283. cfg-fdl -a ${CONFIG_NORFDL_IMAGE_START} -s ${CONFIG_NORFDL_IMAGE_SIZE}
  284. -p ${pac_fdl_files}
  285. )
  286. endif()
  287. if(CONFIG_SOC_8850)
  288. set(${cmd}
  289. cfg-init --pname "8850_MODEM" --palias ${BUILD_TARGET}
  290. --pversion "8850 MODULE" --version "BP_R1.0.0"
  291. --flashtype 0
  292. cfg-fdl -a ${CONFIG_NORFDL_IMAGE_START} -s ${CONFIG_NORFDL_IMAGE_SIZE}
  293. -p ${pac_fdl_files}
  294. )
  295. endif()
  296. endmacro()
  297. # Build unittest target. Parameters are source files.
  298. # When PAC is supported, PAC is create with unittest only.
  299. function(add_unittest target)
  300. if(CONFIG_SOC_8910)
  301. add_uimage(${target} ${unittest_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  302. OUTPUT_DIR ${out_hex_unittest_dir})
  303. target_link_libraries(${target} PRIVATE all_libs)
  304. add_dependencies(unittests ${target})
  305. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  306. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  307. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  308. pac_init_fdl(init_fdl)
  309. sign_image(${target_img_file} ${target_sign_img_file})
  310. add_custom_command(OUTPUT ${pac_file}
  311. COMMAND python3 ${pacgen_py} ${init_fdl}
  312. cfg-image -i UNITTEST -a ${CONFIG_APP_FLASH_ADDRESS}
  313. -s ${CONFIG_APP_FLASH_SIZE}
  314. -p ${target_sign_img_file}
  315. pac-gen ${pac_file}
  316. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  317. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  318. )
  319. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  320. add_dependencies(unittests ${target}_pacgen)
  321. endif()
  322. if(CONFIG_SOC_8811)
  323. add_simage(${target} ${unittest_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  324. OUTPUT_DIR ${out_hex_unittest_dir})
  325. target_link_libraries(${target} PRIVATE all_libs)
  326. add_dependencies(unittests ${target})
  327. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  328. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  329. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  330. pac_init_fdl(init_fdl)
  331. sign_image(${target_img_file} ${target_sign_img_file})
  332. add_custom_command(OUTPUT ${pac_file}
  333. COMMAND python3 ${pacgen_py} ${init_fdl}
  334. cfg-image -i UNITTEST -a ${CONFIG_APP_FLASH_ADDRESS}
  335. -s ${CONFIG_APP_FLASH_SIZE}
  336. -p ${target_sign_img_file}
  337. pac-gen ${pac_file}
  338. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  339. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  340. )
  341. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  342. add_dependencies(unittests ${target}_pacgen)
  343. endif()
  344. if(CONFIG_SOC_8850)
  345. add_simage(${target} ${unittest_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  346. OUTPUT_DIR ${out_hex_unittest_dir})
  347. target_link_libraries(${target} PRIVATE all_libs)
  348. add_dependencies(unittests ${target})
  349. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  350. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  351. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  352. pac_init_fdl(init_fdl)
  353. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  354. add_custom_command(OUTPUT ${pac_file}
  355. COMMAND python3 ${pacgen_py} ${init_fdl}
  356. cfg-image -i UNITTEST -a ${CONFIG_APP_FLASH_ADDRESS}
  357. -s ${CONFIG_APP_FLASH_SIZE}
  358. -p ${target_sign_img_file}
  359. pac-gen ${pac_file}
  360. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  361. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  362. )
  363. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  364. add_dependencies(unittests ${target}_pacgen)
  365. endif()
  366. endfunction()
  367. # Build unittest target. Parameters are source files.
  368. # When PAC is supported, PAC is create with unittest only.
  369. function(add_boot_unittest target)
  370. if(CONFIG_SOC_8910)
  371. add_uimage(${target} ${ramrun_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  372. OUTPUT_DIR ${out_hex_unittest_dir})
  373. target_link_whole_archive(${target} PRIVATE bootloader)
  374. target_link_libraries(${target} PRIVATE all_libs)
  375. add_dependencies(unittests ${target})
  376. target_compile_definitions(${target}_ldscript PRIVATE
  377. RAMRUN_IMAGE_START=${CONFIG_FDL1_IMAGE_START}
  378. RAMRUN_IMAGE_SIZE=${CONFIG_FDL1_IMAGE_SIZE}
  379. RAMRUN_MMU_ENABLE=1
  380. )
  381. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  382. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  383. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  384. sign_image(${target_img_file} ${target_sign_img_file})
  385. add_custom_command(OUTPUT ${pac_file}
  386. COMMAND python3 ${pacgen_py}
  387. cfg-init --pname "UIX8910_MODEM" --palias ${BUILD_TARGET}
  388. --pversion "8910 MODULE" --version "BP_R1.0.0"
  389. --flashtype 1
  390. cfg-host-fdl -a ${CONFIG_FDL1_IMAGE_START} -s ${CONFIG_FDL1_IMAGE_SIZE}
  391. -p ${target_sign_img_file}
  392. pac-gen ${pac_file}
  393. DEPENDS ${pacgen_py} ${target_sign_img_file}
  394. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  395. )
  396. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  397. add_dependencies(unittests ${target}_pacgen)
  398. endif()
  399. if(CONFIG_SOC_8811)
  400. add_simage(${target} ${ramrun_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  401. OUTPUT_DIR ${out_hex_unittest_dir})
  402. target_link_whole_archive(${target} PRIVATE bootloader)
  403. target_link_libraries(${target} PRIVATE all_libs)
  404. add_dependencies(unittests ${target})
  405. target_compile_definitions(${target}_ldscript PRIVATE
  406. RAMRUN_IMAGE_START=${CONFIG_NORFDL_IMAGE_START}
  407. RAMRUN_IMAGE_SIZE=${CONFIG_NORFDL_IMAGE_SIZE}
  408. )
  409. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  410. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  411. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  412. sign_image(${target_img_file} ${target_sign_img_file})
  413. add_custom_command(OUTPUT ${pac_file}
  414. COMMAND python3 ${pacgen_py}
  415. cfg-init --pname "8811_MODEM" --palias ${BUILD_TARGET}
  416. --pversion "8811 MODULE" --version "BP_R1.0.0"
  417. --flashtype 0
  418. cfg-fdl -a ${CONFIG_NORFDL_IMAGE_START} -s ${CONFIG_NORFDL_IMAGE_SIZE}
  419. -p ${target_sign_img_file}
  420. pac-gen ${pac_file}
  421. DEPENDS ${pacgen_py} ${target_sign_img_file}
  422. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  423. )
  424. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  425. add_dependencies(unittests ${target}_pacgen)
  426. endif()
  427. if(CONFIG_SOC_8850)
  428. add_simage(${target} ${ramrun_ldscript} EXCLUDE_FROM_ALL ${ARGN}
  429. OUTPUT_DIR ${out_hex_unittest_dir})
  430. target_link_whole_archive(${target} PRIVATE bootloader)
  431. target_link_libraries(${target} PRIVATE all_libs)
  432. add_dependencies(unittests ${target})
  433. target_compile_definitions(${target}_ldscript PRIVATE
  434. RAMRUN_IMAGE_START=${CONFIG_NORFDL_IMAGE_START}
  435. RAMRUN_IMAGE_SIZE=${CONFIG_NORFDL_IMAGE_SIZE}
  436. )
  437. set(pac_file ${out_hex_unittest_dir}/${target}.pac)
  438. set(target_img_file ${out_hex_unittest_dir}/${target}.img)
  439. set(target_sign_img_file ${out_hex_unittest_dir}/${target}.sign.img)
  440. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  441. add_custom_command(OUTPUT ${pac_file}
  442. COMMAND python3 ${pacgen_py}
  443. cfg-init --pname "8850_MODEM" --palias ${BUILD_TARGET}
  444. --pversion "8850 MODULE" --version "BP_R1.0.0"
  445. --flashtype 0
  446. cfg-fdl -a ${CONFIG_NORFDL_IMAGE_START} -s ${CONFIG_NORFDL_IMAGE_SIZE}
  447. -p ${target_sign_img_file}
  448. pac-gen ${pac_file}
  449. DEPENDS ${pacgen_py} ${target_sign_img_file}
  450. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  451. )
  452. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  453. add_dependencies(unittests ${target}_pacgen)
  454. endif()
  455. endfunction()
  456. # Build example target. Parameters are source files.
  457. # When PAC is supported, PAC is create with unittest only.
  458. function(add_example target)
  459. if(CONFIG_SOC_8910)
  460. add_uimage(${target} ${example_ldscript} ${ARGN}
  461. OUTPUT_DIR ${out_hex_example_dir})
  462. target_link_libraries(${target} PRIVATE all_libs)
  463. set(pac_file ${out_hex_example_dir}/${target}.pac)
  464. set(target_img_file ${out_hex_example_dir}/${target}.img)
  465. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  466. pac_init_fdl(init_fdl)
  467. sign_image(${target_img_file} ${target_sign_img_file})
  468. add_custom_command(OUTPUT ${pac_file}
  469. COMMAND python3 ${pacgen_py} ${init_fdl}
  470. cfg-image -i EXAMPLE -a ${CONFIG_APP_FLASH_ADDRESS}
  471. -s ${CONFIG_APP_FLASH_SIZE}
  472. -p ${target_sign_img_file}
  473. pac-gen ${pac_file}
  474. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  475. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  476. )
  477. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  478. endif()
  479. if(CONFIG_SOC_8811)
  480. add_simage(${target} ${example_ldscript} ${ARGN}
  481. OUTPUT_DIR ${out_hex_example_dir})
  482. target_link_libraries(${target} PRIVATE all_libs)
  483. set(pac_file ${out_hex_example_dir}/${target}.pac)
  484. set(target_img_file ${out_hex_example_dir}/${target}.img)
  485. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  486. pac_init_fdl(init_fdl)
  487. sign_image(${target_img_file} ${target_sign_img_file})
  488. add_custom_command(OUTPUT ${pac_file}
  489. COMMAND python3 ${pacgen_py} ${init_fdl}
  490. cfg-image -i EXAMPLE -a ${CONFIG_APP_FLASH_ADDRESS}
  491. -s ${CONFIG_APP_FLASH_SIZE}
  492. -p ${target_sign_img_file}
  493. pac-gen ${pac_file}
  494. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  495. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  496. )
  497. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  498. endif()
  499. if(CONFIG_SOC_8850)
  500. add_simage(${target} ${example_ldscript} ${ARGN}
  501. OUTPUT_DIR ${out_hex_example_dir})
  502. target_link_libraries(${target} PRIVATE all_libs)
  503. set(pac_file ${out_hex_example_dir}/${target}.pac)
  504. set(target_img_file ${out_hex_example_dir}/${target}.img)
  505. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  506. pac_init_fdl(init_fdl)
  507. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  508. add_custom_command(OUTPUT ${pac_file}
  509. COMMAND python3 ${pacgen_py} ${init_fdl}
  510. cfg-image -i EXAMPLE -a ${CONFIG_APP_FLASH_ADDRESS}
  511. -s ${CONFIG_APP_FLASH_SIZE}
  512. -p ${target_sign_img_file}
  513. pac-gen ${pac_file}
  514. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  515. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  516. )
  517. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  518. endif()
  519. endfunction()
  520. # Build opencpu target img. Parameters are source files.
  521. # When PAC is supported, PAC is create with opencpu app only.
  522. function(add_opencpu_img target)
  523. if(CONFIG_SOC_8811)
  524. set(opencpu_ldscript ${SOURCE_TOP_DIR}/components/openCPU/pack/opencpu_8811.ld)
  525. add_simage(${target} ${opencpu_ldscript} ${ARGN} IMGVER ${CONFIG_OPENCPU_VERSION}
  526. OUTPUT_DIR ${out_hex_example_dir})
  527. endif()
  528. endfunction()
  529. # Build opencpu example target. Parameters are source files.
  530. # When PAC is supported, PAC is create with opencpu app only.
  531. function(add_opencpu_example target)
  532. if(CONFIG_SOC_8811)
  533. add_opencpu_img(${target} ${ARGN})
  534. set(pac_file ${out_hex_example_dir}/${target}.pac)
  535. set(target_img_file ${out_hex_example_dir}/${target}.img)
  536. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  537. pac_init_fdl(init_fdl)
  538. sign_image(${target_img_file} ${target_sign_img_file})
  539. add_custom_command(OUTPUT ${pac_file}
  540. COMMAND python3 ${pacgen_py} ${init_fdl}
  541. cfg-image -i OPENCPU -a ${CONFIG_OPENCPU_FLASH_ADDRESS}
  542. -s ${CONFIG_OPENCPU_FLASH_SIZE}
  543. -p ${target_sign_img_file}
  544. pac-gen ${pac_file}
  545. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file}
  546. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  547. )
  548. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  549. endif()
  550. endfunction()
  551. function(add_rom_lod target ldscript)
  552. set(gen_ldscript ${target}_ldscript)
  553. set(target_map_file ${out_hex_dir}/${target}.map)
  554. set(target_lod_file ${out_hex_dir}/${target}.lod)
  555. cpp_only(${gen_ldscript} ${ldscript} hal)
  556. add_executable(${target} ${ARGN})
  557. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out_hex_dir})
  558. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  559. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections ${link_cref_option})
  560. add_custom_command(TARGET ${target} POST_BUILD
  561. COMMAND ${cmd_elf2lod} $<TARGET_FILE:${target}> ${target_lod_file}
  562. BYPRODUCTS ${target_lod_file} ${target_map_file}
  563. )
  564. endfunction()
  565. function(add_elf target ldscript)
  566. set(gen_ldscript ${target}_ldscript)
  567. set(target_map_file ${out_hex_dir}/${target}.map)
  568. cpp_only(${gen_ldscript} ${ldscript} hal)
  569. add_executable(${target} ${ARGN})
  570. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out_hex_dir})
  571. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  572. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections ${link_cref_option})
  573. target_depend_rom_ld(${target})
  574. endfunction()
  575. # Build appimg with specified link script.
  576. function(add_appimg target ldscript) # <sources> LINK_LIBRARIES <libs> OUTPUT_DIR <dir>
  577. cmake_parse_arguments(MY "" "" "LINK_LIBRARIES;OUTPUT_DIR" ${ARGN})
  578. set(MY_SOURCES ${MY_UNPARSED_ARGUMENTS} ${core_stub_o})
  579. set(MY_LINK_LIBRARIES ${MY_LINK_LIBRARIES} ${libc_file_name} ${libm_file_name} ${libgcc_file_name})
  580. if(NOT MY_OUTPUT_DIR)
  581. set(MY_OUTPUT_DIR ${out_hex_dir})
  582. endif()
  583. set(gen_ldscript ${target}_ldscript)
  584. set(target_app_image_file ${out_hex_example_dir}/${target}.appimg)
  585. set(target_map_file ${MY_OUTPUT_DIR}/${target}.map)
  586. set(target_img_file ${MY_OUTPUT_DIR}/${target}.img)
  587. cpp_only(${gen_ldscript} ${ldscript})
  588. add_executable(${target} ${MY_SOURCES})
  589. set_source_files_properties(${core_stub_o} PROPERTIES GENERATED on)
  590. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MY_OUTPUT_DIR})
  591. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  592. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections ${link_cref_option})
  593. target_link_libraries(${target} PRIVATE ${MY_LINK_LIBRARIES})
  594. target_depend_rom_ld(${target})
  595. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811))
  596. add_custom_command(TARGET ${target} POST_BUILD
  597. COMMAND ${cmd_mkappimg} $<TARGET_FILE:${target}> ${target_img_file}
  598. BYPRODUCTS ${target_img_file} ${target_map_file}
  599. )
  600. endif()
  601. if(CONFIG_SOC_8850)
  602. add_custom_command(TARGET ${target} POST_BUILD
  603. COMMAND ${cmd_mkappimg} $<TARGET_FILE:${target}> ${target_app_image_file}
  604. BYPRODUCTS ${target_img_file} ${target_map_file} ${target_app_image_file}
  605. )
  606. add_custom_command(TARGET ${target} POST_BUILD
  607. COMMAND ${cmd_mksimage} --bin --load 0x0 --entry 0x0
  608. --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}"
  609. --imgver "1.1" --platform "8811" --check crc
  610. ${target_app_image_file} ${target_img_file}
  611. )
  612. endif()
  613. endfunction()
  614. # Build example appimg (linked in flash). Parameters are source files.
  615. function(add_appimg_flash_example target)
  616. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app_flashimg.ld)
  617. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  618. OUTPUT_DIR ${out_hex_example_dir})
  619. add_dependencies(examples ${target})
  620. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  621. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  622. set(pac_file ${out_hex_example_dir}/${target}.pac)
  623. set(target_img_file ${out_hex_example_dir}/${target}.img)
  624. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  625. pac_init_fdl(init_fdl)
  626. if(CONFIG_SOC_8910)
  627. sign_image(${target_img_file} ${target_sign_img_file})
  628. endif()
  629. if(CONFIG_SOC_8850)
  630. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  631. endif()
  632. #if(CONFIG_SOC_8811)
  633. # sign_image(${target_img_file} ${target_sign_img_file})
  634. #endif()
  635. add_custom_command(OUTPUT ${prepack_cpio}
  636. COMMAND python3 ${modemgen_py} prepackgen
  637. --source-top ${SOURCE_TOP_DIR}
  638. --binary-top ${BINARY_TOP_DIR}
  639. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  640. ${prepack_cpio}
  641. DEPENDS ${modemgen_py}
  642. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  643. )
  644. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  645. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  646. set(prepack_file ${prepack_cpio})
  647. endif()
  648. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  649. add_custom_command(OUTPUT ${pac_file}
  650. COMMAND python3 ${pacgen_py} ${init_fdl}
  651. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  652. -s ${CONFIG_APPIMG_FLASH_SIZE}
  653. -p ${target_sign_img_file}
  654. ${cfg_pack_gpio}
  655. pac-gen ${pac_file}
  656. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file}
  657. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  658. )
  659. else()
  660. add_custom_command(OUTPUT ${pac_file}
  661. COMMAND python3 ${pacgen_py} ${init_fdl}
  662. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  663. -s ${CONFIG_APPIMG_FLASH_SIZE}
  664. -p ${target_img_file}
  665. ${cfg_pack_gpio}
  666. pac-gen ${pac_file}
  667. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  668. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  669. )
  670. endif()
  671. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  672. add_dependencies(examples ${target}_pacgen)
  673. endif()
  674. endfunction()
  675. # Build example appimg (linked in file). Parameters are source files.
  676. function(add_appimg_file_example target)
  677. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app_fileimg.ld)
  678. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  679. OUTPUT_DIR ${out_hex_example_dir})
  680. add_dependencies(examples ${target})
  681. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  682. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  683. set(pac_file ${out_hex_example_dir}/${target}.pac)
  684. set(target_img_file ${out_hex_example_dir}/${target}.img)
  685. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  686. pac_init_fdl(init_fdl)
  687. if(CONFIG_SOC_8910)
  688. sign_image(${target_img_file} ${target_sign_img_file})
  689. endif()
  690. if(CONFIG_SOC_8850)
  691. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  692. endif()
  693. #if(CONFIG_SOC_8811)
  694. # sign_image(${target_img_file} ${target_sign_img_file})
  695. #endif()
  696. add_custom_command(OUTPUT ${prepack_cpio}
  697. COMMAND python3 ${modemgen_py} prepackgen
  698. --source-top ${SOURCE_TOP_DIR}
  699. --binary-top ${BINARY_TOP_DIR}
  700. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  701. ${prepack_cpio}
  702. DEPENDS ${modemgen_py}
  703. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  704. )
  705. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  706. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  707. set(prepack_file ${prepack_cpio})
  708. endif()
  709. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  710. add_custom_command(OUTPUT ${pac_file}
  711. COMMAND python3 ${pacgen_py} ${init_fdl}
  712. cfg-pack-file -i APPIMG -p ${target_sign_img_file}
  713. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  714. ${cfg_pack_gpio}
  715. pac-gen ${pac_file}
  716. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file}
  717. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  718. )
  719. else()
  720. add_custom_command(OUTPUT ${pac_file}
  721. COMMAND python3 ${pacgen_py} ${init_fdl}
  722. cfg-pack-file -i APPIMG -p ${target_img_file}
  723. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  724. ${cfg_pack_gpio}
  725. pac-gen ${pac_file}
  726. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  727. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  728. )
  729. endif()
  730. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  731. add_dependencies(examples ${target}_pacgen)
  732. endif()
  733. endfunction()
  734. # quectel start
  735. # Build ql_example appimg (linked in flash). Parameters are source files.
  736. function(add_appimg_flash_ql_example target)
  737. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app_flashimg.ld)
  738. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  739. OUTPUT_DIR ${out_hex_example_dir})
  740. add_dependencies(ql_examples ${target})
  741. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  742. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  743. set(pac_file ${out_hex_example_dir}/${target}.pac)
  744. set(target_img_file ${out_hex_example_dir}/${target}.img)
  745. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  746. pac_init_fdl(init_fdl)
  747. if(CONFIG_SOC_8910)
  748. #sign_image(${target_img_file} ${target_sign_img_file})
  749. endif()
  750. if(CONFIG_SOC_8850)
  751. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  752. endif()
  753. add_custom_command(OUTPUT ${prepack_cpio}
  754. COMMAND python3 ${modemgen_py} prepackgen
  755. --source-top ${SOURCE_TOP_DIR}
  756. --binary-top ${BINARY_TOP_DIR}
  757. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  758. ${prepack_cpio}
  759. DEPENDS ${modemgen_py}
  760. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  761. )
  762. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  763. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  764. set(prepack_file ${prepack_cpio})
  765. endif()
  766. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  767. add_custom_command(OUTPUT ${pac_file}
  768. COMMAND python3 ${pacgen_py} ${init_fdl}
  769. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  770. -s ${CONFIG_APPIMG_FLASH_SIZE}
  771. #-p ${target_img_file} # quectel update
  772. -p ${target_sign_img_file} # quectel update
  773. ${cfg_pack_gpio}
  774. pac-gen ${pac_file}
  775. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file} # quectel update
  776. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  777. )
  778. else()
  779. add_custom_command(OUTPUT ${pac_file}
  780. COMMAND python3 ${pacgen_py} ${init_fdl}
  781. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  782. -s ${CONFIG_APPIMG_FLASH_SIZE}
  783. -p ${target_img_file}
  784. ${cfg_pack_gpio}
  785. pac-gen ${pac_file}
  786. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  787. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  788. )
  789. endif()
  790. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  791. add_dependencies(ql_examples ${target}_pacgen)
  792. endif()
  793. endfunction()
  794. # quectel start
  795. # Build ql_example appimg2 (linked in flash). Parameters are source files.
  796. function(add_appimg2_flash_ql_example target)
  797. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app2_flashimg.ld)
  798. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  799. OUTPUT_DIR ${out_hex_example_dir})
  800. add_dependencies(ql_examples ${target})
  801. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  802. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  803. set(pac_file ${out_hex_example_dir}/${target}.pac)
  804. set(target_img_file ${out_hex_example_dir}/${target}.img)
  805. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  806. pac_init_fdl(init_fdl)
  807. if(CONFIG_SOC_8910)
  808. #sign_image(${target_img_file} ${target_sign_img_file})
  809. endif()
  810. if(CONFIG_SOC_8850)
  811. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  812. endif()
  813. add_custom_command(OUTPUT ${prepack_cpio}
  814. COMMAND python3 ${modemgen_py} prepackgen
  815. --source-top ${SOURCE_TOP_DIR}
  816. --binary-top ${BINARY_TOP_DIR}
  817. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG2_JSON_PATH}
  818. ${prepack_cpio}
  819. DEPENDS ${modemgen_py}
  820. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  821. )
  822. if(CONFIG_PACKAGE_FILE_APPIMG2_JSON_PATH)
  823. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  824. set(prepack_file ${prepack_cpio})
  825. endif()
  826. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  827. add_custom_command(OUTPUT ${pac_file}
  828. COMMAND python3 ${pacgen_py} ${init_fdl}
  829. cfg-image -i APPIMG2 -a ${CONFIG_APPIMG2_FLASH_ADDRESS}
  830. -s ${CONFIG_APPIMG2_FLASH_SIZE}
  831. #-p ${target_img_file} # quectel update
  832. -p ${target_sign_img_file} # quectel update
  833. ${cfg_pack_gpio}
  834. pac-gen ${pac_file}
  835. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file} # quectel update
  836. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  837. )
  838. else()
  839. add_custom_command(OUTPUT ${pac_file}
  840. COMMAND python3 ${pacgen_py} ${init_fdl}
  841. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  842. -s ${CONFIG_APPIMG_FLASH_SIZE}
  843. -p ${target_img_file}
  844. ${cfg_pack_gpio}
  845. pac-gen ${pac_file}
  846. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  847. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  848. )
  849. endif()
  850. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  851. add_dependencies(ql_examples ${target}_pacgen)
  852. endif()
  853. endfunction()
  854. # Build ql_example appimg (linked in file). Parameters are source files.
  855. function(add_appimg_file_ql_example target)
  856. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app_fileimg.ld)
  857. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  858. OUTPUT_DIR ${out_hex_example_dir})
  859. add_dependencies(ql_examples ${target})
  860. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  861. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  862. set(pac_file ${out_hex_example_dir}/${target}.pac)
  863. set(target_img_file ${out_hex_example_dir}/${target}.img)
  864. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  865. pac_init_fdl(init_fdl)
  866. if(CONFIG_SOC_8910)
  867. #sign_image(${target_img_file} ${target_sign_img_file})
  868. endif()
  869. if(CONFIG_SOC_8850)
  870. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  871. endif()
  872. add_custom_command(OUTPUT ${prepack_cpio}
  873. COMMAND python3 ${modemgen_py} prepackgen
  874. --source-top ${SOURCE_TOP_DIR}
  875. --binary-top ${BINARY_TOP_DIR}
  876. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  877. ${prepack_cpio}
  878. DEPENDS ${modemgen_py}
  879. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  880. )
  881. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  882. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  883. set(prepack_file ${prepack_cpio})
  884. endif()
  885. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  886. add_custom_command(OUTPUT ${pac_file}
  887. COMMAND python3 ${pacgen_py} ${init_fdl}
  888. cfg-pack-file -i APPIMG -p ${target_sign_img_file}
  889. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  890. ${cfg_pack_gpio}
  891. pac-gen ${pac_file}
  892. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file}
  893. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  894. )
  895. else()
  896. add_custom_command(OUTPUT ${pac_file}
  897. COMMAND python3 ${pacgen_py} ${init_fdl}
  898. cfg-pack-file -i APPIMG -p ${target_img_file}
  899. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  900. ${cfg_pack_gpio}
  901. pac-gen ${pac_file}
  902. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  903. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  904. )
  905. endif()
  906. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  907. add_dependencies(ql_examples ${target}_pacgen)
  908. endif()
  909. endfunction()
  910. # Build ql_example appimg2 (linked in file). Parameters are source files.
  911. function(add_appimg2_file_ql_example target)
  912. set(ldscript ${SOURCE_TOP_DIR}/components/apploader/pack/app2_fileimg.ld)
  913. add_appimg(${target} ${ldscript} EXCLUDE_FROM_ALL ${ARGN}
  914. OUTPUT_DIR ${out_hex_example_dir})
  915. add_dependencies(ql_examples ${target})
  916. set(prepack_cpio ${out_hex_dir}/examples/${target}_prepack.cpio)
  917. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  918. set(pac_file ${out_hex_example_dir}/${target}.pac)
  919. set(target_img_file ${out_hex_example_dir}/${target}.img)
  920. set(target_sign_img_file ${out_hex_example_dir}/${target}.sign.img)
  921. pac_init_fdl(init_fdl)
  922. if(CONFIG_SOC_8910)
  923. #sign_image(${target_img_file} ${target_sign_img_file})
  924. endif()
  925. if(CONFIG_SOC_8850)
  926. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  927. endif()
  928. add_custom_command(OUTPUT ${prepack_cpio}
  929. COMMAND python3 ${modemgen_py} prepackgen
  930. --source-top ${SOURCE_TOP_DIR}
  931. --binary-top ${BINARY_TOP_DIR}
  932. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG2_JSON_PATH}
  933. ${prepack_cpio}
  934. DEPENDS ${modemgen_py}
  935. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  936. )
  937. if(CONFIG_PACKAGE_FILE_APPIMG2_JSON_PATH)
  938. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  939. set(prepack_file ${prepack_cpio})
  940. endif()
  941. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8850))
  942. add_custom_command(OUTPUT ${pac_file}
  943. COMMAND python3 ${pacgen_py} ${init_fdl}
  944. cfg-pack-file -i APPIMG2 -p ${target_sign_img_file}
  945. -n ${CONFIG_APPIMG2_LOAD_FILE_NAME}
  946. ${cfg_pack_gpio}
  947. pac-gen ${pac_file}
  948. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_sign_img_file} ${prepack_file}
  949. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  950. )
  951. else()
  952. add_custom_command(OUTPUT ${pac_file}
  953. COMMAND python3 ${pacgen_py} ${init_fdl}
  954. cfg-pack-file -i APPIMG2 -p ${target_img_file}
  955. -n ${CONFIG_APPIMG2_LOAD_FILE_NAME}
  956. ${cfg_pack_gpio}
  957. pac-gen ${pac_file}
  958. DEPENDS ${pacgen_py} ${pac_fdl_files} ${target_img_file} ${prepack_file}
  959. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  960. )
  961. endif()
  962. add_custom_target(${target}_pacgen DEPENDS ${pac_file})
  963. add_dependencies(ql_examples ${target}_pacgen)
  964. endif()
  965. endfunction()
  966. # quectel end
  967. # Build appimg (flash and file) pac to delete appimg.
  968. function(add_appimg_delete)
  969. if((CONFIG_SOC_8910) OR (CONFIG_SOC_8811) OR (CONFIG_SOC_8850))
  970. if(CONFIG_APPIMG_LOAD_FLASH)
  971. set(target appimg_flash_delete)
  972. set(pac_file ${out_hex_dir}/${target}.pac)
  973. pac_init_fdl(init_fdl)
  974. add_custom_command(OUTPUT ${pac_file}
  975. COMMAND python3 ${pacgen_py} ${init_fdl}
  976. cfg-erase-flash -i ERASE_APPIMG
  977. -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  978. -s ${CONFIG_APPIMG_FLASH_SIZE}
  979. pac-gen ${pac_file}
  980. DEPENDS ${pacgen_py} ${pac_fdl_files}
  981. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  982. )
  983. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  984. if(CONFIG_QUEC_PROJECT_FEATURE_APPIMG2) #quectel update
  985. set(target appimg2_flash_delete)
  986. set(pac_file ${out_hex_dir}/${target}.pac)
  987. pac_init_fdl(init_fdl)
  988. add_custom_command(OUTPUT ${pac_file}
  989. COMMAND python3 ${pacgen_py} ${init_fdl}
  990. cfg-erase-flash -i ERASE_APPIMG2
  991. -a ${CONFIG_APPIMG2_FLASH_ADDRESS}
  992. -s ${CONFIG_APPIMG2_FLASH_SIZE}
  993. pac-gen ${pac_file}
  994. DEPENDS ${pacgen_py} ${pac_fdl_files}
  995. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  996. )
  997. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  998. endif()
  999. endif()
  1000. if(CONFIG_APPIMG_LOAD_FILE)
  1001. set(target appimg_file_delete)
  1002. set(pac_file ${out_hex_dir}/${target}.pac)
  1003. pac_init_fdl(init_fdl)
  1004. add_custom_command(OUTPUT ${pac_file}
  1005. COMMAND python3 ${pacgen_py} ${init_fdl}
  1006. cfg-del-appimg -i DEL_APPIMG
  1007. pac-gen ${pac_file}
  1008. DEPENDS ${pacgen_py} ${pac_fdl_files}
  1009. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  1010. )
  1011. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  1012. if(CONFIG_QUEC_PROJECT_FEATURE_APPIMG2) #quectel update
  1013. set(target appimg2_file_delete)
  1014. set(pac_file ${out_hex_dir}/${target}.pac)
  1015. pac_init_fdl(init_fdl)
  1016. add_custom_command(OUTPUT ${pac_file}
  1017. COMMAND python3 ${pacgen_py} ${init_fdl}
  1018. cfg-del-appimg -i DEL_APPIMG2
  1019. pac-gen ${pac_file}
  1020. DEPENDS ${pacgen_py} ${pac_fdl_files}
  1021. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  1022. )
  1023. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  1024. endif()
  1025. endif()
  1026. endif()
  1027. endfunction()
  1028. macro(relative_glob var)
  1029. file(GLOB ${var} RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${ARGN})
  1030. endmacro()
  1031. function(beautify_c_code target)
  1032. if(ARGN)
  1033. set(beautify_target beautify_${target})
  1034. if(NOT TARGET ${beautify_target})
  1035. add_custom_target(${beautify_target})
  1036. add_dependencies(beautify ${beautify_target})
  1037. endif()
  1038. add_custom_command(TARGET ${beautify_target} POST_BUILD
  1039. COMMAND clang-format -i ${ARGN}
  1040. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  1041. endif()
  1042. endfunction()
  1043. function(rpcstubgen xml sender receiver)
  1044. get_filename_component(name ${xml} NAME_WE)
  1045. configure_file(${xml} ${out_rpc_dir}/${name}.xml)
  1046. set(gen ${out_rpc_dir}/${name}_${sender}.c
  1047. ${out_rpc_dir}/${name}_${receiver}.c
  1048. ${out_rpc_dir}/${name}_api.h
  1049. ${out_rpc_dir}/${name}_par.h)
  1050. add_custom_command(
  1051. OUTPUT ${gen}
  1052. COMMAND python3 ${tools_dir}/rpcgen.py stubgen ${xml}
  1053. DEPENDS ${xml} ${tools_dir}/rpcgen.py
  1054. WORKING_DIRECTORY ${out_rpc_dir}
  1055. )
  1056. add_custom_target(${name}_rpcgen DEPENDS ${gen})
  1057. add_dependencies(rpcgen ${name}_rpcgen)
  1058. endfunction()
  1059. function(rpcdispatchgen cfile side)
  1060. get_filename_component(name ${cfile} NAME_WE)
  1061. set(xmls)
  1062. foreach(xml ${ARGN})
  1063. list(APPEND xmls ${out_rpc_dir}/${xml})
  1064. endforeach()
  1065. add_custom_command(
  1066. OUTPUT ${out_rpc_dir}/${cfile}
  1067. COMMAND python3 ${tools_dir}/rpcgen.py dispatchgen ${cfile} ${side} ${xmls}
  1068. DEPENDS ${tools_dir}/rpcgen.py ${xmls}
  1069. WORKING_DIRECTORY ${out_rpc_dir}
  1070. )
  1071. add_custom_target(${name}_rpcgen DEPENDS ${out_rpc_dir}/${cfile})
  1072. add_dependencies(rpcgen ${name}_rpcgen)
  1073. endfunction()
  1074. function(nanopbgen)
  1075. foreach(file ${ARGN})
  1076. get_filename_component(name ${file} NAME_WE)
  1077. get_filename_component(fpath ${file} DIRECTORY)
  1078. add_custom_command(
  1079. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.pb.h ${CMAKE_CURRENT_BINARY_DIR}/${name}.pb.c
  1080. COMMAND protoc --proto_path=${fpath} --nanopb_out=${CMAKE_CURRENT_BINARY_DIR} ${file}
  1081. DEPENDS ${file}
  1082. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  1083. )
  1084. endforeach(file ${ARGN})
  1085. endfunction()