supports binary-format, only esp* supported for now

This commit is contained in:
Li Jie
2025-08-22 20:42:43 +08:00
parent 1f193c8533
commit ecaf7c8ac6
10 changed files with 568 additions and 15 deletions

View File

@@ -26,6 +26,33 @@ type Config struct {
CodeModel string `json:"code-model"`
TargetABI string `json:"target-abi"`
RelocationModel string `json:"relocation-model"`
// Binary and firmware configuration
BinaryFormat string `json:"binary-format"`
// Flash and deployment configuration
FlashCommand string `json:"flash-command"`
FlashMethod string `json:"flash-method"`
Flash1200BpsReset string `json:"flash-1200-bps-reset"`
// Mass storage device configuration
MSDVolumeName []string `json:"msd-volume-name"`
MSDFirmwareName string `json:"msd-firmware-name"`
// UF2 configuration
UF2FamilyID string `json:"uf2-family-id"`
// Device-specific configuration
RP2040BootPatch bool `json:"rp2040-boot-patch"`
// Debug and emulation configuration
Emulator string `json:"emulator"`
GDB []string `json:"gdb"`
// OpenOCD configuration
OpenOCDInterface string `json:"openocd-interface"`
OpenOCDTransport string `json:"openocd-transport"`
OpenOCDTarget string `json:"openocd-target"`
}
// RawConfig represents the raw JSON configuration before inheritance resolution

View File

@@ -149,6 +149,39 @@ func (l *Loader) mergeConfig(dst, src *Config) {
if src.RelocationModel != "" {
dst.RelocationModel = src.RelocationModel
}
if src.BinaryFormat != "" {
dst.BinaryFormat = src.BinaryFormat
}
if src.FlashCommand != "" {
dst.FlashCommand = src.FlashCommand
}
if src.FlashMethod != "" {
dst.FlashMethod = src.FlashMethod
}
if src.Flash1200BpsReset != "" {
dst.Flash1200BpsReset = src.Flash1200BpsReset
}
if src.MSDFirmwareName != "" {
dst.MSDFirmwareName = src.MSDFirmwareName
}
if src.UF2FamilyID != "" {
dst.UF2FamilyID = src.UF2FamilyID
}
if src.RP2040BootPatch {
dst.RP2040BootPatch = src.RP2040BootPatch
}
if src.Emulator != "" {
dst.Emulator = src.Emulator
}
if src.OpenOCDInterface != "" {
dst.OpenOCDInterface = src.OpenOCDInterface
}
if src.OpenOCDTransport != "" {
dst.OpenOCDTransport = src.OpenOCDTransport
}
if src.OpenOCDTarget != "" {
dst.OpenOCDTarget = src.OpenOCDTarget
}
// Merge slices (append, don't replace)
if len(src.BuildTags) > 0 {
@@ -163,6 +196,12 @@ func (l *Loader) mergeConfig(dst, src *Config) {
if len(src.ExtraFiles) > 0 {
dst.ExtraFiles = append(dst.ExtraFiles, src.ExtraFiles...)
}
if len(src.MSDVolumeName) > 0 {
dst.MSDVolumeName = append(dst.MSDVolumeName, src.MSDVolumeName...)
}
if len(src.GDB) > 0 {
dst.GDB = append(dst.GDB, src.GDB...)
}
}
// GetTargetsDir returns the targets directory path

View File

@@ -61,7 +61,8 @@ func TestLoaderLoadRaw(t *testing.T) {
"goarch": "arm",
"build-tags": ["test", "embedded"],
"cflags": ["-Os", "-g"],
"ldflags": ["--gc-sections"]
"ldflags": ["--gc-sections"],
"binary-format": "uf2"
}`
configPath := filepath.Join(tempDir, "test-target.json")
@@ -87,6 +88,9 @@ func TestLoaderLoadRaw(t *testing.T) {
if len(config.BuildTags) != 2 || config.BuildTags[0] != "test" || config.BuildTags[1] != "embedded" {
t.Errorf("Expected build-tags [test, embedded], got %v", config.BuildTags)
}
if config.BinaryFormat != "uf2" {
t.Errorf("Expected binary-format 'uf2', got '%s'", config.BinaryFormat)
}
}
func TestLoaderInheritance(t *testing.T) {
@@ -99,7 +103,8 @@ func TestLoaderInheritance(t *testing.T) {
"goos": "linux",
"goarch": "arm",
"cflags": ["-Os"],
"ldflags": ["--gc-sections"]
"ldflags": ["--gc-sections"],
"binary-format": "elf"
}`
// Create child config that inherits from parent
@@ -108,7 +113,8 @@ func TestLoaderInheritance(t *testing.T) {
"cpu": "cortex-m4",
"build-tags": ["child"],
"cflags": ["-O2"],
"ldflags": ["-g"]
"ldflags": ["-g"],
"binary-format": "uf2"
}`
parentPath := filepath.Join(tempDir, "parent.json")
@@ -143,6 +149,11 @@ func TestLoaderInheritance(t *testing.T) {
t.Errorf("Expected overridden cpu 'cortex-m4', got '%s'", config.CPU)
}
// Check binary-format override
if config.BinaryFormat != "uf2" {
t.Errorf("Expected overridden binary-format 'uf2', got '%s'", config.BinaryFormat)
}
// Check merged arrays
expectedCFlags := []string{"-Os", "-O2"}
if len(config.CFlags) != 2 || config.CFlags[0] != "-Os" || config.CFlags[1] != "-O2" {