From f11e033100e690d1b480f48272088315f5df9737 Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Thu, 23 Nov 2023 12:57:21 +0100 Subject: [PATCH] flashmap: Add support for linker script generation Flash map form bsp.yml could easily be inconsistent with linker scrip memory regions. This change aims to allow usage of sysflash.h header generate by newt tool to be used by c preprocessor to automatically generate linker scrips that are consistent with flash description from bsp.yml. This simply excludes part of the header so only constants are exported. --- newt/flashmap/flashmap.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/newt/flashmap/flashmap.go b/newt/flashmap/flashmap.go index 517ad720c..d0c0446c3 100644 --- a/newt/flashmap/flashmap.go +++ b/newt/flashmap/flashmap.go @@ -245,12 +245,15 @@ func writeFlashMapHeader(w io.Writer, fm FlashMap) { fmt.Fprintf(w, "#ifndef H_MYNEWT_SYSFLASH_\n") fmt.Fprintf(w, "#define H_MYNEWT_SYSFLASH_\n") fmt.Fprintf(w, "\n") - fmt.Fprintf(w, "#include \"flash_map/flash_map.h\"\n") - fmt.Fprintf(w, "\n") fmt.Fprintf(w, "#define FLASH_AREA_COUNT %d\n", len(fm.Areas)) fmt.Fprintf(w, "\n") + fmt.Fprintf(w, "/* MYNEWT_SYSFLASH_ONLY_CONST is defined when this header is used for linker script generation */\n") + fmt.Fprintf(w, "#ifndef MYNEWT_SYSFLASH_ONLY_CONST\n") + fmt.Fprintf(w, "#include \"flash_map/flash_map.h\"\n") + fmt.Fprintf(w, "\n") fmt.Fprintf(w, "%s", C_VAR_COMMENT) fmt.Fprintf(w, "extern %s;\n", flashMapVarDecl(fm)) + fmt.Fprintf(w, "#endif\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, "/* Flash map was defined in %s */\n", fm.PkgName) fmt.Fprintf(w, "\n")