Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/master 3eb0674e2 -> 7fb023676


Add 'target label' command for invoking bin2img.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/b221ef8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/b221ef8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/b221ef8c

Branch: refs/heads/master
Commit: b221ef8ccdfb54fee83cd79b771dbec7c80b7ba7
Parents: 3eb0674
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Feb 11 07:39:06 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Feb 11 07:39:06 2016 -0800

----------------------------------------------------------------------
 newt/cli/target.go | 65 +++++++++++++++++++++++++++++++++++++++----------
 newt/newt.go       | 33 +++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b221ef8c/newt/cli/target.go
----------------------------------------------------------------------
diff --git a/newt/cli/target.go b/newt/cli/target.go
index 77dd971..ae04a6d 100644
--- a/newt/cli/target.go
+++ b/newt/cli/target.go
@@ -400,6 +400,52 @@ func (t *Target) Remove() error {
        return nil
 }
 
+func (t *Target) binPath() (string, error) {
+       if t.Vars["project"] == "" {
+               return "", NewNewtError(fmt.Sprintf("No project associated with 
" +
+                       "target %s", t.Name))
+       }
+       p, err := LoadProject(t.Repo, t, t.Vars["project"])
+       if err != nil {
+               return "", err
+       }
+       return filepath.Join(p.BinPath(), p.Name), nil
+}
+
+func (t *Target) Label(versionStr string) error {
+       bin2img, err := LoadTarget(t.Repo, "bin2img")
+       if err != nil {
+               return NewNewtError("Cannot label with bin2img target")
+       }
+
+       err = bin2img.Build()
+       if err != nil {
+               return err
+       }
+
+       bin2imgBase, err := bin2img.binPath()
+       if err != nil {
+               return err
+       }
+
+       bin2imgPath := bin2imgBase + ".elf"
+
+       binBaseName, err := t.binPath()
+       if err != nil {
+               return err
+       }
+
+       os.Chdir(t.Repo.BasePath)
+
+       rsp, err := ShellCommand(fmt.Sprintf("%s %s %s %s", bin2imgPath,
+               binBaseName + ".elf.bin", binBaseName + ".img", versionStr))
+       if err != nil {
+               StatusMessage(VERBOSITY_DEFAULT, "%s", rsp);
+               return err
+       }
+       return nil
+}
+
 func (t *Target) Download() error {
        pkgList, err := NewPkgList(t.Repo)
        if err != nil {
@@ -421,11 +467,7 @@ func (t *Target) Download() error {
        }
        downloadScript := filepath.Join(pkg.BasePath, pkg.DownloadScript)
 
-       if t.Vars["project"] == "" {
-               return NewNewtError(fmt.Sprintf("No project associated with 
target %s",
-                       t.Name))
-       }
-       p, err := LoadProject(t.Repo, t, t.Vars["project"])
+       binBaseName, err := t.binPath()
        if err != nil {
                return err
        }
@@ -439,7 +481,7 @@ func (t *Target) Download() error {
 
        StatusMessage(VERBOSITY_DEFAULT, "Downloading with %s\n", 
downloadScript)
        rsp, err := ShellCommand(fmt.Sprintf("%s %s %s", downloadScript,
-               filepath.Join(p.BinPath(), p.Name), identString))
+               binBaseName, identString))
        if err != nil {
                StatusMessage(VERBOSITY_DEFAULT, "%s", rsp);
                return err
@@ -469,11 +511,7 @@ func (t *Target) Debug() error {
        }
        debugScript := filepath.Join(pkg.BasePath, pkg.DebugScript)
 
-       if t.Vars["project"] == "" {
-               return NewNewtError(fmt.Sprintf("No project associated with 
target %s",
-                       t.Name))
-       }
-       p, err := LoadProject(t.Repo, t, t.Vars["project"])
+       binBaseName, err := t.binPath()
        if err != nil {
                return err
        }
@@ -485,9 +523,10 @@ func (t *Target) Debug() error {
                identString = identString + ident
        }
 
-       StatusMessage(VERBOSITY_DEFAULT, "Debugging with %s %s\n", debugScript, 
p.Name)
+       StatusMessage(VERBOSITY_DEFAULT, "Debugging with %s %s\n", debugScript,
+               binBaseName)
 
-       cmdLine := []string{debugScript, filepath.Join(p.BinPath(), p.Name)}
+       cmdLine := []string{debugScript, binBaseName}
        cmdLine = append(cmdLine, identString)
        err = ShellInteractiveCommand(cmdLine)
        if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b221ef8c/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index af3cdbb..7a41e42 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -303,6 +303,22 @@ func targetSizeCmd(cmd *cobra.Command, args []string) {
        cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", txt)
 }
 
+func targetLabelCmd(cmd *cobra.Command, args []string) {
+       if len(args) < 2 {
+               NewtUsage(cmd, cli.NewNewtError("Must specify target and 
version"))
+       }
+
+       t, err := cli.LoadTarget(NewtRepo, args[0])
+       if err != nil {
+               NewtUsage(nil, err)
+       }
+
+       err = t.Label(args[1])
+       if err != nil {
+               NewtUsage(nil, err)
+       }
+}
+
 func targetDownloadCmd(cmd *cobra.Command, args []string) {
        if len(args) < 1 {
                NewtUsage(cmd, cli.NewNewtError("Must specify target to 
download"))
@@ -386,6 +402,7 @@ func targetAddCmds(base *cobra.Command) {
        targetHelpEx += "  newt target build <target-name> [clean[ all]]\n"
        targetHelpEx += "  newt target test <target-name> [clean[ all]]\n"
        targetHelpEx += "  newt target size <target-name>\n"
+       targetHelpEx += "  newt target label <target-name> <version number>"
        targetHelpEx += "  newt target download <target-name>\n"
        targetHelpEx += "  newt target debug <target-name>\n"
        targetHelpEx += "  newt target export [-a -export-all] 
[<target-name>]\n"
@@ -549,6 +566,22 @@ func targetAddCmds(base *cobra.Command) {
 
        targetCmd.AddCommand(sizeCmd)
 
+       labelHelpText := formatHelp(`Label image by appending image header to 
created
+               binary file <target-name>. Version number in the header is set 
to be
+               <version>`)
+       labelHelpEx := "  newt target label <target-name> <version>\n"
+       labelHelpEx += "  newt target label my_target1 1.2.0\n"
+       labelHelpEx += "  newt target label my_target1 1.2.0.3\n"
+
+       labelCmd := &cobra.Command{
+               Use:     "label",
+               Short:   "Add image header to target binary",
+               Long:    labelHelpText,
+               Example: labelHelpEx,
+               Run:     targetLabelCmd,
+       }
+       targetCmd.AddCommand(labelCmd)
+
        downloadHelpText := formatHelp(`Download project image to target for
                <target-name>.`)
        downloadHelpEx := "  newt target download <target-name>\n"

Reply via email to