]> granicus.if.org Git - esp-idf/commitdiff
cmake: Generate PHY init data partition as part of the build
authorAngus Gratton <angus@espressif.com>
Thu, 1 Feb 2018 09:45:41 +0000 (17:45 +0800)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
components/esp32/CMakeLists.txt
components/esp32/phy_init_data.h
components/esptool_py/CMakeLists.txt
components/esptool_py/flash_project_args.in [new file with mode: 0644]
components/partition_table/CMakeLists.txt
toolchain.cmake
tools/cmake/utilities.cmake

index cf0dff1f0b4f588d544255c44ae8385a36296a5b..a67ab89d1d308a619feca89a59ea083c8f0738ba 100644 (file)
@@ -58,4 +58,18 @@ else()
   add_custom_target(esp32_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld)
   add_dependencies(esp32 esp32_linker_script)
 
-endif()
+  if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
+    set(PHY_INIT_DATA_BIN phy_init_data.bin)
+
+    # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy the object file to a raw binary
+    add_custom_command(
+      OUTPUT ${PHY_INIT_DATA_BIN}
+      DEPENDS ${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
+      COMMAND ${CMAKE_C_COMPILER} -x c -c -o phy_init_data.obj -I ${CMAKE_CURRENT_LIST_DIR} -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
+      COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${PHY_INIT_DATA_BIN}
+      )
+    add_custom_target(phy_init_data ALL DEPENDS ${PHY_INIT_DATA_BIN})
+
+  endif(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
+
+endif(BOOTLOADER_BUILD)
index d09bbdd9c62d2edd92c310eaae56107ef63e3e10..9213020ca1be38af0643a7022f2e6208743c728e 100644 (file)
@@ -12,7 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#pragma once
+#ifndef PHY_INIT_DATA_H
+#define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */
 #include "esp_phy_init.h"
 #include "sdkconfig.h"
 
@@ -138,3 +139,5 @@ static const esp_phy_init_data_t phy_init_data= { {
 
 static const char phy_init_magic_post[] = PHY_INIT_MAGIC;
 
+#endif /* PHY_INIT_DATA_H */
+
index bdd55ceeaced15f311312d37b3e72e4abf221f3f..f5f5514ee298e4197b154a197b973bb594f86875 100644 (file)
@@ -1 +1,10 @@
 register_config_only_component()
+
+configure_file(
+  "${CMAKE_CURRENT_LIST_DIR}/flash_project_args.in"
+  "${CMAKE_BINARY_DIR}/flash_project_args"
+  )
+if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
+  file_append_line(${CMAKE_BINARY_DIR}/flash_project_args
+    "${CONFIG_PHY_DATA_OFFSET} esp32/phy_init_data.bin")
+endif()
diff --git a/components/esptool_py/flash_project_args.in b/components/esptool_py/flash_project_args.in
new file mode 100644 (file)
index 0000000..1733f57
--- /dev/null
@@ -0,0 +1,3 @@
+0x1000 bootloader/bootloader.bin
+0x8000 partition_table/partition-table.bin
+${CONFIG_APP_OFFSET} ${PROJECT_NAME}.elf
index f394088066efaa06f1f4ba86734804c4ab86ae01..c0b2a38336d2e2f7424c92e6ea82b6a55f3e1870 100644 (file)
@@ -11,12 +11,12 @@ else()
 endif()
 
 if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
-  set(unsigned_partition_bin "partition-unsigned.bin")
-  set(final_partition_bin "partition.bin")
+  set(unsigned_partition_bin "partition-table-unsigned.bin")
+  set(final_partition_bin "partition-table.bin")
   set(final_partition_target "sign_partition_table")
 else()
-  set(unsigned_partition_bin "partition.bin")
-  set(final_partition_bin "partition.bin")
+  set(unsigned_partition_bin "partition-table.bin")
+  set(final_partition_bin "partition-table.bin")
   set(final_partition_target "build_partition_table")
 endif()
 
index cecba78af417271a04a0b7ea031c1032f195be7c..ccf6eab864d52724eb01de89d77d8ab6a3e875ef 100644 (file)
@@ -3,5 +3,6 @@ set(CMAKE_SYSTEM_NAME Generic)
 set(CMAKE_C_COMPILER xtensa-esp32-elf-gcc)\r
 set(CMAKE_CXX_COMPILER xtensa-esp32-elf-g++)\r
 set(CMAKE_ASM_COMPILER xtensa-esp32-elf-gcc)\r
+set(CMAKE_OBJCOPY xtensa-esp32-elf-objcopy)\r
 \r
 set(CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "Linker Base Flags")\r
index 5c3bac996ec26621f3a787fa4ba46b3fe42d8ff7..759b559a37a62b1dbf5adc036bdb2c3b86d6886a 100644 (file)
@@ -127,3 +127,22 @@ macro(include_if_exists path)
     include("${path}")
   endif()
 endmacro(include_if_exists)
+
+# Append a single line to the file specified
+# The line ending is determined by the host OS
+function(file_append_line file line)
+  if(ENV{MSYSTEM} OR CMAKE_HOST_WIN32)
+    set(line_ending "\r\n")
+  else() # unix
+    set(line_ending "\n")
+  endif()
+  file(READ ${file} existing)
+  string(FIND ${existing} ${line_ending} last_newline REVERSE)
+  string(LENGTH ${existing} length)
+  math(EXPR length "${length}-1")
+  if(NOT length EQUAL last_newline) # file doesn't end with a newline
+    file(APPEND "${file}" "${line_ending}")
+  endif()
+  file(APPEND "${file}" "${line}${line_ending}")
+endfunction()
+