Skip to content

Commit 75b52b0

Browse files
committed
backend/bitbox02: automatically upgrade ble fw for testing
1 parent b36e9ef commit 75b52b0

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Binary file not shown.

backend/devices/bitbox02/bluetooth.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package bitbox02
16+
17+
import (
18+
"crypto/sha256"
19+
_ "embed" // Needed for the go:embed directive below.
20+
)
21+
22+
//go:embed assets/da14531-firmware.bin
23+
var bluetoothFirmware []byte
24+
25+
func bundledBluetoothFirmwareHash() []byte {
26+
hash := sha256.Sum256(bluetoothFirmware)
27+
return hash[:]
28+
}

backend/devices/bitbox02/device.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package bitbox02
1818

1919
import (
20+
"encoding/hex"
21+
2022
deviceevent "github.com/BitBoxSwiss/bitbox-wallet-app/backend/devices/device/event"
2123
keystoreInterface "github.com/BitBoxSwiss/bitbox-wallet-app/backend/keystore"
2224
"github.com/BitBoxSwiss/bitbox-wallet-app/util/logging"
@@ -90,6 +92,27 @@ func NewDevice(
9092
Subject: string(deviceevent.EventKeystoreAvailable),
9193
Action: action.Replace,
9294
})
95+
96+
}
97+
}
98+
99+
// Temporary automatic Bluetooth firmware upgrade during the testing phase. We prompt an
100+
// upgrade every time if the bundled firmware does not match the actual firmware on the
101+
// device. TODO: remove before production release.
102+
if ev == firmware.EventStatusChanged && device.SupportsBluetooth() {
103+
switch device.Device.Status() {
104+
case firmware.StatusInitialized, firmware.StatusUninitialized:
105+
info, err := device.DeviceInfo()
106+
if err != nil {
107+
device.log.WithError(err).Error("DeviceInfo")
108+
return
109+
}
110+
if info.Bluetooth != nil &&
111+
info.Bluetooth.FirmwareHash != hex.EncodeToString(bundledBluetoothFirmwareHash()) {
112+
if err := device.BluetoothUpgrade(bluetoothFirmware); err != nil {
113+
device.log.WithError(err).Error("BluetoothUpgrade")
114+
}
115+
}
93116
}
94117
}
95118
})

0 commit comments

Comments
 (0)