diff options
author | Ayke van Laethem <[email protected]> | 2020-08-28 15:53:56 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-08-31 13:59:32 +0200 |
commit | 9a17698d6adb99bfa0f07a7d330da67e31978606 (patch) | |
tree | 840d6c7d0aff30f8bd416446f273ab1dc6528124 /compileopts | |
parent | 3ee47a9c1b0787e567d7af0f661cf02b8b5d5aed (diff) | |
download | tinygo-9a17698d6adb99bfa0f07a7d330da67e31978606.tar.gz tinygo-9a17698d6adb99bfa0f07a7d330da67e31978606.zip |
compileopts: add support for custom binary formats
Some chips (like the ESP family) have a particular image format that is
more complex than simply dumping everything in a raw image.
Diffstat (limited to 'compileopts')
-rw-r--r-- | compileopts/config.go | 25 | ||||
-rw-r--r-- | compileopts/target.go | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/compileopts/config.go b/compileopts/config.go index fa82b72e1..c2eb17d16 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -239,6 +239,31 @@ func (c *Config) Debug() bool { return c.Options.Debug } +// BinaryFormat returns an appropriate binary format, based on the file +// extension and the configured binary format in the target JSON file. +func (c *Config) BinaryFormat(ext string) string { + switch ext { + case ".bin", ".gba": + // The simplest format possible: dump everything in a raw binary file. + if c.Target.BinaryFormat != "" { + return c.Target.BinaryFormat + } + return "bin" + case ".hex": + // Similar to bin, but includes the start address and is thus usually a + // better format. + return "hex" + case ".uf2": + // Special purpose firmware format, mainly used on Adafruit boards. + // More information: + // https://github.com/Microsoft/uf2 + return "uf2" + default: + // Use the ELF format for unrecognized file formats. + return "elf" + } +} + // 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. diff --git a/compileopts/target.go b/compileopts/target.go index 076251272..6547320a1 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -47,6 +47,7 @@ type TargetSpec struct { FlashVolume string `json:"msd-volume-name"` FlashFilename string `json:"msd-firmware-name"` UF2FamilyID string `json:"uf2-family-id"` + BinaryFormat string `json:"binary-format"` OpenOCDInterface string `json:"openocd-interface"` OpenOCDTarget string `json:"openocd-target"` OpenOCDTransport string `json:"openocd-transport"` @@ -128,6 +129,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) { if spec2.UF2FamilyID != "" { spec.UF2FamilyID = spec2.UF2FamilyID } + if spec2.BinaryFormat != "" { + spec.BinaryFormat = spec2.BinaryFormat + } if spec2.OpenOCDInterface != "" { spec.OpenOCDInterface = spec2.OpenOCDInterface } |