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/01/13 00:00:07 UTC
[1/2] incubator-mynewt-newt git commit: Add 'image boot' to set the
image to boot.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/master 73fe35035 -> 5e87e8f6f
Add 'image boot' to set the image to boot.
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/982154c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/982154c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/982154c4
Branch: refs/heads/master
Commit: 982154c467b0c0a8e5bd95ac154d9ab8858f1693
Parents: 73fe350
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Jan 12 14:59:14 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Jan 12 14:59:14 2016 -0800
----------------------------------------------------------------------
newtmgr/newtmgr.go | 73 ++++++++++++++++++---
newtmgr/protocol/imageboot.go | 131 +++++++++++++++++++++++++++++++++++++
newtmgr/protocol/imagelist.go | 14 +++-
3 files changed, 208 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/982154c4/newtmgr/newtmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/newtmgr.go b/newtmgr/newtmgr.go
index e7c9622..fb7a722 100644
--- a/newtmgr/newtmgr.go
+++ b/newtmgr/newtmgr.go
@@ -239,9 +239,6 @@ func echoCmd() *cobra.Command {
return echoCmd
}
-func imageRunCmd(cmd *cobra.Command, args []string) {
-}
-
func imageListCmd(cmd *cobra.Command, args []string) {
cpm, err := cli.NewCpMgr()
if err != nil {
@@ -286,13 +283,14 @@ func imageListCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ fmt.Println("Images:")
for i := 0; i < len(iRsp.Images); i++ {
- fmt.Println(iRsp.Images[i])
+ fmt.Println(" ", i, ": " + iRsp.Images[i])
}
}
func imageUploadCmd(cmd *cobra.Command, args []string) {
- if (len(args) < 1) {
+ if len(args) < 1 {
nmUsage(cmd, util.NewNewtError("Need to specify image to upload"))
}
@@ -331,12 +329,12 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
blockSz := imageSz - currOff
- if (blockSz > 64) {
+ if blockSz > 64 {
blockSz = 64
}
imageUpload.Offset = currOff
- imageUpload.Data = imageFile[currOff:currOff + blockSz]
+ imageUpload.Data = imageFile[currOff : currOff+blockSz]
nmr, err := imageUpload.EncodeWriteRequest()
if err != nil {
@@ -362,11 +360,63 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
fmt.Println("Done")
}
+func imageBootCmd(cmd *cobra.Command, args []string) {
+ cpm, err := cli.NewCpMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ imageBoot, err := protocol.NewImageBoot()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if len(args) >= 1 {
+ imageBoot.BootTarget = args[0]
+ }
+ nmr, err := imageBoot.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.DecodeImageBootResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ fmt.Println(" Test image :", iRsp.TestImage)
+ fmt.Println(" Main image :", iRsp.MainImage)
+ fmt.Println(" Active img :", iRsp.ActiveImage)
+}
+
func imageCmd() *cobra.Command {
imageCmd := &cobra.Command{
Use: "image",
Short: "Manage images on remote instance",
- Run: imageRunCmd,
+ Run: imageListCmd,
}
listCmd := &cobra.Command{
@@ -383,6 +433,13 @@ func imageCmd() *cobra.Command {
}
imageCmd.AddCommand(uploadCmd)
+ bootCmd := &cobra.Command{
+ Use: "boot",
+ Short: "Which image to boot",
+ Run: imageBootCmd,
+ }
+ imageCmd.AddCommand(bootCmd)
+
return imageCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/982154c4/newtmgr/protocol/imageboot.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageboot.go b/newtmgr/protocol/imageboot.go
new file mode 100644
index 0000000..5bd3fd8
--- /dev/null
+++ b/newtmgr/protocol/imageboot.go
@@ -0,0 +1,131 @@
+/*
+ Copyright 2015 Runtime Inc.
+ Licensed 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 (
+ "encoding/binary"
+ "strconv"
+ "strings"
+
+ "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
+)
+
+type ImageBoot struct {
+ BootTarget string
+ TestImage string
+ MainImage string
+ ActiveImage string
+}
+
+func NewImageBoot() (*ImageBoot, error) {
+ s := &ImageBoot{}
+ s.BootTarget = ""
+ s.TestImage = ""
+ s.MainImage = ""
+ s.ActiveImage = ""
+ return s, nil
+}
+
+func (i *ImageBoot) 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 = 2
+ nmr.Len = 0
+
+ if i.BootTarget != "" {
+ verArray := strings.Split(i.BootTarget, ".")
+ major, err := strconv.ParseUint(verArray[0], 10, 8)
+ if err != nil {
+ return nil, util.NewNewtError("Invalid version string")
+ }
+ minor, err := strconv.ParseUint(verArray[1], 10, 8)
+ if err != nil {
+ return nil, util.NewNewtError("Invalid version string")
+ }
+
+ var revision uint64 = 0
+ if len(verArray) > 2 {
+ revision, err = strconv.ParseUint(verArray[2], 10, 16)
+ if err != nil {
+ return nil, util.NewNewtError("Invalid version string")
+ }
+ }
+
+ var buildNum uint64 = 0
+ if len(verArray) > 3 {
+ buildNum, err = strconv.ParseUint(verArray[3], 10, 32)
+ if err != nil {
+ return nil, util.NewNewtError("Invalid version string")
+ }
+ }
+
+ u8b := make([]byte, 1)
+ u16b := make([]byte, 2)
+ u32b := make([]byte, 4)
+ data := make([]byte, 0)
+
+ u8b[0] = byte(major)
+ data = append(data, u8b...)
+
+ u8b[0] = byte(minor)
+ data = append(data, u8b...)
+
+ binary.BigEndian.PutUint16(u16b, uint16(revision))
+ data = append(data, u16b...)
+
+ binary.BigEndian.PutUint32(u32b, uint32(buildNum))
+ data = append(data, u32b...)
+
+ nmr.Data = data
+ nmr.Len = 8
+ nmr.Op = NMGR_OP_WRITE
+ }
+ return nmr, nil
+}
+
+func DecodeImageBootResponse(data []byte) (*ImageBoot, error) {
+ i := &ImageBoot{}
+
+ var idx int = 0
+ for len(data) >= 8 {
+ major := uint8(data[0])
+ minor := uint8(data[1])
+ revision := binary.BigEndian.Uint16(data[2:4])
+ buildNum := binary.BigEndian.Uint32(data[4:8])
+ data = data[8:]
+
+ versStr := ImageVersStr(major, minor, revision, buildNum)
+ switch idx {
+ case 0:
+ i.TestImage = versStr
+ case 1:
+ i.MainImage = versStr
+ case 2:
+ i.ActiveImage = versStr
+ default:
+ /* XXXX? */
+ }
+ idx++
+ }
+
+ return i, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/982154c4/newtmgr/protocol/imagelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist.go b/newtmgr/protocol/imagelist.go
index 843fdac..fcc22eb 100644
--- a/newtmgr/protocol/imagelist.go
+++ b/newtmgr/protocol/imagelist.go
@@ -30,6 +30,16 @@ func NewImageList() (*ImageList, error) {
return s, nil
}
+func ImageVersStr(major uint8, minor uint8, revision uint16, buildNum uint32) string {
+ if major == 0xff && minor == 0xff && revision == 0xffff &&
+ buildNum == 0xffffffff {
+ return "Not set"
+ } else {
+ versStr := fmt.Sprintf("%d.%d.%d.%d", major, minor, revision, buildNum)
+ return versStr
+ }
+}
+
func (i *ImageList) EncodeWriteRequest() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
@@ -55,9 +65,9 @@ func DecodeImageListResponse(data []byte) (*ImageList, error) {
buildNum := binary.BigEndian.Uint32(data[4:8])
data = data[8:]
- versStr := fmt.Sprintf("%d.%d.%d.%d", major, minor, revision, buildNum)
+ versStr := ImageVersStr(major, minor, revision, buildNum)
i.Images = append(i.Images, versStr)
- }
+ }
return i, nil
}
[2/2] incubator-mynewt-newt git commit: Mods to satisfy gofmt.
Posted by ma...@apache.org.
Mods to satisfy gofmt.
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/5e87e8f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/5e87e8f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/5e87e8f6
Branch: refs/heads/master
Commit: 5e87e8f6fa2dd6e76b3e4a06ca8396d0cd732502
Parents: 982154c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Jan 12 14:59:49 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Jan 12 14:59:49 2016 -0800
----------------------------------------------------------------------
newtmgr/protocol/cmdrunner.go | 2 +-
newtmgr/protocol/imageupload.go | 4 ++--
newtmgr/protocol/nmgr.go | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5e87e8f6/newtmgr/protocol/cmdrunner.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/cmdrunner.go b/newtmgr/protocol/cmdrunner.go
index 8b04589..05b604a 100644
--- a/newtmgr/protocol/cmdrunner.go
+++ b/newtmgr/protocol/cmdrunner.go
@@ -25,7 +25,7 @@ type CmdRunner struct {
conn transport.Conn
}
-func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
+func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
for {
pkt, err := cr.conn.ReadPacket()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5e87e8f6/newtmgr/protocol/imageupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
index 0db667e..e85bdf2 100644
--- a/newtmgr/protocol/imageupload.go
+++ b/newtmgr/protocol/imageupload.go
@@ -20,8 +20,8 @@ import (
)
type ImageUpload struct {
- Offset uint32
- Data []byte
+ Offset uint32
+ Data []byte
}
func NewImageUpload() (*ImageUpload, error) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5e87e8f6/newtmgr/protocol/nmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/nmgr.go b/newtmgr/protocol/nmgr.go
index 3958d83..731b86b 100644
--- a/newtmgr/protocol/nmgr.go
+++ b/newtmgr/protocol/nmgr.go
@@ -40,8 +40,8 @@ const (
)
const (
- NMGR_GROUP_ID_DEFAULT = 0
- NMGR_GROUP_ID_IMAGE = 1
+ NMGR_GROUP_ID_DEFAULT = 0
+ NMGR_GROUP_ID_IMAGE = 1
)
func NewNmgrReq() (*NmgrReq, error) {