This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit b327a94dc7e797f797207fa9aff918c404a7e78a
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Fri May 19 13:59:53 2023 +0200

    hw/scripts: Add downloader selection
    
    So far (almost) every BSP had its own version of download script.
    Changing download software specially for ST devices was cumbersome.
    Lately it was possible to override download script in target but
    it still is more complicated then just changing syscfg value.
    
    This adds common hw/scripts/download.sh file that can use all available
    options to download image.
    
    sh/scripts is converted to package to allow syscfg definitions that can
    be overriden in BSPs or targets.
    
    jlink, openocd, stutil, stm32_programmer_cli and pyocd can be selected.
    
    Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
---
 hw/scripts/download.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/scripts/pkg.yml     | 28 ++++++++++++++++
 hw/scripts/syscfg.yml  | 73 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+)

diff --git a/hw/scripts/download.sh b/hw/scripts/download.sh
new file mode 100644
index 000000000..78a63195f
--- /dev/null
+++ b/hw/scripts/download.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Called with following variables set:
+#  - CORE_PATH is absolute path to @apache-mynewt-core
+#  - BSP_PATH is absolute path to hw/bsp/bsp_name
+#  - BIN_BASENAME is the path to prefix to target binary,
+#    .elf appended to name is the ELF file
+#  - IMAGE_SLOT is the image slot to download to (for non-mfg-image, non-boot)
+#  - FEATURES holds the target features string
+#  - EXTRA_JTAG_CMD holds extra parameters to pass to jtag software
+#  - MFG_IMAGE is "1" if this is a manufacturing image
+#  - FLASH_OFFSET contains the flash offset to download to
+#  - BOOT_LOADER is set if downloading a bootloader
+
+if [ "$MFG_IMAGE" ]; then
+  if [ -z "$MYNEWT_VAL_MYNEWT_DOWNLOADER_MFG_IMAGE_FLASH_OFFSET"] ; then
+    >&2 echo "Syscfg value MYNEWT_DOWNLOADER_MFG_IMAGE_FLASH_OFFSET not set"
+    exit -1
+  fi
+  FLASH_OFFSET=${MYNEWT_VAL_MYNEWT_DOWNLOADER_MFG_IMAGE_FLASH_OFFSET}
+fi
+
+case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
+  "jlink")
+    . $CORE_PATH/hw/scripts/jlink.sh
+    if [ -z "${MYNEWT_VAL_JLINK_TARGET}"] ; then
+      >&2 echo -e "\n\nSyscfg value MYNEWT_DOWNLOADER set to 'jlink' but 
JLINK_TARGET not set in syscfg."
+      exit -1
+    fi
+    JLINK_DEV=${MYNEWT_VAL_JLINK_TARGET}
+    common_file_to_load
+    jlink_load
+    ;;
+  "openocd")
+    . $CORE_PATH/hw/scripts/openocd.sh
+    if [ -n "${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_INTERFACE}" ] ; then
+      CFG="-f ${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_INTERFACE}"
+    fi
+    if [ -n "${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_BOARD}" ] ; then
+      CFG="${CFG} -f ${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_BOARD}"
+    fi
+    if [ -n "${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_CFG}" ] ; then
+      CFG="${CFG} -s $BSP_PATH -f ${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_CFG}"
+    fi
+    if [ -z "${CFG}"] ; then
+      >&2 echo -e "\n\nSyscfg value MYNEWT_DOWNLOADER set to 'openocd' but 
none of the following syscfg values is not set:"
+      >&2 echo -e 
"\tMYNEWT_DOWNLOADER_OPENOCD_INTERFACE\n\tMYNEWT_DOWNLOADER_OPENOCD_BOARD\n\tMYNEWT_DOWNLOADER_OPENOCD_CFG"
+      exit -1
+    fi
+    common_file_to_load
+    openocd_load
+    openocd_reset_run
+    ;;
+  "pyocd")
+    . $CORE_PATH/hw/scripts/pyocd.sh
+    if [ -z "${MYNEWT_VAL_PYOCD_TARGET}" ] ; then
+      >&2 echo -e "\n\nSyscfg value MYNEWT_DOWNLOADER set to 'pyocd' but 
PYOCD_TARGET not set in syscfg."
+      >&2 echo -e "pyocd supported targets can be found with 'pyocd list 
--targets'\n"
+      exit -1
+    fi
+    TARGET=${MYNEWT_VAL_PYOCD_TARGET}
+    common_file_to_load
+    pyocd_load
+    ;;
+  "stflash")
+    . $CORE_PATH/hw/scripts/stlink.sh
+    common_file_to_load
+    stlink_load
+    ;;
+esac
diff --git a/hw/scripts/pkg.yml b/hw/scripts/pkg.yml
new file mode 100644
index 000000000..063d15be2
--- /dev/null
+++ b/hw/scripts/pkg.yml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/scripts
+pkg.description: >
+    Package with shell scripts.
+pkg.author: "Apache Mynewt <d...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+    - scripts
+    - debug
+    - download
diff --git a/hw/scripts/syscfg.yml b/hw/scripts/syscfg.yml
new file mode 100644
index 000000000..98a76ce92
--- /dev/null
+++ b/hw/scripts/syscfg.yml
@@ -0,0 +1,73 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    MYNEWT_DOWNLOADER:
+        description: >
+            Downloader selection. This settings is usually specified in BSP,
+            but can b overriden in target with different debug probe should be
+            used.
+        choices:
+            # JLink probe with JLinkExe/JLink.exe
+            - jlink
+            # open source st-flash for STM32Fxx devices
+            - stflash
+            - openocd
+            - pyocd
+        value:
+    MYNEWT_DEBUGGER:
+        description: >
+            GDB server provider.
+        choices:
+            # JLink probe with JLinkExe/JLink.exe
+            - jlink
+            # open source st-util for STM32Fxx devices
+            - stutil
+            # ST propitiatory flasher ST-LINK_gdbserver for STM32Fxx devices
+            - st_link_gdbserver
+            - openocd
+            - pyocd
+        value:
+
+    MYNEWT_DOWNLOADER_MFG_IMAGE_FLASH_OFFSET:
+        description: >
+            Load address for manufacturing image. Provided by BSP or MCU.
+        value:
+    MYNEWT_DOWNLOADER_OPENOCD_CFG:
+        description: >
+            Script passed to openocd with -f option.
+        value:
+    MYNEWT_DOWNLOADER_OPENOCD_BOARD:
+        description: >
+            Target baord for openocd (i.e. boards/st_nucleo_f4.cfg)
+        value:
+    MYNEWT_DOWNLOADER_OPENOCD_INTERFACE:
+        description: >
+            Target interface for openocd (i.e. interface/cmsis-dap.cfg)
+        value:
+    JLINK_TARGET:
+        description: >
+            Target name for JLink (i.e. Cortex_M33, NRF5340_XXAA_APP).
+        value:
+    PYOCD_TARGET:
+        description: >
+            Target name for pyocd (command:
+                pyocd list --targets
+            shows supported targets.
+        value:

Reply via email to