You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ml...@apache.org on 2019/03/23 01:53:57 UTC

[mynewt-newt] 01/01: Enable production of hex mfgimg files.

This is an automated email from the ASF dual-hosted git repository.

mlaz pushed a commit to branch hex_img
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 3de0e60b4aca281978e296ad48f834eded633125
Author: Miguel Azevedo <mi...@gmail.com>
AuthorDate: Sat Mar 23 01:48:48 2019 +0000

    Enable production of hex mfgimg files.
---
 artifact/manifest/mfg_manifest.go |  1 +
 artifact/mfg/mfg.go               |  3 ++-
 newt/mfg/emit.go                  | 37 ++++++++++++++++++++++++++-----------
 newt/mfg/paths.go                 |  6 +++++-
 4 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/artifact/manifest/mfg_manifest.go b/artifact/manifest/mfg_manifest.go
index b7f00e8..da2d5e9 100644
--- a/artifact/manifest/mfg_manifest.go
+++ b/artifact/manifest/mfg_manifest.go
@@ -44,6 +44,7 @@ type MfgManifest struct {
 	Version    string            `json:"version"`
 	Device     int               `json:"device"`
 	BinPath    string            `json:"bin_path"`
+	HexPath    string            `json:"hex_path"`
 	Bsp        string            `json:"bsp"`
 	Signatures []MfgManifestSig  `json:"signatures,omitempty"`
 	FlashAreas []flash.FlashArea `json:"flash_map"`
diff --git a/artifact/mfg/mfg.go b/artifact/mfg/mfg.go
index 3e29523..d3f5f93 100644
--- a/artifact/mfg/mfg.go
+++ b/artifact/mfg/mfg.go
@@ -6,7 +6,8 @@ import (
 	"mynewt.apache.org/newt/util"
 )
 
-const MFG_IMG_FILENAME = "mfgimg.bin"
+const MFG_BIN_IMG_FILENAME = "mfgimg.bin"
+const MFG_HEX_IMG_FILENAME = "mfgimg.hex"
 const MANIFEST_FILENAME = "manifest.json"
 
 type Mfg struct {
diff --git a/newt/mfg/emit.go b/newt/mfg/emit.go
index 91d18eb..85c1660 100644
--- a/newt/mfg/emit.go
+++ b/newt/mfg/emit.go
@@ -35,6 +35,7 @@ import (
 	"mynewt.apache.org/newt/newt/builder"
 	"mynewt.apache.org/newt/newt/flashmap"
 	"mynewt.apache.org/newt/newt/target"
+	"mynewt.apache.org/newt/newt/toolchain"
 	"mynewt.apache.org/newt/util"
 )
 
@@ -80,10 +81,11 @@ type MfgEmitter struct {
 	Meta    *MfgEmitMeta
 	Keys    []sec.SignKey
 
-	Mfg      mfg.Mfg
-	Device   int
-	FlashMap flashmap.FlashMap
-	BspName  string
+	Mfg          mfg.Mfg
+	Device       int
+	FlashMap     flashmap.FlashMap
+	BspName      string
+	CompilerName string
 }
 
 // Calculates the source path of a target's binary.  Boot loader targets use
@@ -150,12 +152,13 @@ func NewMfgEmitter(mb MfgBuilder, name string, ver image.ImageVersion,
 	device int, keys []sec.SignKey) (MfgEmitter, error) {
 
 	me := MfgEmitter{
-		Name:     name,
-		Ver:      ver,
-		Device:   device,
-		Keys:     keys,
-		FlashMap: mb.Bsp.FlashMap,
-		BspName:  mb.Bsp.FullName(),
+		Name:         name,
+		Ver:          ver,
+		Device:       device,
+		Keys:         keys,
+		FlashMap:     mb.Bsp.FlashMap,
+		BspName:      mb.Bsp.FullName(),
+		CompilerName: mb.Bsp.CompilerName,
 	}
 
 	m, err := mb.Build()
@@ -285,7 +288,8 @@ func (me *MfgEmitter) emitManifest() ([]byte, error) {
 		MfgHash:    misc.HashString(hashBytes),
 		Version:    me.Ver.String(),
 		Device:     me.Device,
-		BinPath:    mfg.MFG_IMG_FILENAME,
+		BinPath:    mfg.MFG_BIN_IMG_FILENAME,
+		HexPath:    mfg.MFG_HEX_IMG_FILENAME,
 		Signatures: sigs,
 		FlashAreas: me.FlashMap.SortedAreas(),
 		Bsp:        me.BspName,
@@ -355,6 +359,16 @@ func (me *MfgEmitter) Emit() ([]string, []string, error) {
 		return nil, nil, err
 	}
 
+	// Write mfgimg.hex
+	c, err := toolchain.NewCompiler(me.CompilerName, "", "optimized")
+	if err != nil {
+		return nil, nil, err
+	}
+	hexPath := MfgHexPath(me.Name)
+	if err := c.ConvertBinToHex(binPath, hexPath, len(mbin)); err != nil {
+		return nil, nil, err
+	}
+
 	// Write manifest.
 	manifest, err := me.emitManifest()
 	if err != nil {
@@ -370,6 +384,7 @@ func (me *MfgEmitter) Emit() ([]string, []string, error) {
 	srcPaths := []string{}
 	dstPaths := []string{
 		binPath,
+		hexPath,
 		manifestPath,
 	}
 	for _, entry := range cpEntries {
diff --git a/newt/mfg/paths.go b/newt/mfg/paths.go
index 8c70b94..1d4ede9 100644
--- a/newt/mfg/paths.go
+++ b/newt/mfg/paths.go
@@ -34,7 +34,11 @@ func MfgBinDir(mfgPkgName string) string {
 }
 
 func MfgBinPath(mfgPkgName string) string {
-	return MfgBinDir(mfgPkgName) + "/" + mfg.MFG_IMG_FILENAME
+	return MfgBinDir(mfgPkgName) + "/" + mfg.MFG_BIN_IMG_FILENAME
+}
+
+func MfgHexPath(mfgPkgName string) string {
+	return MfgBinDir(mfgPkgName) + "/" + mfg.MFG_HEX_IMG_FILENAME
 }
 
 func MfgManifestPath(mfgPkgName string) string {