You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2019/04/16 12:32:50 UTC
[mynewt-newt] branch master updated: Allow to autogenerate image
version based on elf timestamp
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new 01978ab Allow to autogenerate image version based on elf timestamp
01978ab is described below
commit 01978abb90d0e498fae29cfaf6b8d8644b712d08
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Wed Apr 10 12:06:54 2019 +0200
Allow to autogenerate image version based on elf timestamp
This allows to specify version of image as "timestamp" which requests
newt to generate image version based on last modification time of
application .elf file, for example:
2019-04-10 16:02:10 will be converted to version 19.4.10.160210
This may be useful for debugging so every time application is rebuilt it
can have new image version when flashed so it's easy to check whether
proper/new version of application is currently running.
---
newt/cli/image_cmds.go | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/newt/cli/image_cmds.go b/newt/cli/image_cmds.go
index 7e5ded3..0632a6c 100644
--- a/newt/cli/image_cmds.go
+++ b/newt/cli/image_cmds.go
@@ -20,6 +20,7 @@
package cli
import (
+ "os"
"strconv"
"github.com/spf13/cobra"
@@ -68,6 +69,10 @@ func parseKeyArgs(args []string) ([]sec.SignKey, uint8, error) {
}
func createImageRunCmd(cmd *cobra.Command, args []string) {
+ var verAsTimestamp bool
+ var ver image.ImageVersion
+ var err error
+
if len(args) < 2 {
NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
}
@@ -88,9 +93,14 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Invalid target name: "+targetName))
}
- ver, err := image.ParseVersion(args[1])
- if err != nil {
- NewtUsage(cmd, err)
+ if args[1] == "timestamp" {
+ verAsTimestamp = true
+ } else {
+ verAsTimestamp = false
+ ver, err = image.ParseVersion(args[1])
+ if err != nil {
+ NewtUsage(cmd, err)
+ }
}
b, err := builder.NewTargetBuilder(t)
@@ -107,6 +117,19 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(nil, err)
}
+ if verAsTimestamp {
+ stat, err := os.Stat(b.AppBuilder.AppElfPath())
+ if err != nil {
+ NewtUsage(nil, err)
+ }
+
+ ver.Major = uint8(stat.ModTime().Year() % 1000)
+ ver.Minor = uint8(stat.ModTime().Month())
+ ver.Rev = uint16(stat.ModTime().Day())
+ ver.BuildNum = uint32(stat.ModTime().Hour() * 10000 +
+ stat.ModTime().Minute() * 100 + stat.ModTime().Second())
+ }
+
if useV1 {
err = imgprod.ProduceAllV1(b, ver, keys, encKeyFilename)
} else {