CMakeLists_8850.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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(cmd_mksimage dtools mksimage)
  25. set(cmd_ssign dtools ssign)
  26. set(cmd_ssignchain dtools ssignchain)
  27. set(cmd_ssigndebug dtools ssigndebug)
  28. set(cmd_ssigndevel dtools ssigndevel)
  29. set(cmd_sencrypt dtools sencrypt)
  30. set(pacgen_py ${tools_dir}/pacgen.py)
  31. set(modemgen_py ${tools_dir}/modemgen.py)
  32. set(pac_fdl_files ${out_hex_dir}/norfdl.sign.img)
  33. # NEVER USE THESE KEYS IN PRODUCTION!
  34. set(security_version 1)
  35. set(with_chaincert false)
  36. set(with_debugcert_develcert false)
  37. set(with_encrypt false)
  38. set(SOC_ID 6655aa9900881122)
  39. set(ENC_KEY 40414243444546470123456789ABcdef55aa55aa55aa55aaA8a9aaabacadaeaf)
  40. set(ENC_IV 3132333435363738393a3b3c3d3e3f40)
  41. set(debug_mask 7c) # open the ap_ca5 bits
  42. set(key_root_prv ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp256r1_prv.pem)
  43. set(key_root_pub ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp256r1_pub.pem)
  44. if (${with_chaincert})
  45. set(chain_cert_prv ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp224k1_prv.pem)
  46. set(chain_cert_pub ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp224k1_pub.pem)
  47. endif()
  48. set(key_debug_prv ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp256k1_prv.pem)
  49. set(key_debug_pub ${SOURCE_TOP_DIR}/components/hal/config/8850/ecc/secp256k1_pub.pem)
  50. set(key_devel_prv ${SOURCE_TOP_DIR}/components/hal/config/8850/rsa/4096_prv.pem)
  51. set(key_devel_pub ${SOURCE_TOP_DIR}/components/hal/config/8850/rsa/4096_pub.pem)
  52. set(ssign_param --force) # ssign parameters: --pkcsv15 --force
  53. if(${with_debugcert_develcert})
  54. set(ssign_param ${ssign_param} --debug_pub ${key_debug_pub})
  55. endif()
  56. include(cmake/core_config.cmake)
  57. include(cmake/toolchain-gcc.cmake)
  58. set(BUILD_SHARED_LIBS OFF)
  59. project(core C CXX ASM)
  60. include_directories(components/include)
  61. function(cpp_only target file)
  62. add_library(${target} OBJECT ${file})
  63. set_source_files_properties(${file} PROPERTIES LANGUAGE C)
  64. target_compile_options(${target} PRIVATE -E -P -x c)
  65. endfunction()
  66. function(sign_image src dst chain enc dev_debug)
  67. if (enc)
  68. set(CURR_CMD_ENC ${cmd_sencrypt} ${sencrypt_param} ${src} ${src}.enc)
  69. else()
  70. set(CURR_CMD_ENC ${CMAKE_COMMAND} -E copy ${src} ${src}.enc)
  71. endif()
  72. if (chain)
  73. set(CURR_CMD_CHAIN ${cmd_ssignchain} ${ssignchain_param} ${chain_cert_prv} ${chain_cert_pub} ${src}.keycert ${src}.chaincert)
  74. else()
  75. set(CURR_CMD_CHAIN ${CMAKE_COMMAND} -E copy ${src}.keycert ${src}.chaincert)
  76. endif()
  77. if (dev_debug)
  78. set(CURR_CMD_DEBUG ${cmd_ssigndebug} ${ssigndebug_param} ${key_debug_prv} ${key_debug_pub} ${key_devel_pub} ${debug_mask} ${src}.chaincert ${src}.debugcert)
  79. set(CURR_CMD_DEV ${cmd_ssigndevel} ${ssigndevel_param} ${key_devel_prv} ${key_devel_pub} ${debug_mask} ${SOC_ID} ${src}.debugcert ${dst})
  80. else()
  81. set(CURR_CMD_DEBUG ${CMAKE_COMMAND} -E copy ${src}.chaincert ${src}.debugcert)
  82. set(CURR_CMD_DEV ${CMAKE_COMMAND} -E copy ${src}.debugcert ${dst})
  83. endif()
  84. add_custom_command(OUTPUT ${dst}
  85. COMMAND ${CURR_CMD_ENC}
  86. COMMAND ${cmd_ssign} ${ssign_param} ${key_root_prv} ${key_root_pub} ${security_version} ${src}.enc ${src}.keycert
  87. COMMAND ${CURR_CMD_CHAIN}
  88. COMMAND ${CURR_CMD_DEBUG}
  89. COMMAND ${CURR_CMD_DEV}
  90. DEPENDS ${src}
  91. )
  92. endfunction()
  93. function(add_appimg target ldscript)
  94. set(gen_ldscript ${target}_ldscript)
  95. set(target_app_image_file ${out_hex_dir}/${target}.appimg)
  96. set(target_map_file ${out_hex_dir}/${target}.map)
  97. set(target_img_file ${out_hex_dir}/${target}.img)
  98. cpp_only(${gen_ldscript} ${ldscript})
  99. add_executable(${target} ${ARGN} ${core_stub_o})
  100. set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out_hex_dir})
  101. target_link_libraries(${target} PRIVATE -T $<TARGET_OBJECTS:${gen_ldscript}>)
  102. target_link_libraries(${target} PRIVATE -Wl,-Map=${target_map_file} -nostdlib -Wl,--gc-sections)
  103. add_custom_command(TARGET ${target} POST_BUILD
  104. COMMAND ${cmd_mkappimg} $<TARGET_FILE:${target}> ${target_app_image_file}
  105. BYPRODUCTS ${target_img_file} ${target_map_file} ${target_app_image_file}
  106. )
  107. add_custom_command(TARGET ${target} POST_BUILD
  108. COMMAND ${cmd_mksimage} --bin --load 0x0 --entry 0x0
  109. --name "${BUILD_REVISION}-${BUILD_AUTO_REVISION}"
  110. --imgver "1.1" --platform "8811" --check crc
  111. ${target_app_image_file} ${target_img_file}
  112. )
  113. endfunction()
  114. configure_file(${SOURCE_TOP_DIR}/components/lib/norfdl.sign.img ${out_hex_dir}/norfdl.sign.img COPYONLY)
  115. macro(pac_init_fdl cmd)
  116. set(${cmd}
  117. cfg-init --pname "8850_MODEM" --palias "APPIMG"
  118. --pversion "8850 MODULE" --version "BP_R1.0.0"
  119. --flashtype 0
  120. cfg-fdl -a ${CONFIG_NORFDL_IMAGE_START} -s ${CONFIG_NORFDL_IMAGE_SIZE}
  121. -p ${pac_fdl_files}
  122. )
  123. endmacro()
  124. if(CONFIG_APPIMG_LOAD_FLASH)
  125. set(target appimg_flash_delete)
  126. set(pac_file ${out_hex_dir}/${target}.pac)
  127. pac_init_fdl(init_fdl)
  128. add_custom_command(OUTPUT ${pac_file}
  129. COMMAND python3 ${pacgen_py} ${init_fdl}
  130. cfg-erase-flash -i ERASE_APPIMG
  131. -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  132. -s ${CONFIG_APPIMG_FLASH_SIZE}
  133. pac-gen ${pac_file}
  134. DEPENDS ${pacgen_py}
  135. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  136. )
  137. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  138. endif()
  139. if(CONFIG_APPIMG_LOAD_FILE)
  140. set(target appimg_file_delete)
  141. set(pac_file ${out_hex_dir}/${target}.pac)
  142. pac_init_fdl(init_fdl)
  143. add_custom_command(OUTPUT ${pac_file}
  144. COMMAND python3 ${pacgen_py} ${init_fdl}
  145. cfg-del-appimg -i DEL_APPIMG
  146. pac-gen ${pac_file}
  147. DEPENDS ${pacgen_py}
  148. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  149. )
  150. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  151. endif()
  152. if(CONFIG_APPIMG_LOAD_FLASH)
  153. set(target hello_flash)
  154. add_appimg(${target} ${flash_ldscript} hello_world.c)
  155. target_link_libraries(${target} PRIVATE ${libc_file_name} ${libm_file_name} ${libgcc_file_name})
  156. set(prepack_cpio ${out_hex_dir}/${target}_prepack.cpio)
  157. set(pac_file ${out_hex_dir}/${target}.pac)
  158. set(target_img_file ${out_hex_dir}/${target}.img)
  159. set(target_sign_img_file ${out_hex_dir}/${target}.sign.img)
  160. pac_init_fdl(init_fdl)
  161. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  162. add_custom_command(OUTPUT ${prepack_cpio}
  163. COMMAND python3 ${modemgen_py} prepackgen
  164. --source-top ${SOURCE_TOP_DIR}
  165. --binary-top ${BINARY_TOP_DIR}
  166. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  167. ${prepack_cpio}
  168. DEPENDS ${modemgen_py}
  169. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  170. )
  171. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  172. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  173. set(prepack_file ${prepack_cpio})
  174. endif()
  175. add_custom_command(OUTPUT ${pac_file}
  176. COMMAND python3 ${pacgen_py} ${init_fdl}
  177. cfg-image -i APPIMG -a ${CONFIG_APPIMG_FLASH_ADDRESS}
  178. -s ${CONFIG_APPIMG_FLASH_SIZE}
  179. -p ${target_sign_img_file}
  180. ${cfg_pack_gpio}
  181. pac-gen ${pac_file}
  182. DEPENDS ${pacgen_py} ${target_sign_img_file} ${prepack_file}
  183. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  184. )
  185. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  186. endif()
  187. if(CONFIG_APPIMG_LOAD_FILE)
  188. set(target hello_file)
  189. add_appimg(${target} ${file_ldscript} hello_world.c)
  190. target_link_libraries(${target} PRIVATE ${libc_file_name} ${libm_file_name} ${libgcc_file_name})
  191. set(prepack_cpio ${out_hex_dir}/${target}_prepack.cpio)
  192. set(pac_file ${out_hex_dir}/${target}.pac)
  193. set(target_img_file ${out_hex_dir}/${target}.img)
  194. set(target_sign_img_file ${out_hex_dir}/${target}.sign.img)
  195. pac_init_fdl(init_fdl)
  196. sign_image(${target_img_file} ${target_sign_img_file} ${with_chaincert} ${with_encrypt} ${with_debugcert_develcert})
  197. add_custom_command(OUTPUT ${prepack_cpio}
  198. COMMAND python3 ${modemgen_py} prepackgen
  199. --source-top ${SOURCE_TOP_DIR}
  200. --binary-top ${BINARY_TOP_DIR}
  201. --prepackfile ${CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH}
  202. ${prepack_cpio}
  203. DEPENDS ${modemgen_py}
  204. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  205. )
  206. if(CONFIG_PACKAGE_FILE_APPIMG_JSON_PATH)
  207. set(cfg_pack_gpio cfg-pack-cpio -i PREPACK -p ${prepack_cpio})
  208. set(prepack_file ${prepack_cpio})
  209. endif()
  210. add_custom_command(OUTPUT ${pac_file}
  211. COMMAND python3 ${pacgen_py} ${init_fdl}
  212. cfg-pack-file -i APPIMG -p ${target_sign_img_file}
  213. -n ${CONFIG_APPIMG_LOAD_FILE_NAME}
  214. ${cfg_pack_gpio}
  215. pac-gen ${pac_file}
  216. DEPENDS ${pacgen_py} ${target_sign_img_file} ${prepack_file}
  217. WORKING_DIRECTORY ${SOURCE_TOP_DIR}
  218. )
  219. add_custom_target(${target}_pacgen ALL DEPENDS ${pac_file})
  220. endif()