From b6ba1daed7a69e7efba54997e4b2d3dd890b57ca Mon Sep 17 00:00:00 2001 From: Borja Outerelo Date: Wed, 2 Oct 2019 14:34:51 +0200 Subject: [PATCH 1/3] Add Olimex OpenOCD debuggers check and support. --- scripts/flash.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/flash.sh b/scripts/flash.sh index 86d05f4e3f..ac92326fe4 100755 --- a/scripts/flash.sh +++ b/scripts/flash.sh @@ -1,10 +1,17 @@ #!/bin/bash -if [ $1 = "olimex-stm32-e407" ]; then - openocd -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" -elif [ $1 = "stm32l1" ]; then +if [ $1 = "olimex-stm32-e407" ];then + if lsusb -d 15BA:002a; then + openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" + elif lsusb -d 15BA:0003;then + openocd -f interface/ftdi/olimex-arm-usb-ocd.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" + elif lsusb -d 15BA:002b;then + openocd -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" + else + echo "Error. Unsuported olimex-stm32-e407 flashing device. Try openocd" + fi +elif [ $1 = "stm32l1" ];then openocd -f interface/stlink-v2.cfg -f target/stm32l1.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" else echo "Error. Try: ./flash.sh olimex-stm32-e407 or ./flash.sh stm32l1" fi - From d57177a68749177b857dbbb2fa9f12c5f2a2009c Mon Sep 17 00:00:00 2001 From: Borja Outerelo Date: Mon, 11 Nov 2019 14:32:02 +0100 Subject: [PATCH 2/3] Create scripting tools to install dependencies. --- scripts/flash.sh | 5 +++++ scripts/tools.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 scripts/tools.sh diff --git a/scripts/flash.sh b/scripts/flash.sh index ac92326fe4..b4a9e86e7a 100755 --- a/scripts/flash.sh +++ b/scripts/flash.sh @@ -1,5 +1,10 @@ #!/bin/bash +currdir="${0%/*}" +. $currdir/tools.sh + +install_dep usbutils git + if [ $1 = "olimex-stm32-e407" ];then if lsusb -d 15BA:002a; then openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000" diff --git a/scripts/tools.sh b/scripts/tools.sh new file mode 100644 index 0000000000..c7f2426f2f --- /dev/null +++ b/scripts/tools.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function has_command() { + command -v "$1" >/dev/null 2>&1 +} + +function set_host_installer() { + if [ -f /etc/arch-release ]; then + if has_command pacman; then + INSTALL_COMMAND="pacman" + INSTALL_OPTIONS="-S" + INSTALL_QUERY="pacman -Qi" + fi + elif [ -f /etc/debian_version ]; then + if has_command apt-get; then + INSTALL_COMMAND="apt-get" + INSTALL_OPTIONS="install -y" + INSTALL_QUERY="dpkg -s" + fi + fi +} + +function filter_installed() { + for package in "$@" + do + if $INSTALL_QUERY $package; then + echo $package "Already installed" + else + MISSING_PKGS+=" "$package + fi + done +} + + +function install_dep() { + set_host_installer + filter_installed "$@" + if ! test -z MISSING_PKGS; then + $INSTALL_COMMAND $INSTALL_OPTIONS $MISSING_PKGS + fi + +} \ No newline at end of file From b0cc655932e17b2ee5e9795e5c36db56f10ccba3 Mon Sep 17 00:00:00 2001 From: Borja Outerelo Date: Mon, 11 Nov 2019 14:37:39 +0100 Subject: [PATCH 3/3] Remove not required dependency. Add comments. --- scripts/flash.sh | 4 +++- scripts/tools.sh | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/flash.sh b/scripts/flash.sh index b4a9e86e7a..70ff9c5487 100755 --- a/scripts/flash.sh +++ b/scripts/flash.sh @@ -1,9 +1,11 @@ #!/bin/bash +# Source tools currdir="${0%/*}" . $currdir/tools.sh -install_dep usbutils git +# lsusb dependency installation +install_dep usbutils if [ $1 = "olimex-stm32-e407" ];then if lsusb -d 15BA:002a; then diff --git a/scripts/tools.sh b/scripts/tools.sh index c7f2426f2f..8595d6f92c 100644 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -1,9 +1,15 @@ #!/bin/bash + +# Returns if a command is available in the current machine function has_command() { command -v "$1" >/dev/null 2>&1 } +# Sets multiple variables with system specifics. +# INSTALL_COMMAND: is the package manager of the linux distribution +# INSTALL_OPTIONS: are the options to install packages without any input from the user required +# INSTALL_QUERY: command and options to use for checking the existence of packages. function set_host_installer() { if [ -f /etc/arch-release ]; then if has_command pacman; then @@ -20,6 +26,7 @@ function set_host_installer() { fi } +# Takes a list of pakages and sets MISSING_PKGS with those missing in the current system. function filter_installed() { for package in "$@" do @@ -31,7 +38,7 @@ function filter_installed() { done } - +# Install the list of packages in the current system. function install_dep() { set_host_installer filter_installed "$@"