From b8f9885e840689513f7cf0746598ae65ae593354 Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Fri, 19 Jan 2024 15:28:51 +0100 Subject: [PATCH] [WIP] newt: Use default linker script if it's not specified in bsp.yml Now if "bsp.linkerscript" key is empty default linker script will be passed to the linker. IMPORTANT: bsp.linkerscript key still has to be present in the bsp.yml file. It simply has to exist without any paths specified. It's done this way to prevent adding linker scripts to native target's builds. --- newt/pkg/bsp_package.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/newt/pkg/bsp_package.go b/newt/pkg/bsp_package.go index 158ebec2d..f76f0f635 100644 --- a/newt/pkg/bsp_package.go +++ b/newt/pkg/bsp_package.go @@ -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( @@ -103,7 +113,15 @@ 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 { @@ -111,6 +129,17 @@ func (bsp *BspPackage) resolveLinkerScriptSetting( // Read each linker script from the list. for _, val := range vals { + if val == "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) + continue + } + path, err := proj.ResolvePath(ypkg.Repo().Path(), val) if err != nil { return nil, util.PreNewtError(err, @@ -226,7 +255,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