CMakeLists_8910.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. cmake_minimum_required(VERSION 3.13)
  12. set(SOURCE_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  13. set(BINARY_TOP_DIR ${CMAKE_CURRENT_BINARY_DIR})
  14. set(CMAKE_C_COMPILER_FORCED 1)
  15. set(CMAKE_CXX_COMPILER_FORCED 1)
  16. set(out_hex_dir ${CMAKE_CURRENT_BINARY_DIR}/hex)
  17. set(out_lib_dir ${CMAKE_CURRENT_BINARY_DIR}/lib)
  18. set(out_inc_dir ${CMAKE_CURRENT_BINARY_DIR}/include)
  19. set(tools_dir ${CMAKE_CURRENT_SOURCE_DIR}/tools)
  20. set(core_stub_o ${CMAKE_CURRENT_SOURCE_DIR}/components/lib/core_stub.o)
  21. set(flash_ldscript ${SOURCE_TOP_DIR}/ldscripts/app_flashimg.ld)
  22. set(file_ldscript ${SOURCE_TOP_DIR}/ldscripts/app_fileimg.ld)
  23. set(cmd_mkappimg dtools mkappimg)
  24. set(pacgen_py ${tools_dir}/pacgen.py)
  25. set(modemgen_py ${tools_dir}/modemgen.py)
  26. include(cmake/core_config.cmake)
  27. include(cmake/toolchain-gcc.cmake)
  28. set(BUILD_SHARED_LIBS OFF)
  29. project(core C CXX ASM)
  30. include_directories(components/include)
  31. function(cpp_only target file)
  32. add_library(${target} OBJECT ${file})
  33. set_source_files_properties(${file} PROPERTIES LANGUAGE C)
  34. target_compile_options(${target} PRIVATE -E -P -x c)
  35. endfunction()
  36. set(sign_password 12345678) # customer product shall replace with customer's key
  37. set(sign_product test) # customer product shall replace with customer's product name
  38. function(sign_image src dst)
  39. add_custom_command(OUTPUT ${dst}
  40. COMMAND vlrsign --pw ${sign_password} --pn ${sign_product} --ha Blake2
  41. --img ${src} --out ${dst}
  42. DEPENDS ${src}
  43. )
  44. endfunction()
  45. function(add_appimg target ldscript)
  46. set(gen_ldscript ${target}_ldscript)
  47. set(target_map_file ${out_hex_dir}/${target}.map)
  48. set(target_img_file ${out_hex_dir}/${target}.img)
  49. cpp_only(${gen_ldscript} ${ldscript})
  50. add_executable(${target} ${ARGN} ${core_stub_o})
  51. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out_hex_dir})
  52. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  53. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections)
  54. add_custom_command(TARGET ${target} POST_BUILD
  55. COMMAND ${cmd_mkappimg} $<TARGET_FILE:${target}> ${target_img_file}
  56. BYPRODUCTS ${target_img_file} ${target_map_file}
  57. )
  58. endfunction()
  59. configure_file(${SOURCE_TOP_DIR}/components/lib/fdl1.img ${out_hex_dir}/fdl1.img COPYONLY)
  60. configure_file(${SOURCE_TOP_DIR}/components/lib/fdl2.img ${out_hex_dir}/fdl2.img COPYONLY)
  61. macro(pac_init_fdl cmd)
  62. set(${cmd}
  63. cfg-init --pname UIX8910_MODEM --palias "APPIMG"
  64. --pversion "8910 MODULE" --version "BP_R1.0.0"
  65. --flashtype 1
  66. cfg-host-fdl -a ${CONFIG_FDL1_IMAGE_START} -s ${CONFIG_FDL1_IMAGE_SIZE}
  67. -p ${out_hex_dir}/fdl1.img
  68. cfg-fdl2 -a ${CONFIG_FDL2_IMAGE_START} -s ${CONFIG_FDL2_IMAGE_SIZE}
  69. -p ${out_hex_dir}/fdl2.img
  70. )
  71. endmacro()
  72. if(CONFIG_APPIMG_LOAD_FLASH)
  73. set(target appimg_flash_delete)
  74. set(pac_file ${out_hex_dir}/${target}.pac)
  75. pac_init_fdl(init_fdl)
  76. add_custom_command(OUTPUT ${pac_file}
  77. COMMAND python3 ${pacgen_py} ${init_fdl}
  78. cfg-erase-flash -i ERASE_APPIMG
  79. -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  80. -s ${CONFIG_APPIMG_FLASH_SIZE}
  81. pac-gen ${pac_file}
  82. DEPENDS ${pacgen_py}
  83. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  84. )
  85. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  86. endif()
  87. if(CONFIG_APPIMG_LOAD_FILE)
  88. set(target appimg_file_delete)
  89. set(pac_file ${out_hex_dir}/${target}.pac)
  90. pac_init_fdl(init_fdl)
  91. add_custom_command(OUTPUT ${pac_file}
  92. COMMAND python3 ${pacgen_py} ${init_fdl}
  93. cfg-del-appimg -i DEL_APPIMG
  94. pac-gen ${pac_file}
  95. DEPENDS ${pacgen_py}
  96. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  97. )
  98. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  99. endif()
  100. if(CONFIG_APPIMG_LOAD_FLASH)
  101. set(target hello_flash)
  102. add_appimg(${target} ${flash_ldscript} hello_world.c)
  103. target_link_libraries(${target} PRIVATE ${libc_file_name} ${libm_file_name} ${libgcc_file_name})
  104. set(prepack_cpio ${out_hex_dir}/${target}_prepack.cpio)
  105. set(pac_file ${out_hex_dir}/${target}.pac)
  106. set(target_img_file ${out_hex_dir}/${target}.img)
  107. set(target_sign_img_file ${out_hex_dir}/${target}.sign.img)
  108. pac_init_fdl(init_fdl)
  109. add_custom_command(OUTPUT ${prepack_cpio}
  110. COMMAND python3 ${modemgen_py} prepackgen
  111. --source-top ${SOURCE_TOP_DIR}
  112. --binary-top ${BINARY_TOP_DIR}
  113. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  114. ${prepack_cpio}
  115. DEPENDS ${modemgen_py}
  116. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  117. )
  118. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  119. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  120. set(prepack_file ${prepack_cpio})
  121. endif()
  122. sign_image(${target_img_file} ${target_sign_img_file})
  123. add_custom_command(OUTPUT ${pac_file}
  124. COMMAND python3 ${pacgen_py} ${init_fdl}
  125. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  126. -s ${CONFIG_APPIMG_FLASH_SIZE}
  127. -p ${target_sign_img_file}
  128. ${cfg_pack_gpio}
  129. pac-gen ${pac_file}
  130. DEPENDS ${pacgen_py} ${target_sign_img_file} ${prepack_file}
  131. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  132. )
  133. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  134. endif()
  135. if(CONFIG_APPIMG_LOAD_FILE)
  136. set(target hello_file)
  137. add_appimg(${target} ${file_ldscript} hello_world.c)
  138. target_link_libraries(${target} PRIVATE ${libc_file_name} ${libm_file_name} ${libgcc_file_name})
  139. set(prepack_cpio ${out_hex_dir}/${target}_prepack.cpio)
  140. set(pac_file ${out_hex_dir}/${target}.pac)
  141. set(target_img_file ${out_hex_dir}/${target}.img)
  142. set(target_sign_img_file ${out_hex_dir}/${target}.sign.img)
  143. pac_init_fdl(init_fdl)
  144. add_custom_command(OUTPUT ${prepack_cpio}
  145. COMMAND python3 ${modemgen_py} prepackgen
  146. --source-top ${SOURCE_TOP_DIR}
  147. --binary-top ${BINARY_TOP_DIR}
  148. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  149. ${prepack_cpio}
  150. DEPENDS ${modemgen_py}
  151. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  152. )
  153. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  154. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  155. set(prepack_file ${prepack_cpio})
  156. endif()
  157. sign_image(${target_img_file} ${target_sign_img_file})
  158. add_custom_command(OUTPUT ${pac_file}
  159. COMMAND python3 ${pacgen_py} ${init_fdl}
  160. cfg-pack-file -i APPIMG -p ${target_sign_img_file}
  161. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  162. ${cfg_pack_gpio}
  163. pac-gen ${pac_file}
  164. DEPENDS ${pacgen_py} ${target_sign_img_file} ${prepack_file}
  165. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  166. )
  167. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  168. endif()