main: add -programmer flag
This flag is overloaded. It can be used in two ways: * Choosing the flash method to use (openocd, msd, command). * Choosing the OpenOCD programmer name. For example, you can use one of these to use OpenOCD instead of the mass-storage device programmer: tinygo flash -target=microbit -programmer=openocd tinygo flash -target=microbit -programmer=cmsis-dap
Этот коммит содержится в:
родитель
c6255e4d0a
коммит
d2d78d3d0a
4 изменённых файлов: 60 добавлений и 37 удалений
|
@ -3,7 +3,9 @@
|
||||||
package compileopts
|
package compileopts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -152,6 +154,52 @@ func (c *Config) Debug() bool {
|
||||||
return c.Options.Debug
|
return c.Options.Debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Programmer returns the flash method and OpenOCD interface name given a
|
||||||
|
// particular configuration. It may either be all configured in the target JSON
|
||||||
|
// file or be modified using the -programmmer command-line option.
|
||||||
|
func (c *Config) Programmer() (method, openocdInterface string) {
|
||||||
|
switch c.Options.Programmer {
|
||||||
|
case "":
|
||||||
|
// No configuration supplied.
|
||||||
|
return c.Target.FlashMethod, c.Target.OpenOCDInterface
|
||||||
|
case "openocd", "msd", "command":
|
||||||
|
// The -programmer flag only specifies the flash method.
|
||||||
|
return c.Options.Programmer, c.Target.OpenOCDInterface
|
||||||
|
default:
|
||||||
|
// The -programmer flag specifies something else, assume it specifies
|
||||||
|
// the OpenOCD interface name.
|
||||||
|
return "openocd", c.Options.Programmer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenOCDConfiguration returns a list of command line arguments to OpenOCD.
|
||||||
|
// This list of command-line arguments is based on the various OpenOCD-related
|
||||||
|
// flags in the target specification.
|
||||||
|
func (c *Config) OpenOCDConfiguration() (args []string, err error) {
|
||||||
|
_, openocdInterface := c.Programmer()
|
||||||
|
if openocdInterface == "" {
|
||||||
|
return nil, errors.New("OpenOCD programmer not set")
|
||||||
|
}
|
||||||
|
if !regexp.MustCompile("^[\\p{L}0-9_-]+$").MatchString(openocdInterface) {
|
||||||
|
return nil, fmt.Errorf("OpenOCD programmer has an invalid name: %#v", openocdInterface)
|
||||||
|
}
|
||||||
|
if c.Target.OpenOCDTarget == "" {
|
||||||
|
return nil, errors.New("OpenOCD chip not set")
|
||||||
|
}
|
||||||
|
if !regexp.MustCompile("^[\\p{L}0-9_-]+$").MatchString(c.Target.OpenOCDTarget) {
|
||||||
|
return nil, fmt.Errorf("OpenOCD target has an invalid name: %#v", c.Target.OpenOCDTarget)
|
||||||
|
}
|
||||||
|
if c.Target.OpenOCDTransport != "" && c.Target.OpenOCDTransport != "swd" {
|
||||||
|
return nil, fmt.Errorf("unknown OpenOCD transport: %#v", c.Target.OpenOCDTransport)
|
||||||
|
}
|
||||||
|
args = []string{"-f", "interface/" + openocdInterface + ".cfg"}
|
||||||
|
if c.Target.OpenOCDTransport != "" {
|
||||||
|
args = append(args, "-c", "transport select "+c.Target.OpenOCDTransport)
|
||||||
|
}
|
||||||
|
args = append(args, "-f", "target/"+c.Target.OpenOCDTarget+".cfg")
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
type TestConfig struct {
|
type TestConfig struct {
|
||||||
CompileTestBinary bool
|
CompileTestBinary bool
|
||||||
// TODO: Filter the test functions to run, include verbose flag, etc
|
// TODO: Filter the test functions to run, include verbose flag, etc
|
||||||
|
|
|
@ -19,4 +19,5 @@ type Options struct {
|
||||||
WasmAbi string
|
WasmAbi string
|
||||||
HeapSize int64
|
HeapSize int64
|
||||||
TestConfig TestConfig
|
TestConfig TestConfig
|
||||||
|
Programmer string
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,9 @@ package compileopts
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -277,30 +275,3 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
}
|
}
|
||||||
return &spec, nil
|
return &spec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenOCDConfiguration returns a list of command line arguments to OpenOCD.
|
|
||||||
// This list of command-line arguments is based on the various OpenOCD-related
|
|
||||||
// flags in the target specification.
|
|
||||||
func (spec *TargetSpec) OpenOCDConfiguration() (args []string, err error) {
|
|
||||||
if spec.OpenOCDInterface == "" {
|
|
||||||
return nil, errors.New("OpenOCD programmer not set")
|
|
||||||
}
|
|
||||||
if !regexp.MustCompile("^[\\p{L}0-9_-]+$").MatchString(spec.OpenOCDInterface) {
|
|
||||||
return nil, fmt.Errorf("OpenOCD programmer has an invalid name: %#v", spec.OpenOCDInterface)
|
|
||||||
}
|
|
||||||
if spec.OpenOCDTarget == "" {
|
|
||||||
return nil, errors.New("OpenOCD chip not set")
|
|
||||||
}
|
|
||||||
if !regexp.MustCompile("^[\\p{L}0-9_-]+$").MatchString(spec.OpenOCDTarget) {
|
|
||||||
return nil, fmt.Errorf("OpenOCD target has an invalid name: %#v", spec.OpenOCDTarget)
|
|
||||||
}
|
|
||||||
if spec.OpenOCDTransport != "" && spec.OpenOCDTransport != "swd" {
|
|
||||||
return nil, fmt.Errorf("unknown OpenOCD transport: %#v", spec.OpenOCDTransport)
|
|
||||||
}
|
|
||||||
args = []string{"-f", "interface/" + spec.OpenOCDInterface + ".cfg"}
|
|
||||||
if spec.OpenOCDTransport != "" {
|
|
||||||
args = append(args, "-c", "transport select "+spec.OpenOCDTransport)
|
|
||||||
}
|
|
||||||
args = append(args, "-f", "target/"+spec.OpenOCDTarget+".cfg")
|
|
||||||
return args, nil
|
|
||||||
}
|
|
||||||
|
|
19
main.go
19
main.go
|
@ -151,7 +151,8 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
// determine the type of file to compile
|
// determine the type of file to compile
|
||||||
var fileExt string
|
var fileExt string
|
||||||
|
|
||||||
switch config.Target.FlashMethod {
|
flashMethod, _ := config.Programmer()
|
||||||
|
switch flashMethod {
|
||||||
case "command", "":
|
case "command", "":
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(config.Target.FlashCommand, "{hex}"):
|
case strings.Contains(config.Target.FlashCommand, "{hex}"):
|
||||||
|
@ -175,7 +176,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
case "native":
|
case "native":
|
||||||
return errors.New("unknown flash method \"native\" - did you miss a -target flag?")
|
return errors.New("unknown flash method \"native\" - did you miss a -target flag?")
|
||||||
default:
|
default:
|
||||||
return errors.New("unknown flash method: " + config.Target.FlashMethod)
|
return errors.New("unknown flash method: " + flashMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.Build(pkgName, fileExt, config, func(tmppath string) error {
|
return builder.Build(pkgName, fileExt, config, func(tmppath string) error {
|
||||||
|
@ -190,7 +191,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this flashing method copies the binary data to a Mass Storage Device (msd)
|
// this flashing method copies the binary data to a Mass Storage Device (msd)
|
||||||
switch config.Target.FlashMethod {
|
switch flashMethod {
|
||||||
case "", "command":
|
case "", "command":
|
||||||
// Create the command.
|
// Create the command.
|
||||||
flashCmd := config.Target.FlashCommand
|
flashCmd := config.Target.FlashCommand
|
||||||
|
@ -226,7 +227,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
return errors.New("mass storage device flashing currently only supports uf2 and hex")
|
return errors.New("mass storage device flashing currently only supports uf2 and hex")
|
||||||
}
|
}
|
||||||
case "openocd":
|
case "openocd":
|
||||||
args, err := config.Target.OpenOCDConfiguration()
|
args, err := config.OpenOCDConfiguration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -240,7 +241,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown flash method: %s", config.Target.FlashMethod)
|
return fmt.Errorf("unknown flash method: %s", flashMethod)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -263,13 +264,13 @@ func FlashGDB(pkgName, port string, ocdOutput bool, options *compileopts.Options
|
||||||
|
|
||||||
return builder.Build(pkgName, "", config, func(tmppath string) error {
|
return builder.Build(pkgName, "", config, func(tmppath string) error {
|
||||||
// Find a good way to run GDB.
|
// Find a good way to run GDB.
|
||||||
gdbInterface := config.Target.FlashMethod
|
gdbInterface, openocdInterface := config.Programmer()
|
||||||
switch gdbInterface {
|
switch gdbInterface {
|
||||||
case "msd", "command", "":
|
case "msd", "command", "":
|
||||||
if gdbInterface == "" {
|
if gdbInterface == "" {
|
||||||
gdbInterface = "command"
|
gdbInterface = "command"
|
||||||
}
|
}
|
||||||
if config.Target.OpenOCDInterface != "" && config.Target.OpenOCDTarget != "" {
|
if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
|
||||||
gdbInterface = "openocd"
|
gdbInterface = "openocd"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +284,7 @@ func FlashGDB(pkgName, port string, ocdOutput bool, options *compileopts.Options
|
||||||
gdbCommands = append(gdbCommands, "target remote :3333", "monitor halt", "load", "monitor reset halt")
|
gdbCommands = append(gdbCommands, "target remote :3333", "monitor halt", "load", "monitor reset halt")
|
||||||
|
|
||||||
// We need a separate debugging daemon for on-chip debugging.
|
// We need a separate debugging daemon for on-chip debugging.
|
||||||
args, err := config.Target.OpenOCDConfiguration()
|
args, err := config.OpenOCDConfiguration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -515,6 +516,7 @@ func main() {
|
||||||
nodebug := flag.Bool("no-debug", false, "disable DWARF debug symbol generation")
|
nodebug := flag.Bool("no-debug", false, "disable DWARF debug symbol generation")
|
||||||
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
|
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
|
||||||
port := flag.String("port", "/dev/ttyACM0", "flash port")
|
port := flag.String("port", "/dev/ttyACM0", "flash port")
|
||||||
|
programmer := flag.String("programmer", "", "which hardware programmer to use")
|
||||||
cFlags := flag.String("cflags", "", "additional cflags for compiler")
|
cFlags := flag.String("cflags", "", "additional cflags for compiler")
|
||||||
ldFlags := flag.String("ldflags", "", "additional ldflags for linker")
|
ldFlags := flag.String("ldflags", "", "additional ldflags for linker")
|
||||||
wasmAbi := flag.String("wasm-abi", "js", "WebAssembly ABI conventions: js (no i64 params) or generic")
|
wasmAbi := flag.String("wasm-abi", "js", "WebAssembly ABI conventions: js (no i64 params) or generic")
|
||||||
|
@ -541,6 +543,7 @@ func main() {
|
||||||
PrintSizes: *printSize,
|
PrintSizes: *printSize,
|
||||||
Tags: *tags,
|
Tags: *tags,
|
||||||
WasmAbi: *wasmAbi,
|
WasmAbi: *wasmAbi,
|
||||||
|
Programmer: *programmer,
|
||||||
}
|
}
|
||||||
|
|
||||||
if *cFlags != "" {
|
if *cFlags != "" {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче