board: mec15xxevb_assy6853: generate flashable image
This adds an extra step at the end of build to generate a flashable
image using Microchip tool available at:
https://github.com/MicrochipTech/CPGZephyrDocs
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
diff --git a/boards/arm/mec15xxevb_assy6853/CMakeLists.txt b/boards/arm/mec15xxevb_assy6853/CMakeLists.txt
index ed4e3c4..a7c44f3 100644
--- a/boards/arm/mec15xxevb_assy6853/CMakeLists.txt
+++ b/boards/arm/mec15xxevb_assy6853/CMakeLists.txt
@@ -6,3 +6,41 @@
zephyr_library()
zephyr_library_sources(pinmux.c)
+
+if(DEFINED ENV{EVERGLADES_SPI_GEN})
+ # Grab it from environment variable if defined
+ set(EVERGLADES_SPI_GEN $ENV{EVERGLADES_SPI_GEN})
+else()
+ # Else find the tool in PATH
+
+ if(CMAKE_HOST_APPLE)
+ # CMAKE_HOST_UNIX is also true for Apple,
+ # but there is no tool for Apple. So
+ # we need to skip it.
+ message(NOTICE "There is no SPI image generation tool for MacOS.")
+ elseif(CMAKE_HOST_UNIX)
+ set(EVERGLADES_SPI_GEN_FILENAME everglades_spi_gen_lin64)
+ elseif(CMAKE_HOST_WIN32)
+ set(EVERGLADES_SPI_GEN_FILENAME everglades_spi_gen.exe)
+ endif()
+
+ find_file(EVERGLADES_SPI_GEN_FINDFILE ${EVERGLADES_SPI_GEN_FILENAME})
+ if(EVERGLADES_SPI_GEN_FINDFILE STREQUAL EVERGLADES_SPI_GEN_FINDFILE-NOTFOUND)
+ message(WARNING "Microchip SPI Image Generation tool (${EVERGLADES_SPI_GEN_FILENAME}) is not available. SPI Image will not be generated.")
+ else()
+ set(EVERGLADES_SPI_GEN ${EVERGLADES_SPI_GEN_FINDFILE})
+ endif()
+
+ unset(EVERGLADES_SPI_GEN_FINDFILE)
+ unset(EVERGLADES_SPI_GEN_FILENAME)
+endif()
+
+if(DEFINED EVERGLADES_SPI_GEN)
+ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
+ COMMAND ${EVERGLADES_SPI_GEN}
+ -i ${BOARD_DIR}/support/spi_cfg.txt
+ -o ${PROJECT_BINARY_DIR}/spi_image.bin
+ )
+
+ unset(EVERGLADES_SPI_GEN)
+endif()
diff --git a/boards/arm/mec15xxevb_assy6853/doc/index.rst b/boards/arm/mec15xxevb_assy6853/doc/index.rst
index 9cfbb5d..f30db2a 100644
--- a/boards/arm/mec15xxevb_assy6853/doc/index.rst
+++ b/boards/arm/mec15xxevb_assy6853/doc/index.rst
@@ -221,14 +221,30 @@
Programming and Debugging
*************************
+Setup
+=====
+
+#. Clone the `SPI Image Gen`_ repository or download the files within
+ that directory.
+
+#. Make the image generation available for Zephyr, by making the tool
+ searchable by path, or by setting an environment variable
+ ``EVERGLADES_SPI_GEN``, for example:
+
+ .. code-block:: console
+
+ export EVERGLADES_SPI_GEN=<path to tool>/everglades_spi_gen_lin64
+
+ Note that the tools for Linux and Windows have different file names.
+
Building
-==========
+========
#. Build :ref:`hello_world` application as you would normally do.
-#. Once you have ``zephyr.bin``, proceed to use the `SPI Image Gen`_ microchip tool
- in order to create the the final binary. You need the output from this tool
- to flash in the SHD SPI memory.
+#. The file :file:`spi_image.bin` will be created if the build system
+ can find the image generation tool. This binary image can be used
+ to flash the SPI chip.
Flashing
========
diff --git a/boards/arm/mec15xxevb_assy6853/support/spi_cfg.txt b/boards/arm/mec15xxevb_assy6853/support/spi_cfg.txt
new file mode 100644
index 0000000..a33907b
--- /dev/null
+++ b/boards/arm/mec15xxevb_assy6853/support/spi_cfg.txt
@@ -0,0 +1,39 @@
+[SPI]
+SPISizeMegabits = 128
+Flashmap = true
+FlshmapAddr = 0
+
+[IMAGE "0"]
+ImageLocation = 0x10000
+SpiFreqMHz = 24
+SpiReadCommand = Dual
+SpiDriveStrength = 4
+SpiSlewFast = false
+SpiSignalControl = 0x00
+FwBinFile = zephyr.bin
+FwOffset = 0
+FwLoadAddress = 0xE0000
+FwEntryAddress = 0
+UseECDSA = false
+ECDSAPrivKeyFile = ecprivkey001.pem
+ECDSAPrivKeyPassword = ECPRIVKEY001
+FwEncrypt = false
+AesGenECPubKeyFile = ecpubkey002_crt.pem
+
+[IMAGE "1"]
+ImageLocation = 0x20000
+SpiFreqMHz = 12
+SpiReadCommand = Single
+SpiDriveStrength = 4
+SpiSlewFast = false
+SpiSignalControl = 0x00
+FwBinFile = zephyr.bin
+FwOffset = 0
+FwLoadAddress = 0xE0000
+FwEntryAddress = 0
+UseECDSA = false
+ECDSAPrivKeyFile = ecprivkey001.pem
+ECDSAPrivKeyPassword = ECPRIVKEY001
+ECDSAPubKeyFile = ecpubkey001_crt.pem
+FwEncrypt = false
+AesGenECPubKeyFile = ecpubkey002_crt.pem