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

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


The following commit(s) were added to refs/heads/master by this push:
     new d7efc36  Fix --imgfile option for the `load` command
d7efc36 is described below

commit d7efc36caf7314782c7a21053b7cfa9c46a10fd8
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Fri Jun 12 13:29:09 2020 -0700

    Fix --imgfile option for the `load` command
    
    `--imgfile` lets the user specify the image file to load rather than
    letting newt derive it from the target name.
    
    This option wasn't working properly.  For the download scripts to load
    the specified file, the `BIN_BASENAME` environment variable needs to be
    set to the file's *base* (i.e., strip the `.img` extension).
    
    Prior to this commit, this environment variable wasn't being overridden
    at all.  The effect was that the `--imgfile` option was ignored
    completely.
---
 newt/builder/load.go | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/newt/builder/load.go b/newt/builder/load.go
index d09ce48..f437e8d 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -81,18 +81,28 @@ func (t *TargetBuilder) Load(extraJtagCmd string, 
imgFileOverride string) error
                        "cannot specify image file override for split images")
        }
 
-       appImg := imgFileOverride
-       if appImg == "" {
-               appImg = t.AppBuilder.AppBinBasePath()
+       var imgBase string
+       if imgFileOverride == "" {
+               imgBase = t.AppBuilder.AppBinBasePath()
+       } else {
+               // The download script appends ".img" to the basename.  Make 
sure we
+               // can strip the extension here and the script will reconstruct 
the
+               // original filename.
+               imgBase = strings.TrimSuffix(imgFileOverride, ".img")
+               if imgBase == imgFileOverride {
+                       return util.FmtNewtError(
+                               "invalid img filename: must end in \".img\": 
filename=%s",
+                               imgFileOverride)
+               }
        }
 
        if t.LoaderBuilder != nil {
-               err = t.loadApp(1, extraJtagCmd, appImg)
+               err = t.loadApp(1, extraJtagCmd, imgBase)
                if err == nil {
                        err = t.loadLoader(0, extraJtagCmd, 
t.LoaderBuilder.AppBinBasePath())
                }
        } else {
-               err = t.loadApp(0, extraJtagCmd, appImg)
+               err = t.loadApp(0, extraJtagCmd, imgBase)
        }
 
        return err
@@ -194,6 +204,9 @@ func (b *Builder) Load(imageSlot int, extraJtagCmd string, 
imgFilename string) e
        // compatibility with unix-in-windows environemnts (e.g., cygwin).
        binPath := util.TryRelPath(imgFilename)
 
+       // Make sure the img override (if any) gets used.
+       env["BIN_BASENAME"] = binPath
+
        if err := Load(binPath, b.targetBuilder.bspPkg, env); err != nil {
                return err
        }

Reply via email to