@@ -22,13 +22,14 @@ import (
22
22
"fmt"
23
23
"io/ioutil"
24
24
"os"
25
+ "strings"
25
26
26
27
inota "github.com/arduino/arduino-cloud-cli/internal/ota"
27
28
)
28
29
29
30
var (
30
- arduinoVendorID = "2341"
31
- fqbnToPID = map [string ]string {
31
+ arduinoVendorID = "2341"
32
+ arduinoFqbnToPID = map [string ]string {
32
33
"arduino:samd:nano_33_iot" : "8057" ,
33
34
"arduino:samd:mkr1000" : "804E" ,
34
35
"arduino:samd:mkrgsm1400" : "8052" ,
@@ -39,13 +40,31 @@ var (
39
40
"arduino:mbed_nicla:nicla_vision" : "025F" ,
40
41
"arduino:mbed_opta:opta" : "0064" ,
41
42
}
43
+ esp32MagicNumberPart1 = "4553"
44
+ esp32MagicNumberPart2 = "5033"
42
45
)
43
46
44
47
// Generate takes a .bin file and generates a .ota file.
45
48
func Generate (binFile string , outFile string , fqbn string ) error {
46
- productID , ok := fqbnToPID [fqbn ]
47
- if ! ok {
48
- return errors .New ("fqbn not valid" )
49
+
50
+ // We are going to put a magic number in the ota .bin file, the fw will check the magic number once the binary is received
51
+ var magicNumberPart1 , magicNumberPart2 string
52
+
53
+ // The ota update is available for Arduino boards and ESP32 boards
54
+
55
+ // Esp32 boards have a wide range of vid and pid, we don't map all of them
56
+ // If the fqbn is the one of an ESP32 board, we force a default magic number that matches the same default expected on the fw side
57
+ if strings .HasPrefix (fqbn , "esp32" ) {
58
+ magicNumberPart1 = esp32MagicNumberPart1
59
+ magicNumberPart2 = esp32MagicNumberPart2
60
+ } else {
61
+ //For Arduino Boards we use vendorId and productID to form the magic number
62
+ magicNumberPart1 = arduinoVendorID
63
+ productID , ok := arduinoFqbnToPID [fqbn ]
64
+ if ! ok {
65
+ return errors .New ("fqbn not valid" )
66
+ }
67
+ magicNumberPart2 = productID
49
68
}
50
69
51
70
data , err := ioutil .ReadFile (binFile )
@@ -59,7 +78,7 @@ func Generate(binFile string, outFile string, fqbn string) error {
59
78
}
60
79
defer out .Close ()
61
80
62
- enc := inota .NewEncoder (out , arduinoVendorID , productID )
81
+ enc := inota .NewEncoder (out , magicNumberPart1 , magicNumberPart2 )
63
82
err = enc .Encode (data )
64
83
if err != nil {
65
84
return fmt .Errorf ("failed to encode binary file: %w" , err )
0 commit comments