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 2016/10/11 02:50:28 UTC
incubator-mynewt-newt git commit: newtmgr - "image state" command.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop b153d9581 -> a0810dcb5
newtmgr - "image state" command.
This command is intended to replace the following:
* image list
* image boot
* split status
It remains a separate command until it is complete.
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/a0810dcb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a0810dcb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a0810dcb
Branch: refs/heads/develop
Commit: a0810dcb5ec564efbca6e829d24c1e0caf827e5b
Parents: b153d95
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 10 19:41:20 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Oct 10 19:41:20 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 58 +++++++++++++++++++++++++++++
newtmgr/protocol/imagelist.go | 1 +
newtmgr/protocol/imagestate.go | 73 +++++++++++++++++++++++++++++++++++++
3 files changed, 132 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0810dcb/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 453f4ce..e025f56 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -93,6 +93,57 @@ func imageListCmd(cmd *cobra.Command, args []string) {
}
}
+func imageStateCmd(cmd *cobra.Command, args []string) {
+ runner, err := getTargetCmdRunner()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ defer runner.Conn.Close()
+
+ imageState, err := protocol.NewImageState()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := imageState.EncodeWriteRequest()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ rsp, err := runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ iRsp, err := protocol.DecodeImageStateResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ fmt.Println("Images:")
+ for _, img := range iRsp.Images {
+ fmt.Printf(" slot=%d\n", img.Slot)
+ fmt.Printf(" version=%s\n", img.Version)
+ fmt.Printf(" active=%v\n", img.Active)
+ fmt.Printf(" confirmed=%v\n", img.Confirmed)
+ fmt.Printf(" pending=%v\n", img.Pending)
+ fmt.Printf(" bootable=%v\n", img.Bootable)
+ if img.Hash == "" {
+ fmt.Printf(" hash=Unavailable\n")
+ } else {
+ dec, err := base64.StdEncoding.DecodeString(img.Hash)
+ if err != nil {
+ fmt.Printf(" hash=Unable to Decode")
+ } else {
+ fmt.Printf(" hash=%s\n", hex.EncodeToString(dec[:]))
+ }
+ }
+ }
+}
+
func echoOnNmUsage(runner *protocol.CmdRunner, cmderr error, cmd *cobra.Command) {
echoCtrl(runner, "1")
nmUsage(cmd, cmderr)
@@ -575,6 +626,13 @@ func imageCmd() *cobra.Command {
}
imageCmd.AddCommand(listCmd)
+ stateCmd := &cobra.Command{
+ Use: "state",
+ Short: "Show target images",
+ Run: imageStateCmd,
+ }
+ imageCmd.AddCommand(stateCmd)
+
uploadEx := " newtmgr -c olimex image upload <image_file\n"
uploadEx += " newtmgr -c olimex image upload bin/slinky_zero/apps/slinky.img\n"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0810dcb/newtmgr/protocol/imagelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist.go b/newtmgr/protocol/imagelist.go
index 47e8514..67def59 100644
--- a/newtmgr/protocol/imagelist.go
+++ b/newtmgr/protocol/imagelist.go
@@ -36,6 +36,7 @@ const (
IMGMGR_NMGR_OP_BOOT2 = 5
IMGMGR_NMGR_OP_CORELIST = 6
IMGMGR_NMGR_OP_CORELOAD = 7
+ IMGMGR_NMGR_OP_STATE = 8
)
func HashDecode(src string) (string, error) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0810dcb/newtmgr/protocol/imagestate.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagestate.go b/newtmgr/protocol/imagestate.go
new file mode 100644
index 0000000..4d85ea5
--- /dev/null
+++ b/newtmgr/protocol/imagestate.go
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+import (
+ "fmt"
+
+ "github.com/ugorji/go/codec"
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageStateEntry struct {
+ Slot int `codec:"slot"`
+ Version string `codec:"version"`
+ Hash string `codec:"hash"`
+ Bootable bool `codec:"bootable"`
+ Pending bool `codec:"test-pending"`
+ Confirmed bool `codec:"confirmed"`
+ Active bool `codec:"active"`
+}
+
+type ImageState struct {
+ Images []ImageStateEntry `codec:"images"`
+}
+
+func NewImageState() (*ImageState, error) {
+ s := &ImageState{}
+ return s, nil
+}
+
+func (i *ImageState) EncodeWriteRequest() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_IMAGE
+ nmr.Id = IMGMGR_NMGR_OP_STATE
+ nmr.Len = 0
+
+ return nmr, nil
+}
+
+func DecodeImageStateResponse(data []byte) (*ImageState, error) {
+ state := &ImageState{}
+
+ dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+ err := dec.Decode(&state)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+ return state, nil
+}