You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2020/04/28 23:57:13 UTC

[mynewt-newt] branch master updated (ec8c217 -> f0a1342)

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

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


    from ec8c217  Log exported environnment variables with `-ldebug`
     new 71d8423  load: add --imgfile option
     new f0a1342  debug: add --elffile option

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 newt/builder/load.go   | 92 ++++++++++++++++++++++++++++++++++----------------
 newt/cli/build_cmds.go | 10 ++++--
 newt/cli/run_cmds.go   |  4 +--
 3 files changed, 73 insertions(+), 33 deletions(-)


[mynewt-newt] 02/02: debug: add --elffile option

Posted by cc...@apache.org.
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

commit f0a1342e44fbc85ff1d5cb2b9f6b46e70885eb87
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Apr 27 17:43:46 2020 -0700

    debug: add --elffile option
    
    This option allows the user to specify the .elf file to load into gdb.
    If the option is unspecified, newt uses the .elf file from the target's
    bin directory as before.
---
 newt/builder/load.go   | 54 ++++++++++++++++++++++++++++++++++----------------
 newt/cli/build_cmds.go |  5 ++++-
 newt/cli/run_cmds.go   |  2 +-
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/newt/builder/load.go b/newt/builder/load.go
index ce72591..d09ce48 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -48,23 +48,23 @@ func (t *TargetBuilder) loadApp(slot int, extraJtagCmd string, imgFilename strin
 }
 
 func (t *TargetBuilder) debugLoader(extraJtagCmd string, reset bool,
-	noGDB bool) error {
+	noGDB bool, elfBase string) error {
 
 	if err := t.bspPkg.Reload(t.LoaderBuilder.cfg.SettingValues()); err != nil {
 		return err
 	}
 
-	return t.LoaderBuilder.Debug(extraJtagCmd, reset, noGDB)
+	return t.LoaderBuilder.Debug(extraJtagCmd, reset, noGDB, elfBase)
 }
 
 func (t *TargetBuilder) debugApp(extraJtagCmd string, reset bool,
-	noGDB bool) error {
+	noGDB bool, elfBase string) error {
 
 	if err := t.bspPkg.Reload(t.AppBuilder.cfg.SettingValues()); err != nil {
 		return err
 	}
 
-	return t.AppBuilder.Debug(extraJtagCmd, reset, noGDB)
+	return t.AppBuilder.Debug(extraJtagCmd, reset, noGDB, elfBase)
 }
 
 // Load loads a .img file onto a device.  If imgFileOverride is not empty, it
@@ -201,15 +201,40 @@ func (b *Builder) Load(imageSlot int, extraJtagCmd string, imgFilename string) e
 	return nil
 }
 
-func (t *TargetBuilder) Debug(extraJtagCmd string, reset bool, noGDB bool) error {
+// Debug runs gdb on the .elf file corresponding to what is running on a
+// device.  If elfFileOverride is not empty, it specifies the path of the .elf
+// file to debug.  If it is empty, the .elf file in the target's `bin`
+// directory is loaded.
+func (t *TargetBuilder) Debug(extraJtagCmd string, reset bool, noGDB bool, elfFileOverride string) error {
 	if err := t.PrepBuild(); err != nil {
 		return err
 	}
 
+	var elfBase string // Everything except ".elf"
+
+	if elfFileOverride != "" {
+		// The debug script appends ".elf" to the basename.  Make sure we can strip
+		// the extension here and the script will reconstruct the original
+		// filename.
+		elfBase = strings.TrimSuffix(elfFileOverride, ".elf")
+		if elfBase == elfFileOverride {
+			return util.FmtNewtError(
+				"invalid elf filename: must end in \".elf\": filename=%s",
+				elfFileOverride)
+		}
+	}
+
 	if t.LoaderBuilder == nil {
-		return t.debugApp(extraJtagCmd, reset, noGDB)
+		if elfBase == "" {
+			elfBase = t.AppBuilder.AppBinBasePath()
+		}
+		return t.debugApp(extraJtagCmd, reset, noGDB, elfBase)
+	} else {
+		if elfBase == "" {
+			elfBase = t.LoaderBuilder.AppBinBasePath()
+		}
+		return t.debugLoader(extraJtagCmd, reset, noGDB, elfBase)
 	}
-	return t.debugLoader(extraJtagCmd, reset, noGDB)
 }
 
 func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
@@ -231,6 +256,9 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
 		return err
 	}
 
+	// Make sure the elf override (if any) gets used.
+	env["BIN_BASENAME"] = binPath
+
 	if extraJtagCmd != "" {
 		env["EXTRA_JTAG_CMD"] = extraJtagCmd
 	}
@@ -241,9 +269,6 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
 		env["NO_GDB"] = "1"
 	}
 
-	// The debug script appends ".elf" to the basename.
-	env["BIN_BASENAME"] = strings.TrimSuffix(env["BIN_BASENAME"], ".elf")
-
 	os.Chdir(project.GetProject().Path())
 
 	RunOptionalCheck(bspPkg.OptChkScript, env)
@@ -257,11 +282,6 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
 	return util.ShellInteractiveCommand(cmdLine, env, false)
 }
 
-func (b *Builder) Debug(extraJtagCmd string, reset bool, noGDB bool) error {
-	binPath, err := b.binBasePath()
-	if err != nil {
-		return err
-	}
-
-	return b.debugBin(binPath, extraJtagCmd, reset, noGDB)
+func (b *Builder) Debug(extraJtagCmd string, reset bool, noGDB bool, binBase string) error {
+	return b.debugBin(binBase, extraJtagCmd, reset, noGDB)
 }
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index ff11231..63d08bd 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -105,6 +105,7 @@ var extraJtagCmd string
 var noGDB_flag bool
 var diffFriendly_flag bool
 var imgFileOverride string
+var elfFileOverride string
 
 func buildRunCmd(cmd *cobra.Command, args []string, printShellCmds bool, executeShell bool) {
 	if len(args) < 1 {
@@ -373,7 +374,7 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
 		NewtUsage(nil, err)
 	}
 
-	if err := b.Debug(extraJtagCmd, false, noGDB_flag); err != nil {
+	if err := b.Debug(extraJtagCmd, false, noGDB_flag, elfFileOverride); err != nil {
 		NewtUsage(cmd, err)
 	}
 }
@@ -504,6 +505,8 @@ func AddBuildCommands(cmd *cobra.Command) {
 		"", "Extra commands to send to JTAG software")
 	debugCmd.PersistentFlags().BoolVarP(&noGDB_flag, "noGDB", "n", false,
 		"Do not start GDB from command line")
+	debugCmd.PersistentFlags().StringVarP(&elfFileOverride, "elffile", "",
+		"", "Path of .elf file to debug instead of target artifact")
 
 	cmd.AddCommand(debugCmd)
 	AddTabCompleteFn(debugCmd, targetList)
diff --git a/newt/cli/run_cmds.go b/newt/cli/run_cmds.go
index 99b41bb..0dfd880 100644
--- a/newt/cli/run_cmds.go
+++ b/newt/cli/run_cmds.go
@@ -120,7 +120,7 @@ func runRunCmd(cmd *cobra.Command, args []string) {
 			NewtUsage(nil, err)
 		}
 
-		if err := b.Debug(extraJtagCmd, true, noGDB_flag); err != nil {
+		if err := b.Debug(extraJtagCmd, true, noGDB_flag, ""); err != nil {
 			NewtUsage(nil, err)
 		}
 	}


[mynewt-newt] 01/02: load: add --imgfile option

Posted by cc...@apache.org.
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

commit 71d8423722a554c00bd8ff5734878252d4f42919
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Apr 27 17:12:44 2020 -0700

    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.
---
 newt/builder/load.go   | 38 ++++++++++++++++++++++++++------------
 newt/cli/build_cmds.go |  5 ++++-
 newt/cli/run_cmds.go   |  2 +-
 3 files changed, 31 insertions(+), 14 deletions(-)

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 @@ import (
 	"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 @@ func (t *TargetBuilder) debugApp(extraJtagCmd string, reset bool,
 	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 @@ func Load(binBasePath string, bspPkg *pkg.BspPackage,
 	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 @@ func (b *Builder) Load(imageSlot int, extraJtagCmd string) error {
 
 	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 @@ func pkgToUnitTests(pack *pkg.LocalPackage) []*pkg.LocalPackage {
 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 @@ func loadRunCmd(cmd *cobra.Command, args []string) {
 		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 @@ func AddBuildCommands(cmd *cobra.Command) {
 
 	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 @@ func runRunCmd(cmd *cobra.Command, args []string) {
 			}
 		}
 
-		if err := b.Load(extraJtagCmd); err != nil {
+		if err := b.Load(extraJtagCmd, ""); err != nil {
 			NewtUsage(nil, err)
 		}