You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/06/13 19:55:00 UTC
[3/3] incubator-mynewt-newt git commit: Flags to dump partial core
and elfify core
Flags to dump partial core and elfify core
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/e9b63a79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e9b63a79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e9b63a79
Branch: refs/heads/develop
Commit: e9b63a794ea343966c1f75b2fa2de93c78213020
Parents: dbd9563
Author: spoonofpower <sp...@gmail.com>
Authored: Fri Jun 10 17:13:15 2016 -0700
Committer: spoonofpower <sp...@gmail.com>
Committed: Fri Jun 10 17:20:29 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 24 ++++++++++++++++++++----
newtmgr/protocol/coreload.go | 9 +++++++--
2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e9b63a79/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 5f8f1b3..382371e 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -20,6 +20,7 @@
package cli
import (
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -35,6 +36,12 @@ import (
"github.com/spf13/cobra"
)
+var (
+ coreElfify bool
+ coreOffset uint32
+ coreNumBytes uint32
+)
+
func imageListCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -462,7 +469,7 @@ func fileDownloadCmd(cmd *cobra.Command, args []string) {
func coreDownloadCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
- fmt.Println("Need to specify target filename to download")
+ nmUsage(cmd, errors.New("Need to specify target filename to download"))
return
}
@@ -485,7 +492,7 @@ func coreDownloadCmd(cmd *cobra.Command, args []string) {
coreDownload.Runner = runner
coreDownload.File = file
- err = coreDownload.Download()
+ err = coreDownload.Download(coreOffset, coreNumBytes)
file.Close()
if err != nil {
fmt.Println(err)
@@ -494,6 +501,11 @@ func coreDownloadCmd(cmd *cobra.Command, args []string) {
fmt.Println("Coredump download completed")
+ if !coreElfify {
+ os.Rename(tmpName, args[0])
+ return
+ }
+
/*
* Download finished. Now convert to ELF corefile format.
*/
@@ -686,8 +698,9 @@ func imageCmd() *cobra.Command {
}
imageCmd.AddCommand(coreListCmd)
- coreEx := " newtmgr -c olimex image coredownload <filename>\n"
- coreEx += " newtmgr -c olimex image coredownload core\n"
+ coreEx := " newtmgr -c olimex image coredownload -e <filename>\n"
+ coreEx += " newtmgr -c olimex image coredownload -e core\n"
+ coreEx += " newtmgr -c olimex image coredownload --offset 10 -n 10 core\n"
coreDownloadCmd := &cobra.Command{
Use: "coredownload",
@@ -695,6 +708,9 @@ func imageCmd() *cobra.Command {
Example: coreEx,
Run: coreDownloadCmd,
}
+ coreDownloadCmd.Flags().BoolVarP(&coreElfify, "elfify", "e", false, "Creat an elf file")
+ coreDownloadCmd.Flags().Uint32Var(&coreOffset, "offset", 0, "Start offset")
+ coreDownloadCmd.Flags().Uint32VarP(&coreNumBytes, "bytes", "n", 0, "Number of bytes of the core to download")
imageCmd.AddCommand(coreDownloadCmd)
coreEraseEx := " newtmgr -c olimex image coreerase\n"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e9b63a79/newtmgr/protocol/coreload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/coreload.go b/newtmgr/protocol/coreload.go
index ea2bf4a..ed38bdf 100644
--- a/newtmgr/protocol/coreload.go
+++ b/newtmgr/protocol/coreload.go
@@ -51,7 +51,7 @@ func NewCoreDownload() (*CoreDownload, error) {
return f, nil
}
-func (cl *CoreDownload) Download() error {
+func (cl *CoreDownload) Download(off, size uint32) error {
if cl.File == nil {
return util.NewNewtError("Missing target file")
}
@@ -60,13 +60,13 @@ func (cl *CoreDownload) Download() error {
}
imageDone := 0
+ var bytesWritten uint32 = 0
nmr, err := NewNmgrReq()
if err != nil {
return err
}
req := &coreLoadReq{}
- var off uint32 = 0
for imageDone != 1 {
req.Off = off
@@ -113,6 +113,10 @@ func (cl *CoreDownload) Download() error {
err.Error()))
}
if len(data) > 0 {
+ if size > 0 && uint32(len(data))+bytesWritten >= size {
+ data = data[:size-bytesWritten]
+ imageDone = 1
+ }
n, err := cl.File.Write(data)
if err == nil && n < len(data) {
err = io.ErrShortWrite
@@ -123,6 +127,7 @@ func (cl *CoreDownload) Download() error {
err.Error()))
}
off += uint32(len(data))
+ bytesWritten += uint32(len(data))
} else {
imageDone = 1
}