github.com/google/trillian-examples@v0.0.0-20240520080811-0d40d35cef0e/binary_transparency/firmware/cmd/flash_tool/flash_tool.go (about) 1 // Copyright 2020 Google LLC. All Rights Reserved. 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 // flash_tool is a util to flash firmware update packages created by the publisher tool onto devices. 16 // 17 // Currently, the only device is a dummy device, which simply sorts the firmware+metadata on local disk. 18 // 19 // Usage: 20 // 21 // go run ./cmd/flash_tool/ --logtostderr --dummy_storage_dir=/path/to/dir --update_file=/path/to/update.json 22 // 23 // The first time you use this tool there will be no prior firmware metadata 24 // stored on the device and the tool will fail. In this case, use the --force 25 // flag to apply the update anyway thereby creating the metadata. 26 // Subsequent invocations should then work without needing the --force flag. 27 package main 28 29 import ( 30 "context" 31 "flag" 32 33 "github.com/golang/glog" 34 "github.com/google/trillian-examples/binary_transparency/firmware/cmd/flash_tool/impl" 35 "github.com/google/trillian-examples/binary_transparency/firmware/internal/crypto" 36 "golang.org/x/mod/sumdb/note" 37 ) 38 39 var ( 40 deviceID = flag.String("device", "", "One of [dummy, armory]") 41 logURL = flag.String("log_url", "http://localhost:8000", "Base URL of the log HTTP API") 42 mapURL = flag.String("map_url", "", "Base URL of the map HTTP API. Map checks are not performed if this is absent.") 43 witnessURL = flag.String("witness_url", "", "Base URL of the Witness, or empty if no witness checks needed") 44 updateFile = flag.String("update_file", "", "File path to read the update package from") 45 force = flag.Bool("force", false, "Ignore errors and force update") 46 deviceStorage = flag.String("device_storage", "", "Storage description string for selected device") 47 ) 48 49 func main() { 50 flag.Parse() 51 52 v, err := note.NewVerifier(crypto.TestFTPersonalityPub) 53 if err != nil { 54 glog.Exitf("Failed to create CP verifier: %q", err) 55 } 56 57 if err := impl.Main(context.Background(), impl.FlashOpts{ 58 DeviceID: *deviceID, 59 LogURL: *logURL, 60 LogSigVerifier: v, 61 MapURL: *mapURL, 62 WitnessURL: *witnessURL, 63 UpdateFile: *updateFile, 64 Force: *force, 65 DeviceStorage: *deviceStorage, 66 }); err != nil { 67 glog.Exit(err.Error()) 68 } 69 }