Skip to content

Commit

Permalink
Add support for "name:" and "map:" node (#52)
Browse files Browse the repository at this point in the history
- cbuild.go:
  - Independent of stm32CubeMX
  - Extend structure CbuildGenIdxType with "map" and "name"
  - Function Read returns parameters only for requested generatorID
- stm32CubeMX.go:
  - Introduce structure BridgeParamType that contains only necessary information for CubeMX bridge
  - Determine CubeMX context (including new contexts, that are provided by new "map" node) and save it to 
  BridgeParamType (CubeMX context is parsed only in one place)
- mxDevice.go:
  - Simplify CubeMX context handling. CubeMX context is already provided as parameter in BridgeParamType
  - Change the *hal_msp.c file name retrieval method. (old method does not work for STM32H7RS devices)
- iniReader.go:
  - Simplify CubeMX context handling. CubeMX context is already provided as parameter in BridgeParamType
- readFile.go:
  - synchronize to changes in cbuild.go, mxDevice.go and stm32CubeMx.go
- Synchronize test files to changes in source files
  • Loading branch information
DavidLesnjak authored May 16, 2024
1 parent 456c7ac commit 46cffae
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 673 deletions.
168 changes: 41 additions & 127 deletions internal/cbuild/cbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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"`
Expand Down Expand Up @@ -176,94 +160,49 @@ 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)
if err != nil {
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 := &params.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: "
Expand All @@ -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
}
39 changes: 18 additions & 21 deletions internal/readFile/readFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
err := cbuild.Read(inFile, "CubeMX", &cbuildParams)
if err != nil {
return err
}
_, err = stm32cubemx.WriteProjectFile(outPath, &params)

err = stm32cubemx.GetBridgeInfo(&cbuildParams, &params)
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
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 46cffae

Please sign in to comment.