2013-01-12 23:44:42 +01:00
|
|
|
CC = arm-none-eabi-gcc
|
|
|
|
CPP = arm-none-eabi-cpp
|
|
|
|
LD = arm-none-eabi-gcc
|
|
|
|
AR = arm-none-eabi-ar
|
|
|
|
OBJCOPY = arm-none-eabi-objcopy
|
2014-04-03 00:17:49 +02:00
|
|
|
OBJDUMP = arm-none-eabi-objdump
|
2013-01-12 23:44:42 +01:00
|
|
|
NM = arm-none-eabi-nm
|
|
|
|
|
2013-10-29 14:14:35 +01:00
|
|
|
ifndef SOURCE_LDSCRIPT
|
|
|
|
SOURCE_LDSCRIPT = $(CONTIKI_CPU)/cc2538.lds
|
|
|
|
endif
|
2013-01-12 23:44:42 +01:00
|
|
|
LDSCRIPT = $(OBJECTDIR)/cc2538.ld
|
|
|
|
|
2014-01-30 17:41:51 +01:00
|
|
|
CFLAGS += -mcpu=cortex-m3 -mthumb -mlittle-endian
|
2014-01-31 21:00:31 +01:00
|
|
|
CFLAGS += -ffunction-sections -fdata-sections
|
2013-01-12 23:44:42 +01:00
|
|
|
CFLAGS += -fshort-enums -fomit-frame-pointer -fno-strict-aliasing
|
|
|
|
CFLAGS += -Wall
|
|
|
|
LDFLAGS += -mcpu=cortex-m3 -mthumb -nostartfiles
|
|
|
|
LDFLAGS += -T $(LDSCRIPT)
|
2014-01-31 21:00:31 +01:00
|
|
|
LDFLAGS += -Wl,--gc-sections,--sort-section=alignment
|
2013-01-12 23:44:42 +01:00
|
|
|
LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map),--cref,--no-warn-mismatch
|
|
|
|
OBJCOPY_FLAGS += -O binary --gap-fill 0xff
|
2014-04-03 00:17:49 +02:00
|
|
|
OBJDUMP_FLAGS += --disassemble --source --disassembler-options=force-thumb
|
2013-01-12 23:44:42 +01:00
|
|
|
|
2015-09-26 11:19:22 +02:00
|
|
|
ifdef WERROR
|
|
|
|
CFLAGS += -Werror
|
|
|
|
endif
|
|
|
|
|
2013-01-12 23:44:42 +01:00
|
|
|
### Are we building with code size optimisations?
|
|
|
|
ifeq ($(SMALL),1)
|
2014-01-31 21:00:31 +01:00
|
|
|
CFLAGS += -Os
|
2014-01-30 17:41:51 +01:00
|
|
|
else
|
|
|
|
CFLAGS += -O2
|
2013-01-12 23:44:42 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
### If the user-specified a Node ID, pass a define
|
|
|
|
ifdef NODEID
|
|
|
|
CFLAGS += -DIEEE_ADDR_NODE_ID=$(NODEID)
|
|
|
|
endif
|
|
|
|
|
|
|
|
### CPU-dependent cleanup files
|
2013-10-31 16:25:27 +01:00
|
|
|
CLEAN += symbols.c symbols.h *.d *.elf *.hex
|
2013-01-12 23:44:42 +01:00
|
|
|
|
|
|
|
### CPU-dependent directories
|
|
|
|
CONTIKI_CPU_DIRS = . dev usb
|
|
|
|
|
|
|
|
### Use the existing debug I/O in cpu/arm/common
|
|
|
|
CONTIKI_CPU_DIRS += ../arm/common/dbg-io
|
|
|
|
|
|
|
|
### Use usb core from cpu/cc253x/usb/common
|
|
|
|
CONTIKI_CPU_DIRS += ../cc253x/usb/common ../cc253x/usb/common/cdc-acm
|
|
|
|
|
|
|
|
### CPU-dependent source files
|
|
|
|
CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart.c watchdog.c
|
2013-11-04 20:39:56 +01:00
|
|
|
CONTIKI_CPU_SOURCEFILES += nvic.c cpu.c sys-ctrl.c gpio.c ioc.c spi.c adc.c
|
2015-05-15 19:52:08 +02:00
|
|
|
CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ccm.c sha256.c
|
2013-01-12 23:44:42 +01:00
|
|
|
CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c
|
2015-10-18 20:14:17 +02:00
|
|
|
CONTIKI_CPU_SOURCEFILES += pka.c bignum-driver.c ecc-driver.c ecc-algorithm.c
|
|
|
|
CONTIKI_CPU_SOURCEFILES += ecc-curve.c
|
2013-01-12 23:44:42 +01:00
|
|
|
CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c
|
|
|
|
CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c
|
2015-02-11 17:54:56 +01:00
|
|
|
CONTIKI_CPU_SOURCEFILES += i2c.c cc2538-temp-sensor.c vdd3-sensor.c
|
2015-11-25 23:44:54 +01:00
|
|
|
CONTIKI_CPU_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c pwm.c
|
2013-01-12 23:44:42 +01:00
|
|
|
|
|
|
|
DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c
|
|
|
|
|
|
|
|
USB_CORE_SOURCEFILES += usb-core.c cdc-acm.c
|
|
|
|
USB_ARCH_SOURCEFILES += usb-arch.c usb-serial.c cdc-acm-descriptors.c
|
|
|
|
|
2015-02-09 16:23:36 +01:00
|
|
|
ifneq ($(TARGET_START_SOURCEFILES),)
|
|
|
|
CPU_START_SOURCEFILES = TARGET_START_SOURCEFILES
|
|
|
|
else
|
|
|
|
CPU_START_SOURCEFILES = startup-gcc.c
|
|
|
|
endif
|
|
|
|
CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}}
|
|
|
|
|
2013-01-12 23:44:42 +01:00
|
|
|
CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES)
|
|
|
|
CONTIKI_SOURCEFILES += $(USB_CORE_SOURCEFILES) $(USB_ARCH_SOURCEFILES)
|
|
|
|
|
2015-05-26 20:03:37 +02:00
|
|
|
MODULES += lib/newlib
|
|
|
|
|
cc2538: Build without the Contiki target library
The GNU linker ld searches and processes libraries and object files in
the order they are specified. Library files are archive files whose
members are object files. The linker handles an archive file by scanning
through it for members that define symbols that have so far been
referenced but not defined. But an ordinary object file is linked in the
usual fashion.
The C library is implicitly linked after all object files and libraries
specified on the command line.
Because of that, if the C library depends on the Contiki target library,
e.g. for the implementation of system calls, then these dependencies are
not linked, which results in undefined references. Actually, the Contiki
target library also needs the C library, hence a circular dependency
between these libraries, which means that explicitly adding -lc anywhere
on the command line can not help. The only solution in that case is to
pass these libraries to ld between --start-group and --end-group.
Archives grouped in this way are searched repeatedly by the linker until
no new undefined references are created.
This archive grouping option has a significant performance cost for the
linking stage. Moreover, having to use it and to pass -lc explicitly on
the command line is unusual, which is disturbing and more complicated
for users needing the C library to depend on the Contiki target library.
The same would be true for circular dependencies between the Contiki
target library and any other library.
Another issue with the Contiki target library is that it may alter the
apparent behavior of the weak vs. strong symbols, because of the way ld
handles archives, which may make it discard archive object files
containing strong versions of referenced symbols:
- If a symbol has a weak and a strong version in this library, both
inside the same object file, then the linker uses the strong
definition.
- If a weak symbol in this library has a strong counterpart in an
object file outside, then the linker uses the strong definition.
- If a strong symbol in this library is inside an object file
containing other referenced symbols, and has a weak counterpart
anywhere, then the linker uses the strong definition.
- If a strong symbol in this library is the only symbol referenced in
its object file, and has a weak counterpart in an object file
outside, then the linker uses the strong definition if this library
is linked first, and the weak one otherwise.
- If a strong symbol in this library is the only symbol referenced in
its object file, and has a weak counterpart in another object file in
this library, then the linker uses the definition from the first of
these objects added when creating this archive.
- If a symbol has a weak and a strong version, one in this library, and
the other in another library, then the rules are the same as if both
were in the Contiki target library.
The existence of cases where the linker uses a weak symbol despite the
presence of its strong counterpart in the sources compiled then passed
to the linker is very error-prone, all the more this behavior depends on
the order the object and archive files are passed on the command lines,
which may just result from the order of source files in lists where it
apparently does not matter. Such cases would be needed in the future,
e.g. to define weak default implementations of some system calls that
can be overridden by platform-specific implementations, both ending up
in the Contiki target library. There was already such a case used to
define the UART and USB ISRs as weak aliases of default_handler(),
relying on this implicit unusual behavior to keep default_handler() if
the UART or USB driver was unused, which was dangerous.
Since the Contiki target library was only used as an intermediate file
during the build, the current commit fixes these issues by simply
directly using the object files instead of building an intermediate
archive from them.
The CONTIKI_OBJECTFILES make variable would be incomplete if it were
used as a simple prerequisite in the %.elf rule in Makefile.cc2538,
because other object files are added to it after this rule. That's why
.SECONDEXPANSION is used to defer its expansion. Another solution would
have been to split Makefile.cc2538, with the variable assignments kept
in it, and the rule definitions moved to Makefile.customrules-cc2538,
but this would have required to add Makefile.customrules-<target> files
to all CC2538 platforms, only to include Makefile.customrules-cc2538.
The solution used here is much simpler.
Because the UART and USB ISRs were weak aliases of default_handler(),
this change would imply that these ISRs would always be used by the
linker instead of default_handler(), even if their drivers were
configured as unused with UART_CONF_ENABLE and USB_SERIAL_CONF_ENABLE,
which would be wrong. This commit fixes this issue by removing these
weak aliases and putting either these ISRs or default_handler() in the
vector table, depending on the configuration. Weak aliases are elegant,
but Contiki's build system does not currently allow to automatically
build or not source files depending on the configuration, so keeping
these weak aliases would have required to add #if constructs somewhere
in the source code, which would have broken their elegance and made them
pointless.
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-01 23:27:23 +02:00
|
|
|
.SECONDEXPANSION:
|
|
|
|
|
2013-01-12 23:44:42 +01:00
|
|
|
### Don't treat the .elf as intermediate
|
2013-10-31 16:25:27 +01:00
|
|
|
.PRECIOUS: %.elf %.hex %.bin
|
2013-01-12 23:44:42 +01:00
|
|
|
|
|
|
|
### Always re-build ieee-addr.o in case the command line passes a new NODEID
|
|
|
|
FORCE:
|
|
|
|
|
2013-06-21 00:45:41 +02:00
|
|
|
$(OBJECTDIR)/ieee-addr.o: ieee-addr.c FORCE | $(OBJECTDIR)
|
2013-08-06 17:46:57 +02:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c $< -o $@
|
2013-01-12 23:44:42 +01:00
|
|
|
|
|
|
|
### Compilation rules
|
|
|
|
CUSTOM_RULE_LINK=1
|
|
|
|
|
cc2538: Build without the Contiki target library
The GNU linker ld searches and processes libraries and object files in
the order they are specified. Library files are archive files whose
members are object files. The linker handles an archive file by scanning
through it for members that define symbols that have so far been
referenced but not defined. But an ordinary object file is linked in the
usual fashion.
The C library is implicitly linked after all object files and libraries
specified on the command line.
Because of that, if the C library depends on the Contiki target library,
e.g. for the implementation of system calls, then these dependencies are
not linked, which results in undefined references. Actually, the Contiki
target library also needs the C library, hence a circular dependency
between these libraries, which means that explicitly adding -lc anywhere
on the command line can not help. The only solution in that case is to
pass these libraries to ld between --start-group and --end-group.
Archives grouped in this way are searched repeatedly by the linker until
no new undefined references are created.
This archive grouping option has a significant performance cost for the
linking stage. Moreover, having to use it and to pass -lc explicitly on
the command line is unusual, which is disturbing and more complicated
for users needing the C library to depend on the Contiki target library.
The same would be true for circular dependencies between the Contiki
target library and any other library.
Another issue with the Contiki target library is that it may alter the
apparent behavior of the weak vs. strong symbols, because of the way ld
handles archives, which may make it discard archive object files
containing strong versions of referenced symbols:
- If a symbol has a weak and a strong version in this library, both
inside the same object file, then the linker uses the strong
definition.
- If a weak symbol in this library has a strong counterpart in an
object file outside, then the linker uses the strong definition.
- If a strong symbol in this library is inside an object file
containing other referenced symbols, and has a weak counterpart
anywhere, then the linker uses the strong definition.
- If a strong symbol in this library is the only symbol referenced in
its object file, and has a weak counterpart in an object file
outside, then the linker uses the strong definition if this library
is linked first, and the weak one otherwise.
- If a strong symbol in this library is the only symbol referenced in
its object file, and has a weak counterpart in another object file in
this library, then the linker uses the definition from the first of
these objects added when creating this archive.
- If a symbol has a weak and a strong version, one in this library, and
the other in another library, then the rules are the same as if both
were in the Contiki target library.
The existence of cases where the linker uses a weak symbol despite the
presence of its strong counterpart in the sources compiled then passed
to the linker is very error-prone, all the more this behavior depends on
the order the object and archive files are passed on the command lines,
which may just result from the order of source files in lists where it
apparently does not matter. Such cases would be needed in the future,
e.g. to define weak default implementations of some system calls that
can be overridden by platform-specific implementations, both ending up
in the Contiki target library. There was already such a case used to
define the UART and USB ISRs as weak aliases of default_handler(),
relying on this implicit unusual behavior to keep default_handler() if
the UART or USB driver was unused, which was dangerous.
Since the Contiki target library was only used as an intermediate file
during the build, the current commit fixes these issues by simply
directly using the object files instead of building an intermediate
archive from them.
The CONTIKI_OBJECTFILES make variable would be incomplete if it were
used as a simple prerequisite in the %.elf rule in Makefile.cc2538,
because other object files are added to it after this rule. That's why
.SECONDEXPANSION is used to defer its expansion. Another solution would
have been to split Makefile.cc2538, with the variable assignments kept
in it, and the rule definitions moved to Makefile.customrules-cc2538,
but this would have required to add Makefile.customrules-<target> files
to all CC2538 platforms, only to include Makefile.customrules-cc2538.
The solution used here is much simpler.
Because the UART and USB ISRs were weak aliases of default_handler(),
this change would imply that these ISRs would always be used by the
linker instead of default_handler(), even if their drivers were
configured as unused with UART_CONF_ENABLE and USB_SERIAL_CONF_ENABLE,
which would be wrong. This commit fixes this issue by removing these
weak aliases and putting either these ISRs or default_handler() in the
vector table, depending on the configuration. Weak aliases are elegant,
but Contiki's build system does not currently allow to automatically
build or not source files depending on the configuration, so keeping
these weak aliases would have required to add #if constructs somewhere
in the source code, which would have broken their elegance and made them
pointless.
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-01 23:27:23 +02:00
|
|
|
%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT)
|
2013-08-06 17:46:57 +02:00
|
|
|
$(TRACE_LD)
|
2014-01-27 18:01:37 +01:00
|
|
|
$(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
|
2013-01-12 23:44:42 +01:00
|
|
|
|
2013-10-31 16:25:27 +01:00
|
|
|
%.hex: %.elf
|
|
|
|
$(OBJCOPY) -O ihex $< $@
|
|
|
|
|
2013-01-12 23:44:42 +01:00
|
|
|
%.bin: %.elf
|
|
|
|
$(OBJCOPY) $(OBJCOPY_FLAGS) $< $@
|
|
|
|
|
2014-04-03 00:17:49 +02:00
|
|
|
%.lst: %.elf
|
|
|
|
$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@
|
|
|
|
|
2013-10-31 16:25:27 +01:00
|
|
|
### We don't really need the .hex and .bin for the .$(TARGET) but let's make
|
|
|
|
### sure they get built
|
|
|
|
%.$(TARGET): %.elf %.hex %.bin
|
2013-01-12 23:44:42 +01:00
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
### This rule is used to generate the correct linker script
|
|
|
|
LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES)))
|
|
|
|
LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS))
|
2015-06-18 22:31:53 +02:00
|
|
|
LDGENFLAGS += -imacros "contiki-conf.h" -imacros "dev/cc2538-dev.h"
|
2015-07-12 21:48:18 +02:00
|
|
|
LDGENFLAGS += -imacros "dev/flash.h" -imacros "cfs-coffee-arch.h"
|
2013-08-06 17:46:57 +02:00
|
|
|
LDGENFLAGS += -x c -P -E
|
2013-01-12 23:44:42 +01:00
|
|
|
|
2013-06-21 00:45:41 +02:00
|
|
|
# NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR)
|
2013-10-29 14:14:35 +01:00
|
|
|
$(LDSCRIPT): $(SOURCE_LDSCRIPT) FORCE | $(OBJECTDIR)
|
2013-08-06 17:46:57 +02:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(LDGENFLAGS) $< -o $@
|