Skip to content

Commit

Permalink
Merge pull request #10 from thinnect/append_lic
Browse files Browse the repository at this point in the history
Added arguments to usersiggen, binary, readme.
  • Loading branch information
kobilozor authored Nov 11, 2020
2 parents b9597ae + 9574e2b commit 653ea57
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
16 changes: 16 additions & 0 deletions usersiggen/bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Intergation Documentation

## Introduction
This document provides knowhow how to load the license into the MCU to use beatstack.


## Requirements
* Latest eusiggen (binaries available) : https://github.com/thinnect/euisiggen
* Valid licence file

## Append licence file to signature file
```usersiggen --type license --sigfile signature.bin --licfile license.bin --out signature+license.bin```


## Install sig to MCU using thinnect platform configuration
```PROGRAM_SIGDATA=filename make ARCHITECTURE install-sig DEVICEID```
Binary file added usersiggen/bin/usersiggen
Binary file not shown.
38 changes: 27 additions & 11 deletions usersiggen/usersiggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "github.com/joaojeronimo/go-crc16"
import "github.com/satori/go.uuid"

var g_version_major uint8 = 3
var g_version_minor uint8 = 2
var g_version_minor uint8 = 3
var g_version_patch uint8 = 0

const SIGNATURE_TYPE_EUI64 = 0 // EUI64 is the IEEE Extended Unique Identifier
Expand Down Expand Up @@ -604,7 +604,7 @@ func parseLicenseFile(infile string, t time.Time) ([]byte, error) {
}

func appendFile(outfile string, data []byte) error {
f, err := os.OpenFile(outfile, os.O_APPEND|os.O_WRONLY, 0640)
f, err := os.OpenFile(outfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0640)
if err != nil {
fmt.Printf("ERROR opening output file: %s\n", err)
return err
Expand Down Expand Up @@ -642,6 +642,7 @@ func main() {
Sigdir string `long:"sigdir" default:"sigdata" description:"Where to store EUI_XXXXXXXXXXXXXXXX.bin files."`

Licfile string `long:"licfile" description:"Generated license file."`
Sigfile string `long:"sigfile" description:"Signature file to append license to."`

Timestamp int64 `long:"timestamp" description:"Use the specified timestamp."`

Expand Down Expand Up @@ -691,19 +692,34 @@ func main() {
}

if opts.Type == "license" {
var licdata []byte
if _, err := os.Stat(opts.Output); os.IsNotExist(err) {
fmt.Printf("ERROR initial signature file %s not found!", opts.Output)
if _, err := os.Stat(opts.Sigfile); os.IsNotExist(err) {
fmt.Printf("ERROR initial signature file %s not found!\n", opts.Sigfile)
os.Exit(1)
}
if len(opts.Licfile) != 0 {
licdata, err = parseLicenseFile(opts.Licfile, timestamp)
if err != nil {
fmt.Printf("ERROR parsing license file: %s\n", err)
os.Exit(1)
}

if _, err := os.Stat(opts.Licfile); os.IsNotExist(err) {
fmt.Printf("ERROR initial license file %s not found!\n", opts.Licfile)
os.Exit(1)
}

if _, err := os.Stat(opts.Output); os.IsExist(err) {
fmt.Printf("ERROR output file %s already exists.\n", opts.Output)
os.Exit(1)
}

licdata, err := parseLicenseFile(opts.Licfile, timestamp)
if err != nil {
fmt.Printf("ERROR parsing license file: %s\n", err)
os.Exit(1)
}

sigfiledata, err := ioutil.ReadFile(opts.Sigfile)
if err != nil {
fmt.Printf("ERROR reading signature file: %s\n", err)
os.Exit(1)
}

licdata = append(sigfiledata, licdata...)
err = appendFile(opts.Output, licdata)
if err != nil {
fmt.Printf("ERROR appending license data to file: %s\n", err)
Expand Down

0 comments on commit 653ea57

Please sign in to comment.