diff --git a/internal/cbuild/cbuild.go b/internal/cbuild/cbuild.go index f8c2fc1..2a2ab8c 100644 --- a/internal/cbuild/cbuild.go +++ b/internal/cbuild/cbuild.go @@ -8,47 +8,29 @@ package cbuild import ( "errors" - "path" - "path/filepath" - "strings" "github.com/open-cmsis-pack/generator-bridge/internal/common" "github.com/open-cmsis-pack/generator-bridge/internal/utils" - log "github.com/sirupsen/logrus" ) -type PackType struct { - Pack string - Path string -} - -type SubsystemIdxType struct { - Project string - CbuildGen string - Configuration string - ForProjectPart string - ProjectType string - SecureContextName string - NonSecureContextName string -} - -type SubsystemType struct { - SubsystemIdx SubsystemIdxType - Board string - Device string - Project string - Compiler string - TrustZone string - CoreName string - // Packs []PackType +type CbuildGensType struct { + CbuildGen CbuildGenType + Project string + Configuration string + ForProjectPart string + Output string + Name string + Map string } type ParamsType struct { - Board string + GeneratedBy string + ID string + Output string Device string - OutPath string + Board string ProjectType string - Subsystem []SubsystemType + CbuildGens []CbuildGensType } // https://zhwt.github.io/yaml-to-go/ @@ -69,6 +51,8 @@ type CbuildGenIdxType struct { Configuration string `yaml:"configuration"` ForProjectPart string `yaml:"for-project-part"` Output string `yaml:"output"` + Name string `yaml:"name"` + Map string `yaml:"map"` } `yaml:"cbuild-gens"` } `yaml:"generators"` } `yaml:"build-gen-idx"` @@ -176,11 +160,11 @@ type GeneratorImportType struct { Groups []CgenGroupsType `yaml:"groups,omitempty"` } -func Read(name, outPath string, params *ParamsType) error { - return ReadCbuildgenIdx(name, outPath, params) +func Read(name, generatorID string, params *ParamsType) error { + return ReadCbuildgenIdx(name, generatorID, params) } -func ReadCbuildgenIdx(name, outPath string, params *ParamsType) error { +func ReadCbuildgenIdx(name, generatorID string, params *ParamsType) error { var cbuildGenIdx CbuildGenIdxType err := common.ReadYml(name, &cbuildGenIdx) @@ -188,82 +172,37 @@ func ReadCbuildgenIdx(name, outPath string, params *ParamsType) error { return err } - for idGen, cbuildGenIdx := range cbuildGenIdx.BuildGenIdx.Generators { - cbuildGenIdxID := cbuildGenIdx.ID - cbuildGenIdxBoard := cbuildGenIdx.Board - cbuildGenIdxDevice := cbuildGenIdx.Device - cbuildGenIdxType := cbuildGenIdx.ProjectType - cbuildGenIdxOutputPath := cbuildGenIdx.Output - - log.Debugf("Found CBuildGenIdx: #%v ID: %v, board: %v, device: %v, type: %v", idGen, cbuildGenIdxID, cbuildGenIdxBoard, cbuildGenIdxDevice, cbuildGenIdxType) - log.Debugf("CBuildGenIdx Output path: %v", cbuildGenIdxOutputPath) - - params.Device = cbuildGenIdxDevice - params.OutPath = cbuildGenIdxOutputPath - - var board string - split := strings.SplitAfter(cbuildGenIdx.Board, "::") - if len(split) == 2 { - board = split[1] - } else { - board = cbuildGenIdx.Board - } - split = strings.Split(board, ":") - if len(split) == 2 { - params.Board = split[0] - } else { - params.Board = board - } - - var secureContextName string - var nonsecureContextName string - - for _, cbuildGen := range cbuildGenIdx.CbuildGens { - fileName := cbuildGen.CbuildGen - var subPath string - if filepath.IsAbs(fileName) { - subPath = fileName - } else { - subPath = path.Join(path.Dir(name), fileName) - } - - var subsystem SubsystemType - subsystem.SubsystemIdx.Project = cbuildGen.Project - subsystem.SubsystemIdx.Configuration = cbuildGen.Configuration - subsystem.SubsystemIdx.CbuildGen = cbuildGen.CbuildGen - subsystem.SubsystemIdx.ProjectType = cbuildGenIdx.ProjectType - subsystem.SubsystemIdx.ForProjectPart = cbuildGen.ForProjectPart - - err := ReadCbuildgen(subPath, &subsystem) // use copy, do not override for next instance - if err != nil { - return err - } - - params.Subsystem = append(params.Subsystem, subsystem) - - // store Reference project for TZ - if cbuildGenIdx.ProjectType == "trustzone" { - if cbuildGen.ForProjectPart == "secure" { - secureContextName = cbuildGen.Project - } else if cbuildGen.ForProjectPart == "non-secure" { - nonsecureContextName = cbuildGen.Project + for _, cgen := range cbuildGenIdx.BuildGenIdx.Generators { + if cgen.ID == generatorID { + params.GeneratedBy = cbuildGenIdx.BuildGenIdx.GeneratedBy + params.ID = cgen.ID + params.Output = cgen.Output + params.Device = cgen.Device + params.Board = cgen.Board + params.ProjectType = cgen.ProjectType + + for _, cbuildGen := range cgen.CbuildGens { + var tmpCbuildGen CbuildGensType + err := ReadCbuildgen(cbuildGen.CbuildGen, &tmpCbuildGen.CbuildGen) + if err != nil { + return err } + tmpCbuildGen.Project = cbuildGen.Project + tmpCbuildGen.Configuration = cbuildGen.Configuration + tmpCbuildGen.ForProjectPart = cbuildGen.ForProjectPart + tmpCbuildGen.Output = cbuildGen.Output + tmpCbuildGen.Name = cbuildGen.Name + tmpCbuildGen.Map = cbuildGen.Map + + params.CbuildGens = append(params.CbuildGens, tmpCbuildGen) } } - - // store Reference project for TZ-NS - for idSub := range params.Subsystem { - subsystem := ¶ms.Subsystem[idSub] - subsystem.SubsystemIdx.SecureContextName = secureContextName - subsystem.SubsystemIdx.NonSecureContextName = nonsecureContextName - } } return nil } -func ReadCbuildgen(name string, subsystem *SubsystemType) error { - var cbuildGen CbuildGenType +func ReadCbuildgen(name string, cbuildGen *CbuildGenType) error { if !utils.FileExists(name) { text := "File not found: " @@ -275,30 +214,5 @@ func ReadCbuildgen(name string, subsystem *SubsystemType) error { if err != nil { return err } - - split := strings.SplitAfter(cbuildGen.BuildGen.Board, "::") - if len(split) == 2 { - subsystem.Board = split[1] - } else { - subsystem.Board = cbuildGen.BuildGen.Board - } - subsystem.Device = cbuildGen.BuildGen.Device - subsystem.Compiler = cbuildGen.BuildGen.Compiler - subsystem.Project = cbuildGen.BuildGen.Project - subsystem.CoreName = cbuildGen.BuildGen.Processor.Core - subsystem.TrustZone = cbuildGen.BuildGen.Processor.Trustzone - - log.Debugf("Found CBuildGen: board: %v, device: %v, core: %v, TZ: %v, compiler: %v, project: %v", - subsystem.Board, subsystem.Device, subsystem.CoreName, subsystem.TrustZone, subsystem.Compiler, subsystem.Project) - - // for id := range cbuildGen.BuildGen.Packs { - // genPack := cbuildGen.BuildGen.Packs[id] - // var pack PackType - // pack.Pack = genPack.Pack - // pack.Path = genPack.Path - // log.Debugf("Found Pack: #%v Pack: %v, Path: %v", id, pack.Pack, pack.Path) - // subsystem.Packs = append(subsystem.Packs, pack) - // } - return nil } diff --git a/internal/readFile/readFile.go b/internal/readFile/readFile.go index a497d0e..f6e3c77 100644 --- a/internal/readFile/readFile.go +++ b/internal/readFile/readFile.go @@ -21,28 +21,27 @@ import ( func Process(inFile, inFile2, outPath string) error { log.Debugf("Reading file: %v", inFile) if outPath == "" { - outPath = filepath.Dir(inFile) + outPath = filepath.Dir(inFile2) } - var params cbuild.ParamsType + var cbuildParams cbuild.ParamsType + var params []stm32cubemx.BridgeParamType if strings.Contains(inFile, "cbuild-gen-idx.yml") { - err := cbuild.Read(inFile, outPath, ¶ms) + err := cbuild.Read(inFile, "CubeMX", &cbuildParams) if err != nil { return err } - _, err = stm32cubemx.WriteProjectFile(outPath, ¶ms) + + err = stm32cubemx.GetBridgeInfo(&cbuildParams, ¶ms) if err != nil { return err } - } else if strings.Contains(inFile, "cbuild-gen.yml") || strings.Contains(inFile, "cbuild.yml") { - params.OutPath = outPath - var subsystem cbuild.SubsystemType - err := cbuild.ReadCbuildgen(inFile, &subsystem) + + _, err = stm32cubemx.WriteProjectFile(outPath, params[0]) if err != nil { return err } - params.Subsystem = append(params.Subsystem, subsystem) } var mxprojectFile string @@ -54,25 +53,23 @@ func Process(inFile, inFile2, outPath string) error { } if mxprojectFile != "" { - mxprojectAll, _ := stm32cubemx.IniReader(mxprojectFile, params.Subsystem[0].Compiler, false) + mxprojectAll, _ := stm32cubemx.IniReader(mxprojectFile, params) - if params.Board == "" && params.Device == "" { - params.Board = "Test Board" - params.Device = "Test Device" + if params[0].Board == "" && params[0].Device == "" { + params[0].Board = "Test Board" + params[0].Device = "Test Device" } - var parms cbuild.ParamsType - - err := stm32cubemx.ReadCbuildYmlFile(inFile, outPath, &parms) + err := stm32cubemx.ReadCbuildYmlFile(inFile, "CubeMX", &cbuildParams) if err != nil { return err } workDir := path.Dir(inFile) - if parms.OutPath != "" { - if filepath.IsAbs(parms.OutPath) { - workDir = parms.OutPath + if params[0].Output != "" { + if filepath.IsAbs(params[0].Output) { + workDir = params[0].Output } else { - workDir = path.Join(workDir, parms.OutPath) + workDir = path.Join(workDir, params[0].Output) } } else { if filepath.IsAbs(outPath) { @@ -88,7 +85,7 @@ func Process(inFile, inFile2, outPath string) error { return err } - err = stm32cubemx.ReadContexts(workDir+"/STM32CubeMX/STM32CubeMX.ioc", parms) + err = stm32cubemx.ReadContexts(workDir+"/STM32CubeMX/STM32CubeMX.ioc", params) if err != nil { return err } diff --git a/internal/stm32CubeMX/iniReader.go b/internal/stm32CubeMX/iniReader.go index 35039b5..f16174a 100644 --- a/internal/stm32CubeMX/iniReader.go +++ b/internal/stm32CubeMX/iniReader.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "path/filepath" - "regexp" "strconv" "strings" @@ -25,8 +24,7 @@ type MxprojectAllType struct { } type MxprojectType struct { - CoreName string - Trustzone string + Context string PreviousLibFiles struct { LibFiles []string } @@ -46,15 +44,9 @@ type MxprojectType struct { } } -type IniSectionCore struct { - CoreName string - trustzone string - iniName string -} - type IniSectionsType struct { - cores []IniSectionCore - sections []string + Context string + Section string } func PrintKeyValStr(key, val string) { @@ -137,58 +129,7 @@ func StoreItemIterator(data *[]string, section *ini.Section, key, iterator strin } } -func FindInList(name string, list *[]string) bool { - if name == "" { - return false - } - - for _, item := range *list { - if item == name { - return true - } - } - return false -} - -func AppendToList(name string, list *[]string) { - if name == "" { - return - } - - if FindInList(name, list) { - return - } - - *list = append(*list, name) -} - -func FindInCores(name string, list *[]IniSectionCore) bool { - if name == "" { - return false - } - - for _, item := range *list { - if item.iniName == name { - return true - } - } - return false -} - -func AppendToCores(iniSectionCore IniSectionCore, list *[]IniSectionCore) { - name := iniSectionCore.iniName - if name == "" { - return - } - - if FindInCores(name, list) { - return - } - - *list = append(*list, iniSectionCore) -} - -func IniReader(path string, compiler string, trustzone bool) (MxprojectAllType, error) { +func IniReader(path string, params []BridgeParamType) (MxprojectAllType, error) { var mxprojectAll MxprojectAllType if !utils.FileExists(path) { @@ -204,23 +145,17 @@ func IniReader(path string, compiler string, trustzone bool) (MxprojectAllType, return mxprojectAll, errors.New(text) } - var iniSections IniSectionsType + var iniSections []IniSectionsType err = GetSections(inidata, &iniSections) if err != nil { return mxprojectAll, err } - for _, core := range iniSections.cores { - // core := iniSections.cores[coreID] - iniName := core.iniName - if iniName == "Cortex" { // remove workaround for single-core .mxproject CubeMx files - iniName = "" - } - coreName := core.CoreName - trustzone := core.trustzone - mxproject, _ := GetData(inidata, iniName, compiler) - mxproject.CoreName = coreName - mxproject.Trustzone = trustzone + for _, param := range params { + context := param.CubeContext + + mxproject, _ := GetData(inidata, context, param.Compiler) + mxproject.Context = context mxprojectAll.Mxproject = append(mxprojectAll.Mxproject, mxproject) } @@ -239,45 +174,20 @@ func GetIni(path string) (*ini.File, error) { return inidata, nil } -func GetSections(inidata *ini.File, iniSections *IniSectionsType) error { +func GetSections(inidata *ini.File, iniSections *[]IniSectionsType) error { sectionsData := inidata.SectionStrings() for _, section := range sectionsData { - var iniName string - var sectionName string + var iniSection IniSectionsType sectionString := strings.Split(section, ":") if len(sectionString) > 1 { - iniName = sectionString[0] - sectionName = sectionString[1] + iniSection.Context = sectionString[0] + iniSection.Section = sectionString[1] } else { - iniName = "Cortex" // default - sectionName = section - } - - var coreName string - re := regexp.MustCompile("[0-9]+") - coreNameNumbers := re.FindAllString(iniName, -1) - if len(coreNameNumbers) == 1 { - coreName = "Cortex-M" + coreNameNumbers[0] - } - - var trustzone string - iniLen := len(iniName) - if iniLen > 0 { - if strings.LastIndex(iniName, "S") == iniLen-1 { - if strings.LastIndex(iniName, "NS") == iniLen-2 { - trustzone = "non-secure" - } else { - trustzone = "secure" - } - } + iniSection.Context = "" + iniSection.Section = section } - var iniSectionCore IniSectionCore - iniSectionCore.iniName = iniName - iniSectionCore.CoreName = coreName - iniSectionCore.trustzone = trustzone - AppendToCores(iniSectionCore, &iniSections.cores) - AppendToList(sectionName, &iniSections.sections) + *iniSections = append(*iniSections, iniSection) } return nil diff --git a/internal/stm32CubeMX/mxDevice.go b/internal/stm32CubeMX/mxDevice.go index cad77b1..fe3a26f 100644 --- a/internal/stm32CubeMX/mxDevice.go +++ b/internal/stm32CubeMX/mxDevice.go @@ -9,6 +9,7 @@ package stm32cubemx import ( "bufio" "errors" + "io/fs" "os" "path" "path/filepath" @@ -17,8 +18,6 @@ import ( "strconv" "strings" "time" - - "github.com/open-cmsis-pack/generator-bridge/internal/cbuild" ) type PinDefinition struct { @@ -31,7 +30,7 @@ type PinDefinition struct { alternate string } -func ReadContexts(iocFile string, params cbuild.ParamsType) error { +func ReadContexts(iocFile string, params []BridgeParamType) error { contextMap, err := createContextMap(iocFile) if err != nil { return err @@ -42,75 +41,46 @@ func ReadContexts(iocFile string, params cbuild.ParamsType) error { return err } - deviceFamily, err := getDeviceFamily(contextMap) - if err != nil { - return err - } - workDir := path.Dir(iocFile) mainFolder := contextMap["ProjectManager"]["MainLocation"] if mainFolder == "" { return errors.New("main location missing") } - mspName := deviceFamily + "xx_hal_msp.c" - var cfgPath string - if len(contexts) == 0 { - cfgPath = path.Join("MX_Device", params.Subsystem[0].SubsystemIdx.Project) - err := writeMXdeviceH(contextMap, workDir, mainFolder, mspName, cfgPath, "", params) - if err != nil { - return err - } - } else { - for _, context := range contexts { - var coreName string - var contextFolder string - var projectPart string - re := regexp.MustCompile("[0-9]+") - coreNameNumbers := re.FindAllString(context, -1) - if len(coreNameNumbers) == 1 { - coreName = "Cortex-M" + coreNameNumbers[0] - contextFolder = "CM" + coreNameNumbers[0] - projectPart = contextFolder - } + for _, context := range contexts { + for _, parm := range params { + if parm.CubeContext == context { + srcFolderPath := path.Join(path.Join(workDir, parm.CubeContextFolder), mainFolder) - var trustzone string - contextLen := len(context) - if contextLen > 0 { - if strings.LastIndex(context, "S") == contextLen-1 { - if strings.LastIndex(context, "NS") == contextLen-2 { - trustzone = "NonSecure" - projectPart = "non-secure" - } else { - trustzone = "Secure" - projectPart = "secure" + var mspName string + err = filepath.Walk(srcFolderPath, func(path string, f fs.FileInfo, err error) error { + if f.Mode().IsRegular() && strings.HasSuffix(f.Name(), "_hal_msp.c") { + mspName = filepath.Base(path) + return nil } - contextFolder = trustzone + return nil + }) + if err != nil { + return err + } + if mspName == "" { + return errors.New("*_hal_msp.c not found") } - } - if len(contextFolder) == 0 { - return errors.New("Cannot find context " + context) - } - for _, subsystem := range params.Subsystem { - if subsystem.CoreName == coreName { - if len(subsystem.TrustZone) == 0 { - cfgPath = path.Join("MX_Device", subsystem.SubsystemIdx.Project) - break - } - if subsystem.TrustZone == projectPart { - cfgPath = path.Join("MX_Device", subsystem.SubsystemIdx.Project) - break - } + var cfgPath string + cfgPath = path.Dir(workDir) + cfgPath = path.Join(cfgPath, "MX_Device") + cfgPath = path.Join(cfgPath, parm.ProjectName) + err := writeMXdeviceH(contextMap, srcFolderPath, mspName, cfgPath, context) + if err != nil { + return err } - } - err := writeMXdeviceH(contextMap, workDir, path.Join(contextFolder, mainFolder), mspName, cfgPath, context, params) - if err != nil { - return err + break } } } + return nil } @@ -141,20 +111,25 @@ func createContextMap(iocFile string) (map[string]map[string]string, error) { return contextMap, nil } -func writeMXdeviceH(contextMap map[string]map[string]string, workDir string, mainFolder string, mspName string, cfgPath string, context string, params cbuild.ParamsType) error { - workDirAbs, err := filepath.Abs(workDir) +func writeMXdeviceH(contextMap map[string]map[string]string, srcFolder string, mspName string, cfgPath string, context string) error { + + srcFolderAbs, err := filepath.Abs(srcFolder) if err != nil { return err } - main := path.Join(workDirAbs, mainFolder, "main.c") + main := path.Join(srcFolderAbs, "main.c") + main = filepath.Clean(main) + main = filepath.ToSlash(main) fMain, err := os.Open(main) if err != nil { return err } defer fMain.Close() - msp := path.Join(workDirAbs, mainFolder, mspName) + msp := path.Join(srcFolderAbs, mspName) + msp = filepath.Clean(msp) + msp = filepath.ToSlash(msp) fMsp, err := os.Open(msp) if err != nil { return err @@ -162,7 +137,8 @@ func writeMXdeviceH(contextMap map[string]map[string]string, workDir string, mai defer fMsp.Close() fName := "MX_Device.h" - fPath := path.Join(path.Dir(workDir), cfgPath) + fPath := filepath.Clean(cfgPath) + fPath = filepath.ToSlash(fPath) if _, err := os.Stat(fPath); err != nil { err = os.MkdirAll(fPath, 0750) if err != nil { @@ -170,6 +146,8 @@ func writeMXdeviceH(contextMap map[string]map[string]string, workDir string, mai } } fPath = path.Join(fPath, fName) + fPath = filepath.Clean(fPath) + fPath = filepath.ToSlash(fPath) fMxDevice, err := os.Create(fPath) if err != nil { return err @@ -267,17 +245,10 @@ func getContexts(contextMap map[string]map[string]string) (map[int]string, error } } } - return contexts, nil -} - -func getDeviceFamily(contextMap map[string]map[string]string) (string, error) { - family := contextMap["Mcu"]["Family"] - if family != "" { - if strings.HasPrefix(family, "STM32") { - return family, nil - } + if len(contexts) == 0 { + contexts[0] = "" } - return "", errors.New("missing device family") + return contexts, nil } func getPeripherals(contextMap map[string]map[string]string, context string) ([]string, error) { @@ -362,15 +333,6 @@ func getPins(contextMap map[string]map[string]string, fMsp *os.File, peripheral return pinsInfo, nil } -func replaceSpecialChars(label string, ch string) string { - specialCharacter := [...]string{"!", "@", "#", "$", "%", "^", "&", "*", "(", "+", "=", "-", "_", "[", "]", "{", "}", - ";", ":", ",", ".", "?", "/", "\\", "|", "~", "`", "\"", "'", "<", ">", " "} - for _, spec := range specialCharacter { - label = strings.ReplaceAll(label, spec, ch) - } - return label -} - func getDigitAtEnd(pin string) string { re := regexp.MustCompile("[0-9]+$") numbers := re.FindAllString(pin, -1) @@ -380,6 +342,15 @@ func getDigitAtEnd(pin string) string { return "" } +func replaceSpecialChars(label string, ch string) string { + specialCharacter := [...]string{"!", "@", "#", "$", "%", "^", "&", "*", "(", "+", "=", "-", "_", "[", "]", "{", "}", + ";", ":", ",", ".", "?", "/", "\\", "|", "~", "`", "\"", "'", "<", ">", " "} + for _, spec := range specialCharacter { + label = strings.ReplaceAll(label, spec, ch) + } + return label +} + // Get i2c info (filter, coefficients) func getI2cInfo(fMain *os.File, peripheral string) (map[string]string, error) { info := make(map[string]string) @@ -594,8 +565,13 @@ func mxDeviceWritePeripheralCfg(out *bufio.Writer, peripheral string, vmode stri if _, err = out.WriteString("/* Filter Settings */\n"); err != nil { return err } - for item, value := range i2cInfo { - if err = writeDefine(out, peripheral+"_"+item, value); err != nil { + var i2cInfoItems []string + for item := range i2cInfo { + i2cInfoItems = append(i2cInfoItems, item) + } + sort.Strings(i2cInfoItems) + for _, item := range i2cInfoItems { + if err = writeDefine(out, peripheral+"_"+item, i2cInfo[item]); err != nil { return err } } diff --git a/internal/stm32CubeMX/mxDevice_test.go b/internal/stm32CubeMX/mxDevice_test.go index 53586ad..79fb45f 100644 --- a/internal/stm32CubeMX/mxDevice_test.go +++ b/internal/stm32CubeMX/mxDevice_test.go @@ -15,8 +15,6 @@ import ( "reflect" "testing" "time" - - "github.com/open-cmsis-pack/generator-bridge/internal/cbuild" ) func Test_createContextMap(t *testing.T) { @@ -65,28 +63,26 @@ func Test_writeMXdeviceH(t *testing.T) { type args struct { contextMap map[string]map[string]string - workDir string - mainFolder string + srcFolder string mspName string cfgPath string context string - params cbuild.ParamsType } tests := []struct { name string args args wantErr bool }{ - {"Mcu", args{mcuContext2, "../../testdata/stm32cubemx", "", "test_msp.c", "cfg", "", cbuild.ParamsType{}}, false}, - {"wrong context", args{mcuContext0, "../../testdata/stm32cubemx", "", "test_msp.c", "cfg", "context", cbuild.ParamsType{}}, true}, - {"Mcu Context", args{mcuContext1, "../../testdata/stm32cubemx", "", "test_msp.c", "cfg", "Mcu", cbuild.ParamsType{}}, false}, - {"wrong myContext", args{mcuContext1, "../../testdata/stm32cubemx", "", "test_msp.c", "cfg", "context", cbuild.ParamsType{}}, true}, - {"wrong msp", args{mcuContext1, "", "", "msp", "cfg", "context", cbuild.ParamsType{}}, true}, + {"Mcu", args{mcuContext2, "../../testdata/stm32cubemx", "test_msp.c", "../../testdata/stm32cubemx/cfg", ""}, false}, + {"wrong context", args{mcuContext0, "../../testdata/stm32cubemx", "test_msp.c", "../../testdata/stm32cubemx/cfg", "context"}, true}, + {"Mcu Context", args{mcuContext1, "../../testdata/stm32cubemx", "test_msp.c", "../../testdata/stm32cubemx/cfg", "Mcu"}, false}, + {"wrong myContext", args{mcuContext1, "../../testdata/stm32cubemx", "test_msp.c", "../../testdata/stm32cubemx/cfg", "context"}, true}, + {"wrong msp", args{mcuContext1, "", "msp", "../../testdata/stm32cubemx/cfg", "context"}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - defer os.RemoveAll(tt.args.workDir + "/../" + tt.args.cfgPath) - if err := writeMXdeviceH(tt.args.contextMap, tt.args.workDir, tt.args.mainFolder, tt.args.mspName, tt.args.cfgPath, tt.args.context, tt.args.params); (err != nil) != tt.wantErr { + defer os.RemoveAll(tt.args.srcFolder + "/../" + tt.args.cfgPath) + if err := writeMXdeviceH(tt.args.contextMap, tt.args.srcFolder, tt.args.mspName, tt.args.cfgPath, tt.args.context); (err != nil) != tt.wantErr { t.Errorf("writeMXdeviceH() %s error = %v, wantErr %v", tt.name, err, tt.wantErr) } }) @@ -103,6 +99,7 @@ func Test_getContexts(t *testing.T) { mcuContext2["Mcu"] = map[string]string{"Context1": "myContext1", "Context2": "myContext2"} var oneEmpty = make(map[int]string) + oneEmpty[0] = "" var two1 = make(map[int]string) two1[1] = "myContext1" @@ -141,45 +138,6 @@ func Test_getContexts(t *testing.T) { } } -func Test_getDeviceFamily(t *testing.T) { - t.Parallel() - - var parts = make(map[string]map[string]string) - - parts["Mcu"] = map[string]string{"Family": "STM32U5"} - - var parts1 = make(map[string]map[string]string) - - parts1["Mcu"] = map[string]string{"xFamily": "STM32U5"} - - type args struct { - contextMap map[string]map[string]string - } - tests := []struct { - name string - args args - want string - wantErr bool - }{ - {"test", args{parts}, "STM32U5", false}, - {"fail", args{parts1}, "", true}, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - got, err := getDeviceFamily(tt.args.contextMap) - if (err != nil) != tt.wantErr { - t.Errorf("getDeviceFamily() %s error = %v, wantErr %v", tt.name, err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("getDeviceFamily() %s = %v, want %v", tt.name, got, tt.want) - } - }) - } -} - func Test_getPeripherals(t *testing.T) { // t.Parallel() diff --git a/internal/stm32CubeMX/stm32CubeMX.go b/internal/stm32CubeMX/stm32CubeMX.go index 514a6df..25e5f9a 100644 --- a/internal/stm32CubeMX/stm32CubeMX.go +++ b/internal/stm32CubeMX/stm32CubeMX.go @@ -26,6 +26,21 @@ import ( log "github.com/sirupsen/logrus" ) +type BridgeParamType struct { + Board string + Device string + Output string + ProjectName string + ProjectType string + ForProjectPart string + PairedSecurePart string + Compiler string + GeneratorMap string + CgenName string + CubeContext string + CubeContextFolder string +} + var watcher *fsnotify.Watcher var running bool // true if running in wait loop waiting for .ioc file @@ -76,17 +91,23 @@ func Process(cbuildYmlPath, outPath, cubeMxPath string, runCubeMx bool, pid int) } var parms cbuild.ParamsType - err = ReadCbuildYmlFile(cbuildYmlPath, outPath, &parms) + err = ReadCbuildYmlFile(cbuildYmlPath, "CubeMX", &parms) + if err != nil { + return err + } + + var bridgeParams []BridgeParamType + err = GetBridgeInfo(&parms, &bridgeParams) if err != nil { return err } workDir := path.Dir(cbuildYmlPath) - if parms.OutPath != "" { - if filepath.IsAbs(parms.OutPath) { - workDir = parms.OutPath + if parms.Output != "" { + if filepath.IsAbs(parms.Output) { + workDir = parms.Output } else { - workDir = path.Join(workDir, parms.OutPath) + workDir = path.Join(workDir, parms.Output) } } else { workDir = path.Join(workDir, outPath) @@ -138,12 +159,17 @@ func Process(cbuildYmlPath, outPath, cubeMxPath string, runCubeMx bool, pid int) time.Sleep(time.Second) } if i < 100 { - mxproject, err := IniReader(mxprojectPath, parms.Subsystem[0].Compiler, false) - if err == nil { - err = ReadContexts(iocprojectPath, parms) - if err == nil { - _ = WriteCgenYml(workDir, mxproject, parms) - } + mxproject, err := IniReader(mxprojectPath, bridgeParams) + if err != nil { + return err + } + err = ReadContexts(iocprojectPath, bridgeParams) + if err != nil { + return err + } + err = WriteCgenYml(workDir, mxproject, bridgeParams) + if err != nil { + return err } } } @@ -183,17 +209,15 @@ func Process(cbuildYmlPath, outPath, cubeMxPath string, runCubeMx bool, pid int) } } if i < 100 { - mxproject, err := IniReader(mxprojectPath, parms.Subsystem[0].Compiler, false) + mxproject, err := IniReader(mxprojectPath, bridgeParams) if err != nil { return } - - err = ReadContexts(iocprojectPath, parms) + err = ReadContexts(iocprojectPath, bridgeParams) if err != nil { return } - - err = WriteCgenYml(workDir, mxproject, parms) + err = WriteCgenYml(workDir, mxproject, bridgeParams) if err != nil { return } @@ -237,7 +261,7 @@ func Process(cbuildYmlPath, outPath, cubeMxPath string, runCubeMx bool, pid int) return errors.New("generator '" + gParms.ID + "' missing. Install from '" + gParms.DownloadURL + "'") } } else { - projectFile, err = WriteProjectFile(workDir, &parms) + projectFile, err = WriteProjectFile(workDir, bridgeParams[0]) if err != nil { return nil } @@ -294,19 +318,19 @@ func Launch(iocFile, projectFile string) (int, error) { return cmd.Process.Pid, nil } -func WriteProjectFile(workDir string, parms *cbuild.ParamsType) (string, error) { +func WriteProjectFile(workDir string, params BridgeParamType) (string, error) { filePath := filepath.Join(workDir, "project.script") log.Debugf("Writing CubeMX project file %v", filePath) var text utils.TextBuilder - if parms.Board != "" { - text.AddLine("loadboard", parms.Board, "allmodes") + if params.Board != "" { + text.AddLine("loadboard", params.Board, "allmodes") } else { - text.AddLine("load", parms.Device) + text.AddLine("load", params.Device) } text.AddLine("project name", "STM32CubeMX") - toolchain, err := GetToolchain(parms.Subsystem[0].Compiler) + toolchain, err := GetToolchain(params.Compiler) if err != nil { return "", err } @@ -331,9 +355,9 @@ func WriteProjectFile(workDir string, parms *cbuild.ParamsType) (string, error) return filePath, nil } -func ReadCbuildYmlFile(path, outPath string, parms *cbuild.ParamsType) error { +func ReadCbuildYmlFile(path, generatorID string, parms *cbuild.ParamsType) error { log.Debugf("Reading cbuild.yml file: '%v'", path) - err := cbuild.Read(path, outPath, parms) + err := cbuild.Read(path, generatorID, parms) if err != nil { return err } @@ -347,6 +371,75 @@ func ReadGeneratorYmlFile(path string, parms *generator.ParamsType) error { return err } +func GetBridgeInfo(parms *cbuild.ParamsType, bridgeParams *[]BridgeParamType) error { + var board string + var device string + var output string + var projectType string + + split := strings.SplitAfter(parms.Board, "::") + if len(split) == 2 { + board = split[1] + } else { + board = parms.Board + } + split = strings.Split(board, ":") + if len(split) == 2 { + board = split[0] + } + + device = parms.Device + projectType = parms.ProjectType + output = parms.Output + + for _, gen := range parms.CbuildGens { + var bparm BridgeParamType + + bparm.Board = board + bparm.Device = device + bparm.Output = output + bparm.ProjectName = gen.Project + bparm.ProjectType = projectType + bparm.ForProjectPart = gen.ForProjectPart + bparm.GeneratorMap = gen.Map + bparm.CgenName = gen.Name + bparm.Compiler = gen.CbuildGen.BuildGen.Compiler + if gen.Map != "" { + bparm.CubeContext = gen.Map + bparm.CubeContextFolder = gen.Map + } else { + switch parms.ProjectType { + case "single-core": + bparm.CubeContext = "" + bparm.CubeContextFolder = "" + case "multi-core": + core := gen.CbuildGen.BuildGen.Processor.Core + bparm.CubeContext = strings.ReplaceAll(core, "-", "") + bparm.CubeContextFolder = "C" + strings.Split(core, "-")[1] + case "trustzone": + core := gen.CbuildGen.BuildGen.Processor.Core + context := strings.ReplaceAll(core, "-", "") + if gen.ForProjectPart == "non-secure" { + bparm.CubeContext = context + "NS" + bparm.CubeContextFolder = "NonSecure" + for _, tmpGen := range parms.CbuildGens { + if tmpGen.ForProjectPart == "secure" { + bparm.PairedSecurePart = tmpGen.Project + break + } + } + } + if gen.ForProjectPart == "secure" { + bparm.CubeContext = context + "S" + bparm.CubeContextFolder = "Secure" + } + } + } + *bridgeParams = append(*bridgeParams, bparm) + } + return nil +} + var filterFiles = map[string]string{ "system_": "system_ file (already added)", "Templates": "Templates file (mostly not present)", @@ -364,7 +457,7 @@ func FilterFile(file string) bool { return false } -func FindMxProject(subsystem *cbuild.SubsystemType, mxprojectAll MxprojectAllType) (MxprojectType, error) { +func FindMxProject(context string, mxprojectAll MxprojectAllType) (MxprojectType, error) { if len(mxprojectAll.Mxproject) == 0 { return MxprojectType{}, errors.New("no .mxproject read") } else if len(mxprojectAll.Mxproject) == 1 { @@ -372,13 +465,8 @@ func FindMxProject(subsystem *cbuild.SubsystemType, mxprojectAll MxprojectAllTyp return mxproject, nil } - coreName := subsystem.CoreName - trustzone := subsystem.TrustZone - if trustzone == "off" { - trustzone = "" - } for _, mxproject := range mxprojectAll.Mxproject { - if mxproject.CoreName == coreName && mxproject.Trustzone == trustzone { + if mxproject.Context == context { return mxproject, nil } } @@ -386,15 +474,13 @@ func FindMxProject(subsystem *cbuild.SubsystemType, mxprojectAll MxprojectAllTyp return MxprojectType{}, nil } -func WriteCgenYml(outPath string, mxprojectAll MxprojectAllType, inParms cbuild.ParamsType) error { - for id := range inParms.Subsystem { - subsystem := &inParms.Subsystem[id] - - mxproject, err := FindMxProject(subsystem, mxprojectAll) +func WriteCgenYml(outPath string, mxprojectAll MxprojectAllType, bridgeParams []BridgeParamType) error { + for _, parm := range bridgeParams { + mxproject, err := FindMxProject(parm.CubeContext, mxprojectAll) if err != nil { continue } - err = WriteCgenYmlSub(outPath, mxproject, subsystem) + err = WriteCgenYmlSub(outPath, mxproject, parm) if err != nil { return err } @@ -403,18 +489,16 @@ func WriteCgenYml(outPath string, mxprojectAll MxprojectAllType, inParms cbuild. return nil } -func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild.SubsystemType) error { - outName := subsystem.SubsystemIdx.Project + ".cgen.yml" - outFile := path.Join(outPath, outName) +func WriteCgenYmlSub(outPath string, mxproject MxprojectType, bridgeParam BridgeParamType) error { var cgen cbuild.CgenType - relativePathAdd, err := GetRelativePathAdd(outPath, subsystem.Compiler) + relativePathAdd, err := GetRelativePathAdd(outPath, bridgeParam.Compiler) if err != nil { return err } - cgen.GeneratorImport.ForBoard = subsystem.Board - cgen.GeneratorImport.ForDevice = subsystem.Device + cgen.GeneratorImport.ForBoard = bridgeParam.Board + cgen.GeneratorImport.ForDevice = bridgeParam.Device cgen.GeneratorImport.Define = append(cgen.GeneratorImport.Define, mxproject.PreviousUsedFiles.CDefines...) for _, headerPath := range mxproject.PreviousUsedFiles.HeaderPath { @@ -425,7 +509,7 @@ func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild. cgen.GeneratorImport.AddPath = append(cgen.GeneratorImport.AddPath, headerPath) } - cfgPath := path.Join("MX_Device", subsystem.SubsystemIdx.Project) + cfgPath := path.Join("MX_Device", bridgeParam.ProjectName) cfgPath, _ = utils.ConvertFilename(outPath, cfgPath, "") cgen.GeneratorImport.AddPath = append(cgen.GeneratorImport.AddPath, cfgPath) @@ -454,7 +538,7 @@ func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild. } var cgenFile cbuild.CgenFilesType - startupFile, err := GetStartupFile(outPath, subsystem) + startupFile, err := GetStartupFile(outPath, bridgeParam) if err != nil { return err } @@ -465,7 +549,7 @@ func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild. cgenFile.File = startupFile groupSrc.Files = append(groupSrc.Files, cgenFile) - systemFile, err := GetSystemFile(outPath, subsystem) + systemFile, err := GetSystemFile(outPath, bridgeParam) if err != nil { return err } @@ -476,7 +560,7 @@ func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild. cgenFile.File = systemFile groupSrc.Files = append(groupSrc.Files, cgenFile) - linkerFiles, err := GetLinkerScripts(outPath, subsystem) + linkerFiles, err := GetLinkerScripts(outPath, bridgeParam) if err != nil { return err } @@ -493,17 +577,17 @@ func WriteCgenYmlSub(outPath string, mxproject MxprojectType, subsystem *cbuild. cgen.GeneratorImport.Groups = append(cgen.GeneratorImport.Groups, groupSrc) cgen.GeneratorImport.Groups = append(cgen.GeneratorImport.Groups, groupHalDriver) - if subsystem.TrustZone == "non-secure" { + if bridgeParam.ForProjectPart == "non-secure" { groupTz.Group = "CMSE Library" var cgenFile cbuild.CgenFilesType cgenFile.File = "$cmse-lib(" - cgenFile.File += subsystem.SubsystemIdx.SecureContextName + cgenFile.File += bridgeParam.PairedSecurePart cgenFile.File += ")$" groupTz.Files = append(groupTz.Files, cgenFile) cgen.GeneratorImport.Groups = append(cgen.GeneratorImport.Groups, groupTz) } - return common.WriteYml(outFile, &cgen) + return common.WriteYml(bridgeParam.CgenName, &cgen) } func GetToolchain(compiler string) (string, error) { @@ -567,32 +651,32 @@ func GetToolchainFolderPath(outPath string, compiler string) (string, error) { return toolchainFolderPath, nil } -func GetStartupFile(outPath string, subsystem *cbuild.SubsystemType) (string, error) { +func GetStartupFile(outPath string, bridgeParams BridgeParamType) (string, error) { var startupFolder string var fileExtesion string var fileFilter string - startupFolder, err := GetToolchainFolderPath(outPath, subsystem.Compiler) + startupFolder, err := GetToolchainFolderPath(outPath, bridgeParams.Compiler) if err != nil { return "", err } fileExtesion = ".s" - switch subsystem.Compiler { + switch bridgeParams.Compiler { case "AC6", "IAR": - if subsystem.SubsystemIdx.ProjectType == "multi-core" { - fileFilter = "_" + subsystem.SubsystemIdx.ForProjectPart + if bridgeParams.ProjectType == "multi-core" { + fileFilter = "_" + bridgeParams.ForProjectPart } case "GCC", "CLANG": - switch subsystem.SubsystemIdx.ProjectType { + switch bridgeParams.ProjectType { case "multi-core": - startupFolder = path.Join(startupFolder, subsystem.SubsystemIdx.ForProjectPart) + startupFolder = path.Join(startupFolder, bridgeParams.ForProjectPart) case "trustzone": - if subsystem.SubsystemIdx.ForProjectPart == "secure" { + if bridgeParams.ForProjectPart == "secure" { startupFolder = path.Join(startupFolder, "Secure") } - if subsystem.SubsystemIdx.ForProjectPart == "non-secure" { + if bridgeParams.ForProjectPart == "non-secure" { startupFolder = path.Join(startupFolder, "NonSecure") } } @@ -634,16 +718,16 @@ func GetStartupFile(outPath string, subsystem *cbuild.SubsystemType) (string, er return startupFile, err } -func GetSystemFile(outPath string, subsystem *cbuild.SubsystemType) (string, error) { +func GetSystemFile(outPath string, bridgeParams BridgeParamType) (string, error) { var toolchainFolder string var systemFolder string - toolchainFolder, err := GetToolchainFolderPath(outPath, subsystem.Compiler) + toolchainFolder, err := GetToolchainFolderPath(outPath, bridgeParams.Compiler) if err != nil { return "", err } - if subsystem.SubsystemIdx.ProjectType == "multi-core" { + if bridgeParams.ProjectType == "multi-core" { systemFolder = filepath.Dir(toolchainFolder) systemFolder = path.Join(systemFolder, "Common") systemFolder = path.Join(systemFolder, "Src") @@ -654,14 +738,19 @@ func GetSystemFile(outPath string, subsystem *cbuild.SubsystemType) (string, err if systemFolder == "" { systemFolder = filepath.Dir(toolchainFolder) - switch subsystem.SubsystemIdx.ProjectType { + + if bridgeParams.GeneratorMap != "" { + systemFolder = path.Join(systemFolder, bridgeParams.GeneratorMap) + } + + switch bridgeParams.ProjectType { case "multi-core": - systemFolder = path.Join(systemFolder, subsystem.SubsystemIdx.ForProjectPart) + systemFolder = path.Join(systemFolder, bridgeParams.ForProjectPart) case "trustzone": - if subsystem.SubsystemIdx.ForProjectPart == "secure" { + if bridgeParams.ForProjectPart == "secure" { systemFolder = path.Join(systemFolder, "Secure") } - if subsystem.SubsystemIdx.ForProjectPart == "non-secure" { + if bridgeParams.ForProjectPart == "non-secure" { systemFolder = path.Join(systemFolder, "NonSecure") } } @@ -693,17 +782,17 @@ func GetSystemFile(outPath string, subsystem *cbuild.SubsystemType) (string, err return systemFile, err } -func GetLinkerScripts(outPath string, subsystem *cbuild.SubsystemType) ([]string, error) { +func GetLinkerScripts(outPath string, bridgeParams BridgeParamType) ([]string, error) { var linkerFolder string var fileExtesion string var fileFilter string - linkerFolder, err := GetToolchainFolderPath(outPath, subsystem.Compiler) + linkerFolder, err := GetToolchainFolderPath(outPath, bridgeParams.Compiler) if err != nil { return nil, err } - switch subsystem.Compiler { + switch bridgeParams.Compiler { case "AC6": fileExtesion = ".sct" case "IAR": @@ -714,31 +803,35 @@ func GetLinkerScripts(outPath string, subsystem *cbuild.SubsystemType) ([]string return nil, errors.New("unknown compiler") } - switch subsystem.Compiler { + if bridgeParams.GeneratorMap != "" { + linkerFolder = path.Join(linkerFolder, bridgeParams.GeneratorMap) + } + + switch bridgeParams.Compiler { case "AC6", "IAR": - switch subsystem.SubsystemIdx.ProjectType { + switch bridgeParams.ProjectType { case "single-core": fileFilter = "" case "multi-core": - fileFilter = "_" + subsystem.SubsystemIdx.ForProjectPart + fileFilter = "_" + bridgeParams.ForProjectPart case "trustzone": - if subsystem.SubsystemIdx.ForProjectPart == "secure" { + if bridgeParams.ForProjectPart == "secure" { fileFilter = "_s." } - if subsystem.SubsystemIdx.ForProjectPart == "non-secure" { + if bridgeParams.ForProjectPart == "non-secure" { fileFilter = "_ns." } } case "GCC", "CLANG": - switch subsystem.SubsystemIdx.ProjectType { + switch bridgeParams.ProjectType { case "multi-core": - linkerFolder = path.Join(linkerFolder, subsystem.SubsystemIdx.ForProjectPart) + linkerFolder = path.Join(linkerFolder, bridgeParams.ForProjectPart) case "trustzone": - if subsystem.SubsystemIdx.ForProjectPart == "secure" { + if bridgeParams.ForProjectPart == "secure" { linkerFolder = path.Join(linkerFolder, "Secure") } - if subsystem.SubsystemIdx.ForProjectPart == "non-secure" { + if bridgeParams.ForProjectPart == "non-secure" { linkerFolder = path.Join(linkerFolder, "NonSecure") } } diff --git a/internal/stm32CubeMX/stm32CubeMX_test.go b/internal/stm32CubeMX/stm32CubeMX_test.go index 43e795d..12df530 100644 --- a/internal/stm32CubeMX/stm32CubeMX_test.go +++ b/internal/stm32CubeMX/stm32CubeMX_test.go @@ -10,8 +10,6 @@ import ( "path/filepath" "reflect" "testing" - - "github.com/open-cmsis-pack/generator-bridge/internal/cbuild" ) func Test_GetToolchain(t *testing.T) { @@ -131,71 +129,71 @@ func Test_GetStartupFile(t *testing.T) { // Single core outPathSC := "../../testdata/testExamples/STM32H7_SC/STM32CubeMX/device" - var subsystemScAC6 cbuild.SubsystemType - subsystemScAC6.Compiler = "AC6" - subsystemScAC6.SubsystemIdx.ProjectType = "single-core" - subsystemScAC6.SubsystemIdx.ForProjectPart = "" - var subsystemScGCC cbuild.SubsystemType - subsystemScGCC.Compiler = "GCC" - subsystemScGCC.SubsystemIdx.ProjectType = "single-core" - subsystemScGCC.SubsystemIdx.ForProjectPart = "" - var subsystemScCLANG cbuild.SubsystemType - subsystemScCLANG.Compiler = "CLANG" - subsystemScCLANG.SubsystemIdx.ProjectType = "single-core" - subsystemScCLANG.SubsystemIdx.ForProjectPart = "" - var subsystemScIAR cbuild.SubsystemType - subsystemScIAR.Compiler = "IAR" - subsystemScIAR.SubsystemIdx.ProjectType = "single-core" - subsystemScIAR.SubsystemIdx.ForProjectPart = "" + var infoScAC6 BridgeParamType + infoScAC6.Compiler = "AC6" + infoScAC6.ProjectType = "single-core" + infoScAC6.ForProjectPart = "" + var infoScGCC BridgeParamType + infoScGCC.Compiler = "GCC" + infoScGCC.ProjectType = "single-core" + infoScGCC.ForProjectPart = "" + var infoScCLANG BridgeParamType + infoScCLANG.Compiler = "CLANG" + infoScCLANG.ProjectType = "single-core" + infoScCLANG.ForProjectPart = "" + var infoScIAR BridgeParamType + infoScIAR.Compiler = "IAR" + infoScIAR.ProjectType = "single-core" + infoScIAR.ForProjectPart = "" // Multi core outPathDC := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx" - var subsystemDcAC6 cbuild.SubsystemType - subsystemDcAC6.Compiler = "AC6" - subsystemDcAC6.SubsystemIdx.ProjectType = "multi-core" - subsystemDcAC6.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcGCC cbuild.SubsystemType - subsystemDcGCC.Compiler = "GCC" - subsystemDcGCC.SubsystemIdx.ProjectType = "multi-core" - subsystemDcGCC.SubsystemIdx.ForProjectPart = "CM7" - var subsystemDcCLANG cbuild.SubsystemType - subsystemDcCLANG.Compiler = "CLANG" - subsystemDcCLANG.SubsystemIdx.ProjectType = "multi-core" - subsystemDcCLANG.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcIAR cbuild.SubsystemType - subsystemDcIAR.Compiler = "IAR" - subsystemDcIAR.SubsystemIdx.ProjectType = "multi-core" - subsystemDcIAR.SubsystemIdx.ForProjectPart = "CM7" + var infoDcAC6 BridgeParamType + infoDcAC6.Compiler = "AC6" + infoDcAC6.ProjectType = "multi-core" + infoDcAC6.ForProjectPart = "CM4" + var infoDcGCC BridgeParamType + infoDcGCC.Compiler = "GCC" + infoDcGCC.ProjectType = "multi-core" + infoDcGCC.ForProjectPart = "CM7" + var infoDcCLANG BridgeParamType + infoDcCLANG.Compiler = "CLANG" + infoDcCLANG.ProjectType = "multi-core" + infoDcCLANG.ForProjectPart = "CM4" + var infoDcIAR BridgeParamType + infoDcIAR.Compiler = "IAR" + infoDcIAR.ProjectType = "multi-core" + infoDcIAR.ForProjectPart = "CM7" // secure nonsecure outPathTZ := "../../testdata/testExamples/STM32U5_TZ/STM32CubeMX/Board" - var subsystemTzAC6 cbuild.SubsystemType - subsystemTzAC6.Compiler = "AC6" - subsystemTzAC6.SubsystemIdx.ProjectType = "trustzone" - subsystemTzAC6.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzGCC cbuild.SubsystemType - subsystemTzGCC.Compiler = "GCC" - subsystemTzGCC.SubsystemIdx.ProjectType = "trustzone" - subsystemTzGCC.SubsystemIdx.ForProjectPart = "non-secure" - var subsystemTzCLANG cbuild.SubsystemType - subsystemTzCLANG.Compiler = "CLANG" - subsystemTzCLANG.SubsystemIdx.ProjectType = "trustzone" - subsystemTzCLANG.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzIAR cbuild.SubsystemType - subsystemTzIAR.Compiler = "IAR" - subsystemTzIAR.SubsystemIdx.ProjectType = "trustzone" - subsystemTzIAR.SubsystemIdx.ForProjectPart = "non-secure" + var infoTzAC6 BridgeParamType + infoTzAC6.Compiler = "AC6" + infoTzAC6.ProjectType = "trustzone" + infoTzAC6.ForProjectPart = "secure" + var infoTzGCC BridgeParamType + infoTzGCC.Compiler = "GCC" + infoTzGCC.ProjectType = "trustzone" + infoTzGCC.ForProjectPart = "non-secure" + var infoTzCLANG BridgeParamType + infoTzCLANG.Compiler = "CLANG" + infoTzCLANG.ProjectType = "trustzone" + infoTzCLANG.ForProjectPart = "secure" + var infoTzIAR BridgeParamType + infoTzIAR.Compiler = "IAR" + infoTzIAR.ProjectType = "trustzone" + infoTzIAR.ForProjectPart = "non-secure" // invalid outPathInv := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx/invalid_folder" - var subsystemInv cbuild.SubsystemType - subsystemInv.Compiler = "AC6" - subsystemInv.SubsystemIdx.ProjectType = "single-core" - subsystemInv.SubsystemIdx.ForProjectPart = "" + var infoInv BridgeParamType + infoInv.Compiler = "AC6" + infoInv.ProjectType = "single-core" + infoInv.ForProjectPart = "" type args struct { - outPath string - subsystem cbuild.SubsystemType + outPath string + info BridgeParamType } tests := []struct { name string @@ -203,28 +201,28 @@ func Test_GetStartupFile(t *testing.T) { want string wantErr bool }{ - {"test_sc_ac6", args{outPathSC, subsystemScAC6}, filepath.Clean(outPathSC + "/STM32CubeMX/MDK-ARM/startup_stm32h743xx.s"), false}, - {"test_sc_gcc", args{outPathSC, subsystemScGCC}, filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/Application/Startup/startup_stm32h743agix.s"), false}, - {"test_sc_clang", args{outPathSC, subsystemScCLANG}, filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/Application/Startup/startup_stm32h743agix.s"), false}, - {"test_sc_iar", args{outPathSC, subsystemScIAR}, filepath.Clean(outPathSC + "/STM32CubeMX/EWARM/startup_stm32h743xx.s"), false}, + {"test_sc_ac6", args{outPathSC, infoScAC6}, filepath.Clean(outPathSC + "/STM32CubeMX/MDK-ARM/startup_stm32h743xx.s"), false}, + {"test_sc_gcc", args{outPathSC, infoScGCC}, filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/Application/Startup/startup_stm32h743agix.s"), false}, + {"test_sc_clang", args{outPathSC, infoScCLANG}, filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/Application/Startup/startup_stm32h743agix.s"), false}, + {"test_sc_iar", args{outPathSC, infoScIAR}, filepath.Clean(outPathSC + "/STM32CubeMX/EWARM/startup_stm32h743xx.s"), false}, - {"test_dc_ac6", args{outPathDC, subsystemDcAC6}, filepath.Clean(outPathDC + "/STM32CubeMX/MDK-ARM/startup_stm32h745xx_CM4.s"), false}, - {"test_dc_gcc", args{outPathDC, subsystemDcGCC}, filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM7/Application/Startup/startup_stm32h745bgtx.s"), false}, - {"test_dc_clang", args{outPathDC, subsystemDcCLANG}, filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM4/Application/Startup/startup_stm32h745bgtx.s"), false}, - {"test_dc_iar", args{outPathDC, subsystemDcIAR}, filepath.Clean(outPathDC + "/STM32CubeMX/EWARM/startup_stm32h745xx_CM7.s"), false}, + {"test_dc_ac6", args{outPathDC, infoDcAC6}, filepath.Clean(outPathDC + "/STM32CubeMX/MDK-ARM/startup_stm32h745xx_CM4.s"), false}, + {"test_dc_gcc", args{outPathDC, infoDcGCC}, filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM7/Application/Startup/startup_stm32h745bgtx.s"), false}, + {"test_dc_clang", args{outPathDC, infoDcCLANG}, filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM4/Application/Startup/startup_stm32h745bgtx.s"), false}, + {"test_dc_iar", args{outPathDC, infoDcIAR}, filepath.Clean(outPathDC + "/STM32CubeMX/EWARM/startup_stm32h745xx_CM7.s"), false}, - {"test_tz_ac6", args{outPathTZ, subsystemTzAC6}, filepath.Clean(outPathTZ + "/STM32CubeMX/MDK-ARM/startup_stm32u585xx.s"), false}, - {"test_tz_gcc", args{outPathTZ, subsystemTzGCC}, filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/NonSecure/Application/Startup/startup_stm32u585aiixq.s"), false}, - {"test_tz_clang", args{outPathTZ, subsystemTzCLANG}, filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/Secure/Application/Startup/startup_stm32u585aiixq.s"), false}, - {"test_tz_iar", args{outPathTZ, subsystemTzIAR}, filepath.Clean(outPathTZ + "/STM32CubeMX/EWARM/startup_stm32u585xx.s"), false}, + {"test_tz_ac6", args{outPathTZ, infoTzAC6}, filepath.Clean(outPathTZ + "/STM32CubeMX/MDK-ARM/startup_stm32u585xx.s"), false}, + {"test_tz_gcc", args{outPathTZ, infoTzGCC}, filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/NonSecure/Application/Startup/startup_stm32u585aiixq.s"), false}, + {"test_tz_clang", args{outPathTZ, infoTzCLANG}, filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/Secure/Application/Startup/startup_stm32u585aiixq.s"), false}, + {"test_tz_iar", args{outPathTZ, infoTzIAR}, filepath.Clean(outPathTZ + "/STM32CubeMX/EWARM/startup_stm32u585xx.s"), false}, - {"fail", args{outPathInv, subsystemInv}, "", true}} + {"fail", args{outPathInv, infoInv}, "", true}} for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - got, err := GetStartupFile(tt.args.outPath, &tt.args.subsystem) + got, err := GetStartupFile(tt.args.outPath, tt.args.info) if (err != nil) != tt.wantErr { t.Errorf("GetStartupFile() %s error = %v, wantErr %v", tt.name, err, tt.wantErr) return @@ -241,71 +239,71 @@ func Test_GetSystemFile(t *testing.T) { // Single core outPathSC := "../../testdata/testExamples/STM32H7_SC/STM32CubeMX/device" - var subsystemScAC6 cbuild.SubsystemType - subsystemScAC6.Compiler = "AC6" - subsystemScAC6.SubsystemIdx.ProjectType = "single-core" - subsystemScAC6.SubsystemIdx.ForProjectPart = "" - var subsystemScGCC cbuild.SubsystemType - subsystemScGCC.Compiler = "GCC" - subsystemScGCC.SubsystemIdx.ProjectType = "single-core" - subsystemScGCC.SubsystemIdx.ForProjectPart = "" - var subsystemScCLANG cbuild.SubsystemType - subsystemScCLANG.Compiler = "CLANG" - subsystemScCLANG.SubsystemIdx.ProjectType = "single-core" - subsystemScCLANG.SubsystemIdx.ForProjectPart = "" - var subsystemScIAR cbuild.SubsystemType - subsystemScIAR.Compiler = "IAR" - subsystemScIAR.SubsystemIdx.ProjectType = "single-core" - subsystemScIAR.SubsystemIdx.ForProjectPart = "" + var infoScAC6 BridgeParamType + infoScAC6.Compiler = "AC6" + infoScAC6.ProjectType = "single-core" + infoScAC6.ForProjectPart = "" + var infoScGCC BridgeParamType + infoScGCC.Compiler = "GCC" + infoScGCC.ProjectType = "single-core" + infoScGCC.ForProjectPart = "" + var infoScCLANG BridgeParamType + infoScCLANG.Compiler = "CLANG" + infoScCLANG.ProjectType = "single-core" + infoScCLANG.ForProjectPart = "" + var infoScIAR BridgeParamType + infoScIAR.Compiler = "IAR" + infoScIAR.ProjectType = "single-core" + infoScIAR.ForProjectPart = "" // Multi core outPathDC := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx" - var subsystemDcAC6 cbuild.SubsystemType - subsystemDcAC6.Compiler = "AC6" - subsystemDcAC6.SubsystemIdx.ProjectType = "multi-core" - subsystemDcAC6.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcGCC cbuild.SubsystemType - subsystemDcGCC.Compiler = "GCC" - subsystemDcGCC.SubsystemIdx.ProjectType = "multi-core" - subsystemDcGCC.SubsystemIdx.ForProjectPart = "CM7" - var subsystemDcCLANG cbuild.SubsystemType - subsystemDcCLANG.Compiler = "CLANG" - subsystemDcCLANG.SubsystemIdx.ProjectType = "multi-core" - subsystemDcCLANG.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcIAR cbuild.SubsystemType - subsystemDcIAR.Compiler = "IAR" - subsystemDcIAR.SubsystemIdx.ProjectType = "multi-core" - subsystemDcIAR.SubsystemIdx.ForProjectPart = "CM7" + var infoDcAC6 BridgeParamType + infoDcAC6.Compiler = "AC6" + infoDcAC6.ProjectType = "multi-core" + infoDcAC6.ForProjectPart = "CM4" + var infoDcGCC BridgeParamType + infoDcGCC.Compiler = "GCC" + infoDcGCC.ProjectType = "multi-core" + infoDcGCC.ForProjectPart = "CM7" + var infoDcCLANG BridgeParamType + infoDcCLANG.Compiler = "CLANG" + infoDcCLANG.ProjectType = "multi-core" + infoDcCLANG.ForProjectPart = "CM4" + var infoDcIAR BridgeParamType + infoDcIAR.Compiler = "IAR" + infoDcIAR.ProjectType = "multi-core" + infoDcIAR.ForProjectPart = "CM7" // secure nonsecure outPathTZ := "../../testdata/testExamples/STM32U5_TZ/STM32CubeMX/Board" - var subsystemTzAC6 cbuild.SubsystemType - subsystemTzAC6.Compiler = "AC6" - subsystemTzAC6.SubsystemIdx.ProjectType = "trustzone" - subsystemTzAC6.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzGCC cbuild.SubsystemType - subsystemTzGCC.Compiler = "GCC" - subsystemTzGCC.SubsystemIdx.ProjectType = "trustzone" - subsystemTzGCC.SubsystemIdx.ForProjectPart = "non-secure" - var subsystemTzCLANG cbuild.SubsystemType - subsystemTzCLANG.Compiler = "CLANG" - subsystemTzCLANG.SubsystemIdx.ProjectType = "trustzone" - subsystemTzCLANG.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzIAR cbuild.SubsystemType - subsystemTzIAR.Compiler = "IAR" - subsystemTzIAR.SubsystemIdx.ProjectType = "trustzone" - subsystemTzIAR.SubsystemIdx.ForProjectPart = "non-secure" + var infoTzAC6 BridgeParamType + infoTzAC6.Compiler = "AC6" + infoTzAC6.ProjectType = "trustzone" + infoTzAC6.ForProjectPart = "secure" + var infoTzGCC BridgeParamType + infoTzGCC.Compiler = "GCC" + infoTzGCC.ProjectType = "trustzone" + infoTzGCC.ForProjectPart = "non-secure" + var infoTzCLANG BridgeParamType + infoTzCLANG.Compiler = "CLANG" + infoTzCLANG.ProjectType = "trustzone" + infoTzCLANG.ForProjectPart = "secure" + var infoTzIAR BridgeParamType + infoTzIAR.Compiler = "IAR" + infoTzIAR.ProjectType = "trustzone" + infoTzIAR.ForProjectPart = "non-secure" // invalid outPathInv := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx/invalid_folder" - var subsystemInv cbuild.SubsystemType - subsystemInv.Compiler = "AC6" - subsystemInv.SubsystemIdx.ProjectType = "single-core" - subsystemInv.SubsystemIdx.ForProjectPart = "" + var infoInv BridgeParamType + infoInv.Compiler = "AC6" + infoInv.ProjectType = "single-core" + infoInv.ForProjectPart = "" type args struct { - outPath string - subsystem cbuild.SubsystemType + outPath string + info BridgeParamType } tests := []struct { name string @@ -313,28 +311,28 @@ func Test_GetSystemFile(t *testing.T) { want string wantErr bool }{ - {"test_sc_ac6", args{outPathSC, subsystemScAC6}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, - {"test_sc_gcc", args{outPathSC, subsystemScGCC}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, - {"test_sc_clang", args{outPathSC, subsystemScCLANG}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, - {"test_sc_iar", args{outPathSC, subsystemScIAR}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, + {"test_sc_ac6", args{outPathSC, infoScAC6}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, + {"test_sc_gcc", args{outPathSC, infoScGCC}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, + {"test_sc_clang", args{outPathSC, infoScCLANG}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, + {"test_sc_iar", args{outPathSC, infoScIAR}, filepath.Clean(outPathSC + "/STM32CubeMX/Src/system_stm32h7xx.c"), false}, - {"test_dc_ac6", args{outPathDC, subsystemDcAC6}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, - {"test_dc_gcc", args{outPathDC, subsystemDcGCC}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, - {"test_dc_clang", args{outPathDC, subsystemDcCLANG}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, - {"test_dc_iar", args{outPathDC, subsystemDcIAR}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, + {"test_dc_ac6", args{outPathDC, infoDcAC6}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, + {"test_dc_gcc", args{outPathDC, infoDcGCC}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, + {"test_dc_clang", args{outPathDC, infoDcCLANG}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, + {"test_dc_iar", args{outPathDC, infoDcIAR}, filepath.Clean(outPathDC + "/STM32CubeMX/Common/Src/system_stm32h7xx_dualcore_boot_cm4_cm7.c"), false}, - {"test_tz_ac6", args{outPathTZ, subsystemTzAC6}, filepath.Clean(outPathTZ + "/STM32CubeMX/Secure/Src/system_stm32u5xx_s.c"), false}, - {"test_tz_gcc", args{outPathTZ, subsystemTzGCC}, filepath.Clean(outPathTZ + "/STM32CubeMX/NonSecure/Src/system_stm32u5xx_ns.c"), false}, - {"test_tz_clang", args{outPathTZ, subsystemTzCLANG}, filepath.Clean(outPathTZ + "/STM32CubeMX/Secure/Src/system_stm32u5xx_s.c"), false}, - {"test_tz_iar", args{outPathTZ, subsystemTzIAR}, filepath.Clean(outPathTZ + "/STM32CubeMX/NonSecure/Src/system_stm32u5xx_ns.c"), false}, + {"test_tz_ac6", args{outPathTZ, infoTzAC6}, filepath.Clean(outPathTZ + "/STM32CubeMX/Secure/Src/system_stm32u5xx_s.c"), false}, + {"test_tz_gcc", args{outPathTZ, infoTzGCC}, filepath.Clean(outPathTZ + "/STM32CubeMX/NonSecure/Src/system_stm32u5xx_ns.c"), false}, + {"test_tz_clang", args{outPathTZ, infoTzCLANG}, filepath.Clean(outPathTZ + "/STM32CubeMX/Secure/Src/system_stm32u5xx_s.c"), false}, + {"test_tz_iar", args{outPathTZ, infoTzIAR}, filepath.Clean(outPathTZ + "/STM32CubeMX/NonSecure/Src/system_stm32u5xx_ns.c"), false}, - {"fail", args{outPathInv, subsystemInv}, "", true}} + {"fail", args{outPathInv, infoInv}, "", true}} for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - got, err := GetSystemFile(tt.args.outPath, &tt.args.subsystem) + got, err := GetSystemFile(tt.args.outPath, tt.args.info) if (err != nil) != tt.wantErr { t.Errorf("GetSystemFile() %s error = %v, wantErr %v", tt.name, err, tt.wantErr) return @@ -351,71 +349,71 @@ func Test_GetLinkerScripts(t *testing.T) { // Single core outPathSC := "../../testdata/testExamples/STM32H7_SC/STM32CubeMX/device" - var subsystemScAC6 cbuild.SubsystemType - subsystemScAC6.Compiler = "AC6" - subsystemScAC6.SubsystemIdx.ProjectType = "single-core" - subsystemScAC6.SubsystemIdx.ForProjectPart = "" - var subsystemScGCC cbuild.SubsystemType - subsystemScGCC.Compiler = "GCC" - subsystemScGCC.SubsystemIdx.ProjectType = "single-core" - subsystemScGCC.SubsystemIdx.ForProjectPart = "" - var subsystemScCLANG cbuild.SubsystemType - subsystemScCLANG.Compiler = "CLANG" - subsystemScCLANG.SubsystemIdx.ProjectType = "single-core" - subsystemScCLANG.SubsystemIdx.ForProjectPart = "" - var subsystemScIAR cbuild.SubsystemType - subsystemScIAR.Compiler = "IAR" - subsystemScIAR.SubsystemIdx.ProjectType = "single-core" - subsystemScIAR.SubsystemIdx.ForProjectPart = "" + var infoScAC6 BridgeParamType + infoScAC6.Compiler = "AC6" + infoScAC6.ProjectType = "single-core" + infoScAC6.ForProjectPart = "" + var infoScGCC BridgeParamType + infoScGCC.Compiler = "GCC" + infoScGCC.ProjectType = "single-core" + infoScGCC.ForProjectPart = "" + var infoScCLANG BridgeParamType + infoScCLANG.Compiler = "CLANG" + infoScCLANG.ProjectType = "single-core" + infoScCLANG.ForProjectPart = "" + var infoScIAR BridgeParamType + infoScIAR.Compiler = "IAR" + infoScIAR.ProjectType = "single-core" + infoScIAR.ForProjectPart = "" // Multi core outPathDC := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx" - var subsystemDcAC6 cbuild.SubsystemType - subsystemDcAC6.Compiler = "AC6" - subsystemDcAC6.SubsystemIdx.ProjectType = "multi-core" - subsystemDcAC6.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcGCC cbuild.SubsystemType - subsystemDcGCC.Compiler = "GCC" - subsystemDcGCC.SubsystemIdx.ProjectType = "multi-core" - subsystemDcGCC.SubsystemIdx.ForProjectPart = "CM7" - var subsystemDcCLANG cbuild.SubsystemType - subsystemDcCLANG.Compiler = "CLANG" - subsystemDcCLANG.SubsystemIdx.ProjectType = "multi-core" - subsystemDcCLANG.SubsystemIdx.ForProjectPart = "CM4" - var subsystemDcIAR cbuild.SubsystemType - subsystemDcIAR.Compiler = "IAR" - subsystemDcIAR.SubsystemIdx.ProjectType = "multi-core" - subsystemDcIAR.SubsystemIdx.ForProjectPart = "CM7" + var infoDcAC6 BridgeParamType + infoDcAC6.Compiler = "AC6" + infoDcAC6.ProjectType = "multi-core" + infoDcAC6.ForProjectPart = "CM4" + var infoDcGCC BridgeParamType + infoDcGCC.Compiler = "GCC" + infoDcGCC.ProjectType = "multi-core" + infoDcGCC.ForProjectPart = "CM7" + var infoDcCLANG BridgeParamType + infoDcCLANG.Compiler = "CLANG" + infoDcCLANG.ProjectType = "multi-core" + infoDcCLANG.ForProjectPart = "CM4" + var infoDcIAR BridgeParamType + infoDcIAR.Compiler = "IAR" + infoDcIAR.ProjectType = "multi-core" + infoDcIAR.ForProjectPart = "CM7" // secure nonsecure outPathTZ := "../../testdata/testExamples/STM32U5_TZ/STM32CubeMX/Board" - var subsystemTzAC6 cbuild.SubsystemType - subsystemTzAC6.Compiler = "AC6" - subsystemTzAC6.SubsystemIdx.ProjectType = "trustzone" - subsystemTzAC6.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzGCC cbuild.SubsystemType - subsystemTzGCC.Compiler = "GCC" - subsystemTzGCC.SubsystemIdx.ProjectType = "trustzone" - subsystemTzGCC.SubsystemIdx.ForProjectPart = "non-secure" - var subsystemTzCLANG cbuild.SubsystemType - subsystemTzCLANG.Compiler = "CLANG" - subsystemTzCLANG.SubsystemIdx.ProjectType = "trustzone" - subsystemTzCLANG.SubsystemIdx.ForProjectPart = "secure" - var subsystemTzIAR cbuild.SubsystemType - subsystemTzIAR.Compiler = "IAR" - subsystemTzIAR.SubsystemIdx.ProjectType = "trustzone" - subsystemTzIAR.SubsystemIdx.ForProjectPart = "non-secure" + var infoTzAC6 BridgeParamType + infoTzAC6.Compiler = "AC6" + infoTzAC6.ProjectType = "trustzone" + infoTzAC6.ForProjectPart = "secure" + var infoTzGCC BridgeParamType + infoTzGCC.Compiler = "GCC" + infoTzGCC.ProjectType = "trustzone" + infoTzGCC.ForProjectPart = "non-secure" + var infoTzCLANG BridgeParamType + infoTzCLANG.Compiler = "CLANG" + infoTzCLANG.ProjectType = "trustzone" + infoTzCLANG.ForProjectPart = "secure" + var infoTzIAR BridgeParamType + infoTzIAR.Compiler = "IAR" + infoTzIAR.ProjectType = "trustzone" + infoTzIAR.ForProjectPart = "non-secure" // invalid outPathInv := "../../testdata/testExamples/STM32H7_DC/STM32CubeMX/STM32H745BGTx/invalid_folder" - var subsystemInv cbuild.SubsystemType - subsystemInv.Compiler = "AC6" - subsystemInv.SubsystemIdx.ProjectType = "single-core" - subsystemInv.SubsystemIdx.ForProjectPart = "" + var infoInv BridgeParamType + infoInv.Compiler = "AC6" + infoInv.ProjectType = "single-core" + infoInv.ForProjectPart = "" type args struct { - outPath string - subsystem cbuild.SubsystemType + outPath string + info BridgeParamType } tests := []struct { name string @@ -423,9 +421,9 @@ func Test_GetLinkerScripts(t *testing.T) { want []string wantErr bool }{ - {"test_sc_ac6", args{outPathSC, subsystemScAC6}, nil, false}, + {"test_sc_ac6", args{outPathSC, infoScAC6}, nil, false}, { - "test_sc_gcc", args{outPathSC, subsystemScGCC}, + "test_sc_gcc", args{outPathSC, infoScGCC}, []string{ filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/STM32H743AGIX_FLASH.ld"), filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/STM32H743AGIX_RAM.ld"), @@ -433,7 +431,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_sc_clang", args{outPathSC, subsystemScCLANG}, + "test_sc_clang", args{outPathSC, infoScCLANG}, []string{ filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/STM32H743AGIX_FLASH.ld"), filepath.Clean(outPathSC + "/STM32CubeMX/STM32CubeIDE/STM32H743AGIX_RAM.ld"), @@ -441,7 +439,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_sc_iar", args{outPathSC, subsystemScIAR}, + "test_sc_iar", args{outPathSC, infoScIAR}, []string{ filepath.Clean(outPathSC + "/STM32CubeMX/EWARM/stm32h743xg_flash.icf"), filepath.Clean(outPathSC + "/STM32CubeMX/EWARM/stm32h743xg_flash_rw_sram1.icf"), @@ -452,7 +450,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_dc_ac6", args{outPathDC, subsystemDcAC6}, + "test_dc_ac6", args{outPathDC, infoDcAC6}, []string{ filepath.Clean(outPathDC + "/STM32CubeMX/MDK-ARM/stm32h745xg_flash_CM4.sct"), filepath.Clean(outPathDC + "/STM32CubeMX/MDK-ARM/stm32h745xx_sram2_CM4.sct"), @@ -460,7 +458,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_dc_gcc", args{outPathDC, subsystemDcGCC}, + "test_dc_gcc", args{outPathDC, infoDcGCC}, []string{ filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM7/STM32H745BGTX_FLASH.ld"), filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM7/STM32H745BGTX_RAM.ld"), @@ -468,7 +466,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_dc_clang", args{outPathDC, subsystemDcCLANG}, + "test_dc_clang", args{outPathDC, infoDcCLANG}, []string{ filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM4/STM32H745BGTX_FLASH.ld"), filepath.Clean(outPathDC + "/STM32CubeMX/STM32CubeIDE/CM4/STM32H745BGTX_RAM.ld"), @@ -476,7 +474,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_dc_iar", args{outPathDC, subsystemDcIAR}, + "test_dc_iar", args{outPathDC, infoDcIAR}, []string{ filepath.Clean(outPathDC + "/STM32CubeMX/EWARM/stm32h745xg_flash_CM7.icf"), filepath.Clean(outPathDC + "/STM32CubeMX/EWARM/stm32h745xx_dtcmram_CM7.icf"), @@ -485,9 +483,9 @@ func Test_GetLinkerScripts(t *testing.T) { }, false, }, - {"test_tz_ac6", args{outPathTZ, subsystemTzAC6}, nil, false}, + {"test_tz_ac6", args{outPathTZ, infoTzAC6}, nil, false}, { - "test_tz_gcc", args{outPathTZ, subsystemTzGCC}, + "test_tz_gcc", args{outPathTZ, infoTzGCC}, []string{ filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/NonSecure/STM32U585AIIXQ_FLASH.ld"), filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/NonSecure/STM32U585AIIXQ_RAM.ld"), @@ -495,7 +493,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_tz_clang", args{outPathTZ, subsystemTzCLANG}, + "test_tz_clang", args{outPathTZ, infoTzCLANG}, []string{ filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/Secure/STM32U585AIIXQ_FLASH.ld"), filepath.Clean(outPathTZ + "/STM32CubeMX/STM32CubeIDE/Secure/STM32U585AIIXQ_RAM.ld"), @@ -503,7 +501,7 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, { - "test_tz_iar", args{outPathTZ, subsystemTzIAR}, + "test_tz_iar", args{outPathTZ, infoTzIAR}, []string{ filepath.Clean(outPathTZ + "/STM32CubeMX/EWARM/stm32u585xx_flash_ns.icf"), filepath.Clean(outPathTZ + "/STM32CubeMX/EWARM/stm32u585xx_sram_ns.icf"), @@ -511,13 +509,13 @@ func Test_GetLinkerScripts(t *testing.T) { false, }, - {"fail", args{outPathInv, subsystemInv}, nil, true}} + {"fail", args{outPathInv, infoInv}, nil, true}} for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - got, err := GetLinkerScripts(tt.args.outPath, &tt.args.subsystem) + got, err := GetLinkerScripts(tt.args.outPath, tt.args.info) if (err != nil) != tt.wantErr { t.Errorf("GetLinkerScripts() %s error = %v, wantErr %v", tt.name, err, tt.wantErr) return