Skip to content

Commit e423947

Browse files
author
Clemens Mandl
committed
Fixed Linking with Linker Script
1 parent b112ad7 commit e423947

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

tools/export/nb/Makefile.tmpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ MKDIR=mkdir
4949
CP=cp
5050
CCADMIN=CCadmin
5151

52+
BUILDDIR = BUILD
53+
PLATFORM = {{target}}
54+
ELF2BIN = 'arm-none-eabi-objcopy'
55+
TARGET = ${CND_DISTDIR}/${CONF}/${CND_PLATFORM}/{{name}}
56+
5257

5358
# build
5459
build: .build-post
@@ -58,7 +63,10 @@ build: .build-post
5863

5964
.build-post: .build-impl
6065
# Add your post 'build' code here...
61-
66+
$(ELF2BIN) -O binary ${TARGET}.elf ${TARGET}.bin
67+
+@echo "===== bin file ready to flash: $(TARGET).bin ====="
68+
$(ELF2BIN) -O ihex ${TARGET}.elf ${TARGET}.hex
69+
cp ${TARGET}.* ${CND_BUILDDIR}/${CONF}/${CND_PLATFORM}
6270

6371
# clean
6472
clean: .clean-post
@@ -126,3 +134,6 @@ include nbproject/Makefile-impl.mk
126134

127135
# include project make variables
128136
include nbproject/Makefile-variables.mk
137+
138+
CND_BUILDDIR = ${BUILDDIR}
139+
CND_PLATFORM = ${PLATFORM}

tools/export/nb/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def is_target_supported(cls, target_name):
2828
return apply_supported_whitelist(
2929
cls.TOOLCHAIN, POST_BINARY_WHITELIST, target)
3030

31+
@staticmethod
32+
def prepare_sys_lib(libname):
33+
return "-l" + libname
34+
3135
def toolchain_flags(self, toolchain):
3236
"""Returns a dictionary of toolchain flags.
3337
Keys of the dictionary are:
@@ -207,11 +211,19 @@ def create_jinja_ctx(self):
207211
sources = [self.filter_dot(field) for field in sources]
208212
include_paths = [self.filter_dot(field) for field in self.resources.inc_dirs]
209213

214+
sys_libs = [self.prepare_sys_lib(lib) for lib
215+
in self.toolchain.sys_libs]
216+
preproc = " ".join([part for part
217+
in ([basename(self.toolchain.preproc[0])] +
218+
self.toolchain.preproc[1:] +
219+
self.toolchain.ld[1:])])
220+
210221
if 'nbproject' in include_paths:
211222
include_paths.remove('nbproject')
212223

213224
jinja_ctx = {
214225
'name': self.project_name,
226+
'target': self.toolchain.target.name,
215227
'elf_location': join('BUILD', self.project_name) + '.elf',
216228
'c_symbols': self.toolchain.get_symbols(),
217229
'asm_symbols': self.toolchain.get_symbols(True),
@@ -233,6 +245,8 @@ def create_jinja_ctx(self):
233245
'c_std': self.get_netbeans_c_std(c_std),
234246
'cpp_std': self.get_netbeans_cpp_std(cpp_std),
235247
'linker_script': self.ld_script,
248+
'linker_libs': sys_libs,
249+
'pp_cmd': preproc
236250
}
237251
return jinja_ctx
238252

tools/export/nb/configurations.tmpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@
131131
</preprocessorList>
132132
</asmTool>
133133
<linkerTool>
134+
<output>${CND_DISTDIR}/${CND_CONF}/{{target}}/{{name}}.elf</output>
135+
<additionalDep>${CND_BUILDDIR}/${CND_CONF}/{{target}}/.link_script.ld</additionalDep>
134136
<commandlineTool>arm-none-eabi-gcc</commandlineTool>
135-
<commandLine>{%- for symbol in opts['ld'] -%}{{ symbol+" "}}{%- endfor -%}</commandLine>
137+
<commandLine>-T ${CND_BUILDDIR}/${CND_CONF}/{{target}}/.link_script.ld {%- for symbol in opts['ld'] -%}{{" "+symbol}}{%- endfor -%} {%- for item in linker_libs -%}{{" "+item}}{%- endfor -%} </commandLine>
136138
</linkerTool>
137139
</compileType>
138140
{% for h in headers -%}
@@ -156,6 +158,11 @@
156158
</item>
157159
{% endfor -%}
158160
<item path="{{linker_script }}" ex="false" tool="3" flavor2="0">
161+
<customTool>
162+
<customToolCommandline>{{pp_cmd}} -o $@ $&lt;</customToolCommandline>
163+
<customToolDescription>Create ELF File using Link Script</customToolDescription>
164+
<customToolOutputs>${CND_BUILDDIR}/${CND_CONF}/{{target}}/.link_script.ld</customToolOutputs>
165+
</customTool>
159166
</item>
160167
<item path="/nbproject/private/c_standard_headers_indexer.c" ex="true" tool="0" flavor2="0">
161168
</item>

0 commit comments

Comments
 (0)