Skip to content

Commit

Permalink
Firmware bins from CAS
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Oct 31, 2023
1 parent 3802c9e commit eefcf9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
22 changes: 3 additions & 19 deletions release/firmware/update/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
"sync"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -66,25 +65,10 @@ type FetcherOpts struct {

// BinaryPath returns the relative path within a bucket for the binary referenced by the manifest.
func BinaryPath(fr ftlog.FirmwareRelease) (string, error) {
dir := ""
file := ""
switch fr.Component {
case ftlog.ComponentApplet:
dir = "trusted-applet"
file = "trusted_applet.elf"
case ftlog.ComponentBoot:
dir = "boot"
file = "armored-witness-boot.imx"
case ftlog.ComponentOS:
dir = "trusted-os"
file = "trusted_os.elf"
case ftlog.ComponentRecovery:
dir = "recovery"
file = "armory-ums.imx"
default:
return "", fmt.Errorf("unrecognised component %q", fr.Component)
if len(fr.FirmwareDigestSha256) == 0 {
return "", errors.New("firmware digest unset")
}
return url.JoinPath(dir, fr.GitTagName.String(), file)
return fmt.Sprintf("%064x", fr.FirmwareDigestSha256), nil
}

// NewFetcher returns an implementation of a Remote that uses the given log client to
Expand Down
40 changes: 23 additions & 17 deletions release/firmware/update/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package update
import (
"context"
"encoding/json"
"fmt"
"testing"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -49,29 +50,34 @@ const (

func TestBinPath(t *testing.T) {
for _, test := range []struct {
r ftlog.FirmwareRelease
want string
name string
r ftlog.FirmwareRelease
want string
wantErr bool
}{
{
r: ftlog.FirmwareRelease{Component: ftlog.ComponentOS, GitTagName: *semver.New("1.0.1")},
want: "trusted-os/1.0.1/trusted_os.elf",
name: "Path From Firmware Hash",
r: ftlog.FirmwareRelease{FirmwareDigestSha256: []byte{0x12, 0x34, 0x56, 0x78}},
want: fmt.Sprintf("%064s", "12345678"),
}, {
r: ftlog.FirmwareRelease{Component: ftlog.ComponentOS, GitTagName: *semver.New("1.9.1")},
want: "trusted-os/1.9.1/trusted_os.elf",
name: "Other fields ignored",
r: ftlog.FirmwareRelease{Component: ftlog.ComponentOS, GitTagName: *semver.New("1.9.1"), FirmwareDigestSha256: []byte{0x12, 0x34, 0x56, 0x78}},
want: fmt.Sprintf("%064s", "12345678"),
}, {
r: ftlog.FirmwareRelease{Component: ftlog.ComponentApplet, GitTagName: *semver.New("7.7.7")},
want: "trusted-applet/7.7.7/trusted_applet.elf",
}, {
r: ftlog.FirmwareRelease{Component: ftlog.ComponentBoot, GitTagName: *semver.New("0.0.0")},
want: "boot/0.0.0/armored-witness-boot.imx",
}, {
r: ftlog.FirmwareRelease{Component: ftlog.ComponentRecovery, GitTagName: *semver.New("2.0.0")},
want: "recovery/2.0.0/armory-ums.imx",
name: "Digest unset is an error",
r: ftlog.FirmwareRelease{Component: ftlog.ComponentApplet, GitTagName: *semver.New("7.7.7")},
wantErr: true,
},
} {
if got, _ := BinaryPath(test.r); got != test.want {
t.Errorf("Got %q want %q", got, test.want)
}
t.Run(test.name, func(t *testing.T) {
got, err := BinaryPath(test.r)
if gotErr := err != nil; gotErr != test.wantErr {
t.Fatalf("got err %v, want err %v", err, test.wantErr)
}
if got != test.want {
t.Fatalf("Got %q want %q", got, test.want)
}
})
}
}

Expand Down

0 comments on commit eefcf9d

Please sign in to comment.