title: How to upload binary data (html + favicon) to ESP32 using ESP-IDF?
body: <p>I am writing a file-serving http server for ESP32 using ESP-IDF and PlatformIO, but I just can't make data upload to SPIFFS work. I am trying to send html and favicon to flash, so it can be served on http.</p>
  <p>Code of the server is taken from an example <a href="https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_server/file_serving" rel="nofollow noreferrer">https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_server/file_serving</a>. Noticeable difference is that example project uses only ESP-IDF tools (without platformio) and that in an example data files are in the same directory as source files, where in my projects I have separated directories for /src and /data.
  SPIFFS is configured using custom partition table.</p>
  <p>I was following instructions from both PlatformIO documents (<a href="https://docs.platformio.org/en/latest/platforms/espressif32.html?utm_source=platformio&amp;utm_medium=piohome" rel="nofollow noreferrer">https://docs.platformio.org/en/latest/platforms/espressif32.html?utm_source=platformio&amp;utm_medium=piohome</a>) as well as from ESP (<a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#embedding-binary-data" rel="nofollow noreferrer">https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#embedding-binary-data</a>).</p>
  <p>I have custom partisions.csv file (identical to the example) + changed menuconfig to use it.</p>
  <p>In platformio.ini I added:</p>
  <pre><code>board_build.partitions = partitions.csv
  board_build.embed_txtfiles =
      data/favicon.ico
      data/upload_script.html
  </code></pre>
  <p>I also changed project CMakeLists file to embed data like this:</p>
  <pre><code>cmake_minimum_required(VERSION 3.16.0)
  include($ENV{IDF_PATH}/tools/cmake/project.cmake)
  project(HTTP-server)
  target_add_binary_data(HTTP-server.elf &quot;data/favicon.ico&quot; TEXT)
  target_add_binary_data(HTTP-server.elf &quot;data/upload_script.html&quot; TEXT)
  </code></pre>
  <p>/src/CMakeLists stayed unchanged:</p>
  <pre><code>FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
  idf_component_register(SRCS ${app_sources})
  </code></pre>
  <p>But even with all this configuration when I try to use this data in file_server.c like this:</p>
  <pre><code>extern const unsigned char favicon_ico_start[] asm(&quot;_binary_favicon_ico_start&quot;);
  extern const unsigned char favicon_ico_end[] asm(&quot;_binary_favicon_ico_end&quot;);
  extern const unsigned char upload_script_start[] asm(&quot;_binary_upload_script_html_start&quot;);
  extern const unsigned char upload_script_end[] asm(&quot;_binary_upload_script_html_end&quot;); 
  </code></pre>
  <p>I get compilation errors</p>
  <pre><code>Linking .pio/build/nodemcu-32s/firmware.elf
  /home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.http_resp_dir_html+0x14): undefined reference to `_binary_upload_script_html_end'
  /home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.http_resp_dir_html+0x18): undefined reference to `_binary_upload_script_html_start'
  /home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.favicon_get_handler+0x0): undefined reference to `_binary_favicon_ico_end'
  /home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.favicon_get_handler+0x4): undefined reference to `_binary_favicon_ico_start'
  collect2: error: ld returned 1 exit status
  *** [.pio/build/nodemcu-32s/firmware.elf] Error 1
  ================================================================================= [FAILED] Took 65.20 seconds =================================================================================
  </code></pre>
  <p>I tried changing extern definitions to:</p>
  <pre><code>extern const unsigned char favicon_ico_start[] asm(&quot;_binary_data_favicon_ico_start&quot;);
  </code></pre>
  <p>But it didn't change anything.</p>
  <p>Additionally when running &quot;Build Filesystem Image&quot; task I get this error:</p>
  <pre><code>*** [.pio/build/nodemcu-32s/spiffs.bin] Implicit dependency `data/favicon' not found, needed by target `.pio/build/nodemcu-32s/spiffs.bin'.
  ================================================================================= [FAILED] Took 5.70 seconds =================================================================================
  The terminal process &quot;platformio 'run', '--target', 'buildfs', '--environment', 'nodemcu-32s'&quot; terminated with exit code: 1.
  </code></pre>
  <p>Any help would be very much appreciated, as I feel that I did everything that the documentation stated.</p>