load: add --imgfile option

This option allows the user to specify the .img file to load onto the
device.  If the option is unspecified, newt loads the image file from
the target's bin directory as before.
diff --git a/newt/builder/load.go b/newt/builder/load.go
index ec8f4df..ce72591 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -31,20 +31,20 @@
 	"mynewt.apache.org/newt/util"
 )
 
-func (t *TargetBuilder) loadLoader(slot int, extraJtagCmd string) error {
+func (t *TargetBuilder) loadLoader(slot int, extraJtagCmd string, imgFilename string) error {
 	if err := t.bspPkg.Reload(t.LoaderBuilder.cfg.SettingValues()); err != nil {
 		return err
 	}
 
-	return t.LoaderBuilder.Load(slot, extraJtagCmd)
+	return t.LoaderBuilder.Load(slot, extraJtagCmd, imgFilename)
 }
 
-func (t *TargetBuilder) loadApp(slot int, extraJtagCmd string) error {
+func (t *TargetBuilder) loadApp(slot int, extraJtagCmd string, imgFilename string) error {
 	if err := t.bspPkg.Reload(t.AppBuilder.cfg.SettingValues()); err != nil {
 		return err
 	}
 
-	return t.AppBuilder.Load(slot, extraJtagCmd)
+	return t.AppBuilder.Load(slot, extraJtagCmd, imgFilename)
 }
 
 func (t *TargetBuilder) debugLoader(extraJtagCmd string, reset bool,
@@ -67,19 +67,32 @@
 	return t.AppBuilder.Debug(extraJtagCmd, reset, noGDB)
 }
 
-func (t *TargetBuilder) Load(extraJtagCmd string) error {
+// Load loads a .img file onto a device.  If imgFileOverride is not empty, it
+// specifies the path of the image file to load.  If it is empty, the image in
+// the target's `bin` directory is loaded.
+func (t *TargetBuilder) Load(extraJtagCmd string, imgFileOverride string) error {
 	err := t.PrepBuild()
 	if err != nil {
 		return err
 	}
 
+	if t.LoaderBuilder != nil && imgFileOverride != "" {
+		return util.FmtNewtError(
+			"cannot specify image file override for split images")
+	}
+
+	appImg := imgFileOverride
+	if appImg == "" {
+		appImg = t.AppBuilder.AppBinBasePath()
+	}
+
 	if t.LoaderBuilder != nil {
-		err = t.loadApp(1, extraJtagCmd)
+		err = t.loadApp(1, extraJtagCmd, appImg)
 		if err == nil {
-			err = t.loadLoader(0, extraJtagCmd)
+			err = t.loadLoader(0, extraJtagCmd, t.LoaderBuilder.AppBinBasePath())
 		}
 	} else {
-		err = t.loadApp(0, extraJtagCmd)
+		err = t.loadApp(0, extraJtagCmd, appImg)
 	}
 
 	return err
@@ -149,7 +162,7 @@
 	return nil
 }
 
-func (b *Builder) Load(imageSlot int, extraJtagCmd string) error {
+func (b *Builder) Load(imageSlot int, extraJtagCmd string, imgFilename string) error {
 	if b.appPkg == nil {
 		return util.NewNewtError("app package not specified")
 	}
@@ -171,15 +184,16 @@
 
 	if _, ok := env["BOOT_LOADER"]; ok {
 		util.StatusMessage(util.VERBOSITY_DEFAULT,
-			"Loading bootloader\n")
+			"Loading bootloader (%s)\n", imgFilename)
 	} else {
 		util.StatusMessage(util.VERBOSITY_DEFAULT,
-			"Loading %s image into slot %d\n", b.buildName, imageSlot+1)
+			"Loading %s image into slot %d (%s)\n", b.buildName, imageSlot+1, imgFilename)
 	}
 
 	// Convert the binary path from absolute to relative.  This is required for
 	// compatibility with unix-in-windows environemnts (e.g., cygwin).
-	binPath := util.TryRelPath(b.AppBinBasePath())
+	binPath := util.TryRelPath(imgFilename)
+
 	if err := Load(binPath, b.targetBuilder.bspPkg, env); err != nil {
 		return err
 	}
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 6901e4a..ff11231 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -104,6 +104,7 @@
 var extraJtagCmd string
 var noGDB_flag bool
 var diffFriendly_flag bool
+var imgFileOverride string
 
 func buildRunCmd(cmd *cobra.Command, args []string, printShellCmds bool, executeShell bool) {
 	if len(args) < 1 {
@@ -350,7 +351,7 @@
 		NewtUsage(nil, err)
 	}
 
-	if err := b.Load(extraJtagCmd); err != nil {
+	if err := b.Load(extraJtagCmd, imgFileOverride); err != nil {
 		NewtUsage(cmd, err)
 	}
 }
@@ -487,6 +488,8 @@
 
 	loadCmd.PersistentFlags().StringVarP(&extraJtagCmd, "extrajtagcmd", "", "",
 		"Extra commands to send to JTAG software")
+	loadCmd.PersistentFlags().StringVarP(&imgFileOverride, "imgfile", "", "",
+		"Path of .img file to load instead of target artifact")
 
 	debugHelpText := "Open a debugger session for <target-name>"
 
diff --git a/newt/cli/run_cmds.go b/newt/cli/run_cmds.go
index e008643..99b41bb 100644
--- a/newt/cli/run_cmds.go
+++ b/newt/cli/run_cmds.go
@@ -116,7 +116,7 @@
 			}
 		}
 
-		if err := b.Load(extraJtagCmd); err != nil {
+		if err := b.Load(extraJtagCmd, ""); err != nil {
 			NewtUsage(nil, err)
 		}