Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newt: Add possibility to use generated linker script #540

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions newt/pkg/bsp_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ func (bsp *BspPackage) resolvePathSetting(
return path, nil
}

func (bsp *BspPackage) getAutogeneratedLinkerScriptPath() (string, error) {
defaultLinkerScriptPath := "bin/" + bsp.yov.Pkg.Name() + "/generated/link/mynewt.ld"
proj := interfaces.GetProject()
path, err := proj.ResolvePath(proj.Path(), defaultLinkerScriptPath)
if err != nil {
return "", err
}
return path, nil
}

// Interprets a setting as either a single linker script or a list of linker
// scripts.
func (bsp *BspPackage) resolveLinkerScriptSetting(
Expand All @@ -103,14 +113,28 @@ func (bsp *BspPackage) resolveLinkerScriptSetting(
return nil, err
}

if path != "" {
if path == "autogenerated" {
path, err = bsp.getAutogeneratedLinkerScriptPath()
if err != nil {
return nil, util.PreNewtError(err,
"Could not resolve autogenerated linker script path for target \"%s\"",
bsp.yov.Pkg.Name())
}
paths = append(paths, path)
} else if path != "" {
paths = append(paths, path)
}
} else {
proj := interfaces.GetProject()

// Read each linker script from the list.
for _, val := range vals {
if val == "autogenerated" {
return nil, util.PreNewtError(err,
"Both autogenerated and custom linker scripts cannot be used."+
"Newt handles either autogenerated linker script or a list of custom linker scripts.")
}
m-gorecki marked this conversation as resolved.
Show resolved Hide resolved

path, err := proj.ResolvePath(ypkg.Repo().Path(), val)
if err != nil {
return nil, util.PreNewtError(err,
Expand Down Expand Up @@ -226,7 +250,6 @@ func NewBspPackage(lpkg *LocalPackage, yov *BspYCfgOverride) (*BspPackage, error
lpkg.Load()
bsp.LocalPackage = lpkg
bsp.BspV = ycfg.NewYCfg(bsp.BspYamlPath())

err := bsp.Reload(nil)

return bsp, err
Expand Down
Loading