Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/fwsign/fwsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ const (
TargetESP uint8 = 3
TargetBridge uint8 = 6 // the Wi-Fi bridge's firmware (4 and 5, ca and tls, are not signed)
TargetGW2 uint8 = 7 // gateware image 2, the sensor emulation image (gateware v54+)
// 8 is a Wi-Fi bridge's identity certificate, never an update.
TargetXIP uint8 = 9 // code the pod runs from its W25Q (blob-xip.bin, firmware 4.0.2+)
)

var targetNames = []string{"firmware", "gw0", "gw1", "esp", "", "", "bridge", "gw2"}
var targetNames = []string{"firmware", "gw0", "gw1", "esp", "", "", "bridge", "gw2", "", "xip"}

// TargetByName maps "firmware", "gw0", "gw1", "esp", "bridge", "gw2" to its number.
// TargetByName maps "firmware", "gw0", "gw1", "esp", "bridge", "gw2", "xip" to its number.
func TargetByName(name string) (uint8, bool) {
for i, n := range targetNames {
if n != "" && n == name {
Expand Down
6 changes: 6 additions & 0 deletions internal/fwsign/fwsign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func TestTargetNames(t *testing.T) {
t.Fatalf("bridge: %d %v", n, ok)
}
// 4 and 5 (ca, tls) are not signed targets: no name, and "" maps to nothing.
if n, ok := TargetByName("xip"); !ok || TargetXIP != 9 || n != TargetXIP || TargetName(9) != "xip" {
t.Errorf("xip: TargetByName = %d, %v; TargetName(9) = %q", n, ok, TargetName(9))
}
if _, ok := TargetByName(""); ok {
t.Error("the unused target numbers have names")
}
if n, ok := TargetByName("gw2"); !ok || TargetGW2 != 7 || n != TargetGW2 || TargetName(7) != "gw2" {
t.Fatalf("gw2: %d %v", n, ok)
}
Expand Down