This is an automated email from Gerrit.

"Ahmed Haoues <[email protected]>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/9698

-- gerrit

commit d4aec8f9c255085164a595d14563bee69fefbf05
Author: HAOUES Ahmed <[email protected]>
Date:   Thu Jul 2 15:13:29 2026 +0100

    tcl: add helper to download STM32 flash loader files
    
    Introduce shared Tcl helpers to:
    - create the download directory if needed
    - download loader files using curl or wget
    - reuse already downloaded files
    - clean up partial downloads on failure
    
    Change-Id: Ic9c3681f6ab0c695e177f1470ea491899a316b23
    Signed-off-by: HAOUES Ahmed <[email protected]>

diff --git a/tcl/tools/stldr_helper.tcl b/tcl/tools/stldr_helper.tcl
new file mode 100644
index 0000000000..c8944298d0
--- /dev/null
+++ b/tcl/tools/stldr_helper.tcl
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# common script for stm32 device families to download the Flash Loader file
+
+proc ensure_dir {dir} {
+    if {![file isdirectory $dir] && [catch {file mkdir $dir} err]} {
+        echo "Error: Failed to create directory '$dir': $err"; shutdown
+    }
+}
+
+proc download_loader {url} {
+    set filename [file tail $url]
+    set downloads_dir [file join [pwd] downloads]
+    set dest [file join $downloads_dir $filename]
+
+    if {![file exists $dest]} {
+        ensure_dir [file dirname $dest]
+
+        # Try curl, then wget
+        if {[catch {exec curl -f -L -o $dest $url} err]} {
+            if {[catch {exec wget -O $dest $url} err2]} {
+                echo "Error: Failed to download $url (no curl/wget or error)"
+                echo "curl error: $err"
+                echo "wget error: $err2"
+                if {[file exists $dest]} {
+                    file delete -force $dest
+                }
+                shutdown
+            }
+        }
+        echo "Info: Downloaded: $dest"
+        return $dest
+    } else {
+        echo "Info: File already exists, skip download: $dest"
+        return $dest
+    }
+}

-- 

Reply via email to