refactor: move device types definition into flash
This commit is contained in:
@@ -59,7 +59,7 @@ func runMonitor(cmd *base.Command, args []string) {
|
|||||||
fmt.Fprintf(os.Stderr, "llgo monitor: %v\n", err)
|
fmt.Fprintf(os.Stderr, "llgo monitor: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
serialPort = conf.Flash.SerialPort
|
serialPort = conf.Device.SerialPort
|
||||||
}
|
}
|
||||||
|
|
||||||
config := monitor.MonitorConfig{
|
config := monitor.MonitorConfig{
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
case ModeInstall:
|
case ModeInstall:
|
||||||
// Native already installed in linkMainPkg
|
// Native already installed in linkMainPkg
|
||||||
if conf.Target != "" {
|
if conf.Target != "" {
|
||||||
err = flash.Flash(ctx.crossCompile, finalApp, ctx.buildConf.Port, verbose)
|
err = flash.FlashDevice(ctx.crossCompile.Device, finalApp, ctx.buildConf.Port, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
} else if conf.Emulator {
|
} else if conf.Emulator {
|
||||||
err = runInEmulator(ctx.crossCompile.Emulator, finalApp, pkg.Dir, pkg.PkgPath, conf, mode, verbose)
|
err = runInEmulator(ctx.crossCompile.Emulator, finalApp, pkg.Dir, pkg.PkgPath, conf, mode, verbose)
|
||||||
} else {
|
} else {
|
||||||
err = flash.Flash(ctx.crossCompile, finalApp, ctx.buildConf.Port, verbose)
|
err = flash.FlashDevice(ctx.crossCompile.Device, finalApp, ctx.buildConf.Port, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -365,9 +365,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
Target: conf.Target,
|
Target: conf.Target,
|
||||||
Executable: finalApp,
|
Executable: finalApp,
|
||||||
BaudRate: conf.BaudRate,
|
BaudRate: conf.BaudRate,
|
||||||
}
|
SerialPort: ctx.crossCompile.Device.SerialPort,
|
||||||
if ctx.crossCompile.Flash.Method != "openocd" {
|
|
||||||
monitorConfig.SerialPort = ctx.crossCompile.Flash.SerialPort
|
|
||||||
}
|
}
|
||||||
err = monitor.Monitor(monitorConfig, verbose)
|
err = monitor.Monitor(monitorConfig, verbose)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ func determineFlashFormat(crossCompile *crosscompile.Export) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
flashMethod := crossCompile.Flash.Method
|
flashMethod := crossCompile.Device.Flash.Method
|
||||||
switch flashMethod {
|
switch flashMethod {
|
||||||
case "command", "":
|
case "command", "":
|
||||||
// Extract format from flash command tokens
|
// Extract format from flash command tokens
|
||||||
flashCommand := crossCompile.Flash.Command
|
flashCommand := crossCompile.Device.Flash.Command
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(flashCommand, "{hex}"):
|
case strings.Contains(flashCommand, "{hex}"):
|
||||||
return ".hex"
|
return ".hex"
|
||||||
@@ -106,10 +106,10 @@ func determineFlashFormat(crossCompile *crosscompile.Export) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
case "msd":
|
case "msd":
|
||||||
if crossCompile.MSD.FirmwareName == "" {
|
if crossCompile.Device.MSD.FirmwareName == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return filepath.Ext(crossCompile.MSD.FirmwareName)
|
return filepath.Ext(crossCompile.Device.MSD.FirmwareName)
|
||||||
case "openocd":
|
case "openocd":
|
||||||
return ".hex"
|
return ".hex"
|
||||||
case "bmp":
|
case "bmp":
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goplus/llgo/internal/crosscompile"
|
"github.com/goplus/llgo/internal/crosscompile"
|
||||||
|
"github.com/goplus/llgo/internal/flash"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenOutputs(t *testing.T) {
|
func TestGenOutputs(t *testing.T) {
|
||||||
@@ -315,11 +316,13 @@ func TestGenOutputs(t *testing.T) {
|
|||||||
pkgName: "hello",
|
pkgName: "hello",
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
BinaryFormat: "esp32",
|
BinaryFormat: "esp32",
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "command",
|
Method: "command",
|
||||||
Command: "esptool.py --chip esp32 write_flash 0x10000 {hex}",
|
Command: "esptool.py --chip esp32 write_flash 0x10000 {hex}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantOutPath: "", // temp file
|
wantOutPath: "", // temp file
|
||||||
wantOutExt: ".hex",
|
wantOutExt: ".hex",
|
||||||
wantFileFmt: "hex",
|
wantFileFmt: "hex",
|
||||||
@@ -336,11 +339,13 @@ func TestGenOutputs(t *testing.T) {
|
|||||||
pkgName: "hello",
|
pkgName: "hello",
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
BinaryFormat: "esp32",
|
BinaryFormat: "esp32",
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "command",
|
Method: "command",
|
||||||
Command: "esptool.py --chip esp32 write_flash 0x10000 {bin}",
|
Command: "esptool.py --chip esp32 write_flash 0x10000 {bin}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantOutPath: "", // temp file
|
wantOutPath: "", // temp file
|
||||||
wantOutExt: ".bin",
|
wantOutExt: ".bin",
|
||||||
wantFileFmt: "bin",
|
wantFileFmt: "bin",
|
||||||
@@ -357,10 +362,12 @@ func TestGenOutputs(t *testing.T) {
|
|||||||
pkgName: "hello",
|
pkgName: "hello",
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
BinaryFormat: "arm",
|
BinaryFormat: "arm",
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "openocd",
|
Method: "openocd",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantOutPath: "", // temp file
|
wantOutPath: "", // temp file
|
||||||
wantOutExt: ".hex",
|
wantOutExt: ".hex",
|
||||||
wantFileFmt: "hex",
|
wantFileFmt: "hex",
|
||||||
@@ -377,13 +384,15 @@ func TestGenOutputs(t *testing.T) {
|
|||||||
pkgName: "hello",
|
pkgName: "hello",
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
BinaryFormat: "uf2",
|
BinaryFormat: "uf2",
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "msd",
|
Method: "msd",
|
||||||
},
|
},
|
||||||
MSD: crosscompile.MSD{
|
MSD: flash.MSD{
|
||||||
FirmwareName: "firmware.uf2",
|
FirmwareName: "firmware.uf2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantOutPath: "", // temp file
|
wantOutPath: "", // temp file
|
||||||
wantOutExt: ".uf2",
|
wantOutExt: ".uf2",
|
||||||
wantFileFmt: "uf2",
|
wantFileFmt: "uf2",
|
||||||
@@ -400,10 +409,12 @@ func TestGenOutputs(t *testing.T) {
|
|||||||
pkgName: "hello",
|
pkgName: "hello",
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
BinaryFormat: "arm",
|
BinaryFormat: "arm",
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "bmp",
|
Method: "bmp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantOutPath: "", // temp file
|
wantOutPath: "", // temp file
|
||||||
wantOutExt: ".elf",
|
wantOutExt: ".elf",
|
||||||
wantFileFmt: "elf",
|
wantFileFmt: "elf",
|
||||||
@@ -510,11 +521,13 @@ func TestDetermineFormat(t *testing.T) {
|
|||||||
name: "flash method command - extract hex",
|
name: "flash method command - extract hex",
|
||||||
conf: &Config{Mode: ModeRun, Target: "esp32"},
|
conf: &Config{Mode: ModeRun, Target: "esp32"},
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "command",
|
Method: "command",
|
||||||
Command: "esptool.py --chip esp32 write_flash 0x10000 {hex}",
|
Command: "esptool.py --chip esp32 write_flash 0x10000 {hex}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantFmt: "hex",
|
wantFmt: "hex",
|
||||||
wantExt: ".hex",
|
wantExt: ".hex",
|
||||||
},
|
},
|
||||||
@@ -522,11 +535,13 @@ func TestDetermineFormat(t *testing.T) {
|
|||||||
name: "flash method command - extract bin",
|
name: "flash method command - extract bin",
|
||||||
conf: &Config{Mode: ModeRun, Target: "esp32"},
|
conf: &Config{Mode: ModeRun, Target: "esp32"},
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "command",
|
Method: "command",
|
||||||
Command: "esptool.py --chip esp32 write_flash 0x10000 {bin}",
|
Command: "esptool.py --chip esp32 write_flash 0x10000 {bin}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantFmt: "bin",
|
wantFmt: "bin",
|
||||||
wantExt: ".bin",
|
wantExt: ".bin",
|
||||||
},
|
},
|
||||||
@@ -534,10 +549,12 @@ func TestDetermineFormat(t *testing.T) {
|
|||||||
name: "flash method openocd",
|
name: "flash method openocd",
|
||||||
conf: &Config{Mode: ModeRun, Target: "stm32"},
|
conf: &Config{Mode: ModeRun, Target: "stm32"},
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "openocd",
|
Method: "openocd",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantFmt: "hex",
|
wantFmt: "hex",
|
||||||
wantExt: ".hex",
|
wantExt: ".hex",
|
||||||
},
|
},
|
||||||
@@ -545,13 +562,15 @@ func TestDetermineFormat(t *testing.T) {
|
|||||||
name: "flash method msd - extract from firmware name",
|
name: "flash method msd - extract from firmware name",
|
||||||
conf: &Config{Mode: ModeRun, Target: "rp2040"},
|
conf: &Config{Mode: ModeRun, Target: "rp2040"},
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "msd",
|
Method: "msd",
|
||||||
},
|
},
|
||||||
MSD: crosscompile.MSD{
|
MSD: flash.MSD{
|
||||||
FirmwareName: "firmware.uf2",
|
FirmwareName: "firmware.uf2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantFmt: "uf2",
|
wantFmt: "uf2",
|
||||||
wantExt: ".uf2",
|
wantExt: ".uf2",
|
||||||
},
|
},
|
||||||
@@ -559,10 +578,12 @@ func TestDetermineFormat(t *testing.T) {
|
|||||||
name: "flash method bmp",
|
name: "flash method bmp",
|
||||||
conf: &Config{Mode: ModeRun, Target: "stm32"},
|
conf: &Config{Mode: ModeRun, Target: "stm32"},
|
||||||
crossCompile: &crosscompile.Export{
|
crossCompile: &crosscompile.Export{
|
||||||
Flash: crosscompile.Flash{
|
Device: flash.Device{
|
||||||
|
Flash: flash.Flash{
|
||||||
Method: "bmp",
|
Method: "bmp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
wantFmt: "elf",
|
wantFmt: "elf",
|
||||||
wantExt: ".elf",
|
wantExt: ".elf",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,32 +12,11 @@ import (
|
|||||||
|
|
||||||
"github.com/goplus/llgo/internal/crosscompile/compile"
|
"github.com/goplus/llgo/internal/crosscompile/compile"
|
||||||
"github.com/goplus/llgo/internal/env"
|
"github.com/goplus/llgo/internal/env"
|
||||||
|
"github.com/goplus/llgo/internal/flash"
|
||||||
"github.com/goplus/llgo/internal/targets"
|
"github.com/goplus/llgo/internal/targets"
|
||||||
"github.com/goplus/llgo/internal/xtool/llvm"
|
"github.com/goplus/llgo/internal/xtool/llvm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flash contains configuration for device flashing
|
|
||||||
type Flash struct {
|
|
||||||
Method string // Flash method: "command", "openocd", "msd", "bmp"
|
|
||||||
Command string // Flash command template
|
|
||||||
Serial string // Serial communication settings
|
|
||||||
SerialPort []string // Available serial ports
|
|
||||||
Flash1200BpsReset bool // Whether to use 1200bps reset
|
|
||||||
}
|
|
||||||
|
|
||||||
// MSD contains configuration for Mass Storage Device flashing
|
|
||||||
type MSD struct {
|
|
||||||
VolumeName []string // Names of the volumes
|
|
||||||
FirmwareName string // Firmware file name pattern
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenOCD contains configuration for OpenOCD debugging/flashing
|
|
||||||
type OpenOCD struct {
|
|
||||||
Interface string // Interface configuration (e.g., "stlink")
|
|
||||||
Transport string // Transport protocol (e.g., "swd", "jtag")
|
|
||||||
Target string // Target configuration (e.g., "stm32f4x")
|
|
||||||
}
|
|
||||||
|
|
||||||
type Export struct {
|
type Export struct {
|
||||||
CC string // Compiler to use
|
CC string // Compiler to use
|
||||||
CCFLAGS []string
|
CCFLAGS []string
|
||||||
@@ -59,9 +38,7 @@ type Export struct {
|
|||||||
Emulator string // Emulator command template (e.g., "qemu-system-arm -M {} -kernel {}")
|
Emulator string // Emulator command template (e.g., "qemu-system-arm -M {} -kernel {}")
|
||||||
|
|
||||||
// Flashing/Debugging configuration
|
// Flashing/Debugging configuration
|
||||||
Flash Flash // Flash configuration for device programming
|
Device flash.Device // Device configuration for flashing/debugging
|
||||||
MSD MSD // Mass Storage Device configuration
|
|
||||||
OpenOCD OpenOCD // OpenOCD configuration for debugging/flashing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLs and configuration that can be overridden for testing
|
// URLs and configuration that can be overridden for testing
|
||||||
@@ -530,21 +507,23 @@ func UseTarget(targetName string) (export Export, err error) {
|
|||||||
export.Emulator = config.Emulator
|
export.Emulator = config.Emulator
|
||||||
|
|
||||||
// Set flashing/debugging configuration
|
// Set flashing/debugging configuration
|
||||||
export.Flash = Flash{
|
export.Device = flash.Device{
|
||||||
Method: config.FlashMethod,
|
|
||||||
Command: config.FlashCommand,
|
|
||||||
Serial: config.Serial,
|
Serial: config.Serial,
|
||||||
SerialPort: config.SerialPort,
|
SerialPort: config.SerialPort,
|
||||||
|
Flash: flash.Flash{
|
||||||
|
Method: config.FlashMethod,
|
||||||
|
Command: config.FlashCommand,
|
||||||
Flash1200BpsReset: config.Flash1200BpsReset == "true",
|
Flash1200BpsReset: config.Flash1200BpsReset == "true",
|
||||||
}
|
},
|
||||||
export.MSD = MSD{
|
MSD: flash.MSD{
|
||||||
VolumeName: config.MSDVolumeName,
|
VolumeName: config.MSDVolumeName,
|
||||||
FirmwareName: config.MSDFirmwareName,
|
FirmwareName: config.MSDFirmwareName,
|
||||||
}
|
},
|
||||||
export.OpenOCD = OpenOCD{
|
OpenOCD: flash.OpenOCD{
|
||||||
Interface: config.OpenOCDInterface,
|
Interface: config.OpenOCDInterface,
|
||||||
Transport: config.OpenOCDTransport,
|
Transport: config.OpenOCDTransport,
|
||||||
Target: config.OpenOCDTarget,
|
Target: config.OpenOCDTarget,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build environment map for template variable expansion
|
// Build environment map for template variable expansion
|
||||||
|
|||||||
@@ -11,12 +11,40 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goplus/llgo/internal/crosscompile"
|
|
||||||
"github.com/goplus/llgo/internal/env"
|
"github.com/goplus/llgo/internal/env"
|
||||||
"go.bug.st/serial"
|
"go.bug.st/serial"
|
||||||
"go.bug.st/serial/enumerator"
|
"go.bug.st/serial/enumerator"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Device contains all flashing/debugging configuration for a device
|
||||||
|
type Device struct {
|
||||||
|
Serial string // Serial communication settings
|
||||||
|
SerialPort []string // Available serial ports
|
||||||
|
Flash Flash // Flash configuration for device programming
|
||||||
|
MSD MSD // Mass Storage Device configuration
|
||||||
|
OpenOCD OpenOCD // OpenOCD configuration for debugging/flashing
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flash contains configuration for device flashing
|
||||||
|
type Flash struct {
|
||||||
|
Method string // Flash method: "command", "openocd", "msd", "bmp"
|
||||||
|
Command string // Flash command template
|
||||||
|
Flash1200BpsReset bool // Whether to use 1200bps reset
|
||||||
|
}
|
||||||
|
|
||||||
|
// MSD contains configuration for Mass Storage Device flashing
|
||||||
|
type MSD struct {
|
||||||
|
VolumeName []string // Names of the volumes
|
||||||
|
FirmwareName string // Firmware file name pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenOCD contains configuration for OpenOCD debugging/flashing
|
||||||
|
type OpenOCD struct {
|
||||||
|
Interface string // Interface configuration (e.g., "stlink")
|
||||||
|
Transport string // Transport protocol (e.g., "swd", "jtag")
|
||||||
|
Target string // Target configuration (e.g., "stm32f4x")
|
||||||
|
}
|
||||||
|
|
||||||
// From tinygo/main.go getDefaultPort
|
// From tinygo/main.go getDefaultPort
|
||||||
// GetPort returns the default serial port depending on the operating system and USB interfaces.
|
// GetPort returns the default serial port depending on the operating system and USB interfaces.
|
||||||
func GetPort(portFlag string, usbInterfaces []string) (string, error) {
|
func GetPort(portFlag string, usbInterfaces []string) (string, error) {
|
||||||
@@ -163,9 +191,9 @@ func touchSerialPortAt1200bps(port string) (err error) {
|
|||||||
return fmt.Errorf("opening port: %s", err)
|
return fmt.Errorf("opening port: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flash flashes firmware to a device based on the crosscompile configuration
|
// FlashDevice flashes firmware to a device based on the device configuration
|
||||||
func Flash(crossCompile crosscompile.Export, app string, port string, verbose bool) error {
|
func FlashDevice(device Device, app string, port string, verbose bool) error {
|
||||||
method := crossCompile.Flash.Method
|
method := device.Flash.Method
|
||||||
if method == "" {
|
if method == "" {
|
||||||
method = "command"
|
method = "command"
|
||||||
}
|
}
|
||||||
@@ -173,7 +201,7 @@ func Flash(crossCompile crosscompile.Export, app string, port string, verbose bo
|
|||||||
// Resolve port for methods that need it (all except openocd)
|
// Resolve port for methods that need it (all except openocd)
|
||||||
if method != "openocd" {
|
if method != "openocd" {
|
||||||
var err error
|
var err error
|
||||||
port, err = GetPort(port, crossCompile.Flash.SerialPort)
|
port, err = GetPort(port, device.SerialPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find port: %w", err)
|
return fmt.Errorf("failed to find port: %w", err)
|
||||||
}
|
}
|
||||||
@@ -185,7 +213,7 @@ func Flash(crossCompile crosscompile.Export, app string, port string, verbose bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute 1200bps reset before flashing if needed (except for openocd)
|
// Execute 1200bps reset before flashing if needed (except for openocd)
|
||||||
if method != "openocd" && crossCompile.Flash.Flash1200BpsReset {
|
if method != "openocd" && device.Flash.Flash1200BpsReset {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Fprintf(os.Stderr, "Triggering 1200bps reset on port: %s\n", port)
|
fmt.Fprintf(os.Stderr, "Triggering 1200bps reset on port: %s\n", port)
|
||||||
}
|
}
|
||||||
@@ -198,11 +226,11 @@ func Flash(crossCompile crosscompile.Export, app string, port string, verbose bo
|
|||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case "command":
|
case "command":
|
||||||
return flashCommand(crossCompile.Flash, app, port, verbose)
|
return flashCommand(device.Flash, app, port, verbose)
|
||||||
case "openocd":
|
case "openocd":
|
||||||
return flashOpenOCD(crossCompile.OpenOCD, app, verbose)
|
return flashOpenOCD(device.OpenOCD, app, verbose)
|
||||||
case "msd":
|
case "msd":
|
||||||
return flashMSD(crossCompile.MSD, app, verbose)
|
return flashMSD(device.MSD, app, verbose)
|
||||||
case "bmp":
|
case "bmp":
|
||||||
return flashBMP(app, verbose)
|
return flashBMP(app, verbose)
|
||||||
default:
|
default:
|
||||||
@@ -211,7 +239,7 @@ func Flash(crossCompile crosscompile.Export, app string, port string, verbose bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flashCommand handles command-based flashing
|
// flashCommand handles command-based flashing
|
||||||
func flashCommand(flash crosscompile.Flash, app string, port string, verbose bool) error {
|
func flashCommand(flash Flash, app string, port string, verbose bool) error {
|
||||||
if flash.Command == "" {
|
if flash.Command == "" {
|
||||||
return fmt.Errorf("flash command not specified")
|
return fmt.Errorf("flash command not specified")
|
||||||
}
|
}
|
||||||
@@ -241,7 +269,7 @@ func flashCommand(flash crosscompile.Flash, app string, port string, verbose boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flashOpenOCD handles OpenOCD-based flashing
|
// flashOpenOCD handles OpenOCD-based flashing
|
||||||
func flashOpenOCD(openocd crosscompile.OpenOCD, app string, verbose bool) error {
|
func flashOpenOCD(openocd OpenOCD, app string, verbose bool) error {
|
||||||
if openocd.Interface == "" {
|
if openocd.Interface == "" {
|
||||||
return fmt.Errorf("OpenOCD interface not specified")
|
return fmt.Errorf("OpenOCD interface not specified")
|
||||||
}
|
}
|
||||||
@@ -279,7 +307,7 @@ func flashOpenOCD(openocd crosscompile.OpenOCD, app string, verbose bool) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flashMSD handles Mass Storage Device flashing
|
// flashMSD handles Mass Storage Device flashing
|
||||||
func flashMSD(msd crosscompile.MSD, app string, verbose bool) error {
|
func flashMSD(msd MSD, app string, verbose bool) error {
|
||||||
if len(msd.VolumeName) == 0 {
|
if len(msd.VolumeName) == 0 {
|
||||||
return fmt.Errorf("MSD volume names not specified")
|
return fmt.Errorf("MSD volume names not specified")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user