You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # Derived from the Pico SDK, which carries the following
  2. # LICENSE.txt:
  3. # Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
  4. #
  5. # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  6. # following conditions are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  9. # disclaimer.
  10. #
  11. # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  12. # disclaimer in the documentation and/or other materials provided with the distribution.
  13. #
  14. # 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
  15. # derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  18. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. cmake_minimum_required(VERSION 3.13)
  25. include(pico_sdk_import.cmake)
  26. project(picowota C CXX ASM)
  27. set(CMAKE_C_STANDARD 11)
  28. set(CMAKE_CXX_STANDARD 17)
  29. pico_sdk_init()
  30. add_executable(picowota
  31. main.c
  32. tcp_comm.c
  33. dhcpserver/dhcpserver.c
  34. )
  35. function(target_cl_options option)
  36. target_compile_options(picowota PRIVATE ${option})
  37. target_link_options(picowota PRIVATE ${option})
  38. endfunction()
  39. target_cl_options("-Wall")
  40. target_cl_options("-Os")
  41. target_cl_options("-ffunction-sections")
  42. target_cl_options("-fdata-sections")
  43. target_link_options(picowota PRIVATE "LINKER:--gc-sections")
  44. pico_add_extra_outputs(picowota)
  45. target_include_directories(picowota PRIVATE
  46. ${CMAKE_CURRENT_LIST_DIR} # Needed so that lwip can find lwipopts.h
  47. ${CMAKE_CURRENT_LIST_DIR}/dhcpserver)
  48. pico_enable_stdio_usb(picowota 1)
  49. add_subdirectory(picowota_reboot)
  50. target_link_libraries(picowota
  51. cmsis_core
  52. hardware_dma
  53. hardware_flash
  54. hardware_resets
  55. hardware_structs
  56. pico_cyw43_arch_lwip_poll
  57. pico_stdlib
  58. pico_sync
  59. pico_util
  60. picowota_reboot
  61. )
  62. if (DEFINED ENV{PICOWOTA_WIFI_SSID} AND (NOT PICOWOTA_WIFI_SSID))
  63. set(PICOWOTA_WIFI_SSID $ENV{PICOWOTA_WIFI_SSID})
  64. message("Using PICOWOTA_WIFI_SSID from environment ('${PICOWOTA_WIFI_SSID}')")
  65. endif ()
  66. if (DEFINED ENV{PICOWOTA_WIFI_PASS} AND (NOT PICOWOTA_WIFI_PASS))
  67. set(PICOWOTA_WIFI_PASS $ENV{PICOWOTA_WIFI_PASS})
  68. message("Using PICOWOTA_WIFI_PASS from environment (hidden)")
  69. endif ()
  70. if ((NOT PICOWOTA_WIFI_SSID) OR (NOT PICOWOTA_WIFI_PASS))
  71. message(FATAL_ERROR
  72. "WiFi SSID/Pass not set, please set PICOWOTA_WIFI_SSID/PICOWOTA_WIFI_PASS."
  73. )
  74. endif ()
  75. # TODO: This causes a full rebuild if they change, configure_file might
  76. # be better.
  77. target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_SSID=${PICOWOTA_WIFI_SSID})
  78. target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_PASS=${PICOWOTA_WIFI_PASS})
  79. # Use the WiFi AP mode upon request
  80. if (PICOWOTA_WIFI_AP)
  81. target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_AP=1)
  82. message("Building in WiFi AP mode.")
  83. endif()
  84. # Provide a helper to build a standalone target
  85. function(picowota_build_standalone NAME)
  86. get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR)
  87. pico_set_linker_script(${NAME} ${PICOWOTA_SRC_DIR}/standalone.ld)
  88. pico_add_bin_output(${NAME})
  89. endfunction()
  90. # Provide a helper to build a combined target
  91. # The build process is roughly:
  92. # 1. Build the bootloader, using a special linker script which leaves
  93. # two sections to be filled in with the header (.app_hdr) and
  94. # app binary (.app_bin)
  95. # 2. Build the app binary, using a special linker script to set the load
  96. # address properly and skip boot2.
  97. # 3. Calculate the checksum of the app binary
  98. # 4. Update the header and binary sections in the ELF from 1.
  99. function(picowota_build_combined NAME)
  100. set(APP_BIN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.bin)
  101. set(APP_HDR_BIN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_hdr.bin)
  102. set(COMBINED picowota_${NAME})
  103. get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR)
  104. get_target_property(PICOWOTA_BIN_DIR picowota BINARY_DIR)
  105. # The app must be built with the correct linker script (and a .bin)
  106. picowota_build_standalone(${NAME})
  107. # Build the bootloader with the sections to fill in
  108. pico_set_linker_script(picowota ${PICOWOTA_SRC_DIR}/bootloader_shell.ld)
  109. # TODO: The hard-coded address here is a bit nasty
  110. add_custom_target(${NAME}_hdr DEPENDS ${APP_BIN})
  111. add_custom_command(TARGET ${NAME}_hdr DEPENDS ${APP_BIN}
  112. COMMAND ${PICOWOTA_SRC_DIR}/gen_imghdr.py -a 0x1005B000 ${APP_BIN} ${APP_HDR_BIN}
  113. )
  114. add_custom_target(${COMBINED} ALL)
  115. add_dependencies(${COMBINED} picowota ${NAME}_hdr ${NAME})
  116. add_custom_command(TARGET ${COMBINED} DEPENDS ${APP_HDR_BIN} ${APP_BIN}
  117. COMMAND ${CMAKE_OBJCOPY}
  118. --update-section .app_hdr=${APP_HDR_BIN}
  119. --update-section .app_bin=${APP_BIN} ${PICOWOTA_BIN_DIR}/picowota.elf ${COMBINED}.elf
  120. )
  121. add_custom_command(TARGET ${COMBINED} POST_BUILD
  122. COMMAND ${CMAKE_OBJCOPY} -Obinary ${COMBINED}.elf ${COMBINED}.bin
  123. )
  124. if (NOT ELF2UF2_FOUND)
  125. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools)
  126. find_package(ELF2UF2)
  127. endif()
  128. if (ELF2UF2_FOUND)
  129. add_custom_command(TARGET ${COMBINED} POST_BUILD
  130. COMMAND ELF2UF2 ${COMBINED}.elf ${COMBINED}.uf2
  131. )
  132. endif()
  133. endfunction()