flash: support flashing boards using Mass Storage Device (MSD) operation for uf2 and daplink bootloaders
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
02facb8568
коммит
ba49148644
9 изменённых файлов: 122 добавлений и 37 удалений
56
main.go
56
main.go
|
@ -431,6 +431,26 @@ func Flash(pkgName, target, port string, config *BuildConfig) error {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this flashing method copies the binary data to a Mass Storage Device (msd)
|
||||||
|
if spec.FlashMethod == "msd" {
|
||||||
|
switch fileExt {
|
||||||
|
case ".uf2":
|
||||||
|
err := flashUF2UsingMSD(spec.FlashVolume, tmppath)
|
||||||
|
if err != nil {
|
||||||
|
return &commandError{"failed to flash", tmppath, err}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case ".hex":
|
||||||
|
err := flashHexUsingMSD(spec.FlashVolume, tmppath)
|
||||||
|
if err != nil {
|
||||||
|
return &commandError{"failed to flash", tmppath, err}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return errors.New("mass storage device flashing currently only supports uf2 and hex")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create the command.
|
// Create the command.
|
||||||
flashCmd := spec.Flasher
|
flashCmd := spec.Flasher
|
||||||
fileToken := "{" + fileExt[1:] + "}"
|
fileToken := "{" + fileExt[1:] + "}"
|
||||||
|
@ -574,6 +594,42 @@ func touchSerialPortAt1200bps(port string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flashUF2UsingMSD(volume, tmppath string) error {
|
||||||
|
// find standard UF2 info path
|
||||||
|
infoPath := "/media/*/" + volume + "/INFO_UF2.TXT"
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT"
|
||||||
|
}
|
||||||
|
|
||||||
|
d, err := filepath.Glob(infoPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d == nil {
|
||||||
|
return errors.New("unable to locate UF2 device:" + volume)
|
||||||
|
}
|
||||||
|
|
||||||
|
return moveFile(tmppath, filepath.Dir(d[0])+"/flash.uf2")
|
||||||
|
}
|
||||||
|
|
||||||
|
func flashHexUsingMSD(volume, tmppath string) error {
|
||||||
|
// find expected volume path
|
||||||
|
destPath := "/media/*/" + volume
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
destPath = "/Volumes/" + volume
|
||||||
|
}
|
||||||
|
|
||||||
|
d, err := filepath.Glob(destPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d == nil {
|
||||||
|
return errors.New("unable to locate device:" + volume)
|
||||||
|
}
|
||||||
|
|
||||||
|
return moveFile(tmppath, d[0]+"/flash.hex")
|
||||||
|
}
|
||||||
|
|
||||||
// parseSize converts a human-readable size (with k/m/g suffix) into a plain
|
// parseSize converts a human-readable size (with k/m/g suffix) into a plain
|
||||||
// number.
|
// number.
|
||||||
func parseSize(s string) (int64, error) {
|
func parseSize(s string) (int64, error) {
|
||||||
|
|
69
target.go
69
target.go
|
@ -26,27 +26,29 @@ var TINYGOROOT string
|
||||||
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html
|
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html
|
||||||
// https://github.com/shepmaster/rust-arduino-blink-led-no-core-with-cargo/blob/master/blink/arduino.json
|
// https://github.com/shepmaster/rust-arduino-blink-led-no-core-with-cargo/blob/master/blink/arduino.json
|
||||||
type TargetSpec struct {
|
type TargetSpec struct {
|
||||||
Inherits []string `json:"inherits"`
|
Inherits []string `json:"inherits"`
|
||||||
Triple string `json:"llvm-target"`
|
Triple string `json:"llvm-target"`
|
||||||
CPU string `json:"cpu"`
|
CPU string `json:"cpu"`
|
||||||
Features []string `json:"features"`
|
Features []string `json:"features"`
|
||||||
GOOS string `json:"goos"`
|
GOOS string `json:"goos"`
|
||||||
GOARCH string `json:"goarch"`
|
GOARCH string `json:"goarch"`
|
||||||
BuildTags []string `json:"build-tags"`
|
BuildTags []string `json:"build-tags"`
|
||||||
GC string `json:"gc"`
|
GC string `json:"gc"`
|
||||||
Scheduler string `json:"scheduler"`
|
Scheduler string `json:"scheduler"`
|
||||||
Compiler string `json:"compiler"`
|
Compiler string `json:"compiler"`
|
||||||
Linker string `json:"linker"`
|
Linker string `json:"linker"`
|
||||||
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
||||||
CFlags []string `json:"cflags"`
|
CFlags []string `json:"cflags"`
|
||||||
LDFlags []string `json:"ldflags"`
|
LDFlags []string `json:"ldflags"`
|
||||||
ExtraFiles []string `json:"extra-files"`
|
ExtraFiles []string `json:"extra-files"`
|
||||||
Emulator []string `json:"emulator"`
|
Emulator []string `json:"emulator"`
|
||||||
Flasher string `json:"flash"`
|
Flasher string `json:"flash"`
|
||||||
OCDDaemon []string `json:"ocd-daemon"`
|
OCDDaemon []string `json:"ocd-daemon"`
|
||||||
GDB string `json:"gdb"`
|
GDB string `json:"gdb"`
|
||||||
GDBCmds []string `json:"gdb-initial-cmds"`
|
GDBCmds []string `json:"gdb-initial-cmds"`
|
||||||
PortReset string `json:"flash-1200-bps-reset"`
|
PortReset string `json:"flash-1200-bps-reset"`
|
||||||
|
FlashMethod string `json:"flash-method"`
|
||||||
|
FlashVolume string `json:"flash-msd-volume-name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyProperties copies all properties that are set in spec2 into itself.
|
// copyProperties copies all properties that are set in spec2 into itself.
|
||||||
|
@ -104,6 +106,12 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
|
||||||
if spec2.PortReset != "" {
|
if spec2.PortReset != "" {
|
||||||
spec.PortReset = spec2.PortReset
|
spec.PortReset = spec2.PortReset
|
||||||
}
|
}
|
||||||
|
if spec2.FlashMethod != "" {
|
||||||
|
spec.FlashMethod = spec2.FlashMethod
|
||||||
|
}
|
||||||
|
if spec2.FlashVolume != "" {
|
||||||
|
spec.FlashVolume = spec2.FlashVolume
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load reads a target specification from the JSON in the given io.Reader. It
|
// load reads a target specification from the JSON in the given io.Reader. It
|
||||||
|
@ -233,15 +241,16 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
// No target spec available. Use the default one, useful on most systems
|
// No target spec available. Use the default one, useful on most systems
|
||||||
// with a regular OS.
|
// with a regular OS.
|
||||||
spec := TargetSpec{
|
spec := TargetSpec{
|
||||||
Triple: triple,
|
Triple: triple,
|
||||||
GOOS: goos,
|
GOOS: goos,
|
||||||
GOARCH: goarch,
|
GOARCH: goarch,
|
||||||
BuildTags: []string{goos, goarch},
|
BuildTags: []string{goos, goarch},
|
||||||
Compiler: "clang",
|
Compiler: "clang",
|
||||||
Linker: "cc",
|
Linker: "cc",
|
||||||
GDB: "gdb",
|
GDB: "gdb",
|
||||||
GDBCmds: []string{"run"},
|
GDBCmds: []string{"run"},
|
||||||
PortReset: "false",
|
PortReset: "false",
|
||||||
|
FlashMethod: "command",
|
||||||
}
|
}
|
||||||
if goos == "darwin" {
|
if goos == "darwin" {
|
||||||
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")
|
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"inherits": ["atsamd21g18a"],
|
"inherits": ["atsamd21g18a"],
|
||||||
"build-tags": ["sam", "atsamd21g18a", "circuitplay_express"],
|
"build-tags": ["sam", "atsamd21g18a", "circuitplay_express"],
|
||||||
"flash": "uf2conv.py {bin}"
|
"flash": "{uf2}",
|
||||||
|
"flash-1200-bps-reset": "true",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "CPLAYBOOT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"inherits": ["atsamd21g18a"],
|
"inherits": ["atsamd21g18a"],
|
||||||
"build-tags": ["sam", "atsamd21g18a", "feather_m0"],
|
"build-tags": ["sam", "atsamd21g18a", "feather_m0"],
|
||||||
"flash": "bossac -d -i -e -w -v -R --port={port} --offset=0x2000 {hex}"
|
"flash": "{uf2}",
|
||||||
|
"flash-1200-bps-reset": "true",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "FEATHERBOOT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,8 @@
|
||||||
"build-tags": ["hifive1b"],
|
"build-tags": ["hifive1b"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"-T", "targets/hifive1b.ld"
|
"-T", "targets/hifive1b.ld"
|
||||||
]
|
],
|
||||||
|
"flash": "{hex}",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "HiFive"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"inherits": ["atsamd21g18a"],
|
"inherits": ["atsamd21g18a"],
|
||||||
"build-tags": ["sam", "atsamd21g18a", "itsybitsy_m0"],
|
"build-tags": ["sam", "atsamd21g18a", "itsybitsy_m0"],
|
||||||
"flash": "bossac -d -i -e -w -v -R --port={port} --offset=0x2000 {hex}"
|
"flash": "{uf2}",
|
||||||
|
"flash-1200-bps-reset": "true",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "ITSYBOOT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"inherits": ["atsamd51g19a"],
|
"inherits": ["atsamd51g19a"],
|
||||||
"build-tags": ["sam", "atsamd51g19a", "itsybitsy_m4"],
|
"build-tags": ["sam", "atsamd51g19a", "itsybitsy_m4"],
|
||||||
"flash": "bossac -d -i -e -w -v -R --offset=0x4000 {bin}"
|
"flash": "{uf2}",
|
||||||
|
"flash-1200-bps-reset": "true",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "ITSYM4BOOT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,7 @@
|
||||||
"build-tags": ["microbit"],
|
"build-tags": ["microbit"],
|
||||||
"flash": "openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg -c 'program {hex} reset exit'",
|
"flash": "openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg -c 'program {hex} reset exit'",
|
||||||
"ocd-daemon": ["openocd", "-f", "interface/cmsis-dap.cfg", "-f", "target/nrf51.cfg"],
|
"ocd-daemon": ["openocd", "-f", "interface/cmsis-dap.cfg", "-f", "target/nrf51.cfg"],
|
||||||
"gdb-initial-cmds": ["target remote :3333", "monitor halt", "load", "monitor reset", "c"]
|
"gdb-initial-cmds": ["target remote :3333", "monitor halt", "load", "monitor reset", "c"],
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "MICROBIT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"inherits": ["atsamd21e18a"],
|
"inherits": ["atsamd21e18a"],
|
||||||
"build-tags": ["sam", "atsamd21e18a", "trinket_m0"],
|
"build-tags": ["sam", "atsamd21e18a", "trinket_m0"],
|
||||||
"flash": "bossac -d -i -e -w -v -R --port={port} --offset=0x2000 {hex}"
|
"flash": "{uf2}",
|
||||||
|
"flash-1200-bps-reset": "true",
|
||||||
|
"flash-method": "msd",
|
||||||
|
"flash-msd-volume-name": "TRINKETBOOT"
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче